pdf.worker.js 1.7 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843368443684536846368473684836849368503685136852368533685436855368563685736858368593686036861368623686336864368653686636867368683686936870368713687236873368743687536876368773687836879368803688136882368833688436885368863688736888368893689036891368923689336894368953689636897368983689936900369013690236903369043690536906369073690836909369103691136912369133691436915369163691736918369193692036921369223692336924369253692636927369283692936930369313693236933369343693536936369373693836939369403694136942369433694436945369463694736948369493695036951369523695336954369553695636957369583695936960369613696236963369643696536966369673696836969369703697136972369733697436975369763697736978369793698036981369823698336984369853698636987369883698936990369913699236993369943699536996369973699836999370003700137002370033700437005370063700737008370093701037011370123701337014370153701637017370183701937020370213702237023370243702537026370273702837029370303703137032370333703437035370363703737038370393704037041370423704337044370453704637047370483704937050370513705237053370543705537056370573705837059370603706137062370633706437065370663706737068370693707037071370723707337074370753707637077370783707937080370813708237083370843708537086370873708837089370903709137092370933709437095370963709737098370993710037101371023710337104371053710637107371083710937110371113711237113371143711537116371173711837119371203712137122371233712437125371263712737128371293713037131371323713337134371353713637137371383713937140371413714237143371443714537146371473714837149371503715137152371533715437155371563715737158371593716037161371623716337164371653716637167371683716937170371713717237173371743717537176371773717837179371803718137182371833718437185371863718737188371893719037191371923719337194371953719637197371983719937200372013720237203372043720537206372073720837209372103721137212372133721437215372163721737218372193722037221372223722337224372253722637227372283722937230372313723237233372343723537236372373723837239372403724137242372433724437245372463724737248372493725037251372523725337254372553725637257372583725937260372613726237263372643726537266372673726837269372703727137272372733727437275372763727737278372793728037281372823728337284372853728637287372883728937290372913729237293372943729537296372973729837299373003730137302373033730437305373063730737308373093731037311373123731337314373153731637317373183731937320373213732237323373243732537326373273732837329373303733137332373333733437335373363733737338373393734037341373423734337344373453734637347373483734937350373513735237353373543735537356373573735837359373603736137362373633736437365373663736737368373693737037371373723737337374373753737637377373783737937380373813738237383373843738537386373873738837389373903739137392373933739437395373963739737398373993740037401374023740337404374053740637407374083740937410374113741237413374143741537416374173741837419374203742137422374233742437425374263742737428374293743037431374323743337434374353743637437374383743937440374413744237443374443744537446374473744837449374503745137452374533745437455374563745737458374593746037461374623746337464374653746637467374683746937470374713747237473374743747537476374773747837479374803748137482374833748437485374863748737488374893749037491374923749337494374953749637497374983749937500375013750237503375043750537506375073750837509375103751137512375133751437515375163751737518375193752037521375223752337524375253752637527375283752937530375313753237533375343753537536375373753837539375403754137542375433754437545375463754737548375493755037551375523755337554375553755637557375583755937560375613756237563375643756537566375673756837569375703757137572375733757437575375763757737578375793758037581375823758337584375853758637587375883758937590375913759237593375943759537596375973759837599376003760137602376033760437605376063760737608376093761037611376123761337614376153761637617376183761937620376213762237623376243762537626376273762837629376303763137632376333763437635376363763737638376393764037641376423764337644376453764637647376483764937650376513765237653376543765537656376573765837659376603766137662376633766437665376663766737668376693767037671376723767337674376753767637677376783767937680376813768237683376843768537686376873768837689376903769137692376933769437695376963769737698376993770037701377023770337704377053770637707377083770937710377113771237713377143771537716377173771837719377203772137722377233772437725377263772737728377293773037731377323773337734377353773637737377383773937740377413774237743377443774537746377473774837749377503775137752377533775437755377563775737758377593776037761377623776337764377653776637767377683776937770377713777237773377743777537776377773777837779377803778137782377833778437785377863778737788377893779037791377923779337794377953779637797377983779937800378013780237803378043780537806378073780837809378103781137812378133781437815378163781737818378193782037821378223782337824378253782637827378283782937830378313783237833378343783537836378373783837839378403784137842378433784437845378463784737848378493785037851378523785337854378553785637857378583785937860378613786237863378643786537866378673786837869378703787137872378733787437875378763787737878378793788037881378823788337884378853788637887378883788937890378913789237893378943789537896378973789837899379003790137902379033790437905379063790737908379093791037911379123791337914379153791637917379183791937920379213792237923379243792537926379273792837929379303793137932379333793437935379363793737938379393794037941379423794337944379453794637947379483794937950379513795237953379543795537956379573795837959379603796137962379633796437965379663796737968379693797037971379723797337974379753797637977379783797937980379813798237983379843798537986379873798837989379903799137992379933799437995379963799737998379993800038001380023800338004380053800638007380083800938010380113801238013380143801538016380173801838019380203802138022380233802438025380263802738028380293803038031380323803338034380353803638037380383803938040380413804238043380443804538046380473804838049380503805138052380533805438055380563805738058380593806038061380623806338064380653806638067380683806938070380713807238073380743807538076380773807838079380803808138082380833808438085380863808738088380893809038091380923809338094380953809638097380983809938100381013810238103381043810538106381073810838109381103811138112381133811438115381163811738118381193812038121381223812338124381253812638127381283812938130381313813238133381343813538136381373813838139381403814138142381433814438145381463814738148381493815038151381523815338154381553815638157381583815938160381613816238163381643816538166381673816838169381703817138172381733817438175381763817738178381793818038181381823818338184381853818638187381883818938190381913819238193381943819538196381973819838199382003820138202382033820438205382063820738208382093821038211382123821338214382153821638217382183821938220382213822238223382243822538226382273822838229382303823138232382333823438235382363823738238382393824038241382423824338244382453824638247382483824938250382513825238253382543825538256382573825838259382603826138262382633826438265382663826738268382693827038271382723827338274382753827638277382783827938280382813828238283382843828538286382873828838289382903829138292382933829438295382963829738298382993830038301383023830338304383053830638307383083830938310383113831238313383143831538316383173831838319383203832138322383233832438325383263832738328383293833038331383323833338334383353833638337383383833938340383413834238343383443834538346383473834838349383503835138352383533835438355383563835738358383593836038361383623836338364383653836638367383683836938370383713837238373383743837538376383773837838379383803838138382383833838438385383863838738388383893839038391383923839338394383953839638397383983839938400384013840238403384043840538406384073840838409384103841138412384133841438415384163841738418384193842038421384223842338424384253842638427384283842938430384313843238433384343843538436384373843838439384403844138442384433844438445384463844738448384493845038451384523845338454384553845638457384583845938460384613846238463384643846538466384673846838469384703847138472384733847438475384763847738478384793848038481384823848338484384853848638487384883848938490384913849238493384943849538496384973849838499385003850138502385033850438505385063850738508385093851038511385123851338514385153851638517385183851938520385213852238523385243852538526385273852838529385303853138532385333853438535385363853738538385393854038541385423854338544385453854638547385483854938550385513855238553385543855538556385573855838559385603856138562385633856438565385663856738568385693857038571385723857338574385753857638577385783857938580385813858238583385843858538586385873858838589385903859138592385933859438595385963859738598385993860038601386023860338604386053860638607386083860938610386113861238613386143861538616386173861838619386203862138622386233862438625386263862738628386293863038631386323863338634386353863638637386383863938640386413864238643386443864538646386473864838649386503865138652386533865438655386563865738658386593866038661386623866338664386653866638667386683866938670386713867238673386743867538676386773867838679386803868138682386833868438685386863868738688386893869038691386923869338694386953869638697386983869938700387013870238703387043870538706387073870838709387103871138712387133871438715387163871738718387193872038721387223872338724387253872638727387283872938730387313873238733387343873538736387373873838739387403874138742387433874438745387463874738748387493875038751387523875338754387553875638757387583875938760387613876238763387643876538766387673876838769387703877138772387733877438775387763877738778387793878038781387823878338784387853878638787387883878938790387913879238793387943879538796387973879838799388003880138802388033880438805388063880738808388093881038811388123881338814388153881638817388183881938820388213882238823388243882538826388273882838829388303883138832388333883438835388363883738838388393884038841388423884338844388453884638847388483884938850388513885238853388543885538856388573885838859388603886138862388633886438865388663886738868388693887038871388723887338874388753887638877388783887938880388813888238883388843888538886388873888838889388903889138892388933889438895388963889738898388993890038901389023890338904389053890638907389083890938910389113891238913389143891538916389173891838919389203892138922389233892438925389263892738928389293893038931389323893338934389353893638937389383893938940389413894238943389443894538946389473894838949389503895138952389533895438955389563895738958389593896038961389623896338964389653896638967389683896938970389713897238973389743897538976389773897838979389803898138982389833898438985389863898738988389893899038991389923899338994389953899638997389983899939000390013900239003390043900539006390073900839009390103901139012390133901439015390163901739018390193902039021390223902339024390253902639027390283902939030390313903239033390343903539036390373903839039390403904139042390433904439045390463904739048390493905039051390523905339054390553905639057390583905939060390613906239063390643906539066390673906839069390703907139072390733907439075390763907739078390793908039081390823908339084390853908639087390883908939090390913909239093390943909539096390973909839099391003910139102391033910439105391063910739108391093911039111391123911339114391153911639117391183911939120391213912239123391243912539126391273912839129391303913139132391333913439135391363913739138391393914039141391423914339144391453914639147391483914939150391513915239153391543915539156391573915839159391603916139162391633916439165391663916739168391693917039171391723917339174391753917639177391783917939180391813918239183391843918539186391873918839189391903919139192391933919439195391963919739198391993920039201392023920339204392053920639207392083920939210392113921239213392143921539216392173921839219392203922139222392233922439225392263922739228392293923039231392323923339234392353923639237392383923939240392413924239243392443924539246392473924839249392503925139252392533925439255392563925739258392593926039261392623926339264392653926639267392683926939270392713927239273392743927539276392773927839279392803928139282392833928439285392863928739288392893929039291392923929339294392953929639297392983929939300393013930239303393043930539306393073930839309393103931139312393133931439315393163931739318393193932039321393223932339324393253932639327393283932939330393313933239333393343933539336393373933839339393403934139342393433934439345393463934739348393493935039351393523935339354393553935639357393583935939360393613936239363393643936539366393673936839369393703937139372393733937439375393763937739378393793938039381393823938339384393853938639387393883938939390393913939239393393943939539396393973939839399394003940139402394033940439405394063940739408394093941039411394123941339414394153941639417394183941939420394213942239423394243942539426394273942839429394303943139432394333943439435394363943739438394393944039441394423944339444394453944639447394483944939450394513945239453394543945539456394573945839459394603946139462394633946439465394663946739468394693947039471394723947339474394753947639477394783947939480394813948239483394843948539486394873948839489394903949139492394933949439495394963949739498394993950039501395023950339504395053950639507395083950939510395113951239513395143951539516395173951839519395203952139522395233952439525395263952739528395293953039531395323953339534395353953639537395383953939540395413954239543395443954539546395473954839549395503955139552395533955439555395563955739558395593956039561395623956339564395653956639567395683956939570395713957239573395743957539576395773957839579395803958139582395833958439585395863958739588395893959039591395923959339594395953959639597395983959939600396013960239603396043960539606396073960839609396103961139612396133961439615396163961739618396193962039621396223962339624396253962639627396283962939630396313963239633396343963539636396373963839639396403964139642396433964439645396463964739648396493965039651396523965339654396553965639657396583965939660396613966239663396643966539666396673966839669396703967139672396733967439675396763967739678396793968039681396823968339684396853968639687396883968939690396913969239693396943969539696396973969839699397003970139702397033970439705397063970739708397093971039711397123971339714397153971639717397183971939720397213972239723397243972539726397273972839729397303973139732397333973439735397363973739738397393974039741397423974339744397453974639747397483974939750397513975239753397543975539756397573975839759397603976139762397633976439765397663976739768397693977039771397723977339774397753977639777397783977939780397813978239783397843978539786397873978839789397903979139792397933979439795397963979739798397993980039801398023980339804398053980639807398083980939810398113981239813398143981539816398173981839819398203982139822398233982439825398263982739828398293983039831398323983339834398353983639837398383983939840398413984239843398443984539846398473984839849398503985139852398533985439855398563985739858398593986039861398623986339864398653986639867398683986939870398713987239873398743987539876398773987839879398803988139882398833988439885398863988739888398893989039891398923989339894398953989639897398983989939900399013990239903399043990539906399073990839909399103991139912399133991439915399163991739918399193992039921399223992339924399253992639927399283992939930399313993239933399343993539936399373993839939399403994139942399433994439945399463994739948399493995039951399523995339954399553995639957399583995939960399613996239963399643996539966399673996839969399703997139972399733997439975399763997739978399793998039981399823998339984399853998639987399883998939990399913999239993399943999539996399973999839999400004000140002400034000440005400064000740008400094001040011400124001340014400154001640017400184001940020400214002240023400244002540026400274002840029400304003140032400334003440035400364003740038400394004040041400424004340044400454004640047400484004940050400514005240053400544005540056400574005840059400604006140062400634006440065400664006740068400694007040071400724007340074400754007640077400784007940080400814008240083400844008540086400874008840089400904009140092400934009440095400964009740098400994010040101401024010340104401054010640107401084010940110401114011240113401144011540116401174011840119401204012140122401234012440125401264012740128401294013040131401324013340134401354013640137401384013940140401414014240143401444014540146401474014840149401504015140152401534015440155401564015740158401594016040161401624016340164401654016640167401684016940170401714017240173401744017540176401774017840179401804018140182401834018440185401864018740188401894019040191401924019340194401954019640197401984019940200402014020240203402044020540206402074020840209402104021140212402134021440215402164021740218402194022040221402224022340224402254022640227402284022940230402314023240233402344023540236402374023840239402404024140242402434024440245402464024740248402494025040251402524025340254402554025640257402584025940260402614026240263402644026540266402674026840269402704027140272402734027440275402764027740278402794028040281402824028340284402854028640287402884028940290402914029240293402944029540296402974029840299403004030140302403034030440305403064030740308403094031040311403124031340314403154031640317403184031940320403214032240323403244032540326403274032840329403304033140332403334033440335403364033740338403394034040341403424034340344403454034640347403484034940350403514035240353403544035540356403574035840359403604036140362403634036440365403664036740368403694037040371403724037340374403754037640377403784037940380403814038240383403844038540386403874038840389403904039140392403934039440395403964039740398403994040040401404024040340404404054040640407404084040940410404114041240413404144041540416404174041840419404204042140422404234042440425404264042740428404294043040431404324043340434404354043640437404384043940440404414044240443404444044540446404474044840449404504045140452404534045440455404564045740458404594046040461404624046340464404654046640467404684046940470404714047240473404744047540476404774047840479404804048140482404834048440485404864048740488404894049040491404924049340494404954049640497404984049940500405014050240503405044050540506405074050840509405104051140512405134051440515405164051740518405194052040521405224052340524405254052640527405284052940530405314053240533405344053540536405374053840539405404054140542405434054440545405464054740548405494055040551405524055340554405554055640557405584055940560405614056240563405644056540566405674056840569405704057140572405734057440575405764057740578405794058040581405824058340584405854058640587405884058940590405914059240593405944059540596405974059840599406004060140602406034060440605406064060740608406094061040611406124061340614406154061640617406184061940620406214062240623406244062540626406274062840629406304063140632406334063440635406364063740638406394064040641406424064340644406454064640647406484064940650406514065240653406544065540656406574065840659406604066140662406634066440665406664066740668406694067040671406724067340674406754067640677406784067940680406814068240683406844068540686406874068840689406904069140692406934069440695406964069740698406994070040701407024070340704407054070640707407084070940710407114071240713407144071540716407174071840719407204072140722407234072440725407264072740728407294073040731407324073340734407354073640737407384073940740407414074240743407444074540746407474074840749407504075140752407534075440755407564075740758407594076040761407624076340764407654076640767407684076940770407714077240773407744077540776407774077840779407804078140782407834078440785407864078740788407894079040791407924079340794407954079640797407984079940800408014080240803408044080540806408074080840809408104081140812408134081440815408164081740818408194082040821408224082340824408254082640827408284082940830408314083240833408344083540836408374083840839408404084140842408434084440845408464084740848408494085040851408524085340854408554085640857408584085940860408614086240863408644086540866408674086840869408704087140872408734087440875408764087740878408794088040881408824088340884408854088640887408884088940890408914089240893408944089540896408974089840899409004090140902409034090440905409064090740908409094091040911409124091340914409154091640917409184091940920409214092240923409244092540926409274092840929409304093140932409334093440935409364093740938409394094040941409424094340944409454094640947409484094940950409514095240953409544095540956409574095840959409604096140962409634096440965409664096740968409694097040971409724097340974409754097640977409784097940980409814098240983409844098540986409874098840989409904099140992409934099440995409964099740998409994100041001410024100341004410054100641007410084100941010410114101241013410144101541016410174101841019410204102141022410234102441025410264102741028410294103041031410324103341034410354103641037410384103941040410414104241043410444104541046410474104841049410504105141052410534105441055410564105741058410594106041061410624106341064410654106641067410684106941070410714107241073410744107541076410774107841079410804108141082410834108441085410864108741088410894109041091410924109341094410954109641097410984109941100411014110241103411044110541106411074110841109411104111141112411134111441115411164111741118411194112041121411224112341124411254112641127411284112941130411314113241133411344113541136411374113841139411404114141142411434114441145411464114741148411494115041151411524115341154411554115641157411584115941160411614116241163411644116541166411674116841169411704117141172411734117441175411764117741178411794118041181411824118341184411854118641187411884118941190411914119241193411944119541196411974119841199412004120141202412034120441205412064120741208412094121041211412124121341214412154121641217412184121941220412214122241223412244122541226412274122841229412304123141232412334123441235412364123741238412394124041241412424124341244412454124641247412484124941250412514125241253412544125541256412574125841259412604126141262412634126441265412664126741268412694127041271412724127341274412754127641277412784127941280412814128241283412844128541286412874128841289412904129141292412934129441295412964129741298412994130041301413024130341304413054130641307413084130941310413114131241313413144131541316413174131841319413204132141322413234132441325413264132741328413294133041331413324133341334413354133641337413384133941340413414134241343413444134541346413474134841349413504135141352413534135441355413564135741358413594136041361413624136341364413654136641367413684136941370413714137241373413744137541376413774137841379413804138141382413834138441385413864138741388413894139041391413924139341394413954139641397413984139941400414014140241403414044140541406414074140841409414104141141412414134141441415414164141741418414194142041421414224142341424414254142641427414284142941430414314143241433414344143541436414374143841439414404144141442414434144441445414464144741448414494145041451414524145341454414554145641457414584145941460414614146241463414644146541466414674146841469414704147141472414734147441475414764147741478414794148041481414824148341484414854148641487414884148941490414914149241493414944149541496414974149841499415004150141502415034150441505415064150741508415094151041511415124151341514415154151641517415184151941520415214152241523415244152541526415274152841529415304153141532415334153441535415364153741538415394154041541415424154341544415454154641547415484154941550415514155241553415544155541556415574155841559415604156141562415634156441565415664156741568415694157041571415724157341574415754157641577415784157941580415814158241583415844158541586415874158841589415904159141592415934159441595415964159741598415994160041601416024160341604416054160641607416084160941610416114161241613416144161541616416174161841619416204162141622416234162441625416264162741628416294163041631416324163341634416354163641637416384163941640416414164241643416444164541646416474164841649416504165141652416534165441655416564165741658416594166041661416624166341664416654166641667416684166941670416714167241673416744167541676416774167841679416804168141682416834168441685416864168741688416894169041691416924169341694416954169641697416984169941700417014170241703417044170541706417074170841709417104171141712417134171441715417164171741718417194172041721417224172341724417254172641727417284172941730417314173241733417344173541736417374173841739417404174141742417434174441745417464174741748417494175041751417524175341754417554175641757417584175941760417614176241763417644176541766417674176841769417704177141772417734177441775417764177741778417794178041781417824178341784417854178641787417884178941790417914179241793417944179541796417974179841799418004180141802418034180441805418064180741808418094181041811418124181341814418154181641817418184181941820418214182241823418244182541826418274182841829418304183141832418334183441835418364183741838418394184041841418424184341844418454184641847418484184941850418514185241853418544185541856418574185841859418604186141862418634186441865418664186741868418694187041871418724187341874418754187641877418784187941880418814188241883418844188541886418874188841889418904189141892418934189441895418964189741898418994190041901419024190341904419054190641907419084190941910419114191241913419144191541916419174191841919419204192141922419234192441925419264192741928419294193041931419324193341934419354193641937419384193941940419414194241943419444194541946419474194841949419504195141952419534195441955419564195741958419594196041961419624196341964419654196641967419684196941970419714197241973419744197541976419774197841979419804198141982419834198441985419864198741988419894199041991419924199341994419954199641997419984199942000420014200242003420044200542006420074200842009420104201142012420134201442015420164201742018420194202042021420224202342024420254202642027420284202942030420314203242033420344203542036420374203842039420404204142042420434204442045420464204742048420494205042051420524205342054420554205642057420584205942060420614206242063420644206542066420674206842069420704207142072420734207442075420764207742078420794208042081420824208342084420854208642087420884208942090420914209242093420944209542096420974209842099421004210142102421034210442105421064210742108421094211042111421124211342114421154211642117421184211942120421214212242123421244212542126421274212842129421304213142132421334213442135421364213742138421394214042141421424214342144421454214642147421484214942150421514215242153421544215542156421574215842159421604216142162421634216442165421664216742168421694217042171421724217342174421754217642177421784217942180421814218242183421844218542186421874218842189421904219142192421934219442195421964219742198421994220042201422024220342204422054220642207422084220942210422114221242213422144221542216422174221842219422204222142222422234222442225422264222742228422294223042231422324223342234422354223642237422384223942240422414224242243422444224542246422474224842249422504225142252422534225442255422564225742258422594226042261422624226342264422654226642267422684226942270422714227242273422744227542276422774227842279422804228142282422834228442285422864228742288422894229042291422924229342294422954229642297422984229942300423014230242303423044230542306423074230842309423104231142312423134231442315423164231742318423194232042321423224232342324423254232642327423284232942330423314233242333423344233542336423374233842339423404234142342423434234442345423464234742348423494235042351423524235342354423554235642357423584235942360423614236242363423644236542366423674236842369423704237142372423734237442375423764237742378423794238042381423824238342384423854238642387423884238942390423914239242393423944239542396423974239842399424004240142402424034240442405424064240742408424094241042411424124241342414424154241642417424184241942420424214242242423424244242542426424274242842429424304243142432424334243442435424364243742438424394244042441424424244342444424454244642447424484244942450424514245242453424544245542456424574245842459424604246142462424634246442465424664246742468424694247042471424724247342474424754247642477424784247942480424814248242483424844248542486424874248842489424904249142492424934249442495424964249742498424994250042501425024250342504425054250642507425084250942510425114251242513425144251542516425174251842519425204252142522425234252442525425264252742528425294253042531425324253342534425354253642537425384253942540425414254242543425444254542546425474254842549425504255142552425534255442555425564255742558425594256042561425624256342564425654256642567425684256942570425714257242573425744257542576425774257842579425804258142582425834258442585425864258742588425894259042591425924259342594425954259642597425984259942600426014260242603426044260542606426074260842609426104261142612426134261442615426164261742618426194262042621426224262342624426254262642627426284262942630426314263242633426344263542636426374263842639426404264142642426434264442645426464264742648426494265042651426524265342654426554265642657426584265942660426614266242663426644266542666426674266842669426704267142672426734267442675426764267742678426794268042681426824268342684426854268642687426884268942690426914269242693426944269542696426974269842699427004270142702427034270442705427064270742708427094271042711427124271342714427154271642717427184271942720427214272242723427244272542726427274272842729427304273142732427334273442735427364273742738427394274042741427424274342744427454274642747427484274942750427514275242753427544275542756427574275842759427604276142762427634276442765427664276742768427694277042771427724277342774427754277642777427784277942780427814278242783427844278542786427874278842789427904279142792427934279442795427964279742798427994280042801428024280342804428054280642807428084280942810428114281242813428144281542816428174281842819428204282142822428234282442825428264282742828428294283042831428324283342834428354283642837428384283942840428414284242843428444284542846428474284842849428504285142852428534285442855428564285742858428594286042861428624286342864428654286642867428684286942870428714287242873428744287542876428774287842879428804288142882428834288442885428864288742888428894289042891428924289342894428954289642897428984289942900429014290242903429044290542906429074290842909429104291142912429134291442915429164291742918429194292042921429224292342924429254292642927429284292942930429314293242933429344293542936429374293842939429404294142942429434294442945429464294742948429494295042951429524295342954429554295642957429584295942960429614296242963429644296542966429674296842969429704297142972429734297442975429764297742978429794298042981429824298342984429854298642987429884298942990429914299242993429944299542996429974299842999430004300143002430034300443005430064300743008430094301043011430124301343014430154301643017430184301943020430214302243023430244302543026430274302843029430304303143032430334303443035430364303743038430394304043041430424304343044430454304643047430484304943050430514305243053430544305543056430574305843059430604306143062430634306443065430664306743068430694307043071430724307343074430754307643077430784307943080430814308243083430844308543086430874308843089430904309143092430934309443095430964309743098430994310043101431024310343104431054310643107431084310943110431114311243113431144311543116431174311843119431204312143122431234312443125431264312743128431294313043131431324313343134431354313643137431384313943140431414314243143431444314543146431474314843149431504315143152431534315443155431564315743158431594316043161431624316343164431654316643167431684316943170431714317243173431744317543176431774317843179431804318143182431834318443185431864318743188431894319043191431924319343194431954319643197431984319943200432014320243203432044320543206432074320843209432104321143212432134321443215432164321743218432194322043221432224322343224432254322643227432284322943230432314323243233432344323543236432374323843239432404324143242432434324443245432464324743248432494325043251432524325343254432554325643257432584325943260432614326243263432644326543266432674326843269432704327143272432734327443275432764327743278432794328043281432824328343284432854328643287432884328943290432914329243293432944329543296432974329843299433004330143302433034330443305433064330743308433094331043311433124331343314433154331643317433184331943320433214332243323433244332543326433274332843329433304333143332433334333443335433364333743338433394334043341433424334343344433454334643347433484334943350433514335243353433544335543356433574335843359433604336143362433634336443365433664336743368433694337043371433724337343374433754337643377433784337943380433814338243383433844338543386433874338843389433904339143392433934339443395433964339743398433994340043401434024340343404434054340643407434084340943410434114341243413434144341543416434174341843419434204342143422434234342443425434264342743428434294343043431434324343343434434354343643437434384343943440434414344243443434444344543446434474344843449434504345143452434534345443455434564345743458434594346043461434624346343464434654346643467434684346943470434714347243473434744347543476434774347843479434804348143482434834348443485434864348743488434894349043491434924349343494434954349643497434984349943500435014350243503435044350543506435074350843509435104351143512435134351443515435164351743518435194352043521435224352343524435254352643527435284352943530435314353243533435344353543536435374353843539435404354143542435434354443545435464354743548435494355043551435524355343554435554355643557435584355943560435614356243563435644356543566435674356843569435704357143572435734357443575435764357743578435794358043581435824358343584435854358643587435884358943590435914359243593435944359543596435974359843599436004360143602436034360443605436064360743608436094361043611436124361343614436154361643617436184361943620436214362243623436244362543626436274362843629436304363143632436334363443635436364363743638436394364043641436424364343644436454364643647436484364943650436514365243653436544365543656436574365843659436604366143662436634366443665436664366743668436694367043671436724367343674436754367643677436784367943680436814368243683436844368543686436874368843689436904369143692436934369443695436964369743698436994370043701437024370343704437054370643707437084370943710437114371243713437144371543716437174371843719437204372143722437234372443725437264372743728437294373043731437324373343734437354373643737437384373943740437414374243743437444374543746437474374843749437504375143752437534375443755437564375743758437594376043761437624376343764437654376643767437684376943770437714377243773437744377543776437774377843779437804378143782437834378443785437864378743788437894379043791437924379343794437954379643797437984379943800438014380243803438044380543806438074380843809438104381143812438134381443815438164381743818438194382043821438224382343824438254382643827438284382943830438314383243833438344383543836438374383843839438404384143842438434384443845438464384743848438494385043851438524385343854438554385643857438584385943860438614386243863438644386543866438674386843869438704387143872438734387443875438764387743878438794388043881438824388343884438854388643887438884388943890438914389243893438944389543896438974389843899439004390143902439034390443905439064390743908439094391043911439124391343914439154391643917439184391943920439214392243923439244392543926439274392843929439304393143932439334393443935439364393743938439394394043941439424394343944439454394643947439484394943950439514395243953439544395543956439574395843959439604396143962439634396443965439664396743968439694397043971439724397343974439754397643977439784397943980439814398243983439844398543986439874398843989439904399143992439934399443995439964399743998439994400044001440024400344004440054400644007440084400944010440114401244013440144401544016440174401844019440204402144022440234402444025440264402744028440294403044031440324403344034440354403644037440384403944040440414404244043440444404544046440474404844049440504405144052440534405444055440564405744058440594406044061440624406344064440654406644067440684406944070440714407244073440744407544076440774407844079440804408144082440834408444085440864408744088440894409044091440924409344094440954409644097440984409944100441014410244103441044410544106441074410844109441104411144112441134411444115441164411744118441194412044121441224412344124441254412644127441284412944130441314413244133441344413544136441374413844139441404414144142441434414444145441464414744148441494415044151441524415344154441554415644157441584415944160441614416244163441644416544166441674416844169441704417144172441734417444175441764417744178441794418044181441824418344184441854418644187441884418944190441914419244193441944419544196441974419844199442004420144202442034420444205442064420744208442094421044211442124421344214442154421644217442184421944220442214422244223442244422544226442274422844229442304423144232442334423444235442364423744238442394424044241442424424344244442454424644247442484424944250442514425244253442544425544256442574425844259442604426144262442634426444265442664426744268442694427044271442724427344274442754427644277442784427944280442814428244283442844428544286442874428844289442904429144292442934429444295442964429744298442994430044301443024430344304443054430644307443084430944310443114431244313443144431544316443174431844319443204432144322443234432444325443264432744328443294433044331443324433344334443354433644337443384433944340443414434244343443444434544346443474434844349443504435144352443534435444355443564435744358443594436044361443624436344364443654436644367443684436944370443714437244373443744437544376443774437844379443804438144382443834438444385443864438744388443894439044391443924439344394443954439644397443984439944400444014440244403444044440544406444074440844409444104441144412444134441444415444164441744418444194442044421444224442344424444254442644427444284442944430444314443244433444344443544436444374443844439444404444144442444434444444445444464444744448444494445044451444524445344454444554445644457444584445944460444614446244463444644446544466444674446844469444704447144472444734447444475444764447744478444794448044481444824448344484444854448644487444884448944490444914449244493444944449544496444974449844499445004450144502445034450444505445064450744508445094451044511445124451344514445154451644517445184451944520445214452244523445244452544526445274452844529445304453144532445334453444535445364453744538445394454044541445424454344544445454454644547445484454944550445514455244553445544455544556445574455844559445604456144562445634456444565445664456744568445694457044571445724457344574445754457644577445784457944580445814458244583445844458544586445874458844589445904459144592445934459444595445964459744598445994460044601446024460344604446054460644607446084460944610446114461244613446144461544616446174461844619446204462144622446234462444625446264462744628446294463044631446324463344634446354463644637446384463944640446414464244643446444464544646446474464844649446504465144652446534465444655446564465744658446594466044661446624466344664446654466644667446684466944670446714467244673446744467544676446774467844679446804468144682446834468444685446864468744688446894469044691446924469344694446954469644697446984469944700447014470244703447044470544706447074470844709447104471144712447134471444715447164471744718447194472044721447224472344724447254472644727447284472944730447314473244733447344473544736447374473844739447404474144742447434474444745447464474744748447494475044751447524475344754447554475644757447584475944760447614476244763447644476544766447674476844769447704477144772447734477444775447764477744778447794478044781447824478344784447854478644787447884478944790447914479244793447944479544796447974479844799448004480144802448034480444805448064480744808448094481044811448124481344814448154481644817448184481944820448214482244823448244482544826448274482844829448304483144832448334483444835448364483744838448394484044841448424484344844448454484644847448484484944850448514485244853448544485544856448574485844859448604486144862448634486444865448664486744868448694487044871448724487344874448754487644877448784487944880448814488244883448844488544886448874488844889448904489144892448934489444895448964489744898448994490044901449024490344904449054490644907449084490944910449114491244913449144491544916449174491844919449204492144922449234492444925449264492744928449294493044931449324493344934449354493644937449384493944940449414494244943449444494544946449474494844949449504495144952449534495444955449564495744958449594496044961449624496344964449654496644967449684496944970449714497244973449744497544976449774497844979449804498144982449834498444985449864498744988449894499044991449924499344994449954499644997449984499945000450014500245003450044500545006450074500845009450104501145012450134501445015450164501745018450194502045021450224502345024450254502645027450284502945030450314503245033450344503545036450374503845039450404504145042450434504445045450464504745048450494505045051450524505345054450554505645057450584505945060450614506245063450644506545066450674506845069450704507145072450734507445075450764507745078450794508045081450824508345084450854508645087450884508945090450914509245093450944509545096450974509845099451004510145102451034510445105451064510745108451094511045111451124511345114451154511645117451184511945120451214512245123451244512545126451274512845129451304513145132451334513445135451364513745138451394514045141451424514345144451454514645147451484514945150451514515245153451544515545156451574515845159451604516145162451634516445165451664516745168451694517045171451724517345174451754517645177451784517945180451814518245183451844518545186451874518845189451904519145192451934519445195451964519745198451994520045201452024520345204452054520645207452084520945210452114521245213452144521545216452174521845219452204522145222452234522445225452264522745228452294523045231452324523345234452354523645237452384523945240452414524245243452444524545246452474524845249452504525145252452534525445255452564525745258452594526045261452624526345264452654526645267452684526945270452714527245273452744527545276452774527845279452804528145282452834528445285452864528745288452894529045291452924529345294452954529645297452984529945300453014530245303453044530545306453074530845309453104531145312453134531445315453164531745318453194532045321453224532345324453254532645327453284532945330453314533245333453344533545336453374533845339453404534145342453434534445345453464534745348453494535045351453524535345354453554535645357453584535945360453614536245363453644536545366453674536845369453704537145372453734537445375453764537745378453794538045381453824538345384453854538645387453884538945390453914539245393453944539545396453974539845399454004540145402454034540445405454064540745408454094541045411454124541345414454154541645417454184541945420454214542245423454244542545426454274542845429454304543145432454334543445435454364543745438454394544045441454424544345444454454544645447454484544945450454514545245453454544545545456454574545845459454604546145462454634546445465454664546745468454694547045471454724547345474454754547645477454784547945480454814548245483454844548545486454874548845489454904549145492454934549445495454964549745498454994550045501455024550345504455054550645507455084550945510455114551245513455144551545516455174551845519455204552145522455234552445525455264552745528455294553045531455324553345534455354553645537455384553945540455414554245543455444554545546455474554845549455504555145552455534555445555455564555745558455594556045561455624556345564455654556645567455684556945570455714557245573455744557545576455774557845579455804558145582455834558445585455864558745588455894559045591455924559345594455954559645597455984559945600456014560245603456044560545606456074560845609456104561145612456134561445615456164561745618456194562045621456224562345624456254562645627456284562945630456314563245633456344563545636456374563845639456404564145642456434564445645456464564745648456494565045651456524565345654456554565645657456584565945660456614566245663456644566545666456674566845669456704567145672456734567445675456764567745678456794568045681456824568345684456854568645687456884568945690456914569245693456944569545696456974569845699457004570145702457034570445705457064570745708457094571045711457124571345714457154571645717457184571945720457214572245723457244572545726457274572845729457304573145732457334573445735457364573745738457394574045741457424574345744457454574645747457484574945750457514575245753457544575545756457574575845759457604576145762457634576445765457664576745768457694577045771457724577345774457754577645777457784577945780457814578245783457844578545786457874578845789457904579145792457934579445795457964579745798457994580045801458024580345804458054580645807458084580945810458114581245813458144581545816458174581845819458204582145822458234582445825458264582745828458294583045831458324583345834458354583645837458384583945840458414584245843458444584545846458474584845849458504585145852458534585445855458564585745858458594586045861458624586345864458654586645867458684586945870458714587245873458744587545876458774587845879458804588145882458834588445885458864588745888458894589045891458924589345894458954589645897458984589945900459014590245903459044590545906459074590845909459104591145912459134591445915459164591745918459194592045921459224592345924459254592645927459284592945930459314593245933459344593545936459374593845939459404594145942459434594445945459464594745948459494595045951459524595345954459554595645957459584595945960459614596245963459644596545966459674596845969459704597145972459734597445975459764597745978459794598045981459824598345984459854598645987459884598945990459914599245993459944599545996459974599845999460004600146002460034600446005460064600746008460094601046011460124601346014460154601646017460184601946020460214602246023460244602546026460274602846029460304603146032460334603446035460364603746038460394604046041460424604346044460454604646047460484604946050460514605246053460544605546056460574605846059460604606146062460634606446065460664606746068460694607046071460724607346074460754607646077460784607946080460814608246083460844608546086460874608846089460904609146092460934609446095460964609746098460994610046101461024610346104461054610646107461084610946110461114611246113461144611546116461174611846119461204612146122461234612446125461264612746128461294613046131461324613346134461354613646137461384613946140461414614246143461444614546146461474614846149461504615146152461534615446155461564615746158461594616046161461624616346164461654616646167461684616946170461714617246173461744617546176461774617846179461804618146182461834618446185461864618746188461894619046191461924619346194461954619646197461984619946200462014620246203462044620546206462074620846209462104621146212462134621446215462164621746218462194622046221462224622346224462254622646227462284622946230462314623246233462344623546236462374623846239462404624146242462434624446245462464624746248462494625046251462524625346254462554625646257462584625946260462614626246263462644626546266462674626846269462704627146272462734627446275462764627746278462794628046281462824628346284462854628646287462884628946290462914629246293462944629546296462974629846299463004630146302463034630446305463064630746308463094631046311463124631346314463154631646317463184631946320463214632246323463244632546326463274632846329463304633146332463334633446335463364633746338463394634046341463424634346344463454634646347463484634946350463514635246353463544635546356463574635846359463604636146362463634636446365463664636746368463694637046371463724637346374463754637646377463784637946380463814638246383463844638546386463874638846389463904639146392463934639446395463964639746398463994640046401464024640346404464054640646407464084640946410464114641246413464144641546416464174641846419464204642146422464234642446425464264642746428464294643046431464324643346434464354643646437464384643946440464414644246443464444644546446464474644846449464504645146452464534645446455464564645746458464594646046461464624646346464464654646646467464684646946470464714647246473464744647546476464774647846479464804648146482464834648446485464864648746488464894649046491464924649346494464954649646497464984649946500465014650246503465044650546506465074650846509465104651146512465134651446515465164651746518465194652046521465224652346524465254652646527465284652946530465314653246533465344653546536465374653846539465404654146542465434654446545465464654746548465494655046551465524655346554465554655646557465584655946560465614656246563465644656546566465674656846569465704657146572465734657446575465764657746578465794658046581465824658346584465854658646587465884658946590465914659246593465944659546596465974659846599466004660146602466034660446605466064660746608466094661046611466124661346614466154661646617466184661946620466214662246623466244662546626466274662846629466304663146632466334663446635466364663746638466394664046641466424664346644466454664646647466484664946650466514665246653466544665546656466574665846659466604666146662466634666446665466664666746668466694667046671466724667346674466754667646677466784667946680466814668246683466844668546686466874668846689466904669146692466934669446695466964669746698466994670046701467024670346704467054670646707467084670946710467114671246713467144671546716467174671846719467204672146722467234672446725467264672746728467294673046731467324673346734467354673646737467384673946740467414674246743467444674546746467474674846749467504675146752467534675446755467564675746758467594676046761467624676346764467654676646767467684676946770467714677246773467744677546776467774677846779467804678146782467834678446785467864678746788467894679046791467924679346794467954679646797467984679946800468014680246803468044680546806468074680846809468104681146812468134681446815468164681746818468194682046821468224682346824468254682646827468284682946830468314683246833468344683546836468374683846839468404684146842468434684446845468464684746848468494685046851468524685346854468554685646857468584685946860468614686246863468644686546866468674686846869468704687146872468734687446875468764687746878468794688046881468824688346884468854688646887468884688946890468914689246893468944689546896468974689846899469004690146902469034690446905469064690746908469094691046911469124691346914469154691646917469184691946920469214692246923469244692546926469274692846929469304693146932469334693446935469364693746938469394694046941469424694346944469454694646947469484694946950469514695246953469544695546956469574695846959469604696146962469634696446965469664696746968469694697046971469724697346974469754697646977469784697946980469814698246983469844698546986469874698846989469904699146992469934699446995469964699746998469994700047001470024700347004470054700647007470084700947010470114701247013470144701547016470174701847019470204702147022470234702447025470264702747028470294703047031470324703347034470354703647037470384703947040470414704247043470444704547046470474704847049470504705147052470534705447055470564705747058470594706047061470624706347064470654706647067470684706947070470714707247073470744707547076470774707847079470804708147082470834708447085470864708747088470894709047091470924709347094470954709647097470984709947100471014710247103471044710547106471074710847109471104711147112471134711447115471164711747118471194712047121471224712347124471254712647127471284712947130471314713247133471344713547136471374713847139471404714147142471434714447145471464714747148471494715047151471524715347154471554715647157471584715947160471614716247163471644716547166471674716847169471704717147172471734717447175471764717747178471794718047181471824718347184471854718647187471884718947190471914719247193471944719547196471974719847199472004720147202472034720447205472064720747208472094721047211472124721347214472154721647217472184721947220472214722247223472244722547226472274722847229472304723147232472334723447235472364723747238472394724047241472424724347244472454724647247472484724947250472514725247253472544725547256472574725847259472604726147262472634726447265472664726747268472694727047271472724727347274472754727647277472784727947280472814728247283472844728547286472874728847289472904729147292472934729447295472964729747298472994730047301473024730347304473054730647307473084730947310473114731247313473144731547316473174731847319473204732147322473234732447325473264732747328473294733047331473324733347334473354733647337473384733947340473414734247343473444734547346473474734847349473504735147352473534735447355473564735747358473594736047361473624736347364473654736647367473684736947370473714737247373473744737547376473774737847379473804738147382473834738447385473864738747388473894739047391473924739347394473954739647397473984739947400474014740247403474044740547406474074740847409474104741147412474134741447415474164741747418474194742047421474224742347424474254742647427474284742947430474314743247433474344743547436474374743847439474404744147442474434744447445474464744747448474494745047451474524745347454474554745647457474584745947460474614746247463474644746547466474674746847469474704747147472474734747447475474764747747478474794748047481474824748347484474854748647487474884748947490474914749247493474944749547496474974749847499475004750147502475034750447505475064750747508475094751047511475124751347514475154751647517475184751947520475214752247523475244752547526475274752847529475304753147532475334753447535475364753747538475394754047541475424754347544475454754647547475484754947550475514755247553475544755547556475574755847559475604756147562475634756447565475664756747568475694757047571475724757347574475754757647577475784757947580475814758247583475844758547586475874758847589475904759147592475934759447595475964759747598475994760047601476024760347604476054760647607476084760947610476114761247613476144761547616476174761847619476204762147622476234762447625476264762747628476294763047631476324763347634476354763647637476384763947640476414764247643476444764547646476474764847649476504765147652476534765447655476564765747658476594766047661476624766347664476654766647667476684766947670476714767247673476744767547676476774767847679476804768147682476834768447685476864768747688476894769047691476924769347694476954769647697476984769947700477014770247703477044770547706477074770847709477104771147712477134771447715477164771747718477194772047721477224772347724477254772647727477284772947730477314773247733477344773547736477374773847739477404774147742477434774447745477464774747748477494775047751477524775347754477554775647757477584775947760477614776247763477644776547766477674776847769477704777147772477734777447775477764777747778477794778047781477824778347784477854778647787477884778947790477914779247793477944779547796477974779847799478004780147802478034780447805478064780747808478094781047811478124781347814478154781647817478184781947820478214782247823478244782547826478274782847829478304783147832478334783447835478364783747838478394784047841478424784347844478454784647847478484784947850478514785247853478544785547856478574785847859478604786147862478634786447865478664786747868478694787047871478724787347874478754787647877478784787947880478814788247883478844788547886478874788847889478904789147892478934789447895478964789747898478994790047901479024790347904479054790647907479084790947910479114791247913479144791547916479174791847919479204792147922479234792447925479264792747928479294793047931479324793347934479354793647937479384793947940479414794247943479444794547946479474794847949479504795147952479534795447955479564795747958479594796047961479624796347964479654796647967479684796947970479714797247973479744797547976479774797847979479804798147982479834798447985479864798747988479894799047991479924799347994479954799647997479984799948000480014800248003480044800548006480074800848009480104801148012480134801448015480164801748018480194802048021480224802348024480254802648027480284802948030480314803248033480344803548036480374803848039480404804148042480434804448045480464804748048480494805048051480524805348054480554805648057480584805948060480614806248063480644806548066480674806848069480704807148072480734807448075480764807748078480794808048081480824808348084480854808648087480884808948090480914809248093480944809548096480974809848099481004810148102481034810448105481064810748108481094811048111481124811348114481154811648117481184811948120481214812248123481244812548126481274812848129481304813148132481334813448135481364813748138481394814048141481424814348144481454814648147481484814948150481514815248153481544815548156481574815848159481604816148162481634816448165481664816748168481694817048171481724817348174481754817648177481784817948180481814818248183481844818548186481874818848189481904819148192481934819448195481964819748198481994820048201482024820348204482054820648207482084820948210482114821248213482144821548216482174821848219482204822148222482234822448225482264822748228482294823048231482324823348234482354823648237482384823948240482414824248243482444824548246482474824848249482504825148252482534825448255482564825748258482594826048261482624826348264482654826648267482684826948270482714827248273482744827548276482774827848279482804828148282482834828448285482864828748288482894829048291482924829348294482954829648297482984829948300483014830248303483044830548306483074830848309483104831148312483134831448315483164831748318483194832048321483224832348324483254832648327483284832948330483314833248333483344833548336483374833848339483404834148342483434834448345483464834748348483494835048351483524835348354483554835648357483584835948360483614836248363483644836548366483674836848369483704837148372483734837448375483764837748378483794838048381483824838348384483854838648387483884838948390483914839248393483944839548396483974839848399484004840148402484034840448405484064840748408484094841048411484124841348414484154841648417484184841948420484214842248423484244842548426484274842848429484304843148432484334843448435484364843748438484394844048441484424844348444484454844648447484484844948450484514845248453484544845548456484574845848459484604846148462484634846448465484664846748468484694847048471484724847348474484754847648477484784847948480484814848248483484844848548486484874848848489484904849148492484934849448495484964849748498484994850048501485024850348504485054850648507485084850948510485114851248513485144851548516485174851848519485204852148522485234852448525485264852748528485294853048531485324853348534485354853648537485384853948540485414854248543485444854548546485474854848549485504855148552485534855448555485564855748558485594856048561485624856348564485654856648567485684856948570485714857248573485744857548576485774857848579485804858148582485834858448585485864858748588485894859048591485924859348594485954859648597485984859948600486014860248603486044860548606486074860848609486104861148612486134861448615486164861748618486194862048621486224862348624486254862648627486284862948630486314863248633486344863548636486374863848639486404864148642486434864448645486464864748648486494865048651486524865348654486554865648657486584865948660486614866248663486644866548666486674866848669486704867148672486734867448675486764867748678486794868048681486824868348684486854868648687486884868948690486914869248693486944869548696486974869848699487004870148702487034870448705487064870748708487094871048711487124871348714487154871648717487184871948720487214872248723487244872548726487274872848729487304873148732487334873448735487364873748738487394874048741487424874348744487454874648747487484874948750487514875248753487544875548756487574875848759487604876148762487634876448765487664876748768487694877048771487724877348774487754877648777487784877948780487814878248783487844878548786487874878848789487904879148792487934879448795487964879748798487994880048801488024880348804488054880648807488084880948810488114881248813488144881548816488174881848819488204882148822488234882448825488264882748828488294883048831488324883348834488354883648837488384883948840488414884248843488444884548846488474884848849488504885148852488534885448855488564885748858488594886048861488624886348864488654886648867488684886948870488714887248873488744887548876488774887848879488804888148882488834888448885488864888748888488894889048891488924889348894488954889648897488984889948900489014890248903489044890548906489074890848909489104891148912489134891448915489164891748918489194892048921489224892348924489254892648927489284892948930489314893248933489344893548936489374893848939489404894148942489434894448945489464894748948489494895048951489524895348954489554895648957489584895948960489614896248963489644896548966489674896848969489704897148972489734897448975489764897748978489794898048981489824898348984489854898648987489884898948990489914899248993489944899548996489974899848999490004900149002490034900449005490064900749008490094901049011490124901349014490154901649017490184901949020490214902249023490244902549026490274902849029490304903149032490334903449035490364903749038490394904049041490424904349044490454904649047490484904949050490514905249053490544905549056490574905849059490604906149062490634906449065490664906749068490694907049071490724907349074490754907649077490784907949080490814908249083490844908549086490874908849089490904909149092490934909449095490964909749098490994910049101491024910349104491054910649107491084910949110491114911249113491144911549116491174911849119491204912149122491234912449125491264912749128491294913049131491324913349134491354913649137491384913949140491414914249143491444914549146491474914849149491504915149152491534915449155491564915749158491594916049161491624916349164491654916649167491684916949170491714917249173491744917549176491774917849179491804918149182491834918449185491864918749188491894919049191491924919349194491954919649197491984919949200492014920249203492044920549206492074920849209492104921149212492134921449215492164921749218492194922049221492224922349224492254922649227492284922949230492314923249233492344923549236492374923849239492404924149242492434924449245492464924749248492494925049251492524925349254492554925649257492584925949260492614926249263492644926549266492674926849269492704927149272492734927449275492764927749278492794928049281492824928349284492854928649287492884928949290492914929249293492944929549296492974929849299493004930149302493034930449305493064930749308493094931049311493124931349314493154931649317493184931949320493214932249323493244932549326493274932849329493304933149332493334933449335493364933749338493394934049341493424934349344493454934649347493484934949350493514935249353493544935549356493574935849359493604936149362493634936449365493664936749368493694937049371493724937349374493754937649377493784937949380493814938249383493844938549386493874938849389493904939149392493934939449395493964939749398493994940049401494024940349404494054940649407494084940949410494114941249413494144941549416494174941849419494204942149422494234942449425494264942749428494294943049431494324943349434494354943649437494384943949440494414944249443494444944549446494474944849449494504945149452494534945449455494564945749458494594946049461494624946349464494654946649467494684946949470494714947249473494744947549476494774947849479494804948149482494834948449485494864948749488494894949049491494924949349494494954949649497494984949949500495014950249503495044950549506495074950849509495104951149512495134951449515495164951749518495194952049521495224952349524495254952649527495284952949530495314953249533495344953549536495374953849539495404954149542495434954449545495464954749548495494955049551495524955349554495554955649557495584955949560495614956249563495644956549566495674956849569495704957149572495734957449575495764957749578495794958049581495824958349584495854958649587495884958949590495914959249593495944959549596495974959849599496004960149602496034960449605496064960749608496094961049611496124961349614496154961649617496184961949620496214962249623496244962549626496274962849629496304963149632496334963449635496364963749638496394964049641496424964349644496454964649647496484964949650496514965249653496544965549656496574965849659496604966149662496634966449665496664966749668496694967049671496724967349674496754967649677496784967949680496814968249683496844968549686496874968849689496904969149692496934969449695496964969749698496994970049701497024970349704497054970649707497084970949710497114971249713497144971549716497174971849719497204972149722497234972449725497264972749728497294973049731497324973349734497354973649737497384973949740497414974249743497444974549746497474974849749497504975149752497534975449755497564975749758497594976049761497624976349764497654976649767497684976949770497714977249773497744977549776497774977849779497804978149782497834978449785497864978749788497894979049791497924979349794497954979649797497984979949800498014980249803498044980549806498074980849809498104981149812498134981449815498164981749818498194982049821498224982349824498254982649827498284982949830498314983249833498344983549836498374983849839498404984149842498434984449845498464984749848498494985049851498524985349854498554985649857498584985949860498614986249863498644986549866498674986849869498704987149872498734987449875498764987749878498794988049881498824988349884498854988649887498884988949890498914989249893498944989549896498974989849899499004990149902499034990449905499064990749908499094991049911499124991349914499154991649917499184991949920499214992249923499244992549926499274992849929499304993149932499334993449935499364993749938499394994049941499424994349944499454994649947499484994949950499514995249953499544995549956499574995849959499604996149962499634996449965499664996749968499694997049971499724997349974499754997649977499784997949980499814998249983499844998549986499874998849989499904999149992499934999449995499964999749998499995000050001500025000350004500055000650007500085000950010500115001250013500145001550016500175001850019500205002150022500235002450025500265002750028500295003050031500325003350034500355003650037500385003950040500415004250043500445004550046500475004850049500505005150052500535005450055500565005750058500595006050061500625006350064500655006650067500685006950070500715007250073500745007550076500775007850079500805008150082500835008450085500865008750088500895009050091500925009350094500955009650097500985009950100501015010250103501045010550106501075010850109501105011150112501135011450115501165011750118501195012050121501225012350124501255012650127501285012950130501315013250133501345013550136501375013850139501405014150142501435014450145501465014750148501495015050151501525015350154501555015650157501585015950160501615016250163501645016550166501675016850169501705017150172501735017450175501765017750178501795018050181501825018350184501855018650187501885018950190501915019250193501945019550196501975019850199502005020150202502035020450205502065020750208502095021050211502125021350214502155021650217502185021950220502215022250223502245022550226502275022850229502305023150232502335023450235502365023750238502395024050241502425024350244502455024650247502485024950250502515025250253502545025550256502575025850259502605026150262502635026450265502665026750268502695027050271502725027350274502755027650277502785027950280502815028250283502845028550286502875028850289502905029150292502935029450295502965029750298502995030050301503025030350304503055030650307503085030950310503115031250313503145031550316503175031850319503205032150322503235032450325503265032750328503295033050331503325033350334503355033650337503385033950340503415034250343503445034550346503475034850349503505035150352503535035450355503565035750358503595036050361503625036350364503655036650367503685036950370503715037250373503745037550376503775037850379503805038150382503835038450385503865038750388503895039050391503925039350394503955039650397503985039950400504015040250403504045040550406504075040850409504105041150412504135041450415504165041750418504195042050421504225042350424504255042650427504285042950430504315043250433504345043550436504375043850439504405044150442504435044450445504465044750448504495045050451504525045350454504555045650457504585045950460504615046250463504645046550466504675046850469504705047150472504735047450475504765047750478504795048050481504825048350484504855048650487504885048950490504915049250493504945049550496504975049850499505005050150502505035050450505505065050750508505095051050511505125051350514505155051650517505185051950520505215052250523505245052550526505275052850529505305053150532505335053450535505365053750538505395054050541505425054350544505455054650547505485054950550505515055250553505545055550556505575055850559505605056150562505635056450565505665056750568505695057050571505725057350574505755057650577505785057950580505815058250583505845058550586505875058850589505905059150592505935059450595505965059750598505995060050601506025060350604506055060650607506085060950610506115061250613506145061550616506175061850619506205062150622506235062450625506265062750628506295063050631506325063350634506355063650637506385063950640506415064250643506445064550646506475064850649506505065150652506535065450655506565065750658506595066050661506625066350664506655066650667506685066950670506715067250673506745067550676506775067850679506805068150682506835068450685506865068750688506895069050691506925069350694506955069650697506985069950700507015070250703507045070550706507075070850709507105071150712507135071450715507165071750718507195072050721507225072350724507255072650727507285072950730507315073250733507345073550736507375073850739507405074150742507435074450745507465074750748507495075050751507525075350754507555075650757507585075950760507615076250763507645076550766507675076850769507705077150772507735077450775507765077750778507795078050781507825078350784507855078650787507885078950790507915079250793507945079550796507975079850799508005080150802508035080450805508065080750808508095081050811508125081350814508155081650817508185081950820508215082250823508245082550826508275082850829508305083150832508335083450835508365083750838508395084050841508425084350844508455084650847508485084950850508515085250853508545085550856508575085850859508605086150862508635086450865508665086750868508695087050871508725087350874508755087650877508785087950880508815088250883508845088550886508875088850889508905089150892508935089450895508965089750898508995090050901509025090350904509055090650907509085090950910509115091250913509145091550916509175091850919509205092150922509235092450925509265092750928509295093050931509325093350934509355093650937509385093950940509415094250943509445094550946509475094850949509505095150952509535095450955509565095750958509595096050961509625096350964509655096650967509685096950970509715097250973509745097550976509775097850979509805098150982509835098450985509865098750988509895099050991509925099350994509955099650997509985099951000510015100251003510045100551006510075100851009510105101151012510135101451015510165101751018510195102051021510225102351024510255102651027510285102951030510315103251033510345103551036510375103851039510405104151042510435104451045510465104751048510495105051051510525105351054510555105651057510585105951060510615106251063510645106551066510675106851069510705107151072510735107451075510765107751078510795108051081510825108351084510855108651087510885108951090510915109251093510945109551096510975109851099511005110151102511035110451105511065110751108511095111051111511125111351114511155111651117511185111951120511215112251123511245112551126511275112851129511305113151132511335113451135511365113751138511395114051141511425114351144511455114651147511485114951150511515115251153511545115551156511575115851159511605116151162511635116451165511665116751168511695117051171511725117351174511755117651177511785117951180511815118251183511845118551186511875118851189511905119151192511935119451195511965119751198511995120051201512025120351204512055120651207512085120951210512115121251213512145121551216512175121851219512205122151222512235122451225512265122751228512295123051231512325123351234512355123651237512385123951240512415124251243512445124551246512475124851249512505125151252512535125451255512565125751258512595126051261512625126351264512655126651267512685126951270512715127251273512745127551276512775127851279512805128151282512835128451285512865128751288512895129051291512925129351294512955129651297512985129951300513015130251303513045130551306513075130851309513105131151312513135131451315513165131751318513195132051321513225132351324513255132651327513285132951330513315133251333513345133551336513375133851339513405134151342513435134451345513465134751348513495135051351513525135351354513555135651357513585135951360513615136251363513645136551366513675136851369513705137151372513735137451375513765137751378513795138051381513825138351384513855138651387513885138951390513915139251393513945139551396513975139851399514005140151402514035140451405514065140751408514095141051411514125141351414514155141651417514185141951420514215142251423514245142551426514275142851429514305143151432514335143451435514365143751438514395144051441514425144351444514455144651447514485144951450514515145251453514545145551456514575145851459514605146151462514635146451465514665146751468514695147051471514725147351474514755147651477514785147951480514815148251483514845148551486514875148851489514905149151492514935149451495514965149751498514995150051501515025150351504515055150651507515085150951510515115151251513515145151551516515175151851519515205152151522515235152451525515265152751528515295153051531515325153351534515355153651537515385153951540515415154251543515445154551546515475154851549515505155151552515535155451555515565155751558515595156051561515625156351564515655156651567515685156951570515715157251573515745157551576515775157851579515805158151582515835158451585515865158751588515895159051591515925159351594515955159651597515985159951600516015160251603516045160551606516075160851609516105161151612516135161451615516165161751618516195162051621516225162351624516255162651627516285162951630516315163251633516345163551636516375163851639516405164151642516435164451645516465164751648516495165051651516525165351654516555165651657516585165951660516615166251663516645166551666516675166851669516705167151672516735167451675516765167751678516795168051681516825168351684516855168651687516885168951690516915169251693516945169551696516975169851699517005170151702517035170451705517065170751708517095171051711517125171351714517155171651717517185171951720517215172251723517245172551726517275172851729517305173151732517335173451735517365173751738517395174051741517425174351744517455174651747517485174951750517515175251753517545175551756517575175851759517605176151762517635176451765517665176751768517695177051771517725177351774517755177651777517785177951780517815178251783517845178551786517875178851789517905179151792517935179451795517965179751798517995180051801518025180351804518055180651807518085180951810518115181251813518145181551816518175181851819518205182151822518235182451825518265182751828518295183051831518325183351834518355183651837518385183951840518415184251843518445184551846518475184851849518505185151852518535185451855518565185751858518595186051861518625186351864518655186651867518685186951870518715187251873518745187551876518775187851879518805188151882518835188451885518865188751888518895189051891518925189351894518955189651897518985189951900519015190251903519045190551906519075190851909519105191151912519135191451915519165191751918519195192051921519225192351924519255192651927519285192951930519315193251933519345193551936519375193851939519405194151942519435194451945519465194751948519495195051951519525195351954519555195651957519585195951960519615196251963519645196551966519675196851969519705197151972519735197451975519765197751978519795198051981519825198351984519855198651987519885198951990519915199251993519945199551996519975199851999520005200152002520035200452005520065200752008520095201052011520125201352014520155201652017520185201952020520215202252023520245202552026520275202852029520305203152032520335203452035520365203752038520395204052041520425204352044520455204652047520485204952050520515205252053520545205552056520575205852059520605206152062520635206452065520665206752068520695207052071520725207352074520755207652077520785207952080520815208252083520845208552086520875208852089520905209152092520935209452095520965209752098520995210052101521025210352104521055210652107521085210952110521115211252113521145211552116521175211852119521205212152122521235212452125521265212752128521295213052131521325213352134521355213652137521385213952140521415214252143521445214552146521475214852149521505215152152521535215452155521565215752158521595216052161521625216352164521655216652167521685216952170521715217252173521745217552176521775217852179521805218152182521835218452185521865218752188521895219052191521925219352194521955219652197521985219952200522015220252203522045220552206522075220852209522105221152212522135221452215522165221752218522195222052221522225222352224522255222652227522285222952230522315223252233522345223552236522375223852239522405224152242522435224452245522465224752248522495225052251522525225352254522555225652257522585225952260522615226252263522645226552266522675226852269522705227152272522735227452275522765227752278522795228052281522825228352284522855228652287522885228952290522915229252293522945229552296522975229852299523005230152302523035230452305523065230752308523095231052311523125231352314523155231652317523185231952320523215232252323523245232552326523275232852329523305233152332523335233452335523365233752338523395234052341523425234352344523455234652347523485234952350523515235252353523545235552356523575235852359523605236152362523635236452365523665236752368523695237052371523725237352374523755237652377523785237952380523815238252383523845238552386523875238852389523905239152392523935239452395523965239752398523995240052401524025240352404524055240652407524085240952410524115241252413524145241552416524175241852419524205242152422524235242452425524265242752428524295243052431524325243352434524355243652437524385243952440524415244252443524445244552446524475244852449524505245152452524535245452455524565245752458524595246052461524625246352464524655246652467524685246952470524715247252473524745247552476524775247852479524805248152482524835248452485524865248752488524895249052491524925249352494524955249652497524985249952500525015250252503525045250552506525075250852509525105251152512525135251452515525165251752518525195252052521525225252352524525255252652527525285252952530525315253252533525345253552536525375253852539525405254152542525435254452545525465254752548525495255052551525525255352554525555255652557525585255952560525615256252563525645256552566525675256852569525705257152572525735257452575525765257752578525795258052581525825258352584525855258652587525885258952590525915259252593525945259552596525975259852599526005260152602526035260452605526065260752608526095261052611526125261352614526155261652617526185261952620526215262252623526245262552626526275262852629526305263152632526335263452635526365263752638526395264052641526425264352644526455264652647526485264952650526515265252653526545265552656526575265852659526605266152662526635266452665526665266752668526695267052671526725267352674526755267652677526785267952680526815268252683526845268552686526875268852689526905269152692526935269452695526965269752698526995270052701527025270352704527055270652707527085270952710527115271252713527145271552716527175271852719527205272152722527235272452725527265272752728527295273052731527325273352734527355273652737527385273952740527415274252743527445274552746527475274852749527505275152752527535275452755527565275752758527595276052761527625276352764527655276652767527685276952770527715277252773527745277552776527775277852779527805278152782527835278452785527865278752788527895279052791527925279352794527955279652797527985279952800528015280252803528045280552806528075280852809528105281152812528135281452815528165281752818528195282052821528225282352824528255282652827528285282952830528315283252833528345283552836528375283852839528405284152842528435284452845528465284752848528495285052851528525285352854528555285652857528585285952860528615286252863528645286552866528675286852869528705287152872528735287452875528765287752878528795288052881528825288352884528855288652887528885288952890528915289252893528945289552896528975289852899529005290152902529035290452905529065290752908529095291052911529125291352914529155291652917529185291952920529215292252923529245292552926529275292852929529305293152932529335293452935529365293752938529395294052941529425294352944529455294652947529485294952950529515295252953529545295552956529575295852959529605296152962529635296452965529665296752968529695297052971529725297352974529755297652977529785297952980529815298252983529845298552986529875298852989529905299152992529935299452995529965299752998529995300053001530025300353004530055300653007530085300953010530115301253013530145301553016530175301853019530205302153022530235302453025530265302753028530295303053031530325303353034530355303653037530385303953040530415304253043530445304553046530475304853049530505305153052530535305453055530565305753058530595306053061530625306353064530655306653067530685306953070530715307253073530745307553076530775307853079530805308153082530835308453085530865308753088530895309053091530925309353094530955309653097530985309953100531015310253103531045310553106531075310853109531105311153112531135311453115531165311753118531195312053121531225312353124531255312653127531285312953130531315313253133531345313553136531375313853139531405314153142531435314453145531465314753148531495315053151531525315353154531555315653157531585315953160531615316253163531645316553166531675316853169531705317153172531735317453175531765317753178531795318053181531825318353184531855318653187531885318953190531915319253193531945319553196531975319853199532005320153202532035320453205532065320753208532095321053211532125321353214532155321653217532185321953220532215322253223532245322553226532275322853229532305323153232532335323453235532365323753238532395324053241532425324353244532455324653247532485324953250532515325253253532545325553256532575325853259532605326153262532635326453265532665326753268532695327053271532725327353274532755327653277532785327953280532815328253283532845328553286532875328853289532905329153292532935329453295532965329753298532995330053301533025330353304533055330653307533085330953310533115331253313533145331553316533175331853319533205332153322533235332453325533265332753328533295333053331533325333353334533355333653337533385333953340533415334253343533445334553346533475334853349533505335153352533535335453355533565335753358533595336053361533625336353364533655336653367533685336953370533715337253373533745337553376533775337853379533805338153382533835338453385533865338753388533895339053391533925339353394533955339653397533985339953400534015340253403534045340553406534075340853409534105341153412534135341453415534165341753418534195342053421534225342353424534255342653427534285342953430534315343253433534345343553436534375343853439534405344153442534435344453445534465344753448534495345053451534525345353454534555345653457534585345953460534615346253463534645346553466534675346853469534705347153472534735347453475534765347753478534795348053481534825348353484534855348653487534885348953490534915349253493534945349553496534975349853499535005350153502535035350453505535065350753508535095351053511535125351353514535155351653517535185351953520535215352253523535245352553526535275352853529535305353153532535335353453535535365353753538535395354053541535425354353544535455354653547535485354953550535515355253553535545355553556535575355853559535605356153562535635356453565535665356753568535695357053571535725357353574535755357653577535785357953580535815358253583535845358553586535875358853589535905359153592535935359453595535965359753598535995360053601536025360353604536055360653607536085360953610536115361253613536145361553616536175361853619536205362153622536235362453625536265362753628536295363053631536325363353634536355363653637536385363953640536415364253643536445364553646536475364853649536505365153652536535365453655536565365753658536595366053661536625366353664536655366653667536685366953670536715367253673536745367553676536775367853679536805368153682536835368453685536865368753688536895369053691536925369353694536955369653697536985369953700537015370253703537045370553706537075370853709537105371153712537135371453715537165371753718537195372053721537225372353724537255372653727537285372953730537315373253733537345373553736537375373853739537405374153742537435374453745537465374753748537495375053751537525375353754537555375653757537585375953760537615376253763537645376553766537675376853769537705377153772537735377453775537765377753778537795378053781537825378353784537855378653787537885378953790537915379253793537945379553796537975379853799538005380153802538035380453805538065380753808538095381053811538125381353814538155381653817
  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. (function (root, factory) {
  16. 'use strict';
  17. if (typeof define === 'function' && define.amd) {
  18. define('pdfjs-dist/build/pdf.worker', ['exports'], factory);
  19. } else if (typeof exports !== 'undefined') {
  20. factory(exports);
  21. } else {
  22. factory(root['pdfjsDistBuildPdfWorker'] = {});
  23. }
  24. }(this, function (exports) {
  25. // Use strict in our context only - users might not want it
  26. 'use strict';
  27. var pdfjsVersion = '1.6.250';
  28. var pdfjsBuild = '960e344';
  29. var pdfjsFilePath = typeof document !== 'undefined' && document.currentScript ? document.currentScript.src : null;
  30. var pdfjsLibs = {};
  31. (function pdfjsWrapper() {
  32. (function (root, factory) {
  33. factory(root.pdfjsCoreArithmeticDecoder = {});
  34. }(this, function (exports) {
  35. /* This class implements the QM Coder decoding as defined in
  36. * JPEG 2000 Part I Final Committee Draft Version 1.0
  37. * Annex C.3 Arithmetic decoding procedure
  38. * available at http://www.jpeg.org/public/fcd15444-1.pdf
  39. *
  40. * The arithmetic decoder is used in conjunction with context models to decode
  41. * JPEG2000 and JBIG2 streams.
  42. */
  43. var ArithmeticDecoder = function ArithmeticDecoderClosure() {
  44. // Table C-2
  45. var QeTable = [
  46. {
  47. qe: 0x5601,
  48. nmps: 1,
  49. nlps: 1,
  50. switchFlag: 1
  51. },
  52. {
  53. qe: 0x3401,
  54. nmps: 2,
  55. nlps: 6,
  56. switchFlag: 0
  57. },
  58. {
  59. qe: 0x1801,
  60. nmps: 3,
  61. nlps: 9,
  62. switchFlag: 0
  63. },
  64. {
  65. qe: 0x0AC1,
  66. nmps: 4,
  67. nlps: 12,
  68. switchFlag: 0
  69. },
  70. {
  71. qe: 0x0521,
  72. nmps: 5,
  73. nlps: 29,
  74. switchFlag: 0
  75. },
  76. {
  77. qe: 0x0221,
  78. nmps: 38,
  79. nlps: 33,
  80. switchFlag: 0
  81. },
  82. {
  83. qe: 0x5601,
  84. nmps: 7,
  85. nlps: 6,
  86. switchFlag: 1
  87. },
  88. {
  89. qe: 0x5401,
  90. nmps: 8,
  91. nlps: 14,
  92. switchFlag: 0
  93. },
  94. {
  95. qe: 0x4801,
  96. nmps: 9,
  97. nlps: 14,
  98. switchFlag: 0
  99. },
  100. {
  101. qe: 0x3801,
  102. nmps: 10,
  103. nlps: 14,
  104. switchFlag: 0
  105. },
  106. {
  107. qe: 0x3001,
  108. nmps: 11,
  109. nlps: 17,
  110. switchFlag: 0
  111. },
  112. {
  113. qe: 0x2401,
  114. nmps: 12,
  115. nlps: 18,
  116. switchFlag: 0
  117. },
  118. {
  119. qe: 0x1C01,
  120. nmps: 13,
  121. nlps: 20,
  122. switchFlag: 0
  123. },
  124. {
  125. qe: 0x1601,
  126. nmps: 29,
  127. nlps: 21,
  128. switchFlag: 0
  129. },
  130. {
  131. qe: 0x5601,
  132. nmps: 15,
  133. nlps: 14,
  134. switchFlag: 1
  135. },
  136. {
  137. qe: 0x5401,
  138. nmps: 16,
  139. nlps: 14,
  140. switchFlag: 0
  141. },
  142. {
  143. qe: 0x5101,
  144. nmps: 17,
  145. nlps: 15,
  146. switchFlag: 0
  147. },
  148. {
  149. qe: 0x4801,
  150. nmps: 18,
  151. nlps: 16,
  152. switchFlag: 0
  153. },
  154. {
  155. qe: 0x3801,
  156. nmps: 19,
  157. nlps: 17,
  158. switchFlag: 0
  159. },
  160. {
  161. qe: 0x3401,
  162. nmps: 20,
  163. nlps: 18,
  164. switchFlag: 0
  165. },
  166. {
  167. qe: 0x3001,
  168. nmps: 21,
  169. nlps: 19,
  170. switchFlag: 0
  171. },
  172. {
  173. qe: 0x2801,
  174. nmps: 22,
  175. nlps: 19,
  176. switchFlag: 0
  177. },
  178. {
  179. qe: 0x2401,
  180. nmps: 23,
  181. nlps: 20,
  182. switchFlag: 0
  183. },
  184. {
  185. qe: 0x2201,
  186. nmps: 24,
  187. nlps: 21,
  188. switchFlag: 0
  189. },
  190. {
  191. qe: 0x1C01,
  192. nmps: 25,
  193. nlps: 22,
  194. switchFlag: 0
  195. },
  196. {
  197. qe: 0x1801,
  198. nmps: 26,
  199. nlps: 23,
  200. switchFlag: 0
  201. },
  202. {
  203. qe: 0x1601,
  204. nmps: 27,
  205. nlps: 24,
  206. switchFlag: 0
  207. },
  208. {
  209. qe: 0x1401,
  210. nmps: 28,
  211. nlps: 25,
  212. switchFlag: 0
  213. },
  214. {
  215. qe: 0x1201,
  216. nmps: 29,
  217. nlps: 26,
  218. switchFlag: 0
  219. },
  220. {
  221. qe: 0x1101,
  222. nmps: 30,
  223. nlps: 27,
  224. switchFlag: 0
  225. },
  226. {
  227. qe: 0x0AC1,
  228. nmps: 31,
  229. nlps: 28,
  230. switchFlag: 0
  231. },
  232. {
  233. qe: 0x09C1,
  234. nmps: 32,
  235. nlps: 29,
  236. switchFlag: 0
  237. },
  238. {
  239. qe: 0x08A1,
  240. nmps: 33,
  241. nlps: 30,
  242. switchFlag: 0
  243. },
  244. {
  245. qe: 0x0521,
  246. nmps: 34,
  247. nlps: 31,
  248. switchFlag: 0
  249. },
  250. {
  251. qe: 0x0441,
  252. nmps: 35,
  253. nlps: 32,
  254. switchFlag: 0
  255. },
  256. {
  257. qe: 0x02A1,
  258. nmps: 36,
  259. nlps: 33,
  260. switchFlag: 0
  261. },
  262. {
  263. qe: 0x0221,
  264. nmps: 37,
  265. nlps: 34,
  266. switchFlag: 0
  267. },
  268. {
  269. qe: 0x0141,
  270. nmps: 38,
  271. nlps: 35,
  272. switchFlag: 0
  273. },
  274. {
  275. qe: 0x0111,
  276. nmps: 39,
  277. nlps: 36,
  278. switchFlag: 0
  279. },
  280. {
  281. qe: 0x0085,
  282. nmps: 40,
  283. nlps: 37,
  284. switchFlag: 0
  285. },
  286. {
  287. qe: 0x0049,
  288. nmps: 41,
  289. nlps: 38,
  290. switchFlag: 0
  291. },
  292. {
  293. qe: 0x0025,
  294. nmps: 42,
  295. nlps: 39,
  296. switchFlag: 0
  297. },
  298. {
  299. qe: 0x0015,
  300. nmps: 43,
  301. nlps: 40,
  302. switchFlag: 0
  303. },
  304. {
  305. qe: 0x0009,
  306. nmps: 44,
  307. nlps: 41,
  308. switchFlag: 0
  309. },
  310. {
  311. qe: 0x0005,
  312. nmps: 45,
  313. nlps: 42,
  314. switchFlag: 0
  315. },
  316. {
  317. qe: 0x0001,
  318. nmps: 45,
  319. nlps: 43,
  320. switchFlag: 0
  321. },
  322. {
  323. qe: 0x5601,
  324. nmps: 46,
  325. nlps: 46,
  326. switchFlag: 0
  327. }
  328. ];
  329. // C.3.5 Initialisation of the decoder (INITDEC)
  330. function ArithmeticDecoder(data, start, end) {
  331. this.data = data;
  332. this.bp = start;
  333. this.dataEnd = end;
  334. this.chigh = data[start];
  335. this.clow = 0;
  336. this.byteIn();
  337. this.chigh = this.chigh << 7 & 0xFFFF | this.clow >> 9 & 0x7F;
  338. this.clow = this.clow << 7 & 0xFFFF;
  339. this.ct -= 7;
  340. this.a = 0x8000;
  341. }
  342. ArithmeticDecoder.prototype = {
  343. // C.3.4 Compressed data input (BYTEIN)
  344. byteIn: function ArithmeticDecoder_byteIn() {
  345. var data = this.data;
  346. var bp = this.bp;
  347. if (data[bp] === 0xFF) {
  348. var b1 = data[bp + 1];
  349. if (b1 > 0x8F) {
  350. this.clow += 0xFF00;
  351. this.ct = 8;
  352. } else {
  353. bp++;
  354. this.clow += data[bp] << 9;
  355. this.ct = 7;
  356. this.bp = bp;
  357. }
  358. } else {
  359. bp++;
  360. this.clow += bp < this.dataEnd ? data[bp] << 8 : 0xFF00;
  361. this.ct = 8;
  362. this.bp = bp;
  363. }
  364. if (this.clow > 0xFFFF) {
  365. this.chigh += this.clow >> 16;
  366. this.clow &= 0xFFFF;
  367. }
  368. },
  369. // C.3.2 Decoding a decision (DECODE)
  370. readBit: function ArithmeticDecoder_readBit(contexts, pos) {
  371. // contexts are packed into 1 byte:
  372. // highest 7 bits carry cx.index, lowest bit carries cx.mps
  373. var cx_index = contexts[pos] >> 1, cx_mps = contexts[pos] & 1;
  374. var qeTableIcx = QeTable[cx_index];
  375. var qeIcx = qeTableIcx.qe;
  376. var d;
  377. var a = this.a - qeIcx;
  378. if (this.chigh < qeIcx) {
  379. // exchangeLps
  380. if (a < qeIcx) {
  381. a = qeIcx;
  382. d = cx_mps;
  383. cx_index = qeTableIcx.nmps;
  384. } else {
  385. a = qeIcx;
  386. d = 1 ^ cx_mps;
  387. if (qeTableIcx.switchFlag === 1) {
  388. cx_mps = d;
  389. }
  390. cx_index = qeTableIcx.nlps;
  391. }
  392. } else {
  393. this.chigh -= qeIcx;
  394. if ((a & 0x8000) !== 0) {
  395. this.a = a;
  396. return cx_mps;
  397. }
  398. // exchangeMps
  399. if (a < qeIcx) {
  400. d = 1 ^ cx_mps;
  401. if (qeTableIcx.switchFlag === 1) {
  402. cx_mps = d;
  403. }
  404. cx_index = qeTableIcx.nlps;
  405. } else {
  406. d = cx_mps;
  407. cx_index = qeTableIcx.nmps;
  408. }
  409. }
  410. // C.3.3 renormD;
  411. do {
  412. if (this.ct === 0) {
  413. this.byteIn();
  414. }
  415. a <<= 1;
  416. this.chigh = this.chigh << 1 & 0xFFFF | this.clow >> 15 & 1;
  417. this.clow = this.clow << 1 & 0xFFFF;
  418. this.ct--;
  419. } while ((a & 0x8000) === 0);
  420. this.a = a;
  421. contexts[pos] = cx_index << 1 | cx_mps;
  422. return d;
  423. }
  424. };
  425. return ArithmeticDecoder;
  426. }();
  427. exports.ArithmeticDecoder = ArithmeticDecoder;
  428. }));
  429. (function (root, factory) {
  430. factory(root.pdfjsCoreBidi = {});
  431. }(this, function (exports) {
  432. // Character types for symbols from 0000 to 00FF.
  433. var baseTypes = [
  434. 'BN',
  435. 'BN',
  436. 'BN',
  437. 'BN',
  438. 'BN',
  439. 'BN',
  440. 'BN',
  441. 'BN',
  442. 'BN',
  443. 'S',
  444. 'B',
  445. 'S',
  446. 'WS',
  447. 'B',
  448. 'BN',
  449. 'BN',
  450. 'BN',
  451. 'BN',
  452. 'BN',
  453. 'BN',
  454. 'BN',
  455. 'BN',
  456. 'BN',
  457. 'BN',
  458. 'BN',
  459. 'BN',
  460. 'BN',
  461. 'BN',
  462. 'B',
  463. 'B',
  464. 'B',
  465. 'S',
  466. 'WS',
  467. 'ON',
  468. 'ON',
  469. 'ET',
  470. 'ET',
  471. 'ET',
  472. 'ON',
  473. 'ON',
  474. 'ON',
  475. 'ON',
  476. 'ON',
  477. 'ON',
  478. 'CS',
  479. 'ON',
  480. 'CS',
  481. 'ON',
  482. 'EN',
  483. 'EN',
  484. 'EN',
  485. 'EN',
  486. 'EN',
  487. 'EN',
  488. 'EN',
  489. 'EN',
  490. 'EN',
  491. 'EN',
  492. 'ON',
  493. 'ON',
  494. 'ON',
  495. 'ON',
  496. 'ON',
  497. 'ON',
  498. 'ON',
  499. 'L',
  500. 'L',
  501. 'L',
  502. 'L',
  503. 'L',
  504. 'L',
  505. 'L',
  506. 'L',
  507. 'L',
  508. 'L',
  509. 'L',
  510. 'L',
  511. 'L',
  512. 'L',
  513. 'L',
  514. 'L',
  515. 'L',
  516. 'L',
  517. 'L',
  518. 'L',
  519. 'L',
  520. 'L',
  521. 'L',
  522. 'L',
  523. 'L',
  524. 'L',
  525. 'ON',
  526. 'ON',
  527. 'ON',
  528. 'ON',
  529. 'ON',
  530. 'ON',
  531. 'L',
  532. 'L',
  533. 'L',
  534. 'L',
  535. 'L',
  536. 'L',
  537. 'L',
  538. 'L',
  539. 'L',
  540. 'L',
  541. 'L',
  542. 'L',
  543. 'L',
  544. 'L',
  545. 'L',
  546. 'L',
  547. 'L',
  548. 'L',
  549. 'L',
  550. 'L',
  551. 'L',
  552. 'L',
  553. 'L',
  554. 'L',
  555. 'L',
  556. 'L',
  557. 'ON',
  558. 'ON',
  559. 'ON',
  560. 'ON',
  561. 'BN',
  562. 'BN',
  563. 'BN',
  564. 'BN',
  565. 'BN',
  566. 'BN',
  567. 'B',
  568. 'BN',
  569. 'BN',
  570. 'BN',
  571. 'BN',
  572. 'BN',
  573. 'BN',
  574. 'BN',
  575. 'BN',
  576. 'BN',
  577. 'BN',
  578. 'BN',
  579. 'BN',
  580. 'BN',
  581. 'BN',
  582. 'BN',
  583. 'BN',
  584. 'BN',
  585. 'BN',
  586. 'BN',
  587. 'BN',
  588. 'BN',
  589. 'BN',
  590. 'BN',
  591. 'BN',
  592. 'BN',
  593. 'BN',
  594. 'CS',
  595. 'ON',
  596. 'ET',
  597. 'ET',
  598. 'ET',
  599. 'ET',
  600. 'ON',
  601. 'ON',
  602. 'ON',
  603. 'ON',
  604. 'L',
  605. 'ON',
  606. 'ON',
  607. 'ON',
  608. 'ON',
  609. 'ON',
  610. 'ET',
  611. 'ET',
  612. 'EN',
  613. 'EN',
  614. 'ON',
  615. 'L',
  616. 'ON',
  617. 'ON',
  618. 'ON',
  619. 'EN',
  620. 'L',
  621. 'ON',
  622. 'ON',
  623. 'ON',
  624. 'ON',
  625. 'ON',
  626. 'L',
  627. 'L',
  628. 'L',
  629. 'L',
  630. 'L',
  631. 'L',
  632. 'L',
  633. 'L',
  634. 'L',
  635. 'L',
  636. 'L',
  637. 'L',
  638. 'L',
  639. 'L',
  640. 'L',
  641. 'L',
  642. 'L',
  643. 'L',
  644. 'L',
  645. 'L',
  646. 'L',
  647. 'L',
  648. 'L',
  649. 'ON',
  650. 'L',
  651. 'L',
  652. 'L',
  653. 'L',
  654. 'L',
  655. 'L',
  656. 'L',
  657. 'L',
  658. 'L',
  659. 'L',
  660. 'L',
  661. 'L',
  662. 'L',
  663. 'L',
  664. 'L',
  665. 'L',
  666. 'L',
  667. 'L',
  668. 'L',
  669. 'L',
  670. 'L',
  671. 'L',
  672. 'L',
  673. 'L',
  674. 'L',
  675. 'L',
  676. 'L',
  677. 'L',
  678. 'L',
  679. 'L',
  680. 'L',
  681. 'ON',
  682. 'L',
  683. 'L',
  684. 'L',
  685. 'L',
  686. 'L',
  687. 'L',
  688. 'L',
  689. 'L'
  690. ];
  691. // Character types for symbols from 0600 to 06FF
  692. var arabicTypes = [
  693. 'AL',
  694. 'AL',
  695. 'AL',
  696. 'AL',
  697. 'AL',
  698. 'AL',
  699. 'AL',
  700. 'AL',
  701. 'AL',
  702. 'AL',
  703. 'AL',
  704. 'AL',
  705. 'CS',
  706. 'AL',
  707. 'ON',
  708. 'ON',
  709. 'NSM',
  710. 'NSM',
  711. 'NSM',
  712. 'NSM',
  713. 'NSM',
  714. 'NSM',
  715. 'AL',
  716. 'AL',
  717. 'AL',
  718. 'AL',
  719. 'AL',
  720. 'AL',
  721. 'AL',
  722. 'AL',
  723. 'AL',
  724. 'AL',
  725. 'AL',
  726. 'AL',
  727. 'AL',
  728. 'AL',
  729. 'AL',
  730. 'AL',
  731. 'AL',
  732. 'AL',
  733. 'AL',
  734. 'AL',
  735. 'AL',
  736. 'AL',
  737. 'AL',
  738. 'AL',
  739. 'AL',
  740. 'AL',
  741. 'AL',
  742. 'AL',
  743. 'AL',
  744. 'AL',
  745. 'AL',
  746. 'AL',
  747. 'AL',
  748. 'AL',
  749. 'AL',
  750. 'AL',
  751. 'AL',
  752. 'AL',
  753. 'AL',
  754. 'AL',
  755. 'AL',
  756. 'AL',
  757. 'AL',
  758. 'AL',
  759. 'AL',
  760. 'AL',
  761. 'AL',
  762. 'AL',
  763. 'AL',
  764. 'AL',
  765. 'AL',
  766. 'AL',
  767. 'AL',
  768. 'NSM',
  769. 'NSM',
  770. 'NSM',
  771. 'NSM',
  772. 'NSM',
  773. 'NSM',
  774. 'NSM',
  775. 'NSM',
  776. 'NSM',
  777. 'NSM',
  778. 'NSM',
  779. 'NSM',
  780. 'NSM',
  781. 'NSM',
  782. 'AL',
  783. 'AL',
  784. 'AL',
  785. 'AL',
  786. 'AL',
  787. 'AL',
  788. 'AL',
  789. 'AN',
  790. 'AN',
  791. 'AN',
  792. 'AN',
  793. 'AN',
  794. 'AN',
  795. 'AN',
  796. 'AN',
  797. 'AN',
  798. 'AN',
  799. 'ET',
  800. 'AN',
  801. 'AN',
  802. 'AL',
  803. 'AL',
  804. 'AL',
  805. 'NSM',
  806. 'AL',
  807. 'AL',
  808. 'AL',
  809. 'AL',
  810. 'AL',
  811. 'AL',
  812. 'AL',
  813. 'AL',
  814. 'AL',
  815. 'AL',
  816. 'AL',
  817. 'AL',
  818. 'AL',
  819. 'AL',
  820. 'AL',
  821. 'AL',
  822. 'AL',
  823. 'AL',
  824. 'AL',
  825. 'AL',
  826. 'AL',
  827. 'AL',
  828. 'AL',
  829. 'AL',
  830. 'AL',
  831. 'AL',
  832. 'AL',
  833. 'AL',
  834. 'AL',
  835. 'AL',
  836. 'AL',
  837. 'AL',
  838. 'AL',
  839. 'AL',
  840. 'AL',
  841. 'AL',
  842. 'AL',
  843. 'AL',
  844. 'AL',
  845. 'AL',
  846. 'AL',
  847. 'AL',
  848. 'AL',
  849. 'AL',
  850. 'AL',
  851. 'AL',
  852. 'AL',
  853. 'AL',
  854. 'AL',
  855. 'AL',
  856. 'AL',
  857. 'AL',
  858. 'AL',
  859. 'AL',
  860. 'AL',
  861. 'AL',
  862. 'AL',
  863. 'AL',
  864. 'AL',
  865. 'AL',
  866. 'AL',
  867. 'AL',
  868. 'AL',
  869. 'AL',
  870. 'AL',
  871. 'AL',
  872. 'AL',
  873. 'AL',
  874. 'AL',
  875. 'AL',
  876. 'AL',
  877. 'AL',
  878. 'AL',
  879. 'AL',
  880. 'AL',
  881. 'AL',
  882. 'AL',
  883. 'AL',
  884. 'AL',
  885. 'AL',
  886. 'AL',
  887. 'AL',
  888. 'AL',
  889. 'AL',
  890. 'AL',
  891. 'AL',
  892. 'AL',
  893. 'AL',
  894. 'AL',
  895. 'AL',
  896. 'AL',
  897. 'AL',
  898. 'AL',
  899. 'AL',
  900. 'AL',
  901. 'AL',
  902. 'AL',
  903. 'AL',
  904. 'AL',
  905. 'AL',
  906. 'AL',
  907. 'NSM',
  908. 'NSM',
  909. 'NSM',
  910. 'NSM',
  911. 'NSM',
  912. 'NSM',
  913. 'NSM',
  914. 'NSM',
  915. 'NSM',
  916. 'NSM',
  917. 'NSM',
  918. 'NSM',
  919. 'NSM',
  920. 'NSM',
  921. 'NSM',
  922. 'NSM',
  923. 'NSM',
  924. 'NSM',
  925. 'NSM',
  926. 'ON',
  927. 'NSM',
  928. 'NSM',
  929. 'NSM',
  930. 'NSM',
  931. 'AL',
  932. 'AL',
  933. 'AL',
  934. 'AL',
  935. 'AL',
  936. 'AL',
  937. 'AL',
  938. 'AL',
  939. 'AL',
  940. 'AL',
  941. 'AL',
  942. 'AL',
  943. 'AL',
  944. 'AL',
  945. 'AL',
  946. 'AL',
  947. 'AL',
  948. 'AL'
  949. ];
  950. function isOdd(i) {
  951. return (i & 1) !== 0;
  952. }
  953. function isEven(i) {
  954. return (i & 1) === 0;
  955. }
  956. function findUnequal(arr, start, value) {
  957. for (var j = start, jj = arr.length; j < jj; ++j) {
  958. if (arr[j] !== value) {
  959. return j;
  960. }
  961. }
  962. return j;
  963. }
  964. function setValues(arr, start, end, value) {
  965. for (var j = start; j < end; ++j) {
  966. arr[j] = value;
  967. }
  968. }
  969. function reverseValues(arr, start, end) {
  970. for (var i = start, j = end - 1; i < j; ++i, --j) {
  971. var temp = arr[i];
  972. arr[i] = arr[j];
  973. arr[j] = temp;
  974. }
  975. }
  976. function createBidiText(str, isLTR, vertical) {
  977. return {
  978. str: str,
  979. dir: vertical ? 'ttb' : isLTR ? 'ltr' : 'rtl'
  980. };
  981. }
  982. // These are used in bidi(), which is called frequently. We re-use them on
  983. // each call to avoid unnecessary allocations.
  984. var chars = [];
  985. var types = [];
  986. function bidi(str, startLevel, vertical) {
  987. var isLTR = true;
  988. var strLength = str.length;
  989. if (strLength === 0 || vertical) {
  990. return createBidiText(str, isLTR, vertical);
  991. }
  992. // Get types and fill arrays
  993. chars.length = strLength;
  994. types.length = strLength;
  995. var numBidi = 0;
  996. var i, ii;
  997. for (i = 0; i < strLength; ++i) {
  998. chars[i] = str.charAt(i);
  999. var charCode = str.charCodeAt(i);
  1000. var charType = 'L';
  1001. if (charCode <= 0x00ff) {
  1002. charType = baseTypes[charCode];
  1003. } else if (0x0590 <= charCode && charCode <= 0x05f4) {
  1004. charType = 'R';
  1005. } else if (0x0600 <= charCode && charCode <= 0x06ff) {
  1006. charType = arabicTypes[charCode & 0xff];
  1007. } else if (0x0700 <= charCode && charCode <= 0x08AC) {
  1008. charType = 'AL';
  1009. }
  1010. if (charType === 'R' || charType === 'AL' || charType === 'AN') {
  1011. numBidi++;
  1012. }
  1013. types[i] = charType;
  1014. }
  1015. // Detect the bidi method
  1016. // - If there are no rtl characters then no bidi needed
  1017. // - If less than 30% chars are rtl then string is primarily ltr
  1018. // - If more than 30% chars are rtl then string is primarily rtl
  1019. if (numBidi === 0) {
  1020. isLTR = true;
  1021. return createBidiText(str, isLTR);
  1022. }
  1023. if (startLevel === -1) {
  1024. if (strLength / numBidi < 0.3) {
  1025. isLTR = true;
  1026. startLevel = 0;
  1027. } else {
  1028. isLTR = false;
  1029. startLevel = 1;
  1030. }
  1031. }
  1032. var levels = [];
  1033. for (i = 0; i < strLength; ++i) {
  1034. levels[i] = startLevel;
  1035. }
  1036. /*
  1037. X1-X10: skip most of this, since we are NOT doing the embeddings.
  1038. */
  1039. var e = isOdd(startLevel) ? 'R' : 'L';
  1040. var sor = e;
  1041. var eor = sor;
  1042. /*
  1043. W1. Examine each non-spacing mark (NSM) in the level run, and change the
  1044. type of the NSM to the type of the previous character. If the NSM is at the
  1045. start of the level run, it will get the type of sor.
  1046. */
  1047. var lastType = sor;
  1048. for (i = 0; i < strLength; ++i) {
  1049. if (types[i] === 'NSM') {
  1050. types[i] = lastType;
  1051. } else {
  1052. lastType = types[i];
  1053. }
  1054. }
  1055. /*
  1056. W2. Search backwards from each instance of a European number until the
  1057. first strong type (R, L, AL, or sor) is found. If an AL is found, change
  1058. the type of the European number to Arabic number.
  1059. */
  1060. lastType = sor;
  1061. var t;
  1062. for (i = 0; i < strLength; ++i) {
  1063. t = types[i];
  1064. if (t === 'EN') {
  1065. types[i] = lastType === 'AL' ? 'AN' : 'EN';
  1066. } else if (t === 'R' || t === 'L' || t === 'AL') {
  1067. lastType = t;
  1068. }
  1069. }
  1070. /*
  1071. W3. Change all ALs to R.
  1072. */
  1073. for (i = 0; i < strLength; ++i) {
  1074. t = types[i];
  1075. if (t === 'AL') {
  1076. types[i] = 'R';
  1077. }
  1078. }
  1079. /*
  1080. W4. A single European separator between two European numbers changes to a
  1081. European number. A single common separator between two numbers of the same
  1082. type changes to that type:
  1083. */
  1084. for (i = 1; i < strLength - 1; ++i) {
  1085. if (types[i] === 'ES' && types[i - 1] === 'EN' && types[i + 1] === 'EN') {
  1086. types[i] = 'EN';
  1087. }
  1088. if (types[i] === 'CS' && (types[i - 1] === 'EN' || types[i - 1] === 'AN') && types[i + 1] === types[i - 1]) {
  1089. types[i] = types[i - 1];
  1090. }
  1091. }
  1092. /*
  1093. W5. A sequence of European terminators adjacent to European numbers changes
  1094. to all European numbers:
  1095. */
  1096. for (i = 0; i < strLength; ++i) {
  1097. if (types[i] === 'EN') {
  1098. // do before
  1099. var j;
  1100. for (j = i - 1; j >= 0; --j) {
  1101. if (types[j] !== 'ET') {
  1102. break;
  1103. }
  1104. types[j] = 'EN';
  1105. }
  1106. // do after
  1107. for (j = i + 1; j < strLength; ++j) {
  1108. if (types[j] !== 'ET') {
  1109. break;
  1110. }
  1111. types[j] = 'EN';
  1112. }
  1113. }
  1114. }
  1115. /*
  1116. W6. Otherwise, separators and terminators change to Other Neutral:
  1117. */
  1118. for (i = 0; i < strLength; ++i) {
  1119. t = types[i];
  1120. if (t === 'WS' || t === 'ES' || t === 'ET' || t === 'CS') {
  1121. types[i] = 'ON';
  1122. }
  1123. }
  1124. /*
  1125. W7. Search backwards from each instance of a European number until the
  1126. first strong type (R, L, or sor) is found. If an L is found, then change
  1127. the type of the European number to L.
  1128. */
  1129. lastType = sor;
  1130. for (i = 0; i < strLength; ++i) {
  1131. t = types[i];
  1132. if (t === 'EN') {
  1133. types[i] = lastType === 'L' ? 'L' : 'EN';
  1134. } else if (t === 'R' || t === 'L') {
  1135. lastType = t;
  1136. }
  1137. }
  1138. /*
  1139. N1. A sequence of neutrals takes the direction of the surrounding strong
  1140. text if the text on both sides has the same direction. European and Arabic
  1141. numbers are treated as though they were R. Start-of-level-run (sor) and
  1142. end-of-level-run (eor) are used at level run boundaries.
  1143. */
  1144. for (i = 0; i < strLength; ++i) {
  1145. if (types[i] === 'ON') {
  1146. var end = findUnequal(types, i + 1, 'ON');
  1147. var before = sor;
  1148. if (i > 0) {
  1149. before = types[i - 1];
  1150. }
  1151. var after = eor;
  1152. if (end + 1 < strLength) {
  1153. after = types[end + 1];
  1154. }
  1155. if (before !== 'L') {
  1156. before = 'R';
  1157. }
  1158. if (after !== 'L') {
  1159. after = 'R';
  1160. }
  1161. if (before === after) {
  1162. setValues(types, i, end, before);
  1163. }
  1164. i = end - 1;
  1165. }
  1166. }
  1167. // reset to end (-1 so next iteration is ok)
  1168. /*
  1169. N2. Any remaining neutrals take the embedding direction.
  1170. */
  1171. for (i = 0; i < strLength; ++i) {
  1172. if (types[i] === 'ON') {
  1173. types[i] = e;
  1174. }
  1175. }
  1176. /*
  1177. I1. For all characters with an even (left-to-right) embedding direction,
  1178. those of type R go up one level and those of type AN or EN go up two
  1179. levels.
  1180. I2. For all characters with an odd (right-to-left) embedding direction,
  1181. those of type L, EN or AN go up one level.
  1182. */
  1183. for (i = 0; i < strLength; ++i) {
  1184. t = types[i];
  1185. if (isEven(levels[i])) {
  1186. if (t === 'R') {
  1187. levels[i] += 1;
  1188. } else if (t === 'AN' || t === 'EN') {
  1189. levels[i] += 2;
  1190. }
  1191. } else {
  1192. // isOdd
  1193. if (t === 'L' || t === 'AN' || t === 'EN') {
  1194. levels[i] += 1;
  1195. }
  1196. }
  1197. }
  1198. /*
  1199. L1. On each line, reset the embedding level of the following characters to
  1200. the paragraph embedding level:
  1201. segment separators,
  1202. paragraph separators,
  1203. any sequence of whitespace characters preceding a segment separator or
  1204. paragraph separator, and any sequence of white space characters at the end
  1205. of the line.
  1206. */
  1207. // don't bother as text is only single line
  1208. /*
  1209. L2. From the highest level found in the text to the lowest odd level on
  1210. each line, reverse any contiguous sequence of characters that are at that
  1211. level or higher.
  1212. */
  1213. // find highest level & lowest odd level
  1214. var highestLevel = -1;
  1215. var lowestOddLevel = 99;
  1216. var level;
  1217. for (i = 0, ii = levels.length; i < ii; ++i) {
  1218. level = levels[i];
  1219. if (highestLevel < level) {
  1220. highestLevel = level;
  1221. }
  1222. if (lowestOddLevel > level && isOdd(level)) {
  1223. lowestOddLevel = level;
  1224. }
  1225. }
  1226. // now reverse between those limits
  1227. for (level = highestLevel; level >= lowestOddLevel; --level) {
  1228. // find segments to reverse
  1229. var start = -1;
  1230. for (i = 0, ii = levels.length; i < ii; ++i) {
  1231. if (levels[i] < level) {
  1232. if (start >= 0) {
  1233. reverseValues(chars, start, i);
  1234. start = -1;
  1235. }
  1236. } else if (start < 0) {
  1237. start = i;
  1238. }
  1239. }
  1240. if (start >= 0) {
  1241. reverseValues(chars, start, levels.length);
  1242. }
  1243. }
  1244. /*
  1245. L3. Combining marks applied to a right-to-left base character will at this
  1246. point precede their base character. If the rendering engine expects them to
  1247. follow the base characters in the final display process, then the ordering
  1248. of the marks and the base character must be reversed.
  1249. */
  1250. // don't bother for now
  1251. /*
  1252. L4. A character that possesses the mirrored property as specified by
  1253. Section 4.7, Mirrored, must be depicted by a mirrored glyph if the resolved
  1254. directionality of that character is R.
  1255. */
  1256. // don't mirror as characters are already mirrored in the pdf
  1257. // Finally, return string
  1258. for (i = 0, ii = chars.length; i < ii; ++i) {
  1259. var ch = chars[i];
  1260. if (ch === '<' || ch === '>') {
  1261. chars[i] = '';
  1262. }
  1263. }
  1264. return createBidiText(chars.join(''), isLTR);
  1265. }
  1266. exports.bidi = bidi;
  1267. }));
  1268. (function (root, factory) {
  1269. factory(root.pdfjsCoreCharsets = {});
  1270. }(this, function (exports) {
  1271. var ISOAdobeCharset = [
  1272. '.notdef',
  1273. 'space',
  1274. 'exclam',
  1275. 'quotedbl',
  1276. 'numbersign',
  1277. 'dollar',
  1278. 'percent',
  1279. 'ampersand',
  1280. 'quoteright',
  1281. 'parenleft',
  1282. 'parenright',
  1283. 'asterisk',
  1284. 'plus',
  1285. 'comma',
  1286. 'hyphen',
  1287. 'period',
  1288. 'slash',
  1289. 'zero',
  1290. 'one',
  1291. 'two',
  1292. 'three',
  1293. 'four',
  1294. 'five',
  1295. 'six',
  1296. 'seven',
  1297. 'eight',
  1298. 'nine',
  1299. 'colon',
  1300. 'semicolon',
  1301. 'less',
  1302. 'equal',
  1303. 'greater',
  1304. 'question',
  1305. 'at',
  1306. 'A',
  1307. 'B',
  1308. 'C',
  1309. 'D',
  1310. 'E',
  1311. 'F',
  1312. 'G',
  1313. 'H',
  1314. 'I',
  1315. 'J',
  1316. 'K',
  1317. 'L',
  1318. 'M',
  1319. 'N',
  1320. 'O',
  1321. 'P',
  1322. 'Q',
  1323. 'R',
  1324. 'S',
  1325. 'T',
  1326. 'U',
  1327. 'V',
  1328. 'W',
  1329. 'X',
  1330. 'Y',
  1331. 'Z',
  1332. 'bracketleft',
  1333. 'backslash',
  1334. 'bracketright',
  1335. 'asciicircum',
  1336. 'underscore',
  1337. 'quoteleft',
  1338. 'a',
  1339. 'b',
  1340. 'c',
  1341. 'd',
  1342. 'e',
  1343. 'f',
  1344. 'g',
  1345. 'h',
  1346. 'i',
  1347. 'j',
  1348. 'k',
  1349. 'l',
  1350. 'm',
  1351. 'n',
  1352. 'o',
  1353. 'p',
  1354. 'q',
  1355. 'r',
  1356. 's',
  1357. 't',
  1358. 'u',
  1359. 'v',
  1360. 'w',
  1361. 'x',
  1362. 'y',
  1363. 'z',
  1364. 'braceleft',
  1365. 'bar',
  1366. 'braceright',
  1367. 'asciitilde',
  1368. 'exclamdown',
  1369. 'cent',
  1370. 'sterling',
  1371. 'fraction',
  1372. 'yen',
  1373. 'florin',
  1374. 'section',
  1375. 'currency',
  1376. 'quotesingle',
  1377. 'quotedblleft',
  1378. 'guillemotleft',
  1379. 'guilsinglleft',
  1380. 'guilsinglright',
  1381. 'fi',
  1382. 'fl',
  1383. 'endash',
  1384. 'dagger',
  1385. 'daggerdbl',
  1386. 'periodcentered',
  1387. 'paragraph',
  1388. 'bullet',
  1389. 'quotesinglbase',
  1390. 'quotedblbase',
  1391. 'quotedblright',
  1392. 'guillemotright',
  1393. 'ellipsis',
  1394. 'perthousand',
  1395. 'questiondown',
  1396. 'grave',
  1397. 'acute',
  1398. 'circumflex',
  1399. 'tilde',
  1400. 'macron',
  1401. 'breve',
  1402. 'dotaccent',
  1403. 'dieresis',
  1404. 'ring',
  1405. 'cedilla',
  1406. 'hungarumlaut',
  1407. 'ogonek',
  1408. 'caron',
  1409. 'emdash',
  1410. 'AE',
  1411. 'ordfeminine',
  1412. 'Lslash',
  1413. 'Oslash',
  1414. 'OE',
  1415. 'ordmasculine',
  1416. 'ae',
  1417. 'dotlessi',
  1418. 'lslash',
  1419. 'oslash',
  1420. 'oe',
  1421. 'germandbls',
  1422. 'onesuperior',
  1423. 'logicalnot',
  1424. 'mu',
  1425. 'trademark',
  1426. 'Eth',
  1427. 'onehalf',
  1428. 'plusminus',
  1429. 'Thorn',
  1430. 'onequarter',
  1431. 'divide',
  1432. 'brokenbar',
  1433. 'degree',
  1434. 'thorn',
  1435. 'threequarters',
  1436. 'twosuperior',
  1437. 'registered',
  1438. 'minus',
  1439. 'eth',
  1440. 'multiply',
  1441. 'threesuperior',
  1442. 'copyright',
  1443. 'Aacute',
  1444. 'Acircumflex',
  1445. 'Adieresis',
  1446. 'Agrave',
  1447. 'Aring',
  1448. 'Atilde',
  1449. 'Ccedilla',
  1450. 'Eacute',
  1451. 'Ecircumflex',
  1452. 'Edieresis',
  1453. 'Egrave',
  1454. 'Iacute',
  1455. 'Icircumflex',
  1456. 'Idieresis',
  1457. 'Igrave',
  1458. 'Ntilde',
  1459. 'Oacute',
  1460. 'Ocircumflex',
  1461. 'Odieresis',
  1462. 'Ograve',
  1463. 'Otilde',
  1464. 'Scaron',
  1465. 'Uacute',
  1466. 'Ucircumflex',
  1467. 'Udieresis',
  1468. 'Ugrave',
  1469. 'Yacute',
  1470. 'Ydieresis',
  1471. 'Zcaron',
  1472. 'aacute',
  1473. 'acircumflex',
  1474. 'adieresis',
  1475. 'agrave',
  1476. 'aring',
  1477. 'atilde',
  1478. 'ccedilla',
  1479. 'eacute',
  1480. 'ecircumflex',
  1481. 'edieresis',
  1482. 'egrave',
  1483. 'iacute',
  1484. 'icircumflex',
  1485. 'idieresis',
  1486. 'igrave',
  1487. 'ntilde',
  1488. 'oacute',
  1489. 'ocircumflex',
  1490. 'odieresis',
  1491. 'ograve',
  1492. 'otilde',
  1493. 'scaron',
  1494. 'uacute',
  1495. 'ucircumflex',
  1496. 'udieresis',
  1497. 'ugrave',
  1498. 'yacute',
  1499. 'ydieresis',
  1500. 'zcaron'
  1501. ];
  1502. var ExpertCharset = [
  1503. '.notdef',
  1504. 'space',
  1505. 'exclamsmall',
  1506. 'Hungarumlautsmall',
  1507. 'dollaroldstyle',
  1508. 'dollarsuperior',
  1509. 'ampersandsmall',
  1510. 'Acutesmall',
  1511. 'parenleftsuperior',
  1512. 'parenrightsuperior',
  1513. 'twodotenleader',
  1514. 'onedotenleader',
  1515. 'comma',
  1516. 'hyphen',
  1517. 'period',
  1518. 'fraction',
  1519. 'zerooldstyle',
  1520. 'oneoldstyle',
  1521. 'twooldstyle',
  1522. 'threeoldstyle',
  1523. 'fouroldstyle',
  1524. 'fiveoldstyle',
  1525. 'sixoldstyle',
  1526. 'sevenoldstyle',
  1527. 'eightoldstyle',
  1528. 'nineoldstyle',
  1529. 'colon',
  1530. 'semicolon',
  1531. 'commasuperior',
  1532. 'threequartersemdash',
  1533. 'periodsuperior',
  1534. 'questionsmall',
  1535. 'asuperior',
  1536. 'bsuperior',
  1537. 'centsuperior',
  1538. 'dsuperior',
  1539. 'esuperior',
  1540. 'isuperior',
  1541. 'lsuperior',
  1542. 'msuperior',
  1543. 'nsuperior',
  1544. 'osuperior',
  1545. 'rsuperior',
  1546. 'ssuperior',
  1547. 'tsuperior',
  1548. 'ff',
  1549. 'fi',
  1550. 'fl',
  1551. 'ffi',
  1552. 'ffl',
  1553. 'parenleftinferior',
  1554. 'parenrightinferior',
  1555. 'Circumflexsmall',
  1556. 'hyphensuperior',
  1557. 'Gravesmall',
  1558. 'Asmall',
  1559. 'Bsmall',
  1560. 'Csmall',
  1561. 'Dsmall',
  1562. 'Esmall',
  1563. 'Fsmall',
  1564. 'Gsmall',
  1565. 'Hsmall',
  1566. 'Ismall',
  1567. 'Jsmall',
  1568. 'Ksmall',
  1569. 'Lsmall',
  1570. 'Msmall',
  1571. 'Nsmall',
  1572. 'Osmall',
  1573. 'Psmall',
  1574. 'Qsmall',
  1575. 'Rsmall',
  1576. 'Ssmall',
  1577. 'Tsmall',
  1578. 'Usmall',
  1579. 'Vsmall',
  1580. 'Wsmall',
  1581. 'Xsmall',
  1582. 'Ysmall',
  1583. 'Zsmall',
  1584. 'colonmonetary',
  1585. 'onefitted',
  1586. 'rupiah',
  1587. 'Tildesmall',
  1588. 'exclamdownsmall',
  1589. 'centoldstyle',
  1590. 'Lslashsmall',
  1591. 'Scaronsmall',
  1592. 'Zcaronsmall',
  1593. 'Dieresissmall',
  1594. 'Brevesmall',
  1595. 'Caronsmall',
  1596. 'Dotaccentsmall',
  1597. 'Macronsmall',
  1598. 'figuredash',
  1599. 'hypheninferior',
  1600. 'Ogoneksmall',
  1601. 'Ringsmall',
  1602. 'Cedillasmall',
  1603. 'onequarter',
  1604. 'onehalf',
  1605. 'threequarters',
  1606. 'questiondownsmall',
  1607. 'oneeighth',
  1608. 'threeeighths',
  1609. 'fiveeighths',
  1610. 'seveneighths',
  1611. 'onethird',
  1612. 'twothirds',
  1613. 'zerosuperior',
  1614. 'onesuperior',
  1615. 'twosuperior',
  1616. 'threesuperior',
  1617. 'foursuperior',
  1618. 'fivesuperior',
  1619. 'sixsuperior',
  1620. 'sevensuperior',
  1621. 'eightsuperior',
  1622. 'ninesuperior',
  1623. 'zeroinferior',
  1624. 'oneinferior',
  1625. 'twoinferior',
  1626. 'threeinferior',
  1627. 'fourinferior',
  1628. 'fiveinferior',
  1629. 'sixinferior',
  1630. 'seveninferior',
  1631. 'eightinferior',
  1632. 'nineinferior',
  1633. 'centinferior',
  1634. 'dollarinferior',
  1635. 'periodinferior',
  1636. 'commainferior',
  1637. 'Agravesmall',
  1638. 'Aacutesmall',
  1639. 'Acircumflexsmall',
  1640. 'Atildesmall',
  1641. 'Adieresissmall',
  1642. 'Aringsmall',
  1643. 'AEsmall',
  1644. 'Ccedillasmall',
  1645. 'Egravesmall',
  1646. 'Eacutesmall',
  1647. 'Ecircumflexsmall',
  1648. 'Edieresissmall',
  1649. 'Igravesmall',
  1650. 'Iacutesmall',
  1651. 'Icircumflexsmall',
  1652. 'Idieresissmall',
  1653. 'Ethsmall',
  1654. 'Ntildesmall',
  1655. 'Ogravesmall',
  1656. 'Oacutesmall',
  1657. 'Ocircumflexsmall',
  1658. 'Otildesmall',
  1659. 'Odieresissmall',
  1660. 'OEsmall',
  1661. 'Oslashsmall',
  1662. 'Ugravesmall',
  1663. 'Uacutesmall',
  1664. 'Ucircumflexsmall',
  1665. 'Udieresissmall',
  1666. 'Yacutesmall',
  1667. 'Thornsmall',
  1668. 'Ydieresissmall'
  1669. ];
  1670. var ExpertSubsetCharset = [
  1671. '.notdef',
  1672. 'space',
  1673. 'dollaroldstyle',
  1674. 'dollarsuperior',
  1675. 'parenleftsuperior',
  1676. 'parenrightsuperior',
  1677. 'twodotenleader',
  1678. 'onedotenleader',
  1679. 'comma',
  1680. 'hyphen',
  1681. 'period',
  1682. 'fraction',
  1683. 'zerooldstyle',
  1684. 'oneoldstyle',
  1685. 'twooldstyle',
  1686. 'threeoldstyle',
  1687. 'fouroldstyle',
  1688. 'fiveoldstyle',
  1689. 'sixoldstyle',
  1690. 'sevenoldstyle',
  1691. 'eightoldstyle',
  1692. 'nineoldstyle',
  1693. 'colon',
  1694. 'semicolon',
  1695. 'commasuperior',
  1696. 'threequartersemdash',
  1697. 'periodsuperior',
  1698. 'asuperior',
  1699. 'bsuperior',
  1700. 'centsuperior',
  1701. 'dsuperior',
  1702. 'esuperior',
  1703. 'isuperior',
  1704. 'lsuperior',
  1705. 'msuperior',
  1706. 'nsuperior',
  1707. 'osuperior',
  1708. 'rsuperior',
  1709. 'ssuperior',
  1710. 'tsuperior',
  1711. 'ff',
  1712. 'fi',
  1713. 'fl',
  1714. 'ffi',
  1715. 'ffl',
  1716. 'parenleftinferior',
  1717. 'parenrightinferior',
  1718. 'hyphensuperior',
  1719. 'colonmonetary',
  1720. 'onefitted',
  1721. 'rupiah',
  1722. 'centoldstyle',
  1723. 'figuredash',
  1724. 'hypheninferior',
  1725. 'onequarter',
  1726. 'onehalf',
  1727. 'threequarters',
  1728. 'oneeighth',
  1729. 'threeeighths',
  1730. 'fiveeighths',
  1731. 'seveneighths',
  1732. 'onethird',
  1733. 'twothirds',
  1734. 'zerosuperior',
  1735. 'onesuperior',
  1736. 'twosuperior',
  1737. 'threesuperior',
  1738. 'foursuperior',
  1739. 'fivesuperior',
  1740. 'sixsuperior',
  1741. 'sevensuperior',
  1742. 'eightsuperior',
  1743. 'ninesuperior',
  1744. 'zeroinferior',
  1745. 'oneinferior',
  1746. 'twoinferior',
  1747. 'threeinferior',
  1748. 'fourinferior',
  1749. 'fiveinferior',
  1750. 'sixinferior',
  1751. 'seveninferior',
  1752. 'eightinferior',
  1753. 'nineinferior',
  1754. 'centinferior',
  1755. 'dollarinferior',
  1756. 'periodinferior',
  1757. 'commainferior'
  1758. ];
  1759. exports.ISOAdobeCharset = ISOAdobeCharset;
  1760. exports.ExpertCharset = ExpertCharset;
  1761. exports.ExpertSubsetCharset = ExpertSubsetCharset;
  1762. }));
  1763. (function (root, factory) {
  1764. factory(root.pdfjsCoreEncodings = {});
  1765. }(this, function (exports) {
  1766. var ExpertEncoding = [
  1767. '',
  1768. '',
  1769. '',
  1770. '',
  1771. '',
  1772. '',
  1773. '',
  1774. '',
  1775. '',
  1776. '',
  1777. '',
  1778. '',
  1779. '',
  1780. '',
  1781. '',
  1782. '',
  1783. '',
  1784. '',
  1785. '',
  1786. '',
  1787. '',
  1788. '',
  1789. '',
  1790. '',
  1791. '',
  1792. '',
  1793. '',
  1794. '',
  1795. '',
  1796. '',
  1797. '',
  1798. '',
  1799. 'space',
  1800. 'exclamsmall',
  1801. 'Hungarumlautsmall',
  1802. '',
  1803. 'dollaroldstyle',
  1804. 'dollarsuperior',
  1805. 'ampersandsmall',
  1806. 'Acutesmall',
  1807. 'parenleftsuperior',
  1808. 'parenrightsuperior',
  1809. 'twodotenleader',
  1810. 'onedotenleader',
  1811. 'comma',
  1812. 'hyphen',
  1813. 'period',
  1814. 'fraction',
  1815. 'zerooldstyle',
  1816. 'oneoldstyle',
  1817. 'twooldstyle',
  1818. 'threeoldstyle',
  1819. 'fouroldstyle',
  1820. 'fiveoldstyle',
  1821. 'sixoldstyle',
  1822. 'sevenoldstyle',
  1823. 'eightoldstyle',
  1824. 'nineoldstyle',
  1825. 'colon',
  1826. 'semicolon',
  1827. 'commasuperior',
  1828. 'threequartersemdash',
  1829. 'periodsuperior',
  1830. 'questionsmall',
  1831. '',
  1832. 'asuperior',
  1833. 'bsuperior',
  1834. 'centsuperior',
  1835. 'dsuperior',
  1836. 'esuperior',
  1837. '',
  1838. '',
  1839. 'isuperior',
  1840. '',
  1841. '',
  1842. 'lsuperior',
  1843. 'msuperior',
  1844. 'nsuperior',
  1845. 'osuperior',
  1846. '',
  1847. '',
  1848. 'rsuperior',
  1849. 'ssuperior',
  1850. 'tsuperior',
  1851. '',
  1852. 'ff',
  1853. 'fi',
  1854. 'fl',
  1855. 'ffi',
  1856. 'ffl',
  1857. 'parenleftinferior',
  1858. '',
  1859. 'parenrightinferior',
  1860. 'Circumflexsmall',
  1861. 'hyphensuperior',
  1862. 'Gravesmall',
  1863. 'Asmall',
  1864. 'Bsmall',
  1865. 'Csmall',
  1866. 'Dsmall',
  1867. 'Esmall',
  1868. 'Fsmall',
  1869. 'Gsmall',
  1870. 'Hsmall',
  1871. 'Ismall',
  1872. 'Jsmall',
  1873. 'Ksmall',
  1874. 'Lsmall',
  1875. 'Msmall',
  1876. 'Nsmall',
  1877. 'Osmall',
  1878. 'Psmall',
  1879. 'Qsmall',
  1880. 'Rsmall',
  1881. 'Ssmall',
  1882. 'Tsmall',
  1883. 'Usmall',
  1884. 'Vsmall',
  1885. 'Wsmall',
  1886. 'Xsmall',
  1887. 'Ysmall',
  1888. 'Zsmall',
  1889. 'colonmonetary',
  1890. 'onefitted',
  1891. 'rupiah',
  1892. 'Tildesmall',
  1893. '',
  1894. '',
  1895. '',
  1896. '',
  1897. '',
  1898. '',
  1899. '',
  1900. '',
  1901. '',
  1902. '',
  1903. '',
  1904. '',
  1905. '',
  1906. '',
  1907. '',
  1908. '',
  1909. '',
  1910. '',
  1911. '',
  1912. '',
  1913. '',
  1914. '',
  1915. '',
  1916. '',
  1917. '',
  1918. '',
  1919. '',
  1920. '',
  1921. '',
  1922. '',
  1923. '',
  1924. '',
  1925. '',
  1926. '',
  1927. 'exclamdownsmall',
  1928. 'centoldstyle',
  1929. 'Lslashsmall',
  1930. '',
  1931. '',
  1932. 'Scaronsmall',
  1933. 'Zcaronsmall',
  1934. 'Dieresissmall',
  1935. 'Brevesmall',
  1936. 'Caronsmall',
  1937. '',
  1938. 'Dotaccentsmall',
  1939. '',
  1940. '',
  1941. 'Macronsmall',
  1942. '',
  1943. '',
  1944. 'figuredash',
  1945. 'hypheninferior',
  1946. '',
  1947. '',
  1948. 'Ogoneksmall',
  1949. 'Ringsmall',
  1950. 'Cedillasmall',
  1951. '',
  1952. '',
  1953. '',
  1954. 'onequarter',
  1955. 'onehalf',
  1956. 'threequarters',
  1957. 'questiondownsmall',
  1958. 'oneeighth',
  1959. 'threeeighths',
  1960. 'fiveeighths',
  1961. 'seveneighths',
  1962. 'onethird',
  1963. 'twothirds',
  1964. '',
  1965. '',
  1966. 'zerosuperior',
  1967. 'onesuperior',
  1968. 'twosuperior',
  1969. 'threesuperior',
  1970. 'foursuperior',
  1971. 'fivesuperior',
  1972. 'sixsuperior',
  1973. 'sevensuperior',
  1974. 'eightsuperior',
  1975. 'ninesuperior',
  1976. 'zeroinferior',
  1977. 'oneinferior',
  1978. 'twoinferior',
  1979. 'threeinferior',
  1980. 'fourinferior',
  1981. 'fiveinferior',
  1982. 'sixinferior',
  1983. 'seveninferior',
  1984. 'eightinferior',
  1985. 'nineinferior',
  1986. 'centinferior',
  1987. 'dollarinferior',
  1988. 'periodinferior',
  1989. 'commainferior',
  1990. 'Agravesmall',
  1991. 'Aacutesmall',
  1992. 'Acircumflexsmall',
  1993. 'Atildesmall',
  1994. 'Adieresissmall',
  1995. 'Aringsmall',
  1996. 'AEsmall',
  1997. 'Ccedillasmall',
  1998. 'Egravesmall',
  1999. 'Eacutesmall',
  2000. 'Ecircumflexsmall',
  2001. 'Edieresissmall',
  2002. 'Igravesmall',
  2003. 'Iacutesmall',
  2004. 'Icircumflexsmall',
  2005. 'Idieresissmall',
  2006. 'Ethsmall',
  2007. 'Ntildesmall',
  2008. 'Ogravesmall',
  2009. 'Oacutesmall',
  2010. 'Ocircumflexsmall',
  2011. 'Otildesmall',
  2012. 'Odieresissmall',
  2013. 'OEsmall',
  2014. 'Oslashsmall',
  2015. 'Ugravesmall',
  2016. 'Uacutesmall',
  2017. 'Ucircumflexsmall',
  2018. 'Udieresissmall',
  2019. 'Yacutesmall',
  2020. 'Thornsmall',
  2021. 'Ydieresissmall'
  2022. ];
  2023. var MacExpertEncoding = [
  2024. '',
  2025. '',
  2026. '',
  2027. '',
  2028. '',
  2029. '',
  2030. '',
  2031. '',
  2032. '',
  2033. '',
  2034. '',
  2035. '',
  2036. '',
  2037. '',
  2038. '',
  2039. '',
  2040. '',
  2041. '',
  2042. '',
  2043. '',
  2044. '',
  2045. '',
  2046. '',
  2047. '',
  2048. '',
  2049. '',
  2050. '',
  2051. '',
  2052. '',
  2053. '',
  2054. '',
  2055. '',
  2056. 'space',
  2057. 'exclamsmall',
  2058. 'Hungarumlautsmall',
  2059. 'centoldstyle',
  2060. 'dollaroldstyle',
  2061. 'dollarsuperior',
  2062. 'ampersandsmall',
  2063. 'Acutesmall',
  2064. 'parenleftsuperior',
  2065. 'parenrightsuperior',
  2066. 'twodotenleader',
  2067. 'onedotenleader',
  2068. 'comma',
  2069. 'hyphen',
  2070. 'period',
  2071. 'fraction',
  2072. 'zerooldstyle',
  2073. 'oneoldstyle',
  2074. 'twooldstyle',
  2075. 'threeoldstyle',
  2076. 'fouroldstyle',
  2077. 'fiveoldstyle',
  2078. 'sixoldstyle',
  2079. 'sevenoldstyle',
  2080. 'eightoldstyle',
  2081. 'nineoldstyle',
  2082. 'colon',
  2083. 'semicolon',
  2084. '',
  2085. 'threequartersemdash',
  2086. '',
  2087. 'questionsmall',
  2088. '',
  2089. '',
  2090. '',
  2091. '',
  2092. 'Ethsmall',
  2093. '',
  2094. '',
  2095. 'onequarter',
  2096. 'onehalf',
  2097. 'threequarters',
  2098. 'oneeighth',
  2099. 'threeeighths',
  2100. 'fiveeighths',
  2101. 'seveneighths',
  2102. 'onethird',
  2103. 'twothirds',
  2104. '',
  2105. '',
  2106. '',
  2107. '',
  2108. '',
  2109. '',
  2110. 'ff',
  2111. 'fi',
  2112. 'fl',
  2113. 'ffi',
  2114. 'ffl',
  2115. 'parenleftinferior',
  2116. '',
  2117. 'parenrightinferior',
  2118. 'Circumflexsmall',
  2119. 'hypheninferior',
  2120. 'Gravesmall',
  2121. 'Asmall',
  2122. 'Bsmall',
  2123. 'Csmall',
  2124. 'Dsmall',
  2125. 'Esmall',
  2126. 'Fsmall',
  2127. 'Gsmall',
  2128. 'Hsmall',
  2129. 'Ismall',
  2130. 'Jsmall',
  2131. 'Ksmall',
  2132. 'Lsmall',
  2133. 'Msmall',
  2134. 'Nsmall',
  2135. 'Osmall',
  2136. 'Psmall',
  2137. 'Qsmall',
  2138. 'Rsmall',
  2139. 'Ssmall',
  2140. 'Tsmall',
  2141. 'Usmall',
  2142. 'Vsmall',
  2143. 'Wsmall',
  2144. 'Xsmall',
  2145. 'Ysmall',
  2146. 'Zsmall',
  2147. 'colonmonetary',
  2148. 'onefitted',
  2149. 'rupiah',
  2150. 'Tildesmall',
  2151. '',
  2152. '',
  2153. 'asuperior',
  2154. 'centsuperior',
  2155. '',
  2156. '',
  2157. '',
  2158. '',
  2159. 'Aacutesmall',
  2160. 'Agravesmall',
  2161. 'Acircumflexsmall',
  2162. 'Adieresissmall',
  2163. 'Atildesmall',
  2164. 'Aringsmall',
  2165. 'Ccedillasmall',
  2166. 'Eacutesmall',
  2167. 'Egravesmall',
  2168. 'Ecircumflexsmall',
  2169. 'Edieresissmall',
  2170. 'Iacutesmall',
  2171. 'Igravesmall',
  2172. 'Icircumflexsmall',
  2173. 'Idieresissmall',
  2174. 'Ntildesmall',
  2175. 'Oacutesmall',
  2176. 'Ogravesmall',
  2177. 'Ocircumflexsmall',
  2178. 'Odieresissmall',
  2179. 'Otildesmall',
  2180. 'Uacutesmall',
  2181. 'Ugravesmall',
  2182. 'Ucircumflexsmall',
  2183. 'Udieresissmall',
  2184. '',
  2185. 'eightsuperior',
  2186. 'fourinferior',
  2187. 'threeinferior',
  2188. 'sixinferior',
  2189. 'eightinferior',
  2190. 'seveninferior',
  2191. 'Scaronsmall',
  2192. '',
  2193. 'centinferior',
  2194. 'twoinferior',
  2195. '',
  2196. 'Dieresissmall',
  2197. '',
  2198. 'Caronsmall',
  2199. 'osuperior',
  2200. 'fiveinferior',
  2201. '',
  2202. 'commainferior',
  2203. 'periodinferior',
  2204. 'Yacutesmall',
  2205. '',
  2206. 'dollarinferior',
  2207. '',
  2208. 'Thornsmall',
  2209. '',
  2210. 'nineinferior',
  2211. 'zeroinferior',
  2212. 'Zcaronsmall',
  2213. 'AEsmall',
  2214. 'Oslashsmall',
  2215. 'questiondownsmall',
  2216. 'oneinferior',
  2217. 'Lslashsmall',
  2218. '',
  2219. '',
  2220. '',
  2221. '',
  2222. '',
  2223. '',
  2224. 'Cedillasmall',
  2225. '',
  2226. '',
  2227. '',
  2228. '',
  2229. '',
  2230. 'OEsmall',
  2231. 'figuredash',
  2232. 'hyphensuperior',
  2233. '',
  2234. '',
  2235. '',
  2236. '',
  2237. 'exclamdownsmall',
  2238. '',
  2239. 'Ydieresissmall',
  2240. '',
  2241. 'onesuperior',
  2242. 'twosuperior',
  2243. 'threesuperior',
  2244. 'foursuperior',
  2245. 'fivesuperior',
  2246. 'sixsuperior',
  2247. 'sevensuperior',
  2248. 'ninesuperior',
  2249. 'zerosuperior',
  2250. '',
  2251. 'esuperior',
  2252. 'rsuperior',
  2253. 'tsuperior',
  2254. '',
  2255. '',
  2256. 'isuperior',
  2257. 'ssuperior',
  2258. 'dsuperior',
  2259. '',
  2260. '',
  2261. '',
  2262. '',
  2263. '',
  2264. 'lsuperior',
  2265. 'Ogoneksmall',
  2266. 'Brevesmall',
  2267. 'Macronsmall',
  2268. 'bsuperior',
  2269. 'nsuperior',
  2270. 'msuperior',
  2271. 'commasuperior',
  2272. 'periodsuperior',
  2273. 'Dotaccentsmall',
  2274. 'Ringsmall'
  2275. ];
  2276. var MacRomanEncoding = [
  2277. '',
  2278. '',
  2279. '',
  2280. '',
  2281. '',
  2282. '',
  2283. '',
  2284. '',
  2285. '',
  2286. '',
  2287. '',
  2288. '',
  2289. '',
  2290. '',
  2291. '',
  2292. '',
  2293. '',
  2294. '',
  2295. '',
  2296. '',
  2297. '',
  2298. '',
  2299. '',
  2300. '',
  2301. '',
  2302. '',
  2303. '',
  2304. '',
  2305. '',
  2306. '',
  2307. '',
  2308. '',
  2309. 'space',
  2310. 'exclam',
  2311. 'quotedbl',
  2312. 'numbersign',
  2313. 'dollar',
  2314. 'percent',
  2315. 'ampersand',
  2316. 'quotesingle',
  2317. 'parenleft',
  2318. 'parenright',
  2319. 'asterisk',
  2320. 'plus',
  2321. 'comma',
  2322. 'hyphen',
  2323. 'period',
  2324. 'slash',
  2325. 'zero',
  2326. 'one',
  2327. 'two',
  2328. 'three',
  2329. 'four',
  2330. 'five',
  2331. 'six',
  2332. 'seven',
  2333. 'eight',
  2334. 'nine',
  2335. 'colon',
  2336. 'semicolon',
  2337. 'less',
  2338. 'equal',
  2339. 'greater',
  2340. 'question',
  2341. 'at',
  2342. 'A',
  2343. 'B',
  2344. 'C',
  2345. 'D',
  2346. 'E',
  2347. 'F',
  2348. 'G',
  2349. 'H',
  2350. 'I',
  2351. 'J',
  2352. 'K',
  2353. 'L',
  2354. 'M',
  2355. 'N',
  2356. 'O',
  2357. 'P',
  2358. 'Q',
  2359. 'R',
  2360. 'S',
  2361. 'T',
  2362. 'U',
  2363. 'V',
  2364. 'W',
  2365. 'X',
  2366. 'Y',
  2367. 'Z',
  2368. 'bracketleft',
  2369. 'backslash',
  2370. 'bracketright',
  2371. 'asciicircum',
  2372. 'underscore',
  2373. 'grave',
  2374. 'a',
  2375. 'b',
  2376. 'c',
  2377. 'd',
  2378. 'e',
  2379. 'f',
  2380. 'g',
  2381. 'h',
  2382. 'i',
  2383. 'j',
  2384. 'k',
  2385. 'l',
  2386. 'm',
  2387. 'n',
  2388. 'o',
  2389. 'p',
  2390. 'q',
  2391. 'r',
  2392. 's',
  2393. 't',
  2394. 'u',
  2395. 'v',
  2396. 'w',
  2397. 'x',
  2398. 'y',
  2399. 'z',
  2400. 'braceleft',
  2401. 'bar',
  2402. 'braceright',
  2403. 'asciitilde',
  2404. '',
  2405. 'Adieresis',
  2406. 'Aring',
  2407. 'Ccedilla',
  2408. 'Eacute',
  2409. 'Ntilde',
  2410. 'Odieresis',
  2411. 'Udieresis',
  2412. 'aacute',
  2413. 'agrave',
  2414. 'acircumflex',
  2415. 'adieresis',
  2416. 'atilde',
  2417. 'aring',
  2418. 'ccedilla',
  2419. 'eacute',
  2420. 'egrave',
  2421. 'ecircumflex',
  2422. 'edieresis',
  2423. 'iacute',
  2424. 'igrave',
  2425. 'icircumflex',
  2426. 'idieresis',
  2427. 'ntilde',
  2428. 'oacute',
  2429. 'ograve',
  2430. 'ocircumflex',
  2431. 'odieresis',
  2432. 'otilde',
  2433. 'uacute',
  2434. 'ugrave',
  2435. 'ucircumflex',
  2436. 'udieresis',
  2437. 'dagger',
  2438. 'degree',
  2439. 'cent',
  2440. 'sterling',
  2441. 'section',
  2442. 'bullet',
  2443. 'paragraph',
  2444. 'germandbls',
  2445. 'registered',
  2446. 'copyright',
  2447. 'trademark',
  2448. 'acute',
  2449. 'dieresis',
  2450. 'notequal',
  2451. 'AE',
  2452. 'Oslash',
  2453. 'infinity',
  2454. 'plusminus',
  2455. 'lessequal',
  2456. 'greaterequal',
  2457. 'yen',
  2458. 'mu',
  2459. 'partialdiff',
  2460. 'summation',
  2461. 'product',
  2462. 'pi',
  2463. 'integral',
  2464. 'ordfeminine',
  2465. 'ordmasculine',
  2466. 'Omega',
  2467. 'ae',
  2468. 'oslash',
  2469. 'questiondown',
  2470. 'exclamdown',
  2471. 'logicalnot',
  2472. 'radical',
  2473. 'florin',
  2474. 'approxequal',
  2475. 'Delta',
  2476. 'guillemotleft',
  2477. 'guillemotright',
  2478. 'ellipsis',
  2479. 'space',
  2480. 'Agrave',
  2481. 'Atilde',
  2482. 'Otilde',
  2483. 'OE',
  2484. 'oe',
  2485. 'endash',
  2486. 'emdash',
  2487. 'quotedblleft',
  2488. 'quotedblright',
  2489. 'quoteleft',
  2490. 'quoteright',
  2491. 'divide',
  2492. 'lozenge',
  2493. 'ydieresis',
  2494. 'Ydieresis',
  2495. 'fraction',
  2496. 'currency',
  2497. 'guilsinglleft',
  2498. 'guilsinglright',
  2499. 'fi',
  2500. 'fl',
  2501. 'daggerdbl',
  2502. 'periodcentered',
  2503. 'quotesinglbase',
  2504. 'quotedblbase',
  2505. 'perthousand',
  2506. 'Acircumflex',
  2507. 'Ecircumflex',
  2508. 'Aacute',
  2509. 'Edieresis',
  2510. 'Egrave',
  2511. 'Iacute',
  2512. 'Icircumflex',
  2513. 'Idieresis',
  2514. 'Igrave',
  2515. 'Oacute',
  2516. 'Ocircumflex',
  2517. 'apple',
  2518. 'Ograve',
  2519. 'Uacute',
  2520. 'Ucircumflex',
  2521. 'Ugrave',
  2522. 'dotlessi',
  2523. 'circumflex',
  2524. 'tilde',
  2525. 'macron',
  2526. 'breve',
  2527. 'dotaccent',
  2528. 'ring',
  2529. 'cedilla',
  2530. 'hungarumlaut',
  2531. 'ogonek',
  2532. 'caron'
  2533. ];
  2534. var StandardEncoding = [
  2535. '',
  2536. '',
  2537. '',
  2538. '',
  2539. '',
  2540. '',
  2541. '',
  2542. '',
  2543. '',
  2544. '',
  2545. '',
  2546. '',
  2547. '',
  2548. '',
  2549. '',
  2550. '',
  2551. '',
  2552. '',
  2553. '',
  2554. '',
  2555. '',
  2556. '',
  2557. '',
  2558. '',
  2559. '',
  2560. '',
  2561. '',
  2562. '',
  2563. '',
  2564. '',
  2565. '',
  2566. '',
  2567. 'space',
  2568. 'exclam',
  2569. 'quotedbl',
  2570. 'numbersign',
  2571. 'dollar',
  2572. 'percent',
  2573. 'ampersand',
  2574. 'quoteright',
  2575. 'parenleft',
  2576. 'parenright',
  2577. 'asterisk',
  2578. 'plus',
  2579. 'comma',
  2580. 'hyphen',
  2581. 'period',
  2582. 'slash',
  2583. 'zero',
  2584. 'one',
  2585. 'two',
  2586. 'three',
  2587. 'four',
  2588. 'five',
  2589. 'six',
  2590. 'seven',
  2591. 'eight',
  2592. 'nine',
  2593. 'colon',
  2594. 'semicolon',
  2595. 'less',
  2596. 'equal',
  2597. 'greater',
  2598. 'question',
  2599. 'at',
  2600. 'A',
  2601. 'B',
  2602. 'C',
  2603. 'D',
  2604. 'E',
  2605. 'F',
  2606. 'G',
  2607. 'H',
  2608. 'I',
  2609. 'J',
  2610. 'K',
  2611. 'L',
  2612. 'M',
  2613. 'N',
  2614. 'O',
  2615. 'P',
  2616. 'Q',
  2617. 'R',
  2618. 'S',
  2619. 'T',
  2620. 'U',
  2621. 'V',
  2622. 'W',
  2623. 'X',
  2624. 'Y',
  2625. 'Z',
  2626. 'bracketleft',
  2627. 'backslash',
  2628. 'bracketright',
  2629. 'asciicircum',
  2630. 'underscore',
  2631. 'quoteleft',
  2632. 'a',
  2633. 'b',
  2634. 'c',
  2635. 'd',
  2636. 'e',
  2637. 'f',
  2638. 'g',
  2639. 'h',
  2640. 'i',
  2641. 'j',
  2642. 'k',
  2643. 'l',
  2644. 'm',
  2645. 'n',
  2646. 'o',
  2647. 'p',
  2648. 'q',
  2649. 'r',
  2650. 's',
  2651. 't',
  2652. 'u',
  2653. 'v',
  2654. 'w',
  2655. 'x',
  2656. 'y',
  2657. 'z',
  2658. 'braceleft',
  2659. 'bar',
  2660. 'braceright',
  2661. 'asciitilde',
  2662. '',
  2663. '',
  2664. '',
  2665. '',
  2666. '',
  2667. '',
  2668. '',
  2669. '',
  2670. '',
  2671. '',
  2672. '',
  2673. '',
  2674. '',
  2675. '',
  2676. '',
  2677. '',
  2678. '',
  2679. '',
  2680. '',
  2681. '',
  2682. '',
  2683. '',
  2684. '',
  2685. '',
  2686. '',
  2687. '',
  2688. '',
  2689. '',
  2690. '',
  2691. '',
  2692. '',
  2693. '',
  2694. '',
  2695. '',
  2696. 'exclamdown',
  2697. 'cent',
  2698. 'sterling',
  2699. 'fraction',
  2700. 'yen',
  2701. 'florin',
  2702. 'section',
  2703. 'currency',
  2704. 'quotesingle',
  2705. 'quotedblleft',
  2706. 'guillemotleft',
  2707. 'guilsinglleft',
  2708. 'guilsinglright',
  2709. 'fi',
  2710. 'fl',
  2711. '',
  2712. 'endash',
  2713. 'dagger',
  2714. 'daggerdbl',
  2715. 'periodcentered',
  2716. '',
  2717. 'paragraph',
  2718. 'bullet',
  2719. 'quotesinglbase',
  2720. 'quotedblbase',
  2721. 'quotedblright',
  2722. 'guillemotright',
  2723. 'ellipsis',
  2724. 'perthousand',
  2725. '',
  2726. 'questiondown',
  2727. '',
  2728. 'grave',
  2729. 'acute',
  2730. 'circumflex',
  2731. 'tilde',
  2732. 'macron',
  2733. 'breve',
  2734. 'dotaccent',
  2735. 'dieresis',
  2736. '',
  2737. 'ring',
  2738. 'cedilla',
  2739. '',
  2740. 'hungarumlaut',
  2741. 'ogonek',
  2742. 'caron',
  2743. 'emdash',
  2744. '',
  2745. '',
  2746. '',
  2747. '',
  2748. '',
  2749. '',
  2750. '',
  2751. '',
  2752. '',
  2753. '',
  2754. '',
  2755. '',
  2756. '',
  2757. '',
  2758. '',
  2759. '',
  2760. 'AE',
  2761. '',
  2762. 'ordfeminine',
  2763. '',
  2764. '',
  2765. '',
  2766. '',
  2767. 'Lslash',
  2768. 'Oslash',
  2769. 'OE',
  2770. 'ordmasculine',
  2771. '',
  2772. '',
  2773. '',
  2774. '',
  2775. '',
  2776. 'ae',
  2777. '',
  2778. '',
  2779. '',
  2780. 'dotlessi',
  2781. '',
  2782. '',
  2783. 'lslash',
  2784. 'oslash',
  2785. 'oe',
  2786. 'germandbls'
  2787. ];
  2788. var WinAnsiEncoding = [
  2789. '',
  2790. '',
  2791. '',
  2792. '',
  2793. '',
  2794. '',
  2795. '',
  2796. '',
  2797. '',
  2798. '',
  2799. '',
  2800. '',
  2801. '',
  2802. '',
  2803. '',
  2804. '',
  2805. '',
  2806. '',
  2807. '',
  2808. '',
  2809. '',
  2810. '',
  2811. '',
  2812. '',
  2813. '',
  2814. '',
  2815. '',
  2816. '',
  2817. '',
  2818. '',
  2819. '',
  2820. '',
  2821. 'space',
  2822. 'exclam',
  2823. 'quotedbl',
  2824. 'numbersign',
  2825. 'dollar',
  2826. 'percent',
  2827. 'ampersand',
  2828. 'quotesingle',
  2829. 'parenleft',
  2830. 'parenright',
  2831. 'asterisk',
  2832. 'plus',
  2833. 'comma',
  2834. 'hyphen',
  2835. 'period',
  2836. 'slash',
  2837. 'zero',
  2838. 'one',
  2839. 'two',
  2840. 'three',
  2841. 'four',
  2842. 'five',
  2843. 'six',
  2844. 'seven',
  2845. 'eight',
  2846. 'nine',
  2847. 'colon',
  2848. 'semicolon',
  2849. 'less',
  2850. 'equal',
  2851. 'greater',
  2852. 'question',
  2853. 'at',
  2854. 'A',
  2855. 'B',
  2856. 'C',
  2857. 'D',
  2858. 'E',
  2859. 'F',
  2860. 'G',
  2861. 'H',
  2862. 'I',
  2863. 'J',
  2864. 'K',
  2865. 'L',
  2866. 'M',
  2867. 'N',
  2868. 'O',
  2869. 'P',
  2870. 'Q',
  2871. 'R',
  2872. 'S',
  2873. 'T',
  2874. 'U',
  2875. 'V',
  2876. 'W',
  2877. 'X',
  2878. 'Y',
  2879. 'Z',
  2880. 'bracketleft',
  2881. 'backslash',
  2882. 'bracketright',
  2883. 'asciicircum',
  2884. 'underscore',
  2885. 'grave',
  2886. 'a',
  2887. 'b',
  2888. 'c',
  2889. 'd',
  2890. 'e',
  2891. 'f',
  2892. 'g',
  2893. 'h',
  2894. 'i',
  2895. 'j',
  2896. 'k',
  2897. 'l',
  2898. 'm',
  2899. 'n',
  2900. 'o',
  2901. 'p',
  2902. 'q',
  2903. 'r',
  2904. 's',
  2905. 't',
  2906. 'u',
  2907. 'v',
  2908. 'w',
  2909. 'x',
  2910. 'y',
  2911. 'z',
  2912. 'braceleft',
  2913. 'bar',
  2914. 'braceright',
  2915. 'asciitilde',
  2916. 'bullet',
  2917. 'Euro',
  2918. 'bullet',
  2919. 'quotesinglbase',
  2920. 'florin',
  2921. 'quotedblbase',
  2922. 'ellipsis',
  2923. 'dagger',
  2924. 'daggerdbl',
  2925. 'circumflex',
  2926. 'perthousand',
  2927. 'Scaron',
  2928. 'guilsinglleft',
  2929. 'OE',
  2930. 'bullet',
  2931. 'Zcaron',
  2932. 'bullet',
  2933. 'bullet',
  2934. 'quoteleft',
  2935. 'quoteright',
  2936. 'quotedblleft',
  2937. 'quotedblright',
  2938. 'bullet',
  2939. 'endash',
  2940. 'emdash',
  2941. 'tilde',
  2942. 'trademark',
  2943. 'scaron',
  2944. 'guilsinglright',
  2945. 'oe',
  2946. 'bullet',
  2947. 'zcaron',
  2948. 'Ydieresis',
  2949. 'space',
  2950. 'exclamdown',
  2951. 'cent',
  2952. 'sterling',
  2953. 'currency',
  2954. 'yen',
  2955. 'brokenbar',
  2956. 'section',
  2957. 'dieresis',
  2958. 'copyright',
  2959. 'ordfeminine',
  2960. 'guillemotleft',
  2961. 'logicalnot',
  2962. 'hyphen',
  2963. 'registered',
  2964. 'macron',
  2965. 'degree',
  2966. 'plusminus',
  2967. 'twosuperior',
  2968. 'threesuperior',
  2969. 'acute',
  2970. 'mu',
  2971. 'paragraph',
  2972. 'periodcentered',
  2973. 'cedilla',
  2974. 'onesuperior',
  2975. 'ordmasculine',
  2976. 'guillemotright',
  2977. 'onequarter',
  2978. 'onehalf',
  2979. 'threequarters',
  2980. 'questiondown',
  2981. 'Agrave',
  2982. 'Aacute',
  2983. 'Acircumflex',
  2984. 'Atilde',
  2985. 'Adieresis',
  2986. 'Aring',
  2987. 'AE',
  2988. 'Ccedilla',
  2989. 'Egrave',
  2990. 'Eacute',
  2991. 'Ecircumflex',
  2992. 'Edieresis',
  2993. 'Igrave',
  2994. 'Iacute',
  2995. 'Icircumflex',
  2996. 'Idieresis',
  2997. 'Eth',
  2998. 'Ntilde',
  2999. 'Ograve',
  3000. 'Oacute',
  3001. 'Ocircumflex',
  3002. 'Otilde',
  3003. 'Odieresis',
  3004. 'multiply',
  3005. 'Oslash',
  3006. 'Ugrave',
  3007. 'Uacute',
  3008. 'Ucircumflex',
  3009. 'Udieresis',
  3010. 'Yacute',
  3011. 'Thorn',
  3012. 'germandbls',
  3013. 'agrave',
  3014. 'aacute',
  3015. 'acircumflex',
  3016. 'atilde',
  3017. 'adieresis',
  3018. 'aring',
  3019. 'ae',
  3020. 'ccedilla',
  3021. 'egrave',
  3022. 'eacute',
  3023. 'ecircumflex',
  3024. 'edieresis',
  3025. 'igrave',
  3026. 'iacute',
  3027. 'icircumflex',
  3028. 'idieresis',
  3029. 'eth',
  3030. 'ntilde',
  3031. 'ograve',
  3032. 'oacute',
  3033. 'ocircumflex',
  3034. 'otilde',
  3035. 'odieresis',
  3036. 'divide',
  3037. 'oslash',
  3038. 'ugrave',
  3039. 'uacute',
  3040. 'ucircumflex',
  3041. 'udieresis',
  3042. 'yacute',
  3043. 'thorn',
  3044. 'ydieresis'
  3045. ];
  3046. var SymbolSetEncoding = [
  3047. '',
  3048. '',
  3049. '',
  3050. '',
  3051. '',
  3052. '',
  3053. '',
  3054. '',
  3055. '',
  3056. '',
  3057. '',
  3058. '',
  3059. '',
  3060. '',
  3061. '',
  3062. '',
  3063. '',
  3064. '',
  3065. '',
  3066. '',
  3067. '',
  3068. '',
  3069. '',
  3070. '',
  3071. '',
  3072. '',
  3073. '',
  3074. '',
  3075. '',
  3076. '',
  3077. '',
  3078. '',
  3079. 'space',
  3080. 'exclam',
  3081. 'universal',
  3082. 'numbersign',
  3083. 'existential',
  3084. 'percent',
  3085. 'ampersand',
  3086. 'suchthat',
  3087. 'parenleft',
  3088. 'parenright',
  3089. 'asteriskmath',
  3090. 'plus',
  3091. 'comma',
  3092. 'minus',
  3093. 'period',
  3094. 'slash',
  3095. 'zero',
  3096. 'one',
  3097. 'two',
  3098. 'three',
  3099. 'four',
  3100. 'five',
  3101. 'six',
  3102. 'seven',
  3103. 'eight',
  3104. 'nine',
  3105. 'colon',
  3106. 'semicolon',
  3107. 'less',
  3108. 'equal',
  3109. 'greater',
  3110. 'question',
  3111. 'congruent',
  3112. 'Alpha',
  3113. 'Beta',
  3114. 'Chi',
  3115. 'Delta',
  3116. 'Epsilon',
  3117. 'Phi',
  3118. 'Gamma',
  3119. 'Eta',
  3120. 'Iota',
  3121. 'theta1',
  3122. 'Kappa',
  3123. 'Lambda',
  3124. 'Mu',
  3125. 'Nu',
  3126. 'Omicron',
  3127. 'Pi',
  3128. 'Theta',
  3129. 'Rho',
  3130. 'Sigma',
  3131. 'Tau',
  3132. 'Upsilon',
  3133. 'sigma1',
  3134. 'Omega',
  3135. 'Xi',
  3136. 'Psi',
  3137. 'Zeta',
  3138. 'bracketleft',
  3139. 'therefore',
  3140. 'bracketright',
  3141. 'perpendicular',
  3142. 'underscore',
  3143. 'radicalex',
  3144. 'alpha',
  3145. 'beta',
  3146. 'chi',
  3147. 'delta',
  3148. 'epsilon',
  3149. 'phi',
  3150. 'gamma',
  3151. 'eta',
  3152. 'iota',
  3153. 'phi1',
  3154. 'kappa',
  3155. 'lambda',
  3156. 'mu',
  3157. 'nu',
  3158. 'omicron',
  3159. 'pi',
  3160. 'theta',
  3161. 'rho',
  3162. 'sigma',
  3163. 'tau',
  3164. 'upsilon',
  3165. 'omega1',
  3166. 'omega',
  3167. 'xi',
  3168. 'psi',
  3169. 'zeta',
  3170. 'braceleft',
  3171. 'bar',
  3172. 'braceright',
  3173. 'similar',
  3174. '',
  3175. '',
  3176. '',
  3177. '',
  3178. '',
  3179. '',
  3180. '',
  3181. '',
  3182. '',
  3183. '',
  3184. '',
  3185. '',
  3186. '',
  3187. '',
  3188. '',
  3189. '',
  3190. '',
  3191. '',
  3192. '',
  3193. '',
  3194. '',
  3195. '',
  3196. '',
  3197. '',
  3198. '',
  3199. '',
  3200. '',
  3201. '',
  3202. '',
  3203. '',
  3204. '',
  3205. '',
  3206. '',
  3207. 'Euro',
  3208. 'Upsilon1',
  3209. 'minute',
  3210. 'lessequal',
  3211. 'fraction',
  3212. 'infinity',
  3213. 'florin',
  3214. 'club',
  3215. 'diamond',
  3216. 'heart',
  3217. 'spade',
  3218. 'arrowboth',
  3219. 'arrowleft',
  3220. 'arrowup',
  3221. 'arrowright',
  3222. 'arrowdown',
  3223. 'degree',
  3224. 'plusminus',
  3225. 'second',
  3226. 'greaterequal',
  3227. 'multiply',
  3228. 'proportional',
  3229. 'partialdiff',
  3230. 'bullet',
  3231. 'divide',
  3232. 'notequal',
  3233. 'equivalence',
  3234. 'approxequal',
  3235. 'ellipsis',
  3236. 'arrowvertex',
  3237. 'arrowhorizex',
  3238. 'carriagereturn',
  3239. 'aleph',
  3240. 'Ifraktur',
  3241. 'Rfraktur',
  3242. 'weierstrass',
  3243. 'circlemultiply',
  3244. 'circleplus',
  3245. 'emptyset',
  3246. 'intersection',
  3247. 'union',
  3248. 'propersuperset',
  3249. 'reflexsuperset',
  3250. 'notsubset',
  3251. 'propersubset',
  3252. 'reflexsubset',
  3253. 'element',
  3254. 'notelement',
  3255. 'angle',
  3256. 'gradient',
  3257. 'registerserif',
  3258. 'copyrightserif',
  3259. 'trademarkserif',
  3260. 'product',
  3261. 'radical',
  3262. 'dotmath',
  3263. 'logicalnot',
  3264. 'logicaland',
  3265. 'logicalor',
  3266. 'arrowdblboth',
  3267. 'arrowdblleft',
  3268. 'arrowdblup',
  3269. 'arrowdblright',
  3270. 'arrowdbldown',
  3271. 'lozenge',
  3272. 'angleleft',
  3273. 'registersans',
  3274. 'copyrightsans',
  3275. 'trademarksans',
  3276. 'summation',
  3277. 'parenlefttp',
  3278. 'parenleftex',
  3279. 'parenleftbt',
  3280. 'bracketlefttp',
  3281. 'bracketleftex',
  3282. 'bracketleftbt',
  3283. 'bracelefttp',
  3284. 'braceleftmid',
  3285. 'braceleftbt',
  3286. 'braceex',
  3287. '',
  3288. 'angleright',
  3289. 'integral',
  3290. 'integraltp',
  3291. 'integralex',
  3292. 'integralbt',
  3293. 'parenrighttp',
  3294. 'parenrightex',
  3295. 'parenrightbt',
  3296. 'bracketrighttp',
  3297. 'bracketrightex',
  3298. 'bracketrightbt',
  3299. 'bracerighttp',
  3300. 'bracerightmid',
  3301. 'bracerightbt'
  3302. ];
  3303. var ZapfDingbatsEncoding = [
  3304. '',
  3305. '',
  3306. '',
  3307. '',
  3308. '',
  3309. '',
  3310. '',
  3311. '',
  3312. '',
  3313. '',
  3314. '',
  3315. '',
  3316. '',
  3317. '',
  3318. '',
  3319. '',
  3320. '',
  3321. '',
  3322. '',
  3323. '',
  3324. '',
  3325. '',
  3326. '',
  3327. '',
  3328. '',
  3329. '',
  3330. '',
  3331. '',
  3332. '',
  3333. '',
  3334. '',
  3335. '',
  3336. 'space',
  3337. 'a1',
  3338. 'a2',
  3339. 'a202',
  3340. 'a3',
  3341. 'a4',
  3342. 'a5',
  3343. 'a119',
  3344. 'a118',
  3345. 'a117',
  3346. 'a11',
  3347. 'a12',
  3348. 'a13',
  3349. 'a14',
  3350. 'a15',
  3351. 'a16',
  3352. 'a105',
  3353. 'a17',
  3354. 'a18',
  3355. 'a19',
  3356. 'a20',
  3357. 'a21',
  3358. 'a22',
  3359. 'a23',
  3360. 'a24',
  3361. 'a25',
  3362. 'a26',
  3363. 'a27',
  3364. 'a28',
  3365. 'a6',
  3366. 'a7',
  3367. 'a8',
  3368. 'a9',
  3369. 'a10',
  3370. 'a29',
  3371. 'a30',
  3372. 'a31',
  3373. 'a32',
  3374. 'a33',
  3375. 'a34',
  3376. 'a35',
  3377. 'a36',
  3378. 'a37',
  3379. 'a38',
  3380. 'a39',
  3381. 'a40',
  3382. 'a41',
  3383. 'a42',
  3384. 'a43',
  3385. 'a44',
  3386. 'a45',
  3387. 'a46',
  3388. 'a47',
  3389. 'a48',
  3390. 'a49',
  3391. 'a50',
  3392. 'a51',
  3393. 'a52',
  3394. 'a53',
  3395. 'a54',
  3396. 'a55',
  3397. 'a56',
  3398. 'a57',
  3399. 'a58',
  3400. 'a59',
  3401. 'a60',
  3402. 'a61',
  3403. 'a62',
  3404. 'a63',
  3405. 'a64',
  3406. 'a65',
  3407. 'a66',
  3408. 'a67',
  3409. 'a68',
  3410. 'a69',
  3411. 'a70',
  3412. 'a71',
  3413. 'a72',
  3414. 'a73',
  3415. 'a74',
  3416. 'a203',
  3417. 'a75',
  3418. 'a204',
  3419. 'a76',
  3420. 'a77',
  3421. 'a78',
  3422. 'a79',
  3423. 'a81',
  3424. 'a82',
  3425. 'a83',
  3426. 'a84',
  3427. 'a97',
  3428. 'a98',
  3429. 'a99',
  3430. 'a100',
  3431. '',
  3432. 'a89',
  3433. 'a90',
  3434. 'a93',
  3435. 'a94',
  3436. 'a91',
  3437. 'a92',
  3438. 'a205',
  3439. 'a85',
  3440. 'a206',
  3441. 'a86',
  3442. 'a87',
  3443. 'a88',
  3444. 'a95',
  3445. 'a96',
  3446. '',
  3447. '',
  3448. '',
  3449. '',
  3450. '',
  3451. '',
  3452. '',
  3453. '',
  3454. '',
  3455. '',
  3456. '',
  3457. '',
  3458. '',
  3459. '',
  3460. '',
  3461. '',
  3462. '',
  3463. '',
  3464. '',
  3465. 'a101',
  3466. 'a102',
  3467. 'a103',
  3468. 'a104',
  3469. 'a106',
  3470. 'a107',
  3471. 'a108',
  3472. 'a112',
  3473. 'a111',
  3474. 'a110',
  3475. 'a109',
  3476. 'a120',
  3477. 'a121',
  3478. 'a122',
  3479. 'a123',
  3480. 'a124',
  3481. 'a125',
  3482. 'a126',
  3483. 'a127',
  3484. 'a128',
  3485. 'a129',
  3486. 'a130',
  3487. 'a131',
  3488. 'a132',
  3489. 'a133',
  3490. 'a134',
  3491. 'a135',
  3492. 'a136',
  3493. 'a137',
  3494. 'a138',
  3495. 'a139',
  3496. 'a140',
  3497. 'a141',
  3498. 'a142',
  3499. 'a143',
  3500. 'a144',
  3501. 'a145',
  3502. 'a146',
  3503. 'a147',
  3504. 'a148',
  3505. 'a149',
  3506. 'a150',
  3507. 'a151',
  3508. 'a152',
  3509. 'a153',
  3510. 'a154',
  3511. 'a155',
  3512. 'a156',
  3513. 'a157',
  3514. 'a158',
  3515. 'a159',
  3516. 'a160',
  3517. 'a161',
  3518. 'a163',
  3519. 'a164',
  3520. 'a196',
  3521. 'a165',
  3522. 'a192',
  3523. 'a166',
  3524. 'a167',
  3525. 'a168',
  3526. 'a169',
  3527. 'a170',
  3528. 'a171',
  3529. 'a172',
  3530. 'a173',
  3531. 'a162',
  3532. 'a174',
  3533. 'a175',
  3534. 'a176',
  3535. 'a177',
  3536. 'a178',
  3537. 'a179',
  3538. 'a193',
  3539. 'a180',
  3540. 'a199',
  3541. 'a181',
  3542. 'a200',
  3543. 'a182',
  3544. '',
  3545. 'a201',
  3546. 'a183',
  3547. 'a184',
  3548. 'a197',
  3549. 'a185',
  3550. 'a194',
  3551. 'a198',
  3552. 'a186',
  3553. 'a195',
  3554. 'a187',
  3555. 'a188',
  3556. 'a189',
  3557. 'a190',
  3558. 'a191'
  3559. ];
  3560. function getEncoding(encodingName) {
  3561. switch (encodingName) {
  3562. case 'WinAnsiEncoding':
  3563. return WinAnsiEncoding;
  3564. case 'StandardEncoding':
  3565. return StandardEncoding;
  3566. case 'MacRomanEncoding':
  3567. return MacRomanEncoding;
  3568. case 'SymbolSetEncoding':
  3569. return SymbolSetEncoding;
  3570. case 'ZapfDingbatsEncoding':
  3571. return ZapfDingbatsEncoding;
  3572. case 'ExpertEncoding':
  3573. return ExpertEncoding;
  3574. case 'MacExpertEncoding':
  3575. return MacExpertEncoding;
  3576. default:
  3577. return null;
  3578. }
  3579. }
  3580. exports.WinAnsiEncoding = WinAnsiEncoding;
  3581. exports.StandardEncoding = StandardEncoding;
  3582. exports.MacRomanEncoding = MacRomanEncoding;
  3583. exports.SymbolSetEncoding = SymbolSetEncoding;
  3584. exports.ZapfDingbatsEncoding = ZapfDingbatsEncoding;
  3585. exports.ExpertEncoding = ExpertEncoding;
  3586. exports.getEncoding = getEncoding;
  3587. }));
  3588. (function (root, factory) {
  3589. factory(root.pdfjsSharedUtil = {});
  3590. }(this, function (exports) {
  3591. var globalScope = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : this;
  3592. var FONT_IDENTITY_MATRIX = [
  3593. 0.001,
  3594. 0,
  3595. 0,
  3596. 0.001,
  3597. 0,
  3598. 0
  3599. ];
  3600. var TextRenderingMode = {
  3601. FILL: 0,
  3602. STROKE: 1,
  3603. FILL_STROKE: 2,
  3604. INVISIBLE: 3,
  3605. FILL_ADD_TO_PATH: 4,
  3606. STROKE_ADD_TO_PATH: 5,
  3607. FILL_STROKE_ADD_TO_PATH: 6,
  3608. ADD_TO_PATH: 7,
  3609. FILL_STROKE_MASK: 3,
  3610. ADD_TO_PATH_FLAG: 4
  3611. };
  3612. var ImageKind = {
  3613. GRAYSCALE_1BPP: 1,
  3614. RGB_24BPP: 2,
  3615. RGBA_32BPP: 3
  3616. };
  3617. var AnnotationType = {
  3618. TEXT: 1,
  3619. LINK: 2,
  3620. FREETEXT: 3,
  3621. LINE: 4,
  3622. SQUARE: 5,
  3623. CIRCLE: 6,
  3624. POLYGON: 7,
  3625. POLYLINE: 8,
  3626. HIGHLIGHT: 9,
  3627. UNDERLINE: 10,
  3628. SQUIGGLY: 11,
  3629. STRIKEOUT: 12,
  3630. STAMP: 13,
  3631. CARET: 14,
  3632. INK: 15,
  3633. POPUP: 16,
  3634. FILEATTACHMENT: 17,
  3635. SOUND: 18,
  3636. MOVIE: 19,
  3637. WIDGET: 20,
  3638. SCREEN: 21,
  3639. PRINTERMARK: 22,
  3640. TRAPNET: 23,
  3641. WATERMARK: 24,
  3642. THREED: 25,
  3643. REDACT: 26
  3644. };
  3645. var AnnotationFlag = {
  3646. INVISIBLE: 0x01,
  3647. HIDDEN: 0x02,
  3648. PRINT: 0x04,
  3649. NOZOOM: 0x08,
  3650. NOROTATE: 0x10,
  3651. NOVIEW: 0x20,
  3652. READONLY: 0x40,
  3653. LOCKED: 0x80,
  3654. TOGGLENOVIEW: 0x100,
  3655. LOCKEDCONTENTS: 0x200
  3656. };
  3657. var AnnotationFieldFlag = {
  3658. READONLY: 0x0000001,
  3659. REQUIRED: 0x0000002,
  3660. NOEXPORT: 0x0000004,
  3661. MULTILINE: 0x0001000,
  3662. PASSWORD: 0x0002000,
  3663. NOTOGGLETOOFF: 0x0004000,
  3664. RADIO: 0x0008000,
  3665. PUSHBUTTON: 0x0010000,
  3666. COMBO: 0x0020000,
  3667. EDIT: 0x0040000,
  3668. SORT: 0x0080000,
  3669. FILESELECT: 0x0100000,
  3670. MULTISELECT: 0x0200000,
  3671. DONOTSPELLCHECK: 0x0400000,
  3672. DONOTSCROLL: 0x0800000,
  3673. COMB: 0x1000000,
  3674. RICHTEXT: 0x2000000,
  3675. RADIOSINUNISON: 0x2000000,
  3676. COMMITONSELCHANGE: 0x4000000
  3677. };
  3678. var AnnotationBorderStyleType = {
  3679. SOLID: 1,
  3680. DASHED: 2,
  3681. BEVELED: 3,
  3682. INSET: 4,
  3683. UNDERLINE: 5
  3684. };
  3685. var StreamType = {
  3686. UNKNOWN: 0,
  3687. FLATE: 1,
  3688. LZW: 2,
  3689. DCT: 3,
  3690. JPX: 4,
  3691. JBIG: 5,
  3692. A85: 6,
  3693. AHX: 7,
  3694. CCF: 8,
  3695. RL: 9
  3696. };
  3697. var FontType = {
  3698. UNKNOWN: 0,
  3699. TYPE1: 1,
  3700. TYPE1C: 2,
  3701. CIDFONTTYPE0: 3,
  3702. CIDFONTTYPE0C: 4,
  3703. TRUETYPE: 5,
  3704. CIDFONTTYPE2: 6,
  3705. TYPE3: 7,
  3706. OPENTYPE: 8,
  3707. TYPE0: 9,
  3708. MMTYPE1: 10
  3709. };
  3710. var VERBOSITY_LEVELS = {
  3711. errors: 0,
  3712. warnings: 1,
  3713. infos: 5
  3714. };
  3715. // All the possible operations for an operator list.
  3716. var OPS = {
  3717. // Intentionally start from 1 so it is easy to spot bad operators that will be
  3718. // 0's.
  3719. dependency: 1,
  3720. setLineWidth: 2,
  3721. setLineCap: 3,
  3722. setLineJoin: 4,
  3723. setMiterLimit: 5,
  3724. setDash: 6,
  3725. setRenderingIntent: 7,
  3726. setFlatness: 8,
  3727. setGState: 9,
  3728. save: 10,
  3729. restore: 11,
  3730. transform: 12,
  3731. moveTo: 13,
  3732. lineTo: 14,
  3733. curveTo: 15,
  3734. curveTo2: 16,
  3735. curveTo3: 17,
  3736. closePath: 18,
  3737. rectangle: 19,
  3738. stroke: 20,
  3739. closeStroke: 21,
  3740. fill: 22,
  3741. eoFill: 23,
  3742. fillStroke: 24,
  3743. eoFillStroke: 25,
  3744. closeFillStroke: 26,
  3745. closeEOFillStroke: 27,
  3746. endPath: 28,
  3747. clip: 29,
  3748. eoClip: 30,
  3749. beginText: 31,
  3750. endText: 32,
  3751. setCharSpacing: 33,
  3752. setWordSpacing: 34,
  3753. setHScale: 35,
  3754. setLeading: 36,
  3755. setFont: 37,
  3756. setTextRenderingMode: 38,
  3757. setTextRise: 39,
  3758. moveText: 40,
  3759. setLeadingMoveText: 41,
  3760. setTextMatrix: 42,
  3761. nextLine: 43,
  3762. showText: 44,
  3763. showSpacedText: 45,
  3764. nextLineShowText: 46,
  3765. nextLineSetSpacingShowText: 47,
  3766. setCharWidth: 48,
  3767. setCharWidthAndBounds: 49,
  3768. setStrokeColorSpace: 50,
  3769. setFillColorSpace: 51,
  3770. setStrokeColor: 52,
  3771. setStrokeColorN: 53,
  3772. setFillColor: 54,
  3773. setFillColorN: 55,
  3774. setStrokeGray: 56,
  3775. setFillGray: 57,
  3776. setStrokeRGBColor: 58,
  3777. setFillRGBColor: 59,
  3778. setStrokeCMYKColor: 60,
  3779. setFillCMYKColor: 61,
  3780. shadingFill: 62,
  3781. beginInlineImage: 63,
  3782. beginImageData: 64,
  3783. endInlineImage: 65,
  3784. paintXObject: 66,
  3785. markPoint: 67,
  3786. markPointProps: 68,
  3787. beginMarkedContent: 69,
  3788. beginMarkedContentProps: 70,
  3789. endMarkedContent: 71,
  3790. beginCompat: 72,
  3791. endCompat: 73,
  3792. paintFormXObjectBegin: 74,
  3793. paintFormXObjectEnd: 75,
  3794. beginGroup: 76,
  3795. endGroup: 77,
  3796. beginAnnotations: 78,
  3797. endAnnotations: 79,
  3798. beginAnnotation: 80,
  3799. endAnnotation: 81,
  3800. paintJpegXObject: 82,
  3801. paintImageMaskXObject: 83,
  3802. paintImageMaskXObjectGroup: 84,
  3803. paintImageXObject: 85,
  3804. paintInlineImageXObject: 86,
  3805. paintInlineImageXObjectGroup: 87,
  3806. paintImageXObjectRepeat: 88,
  3807. paintImageMaskXObjectRepeat: 89,
  3808. paintSolidColorImageMask: 90,
  3809. constructPath: 91
  3810. };
  3811. var verbosity = VERBOSITY_LEVELS.warnings;
  3812. function setVerbosityLevel(level) {
  3813. verbosity = level;
  3814. }
  3815. function getVerbosityLevel() {
  3816. return verbosity;
  3817. }
  3818. // A notice for devs. These are good for things that are helpful to devs, such
  3819. // as warning that Workers were disabled, which is important to devs but not
  3820. // end users.
  3821. function info(msg) {
  3822. if (verbosity >= VERBOSITY_LEVELS.infos) {
  3823. console.log('Info: ' + msg);
  3824. }
  3825. }
  3826. // Non-fatal warnings.
  3827. function warn(msg) {
  3828. if (verbosity >= VERBOSITY_LEVELS.warnings) {
  3829. console.log('Warning: ' + msg);
  3830. }
  3831. }
  3832. // Deprecated API function -- display regardless of the PDFJS.verbosity setting.
  3833. function deprecated(details) {
  3834. console.log('Deprecated API usage: ' + details);
  3835. }
  3836. // Fatal errors that should trigger the fallback UI and halt execution by
  3837. // throwing an exception.
  3838. function error(msg) {
  3839. if (verbosity >= VERBOSITY_LEVELS.errors) {
  3840. console.log('Error: ' + msg);
  3841. console.log(backtrace());
  3842. }
  3843. throw new Error(msg);
  3844. }
  3845. function backtrace() {
  3846. try {
  3847. throw new Error();
  3848. } catch (e) {
  3849. return e.stack ? e.stack.split('\n').slice(2).join('\n') : '';
  3850. }
  3851. }
  3852. function assert(cond, msg) {
  3853. if (!cond) {
  3854. error(msg);
  3855. }
  3856. }
  3857. var UNSUPPORTED_FEATURES = {
  3858. unknown: 'unknown',
  3859. forms: 'forms',
  3860. javaScript: 'javaScript',
  3861. smask: 'smask',
  3862. shadingPattern: 'shadingPattern',
  3863. font: 'font'
  3864. };
  3865. // Checks if URLs have the same origin. For non-HTTP based URLs, returns false.
  3866. function isSameOrigin(baseUrl, otherUrl) {
  3867. try {
  3868. var base = new URL(baseUrl);
  3869. if (!base.origin || base.origin === 'null') {
  3870. return false;
  3871. }
  3872. } // non-HTTP url
  3873. catch (e) {
  3874. return false;
  3875. }
  3876. var other = new URL(otherUrl, base);
  3877. return base.origin === other.origin;
  3878. }
  3879. // Validates if URL is safe and allowed, e.g. to avoid XSS.
  3880. function isValidUrl(url, allowRelative) {
  3881. if (!url || typeof url !== 'string') {
  3882. return false;
  3883. }
  3884. // RFC 3986 (http://tools.ietf.org/html/rfc3986#section-3.1)
  3885. // scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
  3886. var protocol = /^[a-z][a-z0-9+\-.]*(?=:)/i.exec(url);
  3887. if (!protocol) {
  3888. return allowRelative;
  3889. }
  3890. protocol = protocol[0].toLowerCase();
  3891. switch (protocol) {
  3892. case 'http':
  3893. case 'https':
  3894. case 'ftp':
  3895. case 'mailto':
  3896. case 'tel':
  3897. return true;
  3898. default:
  3899. return false;
  3900. }
  3901. }
  3902. function shadow(obj, prop, value) {
  3903. Object.defineProperty(obj, prop, {
  3904. value: value,
  3905. enumerable: true,
  3906. configurable: true,
  3907. writable: false
  3908. });
  3909. return value;
  3910. }
  3911. function getLookupTableFactory(initializer) {
  3912. var lookup;
  3913. return function () {
  3914. if (initializer) {
  3915. lookup = Object.create(null);
  3916. initializer(lookup);
  3917. initializer = null;
  3918. }
  3919. return lookup;
  3920. };
  3921. }
  3922. var PasswordResponses = {
  3923. NEED_PASSWORD: 1,
  3924. INCORRECT_PASSWORD: 2
  3925. };
  3926. var PasswordException = function PasswordExceptionClosure() {
  3927. function PasswordException(msg, code) {
  3928. this.name = 'PasswordException';
  3929. this.message = msg;
  3930. this.code = code;
  3931. }
  3932. PasswordException.prototype = new Error();
  3933. PasswordException.constructor = PasswordException;
  3934. return PasswordException;
  3935. }();
  3936. var UnknownErrorException = function UnknownErrorExceptionClosure() {
  3937. function UnknownErrorException(msg, details) {
  3938. this.name = 'UnknownErrorException';
  3939. this.message = msg;
  3940. this.details = details;
  3941. }
  3942. UnknownErrorException.prototype = new Error();
  3943. UnknownErrorException.constructor = UnknownErrorException;
  3944. return UnknownErrorException;
  3945. }();
  3946. var InvalidPDFException = function InvalidPDFExceptionClosure() {
  3947. function InvalidPDFException(msg) {
  3948. this.name = 'InvalidPDFException';
  3949. this.message = msg;
  3950. }
  3951. InvalidPDFException.prototype = new Error();
  3952. InvalidPDFException.constructor = InvalidPDFException;
  3953. return InvalidPDFException;
  3954. }();
  3955. var MissingPDFException = function MissingPDFExceptionClosure() {
  3956. function MissingPDFException(msg) {
  3957. this.name = 'MissingPDFException';
  3958. this.message = msg;
  3959. }
  3960. MissingPDFException.prototype = new Error();
  3961. MissingPDFException.constructor = MissingPDFException;
  3962. return MissingPDFException;
  3963. }();
  3964. var UnexpectedResponseException = function UnexpectedResponseExceptionClosure() {
  3965. function UnexpectedResponseException(msg, status) {
  3966. this.name = 'UnexpectedResponseException';
  3967. this.message = msg;
  3968. this.status = status;
  3969. }
  3970. UnexpectedResponseException.prototype = new Error();
  3971. UnexpectedResponseException.constructor = UnexpectedResponseException;
  3972. return UnexpectedResponseException;
  3973. }();
  3974. var NotImplementedException = function NotImplementedExceptionClosure() {
  3975. function NotImplementedException(msg) {
  3976. this.message = msg;
  3977. }
  3978. NotImplementedException.prototype = new Error();
  3979. NotImplementedException.prototype.name = 'NotImplementedException';
  3980. NotImplementedException.constructor = NotImplementedException;
  3981. return NotImplementedException;
  3982. }();
  3983. var MissingDataException = function MissingDataExceptionClosure() {
  3984. function MissingDataException(begin, end) {
  3985. this.begin = begin;
  3986. this.end = end;
  3987. this.message = 'Missing data [' + begin + ', ' + end + ')';
  3988. }
  3989. MissingDataException.prototype = new Error();
  3990. MissingDataException.prototype.name = 'MissingDataException';
  3991. MissingDataException.constructor = MissingDataException;
  3992. return MissingDataException;
  3993. }();
  3994. var XRefParseException = function XRefParseExceptionClosure() {
  3995. function XRefParseException(msg) {
  3996. this.message = msg;
  3997. }
  3998. XRefParseException.prototype = new Error();
  3999. XRefParseException.prototype.name = 'XRefParseException';
  4000. XRefParseException.constructor = XRefParseException;
  4001. return XRefParseException;
  4002. }();
  4003. var NullCharactersRegExp = /\x00/g;
  4004. function removeNullCharacters(str) {
  4005. if (typeof str !== 'string') {
  4006. warn('The argument for removeNullCharacters must be a string.');
  4007. return str;
  4008. }
  4009. return str.replace(NullCharactersRegExp, '');
  4010. }
  4011. function bytesToString(bytes) {
  4012. assert(bytes !== null && typeof bytes === 'object' && bytes.length !== undefined, 'Invalid argument for bytesToString');
  4013. var length = bytes.length;
  4014. var MAX_ARGUMENT_COUNT = 8192;
  4015. if (length < MAX_ARGUMENT_COUNT) {
  4016. return String.fromCharCode.apply(null, bytes);
  4017. }
  4018. var strBuf = [];
  4019. for (var i = 0; i < length; i += MAX_ARGUMENT_COUNT) {
  4020. var chunkEnd = Math.min(i + MAX_ARGUMENT_COUNT, length);
  4021. var chunk = bytes.subarray(i, chunkEnd);
  4022. strBuf.push(String.fromCharCode.apply(null, chunk));
  4023. }
  4024. return strBuf.join('');
  4025. }
  4026. function stringToBytes(str) {
  4027. assert(typeof str === 'string', 'Invalid argument for stringToBytes');
  4028. var length = str.length;
  4029. var bytes = new Uint8Array(length);
  4030. for (var i = 0; i < length; ++i) {
  4031. bytes[i] = str.charCodeAt(i) & 0xFF;
  4032. }
  4033. return bytes;
  4034. }
  4035. /**
  4036. * Gets length of the array (Array, Uint8Array, or string) in bytes.
  4037. * @param {Array|Uint8Array|string} arr
  4038. * @returns {number}
  4039. */
  4040. function arrayByteLength(arr) {
  4041. if (arr.length !== undefined) {
  4042. return arr.length;
  4043. }
  4044. assert(arr.byteLength !== undefined);
  4045. return arr.byteLength;
  4046. }
  4047. /**
  4048. * Combines array items (arrays) into single Uint8Array object.
  4049. * @param {Array} arr - the array of the arrays (Array, Uint8Array, or string).
  4050. * @returns {Uint8Array}
  4051. */
  4052. function arraysToBytes(arr) {
  4053. // Shortcut: if first and only item is Uint8Array, return it.
  4054. if (arr.length === 1 && arr[0] instanceof Uint8Array) {
  4055. return arr[0];
  4056. }
  4057. var resultLength = 0;
  4058. var i, ii = arr.length;
  4059. var item, itemLength;
  4060. for (i = 0; i < ii; i++) {
  4061. item = arr[i];
  4062. itemLength = arrayByteLength(item);
  4063. resultLength += itemLength;
  4064. }
  4065. var pos = 0;
  4066. var data = new Uint8Array(resultLength);
  4067. for (i = 0; i < ii; i++) {
  4068. item = arr[i];
  4069. if (!(item instanceof Uint8Array)) {
  4070. if (typeof item === 'string') {
  4071. item = stringToBytes(item);
  4072. } else {
  4073. item = new Uint8Array(item);
  4074. }
  4075. }
  4076. itemLength = item.byteLength;
  4077. data.set(item, pos);
  4078. pos += itemLength;
  4079. }
  4080. return data;
  4081. }
  4082. function string32(value) {
  4083. return String.fromCharCode(value >> 24 & 0xff, value >> 16 & 0xff, value >> 8 & 0xff, value & 0xff);
  4084. }
  4085. function log2(x) {
  4086. var n = 1, i = 0;
  4087. while (x > n) {
  4088. n <<= 1;
  4089. i++;
  4090. }
  4091. return i;
  4092. }
  4093. function readInt8(data, start) {
  4094. return data[start] << 24 >> 24;
  4095. }
  4096. function readUint16(data, offset) {
  4097. return data[offset] << 8 | data[offset + 1];
  4098. }
  4099. function readUint32(data, offset) {
  4100. return (data[offset] << 24 | data[offset + 1] << 16 | data[offset + 2] << 8 | data[offset + 3]) >>> 0;
  4101. }
  4102. // Lazy test the endianness of the platform
  4103. // NOTE: This will be 'true' for simulated TypedArrays
  4104. function isLittleEndian() {
  4105. var buffer8 = new Uint8Array(2);
  4106. buffer8[0] = 1;
  4107. var buffer16 = new Uint16Array(buffer8.buffer);
  4108. return buffer16[0] === 1;
  4109. }
  4110. // Checks if it's possible to eval JS expressions.
  4111. function isEvalSupported() {
  4112. try {
  4113. new Function('');
  4114. return true;
  4115. } catch (e) {
  4116. return false;
  4117. }
  4118. }
  4119. var Uint32ArrayView = function Uint32ArrayViewClosure() {
  4120. function Uint32ArrayView(buffer, length) {
  4121. this.buffer = buffer;
  4122. this.byteLength = buffer.length;
  4123. this.length = length === undefined ? this.byteLength >> 2 : length;
  4124. ensureUint32ArrayViewProps(this.length);
  4125. }
  4126. Uint32ArrayView.prototype = Object.create(null);
  4127. var uint32ArrayViewSetters = 0;
  4128. function createUint32ArrayProp(index) {
  4129. return {
  4130. get: function () {
  4131. var buffer = this.buffer, offset = index << 2;
  4132. return (buffer[offset] | buffer[offset + 1] << 8 | buffer[offset + 2] << 16 | buffer[offset + 3] << 24) >>> 0;
  4133. },
  4134. set: function (value) {
  4135. var buffer = this.buffer, offset = index << 2;
  4136. buffer[offset] = value & 255;
  4137. buffer[offset + 1] = value >> 8 & 255;
  4138. buffer[offset + 2] = value >> 16 & 255;
  4139. buffer[offset + 3] = value >>> 24 & 255;
  4140. }
  4141. };
  4142. }
  4143. function ensureUint32ArrayViewProps(length) {
  4144. while (uint32ArrayViewSetters < length) {
  4145. Object.defineProperty(Uint32ArrayView.prototype, uint32ArrayViewSetters, createUint32ArrayProp(uint32ArrayViewSetters));
  4146. uint32ArrayViewSetters++;
  4147. }
  4148. }
  4149. return Uint32ArrayView;
  4150. }();
  4151. exports.Uint32ArrayView = Uint32ArrayView;
  4152. var IDENTITY_MATRIX = [
  4153. 1,
  4154. 0,
  4155. 0,
  4156. 1,
  4157. 0,
  4158. 0
  4159. ];
  4160. var Util = function UtilClosure() {
  4161. function Util() {
  4162. }
  4163. var rgbBuf = [
  4164. 'rgb(',
  4165. 0,
  4166. ',',
  4167. 0,
  4168. ',',
  4169. 0,
  4170. ')'
  4171. ];
  4172. // makeCssRgb() can be called thousands of times. Using |rgbBuf| avoids
  4173. // creating many intermediate strings.
  4174. Util.makeCssRgb = function Util_makeCssRgb(r, g, b) {
  4175. rgbBuf[1] = r;
  4176. rgbBuf[3] = g;
  4177. rgbBuf[5] = b;
  4178. return rgbBuf.join('');
  4179. };
  4180. // Concatenates two transformation matrices together and returns the result.
  4181. Util.transform = function Util_transform(m1, m2) {
  4182. return [
  4183. m1[0] * m2[0] + m1[2] * m2[1],
  4184. m1[1] * m2[0] + m1[3] * m2[1],
  4185. m1[0] * m2[2] + m1[2] * m2[3],
  4186. m1[1] * m2[2] + m1[3] * m2[3],
  4187. m1[0] * m2[4] + m1[2] * m2[5] + m1[4],
  4188. m1[1] * m2[4] + m1[3] * m2[5] + m1[5]
  4189. ];
  4190. };
  4191. // For 2d affine transforms
  4192. Util.applyTransform = function Util_applyTransform(p, m) {
  4193. var xt = p[0] * m[0] + p[1] * m[2] + m[4];
  4194. var yt = p[0] * m[1] + p[1] * m[3] + m[5];
  4195. return [
  4196. xt,
  4197. yt
  4198. ];
  4199. };
  4200. Util.applyInverseTransform = function Util_applyInverseTransform(p, m) {
  4201. var d = m[0] * m[3] - m[1] * m[2];
  4202. var xt = (p[0] * m[3] - p[1] * m[2] + m[2] * m[5] - m[4] * m[3]) / d;
  4203. var yt = (-p[0] * m[1] + p[1] * m[0] + m[4] * m[1] - m[5] * m[0]) / d;
  4204. return [
  4205. xt,
  4206. yt
  4207. ];
  4208. };
  4209. // Applies the transform to the rectangle and finds the minimum axially
  4210. // aligned bounding box.
  4211. Util.getAxialAlignedBoundingBox = function Util_getAxialAlignedBoundingBox(r, m) {
  4212. var p1 = Util.applyTransform(r, m);
  4213. var p2 = Util.applyTransform(r.slice(2, 4), m);
  4214. var p3 = Util.applyTransform([
  4215. r[0],
  4216. r[3]
  4217. ], m);
  4218. var p4 = Util.applyTransform([
  4219. r[2],
  4220. r[1]
  4221. ], m);
  4222. return [
  4223. Math.min(p1[0], p2[0], p3[0], p4[0]),
  4224. Math.min(p1[1], p2[1], p3[1], p4[1]),
  4225. Math.max(p1[0], p2[0], p3[0], p4[0]),
  4226. Math.max(p1[1], p2[1], p3[1], p4[1])
  4227. ];
  4228. };
  4229. Util.inverseTransform = function Util_inverseTransform(m) {
  4230. var d = m[0] * m[3] - m[1] * m[2];
  4231. return [
  4232. m[3] / d,
  4233. -m[1] / d,
  4234. -m[2] / d,
  4235. m[0] / d,
  4236. (m[2] * m[5] - m[4] * m[3]) / d,
  4237. (m[4] * m[1] - m[5] * m[0]) / d
  4238. ];
  4239. };
  4240. // Apply a generic 3d matrix M on a 3-vector v:
  4241. // | a b c | | X |
  4242. // | d e f | x | Y |
  4243. // | g h i | | Z |
  4244. // M is assumed to be serialized as [a,b,c,d,e,f,g,h,i],
  4245. // with v as [X,Y,Z]
  4246. Util.apply3dTransform = function Util_apply3dTransform(m, v) {
  4247. return [
  4248. m[0] * v[0] + m[1] * v[1] + m[2] * v[2],
  4249. m[3] * v[0] + m[4] * v[1] + m[5] * v[2],
  4250. m[6] * v[0] + m[7] * v[1] + m[8] * v[2]
  4251. ];
  4252. };
  4253. // This calculation uses Singular Value Decomposition.
  4254. // The SVD can be represented with formula A = USV. We are interested in the
  4255. // matrix S here because it represents the scale values.
  4256. Util.singularValueDecompose2dScale = function Util_singularValueDecompose2dScale(m) {
  4257. var transpose = [
  4258. m[0],
  4259. m[2],
  4260. m[1],
  4261. m[3]
  4262. ];
  4263. // Multiply matrix m with its transpose.
  4264. var a = m[0] * transpose[0] + m[1] * transpose[2];
  4265. var b = m[0] * transpose[1] + m[1] * transpose[3];
  4266. var c = m[2] * transpose[0] + m[3] * transpose[2];
  4267. var d = m[2] * transpose[1] + m[3] * transpose[3];
  4268. // Solve the second degree polynomial to get roots.
  4269. var first = (a + d) / 2;
  4270. var second = Math.sqrt((a + d) * (a + d) - 4 * (a * d - c * b)) / 2;
  4271. var sx = first + second || 1;
  4272. var sy = first - second || 1;
  4273. // Scale values are the square roots of the eigenvalues.
  4274. return [
  4275. Math.sqrt(sx),
  4276. Math.sqrt(sy)
  4277. ];
  4278. };
  4279. // Normalize rectangle rect=[x1, y1, x2, y2] so that (x1,y1) < (x2,y2)
  4280. // For coordinate systems whose origin lies in the bottom-left, this
  4281. // means normalization to (BL,TR) ordering. For systems with origin in the
  4282. // top-left, this means (TL,BR) ordering.
  4283. Util.normalizeRect = function Util_normalizeRect(rect) {
  4284. var r = rect.slice(0);
  4285. // clone rect
  4286. if (rect[0] > rect[2]) {
  4287. r[0] = rect[2];
  4288. r[2] = rect[0];
  4289. }
  4290. if (rect[1] > rect[3]) {
  4291. r[1] = rect[3];
  4292. r[3] = rect[1];
  4293. }
  4294. return r;
  4295. };
  4296. // Returns a rectangle [x1, y1, x2, y2] corresponding to the
  4297. // intersection of rect1 and rect2. If no intersection, returns 'false'
  4298. // The rectangle coordinates of rect1, rect2 should be [x1, y1, x2, y2]
  4299. Util.intersect = function Util_intersect(rect1, rect2) {
  4300. function compare(a, b) {
  4301. return a - b;
  4302. }
  4303. // Order points along the axes
  4304. var orderedX = [
  4305. rect1[0],
  4306. rect1[2],
  4307. rect2[0],
  4308. rect2[2]
  4309. ].sort(compare), orderedY = [
  4310. rect1[1],
  4311. rect1[3],
  4312. rect2[1],
  4313. rect2[3]
  4314. ].sort(compare), result = [];
  4315. rect1 = Util.normalizeRect(rect1);
  4316. rect2 = Util.normalizeRect(rect2);
  4317. // X: first and second points belong to different rectangles?
  4318. if (orderedX[0] === rect1[0] && orderedX[1] === rect2[0] || orderedX[0] === rect2[0] && orderedX[1] === rect1[0]) {
  4319. // Intersection must be between second and third points
  4320. result[0] = orderedX[1];
  4321. result[2] = orderedX[2];
  4322. } else {
  4323. return false;
  4324. }
  4325. // Y: first and second points belong to different rectangles?
  4326. if (orderedY[0] === rect1[1] && orderedY[1] === rect2[1] || orderedY[0] === rect2[1] && orderedY[1] === rect1[1]) {
  4327. // Intersection must be between second and third points
  4328. result[1] = orderedY[1];
  4329. result[3] = orderedY[2];
  4330. } else {
  4331. return false;
  4332. }
  4333. return result;
  4334. };
  4335. Util.sign = function Util_sign(num) {
  4336. return num < 0 ? -1 : 1;
  4337. };
  4338. var ROMAN_NUMBER_MAP = [
  4339. '',
  4340. 'C',
  4341. 'CC',
  4342. 'CCC',
  4343. 'CD',
  4344. 'D',
  4345. 'DC',
  4346. 'DCC',
  4347. 'DCCC',
  4348. 'CM',
  4349. '',
  4350. 'X',
  4351. 'XX',
  4352. 'XXX',
  4353. 'XL',
  4354. 'L',
  4355. 'LX',
  4356. 'LXX',
  4357. 'LXXX',
  4358. 'XC',
  4359. '',
  4360. 'I',
  4361. 'II',
  4362. 'III',
  4363. 'IV',
  4364. 'V',
  4365. 'VI',
  4366. 'VII',
  4367. 'VIII',
  4368. 'IX'
  4369. ];
  4370. /**
  4371. * Converts positive integers to (upper case) Roman numerals.
  4372. * @param {integer} number - The number that should be converted.
  4373. * @param {boolean} lowerCase - Indicates if the result should be converted
  4374. * to lower case letters. The default is false.
  4375. * @return {string} The resulting Roman number.
  4376. */
  4377. Util.toRoman = function Util_toRoman(number, lowerCase) {
  4378. assert(isInt(number) && number > 0, 'The number should be a positive integer.');
  4379. var pos, romanBuf = [];
  4380. // Thousands
  4381. while (number >= 1000) {
  4382. number -= 1000;
  4383. romanBuf.push('M');
  4384. }
  4385. // Hundreds
  4386. pos = number / 100 | 0;
  4387. number %= 100;
  4388. romanBuf.push(ROMAN_NUMBER_MAP[pos]);
  4389. // Tens
  4390. pos = number / 10 | 0;
  4391. number %= 10;
  4392. romanBuf.push(ROMAN_NUMBER_MAP[10 + pos]);
  4393. // Ones
  4394. romanBuf.push(ROMAN_NUMBER_MAP[20 + number]);
  4395. var romanStr = romanBuf.join('');
  4396. return lowerCase ? romanStr.toLowerCase() : romanStr;
  4397. };
  4398. Util.appendToArray = function Util_appendToArray(arr1, arr2) {
  4399. Array.prototype.push.apply(arr1, arr2);
  4400. };
  4401. Util.prependToArray = function Util_prependToArray(arr1, arr2) {
  4402. Array.prototype.unshift.apply(arr1, arr2);
  4403. };
  4404. Util.extendObj = function extendObj(obj1, obj2) {
  4405. for (var key in obj2) {
  4406. obj1[key] = obj2[key];
  4407. }
  4408. };
  4409. Util.getInheritableProperty = function Util_getInheritableProperty(dict, name, getArray) {
  4410. while (dict && !dict.has(name)) {
  4411. dict = dict.get('Parent');
  4412. }
  4413. if (!dict) {
  4414. return null;
  4415. }
  4416. return getArray ? dict.getArray(name) : dict.get(name);
  4417. };
  4418. Util.inherit = function Util_inherit(sub, base, prototype) {
  4419. sub.prototype = Object.create(base.prototype);
  4420. sub.prototype.constructor = sub;
  4421. for (var prop in prototype) {
  4422. sub.prototype[prop] = prototype[prop];
  4423. }
  4424. };
  4425. Util.loadScript = function Util_loadScript(src, callback) {
  4426. var script = document.createElement('script');
  4427. var loaded = false;
  4428. script.setAttribute('src', src);
  4429. if (callback) {
  4430. script.onload = function () {
  4431. if (!loaded) {
  4432. callback();
  4433. }
  4434. loaded = true;
  4435. };
  4436. }
  4437. document.getElementsByTagName('head')[0].appendChild(script);
  4438. };
  4439. return Util;
  4440. }();
  4441. /**
  4442. * PDF page viewport created based on scale, rotation and offset.
  4443. * @class
  4444. * @alias PageViewport
  4445. */
  4446. var PageViewport = function PageViewportClosure() {
  4447. /**
  4448. * @constructor
  4449. * @private
  4450. * @param viewBox {Array} xMin, yMin, xMax and yMax coordinates.
  4451. * @param scale {number} scale of the viewport.
  4452. * @param rotation {number} rotations of the viewport in degrees.
  4453. * @param offsetX {number} offset X
  4454. * @param offsetY {number} offset Y
  4455. * @param dontFlip {boolean} if true, axis Y will not be flipped.
  4456. */
  4457. function PageViewport(viewBox, scale, rotation, offsetX, offsetY, dontFlip) {
  4458. this.viewBox = viewBox;
  4459. this.scale = scale;
  4460. this.rotation = rotation;
  4461. this.offsetX = offsetX;
  4462. this.offsetY = offsetY;
  4463. // creating transform to convert pdf coordinate system to the normal
  4464. // canvas like coordinates taking in account scale and rotation
  4465. var centerX = (viewBox[2] + viewBox[0]) / 2;
  4466. var centerY = (viewBox[3] + viewBox[1]) / 2;
  4467. var rotateA, rotateB, rotateC, rotateD;
  4468. rotation = rotation % 360;
  4469. rotation = rotation < 0 ? rotation + 360 : rotation;
  4470. switch (rotation) {
  4471. case 180:
  4472. rotateA = -1;
  4473. rotateB = 0;
  4474. rotateC = 0;
  4475. rotateD = 1;
  4476. break;
  4477. case 90:
  4478. rotateA = 0;
  4479. rotateB = 1;
  4480. rotateC = 1;
  4481. rotateD = 0;
  4482. break;
  4483. case 270:
  4484. rotateA = 0;
  4485. rotateB = -1;
  4486. rotateC = -1;
  4487. rotateD = 0;
  4488. break;
  4489. //case 0:
  4490. default:
  4491. rotateA = 1;
  4492. rotateB = 0;
  4493. rotateC = 0;
  4494. rotateD = -1;
  4495. break;
  4496. }
  4497. if (dontFlip) {
  4498. rotateC = -rotateC;
  4499. rotateD = -rotateD;
  4500. }
  4501. var offsetCanvasX, offsetCanvasY;
  4502. var width, height;
  4503. if (rotateA === 0) {
  4504. offsetCanvasX = Math.abs(centerY - viewBox[1]) * scale + offsetX;
  4505. offsetCanvasY = Math.abs(centerX - viewBox[0]) * scale + offsetY;
  4506. width = Math.abs(viewBox[3] - viewBox[1]) * scale;
  4507. height = Math.abs(viewBox[2] - viewBox[0]) * scale;
  4508. } else {
  4509. offsetCanvasX = Math.abs(centerX - viewBox[0]) * scale + offsetX;
  4510. offsetCanvasY = Math.abs(centerY - viewBox[1]) * scale + offsetY;
  4511. width = Math.abs(viewBox[2] - viewBox[0]) * scale;
  4512. height = Math.abs(viewBox[3] - viewBox[1]) * scale;
  4513. }
  4514. // creating transform for the following operations:
  4515. // translate(-centerX, -centerY), rotate and flip vertically,
  4516. // scale, and translate(offsetCanvasX, offsetCanvasY)
  4517. this.transform = [
  4518. rotateA * scale,
  4519. rotateB * scale,
  4520. rotateC * scale,
  4521. rotateD * scale,
  4522. offsetCanvasX - rotateA * scale * centerX - rotateC * scale * centerY,
  4523. offsetCanvasY - rotateB * scale * centerX - rotateD * scale * centerY
  4524. ];
  4525. this.width = width;
  4526. this.height = height;
  4527. this.fontScale = scale;
  4528. }
  4529. PageViewport.prototype = /** @lends PageViewport.prototype */
  4530. {
  4531. /**
  4532. * Clones viewport with additional properties.
  4533. * @param args {Object} (optional) If specified, may contain the 'scale' or
  4534. * 'rotation' properties to override the corresponding properties in
  4535. * the cloned viewport.
  4536. * @returns {PageViewport} Cloned viewport.
  4537. */
  4538. clone: function PageViewPort_clone(args) {
  4539. args = args || {};
  4540. var scale = 'scale' in args ? args.scale : this.scale;
  4541. var rotation = 'rotation' in args ? args.rotation : this.rotation;
  4542. return new PageViewport(this.viewBox.slice(), scale, rotation, this.offsetX, this.offsetY, args.dontFlip);
  4543. },
  4544. /**
  4545. * Converts PDF point to the viewport coordinates. For examples, useful for
  4546. * converting PDF location into canvas pixel coordinates.
  4547. * @param x {number} X coordinate.
  4548. * @param y {number} Y coordinate.
  4549. * @returns {Object} Object that contains 'x' and 'y' properties of the
  4550. * point in the viewport coordinate space.
  4551. * @see {@link convertToPdfPoint}
  4552. * @see {@link convertToViewportRectangle}
  4553. */
  4554. convertToViewportPoint: function PageViewport_convertToViewportPoint(x, y) {
  4555. return Util.applyTransform([
  4556. x,
  4557. y
  4558. ], this.transform);
  4559. },
  4560. /**
  4561. * Converts PDF rectangle to the viewport coordinates.
  4562. * @param rect {Array} xMin, yMin, xMax and yMax coordinates.
  4563. * @returns {Array} Contains corresponding coordinates of the rectangle
  4564. * in the viewport coordinate space.
  4565. * @see {@link convertToViewportPoint}
  4566. */
  4567. convertToViewportRectangle: function PageViewport_convertToViewportRectangle(rect) {
  4568. var tl = Util.applyTransform([
  4569. rect[0],
  4570. rect[1]
  4571. ], this.transform);
  4572. var br = Util.applyTransform([
  4573. rect[2],
  4574. rect[3]
  4575. ], this.transform);
  4576. return [
  4577. tl[0],
  4578. tl[1],
  4579. br[0],
  4580. br[1]
  4581. ];
  4582. },
  4583. /**
  4584. * Converts viewport coordinates to the PDF location. For examples, useful
  4585. * for converting canvas pixel location into PDF one.
  4586. * @param x {number} X coordinate.
  4587. * @param y {number} Y coordinate.
  4588. * @returns {Object} Object that contains 'x' and 'y' properties of the
  4589. * point in the PDF coordinate space.
  4590. * @see {@link convertToViewportPoint}
  4591. */
  4592. convertToPdfPoint: function PageViewport_convertToPdfPoint(x, y) {
  4593. return Util.applyInverseTransform([
  4594. x,
  4595. y
  4596. ], this.transform);
  4597. }
  4598. };
  4599. return PageViewport;
  4600. }();
  4601. var PDFStringTranslateTable = [
  4602. 0,
  4603. 0,
  4604. 0,
  4605. 0,
  4606. 0,
  4607. 0,
  4608. 0,
  4609. 0,
  4610. 0,
  4611. 0,
  4612. 0,
  4613. 0,
  4614. 0,
  4615. 0,
  4616. 0,
  4617. 0,
  4618. 0,
  4619. 0,
  4620. 0,
  4621. 0,
  4622. 0,
  4623. 0,
  4624. 0,
  4625. 0,
  4626. 0x2D8,
  4627. 0x2C7,
  4628. 0x2C6,
  4629. 0x2D9,
  4630. 0x2DD,
  4631. 0x2DB,
  4632. 0x2DA,
  4633. 0x2DC,
  4634. 0,
  4635. 0,
  4636. 0,
  4637. 0,
  4638. 0,
  4639. 0,
  4640. 0,
  4641. 0,
  4642. 0,
  4643. 0,
  4644. 0,
  4645. 0,
  4646. 0,
  4647. 0,
  4648. 0,
  4649. 0,
  4650. 0,
  4651. 0,
  4652. 0,
  4653. 0,
  4654. 0,
  4655. 0,
  4656. 0,
  4657. 0,
  4658. 0,
  4659. 0,
  4660. 0,
  4661. 0,
  4662. 0,
  4663. 0,
  4664. 0,
  4665. 0,
  4666. 0,
  4667. 0,
  4668. 0,
  4669. 0,
  4670. 0,
  4671. 0,
  4672. 0,
  4673. 0,
  4674. 0,
  4675. 0,
  4676. 0,
  4677. 0,
  4678. 0,
  4679. 0,
  4680. 0,
  4681. 0,
  4682. 0,
  4683. 0,
  4684. 0,
  4685. 0,
  4686. 0,
  4687. 0,
  4688. 0,
  4689. 0,
  4690. 0,
  4691. 0,
  4692. 0,
  4693. 0,
  4694. 0,
  4695. 0,
  4696. 0,
  4697. 0,
  4698. 0,
  4699. 0,
  4700. 0,
  4701. 0,
  4702. 0,
  4703. 0,
  4704. 0,
  4705. 0,
  4706. 0,
  4707. 0,
  4708. 0,
  4709. 0,
  4710. 0,
  4711. 0,
  4712. 0,
  4713. 0,
  4714. 0,
  4715. 0,
  4716. 0,
  4717. 0,
  4718. 0,
  4719. 0,
  4720. 0,
  4721. 0,
  4722. 0,
  4723. 0,
  4724. 0,
  4725. 0,
  4726. 0,
  4727. 0,
  4728. 0,
  4729. 0,
  4730. 0x2022,
  4731. 0x2020,
  4732. 0x2021,
  4733. 0x2026,
  4734. 0x2014,
  4735. 0x2013,
  4736. 0x192,
  4737. 0x2044,
  4738. 0x2039,
  4739. 0x203A,
  4740. 0x2212,
  4741. 0x2030,
  4742. 0x201E,
  4743. 0x201C,
  4744. 0x201D,
  4745. 0x2018,
  4746. 0x2019,
  4747. 0x201A,
  4748. 0x2122,
  4749. 0xFB01,
  4750. 0xFB02,
  4751. 0x141,
  4752. 0x152,
  4753. 0x160,
  4754. 0x178,
  4755. 0x17D,
  4756. 0x131,
  4757. 0x142,
  4758. 0x153,
  4759. 0x161,
  4760. 0x17E,
  4761. 0,
  4762. 0x20AC
  4763. ];
  4764. function stringToPDFString(str) {
  4765. var i, n = str.length, strBuf = [];
  4766. if (str[0] === '\xFE' && str[1] === '\xFF') {
  4767. // UTF16BE BOM
  4768. for (i = 2; i < n; i += 2) {
  4769. strBuf.push(String.fromCharCode(str.charCodeAt(i) << 8 | str.charCodeAt(i + 1)));
  4770. }
  4771. } else {
  4772. for (i = 0; i < n; ++i) {
  4773. var code = PDFStringTranslateTable[str.charCodeAt(i)];
  4774. strBuf.push(code ? String.fromCharCode(code) : str.charAt(i));
  4775. }
  4776. }
  4777. return strBuf.join('');
  4778. }
  4779. function stringToUTF8String(str) {
  4780. return decodeURIComponent(escape(str));
  4781. }
  4782. function utf8StringToString(str) {
  4783. return unescape(encodeURIComponent(str));
  4784. }
  4785. function isEmptyObj(obj) {
  4786. for (var key in obj) {
  4787. return false;
  4788. }
  4789. return true;
  4790. }
  4791. function isBool(v) {
  4792. return typeof v === 'boolean';
  4793. }
  4794. function isInt(v) {
  4795. return typeof v === 'number' && (v | 0) === v;
  4796. }
  4797. function isNum(v) {
  4798. return typeof v === 'number';
  4799. }
  4800. function isString(v) {
  4801. return typeof v === 'string';
  4802. }
  4803. function isArray(v) {
  4804. return v instanceof Array;
  4805. }
  4806. function isArrayBuffer(v) {
  4807. return typeof v === 'object' && v !== null && v.byteLength !== undefined;
  4808. }
  4809. // Checks if ch is one of the following characters: SPACE, TAB, CR or LF.
  4810. function isSpace(ch) {
  4811. return ch === 0x20 || ch === 0x09 || ch === 0x0D || ch === 0x0A;
  4812. }
  4813. /**
  4814. * Promise Capability object.
  4815. *
  4816. * @typedef {Object} PromiseCapability
  4817. * @property {Promise} promise - A promise object.
  4818. * @property {function} resolve - Fulfills the promise.
  4819. * @property {function} reject - Rejects the promise.
  4820. */
  4821. /**
  4822. * Creates a promise capability object.
  4823. * @alias createPromiseCapability
  4824. *
  4825. * @return {PromiseCapability} A capability object contains:
  4826. * - a Promise, resolve and reject methods.
  4827. */
  4828. function createPromiseCapability() {
  4829. var capability = {};
  4830. capability.promise = new Promise(function (resolve, reject) {
  4831. capability.resolve = resolve;
  4832. capability.reject = reject;
  4833. });
  4834. return capability;
  4835. }
  4836. /**
  4837. * Polyfill for Promises:
  4838. * The following promise implementation tries to generally implement the
  4839. * Promise/A+ spec. Some notable differences from other promise libraries are:
  4840. * - There currently isn't a separate deferred and promise object.
  4841. * - Unhandled rejections eventually show an error if they aren't handled.
  4842. *
  4843. * Based off of the work in:
  4844. * https://bugzilla.mozilla.org/show_bug.cgi?id=810490
  4845. */
  4846. (function PromiseClosure() {
  4847. if (globalScope.Promise) {
  4848. // Promises existing in the DOM/Worker, checking presence of all/resolve
  4849. if (typeof globalScope.Promise.all !== 'function') {
  4850. globalScope.Promise.all = function (iterable) {
  4851. var count = 0, results = [], resolve, reject;
  4852. var promise = new globalScope.Promise(function (resolve_, reject_) {
  4853. resolve = resolve_;
  4854. reject = reject_;
  4855. });
  4856. iterable.forEach(function (p, i) {
  4857. count++;
  4858. p.then(function (result) {
  4859. results[i] = result;
  4860. count--;
  4861. if (count === 0) {
  4862. resolve(results);
  4863. }
  4864. }, reject);
  4865. });
  4866. if (count === 0) {
  4867. resolve(results);
  4868. }
  4869. return promise;
  4870. };
  4871. }
  4872. if (typeof globalScope.Promise.resolve !== 'function') {
  4873. globalScope.Promise.resolve = function (value) {
  4874. return new globalScope.Promise(function (resolve) {
  4875. resolve(value);
  4876. });
  4877. };
  4878. }
  4879. if (typeof globalScope.Promise.reject !== 'function') {
  4880. globalScope.Promise.reject = function (reason) {
  4881. return new globalScope.Promise(function (resolve, reject) {
  4882. reject(reason);
  4883. });
  4884. };
  4885. }
  4886. if (typeof globalScope.Promise.prototype.catch !== 'function') {
  4887. globalScope.Promise.prototype.catch = function (onReject) {
  4888. return globalScope.Promise.prototype.then(undefined, onReject);
  4889. };
  4890. }
  4891. return;
  4892. }
  4893. var STATUS_PENDING = 0;
  4894. var STATUS_RESOLVED = 1;
  4895. var STATUS_REJECTED = 2;
  4896. // In an attempt to avoid silent exceptions, unhandled rejections are
  4897. // tracked and if they aren't handled in a certain amount of time an
  4898. // error is logged.
  4899. var REJECTION_TIMEOUT = 500;
  4900. var HandlerManager = {
  4901. handlers: [],
  4902. running: false,
  4903. unhandledRejections: [],
  4904. pendingRejectionCheck: false,
  4905. scheduleHandlers: function scheduleHandlers(promise) {
  4906. if (promise._status === STATUS_PENDING) {
  4907. return;
  4908. }
  4909. this.handlers = this.handlers.concat(promise._handlers);
  4910. promise._handlers = [];
  4911. if (this.running) {
  4912. return;
  4913. }
  4914. this.running = true;
  4915. setTimeout(this.runHandlers.bind(this), 0);
  4916. },
  4917. runHandlers: function runHandlers() {
  4918. var RUN_TIMEOUT = 1;
  4919. // ms
  4920. var timeoutAt = Date.now() + RUN_TIMEOUT;
  4921. while (this.handlers.length > 0) {
  4922. var handler = this.handlers.shift();
  4923. var nextStatus = handler.thisPromise._status;
  4924. var nextValue = handler.thisPromise._value;
  4925. try {
  4926. if (nextStatus === STATUS_RESOLVED) {
  4927. if (typeof handler.onResolve === 'function') {
  4928. nextValue = handler.onResolve(nextValue);
  4929. }
  4930. } else if (typeof handler.onReject === 'function') {
  4931. nextValue = handler.onReject(nextValue);
  4932. nextStatus = STATUS_RESOLVED;
  4933. if (handler.thisPromise._unhandledRejection) {
  4934. this.removeUnhandeledRejection(handler.thisPromise);
  4935. }
  4936. }
  4937. } catch (ex) {
  4938. nextStatus = STATUS_REJECTED;
  4939. nextValue = ex;
  4940. }
  4941. handler.nextPromise._updateStatus(nextStatus, nextValue);
  4942. if (Date.now() >= timeoutAt) {
  4943. break;
  4944. }
  4945. }
  4946. if (this.handlers.length > 0) {
  4947. setTimeout(this.runHandlers.bind(this), 0);
  4948. return;
  4949. }
  4950. this.running = false;
  4951. },
  4952. addUnhandledRejection: function addUnhandledRejection(promise) {
  4953. this.unhandledRejections.push({
  4954. promise: promise,
  4955. time: Date.now()
  4956. });
  4957. this.scheduleRejectionCheck();
  4958. },
  4959. removeUnhandeledRejection: function removeUnhandeledRejection(promise) {
  4960. promise._unhandledRejection = false;
  4961. for (var i = 0; i < this.unhandledRejections.length; i++) {
  4962. if (this.unhandledRejections[i].promise === promise) {
  4963. this.unhandledRejections.splice(i);
  4964. i--;
  4965. }
  4966. }
  4967. },
  4968. scheduleRejectionCheck: function scheduleRejectionCheck() {
  4969. if (this.pendingRejectionCheck) {
  4970. return;
  4971. }
  4972. this.pendingRejectionCheck = true;
  4973. setTimeout(function rejectionCheck() {
  4974. this.pendingRejectionCheck = false;
  4975. var now = Date.now();
  4976. for (var i = 0; i < this.unhandledRejections.length; i++) {
  4977. if (now - this.unhandledRejections[i].time > REJECTION_TIMEOUT) {
  4978. var unhandled = this.unhandledRejections[i].promise._value;
  4979. var msg = 'Unhandled rejection: ' + unhandled;
  4980. if (unhandled.stack) {
  4981. msg += '\n' + unhandled.stack;
  4982. }
  4983. warn(msg);
  4984. this.unhandledRejections.splice(i);
  4985. i--;
  4986. }
  4987. }
  4988. if (this.unhandledRejections.length) {
  4989. this.scheduleRejectionCheck();
  4990. }
  4991. }.bind(this), REJECTION_TIMEOUT);
  4992. }
  4993. };
  4994. var Promise = function Promise(resolver) {
  4995. this._status = STATUS_PENDING;
  4996. this._handlers = [];
  4997. try {
  4998. resolver.call(this, this._resolve.bind(this), this._reject.bind(this));
  4999. } catch (e) {
  5000. this._reject(e);
  5001. }
  5002. };
  5003. /**
  5004. * Builds a promise that is resolved when all the passed in promises are
  5005. * resolved.
  5006. * @param {array} promises array of data and/or promises to wait for.
  5007. * @return {Promise} New dependent promise.
  5008. */
  5009. Promise.all = function Promise_all(promises) {
  5010. var resolveAll, rejectAll;
  5011. var deferred = new Promise(function (resolve, reject) {
  5012. resolveAll = resolve;
  5013. rejectAll = reject;
  5014. });
  5015. var unresolved = promises.length;
  5016. var results = [];
  5017. if (unresolved === 0) {
  5018. resolveAll(results);
  5019. return deferred;
  5020. }
  5021. function reject(reason) {
  5022. if (deferred._status === STATUS_REJECTED) {
  5023. return;
  5024. }
  5025. results = [];
  5026. rejectAll(reason);
  5027. }
  5028. for (var i = 0, ii = promises.length; i < ii; ++i) {
  5029. var promise = promises[i];
  5030. var resolve = function (i) {
  5031. return function (value) {
  5032. if (deferred._status === STATUS_REJECTED) {
  5033. return;
  5034. }
  5035. results[i] = value;
  5036. unresolved--;
  5037. if (unresolved === 0) {
  5038. resolveAll(results);
  5039. }
  5040. };
  5041. }(i);
  5042. if (Promise.isPromise(promise)) {
  5043. promise.then(resolve, reject);
  5044. } else {
  5045. resolve(promise);
  5046. }
  5047. }
  5048. return deferred;
  5049. };
  5050. /**
  5051. * Checks if the value is likely a promise (has a 'then' function).
  5052. * @return {boolean} true if value is thenable
  5053. */
  5054. Promise.isPromise = function Promise_isPromise(value) {
  5055. return value && typeof value.then === 'function';
  5056. };
  5057. /**
  5058. * Creates resolved promise
  5059. * @param value resolve value
  5060. * @returns {Promise}
  5061. */
  5062. Promise.resolve = function Promise_resolve(value) {
  5063. return new Promise(function (resolve) {
  5064. resolve(value);
  5065. });
  5066. };
  5067. /**
  5068. * Creates rejected promise
  5069. * @param reason rejection value
  5070. * @returns {Promise}
  5071. */
  5072. Promise.reject = function Promise_reject(reason) {
  5073. return new Promise(function (resolve, reject) {
  5074. reject(reason);
  5075. });
  5076. };
  5077. Promise.prototype = {
  5078. _status: null,
  5079. _value: null,
  5080. _handlers: null,
  5081. _unhandledRejection: null,
  5082. _updateStatus: function Promise__updateStatus(status, value) {
  5083. if (this._status === STATUS_RESOLVED || this._status === STATUS_REJECTED) {
  5084. return;
  5085. }
  5086. if (status === STATUS_RESOLVED && Promise.isPromise(value)) {
  5087. value.then(this._updateStatus.bind(this, STATUS_RESOLVED), this._updateStatus.bind(this, STATUS_REJECTED));
  5088. return;
  5089. }
  5090. this._status = status;
  5091. this._value = value;
  5092. if (status === STATUS_REJECTED && this._handlers.length === 0) {
  5093. this._unhandledRejection = true;
  5094. HandlerManager.addUnhandledRejection(this);
  5095. }
  5096. HandlerManager.scheduleHandlers(this);
  5097. },
  5098. _resolve: function Promise_resolve(value) {
  5099. this._updateStatus(STATUS_RESOLVED, value);
  5100. },
  5101. _reject: function Promise_reject(reason) {
  5102. this._updateStatus(STATUS_REJECTED, reason);
  5103. },
  5104. then: function Promise_then(onResolve, onReject) {
  5105. var nextPromise = new Promise(function (resolve, reject) {
  5106. this.resolve = resolve;
  5107. this.reject = reject;
  5108. });
  5109. this._handlers.push({
  5110. thisPromise: this,
  5111. onResolve: onResolve,
  5112. onReject: onReject,
  5113. nextPromise: nextPromise
  5114. });
  5115. HandlerManager.scheduleHandlers(this);
  5116. return nextPromise;
  5117. },
  5118. catch: function Promise_catch(onReject) {
  5119. return this.then(undefined, onReject);
  5120. }
  5121. };
  5122. globalScope.Promise = Promise;
  5123. }());
  5124. (function WeakMapClosure() {
  5125. if (globalScope.WeakMap) {
  5126. return;
  5127. }
  5128. var id = 0;
  5129. function WeakMap() {
  5130. this.id = '$weakmap' + id++;
  5131. }
  5132. WeakMap.prototype = {
  5133. has: function (obj) {
  5134. return !!Object.getOwnPropertyDescriptor(obj, this.id);
  5135. },
  5136. get: function (obj, defaultValue) {
  5137. return this.has(obj) ? obj[this.id] : defaultValue;
  5138. },
  5139. set: function (obj, value) {
  5140. Object.defineProperty(obj, this.id, {
  5141. value: value,
  5142. enumerable: false,
  5143. configurable: true
  5144. });
  5145. },
  5146. delete: function (obj) {
  5147. delete obj[this.id];
  5148. }
  5149. };
  5150. globalScope.WeakMap = WeakMap;
  5151. }());
  5152. var StatTimer = function StatTimerClosure() {
  5153. function rpad(str, pad, length) {
  5154. while (str.length < length) {
  5155. str += pad;
  5156. }
  5157. return str;
  5158. }
  5159. function StatTimer() {
  5160. this.started = Object.create(null);
  5161. this.times = [];
  5162. this.enabled = true;
  5163. }
  5164. StatTimer.prototype = {
  5165. time: function StatTimer_time(name) {
  5166. if (!this.enabled) {
  5167. return;
  5168. }
  5169. if (name in this.started) {
  5170. warn('Timer is already running for ' + name);
  5171. }
  5172. this.started[name] = Date.now();
  5173. },
  5174. timeEnd: function StatTimer_timeEnd(name) {
  5175. if (!this.enabled) {
  5176. return;
  5177. }
  5178. if (!(name in this.started)) {
  5179. warn('Timer has not been started for ' + name);
  5180. }
  5181. this.times.push({
  5182. 'name': name,
  5183. 'start': this.started[name],
  5184. 'end': Date.now()
  5185. });
  5186. // Remove timer from started so it can be called again.
  5187. delete this.started[name];
  5188. },
  5189. toString: function StatTimer_toString() {
  5190. var i, ii;
  5191. var times = this.times;
  5192. var out = '';
  5193. // Find the longest name for padding purposes.
  5194. var longest = 0;
  5195. for (i = 0, ii = times.length; i < ii; ++i) {
  5196. var name = times[i]['name'];
  5197. if (name.length > longest) {
  5198. longest = name.length;
  5199. }
  5200. }
  5201. for (i = 0, ii = times.length; i < ii; ++i) {
  5202. var span = times[i];
  5203. var duration = span.end - span.start;
  5204. out += rpad(span['name'], ' ', longest) + ' ' + duration + 'ms\n';
  5205. }
  5206. return out;
  5207. }
  5208. };
  5209. return StatTimer;
  5210. }();
  5211. var createBlob = function createBlob(data, contentType) {
  5212. if (typeof Blob !== 'undefined') {
  5213. return new Blob([data], { type: contentType });
  5214. }
  5215. warn('The "Blob" constructor is not supported.');
  5216. };
  5217. var createObjectURL = function createObjectURLClosure() {
  5218. // Blob/createObjectURL is not available, falling back to data schema.
  5219. var digits = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
  5220. return function createObjectURL(data, contentType, forceDataSchema) {
  5221. if (!forceDataSchema && typeof URL !== 'undefined' && URL.createObjectURL) {
  5222. var blob = createBlob(data, contentType);
  5223. return URL.createObjectURL(blob);
  5224. }
  5225. var buffer = 'data:' + contentType + ';base64,';
  5226. for (var i = 0, ii = data.length; i < ii; i += 3) {
  5227. var b1 = data[i] & 0xFF;
  5228. var b2 = data[i + 1] & 0xFF;
  5229. var b3 = data[i + 2] & 0xFF;
  5230. var d1 = b1 >> 2, d2 = (b1 & 3) << 4 | b2 >> 4;
  5231. var d3 = i + 1 < ii ? (b2 & 0xF) << 2 | b3 >> 6 : 64;
  5232. var d4 = i + 2 < ii ? b3 & 0x3F : 64;
  5233. buffer += digits[d1] + digits[d2] + digits[d3] + digits[d4];
  5234. }
  5235. return buffer;
  5236. };
  5237. }();
  5238. function MessageHandler(sourceName, targetName, comObj) {
  5239. this.sourceName = sourceName;
  5240. this.targetName = targetName;
  5241. this.comObj = comObj;
  5242. this.callbackIndex = 1;
  5243. this.postMessageTransfers = true;
  5244. var callbacksCapabilities = this.callbacksCapabilities = Object.create(null);
  5245. var ah = this.actionHandler = Object.create(null);
  5246. this._onComObjOnMessage = function messageHandlerComObjOnMessage(event) {
  5247. var data = event.data;
  5248. if (data.targetName !== this.sourceName) {
  5249. return;
  5250. }
  5251. if (data.isReply) {
  5252. var callbackId = data.callbackId;
  5253. if (data.callbackId in callbacksCapabilities) {
  5254. var callback = callbacksCapabilities[callbackId];
  5255. delete callbacksCapabilities[callbackId];
  5256. if ('error' in data) {
  5257. callback.reject(data.error);
  5258. } else {
  5259. callback.resolve(data.data);
  5260. }
  5261. } else {
  5262. error('Cannot resolve callback ' + callbackId);
  5263. }
  5264. } else if (data.action in ah) {
  5265. var action = ah[data.action];
  5266. if (data.callbackId) {
  5267. var sourceName = this.sourceName;
  5268. var targetName = data.sourceName;
  5269. Promise.resolve().then(function () {
  5270. return action[0].call(action[1], data.data);
  5271. }).then(function (result) {
  5272. comObj.postMessage({
  5273. sourceName: sourceName,
  5274. targetName: targetName,
  5275. isReply: true,
  5276. callbackId: data.callbackId,
  5277. data: result
  5278. });
  5279. }, function (reason) {
  5280. if (reason instanceof Error) {
  5281. // Serialize error to avoid "DataCloneError"
  5282. reason = reason + '';
  5283. }
  5284. comObj.postMessage({
  5285. sourceName: sourceName,
  5286. targetName: targetName,
  5287. isReply: true,
  5288. callbackId: data.callbackId,
  5289. error: reason
  5290. });
  5291. });
  5292. } else {
  5293. action[0].call(action[1], data.data);
  5294. }
  5295. } else {
  5296. error('Unknown action from worker: ' + data.action);
  5297. }
  5298. }.bind(this);
  5299. comObj.addEventListener('message', this._onComObjOnMessage);
  5300. }
  5301. MessageHandler.prototype = {
  5302. on: function messageHandlerOn(actionName, handler, scope) {
  5303. var ah = this.actionHandler;
  5304. if (ah[actionName]) {
  5305. error('There is already an actionName called "' + actionName + '"');
  5306. }
  5307. ah[actionName] = [
  5308. handler,
  5309. scope
  5310. ];
  5311. },
  5312. /**
  5313. * Sends a message to the comObj to invoke the action with the supplied data.
  5314. * @param {String} actionName Action to call.
  5315. * @param {JSON} data JSON data to send.
  5316. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers
  5317. */
  5318. send: function messageHandlerSend(actionName, data, transfers) {
  5319. var message = {
  5320. sourceName: this.sourceName,
  5321. targetName: this.targetName,
  5322. action: actionName,
  5323. data: data
  5324. };
  5325. this.postMessage(message, transfers);
  5326. },
  5327. /**
  5328. * Sends a message to the comObj to invoke the action with the supplied data.
  5329. * Expects that other side will callback with the response.
  5330. * @param {String} actionName Action to call.
  5331. * @param {JSON} data JSON data to send.
  5332. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers.
  5333. * @returns {Promise} Promise to be resolved with response data.
  5334. */
  5335. sendWithPromise: function messageHandlerSendWithPromise(actionName, data, transfers) {
  5336. var callbackId = this.callbackIndex++;
  5337. var message = {
  5338. sourceName: this.sourceName,
  5339. targetName: this.targetName,
  5340. action: actionName,
  5341. data: data,
  5342. callbackId: callbackId
  5343. };
  5344. var capability = createPromiseCapability();
  5345. this.callbacksCapabilities[callbackId] = capability;
  5346. try {
  5347. this.postMessage(message, transfers);
  5348. } catch (e) {
  5349. capability.reject(e);
  5350. }
  5351. return capability.promise;
  5352. },
  5353. /**
  5354. * Sends raw message to the comObj.
  5355. * @private
  5356. * @param message {Object} Raw message.
  5357. * @param transfers List of transfers/ArrayBuffers, or undefined.
  5358. */
  5359. postMessage: function (message, transfers) {
  5360. if (transfers && this.postMessageTransfers) {
  5361. this.comObj.postMessage(message, transfers);
  5362. } else {
  5363. this.comObj.postMessage(message);
  5364. }
  5365. },
  5366. destroy: function () {
  5367. this.comObj.removeEventListener('message', this._onComObjOnMessage);
  5368. }
  5369. };
  5370. function loadJpegStream(id, imageUrl, objs) {
  5371. var img = new Image();
  5372. img.onload = function loadJpegStream_onloadClosure() {
  5373. objs.resolve(id, img);
  5374. };
  5375. img.onerror = function loadJpegStream_onerrorClosure() {
  5376. objs.resolve(id, null);
  5377. warn('Error during JPEG image loading');
  5378. };
  5379. img.src = imageUrl;
  5380. }
  5381. // Polyfill from https://github.com/Polymer/URL
  5382. /* Any copyright is dedicated to the Public Domain.
  5383. * http://creativecommons.org/publicdomain/zero/1.0/ */
  5384. (function checkURLConstructor(scope) {
  5385. // feature detect for URL constructor
  5386. var hasWorkingUrl = false;
  5387. try {
  5388. if (typeof URL === 'function' && typeof URL.prototype === 'object' && 'origin' in URL.prototype) {
  5389. var u = new URL('b', 'http://a');
  5390. u.pathname = 'c%20d';
  5391. hasWorkingUrl = u.href === 'http://a/c%20d';
  5392. }
  5393. } catch (e) {
  5394. }
  5395. if (hasWorkingUrl) {
  5396. return;
  5397. }
  5398. var relative = Object.create(null);
  5399. relative['ftp'] = 21;
  5400. relative['file'] = 0;
  5401. relative['gopher'] = 70;
  5402. relative['http'] = 80;
  5403. relative['https'] = 443;
  5404. relative['ws'] = 80;
  5405. relative['wss'] = 443;
  5406. var relativePathDotMapping = Object.create(null);
  5407. relativePathDotMapping['%2e'] = '.';
  5408. relativePathDotMapping['.%2e'] = '..';
  5409. relativePathDotMapping['%2e.'] = '..';
  5410. relativePathDotMapping['%2e%2e'] = '..';
  5411. function isRelativeScheme(scheme) {
  5412. return relative[scheme] !== undefined;
  5413. }
  5414. function invalid() {
  5415. clear.call(this);
  5416. this._isInvalid = true;
  5417. }
  5418. function IDNAToASCII(h) {
  5419. if ('' === h) {
  5420. invalid.call(this);
  5421. }
  5422. // XXX
  5423. return h.toLowerCase();
  5424. }
  5425. function percentEscape(c) {
  5426. var unicode = c.charCodeAt(0);
  5427. if (unicode > 0x20 && unicode < 0x7F && // " # < > ? `
  5428. [
  5429. 0x22,
  5430. 0x23,
  5431. 0x3C,
  5432. 0x3E,
  5433. 0x3F,
  5434. 0x60
  5435. ].indexOf(unicode) === -1) {
  5436. return c;
  5437. }
  5438. return encodeURIComponent(c);
  5439. }
  5440. function percentEscapeQuery(c) {
  5441. // XXX This actually needs to encode c using encoding and then
  5442. // convert the bytes one-by-one.
  5443. var unicode = c.charCodeAt(0);
  5444. if (unicode > 0x20 && unicode < 0x7F && // " # < > ` (do not escape '?')
  5445. [
  5446. 0x22,
  5447. 0x23,
  5448. 0x3C,
  5449. 0x3E,
  5450. 0x60
  5451. ].indexOf(unicode) === -1) {
  5452. return c;
  5453. }
  5454. return encodeURIComponent(c);
  5455. }
  5456. var EOF, ALPHA = /[a-zA-Z]/, ALPHANUMERIC = /[a-zA-Z0-9\+\-\.]/;
  5457. function parse(input, stateOverride, base) {
  5458. function err(message) {
  5459. errors.push(message);
  5460. }
  5461. var state = stateOverride || 'scheme start', cursor = 0, buffer = '', seenAt = false, seenBracket = false, errors = [];
  5462. loop:
  5463. while ((input[cursor - 1] !== EOF || cursor === 0) && !this._isInvalid) {
  5464. var c = input[cursor];
  5465. switch (state) {
  5466. case 'scheme start':
  5467. if (c && ALPHA.test(c)) {
  5468. buffer += c.toLowerCase();
  5469. // ASCII-safe
  5470. state = 'scheme';
  5471. } else if (!stateOverride) {
  5472. buffer = '';
  5473. state = 'no scheme';
  5474. continue;
  5475. } else {
  5476. err('Invalid scheme.');
  5477. break loop;
  5478. }
  5479. break;
  5480. case 'scheme':
  5481. if (c && ALPHANUMERIC.test(c)) {
  5482. buffer += c.toLowerCase();
  5483. } else // ASCII-safe
  5484. if (':' === c) {
  5485. this._scheme = buffer;
  5486. buffer = '';
  5487. if (stateOverride) {
  5488. break loop;
  5489. }
  5490. if (isRelativeScheme(this._scheme)) {
  5491. this._isRelative = true;
  5492. }
  5493. if ('file' === this._scheme) {
  5494. state = 'relative';
  5495. } else if (this._isRelative && base && base._scheme === this._scheme) {
  5496. state = 'relative or authority';
  5497. } else if (this._isRelative) {
  5498. state = 'authority first slash';
  5499. } else {
  5500. state = 'scheme data';
  5501. }
  5502. } else if (!stateOverride) {
  5503. buffer = '';
  5504. cursor = 0;
  5505. state = 'no scheme';
  5506. continue;
  5507. } else if (EOF === c) {
  5508. break loop;
  5509. } else {
  5510. err('Code point not allowed in scheme: ' + c);
  5511. break loop;
  5512. }
  5513. break;
  5514. case 'scheme data':
  5515. if ('?' === c) {
  5516. this._query = '?';
  5517. state = 'query';
  5518. } else if ('#' === c) {
  5519. this._fragment = '#';
  5520. state = 'fragment';
  5521. } else {
  5522. // XXX error handling
  5523. if (EOF !== c && '\t' !== c && '\n' !== c && '\r' !== c) {
  5524. this._schemeData += percentEscape(c);
  5525. }
  5526. }
  5527. break;
  5528. case 'no scheme':
  5529. if (!base || !isRelativeScheme(base._scheme)) {
  5530. err('Missing scheme.');
  5531. invalid.call(this);
  5532. } else {
  5533. state = 'relative';
  5534. continue;
  5535. }
  5536. break;
  5537. case 'relative or authority':
  5538. if ('/' === c && '/' === input[cursor + 1]) {
  5539. state = 'authority ignore slashes';
  5540. } else {
  5541. err('Expected /, got: ' + c);
  5542. state = 'relative';
  5543. continue;
  5544. }
  5545. break;
  5546. case 'relative':
  5547. this._isRelative = true;
  5548. if ('file' !== this._scheme) {
  5549. this._scheme = base._scheme;
  5550. }
  5551. if (EOF === c) {
  5552. this._host = base._host;
  5553. this._port = base._port;
  5554. this._path = base._path.slice();
  5555. this._query = base._query;
  5556. this._username = base._username;
  5557. this._password = base._password;
  5558. break loop;
  5559. } else if ('/' === c || '\\' === c) {
  5560. if ('\\' === c) {
  5561. err('\\ is an invalid code point.');
  5562. }
  5563. state = 'relative slash';
  5564. } else if ('?' === c) {
  5565. this._host = base._host;
  5566. this._port = base._port;
  5567. this._path = base._path.slice();
  5568. this._query = '?';
  5569. this._username = base._username;
  5570. this._password = base._password;
  5571. state = 'query';
  5572. } else if ('#' === c) {
  5573. this._host = base._host;
  5574. this._port = base._port;
  5575. this._path = base._path.slice();
  5576. this._query = base._query;
  5577. this._fragment = '#';
  5578. this._username = base._username;
  5579. this._password = base._password;
  5580. state = 'fragment';
  5581. } else {
  5582. var nextC = input[cursor + 1];
  5583. var nextNextC = input[cursor + 2];
  5584. if ('file' !== this._scheme || !ALPHA.test(c) || nextC !== ':' && nextC !== '|' || EOF !== nextNextC && '/' !== nextNextC && '\\' !== nextNextC && '?' !== nextNextC && '#' !== nextNextC) {
  5585. this._host = base._host;
  5586. this._port = base._port;
  5587. this._username = base._username;
  5588. this._password = base._password;
  5589. this._path = base._path.slice();
  5590. this._path.pop();
  5591. }
  5592. state = 'relative path';
  5593. continue;
  5594. }
  5595. break;
  5596. case 'relative slash':
  5597. if ('/' === c || '\\' === c) {
  5598. if ('\\' === c) {
  5599. err('\\ is an invalid code point.');
  5600. }
  5601. if ('file' === this._scheme) {
  5602. state = 'file host';
  5603. } else {
  5604. state = 'authority ignore slashes';
  5605. }
  5606. } else {
  5607. if ('file' !== this._scheme) {
  5608. this._host = base._host;
  5609. this._port = base._port;
  5610. this._username = base._username;
  5611. this._password = base._password;
  5612. }
  5613. state = 'relative path';
  5614. continue;
  5615. }
  5616. break;
  5617. case 'authority first slash':
  5618. if ('/' === c) {
  5619. state = 'authority second slash';
  5620. } else {
  5621. err('Expected \'/\', got: ' + c);
  5622. state = 'authority ignore slashes';
  5623. continue;
  5624. }
  5625. break;
  5626. case 'authority second slash':
  5627. state = 'authority ignore slashes';
  5628. if ('/' !== c) {
  5629. err('Expected \'/\', got: ' + c);
  5630. continue;
  5631. }
  5632. break;
  5633. case 'authority ignore slashes':
  5634. if ('/' !== c && '\\' !== c) {
  5635. state = 'authority';
  5636. continue;
  5637. } else {
  5638. err('Expected authority, got: ' + c);
  5639. }
  5640. break;
  5641. case 'authority':
  5642. if ('@' === c) {
  5643. if (seenAt) {
  5644. err('@ already seen.');
  5645. buffer += '%40';
  5646. }
  5647. seenAt = true;
  5648. for (var i = 0; i < buffer.length; i++) {
  5649. var cp = buffer[i];
  5650. if ('\t' === cp || '\n' === cp || '\r' === cp) {
  5651. err('Invalid whitespace in authority.');
  5652. continue;
  5653. }
  5654. // XXX check URL code points
  5655. if (':' === cp && null === this._password) {
  5656. this._password = '';
  5657. continue;
  5658. }
  5659. var tempC = percentEscape(cp);
  5660. if (null !== this._password) {
  5661. this._password += tempC;
  5662. } else {
  5663. this._username += tempC;
  5664. }
  5665. }
  5666. buffer = '';
  5667. } else if (EOF === c || '/' === c || '\\' === c || '?' === c || '#' === c) {
  5668. cursor -= buffer.length;
  5669. buffer = '';
  5670. state = 'host';
  5671. continue;
  5672. } else {
  5673. buffer += c;
  5674. }
  5675. break;
  5676. case 'file host':
  5677. if (EOF === c || '/' === c || '\\' === c || '?' === c || '#' === c) {
  5678. if (buffer.length === 2 && ALPHA.test(buffer[0]) && (buffer[1] === ':' || buffer[1] === '|')) {
  5679. state = 'relative path';
  5680. } else if (buffer.length === 0) {
  5681. state = 'relative path start';
  5682. } else {
  5683. this._host = IDNAToASCII.call(this, buffer);
  5684. buffer = '';
  5685. state = 'relative path start';
  5686. }
  5687. continue;
  5688. } else if ('\t' === c || '\n' === c || '\r' === c) {
  5689. err('Invalid whitespace in file host.');
  5690. } else {
  5691. buffer += c;
  5692. }
  5693. break;
  5694. case 'host':
  5695. case 'hostname':
  5696. if (':' === c && !seenBracket) {
  5697. // XXX host parsing
  5698. this._host = IDNAToASCII.call(this, buffer);
  5699. buffer = '';
  5700. state = 'port';
  5701. if ('hostname' === stateOverride) {
  5702. break loop;
  5703. }
  5704. } else if (EOF === c || '/' === c || '\\' === c || '?' === c || '#' === c) {
  5705. this._host = IDNAToASCII.call(this, buffer);
  5706. buffer = '';
  5707. state = 'relative path start';
  5708. if (stateOverride) {
  5709. break loop;
  5710. }
  5711. continue;
  5712. } else if ('\t' !== c && '\n' !== c && '\r' !== c) {
  5713. if ('[' === c) {
  5714. seenBracket = true;
  5715. } else if (']' === c) {
  5716. seenBracket = false;
  5717. }
  5718. buffer += c;
  5719. } else {
  5720. err('Invalid code point in host/hostname: ' + c);
  5721. }
  5722. break;
  5723. case 'port':
  5724. if (/[0-9]/.test(c)) {
  5725. buffer += c;
  5726. } else if (EOF === c || '/' === c || '\\' === c || '?' === c || '#' === c || stateOverride) {
  5727. if ('' !== buffer) {
  5728. var temp = parseInt(buffer, 10);
  5729. if (temp !== relative[this._scheme]) {
  5730. this._port = temp + '';
  5731. }
  5732. buffer = '';
  5733. }
  5734. if (stateOverride) {
  5735. break loop;
  5736. }
  5737. state = 'relative path start';
  5738. continue;
  5739. } else if ('\t' === c || '\n' === c || '\r' === c) {
  5740. err('Invalid code point in port: ' + c);
  5741. } else {
  5742. invalid.call(this);
  5743. }
  5744. break;
  5745. case 'relative path start':
  5746. if ('\\' === c) {
  5747. err('\'\\\' not allowed in path.');
  5748. }
  5749. state = 'relative path';
  5750. if ('/' !== c && '\\' !== c) {
  5751. continue;
  5752. }
  5753. break;
  5754. case 'relative path':
  5755. if (EOF === c || '/' === c || '\\' === c || !stateOverride && ('?' === c || '#' === c)) {
  5756. if ('\\' === c) {
  5757. err('\\ not allowed in relative path.');
  5758. }
  5759. var tmp;
  5760. if (tmp = relativePathDotMapping[buffer.toLowerCase()]) {
  5761. buffer = tmp;
  5762. }
  5763. if ('..' === buffer) {
  5764. this._path.pop();
  5765. if ('/' !== c && '\\' !== c) {
  5766. this._path.push('');
  5767. }
  5768. } else if ('.' === buffer && '/' !== c && '\\' !== c) {
  5769. this._path.push('');
  5770. } else if ('.' !== buffer) {
  5771. if ('file' === this._scheme && this._path.length === 0 && buffer.length === 2 && ALPHA.test(buffer[0]) && buffer[1] === '|') {
  5772. buffer = buffer[0] + ':';
  5773. }
  5774. this._path.push(buffer);
  5775. }
  5776. buffer = '';
  5777. if ('?' === c) {
  5778. this._query = '?';
  5779. state = 'query';
  5780. } else if ('#' === c) {
  5781. this._fragment = '#';
  5782. state = 'fragment';
  5783. }
  5784. } else if ('\t' !== c && '\n' !== c && '\r' !== c) {
  5785. buffer += percentEscape(c);
  5786. }
  5787. break;
  5788. case 'query':
  5789. if (!stateOverride && '#' === c) {
  5790. this._fragment = '#';
  5791. state = 'fragment';
  5792. } else if (EOF !== c && '\t' !== c && '\n' !== c && '\r' !== c) {
  5793. this._query += percentEscapeQuery(c);
  5794. }
  5795. break;
  5796. case 'fragment':
  5797. if (EOF !== c && '\t' !== c && '\n' !== c && '\r' !== c) {
  5798. this._fragment += c;
  5799. }
  5800. break;
  5801. }
  5802. cursor++;
  5803. }
  5804. }
  5805. function clear() {
  5806. this._scheme = '';
  5807. this._schemeData = '';
  5808. this._username = '';
  5809. this._password = null;
  5810. this._host = '';
  5811. this._port = '';
  5812. this._path = [];
  5813. this._query = '';
  5814. this._fragment = '';
  5815. this._isInvalid = false;
  5816. this._isRelative = false;
  5817. }
  5818. // Does not process domain names or IP addresses.
  5819. // Does not handle encoding for the query parameter.
  5820. function JURL(url, base)
  5821. /* , encoding */
  5822. {
  5823. if (base !== undefined && !(base instanceof JURL)) {
  5824. base = new JURL(String(base));
  5825. }
  5826. this._url = url;
  5827. clear.call(this);
  5828. var input = url.replace(/^[ \t\r\n\f]+|[ \t\r\n\f]+$/g, '');
  5829. // encoding = encoding || 'utf-8'
  5830. parse.call(this, input, null, base);
  5831. }
  5832. JURL.prototype = {
  5833. toString: function () {
  5834. return this.href;
  5835. },
  5836. get href() {
  5837. if (this._isInvalid) {
  5838. return this._url;
  5839. }
  5840. var authority = '';
  5841. if ('' !== this._username || null !== this._password) {
  5842. authority = this._username + (null !== this._password ? ':' + this._password : '') + '@';
  5843. }
  5844. return this.protocol + (this._isRelative ? '//' + authority + this.host : '') + this.pathname + this._query + this._fragment;
  5845. },
  5846. set href(href) {
  5847. clear.call(this);
  5848. parse.call(this, href);
  5849. },
  5850. get protocol() {
  5851. return this._scheme + ':';
  5852. },
  5853. set protocol(protocol) {
  5854. if (this._isInvalid) {
  5855. return;
  5856. }
  5857. parse.call(this, protocol + ':', 'scheme start');
  5858. },
  5859. get host() {
  5860. return this._isInvalid ? '' : this._port ? this._host + ':' + this._port : this._host;
  5861. },
  5862. set host(host) {
  5863. if (this._isInvalid || !this._isRelative) {
  5864. return;
  5865. }
  5866. parse.call(this, host, 'host');
  5867. },
  5868. get hostname() {
  5869. return this._host;
  5870. },
  5871. set hostname(hostname) {
  5872. if (this._isInvalid || !this._isRelative) {
  5873. return;
  5874. }
  5875. parse.call(this, hostname, 'hostname');
  5876. },
  5877. get port() {
  5878. return this._port;
  5879. },
  5880. set port(port) {
  5881. if (this._isInvalid || !this._isRelative) {
  5882. return;
  5883. }
  5884. parse.call(this, port, 'port');
  5885. },
  5886. get pathname() {
  5887. return this._isInvalid ? '' : this._isRelative ? '/' + this._path.join('/') : this._schemeData;
  5888. },
  5889. set pathname(pathname) {
  5890. if (this._isInvalid || !this._isRelative) {
  5891. return;
  5892. }
  5893. this._path = [];
  5894. parse.call(this, pathname, 'relative path start');
  5895. },
  5896. get search() {
  5897. return this._isInvalid || !this._query || '?' === this._query ? '' : this._query;
  5898. },
  5899. set search(search) {
  5900. if (this._isInvalid || !this._isRelative) {
  5901. return;
  5902. }
  5903. this._query = '?';
  5904. if ('?' === search[0]) {
  5905. search = search.slice(1);
  5906. }
  5907. parse.call(this, search, 'query');
  5908. },
  5909. get hash() {
  5910. return this._isInvalid || !this._fragment || '#' === this._fragment ? '' : this._fragment;
  5911. },
  5912. set hash(hash) {
  5913. if (this._isInvalid) {
  5914. return;
  5915. }
  5916. this._fragment = '#';
  5917. if ('#' === hash[0]) {
  5918. hash = hash.slice(1);
  5919. }
  5920. parse.call(this, hash, 'fragment');
  5921. },
  5922. get origin() {
  5923. var host;
  5924. if (this._isInvalid || !this._scheme) {
  5925. return '';
  5926. }
  5927. // javascript: Gecko returns String(""), WebKit/Blink String("null")
  5928. // Gecko throws error for "data://"
  5929. // data: Gecko returns "", Blink returns "data://", WebKit returns "null"
  5930. // Gecko returns String("") for file: mailto:
  5931. // WebKit/Blink returns String("SCHEME://") for file: mailto:
  5932. switch (this._scheme) {
  5933. case 'data':
  5934. case 'file':
  5935. case 'javascript':
  5936. case 'mailto':
  5937. return 'null';
  5938. }
  5939. host = this.host;
  5940. if (!host) {
  5941. return '';
  5942. }
  5943. return this._scheme + '://' + host;
  5944. }
  5945. };
  5946. // Copy over the static methods
  5947. var OriginalURL = scope.URL;
  5948. if (OriginalURL) {
  5949. JURL.createObjectURL = function (blob) {
  5950. // IE extension allows a second optional options argument.
  5951. // http://msdn.microsoft.com/en-us/library/ie/hh772302(v=vs.85).aspx
  5952. return OriginalURL.createObjectURL.apply(OriginalURL, arguments);
  5953. };
  5954. JURL.revokeObjectURL = function (url) {
  5955. OriginalURL.revokeObjectURL(url);
  5956. };
  5957. }
  5958. scope.URL = JURL;
  5959. }(globalScope));
  5960. exports.FONT_IDENTITY_MATRIX = FONT_IDENTITY_MATRIX;
  5961. exports.IDENTITY_MATRIX = IDENTITY_MATRIX;
  5962. exports.OPS = OPS;
  5963. exports.VERBOSITY_LEVELS = VERBOSITY_LEVELS;
  5964. exports.UNSUPPORTED_FEATURES = UNSUPPORTED_FEATURES;
  5965. exports.AnnotationBorderStyleType = AnnotationBorderStyleType;
  5966. exports.AnnotationFieldFlag = AnnotationFieldFlag;
  5967. exports.AnnotationFlag = AnnotationFlag;
  5968. exports.AnnotationType = AnnotationType;
  5969. exports.FontType = FontType;
  5970. exports.ImageKind = ImageKind;
  5971. exports.InvalidPDFException = InvalidPDFException;
  5972. exports.MessageHandler = MessageHandler;
  5973. exports.MissingDataException = MissingDataException;
  5974. exports.MissingPDFException = MissingPDFException;
  5975. exports.NotImplementedException = NotImplementedException;
  5976. exports.PageViewport = PageViewport;
  5977. exports.PasswordException = PasswordException;
  5978. exports.PasswordResponses = PasswordResponses;
  5979. exports.StatTimer = StatTimer;
  5980. exports.StreamType = StreamType;
  5981. exports.TextRenderingMode = TextRenderingMode;
  5982. exports.UnexpectedResponseException = UnexpectedResponseException;
  5983. exports.UnknownErrorException = UnknownErrorException;
  5984. exports.Util = Util;
  5985. exports.XRefParseException = XRefParseException;
  5986. exports.arrayByteLength = arrayByteLength;
  5987. exports.arraysToBytes = arraysToBytes;
  5988. exports.assert = assert;
  5989. exports.bytesToString = bytesToString;
  5990. exports.createBlob = createBlob;
  5991. exports.createPromiseCapability = createPromiseCapability;
  5992. exports.createObjectURL = createObjectURL;
  5993. exports.deprecated = deprecated;
  5994. exports.error = error;
  5995. exports.getLookupTableFactory = getLookupTableFactory;
  5996. exports.getVerbosityLevel = getVerbosityLevel;
  5997. exports.globalScope = globalScope;
  5998. exports.info = info;
  5999. exports.isArray = isArray;
  6000. exports.isArrayBuffer = isArrayBuffer;
  6001. exports.isBool = isBool;
  6002. exports.isEmptyObj = isEmptyObj;
  6003. exports.isInt = isInt;
  6004. exports.isNum = isNum;
  6005. exports.isString = isString;
  6006. exports.isSpace = isSpace;
  6007. exports.isSameOrigin = isSameOrigin;
  6008. exports.isValidUrl = isValidUrl;
  6009. exports.isLittleEndian = isLittleEndian;
  6010. exports.isEvalSupported = isEvalSupported;
  6011. exports.loadJpegStream = loadJpegStream;
  6012. exports.log2 = log2;
  6013. exports.readInt8 = readInt8;
  6014. exports.readUint16 = readUint16;
  6015. exports.readUint32 = readUint32;
  6016. exports.removeNullCharacters = removeNullCharacters;
  6017. exports.setVerbosityLevel = setVerbosityLevel;
  6018. exports.shadow = shadow;
  6019. exports.string32 = string32;
  6020. exports.stringToBytes = stringToBytes;
  6021. exports.stringToPDFString = stringToPDFString;
  6022. exports.stringToUTF8String = stringToUTF8String;
  6023. exports.utf8StringToString = utf8StringToString;
  6024. exports.warn = warn;
  6025. }));
  6026. (function (root, factory) {
  6027. factory(root.pdfjsCoreCFFParser = {}, root.pdfjsSharedUtil, root.pdfjsCoreCharsets, root.pdfjsCoreEncodings);
  6028. }(this, function (exports, sharedUtil, coreCharsets, coreEncodings) {
  6029. var error = sharedUtil.error;
  6030. var info = sharedUtil.info;
  6031. var bytesToString = sharedUtil.bytesToString;
  6032. var warn = sharedUtil.warn;
  6033. var isArray = sharedUtil.isArray;
  6034. var Util = sharedUtil.Util;
  6035. var stringToBytes = sharedUtil.stringToBytes;
  6036. var assert = sharedUtil.assert;
  6037. var ISOAdobeCharset = coreCharsets.ISOAdobeCharset;
  6038. var ExpertCharset = coreCharsets.ExpertCharset;
  6039. var ExpertSubsetCharset = coreCharsets.ExpertSubsetCharset;
  6040. var StandardEncoding = coreEncodings.StandardEncoding;
  6041. var ExpertEncoding = coreEncodings.ExpertEncoding;
  6042. // Maximum subroutine call depth of type 2 chartrings. Matches OTS.
  6043. var MAX_SUBR_NESTING = 10;
  6044. /**
  6045. * The CFF class takes a Type1 file and wrap it into a
  6046. * 'Compact Font Format' which itself embed Type2 charstrings.
  6047. */
  6048. var CFFStandardStrings = [
  6049. '.notdef',
  6050. 'space',
  6051. 'exclam',
  6052. 'quotedbl',
  6053. 'numbersign',
  6054. 'dollar',
  6055. 'percent',
  6056. 'ampersand',
  6057. 'quoteright',
  6058. 'parenleft',
  6059. 'parenright',
  6060. 'asterisk',
  6061. 'plus',
  6062. 'comma',
  6063. 'hyphen',
  6064. 'period',
  6065. 'slash',
  6066. 'zero',
  6067. 'one',
  6068. 'two',
  6069. 'three',
  6070. 'four',
  6071. 'five',
  6072. 'six',
  6073. 'seven',
  6074. 'eight',
  6075. 'nine',
  6076. 'colon',
  6077. 'semicolon',
  6078. 'less',
  6079. 'equal',
  6080. 'greater',
  6081. 'question',
  6082. 'at',
  6083. 'A',
  6084. 'B',
  6085. 'C',
  6086. 'D',
  6087. 'E',
  6088. 'F',
  6089. 'G',
  6090. 'H',
  6091. 'I',
  6092. 'J',
  6093. 'K',
  6094. 'L',
  6095. 'M',
  6096. 'N',
  6097. 'O',
  6098. 'P',
  6099. 'Q',
  6100. 'R',
  6101. 'S',
  6102. 'T',
  6103. 'U',
  6104. 'V',
  6105. 'W',
  6106. 'X',
  6107. 'Y',
  6108. 'Z',
  6109. 'bracketleft',
  6110. 'backslash',
  6111. 'bracketright',
  6112. 'asciicircum',
  6113. 'underscore',
  6114. 'quoteleft',
  6115. 'a',
  6116. 'b',
  6117. 'c',
  6118. 'd',
  6119. 'e',
  6120. 'f',
  6121. 'g',
  6122. 'h',
  6123. 'i',
  6124. 'j',
  6125. 'k',
  6126. 'l',
  6127. 'm',
  6128. 'n',
  6129. 'o',
  6130. 'p',
  6131. 'q',
  6132. 'r',
  6133. 's',
  6134. 't',
  6135. 'u',
  6136. 'v',
  6137. 'w',
  6138. 'x',
  6139. 'y',
  6140. 'z',
  6141. 'braceleft',
  6142. 'bar',
  6143. 'braceright',
  6144. 'asciitilde',
  6145. 'exclamdown',
  6146. 'cent',
  6147. 'sterling',
  6148. 'fraction',
  6149. 'yen',
  6150. 'florin',
  6151. 'section',
  6152. 'currency',
  6153. 'quotesingle',
  6154. 'quotedblleft',
  6155. 'guillemotleft',
  6156. 'guilsinglleft',
  6157. 'guilsinglright',
  6158. 'fi',
  6159. 'fl',
  6160. 'endash',
  6161. 'dagger',
  6162. 'daggerdbl',
  6163. 'periodcentered',
  6164. 'paragraph',
  6165. 'bullet',
  6166. 'quotesinglbase',
  6167. 'quotedblbase',
  6168. 'quotedblright',
  6169. 'guillemotright',
  6170. 'ellipsis',
  6171. 'perthousand',
  6172. 'questiondown',
  6173. 'grave',
  6174. 'acute',
  6175. 'circumflex',
  6176. 'tilde',
  6177. 'macron',
  6178. 'breve',
  6179. 'dotaccent',
  6180. 'dieresis',
  6181. 'ring',
  6182. 'cedilla',
  6183. 'hungarumlaut',
  6184. 'ogonek',
  6185. 'caron',
  6186. 'emdash',
  6187. 'AE',
  6188. 'ordfeminine',
  6189. 'Lslash',
  6190. 'Oslash',
  6191. 'OE',
  6192. 'ordmasculine',
  6193. 'ae',
  6194. 'dotlessi',
  6195. 'lslash',
  6196. 'oslash',
  6197. 'oe',
  6198. 'germandbls',
  6199. 'onesuperior',
  6200. 'logicalnot',
  6201. 'mu',
  6202. 'trademark',
  6203. 'Eth',
  6204. 'onehalf',
  6205. 'plusminus',
  6206. 'Thorn',
  6207. 'onequarter',
  6208. 'divide',
  6209. 'brokenbar',
  6210. 'degree',
  6211. 'thorn',
  6212. 'threequarters',
  6213. 'twosuperior',
  6214. 'registered',
  6215. 'minus',
  6216. 'eth',
  6217. 'multiply',
  6218. 'threesuperior',
  6219. 'copyright',
  6220. 'Aacute',
  6221. 'Acircumflex',
  6222. 'Adieresis',
  6223. 'Agrave',
  6224. 'Aring',
  6225. 'Atilde',
  6226. 'Ccedilla',
  6227. 'Eacute',
  6228. 'Ecircumflex',
  6229. 'Edieresis',
  6230. 'Egrave',
  6231. 'Iacute',
  6232. 'Icircumflex',
  6233. 'Idieresis',
  6234. 'Igrave',
  6235. 'Ntilde',
  6236. 'Oacute',
  6237. 'Ocircumflex',
  6238. 'Odieresis',
  6239. 'Ograve',
  6240. 'Otilde',
  6241. 'Scaron',
  6242. 'Uacute',
  6243. 'Ucircumflex',
  6244. 'Udieresis',
  6245. 'Ugrave',
  6246. 'Yacute',
  6247. 'Ydieresis',
  6248. 'Zcaron',
  6249. 'aacute',
  6250. 'acircumflex',
  6251. 'adieresis',
  6252. 'agrave',
  6253. 'aring',
  6254. 'atilde',
  6255. 'ccedilla',
  6256. 'eacute',
  6257. 'ecircumflex',
  6258. 'edieresis',
  6259. 'egrave',
  6260. 'iacute',
  6261. 'icircumflex',
  6262. 'idieresis',
  6263. 'igrave',
  6264. 'ntilde',
  6265. 'oacute',
  6266. 'ocircumflex',
  6267. 'odieresis',
  6268. 'ograve',
  6269. 'otilde',
  6270. 'scaron',
  6271. 'uacute',
  6272. 'ucircumflex',
  6273. 'udieresis',
  6274. 'ugrave',
  6275. 'yacute',
  6276. 'ydieresis',
  6277. 'zcaron',
  6278. 'exclamsmall',
  6279. 'Hungarumlautsmall',
  6280. 'dollaroldstyle',
  6281. 'dollarsuperior',
  6282. 'ampersandsmall',
  6283. 'Acutesmall',
  6284. 'parenleftsuperior',
  6285. 'parenrightsuperior',
  6286. 'twodotenleader',
  6287. 'onedotenleader',
  6288. 'zerooldstyle',
  6289. 'oneoldstyle',
  6290. 'twooldstyle',
  6291. 'threeoldstyle',
  6292. 'fouroldstyle',
  6293. 'fiveoldstyle',
  6294. 'sixoldstyle',
  6295. 'sevenoldstyle',
  6296. 'eightoldstyle',
  6297. 'nineoldstyle',
  6298. 'commasuperior',
  6299. 'threequartersemdash',
  6300. 'periodsuperior',
  6301. 'questionsmall',
  6302. 'asuperior',
  6303. 'bsuperior',
  6304. 'centsuperior',
  6305. 'dsuperior',
  6306. 'esuperior',
  6307. 'isuperior',
  6308. 'lsuperior',
  6309. 'msuperior',
  6310. 'nsuperior',
  6311. 'osuperior',
  6312. 'rsuperior',
  6313. 'ssuperior',
  6314. 'tsuperior',
  6315. 'ff',
  6316. 'ffi',
  6317. 'ffl',
  6318. 'parenleftinferior',
  6319. 'parenrightinferior',
  6320. 'Circumflexsmall',
  6321. 'hyphensuperior',
  6322. 'Gravesmall',
  6323. 'Asmall',
  6324. 'Bsmall',
  6325. 'Csmall',
  6326. 'Dsmall',
  6327. 'Esmall',
  6328. 'Fsmall',
  6329. 'Gsmall',
  6330. 'Hsmall',
  6331. 'Ismall',
  6332. 'Jsmall',
  6333. 'Ksmall',
  6334. 'Lsmall',
  6335. 'Msmall',
  6336. 'Nsmall',
  6337. 'Osmall',
  6338. 'Psmall',
  6339. 'Qsmall',
  6340. 'Rsmall',
  6341. 'Ssmall',
  6342. 'Tsmall',
  6343. 'Usmall',
  6344. 'Vsmall',
  6345. 'Wsmall',
  6346. 'Xsmall',
  6347. 'Ysmall',
  6348. 'Zsmall',
  6349. 'colonmonetary',
  6350. 'onefitted',
  6351. 'rupiah',
  6352. 'Tildesmall',
  6353. 'exclamdownsmall',
  6354. 'centoldstyle',
  6355. 'Lslashsmall',
  6356. 'Scaronsmall',
  6357. 'Zcaronsmall',
  6358. 'Dieresissmall',
  6359. 'Brevesmall',
  6360. 'Caronsmall',
  6361. 'Dotaccentsmall',
  6362. 'Macronsmall',
  6363. 'figuredash',
  6364. 'hypheninferior',
  6365. 'Ogoneksmall',
  6366. 'Ringsmall',
  6367. 'Cedillasmall',
  6368. 'questiondownsmall',
  6369. 'oneeighth',
  6370. 'threeeighths',
  6371. 'fiveeighths',
  6372. 'seveneighths',
  6373. 'onethird',
  6374. 'twothirds',
  6375. 'zerosuperior',
  6376. 'foursuperior',
  6377. 'fivesuperior',
  6378. 'sixsuperior',
  6379. 'sevensuperior',
  6380. 'eightsuperior',
  6381. 'ninesuperior',
  6382. 'zeroinferior',
  6383. 'oneinferior',
  6384. 'twoinferior',
  6385. 'threeinferior',
  6386. 'fourinferior',
  6387. 'fiveinferior',
  6388. 'sixinferior',
  6389. 'seveninferior',
  6390. 'eightinferior',
  6391. 'nineinferior',
  6392. 'centinferior',
  6393. 'dollarinferior',
  6394. 'periodinferior',
  6395. 'commainferior',
  6396. 'Agravesmall',
  6397. 'Aacutesmall',
  6398. 'Acircumflexsmall',
  6399. 'Atildesmall',
  6400. 'Adieresissmall',
  6401. 'Aringsmall',
  6402. 'AEsmall',
  6403. 'Ccedillasmall',
  6404. 'Egravesmall',
  6405. 'Eacutesmall',
  6406. 'Ecircumflexsmall',
  6407. 'Edieresissmall',
  6408. 'Igravesmall',
  6409. 'Iacutesmall',
  6410. 'Icircumflexsmall',
  6411. 'Idieresissmall',
  6412. 'Ethsmall',
  6413. 'Ntildesmall',
  6414. 'Ogravesmall',
  6415. 'Oacutesmall',
  6416. 'Ocircumflexsmall',
  6417. 'Otildesmall',
  6418. 'Odieresissmall',
  6419. 'OEsmall',
  6420. 'Oslashsmall',
  6421. 'Ugravesmall',
  6422. 'Uacutesmall',
  6423. 'Ucircumflexsmall',
  6424. 'Udieresissmall',
  6425. 'Yacutesmall',
  6426. 'Thornsmall',
  6427. 'Ydieresissmall',
  6428. '001.000',
  6429. '001.001',
  6430. '001.002',
  6431. '001.003',
  6432. 'Black',
  6433. 'Bold',
  6434. 'Book',
  6435. 'Light',
  6436. 'Medium',
  6437. 'Regular',
  6438. 'Roman',
  6439. 'Semibold'
  6440. ];
  6441. var CFFParser = function CFFParserClosure() {
  6442. var CharstringValidationData = [
  6443. null,
  6444. {
  6445. id: 'hstem',
  6446. min: 2,
  6447. stackClearing: true,
  6448. stem: true
  6449. },
  6450. null,
  6451. {
  6452. id: 'vstem',
  6453. min: 2,
  6454. stackClearing: true,
  6455. stem: true
  6456. },
  6457. {
  6458. id: 'vmoveto',
  6459. min: 1,
  6460. stackClearing: true
  6461. },
  6462. {
  6463. id: 'rlineto',
  6464. min: 2,
  6465. resetStack: true
  6466. },
  6467. {
  6468. id: 'hlineto',
  6469. min: 1,
  6470. resetStack: true
  6471. },
  6472. {
  6473. id: 'vlineto',
  6474. min: 1,
  6475. resetStack: true
  6476. },
  6477. {
  6478. id: 'rrcurveto',
  6479. min: 6,
  6480. resetStack: true
  6481. },
  6482. null,
  6483. {
  6484. id: 'callsubr',
  6485. min: 1,
  6486. undefStack: true
  6487. },
  6488. {
  6489. id: 'return',
  6490. min: 0,
  6491. undefStack: true
  6492. },
  6493. null,
  6494. // 12
  6495. null,
  6496. {
  6497. id: 'endchar',
  6498. min: 0,
  6499. stackClearing: true
  6500. },
  6501. null,
  6502. null,
  6503. null,
  6504. {
  6505. id: 'hstemhm',
  6506. min: 2,
  6507. stackClearing: true,
  6508. stem: true
  6509. },
  6510. {
  6511. id: 'hintmask',
  6512. min: 0,
  6513. stackClearing: true
  6514. },
  6515. {
  6516. id: 'cntrmask',
  6517. min: 0,
  6518. stackClearing: true
  6519. },
  6520. {
  6521. id: 'rmoveto',
  6522. min: 2,
  6523. stackClearing: true
  6524. },
  6525. {
  6526. id: 'hmoveto',
  6527. min: 1,
  6528. stackClearing: true
  6529. },
  6530. {
  6531. id: 'vstemhm',
  6532. min: 2,
  6533. stackClearing: true,
  6534. stem: true
  6535. },
  6536. {
  6537. id: 'rcurveline',
  6538. min: 8,
  6539. resetStack: true
  6540. },
  6541. {
  6542. id: 'rlinecurve',
  6543. min: 8,
  6544. resetStack: true
  6545. },
  6546. {
  6547. id: 'vvcurveto',
  6548. min: 4,
  6549. resetStack: true
  6550. },
  6551. {
  6552. id: 'hhcurveto',
  6553. min: 4,
  6554. resetStack: true
  6555. },
  6556. null,
  6557. // shortint
  6558. {
  6559. id: 'callgsubr',
  6560. min: 1,
  6561. undefStack: true
  6562. },
  6563. {
  6564. id: 'vhcurveto',
  6565. min: 4,
  6566. resetStack: true
  6567. },
  6568. {
  6569. id: 'hvcurveto',
  6570. min: 4,
  6571. resetStack: true
  6572. }
  6573. ];
  6574. var CharstringValidationData12 = [
  6575. null,
  6576. null,
  6577. null,
  6578. {
  6579. id: 'and',
  6580. min: 2,
  6581. stackDelta: -1
  6582. },
  6583. {
  6584. id: 'or',
  6585. min: 2,
  6586. stackDelta: -1
  6587. },
  6588. {
  6589. id: 'not',
  6590. min: 1,
  6591. stackDelta: 0
  6592. },
  6593. null,
  6594. null,
  6595. null,
  6596. {
  6597. id: 'abs',
  6598. min: 1,
  6599. stackDelta: 0
  6600. },
  6601. {
  6602. id: 'add',
  6603. min: 2,
  6604. stackDelta: -1,
  6605. stackFn: function stack_div(stack, index) {
  6606. stack[index - 2] = stack[index - 2] + stack[index - 1];
  6607. }
  6608. },
  6609. {
  6610. id: 'sub',
  6611. min: 2,
  6612. stackDelta: -1,
  6613. stackFn: function stack_div(stack, index) {
  6614. stack[index - 2] = stack[index - 2] - stack[index - 1];
  6615. }
  6616. },
  6617. {
  6618. id: 'div',
  6619. min: 2,
  6620. stackDelta: -1,
  6621. stackFn: function stack_div(stack, index) {
  6622. stack[index - 2] = stack[index - 2] / stack[index - 1];
  6623. }
  6624. },
  6625. null,
  6626. {
  6627. id: 'neg',
  6628. min: 1,
  6629. stackDelta: 0,
  6630. stackFn: function stack_div(stack, index) {
  6631. stack[index - 1] = -stack[index - 1];
  6632. }
  6633. },
  6634. {
  6635. id: 'eq',
  6636. min: 2,
  6637. stackDelta: -1
  6638. },
  6639. null,
  6640. null,
  6641. {
  6642. id: 'drop',
  6643. min: 1,
  6644. stackDelta: -1
  6645. },
  6646. null,
  6647. {
  6648. id: 'put',
  6649. min: 2,
  6650. stackDelta: -2
  6651. },
  6652. {
  6653. id: 'get',
  6654. min: 1,
  6655. stackDelta: 0
  6656. },
  6657. {
  6658. id: 'ifelse',
  6659. min: 4,
  6660. stackDelta: -3
  6661. },
  6662. {
  6663. id: 'random',
  6664. min: 0,
  6665. stackDelta: 1
  6666. },
  6667. {
  6668. id: 'mul',
  6669. min: 2,
  6670. stackDelta: -1,
  6671. stackFn: function stack_div(stack, index) {
  6672. stack[index - 2] = stack[index - 2] * stack[index - 1];
  6673. }
  6674. },
  6675. null,
  6676. {
  6677. id: 'sqrt',
  6678. min: 1,
  6679. stackDelta: 0
  6680. },
  6681. {
  6682. id: 'dup',
  6683. min: 1,
  6684. stackDelta: 1
  6685. },
  6686. {
  6687. id: 'exch',
  6688. min: 2,
  6689. stackDelta: 0
  6690. },
  6691. {
  6692. id: 'index',
  6693. min: 2,
  6694. stackDelta: 0
  6695. },
  6696. {
  6697. id: 'roll',
  6698. min: 3,
  6699. stackDelta: -2
  6700. },
  6701. null,
  6702. null,
  6703. null,
  6704. {
  6705. id: 'hflex',
  6706. min: 7,
  6707. resetStack: true
  6708. },
  6709. {
  6710. id: 'flex',
  6711. min: 13,
  6712. resetStack: true
  6713. },
  6714. {
  6715. id: 'hflex1',
  6716. min: 9,
  6717. resetStack: true
  6718. },
  6719. {
  6720. id: 'flex1',
  6721. min: 11,
  6722. resetStack: true
  6723. }
  6724. ];
  6725. function CFFParser(file, properties, seacAnalysisEnabled) {
  6726. this.bytes = file.getBytes();
  6727. this.properties = properties;
  6728. this.seacAnalysisEnabled = !!seacAnalysisEnabled;
  6729. }
  6730. CFFParser.prototype = {
  6731. parse: function CFFParser_parse() {
  6732. var properties = this.properties;
  6733. var cff = new CFF();
  6734. this.cff = cff;
  6735. // The first five sections must be in order, all the others are reached
  6736. // via offsets contained in one of the below.
  6737. var header = this.parseHeader();
  6738. var nameIndex = this.parseIndex(header.endPos);
  6739. var topDictIndex = this.parseIndex(nameIndex.endPos);
  6740. var stringIndex = this.parseIndex(topDictIndex.endPos);
  6741. var globalSubrIndex = this.parseIndex(stringIndex.endPos);
  6742. var topDictParsed = this.parseDict(topDictIndex.obj.get(0));
  6743. var topDict = this.createDict(CFFTopDict, topDictParsed, cff.strings);
  6744. cff.header = header.obj;
  6745. cff.names = this.parseNameIndex(nameIndex.obj);
  6746. cff.strings = this.parseStringIndex(stringIndex.obj);
  6747. cff.topDict = topDict;
  6748. cff.globalSubrIndex = globalSubrIndex.obj;
  6749. this.parsePrivateDict(cff.topDict);
  6750. cff.isCIDFont = topDict.hasName('ROS');
  6751. var charStringOffset = topDict.getByName('CharStrings');
  6752. var charStringIndex = this.parseIndex(charStringOffset).obj;
  6753. var fontMatrix = topDict.getByName('FontMatrix');
  6754. if (fontMatrix) {
  6755. properties.fontMatrix = fontMatrix;
  6756. }
  6757. var fontBBox = topDict.getByName('FontBBox');
  6758. if (fontBBox) {
  6759. // adjusting ascent/descent
  6760. properties.ascent = fontBBox[3];
  6761. properties.descent = fontBBox[1];
  6762. properties.ascentScaled = true;
  6763. }
  6764. var charset, encoding;
  6765. if (cff.isCIDFont) {
  6766. var fdArrayIndex = this.parseIndex(topDict.getByName('FDArray')).obj;
  6767. for (var i = 0, ii = fdArrayIndex.count; i < ii; ++i) {
  6768. var dictRaw = fdArrayIndex.get(i);
  6769. var fontDict = this.createDict(CFFTopDict, this.parseDict(dictRaw), cff.strings);
  6770. this.parsePrivateDict(fontDict);
  6771. cff.fdArray.push(fontDict);
  6772. }
  6773. // cid fonts don't have an encoding
  6774. encoding = null;
  6775. charset = this.parseCharsets(topDict.getByName('charset'), charStringIndex.count, cff.strings, true);
  6776. cff.fdSelect = this.parseFDSelect(topDict.getByName('FDSelect'), charStringIndex.count);
  6777. } else {
  6778. charset = this.parseCharsets(topDict.getByName('charset'), charStringIndex.count, cff.strings, false);
  6779. encoding = this.parseEncoding(topDict.getByName('Encoding'), properties, cff.strings, charset.charset);
  6780. }
  6781. cff.charset = charset;
  6782. cff.encoding = encoding;
  6783. var charStringsAndSeacs = this.parseCharStrings(charStringIndex, topDict.privateDict.subrsIndex, globalSubrIndex.obj, cff.fdSelect, cff.fdArray);
  6784. cff.charStrings = charStringsAndSeacs.charStrings;
  6785. cff.seacs = charStringsAndSeacs.seacs;
  6786. cff.widths = charStringsAndSeacs.widths;
  6787. return cff;
  6788. },
  6789. parseHeader: function CFFParser_parseHeader() {
  6790. var bytes = this.bytes;
  6791. var bytesLength = bytes.length;
  6792. var offset = 0;
  6793. // Prevent an infinite loop, by checking that the offset is within the
  6794. // bounds of the bytes array. Necessary in empty, or invalid, font files.
  6795. while (offset < bytesLength && bytes[offset] !== 1) {
  6796. ++offset;
  6797. }
  6798. if (offset >= bytesLength) {
  6799. error('Invalid CFF header');
  6800. } else if (offset !== 0) {
  6801. info('cff data is shifted');
  6802. bytes = bytes.subarray(offset);
  6803. this.bytes = bytes;
  6804. }
  6805. var major = bytes[0];
  6806. var minor = bytes[1];
  6807. var hdrSize = bytes[2];
  6808. var offSize = bytes[3];
  6809. var header = new CFFHeader(major, minor, hdrSize, offSize);
  6810. return {
  6811. obj: header,
  6812. endPos: hdrSize
  6813. };
  6814. },
  6815. parseDict: function CFFParser_parseDict(dict) {
  6816. var pos = 0;
  6817. function parseOperand() {
  6818. var value = dict[pos++];
  6819. if (value === 30) {
  6820. return parseFloatOperand();
  6821. } else if (value === 28) {
  6822. value = dict[pos++];
  6823. value = (value << 24 | dict[pos++] << 16) >> 16;
  6824. return value;
  6825. } else if (value === 29) {
  6826. value = dict[pos++];
  6827. value = value << 8 | dict[pos++];
  6828. value = value << 8 | dict[pos++];
  6829. value = value << 8 | dict[pos++];
  6830. return value;
  6831. } else if (value >= 32 && value <= 246) {
  6832. return value - 139;
  6833. } else if (value >= 247 && value <= 250) {
  6834. return (value - 247) * 256 + dict[pos++] + 108;
  6835. } else if (value >= 251 && value <= 254) {
  6836. return -((value - 251) * 256) - dict[pos++] - 108;
  6837. } else {
  6838. error('255 is not a valid DICT command');
  6839. }
  6840. return -1;
  6841. }
  6842. function parseFloatOperand() {
  6843. var str = '';
  6844. var eof = 15;
  6845. var lookup = [
  6846. '0',
  6847. '1',
  6848. '2',
  6849. '3',
  6850. '4',
  6851. '5',
  6852. '6',
  6853. '7',
  6854. '8',
  6855. '9',
  6856. '.',
  6857. 'E',
  6858. 'E-',
  6859. null,
  6860. '-'
  6861. ];
  6862. var length = dict.length;
  6863. while (pos < length) {
  6864. var b = dict[pos++];
  6865. var b1 = b >> 4;
  6866. var b2 = b & 15;
  6867. if (b1 === eof) {
  6868. break;
  6869. }
  6870. str += lookup[b1];
  6871. if (b2 === eof) {
  6872. break;
  6873. }
  6874. str += lookup[b2];
  6875. }
  6876. return parseFloat(str);
  6877. }
  6878. var operands = [];
  6879. var entries = [];
  6880. pos = 0;
  6881. var end = dict.length;
  6882. while (pos < end) {
  6883. var b = dict[pos];
  6884. if (b <= 21) {
  6885. if (b === 12) {
  6886. b = b << 8 | dict[++pos];
  6887. }
  6888. entries.push([
  6889. b,
  6890. operands
  6891. ]);
  6892. operands = [];
  6893. ++pos;
  6894. } else {
  6895. operands.push(parseOperand());
  6896. }
  6897. }
  6898. return entries;
  6899. },
  6900. parseIndex: function CFFParser_parseIndex(pos) {
  6901. var cffIndex = new CFFIndex();
  6902. var bytes = this.bytes;
  6903. var count = bytes[pos++] << 8 | bytes[pos++];
  6904. var offsets = [];
  6905. var end = pos;
  6906. var i, ii;
  6907. if (count !== 0) {
  6908. var offsetSize = bytes[pos++];
  6909. // add 1 for offset to determine size of last object
  6910. var startPos = pos + (count + 1) * offsetSize - 1;
  6911. for (i = 0, ii = count + 1; i < ii; ++i) {
  6912. var offset = 0;
  6913. for (var j = 0; j < offsetSize; ++j) {
  6914. offset <<= 8;
  6915. offset += bytes[pos++];
  6916. }
  6917. offsets.push(startPos + offset);
  6918. }
  6919. end = offsets[count];
  6920. }
  6921. for (i = 0, ii = offsets.length - 1; i < ii; ++i) {
  6922. var offsetStart = offsets[i];
  6923. var offsetEnd = offsets[i + 1];
  6924. cffIndex.add(bytes.subarray(offsetStart, offsetEnd));
  6925. }
  6926. return {
  6927. obj: cffIndex,
  6928. endPos: end
  6929. };
  6930. },
  6931. parseNameIndex: function CFFParser_parseNameIndex(index) {
  6932. var names = [];
  6933. for (var i = 0, ii = index.count; i < ii; ++i) {
  6934. var name = index.get(i);
  6935. // OTS doesn't allow names to be over 127 characters.
  6936. var length = Math.min(name.length, 127);
  6937. var data = [];
  6938. // OTS also only permits certain characters in the name.
  6939. for (var j = 0; j < length; ++j) {
  6940. var c = name[j];
  6941. if (j === 0 && c === 0) {
  6942. data[j] = c;
  6943. continue;
  6944. }
  6945. if (c < 33 || c > 126 || c === 91 || /* [ */
  6946. c === 93 || /* ] */
  6947. c === 40 || /* ( */
  6948. c === 41 || /* ) */
  6949. c === 123 || /* { */
  6950. c === 125 || /* } */
  6951. c === 60 || /* < */
  6952. c === 62 || /* > */
  6953. c === 47 || /* / */
  6954. c === 37 || /* % */
  6955. c === 35)
  6956. /* # */
  6957. {
  6958. data[j] = 95;
  6959. continue;
  6960. }
  6961. data[j] = c;
  6962. }
  6963. names.push(bytesToString(data));
  6964. }
  6965. return names;
  6966. },
  6967. parseStringIndex: function CFFParser_parseStringIndex(index) {
  6968. var strings = new CFFStrings();
  6969. for (var i = 0, ii = index.count; i < ii; ++i) {
  6970. var data = index.get(i);
  6971. strings.add(bytesToString(data));
  6972. }
  6973. return strings;
  6974. },
  6975. createDict: function CFFParser_createDict(Type, dict, strings) {
  6976. var cffDict = new Type(strings);
  6977. for (var i = 0, ii = dict.length; i < ii; ++i) {
  6978. var pair = dict[i];
  6979. var key = pair[0];
  6980. var value = pair[1];
  6981. cffDict.setByKey(key, value);
  6982. }
  6983. return cffDict;
  6984. },
  6985. parseCharString: function CFFParser_parseCharString(state, data, localSubrIndex, globalSubrIndex) {
  6986. if (state.callDepth > MAX_SUBR_NESTING) {
  6987. return false;
  6988. }
  6989. var stackSize = state.stackSize;
  6990. var stack = state.stack;
  6991. var length = data.length;
  6992. for (var j = 0; j < length;) {
  6993. var value = data[j++];
  6994. var validationCommand = null;
  6995. if (value === 12) {
  6996. var q = data[j++];
  6997. if (q === 0) {
  6998. // The CFF specification state that the 'dotsection' command
  6999. // (12, 0) is deprecated and treated as a no-op, but all Type2
  7000. // charstrings processors should support them. Unfortunately
  7001. // the font sanitizer don't. As a workaround the sequence (12, 0)
  7002. // is replaced by a useless (0, hmoveto).
  7003. data[j - 2] = 139;
  7004. data[j - 1] = 22;
  7005. stackSize = 0;
  7006. } else {
  7007. validationCommand = CharstringValidationData12[q];
  7008. }
  7009. } else if (value === 28) {
  7010. // number (16 bit)
  7011. stack[stackSize] = (data[j] << 24 | data[j + 1] << 16) >> 16;
  7012. j += 2;
  7013. stackSize++;
  7014. } else if (value === 14) {
  7015. if (stackSize >= 4) {
  7016. stackSize -= 4;
  7017. if (this.seacAnalysisEnabled) {
  7018. state.seac = stack.slice(stackSize, stackSize + 4);
  7019. return false;
  7020. }
  7021. }
  7022. validationCommand = CharstringValidationData[value];
  7023. } else if (value >= 32 && value <= 246) {
  7024. // number
  7025. stack[stackSize] = value - 139;
  7026. stackSize++;
  7027. } else if (value >= 247 && value <= 254) {
  7028. // number (+1 bytes)
  7029. stack[stackSize] = value < 251 ? (value - 247 << 8) + data[j] + 108 : -(value - 251 << 8) - data[j] - 108;
  7030. j++;
  7031. stackSize++;
  7032. } else if (value === 255) {
  7033. // number (32 bit)
  7034. stack[stackSize] = (data[j] << 24 | data[j + 1] << 16 | data[j + 2] << 8 | data[j + 3]) / 65536;
  7035. j += 4;
  7036. stackSize++;
  7037. } else if (value === 19 || value === 20) {
  7038. state.hints += stackSize >> 1;
  7039. // skipping right amount of hints flag data
  7040. j += state.hints + 7 >> 3;
  7041. stackSize %= 2;
  7042. validationCommand = CharstringValidationData[value];
  7043. } else if (value === 10 || value === 29) {
  7044. var subrsIndex;
  7045. if (value === 10) {
  7046. subrsIndex = localSubrIndex;
  7047. } else {
  7048. subrsIndex = globalSubrIndex;
  7049. }
  7050. if (!subrsIndex) {
  7051. validationCommand = CharstringValidationData[value];
  7052. warn('Missing subrsIndex for ' + validationCommand.id);
  7053. return false;
  7054. }
  7055. var bias = 32768;
  7056. if (subrsIndex.count < 1240) {
  7057. bias = 107;
  7058. } else if (subrsIndex.count < 33900) {
  7059. bias = 1131;
  7060. }
  7061. var subrNumber = stack[--stackSize] + bias;
  7062. if (subrNumber < 0 || subrNumber >= subrsIndex.count) {
  7063. validationCommand = CharstringValidationData[value];
  7064. warn('Out of bounds subrIndex for ' + validationCommand.id);
  7065. return false;
  7066. }
  7067. state.stackSize = stackSize;
  7068. state.callDepth++;
  7069. var valid = this.parseCharString(state, subrsIndex.get(subrNumber), localSubrIndex, globalSubrIndex);
  7070. if (!valid) {
  7071. return false;
  7072. }
  7073. state.callDepth--;
  7074. stackSize = state.stackSize;
  7075. continue;
  7076. } else if (value === 11) {
  7077. state.stackSize = stackSize;
  7078. return true;
  7079. } else {
  7080. validationCommand = CharstringValidationData[value];
  7081. }
  7082. if (validationCommand) {
  7083. if (validationCommand.stem) {
  7084. state.hints += stackSize >> 1;
  7085. }
  7086. if ('min' in validationCommand) {
  7087. if (!state.undefStack && stackSize < validationCommand.min) {
  7088. warn('Not enough parameters for ' + validationCommand.id + '; actual: ' + stackSize + ', expected: ' + validationCommand.min);
  7089. return false;
  7090. }
  7091. }
  7092. if (state.firstStackClearing && validationCommand.stackClearing) {
  7093. state.firstStackClearing = false;
  7094. // the optional character width can be found before the first
  7095. // stack-clearing command arguments
  7096. stackSize -= validationCommand.min;
  7097. if (stackSize >= 2 && validationCommand.stem) {
  7098. // there are even amount of arguments for stem commands
  7099. stackSize %= 2;
  7100. } else if (stackSize > 1) {
  7101. warn('Found too many parameters for stack-clearing command');
  7102. }
  7103. if (stackSize > 0 && stack[stackSize - 1] >= 0) {
  7104. state.width = stack[stackSize - 1];
  7105. }
  7106. }
  7107. if ('stackDelta' in validationCommand) {
  7108. if ('stackFn' in validationCommand) {
  7109. validationCommand.stackFn(stack, stackSize);
  7110. }
  7111. stackSize += validationCommand.stackDelta;
  7112. } else if (validationCommand.stackClearing) {
  7113. stackSize = 0;
  7114. } else if (validationCommand.resetStack) {
  7115. stackSize = 0;
  7116. state.undefStack = false;
  7117. } else if (validationCommand.undefStack) {
  7118. stackSize = 0;
  7119. state.undefStack = true;
  7120. state.firstStackClearing = false;
  7121. }
  7122. }
  7123. }
  7124. state.stackSize = stackSize;
  7125. return true;
  7126. },
  7127. parseCharStrings: function CFFParser_parseCharStrings(charStrings, localSubrIndex, globalSubrIndex, fdSelect, fdArray) {
  7128. var seacs = [];
  7129. var widths = [];
  7130. var count = charStrings.count;
  7131. for (var i = 0; i < count; i++) {
  7132. var charstring = charStrings.get(i);
  7133. var state = {
  7134. callDepth: 0,
  7135. stackSize: 0,
  7136. stack: [],
  7137. undefStack: true,
  7138. hints: 0,
  7139. firstStackClearing: true,
  7140. seac: null,
  7141. width: null
  7142. };
  7143. var valid = true;
  7144. var localSubrToUse = null;
  7145. if (fdSelect && fdArray.length) {
  7146. var fdIndex = fdSelect.getFDIndex(i);
  7147. if (fdIndex === -1) {
  7148. warn('Glyph index is not in fd select.');
  7149. valid = false;
  7150. }
  7151. if (fdIndex >= fdArray.length) {
  7152. warn('Invalid fd index for glyph index.');
  7153. valid = false;
  7154. }
  7155. if (valid) {
  7156. localSubrToUse = fdArray[fdIndex].privateDict.subrsIndex;
  7157. }
  7158. } else if (localSubrIndex) {
  7159. localSubrToUse = localSubrIndex;
  7160. }
  7161. if (valid) {
  7162. valid = this.parseCharString(state, charstring, localSubrToUse, globalSubrIndex);
  7163. }
  7164. if (state.width !== null) {
  7165. widths[i] = state.width;
  7166. }
  7167. if (state.seac !== null) {
  7168. seacs[i] = state.seac;
  7169. }
  7170. if (!valid) {
  7171. // resetting invalid charstring to single 'endchar'
  7172. charStrings.set(i, new Uint8Array([14]));
  7173. }
  7174. }
  7175. return {
  7176. charStrings: charStrings,
  7177. seacs: seacs,
  7178. widths: widths
  7179. };
  7180. },
  7181. emptyPrivateDictionary: function CFFParser_emptyPrivateDictionary(parentDict) {
  7182. var privateDict = this.createDict(CFFPrivateDict, [], parentDict.strings);
  7183. parentDict.setByKey(18, [
  7184. 0,
  7185. 0
  7186. ]);
  7187. parentDict.privateDict = privateDict;
  7188. },
  7189. parsePrivateDict: function CFFParser_parsePrivateDict(parentDict) {
  7190. // no private dict, do nothing
  7191. if (!parentDict.hasName('Private')) {
  7192. this.emptyPrivateDictionary(parentDict);
  7193. return;
  7194. }
  7195. var privateOffset = parentDict.getByName('Private');
  7196. // make sure the params are formatted correctly
  7197. if (!isArray(privateOffset) || privateOffset.length !== 2) {
  7198. parentDict.removeByName('Private');
  7199. return;
  7200. }
  7201. var size = privateOffset[0];
  7202. var offset = privateOffset[1];
  7203. // remove empty dicts or ones that refer to invalid location
  7204. if (size === 0 || offset >= this.bytes.length) {
  7205. this.emptyPrivateDictionary(parentDict);
  7206. return;
  7207. }
  7208. var privateDictEnd = offset + size;
  7209. var dictData = this.bytes.subarray(offset, privateDictEnd);
  7210. var dict = this.parseDict(dictData);
  7211. var privateDict = this.createDict(CFFPrivateDict, dict, parentDict.strings);
  7212. parentDict.privateDict = privateDict;
  7213. // Parse the Subrs index also since it's relative to the private dict.
  7214. if (!privateDict.getByName('Subrs')) {
  7215. return;
  7216. }
  7217. var subrsOffset = privateDict.getByName('Subrs');
  7218. var relativeOffset = offset + subrsOffset;
  7219. // Validate the offset.
  7220. if (subrsOffset === 0 || relativeOffset >= this.bytes.length) {
  7221. this.emptyPrivateDictionary(parentDict);
  7222. return;
  7223. }
  7224. var subrsIndex = this.parseIndex(relativeOffset);
  7225. privateDict.subrsIndex = subrsIndex.obj;
  7226. },
  7227. parseCharsets: function CFFParser_parseCharsets(pos, length, strings, cid) {
  7228. if (pos === 0) {
  7229. return new CFFCharset(true, CFFCharsetPredefinedTypes.ISO_ADOBE, ISOAdobeCharset);
  7230. } else if (pos === 1) {
  7231. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT, ExpertCharset);
  7232. } else if (pos === 2) {
  7233. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT_SUBSET, ExpertSubsetCharset);
  7234. }
  7235. var bytes = this.bytes;
  7236. var start = pos;
  7237. var format = bytes[pos++];
  7238. var charset = ['.notdef'];
  7239. var id, count, i;
  7240. // subtract 1 for the .notdef glyph
  7241. length -= 1;
  7242. switch (format) {
  7243. case 0:
  7244. for (i = 0; i < length; i++) {
  7245. id = bytes[pos++] << 8 | bytes[pos++];
  7246. charset.push(cid ? id : strings.get(id));
  7247. }
  7248. break;
  7249. case 1:
  7250. while (charset.length <= length) {
  7251. id = bytes[pos++] << 8 | bytes[pos++];
  7252. count = bytes[pos++];
  7253. for (i = 0; i <= count; i++) {
  7254. charset.push(cid ? id++ : strings.get(id++));
  7255. }
  7256. }
  7257. break;
  7258. case 2:
  7259. while (charset.length <= length) {
  7260. id = bytes[pos++] << 8 | bytes[pos++];
  7261. count = bytes[pos++] << 8 | bytes[pos++];
  7262. for (i = 0; i <= count; i++) {
  7263. charset.push(cid ? id++ : strings.get(id++));
  7264. }
  7265. }
  7266. break;
  7267. default:
  7268. error('Unknown charset format');
  7269. }
  7270. // Raw won't be needed if we actually compile the charset.
  7271. var end = pos;
  7272. var raw = bytes.subarray(start, end);
  7273. return new CFFCharset(false, format, charset, raw);
  7274. },
  7275. parseEncoding: function CFFParser_parseEncoding(pos, properties, strings, charset) {
  7276. var encoding = Object.create(null);
  7277. var bytes = this.bytes;
  7278. var predefined = false;
  7279. var hasSupplement = false;
  7280. var format, i, ii;
  7281. var raw = null;
  7282. function readSupplement() {
  7283. var supplementsCount = bytes[pos++];
  7284. for (i = 0; i < supplementsCount; i++) {
  7285. var code = bytes[pos++];
  7286. var sid = (bytes[pos++] << 8) + (bytes[pos++] & 0xff);
  7287. encoding[code] = charset.indexOf(strings.get(sid));
  7288. }
  7289. }
  7290. if (pos === 0 || pos === 1) {
  7291. predefined = true;
  7292. format = pos;
  7293. var baseEncoding = pos ? ExpertEncoding : StandardEncoding;
  7294. for (i = 0, ii = charset.length; i < ii; i++) {
  7295. var index = baseEncoding.indexOf(charset[i]);
  7296. if (index !== -1) {
  7297. encoding[index] = i;
  7298. }
  7299. }
  7300. } else {
  7301. var dataStart = pos;
  7302. format = bytes[pos++];
  7303. switch (format & 0x7f) {
  7304. case 0:
  7305. var glyphsCount = bytes[pos++];
  7306. for (i = 1; i <= glyphsCount; i++) {
  7307. encoding[bytes[pos++]] = i;
  7308. }
  7309. break;
  7310. case 1:
  7311. var rangesCount = bytes[pos++];
  7312. var gid = 1;
  7313. for (i = 0; i < rangesCount; i++) {
  7314. var start = bytes[pos++];
  7315. var left = bytes[pos++];
  7316. for (var j = start; j <= start + left; j++) {
  7317. encoding[j] = gid++;
  7318. }
  7319. }
  7320. break;
  7321. default:
  7322. error('Unknown encoding format: ' + format + ' in CFF');
  7323. break;
  7324. }
  7325. var dataEnd = pos;
  7326. if (format & 0x80) {
  7327. // The font sanitizer does not support CFF encoding with a
  7328. // supplement, since the encoding is not really used to map
  7329. // between gid to glyph, let's overwrite what is declared in
  7330. // the top dictionary to let the sanitizer think the font use
  7331. // StandardEncoding, that's a lie but that's ok.
  7332. bytes[dataStart] &= 0x7f;
  7333. readSupplement();
  7334. hasSupplement = true;
  7335. }
  7336. raw = bytes.subarray(dataStart, dataEnd);
  7337. }
  7338. format = format & 0x7f;
  7339. return new CFFEncoding(predefined, format, encoding, raw);
  7340. },
  7341. parseFDSelect: function CFFParser_parseFDSelect(pos, length) {
  7342. var start = pos;
  7343. var bytes = this.bytes;
  7344. var format = bytes[pos++];
  7345. var fdSelect = [], rawBytes;
  7346. var i, invalidFirstGID = false;
  7347. switch (format) {
  7348. case 0:
  7349. for (i = 0; i < length; ++i) {
  7350. var id = bytes[pos++];
  7351. fdSelect.push(id);
  7352. }
  7353. rawBytes = bytes.subarray(start, pos);
  7354. break;
  7355. case 3:
  7356. var rangesCount = bytes[pos++] << 8 | bytes[pos++];
  7357. for (i = 0; i < rangesCount; ++i) {
  7358. var first = bytes[pos++] << 8 | bytes[pos++];
  7359. if (i === 0 && first !== 0) {
  7360. warn('parseFDSelect: The first range must have a first GID of 0' + ' -- trying to recover.');
  7361. invalidFirstGID = true;
  7362. first = 0;
  7363. }
  7364. var fdIndex = bytes[pos++];
  7365. var next = bytes[pos] << 8 | bytes[pos + 1];
  7366. for (var j = first; j < next; ++j) {
  7367. fdSelect.push(fdIndex);
  7368. }
  7369. }
  7370. // Advance past the sentinel(next).
  7371. pos += 2;
  7372. rawBytes = bytes.subarray(start, pos);
  7373. if (invalidFirstGID) {
  7374. rawBytes[3] = rawBytes[4] = 0;
  7375. }
  7376. // Adjust the first range, first GID.
  7377. break;
  7378. default:
  7379. error('parseFDSelect: Unknown format "' + format + '".');
  7380. break;
  7381. }
  7382. assert(fdSelect.length === length, 'parseFDSelect: Invalid font data.');
  7383. return new CFFFDSelect(fdSelect, rawBytes);
  7384. }
  7385. };
  7386. return CFFParser;
  7387. }();
  7388. // Compact Font Format
  7389. var CFF = function CFFClosure() {
  7390. function CFF() {
  7391. this.header = null;
  7392. this.names = [];
  7393. this.topDict = null;
  7394. this.strings = new CFFStrings();
  7395. this.globalSubrIndex = null;
  7396. // The following could really be per font, but since we only have one font
  7397. // store them here.
  7398. this.encoding = null;
  7399. this.charset = null;
  7400. this.charStrings = null;
  7401. this.fdArray = [];
  7402. this.fdSelect = null;
  7403. this.isCIDFont = false;
  7404. }
  7405. return CFF;
  7406. }();
  7407. var CFFHeader = function CFFHeaderClosure() {
  7408. function CFFHeader(major, minor, hdrSize, offSize) {
  7409. this.major = major;
  7410. this.minor = minor;
  7411. this.hdrSize = hdrSize;
  7412. this.offSize = offSize;
  7413. }
  7414. return CFFHeader;
  7415. }();
  7416. var CFFStrings = function CFFStringsClosure() {
  7417. function CFFStrings() {
  7418. this.strings = [];
  7419. }
  7420. CFFStrings.prototype = {
  7421. get: function CFFStrings_get(index) {
  7422. if (index >= 0 && index <= 390) {
  7423. return CFFStandardStrings[index];
  7424. }
  7425. if (index - 391 <= this.strings.length) {
  7426. return this.strings[index - 391];
  7427. }
  7428. return CFFStandardStrings[0];
  7429. },
  7430. add: function CFFStrings_add(value) {
  7431. this.strings.push(value);
  7432. },
  7433. get count() {
  7434. return this.strings.length;
  7435. }
  7436. };
  7437. return CFFStrings;
  7438. }();
  7439. var CFFIndex = function CFFIndexClosure() {
  7440. function CFFIndex() {
  7441. this.objects = [];
  7442. this.length = 0;
  7443. }
  7444. CFFIndex.prototype = {
  7445. add: function CFFIndex_add(data) {
  7446. this.length += data.length;
  7447. this.objects.push(data);
  7448. },
  7449. set: function CFFIndex_set(index, data) {
  7450. this.length += data.length - this.objects[index].length;
  7451. this.objects[index] = data;
  7452. },
  7453. get: function CFFIndex_get(index) {
  7454. return this.objects[index];
  7455. },
  7456. get count() {
  7457. return this.objects.length;
  7458. }
  7459. };
  7460. return CFFIndex;
  7461. }();
  7462. var CFFDict = function CFFDictClosure() {
  7463. function CFFDict(tables, strings) {
  7464. this.keyToNameMap = tables.keyToNameMap;
  7465. this.nameToKeyMap = tables.nameToKeyMap;
  7466. this.defaults = tables.defaults;
  7467. this.types = tables.types;
  7468. this.opcodes = tables.opcodes;
  7469. this.order = tables.order;
  7470. this.strings = strings;
  7471. this.values = Object.create(null);
  7472. }
  7473. CFFDict.prototype = {
  7474. // value should always be an array
  7475. setByKey: function CFFDict_setByKey(key, value) {
  7476. if (!(key in this.keyToNameMap)) {
  7477. return false;
  7478. }
  7479. // ignore empty values
  7480. if (value.length === 0) {
  7481. return true;
  7482. }
  7483. var type = this.types[key];
  7484. // remove the array wrapping these types of values
  7485. if (type === 'num' || type === 'sid' || type === 'offset') {
  7486. value = value[0];
  7487. // Ignore invalid values (fixes bug 1068432).
  7488. if (isNaN(value)) {
  7489. warn('Invalid CFFDict value: ' + value + ', for key: ' + key + '.');
  7490. return true;
  7491. }
  7492. }
  7493. this.values[key] = value;
  7494. return true;
  7495. },
  7496. setByName: function CFFDict_setByName(name, value) {
  7497. if (!(name in this.nameToKeyMap)) {
  7498. error('Invalid dictionary name "' + name + '"');
  7499. }
  7500. this.values[this.nameToKeyMap[name]] = value;
  7501. },
  7502. hasName: function CFFDict_hasName(name) {
  7503. return this.nameToKeyMap[name] in this.values;
  7504. },
  7505. getByName: function CFFDict_getByName(name) {
  7506. if (!(name in this.nameToKeyMap)) {
  7507. error('Invalid dictionary name "' + name + '"');
  7508. }
  7509. var key = this.nameToKeyMap[name];
  7510. if (!(key in this.values)) {
  7511. return this.defaults[key];
  7512. }
  7513. return this.values[key];
  7514. },
  7515. removeByName: function CFFDict_removeByName(name) {
  7516. delete this.values[this.nameToKeyMap[name]];
  7517. }
  7518. };
  7519. CFFDict.createTables = function CFFDict_createTables(layout) {
  7520. var tables = {
  7521. keyToNameMap: {},
  7522. nameToKeyMap: {},
  7523. defaults: {},
  7524. types: {},
  7525. opcodes: {},
  7526. order: []
  7527. };
  7528. for (var i = 0, ii = layout.length; i < ii; ++i) {
  7529. var entry = layout[i];
  7530. var key = isArray(entry[0]) ? (entry[0][0] << 8) + entry[0][1] : entry[0];
  7531. tables.keyToNameMap[key] = entry[1];
  7532. tables.nameToKeyMap[entry[1]] = key;
  7533. tables.types[key] = entry[2];
  7534. tables.defaults[key] = entry[3];
  7535. tables.opcodes[key] = isArray(entry[0]) ? entry[0] : [entry[0]];
  7536. tables.order.push(key);
  7537. }
  7538. return tables;
  7539. };
  7540. return CFFDict;
  7541. }();
  7542. var CFFTopDict = function CFFTopDictClosure() {
  7543. var layout = [
  7544. [
  7545. [
  7546. 12,
  7547. 30
  7548. ],
  7549. 'ROS',
  7550. [
  7551. 'sid',
  7552. 'sid',
  7553. 'num'
  7554. ],
  7555. null
  7556. ],
  7557. [
  7558. [
  7559. 12,
  7560. 20
  7561. ],
  7562. 'SyntheticBase',
  7563. 'num',
  7564. null
  7565. ],
  7566. [
  7567. 0,
  7568. 'version',
  7569. 'sid',
  7570. null
  7571. ],
  7572. [
  7573. 1,
  7574. 'Notice',
  7575. 'sid',
  7576. null
  7577. ],
  7578. [
  7579. [
  7580. 12,
  7581. 0
  7582. ],
  7583. 'Copyright',
  7584. 'sid',
  7585. null
  7586. ],
  7587. [
  7588. 2,
  7589. 'FullName',
  7590. 'sid',
  7591. null
  7592. ],
  7593. [
  7594. 3,
  7595. 'FamilyName',
  7596. 'sid',
  7597. null
  7598. ],
  7599. [
  7600. 4,
  7601. 'Weight',
  7602. 'sid',
  7603. null
  7604. ],
  7605. [
  7606. [
  7607. 12,
  7608. 1
  7609. ],
  7610. 'isFixedPitch',
  7611. 'num',
  7612. 0
  7613. ],
  7614. [
  7615. [
  7616. 12,
  7617. 2
  7618. ],
  7619. 'ItalicAngle',
  7620. 'num',
  7621. 0
  7622. ],
  7623. [
  7624. [
  7625. 12,
  7626. 3
  7627. ],
  7628. 'UnderlinePosition',
  7629. 'num',
  7630. -100
  7631. ],
  7632. [
  7633. [
  7634. 12,
  7635. 4
  7636. ],
  7637. 'UnderlineThickness',
  7638. 'num',
  7639. 50
  7640. ],
  7641. [
  7642. [
  7643. 12,
  7644. 5
  7645. ],
  7646. 'PaintType',
  7647. 'num',
  7648. 0
  7649. ],
  7650. [
  7651. [
  7652. 12,
  7653. 6
  7654. ],
  7655. 'CharstringType',
  7656. 'num',
  7657. 2
  7658. ],
  7659. [
  7660. [
  7661. 12,
  7662. 7
  7663. ],
  7664. 'FontMatrix',
  7665. [
  7666. 'num',
  7667. 'num',
  7668. 'num',
  7669. 'num',
  7670. 'num',
  7671. 'num'
  7672. ],
  7673. [
  7674. 0.001,
  7675. 0,
  7676. 0,
  7677. 0.001,
  7678. 0,
  7679. 0
  7680. ]
  7681. ],
  7682. [
  7683. 13,
  7684. 'UniqueID',
  7685. 'num',
  7686. null
  7687. ],
  7688. [
  7689. 5,
  7690. 'FontBBox',
  7691. [
  7692. 'num',
  7693. 'num',
  7694. 'num',
  7695. 'num'
  7696. ],
  7697. [
  7698. 0,
  7699. 0,
  7700. 0,
  7701. 0
  7702. ]
  7703. ],
  7704. [
  7705. [
  7706. 12,
  7707. 8
  7708. ],
  7709. 'StrokeWidth',
  7710. 'num',
  7711. 0
  7712. ],
  7713. [
  7714. 14,
  7715. 'XUID',
  7716. 'array',
  7717. null
  7718. ],
  7719. [
  7720. 15,
  7721. 'charset',
  7722. 'offset',
  7723. 0
  7724. ],
  7725. [
  7726. 16,
  7727. 'Encoding',
  7728. 'offset',
  7729. 0
  7730. ],
  7731. [
  7732. 17,
  7733. 'CharStrings',
  7734. 'offset',
  7735. 0
  7736. ],
  7737. [
  7738. 18,
  7739. 'Private',
  7740. [
  7741. 'offset',
  7742. 'offset'
  7743. ],
  7744. null
  7745. ],
  7746. [
  7747. [
  7748. 12,
  7749. 21
  7750. ],
  7751. 'PostScript',
  7752. 'sid',
  7753. null
  7754. ],
  7755. [
  7756. [
  7757. 12,
  7758. 22
  7759. ],
  7760. 'BaseFontName',
  7761. 'sid',
  7762. null
  7763. ],
  7764. [
  7765. [
  7766. 12,
  7767. 23
  7768. ],
  7769. 'BaseFontBlend',
  7770. 'delta',
  7771. null
  7772. ],
  7773. [
  7774. [
  7775. 12,
  7776. 31
  7777. ],
  7778. 'CIDFontVersion',
  7779. 'num',
  7780. 0
  7781. ],
  7782. [
  7783. [
  7784. 12,
  7785. 32
  7786. ],
  7787. 'CIDFontRevision',
  7788. 'num',
  7789. 0
  7790. ],
  7791. [
  7792. [
  7793. 12,
  7794. 33
  7795. ],
  7796. 'CIDFontType',
  7797. 'num',
  7798. 0
  7799. ],
  7800. [
  7801. [
  7802. 12,
  7803. 34
  7804. ],
  7805. 'CIDCount',
  7806. 'num',
  7807. 8720
  7808. ],
  7809. [
  7810. [
  7811. 12,
  7812. 35
  7813. ],
  7814. 'UIDBase',
  7815. 'num',
  7816. null
  7817. ],
  7818. // XXX: CID Fonts on DirectWrite 6.1 only seem to work if FDSelect comes
  7819. // before FDArray.
  7820. [
  7821. [
  7822. 12,
  7823. 37
  7824. ],
  7825. 'FDSelect',
  7826. 'offset',
  7827. null
  7828. ],
  7829. [
  7830. [
  7831. 12,
  7832. 36
  7833. ],
  7834. 'FDArray',
  7835. 'offset',
  7836. null
  7837. ],
  7838. [
  7839. [
  7840. 12,
  7841. 38
  7842. ],
  7843. 'FontName',
  7844. 'sid',
  7845. null
  7846. ]
  7847. ];
  7848. var tables = null;
  7849. function CFFTopDict(strings) {
  7850. if (tables === null) {
  7851. tables = CFFDict.createTables(layout);
  7852. }
  7853. CFFDict.call(this, tables, strings);
  7854. this.privateDict = null;
  7855. }
  7856. CFFTopDict.prototype = Object.create(CFFDict.prototype);
  7857. return CFFTopDict;
  7858. }();
  7859. var CFFPrivateDict = function CFFPrivateDictClosure() {
  7860. var layout = [
  7861. [
  7862. 6,
  7863. 'BlueValues',
  7864. 'delta',
  7865. null
  7866. ],
  7867. [
  7868. 7,
  7869. 'OtherBlues',
  7870. 'delta',
  7871. null
  7872. ],
  7873. [
  7874. 8,
  7875. 'FamilyBlues',
  7876. 'delta',
  7877. null
  7878. ],
  7879. [
  7880. 9,
  7881. 'FamilyOtherBlues',
  7882. 'delta',
  7883. null
  7884. ],
  7885. [
  7886. [
  7887. 12,
  7888. 9
  7889. ],
  7890. 'BlueScale',
  7891. 'num',
  7892. 0.039625
  7893. ],
  7894. [
  7895. [
  7896. 12,
  7897. 10
  7898. ],
  7899. 'BlueShift',
  7900. 'num',
  7901. 7
  7902. ],
  7903. [
  7904. [
  7905. 12,
  7906. 11
  7907. ],
  7908. 'BlueFuzz',
  7909. 'num',
  7910. 1
  7911. ],
  7912. [
  7913. 10,
  7914. 'StdHW',
  7915. 'num',
  7916. null
  7917. ],
  7918. [
  7919. 11,
  7920. 'StdVW',
  7921. 'num',
  7922. null
  7923. ],
  7924. [
  7925. [
  7926. 12,
  7927. 12
  7928. ],
  7929. 'StemSnapH',
  7930. 'delta',
  7931. null
  7932. ],
  7933. [
  7934. [
  7935. 12,
  7936. 13
  7937. ],
  7938. 'StemSnapV',
  7939. 'delta',
  7940. null
  7941. ],
  7942. [
  7943. [
  7944. 12,
  7945. 14
  7946. ],
  7947. 'ForceBold',
  7948. 'num',
  7949. 0
  7950. ],
  7951. [
  7952. [
  7953. 12,
  7954. 17
  7955. ],
  7956. 'LanguageGroup',
  7957. 'num',
  7958. 0
  7959. ],
  7960. [
  7961. [
  7962. 12,
  7963. 18
  7964. ],
  7965. 'ExpansionFactor',
  7966. 'num',
  7967. 0.06
  7968. ],
  7969. [
  7970. [
  7971. 12,
  7972. 19
  7973. ],
  7974. 'initialRandomSeed',
  7975. 'num',
  7976. 0
  7977. ],
  7978. [
  7979. 20,
  7980. 'defaultWidthX',
  7981. 'num',
  7982. 0
  7983. ],
  7984. [
  7985. 21,
  7986. 'nominalWidthX',
  7987. 'num',
  7988. 0
  7989. ],
  7990. [
  7991. 19,
  7992. 'Subrs',
  7993. 'offset',
  7994. null
  7995. ]
  7996. ];
  7997. var tables = null;
  7998. function CFFPrivateDict(strings) {
  7999. if (tables === null) {
  8000. tables = CFFDict.createTables(layout);
  8001. }
  8002. CFFDict.call(this, tables, strings);
  8003. this.subrsIndex = null;
  8004. }
  8005. CFFPrivateDict.prototype = Object.create(CFFDict.prototype);
  8006. return CFFPrivateDict;
  8007. }();
  8008. var CFFCharsetPredefinedTypes = {
  8009. ISO_ADOBE: 0,
  8010. EXPERT: 1,
  8011. EXPERT_SUBSET: 2
  8012. };
  8013. var CFFCharset = function CFFCharsetClosure() {
  8014. function CFFCharset(predefined, format, charset, raw) {
  8015. this.predefined = predefined;
  8016. this.format = format;
  8017. this.charset = charset;
  8018. this.raw = raw;
  8019. }
  8020. return CFFCharset;
  8021. }();
  8022. var CFFEncoding = function CFFEncodingClosure() {
  8023. function CFFEncoding(predefined, format, encoding, raw) {
  8024. this.predefined = predefined;
  8025. this.format = format;
  8026. this.encoding = encoding;
  8027. this.raw = raw;
  8028. }
  8029. return CFFEncoding;
  8030. }();
  8031. var CFFFDSelect = function CFFFDSelectClosure() {
  8032. function CFFFDSelect(fdSelect, raw) {
  8033. this.fdSelect = fdSelect;
  8034. this.raw = raw;
  8035. }
  8036. CFFFDSelect.prototype = {
  8037. getFDIndex: function CFFFDSelect_get(glyphIndex) {
  8038. if (glyphIndex < 0 || glyphIndex >= this.fdSelect.length) {
  8039. return -1;
  8040. }
  8041. return this.fdSelect[glyphIndex];
  8042. }
  8043. };
  8044. return CFFFDSelect;
  8045. }();
  8046. // Helper class to keep track of where an offset is within the data and helps
  8047. // filling in that offset once it's known.
  8048. var CFFOffsetTracker = function CFFOffsetTrackerClosure() {
  8049. function CFFOffsetTracker() {
  8050. this.offsets = Object.create(null);
  8051. }
  8052. CFFOffsetTracker.prototype = {
  8053. isTracking: function CFFOffsetTracker_isTracking(key) {
  8054. return key in this.offsets;
  8055. },
  8056. track: function CFFOffsetTracker_track(key, location) {
  8057. if (key in this.offsets) {
  8058. error('Already tracking location of ' + key);
  8059. }
  8060. this.offsets[key] = location;
  8061. },
  8062. offset: function CFFOffsetTracker_offset(value) {
  8063. for (var key in this.offsets) {
  8064. this.offsets[key] += value;
  8065. }
  8066. },
  8067. setEntryLocation: function CFFOffsetTracker_setEntryLocation(key, values, output) {
  8068. if (!(key in this.offsets)) {
  8069. error('Not tracking location of ' + key);
  8070. }
  8071. var data = output.data;
  8072. var dataOffset = this.offsets[key];
  8073. var size = 5;
  8074. for (var i = 0, ii = values.length; i < ii; ++i) {
  8075. var offset0 = i * size + dataOffset;
  8076. var offset1 = offset0 + 1;
  8077. var offset2 = offset0 + 2;
  8078. var offset3 = offset0 + 3;
  8079. var offset4 = offset0 + 4;
  8080. // It's easy to screw up offsets so perform this sanity check.
  8081. if (data[offset0] !== 0x1d || data[offset1] !== 0 || data[offset2] !== 0 || data[offset3] !== 0 || data[offset4] !== 0) {
  8082. error('writing to an offset that is not empty');
  8083. }
  8084. var value = values[i];
  8085. data[offset0] = 0x1d;
  8086. data[offset1] = value >> 24 & 0xFF;
  8087. data[offset2] = value >> 16 & 0xFF;
  8088. data[offset3] = value >> 8 & 0xFF;
  8089. data[offset4] = value & 0xFF;
  8090. }
  8091. }
  8092. };
  8093. return CFFOffsetTracker;
  8094. }();
  8095. // Takes a CFF and converts it to the binary representation.
  8096. var CFFCompiler = function CFFCompilerClosure() {
  8097. function CFFCompiler(cff) {
  8098. this.cff = cff;
  8099. }
  8100. CFFCompiler.prototype = {
  8101. compile: function CFFCompiler_compile() {
  8102. var cff = this.cff;
  8103. var output = {
  8104. data: [],
  8105. length: 0,
  8106. add: function CFFCompiler_add(data) {
  8107. this.data = this.data.concat(data);
  8108. this.length = this.data.length;
  8109. }
  8110. };
  8111. // Compile the five entries that must be in order.
  8112. var header = this.compileHeader(cff.header);
  8113. output.add(header);
  8114. var nameIndex = this.compileNameIndex(cff.names);
  8115. output.add(nameIndex);
  8116. if (cff.isCIDFont) {
  8117. // The spec is unclear on how font matrices should relate to each other
  8118. // when there is one in the main top dict and the sub top dicts.
  8119. // Windows handles this differently than linux and osx so we have to
  8120. // normalize to work on all.
  8121. // Rules based off of some mailing list discussions:
  8122. // - If main font has a matrix and subfont doesn't, use the main matrix.
  8123. // - If no main font matrix and there is a subfont matrix, use the
  8124. // subfont matrix.
  8125. // - If both have matrices, concat together.
  8126. // - If neither have matrices, use default.
  8127. // To make this work on all platforms we move the top matrix into each
  8128. // sub top dict and concat if necessary.
  8129. if (cff.topDict.hasName('FontMatrix')) {
  8130. var base = cff.topDict.getByName('FontMatrix');
  8131. cff.topDict.removeByName('FontMatrix');
  8132. for (var i = 0, ii = cff.fdArray.length; i < ii; i++) {
  8133. var subDict = cff.fdArray[i];
  8134. var matrix = base.slice(0);
  8135. if (subDict.hasName('FontMatrix')) {
  8136. matrix = Util.transform(matrix, subDict.getByName('FontMatrix'));
  8137. }
  8138. subDict.setByName('FontMatrix', matrix);
  8139. }
  8140. }
  8141. }
  8142. var compiled = this.compileTopDicts([cff.topDict], output.length, cff.isCIDFont);
  8143. output.add(compiled.output);
  8144. var topDictTracker = compiled.trackers[0];
  8145. var stringIndex = this.compileStringIndex(cff.strings.strings);
  8146. output.add(stringIndex);
  8147. var globalSubrIndex = this.compileIndex(cff.globalSubrIndex);
  8148. output.add(globalSubrIndex);
  8149. // Now start on the other entries that have no specific order.
  8150. if (cff.encoding && cff.topDict.hasName('Encoding')) {
  8151. if (cff.encoding.predefined) {
  8152. topDictTracker.setEntryLocation('Encoding', [cff.encoding.format], output);
  8153. } else {
  8154. var encoding = this.compileEncoding(cff.encoding);
  8155. topDictTracker.setEntryLocation('Encoding', [output.length], output);
  8156. output.add(encoding);
  8157. }
  8158. }
  8159. if (cff.charset && cff.topDict.hasName('charset')) {
  8160. if (cff.charset.predefined) {
  8161. topDictTracker.setEntryLocation('charset', [cff.charset.format], output);
  8162. } else {
  8163. var charset = this.compileCharset(cff.charset);
  8164. topDictTracker.setEntryLocation('charset', [output.length], output);
  8165. output.add(charset);
  8166. }
  8167. }
  8168. var charStrings = this.compileCharStrings(cff.charStrings);
  8169. topDictTracker.setEntryLocation('CharStrings', [output.length], output);
  8170. output.add(charStrings);
  8171. if (cff.isCIDFont) {
  8172. // For some reason FDSelect must be in front of FDArray on windows. OSX
  8173. // and linux don't seem to care.
  8174. topDictTracker.setEntryLocation('FDSelect', [output.length], output);
  8175. var fdSelect = this.compileFDSelect(cff.fdSelect.raw);
  8176. output.add(fdSelect);
  8177. // It is unclear if the sub font dictionary can have CID related
  8178. // dictionary keys, but the sanitizer doesn't like them so remove them.
  8179. compiled = this.compileTopDicts(cff.fdArray, output.length, true);
  8180. topDictTracker.setEntryLocation('FDArray', [output.length], output);
  8181. output.add(compiled.output);
  8182. var fontDictTrackers = compiled.trackers;
  8183. this.compilePrivateDicts(cff.fdArray, fontDictTrackers, output);
  8184. }
  8185. this.compilePrivateDicts([cff.topDict], [topDictTracker], output);
  8186. // If the font data ends with INDEX whose object data is zero-length,
  8187. // the sanitizer will bail out. Add a dummy byte to avoid that.
  8188. output.add([0]);
  8189. return output.data;
  8190. },
  8191. encodeNumber: function CFFCompiler_encodeNumber(value) {
  8192. if (parseFloat(value) === parseInt(value, 10) && !isNaN(value)) {
  8193. // isInt
  8194. return this.encodeInteger(value);
  8195. } else {
  8196. return this.encodeFloat(value);
  8197. }
  8198. },
  8199. encodeFloat: function CFFCompiler_encodeFloat(num) {
  8200. var value = num.toString();
  8201. // rounding inaccurate doubles
  8202. var m = /\.(\d*?)(?:9{5,20}|0{5,20})\d{0,2}(?:e(.+)|$)/.exec(value);
  8203. if (m) {
  8204. var epsilon = parseFloat('1e' + ((m[2] ? +m[2] : 0) + m[1].length));
  8205. value = (Math.round(num * epsilon) / epsilon).toString();
  8206. }
  8207. var nibbles = '';
  8208. var i, ii;
  8209. for (i = 0, ii = value.length; i < ii; ++i) {
  8210. var a = value[i];
  8211. if (a === 'e') {
  8212. nibbles += value[++i] === '-' ? 'c' : 'b';
  8213. } else if (a === '.') {
  8214. nibbles += 'a';
  8215. } else if (a === '-') {
  8216. nibbles += 'e';
  8217. } else {
  8218. nibbles += a;
  8219. }
  8220. }
  8221. nibbles += nibbles.length & 1 ? 'f' : 'ff';
  8222. var out = [30];
  8223. for (i = 0, ii = nibbles.length; i < ii; i += 2) {
  8224. out.push(parseInt(nibbles.substr(i, 2), 16));
  8225. }
  8226. return out;
  8227. },
  8228. encodeInteger: function CFFCompiler_encodeInteger(value) {
  8229. var code;
  8230. if (value >= -107 && value <= 107) {
  8231. code = [value + 139];
  8232. } else if (value >= 108 && value <= 1131) {
  8233. value = value - 108;
  8234. code = [
  8235. (value >> 8) + 247,
  8236. value & 0xFF
  8237. ];
  8238. } else if (value >= -1131 && value <= -108) {
  8239. value = -value - 108;
  8240. code = [
  8241. (value >> 8) + 251,
  8242. value & 0xFF
  8243. ];
  8244. } else if (value >= -32768 && value <= 32767) {
  8245. code = [
  8246. 0x1c,
  8247. value >> 8 & 0xFF,
  8248. value & 0xFF
  8249. ];
  8250. } else {
  8251. code = [
  8252. 0x1d,
  8253. value >> 24 & 0xFF,
  8254. value >> 16 & 0xFF,
  8255. value >> 8 & 0xFF,
  8256. value & 0xFF
  8257. ];
  8258. }
  8259. return code;
  8260. },
  8261. compileHeader: function CFFCompiler_compileHeader(header) {
  8262. return [
  8263. header.major,
  8264. header.minor,
  8265. header.hdrSize,
  8266. header.offSize
  8267. ];
  8268. },
  8269. compileNameIndex: function CFFCompiler_compileNameIndex(names) {
  8270. var nameIndex = new CFFIndex();
  8271. for (var i = 0, ii = names.length; i < ii; ++i) {
  8272. nameIndex.add(stringToBytes(names[i]));
  8273. }
  8274. return this.compileIndex(nameIndex);
  8275. },
  8276. compileTopDicts: function CFFCompiler_compileTopDicts(dicts, length, removeCidKeys) {
  8277. var fontDictTrackers = [];
  8278. var fdArrayIndex = new CFFIndex();
  8279. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  8280. var fontDict = dicts[i];
  8281. if (removeCidKeys) {
  8282. fontDict.removeByName('CIDFontVersion');
  8283. fontDict.removeByName('CIDFontRevision');
  8284. fontDict.removeByName('CIDFontType');
  8285. fontDict.removeByName('CIDCount');
  8286. fontDict.removeByName('UIDBase');
  8287. }
  8288. var fontDictTracker = new CFFOffsetTracker();
  8289. var fontDictData = this.compileDict(fontDict, fontDictTracker);
  8290. fontDictTrackers.push(fontDictTracker);
  8291. fdArrayIndex.add(fontDictData);
  8292. fontDictTracker.offset(length);
  8293. }
  8294. fdArrayIndex = this.compileIndex(fdArrayIndex, fontDictTrackers);
  8295. return {
  8296. trackers: fontDictTrackers,
  8297. output: fdArrayIndex
  8298. };
  8299. },
  8300. compilePrivateDicts: function CFFCompiler_compilePrivateDicts(dicts, trackers, output) {
  8301. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  8302. var fontDict = dicts[i];
  8303. assert(fontDict.privateDict && fontDict.hasName('Private'), 'There must be an private dictionary.');
  8304. var privateDict = fontDict.privateDict;
  8305. var privateDictTracker = new CFFOffsetTracker();
  8306. var privateDictData = this.compileDict(privateDict, privateDictTracker);
  8307. var outputLength = output.length;
  8308. privateDictTracker.offset(outputLength);
  8309. if (!privateDictData.length) {
  8310. // The private dictionary was empty, set the output length to zero to
  8311. // ensure the offset length isn't out of bounds in the eyes of the
  8312. // sanitizer.
  8313. outputLength = 0;
  8314. }
  8315. trackers[i].setEntryLocation('Private', [
  8316. privateDictData.length,
  8317. outputLength
  8318. ], output);
  8319. output.add(privateDictData);
  8320. if (privateDict.subrsIndex && privateDict.hasName('Subrs')) {
  8321. var subrs = this.compileIndex(privateDict.subrsIndex);
  8322. privateDictTracker.setEntryLocation('Subrs', [privateDictData.length], output);
  8323. output.add(subrs);
  8324. }
  8325. }
  8326. },
  8327. compileDict: function CFFCompiler_compileDict(dict, offsetTracker) {
  8328. var out = [];
  8329. // The dictionary keys must be in a certain order.
  8330. var order = dict.order;
  8331. for (var i = 0; i < order.length; ++i) {
  8332. var key = order[i];
  8333. if (!(key in dict.values)) {
  8334. continue;
  8335. }
  8336. var values = dict.values[key];
  8337. var types = dict.types[key];
  8338. if (!isArray(types)) {
  8339. types = [types];
  8340. }
  8341. if (!isArray(values)) {
  8342. values = [values];
  8343. }
  8344. // Remove any empty dict values.
  8345. if (values.length === 0) {
  8346. continue;
  8347. }
  8348. for (var j = 0, jj = types.length; j < jj; ++j) {
  8349. var type = types[j];
  8350. var value = values[j];
  8351. switch (type) {
  8352. case 'num':
  8353. case 'sid':
  8354. out = out.concat(this.encodeNumber(value));
  8355. break;
  8356. case 'offset':
  8357. // For offsets we just insert a 32bit integer so we don't have to
  8358. // deal with figuring out the length of the offset when it gets
  8359. // replaced later on by the compiler.
  8360. var name = dict.keyToNameMap[key];
  8361. // Some offsets have the offset and the length, so just record the
  8362. // position of the first one.
  8363. if (!offsetTracker.isTracking(name)) {
  8364. offsetTracker.track(name, out.length);
  8365. }
  8366. out = out.concat([
  8367. 0x1d,
  8368. 0,
  8369. 0,
  8370. 0,
  8371. 0
  8372. ]);
  8373. break;
  8374. case 'array':
  8375. case 'delta':
  8376. out = out.concat(this.encodeNumber(value));
  8377. for (var k = 1, kk = values.length; k < kk; ++k) {
  8378. out = out.concat(this.encodeNumber(values[k]));
  8379. }
  8380. break;
  8381. default:
  8382. error('Unknown data type of ' + type);
  8383. break;
  8384. }
  8385. }
  8386. out = out.concat(dict.opcodes[key]);
  8387. }
  8388. return out;
  8389. },
  8390. compileStringIndex: function CFFCompiler_compileStringIndex(strings) {
  8391. var stringIndex = new CFFIndex();
  8392. for (var i = 0, ii = strings.length; i < ii; ++i) {
  8393. stringIndex.add(stringToBytes(strings[i]));
  8394. }
  8395. return this.compileIndex(stringIndex);
  8396. },
  8397. compileGlobalSubrIndex: function CFFCompiler_compileGlobalSubrIndex() {
  8398. var globalSubrIndex = this.cff.globalSubrIndex;
  8399. this.out.writeByteArray(this.compileIndex(globalSubrIndex));
  8400. },
  8401. compileCharStrings: function CFFCompiler_compileCharStrings(charStrings) {
  8402. return this.compileIndex(charStrings);
  8403. },
  8404. compileCharset: function CFFCompiler_compileCharset(charset) {
  8405. return this.compileTypedArray(charset.raw);
  8406. },
  8407. compileEncoding: function CFFCompiler_compileEncoding(encoding) {
  8408. return this.compileTypedArray(encoding.raw);
  8409. },
  8410. compileFDSelect: function CFFCompiler_compileFDSelect(fdSelect) {
  8411. return this.compileTypedArray(fdSelect);
  8412. },
  8413. compileTypedArray: function CFFCompiler_compileTypedArray(data) {
  8414. var out = [];
  8415. for (var i = 0, ii = data.length; i < ii; ++i) {
  8416. out[i] = data[i];
  8417. }
  8418. return out;
  8419. },
  8420. compileIndex: function CFFCompiler_compileIndex(index, trackers) {
  8421. trackers = trackers || [];
  8422. var objects = index.objects;
  8423. // First 2 bytes contains the number of objects contained into this index
  8424. var count = objects.length;
  8425. // If there is no object, just create an index. This technically
  8426. // should just be [0, 0] but OTS has an issue with that.
  8427. if (count === 0) {
  8428. return [
  8429. 0,
  8430. 0,
  8431. 0
  8432. ];
  8433. }
  8434. var data = [
  8435. count >> 8 & 0xFF,
  8436. count & 0xff
  8437. ];
  8438. var lastOffset = 1, i;
  8439. for (i = 0; i < count; ++i) {
  8440. lastOffset += objects[i].length;
  8441. }
  8442. var offsetSize;
  8443. if (lastOffset < 0x100) {
  8444. offsetSize = 1;
  8445. } else if (lastOffset < 0x10000) {
  8446. offsetSize = 2;
  8447. } else if (lastOffset < 0x1000000) {
  8448. offsetSize = 3;
  8449. } else {
  8450. offsetSize = 4;
  8451. }
  8452. // Next byte contains the offset size use to reference object in the file
  8453. data.push(offsetSize);
  8454. // Add another offset after this one because we need a new offset
  8455. var relativeOffset = 1;
  8456. for (i = 0; i < count + 1; i++) {
  8457. if (offsetSize === 1) {
  8458. data.push(relativeOffset & 0xFF);
  8459. } else if (offsetSize === 2) {
  8460. data.push(relativeOffset >> 8 & 0xFF, relativeOffset & 0xFF);
  8461. } else if (offsetSize === 3) {
  8462. data.push(relativeOffset >> 16 & 0xFF, relativeOffset >> 8 & 0xFF, relativeOffset & 0xFF);
  8463. } else {
  8464. data.push(relativeOffset >>> 24 & 0xFF, relativeOffset >> 16 & 0xFF, relativeOffset >> 8 & 0xFF, relativeOffset & 0xFF);
  8465. }
  8466. if (objects[i]) {
  8467. relativeOffset += objects[i].length;
  8468. }
  8469. }
  8470. for (i = 0; i < count; i++) {
  8471. // Notify the tracker where the object will be offset in the data.
  8472. if (trackers[i]) {
  8473. trackers[i].offset(data.length);
  8474. }
  8475. for (var j = 0, jj = objects[i].length; j < jj; j++) {
  8476. data.push(objects[i][j]);
  8477. }
  8478. }
  8479. return data;
  8480. }
  8481. };
  8482. return CFFCompiler;
  8483. }();
  8484. exports.CFFStandardStrings = CFFStandardStrings;
  8485. exports.CFFParser = CFFParser;
  8486. exports.CFF = CFF;
  8487. exports.CFFHeader = CFFHeader;
  8488. exports.CFFStrings = CFFStrings;
  8489. exports.CFFIndex = CFFIndex;
  8490. exports.CFFCharset = CFFCharset;
  8491. exports.CFFTopDict = CFFTopDict;
  8492. exports.CFFPrivateDict = CFFPrivateDict;
  8493. exports.CFFCompiler = CFFCompiler;
  8494. }));
  8495. (function (root, factory) {
  8496. factory(root.pdfjsCoreChunkedStream = {}, root.pdfjsSharedUtil);
  8497. }(this, function (exports, sharedUtil) {
  8498. var MissingDataException = sharedUtil.MissingDataException;
  8499. var arrayByteLength = sharedUtil.arrayByteLength;
  8500. var arraysToBytes = sharedUtil.arraysToBytes;
  8501. var assert = sharedUtil.assert;
  8502. var createPromiseCapability = sharedUtil.createPromiseCapability;
  8503. var isInt = sharedUtil.isInt;
  8504. var isEmptyObj = sharedUtil.isEmptyObj;
  8505. var ChunkedStream = function ChunkedStreamClosure() {
  8506. function ChunkedStream(length, chunkSize, manager) {
  8507. this.bytes = new Uint8Array(length);
  8508. this.start = 0;
  8509. this.pos = 0;
  8510. this.end = length;
  8511. this.chunkSize = chunkSize;
  8512. this.loadedChunks = [];
  8513. this.numChunksLoaded = 0;
  8514. this.numChunks = Math.ceil(length / chunkSize);
  8515. this.manager = manager;
  8516. this.progressiveDataLength = 0;
  8517. this.lastSuccessfulEnsureByteChunk = -1;
  8518. }
  8519. // a single-entry cache
  8520. // required methods for a stream. if a particular stream does not
  8521. // implement these, an error should be thrown
  8522. ChunkedStream.prototype = {
  8523. getMissingChunks: function ChunkedStream_getMissingChunks() {
  8524. var chunks = [];
  8525. for (var chunk = 0, n = this.numChunks; chunk < n; ++chunk) {
  8526. if (!this.loadedChunks[chunk]) {
  8527. chunks.push(chunk);
  8528. }
  8529. }
  8530. return chunks;
  8531. },
  8532. getBaseStreams: function ChunkedStream_getBaseStreams() {
  8533. return [this];
  8534. },
  8535. allChunksLoaded: function ChunkedStream_allChunksLoaded() {
  8536. return this.numChunksLoaded === this.numChunks;
  8537. },
  8538. onReceiveData: function ChunkedStream_onReceiveData(begin, chunk) {
  8539. var end = begin + chunk.byteLength;
  8540. assert(begin % this.chunkSize === 0, 'Bad begin offset: ' + begin);
  8541. // Using this.length is inaccurate here since this.start can be moved
  8542. // See ChunkedStream.moveStart()
  8543. var length = this.bytes.length;
  8544. assert(end % this.chunkSize === 0 || end === length, 'Bad end offset: ' + end);
  8545. this.bytes.set(new Uint8Array(chunk), begin);
  8546. var chunkSize = this.chunkSize;
  8547. var beginChunk = Math.floor(begin / chunkSize);
  8548. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  8549. var curChunk;
  8550. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  8551. if (!this.loadedChunks[curChunk]) {
  8552. this.loadedChunks[curChunk] = true;
  8553. ++this.numChunksLoaded;
  8554. }
  8555. }
  8556. },
  8557. onReceiveProgressiveData: function ChunkedStream_onReceiveProgressiveData(data) {
  8558. var position = this.progressiveDataLength;
  8559. var beginChunk = Math.floor(position / this.chunkSize);
  8560. this.bytes.set(new Uint8Array(data), position);
  8561. position += data.byteLength;
  8562. this.progressiveDataLength = position;
  8563. var endChunk = position >= this.end ? this.numChunks : Math.floor(position / this.chunkSize);
  8564. var curChunk;
  8565. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  8566. if (!this.loadedChunks[curChunk]) {
  8567. this.loadedChunks[curChunk] = true;
  8568. ++this.numChunksLoaded;
  8569. }
  8570. }
  8571. },
  8572. ensureByte: function ChunkedStream_ensureByte(pos) {
  8573. var chunk = Math.floor(pos / this.chunkSize);
  8574. if (chunk === this.lastSuccessfulEnsureByteChunk) {
  8575. return;
  8576. }
  8577. if (!this.loadedChunks[chunk]) {
  8578. throw new MissingDataException(pos, pos + 1);
  8579. }
  8580. this.lastSuccessfulEnsureByteChunk = chunk;
  8581. },
  8582. ensureRange: function ChunkedStream_ensureRange(begin, end) {
  8583. if (begin >= end) {
  8584. return;
  8585. }
  8586. if (end <= this.progressiveDataLength) {
  8587. return;
  8588. }
  8589. var chunkSize = this.chunkSize;
  8590. var beginChunk = Math.floor(begin / chunkSize);
  8591. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  8592. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  8593. if (!this.loadedChunks[chunk]) {
  8594. throw new MissingDataException(begin, end);
  8595. }
  8596. }
  8597. },
  8598. nextEmptyChunk: function ChunkedStream_nextEmptyChunk(beginChunk) {
  8599. var chunk, numChunks = this.numChunks;
  8600. for (var i = 0; i < numChunks; ++i) {
  8601. chunk = (beginChunk + i) % numChunks;
  8602. // Wrap around to beginning
  8603. if (!this.loadedChunks[chunk]) {
  8604. return chunk;
  8605. }
  8606. }
  8607. return null;
  8608. },
  8609. hasChunk: function ChunkedStream_hasChunk(chunk) {
  8610. return !!this.loadedChunks[chunk];
  8611. },
  8612. get length() {
  8613. return this.end - this.start;
  8614. },
  8615. get isEmpty() {
  8616. return this.length === 0;
  8617. },
  8618. getByte: function ChunkedStream_getByte() {
  8619. var pos = this.pos;
  8620. if (pos >= this.end) {
  8621. return -1;
  8622. }
  8623. this.ensureByte(pos);
  8624. return this.bytes[this.pos++];
  8625. },
  8626. getUint16: function ChunkedStream_getUint16() {
  8627. var b0 = this.getByte();
  8628. var b1 = this.getByte();
  8629. if (b0 === -1 || b1 === -1) {
  8630. return -1;
  8631. }
  8632. return (b0 << 8) + b1;
  8633. },
  8634. getInt32: function ChunkedStream_getInt32() {
  8635. var b0 = this.getByte();
  8636. var b1 = this.getByte();
  8637. var b2 = this.getByte();
  8638. var b3 = this.getByte();
  8639. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  8640. },
  8641. // returns subarray of original buffer
  8642. // should only be read
  8643. getBytes: function ChunkedStream_getBytes(length) {
  8644. var bytes = this.bytes;
  8645. var pos = this.pos;
  8646. var strEnd = this.end;
  8647. if (!length) {
  8648. this.ensureRange(pos, strEnd);
  8649. return bytes.subarray(pos, strEnd);
  8650. }
  8651. var end = pos + length;
  8652. if (end > strEnd) {
  8653. end = strEnd;
  8654. }
  8655. this.ensureRange(pos, end);
  8656. this.pos = end;
  8657. return bytes.subarray(pos, end);
  8658. },
  8659. peekByte: function ChunkedStream_peekByte() {
  8660. var peekedByte = this.getByte();
  8661. this.pos--;
  8662. return peekedByte;
  8663. },
  8664. peekBytes: function ChunkedStream_peekBytes(length) {
  8665. var bytes = this.getBytes(length);
  8666. this.pos -= bytes.length;
  8667. return bytes;
  8668. },
  8669. getByteRange: function ChunkedStream_getBytes(begin, end) {
  8670. this.ensureRange(begin, end);
  8671. return this.bytes.subarray(begin, end);
  8672. },
  8673. skip: function ChunkedStream_skip(n) {
  8674. if (!n) {
  8675. n = 1;
  8676. }
  8677. this.pos += n;
  8678. },
  8679. reset: function ChunkedStream_reset() {
  8680. this.pos = this.start;
  8681. },
  8682. moveStart: function ChunkedStream_moveStart() {
  8683. this.start = this.pos;
  8684. },
  8685. makeSubStream: function ChunkedStream_makeSubStream(start, length, dict) {
  8686. this.ensureRange(start, start + length);
  8687. function ChunkedStreamSubstream() {
  8688. }
  8689. ChunkedStreamSubstream.prototype = Object.create(this);
  8690. ChunkedStreamSubstream.prototype.getMissingChunks = function () {
  8691. var chunkSize = this.chunkSize;
  8692. var beginChunk = Math.floor(this.start / chunkSize);
  8693. var endChunk = Math.floor((this.end - 1) / chunkSize) + 1;
  8694. var missingChunks = [];
  8695. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  8696. if (!this.loadedChunks[chunk]) {
  8697. missingChunks.push(chunk);
  8698. }
  8699. }
  8700. return missingChunks;
  8701. };
  8702. var subStream = new ChunkedStreamSubstream();
  8703. subStream.pos = subStream.start = start;
  8704. subStream.end = start + length || this.end;
  8705. subStream.dict = dict;
  8706. return subStream;
  8707. },
  8708. isStream: true
  8709. };
  8710. return ChunkedStream;
  8711. }();
  8712. var ChunkedStreamManager = function ChunkedStreamManagerClosure() {
  8713. function ChunkedStreamManager(pdfNetworkStream, args) {
  8714. var chunkSize = args.rangeChunkSize;
  8715. var length = args.length;
  8716. this.stream = new ChunkedStream(length, chunkSize, this);
  8717. this.length = length;
  8718. this.chunkSize = chunkSize;
  8719. this.pdfNetworkStream = pdfNetworkStream;
  8720. this.url = args.url;
  8721. this.disableAutoFetch = args.disableAutoFetch;
  8722. this.msgHandler = args.msgHandler;
  8723. this.currRequestId = 0;
  8724. this.chunksNeededByRequest = Object.create(null);
  8725. this.requestsByChunk = Object.create(null);
  8726. this.promisesByRequest = Object.create(null);
  8727. this.progressiveDataLength = 0;
  8728. this.aborted = false;
  8729. this._loadedStreamCapability = createPromiseCapability();
  8730. }
  8731. ChunkedStreamManager.prototype = {
  8732. onLoadedStream: function ChunkedStreamManager_getLoadedStream() {
  8733. return this._loadedStreamCapability.promise;
  8734. },
  8735. sendRequest: function ChunkedStreamManager_sendRequest(begin, end) {
  8736. var rangeReader = this.pdfNetworkStream.getRangeReader(begin, end);
  8737. if (!rangeReader.isStreamingSupported) {
  8738. rangeReader.onProgress = this.onProgress.bind(this);
  8739. }
  8740. var chunks = [], loaded = 0;
  8741. var manager = this;
  8742. var promise = new Promise(function (resolve, reject) {
  8743. var readChunk = function (chunk) {
  8744. try {
  8745. if (!chunk.done) {
  8746. var data = chunk.value;
  8747. chunks.push(data);
  8748. loaded += arrayByteLength(data);
  8749. if (rangeReader.isStreamingSupported) {
  8750. manager.onProgress({ loaded: loaded });
  8751. }
  8752. rangeReader.read().then(readChunk, reject);
  8753. return;
  8754. }
  8755. var chunkData = arraysToBytes(chunks);
  8756. chunks = null;
  8757. resolve(chunkData);
  8758. } catch (e) {
  8759. reject(e);
  8760. }
  8761. };
  8762. rangeReader.read().then(readChunk, reject);
  8763. });
  8764. promise.then(function (data) {
  8765. if (this.aborted) {
  8766. return;
  8767. }
  8768. // ignoring any data after abort
  8769. this.onReceiveData({
  8770. chunk: data,
  8771. begin: begin
  8772. });
  8773. }.bind(this));
  8774. },
  8775. // TODO check errors
  8776. // Get all the chunks that are not yet loaded and groups them into
  8777. // contiguous ranges to load in as few requests as possible
  8778. requestAllChunks: function ChunkedStreamManager_requestAllChunks() {
  8779. var missingChunks = this.stream.getMissingChunks();
  8780. this._requestChunks(missingChunks);
  8781. return this._loadedStreamCapability.promise;
  8782. },
  8783. _requestChunks: function ChunkedStreamManager_requestChunks(chunks) {
  8784. var requestId = this.currRequestId++;
  8785. var i, ii;
  8786. var chunksNeeded = Object.create(null);
  8787. this.chunksNeededByRequest[requestId] = chunksNeeded;
  8788. for (i = 0, ii = chunks.length; i < ii; i++) {
  8789. if (!this.stream.hasChunk(chunks[i])) {
  8790. chunksNeeded[chunks[i]] = true;
  8791. }
  8792. }
  8793. if (isEmptyObj(chunksNeeded)) {
  8794. return Promise.resolve();
  8795. }
  8796. var capability = createPromiseCapability();
  8797. this.promisesByRequest[requestId] = capability;
  8798. var chunksToRequest = [];
  8799. for (var chunk in chunksNeeded) {
  8800. chunk = chunk | 0;
  8801. if (!(chunk in this.requestsByChunk)) {
  8802. this.requestsByChunk[chunk] = [];
  8803. chunksToRequest.push(chunk);
  8804. }
  8805. this.requestsByChunk[chunk].push(requestId);
  8806. }
  8807. if (!chunksToRequest.length) {
  8808. return capability.promise;
  8809. }
  8810. var groupedChunksToRequest = this.groupChunks(chunksToRequest);
  8811. for (i = 0; i < groupedChunksToRequest.length; ++i) {
  8812. var groupedChunk = groupedChunksToRequest[i];
  8813. var begin = groupedChunk.beginChunk * this.chunkSize;
  8814. var end = Math.min(groupedChunk.endChunk * this.chunkSize, this.length);
  8815. this.sendRequest(begin, end);
  8816. }
  8817. return capability.promise;
  8818. },
  8819. getStream: function ChunkedStreamManager_getStream() {
  8820. return this.stream;
  8821. },
  8822. // Loads any chunks in the requested range that are not yet loaded
  8823. requestRange: function ChunkedStreamManager_requestRange(begin, end) {
  8824. end = Math.min(end, this.length);
  8825. var beginChunk = this.getBeginChunk(begin);
  8826. var endChunk = this.getEndChunk(end);
  8827. var chunks = [];
  8828. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  8829. chunks.push(chunk);
  8830. }
  8831. return this._requestChunks(chunks);
  8832. },
  8833. requestRanges: function ChunkedStreamManager_requestRanges(ranges) {
  8834. ranges = ranges || [];
  8835. var chunksToRequest = [];
  8836. for (var i = 0; i < ranges.length; i++) {
  8837. var beginChunk = this.getBeginChunk(ranges[i].begin);
  8838. var endChunk = this.getEndChunk(ranges[i].end);
  8839. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  8840. if (chunksToRequest.indexOf(chunk) < 0) {
  8841. chunksToRequest.push(chunk);
  8842. }
  8843. }
  8844. }
  8845. chunksToRequest.sort(function (a, b) {
  8846. return a - b;
  8847. });
  8848. return this._requestChunks(chunksToRequest);
  8849. },
  8850. // Groups a sorted array of chunks into as few contiguous larger
  8851. // chunks as possible
  8852. groupChunks: function ChunkedStreamManager_groupChunks(chunks) {
  8853. var groupedChunks = [];
  8854. var beginChunk = -1;
  8855. var prevChunk = -1;
  8856. for (var i = 0; i < chunks.length; ++i) {
  8857. var chunk = chunks[i];
  8858. if (beginChunk < 0) {
  8859. beginChunk = chunk;
  8860. }
  8861. if (prevChunk >= 0 && prevChunk + 1 !== chunk) {
  8862. groupedChunks.push({
  8863. beginChunk: beginChunk,
  8864. endChunk: prevChunk + 1
  8865. });
  8866. beginChunk = chunk;
  8867. }
  8868. if (i + 1 === chunks.length) {
  8869. groupedChunks.push({
  8870. beginChunk: beginChunk,
  8871. endChunk: chunk + 1
  8872. });
  8873. }
  8874. prevChunk = chunk;
  8875. }
  8876. return groupedChunks;
  8877. },
  8878. onProgress: function ChunkedStreamManager_onProgress(args) {
  8879. var bytesLoaded = this.stream.numChunksLoaded * this.chunkSize + args.loaded;
  8880. this.msgHandler.send('DocProgress', {
  8881. loaded: bytesLoaded,
  8882. total: this.length
  8883. });
  8884. },
  8885. onReceiveData: function ChunkedStreamManager_onReceiveData(args) {
  8886. var chunk = args.chunk;
  8887. var isProgressive = args.begin === undefined;
  8888. var begin = isProgressive ? this.progressiveDataLength : args.begin;
  8889. var end = begin + chunk.byteLength;
  8890. var beginChunk = Math.floor(begin / this.chunkSize);
  8891. var endChunk = end < this.length ? Math.floor(end / this.chunkSize) : Math.ceil(end / this.chunkSize);
  8892. if (isProgressive) {
  8893. this.stream.onReceiveProgressiveData(chunk);
  8894. this.progressiveDataLength = end;
  8895. } else {
  8896. this.stream.onReceiveData(begin, chunk);
  8897. }
  8898. if (this.stream.allChunksLoaded()) {
  8899. this._loadedStreamCapability.resolve(this.stream);
  8900. }
  8901. var loadedRequests = [];
  8902. var i, requestId;
  8903. for (chunk = beginChunk; chunk < endChunk; ++chunk) {
  8904. // The server might return more chunks than requested
  8905. var requestIds = this.requestsByChunk[chunk] || [];
  8906. delete this.requestsByChunk[chunk];
  8907. for (i = 0; i < requestIds.length; ++i) {
  8908. requestId = requestIds[i];
  8909. var chunksNeeded = this.chunksNeededByRequest[requestId];
  8910. if (chunk in chunksNeeded) {
  8911. delete chunksNeeded[chunk];
  8912. }
  8913. if (!isEmptyObj(chunksNeeded)) {
  8914. continue;
  8915. }
  8916. loadedRequests.push(requestId);
  8917. }
  8918. }
  8919. // If there are no pending requests, automatically fetch the next
  8920. // unfetched chunk of the PDF
  8921. if (!this.disableAutoFetch && isEmptyObj(this.requestsByChunk)) {
  8922. var nextEmptyChunk;
  8923. if (this.stream.numChunksLoaded === 1) {
  8924. // This is a special optimization so that after fetching the first
  8925. // chunk, rather than fetching the second chunk, we fetch the last
  8926. // chunk.
  8927. var lastChunk = this.stream.numChunks - 1;
  8928. if (!this.stream.hasChunk(lastChunk)) {
  8929. nextEmptyChunk = lastChunk;
  8930. }
  8931. } else {
  8932. nextEmptyChunk = this.stream.nextEmptyChunk(endChunk);
  8933. }
  8934. if (isInt(nextEmptyChunk)) {
  8935. this._requestChunks([nextEmptyChunk]);
  8936. }
  8937. }
  8938. for (i = 0; i < loadedRequests.length; ++i) {
  8939. requestId = loadedRequests[i];
  8940. var capability = this.promisesByRequest[requestId];
  8941. delete this.promisesByRequest[requestId];
  8942. capability.resolve();
  8943. }
  8944. this.msgHandler.send('DocProgress', {
  8945. loaded: this.stream.numChunksLoaded * this.chunkSize,
  8946. total: this.length
  8947. });
  8948. },
  8949. onError: function ChunkedStreamManager_onError(err) {
  8950. this._loadedStreamCapability.reject(err);
  8951. },
  8952. getBeginChunk: function ChunkedStreamManager_getBeginChunk(begin) {
  8953. var chunk = Math.floor(begin / this.chunkSize);
  8954. return chunk;
  8955. },
  8956. getEndChunk: function ChunkedStreamManager_getEndChunk(end) {
  8957. var chunk = Math.floor((end - 1) / this.chunkSize) + 1;
  8958. return chunk;
  8959. },
  8960. abort: function ChunkedStreamManager_abort() {
  8961. this.aborted = true;
  8962. if (this.pdfNetworkStream) {
  8963. this.pdfNetworkStream.cancelAllRequests('abort');
  8964. }
  8965. for (var requestId in this.promisesByRequest) {
  8966. var capability = this.promisesByRequest[requestId];
  8967. capability.reject(new Error('Request was aborted'));
  8968. }
  8969. }
  8970. };
  8971. return ChunkedStreamManager;
  8972. }();
  8973. exports.ChunkedStream = ChunkedStream;
  8974. exports.ChunkedStreamManager = ChunkedStreamManager;
  8975. }));
  8976. (function (root, factory) {
  8977. factory(root.pdfjsCoreGlyphList = {}, root.pdfjsSharedUtil);
  8978. }(this, function (exports, sharedUtil) {
  8979. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  8980. var getGlyphsUnicode = getLookupTableFactory(function (t) {
  8981. t['A'] = 0x0041;
  8982. t['AE'] = 0x00C6;
  8983. t['AEacute'] = 0x01FC;
  8984. t['AEmacron'] = 0x01E2;
  8985. t['AEsmall'] = 0xF7E6;
  8986. t['Aacute'] = 0x00C1;
  8987. t['Aacutesmall'] = 0xF7E1;
  8988. t['Abreve'] = 0x0102;
  8989. t['Abreveacute'] = 0x1EAE;
  8990. t['Abrevecyrillic'] = 0x04D0;
  8991. t['Abrevedotbelow'] = 0x1EB6;
  8992. t['Abrevegrave'] = 0x1EB0;
  8993. t['Abrevehookabove'] = 0x1EB2;
  8994. t['Abrevetilde'] = 0x1EB4;
  8995. t['Acaron'] = 0x01CD;
  8996. t['Acircle'] = 0x24B6;
  8997. t['Acircumflex'] = 0x00C2;
  8998. t['Acircumflexacute'] = 0x1EA4;
  8999. t['Acircumflexdotbelow'] = 0x1EAC;
  9000. t['Acircumflexgrave'] = 0x1EA6;
  9001. t['Acircumflexhookabove'] = 0x1EA8;
  9002. t['Acircumflexsmall'] = 0xF7E2;
  9003. t['Acircumflextilde'] = 0x1EAA;
  9004. t['Acute'] = 0xF6C9;
  9005. t['Acutesmall'] = 0xF7B4;
  9006. t['Acyrillic'] = 0x0410;
  9007. t['Adblgrave'] = 0x0200;
  9008. t['Adieresis'] = 0x00C4;
  9009. t['Adieresiscyrillic'] = 0x04D2;
  9010. t['Adieresismacron'] = 0x01DE;
  9011. t['Adieresissmall'] = 0xF7E4;
  9012. t['Adotbelow'] = 0x1EA0;
  9013. t['Adotmacron'] = 0x01E0;
  9014. t['Agrave'] = 0x00C0;
  9015. t['Agravesmall'] = 0xF7E0;
  9016. t['Ahookabove'] = 0x1EA2;
  9017. t['Aiecyrillic'] = 0x04D4;
  9018. t['Ainvertedbreve'] = 0x0202;
  9019. t['Alpha'] = 0x0391;
  9020. t['Alphatonos'] = 0x0386;
  9021. t['Amacron'] = 0x0100;
  9022. t['Amonospace'] = 0xFF21;
  9023. t['Aogonek'] = 0x0104;
  9024. t['Aring'] = 0x00C5;
  9025. t['Aringacute'] = 0x01FA;
  9026. t['Aringbelow'] = 0x1E00;
  9027. t['Aringsmall'] = 0xF7E5;
  9028. t['Asmall'] = 0xF761;
  9029. t['Atilde'] = 0x00C3;
  9030. t['Atildesmall'] = 0xF7E3;
  9031. t['Aybarmenian'] = 0x0531;
  9032. t['B'] = 0x0042;
  9033. t['Bcircle'] = 0x24B7;
  9034. t['Bdotaccent'] = 0x1E02;
  9035. t['Bdotbelow'] = 0x1E04;
  9036. t['Becyrillic'] = 0x0411;
  9037. t['Benarmenian'] = 0x0532;
  9038. t['Beta'] = 0x0392;
  9039. t['Bhook'] = 0x0181;
  9040. t['Blinebelow'] = 0x1E06;
  9041. t['Bmonospace'] = 0xFF22;
  9042. t['Brevesmall'] = 0xF6F4;
  9043. t['Bsmall'] = 0xF762;
  9044. t['Btopbar'] = 0x0182;
  9045. t['C'] = 0x0043;
  9046. t['Caarmenian'] = 0x053E;
  9047. t['Cacute'] = 0x0106;
  9048. t['Caron'] = 0xF6CA;
  9049. t['Caronsmall'] = 0xF6F5;
  9050. t['Ccaron'] = 0x010C;
  9051. t['Ccedilla'] = 0x00C7;
  9052. t['Ccedillaacute'] = 0x1E08;
  9053. t['Ccedillasmall'] = 0xF7E7;
  9054. t['Ccircle'] = 0x24B8;
  9055. t['Ccircumflex'] = 0x0108;
  9056. t['Cdot'] = 0x010A;
  9057. t['Cdotaccent'] = 0x010A;
  9058. t['Cedillasmall'] = 0xF7B8;
  9059. t['Chaarmenian'] = 0x0549;
  9060. t['Cheabkhasiancyrillic'] = 0x04BC;
  9061. t['Checyrillic'] = 0x0427;
  9062. t['Chedescenderabkhasiancyrillic'] = 0x04BE;
  9063. t['Chedescendercyrillic'] = 0x04B6;
  9064. t['Chedieresiscyrillic'] = 0x04F4;
  9065. t['Cheharmenian'] = 0x0543;
  9066. t['Chekhakassiancyrillic'] = 0x04CB;
  9067. t['Cheverticalstrokecyrillic'] = 0x04B8;
  9068. t['Chi'] = 0x03A7;
  9069. t['Chook'] = 0x0187;
  9070. t['Circumflexsmall'] = 0xF6F6;
  9071. t['Cmonospace'] = 0xFF23;
  9072. t['Coarmenian'] = 0x0551;
  9073. t['Csmall'] = 0xF763;
  9074. t['D'] = 0x0044;
  9075. t['DZ'] = 0x01F1;
  9076. t['DZcaron'] = 0x01C4;
  9077. t['Daarmenian'] = 0x0534;
  9078. t['Dafrican'] = 0x0189;
  9079. t['Dcaron'] = 0x010E;
  9080. t['Dcedilla'] = 0x1E10;
  9081. t['Dcircle'] = 0x24B9;
  9082. t['Dcircumflexbelow'] = 0x1E12;
  9083. t['Dcroat'] = 0x0110;
  9084. t['Ddotaccent'] = 0x1E0A;
  9085. t['Ddotbelow'] = 0x1E0C;
  9086. t['Decyrillic'] = 0x0414;
  9087. t['Deicoptic'] = 0x03EE;
  9088. t['Delta'] = 0x2206;
  9089. t['Deltagreek'] = 0x0394;
  9090. t['Dhook'] = 0x018A;
  9091. t['Dieresis'] = 0xF6CB;
  9092. t['DieresisAcute'] = 0xF6CC;
  9093. t['DieresisGrave'] = 0xF6CD;
  9094. t['Dieresissmall'] = 0xF7A8;
  9095. t['Digammagreek'] = 0x03DC;
  9096. t['Djecyrillic'] = 0x0402;
  9097. t['Dlinebelow'] = 0x1E0E;
  9098. t['Dmonospace'] = 0xFF24;
  9099. t['Dotaccentsmall'] = 0xF6F7;
  9100. t['Dslash'] = 0x0110;
  9101. t['Dsmall'] = 0xF764;
  9102. t['Dtopbar'] = 0x018B;
  9103. t['Dz'] = 0x01F2;
  9104. t['Dzcaron'] = 0x01C5;
  9105. t['Dzeabkhasiancyrillic'] = 0x04E0;
  9106. t['Dzecyrillic'] = 0x0405;
  9107. t['Dzhecyrillic'] = 0x040F;
  9108. t['E'] = 0x0045;
  9109. t['Eacute'] = 0x00C9;
  9110. t['Eacutesmall'] = 0xF7E9;
  9111. t['Ebreve'] = 0x0114;
  9112. t['Ecaron'] = 0x011A;
  9113. t['Ecedillabreve'] = 0x1E1C;
  9114. t['Echarmenian'] = 0x0535;
  9115. t['Ecircle'] = 0x24BA;
  9116. t['Ecircumflex'] = 0x00CA;
  9117. t['Ecircumflexacute'] = 0x1EBE;
  9118. t['Ecircumflexbelow'] = 0x1E18;
  9119. t['Ecircumflexdotbelow'] = 0x1EC6;
  9120. t['Ecircumflexgrave'] = 0x1EC0;
  9121. t['Ecircumflexhookabove'] = 0x1EC2;
  9122. t['Ecircumflexsmall'] = 0xF7EA;
  9123. t['Ecircumflextilde'] = 0x1EC4;
  9124. t['Ecyrillic'] = 0x0404;
  9125. t['Edblgrave'] = 0x0204;
  9126. t['Edieresis'] = 0x00CB;
  9127. t['Edieresissmall'] = 0xF7EB;
  9128. t['Edot'] = 0x0116;
  9129. t['Edotaccent'] = 0x0116;
  9130. t['Edotbelow'] = 0x1EB8;
  9131. t['Efcyrillic'] = 0x0424;
  9132. t['Egrave'] = 0x00C8;
  9133. t['Egravesmall'] = 0xF7E8;
  9134. t['Eharmenian'] = 0x0537;
  9135. t['Ehookabove'] = 0x1EBA;
  9136. t['Eightroman'] = 0x2167;
  9137. t['Einvertedbreve'] = 0x0206;
  9138. t['Eiotifiedcyrillic'] = 0x0464;
  9139. t['Elcyrillic'] = 0x041B;
  9140. t['Elevenroman'] = 0x216A;
  9141. t['Emacron'] = 0x0112;
  9142. t['Emacronacute'] = 0x1E16;
  9143. t['Emacrongrave'] = 0x1E14;
  9144. t['Emcyrillic'] = 0x041C;
  9145. t['Emonospace'] = 0xFF25;
  9146. t['Encyrillic'] = 0x041D;
  9147. t['Endescendercyrillic'] = 0x04A2;
  9148. t['Eng'] = 0x014A;
  9149. t['Enghecyrillic'] = 0x04A4;
  9150. t['Enhookcyrillic'] = 0x04C7;
  9151. t['Eogonek'] = 0x0118;
  9152. t['Eopen'] = 0x0190;
  9153. t['Epsilon'] = 0x0395;
  9154. t['Epsilontonos'] = 0x0388;
  9155. t['Ercyrillic'] = 0x0420;
  9156. t['Ereversed'] = 0x018E;
  9157. t['Ereversedcyrillic'] = 0x042D;
  9158. t['Escyrillic'] = 0x0421;
  9159. t['Esdescendercyrillic'] = 0x04AA;
  9160. t['Esh'] = 0x01A9;
  9161. t['Esmall'] = 0xF765;
  9162. t['Eta'] = 0x0397;
  9163. t['Etarmenian'] = 0x0538;
  9164. t['Etatonos'] = 0x0389;
  9165. t['Eth'] = 0x00D0;
  9166. t['Ethsmall'] = 0xF7F0;
  9167. t['Etilde'] = 0x1EBC;
  9168. t['Etildebelow'] = 0x1E1A;
  9169. t['Euro'] = 0x20AC;
  9170. t['Ezh'] = 0x01B7;
  9171. t['Ezhcaron'] = 0x01EE;
  9172. t['Ezhreversed'] = 0x01B8;
  9173. t['F'] = 0x0046;
  9174. t['Fcircle'] = 0x24BB;
  9175. t['Fdotaccent'] = 0x1E1E;
  9176. t['Feharmenian'] = 0x0556;
  9177. t['Feicoptic'] = 0x03E4;
  9178. t['Fhook'] = 0x0191;
  9179. t['Fitacyrillic'] = 0x0472;
  9180. t['Fiveroman'] = 0x2164;
  9181. t['Fmonospace'] = 0xFF26;
  9182. t['Fourroman'] = 0x2163;
  9183. t['Fsmall'] = 0xF766;
  9184. t['G'] = 0x0047;
  9185. t['GBsquare'] = 0x3387;
  9186. t['Gacute'] = 0x01F4;
  9187. t['Gamma'] = 0x0393;
  9188. t['Gammaafrican'] = 0x0194;
  9189. t['Gangiacoptic'] = 0x03EA;
  9190. t['Gbreve'] = 0x011E;
  9191. t['Gcaron'] = 0x01E6;
  9192. t['Gcedilla'] = 0x0122;
  9193. t['Gcircle'] = 0x24BC;
  9194. t['Gcircumflex'] = 0x011C;
  9195. t['Gcommaaccent'] = 0x0122;
  9196. t['Gdot'] = 0x0120;
  9197. t['Gdotaccent'] = 0x0120;
  9198. t['Gecyrillic'] = 0x0413;
  9199. t['Ghadarmenian'] = 0x0542;
  9200. t['Ghemiddlehookcyrillic'] = 0x0494;
  9201. t['Ghestrokecyrillic'] = 0x0492;
  9202. t['Gheupturncyrillic'] = 0x0490;
  9203. t['Ghook'] = 0x0193;
  9204. t['Gimarmenian'] = 0x0533;
  9205. t['Gjecyrillic'] = 0x0403;
  9206. t['Gmacron'] = 0x1E20;
  9207. t['Gmonospace'] = 0xFF27;
  9208. t['Grave'] = 0xF6CE;
  9209. t['Gravesmall'] = 0xF760;
  9210. t['Gsmall'] = 0xF767;
  9211. t['Gsmallhook'] = 0x029B;
  9212. t['Gstroke'] = 0x01E4;
  9213. t['H'] = 0x0048;
  9214. t['H18533'] = 0x25CF;
  9215. t['H18543'] = 0x25AA;
  9216. t['H18551'] = 0x25AB;
  9217. t['H22073'] = 0x25A1;
  9218. t['HPsquare'] = 0x33CB;
  9219. t['Haabkhasiancyrillic'] = 0x04A8;
  9220. t['Hadescendercyrillic'] = 0x04B2;
  9221. t['Hardsigncyrillic'] = 0x042A;
  9222. t['Hbar'] = 0x0126;
  9223. t['Hbrevebelow'] = 0x1E2A;
  9224. t['Hcedilla'] = 0x1E28;
  9225. t['Hcircle'] = 0x24BD;
  9226. t['Hcircumflex'] = 0x0124;
  9227. t['Hdieresis'] = 0x1E26;
  9228. t['Hdotaccent'] = 0x1E22;
  9229. t['Hdotbelow'] = 0x1E24;
  9230. t['Hmonospace'] = 0xFF28;
  9231. t['Hoarmenian'] = 0x0540;
  9232. t['Horicoptic'] = 0x03E8;
  9233. t['Hsmall'] = 0xF768;
  9234. t['Hungarumlaut'] = 0xF6CF;
  9235. t['Hungarumlautsmall'] = 0xF6F8;
  9236. t['Hzsquare'] = 0x3390;
  9237. t['I'] = 0x0049;
  9238. t['IAcyrillic'] = 0x042F;
  9239. t['IJ'] = 0x0132;
  9240. t['IUcyrillic'] = 0x042E;
  9241. t['Iacute'] = 0x00CD;
  9242. t['Iacutesmall'] = 0xF7ED;
  9243. t['Ibreve'] = 0x012C;
  9244. t['Icaron'] = 0x01CF;
  9245. t['Icircle'] = 0x24BE;
  9246. t['Icircumflex'] = 0x00CE;
  9247. t['Icircumflexsmall'] = 0xF7EE;
  9248. t['Icyrillic'] = 0x0406;
  9249. t['Idblgrave'] = 0x0208;
  9250. t['Idieresis'] = 0x00CF;
  9251. t['Idieresisacute'] = 0x1E2E;
  9252. t['Idieresiscyrillic'] = 0x04E4;
  9253. t['Idieresissmall'] = 0xF7EF;
  9254. t['Idot'] = 0x0130;
  9255. t['Idotaccent'] = 0x0130;
  9256. t['Idotbelow'] = 0x1ECA;
  9257. t['Iebrevecyrillic'] = 0x04D6;
  9258. t['Iecyrillic'] = 0x0415;
  9259. t['Ifraktur'] = 0x2111;
  9260. t['Igrave'] = 0x00CC;
  9261. t['Igravesmall'] = 0xF7EC;
  9262. t['Ihookabove'] = 0x1EC8;
  9263. t['Iicyrillic'] = 0x0418;
  9264. t['Iinvertedbreve'] = 0x020A;
  9265. t['Iishortcyrillic'] = 0x0419;
  9266. t['Imacron'] = 0x012A;
  9267. t['Imacroncyrillic'] = 0x04E2;
  9268. t['Imonospace'] = 0xFF29;
  9269. t['Iniarmenian'] = 0x053B;
  9270. t['Iocyrillic'] = 0x0401;
  9271. t['Iogonek'] = 0x012E;
  9272. t['Iota'] = 0x0399;
  9273. t['Iotaafrican'] = 0x0196;
  9274. t['Iotadieresis'] = 0x03AA;
  9275. t['Iotatonos'] = 0x038A;
  9276. t['Ismall'] = 0xF769;
  9277. t['Istroke'] = 0x0197;
  9278. t['Itilde'] = 0x0128;
  9279. t['Itildebelow'] = 0x1E2C;
  9280. t['Izhitsacyrillic'] = 0x0474;
  9281. t['Izhitsadblgravecyrillic'] = 0x0476;
  9282. t['J'] = 0x004A;
  9283. t['Jaarmenian'] = 0x0541;
  9284. t['Jcircle'] = 0x24BF;
  9285. t['Jcircumflex'] = 0x0134;
  9286. t['Jecyrillic'] = 0x0408;
  9287. t['Jheharmenian'] = 0x054B;
  9288. t['Jmonospace'] = 0xFF2A;
  9289. t['Jsmall'] = 0xF76A;
  9290. t['K'] = 0x004B;
  9291. t['KBsquare'] = 0x3385;
  9292. t['KKsquare'] = 0x33CD;
  9293. t['Kabashkircyrillic'] = 0x04A0;
  9294. t['Kacute'] = 0x1E30;
  9295. t['Kacyrillic'] = 0x041A;
  9296. t['Kadescendercyrillic'] = 0x049A;
  9297. t['Kahookcyrillic'] = 0x04C3;
  9298. t['Kappa'] = 0x039A;
  9299. t['Kastrokecyrillic'] = 0x049E;
  9300. t['Kaverticalstrokecyrillic'] = 0x049C;
  9301. t['Kcaron'] = 0x01E8;
  9302. t['Kcedilla'] = 0x0136;
  9303. t['Kcircle'] = 0x24C0;
  9304. t['Kcommaaccent'] = 0x0136;
  9305. t['Kdotbelow'] = 0x1E32;
  9306. t['Keharmenian'] = 0x0554;
  9307. t['Kenarmenian'] = 0x053F;
  9308. t['Khacyrillic'] = 0x0425;
  9309. t['Kheicoptic'] = 0x03E6;
  9310. t['Khook'] = 0x0198;
  9311. t['Kjecyrillic'] = 0x040C;
  9312. t['Klinebelow'] = 0x1E34;
  9313. t['Kmonospace'] = 0xFF2B;
  9314. t['Koppacyrillic'] = 0x0480;
  9315. t['Koppagreek'] = 0x03DE;
  9316. t['Ksicyrillic'] = 0x046E;
  9317. t['Ksmall'] = 0xF76B;
  9318. t['L'] = 0x004C;
  9319. t['LJ'] = 0x01C7;
  9320. t['LL'] = 0xF6BF;
  9321. t['Lacute'] = 0x0139;
  9322. t['Lambda'] = 0x039B;
  9323. t['Lcaron'] = 0x013D;
  9324. t['Lcedilla'] = 0x013B;
  9325. t['Lcircle'] = 0x24C1;
  9326. t['Lcircumflexbelow'] = 0x1E3C;
  9327. t['Lcommaaccent'] = 0x013B;
  9328. t['Ldot'] = 0x013F;
  9329. t['Ldotaccent'] = 0x013F;
  9330. t['Ldotbelow'] = 0x1E36;
  9331. t['Ldotbelowmacron'] = 0x1E38;
  9332. t['Liwnarmenian'] = 0x053C;
  9333. t['Lj'] = 0x01C8;
  9334. t['Ljecyrillic'] = 0x0409;
  9335. t['Llinebelow'] = 0x1E3A;
  9336. t['Lmonospace'] = 0xFF2C;
  9337. t['Lslash'] = 0x0141;
  9338. t['Lslashsmall'] = 0xF6F9;
  9339. t['Lsmall'] = 0xF76C;
  9340. t['M'] = 0x004D;
  9341. t['MBsquare'] = 0x3386;
  9342. t['Macron'] = 0xF6D0;
  9343. t['Macronsmall'] = 0xF7AF;
  9344. t['Macute'] = 0x1E3E;
  9345. t['Mcircle'] = 0x24C2;
  9346. t['Mdotaccent'] = 0x1E40;
  9347. t['Mdotbelow'] = 0x1E42;
  9348. t['Menarmenian'] = 0x0544;
  9349. t['Mmonospace'] = 0xFF2D;
  9350. t['Msmall'] = 0xF76D;
  9351. t['Mturned'] = 0x019C;
  9352. t['Mu'] = 0x039C;
  9353. t['N'] = 0x004E;
  9354. t['NJ'] = 0x01CA;
  9355. t['Nacute'] = 0x0143;
  9356. t['Ncaron'] = 0x0147;
  9357. t['Ncedilla'] = 0x0145;
  9358. t['Ncircle'] = 0x24C3;
  9359. t['Ncircumflexbelow'] = 0x1E4A;
  9360. t['Ncommaaccent'] = 0x0145;
  9361. t['Ndotaccent'] = 0x1E44;
  9362. t['Ndotbelow'] = 0x1E46;
  9363. t['Nhookleft'] = 0x019D;
  9364. t['Nineroman'] = 0x2168;
  9365. t['Nj'] = 0x01CB;
  9366. t['Njecyrillic'] = 0x040A;
  9367. t['Nlinebelow'] = 0x1E48;
  9368. t['Nmonospace'] = 0xFF2E;
  9369. t['Nowarmenian'] = 0x0546;
  9370. t['Nsmall'] = 0xF76E;
  9371. t['Ntilde'] = 0x00D1;
  9372. t['Ntildesmall'] = 0xF7F1;
  9373. t['Nu'] = 0x039D;
  9374. t['O'] = 0x004F;
  9375. t['OE'] = 0x0152;
  9376. t['OEsmall'] = 0xF6FA;
  9377. t['Oacute'] = 0x00D3;
  9378. t['Oacutesmall'] = 0xF7F3;
  9379. t['Obarredcyrillic'] = 0x04E8;
  9380. t['Obarreddieresiscyrillic'] = 0x04EA;
  9381. t['Obreve'] = 0x014E;
  9382. t['Ocaron'] = 0x01D1;
  9383. t['Ocenteredtilde'] = 0x019F;
  9384. t['Ocircle'] = 0x24C4;
  9385. t['Ocircumflex'] = 0x00D4;
  9386. t['Ocircumflexacute'] = 0x1ED0;
  9387. t['Ocircumflexdotbelow'] = 0x1ED8;
  9388. t['Ocircumflexgrave'] = 0x1ED2;
  9389. t['Ocircumflexhookabove'] = 0x1ED4;
  9390. t['Ocircumflexsmall'] = 0xF7F4;
  9391. t['Ocircumflextilde'] = 0x1ED6;
  9392. t['Ocyrillic'] = 0x041E;
  9393. t['Odblacute'] = 0x0150;
  9394. t['Odblgrave'] = 0x020C;
  9395. t['Odieresis'] = 0x00D6;
  9396. t['Odieresiscyrillic'] = 0x04E6;
  9397. t['Odieresissmall'] = 0xF7F6;
  9398. t['Odotbelow'] = 0x1ECC;
  9399. t['Ogoneksmall'] = 0xF6FB;
  9400. t['Ograve'] = 0x00D2;
  9401. t['Ogravesmall'] = 0xF7F2;
  9402. t['Oharmenian'] = 0x0555;
  9403. t['Ohm'] = 0x2126;
  9404. t['Ohookabove'] = 0x1ECE;
  9405. t['Ohorn'] = 0x01A0;
  9406. t['Ohornacute'] = 0x1EDA;
  9407. t['Ohorndotbelow'] = 0x1EE2;
  9408. t['Ohorngrave'] = 0x1EDC;
  9409. t['Ohornhookabove'] = 0x1EDE;
  9410. t['Ohorntilde'] = 0x1EE0;
  9411. t['Ohungarumlaut'] = 0x0150;
  9412. t['Oi'] = 0x01A2;
  9413. t['Oinvertedbreve'] = 0x020E;
  9414. t['Omacron'] = 0x014C;
  9415. t['Omacronacute'] = 0x1E52;
  9416. t['Omacrongrave'] = 0x1E50;
  9417. t['Omega'] = 0x2126;
  9418. t['Omegacyrillic'] = 0x0460;
  9419. t['Omegagreek'] = 0x03A9;
  9420. t['Omegaroundcyrillic'] = 0x047A;
  9421. t['Omegatitlocyrillic'] = 0x047C;
  9422. t['Omegatonos'] = 0x038F;
  9423. t['Omicron'] = 0x039F;
  9424. t['Omicrontonos'] = 0x038C;
  9425. t['Omonospace'] = 0xFF2F;
  9426. t['Oneroman'] = 0x2160;
  9427. t['Oogonek'] = 0x01EA;
  9428. t['Oogonekmacron'] = 0x01EC;
  9429. t['Oopen'] = 0x0186;
  9430. t['Oslash'] = 0x00D8;
  9431. t['Oslashacute'] = 0x01FE;
  9432. t['Oslashsmall'] = 0xF7F8;
  9433. t['Osmall'] = 0xF76F;
  9434. t['Ostrokeacute'] = 0x01FE;
  9435. t['Otcyrillic'] = 0x047E;
  9436. t['Otilde'] = 0x00D5;
  9437. t['Otildeacute'] = 0x1E4C;
  9438. t['Otildedieresis'] = 0x1E4E;
  9439. t['Otildesmall'] = 0xF7F5;
  9440. t['P'] = 0x0050;
  9441. t['Pacute'] = 0x1E54;
  9442. t['Pcircle'] = 0x24C5;
  9443. t['Pdotaccent'] = 0x1E56;
  9444. t['Pecyrillic'] = 0x041F;
  9445. t['Peharmenian'] = 0x054A;
  9446. t['Pemiddlehookcyrillic'] = 0x04A6;
  9447. t['Phi'] = 0x03A6;
  9448. t['Phook'] = 0x01A4;
  9449. t['Pi'] = 0x03A0;
  9450. t['Piwrarmenian'] = 0x0553;
  9451. t['Pmonospace'] = 0xFF30;
  9452. t['Psi'] = 0x03A8;
  9453. t['Psicyrillic'] = 0x0470;
  9454. t['Psmall'] = 0xF770;
  9455. t['Q'] = 0x0051;
  9456. t['Qcircle'] = 0x24C6;
  9457. t['Qmonospace'] = 0xFF31;
  9458. t['Qsmall'] = 0xF771;
  9459. t['R'] = 0x0052;
  9460. t['Raarmenian'] = 0x054C;
  9461. t['Racute'] = 0x0154;
  9462. t['Rcaron'] = 0x0158;
  9463. t['Rcedilla'] = 0x0156;
  9464. t['Rcircle'] = 0x24C7;
  9465. t['Rcommaaccent'] = 0x0156;
  9466. t['Rdblgrave'] = 0x0210;
  9467. t['Rdotaccent'] = 0x1E58;
  9468. t['Rdotbelow'] = 0x1E5A;
  9469. t['Rdotbelowmacron'] = 0x1E5C;
  9470. t['Reharmenian'] = 0x0550;
  9471. t['Rfraktur'] = 0x211C;
  9472. t['Rho'] = 0x03A1;
  9473. t['Ringsmall'] = 0xF6FC;
  9474. t['Rinvertedbreve'] = 0x0212;
  9475. t['Rlinebelow'] = 0x1E5E;
  9476. t['Rmonospace'] = 0xFF32;
  9477. t['Rsmall'] = 0xF772;
  9478. t['Rsmallinverted'] = 0x0281;
  9479. t['Rsmallinvertedsuperior'] = 0x02B6;
  9480. t['S'] = 0x0053;
  9481. t['SF010000'] = 0x250C;
  9482. t['SF020000'] = 0x2514;
  9483. t['SF030000'] = 0x2510;
  9484. t['SF040000'] = 0x2518;
  9485. t['SF050000'] = 0x253C;
  9486. t['SF060000'] = 0x252C;
  9487. t['SF070000'] = 0x2534;
  9488. t['SF080000'] = 0x251C;
  9489. t['SF090000'] = 0x2524;
  9490. t['SF100000'] = 0x2500;
  9491. t['SF110000'] = 0x2502;
  9492. t['SF190000'] = 0x2561;
  9493. t['SF200000'] = 0x2562;
  9494. t['SF210000'] = 0x2556;
  9495. t['SF220000'] = 0x2555;
  9496. t['SF230000'] = 0x2563;
  9497. t['SF240000'] = 0x2551;
  9498. t['SF250000'] = 0x2557;
  9499. t['SF260000'] = 0x255D;
  9500. t['SF270000'] = 0x255C;
  9501. t['SF280000'] = 0x255B;
  9502. t['SF360000'] = 0x255E;
  9503. t['SF370000'] = 0x255F;
  9504. t['SF380000'] = 0x255A;
  9505. t['SF390000'] = 0x2554;
  9506. t['SF400000'] = 0x2569;
  9507. t['SF410000'] = 0x2566;
  9508. t['SF420000'] = 0x2560;
  9509. t['SF430000'] = 0x2550;
  9510. t['SF440000'] = 0x256C;
  9511. t['SF450000'] = 0x2567;
  9512. t['SF460000'] = 0x2568;
  9513. t['SF470000'] = 0x2564;
  9514. t['SF480000'] = 0x2565;
  9515. t['SF490000'] = 0x2559;
  9516. t['SF500000'] = 0x2558;
  9517. t['SF510000'] = 0x2552;
  9518. t['SF520000'] = 0x2553;
  9519. t['SF530000'] = 0x256B;
  9520. t['SF540000'] = 0x256A;
  9521. t['Sacute'] = 0x015A;
  9522. t['Sacutedotaccent'] = 0x1E64;
  9523. t['Sampigreek'] = 0x03E0;
  9524. t['Scaron'] = 0x0160;
  9525. t['Scarondotaccent'] = 0x1E66;
  9526. t['Scaronsmall'] = 0xF6FD;
  9527. t['Scedilla'] = 0x015E;
  9528. t['Schwa'] = 0x018F;
  9529. t['Schwacyrillic'] = 0x04D8;
  9530. t['Schwadieresiscyrillic'] = 0x04DA;
  9531. t['Scircle'] = 0x24C8;
  9532. t['Scircumflex'] = 0x015C;
  9533. t['Scommaaccent'] = 0x0218;
  9534. t['Sdotaccent'] = 0x1E60;
  9535. t['Sdotbelow'] = 0x1E62;
  9536. t['Sdotbelowdotaccent'] = 0x1E68;
  9537. t['Seharmenian'] = 0x054D;
  9538. t['Sevenroman'] = 0x2166;
  9539. t['Shaarmenian'] = 0x0547;
  9540. t['Shacyrillic'] = 0x0428;
  9541. t['Shchacyrillic'] = 0x0429;
  9542. t['Sheicoptic'] = 0x03E2;
  9543. t['Shhacyrillic'] = 0x04BA;
  9544. t['Shimacoptic'] = 0x03EC;
  9545. t['Sigma'] = 0x03A3;
  9546. t['Sixroman'] = 0x2165;
  9547. t['Smonospace'] = 0xFF33;
  9548. t['Softsigncyrillic'] = 0x042C;
  9549. t['Ssmall'] = 0xF773;
  9550. t['Stigmagreek'] = 0x03DA;
  9551. t['T'] = 0x0054;
  9552. t['Tau'] = 0x03A4;
  9553. t['Tbar'] = 0x0166;
  9554. t['Tcaron'] = 0x0164;
  9555. t['Tcedilla'] = 0x0162;
  9556. t['Tcircle'] = 0x24C9;
  9557. t['Tcircumflexbelow'] = 0x1E70;
  9558. t['Tcommaaccent'] = 0x0162;
  9559. t['Tdotaccent'] = 0x1E6A;
  9560. t['Tdotbelow'] = 0x1E6C;
  9561. t['Tecyrillic'] = 0x0422;
  9562. t['Tedescendercyrillic'] = 0x04AC;
  9563. t['Tenroman'] = 0x2169;
  9564. t['Tetsecyrillic'] = 0x04B4;
  9565. t['Theta'] = 0x0398;
  9566. t['Thook'] = 0x01AC;
  9567. t['Thorn'] = 0x00DE;
  9568. t['Thornsmall'] = 0xF7FE;
  9569. t['Threeroman'] = 0x2162;
  9570. t['Tildesmall'] = 0xF6FE;
  9571. t['Tiwnarmenian'] = 0x054F;
  9572. t['Tlinebelow'] = 0x1E6E;
  9573. t['Tmonospace'] = 0xFF34;
  9574. t['Toarmenian'] = 0x0539;
  9575. t['Tonefive'] = 0x01BC;
  9576. t['Tonesix'] = 0x0184;
  9577. t['Tonetwo'] = 0x01A7;
  9578. t['Tretroflexhook'] = 0x01AE;
  9579. t['Tsecyrillic'] = 0x0426;
  9580. t['Tshecyrillic'] = 0x040B;
  9581. t['Tsmall'] = 0xF774;
  9582. t['Twelveroman'] = 0x216B;
  9583. t['Tworoman'] = 0x2161;
  9584. t['U'] = 0x0055;
  9585. t['Uacute'] = 0x00DA;
  9586. t['Uacutesmall'] = 0xF7FA;
  9587. t['Ubreve'] = 0x016C;
  9588. t['Ucaron'] = 0x01D3;
  9589. t['Ucircle'] = 0x24CA;
  9590. t['Ucircumflex'] = 0x00DB;
  9591. t['Ucircumflexbelow'] = 0x1E76;
  9592. t['Ucircumflexsmall'] = 0xF7FB;
  9593. t['Ucyrillic'] = 0x0423;
  9594. t['Udblacute'] = 0x0170;
  9595. t['Udblgrave'] = 0x0214;
  9596. t['Udieresis'] = 0x00DC;
  9597. t['Udieresisacute'] = 0x01D7;
  9598. t['Udieresisbelow'] = 0x1E72;
  9599. t['Udieresiscaron'] = 0x01D9;
  9600. t['Udieresiscyrillic'] = 0x04F0;
  9601. t['Udieresisgrave'] = 0x01DB;
  9602. t['Udieresismacron'] = 0x01D5;
  9603. t['Udieresissmall'] = 0xF7FC;
  9604. t['Udotbelow'] = 0x1EE4;
  9605. t['Ugrave'] = 0x00D9;
  9606. t['Ugravesmall'] = 0xF7F9;
  9607. t['Uhookabove'] = 0x1EE6;
  9608. t['Uhorn'] = 0x01AF;
  9609. t['Uhornacute'] = 0x1EE8;
  9610. t['Uhorndotbelow'] = 0x1EF0;
  9611. t['Uhorngrave'] = 0x1EEA;
  9612. t['Uhornhookabove'] = 0x1EEC;
  9613. t['Uhorntilde'] = 0x1EEE;
  9614. t['Uhungarumlaut'] = 0x0170;
  9615. t['Uhungarumlautcyrillic'] = 0x04F2;
  9616. t['Uinvertedbreve'] = 0x0216;
  9617. t['Ukcyrillic'] = 0x0478;
  9618. t['Umacron'] = 0x016A;
  9619. t['Umacroncyrillic'] = 0x04EE;
  9620. t['Umacrondieresis'] = 0x1E7A;
  9621. t['Umonospace'] = 0xFF35;
  9622. t['Uogonek'] = 0x0172;
  9623. t['Upsilon'] = 0x03A5;
  9624. t['Upsilon1'] = 0x03D2;
  9625. t['Upsilonacutehooksymbolgreek'] = 0x03D3;
  9626. t['Upsilonafrican'] = 0x01B1;
  9627. t['Upsilondieresis'] = 0x03AB;
  9628. t['Upsilondieresishooksymbolgreek'] = 0x03D4;
  9629. t['Upsilonhooksymbol'] = 0x03D2;
  9630. t['Upsilontonos'] = 0x038E;
  9631. t['Uring'] = 0x016E;
  9632. t['Ushortcyrillic'] = 0x040E;
  9633. t['Usmall'] = 0xF775;
  9634. t['Ustraightcyrillic'] = 0x04AE;
  9635. t['Ustraightstrokecyrillic'] = 0x04B0;
  9636. t['Utilde'] = 0x0168;
  9637. t['Utildeacute'] = 0x1E78;
  9638. t['Utildebelow'] = 0x1E74;
  9639. t['V'] = 0x0056;
  9640. t['Vcircle'] = 0x24CB;
  9641. t['Vdotbelow'] = 0x1E7E;
  9642. t['Vecyrillic'] = 0x0412;
  9643. t['Vewarmenian'] = 0x054E;
  9644. t['Vhook'] = 0x01B2;
  9645. t['Vmonospace'] = 0xFF36;
  9646. t['Voarmenian'] = 0x0548;
  9647. t['Vsmall'] = 0xF776;
  9648. t['Vtilde'] = 0x1E7C;
  9649. t['W'] = 0x0057;
  9650. t['Wacute'] = 0x1E82;
  9651. t['Wcircle'] = 0x24CC;
  9652. t['Wcircumflex'] = 0x0174;
  9653. t['Wdieresis'] = 0x1E84;
  9654. t['Wdotaccent'] = 0x1E86;
  9655. t['Wdotbelow'] = 0x1E88;
  9656. t['Wgrave'] = 0x1E80;
  9657. t['Wmonospace'] = 0xFF37;
  9658. t['Wsmall'] = 0xF777;
  9659. t['X'] = 0x0058;
  9660. t['Xcircle'] = 0x24CD;
  9661. t['Xdieresis'] = 0x1E8C;
  9662. t['Xdotaccent'] = 0x1E8A;
  9663. t['Xeharmenian'] = 0x053D;
  9664. t['Xi'] = 0x039E;
  9665. t['Xmonospace'] = 0xFF38;
  9666. t['Xsmall'] = 0xF778;
  9667. t['Y'] = 0x0059;
  9668. t['Yacute'] = 0x00DD;
  9669. t['Yacutesmall'] = 0xF7FD;
  9670. t['Yatcyrillic'] = 0x0462;
  9671. t['Ycircle'] = 0x24CE;
  9672. t['Ycircumflex'] = 0x0176;
  9673. t['Ydieresis'] = 0x0178;
  9674. t['Ydieresissmall'] = 0xF7FF;
  9675. t['Ydotaccent'] = 0x1E8E;
  9676. t['Ydotbelow'] = 0x1EF4;
  9677. t['Yericyrillic'] = 0x042B;
  9678. t['Yerudieresiscyrillic'] = 0x04F8;
  9679. t['Ygrave'] = 0x1EF2;
  9680. t['Yhook'] = 0x01B3;
  9681. t['Yhookabove'] = 0x1EF6;
  9682. t['Yiarmenian'] = 0x0545;
  9683. t['Yicyrillic'] = 0x0407;
  9684. t['Yiwnarmenian'] = 0x0552;
  9685. t['Ymonospace'] = 0xFF39;
  9686. t['Ysmall'] = 0xF779;
  9687. t['Ytilde'] = 0x1EF8;
  9688. t['Yusbigcyrillic'] = 0x046A;
  9689. t['Yusbigiotifiedcyrillic'] = 0x046C;
  9690. t['Yuslittlecyrillic'] = 0x0466;
  9691. t['Yuslittleiotifiedcyrillic'] = 0x0468;
  9692. t['Z'] = 0x005A;
  9693. t['Zaarmenian'] = 0x0536;
  9694. t['Zacute'] = 0x0179;
  9695. t['Zcaron'] = 0x017D;
  9696. t['Zcaronsmall'] = 0xF6FF;
  9697. t['Zcircle'] = 0x24CF;
  9698. t['Zcircumflex'] = 0x1E90;
  9699. t['Zdot'] = 0x017B;
  9700. t['Zdotaccent'] = 0x017B;
  9701. t['Zdotbelow'] = 0x1E92;
  9702. t['Zecyrillic'] = 0x0417;
  9703. t['Zedescendercyrillic'] = 0x0498;
  9704. t['Zedieresiscyrillic'] = 0x04DE;
  9705. t['Zeta'] = 0x0396;
  9706. t['Zhearmenian'] = 0x053A;
  9707. t['Zhebrevecyrillic'] = 0x04C1;
  9708. t['Zhecyrillic'] = 0x0416;
  9709. t['Zhedescendercyrillic'] = 0x0496;
  9710. t['Zhedieresiscyrillic'] = 0x04DC;
  9711. t['Zlinebelow'] = 0x1E94;
  9712. t['Zmonospace'] = 0xFF3A;
  9713. t['Zsmall'] = 0xF77A;
  9714. t['Zstroke'] = 0x01B5;
  9715. t['a'] = 0x0061;
  9716. t['aabengali'] = 0x0986;
  9717. t['aacute'] = 0x00E1;
  9718. t['aadeva'] = 0x0906;
  9719. t['aagujarati'] = 0x0A86;
  9720. t['aagurmukhi'] = 0x0A06;
  9721. t['aamatragurmukhi'] = 0x0A3E;
  9722. t['aarusquare'] = 0x3303;
  9723. t['aavowelsignbengali'] = 0x09BE;
  9724. t['aavowelsigndeva'] = 0x093E;
  9725. t['aavowelsigngujarati'] = 0x0ABE;
  9726. t['abbreviationmarkarmenian'] = 0x055F;
  9727. t['abbreviationsigndeva'] = 0x0970;
  9728. t['abengali'] = 0x0985;
  9729. t['abopomofo'] = 0x311A;
  9730. t['abreve'] = 0x0103;
  9731. t['abreveacute'] = 0x1EAF;
  9732. t['abrevecyrillic'] = 0x04D1;
  9733. t['abrevedotbelow'] = 0x1EB7;
  9734. t['abrevegrave'] = 0x1EB1;
  9735. t['abrevehookabove'] = 0x1EB3;
  9736. t['abrevetilde'] = 0x1EB5;
  9737. t['acaron'] = 0x01CE;
  9738. t['acircle'] = 0x24D0;
  9739. t['acircumflex'] = 0x00E2;
  9740. t['acircumflexacute'] = 0x1EA5;
  9741. t['acircumflexdotbelow'] = 0x1EAD;
  9742. t['acircumflexgrave'] = 0x1EA7;
  9743. t['acircumflexhookabove'] = 0x1EA9;
  9744. t['acircumflextilde'] = 0x1EAB;
  9745. t['acute'] = 0x00B4;
  9746. t['acutebelowcmb'] = 0x0317;
  9747. t['acutecmb'] = 0x0301;
  9748. t['acutecomb'] = 0x0301;
  9749. t['acutedeva'] = 0x0954;
  9750. t['acutelowmod'] = 0x02CF;
  9751. t['acutetonecmb'] = 0x0341;
  9752. t['acyrillic'] = 0x0430;
  9753. t['adblgrave'] = 0x0201;
  9754. t['addakgurmukhi'] = 0x0A71;
  9755. t['adeva'] = 0x0905;
  9756. t['adieresis'] = 0x00E4;
  9757. t['adieresiscyrillic'] = 0x04D3;
  9758. t['adieresismacron'] = 0x01DF;
  9759. t['adotbelow'] = 0x1EA1;
  9760. t['adotmacron'] = 0x01E1;
  9761. t['ae'] = 0x00E6;
  9762. t['aeacute'] = 0x01FD;
  9763. t['aekorean'] = 0x3150;
  9764. t['aemacron'] = 0x01E3;
  9765. t['afii00208'] = 0x2015;
  9766. t['afii08941'] = 0x20A4;
  9767. t['afii10017'] = 0x0410;
  9768. t['afii10018'] = 0x0411;
  9769. t['afii10019'] = 0x0412;
  9770. t['afii10020'] = 0x0413;
  9771. t['afii10021'] = 0x0414;
  9772. t['afii10022'] = 0x0415;
  9773. t['afii10023'] = 0x0401;
  9774. t['afii10024'] = 0x0416;
  9775. t['afii10025'] = 0x0417;
  9776. t['afii10026'] = 0x0418;
  9777. t['afii10027'] = 0x0419;
  9778. t['afii10028'] = 0x041A;
  9779. t['afii10029'] = 0x041B;
  9780. t['afii10030'] = 0x041C;
  9781. t['afii10031'] = 0x041D;
  9782. t['afii10032'] = 0x041E;
  9783. t['afii10033'] = 0x041F;
  9784. t['afii10034'] = 0x0420;
  9785. t['afii10035'] = 0x0421;
  9786. t['afii10036'] = 0x0422;
  9787. t['afii10037'] = 0x0423;
  9788. t['afii10038'] = 0x0424;
  9789. t['afii10039'] = 0x0425;
  9790. t['afii10040'] = 0x0426;
  9791. t['afii10041'] = 0x0427;
  9792. t['afii10042'] = 0x0428;
  9793. t['afii10043'] = 0x0429;
  9794. t['afii10044'] = 0x042A;
  9795. t['afii10045'] = 0x042B;
  9796. t['afii10046'] = 0x042C;
  9797. t['afii10047'] = 0x042D;
  9798. t['afii10048'] = 0x042E;
  9799. t['afii10049'] = 0x042F;
  9800. t['afii10050'] = 0x0490;
  9801. t['afii10051'] = 0x0402;
  9802. t['afii10052'] = 0x0403;
  9803. t['afii10053'] = 0x0404;
  9804. t['afii10054'] = 0x0405;
  9805. t['afii10055'] = 0x0406;
  9806. t['afii10056'] = 0x0407;
  9807. t['afii10057'] = 0x0408;
  9808. t['afii10058'] = 0x0409;
  9809. t['afii10059'] = 0x040A;
  9810. t['afii10060'] = 0x040B;
  9811. t['afii10061'] = 0x040C;
  9812. t['afii10062'] = 0x040E;
  9813. t['afii10063'] = 0xF6C4;
  9814. t['afii10064'] = 0xF6C5;
  9815. t['afii10065'] = 0x0430;
  9816. t['afii10066'] = 0x0431;
  9817. t['afii10067'] = 0x0432;
  9818. t['afii10068'] = 0x0433;
  9819. t['afii10069'] = 0x0434;
  9820. t['afii10070'] = 0x0435;
  9821. t['afii10071'] = 0x0451;
  9822. t['afii10072'] = 0x0436;
  9823. t['afii10073'] = 0x0437;
  9824. t['afii10074'] = 0x0438;
  9825. t['afii10075'] = 0x0439;
  9826. t['afii10076'] = 0x043A;
  9827. t['afii10077'] = 0x043B;
  9828. t['afii10078'] = 0x043C;
  9829. t['afii10079'] = 0x043D;
  9830. t['afii10080'] = 0x043E;
  9831. t['afii10081'] = 0x043F;
  9832. t['afii10082'] = 0x0440;
  9833. t['afii10083'] = 0x0441;
  9834. t['afii10084'] = 0x0442;
  9835. t['afii10085'] = 0x0443;
  9836. t['afii10086'] = 0x0444;
  9837. t['afii10087'] = 0x0445;
  9838. t['afii10088'] = 0x0446;
  9839. t['afii10089'] = 0x0447;
  9840. t['afii10090'] = 0x0448;
  9841. t['afii10091'] = 0x0449;
  9842. t['afii10092'] = 0x044A;
  9843. t['afii10093'] = 0x044B;
  9844. t['afii10094'] = 0x044C;
  9845. t['afii10095'] = 0x044D;
  9846. t['afii10096'] = 0x044E;
  9847. t['afii10097'] = 0x044F;
  9848. t['afii10098'] = 0x0491;
  9849. t['afii10099'] = 0x0452;
  9850. t['afii10100'] = 0x0453;
  9851. t['afii10101'] = 0x0454;
  9852. t['afii10102'] = 0x0455;
  9853. t['afii10103'] = 0x0456;
  9854. t['afii10104'] = 0x0457;
  9855. t['afii10105'] = 0x0458;
  9856. t['afii10106'] = 0x0459;
  9857. t['afii10107'] = 0x045A;
  9858. t['afii10108'] = 0x045B;
  9859. t['afii10109'] = 0x045C;
  9860. t['afii10110'] = 0x045E;
  9861. t['afii10145'] = 0x040F;
  9862. t['afii10146'] = 0x0462;
  9863. t['afii10147'] = 0x0472;
  9864. t['afii10148'] = 0x0474;
  9865. t['afii10192'] = 0xF6C6;
  9866. t['afii10193'] = 0x045F;
  9867. t['afii10194'] = 0x0463;
  9868. t['afii10195'] = 0x0473;
  9869. t['afii10196'] = 0x0475;
  9870. t['afii10831'] = 0xF6C7;
  9871. t['afii10832'] = 0xF6C8;
  9872. t['afii10846'] = 0x04D9;
  9873. t['afii299'] = 0x200E;
  9874. t['afii300'] = 0x200F;
  9875. t['afii301'] = 0x200D;
  9876. t['afii57381'] = 0x066A;
  9877. t['afii57388'] = 0x060C;
  9878. t['afii57392'] = 0x0660;
  9879. t['afii57393'] = 0x0661;
  9880. t['afii57394'] = 0x0662;
  9881. t['afii57395'] = 0x0663;
  9882. t['afii57396'] = 0x0664;
  9883. t['afii57397'] = 0x0665;
  9884. t['afii57398'] = 0x0666;
  9885. t['afii57399'] = 0x0667;
  9886. t['afii57400'] = 0x0668;
  9887. t['afii57401'] = 0x0669;
  9888. t['afii57403'] = 0x061B;
  9889. t['afii57407'] = 0x061F;
  9890. t['afii57409'] = 0x0621;
  9891. t['afii57410'] = 0x0622;
  9892. t['afii57411'] = 0x0623;
  9893. t['afii57412'] = 0x0624;
  9894. t['afii57413'] = 0x0625;
  9895. t['afii57414'] = 0x0626;
  9896. t['afii57415'] = 0x0627;
  9897. t['afii57416'] = 0x0628;
  9898. t['afii57417'] = 0x0629;
  9899. t['afii57418'] = 0x062A;
  9900. t['afii57419'] = 0x062B;
  9901. t['afii57420'] = 0x062C;
  9902. t['afii57421'] = 0x062D;
  9903. t['afii57422'] = 0x062E;
  9904. t['afii57423'] = 0x062F;
  9905. t['afii57424'] = 0x0630;
  9906. t['afii57425'] = 0x0631;
  9907. t['afii57426'] = 0x0632;
  9908. t['afii57427'] = 0x0633;
  9909. t['afii57428'] = 0x0634;
  9910. t['afii57429'] = 0x0635;
  9911. t['afii57430'] = 0x0636;
  9912. t['afii57431'] = 0x0637;
  9913. t['afii57432'] = 0x0638;
  9914. t['afii57433'] = 0x0639;
  9915. t['afii57434'] = 0x063A;
  9916. t['afii57440'] = 0x0640;
  9917. t['afii57441'] = 0x0641;
  9918. t['afii57442'] = 0x0642;
  9919. t['afii57443'] = 0x0643;
  9920. t['afii57444'] = 0x0644;
  9921. t['afii57445'] = 0x0645;
  9922. t['afii57446'] = 0x0646;
  9923. t['afii57448'] = 0x0648;
  9924. t['afii57449'] = 0x0649;
  9925. t['afii57450'] = 0x064A;
  9926. t['afii57451'] = 0x064B;
  9927. t['afii57452'] = 0x064C;
  9928. t['afii57453'] = 0x064D;
  9929. t['afii57454'] = 0x064E;
  9930. t['afii57455'] = 0x064F;
  9931. t['afii57456'] = 0x0650;
  9932. t['afii57457'] = 0x0651;
  9933. t['afii57458'] = 0x0652;
  9934. t['afii57470'] = 0x0647;
  9935. t['afii57505'] = 0x06A4;
  9936. t['afii57506'] = 0x067E;
  9937. t['afii57507'] = 0x0686;
  9938. t['afii57508'] = 0x0698;
  9939. t['afii57509'] = 0x06AF;
  9940. t['afii57511'] = 0x0679;
  9941. t['afii57512'] = 0x0688;
  9942. t['afii57513'] = 0x0691;
  9943. t['afii57514'] = 0x06BA;
  9944. t['afii57519'] = 0x06D2;
  9945. t['afii57534'] = 0x06D5;
  9946. t['afii57636'] = 0x20AA;
  9947. t['afii57645'] = 0x05BE;
  9948. t['afii57658'] = 0x05C3;
  9949. t['afii57664'] = 0x05D0;
  9950. t['afii57665'] = 0x05D1;
  9951. t['afii57666'] = 0x05D2;
  9952. t['afii57667'] = 0x05D3;
  9953. t['afii57668'] = 0x05D4;
  9954. t['afii57669'] = 0x05D5;
  9955. t['afii57670'] = 0x05D6;
  9956. t['afii57671'] = 0x05D7;
  9957. t['afii57672'] = 0x05D8;
  9958. t['afii57673'] = 0x05D9;
  9959. t['afii57674'] = 0x05DA;
  9960. t['afii57675'] = 0x05DB;
  9961. t['afii57676'] = 0x05DC;
  9962. t['afii57677'] = 0x05DD;
  9963. t['afii57678'] = 0x05DE;
  9964. t['afii57679'] = 0x05DF;
  9965. t['afii57680'] = 0x05E0;
  9966. t['afii57681'] = 0x05E1;
  9967. t['afii57682'] = 0x05E2;
  9968. t['afii57683'] = 0x05E3;
  9969. t['afii57684'] = 0x05E4;
  9970. t['afii57685'] = 0x05E5;
  9971. t['afii57686'] = 0x05E6;
  9972. t['afii57687'] = 0x05E7;
  9973. t['afii57688'] = 0x05E8;
  9974. t['afii57689'] = 0x05E9;
  9975. t['afii57690'] = 0x05EA;
  9976. t['afii57694'] = 0xFB2A;
  9977. t['afii57695'] = 0xFB2B;
  9978. t['afii57700'] = 0xFB4B;
  9979. t['afii57705'] = 0xFB1F;
  9980. t['afii57716'] = 0x05F0;
  9981. t['afii57717'] = 0x05F1;
  9982. t['afii57718'] = 0x05F2;
  9983. t['afii57723'] = 0xFB35;
  9984. t['afii57793'] = 0x05B4;
  9985. t['afii57794'] = 0x05B5;
  9986. t['afii57795'] = 0x05B6;
  9987. t['afii57796'] = 0x05BB;
  9988. t['afii57797'] = 0x05B8;
  9989. t['afii57798'] = 0x05B7;
  9990. t['afii57799'] = 0x05B0;
  9991. t['afii57800'] = 0x05B2;
  9992. t['afii57801'] = 0x05B1;
  9993. t['afii57802'] = 0x05B3;
  9994. t['afii57803'] = 0x05C2;
  9995. t['afii57804'] = 0x05C1;
  9996. t['afii57806'] = 0x05B9;
  9997. t['afii57807'] = 0x05BC;
  9998. t['afii57839'] = 0x05BD;
  9999. t['afii57841'] = 0x05BF;
  10000. t['afii57842'] = 0x05C0;
  10001. t['afii57929'] = 0x02BC;
  10002. t['afii61248'] = 0x2105;
  10003. t['afii61289'] = 0x2113;
  10004. t['afii61352'] = 0x2116;
  10005. t['afii61573'] = 0x202C;
  10006. t['afii61574'] = 0x202D;
  10007. t['afii61575'] = 0x202E;
  10008. t['afii61664'] = 0x200C;
  10009. t['afii63167'] = 0x066D;
  10010. t['afii64937'] = 0x02BD;
  10011. t['agrave'] = 0x00E0;
  10012. t['agujarati'] = 0x0A85;
  10013. t['agurmukhi'] = 0x0A05;
  10014. t['ahiragana'] = 0x3042;
  10015. t['ahookabove'] = 0x1EA3;
  10016. t['aibengali'] = 0x0990;
  10017. t['aibopomofo'] = 0x311E;
  10018. t['aideva'] = 0x0910;
  10019. t['aiecyrillic'] = 0x04D5;
  10020. t['aigujarati'] = 0x0A90;
  10021. t['aigurmukhi'] = 0x0A10;
  10022. t['aimatragurmukhi'] = 0x0A48;
  10023. t['ainarabic'] = 0x0639;
  10024. t['ainfinalarabic'] = 0xFECA;
  10025. t['aininitialarabic'] = 0xFECB;
  10026. t['ainmedialarabic'] = 0xFECC;
  10027. t['ainvertedbreve'] = 0x0203;
  10028. t['aivowelsignbengali'] = 0x09C8;
  10029. t['aivowelsigndeva'] = 0x0948;
  10030. t['aivowelsigngujarati'] = 0x0AC8;
  10031. t['akatakana'] = 0x30A2;
  10032. t['akatakanahalfwidth'] = 0xFF71;
  10033. t['akorean'] = 0x314F;
  10034. t['alef'] = 0x05D0;
  10035. t['alefarabic'] = 0x0627;
  10036. t['alefdageshhebrew'] = 0xFB30;
  10037. t['aleffinalarabic'] = 0xFE8E;
  10038. t['alefhamzaabovearabic'] = 0x0623;
  10039. t['alefhamzaabovefinalarabic'] = 0xFE84;
  10040. t['alefhamzabelowarabic'] = 0x0625;
  10041. t['alefhamzabelowfinalarabic'] = 0xFE88;
  10042. t['alefhebrew'] = 0x05D0;
  10043. t['aleflamedhebrew'] = 0xFB4F;
  10044. t['alefmaddaabovearabic'] = 0x0622;
  10045. t['alefmaddaabovefinalarabic'] = 0xFE82;
  10046. t['alefmaksuraarabic'] = 0x0649;
  10047. t['alefmaksurafinalarabic'] = 0xFEF0;
  10048. t['alefmaksurainitialarabic'] = 0xFEF3;
  10049. t['alefmaksuramedialarabic'] = 0xFEF4;
  10050. t['alefpatahhebrew'] = 0xFB2E;
  10051. t['alefqamatshebrew'] = 0xFB2F;
  10052. t['aleph'] = 0x2135;
  10053. t['allequal'] = 0x224C;
  10054. t['alpha'] = 0x03B1;
  10055. t['alphatonos'] = 0x03AC;
  10056. t['amacron'] = 0x0101;
  10057. t['amonospace'] = 0xFF41;
  10058. t['ampersand'] = 0x0026;
  10059. t['ampersandmonospace'] = 0xFF06;
  10060. t['ampersandsmall'] = 0xF726;
  10061. t['amsquare'] = 0x33C2;
  10062. t['anbopomofo'] = 0x3122;
  10063. t['angbopomofo'] = 0x3124;
  10064. t['angbracketleft'] = 0x3008;
  10065. // Glyph is missing from Adobe's original list.
  10066. t['angbracketright'] = 0x3009;
  10067. // Glyph is missing from Adobe's original list.
  10068. t['angkhankhuthai'] = 0x0E5A;
  10069. t['angle'] = 0x2220;
  10070. t['anglebracketleft'] = 0x3008;
  10071. t['anglebracketleftvertical'] = 0xFE3F;
  10072. t['anglebracketright'] = 0x3009;
  10073. t['anglebracketrightvertical'] = 0xFE40;
  10074. t['angleleft'] = 0x2329;
  10075. t['angleright'] = 0x232A;
  10076. t['angstrom'] = 0x212B;
  10077. t['anoteleia'] = 0x0387;
  10078. t['anudattadeva'] = 0x0952;
  10079. t['anusvarabengali'] = 0x0982;
  10080. t['anusvaradeva'] = 0x0902;
  10081. t['anusvaragujarati'] = 0x0A82;
  10082. t['aogonek'] = 0x0105;
  10083. t['apaatosquare'] = 0x3300;
  10084. t['aparen'] = 0x249C;
  10085. t['apostrophearmenian'] = 0x055A;
  10086. t['apostrophemod'] = 0x02BC;
  10087. t['apple'] = 0xF8FF;
  10088. t['approaches'] = 0x2250;
  10089. t['approxequal'] = 0x2248;
  10090. t['approxequalorimage'] = 0x2252;
  10091. t['approximatelyequal'] = 0x2245;
  10092. t['araeaekorean'] = 0x318E;
  10093. t['araeakorean'] = 0x318D;
  10094. t['arc'] = 0x2312;
  10095. t['arighthalfring'] = 0x1E9A;
  10096. t['aring'] = 0x00E5;
  10097. t['aringacute'] = 0x01FB;
  10098. t['aringbelow'] = 0x1E01;
  10099. t['arrowboth'] = 0x2194;
  10100. t['arrowdashdown'] = 0x21E3;
  10101. t['arrowdashleft'] = 0x21E0;
  10102. t['arrowdashright'] = 0x21E2;
  10103. t['arrowdashup'] = 0x21E1;
  10104. t['arrowdblboth'] = 0x21D4;
  10105. t['arrowdbldown'] = 0x21D3;
  10106. t['arrowdblleft'] = 0x21D0;
  10107. t['arrowdblright'] = 0x21D2;
  10108. t['arrowdblup'] = 0x21D1;
  10109. t['arrowdown'] = 0x2193;
  10110. t['arrowdownleft'] = 0x2199;
  10111. t['arrowdownright'] = 0x2198;
  10112. t['arrowdownwhite'] = 0x21E9;
  10113. t['arrowheaddownmod'] = 0x02C5;
  10114. t['arrowheadleftmod'] = 0x02C2;
  10115. t['arrowheadrightmod'] = 0x02C3;
  10116. t['arrowheadupmod'] = 0x02C4;
  10117. t['arrowhorizex'] = 0xF8E7;
  10118. t['arrowleft'] = 0x2190;
  10119. t['arrowleftdbl'] = 0x21D0;
  10120. t['arrowleftdblstroke'] = 0x21CD;
  10121. t['arrowleftoverright'] = 0x21C6;
  10122. t['arrowleftwhite'] = 0x21E6;
  10123. t['arrowright'] = 0x2192;
  10124. t['arrowrightdblstroke'] = 0x21CF;
  10125. t['arrowrightheavy'] = 0x279E;
  10126. t['arrowrightoverleft'] = 0x21C4;
  10127. t['arrowrightwhite'] = 0x21E8;
  10128. t['arrowtableft'] = 0x21E4;
  10129. t['arrowtabright'] = 0x21E5;
  10130. t['arrowup'] = 0x2191;
  10131. t['arrowupdn'] = 0x2195;
  10132. t['arrowupdnbse'] = 0x21A8;
  10133. t['arrowupdownbase'] = 0x21A8;
  10134. t['arrowupleft'] = 0x2196;
  10135. t['arrowupleftofdown'] = 0x21C5;
  10136. t['arrowupright'] = 0x2197;
  10137. t['arrowupwhite'] = 0x21E7;
  10138. t['arrowvertex'] = 0xF8E6;
  10139. t['asciicircum'] = 0x005E;
  10140. t['asciicircummonospace'] = 0xFF3E;
  10141. t['asciitilde'] = 0x007E;
  10142. t['asciitildemonospace'] = 0xFF5E;
  10143. t['ascript'] = 0x0251;
  10144. t['ascriptturned'] = 0x0252;
  10145. t['asmallhiragana'] = 0x3041;
  10146. t['asmallkatakana'] = 0x30A1;
  10147. t['asmallkatakanahalfwidth'] = 0xFF67;
  10148. t['asterisk'] = 0x002A;
  10149. t['asteriskaltonearabic'] = 0x066D;
  10150. t['asteriskarabic'] = 0x066D;
  10151. t['asteriskmath'] = 0x2217;
  10152. t['asteriskmonospace'] = 0xFF0A;
  10153. t['asterisksmall'] = 0xFE61;
  10154. t['asterism'] = 0x2042;
  10155. t['asuperior'] = 0xF6E9;
  10156. t['asymptoticallyequal'] = 0x2243;
  10157. t['at'] = 0x0040;
  10158. t['atilde'] = 0x00E3;
  10159. t['atmonospace'] = 0xFF20;
  10160. t['atsmall'] = 0xFE6B;
  10161. t['aturned'] = 0x0250;
  10162. t['aubengali'] = 0x0994;
  10163. t['aubopomofo'] = 0x3120;
  10164. t['audeva'] = 0x0914;
  10165. t['augujarati'] = 0x0A94;
  10166. t['augurmukhi'] = 0x0A14;
  10167. t['aulengthmarkbengali'] = 0x09D7;
  10168. t['aumatragurmukhi'] = 0x0A4C;
  10169. t['auvowelsignbengali'] = 0x09CC;
  10170. t['auvowelsigndeva'] = 0x094C;
  10171. t['auvowelsigngujarati'] = 0x0ACC;
  10172. t['avagrahadeva'] = 0x093D;
  10173. t['aybarmenian'] = 0x0561;
  10174. t['ayin'] = 0x05E2;
  10175. t['ayinaltonehebrew'] = 0xFB20;
  10176. t['ayinhebrew'] = 0x05E2;
  10177. t['b'] = 0x0062;
  10178. t['babengali'] = 0x09AC;
  10179. t['backslash'] = 0x005C;
  10180. t['backslashmonospace'] = 0xFF3C;
  10181. t['badeva'] = 0x092C;
  10182. t['bagujarati'] = 0x0AAC;
  10183. t['bagurmukhi'] = 0x0A2C;
  10184. t['bahiragana'] = 0x3070;
  10185. t['bahtthai'] = 0x0E3F;
  10186. t['bakatakana'] = 0x30D0;
  10187. t['bar'] = 0x007C;
  10188. t['barmonospace'] = 0xFF5C;
  10189. t['bbopomofo'] = 0x3105;
  10190. t['bcircle'] = 0x24D1;
  10191. t['bdotaccent'] = 0x1E03;
  10192. t['bdotbelow'] = 0x1E05;
  10193. t['beamedsixteenthnotes'] = 0x266C;
  10194. t['because'] = 0x2235;
  10195. t['becyrillic'] = 0x0431;
  10196. t['beharabic'] = 0x0628;
  10197. t['behfinalarabic'] = 0xFE90;
  10198. t['behinitialarabic'] = 0xFE91;
  10199. t['behiragana'] = 0x3079;
  10200. t['behmedialarabic'] = 0xFE92;
  10201. t['behmeeminitialarabic'] = 0xFC9F;
  10202. t['behmeemisolatedarabic'] = 0xFC08;
  10203. t['behnoonfinalarabic'] = 0xFC6D;
  10204. t['bekatakana'] = 0x30D9;
  10205. t['benarmenian'] = 0x0562;
  10206. t['bet'] = 0x05D1;
  10207. t['beta'] = 0x03B2;
  10208. t['betasymbolgreek'] = 0x03D0;
  10209. t['betdagesh'] = 0xFB31;
  10210. t['betdageshhebrew'] = 0xFB31;
  10211. t['bethebrew'] = 0x05D1;
  10212. t['betrafehebrew'] = 0xFB4C;
  10213. t['bhabengali'] = 0x09AD;
  10214. t['bhadeva'] = 0x092D;
  10215. t['bhagujarati'] = 0x0AAD;
  10216. t['bhagurmukhi'] = 0x0A2D;
  10217. t['bhook'] = 0x0253;
  10218. t['bihiragana'] = 0x3073;
  10219. t['bikatakana'] = 0x30D3;
  10220. t['bilabialclick'] = 0x0298;
  10221. t['bindigurmukhi'] = 0x0A02;
  10222. t['birusquare'] = 0x3331;
  10223. t['blackcircle'] = 0x25CF;
  10224. t['blackdiamond'] = 0x25C6;
  10225. t['blackdownpointingtriangle'] = 0x25BC;
  10226. t['blackleftpointingpointer'] = 0x25C4;
  10227. t['blackleftpointingtriangle'] = 0x25C0;
  10228. t['blacklenticularbracketleft'] = 0x3010;
  10229. t['blacklenticularbracketleftvertical'] = 0xFE3B;
  10230. t['blacklenticularbracketright'] = 0x3011;
  10231. t['blacklenticularbracketrightvertical'] = 0xFE3C;
  10232. t['blacklowerlefttriangle'] = 0x25E3;
  10233. t['blacklowerrighttriangle'] = 0x25E2;
  10234. t['blackrectangle'] = 0x25AC;
  10235. t['blackrightpointingpointer'] = 0x25BA;
  10236. t['blackrightpointingtriangle'] = 0x25B6;
  10237. t['blacksmallsquare'] = 0x25AA;
  10238. t['blacksmilingface'] = 0x263B;
  10239. t['blacksquare'] = 0x25A0;
  10240. t['blackstar'] = 0x2605;
  10241. t['blackupperlefttriangle'] = 0x25E4;
  10242. t['blackupperrighttriangle'] = 0x25E5;
  10243. t['blackuppointingsmalltriangle'] = 0x25B4;
  10244. t['blackuppointingtriangle'] = 0x25B2;
  10245. t['blank'] = 0x2423;
  10246. t['blinebelow'] = 0x1E07;
  10247. t['block'] = 0x2588;
  10248. t['bmonospace'] = 0xFF42;
  10249. t['bobaimaithai'] = 0x0E1A;
  10250. t['bohiragana'] = 0x307C;
  10251. t['bokatakana'] = 0x30DC;
  10252. t['bparen'] = 0x249D;
  10253. t['bqsquare'] = 0x33C3;
  10254. t['braceex'] = 0xF8F4;
  10255. t['braceleft'] = 0x007B;
  10256. t['braceleftbt'] = 0xF8F3;
  10257. t['braceleftmid'] = 0xF8F2;
  10258. t['braceleftmonospace'] = 0xFF5B;
  10259. t['braceleftsmall'] = 0xFE5B;
  10260. t['bracelefttp'] = 0xF8F1;
  10261. t['braceleftvertical'] = 0xFE37;
  10262. t['braceright'] = 0x007D;
  10263. t['bracerightbt'] = 0xF8FE;
  10264. t['bracerightmid'] = 0xF8FD;
  10265. t['bracerightmonospace'] = 0xFF5D;
  10266. t['bracerightsmall'] = 0xFE5C;
  10267. t['bracerighttp'] = 0xF8FC;
  10268. t['bracerightvertical'] = 0xFE38;
  10269. t['bracketleft'] = 0x005B;
  10270. t['bracketleftbt'] = 0xF8F0;
  10271. t['bracketleftex'] = 0xF8EF;
  10272. t['bracketleftmonospace'] = 0xFF3B;
  10273. t['bracketlefttp'] = 0xF8EE;
  10274. t['bracketright'] = 0x005D;
  10275. t['bracketrightbt'] = 0xF8FB;
  10276. t['bracketrightex'] = 0xF8FA;
  10277. t['bracketrightmonospace'] = 0xFF3D;
  10278. t['bracketrighttp'] = 0xF8F9;
  10279. t['breve'] = 0x02D8;
  10280. t['brevebelowcmb'] = 0x032E;
  10281. t['brevecmb'] = 0x0306;
  10282. t['breveinvertedbelowcmb'] = 0x032F;
  10283. t['breveinvertedcmb'] = 0x0311;
  10284. t['breveinverteddoublecmb'] = 0x0361;
  10285. t['bridgebelowcmb'] = 0x032A;
  10286. t['bridgeinvertedbelowcmb'] = 0x033A;
  10287. t['brokenbar'] = 0x00A6;
  10288. t['bstroke'] = 0x0180;
  10289. t['bsuperior'] = 0xF6EA;
  10290. t['btopbar'] = 0x0183;
  10291. t['buhiragana'] = 0x3076;
  10292. t['bukatakana'] = 0x30D6;
  10293. t['bullet'] = 0x2022;
  10294. t['bulletinverse'] = 0x25D8;
  10295. t['bulletoperator'] = 0x2219;
  10296. t['bullseye'] = 0x25CE;
  10297. t['c'] = 0x0063;
  10298. t['caarmenian'] = 0x056E;
  10299. t['cabengali'] = 0x099A;
  10300. t['cacute'] = 0x0107;
  10301. t['cadeva'] = 0x091A;
  10302. t['cagujarati'] = 0x0A9A;
  10303. t['cagurmukhi'] = 0x0A1A;
  10304. t['calsquare'] = 0x3388;
  10305. t['candrabindubengali'] = 0x0981;
  10306. t['candrabinducmb'] = 0x0310;
  10307. t['candrabindudeva'] = 0x0901;
  10308. t['candrabindugujarati'] = 0x0A81;
  10309. t['capslock'] = 0x21EA;
  10310. t['careof'] = 0x2105;
  10311. t['caron'] = 0x02C7;
  10312. t['caronbelowcmb'] = 0x032C;
  10313. t['caroncmb'] = 0x030C;
  10314. t['carriagereturn'] = 0x21B5;
  10315. t['cbopomofo'] = 0x3118;
  10316. t['ccaron'] = 0x010D;
  10317. t['ccedilla'] = 0x00E7;
  10318. t['ccedillaacute'] = 0x1E09;
  10319. t['ccircle'] = 0x24D2;
  10320. t['ccircumflex'] = 0x0109;
  10321. t['ccurl'] = 0x0255;
  10322. t['cdot'] = 0x010B;
  10323. t['cdotaccent'] = 0x010B;
  10324. t['cdsquare'] = 0x33C5;
  10325. t['cedilla'] = 0x00B8;
  10326. t['cedillacmb'] = 0x0327;
  10327. t['cent'] = 0x00A2;
  10328. t['centigrade'] = 0x2103;
  10329. t['centinferior'] = 0xF6DF;
  10330. t['centmonospace'] = 0xFFE0;
  10331. t['centoldstyle'] = 0xF7A2;
  10332. t['centsuperior'] = 0xF6E0;
  10333. t['chaarmenian'] = 0x0579;
  10334. t['chabengali'] = 0x099B;
  10335. t['chadeva'] = 0x091B;
  10336. t['chagujarati'] = 0x0A9B;
  10337. t['chagurmukhi'] = 0x0A1B;
  10338. t['chbopomofo'] = 0x3114;
  10339. t['cheabkhasiancyrillic'] = 0x04BD;
  10340. t['checkmark'] = 0x2713;
  10341. t['checyrillic'] = 0x0447;
  10342. t['chedescenderabkhasiancyrillic'] = 0x04BF;
  10343. t['chedescendercyrillic'] = 0x04B7;
  10344. t['chedieresiscyrillic'] = 0x04F5;
  10345. t['cheharmenian'] = 0x0573;
  10346. t['chekhakassiancyrillic'] = 0x04CC;
  10347. t['cheverticalstrokecyrillic'] = 0x04B9;
  10348. t['chi'] = 0x03C7;
  10349. t['chieuchacirclekorean'] = 0x3277;
  10350. t['chieuchaparenkorean'] = 0x3217;
  10351. t['chieuchcirclekorean'] = 0x3269;
  10352. t['chieuchkorean'] = 0x314A;
  10353. t['chieuchparenkorean'] = 0x3209;
  10354. t['chochangthai'] = 0x0E0A;
  10355. t['chochanthai'] = 0x0E08;
  10356. t['chochingthai'] = 0x0E09;
  10357. t['chochoethai'] = 0x0E0C;
  10358. t['chook'] = 0x0188;
  10359. t['cieucacirclekorean'] = 0x3276;
  10360. t['cieucaparenkorean'] = 0x3216;
  10361. t['cieuccirclekorean'] = 0x3268;
  10362. t['cieuckorean'] = 0x3148;
  10363. t['cieucparenkorean'] = 0x3208;
  10364. t['cieucuparenkorean'] = 0x321C;
  10365. t['circle'] = 0x25CB;
  10366. t['circlecopyrt'] = 0x00A9;
  10367. // Glyph is missing from Adobe's original list.
  10368. t['circlemultiply'] = 0x2297;
  10369. t['circleot'] = 0x2299;
  10370. t['circleplus'] = 0x2295;
  10371. t['circlepostalmark'] = 0x3036;
  10372. t['circlewithlefthalfblack'] = 0x25D0;
  10373. t['circlewithrighthalfblack'] = 0x25D1;
  10374. t['circumflex'] = 0x02C6;
  10375. t['circumflexbelowcmb'] = 0x032D;
  10376. t['circumflexcmb'] = 0x0302;
  10377. t['clear'] = 0x2327;
  10378. t['clickalveolar'] = 0x01C2;
  10379. t['clickdental'] = 0x01C0;
  10380. t['clicklateral'] = 0x01C1;
  10381. t['clickretroflex'] = 0x01C3;
  10382. t['club'] = 0x2663;
  10383. t['clubsuitblack'] = 0x2663;
  10384. t['clubsuitwhite'] = 0x2667;
  10385. t['cmcubedsquare'] = 0x33A4;
  10386. t['cmonospace'] = 0xFF43;
  10387. t['cmsquaredsquare'] = 0x33A0;
  10388. t['coarmenian'] = 0x0581;
  10389. t['colon'] = 0x003A;
  10390. t['colonmonetary'] = 0x20A1;
  10391. t['colonmonospace'] = 0xFF1A;
  10392. t['colonsign'] = 0x20A1;
  10393. t['colonsmall'] = 0xFE55;
  10394. t['colontriangularhalfmod'] = 0x02D1;
  10395. t['colontriangularmod'] = 0x02D0;
  10396. t['comma'] = 0x002C;
  10397. t['commaabovecmb'] = 0x0313;
  10398. t['commaaboverightcmb'] = 0x0315;
  10399. t['commaaccent'] = 0xF6C3;
  10400. t['commaarabic'] = 0x060C;
  10401. t['commaarmenian'] = 0x055D;
  10402. t['commainferior'] = 0xF6E1;
  10403. t['commamonospace'] = 0xFF0C;
  10404. t['commareversedabovecmb'] = 0x0314;
  10405. t['commareversedmod'] = 0x02BD;
  10406. t['commasmall'] = 0xFE50;
  10407. t['commasuperior'] = 0xF6E2;
  10408. t['commaturnedabovecmb'] = 0x0312;
  10409. t['commaturnedmod'] = 0x02BB;
  10410. t['compass'] = 0x263C;
  10411. t['congruent'] = 0x2245;
  10412. t['contourintegral'] = 0x222E;
  10413. t['control'] = 0x2303;
  10414. t['controlACK'] = 0x0006;
  10415. t['controlBEL'] = 0x0007;
  10416. t['controlBS'] = 0x0008;
  10417. t['controlCAN'] = 0x0018;
  10418. t['controlCR'] = 0x000D;
  10419. t['controlDC1'] = 0x0011;
  10420. t['controlDC2'] = 0x0012;
  10421. t['controlDC3'] = 0x0013;
  10422. t['controlDC4'] = 0x0014;
  10423. t['controlDEL'] = 0x007F;
  10424. t['controlDLE'] = 0x0010;
  10425. t['controlEM'] = 0x0019;
  10426. t['controlENQ'] = 0x0005;
  10427. t['controlEOT'] = 0x0004;
  10428. t['controlESC'] = 0x001B;
  10429. t['controlETB'] = 0x0017;
  10430. t['controlETX'] = 0x0003;
  10431. t['controlFF'] = 0x000C;
  10432. t['controlFS'] = 0x001C;
  10433. t['controlGS'] = 0x001D;
  10434. t['controlHT'] = 0x0009;
  10435. t['controlLF'] = 0x000A;
  10436. t['controlNAK'] = 0x0015;
  10437. t['controlRS'] = 0x001E;
  10438. t['controlSI'] = 0x000F;
  10439. t['controlSO'] = 0x000E;
  10440. t['controlSOT'] = 0x0002;
  10441. t['controlSTX'] = 0x0001;
  10442. t['controlSUB'] = 0x001A;
  10443. t['controlSYN'] = 0x0016;
  10444. t['controlUS'] = 0x001F;
  10445. t['controlVT'] = 0x000B;
  10446. t['copyright'] = 0x00A9;
  10447. t['copyrightsans'] = 0xF8E9;
  10448. t['copyrightserif'] = 0xF6D9;
  10449. t['cornerbracketleft'] = 0x300C;
  10450. t['cornerbracketlefthalfwidth'] = 0xFF62;
  10451. t['cornerbracketleftvertical'] = 0xFE41;
  10452. t['cornerbracketright'] = 0x300D;
  10453. t['cornerbracketrighthalfwidth'] = 0xFF63;
  10454. t['cornerbracketrightvertical'] = 0xFE42;
  10455. t['corporationsquare'] = 0x337F;
  10456. t['cosquare'] = 0x33C7;
  10457. t['coverkgsquare'] = 0x33C6;
  10458. t['cparen'] = 0x249E;
  10459. t['cruzeiro'] = 0x20A2;
  10460. t['cstretched'] = 0x0297;
  10461. t['curlyand'] = 0x22CF;
  10462. t['curlyor'] = 0x22CE;
  10463. t['currency'] = 0x00A4;
  10464. t['cyrBreve'] = 0xF6D1;
  10465. t['cyrFlex'] = 0xF6D2;
  10466. t['cyrbreve'] = 0xF6D4;
  10467. t['cyrflex'] = 0xF6D5;
  10468. t['d'] = 0x0064;
  10469. t['daarmenian'] = 0x0564;
  10470. t['dabengali'] = 0x09A6;
  10471. t['dadarabic'] = 0x0636;
  10472. t['dadeva'] = 0x0926;
  10473. t['dadfinalarabic'] = 0xFEBE;
  10474. t['dadinitialarabic'] = 0xFEBF;
  10475. t['dadmedialarabic'] = 0xFEC0;
  10476. t['dagesh'] = 0x05BC;
  10477. t['dageshhebrew'] = 0x05BC;
  10478. t['dagger'] = 0x2020;
  10479. t['daggerdbl'] = 0x2021;
  10480. t['dagujarati'] = 0x0AA6;
  10481. t['dagurmukhi'] = 0x0A26;
  10482. t['dahiragana'] = 0x3060;
  10483. t['dakatakana'] = 0x30C0;
  10484. t['dalarabic'] = 0x062F;
  10485. t['dalet'] = 0x05D3;
  10486. t['daletdagesh'] = 0xFB33;
  10487. t['daletdageshhebrew'] = 0xFB33;
  10488. t['dalethebrew'] = 0x05D3;
  10489. t['dalfinalarabic'] = 0xFEAA;
  10490. t['dammaarabic'] = 0x064F;
  10491. t['dammalowarabic'] = 0x064F;
  10492. t['dammatanaltonearabic'] = 0x064C;
  10493. t['dammatanarabic'] = 0x064C;
  10494. t['danda'] = 0x0964;
  10495. t['dargahebrew'] = 0x05A7;
  10496. t['dargalefthebrew'] = 0x05A7;
  10497. t['dasiapneumatacyrilliccmb'] = 0x0485;
  10498. t['dblGrave'] = 0xF6D3;
  10499. t['dblanglebracketleft'] = 0x300A;
  10500. t['dblanglebracketleftvertical'] = 0xFE3D;
  10501. t['dblanglebracketright'] = 0x300B;
  10502. t['dblanglebracketrightvertical'] = 0xFE3E;
  10503. t['dblarchinvertedbelowcmb'] = 0x032B;
  10504. t['dblarrowleft'] = 0x21D4;
  10505. t['dblarrowright'] = 0x21D2;
  10506. t['dbldanda'] = 0x0965;
  10507. t['dblgrave'] = 0xF6D6;
  10508. t['dblgravecmb'] = 0x030F;
  10509. t['dblintegral'] = 0x222C;
  10510. t['dbllowline'] = 0x2017;
  10511. t['dbllowlinecmb'] = 0x0333;
  10512. t['dbloverlinecmb'] = 0x033F;
  10513. t['dblprimemod'] = 0x02BA;
  10514. t['dblverticalbar'] = 0x2016;
  10515. t['dblverticallineabovecmb'] = 0x030E;
  10516. t['dbopomofo'] = 0x3109;
  10517. t['dbsquare'] = 0x33C8;
  10518. t['dcaron'] = 0x010F;
  10519. t['dcedilla'] = 0x1E11;
  10520. t['dcircle'] = 0x24D3;
  10521. t['dcircumflexbelow'] = 0x1E13;
  10522. t['dcroat'] = 0x0111;
  10523. t['ddabengali'] = 0x09A1;
  10524. t['ddadeva'] = 0x0921;
  10525. t['ddagujarati'] = 0x0AA1;
  10526. t['ddagurmukhi'] = 0x0A21;
  10527. t['ddalarabic'] = 0x0688;
  10528. t['ddalfinalarabic'] = 0xFB89;
  10529. t['dddhadeva'] = 0x095C;
  10530. t['ddhabengali'] = 0x09A2;
  10531. t['ddhadeva'] = 0x0922;
  10532. t['ddhagujarati'] = 0x0AA2;
  10533. t['ddhagurmukhi'] = 0x0A22;
  10534. t['ddotaccent'] = 0x1E0B;
  10535. t['ddotbelow'] = 0x1E0D;
  10536. t['decimalseparatorarabic'] = 0x066B;
  10537. t['decimalseparatorpersian'] = 0x066B;
  10538. t['decyrillic'] = 0x0434;
  10539. t['degree'] = 0x00B0;
  10540. t['dehihebrew'] = 0x05AD;
  10541. t['dehiragana'] = 0x3067;
  10542. t['deicoptic'] = 0x03EF;
  10543. t['dekatakana'] = 0x30C7;
  10544. t['deleteleft'] = 0x232B;
  10545. t['deleteright'] = 0x2326;
  10546. t['delta'] = 0x03B4;
  10547. t['deltaturned'] = 0x018D;
  10548. t['denominatorminusonenumeratorbengali'] = 0x09F8;
  10549. t['dezh'] = 0x02A4;
  10550. t['dhabengali'] = 0x09A7;
  10551. t['dhadeva'] = 0x0927;
  10552. t['dhagujarati'] = 0x0AA7;
  10553. t['dhagurmukhi'] = 0x0A27;
  10554. t['dhook'] = 0x0257;
  10555. t['dialytikatonos'] = 0x0385;
  10556. t['dialytikatonoscmb'] = 0x0344;
  10557. t['diamond'] = 0x2666;
  10558. t['diamondsuitwhite'] = 0x2662;
  10559. t['dieresis'] = 0x00A8;
  10560. t['dieresisacute'] = 0xF6D7;
  10561. t['dieresisbelowcmb'] = 0x0324;
  10562. t['dieresiscmb'] = 0x0308;
  10563. t['dieresisgrave'] = 0xF6D8;
  10564. t['dieresistonos'] = 0x0385;
  10565. t['dihiragana'] = 0x3062;
  10566. t['dikatakana'] = 0x30C2;
  10567. t['dittomark'] = 0x3003;
  10568. t['divide'] = 0x00F7;
  10569. t['divides'] = 0x2223;
  10570. t['divisionslash'] = 0x2215;
  10571. t['djecyrillic'] = 0x0452;
  10572. t['dkshade'] = 0x2593;
  10573. t['dlinebelow'] = 0x1E0F;
  10574. t['dlsquare'] = 0x3397;
  10575. t['dmacron'] = 0x0111;
  10576. t['dmonospace'] = 0xFF44;
  10577. t['dnblock'] = 0x2584;
  10578. t['dochadathai'] = 0x0E0E;
  10579. t['dodekthai'] = 0x0E14;
  10580. t['dohiragana'] = 0x3069;
  10581. t['dokatakana'] = 0x30C9;
  10582. t['dollar'] = 0x0024;
  10583. t['dollarinferior'] = 0xF6E3;
  10584. t['dollarmonospace'] = 0xFF04;
  10585. t['dollaroldstyle'] = 0xF724;
  10586. t['dollarsmall'] = 0xFE69;
  10587. t['dollarsuperior'] = 0xF6E4;
  10588. t['dong'] = 0x20AB;
  10589. t['dorusquare'] = 0x3326;
  10590. t['dotaccent'] = 0x02D9;
  10591. t['dotaccentcmb'] = 0x0307;
  10592. t['dotbelowcmb'] = 0x0323;
  10593. t['dotbelowcomb'] = 0x0323;
  10594. t['dotkatakana'] = 0x30FB;
  10595. t['dotlessi'] = 0x0131;
  10596. t['dotlessj'] = 0xF6BE;
  10597. t['dotlessjstrokehook'] = 0x0284;
  10598. t['dotmath'] = 0x22C5;
  10599. t['dottedcircle'] = 0x25CC;
  10600. t['doubleyodpatah'] = 0xFB1F;
  10601. t['doubleyodpatahhebrew'] = 0xFB1F;
  10602. t['downtackbelowcmb'] = 0x031E;
  10603. t['downtackmod'] = 0x02D5;
  10604. t['dparen'] = 0x249F;
  10605. t['dsuperior'] = 0xF6EB;
  10606. t['dtail'] = 0x0256;
  10607. t['dtopbar'] = 0x018C;
  10608. t['duhiragana'] = 0x3065;
  10609. t['dukatakana'] = 0x30C5;
  10610. t['dz'] = 0x01F3;
  10611. t['dzaltone'] = 0x02A3;
  10612. t['dzcaron'] = 0x01C6;
  10613. t['dzcurl'] = 0x02A5;
  10614. t['dzeabkhasiancyrillic'] = 0x04E1;
  10615. t['dzecyrillic'] = 0x0455;
  10616. t['dzhecyrillic'] = 0x045F;
  10617. t['e'] = 0x0065;
  10618. t['eacute'] = 0x00E9;
  10619. t['earth'] = 0x2641;
  10620. t['ebengali'] = 0x098F;
  10621. t['ebopomofo'] = 0x311C;
  10622. t['ebreve'] = 0x0115;
  10623. t['ecandradeva'] = 0x090D;
  10624. t['ecandragujarati'] = 0x0A8D;
  10625. t['ecandravowelsigndeva'] = 0x0945;
  10626. t['ecandravowelsigngujarati'] = 0x0AC5;
  10627. t['ecaron'] = 0x011B;
  10628. t['ecedillabreve'] = 0x1E1D;
  10629. t['echarmenian'] = 0x0565;
  10630. t['echyiwnarmenian'] = 0x0587;
  10631. t['ecircle'] = 0x24D4;
  10632. t['ecircumflex'] = 0x00EA;
  10633. t['ecircumflexacute'] = 0x1EBF;
  10634. t['ecircumflexbelow'] = 0x1E19;
  10635. t['ecircumflexdotbelow'] = 0x1EC7;
  10636. t['ecircumflexgrave'] = 0x1EC1;
  10637. t['ecircumflexhookabove'] = 0x1EC3;
  10638. t['ecircumflextilde'] = 0x1EC5;
  10639. t['ecyrillic'] = 0x0454;
  10640. t['edblgrave'] = 0x0205;
  10641. t['edeva'] = 0x090F;
  10642. t['edieresis'] = 0x00EB;
  10643. t['edot'] = 0x0117;
  10644. t['edotaccent'] = 0x0117;
  10645. t['edotbelow'] = 0x1EB9;
  10646. t['eegurmukhi'] = 0x0A0F;
  10647. t['eematragurmukhi'] = 0x0A47;
  10648. t['efcyrillic'] = 0x0444;
  10649. t['egrave'] = 0x00E8;
  10650. t['egujarati'] = 0x0A8F;
  10651. t['eharmenian'] = 0x0567;
  10652. t['ehbopomofo'] = 0x311D;
  10653. t['ehiragana'] = 0x3048;
  10654. t['ehookabove'] = 0x1EBB;
  10655. t['eibopomofo'] = 0x311F;
  10656. t['eight'] = 0x0038;
  10657. t['eightarabic'] = 0x0668;
  10658. t['eightbengali'] = 0x09EE;
  10659. t['eightcircle'] = 0x2467;
  10660. t['eightcircleinversesansserif'] = 0x2791;
  10661. t['eightdeva'] = 0x096E;
  10662. t['eighteencircle'] = 0x2471;
  10663. t['eighteenparen'] = 0x2485;
  10664. t['eighteenperiod'] = 0x2499;
  10665. t['eightgujarati'] = 0x0AEE;
  10666. t['eightgurmukhi'] = 0x0A6E;
  10667. t['eighthackarabic'] = 0x0668;
  10668. t['eighthangzhou'] = 0x3028;
  10669. t['eighthnotebeamed'] = 0x266B;
  10670. t['eightideographicparen'] = 0x3227;
  10671. t['eightinferior'] = 0x2088;
  10672. t['eightmonospace'] = 0xFF18;
  10673. t['eightoldstyle'] = 0xF738;
  10674. t['eightparen'] = 0x247B;
  10675. t['eightperiod'] = 0x248F;
  10676. t['eightpersian'] = 0x06F8;
  10677. t['eightroman'] = 0x2177;
  10678. t['eightsuperior'] = 0x2078;
  10679. t['eightthai'] = 0x0E58;
  10680. t['einvertedbreve'] = 0x0207;
  10681. t['eiotifiedcyrillic'] = 0x0465;
  10682. t['ekatakana'] = 0x30A8;
  10683. t['ekatakanahalfwidth'] = 0xFF74;
  10684. t['ekonkargurmukhi'] = 0x0A74;
  10685. t['ekorean'] = 0x3154;
  10686. t['elcyrillic'] = 0x043B;
  10687. t['element'] = 0x2208;
  10688. t['elevencircle'] = 0x246A;
  10689. t['elevenparen'] = 0x247E;
  10690. t['elevenperiod'] = 0x2492;
  10691. t['elevenroman'] = 0x217A;
  10692. t['ellipsis'] = 0x2026;
  10693. t['ellipsisvertical'] = 0x22EE;
  10694. t['emacron'] = 0x0113;
  10695. t['emacronacute'] = 0x1E17;
  10696. t['emacrongrave'] = 0x1E15;
  10697. t['emcyrillic'] = 0x043C;
  10698. t['emdash'] = 0x2014;
  10699. t['emdashvertical'] = 0xFE31;
  10700. t['emonospace'] = 0xFF45;
  10701. t['emphasismarkarmenian'] = 0x055B;
  10702. t['emptyset'] = 0x2205;
  10703. t['enbopomofo'] = 0x3123;
  10704. t['encyrillic'] = 0x043D;
  10705. t['endash'] = 0x2013;
  10706. t['endashvertical'] = 0xFE32;
  10707. t['endescendercyrillic'] = 0x04A3;
  10708. t['eng'] = 0x014B;
  10709. t['engbopomofo'] = 0x3125;
  10710. t['enghecyrillic'] = 0x04A5;
  10711. t['enhookcyrillic'] = 0x04C8;
  10712. t['enspace'] = 0x2002;
  10713. t['eogonek'] = 0x0119;
  10714. t['eokorean'] = 0x3153;
  10715. t['eopen'] = 0x025B;
  10716. t['eopenclosed'] = 0x029A;
  10717. t['eopenreversed'] = 0x025C;
  10718. t['eopenreversedclosed'] = 0x025E;
  10719. t['eopenreversedhook'] = 0x025D;
  10720. t['eparen'] = 0x24A0;
  10721. t['epsilon'] = 0x03B5;
  10722. t['epsilontonos'] = 0x03AD;
  10723. t['equal'] = 0x003D;
  10724. t['equalmonospace'] = 0xFF1D;
  10725. t['equalsmall'] = 0xFE66;
  10726. t['equalsuperior'] = 0x207C;
  10727. t['equivalence'] = 0x2261;
  10728. t['erbopomofo'] = 0x3126;
  10729. t['ercyrillic'] = 0x0440;
  10730. t['ereversed'] = 0x0258;
  10731. t['ereversedcyrillic'] = 0x044D;
  10732. t['escyrillic'] = 0x0441;
  10733. t['esdescendercyrillic'] = 0x04AB;
  10734. t['esh'] = 0x0283;
  10735. t['eshcurl'] = 0x0286;
  10736. t['eshortdeva'] = 0x090E;
  10737. t['eshortvowelsigndeva'] = 0x0946;
  10738. t['eshreversedloop'] = 0x01AA;
  10739. t['eshsquatreversed'] = 0x0285;
  10740. t['esmallhiragana'] = 0x3047;
  10741. t['esmallkatakana'] = 0x30A7;
  10742. t['esmallkatakanahalfwidth'] = 0xFF6A;
  10743. t['estimated'] = 0x212E;
  10744. t['esuperior'] = 0xF6EC;
  10745. t['eta'] = 0x03B7;
  10746. t['etarmenian'] = 0x0568;
  10747. t['etatonos'] = 0x03AE;
  10748. t['eth'] = 0x00F0;
  10749. t['etilde'] = 0x1EBD;
  10750. t['etildebelow'] = 0x1E1B;
  10751. t['etnahtafoukhhebrew'] = 0x0591;
  10752. t['etnahtafoukhlefthebrew'] = 0x0591;
  10753. t['etnahtahebrew'] = 0x0591;
  10754. t['etnahtalefthebrew'] = 0x0591;
  10755. t['eturned'] = 0x01DD;
  10756. t['eukorean'] = 0x3161;
  10757. t['euro'] = 0x20AC;
  10758. t['evowelsignbengali'] = 0x09C7;
  10759. t['evowelsigndeva'] = 0x0947;
  10760. t['evowelsigngujarati'] = 0x0AC7;
  10761. t['exclam'] = 0x0021;
  10762. t['exclamarmenian'] = 0x055C;
  10763. t['exclamdbl'] = 0x203C;
  10764. t['exclamdown'] = 0x00A1;
  10765. t['exclamdownsmall'] = 0xF7A1;
  10766. t['exclammonospace'] = 0xFF01;
  10767. t['exclamsmall'] = 0xF721;
  10768. t['existential'] = 0x2203;
  10769. t['ezh'] = 0x0292;
  10770. t['ezhcaron'] = 0x01EF;
  10771. t['ezhcurl'] = 0x0293;
  10772. t['ezhreversed'] = 0x01B9;
  10773. t['ezhtail'] = 0x01BA;
  10774. t['f'] = 0x0066;
  10775. t['fadeva'] = 0x095E;
  10776. t['fagurmukhi'] = 0x0A5E;
  10777. t['fahrenheit'] = 0x2109;
  10778. t['fathaarabic'] = 0x064E;
  10779. t['fathalowarabic'] = 0x064E;
  10780. t['fathatanarabic'] = 0x064B;
  10781. t['fbopomofo'] = 0x3108;
  10782. t['fcircle'] = 0x24D5;
  10783. t['fdotaccent'] = 0x1E1F;
  10784. t['feharabic'] = 0x0641;
  10785. t['feharmenian'] = 0x0586;
  10786. t['fehfinalarabic'] = 0xFED2;
  10787. t['fehinitialarabic'] = 0xFED3;
  10788. t['fehmedialarabic'] = 0xFED4;
  10789. t['feicoptic'] = 0x03E5;
  10790. t['female'] = 0x2640;
  10791. t['ff'] = 0xFB00;
  10792. t['ffi'] = 0xFB03;
  10793. t['ffl'] = 0xFB04;
  10794. t['fi'] = 0xFB01;
  10795. t['fifteencircle'] = 0x246E;
  10796. t['fifteenparen'] = 0x2482;
  10797. t['fifteenperiod'] = 0x2496;
  10798. t['figuredash'] = 0x2012;
  10799. t['filledbox'] = 0x25A0;
  10800. t['filledrect'] = 0x25AC;
  10801. t['finalkaf'] = 0x05DA;
  10802. t['finalkafdagesh'] = 0xFB3A;
  10803. t['finalkafdageshhebrew'] = 0xFB3A;
  10804. t['finalkafhebrew'] = 0x05DA;
  10805. t['finalmem'] = 0x05DD;
  10806. t['finalmemhebrew'] = 0x05DD;
  10807. t['finalnun'] = 0x05DF;
  10808. t['finalnunhebrew'] = 0x05DF;
  10809. t['finalpe'] = 0x05E3;
  10810. t['finalpehebrew'] = 0x05E3;
  10811. t['finaltsadi'] = 0x05E5;
  10812. t['finaltsadihebrew'] = 0x05E5;
  10813. t['firsttonechinese'] = 0x02C9;
  10814. t['fisheye'] = 0x25C9;
  10815. t['fitacyrillic'] = 0x0473;
  10816. t['five'] = 0x0035;
  10817. t['fivearabic'] = 0x0665;
  10818. t['fivebengali'] = 0x09EB;
  10819. t['fivecircle'] = 0x2464;
  10820. t['fivecircleinversesansserif'] = 0x278E;
  10821. t['fivedeva'] = 0x096B;
  10822. t['fiveeighths'] = 0x215D;
  10823. t['fivegujarati'] = 0x0AEB;
  10824. t['fivegurmukhi'] = 0x0A6B;
  10825. t['fivehackarabic'] = 0x0665;
  10826. t['fivehangzhou'] = 0x3025;
  10827. t['fiveideographicparen'] = 0x3224;
  10828. t['fiveinferior'] = 0x2085;
  10829. t['fivemonospace'] = 0xFF15;
  10830. t['fiveoldstyle'] = 0xF735;
  10831. t['fiveparen'] = 0x2478;
  10832. t['fiveperiod'] = 0x248C;
  10833. t['fivepersian'] = 0x06F5;
  10834. t['fiveroman'] = 0x2174;
  10835. t['fivesuperior'] = 0x2075;
  10836. t['fivethai'] = 0x0E55;
  10837. t['fl'] = 0xFB02;
  10838. t['florin'] = 0x0192;
  10839. t['fmonospace'] = 0xFF46;
  10840. t['fmsquare'] = 0x3399;
  10841. t['fofanthai'] = 0x0E1F;
  10842. t['fofathai'] = 0x0E1D;
  10843. t['fongmanthai'] = 0x0E4F;
  10844. t['forall'] = 0x2200;
  10845. t['four'] = 0x0034;
  10846. t['fourarabic'] = 0x0664;
  10847. t['fourbengali'] = 0x09EA;
  10848. t['fourcircle'] = 0x2463;
  10849. t['fourcircleinversesansserif'] = 0x278D;
  10850. t['fourdeva'] = 0x096A;
  10851. t['fourgujarati'] = 0x0AEA;
  10852. t['fourgurmukhi'] = 0x0A6A;
  10853. t['fourhackarabic'] = 0x0664;
  10854. t['fourhangzhou'] = 0x3024;
  10855. t['fourideographicparen'] = 0x3223;
  10856. t['fourinferior'] = 0x2084;
  10857. t['fourmonospace'] = 0xFF14;
  10858. t['fournumeratorbengali'] = 0x09F7;
  10859. t['fouroldstyle'] = 0xF734;
  10860. t['fourparen'] = 0x2477;
  10861. t['fourperiod'] = 0x248B;
  10862. t['fourpersian'] = 0x06F4;
  10863. t['fourroman'] = 0x2173;
  10864. t['foursuperior'] = 0x2074;
  10865. t['fourteencircle'] = 0x246D;
  10866. t['fourteenparen'] = 0x2481;
  10867. t['fourteenperiod'] = 0x2495;
  10868. t['fourthai'] = 0x0E54;
  10869. t['fourthtonechinese'] = 0x02CB;
  10870. t['fparen'] = 0x24A1;
  10871. t['fraction'] = 0x2044;
  10872. t['franc'] = 0x20A3;
  10873. t['g'] = 0x0067;
  10874. t['gabengali'] = 0x0997;
  10875. t['gacute'] = 0x01F5;
  10876. t['gadeva'] = 0x0917;
  10877. t['gafarabic'] = 0x06AF;
  10878. t['gaffinalarabic'] = 0xFB93;
  10879. t['gafinitialarabic'] = 0xFB94;
  10880. t['gafmedialarabic'] = 0xFB95;
  10881. t['gagujarati'] = 0x0A97;
  10882. t['gagurmukhi'] = 0x0A17;
  10883. t['gahiragana'] = 0x304C;
  10884. t['gakatakana'] = 0x30AC;
  10885. t['gamma'] = 0x03B3;
  10886. t['gammalatinsmall'] = 0x0263;
  10887. t['gammasuperior'] = 0x02E0;
  10888. t['gangiacoptic'] = 0x03EB;
  10889. t['gbopomofo'] = 0x310D;
  10890. t['gbreve'] = 0x011F;
  10891. t['gcaron'] = 0x01E7;
  10892. t['gcedilla'] = 0x0123;
  10893. t['gcircle'] = 0x24D6;
  10894. t['gcircumflex'] = 0x011D;
  10895. t['gcommaaccent'] = 0x0123;
  10896. t['gdot'] = 0x0121;
  10897. t['gdotaccent'] = 0x0121;
  10898. t['gecyrillic'] = 0x0433;
  10899. t['gehiragana'] = 0x3052;
  10900. t['gekatakana'] = 0x30B2;
  10901. t['geometricallyequal'] = 0x2251;
  10902. t['gereshaccenthebrew'] = 0x059C;
  10903. t['gereshhebrew'] = 0x05F3;
  10904. t['gereshmuqdamhebrew'] = 0x059D;
  10905. t['germandbls'] = 0x00DF;
  10906. t['gershayimaccenthebrew'] = 0x059E;
  10907. t['gershayimhebrew'] = 0x05F4;
  10908. t['getamark'] = 0x3013;
  10909. t['ghabengali'] = 0x0998;
  10910. t['ghadarmenian'] = 0x0572;
  10911. t['ghadeva'] = 0x0918;
  10912. t['ghagujarati'] = 0x0A98;
  10913. t['ghagurmukhi'] = 0x0A18;
  10914. t['ghainarabic'] = 0x063A;
  10915. t['ghainfinalarabic'] = 0xFECE;
  10916. t['ghaininitialarabic'] = 0xFECF;
  10917. t['ghainmedialarabic'] = 0xFED0;
  10918. t['ghemiddlehookcyrillic'] = 0x0495;
  10919. t['ghestrokecyrillic'] = 0x0493;
  10920. t['gheupturncyrillic'] = 0x0491;
  10921. t['ghhadeva'] = 0x095A;
  10922. t['ghhagurmukhi'] = 0x0A5A;
  10923. t['ghook'] = 0x0260;
  10924. t['ghzsquare'] = 0x3393;
  10925. t['gihiragana'] = 0x304E;
  10926. t['gikatakana'] = 0x30AE;
  10927. t['gimarmenian'] = 0x0563;
  10928. t['gimel'] = 0x05D2;
  10929. t['gimeldagesh'] = 0xFB32;
  10930. t['gimeldageshhebrew'] = 0xFB32;
  10931. t['gimelhebrew'] = 0x05D2;
  10932. t['gjecyrillic'] = 0x0453;
  10933. t['glottalinvertedstroke'] = 0x01BE;
  10934. t['glottalstop'] = 0x0294;
  10935. t['glottalstopinverted'] = 0x0296;
  10936. t['glottalstopmod'] = 0x02C0;
  10937. t['glottalstopreversed'] = 0x0295;
  10938. t['glottalstopreversedmod'] = 0x02C1;
  10939. t['glottalstopreversedsuperior'] = 0x02E4;
  10940. t['glottalstopstroke'] = 0x02A1;
  10941. t['glottalstopstrokereversed'] = 0x02A2;
  10942. t['gmacron'] = 0x1E21;
  10943. t['gmonospace'] = 0xFF47;
  10944. t['gohiragana'] = 0x3054;
  10945. t['gokatakana'] = 0x30B4;
  10946. t['gparen'] = 0x24A2;
  10947. t['gpasquare'] = 0x33AC;
  10948. t['gradient'] = 0x2207;
  10949. t['grave'] = 0x0060;
  10950. t['gravebelowcmb'] = 0x0316;
  10951. t['gravecmb'] = 0x0300;
  10952. t['gravecomb'] = 0x0300;
  10953. t['gravedeva'] = 0x0953;
  10954. t['gravelowmod'] = 0x02CE;
  10955. t['gravemonospace'] = 0xFF40;
  10956. t['gravetonecmb'] = 0x0340;
  10957. t['greater'] = 0x003E;
  10958. t['greaterequal'] = 0x2265;
  10959. t['greaterequalorless'] = 0x22DB;
  10960. t['greatermonospace'] = 0xFF1E;
  10961. t['greaterorequivalent'] = 0x2273;
  10962. t['greaterorless'] = 0x2277;
  10963. t['greateroverequal'] = 0x2267;
  10964. t['greatersmall'] = 0xFE65;
  10965. t['gscript'] = 0x0261;
  10966. t['gstroke'] = 0x01E5;
  10967. t['guhiragana'] = 0x3050;
  10968. t['guillemotleft'] = 0x00AB;
  10969. t['guillemotright'] = 0x00BB;
  10970. t['guilsinglleft'] = 0x2039;
  10971. t['guilsinglright'] = 0x203A;
  10972. t['gukatakana'] = 0x30B0;
  10973. t['guramusquare'] = 0x3318;
  10974. t['gysquare'] = 0x33C9;
  10975. t['h'] = 0x0068;
  10976. t['haabkhasiancyrillic'] = 0x04A9;
  10977. t['haaltonearabic'] = 0x06C1;
  10978. t['habengali'] = 0x09B9;
  10979. t['hadescendercyrillic'] = 0x04B3;
  10980. t['hadeva'] = 0x0939;
  10981. t['hagujarati'] = 0x0AB9;
  10982. t['hagurmukhi'] = 0x0A39;
  10983. t['haharabic'] = 0x062D;
  10984. t['hahfinalarabic'] = 0xFEA2;
  10985. t['hahinitialarabic'] = 0xFEA3;
  10986. t['hahiragana'] = 0x306F;
  10987. t['hahmedialarabic'] = 0xFEA4;
  10988. t['haitusquare'] = 0x332A;
  10989. t['hakatakana'] = 0x30CF;
  10990. t['hakatakanahalfwidth'] = 0xFF8A;
  10991. t['halantgurmukhi'] = 0x0A4D;
  10992. t['hamzaarabic'] = 0x0621;
  10993. t['hamzalowarabic'] = 0x0621;
  10994. t['hangulfiller'] = 0x3164;
  10995. t['hardsigncyrillic'] = 0x044A;
  10996. t['harpoonleftbarbup'] = 0x21BC;
  10997. t['harpoonrightbarbup'] = 0x21C0;
  10998. t['hasquare'] = 0x33CA;
  10999. t['hatafpatah'] = 0x05B2;
  11000. t['hatafpatah16'] = 0x05B2;
  11001. t['hatafpatah23'] = 0x05B2;
  11002. t['hatafpatah2f'] = 0x05B2;
  11003. t['hatafpatahhebrew'] = 0x05B2;
  11004. t['hatafpatahnarrowhebrew'] = 0x05B2;
  11005. t['hatafpatahquarterhebrew'] = 0x05B2;
  11006. t['hatafpatahwidehebrew'] = 0x05B2;
  11007. t['hatafqamats'] = 0x05B3;
  11008. t['hatafqamats1b'] = 0x05B3;
  11009. t['hatafqamats28'] = 0x05B3;
  11010. t['hatafqamats34'] = 0x05B3;
  11011. t['hatafqamatshebrew'] = 0x05B3;
  11012. t['hatafqamatsnarrowhebrew'] = 0x05B3;
  11013. t['hatafqamatsquarterhebrew'] = 0x05B3;
  11014. t['hatafqamatswidehebrew'] = 0x05B3;
  11015. t['hatafsegol'] = 0x05B1;
  11016. t['hatafsegol17'] = 0x05B1;
  11017. t['hatafsegol24'] = 0x05B1;
  11018. t['hatafsegol30'] = 0x05B1;
  11019. t['hatafsegolhebrew'] = 0x05B1;
  11020. t['hatafsegolnarrowhebrew'] = 0x05B1;
  11021. t['hatafsegolquarterhebrew'] = 0x05B1;
  11022. t['hatafsegolwidehebrew'] = 0x05B1;
  11023. t['hbar'] = 0x0127;
  11024. t['hbopomofo'] = 0x310F;
  11025. t['hbrevebelow'] = 0x1E2B;
  11026. t['hcedilla'] = 0x1E29;
  11027. t['hcircle'] = 0x24D7;
  11028. t['hcircumflex'] = 0x0125;
  11029. t['hdieresis'] = 0x1E27;
  11030. t['hdotaccent'] = 0x1E23;
  11031. t['hdotbelow'] = 0x1E25;
  11032. t['he'] = 0x05D4;
  11033. t['heart'] = 0x2665;
  11034. t['heartsuitblack'] = 0x2665;
  11035. t['heartsuitwhite'] = 0x2661;
  11036. t['hedagesh'] = 0xFB34;
  11037. t['hedageshhebrew'] = 0xFB34;
  11038. t['hehaltonearabic'] = 0x06C1;
  11039. t['heharabic'] = 0x0647;
  11040. t['hehebrew'] = 0x05D4;
  11041. t['hehfinalaltonearabic'] = 0xFBA7;
  11042. t['hehfinalalttwoarabic'] = 0xFEEA;
  11043. t['hehfinalarabic'] = 0xFEEA;
  11044. t['hehhamzaabovefinalarabic'] = 0xFBA5;
  11045. t['hehhamzaaboveisolatedarabic'] = 0xFBA4;
  11046. t['hehinitialaltonearabic'] = 0xFBA8;
  11047. t['hehinitialarabic'] = 0xFEEB;
  11048. t['hehiragana'] = 0x3078;
  11049. t['hehmedialaltonearabic'] = 0xFBA9;
  11050. t['hehmedialarabic'] = 0xFEEC;
  11051. t['heiseierasquare'] = 0x337B;
  11052. t['hekatakana'] = 0x30D8;
  11053. t['hekatakanahalfwidth'] = 0xFF8D;
  11054. t['hekutaarusquare'] = 0x3336;
  11055. t['henghook'] = 0x0267;
  11056. t['herutusquare'] = 0x3339;
  11057. t['het'] = 0x05D7;
  11058. t['hethebrew'] = 0x05D7;
  11059. t['hhook'] = 0x0266;
  11060. t['hhooksuperior'] = 0x02B1;
  11061. t['hieuhacirclekorean'] = 0x327B;
  11062. t['hieuhaparenkorean'] = 0x321B;
  11063. t['hieuhcirclekorean'] = 0x326D;
  11064. t['hieuhkorean'] = 0x314E;
  11065. t['hieuhparenkorean'] = 0x320D;
  11066. t['hihiragana'] = 0x3072;
  11067. t['hikatakana'] = 0x30D2;
  11068. t['hikatakanahalfwidth'] = 0xFF8B;
  11069. t['hiriq'] = 0x05B4;
  11070. t['hiriq14'] = 0x05B4;
  11071. t['hiriq21'] = 0x05B4;
  11072. t['hiriq2d'] = 0x05B4;
  11073. t['hiriqhebrew'] = 0x05B4;
  11074. t['hiriqnarrowhebrew'] = 0x05B4;
  11075. t['hiriqquarterhebrew'] = 0x05B4;
  11076. t['hiriqwidehebrew'] = 0x05B4;
  11077. t['hlinebelow'] = 0x1E96;
  11078. t['hmonospace'] = 0xFF48;
  11079. t['hoarmenian'] = 0x0570;
  11080. t['hohipthai'] = 0x0E2B;
  11081. t['hohiragana'] = 0x307B;
  11082. t['hokatakana'] = 0x30DB;
  11083. t['hokatakanahalfwidth'] = 0xFF8E;
  11084. t['holam'] = 0x05B9;
  11085. t['holam19'] = 0x05B9;
  11086. t['holam26'] = 0x05B9;
  11087. t['holam32'] = 0x05B9;
  11088. t['holamhebrew'] = 0x05B9;
  11089. t['holamnarrowhebrew'] = 0x05B9;
  11090. t['holamquarterhebrew'] = 0x05B9;
  11091. t['holamwidehebrew'] = 0x05B9;
  11092. t['honokhukthai'] = 0x0E2E;
  11093. t['hookabovecomb'] = 0x0309;
  11094. t['hookcmb'] = 0x0309;
  11095. t['hookpalatalizedbelowcmb'] = 0x0321;
  11096. t['hookretroflexbelowcmb'] = 0x0322;
  11097. t['hoonsquare'] = 0x3342;
  11098. t['horicoptic'] = 0x03E9;
  11099. t['horizontalbar'] = 0x2015;
  11100. t['horncmb'] = 0x031B;
  11101. t['hotsprings'] = 0x2668;
  11102. t['house'] = 0x2302;
  11103. t['hparen'] = 0x24A3;
  11104. t['hsuperior'] = 0x02B0;
  11105. t['hturned'] = 0x0265;
  11106. t['huhiragana'] = 0x3075;
  11107. t['huiitosquare'] = 0x3333;
  11108. t['hukatakana'] = 0x30D5;
  11109. t['hukatakanahalfwidth'] = 0xFF8C;
  11110. t['hungarumlaut'] = 0x02DD;
  11111. t['hungarumlautcmb'] = 0x030B;
  11112. t['hv'] = 0x0195;
  11113. t['hyphen'] = 0x002D;
  11114. t['hypheninferior'] = 0xF6E5;
  11115. t['hyphenmonospace'] = 0xFF0D;
  11116. t['hyphensmall'] = 0xFE63;
  11117. t['hyphensuperior'] = 0xF6E6;
  11118. t['hyphentwo'] = 0x2010;
  11119. t['i'] = 0x0069;
  11120. t['iacute'] = 0x00ED;
  11121. t['iacyrillic'] = 0x044F;
  11122. t['ibengali'] = 0x0987;
  11123. t['ibopomofo'] = 0x3127;
  11124. t['ibreve'] = 0x012D;
  11125. t['icaron'] = 0x01D0;
  11126. t['icircle'] = 0x24D8;
  11127. t['icircumflex'] = 0x00EE;
  11128. t['icyrillic'] = 0x0456;
  11129. t['idblgrave'] = 0x0209;
  11130. t['ideographearthcircle'] = 0x328F;
  11131. t['ideographfirecircle'] = 0x328B;
  11132. t['ideographicallianceparen'] = 0x323F;
  11133. t['ideographiccallparen'] = 0x323A;
  11134. t['ideographiccentrecircle'] = 0x32A5;
  11135. t['ideographicclose'] = 0x3006;
  11136. t['ideographiccomma'] = 0x3001;
  11137. t['ideographiccommaleft'] = 0xFF64;
  11138. t['ideographiccongratulationparen'] = 0x3237;
  11139. t['ideographiccorrectcircle'] = 0x32A3;
  11140. t['ideographicearthparen'] = 0x322F;
  11141. t['ideographicenterpriseparen'] = 0x323D;
  11142. t['ideographicexcellentcircle'] = 0x329D;
  11143. t['ideographicfestivalparen'] = 0x3240;
  11144. t['ideographicfinancialcircle'] = 0x3296;
  11145. t['ideographicfinancialparen'] = 0x3236;
  11146. t['ideographicfireparen'] = 0x322B;
  11147. t['ideographichaveparen'] = 0x3232;
  11148. t['ideographichighcircle'] = 0x32A4;
  11149. t['ideographiciterationmark'] = 0x3005;
  11150. t['ideographiclaborcircle'] = 0x3298;
  11151. t['ideographiclaborparen'] = 0x3238;
  11152. t['ideographicleftcircle'] = 0x32A7;
  11153. t['ideographiclowcircle'] = 0x32A6;
  11154. t['ideographicmedicinecircle'] = 0x32A9;
  11155. t['ideographicmetalparen'] = 0x322E;
  11156. t['ideographicmoonparen'] = 0x322A;
  11157. t['ideographicnameparen'] = 0x3234;
  11158. t['ideographicperiod'] = 0x3002;
  11159. t['ideographicprintcircle'] = 0x329E;
  11160. t['ideographicreachparen'] = 0x3243;
  11161. t['ideographicrepresentparen'] = 0x3239;
  11162. t['ideographicresourceparen'] = 0x323E;
  11163. t['ideographicrightcircle'] = 0x32A8;
  11164. t['ideographicsecretcircle'] = 0x3299;
  11165. t['ideographicselfparen'] = 0x3242;
  11166. t['ideographicsocietyparen'] = 0x3233;
  11167. t['ideographicspace'] = 0x3000;
  11168. t['ideographicspecialparen'] = 0x3235;
  11169. t['ideographicstockparen'] = 0x3231;
  11170. t['ideographicstudyparen'] = 0x323B;
  11171. t['ideographicsunparen'] = 0x3230;
  11172. t['ideographicsuperviseparen'] = 0x323C;
  11173. t['ideographicwaterparen'] = 0x322C;
  11174. t['ideographicwoodparen'] = 0x322D;
  11175. t['ideographiczero'] = 0x3007;
  11176. t['ideographmetalcircle'] = 0x328E;
  11177. t['ideographmooncircle'] = 0x328A;
  11178. t['ideographnamecircle'] = 0x3294;
  11179. t['ideographsuncircle'] = 0x3290;
  11180. t['ideographwatercircle'] = 0x328C;
  11181. t['ideographwoodcircle'] = 0x328D;
  11182. t['ideva'] = 0x0907;
  11183. t['idieresis'] = 0x00EF;
  11184. t['idieresisacute'] = 0x1E2F;
  11185. t['idieresiscyrillic'] = 0x04E5;
  11186. t['idotbelow'] = 0x1ECB;
  11187. t['iebrevecyrillic'] = 0x04D7;
  11188. t['iecyrillic'] = 0x0435;
  11189. t['ieungacirclekorean'] = 0x3275;
  11190. t['ieungaparenkorean'] = 0x3215;
  11191. t['ieungcirclekorean'] = 0x3267;
  11192. t['ieungkorean'] = 0x3147;
  11193. t['ieungparenkorean'] = 0x3207;
  11194. t['igrave'] = 0x00EC;
  11195. t['igujarati'] = 0x0A87;
  11196. t['igurmukhi'] = 0x0A07;
  11197. t['ihiragana'] = 0x3044;
  11198. t['ihookabove'] = 0x1EC9;
  11199. t['iibengali'] = 0x0988;
  11200. t['iicyrillic'] = 0x0438;
  11201. t['iideva'] = 0x0908;
  11202. t['iigujarati'] = 0x0A88;
  11203. t['iigurmukhi'] = 0x0A08;
  11204. t['iimatragurmukhi'] = 0x0A40;
  11205. t['iinvertedbreve'] = 0x020B;
  11206. t['iishortcyrillic'] = 0x0439;
  11207. t['iivowelsignbengali'] = 0x09C0;
  11208. t['iivowelsigndeva'] = 0x0940;
  11209. t['iivowelsigngujarati'] = 0x0AC0;
  11210. t['ij'] = 0x0133;
  11211. t['ikatakana'] = 0x30A4;
  11212. t['ikatakanahalfwidth'] = 0xFF72;
  11213. t['ikorean'] = 0x3163;
  11214. t['ilde'] = 0x02DC;
  11215. t['iluyhebrew'] = 0x05AC;
  11216. t['imacron'] = 0x012B;
  11217. t['imacroncyrillic'] = 0x04E3;
  11218. t['imageorapproximatelyequal'] = 0x2253;
  11219. t['imatragurmukhi'] = 0x0A3F;
  11220. t['imonospace'] = 0xFF49;
  11221. t['increment'] = 0x2206;
  11222. t['infinity'] = 0x221E;
  11223. t['iniarmenian'] = 0x056B;
  11224. t['integral'] = 0x222B;
  11225. t['integralbottom'] = 0x2321;
  11226. t['integralbt'] = 0x2321;
  11227. t['integralex'] = 0xF8F5;
  11228. t['integraltop'] = 0x2320;
  11229. t['integraltp'] = 0x2320;
  11230. t['intersection'] = 0x2229;
  11231. t['intisquare'] = 0x3305;
  11232. t['invbullet'] = 0x25D8;
  11233. t['invcircle'] = 0x25D9;
  11234. t['invsmileface'] = 0x263B;
  11235. t['iocyrillic'] = 0x0451;
  11236. t['iogonek'] = 0x012F;
  11237. t['iota'] = 0x03B9;
  11238. t['iotadieresis'] = 0x03CA;
  11239. t['iotadieresistonos'] = 0x0390;
  11240. t['iotalatin'] = 0x0269;
  11241. t['iotatonos'] = 0x03AF;
  11242. t['iparen'] = 0x24A4;
  11243. t['irigurmukhi'] = 0x0A72;
  11244. t['ismallhiragana'] = 0x3043;
  11245. t['ismallkatakana'] = 0x30A3;
  11246. t['ismallkatakanahalfwidth'] = 0xFF68;
  11247. t['issharbengali'] = 0x09FA;
  11248. t['istroke'] = 0x0268;
  11249. t['isuperior'] = 0xF6ED;
  11250. t['iterationhiragana'] = 0x309D;
  11251. t['iterationkatakana'] = 0x30FD;
  11252. t['itilde'] = 0x0129;
  11253. t['itildebelow'] = 0x1E2D;
  11254. t['iubopomofo'] = 0x3129;
  11255. t['iucyrillic'] = 0x044E;
  11256. t['ivowelsignbengali'] = 0x09BF;
  11257. t['ivowelsigndeva'] = 0x093F;
  11258. t['ivowelsigngujarati'] = 0x0ABF;
  11259. t['izhitsacyrillic'] = 0x0475;
  11260. t['izhitsadblgravecyrillic'] = 0x0477;
  11261. t['j'] = 0x006A;
  11262. t['jaarmenian'] = 0x0571;
  11263. t['jabengali'] = 0x099C;
  11264. t['jadeva'] = 0x091C;
  11265. t['jagujarati'] = 0x0A9C;
  11266. t['jagurmukhi'] = 0x0A1C;
  11267. t['jbopomofo'] = 0x3110;
  11268. t['jcaron'] = 0x01F0;
  11269. t['jcircle'] = 0x24D9;
  11270. t['jcircumflex'] = 0x0135;
  11271. t['jcrossedtail'] = 0x029D;
  11272. t['jdotlessstroke'] = 0x025F;
  11273. t['jecyrillic'] = 0x0458;
  11274. t['jeemarabic'] = 0x062C;
  11275. t['jeemfinalarabic'] = 0xFE9E;
  11276. t['jeeminitialarabic'] = 0xFE9F;
  11277. t['jeemmedialarabic'] = 0xFEA0;
  11278. t['jeharabic'] = 0x0698;
  11279. t['jehfinalarabic'] = 0xFB8B;
  11280. t['jhabengali'] = 0x099D;
  11281. t['jhadeva'] = 0x091D;
  11282. t['jhagujarati'] = 0x0A9D;
  11283. t['jhagurmukhi'] = 0x0A1D;
  11284. t['jheharmenian'] = 0x057B;
  11285. t['jis'] = 0x3004;
  11286. t['jmonospace'] = 0xFF4A;
  11287. t['jparen'] = 0x24A5;
  11288. t['jsuperior'] = 0x02B2;
  11289. t['k'] = 0x006B;
  11290. t['kabashkircyrillic'] = 0x04A1;
  11291. t['kabengali'] = 0x0995;
  11292. t['kacute'] = 0x1E31;
  11293. t['kacyrillic'] = 0x043A;
  11294. t['kadescendercyrillic'] = 0x049B;
  11295. t['kadeva'] = 0x0915;
  11296. t['kaf'] = 0x05DB;
  11297. t['kafarabic'] = 0x0643;
  11298. t['kafdagesh'] = 0xFB3B;
  11299. t['kafdageshhebrew'] = 0xFB3B;
  11300. t['kaffinalarabic'] = 0xFEDA;
  11301. t['kafhebrew'] = 0x05DB;
  11302. t['kafinitialarabic'] = 0xFEDB;
  11303. t['kafmedialarabic'] = 0xFEDC;
  11304. t['kafrafehebrew'] = 0xFB4D;
  11305. t['kagujarati'] = 0x0A95;
  11306. t['kagurmukhi'] = 0x0A15;
  11307. t['kahiragana'] = 0x304B;
  11308. t['kahookcyrillic'] = 0x04C4;
  11309. t['kakatakana'] = 0x30AB;
  11310. t['kakatakanahalfwidth'] = 0xFF76;
  11311. t['kappa'] = 0x03BA;
  11312. t['kappasymbolgreek'] = 0x03F0;
  11313. t['kapyeounmieumkorean'] = 0x3171;
  11314. t['kapyeounphieuphkorean'] = 0x3184;
  11315. t['kapyeounpieupkorean'] = 0x3178;
  11316. t['kapyeounssangpieupkorean'] = 0x3179;
  11317. t['karoriisquare'] = 0x330D;
  11318. t['kashidaautoarabic'] = 0x0640;
  11319. t['kashidaautonosidebearingarabic'] = 0x0640;
  11320. t['kasmallkatakana'] = 0x30F5;
  11321. t['kasquare'] = 0x3384;
  11322. t['kasraarabic'] = 0x0650;
  11323. t['kasratanarabic'] = 0x064D;
  11324. t['kastrokecyrillic'] = 0x049F;
  11325. t['katahiraprolongmarkhalfwidth'] = 0xFF70;
  11326. t['kaverticalstrokecyrillic'] = 0x049D;
  11327. t['kbopomofo'] = 0x310E;
  11328. t['kcalsquare'] = 0x3389;
  11329. t['kcaron'] = 0x01E9;
  11330. t['kcedilla'] = 0x0137;
  11331. t['kcircle'] = 0x24DA;
  11332. t['kcommaaccent'] = 0x0137;
  11333. t['kdotbelow'] = 0x1E33;
  11334. t['keharmenian'] = 0x0584;
  11335. t['kehiragana'] = 0x3051;
  11336. t['kekatakana'] = 0x30B1;
  11337. t['kekatakanahalfwidth'] = 0xFF79;
  11338. t['kenarmenian'] = 0x056F;
  11339. t['kesmallkatakana'] = 0x30F6;
  11340. t['kgreenlandic'] = 0x0138;
  11341. t['khabengali'] = 0x0996;
  11342. t['khacyrillic'] = 0x0445;
  11343. t['khadeva'] = 0x0916;
  11344. t['khagujarati'] = 0x0A96;
  11345. t['khagurmukhi'] = 0x0A16;
  11346. t['khaharabic'] = 0x062E;
  11347. t['khahfinalarabic'] = 0xFEA6;
  11348. t['khahinitialarabic'] = 0xFEA7;
  11349. t['khahmedialarabic'] = 0xFEA8;
  11350. t['kheicoptic'] = 0x03E7;
  11351. t['khhadeva'] = 0x0959;
  11352. t['khhagurmukhi'] = 0x0A59;
  11353. t['khieukhacirclekorean'] = 0x3278;
  11354. t['khieukhaparenkorean'] = 0x3218;
  11355. t['khieukhcirclekorean'] = 0x326A;
  11356. t['khieukhkorean'] = 0x314B;
  11357. t['khieukhparenkorean'] = 0x320A;
  11358. t['khokhaithai'] = 0x0E02;
  11359. t['khokhonthai'] = 0x0E05;
  11360. t['khokhuatthai'] = 0x0E03;
  11361. t['khokhwaithai'] = 0x0E04;
  11362. t['khomutthai'] = 0x0E5B;
  11363. t['khook'] = 0x0199;
  11364. t['khorakhangthai'] = 0x0E06;
  11365. t['khzsquare'] = 0x3391;
  11366. t['kihiragana'] = 0x304D;
  11367. t['kikatakana'] = 0x30AD;
  11368. t['kikatakanahalfwidth'] = 0xFF77;
  11369. t['kiroguramusquare'] = 0x3315;
  11370. t['kiromeetorusquare'] = 0x3316;
  11371. t['kirosquare'] = 0x3314;
  11372. t['kiyeokacirclekorean'] = 0x326E;
  11373. t['kiyeokaparenkorean'] = 0x320E;
  11374. t['kiyeokcirclekorean'] = 0x3260;
  11375. t['kiyeokkorean'] = 0x3131;
  11376. t['kiyeokparenkorean'] = 0x3200;
  11377. t['kiyeoksioskorean'] = 0x3133;
  11378. t['kjecyrillic'] = 0x045C;
  11379. t['klinebelow'] = 0x1E35;
  11380. t['klsquare'] = 0x3398;
  11381. t['kmcubedsquare'] = 0x33A6;
  11382. t['kmonospace'] = 0xFF4B;
  11383. t['kmsquaredsquare'] = 0x33A2;
  11384. t['kohiragana'] = 0x3053;
  11385. t['kohmsquare'] = 0x33C0;
  11386. t['kokaithai'] = 0x0E01;
  11387. t['kokatakana'] = 0x30B3;
  11388. t['kokatakanahalfwidth'] = 0xFF7A;
  11389. t['kooposquare'] = 0x331E;
  11390. t['koppacyrillic'] = 0x0481;
  11391. t['koreanstandardsymbol'] = 0x327F;
  11392. t['koroniscmb'] = 0x0343;
  11393. t['kparen'] = 0x24A6;
  11394. t['kpasquare'] = 0x33AA;
  11395. t['ksicyrillic'] = 0x046F;
  11396. t['ktsquare'] = 0x33CF;
  11397. t['kturned'] = 0x029E;
  11398. t['kuhiragana'] = 0x304F;
  11399. t['kukatakana'] = 0x30AF;
  11400. t['kukatakanahalfwidth'] = 0xFF78;
  11401. t['kvsquare'] = 0x33B8;
  11402. t['kwsquare'] = 0x33BE;
  11403. t['l'] = 0x006C;
  11404. t['labengali'] = 0x09B2;
  11405. t['lacute'] = 0x013A;
  11406. t['ladeva'] = 0x0932;
  11407. t['lagujarati'] = 0x0AB2;
  11408. t['lagurmukhi'] = 0x0A32;
  11409. t['lakkhangyaothai'] = 0x0E45;
  11410. t['lamaleffinalarabic'] = 0xFEFC;
  11411. t['lamalefhamzaabovefinalarabic'] = 0xFEF8;
  11412. t['lamalefhamzaaboveisolatedarabic'] = 0xFEF7;
  11413. t['lamalefhamzabelowfinalarabic'] = 0xFEFA;
  11414. t['lamalefhamzabelowisolatedarabic'] = 0xFEF9;
  11415. t['lamalefisolatedarabic'] = 0xFEFB;
  11416. t['lamalefmaddaabovefinalarabic'] = 0xFEF6;
  11417. t['lamalefmaddaaboveisolatedarabic'] = 0xFEF5;
  11418. t['lamarabic'] = 0x0644;
  11419. t['lambda'] = 0x03BB;
  11420. t['lambdastroke'] = 0x019B;
  11421. t['lamed'] = 0x05DC;
  11422. t['lameddagesh'] = 0xFB3C;
  11423. t['lameddageshhebrew'] = 0xFB3C;
  11424. t['lamedhebrew'] = 0x05DC;
  11425. t['lamfinalarabic'] = 0xFEDE;
  11426. t['lamhahinitialarabic'] = 0xFCCA;
  11427. t['laminitialarabic'] = 0xFEDF;
  11428. t['lamjeeminitialarabic'] = 0xFCC9;
  11429. t['lamkhahinitialarabic'] = 0xFCCB;
  11430. t['lamlamhehisolatedarabic'] = 0xFDF2;
  11431. t['lammedialarabic'] = 0xFEE0;
  11432. t['lammeemhahinitialarabic'] = 0xFD88;
  11433. t['lammeeminitialarabic'] = 0xFCCC;
  11434. t['largecircle'] = 0x25EF;
  11435. t['lbar'] = 0x019A;
  11436. t['lbelt'] = 0x026C;
  11437. t['lbopomofo'] = 0x310C;
  11438. t['lcaron'] = 0x013E;
  11439. t['lcedilla'] = 0x013C;
  11440. t['lcircle'] = 0x24DB;
  11441. t['lcircumflexbelow'] = 0x1E3D;
  11442. t['lcommaaccent'] = 0x013C;
  11443. t['ldot'] = 0x0140;
  11444. t['ldotaccent'] = 0x0140;
  11445. t['ldotbelow'] = 0x1E37;
  11446. t['ldotbelowmacron'] = 0x1E39;
  11447. t['leftangleabovecmb'] = 0x031A;
  11448. t['lefttackbelowcmb'] = 0x0318;
  11449. t['less'] = 0x003C;
  11450. t['lessequal'] = 0x2264;
  11451. t['lessequalorgreater'] = 0x22DA;
  11452. t['lessmonospace'] = 0xFF1C;
  11453. t['lessorequivalent'] = 0x2272;
  11454. t['lessorgreater'] = 0x2276;
  11455. t['lessoverequal'] = 0x2266;
  11456. t['lesssmall'] = 0xFE64;
  11457. t['lezh'] = 0x026E;
  11458. t['lfblock'] = 0x258C;
  11459. t['lhookretroflex'] = 0x026D;
  11460. t['lira'] = 0x20A4;
  11461. t['liwnarmenian'] = 0x056C;
  11462. t['lj'] = 0x01C9;
  11463. t['ljecyrillic'] = 0x0459;
  11464. t['ll'] = 0xF6C0;
  11465. t['lladeva'] = 0x0933;
  11466. t['llagujarati'] = 0x0AB3;
  11467. t['llinebelow'] = 0x1E3B;
  11468. t['llladeva'] = 0x0934;
  11469. t['llvocalicbengali'] = 0x09E1;
  11470. t['llvocalicdeva'] = 0x0961;
  11471. t['llvocalicvowelsignbengali'] = 0x09E3;
  11472. t['llvocalicvowelsigndeva'] = 0x0963;
  11473. t['lmiddletilde'] = 0x026B;
  11474. t['lmonospace'] = 0xFF4C;
  11475. t['lmsquare'] = 0x33D0;
  11476. t['lochulathai'] = 0x0E2C;
  11477. t['logicaland'] = 0x2227;
  11478. t['logicalnot'] = 0x00AC;
  11479. t['logicalnotreversed'] = 0x2310;
  11480. t['logicalor'] = 0x2228;
  11481. t['lolingthai'] = 0x0E25;
  11482. t['longs'] = 0x017F;
  11483. t['lowlinecenterline'] = 0xFE4E;
  11484. t['lowlinecmb'] = 0x0332;
  11485. t['lowlinedashed'] = 0xFE4D;
  11486. t['lozenge'] = 0x25CA;
  11487. t['lparen'] = 0x24A7;
  11488. t['lslash'] = 0x0142;
  11489. t['lsquare'] = 0x2113;
  11490. t['lsuperior'] = 0xF6EE;
  11491. t['ltshade'] = 0x2591;
  11492. t['luthai'] = 0x0E26;
  11493. t['lvocalicbengali'] = 0x098C;
  11494. t['lvocalicdeva'] = 0x090C;
  11495. t['lvocalicvowelsignbengali'] = 0x09E2;
  11496. t['lvocalicvowelsigndeva'] = 0x0962;
  11497. t['lxsquare'] = 0x33D3;
  11498. t['m'] = 0x006D;
  11499. t['mabengali'] = 0x09AE;
  11500. t['macron'] = 0x00AF;
  11501. t['macronbelowcmb'] = 0x0331;
  11502. t['macroncmb'] = 0x0304;
  11503. t['macronlowmod'] = 0x02CD;
  11504. t['macronmonospace'] = 0xFFE3;
  11505. t['macute'] = 0x1E3F;
  11506. t['madeva'] = 0x092E;
  11507. t['magujarati'] = 0x0AAE;
  11508. t['magurmukhi'] = 0x0A2E;
  11509. t['mahapakhhebrew'] = 0x05A4;
  11510. t['mahapakhlefthebrew'] = 0x05A4;
  11511. t['mahiragana'] = 0x307E;
  11512. t['maichattawalowleftthai'] = 0xF895;
  11513. t['maichattawalowrightthai'] = 0xF894;
  11514. t['maichattawathai'] = 0x0E4B;
  11515. t['maichattawaupperleftthai'] = 0xF893;
  11516. t['maieklowleftthai'] = 0xF88C;
  11517. t['maieklowrightthai'] = 0xF88B;
  11518. t['maiekthai'] = 0x0E48;
  11519. t['maiekupperleftthai'] = 0xF88A;
  11520. t['maihanakatleftthai'] = 0xF884;
  11521. t['maihanakatthai'] = 0x0E31;
  11522. t['maitaikhuleftthai'] = 0xF889;
  11523. t['maitaikhuthai'] = 0x0E47;
  11524. t['maitholowleftthai'] = 0xF88F;
  11525. t['maitholowrightthai'] = 0xF88E;
  11526. t['maithothai'] = 0x0E49;
  11527. t['maithoupperleftthai'] = 0xF88D;
  11528. t['maitrilowleftthai'] = 0xF892;
  11529. t['maitrilowrightthai'] = 0xF891;
  11530. t['maitrithai'] = 0x0E4A;
  11531. t['maitriupperleftthai'] = 0xF890;
  11532. t['maiyamokthai'] = 0x0E46;
  11533. t['makatakana'] = 0x30DE;
  11534. t['makatakanahalfwidth'] = 0xFF8F;
  11535. t['male'] = 0x2642;
  11536. t['mansyonsquare'] = 0x3347;
  11537. t['maqafhebrew'] = 0x05BE;
  11538. t['mars'] = 0x2642;
  11539. t['masoracirclehebrew'] = 0x05AF;
  11540. t['masquare'] = 0x3383;
  11541. t['mbopomofo'] = 0x3107;
  11542. t['mbsquare'] = 0x33D4;
  11543. t['mcircle'] = 0x24DC;
  11544. t['mcubedsquare'] = 0x33A5;
  11545. t['mdotaccent'] = 0x1E41;
  11546. t['mdotbelow'] = 0x1E43;
  11547. t['meemarabic'] = 0x0645;
  11548. t['meemfinalarabic'] = 0xFEE2;
  11549. t['meeminitialarabic'] = 0xFEE3;
  11550. t['meemmedialarabic'] = 0xFEE4;
  11551. t['meemmeeminitialarabic'] = 0xFCD1;
  11552. t['meemmeemisolatedarabic'] = 0xFC48;
  11553. t['meetorusquare'] = 0x334D;
  11554. t['mehiragana'] = 0x3081;
  11555. t['meizierasquare'] = 0x337E;
  11556. t['mekatakana'] = 0x30E1;
  11557. t['mekatakanahalfwidth'] = 0xFF92;
  11558. t['mem'] = 0x05DE;
  11559. t['memdagesh'] = 0xFB3E;
  11560. t['memdageshhebrew'] = 0xFB3E;
  11561. t['memhebrew'] = 0x05DE;
  11562. t['menarmenian'] = 0x0574;
  11563. t['merkhahebrew'] = 0x05A5;
  11564. t['merkhakefulahebrew'] = 0x05A6;
  11565. t['merkhakefulalefthebrew'] = 0x05A6;
  11566. t['merkhalefthebrew'] = 0x05A5;
  11567. t['mhook'] = 0x0271;
  11568. t['mhzsquare'] = 0x3392;
  11569. t['middledotkatakanahalfwidth'] = 0xFF65;
  11570. t['middot'] = 0x00B7;
  11571. t['mieumacirclekorean'] = 0x3272;
  11572. t['mieumaparenkorean'] = 0x3212;
  11573. t['mieumcirclekorean'] = 0x3264;
  11574. t['mieumkorean'] = 0x3141;
  11575. t['mieumpansioskorean'] = 0x3170;
  11576. t['mieumparenkorean'] = 0x3204;
  11577. t['mieumpieupkorean'] = 0x316E;
  11578. t['mieumsioskorean'] = 0x316F;
  11579. t['mihiragana'] = 0x307F;
  11580. t['mikatakana'] = 0x30DF;
  11581. t['mikatakanahalfwidth'] = 0xFF90;
  11582. t['minus'] = 0x2212;
  11583. t['minusbelowcmb'] = 0x0320;
  11584. t['minuscircle'] = 0x2296;
  11585. t['minusmod'] = 0x02D7;
  11586. t['minusplus'] = 0x2213;
  11587. t['minute'] = 0x2032;
  11588. t['miribaarusquare'] = 0x334A;
  11589. t['mirisquare'] = 0x3349;
  11590. t['mlonglegturned'] = 0x0270;
  11591. t['mlsquare'] = 0x3396;
  11592. t['mmcubedsquare'] = 0x33A3;
  11593. t['mmonospace'] = 0xFF4D;
  11594. t['mmsquaredsquare'] = 0x339F;
  11595. t['mohiragana'] = 0x3082;
  11596. t['mohmsquare'] = 0x33C1;
  11597. t['mokatakana'] = 0x30E2;
  11598. t['mokatakanahalfwidth'] = 0xFF93;
  11599. t['molsquare'] = 0x33D6;
  11600. t['momathai'] = 0x0E21;
  11601. t['moverssquare'] = 0x33A7;
  11602. t['moverssquaredsquare'] = 0x33A8;
  11603. t['mparen'] = 0x24A8;
  11604. t['mpasquare'] = 0x33AB;
  11605. t['mssquare'] = 0x33B3;
  11606. t['msuperior'] = 0xF6EF;
  11607. t['mturned'] = 0x026F;
  11608. t['mu'] = 0x00B5;
  11609. t['mu1'] = 0x00B5;
  11610. t['muasquare'] = 0x3382;
  11611. t['muchgreater'] = 0x226B;
  11612. t['muchless'] = 0x226A;
  11613. t['mufsquare'] = 0x338C;
  11614. t['mugreek'] = 0x03BC;
  11615. t['mugsquare'] = 0x338D;
  11616. t['muhiragana'] = 0x3080;
  11617. t['mukatakana'] = 0x30E0;
  11618. t['mukatakanahalfwidth'] = 0xFF91;
  11619. t['mulsquare'] = 0x3395;
  11620. t['multiply'] = 0x00D7;
  11621. t['mumsquare'] = 0x339B;
  11622. t['munahhebrew'] = 0x05A3;
  11623. t['munahlefthebrew'] = 0x05A3;
  11624. t['musicalnote'] = 0x266A;
  11625. t['musicalnotedbl'] = 0x266B;
  11626. t['musicflatsign'] = 0x266D;
  11627. t['musicsharpsign'] = 0x266F;
  11628. t['mussquare'] = 0x33B2;
  11629. t['muvsquare'] = 0x33B6;
  11630. t['muwsquare'] = 0x33BC;
  11631. t['mvmegasquare'] = 0x33B9;
  11632. t['mvsquare'] = 0x33B7;
  11633. t['mwmegasquare'] = 0x33BF;
  11634. t['mwsquare'] = 0x33BD;
  11635. t['n'] = 0x006E;
  11636. t['nabengali'] = 0x09A8;
  11637. t['nabla'] = 0x2207;
  11638. t['nacute'] = 0x0144;
  11639. t['nadeva'] = 0x0928;
  11640. t['nagujarati'] = 0x0AA8;
  11641. t['nagurmukhi'] = 0x0A28;
  11642. t['nahiragana'] = 0x306A;
  11643. t['nakatakana'] = 0x30CA;
  11644. t['nakatakanahalfwidth'] = 0xFF85;
  11645. t['napostrophe'] = 0x0149;
  11646. t['nasquare'] = 0x3381;
  11647. t['nbopomofo'] = 0x310B;
  11648. t['nbspace'] = 0x00A0;
  11649. t['ncaron'] = 0x0148;
  11650. t['ncedilla'] = 0x0146;
  11651. t['ncircle'] = 0x24DD;
  11652. t['ncircumflexbelow'] = 0x1E4B;
  11653. t['ncommaaccent'] = 0x0146;
  11654. t['ndotaccent'] = 0x1E45;
  11655. t['ndotbelow'] = 0x1E47;
  11656. t['nehiragana'] = 0x306D;
  11657. t['nekatakana'] = 0x30CD;
  11658. t['nekatakanahalfwidth'] = 0xFF88;
  11659. t['newsheqelsign'] = 0x20AA;
  11660. t['nfsquare'] = 0x338B;
  11661. t['ngabengali'] = 0x0999;
  11662. t['ngadeva'] = 0x0919;
  11663. t['ngagujarati'] = 0x0A99;
  11664. t['ngagurmukhi'] = 0x0A19;
  11665. t['ngonguthai'] = 0x0E07;
  11666. t['nhiragana'] = 0x3093;
  11667. t['nhookleft'] = 0x0272;
  11668. t['nhookretroflex'] = 0x0273;
  11669. t['nieunacirclekorean'] = 0x326F;
  11670. t['nieunaparenkorean'] = 0x320F;
  11671. t['nieuncieuckorean'] = 0x3135;
  11672. t['nieuncirclekorean'] = 0x3261;
  11673. t['nieunhieuhkorean'] = 0x3136;
  11674. t['nieunkorean'] = 0x3134;
  11675. t['nieunpansioskorean'] = 0x3168;
  11676. t['nieunparenkorean'] = 0x3201;
  11677. t['nieunsioskorean'] = 0x3167;
  11678. t['nieuntikeutkorean'] = 0x3166;
  11679. t['nihiragana'] = 0x306B;
  11680. t['nikatakana'] = 0x30CB;
  11681. t['nikatakanahalfwidth'] = 0xFF86;
  11682. t['nikhahitleftthai'] = 0xF899;
  11683. t['nikhahitthai'] = 0x0E4D;
  11684. t['nine'] = 0x0039;
  11685. t['ninearabic'] = 0x0669;
  11686. t['ninebengali'] = 0x09EF;
  11687. t['ninecircle'] = 0x2468;
  11688. t['ninecircleinversesansserif'] = 0x2792;
  11689. t['ninedeva'] = 0x096F;
  11690. t['ninegujarati'] = 0x0AEF;
  11691. t['ninegurmukhi'] = 0x0A6F;
  11692. t['ninehackarabic'] = 0x0669;
  11693. t['ninehangzhou'] = 0x3029;
  11694. t['nineideographicparen'] = 0x3228;
  11695. t['nineinferior'] = 0x2089;
  11696. t['ninemonospace'] = 0xFF19;
  11697. t['nineoldstyle'] = 0xF739;
  11698. t['nineparen'] = 0x247C;
  11699. t['nineperiod'] = 0x2490;
  11700. t['ninepersian'] = 0x06F9;
  11701. t['nineroman'] = 0x2178;
  11702. t['ninesuperior'] = 0x2079;
  11703. t['nineteencircle'] = 0x2472;
  11704. t['nineteenparen'] = 0x2486;
  11705. t['nineteenperiod'] = 0x249A;
  11706. t['ninethai'] = 0x0E59;
  11707. t['nj'] = 0x01CC;
  11708. t['njecyrillic'] = 0x045A;
  11709. t['nkatakana'] = 0x30F3;
  11710. t['nkatakanahalfwidth'] = 0xFF9D;
  11711. t['nlegrightlong'] = 0x019E;
  11712. t['nlinebelow'] = 0x1E49;
  11713. t['nmonospace'] = 0xFF4E;
  11714. t['nmsquare'] = 0x339A;
  11715. t['nnabengali'] = 0x09A3;
  11716. t['nnadeva'] = 0x0923;
  11717. t['nnagujarati'] = 0x0AA3;
  11718. t['nnagurmukhi'] = 0x0A23;
  11719. t['nnnadeva'] = 0x0929;
  11720. t['nohiragana'] = 0x306E;
  11721. t['nokatakana'] = 0x30CE;
  11722. t['nokatakanahalfwidth'] = 0xFF89;
  11723. t['nonbreakingspace'] = 0x00A0;
  11724. t['nonenthai'] = 0x0E13;
  11725. t['nonuthai'] = 0x0E19;
  11726. t['noonarabic'] = 0x0646;
  11727. t['noonfinalarabic'] = 0xFEE6;
  11728. t['noonghunnaarabic'] = 0x06BA;
  11729. t['noonghunnafinalarabic'] = 0xFB9F;
  11730. t['nooninitialarabic'] = 0xFEE7;
  11731. t['noonjeeminitialarabic'] = 0xFCD2;
  11732. t['noonjeemisolatedarabic'] = 0xFC4B;
  11733. t['noonmedialarabic'] = 0xFEE8;
  11734. t['noonmeeminitialarabic'] = 0xFCD5;
  11735. t['noonmeemisolatedarabic'] = 0xFC4E;
  11736. t['noonnoonfinalarabic'] = 0xFC8D;
  11737. t['notcontains'] = 0x220C;
  11738. t['notelement'] = 0x2209;
  11739. t['notelementof'] = 0x2209;
  11740. t['notequal'] = 0x2260;
  11741. t['notgreater'] = 0x226F;
  11742. t['notgreaternorequal'] = 0x2271;
  11743. t['notgreaternorless'] = 0x2279;
  11744. t['notidentical'] = 0x2262;
  11745. t['notless'] = 0x226E;
  11746. t['notlessnorequal'] = 0x2270;
  11747. t['notparallel'] = 0x2226;
  11748. t['notprecedes'] = 0x2280;
  11749. t['notsubset'] = 0x2284;
  11750. t['notsucceeds'] = 0x2281;
  11751. t['notsuperset'] = 0x2285;
  11752. t['nowarmenian'] = 0x0576;
  11753. t['nparen'] = 0x24A9;
  11754. t['nssquare'] = 0x33B1;
  11755. t['nsuperior'] = 0x207F;
  11756. t['ntilde'] = 0x00F1;
  11757. t['nu'] = 0x03BD;
  11758. t['nuhiragana'] = 0x306C;
  11759. t['nukatakana'] = 0x30CC;
  11760. t['nukatakanahalfwidth'] = 0xFF87;
  11761. t['nuktabengali'] = 0x09BC;
  11762. t['nuktadeva'] = 0x093C;
  11763. t['nuktagujarati'] = 0x0ABC;
  11764. t['nuktagurmukhi'] = 0x0A3C;
  11765. t['numbersign'] = 0x0023;
  11766. t['numbersignmonospace'] = 0xFF03;
  11767. t['numbersignsmall'] = 0xFE5F;
  11768. t['numeralsigngreek'] = 0x0374;
  11769. t['numeralsignlowergreek'] = 0x0375;
  11770. t['numero'] = 0x2116;
  11771. t['nun'] = 0x05E0;
  11772. t['nundagesh'] = 0xFB40;
  11773. t['nundageshhebrew'] = 0xFB40;
  11774. t['nunhebrew'] = 0x05E0;
  11775. t['nvsquare'] = 0x33B5;
  11776. t['nwsquare'] = 0x33BB;
  11777. t['nyabengali'] = 0x099E;
  11778. t['nyadeva'] = 0x091E;
  11779. t['nyagujarati'] = 0x0A9E;
  11780. t['nyagurmukhi'] = 0x0A1E;
  11781. t['o'] = 0x006F;
  11782. t['oacute'] = 0x00F3;
  11783. t['oangthai'] = 0x0E2D;
  11784. t['obarred'] = 0x0275;
  11785. t['obarredcyrillic'] = 0x04E9;
  11786. t['obarreddieresiscyrillic'] = 0x04EB;
  11787. t['obengali'] = 0x0993;
  11788. t['obopomofo'] = 0x311B;
  11789. t['obreve'] = 0x014F;
  11790. t['ocandradeva'] = 0x0911;
  11791. t['ocandragujarati'] = 0x0A91;
  11792. t['ocandravowelsigndeva'] = 0x0949;
  11793. t['ocandravowelsigngujarati'] = 0x0AC9;
  11794. t['ocaron'] = 0x01D2;
  11795. t['ocircle'] = 0x24DE;
  11796. t['ocircumflex'] = 0x00F4;
  11797. t['ocircumflexacute'] = 0x1ED1;
  11798. t['ocircumflexdotbelow'] = 0x1ED9;
  11799. t['ocircumflexgrave'] = 0x1ED3;
  11800. t['ocircumflexhookabove'] = 0x1ED5;
  11801. t['ocircumflextilde'] = 0x1ED7;
  11802. t['ocyrillic'] = 0x043E;
  11803. t['odblacute'] = 0x0151;
  11804. t['odblgrave'] = 0x020D;
  11805. t['odeva'] = 0x0913;
  11806. t['odieresis'] = 0x00F6;
  11807. t['odieresiscyrillic'] = 0x04E7;
  11808. t['odotbelow'] = 0x1ECD;
  11809. t['oe'] = 0x0153;
  11810. t['oekorean'] = 0x315A;
  11811. t['ogonek'] = 0x02DB;
  11812. t['ogonekcmb'] = 0x0328;
  11813. t['ograve'] = 0x00F2;
  11814. t['ogujarati'] = 0x0A93;
  11815. t['oharmenian'] = 0x0585;
  11816. t['ohiragana'] = 0x304A;
  11817. t['ohookabove'] = 0x1ECF;
  11818. t['ohorn'] = 0x01A1;
  11819. t['ohornacute'] = 0x1EDB;
  11820. t['ohorndotbelow'] = 0x1EE3;
  11821. t['ohorngrave'] = 0x1EDD;
  11822. t['ohornhookabove'] = 0x1EDF;
  11823. t['ohorntilde'] = 0x1EE1;
  11824. t['ohungarumlaut'] = 0x0151;
  11825. t['oi'] = 0x01A3;
  11826. t['oinvertedbreve'] = 0x020F;
  11827. t['okatakana'] = 0x30AA;
  11828. t['okatakanahalfwidth'] = 0xFF75;
  11829. t['okorean'] = 0x3157;
  11830. t['olehebrew'] = 0x05AB;
  11831. t['omacron'] = 0x014D;
  11832. t['omacronacute'] = 0x1E53;
  11833. t['omacrongrave'] = 0x1E51;
  11834. t['omdeva'] = 0x0950;
  11835. t['omega'] = 0x03C9;
  11836. t['omega1'] = 0x03D6;
  11837. t['omegacyrillic'] = 0x0461;
  11838. t['omegalatinclosed'] = 0x0277;
  11839. t['omegaroundcyrillic'] = 0x047B;
  11840. t['omegatitlocyrillic'] = 0x047D;
  11841. t['omegatonos'] = 0x03CE;
  11842. t['omgujarati'] = 0x0AD0;
  11843. t['omicron'] = 0x03BF;
  11844. t['omicrontonos'] = 0x03CC;
  11845. t['omonospace'] = 0xFF4F;
  11846. t['one'] = 0x0031;
  11847. t['onearabic'] = 0x0661;
  11848. t['onebengali'] = 0x09E7;
  11849. t['onecircle'] = 0x2460;
  11850. t['onecircleinversesansserif'] = 0x278A;
  11851. t['onedeva'] = 0x0967;
  11852. t['onedotenleader'] = 0x2024;
  11853. t['oneeighth'] = 0x215B;
  11854. t['onefitted'] = 0xF6DC;
  11855. t['onegujarati'] = 0x0AE7;
  11856. t['onegurmukhi'] = 0x0A67;
  11857. t['onehackarabic'] = 0x0661;
  11858. t['onehalf'] = 0x00BD;
  11859. t['onehangzhou'] = 0x3021;
  11860. t['oneideographicparen'] = 0x3220;
  11861. t['oneinferior'] = 0x2081;
  11862. t['onemonospace'] = 0xFF11;
  11863. t['onenumeratorbengali'] = 0x09F4;
  11864. t['oneoldstyle'] = 0xF731;
  11865. t['oneparen'] = 0x2474;
  11866. t['oneperiod'] = 0x2488;
  11867. t['onepersian'] = 0x06F1;
  11868. t['onequarter'] = 0x00BC;
  11869. t['oneroman'] = 0x2170;
  11870. t['onesuperior'] = 0x00B9;
  11871. t['onethai'] = 0x0E51;
  11872. t['onethird'] = 0x2153;
  11873. t['oogonek'] = 0x01EB;
  11874. t['oogonekmacron'] = 0x01ED;
  11875. t['oogurmukhi'] = 0x0A13;
  11876. t['oomatragurmukhi'] = 0x0A4B;
  11877. t['oopen'] = 0x0254;
  11878. t['oparen'] = 0x24AA;
  11879. t['openbullet'] = 0x25E6;
  11880. t['option'] = 0x2325;
  11881. t['ordfeminine'] = 0x00AA;
  11882. t['ordmasculine'] = 0x00BA;
  11883. t['orthogonal'] = 0x221F;
  11884. t['oshortdeva'] = 0x0912;
  11885. t['oshortvowelsigndeva'] = 0x094A;
  11886. t['oslash'] = 0x00F8;
  11887. t['oslashacute'] = 0x01FF;
  11888. t['osmallhiragana'] = 0x3049;
  11889. t['osmallkatakana'] = 0x30A9;
  11890. t['osmallkatakanahalfwidth'] = 0xFF6B;
  11891. t['ostrokeacute'] = 0x01FF;
  11892. t['osuperior'] = 0xF6F0;
  11893. t['otcyrillic'] = 0x047F;
  11894. t['otilde'] = 0x00F5;
  11895. t['otildeacute'] = 0x1E4D;
  11896. t['otildedieresis'] = 0x1E4F;
  11897. t['oubopomofo'] = 0x3121;
  11898. t['overline'] = 0x203E;
  11899. t['overlinecenterline'] = 0xFE4A;
  11900. t['overlinecmb'] = 0x0305;
  11901. t['overlinedashed'] = 0xFE49;
  11902. t['overlinedblwavy'] = 0xFE4C;
  11903. t['overlinewavy'] = 0xFE4B;
  11904. t['overscore'] = 0x00AF;
  11905. t['ovowelsignbengali'] = 0x09CB;
  11906. t['ovowelsigndeva'] = 0x094B;
  11907. t['ovowelsigngujarati'] = 0x0ACB;
  11908. t['p'] = 0x0070;
  11909. t['paampssquare'] = 0x3380;
  11910. t['paasentosquare'] = 0x332B;
  11911. t['pabengali'] = 0x09AA;
  11912. t['pacute'] = 0x1E55;
  11913. t['padeva'] = 0x092A;
  11914. t['pagedown'] = 0x21DF;
  11915. t['pageup'] = 0x21DE;
  11916. t['pagujarati'] = 0x0AAA;
  11917. t['pagurmukhi'] = 0x0A2A;
  11918. t['pahiragana'] = 0x3071;
  11919. t['paiyannoithai'] = 0x0E2F;
  11920. t['pakatakana'] = 0x30D1;
  11921. t['palatalizationcyrilliccmb'] = 0x0484;
  11922. t['palochkacyrillic'] = 0x04C0;
  11923. t['pansioskorean'] = 0x317F;
  11924. t['paragraph'] = 0x00B6;
  11925. t['parallel'] = 0x2225;
  11926. t['parenleft'] = 0x0028;
  11927. t['parenleftaltonearabic'] = 0xFD3E;
  11928. t['parenleftbt'] = 0xF8ED;
  11929. t['parenleftex'] = 0xF8EC;
  11930. t['parenleftinferior'] = 0x208D;
  11931. t['parenleftmonospace'] = 0xFF08;
  11932. t['parenleftsmall'] = 0xFE59;
  11933. t['parenleftsuperior'] = 0x207D;
  11934. t['parenlefttp'] = 0xF8EB;
  11935. t['parenleftvertical'] = 0xFE35;
  11936. t['parenright'] = 0x0029;
  11937. t['parenrightaltonearabic'] = 0xFD3F;
  11938. t['parenrightbt'] = 0xF8F8;
  11939. t['parenrightex'] = 0xF8F7;
  11940. t['parenrightinferior'] = 0x208E;
  11941. t['parenrightmonospace'] = 0xFF09;
  11942. t['parenrightsmall'] = 0xFE5A;
  11943. t['parenrightsuperior'] = 0x207E;
  11944. t['parenrighttp'] = 0xF8F6;
  11945. t['parenrightvertical'] = 0xFE36;
  11946. t['partialdiff'] = 0x2202;
  11947. t['paseqhebrew'] = 0x05C0;
  11948. t['pashtahebrew'] = 0x0599;
  11949. t['pasquare'] = 0x33A9;
  11950. t['patah'] = 0x05B7;
  11951. t['patah11'] = 0x05B7;
  11952. t['patah1d'] = 0x05B7;
  11953. t['patah2a'] = 0x05B7;
  11954. t['patahhebrew'] = 0x05B7;
  11955. t['patahnarrowhebrew'] = 0x05B7;
  11956. t['patahquarterhebrew'] = 0x05B7;
  11957. t['patahwidehebrew'] = 0x05B7;
  11958. t['pazerhebrew'] = 0x05A1;
  11959. t['pbopomofo'] = 0x3106;
  11960. t['pcircle'] = 0x24DF;
  11961. t['pdotaccent'] = 0x1E57;
  11962. t['pe'] = 0x05E4;
  11963. t['pecyrillic'] = 0x043F;
  11964. t['pedagesh'] = 0xFB44;
  11965. t['pedageshhebrew'] = 0xFB44;
  11966. t['peezisquare'] = 0x333B;
  11967. t['pefinaldageshhebrew'] = 0xFB43;
  11968. t['peharabic'] = 0x067E;
  11969. t['peharmenian'] = 0x057A;
  11970. t['pehebrew'] = 0x05E4;
  11971. t['pehfinalarabic'] = 0xFB57;
  11972. t['pehinitialarabic'] = 0xFB58;
  11973. t['pehiragana'] = 0x307A;
  11974. t['pehmedialarabic'] = 0xFB59;
  11975. t['pekatakana'] = 0x30DA;
  11976. t['pemiddlehookcyrillic'] = 0x04A7;
  11977. t['perafehebrew'] = 0xFB4E;
  11978. t['percent'] = 0x0025;
  11979. t['percentarabic'] = 0x066A;
  11980. t['percentmonospace'] = 0xFF05;
  11981. t['percentsmall'] = 0xFE6A;
  11982. t['period'] = 0x002E;
  11983. t['periodarmenian'] = 0x0589;
  11984. t['periodcentered'] = 0x00B7;
  11985. t['periodhalfwidth'] = 0xFF61;
  11986. t['periodinferior'] = 0xF6E7;
  11987. t['periodmonospace'] = 0xFF0E;
  11988. t['periodsmall'] = 0xFE52;
  11989. t['periodsuperior'] = 0xF6E8;
  11990. t['perispomenigreekcmb'] = 0x0342;
  11991. t['perpendicular'] = 0x22A5;
  11992. t['perthousand'] = 0x2030;
  11993. t['peseta'] = 0x20A7;
  11994. t['pfsquare'] = 0x338A;
  11995. t['phabengali'] = 0x09AB;
  11996. t['phadeva'] = 0x092B;
  11997. t['phagujarati'] = 0x0AAB;
  11998. t['phagurmukhi'] = 0x0A2B;
  11999. t['phi'] = 0x03C6;
  12000. t['phi1'] = 0x03D5;
  12001. t['phieuphacirclekorean'] = 0x327A;
  12002. t['phieuphaparenkorean'] = 0x321A;
  12003. t['phieuphcirclekorean'] = 0x326C;
  12004. t['phieuphkorean'] = 0x314D;
  12005. t['phieuphparenkorean'] = 0x320C;
  12006. t['philatin'] = 0x0278;
  12007. t['phinthuthai'] = 0x0E3A;
  12008. t['phisymbolgreek'] = 0x03D5;
  12009. t['phook'] = 0x01A5;
  12010. t['phophanthai'] = 0x0E1E;
  12011. t['phophungthai'] = 0x0E1C;
  12012. t['phosamphaothai'] = 0x0E20;
  12013. t['pi'] = 0x03C0;
  12014. t['pieupacirclekorean'] = 0x3273;
  12015. t['pieupaparenkorean'] = 0x3213;
  12016. t['pieupcieuckorean'] = 0x3176;
  12017. t['pieupcirclekorean'] = 0x3265;
  12018. t['pieupkiyeokkorean'] = 0x3172;
  12019. t['pieupkorean'] = 0x3142;
  12020. t['pieupparenkorean'] = 0x3205;
  12021. t['pieupsioskiyeokkorean'] = 0x3174;
  12022. t['pieupsioskorean'] = 0x3144;
  12023. t['pieupsiostikeutkorean'] = 0x3175;
  12024. t['pieupthieuthkorean'] = 0x3177;
  12025. t['pieuptikeutkorean'] = 0x3173;
  12026. t['pihiragana'] = 0x3074;
  12027. t['pikatakana'] = 0x30D4;
  12028. t['pisymbolgreek'] = 0x03D6;
  12029. t['piwrarmenian'] = 0x0583;
  12030. t['plus'] = 0x002B;
  12031. t['plusbelowcmb'] = 0x031F;
  12032. t['pluscircle'] = 0x2295;
  12033. t['plusminus'] = 0x00B1;
  12034. t['plusmod'] = 0x02D6;
  12035. t['plusmonospace'] = 0xFF0B;
  12036. t['plussmall'] = 0xFE62;
  12037. t['plussuperior'] = 0x207A;
  12038. t['pmonospace'] = 0xFF50;
  12039. t['pmsquare'] = 0x33D8;
  12040. t['pohiragana'] = 0x307D;
  12041. t['pointingindexdownwhite'] = 0x261F;
  12042. t['pointingindexleftwhite'] = 0x261C;
  12043. t['pointingindexrightwhite'] = 0x261E;
  12044. t['pointingindexupwhite'] = 0x261D;
  12045. t['pokatakana'] = 0x30DD;
  12046. t['poplathai'] = 0x0E1B;
  12047. t['postalmark'] = 0x3012;
  12048. t['postalmarkface'] = 0x3020;
  12049. t['pparen'] = 0x24AB;
  12050. t['precedes'] = 0x227A;
  12051. t['prescription'] = 0x211E;
  12052. t['primemod'] = 0x02B9;
  12053. t['primereversed'] = 0x2035;
  12054. t['product'] = 0x220F;
  12055. t['projective'] = 0x2305;
  12056. t['prolongedkana'] = 0x30FC;
  12057. t['propellor'] = 0x2318;
  12058. t['propersubset'] = 0x2282;
  12059. t['propersuperset'] = 0x2283;
  12060. t['proportion'] = 0x2237;
  12061. t['proportional'] = 0x221D;
  12062. t['psi'] = 0x03C8;
  12063. t['psicyrillic'] = 0x0471;
  12064. t['psilipneumatacyrilliccmb'] = 0x0486;
  12065. t['pssquare'] = 0x33B0;
  12066. t['puhiragana'] = 0x3077;
  12067. t['pukatakana'] = 0x30D7;
  12068. t['pvsquare'] = 0x33B4;
  12069. t['pwsquare'] = 0x33BA;
  12070. t['q'] = 0x0071;
  12071. t['qadeva'] = 0x0958;
  12072. t['qadmahebrew'] = 0x05A8;
  12073. t['qafarabic'] = 0x0642;
  12074. t['qaffinalarabic'] = 0xFED6;
  12075. t['qafinitialarabic'] = 0xFED7;
  12076. t['qafmedialarabic'] = 0xFED8;
  12077. t['qamats'] = 0x05B8;
  12078. t['qamats10'] = 0x05B8;
  12079. t['qamats1a'] = 0x05B8;
  12080. t['qamats1c'] = 0x05B8;
  12081. t['qamats27'] = 0x05B8;
  12082. t['qamats29'] = 0x05B8;
  12083. t['qamats33'] = 0x05B8;
  12084. t['qamatsde'] = 0x05B8;
  12085. t['qamatshebrew'] = 0x05B8;
  12086. t['qamatsnarrowhebrew'] = 0x05B8;
  12087. t['qamatsqatanhebrew'] = 0x05B8;
  12088. t['qamatsqatannarrowhebrew'] = 0x05B8;
  12089. t['qamatsqatanquarterhebrew'] = 0x05B8;
  12090. t['qamatsqatanwidehebrew'] = 0x05B8;
  12091. t['qamatsquarterhebrew'] = 0x05B8;
  12092. t['qamatswidehebrew'] = 0x05B8;
  12093. t['qarneyparahebrew'] = 0x059F;
  12094. t['qbopomofo'] = 0x3111;
  12095. t['qcircle'] = 0x24E0;
  12096. t['qhook'] = 0x02A0;
  12097. t['qmonospace'] = 0xFF51;
  12098. t['qof'] = 0x05E7;
  12099. t['qofdagesh'] = 0xFB47;
  12100. t['qofdageshhebrew'] = 0xFB47;
  12101. t['qofhebrew'] = 0x05E7;
  12102. t['qparen'] = 0x24AC;
  12103. t['quarternote'] = 0x2669;
  12104. t['qubuts'] = 0x05BB;
  12105. t['qubuts18'] = 0x05BB;
  12106. t['qubuts25'] = 0x05BB;
  12107. t['qubuts31'] = 0x05BB;
  12108. t['qubutshebrew'] = 0x05BB;
  12109. t['qubutsnarrowhebrew'] = 0x05BB;
  12110. t['qubutsquarterhebrew'] = 0x05BB;
  12111. t['qubutswidehebrew'] = 0x05BB;
  12112. t['question'] = 0x003F;
  12113. t['questionarabic'] = 0x061F;
  12114. t['questionarmenian'] = 0x055E;
  12115. t['questiondown'] = 0x00BF;
  12116. t['questiondownsmall'] = 0xF7BF;
  12117. t['questiongreek'] = 0x037E;
  12118. t['questionmonospace'] = 0xFF1F;
  12119. t['questionsmall'] = 0xF73F;
  12120. t['quotedbl'] = 0x0022;
  12121. t['quotedblbase'] = 0x201E;
  12122. t['quotedblleft'] = 0x201C;
  12123. t['quotedblmonospace'] = 0xFF02;
  12124. t['quotedblprime'] = 0x301E;
  12125. t['quotedblprimereversed'] = 0x301D;
  12126. t['quotedblright'] = 0x201D;
  12127. t['quoteleft'] = 0x2018;
  12128. t['quoteleftreversed'] = 0x201B;
  12129. t['quotereversed'] = 0x201B;
  12130. t['quoteright'] = 0x2019;
  12131. t['quoterightn'] = 0x0149;
  12132. t['quotesinglbase'] = 0x201A;
  12133. t['quotesingle'] = 0x0027;
  12134. t['quotesinglemonospace'] = 0xFF07;
  12135. t['r'] = 0x0072;
  12136. t['raarmenian'] = 0x057C;
  12137. t['rabengali'] = 0x09B0;
  12138. t['racute'] = 0x0155;
  12139. t['radeva'] = 0x0930;
  12140. t['radical'] = 0x221A;
  12141. t['radicalex'] = 0xF8E5;
  12142. t['radoverssquare'] = 0x33AE;
  12143. t['radoverssquaredsquare'] = 0x33AF;
  12144. t['radsquare'] = 0x33AD;
  12145. t['rafe'] = 0x05BF;
  12146. t['rafehebrew'] = 0x05BF;
  12147. t['ragujarati'] = 0x0AB0;
  12148. t['ragurmukhi'] = 0x0A30;
  12149. t['rahiragana'] = 0x3089;
  12150. t['rakatakana'] = 0x30E9;
  12151. t['rakatakanahalfwidth'] = 0xFF97;
  12152. t['ralowerdiagonalbengali'] = 0x09F1;
  12153. t['ramiddlediagonalbengali'] = 0x09F0;
  12154. t['ramshorn'] = 0x0264;
  12155. t['ratio'] = 0x2236;
  12156. t['rbopomofo'] = 0x3116;
  12157. t['rcaron'] = 0x0159;
  12158. t['rcedilla'] = 0x0157;
  12159. t['rcircle'] = 0x24E1;
  12160. t['rcommaaccent'] = 0x0157;
  12161. t['rdblgrave'] = 0x0211;
  12162. t['rdotaccent'] = 0x1E59;
  12163. t['rdotbelow'] = 0x1E5B;
  12164. t['rdotbelowmacron'] = 0x1E5D;
  12165. t['referencemark'] = 0x203B;
  12166. t['reflexsubset'] = 0x2286;
  12167. t['reflexsuperset'] = 0x2287;
  12168. t['registered'] = 0x00AE;
  12169. t['registersans'] = 0xF8E8;
  12170. t['registerserif'] = 0xF6DA;
  12171. t['reharabic'] = 0x0631;
  12172. t['reharmenian'] = 0x0580;
  12173. t['rehfinalarabic'] = 0xFEAE;
  12174. t['rehiragana'] = 0x308C;
  12175. t['rekatakana'] = 0x30EC;
  12176. t['rekatakanahalfwidth'] = 0xFF9A;
  12177. t['resh'] = 0x05E8;
  12178. t['reshdageshhebrew'] = 0xFB48;
  12179. t['reshhebrew'] = 0x05E8;
  12180. t['reversedtilde'] = 0x223D;
  12181. t['reviahebrew'] = 0x0597;
  12182. t['reviamugrashhebrew'] = 0x0597;
  12183. t['revlogicalnot'] = 0x2310;
  12184. t['rfishhook'] = 0x027E;
  12185. t['rfishhookreversed'] = 0x027F;
  12186. t['rhabengali'] = 0x09DD;
  12187. t['rhadeva'] = 0x095D;
  12188. t['rho'] = 0x03C1;
  12189. t['rhook'] = 0x027D;
  12190. t['rhookturned'] = 0x027B;
  12191. t['rhookturnedsuperior'] = 0x02B5;
  12192. t['rhosymbolgreek'] = 0x03F1;
  12193. t['rhotichookmod'] = 0x02DE;
  12194. t['rieulacirclekorean'] = 0x3271;
  12195. t['rieulaparenkorean'] = 0x3211;
  12196. t['rieulcirclekorean'] = 0x3263;
  12197. t['rieulhieuhkorean'] = 0x3140;
  12198. t['rieulkiyeokkorean'] = 0x313A;
  12199. t['rieulkiyeoksioskorean'] = 0x3169;
  12200. t['rieulkorean'] = 0x3139;
  12201. t['rieulmieumkorean'] = 0x313B;
  12202. t['rieulpansioskorean'] = 0x316C;
  12203. t['rieulparenkorean'] = 0x3203;
  12204. t['rieulphieuphkorean'] = 0x313F;
  12205. t['rieulpieupkorean'] = 0x313C;
  12206. t['rieulpieupsioskorean'] = 0x316B;
  12207. t['rieulsioskorean'] = 0x313D;
  12208. t['rieulthieuthkorean'] = 0x313E;
  12209. t['rieultikeutkorean'] = 0x316A;
  12210. t['rieulyeorinhieuhkorean'] = 0x316D;
  12211. t['rightangle'] = 0x221F;
  12212. t['righttackbelowcmb'] = 0x0319;
  12213. t['righttriangle'] = 0x22BF;
  12214. t['rihiragana'] = 0x308A;
  12215. t['rikatakana'] = 0x30EA;
  12216. t['rikatakanahalfwidth'] = 0xFF98;
  12217. t['ring'] = 0x02DA;
  12218. t['ringbelowcmb'] = 0x0325;
  12219. t['ringcmb'] = 0x030A;
  12220. t['ringhalfleft'] = 0x02BF;
  12221. t['ringhalfleftarmenian'] = 0x0559;
  12222. t['ringhalfleftbelowcmb'] = 0x031C;
  12223. t['ringhalfleftcentered'] = 0x02D3;
  12224. t['ringhalfright'] = 0x02BE;
  12225. t['ringhalfrightbelowcmb'] = 0x0339;
  12226. t['ringhalfrightcentered'] = 0x02D2;
  12227. t['rinvertedbreve'] = 0x0213;
  12228. t['rittorusquare'] = 0x3351;
  12229. t['rlinebelow'] = 0x1E5F;
  12230. t['rlongleg'] = 0x027C;
  12231. t['rlonglegturned'] = 0x027A;
  12232. t['rmonospace'] = 0xFF52;
  12233. t['rohiragana'] = 0x308D;
  12234. t['rokatakana'] = 0x30ED;
  12235. t['rokatakanahalfwidth'] = 0xFF9B;
  12236. t['roruathai'] = 0x0E23;
  12237. t['rparen'] = 0x24AD;
  12238. t['rrabengali'] = 0x09DC;
  12239. t['rradeva'] = 0x0931;
  12240. t['rragurmukhi'] = 0x0A5C;
  12241. t['rreharabic'] = 0x0691;
  12242. t['rrehfinalarabic'] = 0xFB8D;
  12243. t['rrvocalicbengali'] = 0x09E0;
  12244. t['rrvocalicdeva'] = 0x0960;
  12245. t['rrvocalicgujarati'] = 0x0AE0;
  12246. t['rrvocalicvowelsignbengali'] = 0x09C4;
  12247. t['rrvocalicvowelsigndeva'] = 0x0944;
  12248. t['rrvocalicvowelsigngujarati'] = 0x0AC4;
  12249. t['rsuperior'] = 0xF6F1;
  12250. t['rtblock'] = 0x2590;
  12251. t['rturned'] = 0x0279;
  12252. t['rturnedsuperior'] = 0x02B4;
  12253. t['ruhiragana'] = 0x308B;
  12254. t['rukatakana'] = 0x30EB;
  12255. t['rukatakanahalfwidth'] = 0xFF99;
  12256. t['rupeemarkbengali'] = 0x09F2;
  12257. t['rupeesignbengali'] = 0x09F3;
  12258. t['rupiah'] = 0xF6DD;
  12259. t['ruthai'] = 0x0E24;
  12260. t['rvocalicbengali'] = 0x098B;
  12261. t['rvocalicdeva'] = 0x090B;
  12262. t['rvocalicgujarati'] = 0x0A8B;
  12263. t['rvocalicvowelsignbengali'] = 0x09C3;
  12264. t['rvocalicvowelsigndeva'] = 0x0943;
  12265. t['rvocalicvowelsigngujarati'] = 0x0AC3;
  12266. t['s'] = 0x0073;
  12267. t['sabengali'] = 0x09B8;
  12268. t['sacute'] = 0x015B;
  12269. t['sacutedotaccent'] = 0x1E65;
  12270. t['sadarabic'] = 0x0635;
  12271. t['sadeva'] = 0x0938;
  12272. t['sadfinalarabic'] = 0xFEBA;
  12273. t['sadinitialarabic'] = 0xFEBB;
  12274. t['sadmedialarabic'] = 0xFEBC;
  12275. t['sagujarati'] = 0x0AB8;
  12276. t['sagurmukhi'] = 0x0A38;
  12277. t['sahiragana'] = 0x3055;
  12278. t['sakatakana'] = 0x30B5;
  12279. t['sakatakanahalfwidth'] = 0xFF7B;
  12280. t['sallallahoualayhewasallamarabic'] = 0xFDFA;
  12281. t['samekh'] = 0x05E1;
  12282. t['samekhdagesh'] = 0xFB41;
  12283. t['samekhdageshhebrew'] = 0xFB41;
  12284. t['samekhhebrew'] = 0x05E1;
  12285. t['saraaathai'] = 0x0E32;
  12286. t['saraaethai'] = 0x0E41;
  12287. t['saraaimaimalaithai'] = 0x0E44;
  12288. t['saraaimaimuanthai'] = 0x0E43;
  12289. t['saraamthai'] = 0x0E33;
  12290. t['saraathai'] = 0x0E30;
  12291. t['saraethai'] = 0x0E40;
  12292. t['saraiileftthai'] = 0xF886;
  12293. t['saraiithai'] = 0x0E35;
  12294. t['saraileftthai'] = 0xF885;
  12295. t['saraithai'] = 0x0E34;
  12296. t['saraothai'] = 0x0E42;
  12297. t['saraueeleftthai'] = 0xF888;
  12298. t['saraueethai'] = 0x0E37;
  12299. t['saraueleftthai'] = 0xF887;
  12300. t['sarauethai'] = 0x0E36;
  12301. t['sarauthai'] = 0x0E38;
  12302. t['sarauuthai'] = 0x0E39;
  12303. t['sbopomofo'] = 0x3119;
  12304. t['scaron'] = 0x0161;
  12305. t['scarondotaccent'] = 0x1E67;
  12306. t['scedilla'] = 0x015F;
  12307. t['schwa'] = 0x0259;
  12308. t['schwacyrillic'] = 0x04D9;
  12309. t['schwadieresiscyrillic'] = 0x04DB;
  12310. t['schwahook'] = 0x025A;
  12311. t['scircle'] = 0x24E2;
  12312. t['scircumflex'] = 0x015D;
  12313. t['scommaaccent'] = 0x0219;
  12314. t['sdotaccent'] = 0x1E61;
  12315. t['sdotbelow'] = 0x1E63;
  12316. t['sdotbelowdotaccent'] = 0x1E69;
  12317. t['seagullbelowcmb'] = 0x033C;
  12318. t['second'] = 0x2033;
  12319. t['secondtonechinese'] = 0x02CA;
  12320. t['section'] = 0x00A7;
  12321. t['seenarabic'] = 0x0633;
  12322. t['seenfinalarabic'] = 0xFEB2;
  12323. t['seeninitialarabic'] = 0xFEB3;
  12324. t['seenmedialarabic'] = 0xFEB4;
  12325. t['segol'] = 0x05B6;
  12326. t['segol13'] = 0x05B6;
  12327. t['segol1f'] = 0x05B6;
  12328. t['segol2c'] = 0x05B6;
  12329. t['segolhebrew'] = 0x05B6;
  12330. t['segolnarrowhebrew'] = 0x05B6;
  12331. t['segolquarterhebrew'] = 0x05B6;
  12332. t['segoltahebrew'] = 0x0592;
  12333. t['segolwidehebrew'] = 0x05B6;
  12334. t['seharmenian'] = 0x057D;
  12335. t['sehiragana'] = 0x305B;
  12336. t['sekatakana'] = 0x30BB;
  12337. t['sekatakanahalfwidth'] = 0xFF7E;
  12338. t['semicolon'] = 0x003B;
  12339. t['semicolonarabic'] = 0x061B;
  12340. t['semicolonmonospace'] = 0xFF1B;
  12341. t['semicolonsmall'] = 0xFE54;
  12342. t['semivoicedmarkkana'] = 0x309C;
  12343. t['semivoicedmarkkanahalfwidth'] = 0xFF9F;
  12344. t['sentisquare'] = 0x3322;
  12345. t['sentosquare'] = 0x3323;
  12346. t['seven'] = 0x0037;
  12347. t['sevenarabic'] = 0x0667;
  12348. t['sevenbengali'] = 0x09ED;
  12349. t['sevencircle'] = 0x2466;
  12350. t['sevencircleinversesansserif'] = 0x2790;
  12351. t['sevendeva'] = 0x096D;
  12352. t['seveneighths'] = 0x215E;
  12353. t['sevengujarati'] = 0x0AED;
  12354. t['sevengurmukhi'] = 0x0A6D;
  12355. t['sevenhackarabic'] = 0x0667;
  12356. t['sevenhangzhou'] = 0x3027;
  12357. t['sevenideographicparen'] = 0x3226;
  12358. t['seveninferior'] = 0x2087;
  12359. t['sevenmonospace'] = 0xFF17;
  12360. t['sevenoldstyle'] = 0xF737;
  12361. t['sevenparen'] = 0x247A;
  12362. t['sevenperiod'] = 0x248E;
  12363. t['sevenpersian'] = 0x06F7;
  12364. t['sevenroman'] = 0x2176;
  12365. t['sevensuperior'] = 0x2077;
  12366. t['seventeencircle'] = 0x2470;
  12367. t['seventeenparen'] = 0x2484;
  12368. t['seventeenperiod'] = 0x2498;
  12369. t['seventhai'] = 0x0E57;
  12370. t['sfthyphen'] = 0x00AD;
  12371. t['shaarmenian'] = 0x0577;
  12372. t['shabengali'] = 0x09B6;
  12373. t['shacyrillic'] = 0x0448;
  12374. t['shaddaarabic'] = 0x0651;
  12375. t['shaddadammaarabic'] = 0xFC61;
  12376. t['shaddadammatanarabic'] = 0xFC5E;
  12377. t['shaddafathaarabic'] = 0xFC60;
  12378. t['shaddakasraarabic'] = 0xFC62;
  12379. t['shaddakasratanarabic'] = 0xFC5F;
  12380. t['shade'] = 0x2592;
  12381. t['shadedark'] = 0x2593;
  12382. t['shadelight'] = 0x2591;
  12383. t['shademedium'] = 0x2592;
  12384. t['shadeva'] = 0x0936;
  12385. t['shagujarati'] = 0x0AB6;
  12386. t['shagurmukhi'] = 0x0A36;
  12387. t['shalshelethebrew'] = 0x0593;
  12388. t['shbopomofo'] = 0x3115;
  12389. t['shchacyrillic'] = 0x0449;
  12390. t['sheenarabic'] = 0x0634;
  12391. t['sheenfinalarabic'] = 0xFEB6;
  12392. t['sheeninitialarabic'] = 0xFEB7;
  12393. t['sheenmedialarabic'] = 0xFEB8;
  12394. t['sheicoptic'] = 0x03E3;
  12395. t['sheqel'] = 0x20AA;
  12396. t['sheqelhebrew'] = 0x20AA;
  12397. t['sheva'] = 0x05B0;
  12398. t['sheva115'] = 0x05B0;
  12399. t['sheva15'] = 0x05B0;
  12400. t['sheva22'] = 0x05B0;
  12401. t['sheva2e'] = 0x05B0;
  12402. t['shevahebrew'] = 0x05B0;
  12403. t['shevanarrowhebrew'] = 0x05B0;
  12404. t['shevaquarterhebrew'] = 0x05B0;
  12405. t['shevawidehebrew'] = 0x05B0;
  12406. t['shhacyrillic'] = 0x04BB;
  12407. t['shimacoptic'] = 0x03ED;
  12408. t['shin'] = 0x05E9;
  12409. t['shindagesh'] = 0xFB49;
  12410. t['shindageshhebrew'] = 0xFB49;
  12411. t['shindageshshindot'] = 0xFB2C;
  12412. t['shindageshshindothebrew'] = 0xFB2C;
  12413. t['shindageshsindot'] = 0xFB2D;
  12414. t['shindageshsindothebrew'] = 0xFB2D;
  12415. t['shindothebrew'] = 0x05C1;
  12416. t['shinhebrew'] = 0x05E9;
  12417. t['shinshindot'] = 0xFB2A;
  12418. t['shinshindothebrew'] = 0xFB2A;
  12419. t['shinsindot'] = 0xFB2B;
  12420. t['shinsindothebrew'] = 0xFB2B;
  12421. t['shook'] = 0x0282;
  12422. t['sigma'] = 0x03C3;
  12423. t['sigma1'] = 0x03C2;
  12424. t['sigmafinal'] = 0x03C2;
  12425. t['sigmalunatesymbolgreek'] = 0x03F2;
  12426. t['sihiragana'] = 0x3057;
  12427. t['sikatakana'] = 0x30B7;
  12428. t['sikatakanahalfwidth'] = 0xFF7C;
  12429. t['siluqhebrew'] = 0x05BD;
  12430. t['siluqlefthebrew'] = 0x05BD;
  12431. t['similar'] = 0x223C;
  12432. t['sindothebrew'] = 0x05C2;
  12433. t['siosacirclekorean'] = 0x3274;
  12434. t['siosaparenkorean'] = 0x3214;
  12435. t['sioscieuckorean'] = 0x317E;
  12436. t['sioscirclekorean'] = 0x3266;
  12437. t['sioskiyeokkorean'] = 0x317A;
  12438. t['sioskorean'] = 0x3145;
  12439. t['siosnieunkorean'] = 0x317B;
  12440. t['siosparenkorean'] = 0x3206;
  12441. t['siospieupkorean'] = 0x317D;
  12442. t['siostikeutkorean'] = 0x317C;
  12443. t['six'] = 0x0036;
  12444. t['sixarabic'] = 0x0666;
  12445. t['sixbengali'] = 0x09EC;
  12446. t['sixcircle'] = 0x2465;
  12447. t['sixcircleinversesansserif'] = 0x278F;
  12448. t['sixdeva'] = 0x096C;
  12449. t['sixgujarati'] = 0x0AEC;
  12450. t['sixgurmukhi'] = 0x0A6C;
  12451. t['sixhackarabic'] = 0x0666;
  12452. t['sixhangzhou'] = 0x3026;
  12453. t['sixideographicparen'] = 0x3225;
  12454. t['sixinferior'] = 0x2086;
  12455. t['sixmonospace'] = 0xFF16;
  12456. t['sixoldstyle'] = 0xF736;
  12457. t['sixparen'] = 0x2479;
  12458. t['sixperiod'] = 0x248D;
  12459. t['sixpersian'] = 0x06F6;
  12460. t['sixroman'] = 0x2175;
  12461. t['sixsuperior'] = 0x2076;
  12462. t['sixteencircle'] = 0x246F;
  12463. t['sixteencurrencydenominatorbengali'] = 0x09F9;
  12464. t['sixteenparen'] = 0x2483;
  12465. t['sixteenperiod'] = 0x2497;
  12466. t['sixthai'] = 0x0E56;
  12467. t['slash'] = 0x002F;
  12468. t['slashmonospace'] = 0xFF0F;
  12469. t['slong'] = 0x017F;
  12470. t['slongdotaccent'] = 0x1E9B;
  12471. t['smileface'] = 0x263A;
  12472. t['smonospace'] = 0xFF53;
  12473. t['sofpasuqhebrew'] = 0x05C3;
  12474. t['softhyphen'] = 0x00AD;
  12475. t['softsigncyrillic'] = 0x044C;
  12476. t['sohiragana'] = 0x305D;
  12477. t['sokatakana'] = 0x30BD;
  12478. t['sokatakanahalfwidth'] = 0xFF7F;
  12479. t['soliduslongoverlaycmb'] = 0x0338;
  12480. t['solidusshortoverlaycmb'] = 0x0337;
  12481. t['sorusithai'] = 0x0E29;
  12482. t['sosalathai'] = 0x0E28;
  12483. t['sosothai'] = 0x0E0B;
  12484. t['sosuathai'] = 0x0E2A;
  12485. t['space'] = 0x0020;
  12486. t['spacehackarabic'] = 0x0020;
  12487. t['spade'] = 0x2660;
  12488. t['spadesuitblack'] = 0x2660;
  12489. t['spadesuitwhite'] = 0x2664;
  12490. t['sparen'] = 0x24AE;
  12491. t['squarebelowcmb'] = 0x033B;
  12492. t['squarecc'] = 0x33C4;
  12493. t['squarecm'] = 0x339D;
  12494. t['squarediagonalcrosshatchfill'] = 0x25A9;
  12495. t['squarehorizontalfill'] = 0x25A4;
  12496. t['squarekg'] = 0x338F;
  12497. t['squarekm'] = 0x339E;
  12498. t['squarekmcapital'] = 0x33CE;
  12499. t['squareln'] = 0x33D1;
  12500. t['squarelog'] = 0x33D2;
  12501. t['squaremg'] = 0x338E;
  12502. t['squaremil'] = 0x33D5;
  12503. t['squaremm'] = 0x339C;
  12504. t['squaremsquared'] = 0x33A1;
  12505. t['squareorthogonalcrosshatchfill'] = 0x25A6;
  12506. t['squareupperlefttolowerrightfill'] = 0x25A7;
  12507. t['squareupperrighttolowerleftfill'] = 0x25A8;
  12508. t['squareverticalfill'] = 0x25A5;
  12509. t['squarewhitewithsmallblack'] = 0x25A3;
  12510. t['srsquare'] = 0x33DB;
  12511. t['ssabengali'] = 0x09B7;
  12512. t['ssadeva'] = 0x0937;
  12513. t['ssagujarati'] = 0x0AB7;
  12514. t['ssangcieuckorean'] = 0x3149;
  12515. t['ssanghieuhkorean'] = 0x3185;
  12516. t['ssangieungkorean'] = 0x3180;
  12517. t['ssangkiyeokkorean'] = 0x3132;
  12518. t['ssangnieunkorean'] = 0x3165;
  12519. t['ssangpieupkorean'] = 0x3143;
  12520. t['ssangsioskorean'] = 0x3146;
  12521. t['ssangtikeutkorean'] = 0x3138;
  12522. t['ssuperior'] = 0xF6F2;
  12523. t['sterling'] = 0x00A3;
  12524. t['sterlingmonospace'] = 0xFFE1;
  12525. t['strokelongoverlaycmb'] = 0x0336;
  12526. t['strokeshortoverlaycmb'] = 0x0335;
  12527. t['subset'] = 0x2282;
  12528. t['subsetnotequal'] = 0x228A;
  12529. t['subsetorequal'] = 0x2286;
  12530. t['succeeds'] = 0x227B;
  12531. t['suchthat'] = 0x220B;
  12532. t['suhiragana'] = 0x3059;
  12533. t['sukatakana'] = 0x30B9;
  12534. t['sukatakanahalfwidth'] = 0xFF7D;
  12535. t['sukunarabic'] = 0x0652;
  12536. t['summation'] = 0x2211;
  12537. t['sun'] = 0x263C;
  12538. t['superset'] = 0x2283;
  12539. t['supersetnotequal'] = 0x228B;
  12540. t['supersetorequal'] = 0x2287;
  12541. t['svsquare'] = 0x33DC;
  12542. t['syouwaerasquare'] = 0x337C;
  12543. t['t'] = 0x0074;
  12544. t['tabengali'] = 0x09A4;
  12545. t['tackdown'] = 0x22A4;
  12546. t['tackleft'] = 0x22A3;
  12547. t['tadeva'] = 0x0924;
  12548. t['tagujarati'] = 0x0AA4;
  12549. t['tagurmukhi'] = 0x0A24;
  12550. t['taharabic'] = 0x0637;
  12551. t['tahfinalarabic'] = 0xFEC2;
  12552. t['tahinitialarabic'] = 0xFEC3;
  12553. t['tahiragana'] = 0x305F;
  12554. t['tahmedialarabic'] = 0xFEC4;
  12555. t['taisyouerasquare'] = 0x337D;
  12556. t['takatakana'] = 0x30BF;
  12557. t['takatakanahalfwidth'] = 0xFF80;
  12558. t['tatweelarabic'] = 0x0640;
  12559. t['tau'] = 0x03C4;
  12560. t['tav'] = 0x05EA;
  12561. t['tavdages'] = 0xFB4A;
  12562. t['tavdagesh'] = 0xFB4A;
  12563. t['tavdageshhebrew'] = 0xFB4A;
  12564. t['tavhebrew'] = 0x05EA;
  12565. t['tbar'] = 0x0167;
  12566. t['tbopomofo'] = 0x310A;
  12567. t['tcaron'] = 0x0165;
  12568. t['tccurl'] = 0x02A8;
  12569. t['tcedilla'] = 0x0163;
  12570. t['tcheharabic'] = 0x0686;
  12571. t['tchehfinalarabic'] = 0xFB7B;
  12572. t['tchehinitialarabic'] = 0xFB7C;
  12573. t['tchehmedialarabic'] = 0xFB7D;
  12574. t['tcircle'] = 0x24E3;
  12575. t['tcircumflexbelow'] = 0x1E71;
  12576. t['tcommaaccent'] = 0x0163;
  12577. t['tdieresis'] = 0x1E97;
  12578. t['tdotaccent'] = 0x1E6B;
  12579. t['tdotbelow'] = 0x1E6D;
  12580. t['tecyrillic'] = 0x0442;
  12581. t['tedescendercyrillic'] = 0x04AD;
  12582. t['teharabic'] = 0x062A;
  12583. t['tehfinalarabic'] = 0xFE96;
  12584. t['tehhahinitialarabic'] = 0xFCA2;
  12585. t['tehhahisolatedarabic'] = 0xFC0C;
  12586. t['tehinitialarabic'] = 0xFE97;
  12587. t['tehiragana'] = 0x3066;
  12588. t['tehjeeminitialarabic'] = 0xFCA1;
  12589. t['tehjeemisolatedarabic'] = 0xFC0B;
  12590. t['tehmarbutaarabic'] = 0x0629;
  12591. t['tehmarbutafinalarabic'] = 0xFE94;
  12592. t['tehmedialarabic'] = 0xFE98;
  12593. t['tehmeeminitialarabic'] = 0xFCA4;
  12594. t['tehmeemisolatedarabic'] = 0xFC0E;
  12595. t['tehnoonfinalarabic'] = 0xFC73;
  12596. t['tekatakana'] = 0x30C6;
  12597. t['tekatakanahalfwidth'] = 0xFF83;
  12598. t['telephone'] = 0x2121;
  12599. t['telephoneblack'] = 0x260E;
  12600. t['telishagedolahebrew'] = 0x05A0;
  12601. t['telishaqetanahebrew'] = 0x05A9;
  12602. t['tencircle'] = 0x2469;
  12603. t['tenideographicparen'] = 0x3229;
  12604. t['tenparen'] = 0x247D;
  12605. t['tenperiod'] = 0x2491;
  12606. t['tenroman'] = 0x2179;
  12607. t['tesh'] = 0x02A7;
  12608. t['tet'] = 0x05D8;
  12609. t['tetdagesh'] = 0xFB38;
  12610. t['tetdageshhebrew'] = 0xFB38;
  12611. t['tethebrew'] = 0x05D8;
  12612. t['tetsecyrillic'] = 0x04B5;
  12613. t['tevirhebrew'] = 0x059B;
  12614. t['tevirlefthebrew'] = 0x059B;
  12615. t['thabengali'] = 0x09A5;
  12616. t['thadeva'] = 0x0925;
  12617. t['thagujarati'] = 0x0AA5;
  12618. t['thagurmukhi'] = 0x0A25;
  12619. t['thalarabic'] = 0x0630;
  12620. t['thalfinalarabic'] = 0xFEAC;
  12621. t['thanthakhatlowleftthai'] = 0xF898;
  12622. t['thanthakhatlowrightthai'] = 0xF897;
  12623. t['thanthakhatthai'] = 0x0E4C;
  12624. t['thanthakhatupperleftthai'] = 0xF896;
  12625. t['theharabic'] = 0x062B;
  12626. t['thehfinalarabic'] = 0xFE9A;
  12627. t['thehinitialarabic'] = 0xFE9B;
  12628. t['thehmedialarabic'] = 0xFE9C;
  12629. t['thereexists'] = 0x2203;
  12630. t['therefore'] = 0x2234;
  12631. t['theta'] = 0x03B8;
  12632. t['theta1'] = 0x03D1;
  12633. t['thetasymbolgreek'] = 0x03D1;
  12634. t['thieuthacirclekorean'] = 0x3279;
  12635. t['thieuthaparenkorean'] = 0x3219;
  12636. t['thieuthcirclekorean'] = 0x326B;
  12637. t['thieuthkorean'] = 0x314C;
  12638. t['thieuthparenkorean'] = 0x320B;
  12639. t['thirteencircle'] = 0x246C;
  12640. t['thirteenparen'] = 0x2480;
  12641. t['thirteenperiod'] = 0x2494;
  12642. t['thonangmonthothai'] = 0x0E11;
  12643. t['thook'] = 0x01AD;
  12644. t['thophuthaothai'] = 0x0E12;
  12645. t['thorn'] = 0x00FE;
  12646. t['thothahanthai'] = 0x0E17;
  12647. t['thothanthai'] = 0x0E10;
  12648. t['thothongthai'] = 0x0E18;
  12649. t['thothungthai'] = 0x0E16;
  12650. t['thousandcyrillic'] = 0x0482;
  12651. t['thousandsseparatorarabic'] = 0x066C;
  12652. t['thousandsseparatorpersian'] = 0x066C;
  12653. t['three'] = 0x0033;
  12654. t['threearabic'] = 0x0663;
  12655. t['threebengali'] = 0x09E9;
  12656. t['threecircle'] = 0x2462;
  12657. t['threecircleinversesansserif'] = 0x278C;
  12658. t['threedeva'] = 0x0969;
  12659. t['threeeighths'] = 0x215C;
  12660. t['threegujarati'] = 0x0AE9;
  12661. t['threegurmukhi'] = 0x0A69;
  12662. t['threehackarabic'] = 0x0663;
  12663. t['threehangzhou'] = 0x3023;
  12664. t['threeideographicparen'] = 0x3222;
  12665. t['threeinferior'] = 0x2083;
  12666. t['threemonospace'] = 0xFF13;
  12667. t['threenumeratorbengali'] = 0x09F6;
  12668. t['threeoldstyle'] = 0xF733;
  12669. t['threeparen'] = 0x2476;
  12670. t['threeperiod'] = 0x248A;
  12671. t['threepersian'] = 0x06F3;
  12672. t['threequarters'] = 0x00BE;
  12673. t['threequartersemdash'] = 0xF6DE;
  12674. t['threeroman'] = 0x2172;
  12675. t['threesuperior'] = 0x00B3;
  12676. t['threethai'] = 0x0E53;
  12677. t['thzsquare'] = 0x3394;
  12678. t['tihiragana'] = 0x3061;
  12679. t['tikatakana'] = 0x30C1;
  12680. t['tikatakanahalfwidth'] = 0xFF81;
  12681. t['tikeutacirclekorean'] = 0x3270;
  12682. t['tikeutaparenkorean'] = 0x3210;
  12683. t['tikeutcirclekorean'] = 0x3262;
  12684. t['tikeutkorean'] = 0x3137;
  12685. t['tikeutparenkorean'] = 0x3202;
  12686. t['tilde'] = 0x02DC;
  12687. t['tildebelowcmb'] = 0x0330;
  12688. t['tildecmb'] = 0x0303;
  12689. t['tildecomb'] = 0x0303;
  12690. t['tildedoublecmb'] = 0x0360;
  12691. t['tildeoperator'] = 0x223C;
  12692. t['tildeoverlaycmb'] = 0x0334;
  12693. t['tildeverticalcmb'] = 0x033E;
  12694. t['timescircle'] = 0x2297;
  12695. t['tipehahebrew'] = 0x0596;
  12696. t['tipehalefthebrew'] = 0x0596;
  12697. t['tippigurmukhi'] = 0x0A70;
  12698. t['titlocyrilliccmb'] = 0x0483;
  12699. t['tiwnarmenian'] = 0x057F;
  12700. t['tlinebelow'] = 0x1E6F;
  12701. t['tmonospace'] = 0xFF54;
  12702. t['toarmenian'] = 0x0569;
  12703. t['tohiragana'] = 0x3068;
  12704. t['tokatakana'] = 0x30C8;
  12705. t['tokatakanahalfwidth'] = 0xFF84;
  12706. t['tonebarextrahighmod'] = 0x02E5;
  12707. t['tonebarextralowmod'] = 0x02E9;
  12708. t['tonebarhighmod'] = 0x02E6;
  12709. t['tonebarlowmod'] = 0x02E8;
  12710. t['tonebarmidmod'] = 0x02E7;
  12711. t['tonefive'] = 0x01BD;
  12712. t['tonesix'] = 0x0185;
  12713. t['tonetwo'] = 0x01A8;
  12714. t['tonos'] = 0x0384;
  12715. t['tonsquare'] = 0x3327;
  12716. t['topatakthai'] = 0x0E0F;
  12717. t['tortoiseshellbracketleft'] = 0x3014;
  12718. t['tortoiseshellbracketleftsmall'] = 0xFE5D;
  12719. t['tortoiseshellbracketleftvertical'] = 0xFE39;
  12720. t['tortoiseshellbracketright'] = 0x3015;
  12721. t['tortoiseshellbracketrightsmall'] = 0xFE5E;
  12722. t['tortoiseshellbracketrightvertical'] = 0xFE3A;
  12723. t['totaothai'] = 0x0E15;
  12724. t['tpalatalhook'] = 0x01AB;
  12725. t['tparen'] = 0x24AF;
  12726. t['trademark'] = 0x2122;
  12727. t['trademarksans'] = 0xF8EA;
  12728. t['trademarkserif'] = 0xF6DB;
  12729. t['tretroflexhook'] = 0x0288;
  12730. t['triagdn'] = 0x25BC;
  12731. t['triaglf'] = 0x25C4;
  12732. t['triagrt'] = 0x25BA;
  12733. t['triagup'] = 0x25B2;
  12734. t['ts'] = 0x02A6;
  12735. t['tsadi'] = 0x05E6;
  12736. t['tsadidagesh'] = 0xFB46;
  12737. t['tsadidageshhebrew'] = 0xFB46;
  12738. t['tsadihebrew'] = 0x05E6;
  12739. t['tsecyrillic'] = 0x0446;
  12740. t['tsere'] = 0x05B5;
  12741. t['tsere12'] = 0x05B5;
  12742. t['tsere1e'] = 0x05B5;
  12743. t['tsere2b'] = 0x05B5;
  12744. t['tserehebrew'] = 0x05B5;
  12745. t['tserenarrowhebrew'] = 0x05B5;
  12746. t['tserequarterhebrew'] = 0x05B5;
  12747. t['tserewidehebrew'] = 0x05B5;
  12748. t['tshecyrillic'] = 0x045B;
  12749. t['tsuperior'] = 0xF6F3;
  12750. t['ttabengali'] = 0x099F;
  12751. t['ttadeva'] = 0x091F;
  12752. t['ttagujarati'] = 0x0A9F;
  12753. t['ttagurmukhi'] = 0x0A1F;
  12754. t['tteharabic'] = 0x0679;
  12755. t['ttehfinalarabic'] = 0xFB67;
  12756. t['ttehinitialarabic'] = 0xFB68;
  12757. t['ttehmedialarabic'] = 0xFB69;
  12758. t['tthabengali'] = 0x09A0;
  12759. t['tthadeva'] = 0x0920;
  12760. t['tthagujarati'] = 0x0AA0;
  12761. t['tthagurmukhi'] = 0x0A20;
  12762. t['tturned'] = 0x0287;
  12763. t['tuhiragana'] = 0x3064;
  12764. t['tukatakana'] = 0x30C4;
  12765. t['tukatakanahalfwidth'] = 0xFF82;
  12766. t['tusmallhiragana'] = 0x3063;
  12767. t['tusmallkatakana'] = 0x30C3;
  12768. t['tusmallkatakanahalfwidth'] = 0xFF6F;
  12769. t['twelvecircle'] = 0x246B;
  12770. t['twelveparen'] = 0x247F;
  12771. t['twelveperiod'] = 0x2493;
  12772. t['twelveroman'] = 0x217B;
  12773. t['twentycircle'] = 0x2473;
  12774. t['twentyhangzhou'] = 0x5344;
  12775. t['twentyparen'] = 0x2487;
  12776. t['twentyperiod'] = 0x249B;
  12777. t['two'] = 0x0032;
  12778. t['twoarabic'] = 0x0662;
  12779. t['twobengali'] = 0x09E8;
  12780. t['twocircle'] = 0x2461;
  12781. t['twocircleinversesansserif'] = 0x278B;
  12782. t['twodeva'] = 0x0968;
  12783. t['twodotenleader'] = 0x2025;
  12784. t['twodotleader'] = 0x2025;
  12785. t['twodotleadervertical'] = 0xFE30;
  12786. t['twogujarati'] = 0x0AE8;
  12787. t['twogurmukhi'] = 0x0A68;
  12788. t['twohackarabic'] = 0x0662;
  12789. t['twohangzhou'] = 0x3022;
  12790. t['twoideographicparen'] = 0x3221;
  12791. t['twoinferior'] = 0x2082;
  12792. t['twomonospace'] = 0xFF12;
  12793. t['twonumeratorbengali'] = 0x09F5;
  12794. t['twooldstyle'] = 0xF732;
  12795. t['twoparen'] = 0x2475;
  12796. t['twoperiod'] = 0x2489;
  12797. t['twopersian'] = 0x06F2;
  12798. t['tworoman'] = 0x2171;
  12799. t['twostroke'] = 0x01BB;
  12800. t['twosuperior'] = 0x00B2;
  12801. t['twothai'] = 0x0E52;
  12802. t['twothirds'] = 0x2154;
  12803. t['u'] = 0x0075;
  12804. t['uacute'] = 0x00FA;
  12805. t['ubar'] = 0x0289;
  12806. t['ubengali'] = 0x0989;
  12807. t['ubopomofo'] = 0x3128;
  12808. t['ubreve'] = 0x016D;
  12809. t['ucaron'] = 0x01D4;
  12810. t['ucircle'] = 0x24E4;
  12811. t['ucircumflex'] = 0x00FB;
  12812. t['ucircumflexbelow'] = 0x1E77;
  12813. t['ucyrillic'] = 0x0443;
  12814. t['udattadeva'] = 0x0951;
  12815. t['udblacute'] = 0x0171;
  12816. t['udblgrave'] = 0x0215;
  12817. t['udeva'] = 0x0909;
  12818. t['udieresis'] = 0x00FC;
  12819. t['udieresisacute'] = 0x01D8;
  12820. t['udieresisbelow'] = 0x1E73;
  12821. t['udieresiscaron'] = 0x01DA;
  12822. t['udieresiscyrillic'] = 0x04F1;
  12823. t['udieresisgrave'] = 0x01DC;
  12824. t['udieresismacron'] = 0x01D6;
  12825. t['udotbelow'] = 0x1EE5;
  12826. t['ugrave'] = 0x00F9;
  12827. t['ugujarati'] = 0x0A89;
  12828. t['ugurmukhi'] = 0x0A09;
  12829. t['uhiragana'] = 0x3046;
  12830. t['uhookabove'] = 0x1EE7;
  12831. t['uhorn'] = 0x01B0;
  12832. t['uhornacute'] = 0x1EE9;
  12833. t['uhorndotbelow'] = 0x1EF1;
  12834. t['uhorngrave'] = 0x1EEB;
  12835. t['uhornhookabove'] = 0x1EED;
  12836. t['uhorntilde'] = 0x1EEF;
  12837. t['uhungarumlaut'] = 0x0171;
  12838. t['uhungarumlautcyrillic'] = 0x04F3;
  12839. t['uinvertedbreve'] = 0x0217;
  12840. t['ukatakana'] = 0x30A6;
  12841. t['ukatakanahalfwidth'] = 0xFF73;
  12842. t['ukcyrillic'] = 0x0479;
  12843. t['ukorean'] = 0x315C;
  12844. t['umacron'] = 0x016B;
  12845. t['umacroncyrillic'] = 0x04EF;
  12846. t['umacrondieresis'] = 0x1E7B;
  12847. t['umatragurmukhi'] = 0x0A41;
  12848. t['umonospace'] = 0xFF55;
  12849. t['underscore'] = 0x005F;
  12850. t['underscoredbl'] = 0x2017;
  12851. t['underscoremonospace'] = 0xFF3F;
  12852. t['underscorevertical'] = 0xFE33;
  12853. t['underscorewavy'] = 0xFE4F;
  12854. t['union'] = 0x222A;
  12855. t['universal'] = 0x2200;
  12856. t['uogonek'] = 0x0173;
  12857. t['uparen'] = 0x24B0;
  12858. t['upblock'] = 0x2580;
  12859. t['upperdothebrew'] = 0x05C4;
  12860. t['upsilon'] = 0x03C5;
  12861. t['upsilondieresis'] = 0x03CB;
  12862. t['upsilondieresistonos'] = 0x03B0;
  12863. t['upsilonlatin'] = 0x028A;
  12864. t['upsilontonos'] = 0x03CD;
  12865. t['uptackbelowcmb'] = 0x031D;
  12866. t['uptackmod'] = 0x02D4;
  12867. t['uragurmukhi'] = 0x0A73;
  12868. t['uring'] = 0x016F;
  12869. t['ushortcyrillic'] = 0x045E;
  12870. t['usmallhiragana'] = 0x3045;
  12871. t['usmallkatakana'] = 0x30A5;
  12872. t['usmallkatakanahalfwidth'] = 0xFF69;
  12873. t['ustraightcyrillic'] = 0x04AF;
  12874. t['ustraightstrokecyrillic'] = 0x04B1;
  12875. t['utilde'] = 0x0169;
  12876. t['utildeacute'] = 0x1E79;
  12877. t['utildebelow'] = 0x1E75;
  12878. t['uubengali'] = 0x098A;
  12879. t['uudeva'] = 0x090A;
  12880. t['uugujarati'] = 0x0A8A;
  12881. t['uugurmukhi'] = 0x0A0A;
  12882. t['uumatragurmukhi'] = 0x0A42;
  12883. t['uuvowelsignbengali'] = 0x09C2;
  12884. t['uuvowelsigndeva'] = 0x0942;
  12885. t['uuvowelsigngujarati'] = 0x0AC2;
  12886. t['uvowelsignbengali'] = 0x09C1;
  12887. t['uvowelsigndeva'] = 0x0941;
  12888. t['uvowelsigngujarati'] = 0x0AC1;
  12889. t['v'] = 0x0076;
  12890. t['vadeva'] = 0x0935;
  12891. t['vagujarati'] = 0x0AB5;
  12892. t['vagurmukhi'] = 0x0A35;
  12893. t['vakatakana'] = 0x30F7;
  12894. t['vav'] = 0x05D5;
  12895. t['vavdagesh'] = 0xFB35;
  12896. t['vavdagesh65'] = 0xFB35;
  12897. t['vavdageshhebrew'] = 0xFB35;
  12898. t['vavhebrew'] = 0x05D5;
  12899. t['vavholam'] = 0xFB4B;
  12900. t['vavholamhebrew'] = 0xFB4B;
  12901. t['vavvavhebrew'] = 0x05F0;
  12902. t['vavyodhebrew'] = 0x05F1;
  12903. t['vcircle'] = 0x24E5;
  12904. t['vdotbelow'] = 0x1E7F;
  12905. t['vecyrillic'] = 0x0432;
  12906. t['veharabic'] = 0x06A4;
  12907. t['vehfinalarabic'] = 0xFB6B;
  12908. t['vehinitialarabic'] = 0xFB6C;
  12909. t['vehmedialarabic'] = 0xFB6D;
  12910. t['vekatakana'] = 0x30F9;
  12911. t['venus'] = 0x2640;
  12912. t['verticalbar'] = 0x007C;
  12913. t['verticallineabovecmb'] = 0x030D;
  12914. t['verticallinebelowcmb'] = 0x0329;
  12915. t['verticallinelowmod'] = 0x02CC;
  12916. t['verticallinemod'] = 0x02C8;
  12917. t['vewarmenian'] = 0x057E;
  12918. t['vhook'] = 0x028B;
  12919. t['vikatakana'] = 0x30F8;
  12920. t['viramabengali'] = 0x09CD;
  12921. t['viramadeva'] = 0x094D;
  12922. t['viramagujarati'] = 0x0ACD;
  12923. t['visargabengali'] = 0x0983;
  12924. t['visargadeva'] = 0x0903;
  12925. t['visargagujarati'] = 0x0A83;
  12926. t['vmonospace'] = 0xFF56;
  12927. t['voarmenian'] = 0x0578;
  12928. t['voicediterationhiragana'] = 0x309E;
  12929. t['voicediterationkatakana'] = 0x30FE;
  12930. t['voicedmarkkana'] = 0x309B;
  12931. t['voicedmarkkanahalfwidth'] = 0xFF9E;
  12932. t['vokatakana'] = 0x30FA;
  12933. t['vparen'] = 0x24B1;
  12934. t['vtilde'] = 0x1E7D;
  12935. t['vturned'] = 0x028C;
  12936. t['vuhiragana'] = 0x3094;
  12937. t['vukatakana'] = 0x30F4;
  12938. t['w'] = 0x0077;
  12939. t['wacute'] = 0x1E83;
  12940. t['waekorean'] = 0x3159;
  12941. t['wahiragana'] = 0x308F;
  12942. t['wakatakana'] = 0x30EF;
  12943. t['wakatakanahalfwidth'] = 0xFF9C;
  12944. t['wakorean'] = 0x3158;
  12945. t['wasmallhiragana'] = 0x308E;
  12946. t['wasmallkatakana'] = 0x30EE;
  12947. t['wattosquare'] = 0x3357;
  12948. t['wavedash'] = 0x301C;
  12949. t['wavyunderscorevertical'] = 0xFE34;
  12950. t['wawarabic'] = 0x0648;
  12951. t['wawfinalarabic'] = 0xFEEE;
  12952. t['wawhamzaabovearabic'] = 0x0624;
  12953. t['wawhamzaabovefinalarabic'] = 0xFE86;
  12954. t['wbsquare'] = 0x33DD;
  12955. t['wcircle'] = 0x24E6;
  12956. t['wcircumflex'] = 0x0175;
  12957. t['wdieresis'] = 0x1E85;
  12958. t['wdotaccent'] = 0x1E87;
  12959. t['wdotbelow'] = 0x1E89;
  12960. t['wehiragana'] = 0x3091;
  12961. t['weierstrass'] = 0x2118;
  12962. t['wekatakana'] = 0x30F1;
  12963. t['wekorean'] = 0x315E;
  12964. t['weokorean'] = 0x315D;
  12965. t['wgrave'] = 0x1E81;
  12966. t['whitebullet'] = 0x25E6;
  12967. t['whitecircle'] = 0x25CB;
  12968. t['whitecircleinverse'] = 0x25D9;
  12969. t['whitecornerbracketleft'] = 0x300E;
  12970. t['whitecornerbracketleftvertical'] = 0xFE43;
  12971. t['whitecornerbracketright'] = 0x300F;
  12972. t['whitecornerbracketrightvertical'] = 0xFE44;
  12973. t['whitediamond'] = 0x25C7;
  12974. t['whitediamondcontainingblacksmalldiamond'] = 0x25C8;
  12975. t['whitedownpointingsmalltriangle'] = 0x25BF;
  12976. t['whitedownpointingtriangle'] = 0x25BD;
  12977. t['whiteleftpointingsmalltriangle'] = 0x25C3;
  12978. t['whiteleftpointingtriangle'] = 0x25C1;
  12979. t['whitelenticularbracketleft'] = 0x3016;
  12980. t['whitelenticularbracketright'] = 0x3017;
  12981. t['whiterightpointingsmalltriangle'] = 0x25B9;
  12982. t['whiterightpointingtriangle'] = 0x25B7;
  12983. t['whitesmallsquare'] = 0x25AB;
  12984. t['whitesmilingface'] = 0x263A;
  12985. t['whitesquare'] = 0x25A1;
  12986. t['whitestar'] = 0x2606;
  12987. t['whitetelephone'] = 0x260F;
  12988. t['whitetortoiseshellbracketleft'] = 0x3018;
  12989. t['whitetortoiseshellbracketright'] = 0x3019;
  12990. t['whiteuppointingsmalltriangle'] = 0x25B5;
  12991. t['whiteuppointingtriangle'] = 0x25B3;
  12992. t['wihiragana'] = 0x3090;
  12993. t['wikatakana'] = 0x30F0;
  12994. t['wikorean'] = 0x315F;
  12995. t['wmonospace'] = 0xFF57;
  12996. t['wohiragana'] = 0x3092;
  12997. t['wokatakana'] = 0x30F2;
  12998. t['wokatakanahalfwidth'] = 0xFF66;
  12999. t['won'] = 0x20A9;
  13000. t['wonmonospace'] = 0xFFE6;
  13001. t['wowaenthai'] = 0x0E27;
  13002. t['wparen'] = 0x24B2;
  13003. t['wring'] = 0x1E98;
  13004. t['wsuperior'] = 0x02B7;
  13005. t['wturned'] = 0x028D;
  13006. t['wynn'] = 0x01BF;
  13007. t['x'] = 0x0078;
  13008. t['xabovecmb'] = 0x033D;
  13009. t['xbopomofo'] = 0x3112;
  13010. t['xcircle'] = 0x24E7;
  13011. t['xdieresis'] = 0x1E8D;
  13012. t['xdotaccent'] = 0x1E8B;
  13013. t['xeharmenian'] = 0x056D;
  13014. t['xi'] = 0x03BE;
  13015. t['xmonospace'] = 0xFF58;
  13016. t['xparen'] = 0x24B3;
  13017. t['xsuperior'] = 0x02E3;
  13018. t['y'] = 0x0079;
  13019. t['yaadosquare'] = 0x334E;
  13020. t['yabengali'] = 0x09AF;
  13021. t['yacute'] = 0x00FD;
  13022. t['yadeva'] = 0x092F;
  13023. t['yaekorean'] = 0x3152;
  13024. t['yagujarati'] = 0x0AAF;
  13025. t['yagurmukhi'] = 0x0A2F;
  13026. t['yahiragana'] = 0x3084;
  13027. t['yakatakana'] = 0x30E4;
  13028. t['yakatakanahalfwidth'] = 0xFF94;
  13029. t['yakorean'] = 0x3151;
  13030. t['yamakkanthai'] = 0x0E4E;
  13031. t['yasmallhiragana'] = 0x3083;
  13032. t['yasmallkatakana'] = 0x30E3;
  13033. t['yasmallkatakanahalfwidth'] = 0xFF6C;
  13034. t['yatcyrillic'] = 0x0463;
  13035. t['ycircle'] = 0x24E8;
  13036. t['ycircumflex'] = 0x0177;
  13037. t['ydieresis'] = 0x00FF;
  13038. t['ydotaccent'] = 0x1E8F;
  13039. t['ydotbelow'] = 0x1EF5;
  13040. t['yeharabic'] = 0x064A;
  13041. t['yehbarreearabic'] = 0x06D2;
  13042. t['yehbarreefinalarabic'] = 0xFBAF;
  13043. t['yehfinalarabic'] = 0xFEF2;
  13044. t['yehhamzaabovearabic'] = 0x0626;
  13045. t['yehhamzaabovefinalarabic'] = 0xFE8A;
  13046. t['yehhamzaaboveinitialarabic'] = 0xFE8B;
  13047. t['yehhamzaabovemedialarabic'] = 0xFE8C;
  13048. t['yehinitialarabic'] = 0xFEF3;
  13049. t['yehmedialarabic'] = 0xFEF4;
  13050. t['yehmeeminitialarabic'] = 0xFCDD;
  13051. t['yehmeemisolatedarabic'] = 0xFC58;
  13052. t['yehnoonfinalarabic'] = 0xFC94;
  13053. t['yehthreedotsbelowarabic'] = 0x06D1;
  13054. t['yekorean'] = 0x3156;
  13055. t['yen'] = 0x00A5;
  13056. t['yenmonospace'] = 0xFFE5;
  13057. t['yeokorean'] = 0x3155;
  13058. t['yeorinhieuhkorean'] = 0x3186;
  13059. t['yerahbenyomohebrew'] = 0x05AA;
  13060. t['yerahbenyomolefthebrew'] = 0x05AA;
  13061. t['yericyrillic'] = 0x044B;
  13062. t['yerudieresiscyrillic'] = 0x04F9;
  13063. t['yesieungkorean'] = 0x3181;
  13064. t['yesieungpansioskorean'] = 0x3183;
  13065. t['yesieungsioskorean'] = 0x3182;
  13066. t['yetivhebrew'] = 0x059A;
  13067. t['ygrave'] = 0x1EF3;
  13068. t['yhook'] = 0x01B4;
  13069. t['yhookabove'] = 0x1EF7;
  13070. t['yiarmenian'] = 0x0575;
  13071. t['yicyrillic'] = 0x0457;
  13072. t['yikorean'] = 0x3162;
  13073. t['yinyang'] = 0x262F;
  13074. t['yiwnarmenian'] = 0x0582;
  13075. t['ymonospace'] = 0xFF59;
  13076. t['yod'] = 0x05D9;
  13077. t['yoddagesh'] = 0xFB39;
  13078. t['yoddageshhebrew'] = 0xFB39;
  13079. t['yodhebrew'] = 0x05D9;
  13080. t['yodyodhebrew'] = 0x05F2;
  13081. t['yodyodpatahhebrew'] = 0xFB1F;
  13082. t['yohiragana'] = 0x3088;
  13083. t['yoikorean'] = 0x3189;
  13084. t['yokatakana'] = 0x30E8;
  13085. t['yokatakanahalfwidth'] = 0xFF96;
  13086. t['yokorean'] = 0x315B;
  13087. t['yosmallhiragana'] = 0x3087;
  13088. t['yosmallkatakana'] = 0x30E7;
  13089. t['yosmallkatakanahalfwidth'] = 0xFF6E;
  13090. t['yotgreek'] = 0x03F3;
  13091. t['yoyaekorean'] = 0x3188;
  13092. t['yoyakorean'] = 0x3187;
  13093. t['yoyakthai'] = 0x0E22;
  13094. t['yoyingthai'] = 0x0E0D;
  13095. t['yparen'] = 0x24B4;
  13096. t['ypogegrammeni'] = 0x037A;
  13097. t['ypogegrammenigreekcmb'] = 0x0345;
  13098. t['yr'] = 0x01A6;
  13099. t['yring'] = 0x1E99;
  13100. t['ysuperior'] = 0x02B8;
  13101. t['ytilde'] = 0x1EF9;
  13102. t['yturned'] = 0x028E;
  13103. t['yuhiragana'] = 0x3086;
  13104. t['yuikorean'] = 0x318C;
  13105. t['yukatakana'] = 0x30E6;
  13106. t['yukatakanahalfwidth'] = 0xFF95;
  13107. t['yukorean'] = 0x3160;
  13108. t['yusbigcyrillic'] = 0x046B;
  13109. t['yusbigiotifiedcyrillic'] = 0x046D;
  13110. t['yuslittlecyrillic'] = 0x0467;
  13111. t['yuslittleiotifiedcyrillic'] = 0x0469;
  13112. t['yusmallhiragana'] = 0x3085;
  13113. t['yusmallkatakana'] = 0x30E5;
  13114. t['yusmallkatakanahalfwidth'] = 0xFF6D;
  13115. t['yuyekorean'] = 0x318B;
  13116. t['yuyeokorean'] = 0x318A;
  13117. t['yyabengali'] = 0x09DF;
  13118. t['yyadeva'] = 0x095F;
  13119. t['z'] = 0x007A;
  13120. t['zaarmenian'] = 0x0566;
  13121. t['zacute'] = 0x017A;
  13122. t['zadeva'] = 0x095B;
  13123. t['zagurmukhi'] = 0x0A5B;
  13124. t['zaharabic'] = 0x0638;
  13125. t['zahfinalarabic'] = 0xFEC6;
  13126. t['zahinitialarabic'] = 0xFEC7;
  13127. t['zahiragana'] = 0x3056;
  13128. t['zahmedialarabic'] = 0xFEC8;
  13129. t['zainarabic'] = 0x0632;
  13130. t['zainfinalarabic'] = 0xFEB0;
  13131. t['zakatakana'] = 0x30B6;
  13132. t['zaqefgadolhebrew'] = 0x0595;
  13133. t['zaqefqatanhebrew'] = 0x0594;
  13134. t['zarqahebrew'] = 0x0598;
  13135. t['zayin'] = 0x05D6;
  13136. t['zayindagesh'] = 0xFB36;
  13137. t['zayindageshhebrew'] = 0xFB36;
  13138. t['zayinhebrew'] = 0x05D6;
  13139. t['zbopomofo'] = 0x3117;
  13140. t['zcaron'] = 0x017E;
  13141. t['zcircle'] = 0x24E9;
  13142. t['zcircumflex'] = 0x1E91;
  13143. t['zcurl'] = 0x0291;
  13144. t['zdot'] = 0x017C;
  13145. t['zdotaccent'] = 0x017C;
  13146. t['zdotbelow'] = 0x1E93;
  13147. t['zecyrillic'] = 0x0437;
  13148. t['zedescendercyrillic'] = 0x0499;
  13149. t['zedieresiscyrillic'] = 0x04DF;
  13150. t['zehiragana'] = 0x305C;
  13151. t['zekatakana'] = 0x30BC;
  13152. t['zero'] = 0x0030;
  13153. t['zeroarabic'] = 0x0660;
  13154. t['zerobengali'] = 0x09E6;
  13155. t['zerodeva'] = 0x0966;
  13156. t['zerogujarati'] = 0x0AE6;
  13157. t['zerogurmukhi'] = 0x0A66;
  13158. t['zerohackarabic'] = 0x0660;
  13159. t['zeroinferior'] = 0x2080;
  13160. t['zeromonospace'] = 0xFF10;
  13161. t['zerooldstyle'] = 0xF730;
  13162. t['zeropersian'] = 0x06F0;
  13163. t['zerosuperior'] = 0x2070;
  13164. t['zerothai'] = 0x0E50;
  13165. t['zerowidthjoiner'] = 0xFEFF;
  13166. t['zerowidthnonjoiner'] = 0x200C;
  13167. t['zerowidthspace'] = 0x200B;
  13168. t['zeta'] = 0x03B6;
  13169. t['zhbopomofo'] = 0x3113;
  13170. t['zhearmenian'] = 0x056A;
  13171. t['zhebrevecyrillic'] = 0x04C2;
  13172. t['zhecyrillic'] = 0x0436;
  13173. t['zhedescendercyrillic'] = 0x0497;
  13174. t['zhedieresiscyrillic'] = 0x04DD;
  13175. t['zihiragana'] = 0x3058;
  13176. t['zikatakana'] = 0x30B8;
  13177. t['zinorhebrew'] = 0x05AE;
  13178. t['zlinebelow'] = 0x1E95;
  13179. t['zmonospace'] = 0xFF5A;
  13180. t['zohiragana'] = 0x305E;
  13181. t['zokatakana'] = 0x30BE;
  13182. t['zparen'] = 0x24B5;
  13183. t['zretroflexhook'] = 0x0290;
  13184. t['zstroke'] = 0x01B6;
  13185. t['zuhiragana'] = 0x305A;
  13186. t['zukatakana'] = 0x30BA;
  13187. t['.notdef'] = 0x0000;
  13188. });
  13189. var getDingbatsGlyphsUnicode = getLookupTableFactory(function (t) {
  13190. t['space'] = 0x0020;
  13191. t['a1'] = 0x2701;
  13192. t['a2'] = 0x2702;
  13193. t['a202'] = 0x2703;
  13194. t['a3'] = 0x2704;
  13195. t['a4'] = 0x260E;
  13196. t['a5'] = 0x2706;
  13197. t['a119'] = 0x2707;
  13198. t['a118'] = 0x2708;
  13199. t['a117'] = 0x2709;
  13200. t['a11'] = 0x261B;
  13201. t['a12'] = 0x261E;
  13202. t['a13'] = 0x270C;
  13203. t['a14'] = 0x270D;
  13204. t['a15'] = 0x270E;
  13205. t['a16'] = 0x270F;
  13206. t['a105'] = 0x2710;
  13207. t['a17'] = 0x2711;
  13208. t['a18'] = 0x2712;
  13209. t['a19'] = 0x2713;
  13210. t['a20'] = 0x2714;
  13211. t['a21'] = 0x2715;
  13212. t['a22'] = 0x2716;
  13213. t['a23'] = 0x2717;
  13214. t['a24'] = 0x2718;
  13215. t['a25'] = 0x2719;
  13216. t['a26'] = 0x271A;
  13217. t['a27'] = 0x271B;
  13218. t['a28'] = 0x271C;
  13219. t['a6'] = 0x271D;
  13220. t['a7'] = 0x271E;
  13221. t['a8'] = 0x271F;
  13222. t['a9'] = 0x2720;
  13223. t['a10'] = 0x2721;
  13224. t['a29'] = 0x2722;
  13225. t['a30'] = 0x2723;
  13226. t['a31'] = 0x2724;
  13227. t['a32'] = 0x2725;
  13228. t['a33'] = 0x2726;
  13229. t['a34'] = 0x2727;
  13230. t['a35'] = 0x2605;
  13231. t['a36'] = 0x2729;
  13232. t['a37'] = 0x272A;
  13233. t['a38'] = 0x272B;
  13234. t['a39'] = 0x272C;
  13235. t['a40'] = 0x272D;
  13236. t['a41'] = 0x272E;
  13237. t['a42'] = 0x272F;
  13238. t['a43'] = 0x2730;
  13239. t['a44'] = 0x2731;
  13240. t['a45'] = 0x2732;
  13241. t['a46'] = 0x2733;
  13242. t['a47'] = 0x2734;
  13243. t['a48'] = 0x2735;
  13244. t['a49'] = 0x2736;
  13245. t['a50'] = 0x2737;
  13246. t['a51'] = 0x2738;
  13247. t['a52'] = 0x2739;
  13248. t['a53'] = 0x273A;
  13249. t['a54'] = 0x273B;
  13250. t['a55'] = 0x273C;
  13251. t['a56'] = 0x273D;
  13252. t['a57'] = 0x273E;
  13253. t['a58'] = 0x273F;
  13254. t['a59'] = 0x2740;
  13255. t['a60'] = 0x2741;
  13256. t['a61'] = 0x2742;
  13257. t['a62'] = 0x2743;
  13258. t['a63'] = 0x2744;
  13259. t['a64'] = 0x2745;
  13260. t['a65'] = 0x2746;
  13261. t['a66'] = 0x2747;
  13262. t['a67'] = 0x2748;
  13263. t['a68'] = 0x2749;
  13264. t['a69'] = 0x274A;
  13265. t['a70'] = 0x274B;
  13266. t['a71'] = 0x25CF;
  13267. t['a72'] = 0x274D;
  13268. t['a73'] = 0x25A0;
  13269. t['a74'] = 0x274F;
  13270. t['a203'] = 0x2750;
  13271. t['a75'] = 0x2751;
  13272. t['a204'] = 0x2752;
  13273. t['a76'] = 0x25B2;
  13274. t['a77'] = 0x25BC;
  13275. t['a78'] = 0x25C6;
  13276. t['a79'] = 0x2756;
  13277. t['a81'] = 0x25D7;
  13278. t['a82'] = 0x2758;
  13279. t['a83'] = 0x2759;
  13280. t['a84'] = 0x275A;
  13281. t['a97'] = 0x275B;
  13282. t['a98'] = 0x275C;
  13283. t['a99'] = 0x275D;
  13284. t['a100'] = 0x275E;
  13285. t['a101'] = 0x2761;
  13286. t['a102'] = 0x2762;
  13287. t['a103'] = 0x2763;
  13288. t['a104'] = 0x2764;
  13289. t['a106'] = 0x2765;
  13290. t['a107'] = 0x2766;
  13291. t['a108'] = 0x2767;
  13292. t['a112'] = 0x2663;
  13293. t['a111'] = 0x2666;
  13294. t['a110'] = 0x2665;
  13295. t['a109'] = 0x2660;
  13296. t['a120'] = 0x2460;
  13297. t['a121'] = 0x2461;
  13298. t['a122'] = 0x2462;
  13299. t['a123'] = 0x2463;
  13300. t['a124'] = 0x2464;
  13301. t['a125'] = 0x2465;
  13302. t['a126'] = 0x2466;
  13303. t['a127'] = 0x2467;
  13304. t['a128'] = 0x2468;
  13305. t['a129'] = 0x2469;
  13306. t['a130'] = 0x2776;
  13307. t['a131'] = 0x2777;
  13308. t['a132'] = 0x2778;
  13309. t['a133'] = 0x2779;
  13310. t['a134'] = 0x277A;
  13311. t['a135'] = 0x277B;
  13312. t['a136'] = 0x277C;
  13313. t['a137'] = 0x277D;
  13314. t['a138'] = 0x277E;
  13315. t['a139'] = 0x277F;
  13316. t['a140'] = 0x2780;
  13317. t['a141'] = 0x2781;
  13318. t['a142'] = 0x2782;
  13319. t['a143'] = 0x2783;
  13320. t['a144'] = 0x2784;
  13321. t['a145'] = 0x2785;
  13322. t['a146'] = 0x2786;
  13323. t['a147'] = 0x2787;
  13324. t['a148'] = 0x2788;
  13325. t['a149'] = 0x2789;
  13326. t['a150'] = 0x278A;
  13327. t['a151'] = 0x278B;
  13328. t['a152'] = 0x278C;
  13329. t['a153'] = 0x278D;
  13330. t['a154'] = 0x278E;
  13331. t['a155'] = 0x278F;
  13332. t['a156'] = 0x2790;
  13333. t['a157'] = 0x2791;
  13334. t['a158'] = 0x2792;
  13335. t['a159'] = 0x2793;
  13336. t['a160'] = 0x2794;
  13337. t['a161'] = 0x2192;
  13338. t['a163'] = 0x2194;
  13339. t['a164'] = 0x2195;
  13340. t['a196'] = 0x2798;
  13341. t['a165'] = 0x2799;
  13342. t['a192'] = 0x279A;
  13343. t['a166'] = 0x279B;
  13344. t['a167'] = 0x279C;
  13345. t['a168'] = 0x279D;
  13346. t['a169'] = 0x279E;
  13347. t['a170'] = 0x279F;
  13348. t['a171'] = 0x27A0;
  13349. t['a172'] = 0x27A1;
  13350. t['a173'] = 0x27A2;
  13351. t['a162'] = 0x27A3;
  13352. t['a174'] = 0x27A4;
  13353. t['a175'] = 0x27A5;
  13354. t['a176'] = 0x27A6;
  13355. t['a177'] = 0x27A7;
  13356. t['a178'] = 0x27A8;
  13357. t['a179'] = 0x27A9;
  13358. t['a193'] = 0x27AA;
  13359. t['a180'] = 0x27AB;
  13360. t['a199'] = 0x27AC;
  13361. t['a181'] = 0x27AD;
  13362. t['a200'] = 0x27AE;
  13363. t['a182'] = 0x27AF;
  13364. t['a201'] = 0x27B1;
  13365. t['a183'] = 0x27B2;
  13366. t['a184'] = 0x27B3;
  13367. t['a197'] = 0x27B4;
  13368. t['a185'] = 0x27B5;
  13369. t['a194'] = 0x27B6;
  13370. t['a198'] = 0x27B7;
  13371. t['a186'] = 0x27B8;
  13372. t['a195'] = 0x27B9;
  13373. t['a187'] = 0x27BA;
  13374. t['a188'] = 0x27BB;
  13375. t['a189'] = 0x27BC;
  13376. t['a190'] = 0x27BD;
  13377. t['a191'] = 0x27BE;
  13378. t['a89'] = 0x2768;
  13379. // 0xF8D7
  13380. t['a90'] = 0x2769;
  13381. // 0xF8D8
  13382. t['a93'] = 0x276A;
  13383. // 0xF8D9
  13384. t['a94'] = 0x276B;
  13385. // 0xF8DA
  13386. t['a91'] = 0x276C;
  13387. // 0xF8DB
  13388. t['a92'] = 0x276D;
  13389. // 0xF8DC
  13390. t['a205'] = 0x276E;
  13391. // 0xF8DD
  13392. t['a85'] = 0x276F;
  13393. // 0xF8DE
  13394. t['a206'] = 0x2770;
  13395. // 0xF8DF
  13396. t['a86'] = 0x2771;
  13397. // 0xF8E0
  13398. t['a87'] = 0x2772;
  13399. // 0xF8E1
  13400. t['a88'] = 0x2773;
  13401. // 0xF8E2
  13402. t['a95'] = 0x2774;
  13403. // 0xF8E3
  13404. t['a96'] = 0x2775;
  13405. // 0xF8E4
  13406. t['.notdef'] = 0x0000;
  13407. });
  13408. exports.getGlyphsUnicode = getGlyphsUnicode;
  13409. exports.getDingbatsGlyphsUnicode = getDingbatsGlyphsUnicode;
  13410. }));
  13411. (function (root, factory) {
  13412. factory(root.pdfjsCoreJbig2 = {}, root.pdfjsSharedUtil, root.pdfjsCoreArithmeticDecoder);
  13413. }(this, function (exports, sharedUtil, coreArithmeticDecoder) {
  13414. var error = sharedUtil.error;
  13415. var log2 = sharedUtil.log2;
  13416. var readInt8 = sharedUtil.readInt8;
  13417. var readUint16 = sharedUtil.readUint16;
  13418. var readUint32 = sharedUtil.readUint32;
  13419. var shadow = sharedUtil.shadow;
  13420. var ArithmeticDecoder = coreArithmeticDecoder.ArithmeticDecoder;
  13421. var Jbig2Image = function Jbig2ImageClosure() {
  13422. // Utility data structures
  13423. function ContextCache() {
  13424. }
  13425. ContextCache.prototype = {
  13426. getContexts: function (id) {
  13427. if (id in this) {
  13428. return this[id];
  13429. }
  13430. return this[id] = new Int8Array(1 << 16);
  13431. }
  13432. };
  13433. function DecodingContext(data, start, end) {
  13434. this.data = data;
  13435. this.start = start;
  13436. this.end = end;
  13437. }
  13438. DecodingContext.prototype = {
  13439. get decoder() {
  13440. var decoder = new ArithmeticDecoder(this.data, this.start, this.end);
  13441. return shadow(this, 'decoder', decoder);
  13442. },
  13443. get contextCache() {
  13444. var cache = new ContextCache();
  13445. return shadow(this, 'contextCache', cache);
  13446. }
  13447. };
  13448. // Annex A. Arithmetic Integer Decoding Procedure
  13449. // A.2 Procedure for decoding values
  13450. function decodeInteger(contextCache, procedure, decoder) {
  13451. var contexts = contextCache.getContexts(procedure);
  13452. var prev = 1;
  13453. function readBits(length) {
  13454. var v = 0;
  13455. for (var i = 0; i < length; i++) {
  13456. var bit = decoder.readBit(contexts, prev);
  13457. prev = prev < 256 ? prev << 1 | bit : (prev << 1 | bit) & 511 | 256;
  13458. v = v << 1 | bit;
  13459. }
  13460. return v >>> 0;
  13461. }
  13462. var sign = readBits(1);
  13463. var value = readBits(1) ? readBits(1) ? readBits(1) ? readBits(1) ? readBits(1) ? readBits(32) + 4436 : readBits(12) + 340 : readBits(8) + 84 : readBits(6) + 20 : readBits(4) + 4 : readBits(2);
  13464. return sign === 0 ? value : value > 0 ? -value : null;
  13465. }
  13466. // A.3 The IAID decoding procedure
  13467. function decodeIAID(contextCache, decoder, codeLength) {
  13468. var contexts = contextCache.getContexts('IAID');
  13469. var prev = 1;
  13470. for (var i = 0; i < codeLength; i++) {
  13471. var bit = decoder.readBit(contexts, prev);
  13472. prev = prev << 1 | bit;
  13473. }
  13474. if (codeLength < 31) {
  13475. return prev & (1 << codeLength) - 1;
  13476. }
  13477. return prev & 0x7FFFFFFF;
  13478. }
  13479. // 7.3 Segment types
  13480. var SegmentTypes = [
  13481. 'SymbolDictionary',
  13482. null,
  13483. null,
  13484. null,
  13485. 'IntermediateTextRegion',
  13486. null,
  13487. 'ImmediateTextRegion',
  13488. 'ImmediateLosslessTextRegion',
  13489. null,
  13490. null,
  13491. null,
  13492. null,
  13493. null,
  13494. null,
  13495. null,
  13496. null,
  13497. 'patternDictionary',
  13498. null,
  13499. null,
  13500. null,
  13501. 'IntermediateHalftoneRegion',
  13502. null,
  13503. 'ImmediateHalftoneRegion',
  13504. 'ImmediateLosslessHalftoneRegion',
  13505. null,
  13506. null,
  13507. null,
  13508. null,
  13509. null,
  13510. null,
  13511. null,
  13512. null,
  13513. null,
  13514. null,
  13515. null,
  13516. null,
  13517. 'IntermediateGenericRegion',
  13518. null,
  13519. 'ImmediateGenericRegion',
  13520. 'ImmediateLosslessGenericRegion',
  13521. 'IntermediateGenericRefinementRegion',
  13522. null,
  13523. 'ImmediateGenericRefinementRegion',
  13524. 'ImmediateLosslessGenericRefinementRegion',
  13525. null,
  13526. null,
  13527. null,
  13528. null,
  13529. 'PageInformation',
  13530. 'EndOfPage',
  13531. 'EndOfStripe',
  13532. 'EndOfFile',
  13533. 'Profiles',
  13534. 'Tables',
  13535. null,
  13536. null,
  13537. null,
  13538. null,
  13539. null,
  13540. null,
  13541. null,
  13542. null,
  13543. 'Extension'
  13544. ];
  13545. var CodingTemplates = [
  13546. [
  13547. {
  13548. x: -1,
  13549. y: -2
  13550. },
  13551. {
  13552. x: 0,
  13553. y: -2
  13554. },
  13555. {
  13556. x: 1,
  13557. y: -2
  13558. },
  13559. {
  13560. x: -2,
  13561. y: -1
  13562. },
  13563. {
  13564. x: -1,
  13565. y: -1
  13566. },
  13567. {
  13568. x: 0,
  13569. y: -1
  13570. },
  13571. {
  13572. x: 1,
  13573. y: -1
  13574. },
  13575. {
  13576. x: 2,
  13577. y: -1
  13578. },
  13579. {
  13580. x: -4,
  13581. y: 0
  13582. },
  13583. {
  13584. x: -3,
  13585. y: 0
  13586. },
  13587. {
  13588. x: -2,
  13589. y: 0
  13590. },
  13591. {
  13592. x: -1,
  13593. y: 0
  13594. }
  13595. ],
  13596. [
  13597. {
  13598. x: -1,
  13599. y: -2
  13600. },
  13601. {
  13602. x: 0,
  13603. y: -2
  13604. },
  13605. {
  13606. x: 1,
  13607. y: -2
  13608. },
  13609. {
  13610. x: 2,
  13611. y: -2
  13612. },
  13613. {
  13614. x: -2,
  13615. y: -1
  13616. },
  13617. {
  13618. x: -1,
  13619. y: -1
  13620. },
  13621. {
  13622. x: 0,
  13623. y: -1
  13624. },
  13625. {
  13626. x: 1,
  13627. y: -1
  13628. },
  13629. {
  13630. x: 2,
  13631. y: -1
  13632. },
  13633. {
  13634. x: -3,
  13635. y: 0
  13636. },
  13637. {
  13638. x: -2,
  13639. y: 0
  13640. },
  13641. {
  13642. x: -1,
  13643. y: 0
  13644. }
  13645. ],
  13646. [
  13647. {
  13648. x: -1,
  13649. y: -2
  13650. },
  13651. {
  13652. x: 0,
  13653. y: -2
  13654. },
  13655. {
  13656. x: 1,
  13657. y: -2
  13658. },
  13659. {
  13660. x: -2,
  13661. y: -1
  13662. },
  13663. {
  13664. x: -1,
  13665. y: -1
  13666. },
  13667. {
  13668. x: 0,
  13669. y: -1
  13670. },
  13671. {
  13672. x: 1,
  13673. y: -1
  13674. },
  13675. {
  13676. x: -2,
  13677. y: 0
  13678. },
  13679. {
  13680. x: -1,
  13681. y: 0
  13682. }
  13683. ],
  13684. [
  13685. {
  13686. x: -3,
  13687. y: -1
  13688. },
  13689. {
  13690. x: -2,
  13691. y: -1
  13692. },
  13693. {
  13694. x: -1,
  13695. y: -1
  13696. },
  13697. {
  13698. x: 0,
  13699. y: -1
  13700. },
  13701. {
  13702. x: 1,
  13703. y: -1
  13704. },
  13705. {
  13706. x: -4,
  13707. y: 0
  13708. },
  13709. {
  13710. x: -3,
  13711. y: 0
  13712. },
  13713. {
  13714. x: -2,
  13715. y: 0
  13716. },
  13717. {
  13718. x: -1,
  13719. y: 0
  13720. }
  13721. ]
  13722. ];
  13723. var RefinementTemplates = [
  13724. {
  13725. coding: [
  13726. {
  13727. x: 0,
  13728. y: -1
  13729. },
  13730. {
  13731. x: 1,
  13732. y: -1
  13733. },
  13734. {
  13735. x: -1,
  13736. y: 0
  13737. }
  13738. ],
  13739. reference: [
  13740. {
  13741. x: 0,
  13742. y: -1
  13743. },
  13744. {
  13745. x: 1,
  13746. y: -1
  13747. },
  13748. {
  13749. x: -1,
  13750. y: 0
  13751. },
  13752. {
  13753. x: 0,
  13754. y: 0
  13755. },
  13756. {
  13757. x: 1,
  13758. y: 0
  13759. },
  13760. {
  13761. x: -1,
  13762. y: 1
  13763. },
  13764. {
  13765. x: 0,
  13766. y: 1
  13767. },
  13768. {
  13769. x: 1,
  13770. y: 1
  13771. }
  13772. ]
  13773. },
  13774. {
  13775. coding: [
  13776. {
  13777. x: -1,
  13778. y: -1
  13779. },
  13780. {
  13781. x: 0,
  13782. y: -1
  13783. },
  13784. {
  13785. x: 1,
  13786. y: -1
  13787. },
  13788. {
  13789. x: -1,
  13790. y: 0
  13791. }
  13792. ],
  13793. reference: [
  13794. {
  13795. x: 0,
  13796. y: -1
  13797. },
  13798. {
  13799. x: -1,
  13800. y: 0
  13801. },
  13802. {
  13803. x: 0,
  13804. y: 0
  13805. },
  13806. {
  13807. x: 1,
  13808. y: 0
  13809. },
  13810. {
  13811. x: 0,
  13812. y: 1
  13813. },
  13814. {
  13815. x: 1,
  13816. y: 1
  13817. }
  13818. ]
  13819. }
  13820. ];
  13821. // See 6.2.5.7 Decoding the bitmap.
  13822. var ReusedContexts = [
  13823. 0x9B25,
  13824. // 10011 0110010 0101
  13825. 0x0795,
  13826. // 0011 110010 101
  13827. 0x00E5,
  13828. // 001 11001 01
  13829. 0x0195
  13830. ];
  13831. // 011001 0101
  13832. var RefinementReusedContexts = [
  13833. 0x0020,
  13834. // '000' + '0' (coding) + '00010000' + '0' (reference)
  13835. 0x0008
  13836. ];
  13837. // '0000' + '001000'
  13838. function decodeBitmapTemplate0(width, height, decodingContext) {
  13839. var decoder = decodingContext.decoder;
  13840. var contexts = decodingContext.contextCache.getContexts('GB');
  13841. var contextLabel, i, j, pixel, row, row1, row2, bitmap = [];
  13842. // ...ooooo....
  13843. // ..ooooooo... Context template for current pixel (X)
  13844. // .ooooX...... (concatenate values of 'o'-pixels to get contextLabel)
  13845. var OLD_PIXEL_MASK = 0x7BF7;
  13846. // 01111 0111111 0111
  13847. for (i = 0; i < height; i++) {
  13848. row = bitmap[i] = new Uint8Array(width);
  13849. row1 = i < 1 ? row : bitmap[i - 1];
  13850. row2 = i < 2 ? row : bitmap[i - 2];
  13851. // At the beginning of each row:
  13852. // Fill contextLabel with pixels that are above/right of (X)
  13853. contextLabel = row2[0] << 13 | row2[1] << 12 | row2[2] << 11 | row1[0] << 7 | row1[1] << 6 | row1[2] << 5 | row1[3] << 4;
  13854. for (j = 0; j < width; j++) {
  13855. row[j] = pixel = decoder.readBit(contexts, contextLabel);
  13856. // At each pixel: Clear contextLabel pixels that are shifted
  13857. // out of the context, then add new ones.
  13858. contextLabel = (contextLabel & OLD_PIXEL_MASK) << 1 | (j + 3 < width ? row2[j + 3] << 11 : 0) | (j + 4 < width ? row1[j + 4] << 4 : 0) | pixel;
  13859. }
  13860. }
  13861. return bitmap;
  13862. }
  13863. // 6.2 Generic Region Decoding Procedure
  13864. function decodeBitmap(mmr, width, height, templateIndex, prediction, skip, at, decodingContext) {
  13865. if (mmr) {
  13866. error('JBIG2 error: MMR encoding is not supported');
  13867. }
  13868. // Use optimized version for the most common case
  13869. if (templateIndex === 0 && !skip && !prediction && at.length === 4 && at[0].x === 3 && at[0].y === -1 && at[1].x === -3 && at[1].y === -1 && at[2].x === 2 && at[2].y === -2 && at[3].x === -2 && at[3].y === -2) {
  13870. return decodeBitmapTemplate0(width, height, decodingContext);
  13871. }
  13872. var useskip = !!skip;
  13873. var template = CodingTemplates[templateIndex].concat(at);
  13874. // Sorting is non-standard, and it is not required. But sorting increases
  13875. // the number of template bits that can be reused from the previous
  13876. // contextLabel in the main loop.
  13877. template.sort(function (a, b) {
  13878. return a.y - b.y || a.x - b.x;
  13879. });
  13880. var templateLength = template.length;
  13881. var templateX = new Int8Array(templateLength);
  13882. var templateY = new Int8Array(templateLength);
  13883. var changingTemplateEntries = [];
  13884. var reuseMask = 0, minX = 0, maxX = 0, minY = 0;
  13885. var c, k;
  13886. for (k = 0; k < templateLength; k++) {
  13887. templateX[k] = template[k].x;
  13888. templateY[k] = template[k].y;
  13889. minX = Math.min(minX, template[k].x);
  13890. maxX = Math.max(maxX, template[k].x);
  13891. minY = Math.min(minY, template[k].y);
  13892. // Check if the template pixel appears in two consecutive context labels,
  13893. // so it can be reused. Otherwise, we add it to the list of changing
  13894. // template entries.
  13895. if (k < templateLength - 1 && template[k].y === template[k + 1].y && template[k].x === template[k + 1].x - 1) {
  13896. reuseMask |= 1 << templateLength - 1 - k;
  13897. } else {
  13898. changingTemplateEntries.push(k);
  13899. }
  13900. }
  13901. var changingEntriesLength = changingTemplateEntries.length;
  13902. var changingTemplateX = new Int8Array(changingEntriesLength);
  13903. var changingTemplateY = new Int8Array(changingEntriesLength);
  13904. var changingTemplateBit = new Uint16Array(changingEntriesLength);
  13905. for (c = 0; c < changingEntriesLength; c++) {
  13906. k = changingTemplateEntries[c];
  13907. changingTemplateX[c] = template[k].x;
  13908. changingTemplateY[c] = template[k].y;
  13909. changingTemplateBit[c] = 1 << templateLength - 1 - k;
  13910. }
  13911. // Get the safe bounding box edges from the width, height, minX, maxX, minY
  13912. var sbb_left = -minX;
  13913. var sbb_top = -minY;
  13914. var sbb_right = width - maxX;
  13915. var pseudoPixelContext = ReusedContexts[templateIndex];
  13916. var row = new Uint8Array(width);
  13917. var bitmap = [];
  13918. var decoder = decodingContext.decoder;
  13919. var contexts = decodingContext.contextCache.getContexts('GB');
  13920. var ltp = 0, j, i0, j0, contextLabel = 0, bit, shift;
  13921. for (var i = 0; i < height; i++) {
  13922. if (prediction) {
  13923. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  13924. ltp ^= sltp;
  13925. if (ltp) {
  13926. bitmap.push(row);
  13927. // duplicate previous row
  13928. continue;
  13929. }
  13930. }
  13931. row = new Uint8Array(row);
  13932. bitmap.push(row);
  13933. for (j = 0; j < width; j++) {
  13934. if (useskip && skip[i][j]) {
  13935. row[j] = 0;
  13936. continue;
  13937. }
  13938. // Are we in the middle of a scanline, so we can reuse contextLabel
  13939. // bits?
  13940. if (j >= sbb_left && j < sbb_right && i >= sbb_top) {
  13941. // If yes, we can just shift the bits that are reusable and only
  13942. // fetch the remaining ones.
  13943. contextLabel = contextLabel << 1 & reuseMask;
  13944. for (k = 0; k < changingEntriesLength; k++) {
  13945. i0 = i + changingTemplateY[k];
  13946. j0 = j + changingTemplateX[k];
  13947. bit = bitmap[i0][j0];
  13948. if (bit) {
  13949. bit = changingTemplateBit[k];
  13950. contextLabel |= bit;
  13951. }
  13952. }
  13953. } else {
  13954. // compute the contextLabel from scratch
  13955. contextLabel = 0;
  13956. shift = templateLength - 1;
  13957. for (k = 0; k < templateLength; k++, shift--) {
  13958. j0 = j + templateX[k];
  13959. if (j0 >= 0 && j0 < width) {
  13960. i0 = i + templateY[k];
  13961. if (i0 >= 0) {
  13962. bit = bitmap[i0][j0];
  13963. if (bit) {
  13964. contextLabel |= bit << shift;
  13965. }
  13966. }
  13967. }
  13968. }
  13969. }
  13970. var pixel = decoder.readBit(contexts, contextLabel);
  13971. row[j] = pixel;
  13972. }
  13973. }
  13974. return bitmap;
  13975. }
  13976. // 6.3.2 Generic Refinement Region Decoding Procedure
  13977. function decodeRefinement(width, height, templateIndex, referenceBitmap, offsetX, offsetY, prediction, at, decodingContext) {
  13978. var codingTemplate = RefinementTemplates[templateIndex].coding;
  13979. if (templateIndex === 0) {
  13980. codingTemplate = codingTemplate.concat([at[0]]);
  13981. }
  13982. var codingTemplateLength = codingTemplate.length;
  13983. var codingTemplateX = new Int32Array(codingTemplateLength);
  13984. var codingTemplateY = new Int32Array(codingTemplateLength);
  13985. var k;
  13986. for (k = 0; k < codingTemplateLength; k++) {
  13987. codingTemplateX[k] = codingTemplate[k].x;
  13988. codingTemplateY[k] = codingTemplate[k].y;
  13989. }
  13990. var referenceTemplate = RefinementTemplates[templateIndex].reference;
  13991. if (templateIndex === 0) {
  13992. referenceTemplate = referenceTemplate.concat([at[1]]);
  13993. }
  13994. var referenceTemplateLength = referenceTemplate.length;
  13995. var referenceTemplateX = new Int32Array(referenceTemplateLength);
  13996. var referenceTemplateY = new Int32Array(referenceTemplateLength);
  13997. for (k = 0; k < referenceTemplateLength; k++) {
  13998. referenceTemplateX[k] = referenceTemplate[k].x;
  13999. referenceTemplateY[k] = referenceTemplate[k].y;
  14000. }
  14001. var referenceWidth = referenceBitmap[0].length;
  14002. var referenceHeight = referenceBitmap.length;
  14003. var pseudoPixelContext = RefinementReusedContexts[templateIndex];
  14004. var bitmap = [];
  14005. var decoder = decodingContext.decoder;
  14006. var contexts = decodingContext.contextCache.getContexts('GR');
  14007. var ltp = 0;
  14008. for (var i = 0; i < height; i++) {
  14009. if (prediction) {
  14010. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  14011. ltp ^= sltp;
  14012. if (ltp) {
  14013. error('JBIG2 error: prediction is not supported');
  14014. }
  14015. }
  14016. var row = new Uint8Array(width);
  14017. bitmap.push(row);
  14018. for (var j = 0; j < width; j++) {
  14019. var i0, j0;
  14020. var contextLabel = 0;
  14021. for (k = 0; k < codingTemplateLength; k++) {
  14022. i0 = i + codingTemplateY[k];
  14023. j0 = j + codingTemplateX[k];
  14024. if (i0 < 0 || j0 < 0 || j0 >= width) {
  14025. contextLabel <<= 1;
  14026. } else
  14027. // out of bound pixel
  14028. {
  14029. contextLabel = contextLabel << 1 | bitmap[i0][j0];
  14030. }
  14031. }
  14032. for (k = 0; k < referenceTemplateLength; k++) {
  14033. i0 = i + referenceTemplateY[k] + offsetY;
  14034. j0 = j + referenceTemplateX[k] + offsetX;
  14035. if (i0 < 0 || i0 >= referenceHeight || j0 < 0 || j0 >= referenceWidth) {
  14036. contextLabel <<= 1;
  14037. } else
  14038. // out of bound pixel
  14039. {
  14040. contextLabel = contextLabel << 1 | referenceBitmap[i0][j0];
  14041. }
  14042. }
  14043. var pixel = decoder.readBit(contexts, contextLabel);
  14044. row[j] = pixel;
  14045. }
  14046. }
  14047. return bitmap;
  14048. }
  14049. // 6.5.5 Decoding the symbol dictionary
  14050. function decodeSymbolDictionary(huffman, refinement, symbols, numberOfNewSymbols, numberOfExportedSymbols, huffmanTables, templateIndex, at, refinementTemplateIndex, refinementAt, decodingContext) {
  14051. if (huffman) {
  14052. error('JBIG2 error: huffman is not supported');
  14053. }
  14054. var newSymbols = [];
  14055. var currentHeight = 0;
  14056. var symbolCodeLength = log2(symbols.length + numberOfNewSymbols);
  14057. var decoder = decodingContext.decoder;
  14058. var contextCache = decodingContext.contextCache;
  14059. while (newSymbols.length < numberOfNewSymbols) {
  14060. var deltaHeight = decodeInteger(contextCache, 'IADH', decoder);
  14061. // 6.5.6
  14062. currentHeight += deltaHeight;
  14063. var currentWidth = 0;
  14064. var totalWidth = 0;
  14065. while (true) {
  14066. var deltaWidth = decodeInteger(contextCache, 'IADW', decoder);
  14067. // 6.5.7
  14068. if (deltaWidth === null) {
  14069. break;
  14070. }
  14071. // OOB
  14072. currentWidth += deltaWidth;
  14073. totalWidth += currentWidth;
  14074. var bitmap;
  14075. if (refinement) {
  14076. // 6.5.8.2 Refinement/aggregate-coded symbol bitmap
  14077. var numberOfInstances = decodeInteger(contextCache, 'IAAI', decoder);
  14078. if (numberOfInstances > 1) {
  14079. bitmap = decodeTextRegion(huffman, refinement, currentWidth, currentHeight, 0, numberOfInstances, 1, //strip size
  14080. symbols.concat(newSymbols), symbolCodeLength, 0, //transposed
  14081. 0, //ds offset
  14082. 1, //top left 7.4.3.1.1
  14083. 0, //OR operator
  14084. huffmanTables, refinementTemplateIndex, refinementAt, decodingContext);
  14085. } else {
  14086. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  14087. var rdx = decodeInteger(contextCache, 'IARDX', decoder);
  14088. // 6.4.11.3
  14089. var rdy = decodeInteger(contextCache, 'IARDY', decoder);
  14090. // 6.4.11.4
  14091. var symbol = symbolId < symbols.length ? symbols[symbolId] : newSymbols[symbolId - symbols.length];
  14092. bitmap = decodeRefinement(currentWidth, currentHeight, refinementTemplateIndex, symbol, rdx, rdy, false, refinementAt, decodingContext);
  14093. }
  14094. } else {
  14095. // 6.5.8.1 Direct-coded symbol bitmap
  14096. bitmap = decodeBitmap(false, currentWidth, currentHeight, templateIndex, false, null, at, decodingContext);
  14097. }
  14098. newSymbols.push(bitmap);
  14099. }
  14100. }
  14101. // 6.5.10 Exported symbols
  14102. var exportedSymbols = [];
  14103. var flags = [], currentFlag = false;
  14104. var totalSymbolsLength = symbols.length + numberOfNewSymbols;
  14105. while (flags.length < totalSymbolsLength) {
  14106. var runLength = decodeInteger(contextCache, 'IAEX', decoder);
  14107. while (runLength--) {
  14108. flags.push(currentFlag);
  14109. }
  14110. currentFlag = !currentFlag;
  14111. }
  14112. for (var i = 0, ii = symbols.length; i < ii; i++) {
  14113. if (flags[i]) {
  14114. exportedSymbols.push(symbols[i]);
  14115. }
  14116. }
  14117. for (var j = 0; j < numberOfNewSymbols; i++, j++) {
  14118. if (flags[i]) {
  14119. exportedSymbols.push(newSymbols[j]);
  14120. }
  14121. }
  14122. return exportedSymbols;
  14123. }
  14124. function decodeTextRegion(huffman, refinement, width, height, defaultPixelValue, numberOfSymbolInstances, stripSize, inputSymbols, symbolCodeLength, transposed, dsOffset, referenceCorner, combinationOperator, huffmanTables, refinementTemplateIndex, refinementAt, decodingContext) {
  14125. if (huffman) {
  14126. error('JBIG2 error: huffman is not supported');
  14127. }
  14128. // Prepare bitmap
  14129. var bitmap = [];
  14130. var i, row;
  14131. for (i = 0; i < height; i++) {
  14132. row = new Uint8Array(width);
  14133. if (defaultPixelValue) {
  14134. for (var j = 0; j < width; j++) {
  14135. row[j] = defaultPixelValue;
  14136. }
  14137. }
  14138. bitmap.push(row);
  14139. }
  14140. var decoder = decodingContext.decoder;
  14141. var contextCache = decodingContext.contextCache;
  14142. var stripT = -decodeInteger(contextCache, 'IADT', decoder);
  14143. // 6.4.6
  14144. var firstS = 0;
  14145. i = 0;
  14146. while (i < numberOfSymbolInstances) {
  14147. var deltaT = decodeInteger(contextCache, 'IADT', decoder);
  14148. // 6.4.6
  14149. stripT += deltaT;
  14150. var deltaFirstS = decodeInteger(contextCache, 'IAFS', decoder);
  14151. // 6.4.7
  14152. firstS += deltaFirstS;
  14153. var currentS = firstS;
  14154. do {
  14155. var currentT = stripSize === 1 ? 0 : decodeInteger(contextCache, 'IAIT', decoder);
  14156. // 6.4.9
  14157. var t = stripSize * stripT + currentT;
  14158. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  14159. var applyRefinement = refinement && decodeInteger(contextCache, 'IARI', decoder);
  14160. var symbolBitmap = inputSymbols[symbolId];
  14161. var symbolWidth = symbolBitmap[0].length;
  14162. var symbolHeight = symbolBitmap.length;
  14163. if (applyRefinement) {
  14164. var rdw = decodeInteger(contextCache, 'IARDW', decoder);
  14165. // 6.4.11.1
  14166. var rdh = decodeInteger(contextCache, 'IARDH', decoder);
  14167. // 6.4.11.2
  14168. var rdx = decodeInteger(contextCache, 'IARDX', decoder);
  14169. // 6.4.11.3
  14170. var rdy = decodeInteger(contextCache, 'IARDY', decoder);
  14171. // 6.4.11.4
  14172. symbolWidth += rdw;
  14173. symbolHeight += rdh;
  14174. symbolBitmap = decodeRefinement(symbolWidth, symbolHeight, refinementTemplateIndex, symbolBitmap, (rdw >> 1) + rdx, (rdh >> 1) + rdy, false, refinementAt, decodingContext);
  14175. }
  14176. var offsetT = t - (referenceCorner & 1 ? 0 : symbolHeight);
  14177. var offsetS = currentS - (referenceCorner & 2 ? symbolWidth : 0);
  14178. var s2, t2, symbolRow;
  14179. if (transposed) {
  14180. // Place Symbol Bitmap from T1,S1
  14181. for (s2 = 0; s2 < symbolHeight; s2++) {
  14182. row = bitmap[offsetS + s2];
  14183. if (!row) {
  14184. continue;
  14185. }
  14186. symbolRow = symbolBitmap[s2];
  14187. // To ignore Parts of Symbol bitmap which goes
  14188. // outside bitmap region
  14189. var maxWidth = Math.min(width - offsetT, symbolWidth);
  14190. switch (combinationOperator) {
  14191. case 0:
  14192. // OR
  14193. for (t2 = 0; t2 < maxWidth; t2++) {
  14194. row[offsetT + t2] |= symbolRow[t2];
  14195. }
  14196. break;
  14197. case 2:
  14198. // XOR
  14199. for (t2 = 0; t2 < maxWidth; t2++) {
  14200. row[offsetT + t2] ^= symbolRow[t2];
  14201. }
  14202. break;
  14203. default:
  14204. error('JBIG2 error: operator ' + combinationOperator + ' is not supported');
  14205. }
  14206. }
  14207. currentS += symbolHeight - 1;
  14208. } else {
  14209. for (t2 = 0; t2 < symbolHeight; t2++) {
  14210. row = bitmap[offsetT + t2];
  14211. if (!row) {
  14212. continue;
  14213. }
  14214. symbolRow = symbolBitmap[t2];
  14215. switch (combinationOperator) {
  14216. case 0:
  14217. // OR
  14218. for (s2 = 0; s2 < symbolWidth; s2++) {
  14219. row[offsetS + s2] |= symbolRow[s2];
  14220. }
  14221. break;
  14222. case 2:
  14223. // XOR
  14224. for (s2 = 0; s2 < symbolWidth; s2++) {
  14225. row[offsetS + s2] ^= symbolRow[s2];
  14226. }
  14227. break;
  14228. default:
  14229. error('JBIG2 error: operator ' + combinationOperator + ' is not supported');
  14230. }
  14231. }
  14232. currentS += symbolWidth - 1;
  14233. }
  14234. i++;
  14235. var deltaS = decodeInteger(contextCache, 'IADS', decoder);
  14236. // 6.4.8
  14237. if (deltaS === null) {
  14238. break;
  14239. }
  14240. // OOB
  14241. currentS += deltaS + dsOffset;
  14242. } while (true);
  14243. }
  14244. return bitmap;
  14245. }
  14246. function readSegmentHeader(data, start) {
  14247. var segmentHeader = {};
  14248. segmentHeader.number = readUint32(data, start);
  14249. var flags = data[start + 4];
  14250. var segmentType = flags & 0x3F;
  14251. if (!SegmentTypes[segmentType]) {
  14252. error('JBIG2 error: invalid segment type: ' + segmentType);
  14253. }
  14254. segmentHeader.type = segmentType;
  14255. segmentHeader.typeName = SegmentTypes[segmentType];
  14256. segmentHeader.deferredNonRetain = !!(flags & 0x80);
  14257. var pageAssociationFieldSize = !!(flags & 0x40);
  14258. var referredFlags = data[start + 5];
  14259. var referredToCount = referredFlags >> 5 & 7;
  14260. var retainBits = [referredFlags & 31];
  14261. var position = start + 6;
  14262. if (referredFlags === 7) {
  14263. referredToCount = readUint32(data, position - 1) & 0x1FFFFFFF;
  14264. position += 3;
  14265. var bytes = referredToCount + 7 >> 3;
  14266. retainBits[0] = data[position++];
  14267. while (--bytes > 0) {
  14268. retainBits.push(data[position++]);
  14269. }
  14270. } else if (referredFlags === 5 || referredFlags === 6) {
  14271. error('JBIG2 error: invalid referred-to flags');
  14272. }
  14273. segmentHeader.retainBits = retainBits;
  14274. var referredToSegmentNumberSize = segmentHeader.number <= 256 ? 1 : segmentHeader.number <= 65536 ? 2 : 4;
  14275. var referredTo = [];
  14276. var i, ii;
  14277. for (i = 0; i < referredToCount; i++) {
  14278. var number = referredToSegmentNumberSize === 1 ? data[position] : referredToSegmentNumberSize === 2 ? readUint16(data, position) : readUint32(data, position);
  14279. referredTo.push(number);
  14280. position += referredToSegmentNumberSize;
  14281. }
  14282. segmentHeader.referredTo = referredTo;
  14283. if (!pageAssociationFieldSize) {
  14284. segmentHeader.pageAssociation = data[position++];
  14285. } else {
  14286. segmentHeader.pageAssociation = readUint32(data, position);
  14287. position += 4;
  14288. }
  14289. segmentHeader.length = readUint32(data, position);
  14290. position += 4;
  14291. if (segmentHeader.length === 0xFFFFFFFF) {
  14292. // 7.2.7 Segment data length, unknown segment length
  14293. if (segmentType === 38) {
  14294. // ImmediateGenericRegion
  14295. var genericRegionInfo = readRegionSegmentInformation(data, position);
  14296. var genericRegionSegmentFlags = data[position + RegionSegmentInformationFieldLength];
  14297. var genericRegionMmr = !!(genericRegionSegmentFlags & 1);
  14298. // searching for the segment end
  14299. var searchPatternLength = 6;
  14300. var searchPattern = new Uint8Array(searchPatternLength);
  14301. if (!genericRegionMmr) {
  14302. searchPattern[0] = 0xFF;
  14303. searchPattern[1] = 0xAC;
  14304. }
  14305. searchPattern[2] = genericRegionInfo.height >>> 24 & 0xFF;
  14306. searchPattern[3] = genericRegionInfo.height >> 16 & 0xFF;
  14307. searchPattern[4] = genericRegionInfo.height >> 8 & 0xFF;
  14308. searchPattern[5] = genericRegionInfo.height & 0xFF;
  14309. for (i = position, ii = data.length; i < ii; i++) {
  14310. var j = 0;
  14311. while (j < searchPatternLength && searchPattern[j] === data[i + j]) {
  14312. j++;
  14313. }
  14314. if (j === searchPatternLength) {
  14315. segmentHeader.length = i + searchPatternLength;
  14316. break;
  14317. }
  14318. }
  14319. if (segmentHeader.length === 0xFFFFFFFF) {
  14320. error('JBIG2 error: segment end was not found');
  14321. }
  14322. } else {
  14323. error('JBIG2 error: invalid unknown segment length');
  14324. }
  14325. }
  14326. segmentHeader.headerEnd = position;
  14327. return segmentHeader;
  14328. }
  14329. function readSegments(header, data, start, end) {
  14330. var segments = [];
  14331. var position = start;
  14332. while (position < end) {
  14333. var segmentHeader = readSegmentHeader(data, position);
  14334. position = segmentHeader.headerEnd;
  14335. var segment = {
  14336. header: segmentHeader,
  14337. data: data
  14338. };
  14339. if (!header.randomAccess) {
  14340. segment.start = position;
  14341. position += segmentHeader.length;
  14342. segment.end = position;
  14343. }
  14344. segments.push(segment);
  14345. if (segmentHeader.type === 51) {
  14346. break;
  14347. }
  14348. }
  14349. // end of file is found
  14350. if (header.randomAccess) {
  14351. for (var i = 0, ii = segments.length; i < ii; i++) {
  14352. segments[i].start = position;
  14353. position += segments[i].header.length;
  14354. segments[i].end = position;
  14355. }
  14356. }
  14357. return segments;
  14358. }
  14359. // 7.4.1 Region segment information field
  14360. function readRegionSegmentInformation(data, start) {
  14361. return {
  14362. width: readUint32(data, start),
  14363. height: readUint32(data, start + 4),
  14364. x: readUint32(data, start + 8),
  14365. y: readUint32(data, start + 12),
  14366. combinationOperator: data[start + 16] & 7
  14367. };
  14368. }
  14369. var RegionSegmentInformationFieldLength = 17;
  14370. function processSegment(segment, visitor) {
  14371. var header = segment.header;
  14372. var data = segment.data, position = segment.start, end = segment.end;
  14373. var args, at, i, atLength;
  14374. switch (header.type) {
  14375. case 0:
  14376. // SymbolDictionary
  14377. // 7.4.2 Symbol dictionary segment syntax
  14378. var dictionary = {};
  14379. var dictionaryFlags = readUint16(data, position);
  14380. // 7.4.2.1.1
  14381. dictionary.huffman = !!(dictionaryFlags & 1);
  14382. dictionary.refinement = !!(dictionaryFlags & 2);
  14383. dictionary.huffmanDHSelector = dictionaryFlags >> 2 & 3;
  14384. dictionary.huffmanDWSelector = dictionaryFlags >> 4 & 3;
  14385. dictionary.bitmapSizeSelector = dictionaryFlags >> 6 & 1;
  14386. dictionary.aggregationInstancesSelector = dictionaryFlags >> 7 & 1;
  14387. dictionary.bitmapCodingContextUsed = !!(dictionaryFlags & 256);
  14388. dictionary.bitmapCodingContextRetained = !!(dictionaryFlags & 512);
  14389. dictionary.template = dictionaryFlags >> 10 & 3;
  14390. dictionary.refinementTemplate = dictionaryFlags >> 12 & 1;
  14391. position += 2;
  14392. if (!dictionary.huffman) {
  14393. atLength = dictionary.template === 0 ? 4 : 1;
  14394. at = [];
  14395. for (i = 0; i < atLength; i++) {
  14396. at.push({
  14397. x: readInt8(data, position),
  14398. y: readInt8(data, position + 1)
  14399. });
  14400. position += 2;
  14401. }
  14402. dictionary.at = at;
  14403. }
  14404. if (dictionary.refinement && !dictionary.refinementTemplate) {
  14405. at = [];
  14406. for (i = 0; i < 2; i++) {
  14407. at.push({
  14408. x: readInt8(data, position),
  14409. y: readInt8(data, position + 1)
  14410. });
  14411. position += 2;
  14412. }
  14413. dictionary.refinementAt = at;
  14414. }
  14415. dictionary.numberOfExportedSymbols = readUint32(data, position);
  14416. position += 4;
  14417. dictionary.numberOfNewSymbols = readUint32(data, position);
  14418. position += 4;
  14419. args = [
  14420. dictionary,
  14421. header.number,
  14422. header.referredTo,
  14423. data,
  14424. position,
  14425. end
  14426. ];
  14427. break;
  14428. case 6:
  14429. // ImmediateTextRegion
  14430. case 7:
  14431. // ImmediateLosslessTextRegion
  14432. var textRegion = {};
  14433. textRegion.info = readRegionSegmentInformation(data, position);
  14434. position += RegionSegmentInformationFieldLength;
  14435. var textRegionSegmentFlags = readUint16(data, position);
  14436. position += 2;
  14437. textRegion.huffman = !!(textRegionSegmentFlags & 1);
  14438. textRegion.refinement = !!(textRegionSegmentFlags & 2);
  14439. textRegion.stripSize = 1 << (textRegionSegmentFlags >> 2 & 3);
  14440. textRegion.referenceCorner = textRegionSegmentFlags >> 4 & 3;
  14441. textRegion.transposed = !!(textRegionSegmentFlags & 64);
  14442. textRegion.combinationOperator = textRegionSegmentFlags >> 7 & 3;
  14443. textRegion.defaultPixelValue = textRegionSegmentFlags >> 9 & 1;
  14444. textRegion.dsOffset = textRegionSegmentFlags << 17 >> 27;
  14445. textRegion.refinementTemplate = textRegionSegmentFlags >> 15 & 1;
  14446. if (textRegion.huffman) {
  14447. var textRegionHuffmanFlags = readUint16(data, position);
  14448. position += 2;
  14449. textRegion.huffmanFS = textRegionHuffmanFlags & 3;
  14450. textRegion.huffmanDS = textRegionHuffmanFlags >> 2 & 3;
  14451. textRegion.huffmanDT = textRegionHuffmanFlags >> 4 & 3;
  14452. textRegion.huffmanRefinementDW = textRegionHuffmanFlags >> 6 & 3;
  14453. textRegion.huffmanRefinementDH = textRegionHuffmanFlags >> 8 & 3;
  14454. textRegion.huffmanRefinementDX = textRegionHuffmanFlags >> 10 & 3;
  14455. textRegion.huffmanRefinementDY = textRegionHuffmanFlags >> 12 & 3;
  14456. textRegion.huffmanRefinementSizeSelector = !!(textRegionHuffmanFlags & 14);
  14457. }
  14458. if (textRegion.refinement && !textRegion.refinementTemplate) {
  14459. at = [];
  14460. for (i = 0; i < 2; i++) {
  14461. at.push({
  14462. x: readInt8(data, position),
  14463. y: readInt8(data, position + 1)
  14464. });
  14465. position += 2;
  14466. }
  14467. textRegion.refinementAt = at;
  14468. }
  14469. textRegion.numberOfSymbolInstances = readUint32(data, position);
  14470. position += 4;
  14471. // TODO 7.4.3.1.7 Symbol ID Huffman table decoding
  14472. if (textRegion.huffman) {
  14473. error('JBIG2 error: huffman is not supported');
  14474. }
  14475. args = [
  14476. textRegion,
  14477. header.referredTo,
  14478. data,
  14479. position,
  14480. end
  14481. ];
  14482. break;
  14483. case 38:
  14484. // ImmediateGenericRegion
  14485. case 39:
  14486. // ImmediateLosslessGenericRegion
  14487. var genericRegion = {};
  14488. genericRegion.info = readRegionSegmentInformation(data, position);
  14489. position += RegionSegmentInformationFieldLength;
  14490. var genericRegionSegmentFlags = data[position++];
  14491. genericRegion.mmr = !!(genericRegionSegmentFlags & 1);
  14492. genericRegion.template = genericRegionSegmentFlags >> 1 & 3;
  14493. genericRegion.prediction = !!(genericRegionSegmentFlags & 8);
  14494. if (!genericRegion.mmr) {
  14495. atLength = genericRegion.template === 0 ? 4 : 1;
  14496. at = [];
  14497. for (i = 0; i < atLength; i++) {
  14498. at.push({
  14499. x: readInt8(data, position),
  14500. y: readInt8(data, position + 1)
  14501. });
  14502. position += 2;
  14503. }
  14504. genericRegion.at = at;
  14505. }
  14506. args = [
  14507. genericRegion,
  14508. data,
  14509. position,
  14510. end
  14511. ];
  14512. break;
  14513. case 48:
  14514. // PageInformation
  14515. var pageInfo = {
  14516. width: readUint32(data, position),
  14517. height: readUint32(data, position + 4),
  14518. resolutionX: readUint32(data, position + 8),
  14519. resolutionY: readUint32(data, position + 12)
  14520. };
  14521. if (pageInfo.height === 0xFFFFFFFF) {
  14522. delete pageInfo.height;
  14523. }
  14524. var pageSegmentFlags = data[position + 16];
  14525. var pageStripingInformation = readUint16(data, position + 17);
  14526. pageInfo.lossless = !!(pageSegmentFlags & 1);
  14527. pageInfo.refinement = !!(pageSegmentFlags & 2);
  14528. pageInfo.defaultPixelValue = pageSegmentFlags >> 2 & 1;
  14529. pageInfo.combinationOperator = pageSegmentFlags >> 3 & 3;
  14530. pageInfo.requiresBuffer = !!(pageSegmentFlags & 32);
  14531. pageInfo.combinationOperatorOverride = !!(pageSegmentFlags & 64);
  14532. args = [pageInfo];
  14533. break;
  14534. case 49:
  14535. // EndOfPage
  14536. break;
  14537. case 50:
  14538. // EndOfStripe
  14539. break;
  14540. case 51:
  14541. // EndOfFile
  14542. break;
  14543. case 62:
  14544. // 7.4.15 defines 2 extension types which
  14545. // are comments and can be ignored.
  14546. break;
  14547. default:
  14548. error('JBIG2 error: segment type ' + header.typeName + '(' + header.type + ') is not implemented');
  14549. }
  14550. var callbackName = 'on' + header.typeName;
  14551. if (callbackName in visitor) {
  14552. visitor[callbackName].apply(visitor, args);
  14553. }
  14554. }
  14555. function processSegments(segments, visitor) {
  14556. for (var i = 0, ii = segments.length; i < ii; i++) {
  14557. processSegment(segments[i], visitor);
  14558. }
  14559. }
  14560. function parseJbig2(data, start, end) {
  14561. var position = start;
  14562. if (data[position] !== 0x97 || data[position + 1] !== 0x4A || data[position + 2] !== 0x42 || data[position + 3] !== 0x32 || data[position + 4] !== 0x0D || data[position + 5] !== 0x0A || data[position + 6] !== 0x1A || data[position + 7] !== 0x0A) {
  14563. error('JBIG2 error: invalid header');
  14564. }
  14565. var header = {};
  14566. position += 8;
  14567. var flags = data[position++];
  14568. header.randomAccess = !(flags & 1);
  14569. if (!(flags & 2)) {
  14570. header.numberOfPages = readUint32(data, position);
  14571. position += 4;
  14572. }
  14573. var segments = readSegments(header, data, position, end);
  14574. error('Not implemented');
  14575. }
  14576. // processSegments(segments, new SimpleSegmentVisitor());
  14577. function parseJbig2Chunks(chunks) {
  14578. var visitor = new SimpleSegmentVisitor();
  14579. for (var i = 0, ii = chunks.length; i < ii; i++) {
  14580. var chunk = chunks[i];
  14581. var segments = readSegments({}, chunk.data, chunk.start, chunk.end);
  14582. processSegments(segments, visitor);
  14583. }
  14584. return visitor.buffer;
  14585. }
  14586. function SimpleSegmentVisitor() {
  14587. }
  14588. SimpleSegmentVisitor.prototype = {
  14589. onPageInformation: function SimpleSegmentVisitor_onPageInformation(info) {
  14590. this.currentPageInfo = info;
  14591. var rowSize = info.width + 7 >> 3;
  14592. var buffer = new Uint8Array(rowSize * info.height);
  14593. // The contents of ArrayBuffers are initialized to 0.
  14594. // Fill the buffer with 0xFF only if info.defaultPixelValue is set
  14595. if (info.defaultPixelValue) {
  14596. for (var i = 0, ii = buffer.length; i < ii; i++) {
  14597. buffer[i] = 0xFF;
  14598. }
  14599. }
  14600. this.buffer = buffer;
  14601. },
  14602. drawBitmap: function SimpleSegmentVisitor_drawBitmap(regionInfo, bitmap) {
  14603. var pageInfo = this.currentPageInfo;
  14604. var width = regionInfo.width, height = regionInfo.height;
  14605. var rowSize = pageInfo.width + 7 >> 3;
  14606. var combinationOperator = pageInfo.combinationOperatorOverride ? regionInfo.combinationOperator : pageInfo.combinationOperator;
  14607. var buffer = this.buffer;
  14608. var mask0 = 128 >> (regionInfo.x & 7);
  14609. var offset0 = regionInfo.y * rowSize + (regionInfo.x >> 3);
  14610. var i, j, mask, offset;
  14611. switch (combinationOperator) {
  14612. case 0:
  14613. // OR
  14614. for (i = 0; i < height; i++) {
  14615. mask = mask0;
  14616. offset = offset0;
  14617. for (j = 0; j < width; j++) {
  14618. if (bitmap[i][j]) {
  14619. buffer[offset] |= mask;
  14620. }
  14621. mask >>= 1;
  14622. if (!mask) {
  14623. mask = 128;
  14624. offset++;
  14625. }
  14626. }
  14627. offset0 += rowSize;
  14628. }
  14629. break;
  14630. case 2:
  14631. // XOR
  14632. for (i = 0; i < height; i++) {
  14633. mask = mask0;
  14634. offset = offset0;
  14635. for (j = 0; j < width; j++) {
  14636. if (bitmap[i][j]) {
  14637. buffer[offset] ^= mask;
  14638. }
  14639. mask >>= 1;
  14640. if (!mask) {
  14641. mask = 128;
  14642. offset++;
  14643. }
  14644. }
  14645. offset0 += rowSize;
  14646. }
  14647. break;
  14648. default:
  14649. error('JBIG2 error: operator ' + combinationOperator + ' is not supported');
  14650. }
  14651. },
  14652. onImmediateGenericRegion: function SimpleSegmentVisitor_onImmediateGenericRegion(region, data, start, end) {
  14653. var regionInfo = region.info;
  14654. var decodingContext = new DecodingContext(data, start, end);
  14655. var bitmap = decodeBitmap(region.mmr, regionInfo.width, regionInfo.height, region.template, region.prediction, null, region.at, decodingContext);
  14656. this.drawBitmap(regionInfo, bitmap);
  14657. },
  14658. onImmediateLosslessGenericRegion: function SimpleSegmentVisitor_onImmediateLosslessGenericRegion() {
  14659. this.onImmediateGenericRegion.apply(this, arguments);
  14660. },
  14661. onSymbolDictionary: function SimpleSegmentVisitor_onSymbolDictionary(dictionary, currentSegment, referredSegments, data, start, end) {
  14662. var huffmanTables;
  14663. if (dictionary.huffman) {
  14664. error('JBIG2 error: huffman is not supported');
  14665. }
  14666. // Combines exported symbols from all referred segments
  14667. var symbols = this.symbols;
  14668. if (!symbols) {
  14669. this.symbols = symbols = {};
  14670. }
  14671. var inputSymbols = [];
  14672. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  14673. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  14674. }
  14675. var decodingContext = new DecodingContext(data, start, end);
  14676. symbols[currentSegment] = decodeSymbolDictionary(dictionary.huffman, dictionary.refinement, inputSymbols, dictionary.numberOfNewSymbols, dictionary.numberOfExportedSymbols, huffmanTables, dictionary.template, dictionary.at, dictionary.refinementTemplate, dictionary.refinementAt, decodingContext);
  14677. },
  14678. onImmediateTextRegion: function SimpleSegmentVisitor_onImmediateTextRegion(region, referredSegments, data, start, end) {
  14679. var regionInfo = region.info;
  14680. var huffmanTables;
  14681. // Combines exported symbols from all referred segments
  14682. var symbols = this.symbols;
  14683. var inputSymbols = [];
  14684. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  14685. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  14686. }
  14687. var symbolCodeLength = log2(inputSymbols.length);
  14688. var decodingContext = new DecodingContext(data, start, end);
  14689. var bitmap = decodeTextRegion(region.huffman, region.refinement, regionInfo.width, regionInfo.height, region.defaultPixelValue, region.numberOfSymbolInstances, region.stripSize, inputSymbols, symbolCodeLength, region.transposed, region.dsOffset, region.referenceCorner, region.combinationOperator, huffmanTables, region.refinementTemplate, region.refinementAt, decodingContext);
  14690. this.drawBitmap(regionInfo, bitmap);
  14691. },
  14692. onImmediateLosslessTextRegion: function SimpleSegmentVisitor_onImmediateLosslessTextRegion() {
  14693. this.onImmediateTextRegion.apply(this, arguments);
  14694. }
  14695. };
  14696. function Jbig2Image() {
  14697. }
  14698. Jbig2Image.prototype = {
  14699. parseChunks: function Jbig2Image_parseChunks(chunks) {
  14700. return parseJbig2Chunks(chunks);
  14701. }
  14702. };
  14703. return Jbig2Image;
  14704. }();
  14705. exports.Jbig2Image = Jbig2Image;
  14706. }));
  14707. (function (root, factory) {
  14708. factory(root.pdfjsCoreJpg = {}, root.pdfjsSharedUtil);
  14709. }(this, function (exports, sharedUtil) {
  14710. var error = sharedUtil.error;
  14711. /**
  14712. * This code was forked from https://github.com/notmasteryet/jpgjs.
  14713. * The original version was created by GitHub user notmasteryet.
  14714. *
  14715. * - The JPEG specification can be found in the ITU CCITT Recommendation T.81
  14716. * (www.w3.org/Graphics/JPEG/itu-t81.pdf)
  14717. * - The JFIF specification can be found in the JPEG File Interchange Format
  14718. * (www.w3.org/Graphics/JPEG/jfif3.pdf)
  14719. * - The Adobe Application-Specific JPEG markers in the
  14720. * Supporting the DCT Filters in PostScript Level 2, Technical Note #5116
  14721. * (partners.adobe.com/public/developer/en/ps/sdk/5116.DCT_Filter.pdf)
  14722. */
  14723. var JpegImage = function JpegImageClosure() {
  14724. var dctZigZag = new Uint8Array([
  14725. 0,
  14726. 1,
  14727. 8,
  14728. 16,
  14729. 9,
  14730. 2,
  14731. 3,
  14732. 10,
  14733. 17,
  14734. 24,
  14735. 32,
  14736. 25,
  14737. 18,
  14738. 11,
  14739. 4,
  14740. 5,
  14741. 12,
  14742. 19,
  14743. 26,
  14744. 33,
  14745. 40,
  14746. 48,
  14747. 41,
  14748. 34,
  14749. 27,
  14750. 20,
  14751. 13,
  14752. 6,
  14753. 7,
  14754. 14,
  14755. 21,
  14756. 28,
  14757. 35,
  14758. 42,
  14759. 49,
  14760. 56,
  14761. 57,
  14762. 50,
  14763. 43,
  14764. 36,
  14765. 29,
  14766. 22,
  14767. 15,
  14768. 23,
  14769. 30,
  14770. 37,
  14771. 44,
  14772. 51,
  14773. 58,
  14774. 59,
  14775. 52,
  14776. 45,
  14777. 38,
  14778. 31,
  14779. 39,
  14780. 46,
  14781. 53,
  14782. 60,
  14783. 61,
  14784. 54,
  14785. 47,
  14786. 55,
  14787. 62,
  14788. 63
  14789. ]);
  14790. var dctCos1 = 4017;
  14791. // cos(pi/16)
  14792. var dctSin1 = 799;
  14793. // sin(pi/16)
  14794. var dctCos3 = 3406;
  14795. // cos(3*pi/16)
  14796. var dctSin3 = 2276;
  14797. // sin(3*pi/16)
  14798. var dctCos6 = 1567;
  14799. // cos(6*pi/16)
  14800. var dctSin6 = 3784;
  14801. // sin(6*pi/16)
  14802. var dctSqrt2 = 5793;
  14803. // sqrt(2)
  14804. var dctSqrt1d2 = 2896;
  14805. // sqrt(2) / 2
  14806. function JpegImage() {
  14807. this.decodeTransform = null;
  14808. this.colorTransform = -1;
  14809. }
  14810. function buildHuffmanTable(codeLengths, values) {
  14811. var k = 0, code = [], i, j, length = 16;
  14812. while (length > 0 && !codeLengths[length - 1]) {
  14813. length--;
  14814. }
  14815. code.push({
  14816. children: [],
  14817. index: 0
  14818. });
  14819. var p = code[0], q;
  14820. for (i = 0; i < length; i++) {
  14821. for (j = 0; j < codeLengths[i]; j++) {
  14822. p = code.pop();
  14823. p.children[p.index] = values[k];
  14824. while (p.index > 0) {
  14825. p = code.pop();
  14826. }
  14827. p.index++;
  14828. code.push(p);
  14829. while (code.length <= i) {
  14830. code.push(q = {
  14831. children: [],
  14832. index: 0
  14833. });
  14834. p.children[p.index] = q.children;
  14835. p = q;
  14836. }
  14837. k++;
  14838. }
  14839. if (i + 1 < length) {
  14840. // p here points to last code
  14841. code.push(q = {
  14842. children: [],
  14843. index: 0
  14844. });
  14845. p.children[p.index] = q.children;
  14846. p = q;
  14847. }
  14848. }
  14849. return code[0].children;
  14850. }
  14851. function getBlockBufferOffset(component, row, col) {
  14852. return 64 * ((component.blocksPerLine + 1) * row + col);
  14853. }
  14854. function decodeScan(data, offset, frame, components, resetInterval, spectralStart, spectralEnd, successivePrev, successive) {
  14855. var mcusPerLine = frame.mcusPerLine;
  14856. var progressive = frame.progressive;
  14857. var startOffset = offset, bitsData = 0, bitsCount = 0;
  14858. function readBit() {
  14859. if (bitsCount > 0) {
  14860. bitsCount--;
  14861. return bitsData >> bitsCount & 1;
  14862. }
  14863. bitsData = data[offset++];
  14864. if (bitsData === 0xFF) {
  14865. var nextByte = data[offset++];
  14866. if (nextByte) {
  14867. error('JPEG error: unexpected marker ' + (bitsData << 8 | nextByte).toString(16));
  14868. }
  14869. }
  14870. // unstuff 0
  14871. bitsCount = 7;
  14872. return bitsData >>> 7;
  14873. }
  14874. function decodeHuffman(tree) {
  14875. var node = tree;
  14876. while (true) {
  14877. node = node[readBit()];
  14878. if (typeof node === 'number') {
  14879. return node;
  14880. }
  14881. if (typeof node !== 'object') {
  14882. error('JPEG error: invalid huffman sequence');
  14883. }
  14884. }
  14885. }
  14886. function receive(length) {
  14887. var n = 0;
  14888. while (length > 0) {
  14889. n = n << 1 | readBit();
  14890. length--;
  14891. }
  14892. return n;
  14893. }
  14894. function receiveAndExtend(length) {
  14895. if (length === 1) {
  14896. return readBit() === 1 ? 1 : -1;
  14897. }
  14898. var n = receive(length);
  14899. if (n >= 1 << length - 1) {
  14900. return n;
  14901. }
  14902. return n + (-1 << length) + 1;
  14903. }
  14904. function decodeBaseline(component, offset) {
  14905. var t = decodeHuffman(component.huffmanTableDC);
  14906. var diff = t === 0 ? 0 : receiveAndExtend(t);
  14907. component.blockData[offset] = component.pred += diff;
  14908. var k = 1;
  14909. while (k < 64) {
  14910. var rs = decodeHuffman(component.huffmanTableAC);
  14911. var s = rs & 15, r = rs >> 4;
  14912. if (s === 0) {
  14913. if (r < 15) {
  14914. break;
  14915. }
  14916. k += 16;
  14917. continue;
  14918. }
  14919. k += r;
  14920. var z = dctZigZag[k];
  14921. component.blockData[offset + z] = receiveAndExtend(s);
  14922. k++;
  14923. }
  14924. }
  14925. function decodeDCFirst(component, offset) {
  14926. var t = decodeHuffman(component.huffmanTableDC);
  14927. var diff = t === 0 ? 0 : receiveAndExtend(t) << successive;
  14928. component.blockData[offset] = component.pred += diff;
  14929. }
  14930. function decodeDCSuccessive(component, offset) {
  14931. component.blockData[offset] |= readBit() << successive;
  14932. }
  14933. var eobrun = 0;
  14934. function decodeACFirst(component, offset) {
  14935. if (eobrun > 0) {
  14936. eobrun--;
  14937. return;
  14938. }
  14939. var k = spectralStart, e = spectralEnd;
  14940. while (k <= e) {
  14941. var rs = decodeHuffman(component.huffmanTableAC);
  14942. var s = rs & 15, r = rs >> 4;
  14943. if (s === 0) {
  14944. if (r < 15) {
  14945. eobrun = receive(r) + (1 << r) - 1;
  14946. break;
  14947. }
  14948. k += 16;
  14949. continue;
  14950. }
  14951. k += r;
  14952. var z = dctZigZag[k];
  14953. component.blockData[offset + z] = receiveAndExtend(s) * (1 << successive);
  14954. k++;
  14955. }
  14956. }
  14957. var successiveACState = 0, successiveACNextValue;
  14958. function decodeACSuccessive(component, offset) {
  14959. var k = spectralStart;
  14960. var e = spectralEnd;
  14961. var r = 0;
  14962. var s;
  14963. var rs;
  14964. while (k <= e) {
  14965. var z = dctZigZag[k];
  14966. switch (successiveACState) {
  14967. case 0:
  14968. // initial state
  14969. rs = decodeHuffman(component.huffmanTableAC);
  14970. s = rs & 15;
  14971. r = rs >> 4;
  14972. if (s === 0) {
  14973. if (r < 15) {
  14974. eobrun = receive(r) + (1 << r);
  14975. successiveACState = 4;
  14976. } else {
  14977. r = 16;
  14978. successiveACState = 1;
  14979. }
  14980. } else {
  14981. if (s !== 1) {
  14982. error('JPEG error: invalid ACn encoding');
  14983. }
  14984. successiveACNextValue = receiveAndExtend(s);
  14985. successiveACState = r ? 2 : 3;
  14986. }
  14987. continue;
  14988. case 1:
  14989. // skipping r zero items
  14990. case 2:
  14991. if (component.blockData[offset + z]) {
  14992. component.blockData[offset + z] += readBit() << successive;
  14993. } else {
  14994. r--;
  14995. if (r === 0) {
  14996. successiveACState = successiveACState === 2 ? 3 : 0;
  14997. }
  14998. }
  14999. break;
  15000. case 3:
  15001. // set value for a zero item
  15002. if (component.blockData[offset + z]) {
  15003. component.blockData[offset + z] += readBit() << successive;
  15004. } else {
  15005. component.blockData[offset + z] = successiveACNextValue << successive;
  15006. successiveACState = 0;
  15007. }
  15008. break;
  15009. case 4:
  15010. // eob
  15011. if (component.blockData[offset + z]) {
  15012. component.blockData[offset + z] += readBit() << successive;
  15013. }
  15014. break;
  15015. }
  15016. k++;
  15017. }
  15018. if (successiveACState === 4) {
  15019. eobrun--;
  15020. if (eobrun === 0) {
  15021. successiveACState = 0;
  15022. }
  15023. }
  15024. }
  15025. function decodeMcu(component, decode, mcu, row, col) {
  15026. var mcuRow = mcu / mcusPerLine | 0;
  15027. var mcuCol = mcu % mcusPerLine;
  15028. var blockRow = mcuRow * component.v + row;
  15029. var blockCol = mcuCol * component.h + col;
  15030. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  15031. decode(component, offset);
  15032. }
  15033. function decodeBlock(component, decode, mcu) {
  15034. var blockRow = mcu / component.blocksPerLine | 0;
  15035. var blockCol = mcu % component.blocksPerLine;
  15036. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  15037. decode(component, offset);
  15038. }
  15039. var componentsLength = components.length;
  15040. var component, i, j, k, n;
  15041. var decodeFn;
  15042. if (progressive) {
  15043. if (spectralStart === 0) {
  15044. decodeFn = successivePrev === 0 ? decodeDCFirst : decodeDCSuccessive;
  15045. } else {
  15046. decodeFn = successivePrev === 0 ? decodeACFirst : decodeACSuccessive;
  15047. }
  15048. } else {
  15049. decodeFn = decodeBaseline;
  15050. }
  15051. var mcu = 0, marker;
  15052. var mcuExpected;
  15053. if (componentsLength === 1) {
  15054. mcuExpected = components[0].blocksPerLine * components[0].blocksPerColumn;
  15055. } else {
  15056. mcuExpected = mcusPerLine * frame.mcusPerColumn;
  15057. }
  15058. if (!resetInterval) {
  15059. resetInterval = mcuExpected;
  15060. }
  15061. var h, v;
  15062. while (mcu < mcuExpected) {
  15063. // reset interval stuff
  15064. for (i = 0; i < componentsLength; i++) {
  15065. components[i].pred = 0;
  15066. }
  15067. eobrun = 0;
  15068. if (componentsLength === 1) {
  15069. component = components[0];
  15070. for (n = 0; n < resetInterval; n++) {
  15071. decodeBlock(component, decodeFn, mcu);
  15072. mcu++;
  15073. }
  15074. } else {
  15075. for (n = 0; n < resetInterval; n++) {
  15076. for (i = 0; i < componentsLength; i++) {
  15077. component = components[i];
  15078. h = component.h;
  15079. v = component.v;
  15080. for (j = 0; j < v; j++) {
  15081. for (k = 0; k < h; k++) {
  15082. decodeMcu(component, decodeFn, mcu, j, k);
  15083. }
  15084. }
  15085. }
  15086. mcu++;
  15087. }
  15088. }
  15089. // find marker
  15090. bitsCount = 0;
  15091. marker = data[offset] << 8 | data[offset + 1];
  15092. // Some bad images seem to pad Scan blocks with zero bytes, skip past
  15093. // those to attempt to find a valid marker (fixes issue4090.pdf).
  15094. while (data[offset] === 0x00 && offset < data.length - 1) {
  15095. offset++;
  15096. marker = data[offset] << 8 | data[offset + 1];
  15097. }
  15098. if (marker <= 0xFF00) {
  15099. error('JPEG error: marker was not found');
  15100. }
  15101. if (marker >= 0xFFD0 && marker <= 0xFFD7) {
  15102. // RSTx
  15103. offset += 2;
  15104. } else {
  15105. break;
  15106. }
  15107. }
  15108. return offset - startOffset;
  15109. }
  15110. // A port of poppler's IDCT method which in turn is taken from:
  15111. // Christoph Loeffler, Adriaan Ligtenberg, George S. Moschytz,
  15112. // 'Practical Fast 1-D DCT Algorithms with 11 Multiplications',
  15113. // IEEE Intl. Conf. on Acoustics, Speech & Signal Processing, 1989,
  15114. // 988-991.
  15115. function quantizeAndInverse(component, blockBufferOffset, p) {
  15116. var qt = component.quantizationTable, blockData = component.blockData;
  15117. var v0, v1, v2, v3, v4, v5, v6, v7;
  15118. var p0, p1, p2, p3, p4, p5, p6, p7;
  15119. var t;
  15120. if (!qt) {
  15121. error('JPEG error: missing required Quantization Table.');
  15122. }
  15123. // inverse DCT on rows
  15124. for (var row = 0; row < 64; row += 8) {
  15125. // gather block data
  15126. p0 = blockData[blockBufferOffset + row];
  15127. p1 = blockData[blockBufferOffset + row + 1];
  15128. p2 = blockData[blockBufferOffset + row + 2];
  15129. p3 = blockData[blockBufferOffset + row + 3];
  15130. p4 = blockData[blockBufferOffset + row + 4];
  15131. p5 = blockData[blockBufferOffset + row + 5];
  15132. p6 = blockData[blockBufferOffset + row + 6];
  15133. p7 = blockData[blockBufferOffset + row + 7];
  15134. // dequant p0
  15135. p0 *= qt[row];
  15136. // check for all-zero AC coefficients
  15137. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  15138. t = dctSqrt2 * p0 + 512 >> 10;
  15139. p[row] = t;
  15140. p[row + 1] = t;
  15141. p[row + 2] = t;
  15142. p[row + 3] = t;
  15143. p[row + 4] = t;
  15144. p[row + 5] = t;
  15145. p[row + 6] = t;
  15146. p[row + 7] = t;
  15147. continue;
  15148. }
  15149. // dequant p1 ... p7
  15150. p1 *= qt[row + 1];
  15151. p2 *= qt[row + 2];
  15152. p3 *= qt[row + 3];
  15153. p4 *= qt[row + 4];
  15154. p5 *= qt[row + 5];
  15155. p6 *= qt[row + 6];
  15156. p7 *= qt[row + 7];
  15157. // stage 4
  15158. v0 = dctSqrt2 * p0 + 128 >> 8;
  15159. v1 = dctSqrt2 * p4 + 128 >> 8;
  15160. v2 = p2;
  15161. v3 = p6;
  15162. v4 = dctSqrt1d2 * (p1 - p7) + 128 >> 8;
  15163. v7 = dctSqrt1d2 * (p1 + p7) + 128 >> 8;
  15164. v5 = p3 << 4;
  15165. v6 = p5 << 4;
  15166. // stage 3
  15167. v0 = v0 + v1 + 1 >> 1;
  15168. v1 = v0 - v1;
  15169. t = v2 * dctSin6 + v3 * dctCos6 + 128 >> 8;
  15170. v2 = v2 * dctCos6 - v3 * dctSin6 + 128 >> 8;
  15171. v3 = t;
  15172. v4 = v4 + v6 + 1 >> 1;
  15173. v6 = v4 - v6;
  15174. v7 = v7 + v5 + 1 >> 1;
  15175. v5 = v7 - v5;
  15176. // stage 2
  15177. v0 = v0 + v3 + 1 >> 1;
  15178. v3 = v0 - v3;
  15179. v1 = v1 + v2 + 1 >> 1;
  15180. v2 = v1 - v2;
  15181. t = v4 * dctSin3 + v7 * dctCos3 + 2048 >> 12;
  15182. v4 = v4 * dctCos3 - v7 * dctSin3 + 2048 >> 12;
  15183. v7 = t;
  15184. t = v5 * dctSin1 + v6 * dctCos1 + 2048 >> 12;
  15185. v5 = v5 * dctCos1 - v6 * dctSin1 + 2048 >> 12;
  15186. v6 = t;
  15187. // stage 1
  15188. p[row] = v0 + v7;
  15189. p[row + 7] = v0 - v7;
  15190. p[row + 1] = v1 + v6;
  15191. p[row + 6] = v1 - v6;
  15192. p[row + 2] = v2 + v5;
  15193. p[row + 5] = v2 - v5;
  15194. p[row + 3] = v3 + v4;
  15195. p[row + 4] = v3 - v4;
  15196. }
  15197. // inverse DCT on columns
  15198. for (var col = 0; col < 8; ++col) {
  15199. p0 = p[col];
  15200. p1 = p[col + 8];
  15201. p2 = p[col + 16];
  15202. p3 = p[col + 24];
  15203. p4 = p[col + 32];
  15204. p5 = p[col + 40];
  15205. p6 = p[col + 48];
  15206. p7 = p[col + 56];
  15207. // check for all-zero AC coefficients
  15208. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  15209. t = dctSqrt2 * p0 + 8192 >> 14;
  15210. // convert to 8 bit
  15211. t = t < -2040 ? 0 : t >= 2024 ? 255 : t + 2056 >> 4;
  15212. blockData[blockBufferOffset + col] = t;
  15213. blockData[blockBufferOffset + col + 8] = t;
  15214. blockData[blockBufferOffset + col + 16] = t;
  15215. blockData[blockBufferOffset + col + 24] = t;
  15216. blockData[blockBufferOffset + col + 32] = t;
  15217. blockData[blockBufferOffset + col + 40] = t;
  15218. blockData[blockBufferOffset + col + 48] = t;
  15219. blockData[blockBufferOffset + col + 56] = t;
  15220. continue;
  15221. }
  15222. // stage 4
  15223. v0 = dctSqrt2 * p0 + 2048 >> 12;
  15224. v1 = dctSqrt2 * p4 + 2048 >> 12;
  15225. v2 = p2;
  15226. v3 = p6;
  15227. v4 = dctSqrt1d2 * (p1 - p7) + 2048 >> 12;
  15228. v7 = dctSqrt1d2 * (p1 + p7) + 2048 >> 12;
  15229. v5 = p3;
  15230. v6 = p5;
  15231. // stage 3
  15232. // Shift v0 by 128.5 << 5 here, so we don't need to shift p0...p7 when
  15233. // converting to UInt8 range later.
  15234. v0 = (v0 + v1 + 1 >> 1) + 4112;
  15235. v1 = v0 - v1;
  15236. t = v2 * dctSin6 + v3 * dctCos6 + 2048 >> 12;
  15237. v2 = v2 * dctCos6 - v3 * dctSin6 + 2048 >> 12;
  15238. v3 = t;
  15239. v4 = v4 + v6 + 1 >> 1;
  15240. v6 = v4 - v6;
  15241. v7 = v7 + v5 + 1 >> 1;
  15242. v5 = v7 - v5;
  15243. // stage 2
  15244. v0 = v0 + v3 + 1 >> 1;
  15245. v3 = v0 - v3;
  15246. v1 = v1 + v2 + 1 >> 1;
  15247. v2 = v1 - v2;
  15248. t = v4 * dctSin3 + v7 * dctCos3 + 2048 >> 12;
  15249. v4 = v4 * dctCos3 - v7 * dctSin3 + 2048 >> 12;
  15250. v7 = t;
  15251. t = v5 * dctSin1 + v6 * dctCos1 + 2048 >> 12;
  15252. v5 = v5 * dctCos1 - v6 * dctSin1 + 2048 >> 12;
  15253. v6 = t;
  15254. // stage 1
  15255. p0 = v0 + v7;
  15256. p7 = v0 - v7;
  15257. p1 = v1 + v6;
  15258. p6 = v1 - v6;
  15259. p2 = v2 + v5;
  15260. p5 = v2 - v5;
  15261. p3 = v3 + v4;
  15262. p4 = v3 - v4;
  15263. // convert to 8-bit integers
  15264. p0 = p0 < 16 ? 0 : p0 >= 4080 ? 255 : p0 >> 4;
  15265. p1 = p1 < 16 ? 0 : p1 >= 4080 ? 255 : p1 >> 4;
  15266. p2 = p2 < 16 ? 0 : p2 >= 4080 ? 255 : p2 >> 4;
  15267. p3 = p3 < 16 ? 0 : p3 >= 4080 ? 255 : p3 >> 4;
  15268. p4 = p4 < 16 ? 0 : p4 >= 4080 ? 255 : p4 >> 4;
  15269. p5 = p5 < 16 ? 0 : p5 >= 4080 ? 255 : p5 >> 4;
  15270. p6 = p6 < 16 ? 0 : p6 >= 4080 ? 255 : p6 >> 4;
  15271. p7 = p7 < 16 ? 0 : p7 >= 4080 ? 255 : p7 >> 4;
  15272. // store block data
  15273. blockData[blockBufferOffset + col] = p0;
  15274. blockData[blockBufferOffset + col + 8] = p1;
  15275. blockData[blockBufferOffset + col + 16] = p2;
  15276. blockData[blockBufferOffset + col + 24] = p3;
  15277. blockData[blockBufferOffset + col + 32] = p4;
  15278. blockData[blockBufferOffset + col + 40] = p5;
  15279. blockData[blockBufferOffset + col + 48] = p6;
  15280. blockData[blockBufferOffset + col + 56] = p7;
  15281. }
  15282. }
  15283. function buildComponentData(frame, component) {
  15284. var blocksPerLine = component.blocksPerLine;
  15285. var blocksPerColumn = component.blocksPerColumn;
  15286. var computationBuffer = new Int16Array(64);
  15287. for (var blockRow = 0; blockRow < blocksPerColumn; blockRow++) {
  15288. for (var blockCol = 0; blockCol < blocksPerLine; blockCol++) {
  15289. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  15290. quantizeAndInverse(component, offset, computationBuffer);
  15291. }
  15292. }
  15293. return component.blockData;
  15294. }
  15295. function clamp0to255(a) {
  15296. return a <= 0 ? 0 : a >= 255 ? 255 : a;
  15297. }
  15298. JpegImage.prototype = {
  15299. parse: function parse(data) {
  15300. function readUint16() {
  15301. var value = data[offset] << 8 | data[offset + 1];
  15302. offset += 2;
  15303. return value;
  15304. }
  15305. function readDataBlock() {
  15306. var length = readUint16();
  15307. var array = data.subarray(offset, offset + length - 2);
  15308. offset += array.length;
  15309. return array;
  15310. }
  15311. function prepareComponents(frame) {
  15312. var mcusPerLine = Math.ceil(frame.samplesPerLine / 8 / frame.maxH);
  15313. var mcusPerColumn = Math.ceil(frame.scanLines / 8 / frame.maxV);
  15314. for (var i = 0; i < frame.components.length; i++) {
  15315. component = frame.components[i];
  15316. var blocksPerLine = Math.ceil(Math.ceil(frame.samplesPerLine / 8) * component.h / frame.maxH);
  15317. var blocksPerColumn = Math.ceil(Math.ceil(frame.scanLines / 8) * component.v / frame.maxV);
  15318. var blocksPerLineForMcu = mcusPerLine * component.h;
  15319. var blocksPerColumnForMcu = mcusPerColumn * component.v;
  15320. var blocksBufferSize = 64 * blocksPerColumnForMcu * (blocksPerLineForMcu + 1);
  15321. component.blockData = new Int16Array(blocksBufferSize);
  15322. component.blocksPerLine = blocksPerLine;
  15323. component.blocksPerColumn = blocksPerColumn;
  15324. }
  15325. frame.mcusPerLine = mcusPerLine;
  15326. frame.mcusPerColumn = mcusPerColumn;
  15327. }
  15328. var offset = 0;
  15329. var jfif = null;
  15330. var adobe = null;
  15331. var frame, resetInterval;
  15332. var quantizationTables = [];
  15333. var huffmanTablesAC = [], huffmanTablesDC = [];
  15334. var fileMarker = readUint16();
  15335. if (fileMarker !== 0xFFD8) {
  15336. // SOI (Start of Image)
  15337. error('JPEG error: SOI not found');
  15338. }
  15339. fileMarker = readUint16();
  15340. while (fileMarker !== 0xFFD9) {
  15341. // EOI (End of image)
  15342. var i, j, l;
  15343. switch (fileMarker) {
  15344. case 0xFFE0:
  15345. // APP0 (Application Specific)
  15346. case 0xFFE1:
  15347. // APP1
  15348. case 0xFFE2:
  15349. // APP2
  15350. case 0xFFE3:
  15351. // APP3
  15352. case 0xFFE4:
  15353. // APP4
  15354. case 0xFFE5:
  15355. // APP5
  15356. case 0xFFE6:
  15357. // APP6
  15358. case 0xFFE7:
  15359. // APP7
  15360. case 0xFFE8:
  15361. // APP8
  15362. case 0xFFE9:
  15363. // APP9
  15364. case 0xFFEA:
  15365. // APP10
  15366. case 0xFFEB:
  15367. // APP11
  15368. case 0xFFEC:
  15369. // APP12
  15370. case 0xFFED:
  15371. // APP13
  15372. case 0xFFEE:
  15373. // APP14
  15374. case 0xFFEF:
  15375. // APP15
  15376. case 0xFFFE:
  15377. // COM (Comment)
  15378. var appData = readDataBlock();
  15379. if (fileMarker === 0xFFE0) {
  15380. if (appData[0] === 0x4A && appData[1] === 0x46 && appData[2] === 0x49 && appData[3] === 0x46 && appData[4] === 0) {
  15381. // 'JFIF\x00'
  15382. jfif = {
  15383. version: {
  15384. major: appData[5],
  15385. minor: appData[6]
  15386. },
  15387. densityUnits: appData[7],
  15388. xDensity: appData[8] << 8 | appData[9],
  15389. yDensity: appData[10] << 8 | appData[11],
  15390. thumbWidth: appData[12],
  15391. thumbHeight: appData[13],
  15392. thumbData: appData.subarray(14, 14 + 3 * appData[12] * appData[13])
  15393. };
  15394. }
  15395. }
  15396. // TODO APP1 - Exif
  15397. if (fileMarker === 0xFFEE) {
  15398. if (appData[0] === 0x41 && appData[1] === 0x64 && appData[2] === 0x6F && appData[3] === 0x62 && appData[4] === 0x65) {
  15399. // 'Adobe'
  15400. adobe = {
  15401. version: appData[5] << 8 | appData[6],
  15402. flags0: appData[7] << 8 | appData[8],
  15403. flags1: appData[9] << 8 | appData[10],
  15404. transformCode: appData[11]
  15405. };
  15406. }
  15407. }
  15408. break;
  15409. case 0xFFDB:
  15410. // DQT (Define Quantization Tables)
  15411. var quantizationTablesLength = readUint16();
  15412. var quantizationTablesEnd = quantizationTablesLength + offset - 2;
  15413. var z;
  15414. while (offset < quantizationTablesEnd) {
  15415. var quantizationTableSpec = data[offset++];
  15416. var tableData = new Uint16Array(64);
  15417. if (quantizationTableSpec >> 4 === 0) {
  15418. // 8 bit values
  15419. for (j = 0; j < 64; j++) {
  15420. z = dctZigZag[j];
  15421. tableData[z] = data[offset++];
  15422. }
  15423. } else if (quantizationTableSpec >> 4 === 1) {
  15424. //16 bit
  15425. for (j = 0; j < 64; j++) {
  15426. z = dctZigZag[j];
  15427. tableData[z] = readUint16();
  15428. }
  15429. } else {
  15430. error('JPEG error: DQT - invalid table spec');
  15431. }
  15432. quantizationTables[quantizationTableSpec & 15] = tableData;
  15433. }
  15434. break;
  15435. case 0xFFC0:
  15436. // SOF0 (Start of Frame, Baseline DCT)
  15437. case 0xFFC1:
  15438. // SOF1 (Start of Frame, Extended DCT)
  15439. case 0xFFC2:
  15440. // SOF2 (Start of Frame, Progressive DCT)
  15441. if (frame) {
  15442. error('JPEG error: Only single frame JPEGs supported');
  15443. }
  15444. readUint16();
  15445. // skip data length
  15446. frame = {};
  15447. frame.extended = fileMarker === 0xFFC1;
  15448. frame.progressive = fileMarker === 0xFFC2;
  15449. frame.precision = data[offset++];
  15450. frame.scanLines = readUint16();
  15451. frame.samplesPerLine = readUint16();
  15452. frame.components = [];
  15453. frame.componentIds = {};
  15454. var componentsCount = data[offset++], componentId;
  15455. var maxH = 0, maxV = 0;
  15456. for (i = 0; i < componentsCount; i++) {
  15457. componentId = data[offset];
  15458. var h = data[offset + 1] >> 4;
  15459. var v = data[offset + 1] & 15;
  15460. if (maxH < h) {
  15461. maxH = h;
  15462. }
  15463. if (maxV < v) {
  15464. maxV = v;
  15465. }
  15466. var qId = data[offset + 2];
  15467. l = frame.components.push({
  15468. h: h,
  15469. v: v,
  15470. quantizationId: qId,
  15471. quantizationTable: null
  15472. });
  15473. // See comment below.
  15474. frame.componentIds[componentId] = l - 1;
  15475. offset += 3;
  15476. }
  15477. frame.maxH = maxH;
  15478. frame.maxV = maxV;
  15479. prepareComponents(frame);
  15480. break;
  15481. case 0xFFC4:
  15482. // DHT (Define Huffman Tables)
  15483. var huffmanLength = readUint16();
  15484. for (i = 2; i < huffmanLength;) {
  15485. var huffmanTableSpec = data[offset++];
  15486. var codeLengths = new Uint8Array(16);
  15487. var codeLengthSum = 0;
  15488. for (j = 0; j < 16; j++, offset++) {
  15489. codeLengthSum += codeLengths[j] = data[offset];
  15490. }
  15491. var huffmanValues = new Uint8Array(codeLengthSum);
  15492. for (j = 0; j < codeLengthSum; j++, offset++) {
  15493. huffmanValues[j] = data[offset];
  15494. }
  15495. i += 17 + codeLengthSum;
  15496. (huffmanTableSpec >> 4 === 0 ? huffmanTablesDC : huffmanTablesAC)[huffmanTableSpec & 15] = buildHuffmanTable(codeLengths, huffmanValues);
  15497. }
  15498. break;
  15499. case 0xFFDD:
  15500. // DRI (Define Restart Interval)
  15501. readUint16();
  15502. // skip data length
  15503. resetInterval = readUint16();
  15504. break;
  15505. case 0xFFDA:
  15506. // SOS (Start of Scan)
  15507. var scanLength = readUint16();
  15508. var selectorsCount = data[offset++];
  15509. var components = [], component;
  15510. for (i = 0; i < selectorsCount; i++) {
  15511. var componentIndex = frame.componentIds[data[offset++]];
  15512. component = frame.components[componentIndex];
  15513. var tableSpec = data[offset++];
  15514. component.huffmanTableDC = huffmanTablesDC[tableSpec >> 4];
  15515. component.huffmanTableAC = huffmanTablesAC[tableSpec & 15];
  15516. components.push(component);
  15517. }
  15518. var spectralStart = data[offset++];
  15519. var spectralEnd = data[offset++];
  15520. var successiveApproximation = data[offset++];
  15521. var processed = decodeScan(data, offset, frame, components, resetInterval, spectralStart, spectralEnd, successiveApproximation >> 4, successiveApproximation & 15);
  15522. offset += processed;
  15523. break;
  15524. case 0xFFFF:
  15525. // Fill bytes
  15526. if (data[offset] !== 0xFF) {
  15527. // Avoid skipping a valid marker.
  15528. offset--;
  15529. }
  15530. break;
  15531. default:
  15532. if (data[offset - 3] === 0xFF && data[offset - 2] >= 0xC0 && data[offset - 2] <= 0xFE) {
  15533. // could be incorrect encoding -- last 0xFF byte of the previous
  15534. // block was eaten by the encoder
  15535. offset -= 3;
  15536. break;
  15537. }
  15538. error('JPEG error: unknown marker ' + fileMarker.toString(16));
  15539. }
  15540. fileMarker = readUint16();
  15541. }
  15542. this.width = frame.samplesPerLine;
  15543. this.height = frame.scanLines;
  15544. this.jfif = jfif;
  15545. this.adobe = adobe;
  15546. this.components = [];
  15547. for (i = 0; i < frame.components.length; i++) {
  15548. component = frame.components[i];
  15549. // Prevent errors when DQT markers are placed after SOF{n} markers,
  15550. // by assigning the `quantizationTable` entry after the entire image
  15551. // has been parsed (fixes issue7406.pdf).
  15552. var quantizationTable = quantizationTables[component.quantizationId];
  15553. if (quantizationTable) {
  15554. component.quantizationTable = quantizationTable;
  15555. }
  15556. this.components.push({
  15557. output: buildComponentData(frame, component),
  15558. scaleX: component.h / frame.maxH,
  15559. scaleY: component.v / frame.maxV,
  15560. blocksPerLine: component.blocksPerLine,
  15561. blocksPerColumn: component.blocksPerColumn
  15562. });
  15563. }
  15564. this.numComponents = this.components.length;
  15565. },
  15566. _getLinearizedBlockData: function getLinearizedBlockData(width, height) {
  15567. var scaleX = this.width / width, scaleY = this.height / height;
  15568. var component, componentScaleX, componentScaleY, blocksPerScanline;
  15569. var x, y, i, j, k;
  15570. var index;
  15571. var offset = 0;
  15572. var output;
  15573. var numComponents = this.components.length;
  15574. var dataLength = width * height * numComponents;
  15575. var data = new Uint8Array(dataLength);
  15576. var xScaleBlockOffset = new Uint32Array(width);
  15577. var mask3LSB = 0xfffffff8;
  15578. // used to clear the 3 LSBs
  15579. for (i = 0; i < numComponents; i++) {
  15580. component = this.components[i];
  15581. componentScaleX = component.scaleX * scaleX;
  15582. componentScaleY = component.scaleY * scaleY;
  15583. offset = i;
  15584. output = component.output;
  15585. blocksPerScanline = component.blocksPerLine + 1 << 3;
  15586. // precalculate the xScaleBlockOffset
  15587. for (x = 0; x < width; x++) {
  15588. j = 0 | x * componentScaleX;
  15589. xScaleBlockOffset[x] = (j & mask3LSB) << 3 | j & 7;
  15590. }
  15591. // linearize the blocks of the component
  15592. for (y = 0; y < height; y++) {
  15593. j = 0 | y * componentScaleY;
  15594. index = blocksPerScanline * (j & mask3LSB) | (j & 7) << 3;
  15595. for (x = 0; x < width; x++) {
  15596. data[offset] = output[index + xScaleBlockOffset[x]];
  15597. offset += numComponents;
  15598. }
  15599. }
  15600. }
  15601. // decodeTransform contains pairs of multiplier (-256..256) and additive
  15602. var transform = this.decodeTransform;
  15603. if (transform) {
  15604. for (i = 0; i < dataLength;) {
  15605. for (j = 0, k = 0; j < numComponents; j++, i++, k += 2) {
  15606. data[i] = (data[i] * transform[k] >> 8) + transform[k + 1];
  15607. }
  15608. }
  15609. }
  15610. return data;
  15611. },
  15612. _isColorConversionNeeded: function isColorConversionNeeded() {
  15613. if (this.adobe && this.adobe.transformCode) {
  15614. // The adobe transform marker overrides any previous setting
  15615. return true;
  15616. } else if (this.numComponents === 3) {
  15617. if (!this.adobe && this.colorTransform === 0) {
  15618. // If the Adobe transform marker is not present and the image
  15619. // dictionary has a 'ColorTransform' entry, explicitly set to `0`,
  15620. // then the colours should *not* be transformed.
  15621. return false;
  15622. }
  15623. return true;
  15624. } else {
  15625. // `this.numComponents !== 3`
  15626. if (!this.adobe && this.colorTransform === 1) {
  15627. // If the Adobe transform marker is not present and the image
  15628. // dictionary has a 'ColorTransform' entry, explicitly set to `1`,
  15629. // then the colours should be transformed.
  15630. return true;
  15631. }
  15632. return false;
  15633. }
  15634. },
  15635. _convertYccToRgb: function convertYccToRgb(data) {
  15636. var Y, Cb, Cr;
  15637. for (var i = 0, length = data.length; i < length; i += 3) {
  15638. Y = data[i];
  15639. Cb = data[i + 1];
  15640. Cr = data[i + 2];
  15641. data[i] = clamp0to255(Y - 179.456 + 1.402 * Cr);
  15642. data[i + 1] = clamp0to255(Y + 135.459 - 0.344 * Cb - 0.714 * Cr);
  15643. data[i + 2] = clamp0to255(Y - 226.816 + 1.772 * Cb);
  15644. }
  15645. return data;
  15646. },
  15647. _convertYcckToRgb: function convertYcckToRgb(data) {
  15648. var Y, Cb, Cr, k;
  15649. var offset = 0;
  15650. for (var i = 0, length = data.length; i < length; i += 4) {
  15651. Y = data[i];
  15652. Cb = data[i + 1];
  15653. Cr = data[i + 2];
  15654. k = data[i + 3];
  15655. var r = -122.67195406894 + Cb * (-6.60635669420364e-5 * Cb + 0.000437130475926232 * Cr - 5.4080610064599e-5 * Y + 0.00048449797120281 * k - 0.154362151871126) + Cr * (-0.000957964378445773 * Cr + 0.000817076911346625 * Y - 0.00477271405408747 * k + 1.53380253221734) + Y * (0.000961250184130688 * Y - 0.00266257332283933 * k + 0.48357088451265) + k * (-0.000336197177618394 * k + 0.484791561490776);
  15656. var g = 107.268039397724 + Cb * (2.19927104525741e-5 * Cb - 0.000640992018297945 * Cr + 0.000659397001245577 * Y + 0.000426105652938837 * k - 0.176491792462875) + Cr * (-0.000778269941513683 * Cr + 0.00130872261408275 * Y + 0.000770482631801132 * k - 0.151051492775562) + Y * (0.00126935368114843 * Y - 0.00265090189010898 * k + 0.25802910206845) + k * (-0.000318913117588328 * k - 0.213742400323665);
  15657. var b = -20.810012546947 + Cb * (-0.000570115196973677 * Cb - 2.63409051004589e-5 * Cr + 0.0020741088115012 * Y - 0.00288260236853442 * k + 0.814272968359295) + Cr * (-1.53496057440975e-5 * Cr - 0.000132689043961446 * Y + 0.000560833691242812 * k - 0.195152027534049) + Y * (0.00174418132927582 * Y - 0.00255243321439347 * k + 0.116935020465145) + k * (-0.000343531996510555 * k + 0.24165260232407);
  15658. data[offset++] = clamp0to255(r);
  15659. data[offset++] = clamp0to255(g);
  15660. data[offset++] = clamp0to255(b);
  15661. }
  15662. return data;
  15663. },
  15664. _convertYcckToCmyk: function convertYcckToCmyk(data) {
  15665. var Y, Cb, Cr;
  15666. for (var i = 0, length = data.length; i < length; i += 4) {
  15667. Y = data[i];
  15668. Cb = data[i + 1];
  15669. Cr = data[i + 2];
  15670. data[i] = clamp0to255(434.456 - Y - 1.402 * Cr);
  15671. data[i + 1] = clamp0to255(119.541 - Y + 0.344 * Cb + 0.714 * Cr);
  15672. data[i + 2] = clamp0to255(481.816 - Y - 1.772 * Cb);
  15673. }
  15674. // K in data[i + 3] is unchanged
  15675. return data;
  15676. },
  15677. _convertCmykToRgb: function convertCmykToRgb(data) {
  15678. var c, m, y, k;
  15679. var offset = 0;
  15680. var min = -255 * 255 * 255;
  15681. var scale = 1 / 255 / 255;
  15682. for (var i = 0, length = data.length; i < length; i += 4) {
  15683. c = data[i];
  15684. m = data[i + 1];
  15685. y = data[i + 2];
  15686. k = data[i + 3];
  15687. var r = c * (-4.387332384609988 * c + 54.48615194189176 * m + 18.82290502165302 * y + 212.25662451639585 * k - 72734.4411664936) + m * (1.7149763477362134 * m - 5.6096736904047315 * y - 17.873870861415444 * k - 1401.7366389350734) + y * (-2.5217340131683033 * y - 21.248923337353073 * k + 4465.541406466231) - k * (21.86122147463605 * k + 48317.86113160301);
  15688. var g = c * (8.841041422036149 * c + 60.118027045597366 * m + 6.871425592049007 * y + 31.159100130055922 * k - 20220.756542821975) + m * (-15.310361306967817 * m + 17.575251261109482 * y + 131.35250912493976 * k - 48691.05921601825) + y * (4.444339102852739 * y + 9.8632861493405 * k - 6341.191035517494) - k * (20.737325471181034 * k + 47890.15695978492);
  15689. var b = c * (0.8842522430003296 * c + 8.078677503112928 * m + 30.89978309703729 * y - 0.23883238689178934 * k - 3616.812083916688) + m * (10.49593273432072 * m + 63.02378494754052 * y + 50.606957656360734 * k - 28620.90484698408) + y * (0.03296041114873217 * y + 115.60384449646641 * k - 49363.43385999684) - k * (22.33816807309886 * k + 45932.16563550634);
  15690. data[offset++] = r >= 0 ? 255 : r <= min ? 0 : 255 + r * scale | 0;
  15691. data[offset++] = g >= 0 ? 255 : g <= min ? 0 : 255 + g * scale | 0;
  15692. data[offset++] = b >= 0 ? 255 : b <= min ? 0 : 255 + b * scale | 0;
  15693. }
  15694. return data;
  15695. },
  15696. getData: function getData(width, height, forceRGBoutput) {
  15697. if (this.numComponents > 4) {
  15698. error('JPEG error: Unsupported color mode');
  15699. }
  15700. // type of data: Uint8Array(width * height * numComponents)
  15701. var data = this._getLinearizedBlockData(width, height);
  15702. if (this.numComponents === 1 && forceRGBoutput) {
  15703. var dataLength = data.length;
  15704. var rgbData = new Uint8Array(dataLength * 3);
  15705. var offset = 0;
  15706. for (var i = 0; i < dataLength; i++) {
  15707. var grayColor = data[i];
  15708. rgbData[offset++] = grayColor;
  15709. rgbData[offset++] = grayColor;
  15710. rgbData[offset++] = grayColor;
  15711. }
  15712. return rgbData;
  15713. } else if (this.numComponents === 3 && this._isColorConversionNeeded()) {
  15714. return this._convertYccToRgb(data);
  15715. } else if (this.numComponents === 4) {
  15716. if (this._isColorConversionNeeded()) {
  15717. if (forceRGBoutput) {
  15718. return this._convertYcckToRgb(data);
  15719. } else {
  15720. return this._convertYcckToCmyk(data);
  15721. }
  15722. } else if (forceRGBoutput) {
  15723. return this._convertCmykToRgb(data);
  15724. }
  15725. }
  15726. return data;
  15727. }
  15728. };
  15729. return JpegImage;
  15730. }();
  15731. exports.JpegImage = JpegImage;
  15732. }));
  15733. (function (root, factory) {
  15734. factory(root.pdfjsCoreJpx = {}, root.pdfjsSharedUtil, root.pdfjsCoreArithmeticDecoder);
  15735. }(this, function (exports, sharedUtil, coreArithmeticDecoder) {
  15736. var info = sharedUtil.info;
  15737. var warn = sharedUtil.warn;
  15738. var error = sharedUtil.error;
  15739. var log2 = sharedUtil.log2;
  15740. var readUint16 = sharedUtil.readUint16;
  15741. var readUint32 = sharedUtil.readUint32;
  15742. var ArithmeticDecoder = coreArithmeticDecoder.ArithmeticDecoder;
  15743. var JpxImage = function JpxImageClosure() {
  15744. // Table E.1
  15745. var SubbandsGainLog2 = {
  15746. 'LL': 0,
  15747. 'LH': 1,
  15748. 'HL': 1,
  15749. 'HH': 2
  15750. };
  15751. function JpxImage() {
  15752. this.failOnCorruptedImage = false;
  15753. }
  15754. JpxImage.prototype = {
  15755. parse: function JpxImage_parse(data) {
  15756. var head = readUint16(data, 0);
  15757. // No box header, immediate start of codestream (SOC)
  15758. if (head === 0xFF4F) {
  15759. this.parseCodestream(data, 0, data.length);
  15760. return;
  15761. }
  15762. var position = 0, length = data.length;
  15763. while (position < length) {
  15764. var headerSize = 8;
  15765. var lbox = readUint32(data, position);
  15766. var tbox = readUint32(data, position + 4);
  15767. position += headerSize;
  15768. if (lbox === 1) {
  15769. // XLBox: read UInt64 according to spec.
  15770. // JavaScript's int precision of 53 bit should be sufficient here.
  15771. lbox = readUint32(data, position) * 4294967296 + readUint32(data, position + 4);
  15772. position += 8;
  15773. headerSize += 8;
  15774. }
  15775. if (lbox === 0) {
  15776. lbox = length - position + headerSize;
  15777. }
  15778. if (lbox < headerSize) {
  15779. error('JPX Error: Invalid box field size');
  15780. }
  15781. var dataLength = lbox - headerSize;
  15782. var jumpDataLength = true;
  15783. switch (tbox) {
  15784. case 0x6A703268:
  15785. // 'jp2h'
  15786. jumpDataLength = false;
  15787. // parsing child boxes
  15788. break;
  15789. case 0x636F6C72:
  15790. // 'colr'
  15791. // Colorspaces are not used, the CS from the PDF is used.
  15792. var method = data[position];
  15793. if (method === 1) {
  15794. // enumerated colorspace
  15795. var colorspace = readUint32(data, position + 3);
  15796. switch (colorspace) {
  15797. case 16:
  15798. // this indicates a sRGB colorspace
  15799. case 17:
  15800. // this indicates a grayscale colorspace
  15801. case 18:
  15802. // this indicates a YUV colorspace
  15803. break;
  15804. default:
  15805. warn('Unknown colorspace ' + colorspace);
  15806. break;
  15807. }
  15808. } else if (method === 2) {
  15809. info('ICC profile not supported');
  15810. }
  15811. break;
  15812. case 0x6A703263:
  15813. // 'jp2c'
  15814. this.parseCodestream(data, position, position + dataLength);
  15815. break;
  15816. case 0x6A502020:
  15817. // 'jP\024\024'
  15818. if (0x0d0a870a !== readUint32(data, position)) {
  15819. warn('Invalid JP2 signature');
  15820. }
  15821. break;
  15822. // The following header types are valid but currently not used:
  15823. case 0x6A501A1A:
  15824. // 'jP\032\032'
  15825. case 0x66747970:
  15826. // 'ftyp'
  15827. case 0x72726571:
  15828. // 'rreq'
  15829. case 0x72657320:
  15830. // 'res '
  15831. case 0x69686472:
  15832. // 'ihdr'
  15833. break;
  15834. default:
  15835. var headerType = String.fromCharCode(tbox >> 24 & 0xFF, tbox >> 16 & 0xFF, tbox >> 8 & 0xFF, tbox & 0xFF);
  15836. warn('Unsupported header type ' + tbox + ' (' + headerType + ')');
  15837. break;
  15838. }
  15839. if (jumpDataLength) {
  15840. position += dataLength;
  15841. }
  15842. }
  15843. },
  15844. parseImageProperties: function JpxImage_parseImageProperties(stream) {
  15845. var newByte = stream.getByte();
  15846. while (newByte >= 0) {
  15847. var oldByte = newByte;
  15848. newByte = stream.getByte();
  15849. var code = oldByte << 8 | newByte;
  15850. // Image and tile size (SIZ)
  15851. if (code === 0xFF51) {
  15852. stream.skip(4);
  15853. var Xsiz = stream.getInt32() >>> 0;
  15854. // Byte 4
  15855. var Ysiz = stream.getInt32() >>> 0;
  15856. // Byte 8
  15857. var XOsiz = stream.getInt32() >>> 0;
  15858. // Byte 12
  15859. var YOsiz = stream.getInt32() >>> 0;
  15860. // Byte 16
  15861. stream.skip(16);
  15862. var Csiz = stream.getUint16();
  15863. // Byte 36
  15864. this.width = Xsiz - XOsiz;
  15865. this.height = Ysiz - YOsiz;
  15866. this.componentsCount = Csiz;
  15867. // Results are always returned as Uint8Arrays
  15868. this.bitsPerComponent = 8;
  15869. return;
  15870. }
  15871. }
  15872. error('JPX Error: No size marker found in JPX stream');
  15873. },
  15874. parseCodestream: function JpxImage_parseCodestream(data, start, end) {
  15875. var context = {};
  15876. var doNotRecover = false;
  15877. try {
  15878. var position = start;
  15879. while (position + 1 < end) {
  15880. var code = readUint16(data, position);
  15881. position += 2;
  15882. var length = 0, j, sqcd, spqcds, spqcdSize, scalarExpounded, tile;
  15883. switch (code) {
  15884. case 0xFF4F:
  15885. // Start of codestream (SOC)
  15886. context.mainHeader = true;
  15887. break;
  15888. case 0xFFD9:
  15889. // End of codestream (EOC)
  15890. break;
  15891. case 0xFF51:
  15892. // Image and tile size (SIZ)
  15893. length = readUint16(data, position);
  15894. var siz = {};
  15895. siz.Xsiz = readUint32(data, position + 4);
  15896. siz.Ysiz = readUint32(data, position + 8);
  15897. siz.XOsiz = readUint32(data, position + 12);
  15898. siz.YOsiz = readUint32(data, position + 16);
  15899. siz.XTsiz = readUint32(data, position + 20);
  15900. siz.YTsiz = readUint32(data, position + 24);
  15901. siz.XTOsiz = readUint32(data, position + 28);
  15902. siz.YTOsiz = readUint32(data, position + 32);
  15903. var componentsCount = readUint16(data, position + 36);
  15904. siz.Csiz = componentsCount;
  15905. var components = [];
  15906. j = position + 38;
  15907. for (var i = 0; i < componentsCount; i++) {
  15908. var component = {
  15909. precision: (data[j] & 0x7F) + 1,
  15910. isSigned: !!(data[j] & 0x80),
  15911. XRsiz: data[j + 1],
  15912. YRsiz: data[j + 1]
  15913. };
  15914. calculateComponentDimensions(component, siz);
  15915. components.push(component);
  15916. }
  15917. context.SIZ = siz;
  15918. context.components = components;
  15919. calculateTileGrids(context, components);
  15920. context.QCC = [];
  15921. context.COC = [];
  15922. break;
  15923. case 0xFF5C:
  15924. // Quantization default (QCD)
  15925. length = readUint16(data, position);
  15926. var qcd = {};
  15927. j = position + 2;
  15928. sqcd = data[j++];
  15929. switch (sqcd & 0x1F) {
  15930. case 0:
  15931. spqcdSize = 8;
  15932. scalarExpounded = true;
  15933. break;
  15934. case 1:
  15935. spqcdSize = 16;
  15936. scalarExpounded = false;
  15937. break;
  15938. case 2:
  15939. spqcdSize = 16;
  15940. scalarExpounded = true;
  15941. break;
  15942. default:
  15943. throw new Error('Invalid SQcd value ' + sqcd);
  15944. }
  15945. qcd.noQuantization = spqcdSize === 8;
  15946. qcd.scalarExpounded = scalarExpounded;
  15947. qcd.guardBits = sqcd >> 5;
  15948. spqcds = [];
  15949. while (j < length + position) {
  15950. var spqcd = {};
  15951. if (spqcdSize === 8) {
  15952. spqcd.epsilon = data[j++] >> 3;
  15953. spqcd.mu = 0;
  15954. } else {
  15955. spqcd.epsilon = data[j] >> 3;
  15956. spqcd.mu = (data[j] & 0x7) << 8 | data[j + 1];
  15957. j += 2;
  15958. }
  15959. spqcds.push(spqcd);
  15960. }
  15961. qcd.SPqcds = spqcds;
  15962. if (context.mainHeader) {
  15963. context.QCD = qcd;
  15964. } else {
  15965. context.currentTile.QCD = qcd;
  15966. context.currentTile.QCC = [];
  15967. }
  15968. break;
  15969. case 0xFF5D:
  15970. // Quantization component (QCC)
  15971. length = readUint16(data, position);
  15972. var qcc = {};
  15973. j = position + 2;
  15974. var cqcc;
  15975. if (context.SIZ.Csiz < 257) {
  15976. cqcc = data[j++];
  15977. } else {
  15978. cqcc = readUint16(data, j);
  15979. j += 2;
  15980. }
  15981. sqcd = data[j++];
  15982. switch (sqcd & 0x1F) {
  15983. case 0:
  15984. spqcdSize = 8;
  15985. scalarExpounded = true;
  15986. break;
  15987. case 1:
  15988. spqcdSize = 16;
  15989. scalarExpounded = false;
  15990. break;
  15991. case 2:
  15992. spqcdSize = 16;
  15993. scalarExpounded = true;
  15994. break;
  15995. default:
  15996. throw new Error('Invalid SQcd value ' + sqcd);
  15997. }
  15998. qcc.noQuantization = spqcdSize === 8;
  15999. qcc.scalarExpounded = scalarExpounded;
  16000. qcc.guardBits = sqcd >> 5;
  16001. spqcds = [];
  16002. while (j < length + position) {
  16003. spqcd = {};
  16004. if (spqcdSize === 8) {
  16005. spqcd.epsilon = data[j++] >> 3;
  16006. spqcd.mu = 0;
  16007. } else {
  16008. spqcd.epsilon = data[j] >> 3;
  16009. spqcd.mu = (data[j] & 0x7) << 8 | data[j + 1];
  16010. j += 2;
  16011. }
  16012. spqcds.push(spqcd);
  16013. }
  16014. qcc.SPqcds = spqcds;
  16015. if (context.mainHeader) {
  16016. context.QCC[cqcc] = qcc;
  16017. } else {
  16018. context.currentTile.QCC[cqcc] = qcc;
  16019. }
  16020. break;
  16021. case 0xFF52:
  16022. // Coding style default (COD)
  16023. length = readUint16(data, position);
  16024. var cod = {};
  16025. j = position + 2;
  16026. var scod = data[j++];
  16027. cod.entropyCoderWithCustomPrecincts = !!(scod & 1);
  16028. cod.sopMarkerUsed = !!(scod & 2);
  16029. cod.ephMarkerUsed = !!(scod & 4);
  16030. cod.progressionOrder = data[j++];
  16031. cod.layersCount = readUint16(data, j);
  16032. j += 2;
  16033. cod.multipleComponentTransform = data[j++];
  16034. cod.decompositionLevelsCount = data[j++];
  16035. cod.xcb = (data[j++] & 0xF) + 2;
  16036. cod.ycb = (data[j++] & 0xF) + 2;
  16037. var blockStyle = data[j++];
  16038. cod.selectiveArithmeticCodingBypass = !!(blockStyle & 1);
  16039. cod.resetContextProbabilities = !!(blockStyle & 2);
  16040. cod.terminationOnEachCodingPass = !!(blockStyle & 4);
  16041. cod.verticalyStripe = !!(blockStyle & 8);
  16042. cod.predictableTermination = !!(blockStyle & 16);
  16043. cod.segmentationSymbolUsed = !!(blockStyle & 32);
  16044. cod.reversibleTransformation = data[j++];
  16045. if (cod.entropyCoderWithCustomPrecincts) {
  16046. var precinctsSizes = [];
  16047. while (j < length + position) {
  16048. var precinctsSize = data[j++];
  16049. precinctsSizes.push({
  16050. PPx: precinctsSize & 0xF,
  16051. PPy: precinctsSize >> 4
  16052. });
  16053. }
  16054. cod.precinctsSizes = precinctsSizes;
  16055. }
  16056. var unsupported = [];
  16057. if (cod.selectiveArithmeticCodingBypass) {
  16058. unsupported.push('selectiveArithmeticCodingBypass');
  16059. }
  16060. if (cod.resetContextProbabilities) {
  16061. unsupported.push('resetContextProbabilities');
  16062. }
  16063. if (cod.terminationOnEachCodingPass) {
  16064. unsupported.push('terminationOnEachCodingPass');
  16065. }
  16066. if (cod.verticalyStripe) {
  16067. unsupported.push('verticalyStripe');
  16068. }
  16069. if (cod.predictableTermination) {
  16070. unsupported.push('predictableTermination');
  16071. }
  16072. if (unsupported.length > 0) {
  16073. doNotRecover = true;
  16074. throw new Error('Unsupported COD options (' + unsupported.join(', ') + ')');
  16075. }
  16076. if (context.mainHeader) {
  16077. context.COD = cod;
  16078. } else {
  16079. context.currentTile.COD = cod;
  16080. context.currentTile.COC = [];
  16081. }
  16082. break;
  16083. case 0xFF90:
  16084. // Start of tile-part (SOT)
  16085. length = readUint16(data, position);
  16086. tile = {};
  16087. tile.index = readUint16(data, position + 2);
  16088. tile.length = readUint32(data, position + 4);
  16089. tile.dataEnd = tile.length + position - 2;
  16090. tile.partIndex = data[position + 8];
  16091. tile.partsCount = data[position + 9];
  16092. context.mainHeader = false;
  16093. if (tile.partIndex === 0) {
  16094. // reset component specific settings
  16095. tile.COD = context.COD;
  16096. tile.COC = context.COC.slice(0);
  16097. // clone of the global COC
  16098. tile.QCD = context.QCD;
  16099. tile.QCC = context.QCC.slice(0);
  16100. }
  16101. // clone of the global COC
  16102. context.currentTile = tile;
  16103. break;
  16104. case 0xFF93:
  16105. // Start of data (SOD)
  16106. tile = context.currentTile;
  16107. if (tile.partIndex === 0) {
  16108. initializeTile(context, tile.index);
  16109. buildPackets(context);
  16110. }
  16111. // moving to the end of the data
  16112. length = tile.dataEnd - position;
  16113. parseTilePackets(context, data, position, length);
  16114. break;
  16115. case 0xFF55:
  16116. // Tile-part lengths, main header (TLM)
  16117. case 0xFF57:
  16118. // Packet length, main header (PLM)
  16119. case 0xFF58:
  16120. // Packet length, tile-part header (PLT)
  16121. case 0xFF64:
  16122. // Comment (COM)
  16123. length = readUint16(data, position);
  16124. // skipping content
  16125. break;
  16126. case 0xFF53:
  16127. // Coding style component (COC)
  16128. throw new Error('Codestream code 0xFF53 (COC) is ' + 'not implemented');
  16129. default:
  16130. throw new Error('Unknown codestream code: ' + code.toString(16));
  16131. }
  16132. position += length;
  16133. }
  16134. } catch (e) {
  16135. if (doNotRecover || this.failOnCorruptedImage) {
  16136. error('JPX Error: ' + e.message);
  16137. } else {
  16138. warn('JPX: Trying to recover from: ' + e.message);
  16139. }
  16140. }
  16141. this.tiles = transformComponents(context);
  16142. this.width = context.SIZ.Xsiz - context.SIZ.XOsiz;
  16143. this.height = context.SIZ.Ysiz - context.SIZ.YOsiz;
  16144. this.componentsCount = context.SIZ.Csiz;
  16145. }
  16146. };
  16147. function calculateComponentDimensions(component, siz) {
  16148. // Section B.2 Component mapping
  16149. component.x0 = Math.ceil(siz.XOsiz / component.XRsiz);
  16150. component.x1 = Math.ceil(siz.Xsiz / component.XRsiz);
  16151. component.y0 = Math.ceil(siz.YOsiz / component.YRsiz);
  16152. component.y1 = Math.ceil(siz.Ysiz / component.YRsiz);
  16153. component.width = component.x1 - component.x0;
  16154. component.height = component.y1 - component.y0;
  16155. }
  16156. function calculateTileGrids(context, components) {
  16157. var siz = context.SIZ;
  16158. // Section B.3 Division into tile and tile-components
  16159. var tile, tiles = [];
  16160. var numXtiles = Math.ceil((siz.Xsiz - siz.XTOsiz) / siz.XTsiz);
  16161. var numYtiles = Math.ceil((siz.Ysiz - siz.YTOsiz) / siz.YTsiz);
  16162. for (var q = 0; q < numYtiles; q++) {
  16163. for (var p = 0; p < numXtiles; p++) {
  16164. tile = {};
  16165. tile.tx0 = Math.max(siz.XTOsiz + p * siz.XTsiz, siz.XOsiz);
  16166. tile.ty0 = Math.max(siz.YTOsiz + q * siz.YTsiz, siz.YOsiz);
  16167. tile.tx1 = Math.min(siz.XTOsiz + (p + 1) * siz.XTsiz, siz.Xsiz);
  16168. tile.ty1 = Math.min(siz.YTOsiz + (q + 1) * siz.YTsiz, siz.Ysiz);
  16169. tile.width = tile.tx1 - tile.tx0;
  16170. tile.height = tile.ty1 - tile.ty0;
  16171. tile.components = [];
  16172. tiles.push(tile);
  16173. }
  16174. }
  16175. context.tiles = tiles;
  16176. var componentsCount = siz.Csiz;
  16177. for (var i = 0, ii = componentsCount; i < ii; i++) {
  16178. var component = components[i];
  16179. for (var j = 0, jj = tiles.length; j < jj; j++) {
  16180. var tileComponent = {};
  16181. tile = tiles[j];
  16182. tileComponent.tcx0 = Math.ceil(tile.tx0 / component.XRsiz);
  16183. tileComponent.tcy0 = Math.ceil(tile.ty0 / component.YRsiz);
  16184. tileComponent.tcx1 = Math.ceil(tile.tx1 / component.XRsiz);
  16185. tileComponent.tcy1 = Math.ceil(tile.ty1 / component.YRsiz);
  16186. tileComponent.width = tileComponent.tcx1 - tileComponent.tcx0;
  16187. tileComponent.height = tileComponent.tcy1 - tileComponent.tcy0;
  16188. tile.components[i] = tileComponent;
  16189. }
  16190. }
  16191. }
  16192. function getBlocksDimensions(context, component, r) {
  16193. var codOrCoc = component.codingStyleParameters;
  16194. var result = {};
  16195. if (!codOrCoc.entropyCoderWithCustomPrecincts) {
  16196. result.PPx = 15;
  16197. result.PPy = 15;
  16198. } else {
  16199. result.PPx = codOrCoc.precinctsSizes[r].PPx;
  16200. result.PPy = codOrCoc.precinctsSizes[r].PPy;
  16201. }
  16202. // calculate codeblock size as described in section B.7
  16203. result.xcb_ = r > 0 ? Math.min(codOrCoc.xcb, result.PPx - 1) : Math.min(codOrCoc.xcb, result.PPx);
  16204. result.ycb_ = r > 0 ? Math.min(codOrCoc.ycb, result.PPy - 1) : Math.min(codOrCoc.ycb, result.PPy);
  16205. return result;
  16206. }
  16207. function buildPrecincts(context, resolution, dimensions) {
  16208. // Section B.6 Division resolution to precincts
  16209. var precinctWidth = 1 << dimensions.PPx;
  16210. var precinctHeight = 1 << dimensions.PPy;
  16211. // Jasper introduces codeblock groups for mapping each subband codeblocks
  16212. // to precincts. Precinct partition divides a resolution according to width
  16213. // and height parameters. The subband that belongs to the resolution level
  16214. // has a different size than the level, unless it is the zero resolution.
  16215. // From Jasper documentation: jpeg2000.pdf, section K: Tier-2 coding:
  16216. // The precinct partitioning for a particular subband is derived from a
  16217. // partitioning of its parent LL band (i.e., the LL band at the next higher
  16218. // resolution level)... The LL band associated with each resolution level is
  16219. // divided into precincts... Each of the resulting precinct regions is then
  16220. // mapped into its child subbands (if any) at the next lower resolution
  16221. // level. This is accomplished by using the coordinate transformation
  16222. // (u, v) = (ceil(x/2), ceil(y/2)) where (x, y) and (u, v) are the
  16223. // coordinates of a point in the LL band and child subband, respectively.
  16224. var isZeroRes = resolution.resLevel === 0;
  16225. var precinctWidthInSubband = 1 << dimensions.PPx + (isZeroRes ? 0 : -1);
  16226. var precinctHeightInSubband = 1 << dimensions.PPy + (isZeroRes ? 0 : -1);
  16227. var numprecinctswide = resolution.trx1 > resolution.trx0 ? Math.ceil(resolution.trx1 / precinctWidth) - Math.floor(resolution.trx0 / precinctWidth) : 0;
  16228. var numprecinctshigh = resolution.try1 > resolution.try0 ? Math.ceil(resolution.try1 / precinctHeight) - Math.floor(resolution.try0 / precinctHeight) : 0;
  16229. var numprecincts = numprecinctswide * numprecinctshigh;
  16230. resolution.precinctParameters = {
  16231. precinctWidth: precinctWidth,
  16232. precinctHeight: precinctHeight,
  16233. numprecinctswide: numprecinctswide,
  16234. numprecinctshigh: numprecinctshigh,
  16235. numprecincts: numprecincts,
  16236. precinctWidthInSubband: precinctWidthInSubband,
  16237. precinctHeightInSubband: precinctHeightInSubband
  16238. };
  16239. }
  16240. function buildCodeblocks(context, subband, dimensions) {
  16241. // Section B.7 Division sub-band into code-blocks
  16242. var xcb_ = dimensions.xcb_;
  16243. var ycb_ = dimensions.ycb_;
  16244. var codeblockWidth = 1 << xcb_;
  16245. var codeblockHeight = 1 << ycb_;
  16246. var cbx0 = subband.tbx0 >> xcb_;
  16247. var cby0 = subband.tby0 >> ycb_;
  16248. var cbx1 = subband.tbx1 + codeblockWidth - 1 >> xcb_;
  16249. var cby1 = subband.tby1 + codeblockHeight - 1 >> ycb_;
  16250. var precinctParameters = subband.resolution.precinctParameters;
  16251. var codeblocks = [];
  16252. var precincts = [];
  16253. var i, j, codeblock, precinctNumber;
  16254. for (j = cby0; j < cby1; j++) {
  16255. for (i = cbx0; i < cbx1; i++) {
  16256. codeblock = {
  16257. cbx: i,
  16258. cby: j,
  16259. tbx0: codeblockWidth * i,
  16260. tby0: codeblockHeight * j,
  16261. tbx1: codeblockWidth * (i + 1),
  16262. tby1: codeblockHeight * (j + 1)
  16263. };
  16264. codeblock.tbx0_ = Math.max(subband.tbx0, codeblock.tbx0);
  16265. codeblock.tby0_ = Math.max(subband.tby0, codeblock.tby0);
  16266. codeblock.tbx1_ = Math.min(subband.tbx1, codeblock.tbx1);
  16267. codeblock.tby1_ = Math.min(subband.tby1, codeblock.tby1);
  16268. // Calculate precinct number for this codeblock, codeblock position
  16269. // should be relative to its subband, use actual dimension and position
  16270. // See comment about codeblock group width and height
  16271. var pi = Math.floor((codeblock.tbx0_ - subband.tbx0) / precinctParameters.precinctWidthInSubband);
  16272. var pj = Math.floor((codeblock.tby0_ - subband.tby0) / precinctParameters.precinctHeightInSubband);
  16273. precinctNumber = pi + pj * precinctParameters.numprecinctswide;
  16274. codeblock.precinctNumber = precinctNumber;
  16275. codeblock.subbandType = subband.type;
  16276. codeblock.Lblock = 3;
  16277. if (codeblock.tbx1_ <= codeblock.tbx0_ || codeblock.tby1_ <= codeblock.tby0_) {
  16278. continue;
  16279. }
  16280. codeblocks.push(codeblock);
  16281. // building precinct for the sub-band
  16282. var precinct = precincts[precinctNumber];
  16283. if (precinct !== undefined) {
  16284. if (i < precinct.cbxMin) {
  16285. precinct.cbxMin = i;
  16286. } else if (i > precinct.cbxMax) {
  16287. precinct.cbxMax = i;
  16288. }
  16289. if (j < precinct.cbyMin) {
  16290. precinct.cbxMin = j;
  16291. } else if (j > precinct.cbyMax) {
  16292. precinct.cbyMax = j;
  16293. }
  16294. } else {
  16295. precincts[precinctNumber] = precinct = {
  16296. cbxMin: i,
  16297. cbyMin: j,
  16298. cbxMax: i,
  16299. cbyMax: j
  16300. };
  16301. }
  16302. codeblock.precinct = precinct;
  16303. }
  16304. }
  16305. subband.codeblockParameters = {
  16306. codeblockWidth: xcb_,
  16307. codeblockHeight: ycb_,
  16308. numcodeblockwide: cbx1 - cbx0 + 1,
  16309. numcodeblockhigh: cby1 - cby0 + 1
  16310. };
  16311. subband.codeblocks = codeblocks;
  16312. subband.precincts = precincts;
  16313. }
  16314. function createPacket(resolution, precinctNumber, layerNumber) {
  16315. var precinctCodeblocks = [];
  16316. // Section B.10.8 Order of info in packet
  16317. var subbands = resolution.subbands;
  16318. // sub-bands already ordered in 'LL', 'HL', 'LH', and 'HH' sequence
  16319. for (var i = 0, ii = subbands.length; i < ii; i++) {
  16320. var subband = subbands[i];
  16321. var codeblocks = subband.codeblocks;
  16322. for (var j = 0, jj = codeblocks.length; j < jj; j++) {
  16323. var codeblock = codeblocks[j];
  16324. if (codeblock.precinctNumber !== precinctNumber) {
  16325. continue;
  16326. }
  16327. precinctCodeblocks.push(codeblock);
  16328. }
  16329. }
  16330. return {
  16331. layerNumber: layerNumber,
  16332. codeblocks: precinctCodeblocks
  16333. };
  16334. }
  16335. function LayerResolutionComponentPositionIterator(context) {
  16336. var siz = context.SIZ;
  16337. var tileIndex = context.currentTile.index;
  16338. var tile = context.tiles[tileIndex];
  16339. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  16340. var componentsCount = siz.Csiz;
  16341. var maxDecompositionLevelsCount = 0;
  16342. for (var q = 0; q < componentsCount; q++) {
  16343. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount, tile.components[q].codingStyleParameters.decompositionLevelsCount);
  16344. }
  16345. var l = 0, r = 0, i = 0, k = 0;
  16346. this.nextPacket = function JpxImage_nextPacket() {
  16347. // Section B.12.1.1 Layer-resolution-component-position
  16348. for (; l < layersCount; l++) {
  16349. for (; r <= maxDecompositionLevelsCount; r++) {
  16350. for (; i < componentsCount; i++) {
  16351. var component = tile.components[i];
  16352. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  16353. continue;
  16354. }
  16355. var resolution = component.resolutions[r];
  16356. var numprecincts = resolution.precinctParameters.numprecincts;
  16357. for (; k < numprecincts;) {
  16358. var packet = createPacket(resolution, k, l);
  16359. k++;
  16360. return packet;
  16361. }
  16362. k = 0;
  16363. }
  16364. i = 0;
  16365. }
  16366. r = 0;
  16367. }
  16368. error('JPX Error: Out of packets');
  16369. };
  16370. }
  16371. function ResolutionLayerComponentPositionIterator(context) {
  16372. var siz = context.SIZ;
  16373. var tileIndex = context.currentTile.index;
  16374. var tile = context.tiles[tileIndex];
  16375. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  16376. var componentsCount = siz.Csiz;
  16377. var maxDecompositionLevelsCount = 0;
  16378. for (var q = 0; q < componentsCount; q++) {
  16379. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount, tile.components[q].codingStyleParameters.decompositionLevelsCount);
  16380. }
  16381. var r = 0, l = 0, i = 0, k = 0;
  16382. this.nextPacket = function JpxImage_nextPacket() {
  16383. // Section B.12.1.2 Resolution-layer-component-position
  16384. for (; r <= maxDecompositionLevelsCount; r++) {
  16385. for (; l < layersCount; l++) {
  16386. for (; i < componentsCount; i++) {
  16387. var component = tile.components[i];
  16388. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  16389. continue;
  16390. }
  16391. var resolution = component.resolutions[r];
  16392. var numprecincts = resolution.precinctParameters.numprecincts;
  16393. for (; k < numprecincts;) {
  16394. var packet = createPacket(resolution, k, l);
  16395. k++;
  16396. return packet;
  16397. }
  16398. k = 0;
  16399. }
  16400. i = 0;
  16401. }
  16402. l = 0;
  16403. }
  16404. error('JPX Error: Out of packets');
  16405. };
  16406. }
  16407. function ResolutionPositionComponentLayerIterator(context) {
  16408. var siz = context.SIZ;
  16409. var tileIndex = context.currentTile.index;
  16410. var tile = context.tiles[tileIndex];
  16411. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  16412. var componentsCount = siz.Csiz;
  16413. var l, r, c, p;
  16414. var maxDecompositionLevelsCount = 0;
  16415. for (c = 0; c < componentsCount; c++) {
  16416. var component = tile.components[c];
  16417. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount, component.codingStyleParameters.decompositionLevelsCount);
  16418. }
  16419. var maxNumPrecinctsInLevel = new Int32Array(maxDecompositionLevelsCount + 1);
  16420. for (r = 0; r <= maxDecompositionLevelsCount; ++r) {
  16421. var maxNumPrecincts = 0;
  16422. for (c = 0; c < componentsCount; ++c) {
  16423. var resolutions = tile.components[c].resolutions;
  16424. if (r < resolutions.length) {
  16425. maxNumPrecincts = Math.max(maxNumPrecincts, resolutions[r].precinctParameters.numprecincts);
  16426. }
  16427. }
  16428. maxNumPrecinctsInLevel[r] = maxNumPrecincts;
  16429. }
  16430. l = 0;
  16431. r = 0;
  16432. c = 0;
  16433. p = 0;
  16434. this.nextPacket = function JpxImage_nextPacket() {
  16435. // Section B.12.1.3 Resolution-position-component-layer
  16436. for (; r <= maxDecompositionLevelsCount; r++) {
  16437. for (; p < maxNumPrecinctsInLevel[r]; p++) {
  16438. for (; c < componentsCount; c++) {
  16439. var component = tile.components[c];
  16440. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  16441. continue;
  16442. }
  16443. var resolution = component.resolutions[r];
  16444. var numprecincts = resolution.precinctParameters.numprecincts;
  16445. if (p >= numprecincts) {
  16446. continue;
  16447. }
  16448. for (; l < layersCount;) {
  16449. var packet = createPacket(resolution, p, l);
  16450. l++;
  16451. return packet;
  16452. }
  16453. l = 0;
  16454. }
  16455. c = 0;
  16456. }
  16457. p = 0;
  16458. }
  16459. error('JPX Error: Out of packets');
  16460. };
  16461. }
  16462. function PositionComponentResolutionLayerIterator(context) {
  16463. var siz = context.SIZ;
  16464. var tileIndex = context.currentTile.index;
  16465. var tile = context.tiles[tileIndex];
  16466. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  16467. var componentsCount = siz.Csiz;
  16468. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  16469. var precinctsIterationSizes = precinctsSizes;
  16470. var l = 0, r = 0, c = 0, px = 0, py = 0;
  16471. this.nextPacket = function JpxImage_nextPacket() {
  16472. // Section B.12.1.4 Position-component-resolution-layer
  16473. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  16474. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  16475. for (; c < componentsCount; c++) {
  16476. var component = tile.components[c];
  16477. var decompositionLevelsCount = component.codingStyleParameters.decompositionLevelsCount;
  16478. for (; r <= decompositionLevelsCount; r++) {
  16479. var resolution = component.resolutions[r];
  16480. var sizeInImageScale = precinctsSizes.components[c].resolutions[r];
  16481. var k = getPrecinctIndexIfExist(px, py, sizeInImageScale, precinctsIterationSizes, resolution);
  16482. if (k === null) {
  16483. continue;
  16484. }
  16485. for (; l < layersCount;) {
  16486. var packet = createPacket(resolution, k, l);
  16487. l++;
  16488. return packet;
  16489. }
  16490. l = 0;
  16491. }
  16492. r = 0;
  16493. }
  16494. c = 0;
  16495. }
  16496. px = 0;
  16497. }
  16498. error('JPX Error: Out of packets');
  16499. };
  16500. }
  16501. function ComponentPositionResolutionLayerIterator(context) {
  16502. var siz = context.SIZ;
  16503. var tileIndex = context.currentTile.index;
  16504. var tile = context.tiles[tileIndex];
  16505. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  16506. var componentsCount = siz.Csiz;
  16507. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  16508. var l = 0, r = 0, c = 0, px = 0, py = 0;
  16509. this.nextPacket = function JpxImage_nextPacket() {
  16510. // Section B.12.1.5 Component-position-resolution-layer
  16511. for (; c < componentsCount; ++c) {
  16512. var component = tile.components[c];
  16513. var precinctsIterationSizes = precinctsSizes.components[c];
  16514. var decompositionLevelsCount = component.codingStyleParameters.decompositionLevelsCount;
  16515. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  16516. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  16517. for (; r <= decompositionLevelsCount; r++) {
  16518. var resolution = component.resolutions[r];
  16519. var sizeInImageScale = precinctsIterationSizes.resolutions[r];
  16520. var k = getPrecinctIndexIfExist(px, py, sizeInImageScale, precinctsIterationSizes, resolution);
  16521. if (k === null) {
  16522. continue;
  16523. }
  16524. for (; l < layersCount;) {
  16525. var packet = createPacket(resolution, k, l);
  16526. l++;
  16527. return packet;
  16528. }
  16529. l = 0;
  16530. }
  16531. r = 0;
  16532. }
  16533. px = 0;
  16534. }
  16535. py = 0;
  16536. }
  16537. error('JPX Error: Out of packets');
  16538. };
  16539. }
  16540. function getPrecinctIndexIfExist(pxIndex, pyIndex, sizeInImageScale, precinctIterationSizes, resolution) {
  16541. var posX = pxIndex * precinctIterationSizes.minWidth;
  16542. var posY = pyIndex * precinctIterationSizes.minHeight;
  16543. if (posX % sizeInImageScale.width !== 0 || posY % sizeInImageScale.height !== 0) {
  16544. return null;
  16545. }
  16546. var startPrecinctRowIndex = posY / sizeInImageScale.width * resolution.precinctParameters.numprecinctswide;
  16547. return posX / sizeInImageScale.height + startPrecinctRowIndex;
  16548. }
  16549. function getPrecinctSizesInImageScale(tile) {
  16550. var componentsCount = tile.components.length;
  16551. var minWidth = Number.MAX_VALUE;
  16552. var minHeight = Number.MAX_VALUE;
  16553. var maxNumWide = 0;
  16554. var maxNumHigh = 0;
  16555. var sizePerComponent = new Array(componentsCount);
  16556. for (var c = 0; c < componentsCount; c++) {
  16557. var component = tile.components[c];
  16558. var decompositionLevelsCount = component.codingStyleParameters.decompositionLevelsCount;
  16559. var sizePerResolution = new Array(decompositionLevelsCount + 1);
  16560. var minWidthCurrentComponent = Number.MAX_VALUE;
  16561. var minHeightCurrentComponent = Number.MAX_VALUE;
  16562. var maxNumWideCurrentComponent = 0;
  16563. var maxNumHighCurrentComponent = 0;
  16564. var scale = 1;
  16565. for (var r = decompositionLevelsCount; r >= 0; --r) {
  16566. var resolution = component.resolutions[r];
  16567. var widthCurrentResolution = scale * resolution.precinctParameters.precinctWidth;
  16568. var heightCurrentResolution = scale * resolution.precinctParameters.precinctHeight;
  16569. minWidthCurrentComponent = Math.min(minWidthCurrentComponent, widthCurrentResolution);
  16570. minHeightCurrentComponent = Math.min(minHeightCurrentComponent, heightCurrentResolution);
  16571. maxNumWideCurrentComponent = Math.max(maxNumWideCurrentComponent, resolution.precinctParameters.numprecinctswide);
  16572. maxNumHighCurrentComponent = Math.max(maxNumHighCurrentComponent, resolution.precinctParameters.numprecinctshigh);
  16573. sizePerResolution[r] = {
  16574. width: widthCurrentResolution,
  16575. height: heightCurrentResolution
  16576. };
  16577. scale <<= 1;
  16578. }
  16579. minWidth = Math.min(minWidth, minWidthCurrentComponent);
  16580. minHeight = Math.min(minHeight, minHeightCurrentComponent);
  16581. maxNumWide = Math.max(maxNumWide, maxNumWideCurrentComponent);
  16582. maxNumHigh = Math.max(maxNumHigh, maxNumHighCurrentComponent);
  16583. sizePerComponent[c] = {
  16584. resolutions: sizePerResolution,
  16585. minWidth: minWidthCurrentComponent,
  16586. minHeight: minHeightCurrentComponent,
  16587. maxNumWide: maxNumWideCurrentComponent,
  16588. maxNumHigh: maxNumHighCurrentComponent
  16589. };
  16590. }
  16591. return {
  16592. components: sizePerComponent,
  16593. minWidth: minWidth,
  16594. minHeight: minHeight,
  16595. maxNumWide: maxNumWide,
  16596. maxNumHigh: maxNumHigh
  16597. };
  16598. }
  16599. function buildPackets(context) {
  16600. var siz = context.SIZ;
  16601. var tileIndex = context.currentTile.index;
  16602. var tile = context.tiles[tileIndex];
  16603. var componentsCount = siz.Csiz;
  16604. // Creating resolutions and sub-bands for each component
  16605. for (var c = 0; c < componentsCount; c++) {
  16606. var component = tile.components[c];
  16607. var decompositionLevelsCount = component.codingStyleParameters.decompositionLevelsCount;
  16608. // Section B.5 Resolution levels and sub-bands
  16609. var resolutions = [];
  16610. var subbands = [];
  16611. for (var r = 0; r <= decompositionLevelsCount; r++) {
  16612. var blocksDimensions = getBlocksDimensions(context, component, r);
  16613. var resolution = {};
  16614. var scale = 1 << decompositionLevelsCount - r;
  16615. resolution.trx0 = Math.ceil(component.tcx0 / scale);
  16616. resolution.try0 = Math.ceil(component.tcy0 / scale);
  16617. resolution.trx1 = Math.ceil(component.tcx1 / scale);
  16618. resolution.try1 = Math.ceil(component.tcy1 / scale);
  16619. resolution.resLevel = r;
  16620. buildPrecincts(context, resolution, blocksDimensions);
  16621. resolutions.push(resolution);
  16622. var subband;
  16623. if (r === 0) {
  16624. // one sub-band (LL) with last decomposition
  16625. subband = {};
  16626. subband.type = 'LL';
  16627. subband.tbx0 = Math.ceil(component.tcx0 / scale);
  16628. subband.tby0 = Math.ceil(component.tcy0 / scale);
  16629. subband.tbx1 = Math.ceil(component.tcx1 / scale);
  16630. subband.tby1 = Math.ceil(component.tcy1 / scale);
  16631. subband.resolution = resolution;
  16632. buildCodeblocks(context, subband, blocksDimensions);
  16633. subbands.push(subband);
  16634. resolution.subbands = [subband];
  16635. } else {
  16636. var bscale = 1 << decompositionLevelsCount - r + 1;
  16637. var resolutionSubbands = [];
  16638. // three sub-bands (HL, LH and HH) with rest of decompositions
  16639. subband = {};
  16640. subband.type = 'HL';
  16641. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  16642. subband.tby0 = Math.ceil(component.tcy0 / bscale);
  16643. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  16644. subband.tby1 = Math.ceil(component.tcy1 / bscale);
  16645. subband.resolution = resolution;
  16646. buildCodeblocks(context, subband, blocksDimensions);
  16647. subbands.push(subband);
  16648. resolutionSubbands.push(subband);
  16649. subband = {};
  16650. subband.type = 'LH';
  16651. subband.tbx0 = Math.ceil(component.tcx0 / bscale);
  16652. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  16653. subband.tbx1 = Math.ceil(component.tcx1 / bscale);
  16654. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  16655. subband.resolution = resolution;
  16656. buildCodeblocks(context, subband, blocksDimensions);
  16657. subbands.push(subband);
  16658. resolutionSubbands.push(subband);
  16659. subband = {};
  16660. subband.type = 'HH';
  16661. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  16662. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  16663. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  16664. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  16665. subband.resolution = resolution;
  16666. buildCodeblocks(context, subband, blocksDimensions);
  16667. subbands.push(subband);
  16668. resolutionSubbands.push(subband);
  16669. resolution.subbands = resolutionSubbands;
  16670. }
  16671. }
  16672. component.resolutions = resolutions;
  16673. component.subbands = subbands;
  16674. }
  16675. // Generate the packets sequence
  16676. var progressionOrder = tile.codingStyleDefaultParameters.progressionOrder;
  16677. switch (progressionOrder) {
  16678. case 0:
  16679. tile.packetsIterator = new LayerResolutionComponentPositionIterator(context);
  16680. break;
  16681. case 1:
  16682. tile.packetsIterator = new ResolutionLayerComponentPositionIterator(context);
  16683. break;
  16684. case 2:
  16685. tile.packetsIterator = new ResolutionPositionComponentLayerIterator(context);
  16686. break;
  16687. case 3:
  16688. tile.packetsIterator = new PositionComponentResolutionLayerIterator(context);
  16689. break;
  16690. case 4:
  16691. tile.packetsIterator = new ComponentPositionResolutionLayerIterator(context);
  16692. break;
  16693. default:
  16694. error('JPX Error: Unsupported progression order ' + progressionOrder);
  16695. }
  16696. }
  16697. function parseTilePackets(context, data, offset, dataLength) {
  16698. var position = 0;
  16699. var buffer, bufferSize = 0, skipNextBit = false;
  16700. function readBits(count) {
  16701. while (bufferSize < count) {
  16702. var b = data[offset + position];
  16703. position++;
  16704. if (skipNextBit) {
  16705. buffer = buffer << 7 | b;
  16706. bufferSize += 7;
  16707. skipNextBit = false;
  16708. } else {
  16709. buffer = buffer << 8 | b;
  16710. bufferSize += 8;
  16711. }
  16712. if (b === 0xFF) {
  16713. skipNextBit = true;
  16714. }
  16715. }
  16716. bufferSize -= count;
  16717. return buffer >>> bufferSize & (1 << count) - 1;
  16718. }
  16719. function skipMarkerIfEqual(value) {
  16720. if (data[offset + position - 1] === 0xFF && data[offset + position] === value) {
  16721. skipBytes(1);
  16722. return true;
  16723. } else if (data[offset + position] === 0xFF && data[offset + position + 1] === value) {
  16724. skipBytes(2);
  16725. return true;
  16726. }
  16727. return false;
  16728. }
  16729. function skipBytes(count) {
  16730. position += count;
  16731. }
  16732. function alignToByte() {
  16733. bufferSize = 0;
  16734. if (skipNextBit) {
  16735. position++;
  16736. skipNextBit = false;
  16737. }
  16738. }
  16739. function readCodingpasses() {
  16740. if (readBits(1) === 0) {
  16741. return 1;
  16742. }
  16743. if (readBits(1) === 0) {
  16744. return 2;
  16745. }
  16746. var value = readBits(2);
  16747. if (value < 3) {
  16748. return value + 3;
  16749. }
  16750. value = readBits(5);
  16751. if (value < 31) {
  16752. return value + 6;
  16753. }
  16754. value = readBits(7);
  16755. return value + 37;
  16756. }
  16757. var tileIndex = context.currentTile.index;
  16758. var tile = context.tiles[tileIndex];
  16759. var sopMarkerUsed = context.COD.sopMarkerUsed;
  16760. var ephMarkerUsed = context.COD.ephMarkerUsed;
  16761. var packetsIterator = tile.packetsIterator;
  16762. while (position < dataLength) {
  16763. alignToByte();
  16764. if (sopMarkerUsed && skipMarkerIfEqual(0x91)) {
  16765. // Skip also marker segment length and packet sequence ID
  16766. skipBytes(4);
  16767. }
  16768. var packet = packetsIterator.nextPacket();
  16769. if (!readBits(1)) {
  16770. continue;
  16771. }
  16772. var layerNumber = packet.layerNumber;
  16773. var queue = [], codeblock;
  16774. for (var i = 0, ii = packet.codeblocks.length; i < ii; i++) {
  16775. codeblock = packet.codeblocks[i];
  16776. var precinct = codeblock.precinct;
  16777. var codeblockColumn = codeblock.cbx - precinct.cbxMin;
  16778. var codeblockRow = codeblock.cby - precinct.cbyMin;
  16779. var codeblockIncluded = false;
  16780. var firstTimeInclusion = false;
  16781. var valueReady;
  16782. if (codeblock['included'] !== undefined) {
  16783. codeblockIncluded = !!readBits(1);
  16784. } else {
  16785. // reading inclusion tree
  16786. precinct = codeblock.precinct;
  16787. var inclusionTree, zeroBitPlanesTree;
  16788. if (precinct['inclusionTree'] !== undefined) {
  16789. inclusionTree = precinct.inclusionTree;
  16790. } else {
  16791. // building inclusion and zero bit-planes trees
  16792. var width = precinct.cbxMax - precinct.cbxMin + 1;
  16793. var height = precinct.cbyMax - precinct.cbyMin + 1;
  16794. inclusionTree = new InclusionTree(width, height, layerNumber);
  16795. zeroBitPlanesTree = new TagTree(width, height);
  16796. precinct.inclusionTree = inclusionTree;
  16797. precinct.zeroBitPlanesTree = zeroBitPlanesTree;
  16798. }
  16799. if (inclusionTree.reset(codeblockColumn, codeblockRow, layerNumber)) {
  16800. while (true) {
  16801. if (readBits(1)) {
  16802. valueReady = !inclusionTree.nextLevel();
  16803. if (valueReady) {
  16804. codeblock.included = true;
  16805. codeblockIncluded = firstTimeInclusion = true;
  16806. break;
  16807. }
  16808. } else {
  16809. inclusionTree.incrementValue(layerNumber);
  16810. break;
  16811. }
  16812. }
  16813. }
  16814. }
  16815. if (!codeblockIncluded) {
  16816. continue;
  16817. }
  16818. if (firstTimeInclusion) {
  16819. zeroBitPlanesTree = precinct.zeroBitPlanesTree;
  16820. zeroBitPlanesTree.reset(codeblockColumn, codeblockRow);
  16821. while (true) {
  16822. if (readBits(1)) {
  16823. valueReady = !zeroBitPlanesTree.nextLevel();
  16824. if (valueReady) {
  16825. break;
  16826. }
  16827. } else {
  16828. zeroBitPlanesTree.incrementValue();
  16829. }
  16830. }
  16831. codeblock.zeroBitPlanes = zeroBitPlanesTree.value;
  16832. }
  16833. var codingpasses = readCodingpasses();
  16834. while (readBits(1)) {
  16835. codeblock.Lblock++;
  16836. }
  16837. var codingpassesLog2 = log2(codingpasses);
  16838. // rounding down log2
  16839. var bits = (codingpasses < 1 << codingpassesLog2 ? codingpassesLog2 - 1 : codingpassesLog2) + codeblock.Lblock;
  16840. var codedDataLength = readBits(bits);
  16841. queue.push({
  16842. codeblock: codeblock,
  16843. codingpasses: codingpasses,
  16844. dataLength: codedDataLength
  16845. });
  16846. }
  16847. alignToByte();
  16848. if (ephMarkerUsed) {
  16849. skipMarkerIfEqual(0x92);
  16850. }
  16851. while (queue.length > 0) {
  16852. var packetItem = queue.shift();
  16853. codeblock = packetItem.codeblock;
  16854. if (codeblock['data'] === undefined) {
  16855. codeblock.data = [];
  16856. }
  16857. codeblock.data.push({
  16858. data: data,
  16859. start: offset + position,
  16860. end: offset + position + packetItem.dataLength,
  16861. codingpasses: packetItem.codingpasses
  16862. });
  16863. position += packetItem.dataLength;
  16864. }
  16865. }
  16866. return position;
  16867. }
  16868. function copyCoefficients(coefficients, levelWidth, levelHeight, subband, delta, mb, reversible, segmentationSymbolUsed) {
  16869. var x0 = subband.tbx0;
  16870. var y0 = subband.tby0;
  16871. var width = subband.tbx1 - subband.tbx0;
  16872. var codeblocks = subband.codeblocks;
  16873. var right = subband.type.charAt(0) === 'H' ? 1 : 0;
  16874. var bottom = subband.type.charAt(1) === 'H' ? levelWidth : 0;
  16875. for (var i = 0, ii = codeblocks.length; i < ii; ++i) {
  16876. var codeblock = codeblocks[i];
  16877. var blockWidth = codeblock.tbx1_ - codeblock.tbx0_;
  16878. var blockHeight = codeblock.tby1_ - codeblock.tby0_;
  16879. if (blockWidth === 0 || blockHeight === 0) {
  16880. continue;
  16881. }
  16882. if (codeblock['data'] === undefined) {
  16883. continue;
  16884. }
  16885. var bitModel, currentCodingpassType;
  16886. bitModel = new BitModel(blockWidth, blockHeight, codeblock.subbandType, codeblock.zeroBitPlanes, mb);
  16887. currentCodingpassType = 2;
  16888. // first bit plane starts from cleanup
  16889. // collect data
  16890. var data = codeblock.data, totalLength = 0, codingpasses = 0;
  16891. var j, jj, dataItem;
  16892. for (j = 0, jj = data.length; j < jj; j++) {
  16893. dataItem = data[j];
  16894. totalLength += dataItem.end - dataItem.start;
  16895. codingpasses += dataItem.codingpasses;
  16896. }
  16897. var encodedData = new Uint8Array(totalLength);
  16898. var position = 0;
  16899. for (j = 0, jj = data.length; j < jj; j++) {
  16900. dataItem = data[j];
  16901. var chunk = dataItem.data.subarray(dataItem.start, dataItem.end);
  16902. encodedData.set(chunk, position);
  16903. position += chunk.length;
  16904. }
  16905. // decoding the item
  16906. var decoder = new ArithmeticDecoder(encodedData, 0, totalLength);
  16907. bitModel.setDecoder(decoder);
  16908. for (j = 0; j < codingpasses; j++) {
  16909. switch (currentCodingpassType) {
  16910. case 0:
  16911. bitModel.runSignificancePropagationPass();
  16912. break;
  16913. case 1:
  16914. bitModel.runMagnitudeRefinementPass();
  16915. break;
  16916. case 2:
  16917. bitModel.runCleanupPass();
  16918. if (segmentationSymbolUsed) {
  16919. bitModel.checkSegmentationSymbol();
  16920. }
  16921. break;
  16922. }
  16923. currentCodingpassType = (currentCodingpassType + 1) % 3;
  16924. }
  16925. var offset = codeblock.tbx0_ - x0 + (codeblock.tby0_ - y0) * width;
  16926. var sign = bitModel.coefficentsSign;
  16927. var magnitude = bitModel.coefficentsMagnitude;
  16928. var bitsDecoded = bitModel.bitsDecoded;
  16929. var magnitudeCorrection = reversible ? 0 : 0.5;
  16930. var k, n, nb;
  16931. position = 0;
  16932. // Do the interleaving of Section F.3.3 here, so we do not need
  16933. // to copy later. LL level is not interleaved, just copied.
  16934. var interleave = subband.type !== 'LL';
  16935. for (j = 0; j < blockHeight; j++) {
  16936. var row = offset / width | 0;
  16937. // row in the non-interleaved subband
  16938. var levelOffset = 2 * row * (levelWidth - width) + right + bottom;
  16939. for (k = 0; k < blockWidth; k++) {
  16940. n = magnitude[position];
  16941. if (n !== 0) {
  16942. n = (n + magnitudeCorrection) * delta;
  16943. if (sign[position] !== 0) {
  16944. n = -n;
  16945. }
  16946. nb = bitsDecoded[position];
  16947. var pos = interleave ? levelOffset + (offset << 1) : offset;
  16948. if (reversible && nb >= mb) {
  16949. coefficients[pos] = n;
  16950. } else {
  16951. coefficients[pos] = n * (1 << mb - nb);
  16952. }
  16953. }
  16954. offset++;
  16955. position++;
  16956. }
  16957. offset += width - blockWidth;
  16958. }
  16959. }
  16960. }
  16961. function transformTile(context, tile, c) {
  16962. var component = tile.components[c];
  16963. var codingStyleParameters = component.codingStyleParameters;
  16964. var quantizationParameters = component.quantizationParameters;
  16965. var decompositionLevelsCount = codingStyleParameters.decompositionLevelsCount;
  16966. var spqcds = quantizationParameters.SPqcds;
  16967. var scalarExpounded = quantizationParameters.scalarExpounded;
  16968. var guardBits = quantizationParameters.guardBits;
  16969. var segmentationSymbolUsed = codingStyleParameters.segmentationSymbolUsed;
  16970. var precision = context.components[c].precision;
  16971. var reversible = codingStyleParameters.reversibleTransformation;
  16972. var transform = reversible ? new ReversibleTransform() : new IrreversibleTransform();
  16973. var subbandCoefficients = [];
  16974. var b = 0;
  16975. for (var i = 0; i <= decompositionLevelsCount; i++) {
  16976. var resolution = component.resolutions[i];
  16977. var width = resolution.trx1 - resolution.trx0;
  16978. var height = resolution.try1 - resolution.try0;
  16979. // Allocate space for the whole sublevel.
  16980. var coefficients = new Float32Array(width * height);
  16981. for (var j = 0, jj = resolution.subbands.length; j < jj; j++) {
  16982. var mu, epsilon;
  16983. if (!scalarExpounded) {
  16984. // formula E-5
  16985. mu = spqcds[0].mu;
  16986. epsilon = spqcds[0].epsilon + (i > 0 ? 1 - i : 0);
  16987. } else {
  16988. mu = spqcds[b].mu;
  16989. epsilon = spqcds[b].epsilon;
  16990. b++;
  16991. }
  16992. var subband = resolution.subbands[j];
  16993. var gainLog2 = SubbandsGainLog2[subband.type];
  16994. // calculate quantization coefficient (Section E.1.1.1)
  16995. var delta = reversible ? 1 : Math.pow(2, precision + gainLog2 - epsilon) * (1 + mu / 2048);
  16996. var mb = guardBits + epsilon - 1;
  16997. // In the first resolution level, copyCoefficients will fill the
  16998. // whole array with coefficients. In the succeeding passes,
  16999. // copyCoefficients will consecutively fill in the values that belong
  17000. // to the interleaved positions of the HL, LH, and HH coefficients.
  17001. // The LL coefficients will then be interleaved in Transform.iterate().
  17002. copyCoefficients(coefficients, width, height, subband, delta, mb, reversible, segmentationSymbolUsed);
  17003. }
  17004. subbandCoefficients.push({
  17005. width: width,
  17006. height: height,
  17007. items: coefficients
  17008. });
  17009. }
  17010. var result = transform.calculate(subbandCoefficients, component.tcx0, component.tcy0);
  17011. return {
  17012. left: component.tcx0,
  17013. top: component.tcy0,
  17014. width: result.width,
  17015. height: result.height,
  17016. items: result.items
  17017. };
  17018. }
  17019. function transformComponents(context) {
  17020. var siz = context.SIZ;
  17021. var components = context.components;
  17022. var componentsCount = siz.Csiz;
  17023. var resultImages = [];
  17024. for (var i = 0, ii = context.tiles.length; i < ii; i++) {
  17025. var tile = context.tiles[i];
  17026. var transformedTiles = [];
  17027. var c;
  17028. for (c = 0; c < componentsCount; c++) {
  17029. transformedTiles[c] = transformTile(context, tile, c);
  17030. }
  17031. var tile0 = transformedTiles[0];
  17032. var out = new Uint8Array(tile0.items.length * componentsCount);
  17033. var result = {
  17034. left: tile0.left,
  17035. top: tile0.top,
  17036. width: tile0.width,
  17037. height: tile0.height,
  17038. items: out
  17039. };
  17040. // Section G.2.2 Inverse multi component transform
  17041. var shift, offset, max, min, maxK;
  17042. var pos = 0, j, jj, y0, y1, y2, r, g, b, k, val;
  17043. if (tile.codingStyleDefaultParameters.multipleComponentTransform) {
  17044. var fourComponents = componentsCount === 4;
  17045. var y0items = transformedTiles[0].items;
  17046. var y1items = transformedTiles[1].items;
  17047. var y2items = transformedTiles[2].items;
  17048. var y3items = fourComponents ? transformedTiles[3].items : null;
  17049. // HACK: The multiple component transform formulas below assume that
  17050. // all components have the same precision. With this in mind, we
  17051. // compute shift and offset only once.
  17052. shift = components[0].precision - 8;
  17053. offset = (128 << shift) + 0.5;
  17054. max = 255 * (1 << shift);
  17055. maxK = max * 0.5;
  17056. min = -maxK;
  17057. var component0 = tile.components[0];
  17058. var alpha01 = componentsCount - 3;
  17059. jj = y0items.length;
  17060. if (!component0.codingStyleParameters.reversibleTransformation) {
  17061. // inverse irreversible multiple component transform
  17062. for (j = 0; j < jj; j++, pos += alpha01) {
  17063. y0 = y0items[j] + offset;
  17064. y1 = y1items[j];
  17065. y2 = y2items[j];
  17066. r = y0 + 1.402 * y2;
  17067. g = y0 - 0.34413 * y1 - 0.71414 * y2;
  17068. b = y0 + 1.772 * y1;
  17069. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  17070. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  17071. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  17072. }
  17073. } else {
  17074. // inverse reversible multiple component transform
  17075. for (j = 0; j < jj; j++, pos += alpha01) {
  17076. y0 = y0items[j] + offset;
  17077. y1 = y1items[j];
  17078. y2 = y2items[j];
  17079. g = y0 - (y2 + y1 >> 2);
  17080. r = g + y2;
  17081. b = g + y1;
  17082. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  17083. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  17084. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  17085. }
  17086. }
  17087. if (fourComponents) {
  17088. for (j = 0, pos = 3; j < jj; j++, pos += 4) {
  17089. k = y3items[j];
  17090. out[pos] = k <= min ? 0 : k >= maxK ? 255 : k + offset >> shift;
  17091. }
  17092. }
  17093. } else {
  17094. // no multi-component transform
  17095. for (c = 0; c < componentsCount; c++) {
  17096. var items = transformedTiles[c].items;
  17097. shift = components[c].precision - 8;
  17098. offset = (128 << shift) + 0.5;
  17099. max = 127.5 * (1 << shift);
  17100. min = -max;
  17101. for (pos = c, j = 0, jj = items.length; j < jj; j++) {
  17102. val = items[j];
  17103. out[pos] = val <= min ? 0 : val >= max ? 255 : val + offset >> shift;
  17104. pos += componentsCount;
  17105. }
  17106. }
  17107. }
  17108. resultImages.push(result);
  17109. }
  17110. return resultImages;
  17111. }
  17112. function initializeTile(context, tileIndex) {
  17113. var siz = context.SIZ;
  17114. var componentsCount = siz.Csiz;
  17115. var tile = context.tiles[tileIndex];
  17116. for (var c = 0; c < componentsCount; c++) {
  17117. var component = tile.components[c];
  17118. var qcdOrQcc = context.currentTile.QCC[c] !== undefined ? context.currentTile.QCC[c] : context.currentTile.QCD;
  17119. component.quantizationParameters = qcdOrQcc;
  17120. var codOrCoc = context.currentTile.COC[c] !== undefined ? context.currentTile.COC[c] : context.currentTile.COD;
  17121. component.codingStyleParameters = codOrCoc;
  17122. }
  17123. tile.codingStyleDefaultParameters = context.currentTile.COD;
  17124. }
  17125. // Section B.10.2 Tag trees
  17126. var TagTree = function TagTreeClosure() {
  17127. function TagTree(width, height) {
  17128. var levelsLength = log2(Math.max(width, height)) + 1;
  17129. this.levels = [];
  17130. for (var i = 0; i < levelsLength; i++) {
  17131. var level = {
  17132. width: width,
  17133. height: height,
  17134. items: []
  17135. };
  17136. this.levels.push(level);
  17137. width = Math.ceil(width / 2);
  17138. height = Math.ceil(height / 2);
  17139. }
  17140. }
  17141. TagTree.prototype = {
  17142. reset: function TagTree_reset(i, j) {
  17143. var currentLevel = 0, value = 0, level;
  17144. while (currentLevel < this.levels.length) {
  17145. level = this.levels[currentLevel];
  17146. var index = i + j * level.width;
  17147. if (level.items[index] !== undefined) {
  17148. value = level.items[index];
  17149. break;
  17150. }
  17151. level.index = index;
  17152. i >>= 1;
  17153. j >>= 1;
  17154. currentLevel++;
  17155. }
  17156. currentLevel--;
  17157. level = this.levels[currentLevel];
  17158. level.items[level.index] = value;
  17159. this.currentLevel = currentLevel;
  17160. delete this.value;
  17161. },
  17162. incrementValue: function TagTree_incrementValue() {
  17163. var level = this.levels[this.currentLevel];
  17164. level.items[level.index]++;
  17165. },
  17166. nextLevel: function TagTree_nextLevel() {
  17167. var currentLevel = this.currentLevel;
  17168. var level = this.levels[currentLevel];
  17169. var value = level.items[level.index];
  17170. currentLevel--;
  17171. if (currentLevel < 0) {
  17172. this.value = value;
  17173. return false;
  17174. }
  17175. this.currentLevel = currentLevel;
  17176. level = this.levels[currentLevel];
  17177. level.items[level.index] = value;
  17178. return true;
  17179. }
  17180. };
  17181. return TagTree;
  17182. }();
  17183. var InclusionTree = function InclusionTreeClosure() {
  17184. function InclusionTree(width, height, defaultValue) {
  17185. var levelsLength = log2(Math.max(width, height)) + 1;
  17186. this.levels = [];
  17187. for (var i = 0; i < levelsLength; i++) {
  17188. var items = new Uint8Array(width * height);
  17189. for (var j = 0, jj = items.length; j < jj; j++) {
  17190. items[j] = defaultValue;
  17191. }
  17192. var level = {
  17193. width: width,
  17194. height: height,
  17195. items: items
  17196. };
  17197. this.levels.push(level);
  17198. width = Math.ceil(width / 2);
  17199. height = Math.ceil(height / 2);
  17200. }
  17201. }
  17202. InclusionTree.prototype = {
  17203. reset: function InclusionTree_reset(i, j, stopValue) {
  17204. var currentLevel = 0;
  17205. while (currentLevel < this.levels.length) {
  17206. var level = this.levels[currentLevel];
  17207. var index = i + j * level.width;
  17208. level.index = index;
  17209. var value = level.items[index];
  17210. if (value === 0xFF) {
  17211. break;
  17212. }
  17213. if (value > stopValue) {
  17214. this.currentLevel = currentLevel;
  17215. // already know about this one, propagating the value to top levels
  17216. this.propagateValues();
  17217. return false;
  17218. }
  17219. i >>= 1;
  17220. j >>= 1;
  17221. currentLevel++;
  17222. }
  17223. this.currentLevel = currentLevel - 1;
  17224. return true;
  17225. },
  17226. incrementValue: function InclusionTree_incrementValue(stopValue) {
  17227. var level = this.levels[this.currentLevel];
  17228. level.items[level.index] = stopValue + 1;
  17229. this.propagateValues();
  17230. },
  17231. propagateValues: function InclusionTree_propagateValues() {
  17232. var levelIndex = this.currentLevel;
  17233. var level = this.levels[levelIndex];
  17234. var currentValue = level.items[level.index];
  17235. while (--levelIndex >= 0) {
  17236. level = this.levels[levelIndex];
  17237. level.items[level.index] = currentValue;
  17238. }
  17239. },
  17240. nextLevel: function InclusionTree_nextLevel() {
  17241. var currentLevel = this.currentLevel;
  17242. var level = this.levels[currentLevel];
  17243. var value = level.items[level.index];
  17244. level.items[level.index] = 0xFF;
  17245. currentLevel--;
  17246. if (currentLevel < 0) {
  17247. return false;
  17248. }
  17249. this.currentLevel = currentLevel;
  17250. level = this.levels[currentLevel];
  17251. level.items[level.index] = value;
  17252. return true;
  17253. }
  17254. };
  17255. return InclusionTree;
  17256. }();
  17257. // Section D. Coefficient bit modeling
  17258. var BitModel = function BitModelClosure() {
  17259. var UNIFORM_CONTEXT = 17;
  17260. var RUNLENGTH_CONTEXT = 18;
  17261. // Table D-1
  17262. // The index is binary presentation: 0dddvvhh, ddd - sum of Di (0..4),
  17263. // vv - sum of Vi (0..2), and hh - sum of Hi (0..2)
  17264. var LLAndLHContextsLabel = new Uint8Array([
  17265. 0,
  17266. 5,
  17267. 8,
  17268. 0,
  17269. 3,
  17270. 7,
  17271. 8,
  17272. 0,
  17273. 4,
  17274. 7,
  17275. 8,
  17276. 0,
  17277. 0,
  17278. 0,
  17279. 0,
  17280. 0,
  17281. 1,
  17282. 6,
  17283. 8,
  17284. 0,
  17285. 3,
  17286. 7,
  17287. 8,
  17288. 0,
  17289. 4,
  17290. 7,
  17291. 8,
  17292. 0,
  17293. 0,
  17294. 0,
  17295. 0,
  17296. 0,
  17297. 2,
  17298. 6,
  17299. 8,
  17300. 0,
  17301. 3,
  17302. 7,
  17303. 8,
  17304. 0,
  17305. 4,
  17306. 7,
  17307. 8,
  17308. 0,
  17309. 0,
  17310. 0,
  17311. 0,
  17312. 0,
  17313. 2,
  17314. 6,
  17315. 8,
  17316. 0,
  17317. 3,
  17318. 7,
  17319. 8,
  17320. 0,
  17321. 4,
  17322. 7,
  17323. 8,
  17324. 0,
  17325. 0,
  17326. 0,
  17327. 0,
  17328. 0,
  17329. 2,
  17330. 6,
  17331. 8,
  17332. 0,
  17333. 3,
  17334. 7,
  17335. 8,
  17336. 0,
  17337. 4,
  17338. 7,
  17339. 8
  17340. ]);
  17341. var HLContextLabel = new Uint8Array([
  17342. 0,
  17343. 3,
  17344. 4,
  17345. 0,
  17346. 5,
  17347. 7,
  17348. 7,
  17349. 0,
  17350. 8,
  17351. 8,
  17352. 8,
  17353. 0,
  17354. 0,
  17355. 0,
  17356. 0,
  17357. 0,
  17358. 1,
  17359. 3,
  17360. 4,
  17361. 0,
  17362. 6,
  17363. 7,
  17364. 7,
  17365. 0,
  17366. 8,
  17367. 8,
  17368. 8,
  17369. 0,
  17370. 0,
  17371. 0,
  17372. 0,
  17373. 0,
  17374. 2,
  17375. 3,
  17376. 4,
  17377. 0,
  17378. 6,
  17379. 7,
  17380. 7,
  17381. 0,
  17382. 8,
  17383. 8,
  17384. 8,
  17385. 0,
  17386. 0,
  17387. 0,
  17388. 0,
  17389. 0,
  17390. 2,
  17391. 3,
  17392. 4,
  17393. 0,
  17394. 6,
  17395. 7,
  17396. 7,
  17397. 0,
  17398. 8,
  17399. 8,
  17400. 8,
  17401. 0,
  17402. 0,
  17403. 0,
  17404. 0,
  17405. 0,
  17406. 2,
  17407. 3,
  17408. 4,
  17409. 0,
  17410. 6,
  17411. 7,
  17412. 7,
  17413. 0,
  17414. 8,
  17415. 8,
  17416. 8
  17417. ]);
  17418. var HHContextLabel = new Uint8Array([
  17419. 0,
  17420. 1,
  17421. 2,
  17422. 0,
  17423. 1,
  17424. 2,
  17425. 2,
  17426. 0,
  17427. 2,
  17428. 2,
  17429. 2,
  17430. 0,
  17431. 0,
  17432. 0,
  17433. 0,
  17434. 0,
  17435. 3,
  17436. 4,
  17437. 5,
  17438. 0,
  17439. 4,
  17440. 5,
  17441. 5,
  17442. 0,
  17443. 5,
  17444. 5,
  17445. 5,
  17446. 0,
  17447. 0,
  17448. 0,
  17449. 0,
  17450. 0,
  17451. 6,
  17452. 7,
  17453. 7,
  17454. 0,
  17455. 7,
  17456. 7,
  17457. 7,
  17458. 0,
  17459. 7,
  17460. 7,
  17461. 7,
  17462. 0,
  17463. 0,
  17464. 0,
  17465. 0,
  17466. 0,
  17467. 8,
  17468. 8,
  17469. 8,
  17470. 0,
  17471. 8,
  17472. 8,
  17473. 8,
  17474. 0,
  17475. 8,
  17476. 8,
  17477. 8,
  17478. 0,
  17479. 0,
  17480. 0,
  17481. 0,
  17482. 0,
  17483. 8,
  17484. 8,
  17485. 8,
  17486. 0,
  17487. 8,
  17488. 8,
  17489. 8,
  17490. 0,
  17491. 8,
  17492. 8,
  17493. 8
  17494. ]);
  17495. function BitModel(width, height, subband, zeroBitPlanes, mb) {
  17496. this.width = width;
  17497. this.height = height;
  17498. this.contextLabelTable = subband === 'HH' ? HHContextLabel : subband === 'HL' ? HLContextLabel : LLAndLHContextsLabel;
  17499. var coefficientCount = width * height;
  17500. // coefficients outside the encoding region treated as insignificant
  17501. // add border state cells for significanceState
  17502. this.neighborsSignificance = new Uint8Array(coefficientCount);
  17503. this.coefficentsSign = new Uint8Array(coefficientCount);
  17504. this.coefficentsMagnitude = mb > 14 ? new Uint32Array(coefficientCount) : mb > 6 ? new Uint16Array(coefficientCount) : new Uint8Array(coefficientCount);
  17505. this.processingFlags = new Uint8Array(coefficientCount);
  17506. var bitsDecoded = new Uint8Array(coefficientCount);
  17507. if (zeroBitPlanes !== 0) {
  17508. for (var i = 0; i < coefficientCount; i++) {
  17509. bitsDecoded[i] = zeroBitPlanes;
  17510. }
  17511. }
  17512. this.bitsDecoded = bitsDecoded;
  17513. this.reset();
  17514. }
  17515. BitModel.prototype = {
  17516. setDecoder: function BitModel_setDecoder(decoder) {
  17517. this.decoder = decoder;
  17518. },
  17519. reset: function BitModel_reset() {
  17520. // We have 17 contexts that are accessed via context labels,
  17521. // plus the uniform and runlength context.
  17522. this.contexts = new Int8Array(19);
  17523. // Contexts are packed into 1 byte:
  17524. // highest 7 bits carry the index, lowest bit carries mps
  17525. this.contexts[0] = 4 << 1 | 0;
  17526. this.contexts[UNIFORM_CONTEXT] = 46 << 1 | 0;
  17527. this.contexts[RUNLENGTH_CONTEXT] = 3 << 1 | 0;
  17528. },
  17529. setNeighborsSignificance: function BitModel_setNeighborsSignificance(row, column, index) {
  17530. var neighborsSignificance = this.neighborsSignificance;
  17531. var width = this.width, height = this.height;
  17532. var left = column > 0;
  17533. var right = column + 1 < width;
  17534. var i;
  17535. if (row > 0) {
  17536. i = index - width;
  17537. if (left) {
  17538. neighborsSignificance[i - 1] += 0x10;
  17539. }
  17540. if (right) {
  17541. neighborsSignificance[i + 1] += 0x10;
  17542. }
  17543. neighborsSignificance[i] += 0x04;
  17544. }
  17545. if (row + 1 < height) {
  17546. i = index + width;
  17547. if (left) {
  17548. neighborsSignificance[i - 1] += 0x10;
  17549. }
  17550. if (right) {
  17551. neighborsSignificance[i + 1] += 0x10;
  17552. }
  17553. neighborsSignificance[i] += 0x04;
  17554. }
  17555. if (left) {
  17556. neighborsSignificance[index - 1] += 0x01;
  17557. }
  17558. if (right) {
  17559. neighborsSignificance[index + 1] += 0x01;
  17560. }
  17561. neighborsSignificance[index] |= 0x80;
  17562. },
  17563. runSignificancePropagationPass: function BitModel_runSignificancePropagationPass() {
  17564. var decoder = this.decoder;
  17565. var width = this.width, height = this.height;
  17566. var coefficentsMagnitude = this.coefficentsMagnitude;
  17567. var coefficentsSign = this.coefficentsSign;
  17568. var neighborsSignificance = this.neighborsSignificance;
  17569. var processingFlags = this.processingFlags;
  17570. var contexts = this.contexts;
  17571. var labels = this.contextLabelTable;
  17572. var bitsDecoded = this.bitsDecoded;
  17573. var processedInverseMask = ~1;
  17574. var processedMask = 1;
  17575. var firstMagnitudeBitMask = 2;
  17576. for (var i0 = 0; i0 < height; i0 += 4) {
  17577. for (var j = 0; j < width; j++) {
  17578. var index = i0 * width + j;
  17579. for (var i1 = 0; i1 < 4; i1++, index += width) {
  17580. var i = i0 + i1;
  17581. if (i >= height) {
  17582. break;
  17583. }
  17584. // clear processed flag first
  17585. processingFlags[index] &= processedInverseMask;
  17586. if (coefficentsMagnitude[index] || !neighborsSignificance[index]) {
  17587. continue;
  17588. }
  17589. var contextLabel = labels[neighborsSignificance[index]];
  17590. var decision = decoder.readBit(contexts, contextLabel);
  17591. if (decision) {
  17592. var sign = this.decodeSignBit(i, j, index);
  17593. coefficentsSign[index] = sign;
  17594. coefficentsMagnitude[index] = 1;
  17595. this.setNeighborsSignificance(i, j, index);
  17596. processingFlags[index] |= firstMagnitudeBitMask;
  17597. }
  17598. bitsDecoded[index]++;
  17599. processingFlags[index] |= processedMask;
  17600. }
  17601. }
  17602. }
  17603. },
  17604. decodeSignBit: function BitModel_decodeSignBit(row, column, index) {
  17605. var width = this.width, height = this.height;
  17606. var coefficentsMagnitude = this.coefficentsMagnitude;
  17607. var coefficentsSign = this.coefficentsSign;
  17608. var contribution, sign0, sign1, significance1;
  17609. var contextLabel, decoded;
  17610. // calculate horizontal contribution
  17611. significance1 = column > 0 && coefficentsMagnitude[index - 1] !== 0;
  17612. if (column + 1 < width && coefficentsMagnitude[index + 1] !== 0) {
  17613. sign1 = coefficentsSign[index + 1];
  17614. if (significance1) {
  17615. sign0 = coefficentsSign[index - 1];
  17616. contribution = 1 - sign1 - sign0;
  17617. } else {
  17618. contribution = 1 - sign1 - sign1;
  17619. }
  17620. } else if (significance1) {
  17621. sign0 = coefficentsSign[index - 1];
  17622. contribution = 1 - sign0 - sign0;
  17623. } else {
  17624. contribution = 0;
  17625. }
  17626. var horizontalContribution = 3 * contribution;
  17627. // calculate vertical contribution and combine with the horizontal
  17628. significance1 = row > 0 && coefficentsMagnitude[index - width] !== 0;
  17629. if (row + 1 < height && coefficentsMagnitude[index + width] !== 0) {
  17630. sign1 = coefficentsSign[index + width];
  17631. if (significance1) {
  17632. sign0 = coefficentsSign[index - width];
  17633. contribution = 1 - sign1 - sign0 + horizontalContribution;
  17634. } else {
  17635. contribution = 1 - sign1 - sign1 + horizontalContribution;
  17636. }
  17637. } else if (significance1) {
  17638. sign0 = coefficentsSign[index - width];
  17639. contribution = 1 - sign0 - sign0 + horizontalContribution;
  17640. } else {
  17641. contribution = horizontalContribution;
  17642. }
  17643. if (contribution >= 0) {
  17644. contextLabel = 9 + contribution;
  17645. decoded = this.decoder.readBit(this.contexts, contextLabel);
  17646. } else {
  17647. contextLabel = 9 - contribution;
  17648. decoded = this.decoder.readBit(this.contexts, contextLabel) ^ 1;
  17649. }
  17650. return decoded;
  17651. },
  17652. runMagnitudeRefinementPass: function BitModel_runMagnitudeRefinementPass() {
  17653. var decoder = this.decoder;
  17654. var width = this.width, height = this.height;
  17655. var coefficentsMagnitude = this.coefficentsMagnitude;
  17656. var neighborsSignificance = this.neighborsSignificance;
  17657. var contexts = this.contexts;
  17658. var bitsDecoded = this.bitsDecoded;
  17659. var processingFlags = this.processingFlags;
  17660. var processedMask = 1;
  17661. var firstMagnitudeBitMask = 2;
  17662. var length = width * height;
  17663. var width4 = width * 4;
  17664. for (var index0 = 0, indexNext; index0 < length; index0 = indexNext) {
  17665. indexNext = Math.min(length, index0 + width4);
  17666. for (var j = 0; j < width; j++) {
  17667. for (var index = index0 + j; index < indexNext; index += width) {
  17668. // significant but not those that have just become
  17669. if (!coefficentsMagnitude[index] || (processingFlags[index] & processedMask) !== 0) {
  17670. continue;
  17671. }
  17672. var contextLabel = 16;
  17673. if ((processingFlags[index] & firstMagnitudeBitMask) !== 0) {
  17674. processingFlags[index] ^= firstMagnitudeBitMask;
  17675. // first refinement
  17676. var significance = neighborsSignificance[index] & 127;
  17677. contextLabel = significance === 0 ? 15 : 14;
  17678. }
  17679. var bit = decoder.readBit(contexts, contextLabel);
  17680. coefficentsMagnitude[index] = coefficentsMagnitude[index] << 1 | bit;
  17681. bitsDecoded[index]++;
  17682. processingFlags[index] |= processedMask;
  17683. }
  17684. }
  17685. }
  17686. },
  17687. runCleanupPass: function BitModel_runCleanupPass() {
  17688. var decoder = this.decoder;
  17689. var width = this.width, height = this.height;
  17690. var neighborsSignificance = this.neighborsSignificance;
  17691. var coefficentsMagnitude = this.coefficentsMagnitude;
  17692. var coefficentsSign = this.coefficentsSign;
  17693. var contexts = this.contexts;
  17694. var labels = this.contextLabelTable;
  17695. var bitsDecoded = this.bitsDecoded;
  17696. var processingFlags = this.processingFlags;
  17697. var processedMask = 1;
  17698. var firstMagnitudeBitMask = 2;
  17699. var oneRowDown = width;
  17700. var twoRowsDown = width * 2;
  17701. var threeRowsDown = width * 3;
  17702. var iNext;
  17703. for (var i0 = 0; i0 < height; i0 = iNext) {
  17704. iNext = Math.min(i0 + 4, height);
  17705. var indexBase = i0 * width;
  17706. var checkAllEmpty = i0 + 3 < height;
  17707. for (var j = 0; j < width; j++) {
  17708. var index0 = indexBase + j;
  17709. // using the property: labels[neighborsSignificance[index]] === 0
  17710. // when neighborsSignificance[index] === 0
  17711. var allEmpty = checkAllEmpty && processingFlags[index0] === 0 && processingFlags[index0 + oneRowDown] === 0 && processingFlags[index0 + twoRowsDown] === 0 && processingFlags[index0 + threeRowsDown] === 0 && neighborsSignificance[index0] === 0 && neighborsSignificance[index0 + oneRowDown] === 0 && neighborsSignificance[index0 + twoRowsDown] === 0 && neighborsSignificance[index0 + threeRowsDown] === 0;
  17712. var i1 = 0, index = index0;
  17713. var i = i0, sign;
  17714. if (allEmpty) {
  17715. var hasSignificantCoefficent = decoder.readBit(contexts, RUNLENGTH_CONTEXT);
  17716. if (!hasSignificantCoefficent) {
  17717. bitsDecoded[index0]++;
  17718. bitsDecoded[index0 + oneRowDown]++;
  17719. bitsDecoded[index0 + twoRowsDown]++;
  17720. bitsDecoded[index0 + threeRowsDown]++;
  17721. continue;
  17722. }
  17723. // next column
  17724. i1 = decoder.readBit(contexts, UNIFORM_CONTEXT) << 1 | decoder.readBit(contexts, UNIFORM_CONTEXT);
  17725. if (i1 !== 0) {
  17726. i = i0 + i1;
  17727. index += i1 * width;
  17728. }
  17729. sign = this.decodeSignBit(i, j, index);
  17730. coefficentsSign[index] = sign;
  17731. coefficentsMagnitude[index] = 1;
  17732. this.setNeighborsSignificance(i, j, index);
  17733. processingFlags[index] |= firstMagnitudeBitMask;
  17734. index = index0;
  17735. for (var i2 = i0; i2 <= i; i2++, index += width) {
  17736. bitsDecoded[index]++;
  17737. }
  17738. i1++;
  17739. }
  17740. for (i = i0 + i1; i < iNext; i++, index += width) {
  17741. if (coefficentsMagnitude[index] || (processingFlags[index] & processedMask) !== 0) {
  17742. continue;
  17743. }
  17744. var contextLabel = labels[neighborsSignificance[index]];
  17745. var decision = decoder.readBit(contexts, contextLabel);
  17746. if (decision === 1) {
  17747. sign = this.decodeSignBit(i, j, index);
  17748. coefficentsSign[index] = sign;
  17749. coefficentsMagnitude[index] = 1;
  17750. this.setNeighborsSignificance(i, j, index);
  17751. processingFlags[index] |= firstMagnitudeBitMask;
  17752. }
  17753. bitsDecoded[index]++;
  17754. }
  17755. }
  17756. }
  17757. },
  17758. checkSegmentationSymbol: function BitModel_checkSegmentationSymbol() {
  17759. var decoder = this.decoder;
  17760. var contexts = this.contexts;
  17761. var symbol = decoder.readBit(contexts, UNIFORM_CONTEXT) << 3 | decoder.readBit(contexts, UNIFORM_CONTEXT) << 2 | decoder.readBit(contexts, UNIFORM_CONTEXT) << 1 | decoder.readBit(contexts, UNIFORM_CONTEXT);
  17762. if (symbol !== 0xA) {
  17763. error('JPX Error: Invalid segmentation symbol');
  17764. }
  17765. }
  17766. };
  17767. return BitModel;
  17768. }();
  17769. // Section F, Discrete wavelet transformation
  17770. var Transform = function TransformClosure() {
  17771. function Transform() {
  17772. }
  17773. Transform.prototype.calculate = function transformCalculate(subbands, u0, v0) {
  17774. var ll = subbands[0];
  17775. for (var i = 1, ii = subbands.length; i < ii; i++) {
  17776. ll = this.iterate(ll, subbands[i], u0, v0);
  17777. }
  17778. return ll;
  17779. };
  17780. Transform.prototype.extend = function extend(buffer, offset, size) {
  17781. // Section F.3.7 extending... using max extension of 4
  17782. var i1 = offset - 1, j1 = offset + 1;
  17783. var i2 = offset + size - 2, j2 = offset + size;
  17784. buffer[i1--] = buffer[j1++];
  17785. buffer[j2++] = buffer[i2--];
  17786. buffer[i1--] = buffer[j1++];
  17787. buffer[j2++] = buffer[i2--];
  17788. buffer[i1--] = buffer[j1++];
  17789. buffer[j2++] = buffer[i2--];
  17790. buffer[i1] = buffer[j1];
  17791. buffer[j2] = buffer[i2];
  17792. };
  17793. Transform.prototype.iterate = function Transform_iterate(ll, hl_lh_hh, u0, v0) {
  17794. var llWidth = ll.width, llHeight = ll.height, llItems = ll.items;
  17795. var width = hl_lh_hh.width;
  17796. var height = hl_lh_hh.height;
  17797. var items = hl_lh_hh.items;
  17798. var i, j, k, l, u, v;
  17799. // Interleave LL according to Section F.3.3
  17800. for (k = 0, i = 0; i < llHeight; i++) {
  17801. l = i * 2 * width;
  17802. for (j = 0; j < llWidth; j++, k++, l += 2) {
  17803. items[l] = llItems[k];
  17804. }
  17805. }
  17806. // The LL band is not needed anymore.
  17807. llItems = ll.items = null;
  17808. var bufferPadding = 4;
  17809. var rowBuffer = new Float32Array(width + 2 * bufferPadding);
  17810. // Section F.3.4 HOR_SR
  17811. if (width === 1) {
  17812. // if width = 1, when u0 even keep items as is, when odd divide by 2
  17813. if ((u0 & 1) !== 0) {
  17814. for (v = 0, k = 0; v < height; v++, k += width) {
  17815. items[k] *= 0.5;
  17816. }
  17817. }
  17818. } else {
  17819. for (v = 0, k = 0; v < height; v++, k += width) {
  17820. rowBuffer.set(items.subarray(k, k + width), bufferPadding);
  17821. this.extend(rowBuffer, bufferPadding, width);
  17822. this.filter(rowBuffer, bufferPadding, width);
  17823. items.set(rowBuffer.subarray(bufferPadding, bufferPadding + width), k);
  17824. }
  17825. }
  17826. // Accesses to the items array can take long, because it may not fit into
  17827. // CPU cache and has to be fetched from main memory. Since subsequent
  17828. // accesses to the items array are not local when reading columns, we
  17829. // have a cache miss every time. To reduce cache misses, get up to
  17830. // 'numBuffers' items at a time and store them into the individual
  17831. // buffers. The colBuffers should be small enough to fit into CPU cache.
  17832. var numBuffers = 16;
  17833. var colBuffers = [];
  17834. for (i = 0; i < numBuffers; i++) {
  17835. colBuffers.push(new Float32Array(height + 2 * bufferPadding));
  17836. }
  17837. var b, currentBuffer = 0;
  17838. ll = bufferPadding + height;
  17839. // Section F.3.5 VER_SR
  17840. if (height === 1) {
  17841. // if height = 1, when v0 even keep items as is, when odd divide by 2
  17842. if ((v0 & 1) !== 0) {
  17843. for (u = 0; u < width; u++) {
  17844. items[u] *= 0.5;
  17845. }
  17846. }
  17847. } else {
  17848. for (u = 0; u < width; u++) {
  17849. // if we ran out of buffers, copy several image columns at once
  17850. if (currentBuffer === 0) {
  17851. numBuffers = Math.min(width - u, numBuffers);
  17852. for (k = u, l = bufferPadding; l < ll; k += width, l++) {
  17853. for (b = 0; b < numBuffers; b++) {
  17854. colBuffers[b][l] = items[k + b];
  17855. }
  17856. }
  17857. currentBuffer = numBuffers;
  17858. }
  17859. currentBuffer--;
  17860. var buffer = colBuffers[currentBuffer];
  17861. this.extend(buffer, bufferPadding, height);
  17862. this.filter(buffer, bufferPadding, height);
  17863. // If this is last buffer in this group of buffers, flush all buffers.
  17864. if (currentBuffer === 0) {
  17865. k = u - numBuffers + 1;
  17866. for (l = bufferPadding; l < ll; k += width, l++) {
  17867. for (b = 0; b < numBuffers; b++) {
  17868. items[k + b] = colBuffers[b][l];
  17869. }
  17870. }
  17871. }
  17872. }
  17873. }
  17874. return {
  17875. width: width,
  17876. height: height,
  17877. items: items
  17878. };
  17879. };
  17880. return Transform;
  17881. }();
  17882. // Section 3.8.2 Irreversible 9-7 filter
  17883. var IrreversibleTransform = function IrreversibleTransformClosure() {
  17884. function IrreversibleTransform() {
  17885. Transform.call(this);
  17886. }
  17887. IrreversibleTransform.prototype = Object.create(Transform.prototype);
  17888. IrreversibleTransform.prototype.filter = function irreversibleTransformFilter(x, offset, length) {
  17889. var len = length >> 1;
  17890. offset = offset | 0;
  17891. var j, n, current, next;
  17892. var alpha = -1.586134342059924;
  17893. var beta = -0.052980118572961;
  17894. var gamma = 0.882911075530934;
  17895. var delta = 0.443506852043971;
  17896. var K = 1.230174104914001;
  17897. var K_ = 1 / K;
  17898. // step 1 is combined with step 3
  17899. // step 2
  17900. j = offset - 3;
  17901. for (n = len + 4; n--; j += 2) {
  17902. x[j] *= K_;
  17903. }
  17904. // step 1 & 3
  17905. j = offset - 2;
  17906. current = delta * x[j - 1];
  17907. for (n = len + 3; n--; j += 2) {
  17908. next = delta * x[j + 1];
  17909. x[j] = K * x[j] - current - next;
  17910. if (n--) {
  17911. j += 2;
  17912. current = delta * x[j + 1];
  17913. x[j] = K * x[j] - current - next;
  17914. } else {
  17915. break;
  17916. }
  17917. }
  17918. // step 4
  17919. j = offset - 1;
  17920. current = gamma * x[j - 1];
  17921. for (n = len + 2; n--; j += 2) {
  17922. next = gamma * x[j + 1];
  17923. x[j] -= current + next;
  17924. if (n--) {
  17925. j += 2;
  17926. current = gamma * x[j + 1];
  17927. x[j] -= current + next;
  17928. } else {
  17929. break;
  17930. }
  17931. }
  17932. // step 5
  17933. j = offset;
  17934. current = beta * x[j - 1];
  17935. for (n = len + 1; n--; j += 2) {
  17936. next = beta * x[j + 1];
  17937. x[j] -= current + next;
  17938. if (n--) {
  17939. j += 2;
  17940. current = beta * x[j + 1];
  17941. x[j] -= current + next;
  17942. } else {
  17943. break;
  17944. }
  17945. }
  17946. // step 6
  17947. if (len !== 0) {
  17948. j = offset + 1;
  17949. current = alpha * x[j - 1];
  17950. for (n = len; n--; j += 2) {
  17951. next = alpha * x[j + 1];
  17952. x[j] -= current + next;
  17953. if (n--) {
  17954. j += 2;
  17955. current = alpha * x[j + 1];
  17956. x[j] -= current + next;
  17957. } else {
  17958. break;
  17959. }
  17960. }
  17961. }
  17962. };
  17963. return IrreversibleTransform;
  17964. }();
  17965. // Section 3.8.1 Reversible 5-3 filter
  17966. var ReversibleTransform = function ReversibleTransformClosure() {
  17967. function ReversibleTransform() {
  17968. Transform.call(this);
  17969. }
  17970. ReversibleTransform.prototype = Object.create(Transform.prototype);
  17971. ReversibleTransform.prototype.filter = function reversibleTransformFilter(x, offset, length) {
  17972. var len = length >> 1;
  17973. offset = offset | 0;
  17974. var j, n;
  17975. for (j = offset, n = len + 1; n--; j += 2) {
  17976. x[j] -= x[j - 1] + x[j + 1] + 2 >> 2;
  17977. }
  17978. for (j = offset + 1, n = len; n--; j += 2) {
  17979. x[j] += x[j - 1] + x[j + 1] >> 1;
  17980. }
  17981. };
  17982. return ReversibleTransform;
  17983. }();
  17984. return JpxImage;
  17985. }();
  17986. exports.JpxImage = JpxImage;
  17987. }));
  17988. (function (root, factory) {
  17989. factory(root.pdfjsCoreMetrics = {}, root.pdfjsSharedUtil);
  17990. }(this, function (exports, sharedUtil) {
  17991. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  17992. // The Metrics object contains glyph widths (in glyph space units).
  17993. // As per PDF spec, for most fonts (Type 3 being an exception) a glyph
  17994. // space unit corresponds to 1/1000th of text space unit.
  17995. var getMetrics = getLookupTableFactory(function (t) {
  17996. t['Courier'] = 600;
  17997. t['Courier-Bold'] = 600;
  17998. t['Courier-BoldOblique'] = 600;
  17999. t['Courier-Oblique'] = 600;
  18000. t['Helvetica'] = getLookupTableFactory(function (t) {
  18001. t['space'] = 278;
  18002. t['exclam'] = 278;
  18003. t['quotedbl'] = 355;
  18004. t['numbersign'] = 556;
  18005. t['dollar'] = 556;
  18006. t['percent'] = 889;
  18007. t['ampersand'] = 667;
  18008. t['quoteright'] = 222;
  18009. t['parenleft'] = 333;
  18010. t['parenright'] = 333;
  18011. t['asterisk'] = 389;
  18012. t['plus'] = 584;
  18013. t['comma'] = 278;
  18014. t['hyphen'] = 333;
  18015. t['period'] = 278;
  18016. t['slash'] = 278;
  18017. t['zero'] = 556;
  18018. t['one'] = 556;
  18019. t['two'] = 556;
  18020. t['three'] = 556;
  18021. t['four'] = 556;
  18022. t['five'] = 556;
  18023. t['six'] = 556;
  18024. t['seven'] = 556;
  18025. t['eight'] = 556;
  18026. t['nine'] = 556;
  18027. t['colon'] = 278;
  18028. t['semicolon'] = 278;
  18029. t['less'] = 584;
  18030. t['equal'] = 584;
  18031. t['greater'] = 584;
  18032. t['question'] = 556;
  18033. t['at'] = 1015;
  18034. t['A'] = 667;
  18035. t['B'] = 667;
  18036. t['C'] = 722;
  18037. t['D'] = 722;
  18038. t['E'] = 667;
  18039. t['F'] = 611;
  18040. t['G'] = 778;
  18041. t['H'] = 722;
  18042. t['I'] = 278;
  18043. t['J'] = 500;
  18044. t['K'] = 667;
  18045. t['L'] = 556;
  18046. t['M'] = 833;
  18047. t['N'] = 722;
  18048. t['O'] = 778;
  18049. t['P'] = 667;
  18050. t['Q'] = 778;
  18051. t['R'] = 722;
  18052. t['S'] = 667;
  18053. t['T'] = 611;
  18054. t['U'] = 722;
  18055. t['V'] = 667;
  18056. t['W'] = 944;
  18057. t['X'] = 667;
  18058. t['Y'] = 667;
  18059. t['Z'] = 611;
  18060. t['bracketleft'] = 278;
  18061. t['backslash'] = 278;
  18062. t['bracketright'] = 278;
  18063. t['asciicircum'] = 469;
  18064. t['underscore'] = 556;
  18065. t['quoteleft'] = 222;
  18066. t['a'] = 556;
  18067. t['b'] = 556;
  18068. t['c'] = 500;
  18069. t['d'] = 556;
  18070. t['e'] = 556;
  18071. t['f'] = 278;
  18072. t['g'] = 556;
  18073. t['h'] = 556;
  18074. t['i'] = 222;
  18075. t['j'] = 222;
  18076. t['k'] = 500;
  18077. t['l'] = 222;
  18078. t['m'] = 833;
  18079. t['n'] = 556;
  18080. t['o'] = 556;
  18081. t['p'] = 556;
  18082. t['q'] = 556;
  18083. t['r'] = 333;
  18084. t['s'] = 500;
  18085. t['t'] = 278;
  18086. t['u'] = 556;
  18087. t['v'] = 500;
  18088. t['w'] = 722;
  18089. t['x'] = 500;
  18090. t['y'] = 500;
  18091. t['z'] = 500;
  18092. t['braceleft'] = 334;
  18093. t['bar'] = 260;
  18094. t['braceright'] = 334;
  18095. t['asciitilde'] = 584;
  18096. t['exclamdown'] = 333;
  18097. t['cent'] = 556;
  18098. t['sterling'] = 556;
  18099. t['fraction'] = 167;
  18100. t['yen'] = 556;
  18101. t['florin'] = 556;
  18102. t['section'] = 556;
  18103. t['currency'] = 556;
  18104. t['quotesingle'] = 191;
  18105. t['quotedblleft'] = 333;
  18106. t['guillemotleft'] = 556;
  18107. t['guilsinglleft'] = 333;
  18108. t['guilsinglright'] = 333;
  18109. t['fi'] = 500;
  18110. t['fl'] = 500;
  18111. t['endash'] = 556;
  18112. t['dagger'] = 556;
  18113. t['daggerdbl'] = 556;
  18114. t['periodcentered'] = 278;
  18115. t['paragraph'] = 537;
  18116. t['bullet'] = 350;
  18117. t['quotesinglbase'] = 222;
  18118. t['quotedblbase'] = 333;
  18119. t['quotedblright'] = 333;
  18120. t['guillemotright'] = 556;
  18121. t['ellipsis'] = 1000;
  18122. t['perthousand'] = 1000;
  18123. t['questiondown'] = 611;
  18124. t['grave'] = 333;
  18125. t['acute'] = 333;
  18126. t['circumflex'] = 333;
  18127. t['tilde'] = 333;
  18128. t['macron'] = 333;
  18129. t['breve'] = 333;
  18130. t['dotaccent'] = 333;
  18131. t['dieresis'] = 333;
  18132. t['ring'] = 333;
  18133. t['cedilla'] = 333;
  18134. t['hungarumlaut'] = 333;
  18135. t['ogonek'] = 333;
  18136. t['caron'] = 333;
  18137. t['emdash'] = 1000;
  18138. t['AE'] = 1000;
  18139. t['ordfeminine'] = 370;
  18140. t['Lslash'] = 556;
  18141. t['Oslash'] = 778;
  18142. t['OE'] = 1000;
  18143. t['ordmasculine'] = 365;
  18144. t['ae'] = 889;
  18145. t['dotlessi'] = 278;
  18146. t['lslash'] = 222;
  18147. t['oslash'] = 611;
  18148. t['oe'] = 944;
  18149. t['germandbls'] = 611;
  18150. t['Idieresis'] = 278;
  18151. t['eacute'] = 556;
  18152. t['abreve'] = 556;
  18153. t['uhungarumlaut'] = 556;
  18154. t['ecaron'] = 556;
  18155. t['Ydieresis'] = 667;
  18156. t['divide'] = 584;
  18157. t['Yacute'] = 667;
  18158. t['Acircumflex'] = 667;
  18159. t['aacute'] = 556;
  18160. t['Ucircumflex'] = 722;
  18161. t['yacute'] = 500;
  18162. t['scommaaccent'] = 500;
  18163. t['ecircumflex'] = 556;
  18164. t['Uring'] = 722;
  18165. t['Udieresis'] = 722;
  18166. t['aogonek'] = 556;
  18167. t['Uacute'] = 722;
  18168. t['uogonek'] = 556;
  18169. t['Edieresis'] = 667;
  18170. t['Dcroat'] = 722;
  18171. t['commaaccent'] = 250;
  18172. t['copyright'] = 737;
  18173. t['Emacron'] = 667;
  18174. t['ccaron'] = 500;
  18175. t['aring'] = 556;
  18176. t['Ncommaaccent'] = 722;
  18177. t['lacute'] = 222;
  18178. t['agrave'] = 556;
  18179. t['Tcommaaccent'] = 611;
  18180. t['Cacute'] = 722;
  18181. t['atilde'] = 556;
  18182. t['Edotaccent'] = 667;
  18183. t['scaron'] = 500;
  18184. t['scedilla'] = 500;
  18185. t['iacute'] = 278;
  18186. t['lozenge'] = 471;
  18187. t['Rcaron'] = 722;
  18188. t['Gcommaaccent'] = 778;
  18189. t['ucircumflex'] = 556;
  18190. t['acircumflex'] = 556;
  18191. t['Amacron'] = 667;
  18192. t['rcaron'] = 333;
  18193. t['ccedilla'] = 500;
  18194. t['Zdotaccent'] = 611;
  18195. t['Thorn'] = 667;
  18196. t['Omacron'] = 778;
  18197. t['Racute'] = 722;
  18198. t['Sacute'] = 667;
  18199. t['dcaron'] = 643;
  18200. t['Umacron'] = 722;
  18201. t['uring'] = 556;
  18202. t['threesuperior'] = 333;
  18203. t['Ograve'] = 778;
  18204. t['Agrave'] = 667;
  18205. t['Abreve'] = 667;
  18206. t['multiply'] = 584;
  18207. t['uacute'] = 556;
  18208. t['Tcaron'] = 611;
  18209. t['partialdiff'] = 476;
  18210. t['ydieresis'] = 500;
  18211. t['Nacute'] = 722;
  18212. t['icircumflex'] = 278;
  18213. t['Ecircumflex'] = 667;
  18214. t['adieresis'] = 556;
  18215. t['edieresis'] = 556;
  18216. t['cacute'] = 500;
  18217. t['nacute'] = 556;
  18218. t['umacron'] = 556;
  18219. t['Ncaron'] = 722;
  18220. t['Iacute'] = 278;
  18221. t['plusminus'] = 584;
  18222. t['brokenbar'] = 260;
  18223. t['registered'] = 737;
  18224. t['Gbreve'] = 778;
  18225. t['Idotaccent'] = 278;
  18226. t['summation'] = 600;
  18227. t['Egrave'] = 667;
  18228. t['racute'] = 333;
  18229. t['omacron'] = 556;
  18230. t['Zacute'] = 611;
  18231. t['Zcaron'] = 611;
  18232. t['greaterequal'] = 549;
  18233. t['Eth'] = 722;
  18234. t['Ccedilla'] = 722;
  18235. t['lcommaaccent'] = 222;
  18236. t['tcaron'] = 317;
  18237. t['eogonek'] = 556;
  18238. t['Uogonek'] = 722;
  18239. t['Aacute'] = 667;
  18240. t['Adieresis'] = 667;
  18241. t['egrave'] = 556;
  18242. t['zacute'] = 500;
  18243. t['iogonek'] = 222;
  18244. t['Oacute'] = 778;
  18245. t['oacute'] = 556;
  18246. t['amacron'] = 556;
  18247. t['sacute'] = 500;
  18248. t['idieresis'] = 278;
  18249. t['Ocircumflex'] = 778;
  18250. t['Ugrave'] = 722;
  18251. t['Delta'] = 612;
  18252. t['thorn'] = 556;
  18253. t['twosuperior'] = 333;
  18254. t['Odieresis'] = 778;
  18255. t['mu'] = 556;
  18256. t['igrave'] = 278;
  18257. t['ohungarumlaut'] = 556;
  18258. t['Eogonek'] = 667;
  18259. t['dcroat'] = 556;
  18260. t['threequarters'] = 834;
  18261. t['Scedilla'] = 667;
  18262. t['lcaron'] = 299;
  18263. t['Kcommaaccent'] = 667;
  18264. t['Lacute'] = 556;
  18265. t['trademark'] = 1000;
  18266. t['edotaccent'] = 556;
  18267. t['Igrave'] = 278;
  18268. t['Imacron'] = 278;
  18269. t['Lcaron'] = 556;
  18270. t['onehalf'] = 834;
  18271. t['lessequal'] = 549;
  18272. t['ocircumflex'] = 556;
  18273. t['ntilde'] = 556;
  18274. t['Uhungarumlaut'] = 722;
  18275. t['Eacute'] = 667;
  18276. t['emacron'] = 556;
  18277. t['gbreve'] = 556;
  18278. t['onequarter'] = 834;
  18279. t['Scaron'] = 667;
  18280. t['Scommaaccent'] = 667;
  18281. t['Ohungarumlaut'] = 778;
  18282. t['degree'] = 400;
  18283. t['ograve'] = 556;
  18284. t['Ccaron'] = 722;
  18285. t['ugrave'] = 556;
  18286. t['radical'] = 453;
  18287. t['Dcaron'] = 722;
  18288. t['rcommaaccent'] = 333;
  18289. t['Ntilde'] = 722;
  18290. t['otilde'] = 556;
  18291. t['Rcommaaccent'] = 722;
  18292. t['Lcommaaccent'] = 556;
  18293. t['Atilde'] = 667;
  18294. t['Aogonek'] = 667;
  18295. t['Aring'] = 667;
  18296. t['Otilde'] = 778;
  18297. t['zdotaccent'] = 500;
  18298. t['Ecaron'] = 667;
  18299. t['Iogonek'] = 278;
  18300. t['kcommaaccent'] = 500;
  18301. t['minus'] = 584;
  18302. t['Icircumflex'] = 278;
  18303. t['ncaron'] = 556;
  18304. t['tcommaaccent'] = 278;
  18305. t['logicalnot'] = 584;
  18306. t['odieresis'] = 556;
  18307. t['udieresis'] = 556;
  18308. t['notequal'] = 549;
  18309. t['gcommaaccent'] = 556;
  18310. t['eth'] = 556;
  18311. t['zcaron'] = 500;
  18312. t['ncommaaccent'] = 556;
  18313. t['onesuperior'] = 333;
  18314. t['imacron'] = 278;
  18315. t['Euro'] = 556;
  18316. });
  18317. t['Helvetica-Bold'] = getLookupTableFactory(function (t) {
  18318. t['space'] = 278;
  18319. t['exclam'] = 333;
  18320. t['quotedbl'] = 474;
  18321. t['numbersign'] = 556;
  18322. t['dollar'] = 556;
  18323. t['percent'] = 889;
  18324. t['ampersand'] = 722;
  18325. t['quoteright'] = 278;
  18326. t['parenleft'] = 333;
  18327. t['parenright'] = 333;
  18328. t['asterisk'] = 389;
  18329. t['plus'] = 584;
  18330. t['comma'] = 278;
  18331. t['hyphen'] = 333;
  18332. t['period'] = 278;
  18333. t['slash'] = 278;
  18334. t['zero'] = 556;
  18335. t['one'] = 556;
  18336. t['two'] = 556;
  18337. t['three'] = 556;
  18338. t['four'] = 556;
  18339. t['five'] = 556;
  18340. t['six'] = 556;
  18341. t['seven'] = 556;
  18342. t['eight'] = 556;
  18343. t['nine'] = 556;
  18344. t['colon'] = 333;
  18345. t['semicolon'] = 333;
  18346. t['less'] = 584;
  18347. t['equal'] = 584;
  18348. t['greater'] = 584;
  18349. t['question'] = 611;
  18350. t['at'] = 975;
  18351. t['A'] = 722;
  18352. t['B'] = 722;
  18353. t['C'] = 722;
  18354. t['D'] = 722;
  18355. t['E'] = 667;
  18356. t['F'] = 611;
  18357. t['G'] = 778;
  18358. t['H'] = 722;
  18359. t['I'] = 278;
  18360. t['J'] = 556;
  18361. t['K'] = 722;
  18362. t['L'] = 611;
  18363. t['M'] = 833;
  18364. t['N'] = 722;
  18365. t['O'] = 778;
  18366. t['P'] = 667;
  18367. t['Q'] = 778;
  18368. t['R'] = 722;
  18369. t['S'] = 667;
  18370. t['T'] = 611;
  18371. t['U'] = 722;
  18372. t['V'] = 667;
  18373. t['W'] = 944;
  18374. t['X'] = 667;
  18375. t['Y'] = 667;
  18376. t['Z'] = 611;
  18377. t['bracketleft'] = 333;
  18378. t['backslash'] = 278;
  18379. t['bracketright'] = 333;
  18380. t['asciicircum'] = 584;
  18381. t['underscore'] = 556;
  18382. t['quoteleft'] = 278;
  18383. t['a'] = 556;
  18384. t['b'] = 611;
  18385. t['c'] = 556;
  18386. t['d'] = 611;
  18387. t['e'] = 556;
  18388. t['f'] = 333;
  18389. t['g'] = 611;
  18390. t['h'] = 611;
  18391. t['i'] = 278;
  18392. t['j'] = 278;
  18393. t['k'] = 556;
  18394. t['l'] = 278;
  18395. t['m'] = 889;
  18396. t['n'] = 611;
  18397. t['o'] = 611;
  18398. t['p'] = 611;
  18399. t['q'] = 611;
  18400. t['r'] = 389;
  18401. t['s'] = 556;
  18402. t['t'] = 333;
  18403. t['u'] = 611;
  18404. t['v'] = 556;
  18405. t['w'] = 778;
  18406. t['x'] = 556;
  18407. t['y'] = 556;
  18408. t['z'] = 500;
  18409. t['braceleft'] = 389;
  18410. t['bar'] = 280;
  18411. t['braceright'] = 389;
  18412. t['asciitilde'] = 584;
  18413. t['exclamdown'] = 333;
  18414. t['cent'] = 556;
  18415. t['sterling'] = 556;
  18416. t['fraction'] = 167;
  18417. t['yen'] = 556;
  18418. t['florin'] = 556;
  18419. t['section'] = 556;
  18420. t['currency'] = 556;
  18421. t['quotesingle'] = 238;
  18422. t['quotedblleft'] = 500;
  18423. t['guillemotleft'] = 556;
  18424. t['guilsinglleft'] = 333;
  18425. t['guilsinglright'] = 333;
  18426. t['fi'] = 611;
  18427. t['fl'] = 611;
  18428. t['endash'] = 556;
  18429. t['dagger'] = 556;
  18430. t['daggerdbl'] = 556;
  18431. t['periodcentered'] = 278;
  18432. t['paragraph'] = 556;
  18433. t['bullet'] = 350;
  18434. t['quotesinglbase'] = 278;
  18435. t['quotedblbase'] = 500;
  18436. t['quotedblright'] = 500;
  18437. t['guillemotright'] = 556;
  18438. t['ellipsis'] = 1000;
  18439. t['perthousand'] = 1000;
  18440. t['questiondown'] = 611;
  18441. t['grave'] = 333;
  18442. t['acute'] = 333;
  18443. t['circumflex'] = 333;
  18444. t['tilde'] = 333;
  18445. t['macron'] = 333;
  18446. t['breve'] = 333;
  18447. t['dotaccent'] = 333;
  18448. t['dieresis'] = 333;
  18449. t['ring'] = 333;
  18450. t['cedilla'] = 333;
  18451. t['hungarumlaut'] = 333;
  18452. t['ogonek'] = 333;
  18453. t['caron'] = 333;
  18454. t['emdash'] = 1000;
  18455. t['AE'] = 1000;
  18456. t['ordfeminine'] = 370;
  18457. t['Lslash'] = 611;
  18458. t['Oslash'] = 778;
  18459. t['OE'] = 1000;
  18460. t['ordmasculine'] = 365;
  18461. t['ae'] = 889;
  18462. t['dotlessi'] = 278;
  18463. t['lslash'] = 278;
  18464. t['oslash'] = 611;
  18465. t['oe'] = 944;
  18466. t['germandbls'] = 611;
  18467. t['Idieresis'] = 278;
  18468. t['eacute'] = 556;
  18469. t['abreve'] = 556;
  18470. t['uhungarumlaut'] = 611;
  18471. t['ecaron'] = 556;
  18472. t['Ydieresis'] = 667;
  18473. t['divide'] = 584;
  18474. t['Yacute'] = 667;
  18475. t['Acircumflex'] = 722;
  18476. t['aacute'] = 556;
  18477. t['Ucircumflex'] = 722;
  18478. t['yacute'] = 556;
  18479. t['scommaaccent'] = 556;
  18480. t['ecircumflex'] = 556;
  18481. t['Uring'] = 722;
  18482. t['Udieresis'] = 722;
  18483. t['aogonek'] = 556;
  18484. t['Uacute'] = 722;
  18485. t['uogonek'] = 611;
  18486. t['Edieresis'] = 667;
  18487. t['Dcroat'] = 722;
  18488. t['commaaccent'] = 250;
  18489. t['copyright'] = 737;
  18490. t['Emacron'] = 667;
  18491. t['ccaron'] = 556;
  18492. t['aring'] = 556;
  18493. t['Ncommaaccent'] = 722;
  18494. t['lacute'] = 278;
  18495. t['agrave'] = 556;
  18496. t['Tcommaaccent'] = 611;
  18497. t['Cacute'] = 722;
  18498. t['atilde'] = 556;
  18499. t['Edotaccent'] = 667;
  18500. t['scaron'] = 556;
  18501. t['scedilla'] = 556;
  18502. t['iacute'] = 278;
  18503. t['lozenge'] = 494;
  18504. t['Rcaron'] = 722;
  18505. t['Gcommaaccent'] = 778;
  18506. t['ucircumflex'] = 611;
  18507. t['acircumflex'] = 556;
  18508. t['Amacron'] = 722;
  18509. t['rcaron'] = 389;
  18510. t['ccedilla'] = 556;
  18511. t['Zdotaccent'] = 611;
  18512. t['Thorn'] = 667;
  18513. t['Omacron'] = 778;
  18514. t['Racute'] = 722;
  18515. t['Sacute'] = 667;
  18516. t['dcaron'] = 743;
  18517. t['Umacron'] = 722;
  18518. t['uring'] = 611;
  18519. t['threesuperior'] = 333;
  18520. t['Ograve'] = 778;
  18521. t['Agrave'] = 722;
  18522. t['Abreve'] = 722;
  18523. t['multiply'] = 584;
  18524. t['uacute'] = 611;
  18525. t['Tcaron'] = 611;
  18526. t['partialdiff'] = 494;
  18527. t['ydieresis'] = 556;
  18528. t['Nacute'] = 722;
  18529. t['icircumflex'] = 278;
  18530. t['Ecircumflex'] = 667;
  18531. t['adieresis'] = 556;
  18532. t['edieresis'] = 556;
  18533. t['cacute'] = 556;
  18534. t['nacute'] = 611;
  18535. t['umacron'] = 611;
  18536. t['Ncaron'] = 722;
  18537. t['Iacute'] = 278;
  18538. t['plusminus'] = 584;
  18539. t['brokenbar'] = 280;
  18540. t['registered'] = 737;
  18541. t['Gbreve'] = 778;
  18542. t['Idotaccent'] = 278;
  18543. t['summation'] = 600;
  18544. t['Egrave'] = 667;
  18545. t['racute'] = 389;
  18546. t['omacron'] = 611;
  18547. t['Zacute'] = 611;
  18548. t['Zcaron'] = 611;
  18549. t['greaterequal'] = 549;
  18550. t['Eth'] = 722;
  18551. t['Ccedilla'] = 722;
  18552. t['lcommaaccent'] = 278;
  18553. t['tcaron'] = 389;
  18554. t['eogonek'] = 556;
  18555. t['Uogonek'] = 722;
  18556. t['Aacute'] = 722;
  18557. t['Adieresis'] = 722;
  18558. t['egrave'] = 556;
  18559. t['zacute'] = 500;
  18560. t['iogonek'] = 278;
  18561. t['Oacute'] = 778;
  18562. t['oacute'] = 611;
  18563. t['amacron'] = 556;
  18564. t['sacute'] = 556;
  18565. t['idieresis'] = 278;
  18566. t['Ocircumflex'] = 778;
  18567. t['Ugrave'] = 722;
  18568. t['Delta'] = 612;
  18569. t['thorn'] = 611;
  18570. t['twosuperior'] = 333;
  18571. t['Odieresis'] = 778;
  18572. t['mu'] = 611;
  18573. t['igrave'] = 278;
  18574. t['ohungarumlaut'] = 611;
  18575. t['Eogonek'] = 667;
  18576. t['dcroat'] = 611;
  18577. t['threequarters'] = 834;
  18578. t['Scedilla'] = 667;
  18579. t['lcaron'] = 400;
  18580. t['Kcommaaccent'] = 722;
  18581. t['Lacute'] = 611;
  18582. t['trademark'] = 1000;
  18583. t['edotaccent'] = 556;
  18584. t['Igrave'] = 278;
  18585. t['Imacron'] = 278;
  18586. t['Lcaron'] = 611;
  18587. t['onehalf'] = 834;
  18588. t['lessequal'] = 549;
  18589. t['ocircumflex'] = 611;
  18590. t['ntilde'] = 611;
  18591. t['Uhungarumlaut'] = 722;
  18592. t['Eacute'] = 667;
  18593. t['emacron'] = 556;
  18594. t['gbreve'] = 611;
  18595. t['onequarter'] = 834;
  18596. t['Scaron'] = 667;
  18597. t['Scommaaccent'] = 667;
  18598. t['Ohungarumlaut'] = 778;
  18599. t['degree'] = 400;
  18600. t['ograve'] = 611;
  18601. t['Ccaron'] = 722;
  18602. t['ugrave'] = 611;
  18603. t['radical'] = 549;
  18604. t['Dcaron'] = 722;
  18605. t['rcommaaccent'] = 389;
  18606. t['Ntilde'] = 722;
  18607. t['otilde'] = 611;
  18608. t['Rcommaaccent'] = 722;
  18609. t['Lcommaaccent'] = 611;
  18610. t['Atilde'] = 722;
  18611. t['Aogonek'] = 722;
  18612. t['Aring'] = 722;
  18613. t['Otilde'] = 778;
  18614. t['zdotaccent'] = 500;
  18615. t['Ecaron'] = 667;
  18616. t['Iogonek'] = 278;
  18617. t['kcommaaccent'] = 556;
  18618. t['minus'] = 584;
  18619. t['Icircumflex'] = 278;
  18620. t['ncaron'] = 611;
  18621. t['tcommaaccent'] = 333;
  18622. t['logicalnot'] = 584;
  18623. t['odieresis'] = 611;
  18624. t['udieresis'] = 611;
  18625. t['notequal'] = 549;
  18626. t['gcommaaccent'] = 611;
  18627. t['eth'] = 611;
  18628. t['zcaron'] = 500;
  18629. t['ncommaaccent'] = 611;
  18630. t['onesuperior'] = 333;
  18631. t['imacron'] = 278;
  18632. t['Euro'] = 556;
  18633. });
  18634. t['Helvetica-BoldOblique'] = getLookupTableFactory(function (t) {
  18635. t['space'] = 278;
  18636. t['exclam'] = 333;
  18637. t['quotedbl'] = 474;
  18638. t['numbersign'] = 556;
  18639. t['dollar'] = 556;
  18640. t['percent'] = 889;
  18641. t['ampersand'] = 722;
  18642. t['quoteright'] = 278;
  18643. t['parenleft'] = 333;
  18644. t['parenright'] = 333;
  18645. t['asterisk'] = 389;
  18646. t['plus'] = 584;
  18647. t['comma'] = 278;
  18648. t['hyphen'] = 333;
  18649. t['period'] = 278;
  18650. t['slash'] = 278;
  18651. t['zero'] = 556;
  18652. t['one'] = 556;
  18653. t['two'] = 556;
  18654. t['three'] = 556;
  18655. t['four'] = 556;
  18656. t['five'] = 556;
  18657. t['six'] = 556;
  18658. t['seven'] = 556;
  18659. t['eight'] = 556;
  18660. t['nine'] = 556;
  18661. t['colon'] = 333;
  18662. t['semicolon'] = 333;
  18663. t['less'] = 584;
  18664. t['equal'] = 584;
  18665. t['greater'] = 584;
  18666. t['question'] = 611;
  18667. t['at'] = 975;
  18668. t['A'] = 722;
  18669. t['B'] = 722;
  18670. t['C'] = 722;
  18671. t['D'] = 722;
  18672. t['E'] = 667;
  18673. t['F'] = 611;
  18674. t['G'] = 778;
  18675. t['H'] = 722;
  18676. t['I'] = 278;
  18677. t['J'] = 556;
  18678. t['K'] = 722;
  18679. t['L'] = 611;
  18680. t['M'] = 833;
  18681. t['N'] = 722;
  18682. t['O'] = 778;
  18683. t['P'] = 667;
  18684. t['Q'] = 778;
  18685. t['R'] = 722;
  18686. t['S'] = 667;
  18687. t['T'] = 611;
  18688. t['U'] = 722;
  18689. t['V'] = 667;
  18690. t['W'] = 944;
  18691. t['X'] = 667;
  18692. t['Y'] = 667;
  18693. t['Z'] = 611;
  18694. t['bracketleft'] = 333;
  18695. t['backslash'] = 278;
  18696. t['bracketright'] = 333;
  18697. t['asciicircum'] = 584;
  18698. t['underscore'] = 556;
  18699. t['quoteleft'] = 278;
  18700. t['a'] = 556;
  18701. t['b'] = 611;
  18702. t['c'] = 556;
  18703. t['d'] = 611;
  18704. t['e'] = 556;
  18705. t['f'] = 333;
  18706. t['g'] = 611;
  18707. t['h'] = 611;
  18708. t['i'] = 278;
  18709. t['j'] = 278;
  18710. t['k'] = 556;
  18711. t['l'] = 278;
  18712. t['m'] = 889;
  18713. t['n'] = 611;
  18714. t['o'] = 611;
  18715. t['p'] = 611;
  18716. t['q'] = 611;
  18717. t['r'] = 389;
  18718. t['s'] = 556;
  18719. t['t'] = 333;
  18720. t['u'] = 611;
  18721. t['v'] = 556;
  18722. t['w'] = 778;
  18723. t['x'] = 556;
  18724. t['y'] = 556;
  18725. t['z'] = 500;
  18726. t['braceleft'] = 389;
  18727. t['bar'] = 280;
  18728. t['braceright'] = 389;
  18729. t['asciitilde'] = 584;
  18730. t['exclamdown'] = 333;
  18731. t['cent'] = 556;
  18732. t['sterling'] = 556;
  18733. t['fraction'] = 167;
  18734. t['yen'] = 556;
  18735. t['florin'] = 556;
  18736. t['section'] = 556;
  18737. t['currency'] = 556;
  18738. t['quotesingle'] = 238;
  18739. t['quotedblleft'] = 500;
  18740. t['guillemotleft'] = 556;
  18741. t['guilsinglleft'] = 333;
  18742. t['guilsinglright'] = 333;
  18743. t['fi'] = 611;
  18744. t['fl'] = 611;
  18745. t['endash'] = 556;
  18746. t['dagger'] = 556;
  18747. t['daggerdbl'] = 556;
  18748. t['periodcentered'] = 278;
  18749. t['paragraph'] = 556;
  18750. t['bullet'] = 350;
  18751. t['quotesinglbase'] = 278;
  18752. t['quotedblbase'] = 500;
  18753. t['quotedblright'] = 500;
  18754. t['guillemotright'] = 556;
  18755. t['ellipsis'] = 1000;
  18756. t['perthousand'] = 1000;
  18757. t['questiondown'] = 611;
  18758. t['grave'] = 333;
  18759. t['acute'] = 333;
  18760. t['circumflex'] = 333;
  18761. t['tilde'] = 333;
  18762. t['macron'] = 333;
  18763. t['breve'] = 333;
  18764. t['dotaccent'] = 333;
  18765. t['dieresis'] = 333;
  18766. t['ring'] = 333;
  18767. t['cedilla'] = 333;
  18768. t['hungarumlaut'] = 333;
  18769. t['ogonek'] = 333;
  18770. t['caron'] = 333;
  18771. t['emdash'] = 1000;
  18772. t['AE'] = 1000;
  18773. t['ordfeminine'] = 370;
  18774. t['Lslash'] = 611;
  18775. t['Oslash'] = 778;
  18776. t['OE'] = 1000;
  18777. t['ordmasculine'] = 365;
  18778. t['ae'] = 889;
  18779. t['dotlessi'] = 278;
  18780. t['lslash'] = 278;
  18781. t['oslash'] = 611;
  18782. t['oe'] = 944;
  18783. t['germandbls'] = 611;
  18784. t['Idieresis'] = 278;
  18785. t['eacute'] = 556;
  18786. t['abreve'] = 556;
  18787. t['uhungarumlaut'] = 611;
  18788. t['ecaron'] = 556;
  18789. t['Ydieresis'] = 667;
  18790. t['divide'] = 584;
  18791. t['Yacute'] = 667;
  18792. t['Acircumflex'] = 722;
  18793. t['aacute'] = 556;
  18794. t['Ucircumflex'] = 722;
  18795. t['yacute'] = 556;
  18796. t['scommaaccent'] = 556;
  18797. t['ecircumflex'] = 556;
  18798. t['Uring'] = 722;
  18799. t['Udieresis'] = 722;
  18800. t['aogonek'] = 556;
  18801. t['Uacute'] = 722;
  18802. t['uogonek'] = 611;
  18803. t['Edieresis'] = 667;
  18804. t['Dcroat'] = 722;
  18805. t['commaaccent'] = 250;
  18806. t['copyright'] = 737;
  18807. t['Emacron'] = 667;
  18808. t['ccaron'] = 556;
  18809. t['aring'] = 556;
  18810. t['Ncommaaccent'] = 722;
  18811. t['lacute'] = 278;
  18812. t['agrave'] = 556;
  18813. t['Tcommaaccent'] = 611;
  18814. t['Cacute'] = 722;
  18815. t['atilde'] = 556;
  18816. t['Edotaccent'] = 667;
  18817. t['scaron'] = 556;
  18818. t['scedilla'] = 556;
  18819. t['iacute'] = 278;
  18820. t['lozenge'] = 494;
  18821. t['Rcaron'] = 722;
  18822. t['Gcommaaccent'] = 778;
  18823. t['ucircumflex'] = 611;
  18824. t['acircumflex'] = 556;
  18825. t['Amacron'] = 722;
  18826. t['rcaron'] = 389;
  18827. t['ccedilla'] = 556;
  18828. t['Zdotaccent'] = 611;
  18829. t['Thorn'] = 667;
  18830. t['Omacron'] = 778;
  18831. t['Racute'] = 722;
  18832. t['Sacute'] = 667;
  18833. t['dcaron'] = 743;
  18834. t['Umacron'] = 722;
  18835. t['uring'] = 611;
  18836. t['threesuperior'] = 333;
  18837. t['Ograve'] = 778;
  18838. t['Agrave'] = 722;
  18839. t['Abreve'] = 722;
  18840. t['multiply'] = 584;
  18841. t['uacute'] = 611;
  18842. t['Tcaron'] = 611;
  18843. t['partialdiff'] = 494;
  18844. t['ydieresis'] = 556;
  18845. t['Nacute'] = 722;
  18846. t['icircumflex'] = 278;
  18847. t['Ecircumflex'] = 667;
  18848. t['adieresis'] = 556;
  18849. t['edieresis'] = 556;
  18850. t['cacute'] = 556;
  18851. t['nacute'] = 611;
  18852. t['umacron'] = 611;
  18853. t['Ncaron'] = 722;
  18854. t['Iacute'] = 278;
  18855. t['plusminus'] = 584;
  18856. t['brokenbar'] = 280;
  18857. t['registered'] = 737;
  18858. t['Gbreve'] = 778;
  18859. t['Idotaccent'] = 278;
  18860. t['summation'] = 600;
  18861. t['Egrave'] = 667;
  18862. t['racute'] = 389;
  18863. t['omacron'] = 611;
  18864. t['Zacute'] = 611;
  18865. t['Zcaron'] = 611;
  18866. t['greaterequal'] = 549;
  18867. t['Eth'] = 722;
  18868. t['Ccedilla'] = 722;
  18869. t['lcommaaccent'] = 278;
  18870. t['tcaron'] = 389;
  18871. t['eogonek'] = 556;
  18872. t['Uogonek'] = 722;
  18873. t['Aacute'] = 722;
  18874. t['Adieresis'] = 722;
  18875. t['egrave'] = 556;
  18876. t['zacute'] = 500;
  18877. t['iogonek'] = 278;
  18878. t['Oacute'] = 778;
  18879. t['oacute'] = 611;
  18880. t['amacron'] = 556;
  18881. t['sacute'] = 556;
  18882. t['idieresis'] = 278;
  18883. t['Ocircumflex'] = 778;
  18884. t['Ugrave'] = 722;
  18885. t['Delta'] = 612;
  18886. t['thorn'] = 611;
  18887. t['twosuperior'] = 333;
  18888. t['Odieresis'] = 778;
  18889. t['mu'] = 611;
  18890. t['igrave'] = 278;
  18891. t['ohungarumlaut'] = 611;
  18892. t['Eogonek'] = 667;
  18893. t['dcroat'] = 611;
  18894. t['threequarters'] = 834;
  18895. t['Scedilla'] = 667;
  18896. t['lcaron'] = 400;
  18897. t['Kcommaaccent'] = 722;
  18898. t['Lacute'] = 611;
  18899. t['trademark'] = 1000;
  18900. t['edotaccent'] = 556;
  18901. t['Igrave'] = 278;
  18902. t['Imacron'] = 278;
  18903. t['Lcaron'] = 611;
  18904. t['onehalf'] = 834;
  18905. t['lessequal'] = 549;
  18906. t['ocircumflex'] = 611;
  18907. t['ntilde'] = 611;
  18908. t['Uhungarumlaut'] = 722;
  18909. t['Eacute'] = 667;
  18910. t['emacron'] = 556;
  18911. t['gbreve'] = 611;
  18912. t['onequarter'] = 834;
  18913. t['Scaron'] = 667;
  18914. t['Scommaaccent'] = 667;
  18915. t['Ohungarumlaut'] = 778;
  18916. t['degree'] = 400;
  18917. t['ograve'] = 611;
  18918. t['Ccaron'] = 722;
  18919. t['ugrave'] = 611;
  18920. t['radical'] = 549;
  18921. t['Dcaron'] = 722;
  18922. t['rcommaaccent'] = 389;
  18923. t['Ntilde'] = 722;
  18924. t['otilde'] = 611;
  18925. t['Rcommaaccent'] = 722;
  18926. t['Lcommaaccent'] = 611;
  18927. t['Atilde'] = 722;
  18928. t['Aogonek'] = 722;
  18929. t['Aring'] = 722;
  18930. t['Otilde'] = 778;
  18931. t['zdotaccent'] = 500;
  18932. t['Ecaron'] = 667;
  18933. t['Iogonek'] = 278;
  18934. t['kcommaaccent'] = 556;
  18935. t['minus'] = 584;
  18936. t['Icircumflex'] = 278;
  18937. t['ncaron'] = 611;
  18938. t['tcommaaccent'] = 333;
  18939. t['logicalnot'] = 584;
  18940. t['odieresis'] = 611;
  18941. t['udieresis'] = 611;
  18942. t['notequal'] = 549;
  18943. t['gcommaaccent'] = 611;
  18944. t['eth'] = 611;
  18945. t['zcaron'] = 500;
  18946. t['ncommaaccent'] = 611;
  18947. t['onesuperior'] = 333;
  18948. t['imacron'] = 278;
  18949. t['Euro'] = 556;
  18950. });
  18951. t['Helvetica-Oblique'] = getLookupTableFactory(function (t) {
  18952. t['space'] = 278;
  18953. t['exclam'] = 278;
  18954. t['quotedbl'] = 355;
  18955. t['numbersign'] = 556;
  18956. t['dollar'] = 556;
  18957. t['percent'] = 889;
  18958. t['ampersand'] = 667;
  18959. t['quoteright'] = 222;
  18960. t['parenleft'] = 333;
  18961. t['parenright'] = 333;
  18962. t['asterisk'] = 389;
  18963. t['plus'] = 584;
  18964. t['comma'] = 278;
  18965. t['hyphen'] = 333;
  18966. t['period'] = 278;
  18967. t['slash'] = 278;
  18968. t['zero'] = 556;
  18969. t['one'] = 556;
  18970. t['two'] = 556;
  18971. t['three'] = 556;
  18972. t['four'] = 556;
  18973. t['five'] = 556;
  18974. t['six'] = 556;
  18975. t['seven'] = 556;
  18976. t['eight'] = 556;
  18977. t['nine'] = 556;
  18978. t['colon'] = 278;
  18979. t['semicolon'] = 278;
  18980. t['less'] = 584;
  18981. t['equal'] = 584;
  18982. t['greater'] = 584;
  18983. t['question'] = 556;
  18984. t['at'] = 1015;
  18985. t['A'] = 667;
  18986. t['B'] = 667;
  18987. t['C'] = 722;
  18988. t['D'] = 722;
  18989. t['E'] = 667;
  18990. t['F'] = 611;
  18991. t['G'] = 778;
  18992. t['H'] = 722;
  18993. t['I'] = 278;
  18994. t['J'] = 500;
  18995. t['K'] = 667;
  18996. t['L'] = 556;
  18997. t['M'] = 833;
  18998. t['N'] = 722;
  18999. t['O'] = 778;
  19000. t['P'] = 667;
  19001. t['Q'] = 778;
  19002. t['R'] = 722;
  19003. t['S'] = 667;
  19004. t['T'] = 611;
  19005. t['U'] = 722;
  19006. t['V'] = 667;
  19007. t['W'] = 944;
  19008. t['X'] = 667;
  19009. t['Y'] = 667;
  19010. t['Z'] = 611;
  19011. t['bracketleft'] = 278;
  19012. t['backslash'] = 278;
  19013. t['bracketright'] = 278;
  19014. t['asciicircum'] = 469;
  19015. t['underscore'] = 556;
  19016. t['quoteleft'] = 222;
  19017. t['a'] = 556;
  19018. t['b'] = 556;
  19019. t['c'] = 500;
  19020. t['d'] = 556;
  19021. t['e'] = 556;
  19022. t['f'] = 278;
  19023. t['g'] = 556;
  19024. t['h'] = 556;
  19025. t['i'] = 222;
  19026. t['j'] = 222;
  19027. t['k'] = 500;
  19028. t['l'] = 222;
  19029. t['m'] = 833;
  19030. t['n'] = 556;
  19031. t['o'] = 556;
  19032. t['p'] = 556;
  19033. t['q'] = 556;
  19034. t['r'] = 333;
  19035. t['s'] = 500;
  19036. t['t'] = 278;
  19037. t['u'] = 556;
  19038. t['v'] = 500;
  19039. t['w'] = 722;
  19040. t['x'] = 500;
  19041. t['y'] = 500;
  19042. t['z'] = 500;
  19043. t['braceleft'] = 334;
  19044. t['bar'] = 260;
  19045. t['braceright'] = 334;
  19046. t['asciitilde'] = 584;
  19047. t['exclamdown'] = 333;
  19048. t['cent'] = 556;
  19049. t['sterling'] = 556;
  19050. t['fraction'] = 167;
  19051. t['yen'] = 556;
  19052. t['florin'] = 556;
  19053. t['section'] = 556;
  19054. t['currency'] = 556;
  19055. t['quotesingle'] = 191;
  19056. t['quotedblleft'] = 333;
  19057. t['guillemotleft'] = 556;
  19058. t['guilsinglleft'] = 333;
  19059. t['guilsinglright'] = 333;
  19060. t['fi'] = 500;
  19061. t['fl'] = 500;
  19062. t['endash'] = 556;
  19063. t['dagger'] = 556;
  19064. t['daggerdbl'] = 556;
  19065. t['periodcentered'] = 278;
  19066. t['paragraph'] = 537;
  19067. t['bullet'] = 350;
  19068. t['quotesinglbase'] = 222;
  19069. t['quotedblbase'] = 333;
  19070. t['quotedblright'] = 333;
  19071. t['guillemotright'] = 556;
  19072. t['ellipsis'] = 1000;
  19073. t['perthousand'] = 1000;
  19074. t['questiondown'] = 611;
  19075. t['grave'] = 333;
  19076. t['acute'] = 333;
  19077. t['circumflex'] = 333;
  19078. t['tilde'] = 333;
  19079. t['macron'] = 333;
  19080. t['breve'] = 333;
  19081. t['dotaccent'] = 333;
  19082. t['dieresis'] = 333;
  19083. t['ring'] = 333;
  19084. t['cedilla'] = 333;
  19085. t['hungarumlaut'] = 333;
  19086. t['ogonek'] = 333;
  19087. t['caron'] = 333;
  19088. t['emdash'] = 1000;
  19089. t['AE'] = 1000;
  19090. t['ordfeminine'] = 370;
  19091. t['Lslash'] = 556;
  19092. t['Oslash'] = 778;
  19093. t['OE'] = 1000;
  19094. t['ordmasculine'] = 365;
  19095. t['ae'] = 889;
  19096. t['dotlessi'] = 278;
  19097. t['lslash'] = 222;
  19098. t['oslash'] = 611;
  19099. t['oe'] = 944;
  19100. t['germandbls'] = 611;
  19101. t['Idieresis'] = 278;
  19102. t['eacute'] = 556;
  19103. t['abreve'] = 556;
  19104. t['uhungarumlaut'] = 556;
  19105. t['ecaron'] = 556;
  19106. t['Ydieresis'] = 667;
  19107. t['divide'] = 584;
  19108. t['Yacute'] = 667;
  19109. t['Acircumflex'] = 667;
  19110. t['aacute'] = 556;
  19111. t['Ucircumflex'] = 722;
  19112. t['yacute'] = 500;
  19113. t['scommaaccent'] = 500;
  19114. t['ecircumflex'] = 556;
  19115. t['Uring'] = 722;
  19116. t['Udieresis'] = 722;
  19117. t['aogonek'] = 556;
  19118. t['Uacute'] = 722;
  19119. t['uogonek'] = 556;
  19120. t['Edieresis'] = 667;
  19121. t['Dcroat'] = 722;
  19122. t['commaaccent'] = 250;
  19123. t['copyright'] = 737;
  19124. t['Emacron'] = 667;
  19125. t['ccaron'] = 500;
  19126. t['aring'] = 556;
  19127. t['Ncommaaccent'] = 722;
  19128. t['lacute'] = 222;
  19129. t['agrave'] = 556;
  19130. t['Tcommaaccent'] = 611;
  19131. t['Cacute'] = 722;
  19132. t['atilde'] = 556;
  19133. t['Edotaccent'] = 667;
  19134. t['scaron'] = 500;
  19135. t['scedilla'] = 500;
  19136. t['iacute'] = 278;
  19137. t['lozenge'] = 471;
  19138. t['Rcaron'] = 722;
  19139. t['Gcommaaccent'] = 778;
  19140. t['ucircumflex'] = 556;
  19141. t['acircumflex'] = 556;
  19142. t['Amacron'] = 667;
  19143. t['rcaron'] = 333;
  19144. t['ccedilla'] = 500;
  19145. t['Zdotaccent'] = 611;
  19146. t['Thorn'] = 667;
  19147. t['Omacron'] = 778;
  19148. t['Racute'] = 722;
  19149. t['Sacute'] = 667;
  19150. t['dcaron'] = 643;
  19151. t['Umacron'] = 722;
  19152. t['uring'] = 556;
  19153. t['threesuperior'] = 333;
  19154. t['Ograve'] = 778;
  19155. t['Agrave'] = 667;
  19156. t['Abreve'] = 667;
  19157. t['multiply'] = 584;
  19158. t['uacute'] = 556;
  19159. t['Tcaron'] = 611;
  19160. t['partialdiff'] = 476;
  19161. t['ydieresis'] = 500;
  19162. t['Nacute'] = 722;
  19163. t['icircumflex'] = 278;
  19164. t['Ecircumflex'] = 667;
  19165. t['adieresis'] = 556;
  19166. t['edieresis'] = 556;
  19167. t['cacute'] = 500;
  19168. t['nacute'] = 556;
  19169. t['umacron'] = 556;
  19170. t['Ncaron'] = 722;
  19171. t['Iacute'] = 278;
  19172. t['plusminus'] = 584;
  19173. t['brokenbar'] = 260;
  19174. t['registered'] = 737;
  19175. t['Gbreve'] = 778;
  19176. t['Idotaccent'] = 278;
  19177. t['summation'] = 600;
  19178. t['Egrave'] = 667;
  19179. t['racute'] = 333;
  19180. t['omacron'] = 556;
  19181. t['Zacute'] = 611;
  19182. t['Zcaron'] = 611;
  19183. t['greaterequal'] = 549;
  19184. t['Eth'] = 722;
  19185. t['Ccedilla'] = 722;
  19186. t['lcommaaccent'] = 222;
  19187. t['tcaron'] = 317;
  19188. t['eogonek'] = 556;
  19189. t['Uogonek'] = 722;
  19190. t['Aacute'] = 667;
  19191. t['Adieresis'] = 667;
  19192. t['egrave'] = 556;
  19193. t['zacute'] = 500;
  19194. t['iogonek'] = 222;
  19195. t['Oacute'] = 778;
  19196. t['oacute'] = 556;
  19197. t['amacron'] = 556;
  19198. t['sacute'] = 500;
  19199. t['idieresis'] = 278;
  19200. t['Ocircumflex'] = 778;
  19201. t['Ugrave'] = 722;
  19202. t['Delta'] = 612;
  19203. t['thorn'] = 556;
  19204. t['twosuperior'] = 333;
  19205. t['Odieresis'] = 778;
  19206. t['mu'] = 556;
  19207. t['igrave'] = 278;
  19208. t['ohungarumlaut'] = 556;
  19209. t['Eogonek'] = 667;
  19210. t['dcroat'] = 556;
  19211. t['threequarters'] = 834;
  19212. t['Scedilla'] = 667;
  19213. t['lcaron'] = 299;
  19214. t['Kcommaaccent'] = 667;
  19215. t['Lacute'] = 556;
  19216. t['trademark'] = 1000;
  19217. t['edotaccent'] = 556;
  19218. t['Igrave'] = 278;
  19219. t['Imacron'] = 278;
  19220. t['Lcaron'] = 556;
  19221. t['onehalf'] = 834;
  19222. t['lessequal'] = 549;
  19223. t['ocircumflex'] = 556;
  19224. t['ntilde'] = 556;
  19225. t['Uhungarumlaut'] = 722;
  19226. t['Eacute'] = 667;
  19227. t['emacron'] = 556;
  19228. t['gbreve'] = 556;
  19229. t['onequarter'] = 834;
  19230. t['Scaron'] = 667;
  19231. t['Scommaaccent'] = 667;
  19232. t['Ohungarumlaut'] = 778;
  19233. t['degree'] = 400;
  19234. t['ograve'] = 556;
  19235. t['Ccaron'] = 722;
  19236. t['ugrave'] = 556;
  19237. t['radical'] = 453;
  19238. t['Dcaron'] = 722;
  19239. t['rcommaaccent'] = 333;
  19240. t['Ntilde'] = 722;
  19241. t['otilde'] = 556;
  19242. t['Rcommaaccent'] = 722;
  19243. t['Lcommaaccent'] = 556;
  19244. t['Atilde'] = 667;
  19245. t['Aogonek'] = 667;
  19246. t['Aring'] = 667;
  19247. t['Otilde'] = 778;
  19248. t['zdotaccent'] = 500;
  19249. t['Ecaron'] = 667;
  19250. t['Iogonek'] = 278;
  19251. t['kcommaaccent'] = 500;
  19252. t['minus'] = 584;
  19253. t['Icircumflex'] = 278;
  19254. t['ncaron'] = 556;
  19255. t['tcommaaccent'] = 278;
  19256. t['logicalnot'] = 584;
  19257. t['odieresis'] = 556;
  19258. t['udieresis'] = 556;
  19259. t['notequal'] = 549;
  19260. t['gcommaaccent'] = 556;
  19261. t['eth'] = 556;
  19262. t['zcaron'] = 500;
  19263. t['ncommaaccent'] = 556;
  19264. t['onesuperior'] = 333;
  19265. t['imacron'] = 278;
  19266. t['Euro'] = 556;
  19267. });
  19268. t['Symbol'] = getLookupTableFactory(function (t) {
  19269. t['space'] = 250;
  19270. t['exclam'] = 333;
  19271. t['universal'] = 713;
  19272. t['numbersign'] = 500;
  19273. t['existential'] = 549;
  19274. t['percent'] = 833;
  19275. t['ampersand'] = 778;
  19276. t['suchthat'] = 439;
  19277. t['parenleft'] = 333;
  19278. t['parenright'] = 333;
  19279. t['asteriskmath'] = 500;
  19280. t['plus'] = 549;
  19281. t['comma'] = 250;
  19282. t['minus'] = 549;
  19283. t['period'] = 250;
  19284. t['slash'] = 278;
  19285. t['zero'] = 500;
  19286. t['one'] = 500;
  19287. t['two'] = 500;
  19288. t['three'] = 500;
  19289. t['four'] = 500;
  19290. t['five'] = 500;
  19291. t['six'] = 500;
  19292. t['seven'] = 500;
  19293. t['eight'] = 500;
  19294. t['nine'] = 500;
  19295. t['colon'] = 278;
  19296. t['semicolon'] = 278;
  19297. t['less'] = 549;
  19298. t['equal'] = 549;
  19299. t['greater'] = 549;
  19300. t['question'] = 444;
  19301. t['congruent'] = 549;
  19302. t['Alpha'] = 722;
  19303. t['Beta'] = 667;
  19304. t['Chi'] = 722;
  19305. t['Delta'] = 612;
  19306. t['Epsilon'] = 611;
  19307. t['Phi'] = 763;
  19308. t['Gamma'] = 603;
  19309. t['Eta'] = 722;
  19310. t['Iota'] = 333;
  19311. t['theta1'] = 631;
  19312. t['Kappa'] = 722;
  19313. t['Lambda'] = 686;
  19314. t['Mu'] = 889;
  19315. t['Nu'] = 722;
  19316. t['Omicron'] = 722;
  19317. t['Pi'] = 768;
  19318. t['Theta'] = 741;
  19319. t['Rho'] = 556;
  19320. t['Sigma'] = 592;
  19321. t['Tau'] = 611;
  19322. t['Upsilon'] = 690;
  19323. t['sigma1'] = 439;
  19324. t['Omega'] = 768;
  19325. t['Xi'] = 645;
  19326. t['Psi'] = 795;
  19327. t['Zeta'] = 611;
  19328. t['bracketleft'] = 333;
  19329. t['therefore'] = 863;
  19330. t['bracketright'] = 333;
  19331. t['perpendicular'] = 658;
  19332. t['underscore'] = 500;
  19333. t['radicalex'] = 500;
  19334. t['alpha'] = 631;
  19335. t['beta'] = 549;
  19336. t['chi'] = 549;
  19337. t['delta'] = 494;
  19338. t['epsilon'] = 439;
  19339. t['phi'] = 521;
  19340. t['gamma'] = 411;
  19341. t['eta'] = 603;
  19342. t['iota'] = 329;
  19343. t['phi1'] = 603;
  19344. t['kappa'] = 549;
  19345. t['lambda'] = 549;
  19346. t['mu'] = 576;
  19347. t['nu'] = 521;
  19348. t['omicron'] = 549;
  19349. t['pi'] = 549;
  19350. t['theta'] = 521;
  19351. t['rho'] = 549;
  19352. t['sigma'] = 603;
  19353. t['tau'] = 439;
  19354. t['upsilon'] = 576;
  19355. t['omega1'] = 713;
  19356. t['omega'] = 686;
  19357. t['xi'] = 493;
  19358. t['psi'] = 686;
  19359. t['zeta'] = 494;
  19360. t['braceleft'] = 480;
  19361. t['bar'] = 200;
  19362. t['braceright'] = 480;
  19363. t['similar'] = 549;
  19364. t['Euro'] = 750;
  19365. t['Upsilon1'] = 620;
  19366. t['minute'] = 247;
  19367. t['lessequal'] = 549;
  19368. t['fraction'] = 167;
  19369. t['infinity'] = 713;
  19370. t['florin'] = 500;
  19371. t['club'] = 753;
  19372. t['diamond'] = 753;
  19373. t['heart'] = 753;
  19374. t['spade'] = 753;
  19375. t['arrowboth'] = 1042;
  19376. t['arrowleft'] = 987;
  19377. t['arrowup'] = 603;
  19378. t['arrowright'] = 987;
  19379. t['arrowdown'] = 603;
  19380. t['degree'] = 400;
  19381. t['plusminus'] = 549;
  19382. t['second'] = 411;
  19383. t['greaterequal'] = 549;
  19384. t['multiply'] = 549;
  19385. t['proportional'] = 713;
  19386. t['partialdiff'] = 494;
  19387. t['bullet'] = 460;
  19388. t['divide'] = 549;
  19389. t['notequal'] = 549;
  19390. t['equivalence'] = 549;
  19391. t['approxequal'] = 549;
  19392. t['ellipsis'] = 1000;
  19393. t['arrowvertex'] = 603;
  19394. t['arrowhorizex'] = 1000;
  19395. t['carriagereturn'] = 658;
  19396. t['aleph'] = 823;
  19397. t['Ifraktur'] = 686;
  19398. t['Rfraktur'] = 795;
  19399. t['weierstrass'] = 987;
  19400. t['circlemultiply'] = 768;
  19401. t['circleplus'] = 768;
  19402. t['emptyset'] = 823;
  19403. t['intersection'] = 768;
  19404. t['union'] = 768;
  19405. t['propersuperset'] = 713;
  19406. t['reflexsuperset'] = 713;
  19407. t['notsubset'] = 713;
  19408. t['propersubset'] = 713;
  19409. t['reflexsubset'] = 713;
  19410. t['element'] = 713;
  19411. t['notelement'] = 713;
  19412. t['angle'] = 768;
  19413. t['gradient'] = 713;
  19414. t['registerserif'] = 790;
  19415. t['copyrightserif'] = 790;
  19416. t['trademarkserif'] = 890;
  19417. t['product'] = 823;
  19418. t['radical'] = 549;
  19419. t['dotmath'] = 250;
  19420. t['logicalnot'] = 713;
  19421. t['logicaland'] = 603;
  19422. t['logicalor'] = 603;
  19423. t['arrowdblboth'] = 1042;
  19424. t['arrowdblleft'] = 987;
  19425. t['arrowdblup'] = 603;
  19426. t['arrowdblright'] = 987;
  19427. t['arrowdbldown'] = 603;
  19428. t['lozenge'] = 494;
  19429. t['angleleft'] = 329;
  19430. t['registersans'] = 790;
  19431. t['copyrightsans'] = 790;
  19432. t['trademarksans'] = 786;
  19433. t['summation'] = 713;
  19434. t['parenlefttp'] = 384;
  19435. t['parenleftex'] = 384;
  19436. t['parenleftbt'] = 384;
  19437. t['bracketlefttp'] = 384;
  19438. t['bracketleftex'] = 384;
  19439. t['bracketleftbt'] = 384;
  19440. t['bracelefttp'] = 494;
  19441. t['braceleftmid'] = 494;
  19442. t['braceleftbt'] = 494;
  19443. t['braceex'] = 494;
  19444. t['angleright'] = 329;
  19445. t['integral'] = 274;
  19446. t['integraltp'] = 686;
  19447. t['integralex'] = 686;
  19448. t['integralbt'] = 686;
  19449. t['parenrighttp'] = 384;
  19450. t['parenrightex'] = 384;
  19451. t['parenrightbt'] = 384;
  19452. t['bracketrighttp'] = 384;
  19453. t['bracketrightex'] = 384;
  19454. t['bracketrightbt'] = 384;
  19455. t['bracerighttp'] = 494;
  19456. t['bracerightmid'] = 494;
  19457. t['bracerightbt'] = 494;
  19458. t['apple'] = 790;
  19459. });
  19460. t['Times-Roman'] = getLookupTableFactory(function (t) {
  19461. t['space'] = 250;
  19462. t['exclam'] = 333;
  19463. t['quotedbl'] = 408;
  19464. t['numbersign'] = 500;
  19465. t['dollar'] = 500;
  19466. t['percent'] = 833;
  19467. t['ampersand'] = 778;
  19468. t['quoteright'] = 333;
  19469. t['parenleft'] = 333;
  19470. t['parenright'] = 333;
  19471. t['asterisk'] = 500;
  19472. t['plus'] = 564;
  19473. t['comma'] = 250;
  19474. t['hyphen'] = 333;
  19475. t['period'] = 250;
  19476. t['slash'] = 278;
  19477. t['zero'] = 500;
  19478. t['one'] = 500;
  19479. t['two'] = 500;
  19480. t['three'] = 500;
  19481. t['four'] = 500;
  19482. t['five'] = 500;
  19483. t['six'] = 500;
  19484. t['seven'] = 500;
  19485. t['eight'] = 500;
  19486. t['nine'] = 500;
  19487. t['colon'] = 278;
  19488. t['semicolon'] = 278;
  19489. t['less'] = 564;
  19490. t['equal'] = 564;
  19491. t['greater'] = 564;
  19492. t['question'] = 444;
  19493. t['at'] = 921;
  19494. t['A'] = 722;
  19495. t['B'] = 667;
  19496. t['C'] = 667;
  19497. t['D'] = 722;
  19498. t['E'] = 611;
  19499. t['F'] = 556;
  19500. t['G'] = 722;
  19501. t['H'] = 722;
  19502. t['I'] = 333;
  19503. t['J'] = 389;
  19504. t['K'] = 722;
  19505. t['L'] = 611;
  19506. t['M'] = 889;
  19507. t['N'] = 722;
  19508. t['O'] = 722;
  19509. t['P'] = 556;
  19510. t['Q'] = 722;
  19511. t['R'] = 667;
  19512. t['S'] = 556;
  19513. t['T'] = 611;
  19514. t['U'] = 722;
  19515. t['V'] = 722;
  19516. t['W'] = 944;
  19517. t['X'] = 722;
  19518. t['Y'] = 722;
  19519. t['Z'] = 611;
  19520. t['bracketleft'] = 333;
  19521. t['backslash'] = 278;
  19522. t['bracketright'] = 333;
  19523. t['asciicircum'] = 469;
  19524. t['underscore'] = 500;
  19525. t['quoteleft'] = 333;
  19526. t['a'] = 444;
  19527. t['b'] = 500;
  19528. t['c'] = 444;
  19529. t['d'] = 500;
  19530. t['e'] = 444;
  19531. t['f'] = 333;
  19532. t['g'] = 500;
  19533. t['h'] = 500;
  19534. t['i'] = 278;
  19535. t['j'] = 278;
  19536. t['k'] = 500;
  19537. t['l'] = 278;
  19538. t['m'] = 778;
  19539. t['n'] = 500;
  19540. t['o'] = 500;
  19541. t['p'] = 500;
  19542. t['q'] = 500;
  19543. t['r'] = 333;
  19544. t['s'] = 389;
  19545. t['t'] = 278;
  19546. t['u'] = 500;
  19547. t['v'] = 500;
  19548. t['w'] = 722;
  19549. t['x'] = 500;
  19550. t['y'] = 500;
  19551. t['z'] = 444;
  19552. t['braceleft'] = 480;
  19553. t['bar'] = 200;
  19554. t['braceright'] = 480;
  19555. t['asciitilde'] = 541;
  19556. t['exclamdown'] = 333;
  19557. t['cent'] = 500;
  19558. t['sterling'] = 500;
  19559. t['fraction'] = 167;
  19560. t['yen'] = 500;
  19561. t['florin'] = 500;
  19562. t['section'] = 500;
  19563. t['currency'] = 500;
  19564. t['quotesingle'] = 180;
  19565. t['quotedblleft'] = 444;
  19566. t['guillemotleft'] = 500;
  19567. t['guilsinglleft'] = 333;
  19568. t['guilsinglright'] = 333;
  19569. t['fi'] = 556;
  19570. t['fl'] = 556;
  19571. t['endash'] = 500;
  19572. t['dagger'] = 500;
  19573. t['daggerdbl'] = 500;
  19574. t['periodcentered'] = 250;
  19575. t['paragraph'] = 453;
  19576. t['bullet'] = 350;
  19577. t['quotesinglbase'] = 333;
  19578. t['quotedblbase'] = 444;
  19579. t['quotedblright'] = 444;
  19580. t['guillemotright'] = 500;
  19581. t['ellipsis'] = 1000;
  19582. t['perthousand'] = 1000;
  19583. t['questiondown'] = 444;
  19584. t['grave'] = 333;
  19585. t['acute'] = 333;
  19586. t['circumflex'] = 333;
  19587. t['tilde'] = 333;
  19588. t['macron'] = 333;
  19589. t['breve'] = 333;
  19590. t['dotaccent'] = 333;
  19591. t['dieresis'] = 333;
  19592. t['ring'] = 333;
  19593. t['cedilla'] = 333;
  19594. t['hungarumlaut'] = 333;
  19595. t['ogonek'] = 333;
  19596. t['caron'] = 333;
  19597. t['emdash'] = 1000;
  19598. t['AE'] = 889;
  19599. t['ordfeminine'] = 276;
  19600. t['Lslash'] = 611;
  19601. t['Oslash'] = 722;
  19602. t['OE'] = 889;
  19603. t['ordmasculine'] = 310;
  19604. t['ae'] = 667;
  19605. t['dotlessi'] = 278;
  19606. t['lslash'] = 278;
  19607. t['oslash'] = 500;
  19608. t['oe'] = 722;
  19609. t['germandbls'] = 500;
  19610. t['Idieresis'] = 333;
  19611. t['eacute'] = 444;
  19612. t['abreve'] = 444;
  19613. t['uhungarumlaut'] = 500;
  19614. t['ecaron'] = 444;
  19615. t['Ydieresis'] = 722;
  19616. t['divide'] = 564;
  19617. t['Yacute'] = 722;
  19618. t['Acircumflex'] = 722;
  19619. t['aacute'] = 444;
  19620. t['Ucircumflex'] = 722;
  19621. t['yacute'] = 500;
  19622. t['scommaaccent'] = 389;
  19623. t['ecircumflex'] = 444;
  19624. t['Uring'] = 722;
  19625. t['Udieresis'] = 722;
  19626. t['aogonek'] = 444;
  19627. t['Uacute'] = 722;
  19628. t['uogonek'] = 500;
  19629. t['Edieresis'] = 611;
  19630. t['Dcroat'] = 722;
  19631. t['commaaccent'] = 250;
  19632. t['copyright'] = 760;
  19633. t['Emacron'] = 611;
  19634. t['ccaron'] = 444;
  19635. t['aring'] = 444;
  19636. t['Ncommaaccent'] = 722;
  19637. t['lacute'] = 278;
  19638. t['agrave'] = 444;
  19639. t['Tcommaaccent'] = 611;
  19640. t['Cacute'] = 667;
  19641. t['atilde'] = 444;
  19642. t['Edotaccent'] = 611;
  19643. t['scaron'] = 389;
  19644. t['scedilla'] = 389;
  19645. t['iacute'] = 278;
  19646. t['lozenge'] = 471;
  19647. t['Rcaron'] = 667;
  19648. t['Gcommaaccent'] = 722;
  19649. t['ucircumflex'] = 500;
  19650. t['acircumflex'] = 444;
  19651. t['Amacron'] = 722;
  19652. t['rcaron'] = 333;
  19653. t['ccedilla'] = 444;
  19654. t['Zdotaccent'] = 611;
  19655. t['Thorn'] = 556;
  19656. t['Omacron'] = 722;
  19657. t['Racute'] = 667;
  19658. t['Sacute'] = 556;
  19659. t['dcaron'] = 588;
  19660. t['Umacron'] = 722;
  19661. t['uring'] = 500;
  19662. t['threesuperior'] = 300;
  19663. t['Ograve'] = 722;
  19664. t['Agrave'] = 722;
  19665. t['Abreve'] = 722;
  19666. t['multiply'] = 564;
  19667. t['uacute'] = 500;
  19668. t['Tcaron'] = 611;
  19669. t['partialdiff'] = 476;
  19670. t['ydieresis'] = 500;
  19671. t['Nacute'] = 722;
  19672. t['icircumflex'] = 278;
  19673. t['Ecircumflex'] = 611;
  19674. t['adieresis'] = 444;
  19675. t['edieresis'] = 444;
  19676. t['cacute'] = 444;
  19677. t['nacute'] = 500;
  19678. t['umacron'] = 500;
  19679. t['Ncaron'] = 722;
  19680. t['Iacute'] = 333;
  19681. t['plusminus'] = 564;
  19682. t['brokenbar'] = 200;
  19683. t['registered'] = 760;
  19684. t['Gbreve'] = 722;
  19685. t['Idotaccent'] = 333;
  19686. t['summation'] = 600;
  19687. t['Egrave'] = 611;
  19688. t['racute'] = 333;
  19689. t['omacron'] = 500;
  19690. t['Zacute'] = 611;
  19691. t['Zcaron'] = 611;
  19692. t['greaterequal'] = 549;
  19693. t['Eth'] = 722;
  19694. t['Ccedilla'] = 667;
  19695. t['lcommaaccent'] = 278;
  19696. t['tcaron'] = 326;
  19697. t['eogonek'] = 444;
  19698. t['Uogonek'] = 722;
  19699. t['Aacute'] = 722;
  19700. t['Adieresis'] = 722;
  19701. t['egrave'] = 444;
  19702. t['zacute'] = 444;
  19703. t['iogonek'] = 278;
  19704. t['Oacute'] = 722;
  19705. t['oacute'] = 500;
  19706. t['amacron'] = 444;
  19707. t['sacute'] = 389;
  19708. t['idieresis'] = 278;
  19709. t['Ocircumflex'] = 722;
  19710. t['Ugrave'] = 722;
  19711. t['Delta'] = 612;
  19712. t['thorn'] = 500;
  19713. t['twosuperior'] = 300;
  19714. t['Odieresis'] = 722;
  19715. t['mu'] = 500;
  19716. t['igrave'] = 278;
  19717. t['ohungarumlaut'] = 500;
  19718. t['Eogonek'] = 611;
  19719. t['dcroat'] = 500;
  19720. t['threequarters'] = 750;
  19721. t['Scedilla'] = 556;
  19722. t['lcaron'] = 344;
  19723. t['Kcommaaccent'] = 722;
  19724. t['Lacute'] = 611;
  19725. t['trademark'] = 980;
  19726. t['edotaccent'] = 444;
  19727. t['Igrave'] = 333;
  19728. t['Imacron'] = 333;
  19729. t['Lcaron'] = 611;
  19730. t['onehalf'] = 750;
  19731. t['lessequal'] = 549;
  19732. t['ocircumflex'] = 500;
  19733. t['ntilde'] = 500;
  19734. t['Uhungarumlaut'] = 722;
  19735. t['Eacute'] = 611;
  19736. t['emacron'] = 444;
  19737. t['gbreve'] = 500;
  19738. t['onequarter'] = 750;
  19739. t['Scaron'] = 556;
  19740. t['Scommaaccent'] = 556;
  19741. t['Ohungarumlaut'] = 722;
  19742. t['degree'] = 400;
  19743. t['ograve'] = 500;
  19744. t['Ccaron'] = 667;
  19745. t['ugrave'] = 500;
  19746. t['radical'] = 453;
  19747. t['Dcaron'] = 722;
  19748. t['rcommaaccent'] = 333;
  19749. t['Ntilde'] = 722;
  19750. t['otilde'] = 500;
  19751. t['Rcommaaccent'] = 667;
  19752. t['Lcommaaccent'] = 611;
  19753. t['Atilde'] = 722;
  19754. t['Aogonek'] = 722;
  19755. t['Aring'] = 722;
  19756. t['Otilde'] = 722;
  19757. t['zdotaccent'] = 444;
  19758. t['Ecaron'] = 611;
  19759. t['Iogonek'] = 333;
  19760. t['kcommaaccent'] = 500;
  19761. t['minus'] = 564;
  19762. t['Icircumflex'] = 333;
  19763. t['ncaron'] = 500;
  19764. t['tcommaaccent'] = 278;
  19765. t['logicalnot'] = 564;
  19766. t['odieresis'] = 500;
  19767. t['udieresis'] = 500;
  19768. t['notequal'] = 549;
  19769. t['gcommaaccent'] = 500;
  19770. t['eth'] = 500;
  19771. t['zcaron'] = 444;
  19772. t['ncommaaccent'] = 500;
  19773. t['onesuperior'] = 300;
  19774. t['imacron'] = 278;
  19775. t['Euro'] = 500;
  19776. });
  19777. t['Times-Bold'] = getLookupTableFactory(function (t) {
  19778. t['space'] = 250;
  19779. t['exclam'] = 333;
  19780. t['quotedbl'] = 555;
  19781. t['numbersign'] = 500;
  19782. t['dollar'] = 500;
  19783. t['percent'] = 1000;
  19784. t['ampersand'] = 833;
  19785. t['quoteright'] = 333;
  19786. t['parenleft'] = 333;
  19787. t['parenright'] = 333;
  19788. t['asterisk'] = 500;
  19789. t['plus'] = 570;
  19790. t['comma'] = 250;
  19791. t['hyphen'] = 333;
  19792. t['period'] = 250;
  19793. t['slash'] = 278;
  19794. t['zero'] = 500;
  19795. t['one'] = 500;
  19796. t['two'] = 500;
  19797. t['three'] = 500;
  19798. t['four'] = 500;
  19799. t['five'] = 500;
  19800. t['six'] = 500;
  19801. t['seven'] = 500;
  19802. t['eight'] = 500;
  19803. t['nine'] = 500;
  19804. t['colon'] = 333;
  19805. t['semicolon'] = 333;
  19806. t['less'] = 570;
  19807. t['equal'] = 570;
  19808. t['greater'] = 570;
  19809. t['question'] = 500;
  19810. t['at'] = 930;
  19811. t['A'] = 722;
  19812. t['B'] = 667;
  19813. t['C'] = 722;
  19814. t['D'] = 722;
  19815. t['E'] = 667;
  19816. t['F'] = 611;
  19817. t['G'] = 778;
  19818. t['H'] = 778;
  19819. t['I'] = 389;
  19820. t['J'] = 500;
  19821. t['K'] = 778;
  19822. t['L'] = 667;
  19823. t['M'] = 944;
  19824. t['N'] = 722;
  19825. t['O'] = 778;
  19826. t['P'] = 611;
  19827. t['Q'] = 778;
  19828. t['R'] = 722;
  19829. t['S'] = 556;
  19830. t['T'] = 667;
  19831. t['U'] = 722;
  19832. t['V'] = 722;
  19833. t['W'] = 1000;
  19834. t['X'] = 722;
  19835. t['Y'] = 722;
  19836. t['Z'] = 667;
  19837. t['bracketleft'] = 333;
  19838. t['backslash'] = 278;
  19839. t['bracketright'] = 333;
  19840. t['asciicircum'] = 581;
  19841. t['underscore'] = 500;
  19842. t['quoteleft'] = 333;
  19843. t['a'] = 500;
  19844. t['b'] = 556;
  19845. t['c'] = 444;
  19846. t['d'] = 556;
  19847. t['e'] = 444;
  19848. t['f'] = 333;
  19849. t['g'] = 500;
  19850. t['h'] = 556;
  19851. t['i'] = 278;
  19852. t['j'] = 333;
  19853. t['k'] = 556;
  19854. t['l'] = 278;
  19855. t['m'] = 833;
  19856. t['n'] = 556;
  19857. t['o'] = 500;
  19858. t['p'] = 556;
  19859. t['q'] = 556;
  19860. t['r'] = 444;
  19861. t['s'] = 389;
  19862. t['t'] = 333;
  19863. t['u'] = 556;
  19864. t['v'] = 500;
  19865. t['w'] = 722;
  19866. t['x'] = 500;
  19867. t['y'] = 500;
  19868. t['z'] = 444;
  19869. t['braceleft'] = 394;
  19870. t['bar'] = 220;
  19871. t['braceright'] = 394;
  19872. t['asciitilde'] = 520;
  19873. t['exclamdown'] = 333;
  19874. t['cent'] = 500;
  19875. t['sterling'] = 500;
  19876. t['fraction'] = 167;
  19877. t['yen'] = 500;
  19878. t['florin'] = 500;
  19879. t['section'] = 500;
  19880. t['currency'] = 500;
  19881. t['quotesingle'] = 278;
  19882. t['quotedblleft'] = 500;
  19883. t['guillemotleft'] = 500;
  19884. t['guilsinglleft'] = 333;
  19885. t['guilsinglright'] = 333;
  19886. t['fi'] = 556;
  19887. t['fl'] = 556;
  19888. t['endash'] = 500;
  19889. t['dagger'] = 500;
  19890. t['daggerdbl'] = 500;
  19891. t['periodcentered'] = 250;
  19892. t['paragraph'] = 540;
  19893. t['bullet'] = 350;
  19894. t['quotesinglbase'] = 333;
  19895. t['quotedblbase'] = 500;
  19896. t['quotedblright'] = 500;
  19897. t['guillemotright'] = 500;
  19898. t['ellipsis'] = 1000;
  19899. t['perthousand'] = 1000;
  19900. t['questiondown'] = 500;
  19901. t['grave'] = 333;
  19902. t['acute'] = 333;
  19903. t['circumflex'] = 333;
  19904. t['tilde'] = 333;
  19905. t['macron'] = 333;
  19906. t['breve'] = 333;
  19907. t['dotaccent'] = 333;
  19908. t['dieresis'] = 333;
  19909. t['ring'] = 333;
  19910. t['cedilla'] = 333;
  19911. t['hungarumlaut'] = 333;
  19912. t['ogonek'] = 333;
  19913. t['caron'] = 333;
  19914. t['emdash'] = 1000;
  19915. t['AE'] = 1000;
  19916. t['ordfeminine'] = 300;
  19917. t['Lslash'] = 667;
  19918. t['Oslash'] = 778;
  19919. t['OE'] = 1000;
  19920. t['ordmasculine'] = 330;
  19921. t['ae'] = 722;
  19922. t['dotlessi'] = 278;
  19923. t['lslash'] = 278;
  19924. t['oslash'] = 500;
  19925. t['oe'] = 722;
  19926. t['germandbls'] = 556;
  19927. t['Idieresis'] = 389;
  19928. t['eacute'] = 444;
  19929. t['abreve'] = 500;
  19930. t['uhungarumlaut'] = 556;
  19931. t['ecaron'] = 444;
  19932. t['Ydieresis'] = 722;
  19933. t['divide'] = 570;
  19934. t['Yacute'] = 722;
  19935. t['Acircumflex'] = 722;
  19936. t['aacute'] = 500;
  19937. t['Ucircumflex'] = 722;
  19938. t['yacute'] = 500;
  19939. t['scommaaccent'] = 389;
  19940. t['ecircumflex'] = 444;
  19941. t['Uring'] = 722;
  19942. t['Udieresis'] = 722;
  19943. t['aogonek'] = 500;
  19944. t['Uacute'] = 722;
  19945. t['uogonek'] = 556;
  19946. t['Edieresis'] = 667;
  19947. t['Dcroat'] = 722;
  19948. t['commaaccent'] = 250;
  19949. t['copyright'] = 747;
  19950. t['Emacron'] = 667;
  19951. t['ccaron'] = 444;
  19952. t['aring'] = 500;
  19953. t['Ncommaaccent'] = 722;
  19954. t['lacute'] = 278;
  19955. t['agrave'] = 500;
  19956. t['Tcommaaccent'] = 667;
  19957. t['Cacute'] = 722;
  19958. t['atilde'] = 500;
  19959. t['Edotaccent'] = 667;
  19960. t['scaron'] = 389;
  19961. t['scedilla'] = 389;
  19962. t['iacute'] = 278;
  19963. t['lozenge'] = 494;
  19964. t['Rcaron'] = 722;
  19965. t['Gcommaaccent'] = 778;
  19966. t['ucircumflex'] = 556;
  19967. t['acircumflex'] = 500;
  19968. t['Amacron'] = 722;
  19969. t['rcaron'] = 444;
  19970. t['ccedilla'] = 444;
  19971. t['Zdotaccent'] = 667;
  19972. t['Thorn'] = 611;
  19973. t['Omacron'] = 778;
  19974. t['Racute'] = 722;
  19975. t['Sacute'] = 556;
  19976. t['dcaron'] = 672;
  19977. t['Umacron'] = 722;
  19978. t['uring'] = 556;
  19979. t['threesuperior'] = 300;
  19980. t['Ograve'] = 778;
  19981. t['Agrave'] = 722;
  19982. t['Abreve'] = 722;
  19983. t['multiply'] = 570;
  19984. t['uacute'] = 556;
  19985. t['Tcaron'] = 667;
  19986. t['partialdiff'] = 494;
  19987. t['ydieresis'] = 500;
  19988. t['Nacute'] = 722;
  19989. t['icircumflex'] = 278;
  19990. t['Ecircumflex'] = 667;
  19991. t['adieresis'] = 500;
  19992. t['edieresis'] = 444;
  19993. t['cacute'] = 444;
  19994. t['nacute'] = 556;
  19995. t['umacron'] = 556;
  19996. t['Ncaron'] = 722;
  19997. t['Iacute'] = 389;
  19998. t['plusminus'] = 570;
  19999. t['brokenbar'] = 220;
  20000. t['registered'] = 747;
  20001. t['Gbreve'] = 778;
  20002. t['Idotaccent'] = 389;
  20003. t['summation'] = 600;
  20004. t['Egrave'] = 667;
  20005. t['racute'] = 444;
  20006. t['omacron'] = 500;
  20007. t['Zacute'] = 667;
  20008. t['Zcaron'] = 667;
  20009. t['greaterequal'] = 549;
  20010. t['Eth'] = 722;
  20011. t['Ccedilla'] = 722;
  20012. t['lcommaaccent'] = 278;
  20013. t['tcaron'] = 416;
  20014. t['eogonek'] = 444;
  20015. t['Uogonek'] = 722;
  20016. t['Aacute'] = 722;
  20017. t['Adieresis'] = 722;
  20018. t['egrave'] = 444;
  20019. t['zacute'] = 444;
  20020. t['iogonek'] = 278;
  20021. t['Oacute'] = 778;
  20022. t['oacute'] = 500;
  20023. t['amacron'] = 500;
  20024. t['sacute'] = 389;
  20025. t['idieresis'] = 278;
  20026. t['Ocircumflex'] = 778;
  20027. t['Ugrave'] = 722;
  20028. t['Delta'] = 612;
  20029. t['thorn'] = 556;
  20030. t['twosuperior'] = 300;
  20031. t['Odieresis'] = 778;
  20032. t['mu'] = 556;
  20033. t['igrave'] = 278;
  20034. t['ohungarumlaut'] = 500;
  20035. t['Eogonek'] = 667;
  20036. t['dcroat'] = 556;
  20037. t['threequarters'] = 750;
  20038. t['Scedilla'] = 556;
  20039. t['lcaron'] = 394;
  20040. t['Kcommaaccent'] = 778;
  20041. t['Lacute'] = 667;
  20042. t['trademark'] = 1000;
  20043. t['edotaccent'] = 444;
  20044. t['Igrave'] = 389;
  20045. t['Imacron'] = 389;
  20046. t['Lcaron'] = 667;
  20047. t['onehalf'] = 750;
  20048. t['lessequal'] = 549;
  20049. t['ocircumflex'] = 500;
  20050. t['ntilde'] = 556;
  20051. t['Uhungarumlaut'] = 722;
  20052. t['Eacute'] = 667;
  20053. t['emacron'] = 444;
  20054. t['gbreve'] = 500;
  20055. t['onequarter'] = 750;
  20056. t['Scaron'] = 556;
  20057. t['Scommaaccent'] = 556;
  20058. t['Ohungarumlaut'] = 778;
  20059. t['degree'] = 400;
  20060. t['ograve'] = 500;
  20061. t['Ccaron'] = 722;
  20062. t['ugrave'] = 556;
  20063. t['radical'] = 549;
  20064. t['Dcaron'] = 722;
  20065. t['rcommaaccent'] = 444;
  20066. t['Ntilde'] = 722;
  20067. t['otilde'] = 500;
  20068. t['Rcommaaccent'] = 722;
  20069. t['Lcommaaccent'] = 667;
  20070. t['Atilde'] = 722;
  20071. t['Aogonek'] = 722;
  20072. t['Aring'] = 722;
  20073. t['Otilde'] = 778;
  20074. t['zdotaccent'] = 444;
  20075. t['Ecaron'] = 667;
  20076. t['Iogonek'] = 389;
  20077. t['kcommaaccent'] = 556;
  20078. t['minus'] = 570;
  20079. t['Icircumflex'] = 389;
  20080. t['ncaron'] = 556;
  20081. t['tcommaaccent'] = 333;
  20082. t['logicalnot'] = 570;
  20083. t['odieresis'] = 500;
  20084. t['udieresis'] = 556;
  20085. t['notequal'] = 549;
  20086. t['gcommaaccent'] = 500;
  20087. t['eth'] = 500;
  20088. t['zcaron'] = 444;
  20089. t['ncommaaccent'] = 556;
  20090. t['onesuperior'] = 300;
  20091. t['imacron'] = 278;
  20092. t['Euro'] = 500;
  20093. });
  20094. t['Times-BoldItalic'] = getLookupTableFactory(function (t) {
  20095. t['space'] = 250;
  20096. t['exclam'] = 389;
  20097. t['quotedbl'] = 555;
  20098. t['numbersign'] = 500;
  20099. t['dollar'] = 500;
  20100. t['percent'] = 833;
  20101. t['ampersand'] = 778;
  20102. t['quoteright'] = 333;
  20103. t['parenleft'] = 333;
  20104. t['parenright'] = 333;
  20105. t['asterisk'] = 500;
  20106. t['plus'] = 570;
  20107. t['comma'] = 250;
  20108. t['hyphen'] = 333;
  20109. t['period'] = 250;
  20110. t['slash'] = 278;
  20111. t['zero'] = 500;
  20112. t['one'] = 500;
  20113. t['two'] = 500;
  20114. t['three'] = 500;
  20115. t['four'] = 500;
  20116. t['five'] = 500;
  20117. t['six'] = 500;
  20118. t['seven'] = 500;
  20119. t['eight'] = 500;
  20120. t['nine'] = 500;
  20121. t['colon'] = 333;
  20122. t['semicolon'] = 333;
  20123. t['less'] = 570;
  20124. t['equal'] = 570;
  20125. t['greater'] = 570;
  20126. t['question'] = 500;
  20127. t['at'] = 832;
  20128. t['A'] = 667;
  20129. t['B'] = 667;
  20130. t['C'] = 667;
  20131. t['D'] = 722;
  20132. t['E'] = 667;
  20133. t['F'] = 667;
  20134. t['G'] = 722;
  20135. t['H'] = 778;
  20136. t['I'] = 389;
  20137. t['J'] = 500;
  20138. t['K'] = 667;
  20139. t['L'] = 611;
  20140. t['M'] = 889;
  20141. t['N'] = 722;
  20142. t['O'] = 722;
  20143. t['P'] = 611;
  20144. t['Q'] = 722;
  20145. t['R'] = 667;
  20146. t['S'] = 556;
  20147. t['T'] = 611;
  20148. t['U'] = 722;
  20149. t['V'] = 667;
  20150. t['W'] = 889;
  20151. t['X'] = 667;
  20152. t['Y'] = 611;
  20153. t['Z'] = 611;
  20154. t['bracketleft'] = 333;
  20155. t['backslash'] = 278;
  20156. t['bracketright'] = 333;
  20157. t['asciicircum'] = 570;
  20158. t['underscore'] = 500;
  20159. t['quoteleft'] = 333;
  20160. t['a'] = 500;
  20161. t['b'] = 500;
  20162. t['c'] = 444;
  20163. t['d'] = 500;
  20164. t['e'] = 444;
  20165. t['f'] = 333;
  20166. t['g'] = 500;
  20167. t['h'] = 556;
  20168. t['i'] = 278;
  20169. t['j'] = 278;
  20170. t['k'] = 500;
  20171. t['l'] = 278;
  20172. t['m'] = 778;
  20173. t['n'] = 556;
  20174. t['o'] = 500;
  20175. t['p'] = 500;
  20176. t['q'] = 500;
  20177. t['r'] = 389;
  20178. t['s'] = 389;
  20179. t['t'] = 278;
  20180. t['u'] = 556;
  20181. t['v'] = 444;
  20182. t['w'] = 667;
  20183. t['x'] = 500;
  20184. t['y'] = 444;
  20185. t['z'] = 389;
  20186. t['braceleft'] = 348;
  20187. t['bar'] = 220;
  20188. t['braceright'] = 348;
  20189. t['asciitilde'] = 570;
  20190. t['exclamdown'] = 389;
  20191. t['cent'] = 500;
  20192. t['sterling'] = 500;
  20193. t['fraction'] = 167;
  20194. t['yen'] = 500;
  20195. t['florin'] = 500;
  20196. t['section'] = 500;
  20197. t['currency'] = 500;
  20198. t['quotesingle'] = 278;
  20199. t['quotedblleft'] = 500;
  20200. t['guillemotleft'] = 500;
  20201. t['guilsinglleft'] = 333;
  20202. t['guilsinglright'] = 333;
  20203. t['fi'] = 556;
  20204. t['fl'] = 556;
  20205. t['endash'] = 500;
  20206. t['dagger'] = 500;
  20207. t['daggerdbl'] = 500;
  20208. t['periodcentered'] = 250;
  20209. t['paragraph'] = 500;
  20210. t['bullet'] = 350;
  20211. t['quotesinglbase'] = 333;
  20212. t['quotedblbase'] = 500;
  20213. t['quotedblright'] = 500;
  20214. t['guillemotright'] = 500;
  20215. t['ellipsis'] = 1000;
  20216. t['perthousand'] = 1000;
  20217. t['questiondown'] = 500;
  20218. t['grave'] = 333;
  20219. t['acute'] = 333;
  20220. t['circumflex'] = 333;
  20221. t['tilde'] = 333;
  20222. t['macron'] = 333;
  20223. t['breve'] = 333;
  20224. t['dotaccent'] = 333;
  20225. t['dieresis'] = 333;
  20226. t['ring'] = 333;
  20227. t['cedilla'] = 333;
  20228. t['hungarumlaut'] = 333;
  20229. t['ogonek'] = 333;
  20230. t['caron'] = 333;
  20231. t['emdash'] = 1000;
  20232. t['AE'] = 944;
  20233. t['ordfeminine'] = 266;
  20234. t['Lslash'] = 611;
  20235. t['Oslash'] = 722;
  20236. t['OE'] = 944;
  20237. t['ordmasculine'] = 300;
  20238. t['ae'] = 722;
  20239. t['dotlessi'] = 278;
  20240. t['lslash'] = 278;
  20241. t['oslash'] = 500;
  20242. t['oe'] = 722;
  20243. t['germandbls'] = 500;
  20244. t['Idieresis'] = 389;
  20245. t['eacute'] = 444;
  20246. t['abreve'] = 500;
  20247. t['uhungarumlaut'] = 556;
  20248. t['ecaron'] = 444;
  20249. t['Ydieresis'] = 611;
  20250. t['divide'] = 570;
  20251. t['Yacute'] = 611;
  20252. t['Acircumflex'] = 667;
  20253. t['aacute'] = 500;
  20254. t['Ucircumflex'] = 722;
  20255. t['yacute'] = 444;
  20256. t['scommaaccent'] = 389;
  20257. t['ecircumflex'] = 444;
  20258. t['Uring'] = 722;
  20259. t['Udieresis'] = 722;
  20260. t['aogonek'] = 500;
  20261. t['Uacute'] = 722;
  20262. t['uogonek'] = 556;
  20263. t['Edieresis'] = 667;
  20264. t['Dcroat'] = 722;
  20265. t['commaaccent'] = 250;
  20266. t['copyright'] = 747;
  20267. t['Emacron'] = 667;
  20268. t['ccaron'] = 444;
  20269. t['aring'] = 500;
  20270. t['Ncommaaccent'] = 722;
  20271. t['lacute'] = 278;
  20272. t['agrave'] = 500;
  20273. t['Tcommaaccent'] = 611;
  20274. t['Cacute'] = 667;
  20275. t['atilde'] = 500;
  20276. t['Edotaccent'] = 667;
  20277. t['scaron'] = 389;
  20278. t['scedilla'] = 389;
  20279. t['iacute'] = 278;
  20280. t['lozenge'] = 494;
  20281. t['Rcaron'] = 667;
  20282. t['Gcommaaccent'] = 722;
  20283. t['ucircumflex'] = 556;
  20284. t['acircumflex'] = 500;
  20285. t['Amacron'] = 667;
  20286. t['rcaron'] = 389;
  20287. t['ccedilla'] = 444;
  20288. t['Zdotaccent'] = 611;
  20289. t['Thorn'] = 611;
  20290. t['Omacron'] = 722;
  20291. t['Racute'] = 667;
  20292. t['Sacute'] = 556;
  20293. t['dcaron'] = 608;
  20294. t['Umacron'] = 722;
  20295. t['uring'] = 556;
  20296. t['threesuperior'] = 300;
  20297. t['Ograve'] = 722;
  20298. t['Agrave'] = 667;
  20299. t['Abreve'] = 667;
  20300. t['multiply'] = 570;
  20301. t['uacute'] = 556;
  20302. t['Tcaron'] = 611;
  20303. t['partialdiff'] = 494;
  20304. t['ydieresis'] = 444;
  20305. t['Nacute'] = 722;
  20306. t['icircumflex'] = 278;
  20307. t['Ecircumflex'] = 667;
  20308. t['adieresis'] = 500;
  20309. t['edieresis'] = 444;
  20310. t['cacute'] = 444;
  20311. t['nacute'] = 556;
  20312. t['umacron'] = 556;
  20313. t['Ncaron'] = 722;
  20314. t['Iacute'] = 389;
  20315. t['plusminus'] = 570;
  20316. t['brokenbar'] = 220;
  20317. t['registered'] = 747;
  20318. t['Gbreve'] = 722;
  20319. t['Idotaccent'] = 389;
  20320. t['summation'] = 600;
  20321. t['Egrave'] = 667;
  20322. t['racute'] = 389;
  20323. t['omacron'] = 500;
  20324. t['Zacute'] = 611;
  20325. t['Zcaron'] = 611;
  20326. t['greaterequal'] = 549;
  20327. t['Eth'] = 722;
  20328. t['Ccedilla'] = 667;
  20329. t['lcommaaccent'] = 278;
  20330. t['tcaron'] = 366;
  20331. t['eogonek'] = 444;
  20332. t['Uogonek'] = 722;
  20333. t['Aacute'] = 667;
  20334. t['Adieresis'] = 667;
  20335. t['egrave'] = 444;
  20336. t['zacute'] = 389;
  20337. t['iogonek'] = 278;
  20338. t['Oacute'] = 722;
  20339. t['oacute'] = 500;
  20340. t['amacron'] = 500;
  20341. t['sacute'] = 389;
  20342. t['idieresis'] = 278;
  20343. t['Ocircumflex'] = 722;
  20344. t['Ugrave'] = 722;
  20345. t['Delta'] = 612;
  20346. t['thorn'] = 500;
  20347. t['twosuperior'] = 300;
  20348. t['Odieresis'] = 722;
  20349. t['mu'] = 576;
  20350. t['igrave'] = 278;
  20351. t['ohungarumlaut'] = 500;
  20352. t['Eogonek'] = 667;
  20353. t['dcroat'] = 500;
  20354. t['threequarters'] = 750;
  20355. t['Scedilla'] = 556;
  20356. t['lcaron'] = 382;
  20357. t['Kcommaaccent'] = 667;
  20358. t['Lacute'] = 611;
  20359. t['trademark'] = 1000;
  20360. t['edotaccent'] = 444;
  20361. t['Igrave'] = 389;
  20362. t['Imacron'] = 389;
  20363. t['Lcaron'] = 611;
  20364. t['onehalf'] = 750;
  20365. t['lessequal'] = 549;
  20366. t['ocircumflex'] = 500;
  20367. t['ntilde'] = 556;
  20368. t['Uhungarumlaut'] = 722;
  20369. t['Eacute'] = 667;
  20370. t['emacron'] = 444;
  20371. t['gbreve'] = 500;
  20372. t['onequarter'] = 750;
  20373. t['Scaron'] = 556;
  20374. t['Scommaaccent'] = 556;
  20375. t['Ohungarumlaut'] = 722;
  20376. t['degree'] = 400;
  20377. t['ograve'] = 500;
  20378. t['Ccaron'] = 667;
  20379. t['ugrave'] = 556;
  20380. t['radical'] = 549;
  20381. t['Dcaron'] = 722;
  20382. t['rcommaaccent'] = 389;
  20383. t['Ntilde'] = 722;
  20384. t['otilde'] = 500;
  20385. t['Rcommaaccent'] = 667;
  20386. t['Lcommaaccent'] = 611;
  20387. t['Atilde'] = 667;
  20388. t['Aogonek'] = 667;
  20389. t['Aring'] = 667;
  20390. t['Otilde'] = 722;
  20391. t['zdotaccent'] = 389;
  20392. t['Ecaron'] = 667;
  20393. t['Iogonek'] = 389;
  20394. t['kcommaaccent'] = 500;
  20395. t['minus'] = 606;
  20396. t['Icircumflex'] = 389;
  20397. t['ncaron'] = 556;
  20398. t['tcommaaccent'] = 278;
  20399. t['logicalnot'] = 606;
  20400. t['odieresis'] = 500;
  20401. t['udieresis'] = 556;
  20402. t['notequal'] = 549;
  20403. t['gcommaaccent'] = 500;
  20404. t['eth'] = 500;
  20405. t['zcaron'] = 389;
  20406. t['ncommaaccent'] = 556;
  20407. t['onesuperior'] = 300;
  20408. t['imacron'] = 278;
  20409. t['Euro'] = 500;
  20410. });
  20411. t['Times-Italic'] = getLookupTableFactory(function (t) {
  20412. t['space'] = 250;
  20413. t['exclam'] = 333;
  20414. t['quotedbl'] = 420;
  20415. t['numbersign'] = 500;
  20416. t['dollar'] = 500;
  20417. t['percent'] = 833;
  20418. t['ampersand'] = 778;
  20419. t['quoteright'] = 333;
  20420. t['parenleft'] = 333;
  20421. t['parenright'] = 333;
  20422. t['asterisk'] = 500;
  20423. t['plus'] = 675;
  20424. t['comma'] = 250;
  20425. t['hyphen'] = 333;
  20426. t['period'] = 250;
  20427. t['slash'] = 278;
  20428. t['zero'] = 500;
  20429. t['one'] = 500;
  20430. t['two'] = 500;
  20431. t['three'] = 500;
  20432. t['four'] = 500;
  20433. t['five'] = 500;
  20434. t['six'] = 500;
  20435. t['seven'] = 500;
  20436. t['eight'] = 500;
  20437. t['nine'] = 500;
  20438. t['colon'] = 333;
  20439. t['semicolon'] = 333;
  20440. t['less'] = 675;
  20441. t['equal'] = 675;
  20442. t['greater'] = 675;
  20443. t['question'] = 500;
  20444. t['at'] = 920;
  20445. t['A'] = 611;
  20446. t['B'] = 611;
  20447. t['C'] = 667;
  20448. t['D'] = 722;
  20449. t['E'] = 611;
  20450. t['F'] = 611;
  20451. t['G'] = 722;
  20452. t['H'] = 722;
  20453. t['I'] = 333;
  20454. t['J'] = 444;
  20455. t['K'] = 667;
  20456. t['L'] = 556;
  20457. t['M'] = 833;
  20458. t['N'] = 667;
  20459. t['O'] = 722;
  20460. t['P'] = 611;
  20461. t['Q'] = 722;
  20462. t['R'] = 611;
  20463. t['S'] = 500;
  20464. t['T'] = 556;
  20465. t['U'] = 722;
  20466. t['V'] = 611;
  20467. t['W'] = 833;
  20468. t['X'] = 611;
  20469. t['Y'] = 556;
  20470. t['Z'] = 556;
  20471. t['bracketleft'] = 389;
  20472. t['backslash'] = 278;
  20473. t['bracketright'] = 389;
  20474. t['asciicircum'] = 422;
  20475. t['underscore'] = 500;
  20476. t['quoteleft'] = 333;
  20477. t['a'] = 500;
  20478. t['b'] = 500;
  20479. t['c'] = 444;
  20480. t['d'] = 500;
  20481. t['e'] = 444;
  20482. t['f'] = 278;
  20483. t['g'] = 500;
  20484. t['h'] = 500;
  20485. t['i'] = 278;
  20486. t['j'] = 278;
  20487. t['k'] = 444;
  20488. t['l'] = 278;
  20489. t['m'] = 722;
  20490. t['n'] = 500;
  20491. t['o'] = 500;
  20492. t['p'] = 500;
  20493. t['q'] = 500;
  20494. t['r'] = 389;
  20495. t['s'] = 389;
  20496. t['t'] = 278;
  20497. t['u'] = 500;
  20498. t['v'] = 444;
  20499. t['w'] = 667;
  20500. t['x'] = 444;
  20501. t['y'] = 444;
  20502. t['z'] = 389;
  20503. t['braceleft'] = 400;
  20504. t['bar'] = 275;
  20505. t['braceright'] = 400;
  20506. t['asciitilde'] = 541;
  20507. t['exclamdown'] = 389;
  20508. t['cent'] = 500;
  20509. t['sterling'] = 500;
  20510. t['fraction'] = 167;
  20511. t['yen'] = 500;
  20512. t['florin'] = 500;
  20513. t['section'] = 500;
  20514. t['currency'] = 500;
  20515. t['quotesingle'] = 214;
  20516. t['quotedblleft'] = 556;
  20517. t['guillemotleft'] = 500;
  20518. t['guilsinglleft'] = 333;
  20519. t['guilsinglright'] = 333;
  20520. t['fi'] = 500;
  20521. t['fl'] = 500;
  20522. t['endash'] = 500;
  20523. t['dagger'] = 500;
  20524. t['daggerdbl'] = 500;
  20525. t['periodcentered'] = 250;
  20526. t['paragraph'] = 523;
  20527. t['bullet'] = 350;
  20528. t['quotesinglbase'] = 333;
  20529. t['quotedblbase'] = 556;
  20530. t['quotedblright'] = 556;
  20531. t['guillemotright'] = 500;
  20532. t['ellipsis'] = 889;
  20533. t['perthousand'] = 1000;
  20534. t['questiondown'] = 500;
  20535. t['grave'] = 333;
  20536. t['acute'] = 333;
  20537. t['circumflex'] = 333;
  20538. t['tilde'] = 333;
  20539. t['macron'] = 333;
  20540. t['breve'] = 333;
  20541. t['dotaccent'] = 333;
  20542. t['dieresis'] = 333;
  20543. t['ring'] = 333;
  20544. t['cedilla'] = 333;
  20545. t['hungarumlaut'] = 333;
  20546. t['ogonek'] = 333;
  20547. t['caron'] = 333;
  20548. t['emdash'] = 889;
  20549. t['AE'] = 889;
  20550. t['ordfeminine'] = 276;
  20551. t['Lslash'] = 556;
  20552. t['Oslash'] = 722;
  20553. t['OE'] = 944;
  20554. t['ordmasculine'] = 310;
  20555. t['ae'] = 667;
  20556. t['dotlessi'] = 278;
  20557. t['lslash'] = 278;
  20558. t['oslash'] = 500;
  20559. t['oe'] = 667;
  20560. t['germandbls'] = 500;
  20561. t['Idieresis'] = 333;
  20562. t['eacute'] = 444;
  20563. t['abreve'] = 500;
  20564. t['uhungarumlaut'] = 500;
  20565. t['ecaron'] = 444;
  20566. t['Ydieresis'] = 556;
  20567. t['divide'] = 675;
  20568. t['Yacute'] = 556;
  20569. t['Acircumflex'] = 611;
  20570. t['aacute'] = 500;
  20571. t['Ucircumflex'] = 722;
  20572. t['yacute'] = 444;
  20573. t['scommaaccent'] = 389;
  20574. t['ecircumflex'] = 444;
  20575. t['Uring'] = 722;
  20576. t['Udieresis'] = 722;
  20577. t['aogonek'] = 500;
  20578. t['Uacute'] = 722;
  20579. t['uogonek'] = 500;
  20580. t['Edieresis'] = 611;
  20581. t['Dcroat'] = 722;
  20582. t['commaaccent'] = 250;
  20583. t['copyright'] = 760;
  20584. t['Emacron'] = 611;
  20585. t['ccaron'] = 444;
  20586. t['aring'] = 500;
  20587. t['Ncommaaccent'] = 667;
  20588. t['lacute'] = 278;
  20589. t['agrave'] = 500;
  20590. t['Tcommaaccent'] = 556;
  20591. t['Cacute'] = 667;
  20592. t['atilde'] = 500;
  20593. t['Edotaccent'] = 611;
  20594. t['scaron'] = 389;
  20595. t['scedilla'] = 389;
  20596. t['iacute'] = 278;
  20597. t['lozenge'] = 471;
  20598. t['Rcaron'] = 611;
  20599. t['Gcommaaccent'] = 722;
  20600. t['ucircumflex'] = 500;
  20601. t['acircumflex'] = 500;
  20602. t['Amacron'] = 611;
  20603. t['rcaron'] = 389;
  20604. t['ccedilla'] = 444;
  20605. t['Zdotaccent'] = 556;
  20606. t['Thorn'] = 611;
  20607. t['Omacron'] = 722;
  20608. t['Racute'] = 611;
  20609. t['Sacute'] = 500;
  20610. t['dcaron'] = 544;
  20611. t['Umacron'] = 722;
  20612. t['uring'] = 500;
  20613. t['threesuperior'] = 300;
  20614. t['Ograve'] = 722;
  20615. t['Agrave'] = 611;
  20616. t['Abreve'] = 611;
  20617. t['multiply'] = 675;
  20618. t['uacute'] = 500;
  20619. t['Tcaron'] = 556;
  20620. t['partialdiff'] = 476;
  20621. t['ydieresis'] = 444;
  20622. t['Nacute'] = 667;
  20623. t['icircumflex'] = 278;
  20624. t['Ecircumflex'] = 611;
  20625. t['adieresis'] = 500;
  20626. t['edieresis'] = 444;
  20627. t['cacute'] = 444;
  20628. t['nacute'] = 500;
  20629. t['umacron'] = 500;
  20630. t['Ncaron'] = 667;
  20631. t['Iacute'] = 333;
  20632. t['plusminus'] = 675;
  20633. t['brokenbar'] = 275;
  20634. t['registered'] = 760;
  20635. t['Gbreve'] = 722;
  20636. t['Idotaccent'] = 333;
  20637. t['summation'] = 600;
  20638. t['Egrave'] = 611;
  20639. t['racute'] = 389;
  20640. t['omacron'] = 500;
  20641. t['Zacute'] = 556;
  20642. t['Zcaron'] = 556;
  20643. t['greaterequal'] = 549;
  20644. t['Eth'] = 722;
  20645. t['Ccedilla'] = 667;
  20646. t['lcommaaccent'] = 278;
  20647. t['tcaron'] = 300;
  20648. t['eogonek'] = 444;
  20649. t['Uogonek'] = 722;
  20650. t['Aacute'] = 611;
  20651. t['Adieresis'] = 611;
  20652. t['egrave'] = 444;
  20653. t['zacute'] = 389;
  20654. t['iogonek'] = 278;
  20655. t['Oacute'] = 722;
  20656. t['oacute'] = 500;
  20657. t['amacron'] = 500;
  20658. t['sacute'] = 389;
  20659. t['idieresis'] = 278;
  20660. t['Ocircumflex'] = 722;
  20661. t['Ugrave'] = 722;
  20662. t['Delta'] = 612;
  20663. t['thorn'] = 500;
  20664. t['twosuperior'] = 300;
  20665. t['Odieresis'] = 722;
  20666. t['mu'] = 500;
  20667. t['igrave'] = 278;
  20668. t['ohungarumlaut'] = 500;
  20669. t['Eogonek'] = 611;
  20670. t['dcroat'] = 500;
  20671. t['threequarters'] = 750;
  20672. t['Scedilla'] = 500;
  20673. t['lcaron'] = 300;
  20674. t['Kcommaaccent'] = 667;
  20675. t['Lacute'] = 556;
  20676. t['trademark'] = 980;
  20677. t['edotaccent'] = 444;
  20678. t['Igrave'] = 333;
  20679. t['Imacron'] = 333;
  20680. t['Lcaron'] = 611;
  20681. t['onehalf'] = 750;
  20682. t['lessequal'] = 549;
  20683. t['ocircumflex'] = 500;
  20684. t['ntilde'] = 500;
  20685. t['Uhungarumlaut'] = 722;
  20686. t['Eacute'] = 611;
  20687. t['emacron'] = 444;
  20688. t['gbreve'] = 500;
  20689. t['onequarter'] = 750;
  20690. t['Scaron'] = 500;
  20691. t['Scommaaccent'] = 500;
  20692. t['Ohungarumlaut'] = 722;
  20693. t['degree'] = 400;
  20694. t['ograve'] = 500;
  20695. t['Ccaron'] = 667;
  20696. t['ugrave'] = 500;
  20697. t['radical'] = 453;
  20698. t['Dcaron'] = 722;
  20699. t['rcommaaccent'] = 389;
  20700. t['Ntilde'] = 667;
  20701. t['otilde'] = 500;
  20702. t['Rcommaaccent'] = 611;
  20703. t['Lcommaaccent'] = 556;
  20704. t['Atilde'] = 611;
  20705. t['Aogonek'] = 611;
  20706. t['Aring'] = 611;
  20707. t['Otilde'] = 722;
  20708. t['zdotaccent'] = 389;
  20709. t['Ecaron'] = 611;
  20710. t['Iogonek'] = 333;
  20711. t['kcommaaccent'] = 444;
  20712. t['minus'] = 675;
  20713. t['Icircumflex'] = 333;
  20714. t['ncaron'] = 500;
  20715. t['tcommaaccent'] = 278;
  20716. t['logicalnot'] = 675;
  20717. t['odieresis'] = 500;
  20718. t['udieresis'] = 500;
  20719. t['notequal'] = 549;
  20720. t['gcommaaccent'] = 500;
  20721. t['eth'] = 500;
  20722. t['zcaron'] = 389;
  20723. t['ncommaaccent'] = 500;
  20724. t['onesuperior'] = 300;
  20725. t['imacron'] = 278;
  20726. t['Euro'] = 500;
  20727. });
  20728. t['ZapfDingbats'] = getLookupTableFactory(function (t) {
  20729. t['space'] = 278;
  20730. t['a1'] = 974;
  20731. t['a2'] = 961;
  20732. t['a202'] = 974;
  20733. t['a3'] = 980;
  20734. t['a4'] = 719;
  20735. t['a5'] = 789;
  20736. t['a119'] = 790;
  20737. t['a118'] = 791;
  20738. t['a117'] = 690;
  20739. t['a11'] = 960;
  20740. t['a12'] = 939;
  20741. t['a13'] = 549;
  20742. t['a14'] = 855;
  20743. t['a15'] = 911;
  20744. t['a16'] = 933;
  20745. t['a105'] = 911;
  20746. t['a17'] = 945;
  20747. t['a18'] = 974;
  20748. t['a19'] = 755;
  20749. t['a20'] = 846;
  20750. t['a21'] = 762;
  20751. t['a22'] = 761;
  20752. t['a23'] = 571;
  20753. t['a24'] = 677;
  20754. t['a25'] = 763;
  20755. t['a26'] = 760;
  20756. t['a27'] = 759;
  20757. t['a28'] = 754;
  20758. t['a6'] = 494;
  20759. t['a7'] = 552;
  20760. t['a8'] = 537;
  20761. t['a9'] = 577;
  20762. t['a10'] = 692;
  20763. t['a29'] = 786;
  20764. t['a30'] = 788;
  20765. t['a31'] = 788;
  20766. t['a32'] = 790;
  20767. t['a33'] = 793;
  20768. t['a34'] = 794;
  20769. t['a35'] = 816;
  20770. t['a36'] = 823;
  20771. t['a37'] = 789;
  20772. t['a38'] = 841;
  20773. t['a39'] = 823;
  20774. t['a40'] = 833;
  20775. t['a41'] = 816;
  20776. t['a42'] = 831;
  20777. t['a43'] = 923;
  20778. t['a44'] = 744;
  20779. t['a45'] = 723;
  20780. t['a46'] = 749;
  20781. t['a47'] = 790;
  20782. t['a48'] = 792;
  20783. t['a49'] = 695;
  20784. t['a50'] = 776;
  20785. t['a51'] = 768;
  20786. t['a52'] = 792;
  20787. t['a53'] = 759;
  20788. t['a54'] = 707;
  20789. t['a55'] = 708;
  20790. t['a56'] = 682;
  20791. t['a57'] = 701;
  20792. t['a58'] = 826;
  20793. t['a59'] = 815;
  20794. t['a60'] = 789;
  20795. t['a61'] = 789;
  20796. t['a62'] = 707;
  20797. t['a63'] = 687;
  20798. t['a64'] = 696;
  20799. t['a65'] = 689;
  20800. t['a66'] = 786;
  20801. t['a67'] = 787;
  20802. t['a68'] = 713;
  20803. t['a69'] = 791;
  20804. t['a70'] = 785;
  20805. t['a71'] = 791;
  20806. t['a72'] = 873;
  20807. t['a73'] = 761;
  20808. t['a74'] = 762;
  20809. t['a203'] = 762;
  20810. t['a75'] = 759;
  20811. t['a204'] = 759;
  20812. t['a76'] = 892;
  20813. t['a77'] = 892;
  20814. t['a78'] = 788;
  20815. t['a79'] = 784;
  20816. t['a81'] = 438;
  20817. t['a82'] = 138;
  20818. t['a83'] = 277;
  20819. t['a84'] = 415;
  20820. t['a97'] = 392;
  20821. t['a98'] = 392;
  20822. t['a99'] = 668;
  20823. t['a100'] = 668;
  20824. t['a89'] = 390;
  20825. t['a90'] = 390;
  20826. t['a93'] = 317;
  20827. t['a94'] = 317;
  20828. t['a91'] = 276;
  20829. t['a92'] = 276;
  20830. t['a205'] = 509;
  20831. t['a85'] = 509;
  20832. t['a206'] = 410;
  20833. t['a86'] = 410;
  20834. t['a87'] = 234;
  20835. t['a88'] = 234;
  20836. t['a95'] = 334;
  20837. t['a96'] = 334;
  20838. t['a101'] = 732;
  20839. t['a102'] = 544;
  20840. t['a103'] = 544;
  20841. t['a104'] = 910;
  20842. t['a106'] = 667;
  20843. t['a107'] = 760;
  20844. t['a108'] = 760;
  20845. t['a112'] = 776;
  20846. t['a111'] = 595;
  20847. t['a110'] = 694;
  20848. t['a109'] = 626;
  20849. t['a120'] = 788;
  20850. t['a121'] = 788;
  20851. t['a122'] = 788;
  20852. t['a123'] = 788;
  20853. t['a124'] = 788;
  20854. t['a125'] = 788;
  20855. t['a126'] = 788;
  20856. t['a127'] = 788;
  20857. t['a128'] = 788;
  20858. t['a129'] = 788;
  20859. t['a130'] = 788;
  20860. t['a131'] = 788;
  20861. t['a132'] = 788;
  20862. t['a133'] = 788;
  20863. t['a134'] = 788;
  20864. t['a135'] = 788;
  20865. t['a136'] = 788;
  20866. t['a137'] = 788;
  20867. t['a138'] = 788;
  20868. t['a139'] = 788;
  20869. t['a140'] = 788;
  20870. t['a141'] = 788;
  20871. t['a142'] = 788;
  20872. t['a143'] = 788;
  20873. t['a144'] = 788;
  20874. t['a145'] = 788;
  20875. t['a146'] = 788;
  20876. t['a147'] = 788;
  20877. t['a148'] = 788;
  20878. t['a149'] = 788;
  20879. t['a150'] = 788;
  20880. t['a151'] = 788;
  20881. t['a152'] = 788;
  20882. t['a153'] = 788;
  20883. t['a154'] = 788;
  20884. t['a155'] = 788;
  20885. t['a156'] = 788;
  20886. t['a157'] = 788;
  20887. t['a158'] = 788;
  20888. t['a159'] = 788;
  20889. t['a160'] = 894;
  20890. t['a161'] = 838;
  20891. t['a163'] = 1016;
  20892. t['a164'] = 458;
  20893. t['a196'] = 748;
  20894. t['a165'] = 924;
  20895. t['a192'] = 748;
  20896. t['a166'] = 918;
  20897. t['a167'] = 927;
  20898. t['a168'] = 928;
  20899. t['a169'] = 928;
  20900. t['a170'] = 834;
  20901. t['a171'] = 873;
  20902. t['a172'] = 828;
  20903. t['a173'] = 924;
  20904. t['a162'] = 924;
  20905. t['a174'] = 917;
  20906. t['a175'] = 930;
  20907. t['a176'] = 931;
  20908. t['a177'] = 463;
  20909. t['a178'] = 883;
  20910. t['a179'] = 836;
  20911. t['a193'] = 836;
  20912. t['a180'] = 867;
  20913. t['a199'] = 867;
  20914. t['a181'] = 696;
  20915. t['a200'] = 696;
  20916. t['a182'] = 874;
  20917. t['a201'] = 874;
  20918. t['a183'] = 760;
  20919. t['a184'] = 946;
  20920. t['a197'] = 771;
  20921. t['a185'] = 865;
  20922. t['a194'] = 771;
  20923. t['a198'] = 888;
  20924. t['a186'] = 967;
  20925. t['a195'] = 888;
  20926. t['a187'] = 831;
  20927. t['a188'] = 873;
  20928. t['a189'] = 927;
  20929. t['a190'] = 970;
  20930. t['a191'] = 918;
  20931. });
  20932. });
  20933. exports.getMetrics = getMetrics;
  20934. }));
  20935. (function (root, factory) {
  20936. factory(root.pdfjsCoreMurmurHash3 = {}, root.pdfjsSharedUtil);
  20937. }(this, function (exports, sharedUtil) {
  20938. var Uint32ArrayView = sharedUtil.Uint32ArrayView;
  20939. var MurmurHash3_64 = function MurmurHash3_64Closure(seed) {
  20940. // Workaround for missing math precision in JS.
  20941. var MASK_HIGH = 0xffff0000;
  20942. var MASK_LOW = 0xffff;
  20943. function MurmurHash3_64(seed) {
  20944. var SEED = 0xc3d2e1f0;
  20945. this.h1 = seed ? seed & 0xffffffff : SEED;
  20946. this.h2 = seed ? seed & 0xffffffff : SEED;
  20947. }
  20948. var alwaysUseUint32ArrayView = false;
  20949. // old webkits have issues with non-aligned arrays
  20950. try {
  20951. new Uint32Array(new Uint8Array(5).buffer, 0, 1);
  20952. } catch (e) {
  20953. alwaysUseUint32ArrayView = true;
  20954. }
  20955. MurmurHash3_64.prototype = {
  20956. update: function MurmurHash3_64_update(input) {
  20957. var useUint32ArrayView = alwaysUseUint32ArrayView;
  20958. var i;
  20959. if (typeof input === 'string') {
  20960. var data = new Uint8Array(input.length * 2);
  20961. var length = 0;
  20962. for (i = 0; i < input.length; i++) {
  20963. var code = input.charCodeAt(i);
  20964. if (code <= 0xff) {
  20965. data[length++] = code;
  20966. } else {
  20967. data[length++] = code >>> 8;
  20968. data[length++] = code & 0xff;
  20969. }
  20970. }
  20971. } else if (input instanceof Uint8Array) {
  20972. data = input;
  20973. length = data.length;
  20974. } else if (typeof input === 'object' && 'length' in input) {
  20975. // processing regular arrays as well, e.g. for IE9
  20976. data = input;
  20977. length = data.length;
  20978. useUint32ArrayView = true;
  20979. } else {
  20980. throw new Error('Wrong data format in MurmurHash3_64_update. ' + 'Input must be a string or array.');
  20981. }
  20982. var blockCounts = length >> 2;
  20983. var tailLength = length - blockCounts * 4;
  20984. // we don't care about endianness here
  20985. var dataUint32 = useUint32ArrayView ? new Uint32ArrayView(data, blockCounts) : new Uint32Array(data.buffer, 0, blockCounts);
  20986. var k1 = 0;
  20987. var k2 = 0;
  20988. var h1 = this.h1;
  20989. var h2 = this.h2;
  20990. var C1 = 0xcc9e2d51;
  20991. var C2 = 0x1b873593;
  20992. var C1_LOW = C1 & MASK_LOW;
  20993. var C2_LOW = C2 & MASK_LOW;
  20994. for (i = 0; i < blockCounts; i++) {
  20995. if (i & 1) {
  20996. k1 = dataUint32[i];
  20997. k1 = k1 * C1 & MASK_HIGH | k1 * C1_LOW & MASK_LOW;
  20998. k1 = k1 << 15 | k1 >>> 17;
  20999. k1 = k1 * C2 & MASK_HIGH | k1 * C2_LOW & MASK_LOW;
  21000. h1 ^= k1;
  21001. h1 = h1 << 13 | h1 >>> 19;
  21002. h1 = h1 * 5 + 0xe6546b64;
  21003. } else {
  21004. k2 = dataUint32[i];
  21005. k2 = k2 * C1 & MASK_HIGH | k2 * C1_LOW & MASK_LOW;
  21006. k2 = k2 << 15 | k2 >>> 17;
  21007. k2 = k2 * C2 & MASK_HIGH | k2 * C2_LOW & MASK_LOW;
  21008. h2 ^= k2;
  21009. h2 = h2 << 13 | h2 >>> 19;
  21010. h2 = h2 * 5 + 0xe6546b64;
  21011. }
  21012. }
  21013. k1 = 0;
  21014. switch (tailLength) {
  21015. case 3:
  21016. k1 ^= data[blockCounts * 4 + 2] << 16;
  21017. case 2:
  21018. k1 ^= data[blockCounts * 4 + 1] << 8;
  21019. case 1:
  21020. k1 ^= data[blockCounts * 4];
  21021. k1 = k1 * C1 & MASK_HIGH | k1 * C1_LOW & MASK_LOW;
  21022. k1 = k1 << 15 | k1 >>> 17;
  21023. k1 = k1 * C2 & MASK_HIGH | k1 * C2_LOW & MASK_LOW;
  21024. if (blockCounts & 1) {
  21025. h1 ^= k1;
  21026. } else {
  21027. h2 ^= k1;
  21028. }
  21029. }
  21030. this.h1 = h1;
  21031. this.h2 = h2;
  21032. return this;
  21033. },
  21034. hexdigest: function MurmurHash3_64_hexdigest() {
  21035. var h1 = this.h1;
  21036. var h2 = this.h2;
  21037. h1 ^= h2 >>> 1;
  21038. h1 = h1 * 0xed558ccd & MASK_HIGH | h1 * 0x8ccd & MASK_LOW;
  21039. h2 = h2 * 0xff51afd7 & MASK_HIGH | ((h2 << 16 | h1 >>> 16) * 0xafd7ed55 & MASK_HIGH) >>> 16;
  21040. h1 ^= h2 >>> 1;
  21041. h1 = h1 * 0x1a85ec53 & MASK_HIGH | h1 * 0xec53 & MASK_LOW;
  21042. h2 = h2 * 0xc4ceb9fe & MASK_HIGH | ((h2 << 16 | h1 >>> 16) * 0xb9fe1a85 & MASK_HIGH) >>> 16;
  21043. h1 ^= h2 >>> 1;
  21044. for (var i = 0, arr = [
  21045. h1,
  21046. h2
  21047. ], str = ''; i < arr.length; i++) {
  21048. var hex = (arr[i] >>> 0).toString(16);
  21049. while (hex.length < 8) {
  21050. hex = '0' + hex;
  21051. }
  21052. str += hex;
  21053. }
  21054. return str;
  21055. }
  21056. };
  21057. return MurmurHash3_64;
  21058. }();
  21059. exports.MurmurHash3_64 = MurmurHash3_64;
  21060. }));
  21061. (function (root, factory) {
  21062. factory(root.pdfjsCorePrimitives = {}, root.pdfjsSharedUtil);
  21063. }(this, function (exports, sharedUtil) {
  21064. var isArray = sharedUtil.isArray;
  21065. var Name = function NameClosure() {
  21066. function Name(name) {
  21067. this.name = name;
  21068. }
  21069. Name.prototype = {};
  21070. var nameCache = Object.create(null);
  21071. Name.get = function Name_get(name) {
  21072. var nameValue = nameCache[name];
  21073. return nameValue ? nameValue : nameCache[name] = new Name(name);
  21074. };
  21075. return Name;
  21076. }();
  21077. var Cmd = function CmdClosure() {
  21078. function Cmd(cmd) {
  21079. this.cmd = cmd;
  21080. }
  21081. Cmd.prototype = {};
  21082. var cmdCache = Object.create(null);
  21083. Cmd.get = function Cmd_get(cmd) {
  21084. var cmdValue = cmdCache[cmd];
  21085. return cmdValue ? cmdValue : cmdCache[cmd] = new Cmd(cmd);
  21086. };
  21087. return Cmd;
  21088. }();
  21089. var Dict = function DictClosure() {
  21090. var nonSerializable = function nonSerializableClosure() {
  21091. return nonSerializable;
  21092. };
  21093. // creating closure on some variable
  21094. // xref is optional
  21095. function Dict(xref) {
  21096. // Map should only be used internally, use functions below to access.
  21097. this.map = Object.create(null);
  21098. this.xref = xref;
  21099. this.objId = null;
  21100. this.suppressEncryption = false;
  21101. this.__nonSerializable__ = nonSerializable;
  21102. }
  21103. // disable cloning of the Dict
  21104. Dict.prototype = {
  21105. assignXref: function Dict_assignXref(newXref) {
  21106. this.xref = newXref;
  21107. },
  21108. // automatically dereferences Ref objects
  21109. get: function Dict_get(key1, key2, key3) {
  21110. var value;
  21111. var xref = this.xref, suppressEncryption = this.suppressEncryption;
  21112. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map || typeof key2 === 'undefined') {
  21113. return xref ? xref.fetchIfRef(value, suppressEncryption) : value;
  21114. }
  21115. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map || typeof key3 === 'undefined') {
  21116. return xref ? xref.fetchIfRef(value, suppressEncryption) : value;
  21117. }
  21118. value = this.map[key3] || null;
  21119. return xref ? xref.fetchIfRef(value, suppressEncryption) : value;
  21120. },
  21121. // Same as get(), but returns a promise and uses fetchIfRefAsync().
  21122. getAsync: function Dict_getAsync(key1, key2, key3) {
  21123. var value;
  21124. var xref = this.xref, suppressEncryption = this.suppressEncryption;
  21125. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map || typeof key2 === 'undefined') {
  21126. if (xref) {
  21127. return xref.fetchIfRefAsync(value, suppressEncryption);
  21128. }
  21129. return Promise.resolve(value);
  21130. }
  21131. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map || typeof key3 === 'undefined') {
  21132. if (xref) {
  21133. return xref.fetchIfRefAsync(value, suppressEncryption);
  21134. }
  21135. return Promise.resolve(value);
  21136. }
  21137. value = this.map[key3] || null;
  21138. if (xref) {
  21139. return xref.fetchIfRefAsync(value, suppressEncryption);
  21140. }
  21141. return Promise.resolve(value);
  21142. },
  21143. // Same as get(), but dereferences all elements if the result is an Array.
  21144. getArray: function Dict_getArray(key1, key2, key3) {
  21145. var value = this.get(key1, key2, key3);
  21146. var xref = this.xref, suppressEncryption = this.suppressEncryption;
  21147. if (!isArray(value) || !xref) {
  21148. return value;
  21149. }
  21150. value = value.slice();
  21151. // Ensure that we don't modify the Dict data.
  21152. for (var i = 0, ii = value.length; i < ii; i++) {
  21153. if (!isRef(value[i])) {
  21154. continue;
  21155. }
  21156. value[i] = xref.fetch(value[i], suppressEncryption);
  21157. }
  21158. return value;
  21159. },
  21160. // no dereferencing
  21161. getRaw: function Dict_getRaw(key) {
  21162. return this.map[key];
  21163. },
  21164. getKeys: function Dict_getKeys() {
  21165. return Object.keys(this.map);
  21166. },
  21167. set: function Dict_set(key, value) {
  21168. this.map[key] = value;
  21169. },
  21170. has: function Dict_has(key) {
  21171. return key in this.map;
  21172. },
  21173. forEach: function Dict_forEach(callback) {
  21174. for (var key in this.map) {
  21175. callback(key, this.get(key));
  21176. }
  21177. }
  21178. };
  21179. Dict.empty = new Dict(null);
  21180. Dict.merge = function Dict_merge(xref, dictArray) {
  21181. var mergedDict = new Dict(xref);
  21182. for (var i = 0, ii = dictArray.length; i < ii; i++) {
  21183. var dict = dictArray[i];
  21184. if (!isDict(dict)) {
  21185. continue;
  21186. }
  21187. for (var keyName in dict.map) {
  21188. if (mergedDict.map[keyName]) {
  21189. continue;
  21190. }
  21191. mergedDict.map[keyName] = dict.map[keyName];
  21192. }
  21193. }
  21194. return mergedDict;
  21195. };
  21196. return Dict;
  21197. }();
  21198. var Ref = function RefClosure() {
  21199. function Ref(num, gen) {
  21200. this.num = num;
  21201. this.gen = gen;
  21202. }
  21203. Ref.prototype = {
  21204. toString: function Ref_toString() {
  21205. // This function is hot, so we make the string as compact as possible.
  21206. // |this.gen| is almost always zero, so we treat that case specially.
  21207. var str = this.num + 'R';
  21208. if (this.gen !== 0) {
  21209. str += this.gen;
  21210. }
  21211. return str;
  21212. }
  21213. };
  21214. return Ref;
  21215. }();
  21216. // The reference is identified by number and generation.
  21217. // This structure stores only one instance of the reference.
  21218. var RefSet = function RefSetClosure() {
  21219. function RefSet() {
  21220. this.dict = Object.create(null);
  21221. }
  21222. RefSet.prototype = {
  21223. has: function RefSet_has(ref) {
  21224. return ref.toString() in this.dict;
  21225. },
  21226. put: function RefSet_put(ref) {
  21227. this.dict[ref.toString()] = true;
  21228. },
  21229. remove: function RefSet_remove(ref) {
  21230. delete this.dict[ref.toString()];
  21231. }
  21232. };
  21233. return RefSet;
  21234. }();
  21235. var RefSetCache = function RefSetCacheClosure() {
  21236. function RefSetCache() {
  21237. this.dict = Object.create(null);
  21238. }
  21239. RefSetCache.prototype = {
  21240. get: function RefSetCache_get(ref) {
  21241. return this.dict[ref.toString()];
  21242. },
  21243. has: function RefSetCache_has(ref) {
  21244. return ref.toString() in this.dict;
  21245. },
  21246. put: function RefSetCache_put(ref, obj) {
  21247. this.dict[ref.toString()] = obj;
  21248. },
  21249. putAlias: function RefSetCache_putAlias(ref, aliasRef) {
  21250. this.dict[ref.toString()] = this.get(aliasRef);
  21251. },
  21252. forEach: function RefSetCache_forEach(fn, thisArg) {
  21253. for (var i in this.dict) {
  21254. fn.call(thisArg, this.dict[i]);
  21255. }
  21256. },
  21257. clear: function RefSetCache_clear() {
  21258. this.dict = Object.create(null);
  21259. }
  21260. };
  21261. return RefSetCache;
  21262. }();
  21263. function isName(v, name) {
  21264. return v instanceof Name && (name === undefined || v.name === name);
  21265. }
  21266. function isCmd(v, cmd) {
  21267. return v instanceof Cmd && (cmd === undefined || v.cmd === cmd);
  21268. }
  21269. function isDict(v, type) {
  21270. return v instanceof Dict && (type === undefined || isName(v.get('Type'), type));
  21271. }
  21272. function isRef(v) {
  21273. return v instanceof Ref;
  21274. }
  21275. function isRefsEqual(v1, v2) {
  21276. return v1.num === v2.num && v1.gen === v2.gen;
  21277. }
  21278. function isStream(v) {
  21279. return typeof v === 'object' && v !== null && v.getBytes !== undefined;
  21280. }
  21281. exports.Cmd = Cmd;
  21282. exports.Dict = Dict;
  21283. exports.Name = Name;
  21284. exports.Ref = Ref;
  21285. exports.RefSet = RefSet;
  21286. exports.RefSetCache = RefSetCache;
  21287. exports.isCmd = isCmd;
  21288. exports.isDict = isDict;
  21289. exports.isName = isName;
  21290. exports.isRef = isRef;
  21291. exports.isRefsEqual = isRefsEqual;
  21292. exports.isStream = isStream;
  21293. }));
  21294. (function (root, factory) {
  21295. factory(root.pdfjsCoreStandardFonts = {}, root.pdfjsSharedUtil);
  21296. }(this, function (exports, sharedUtil) {
  21297. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  21298. /**
  21299. * Hold a map of decoded fonts and of the standard fourteen Type1
  21300. * fonts and their acronyms.
  21301. */
  21302. var getStdFontMap = getLookupTableFactory(function (t) {
  21303. t['ArialNarrow'] = 'Helvetica';
  21304. t['ArialNarrow-Bold'] = 'Helvetica-Bold';
  21305. t['ArialNarrow-BoldItalic'] = 'Helvetica-BoldOblique';
  21306. t['ArialNarrow-Italic'] = 'Helvetica-Oblique';
  21307. t['ArialBlack'] = 'Helvetica';
  21308. t['ArialBlack-Bold'] = 'Helvetica-Bold';
  21309. t['ArialBlack-BoldItalic'] = 'Helvetica-BoldOblique';
  21310. t['ArialBlack-Italic'] = 'Helvetica-Oblique';
  21311. t['Arial'] = 'Helvetica';
  21312. t['Arial-Bold'] = 'Helvetica-Bold';
  21313. t['Arial-BoldItalic'] = 'Helvetica-BoldOblique';
  21314. t['Arial-Italic'] = 'Helvetica-Oblique';
  21315. t['Arial-BoldItalicMT'] = 'Helvetica-BoldOblique';
  21316. t['Arial-BoldMT'] = 'Helvetica-Bold';
  21317. t['Arial-ItalicMT'] = 'Helvetica-Oblique';
  21318. t['ArialMT'] = 'Helvetica';
  21319. t['Courier-Bold'] = 'Courier-Bold';
  21320. t['Courier-BoldItalic'] = 'Courier-BoldOblique';
  21321. t['Courier-Italic'] = 'Courier-Oblique';
  21322. t['CourierNew'] = 'Courier';
  21323. t['CourierNew-Bold'] = 'Courier-Bold';
  21324. t['CourierNew-BoldItalic'] = 'Courier-BoldOblique';
  21325. t['CourierNew-Italic'] = 'Courier-Oblique';
  21326. t['CourierNewPS-BoldItalicMT'] = 'Courier-BoldOblique';
  21327. t['CourierNewPS-BoldMT'] = 'Courier-Bold';
  21328. t['CourierNewPS-ItalicMT'] = 'Courier-Oblique';
  21329. t['CourierNewPSMT'] = 'Courier';
  21330. t['Helvetica'] = 'Helvetica';
  21331. t['Helvetica-Bold'] = 'Helvetica-Bold';
  21332. t['Helvetica-BoldItalic'] = 'Helvetica-BoldOblique';
  21333. t['Helvetica-BoldOblique'] = 'Helvetica-BoldOblique';
  21334. t['Helvetica-Italic'] = 'Helvetica-Oblique';
  21335. t['Helvetica-Oblique'] = 'Helvetica-Oblique';
  21336. t['Symbol-Bold'] = 'Symbol';
  21337. t['Symbol-BoldItalic'] = 'Symbol';
  21338. t['Symbol-Italic'] = 'Symbol';
  21339. t['TimesNewRoman'] = 'Times-Roman';
  21340. t['TimesNewRoman-Bold'] = 'Times-Bold';
  21341. t['TimesNewRoman-BoldItalic'] = 'Times-BoldItalic';
  21342. t['TimesNewRoman-Italic'] = 'Times-Italic';
  21343. t['TimesNewRomanPS'] = 'Times-Roman';
  21344. t['TimesNewRomanPS-Bold'] = 'Times-Bold';
  21345. t['TimesNewRomanPS-BoldItalic'] = 'Times-BoldItalic';
  21346. t['TimesNewRomanPS-BoldItalicMT'] = 'Times-BoldItalic';
  21347. t['TimesNewRomanPS-BoldMT'] = 'Times-Bold';
  21348. t['TimesNewRomanPS-Italic'] = 'Times-Italic';
  21349. t['TimesNewRomanPS-ItalicMT'] = 'Times-Italic';
  21350. t['TimesNewRomanPSMT'] = 'Times-Roman';
  21351. t['TimesNewRomanPSMT-Bold'] = 'Times-Bold';
  21352. t['TimesNewRomanPSMT-BoldItalic'] = 'Times-BoldItalic';
  21353. t['TimesNewRomanPSMT-Italic'] = 'Times-Italic';
  21354. });
  21355. /**
  21356. * Holds the map of the non-standard fonts that might be included as
  21357. * a standard fonts without glyph data.
  21358. */
  21359. var getNonStdFontMap = getLookupTableFactory(function (t) {
  21360. t['CenturyGothic'] = 'Helvetica';
  21361. t['CenturyGothic-Bold'] = 'Helvetica-Bold';
  21362. t['CenturyGothic-BoldItalic'] = 'Helvetica-BoldOblique';
  21363. t['CenturyGothic-Italic'] = 'Helvetica-Oblique';
  21364. t['ComicSansMS'] = 'Comic Sans MS';
  21365. t['ComicSansMS-Bold'] = 'Comic Sans MS-Bold';
  21366. t['ComicSansMS-BoldItalic'] = 'Comic Sans MS-BoldItalic';
  21367. t['ComicSansMS-Italic'] = 'Comic Sans MS-Italic';
  21368. t['LucidaConsole'] = 'Courier';
  21369. t['LucidaConsole-Bold'] = 'Courier-Bold';
  21370. t['LucidaConsole-BoldItalic'] = 'Courier-BoldOblique';
  21371. t['LucidaConsole-Italic'] = 'Courier-Oblique';
  21372. t['MS-Gothic'] = 'MS Gothic';
  21373. t['MS-Gothic-Bold'] = 'MS Gothic-Bold';
  21374. t['MS-Gothic-BoldItalic'] = 'MS Gothic-BoldItalic';
  21375. t['MS-Gothic-Italic'] = 'MS Gothic-Italic';
  21376. t['MS-Mincho'] = 'MS Mincho';
  21377. t['MS-Mincho-Bold'] = 'MS Mincho-Bold';
  21378. t['MS-Mincho-BoldItalic'] = 'MS Mincho-BoldItalic';
  21379. t['MS-Mincho-Italic'] = 'MS Mincho-Italic';
  21380. t['MS-PGothic'] = 'MS PGothic';
  21381. t['MS-PGothic-Bold'] = 'MS PGothic-Bold';
  21382. t['MS-PGothic-BoldItalic'] = 'MS PGothic-BoldItalic';
  21383. t['MS-PGothic-Italic'] = 'MS PGothic-Italic';
  21384. t['MS-PMincho'] = 'MS PMincho';
  21385. t['MS-PMincho-Bold'] = 'MS PMincho-Bold';
  21386. t['MS-PMincho-BoldItalic'] = 'MS PMincho-BoldItalic';
  21387. t['MS-PMincho-Italic'] = 'MS PMincho-Italic';
  21388. t['Wingdings'] = 'ZapfDingbats';
  21389. });
  21390. var getSerifFonts = getLookupTableFactory(function (t) {
  21391. t['Adobe Jenson'] = true;
  21392. t['Adobe Text'] = true;
  21393. t['Albertus'] = true;
  21394. t['Aldus'] = true;
  21395. t['Alexandria'] = true;
  21396. t['Algerian'] = true;
  21397. t['American Typewriter'] = true;
  21398. t['Antiqua'] = true;
  21399. t['Apex'] = true;
  21400. t['Arno'] = true;
  21401. t['Aster'] = true;
  21402. t['Aurora'] = true;
  21403. t['Baskerville'] = true;
  21404. t['Bell'] = true;
  21405. t['Bembo'] = true;
  21406. t['Bembo Schoolbook'] = true;
  21407. t['Benguiat'] = true;
  21408. t['Berkeley Old Style'] = true;
  21409. t['Bernhard Modern'] = true;
  21410. t['Berthold City'] = true;
  21411. t['Bodoni'] = true;
  21412. t['Bauer Bodoni'] = true;
  21413. t['Book Antiqua'] = true;
  21414. t['Bookman'] = true;
  21415. t['Bordeaux Roman'] = true;
  21416. t['Californian FB'] = true;
  21417. t['Calisto'] = true;
  21418. t['Calvert'] = true;
  21419. t['Capitals'] = true;
  21420. t['Cambria'] = true;
  21421. t['Cartier'] = true;
  21422. t['Caslon'] = true;
  21423. t['Catull'] = true;
  21424. t['Centaur'] = true;
  21425. t['Century Old Style'] = true;
  21426. t['Century Schoolbook'] = true;
  21427. t['Chaparral'] = true;
  21428. t['Charis SIL'] = true;
  21429. t['Cheltenham'] = true;
  21430. t['Cholla Slab'] = true;
  21431. t['Clarendon'] = true;
  21432. t['Clearface'] = true;
  21433. t['Cochin'] = true;
  21434. t['Colonna'] = true;
  21435. t['Computer Modern'] = true;
  21436. t['Concrete Roman'] = true;
  21437. t['Constantia'] = true;
  21438. t['Cooper Black'] = true;
  21439. t['Corona'] = true;
  21440. t['Ecotype'] = true;
  21441. t['Egyptienne'] = true;
  21442. t['Elephant'] = true;
  21443. t['Excelsior'] = true;
  21444. t['Fairfield'] = true;
  21445. t['FF Scala'] = true;
  21446. t['Folkard'] = true;
  21447. t['Footlight'] = true;
  21448. t['FreeSerif'] = true;
  21449. t['Friz Quadrata'] = true;
  21450. t['Garamond'] = true;
  21451. t['Gentium'] = true;
  21452. t['Georgia'] = true;
  21453. t['Gloucester'] = true;
  21454. t['Goudy Old Style'] = true;
  21455. t['Goudy Schoolbook'] = true;
  21456. t['Goudy Pro Font'] = true;
  21457. t['Granjon'] = true;
  21458. t['Guardian Egyptian'] = true;
  21459. t['Heather'] = true;
  21460. t['Hercules'] = true;
  21461. t['High Tower Text'] = true;
  21462. t['Hiroshige'] = true;
  21463. t['Hoefler Text'] = true;
  21464. t['Humana Serif'] = true;
  21465. t['Imprint'] = true;
  21466. t['Ionic No. 5'] = true;
  21467. t['Janson'] = true;
  21468. t['Joanna'] = true;
  21469. t['Korinna'] = true;
  21470. t['Lexicon'] = true;
  21471. t['Liberation Serif'] = true;
  21472. t['Linux Libertine'] = true;
  21473. t['Literaturnaya'] = true;
  21474. t['Lucida'] = true;
  21475. t['Lucida Bright'] = true;
  21476. t['Melior'] = true;
  21477. t['Memphis'] = true;
  21478. t['Miller'] = true;
  21479. t['Minion'] = true;
  21480. t['Modern'] = true;
  21481. t['Mona Lisa'] = true;
  21482. t['Mrs Eaves'] = true;
  21483. t['MS Serif'] = true;
  21484. t['Museo Slab'] = true;
  21485. t['New York'] = true;
  21486. t['Nimbus Roman'] = true;
  21487. t['NPS Rawlinson Roadway'] = true;
  21488. t['Palatino'] = true;
  21489. t['Perpetua'] = true;
  21490. t['Plantin'] = true;
  21491. t['Plantin Schoolbook'] = true;
  21492. t['Playbill'] = true;
  21493. t['Poor Richard'] = true;
  21494. t['Rawlinson Roadway'] = true;
  21495. t['Renault'] = true;
  21496. t['Requiem'] = true;
  21497. t['Rockwell'] = true;
  21498. t['Roman'] = true;
  21499. t['Rotis Serif'] = true;
  21500. t['Sabon'] = true;
  21501. t['Scala'] = true;
  21502. t['Seagull'] = true;
  21503. t['Sistina'] = true;
  21504. t['Souvenir'] = true;
  21505. t['STIX'] = true;
  21506. t['Stone Informal'] = true;
  21507. t['Stone Serif'] = true;
  21508. t['Sylfaen'] = true;
  21509. t['Times'] = true;
  21510. t['Trajan'] = true;
  21511. t['Trinité'] = true;
  21512. t['Trump Mediaeval'] = true;
  21513. t['Utopia'] = true;
  21514. t['Vale Type'] = true;
  21515. t['Bitstream Vera'] = true;
  21516. t['Vera Serif'] = true;
  21517. t['Versailles'] = true;
  21518. t['Wanted'] = true;
  21519. t['Weiss'] = true;
  21520. t['Wide Latin'] = true;
  21521. t['Windsor'] = true;
  21522. t['XITS'] = true;
  21523. });
  21524. var getSymbolsFonts = getLookupTableFactory(function (t) {
  21525. t['Dingbats'] = true;
  21526. t['Symbol'] = true;
  21527. t['ZapfDingbats'] = true;
  21528. });
  21529. // Glyph map for well-known standard fonts. Sometimes Ghostscript uses CID
  21530. // fonts, but does not embed the CID to GID mapping. The mapping is incomplete
  21531. // for all glyphs, but common for some set of the standard fonts.
  21532. var getGlyphMapForStandardFonts = getLookupTableFactory(function (t) {
  21533. t[2] = 10;
  21534. t[3] = 32;
  21535. t[4] = 33;
  21536. t[5] = 34;
  21537. t[6] = 35;
  21538. t[7] = 36;
  21539. t[8] = 37;
  21540. t[9] = 38;
  21541. t[10] = 39;
  21542. t[11] = 40;
  21543. t[12] = 41;
  21544. t[13] = 42;
  21545. t[14] = 43;
  21546. t[15] = 44;
  21547. t[16] = 45;
  21548. t[17] = 46;
  21549. t[18] = 47;
  21550. t[19] = 48;
  21551. t[20] = 49;
  21552. t[21] = 50;
  21553. t[22] = 51;
  21554. t[23] = 52;
  21555. t[24] = 53;
  21556. t[25] = 54;
  21557. t[26] = 55;
  21558. t[27] = 56;
  21559. t[28] = 57;
  21560. t[29] = 58;
  21561. t[30] = 894;
  21562. t[31] = 60;
  21563. t[32] = 61;
  21564. t[33] = 62;
  21565. t[34] = 63;
  21566. t[35] = 64;
  21567. t[36] = 65;
  21568. t[37] = 66;
  21569. t[38] = 67;
  21570. t[39] = 68;
  21571. t[40] = 69;
  21572. t[41] = 70;
  21573. t[42] = 71;
  21574. t[43] = 72;
  21575. t[44] = 73;
  21576. t[45] = 74;
  21577. t[46] = 75;
  21578. t[47] = 76;
  21579. t[48] = 77;
  21580. t[49] = 78;
  21581. t[50] = 79;
  21582. t[51] = 80;
  21583. t[52] = 81;
  21584. t[53] = 82;
  21585. t[54] = 83;
  21586. t[55] = 84;
  21587. t[56] = 85;
  21588. t[57] = 86;
  21589. t[58] = 87;
  21590. t[59] = 88;
  21591. t[60] = 89;
  21592. t[61] = 90;
  21593. t[62] = 91;
  21594. t[63] = 92;
  21595. t[64] = 93;
  21596. t[65] = 94;
  21597. t[66] = 95;
  21598. t[67] = 96;
  21599. t[68] = 97;
  21600. t[69] = 98;
  21601. t[70] = 99;
  21602. t[71] = 100;
  21603. t[72] = 101;
  21604. t[73] = 102;
  21605. t[74] = 103;
  21606. t[75] = 104;
  21607. t[76] = 105;
  21608. t[77] = 106;
  21609. t[78] = 107;
  21610. t[79] = 108;
  21611. t[80] = 109;
  21612. t[81] = 110;
  21613. t[82] = 111;
  21614. t[83] = 112;
  21615. t[84] = 113;
  21616. t[85] = 114;
  21617. t[86] = 115;
  21618. t[87] = 116;
  21619. t[88] = 117;
  21620. t[89] = 118;
  21621. t[90] = 119;
  21622. t[91] = 120;
  21623. t[92] = 121;
  21624. t[93] = 122;
  21625. t[94] = 123;
  21626. t[95] = 124;
  21627. t[96] = 125;
  21628. t[97] = 126;
  21629. t[98] = 196;
  21630. t[99] = 197;
  21631. t[100] = 199;
  21632. t[101] = 201;
  21633. t[102] = 209;
  21634. t[103] = 214;
  21635. t[104] = 220;
  21636. t[105] = 225;
  21637. t[106] = 224;
  21638. t[107] = 226;
  21639. t[108] = 228;
  21640. t[109] = 227;
  21641. t[110] = 229;
  21642. t[111] = 231;
  21643. t[112] = 233;
  21644. t[113] = 232;
  21645. t[114] = 234;
  21646. t[115] = 235;
  21647. t[116] = 237;
  21648. t[117] = 236;
  21649. t[118] = 238;
  21650. t[119] = 239;
  21651. t[120] = 241;
  21652. t[121] = 243;
  21653. t[122] = 242;
  21654. t[123] = 244;
  21655. t[124] = 246;
  21656. t[125] = 245;
  21657. t[126] = 250;
  21658. t[127] = 249;
  21659. t[128] = 251;
  21660. t[129] = 252;
  21661. t[130] = 8224;
  21662. t[131] = 176;
  21663. t[132] = 162;
  21664. t[133] = 163;
  21665. t[134] = 167;
  21666. t[135] = 8226;
  21667. t[136] = 182;
  21668. t[137] = 223;
  21669. t[138] = 174;
  21670. t[139] = 169;
  21671. t[140] = 8482;
  21672. t[141] = 180;
  21673. t[142] = 168;
  21674. t[143] = 8800;
  21675. t[144] = 198;
  21676. t[145] = 216;
  21677. t[146] = 8734;
  21678. t[147] = 177;
  21679. t[148] = 8804;
  21680. t[149] = 8805;
  21681. t[150] = 165;
  21682. t[151] = 181;
  21683. t[152] = 8706;
  21684. t[153] = 8721;
  21685. t[154] = 8719;
  21686. t[156] = 8747;
  21687. t[157] = 170;
  21688. t[158] = 186;
  21689. t[159] = 8486;
  21690. t[160] = 230;
  21691. t[161] = 248;
  21692. t[162] = 191;
  21693. t[163] = 161;
  21694. t[164] = 172;
  21695. t[165] = 8730;
  21696. t[166] = 402;
  21697. t[167] = 8776;
  21698. t[168] = 8710;
  21699. t[169] = 171;
  21700. t[170] = 187;
  21701. t[171] = 8230;
  21702. t[210] = 218;
  21703. t[223] = 711;
  21704. t[224] = 321;
  21705. t[225] = 322;
  21706. t[227] = 353;
  21707. t[229] = 382;
  21708. t[234] = 253;
  21709. t[252] = 263;
  21710. t[253] = 268;
  21711. t[254] = 269;
  21712. t[258] = 258;
  21713. t[260] = 260;
  21714. t[261] = 261;
  21715. t[265] = 280;
  21716. t[266] = 281;
  21717. t[268] = 283;
  21718. t[269] = 313;
  21719. t[275] = 323;
  21720. t[276] = 324;
  21721. t[278] = 328;
  21722. t[284] = 345;
  21723. t[285] = 346;
  21724. t[286] = 347;
  21725. t[292] = 367;
  21726. t[295] = 377;
  21727. t[296] = 378;
  21728. t[298] = 380;
  21729. t[305] = 963;
  21730. t[306] = 964;
  21731. t[307] = 966;
  21732. t[308] = 8215;
  21733. t[309] = 8252;
  21734. t[310] = 8319;
  21735. t[311] = 8359;
  21736. t[312] = 8592;
  21737. t[313] = 8593;
  21738. t[337] = 9552;
  21739. t[493] = 1039;
  21740. t[494] = 1040;
  21741. t[705] = 1524;
  21742. t[706] = 8362;
  21743. t[710] = 64288;
  21744. t[711] = 64298;
  21745. t[759] = 1617;
  21746. t[761] = 1776;
  21747. t[763] = 1778;
  21748. t[775] = 1652;
  21749. t[777] = 1764;
  21750. t[778] = 1780;
  21751. t[779] = 1781;
  21752. t[780] = 1782;
  21753. t[782] = 771;
  21754. t[783] = 64726;
  21755. t[786] = 8363;
  21756. t[788] = 8532;
  21757. t[790] = 768;
  21758. t[791] = 769;
  21759. t[792] = 768;
  21760. t[795] = 803;
  21761. t[797] = 64336;
  21762. t[798] = 64337;
  21763. t[799] = 64342;
  21764. t[800] = 64343;
  21765. t[801] = 64344;
  21766. t[802] = 64345;
  21767. t[803] = 64362;
  21768. t[804] = 64363;
  21769. t[805] = 64364;
  21770. t[2424] = 7821;
  21771. t[2425] = 7822;
  21772. t[2426] = 7823;
  21773. t[2427] = 7824;
  21774. t[2428] = 7825;
  21775. t[2429] = 7826;
  21776. t[2430] = 7827;
  21777. t[2433] = 7682;
  21778. t[2678] = 8045;
  21779. t[2679] = 8046;
  21780. t[2830] = 1552;
  21781. t[2838] = 686;
  21782. t[2840] = 751;
  21783. t[2842] = 753;
  21784. t[2843] = 754;
  21785. t[2844] = 755;
  21786. t[2846] = 757;
  21787. t[2856] = 767;
  21788. t[2857] = 848;
  21789. t[2858] = 849;
  21790. t[2862] = 853;
  21791. t[2863] = 854;
  21792. t[2864] = 855;
  21793. t[2865] = 861;
  21794. t[2866] = 862;
  21795. t[2906] = 7460;
  21796. t[2908] = 7462;
  21797. t[2909] = 7463;
  21798. t[2910] = 7464;
  21799. t[2912] = 7466;
  21800. t[2913] = 7467;
  21801. t[2914] = 7468;
  21802. t[2916] = 7470;
  21803. t[2917] = 7471;
  21804. t[2918] = 7472;
  21805. t[2920] = 7474;
  21806. t[2921] = 7475;
  21807. t[2922] = 7476;
  21808. t[2924] = 7478;
  21809. t[2925] = 7479;
  21810. t[2926] = 7480;
  21811. t[2928] = 7482;
  21812. t[2929] = 7483;
  21813. t[2930] = 7484;
  21814. t[2932] = 7486;
  21815. t[2933] = 7487;
  21816. t[2934] = 7488;
  21817. t[2936] = 7490;
  21818. t[2937] = 7491;
  21819. t[2938] = 7492;
  21820. t[2940] = 7494;
  21821. t[2941] = 7495;
  21822. t[2942] = 7496;
  21823. t[2944] = 7498;
  21824. t[2946] = 7500;
  21825. t[2948] = 7502;
  21826. t[2950] = 7504;
  21827. t[2951] = 7505;
  21828. t[2952] = 7506;
  21829. t[2954] = 7508;
  21830. t[2955] = 7509;
  21831. t[2956] = 7510;
  21832. t[2958] = 7512;
  21833. t[2959] = 7513;
  21834. t[2960] = 7514;
  21835. t[2962] = 7516;
  21836. t[2963] = 7517;
  21837. t[2964] = 7518;
  21838. t[2966] = 7520;
  21839. t[2967] = 7521;
  21840. t[2968] = 7522;
  21841. t[2970] = 7524;
  21842. t[2971] = 7525;
  21843. t[2972] = 7526;
  21844. t[2974] = 7528;
  21845. t[2975] = 7529;
  21846. t[2976] = 7530;
  21847. t[2978] = 1537;
  21848. t[2979] = 1538;
  21849. t[2980] = 1539;
  21850. t[2982] = 1549;
  21851. t[2983] = 1551;
  21852. t[2984] = 1552;
  21853. t[2986] = 1554;
  21854. t[2987] = 1555;
  21855. t[2988] = 1556;
  21856. t[2990] = 1623;
  21857. t[2991] = 1624;
  21858. t[2995] = 1775;
  21859. t[2999] = 1791;
  21860. t[3002] = 64290;
  21861. t[3003] = 64291;
  21862. t[3004] = 64292;
  21863. t[3006] = 64294;
  21864. t[3007] = 64295;
  21865. t[3008] = 64296;
  21866. t[3011] = 1900;
  21867. t[3014] = 8223;
  21868. t[3015] = 8244;
  21869. t[3017] = 7532;
  21870. t[3018] = 7533;
  21871. t[3019] = 7534;
  21872. t[3075] = 7590;
  21873. t[3076] = 7591;
  21874. t[3079] = 7594;
  21875. t[3080] = 7595;
  21876. t[3083] = 7598;
  21877. t[3084] = 7599;
  21878. t[3087] = 7602;
  21879. t[3088] = 7603;
  21880. t[3091] = 7606;
  21881. t[3092] = 7607;
  21882. t[3095] = 7610;
  21883. t[3096] = 7611;
  21884. t[3099] = 7614;
  21885. t[3100] = 7615;
  21886. t[3103] = 7618;
  21887. t[3104] = 7619;
  21888. t[3107] = 8337;
  21889. t[3108] = 8338;
  21890. t[3116] = 1884;
  21891. t[3119] = 1885;
  21892. t[3120] = 1885;
  21893. t[3123] = 1886;
  21894. t[3124] = 1886;
  21895. t[3127] = 1887;
  21896. t[3128] = 1887;
  21897. t[3131] = 1888;
  21898. t[3132] = 1888;
  21899. t[3135] = 1889;
  21900. t[3136] = 1889;
  21901. t[3139] = 1890;
  21902. t[3140] = 1890;
  21903. t[3143] = 1891;
  21904. t[3144] = 1891;
  21905. t[3147] = 1892;
  21906. t[3148] = 1892;
  21907. t[3153] = 580;
  21908. t[3154] = 581;
  21909. t[3157] = 584;
  21910. t[3158] = 585;
  21911. t[3161] = 588;
  21912. t[3162] = 589;
  21913. t[3165] = 891;
  21914. t[3166] = 892;
  21915. t[3169] = 1274;
  21916. t[3170] = 1275;
  21917. t[3173] = 1278;
  21918. t[3174] = 1279;
  21919. t[3181] = 7622;
  21920. t[3182] = 7623;
  21921. t[3282] = 11799;
  21922. t[3316] = 578;
  21923. t[3379] = 42785;
  21924. t[3393] = 1159;
  21925. t[3416] = 8377;
  21926. });
  21927. // The glyph map for ArialBlack differs slightly from the glyph map used for
  21928. // other well-known standard fonts. Hence we use this (incomplete) CID to GID
  21929. // mapping to adjust the glyph map for non-embedded ArialBlack fonts.
  21930. var getSupplementalGlyphMapForArialBlack = getLookupTableFactory(function (t) {
  21931. t[227] = 322;
  21932. t[264] = 261;
  21933. t[291] = 346;
  21934. });
  21935. exports.getStdFontMap = getStdFontMap;
  21936. exports.getNonStdFontMap = getNonStdFontMap;
  21937. exports.getSerifFonts = getSerifFonts;
  21938. exports.getSymbolsFonts = getSymbolsFonts;
  21939. exports.getGlyphMapForStandardFonts = getGlyphMapForStandardFonts;
  21940. exports.getSupplementalGlyphMapForArialBlack = getSupplementalGlyphMapForArialBlack;
  21941. }));
  21942. (function (root, factory) {
  21943. factory(root.pdfjsCoreUnicode = {}, root.pdfjsSharedUtil);
  21944. }(this, function (exports, sharedUtil) {
  21945. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  21946. // Some characters, e.g. copyrightserif, are mapped to the private use area
  21947. // and might not be displayed using standard fonts. Mapping/hacking well-known
  21948. // chars to the similar equivalents in the normal characters range.
  21949. var getSpecialPUASymbols = getLookupTableFactory(function (t) {
  21950. t[63721] = 0x00A9;
  21951. // copyrightsans (0xF8E9) => copyright
  21952. t[63193] = 0x00A9;
  21953. // copyrightserif (0xF6D9) => copyright
  21954. t[63720] = 0x00AE;
  21955. // registersans (0xF8E8) => registered
  21956. t[63194] = 0x00AE;
  21957. // registerserif (0xF6DA) => registered
  21958. t[63722] = 0x2122;
  21959. // trademarksans (0xF8EA) => trademark
  21960. t[63195] = 0x2122;
  21961. // trademarkserif (0xF6DB) => trademark
  21962. t[63729] = 0x23A7;
  21963. // bracelefttp (0xF8F1)
  21964. t[63730] = 0x23A8;
  21965. // braceleftmid (0xF8F2)
  21966. t[63731] = 0x23A9;
  21967. // braceleftbt (0xF8F3)
  21968. t[63740] = 0x23AB;
  21969. // bracerighttp (0xF8FC)
  21970. t[63741] = 0x23AC;
  21971. // bracerightmid (0xF8FD)
  21972. t[63742] = 0x23AD;
  21973. // bracerightbt (0xF8FE)
  21974. t[63726] = 0x23A1;
  21975. // bracketlefttp (0xF8EE)
  21976. t[63727] = 0x23A2;
  21977. // bracketleftex (0xF8EF)
  21978. t[63728] = 0x23A3;
  21979. // bracketleftbt (0xF8F0)
  21980. t[63737] = 0x23A4;
  21981. // bracketrighttp (0xF8F9)
  21982. t[63738] = 0x23A5;
  21983. // bracketrightex (0xF8FA)
  21984. t[63739] = 0x23A6;
  21985. // bracketrightbt (0xF8FB)
  21986. t[63723] = 0x239B;
  21987. // parenlefttp (0xF8EB)
  21988. t[63724] = 0x239C;
  21989. // parenleftex (0xF8EC)
  21990. t[63725] = 0x239D;
  21991. // parenleftbt (0xF8ED)
  21992. t[63734] = 0x239E;
  21993. // parenrighttp (0xF8F6)
  21994. t[63735] = 0x239F;
  21995. // parenrightex (0xF8F7)
  21996. t[63736] = 0x23A0;
  21997. });
  21998. // parenrightbt (0xF8F8)
  21999. function mapSpecialUnicodeValues(code) {
  22000. if (code >= 0xFFF0 && code <= 0xFFFF) {
  22001. // Specials unicode block.
  22002. return 0;
  22003. } else if (code >= 0xF600 && code <= 0xF8FF) {
  22004. return getSpecialPUASymbols()[code] || code;
  22005. }
  22006. return code;
  22007. }
  22008. function getUnicodeForGlyph(name, glyphsUnicodeMap) {
  22009. var unicode = glyphsUnicodeMap[name];
  22010. if (unicode !== undefined) {
  22011. return unicode;
  22012. }
  22013. if (!name) {
  22014. return -1;
  22015. }
  22016. // Try to recover valid Unicode values from 'uniXXXX'/'uXXXX{XX}' glyphs.
  22017. if (name[0] === 'u') {
  22018. var nameLen = name.length, hexStr;
  22019. if (nameLen === 7 && name[1] === 'n' && name[2] === 'i') {
  22020. // 'uniXXXX'
  22021. hexStr = name.substr(3);
  22022. } else if (nameLen >= 5 && nameLen <= 7) {
  22023. // 'uXXXX{XX}'
  22024. hexStr = name.substr(1);
  22025. } else {
  22026. return -1;
  22027. }
  22028. // Check for upper-case hexadecimal characters, to avoid false positives.
  22029. if (hexStr === hexStr.toUpperCase()) {
  22030. unicode = parseInt(hexStr, 16);
  22031. if (unicode >= 0) {
  22032. return unicode;
  22033. }
  22034. }
  22035. }
  22036. return -1;
  22037. }
  22038. var UnicodeRanges = [
  22039. {
  22040. 'begin': 0x0000,
  22041. 'end': 0x007F
  22042. },
  22043. // Basic Latin
  22044. {
  22045. 'begin': 0x0080,
  22046. 'end': 0x00FF
  22047. },
  22048. // Latin-1 Supplement
  22049. {
  22050. 'begin': 0x0100,
  22051. 'end': 0x017F
  22052. },
  22053. // Latin Extended-A
  22054. {
  22055. 'begin': 0x0180,
  22056. 'end': 0x024F
  22057. },
  22058. // Latin Extended-B
  22059. {
  22060. 'begin': 0x0250,
  22061. 'end': 0x02AF
  22062. },
  22063. // IPA Extensions
  22064. {
  22065. 'begin': 0x02B0,
  22066. 'end': 0x02FF
  22067. },
  22068. // Spacing Modifier Letters
  22069. {
  22070. 'begin': 0x0300,
  22071. 'end': 0x036F
  22072. },
  22073. // Combining Diacritical Marks
  22074. {
  22075. 'begin': 0x0370,
  22076. 'end': 0x03FF
  22077. },
  22078. // Greek and Coptic
  22079. {
  22080. 'begin': 0x2C80,
  22081. 'end': 0x2CFF
  22082. },
  22083. // Coptic
  22084. {
  22085. 'begin': 0x0400,
  22086. 'end': 0x04FF
  22087. },
  22088. // Cyrillic
  22089. {
  22090. 'begin': 0x0530,
  22091. 'end': 0x058F
  22092. },
  22093. // Armenian
  22094. {
  22095. 'begin': 0x0590,
  22096. 'end': 0x05FF
  22097. },
  22098. // Hebrew
  22099. {
  22100. 'begin': 0xA500,
  22101. 'end': 0xA63F
  22102. },
  22103. // Vai
  22104. {
  22105. 'begin': 0x0600,
  22106. 'end': 0x06FF
  22107. },
  22108. // Arabic
  22109. {
  22110. 'begin': 0x07C0,
  22111. 'end': 0x07FF
  22112. },
  22113. // NKo
  22114. {
  22115. 'begin': 0x0900,
  22116. 'end': 0x097F
  22117. },
  22118. // Devanagari
  22119. {
  22120. 'begin': 0x0980,
  22121. 'end': 0x09FF
  22122. },
  22123. // Bengali
  22124. {
  22125. 'begin': 0x0A00,
  22126. 'end': 0x0A7F
  22127. },
  22128. // Gurmukhi
  22129. {
  22130. 'begin': 0x0A80,
  22131. 'end': 0x0AFF
  22132. },
  22133. // Gujarati
  22134. {
  22135. 'begin': 0x0B00,
  22136. 'end': 0x0B7F
  22137. },
  22138. // Oriya
  22139. {
  22140. 'begin': 0x0B80,
  22141. 'end': 0x0BFF
  22142. },
  22143. // Tamil
  22144. {
  22145. 'begin': 0x0C00,
  22146. 'end': 0x0C7F
  22147. },
  22148. // Telugu
  22149. {
  22150. 'begin': 0x0C80,
  22151. 'end': 0x0CFF
  22152. },
  22153. // Kannada
  22154. {
  22155. 'begin': 0x0D00,
  22156. 'end': 0x0D7F
  22157. },
  22158. // Malayalam
  22159. {
  22160. 'begin': 0x0E00,
  22161. 'end': 0x0E7F
  22162. },
  22163. // Thai
  22164. {
  22165. 'begin': 0x0E80,
  22166. 'end': 0x0EFF
  22167. },
  22168. // Lao
  22169. {
  22170. 'begin': 0x10A0,
  22171. 'end': 0x10FF
  22172. },
  22173. // Georgian
  22174. {
  22175. 'begin': 0x1B00,
  22176. 'end': 0x1B7F
  22177. },
  22178. // Balinese
  22179. {
  22180. 'begin': 0x1100,
  22181. 'end': 0x11FF
  22182. },
  22183. // Hangul Jamo
  22184. {
  22185. 'begin': 0x1E00,
  22186. 'end': 0x1EFF
  22187. },
  22188. // Latin Extended Additional
  22189. {
  22190. 'begin': 0x1F00,
  22191. 'end': 0x1FFF
  22192. },
  22193. // Greek Extended
  22194. {
  22195. 'begin': 0x2000,
  22196. 'end': 0x206F
  22197. },
  22198. // General Punctuation
  22199. {
  22200. 'begin': 0x2070,
  22201. 'end': 0x209F
  22202. },
  22203. // Superscripts And Subscripts
  22204. {
  22205. 'begin': 0x20A0,
  22206. 'end': 0x20CF
  22207. },
  22208. // Currency Symbol
  22209. {
  22210. 'begin': 0x20D0,
  22211. 'end': 0x20FF
  22212. },
  22213. // Combining Diacritical Marks
  22214. {
  22215. 'begin': 0x2100,
  22216. 'end': 0x214F
  22217. },
  22218. // Letterlike Symbols
  22219. {
  22220. 'begin': 0x2150,
  22221. 'end': 0x218F
  22222. },
  22223. // Number Forms
  22224. {
  22225. 'begin': 0x2190,
  22226. 'end': 0x21FF
  22227. },
  22228. // Arrows
  22229. {
  22230. 'begin': 0x2200,
  22231. 'end': 0x22FF
  22232. },
  22233. // Mathematical Operators
  22234. {
  22235. 'begin': 0x2300,
  22236. 'end': 0x23FF
  22237. },
  22238. // Miscellaneous Technical
  22239. {
  22240. 'begin': 0x2400,
  22241. 'end': 0x243F
  22242. },
  22243. // Control Pictures
  22244. {
  22245. 'begin': 0x2440,
  22246. 'end': 0x245F
  22247. },
  22248. // Optical Character Recognition
  22249. {
  22250. 'begin': 0x2460,
  22251. 'end': 0x24FF
  22252. },
  22253. // Enclosed Alphanumerics
  22254. {
  22255. 'begin': 0x2500,
  22256. 'end': 0x257F
  22257. },
  22258. // Box Drawing
  22259. {
  22260. 'begin': 0x2580,
  22261. 'end': 0x259F
  22262. },
  22263. // Block Elements
  22264. {
  22265. 'begin': 0x25A0,
  22266. 'end': 0x25FF
  22267. },
  22268. // Geometric Shapes
  22269. {
  22270. 'begin': 0x2600,
  22271. 'end': 0x26FF
  22272. },
  22273. // Miscellaneous Symbols
  22274. {
  22275. 'begin': 0x2700,
  22276. 'end': 0x27BF
  22277. },
  22278. // Dingbats
  22279. {
  22280. 'begin': 0x3000,
  22281. 'end': 0x303F
  22282. },
  22283. // CJK Symbols And Punctuation
  22284. {
  22285. 'begin': 0x3040,
  22286. 'end': 0x309F
  22287. },
  22288. // Hiragana
  22289. {
  22290. 'begin': 0x30A0,
  22291. 'end': 0x30FF
  22292. },
  22293. // Katakana
  22294. {
  22295. 'begin': 0x3100,
  22296. 'end': 0x312F
  22297. },
  22298. // Bopomofo
  22299. {
  22300. 'begin': 0x3130,
  22301. 'end': 0x318F
  22302. },
  22303. // Hangul Compatibility Jamo
  22304. {
  22305. 'begin': 0xA840,
  22306. 'end': 0xA87F
  22307. },
  22308. // Phags-pa
  22309. {
  22310. 'begin': 0x3200,
  22311. 'end': 0x32FF
  22312. },
  22313. // Enclosed CJK Letters And Months
  22314. {
  22315. 'begin': 0x3300,
  22316. 'end': 0x33FF
  22317. },
  22318. // CJK Compatibility
  22319. {
  22320. 'begin': 0xAC00,
  22321. 'end': 0xD7AF
  22322. },
  22323. // Hangul Syllables
  22324. {
  22325. 'begin': 0xD800,
  22326. 'end': 0xDFFF
  22327. },
  22328. // Non-Plane 0 *
  22329. {
  22330. 'begin': 0x10900,
  22331. 'end': 0x1091F
  22332. },
  22333. // Phoenicia
  22334. {
  22335. 'begin': 0x4E00,
  22336. 'end': 0x9FFF
  22337. },
  22338. // CJK Unified Ideographs
  22339. {
  22340. 'begin': 0xE000,
  22341. 'end': 0xF8FF
  22342. },
  22343. // Private Use Area (plane 0)
  22344. {
  22345. 'begin': 0x31C0,
  22346. 'end': 0x31EF
  22347. },
  22348. // CJK Strokes
  22349. {
  22350. 'begin': 0xFB00,
  22351. 'end': 0xFB4F
  22352. },
  22353. // Alphabetic Presentation Forms
  22354. {
  22355. 'begin': 0xFB50,
  22356. 'end': 0xFDFF
  22357. },
  22358. // Arabic Presentation Forms-A
  22359. {
  22360. 'begin': 0xFE20,
  22361. 'end': 0xFE2F
  22362. },
  22363. // Combining Half Marks
  22364. {
  22365. 'begin': 0xFE10,
  22366. 'end': 0xFE1F
  22367. },
  22368. // Vertical Forms
  22369. {
  22370. 'begin': 0xFE50,
  22371. 'end': 0xFE6F
  22372. },
  22373. // Small Form Variants
  22374. {
  22375. 'begin': 0xFE70,
  22376. 'end': 0xFEFF
  22377. },
  22378. // Arabic Presentation Forms-B
  22379. {
  22380. 'begin': 0xFF00,
  22381. 'end': 0xFFEF
  22382. },
  22383. // Halfwidth And Fullwidth Forms
  22384. {
  22385. 'begin': 0xFFF0,
  22386. 'end': 0xFFFF
  22387. },
  22388. // Specials
  22389. {
  22390. 'begin': 0x0F00,
  22391. 'end': 0x0FFF
  22392. },
  22393. // Tibetan
  22394. {
  22395. 'begin': 0x0700,
  22396. 'end': 0x074F
  22397. },
  22398. // Syriac
  22399. {
  22400. 'begin': 0x0780,
  22401. 'end': 0x07BF
  22402. },
  22403. // Thaana
  22404. {
  22405. 'begin': 0x0D80,
  22406. 'end': 0x0DFF
  22407. },
  22408. // Sinhala
  22409. {
  22410. 'begin': 0x1000,
  22411. 'end': 0x109F
  22412. },
  22413. // Myanmar
  22414. {
  22415. 'begin': 0x1200,
  22416. 'end': 0x137F
  22417. },
  22418. // Ethiopic
  22419. {
  22420. 'begin': 0x13A0,
  22421. 'end': 0x13FF
  22422. },
  22423. // Cherokee
  22424. {
  22425. 'begin': 0x1400,
  22426. 'end': 0x167F
  22427. },
  22428. // Unified Canadian Aboriginal Syllabics
  22429. {
  22430. 'begin': 0x1680,
  22431. 'end': 0x169F
  22432. },
  22433. // Ogham
  22434. {
  22435. 'begin': 0x16A0,
  22436. 'end': 0x16FF
  22437. },
  22438. // Runic
  22439. {
  22440. 'begin': 0x1780,
  22441. 'end': 0x17FF
  22442. },
  22443. // Khmer
  22444. {
  22445. 'begin': 0x1800,
  22446. 'end': 0x18AF
  22447. },
  22448. // Mongolian
  22449. {
  22450. 'begin': 0x2800,
  22451. 'end': 0x28FF
  22452. },
  22453. // Braille Patterns
  22454. {
  22455. 'begin': 0xA000,
  22456. 'end': 0xA48F
  22457. },
  22458. // Yi Syllables
  22459. {
  22460. 'begin': 0x1700,
  22461. 'end': 0x171F
  22462. },
  22463. // Tagalog
  22464. {
  22465. 'begin': 0x10300,
  22466. 'end': 0x1032F
  22467. },
  22468. // Old Italic
  22469. {
  22470. 'begin': 0x10330,
  22471. 'end': 0x1034F
  22472. },
  22473. // Gothic
  22474. {
  22475. 'begin': 0x10400,
  22476. 'end': 0x1044F
  22477. },
  22478. // Deseret
  22479. {
  22480. 'begin': 0x1D000,
  22481. 'end': 0x1D0FF
  22482. },
  22483. // Byzantine Musical Symbols
  22484. {
  22485. 'begin': 0x1D400,
  22486. 'end': 0x1D7FF
  22487. },
  22488. // Mathematical Alphanumeric Symbols
  22489. {
  22490. 'begin': 0xFF000,
  22491. 'end': 0xFFFFD
  22492. },
  22493. // Private Use (plane 15)
  22494. {
  22495. 'begin': 0xFE00,
  22496. 'end': 0xFE0F
  22497. },
  22498. // Variation Selectors
  22499. {
  22500. 'begin': 0xE0000,
  22501. 'end': 0xE007F
  22502. },
  22503. // Tags
  22504. {
  22505. 'begin': 0x1900,
  22506. 'end': 0x194F
  22507. },
  22508. // Limbu
  22509. {
  22510. 'begin': 0x1950,
  22511. 'end': 0x197F
  22512. },
  22513. // Tai Le
  22514. {
  22515. 'begin': 0x1980,
  22516. 'end': 0x19DF
  22517. },
  22518. // New Tai Lue
  22519. {
  22520. 'begin': 0x1A00,
  22521. 'end': 0x1A1F
  22522. },
  22523. // Buginese
  22524. {
  22525. 'begin': 0x2C00,
  22526. 'end': 0x2C5F
  22527. },
  22528. // Glagolitic
  22529. {
  22530. 'begin': 0x2D30,
  22531. 'end': 0x2D7F
  22532. },
  22533. // Tifinagh
  22534. {
  22535. 'begin': 0x4DC0,
  22536. 'end': 0x4DFF
  22537. },
  22538. // Yijing Hexagram Symbols
  22539. {
  22540. 'begin': 0xA800,
  22541. 'end': 0xA82F
  22542. },
  22543. // Syloti Nagri
  22544. {
  22545. 'begin': 0x10000,
  22546. 'end': 0x1007F
  22547. },
  22548. // Linear B Syllabary
  22549. {
  22550. 'begin': 0x10140,
  22551. 'end': 0x1018F
  22552. },
  22553. // Ancient Greek Numbers
  22554. {
  22555. 'begin': 0x10380,
  22556. 'end': 0x1039F
  22557. },
  22558. // Ugaritic
  22559. {
  22560. 'begin': 0x103A0,
  22561. 'end': 0x103DF
  22562. },
  22563. // Old Persian
  22564. {
  22565. 'begin': 0x10450,
  22566. 'end': 0x1047F
  22567. },
  22568. // Shavian
  22569. {
  22570. 'begin': 0x10480,
  22571. 'end': 0x104AF
  22572. },
  22573. // Osmanya
  22574. {
  22575. 'begin': 0x10800,
  22576. 'end': 0x1083F
  22577. },
  22578. // Cypriot Syllabary
  22579. {
  22580. 'begin': 0x10A00,
  22581. 'end': 0x10A5F
  22582. },
  22583. // Kharoshthi
  22584. {
  22585. 'begin': 0x1D300,
  22586. 'end': 0x1D35F
  22587. },
  22588. // Tai Xuan Jing Symbols
  22589. {
  22590. 'begin': 0x12000,
  22591. 'end': 0x123FF
  22592. },
  22593. // Cuneiform
  22594. {
  22595. 'begin': 0x1D360,
  22596. 'end': 0x1D37F
  22597. },
  22598. // Counting Rod Numerals
  22599. {
  22600. 'begin': 0x1B80,
  22601. 'end': 0x1BBF
  22602. },
  22603. // Sundanese
  22604. {
  22605. 'begin': 0x1C00,
  22606. 'end': 0x1C4F
  22607. },
  22608. // Lepcha
  22609. {
  22610. 'begin': 0x1C50,
  22611. 'end': 0x1C7F
  22612. },
  22613. // Ol Chiki
  22614. {
  22615. 'begin': 0xA880,
  22616. 'end': 0xA8DF
  22617. },
  22618. // Saurashtra
  22619. {
  22620. 'begin': 0xA900,
  22621. 'end': 0xA92F
  22622. },
  22623. // Kayah Li
  22624. {
  22625. 'begin': 0xA930,
  22626. 'end': 0xA95F
  22627. },
  22628. // Rejang
  22629. {
  22630. 'begin': 0xAA00,
  22631. 'end': 0xAA5F
  22632. },
  22633. // Cham
  22634. {
  22635. 'begin': 0x10190,
  22636. 'end': 0x101CF
  22637. },
  22638. // Ancient Symbols
  22639. {
  22640. 'begin': 0x101D0,
  22641. 'end': 0x101FF
  22642. },
  22643. // Phaistos Disc
  22644. {
  22645. 'begin': 0x102A0,
  22646. 'end': 0x102DF
  22647. },
  22648. // Carian
  22649. {
  22650. 'begin': 0x1F030,
  22651. 'end': 0x1F09F
  22652. }
  22653. ];
  22654. // Domino Tiles
  22655. function getUnicodeRangeFor(value) {
  22656. for (var i = 0, ii = UnicodeRanges.length; i < ii; i++) {
  22657. var range = UnicodeRanges[i];
  22658. if (value >= range.begin && value < range.end) {
  22659. return i;
  22660. }
  22661. }
  22662. return -1;
  22663. }
  22664. function isRTLRangeFor(value) {
  22665. var range = UnicodeRanges[13];
  22666. if (value >= range.begin && value < range.end) {
  22667. return true;
  22668. }
  22669. range = UnicodeRanges[11];
  22670. if (value >= range.begin && value < range.end) {
  22671. return true;
  22672. }
  22673. return false;
  22674. }
  22675. // The normalization table is obtained by filtering the Unicode characters
  22676. // database with <compat> entries.
  22677. var getNormalizedUnicodes = getLookupTableFactory(function (t) {
  22678. t['\u00A8'] = '\u0020\u0308';
  22679. t['\u00AF'] = '\u0020\u0304';
  22680. t['\u00B4'] = '\u0020\u0301';
  22681. t['\u00B5'] = '\u03BC';
  22682. t['\u00B8'] = '\u0020\u0327';
  22683. t['\u0132'] = '\u0049\u004A';
  22684. t['\u0133'] = '\u0069\u006A';
  22685. t['\u013F'] = '\u004C\u00B7';
  22686. t['\u0140'] = '\u006C\u00B7';
  22687. t['\u0149'] = '\u02BC\u006E';
  22688. t['\u017F'] = '\u0073';
  22689. t['\u01C4'] = '\u0044\u017D';
  22690. t['\u01C5'] = '\u0044\u017E';
  22691. t['\u01C6'] = '\u0064\u017E';
  22692. t['\u01C7'] = '\u004C\u004A';
  22693. t['\u01C8'] = '\u004C\u006A';
  22694. t['\u01C9'] = '\u006C\u006A';
  22695. t['\u01CA'] = '\u004E\u004A';
  22696. t['\u01CB'] = '\u004E\u006A';
  22697. t['\u01CC'] = '\u006E\u006A';
  22698. t['\u01F1'] = '\u0044\u005A';
  22699. t['\u01F2'] = '\u0044\u007A';
  22700. t['\u01F3'] = '\u0064\u007A';
  22701. t['\u02D8'] = '\u0020\u0306';
  22702. t['\u02D9'] = '\u0020\u0307';
  22703. t['\u02DA'] = '\u0020\u030A';
  22704. t['\u02DB'] = '\u0020\u0328';
  22705. t['\u02DC'] = '\u0020\u0303';
  22706. t['\u02DD'] = '\u0020\u030B';
  22707. t['\u037A'] = '\u0020\u0345';
  22708. t['\u0384'] = '\u0020\u0301';
  22709. t['\u03D0'] = '\u03B2';
  22710. t['\u03D1'] = '\u03B8';
  22711. t['\u03D2'] = '\u03A5';
  22712. t['\u03D5'] = '\u03C6';
  22713. t['\u03D6'] = '\u03C0';
  22714. t['\u03F0'] = '\u03BA';
  22715. t['\u03F1'] = '\u03C1';
  22716. t['\u03F2'] = '\u03C2';
  22717. t['\u03F4'] = '\u0398';
  22718. t['\u03F5'] = '\u03B5';
  22719. t['\u03F9'] = '\u03A3';
  22720. t['\u0587'] = '\u0565\u0582';
  22721. t['\u0675'] = '\u0627\u0674';
  22722. t['\u0676'] = '\u0648\u0674';
  22723. t['\u0677'] = '\u06C7\u0674';
  22724. t['\u0678'] = '\u064A\u0674';
  22725. t['\u0E33'] = '\u0E4D\u0E32';
  22726. t['\u0EB3'] = '\u0ECD\u0EB2';
  22727. t['\u0EDC'] = '\u0EAB\u0E99';
  22728. t['\u0EDD'] = '\u0EAB\u0EA1';
  22729. t['\u0F77'] = '\u0FB2\u0F81';
  22730. t['\u0F79'] = '\u0FB3\u0F81';
  22731. t['\u1E9A'] = '\u0061\u02BE';
  22732. t['\u1FBD'] = '\u0020\u0313';
  22733. t['\u1FBF'] = '\u0020\u0313';
  22734. t['\u1FC0'] = '\u0020\u0342';
  22735. t['\u1FFE'] = '\u0020\u0314';
  22736. t['\u2002'] = '\u0020';
  22737. t['\u2003'] = '\u0020';
  22738. t['\u2004'] = '\u0020';
  22739. t['\u2005'] = '\u0020';
  22740. t['\u2006'] = '\u0020';
  22741. t['\u2008'] = '\u0020';
  22742. t['\u2009'] = '\u0020';
  22743. t['\u200A'] = '\u0020';
  22744. t['\u2017'] = '\u0020\u0333';
  22745. t['\u2024'] = '\u002E';
  22746. t['\u2025'] = '\u002E\u002E';
  22747. t['\u2026'] = '\u002E\u002E\u002E';
  22748. t['\u2033'] = '\u2032\u2032';
  22749. t['\u2034'] = '\u2032\u2032\u2032';
  22750. t['\u2036'] = '\u2035\u2035';
  22751. t['\u2037'] = '\u2035\u2035\u2035';
  22752. t['\u203C'] = '\u0021\u0021';
  22753. t['\u203E'] = '\u0020\u0305';
  22754. t['\u2047'] = '\u003F\u003F';
  22755. t['\u2048'] = '\u003F\u0021';
  22756. t['\u2049'] = '\u0021\u003F';
  22757. t['\u2057'] = '\u2032\u2032\u2032\u2032';
  22758. t['\u205F'] = '\u0020';
  22759. t['\u20A8'] = '\u0052\u0073';
  22760. t['\u2100'] = '\u0061\u002F\u0063';
  22761. t['\u2101'] = '\u0061\u002F\u0073';
  22762. t['\u2103'] = '\u00B0\u0043';
  22763. t['\u2105'] = '\u0063\u002F\u006F';
  22764. t['\u2106'] = '\u0063\u002F\u0075';
  22765. t['\u2107'] = '\u0190';
  22766. t['\u2109'] = '\u00B0\u0046';
  22767. t['\u2116'] = '\u004E\u006F';
  22768. t['\u2121'] = '\u0054\u0045\u004C';
  22769. t['\u2135'] = '\u05D0';
  22770. t['\u2136'] = '\u05D1';
  22771. t['\u2137'] = '\u05D2';
  22772. t['\u2138'] = '\u05D3';
  22773. t['\u213B'] = '\u0046\u0041\u0058';
  22774. t['\u2160'] = '\u0049';
  22775. t['\u2161'] = '\u0049\u0049';
  22776. t['\u2162'] = '\u0049\u0049\u0049';
  22777. t['\u2163'] = '\u0049\u0056';
  22778. t['\u2164'] = '\u0056';
  22779. t['\u2165'] = '\u0056\u0049';
  22780. t['\u2166'] = '\u0056\u0049\u0049';
  22781. t['\u2167'] = '\u0056\u0049\u0049\u0049';
  22782. t['\u2168'] = '\u0049\u0058';
  22783. t['\u2169'] = '\u0058';
  22784. t['\u216A'] = '\u0058\u0049';
  22785. t['\u216B'] = '\u0058\u0049\u0049';
  22786. t['\u216C'] = '\u004C';
  22787. t['\u216D'] = '\u0043';
  22788. t['\u216E'] = '\u0044';
  22789. t['\u216F'] = '\u004D';
  22790. t['\u2170'] = '\u0069';
  22791. t['\u2171'] = '\u0069\u0069';
  22792. t['\u2172'] = '\u0069\u0069\u0069';
  22793. t['\u2173'] = '\u0069\u0076';
  22794. t['\u2174'] = '\u0076';
  22795. t['\u2175'] = '\u0076\u0069';
  22796. t['\u2176'] = '\u0076\u0069\u0069';
  22797. t['\u2177'] = '\u0076\u0069\u0069\u0069';
  22798. t['\u2178'] = '\u0069\u0078';
  22799. t['\u2179'] = '\u0078';
  22800. t['\u217A'] = '\u0078\u0069';
  22801. t['\u217B'] = '\u0078\u0069\u0069';
  22802. t['\u217C'] = '\u006C';
  22803. t['\u217D'] = '\u0063';
  22804. t['\u217E'] = '\u0064';
  22805. t['\u217F'] = '\u006D';
  22806. t['\u222C'] = '\u222B\u222B';
  22807. t['\u222D'] = '\u222B\u222B\u222B';
  22808. t['\u222F'] = '\u222E\u222E';
  22809. t['\u2230'] = '\u222E\u222E\u222E';
  22810. t['\u2474'] = '\u0028\u0031\u0029';
  22811. t['\u2475'] = '\u0028\u0032\u0029';
  22812. t['\u2476'] = '\u0028\u0033\u0029';
  22813. t['\u2477'] = '\u0028\u0034\u0029';
  22814. t['\u2478'] = '\u0028\u0035\u0029';
  22815. t['\u2479'] = '\u0028\u0036\u0029';
  22816. t['\u247A'] = '\u0028\u0037\u0029';
  22817. t['\u247B'] = '\u0028\u0038\u0029';
  22818. t['\u247C'] = '\u0028\u0039\u0029';
  22819. t['\u247D'] = '\u0028\u0031\u0030\u0029';
  22820. t['\u247E'] = '\u0028\u0031\u0031\u0029';
  22821. t['\u247F'] = '\u0028\u0031\u0032\u0029';
  22822. t['\u2480'] = '\u0028\u0031\u0033\u0029';
  22823. t['\u2481'] = '\u0028\u0031\u0034\u0029';
  22824. t['\u2482'] = '\u0028\u0031\u0035\u0029';
  22825. t['\u2483'] = '\u0028\u0031\u0036\u0029';
  22826. t['\u2484'] = '\u0028\u0031\u0037\u0029';
  22827. t['\u2485'] = '\u0028\u0031\u0038\u0029';
  22828. t['\u2486'] = '\u0028\u0031\u0039\u0029';
  22829. t['\u2487'] = '\u0028\u0032\u0030\u0029';
  22830. t['\u2488'] = '\u0031\u002E';
  22831. t['\u2489'] = '\u0032\u002E';
  22832. t['\u248A'] = '\u0033\u002E';
  22833. t['\u248B'] = '\u0034\u002E';
  22834. t['\u248C'] = '\u0035\u002E';
  22835. t['\u248D'] = '\u0036\u002E';
  22836. t['\u248E'] = '\u0037\u002E';
  22837. t['\u248F'] = '\u0038\u002E';
  22838. t['\u2490'] = '\u0039\u002E';
  22839. t['\u2491'] = '\u0031\u0030\u002E';
  22840. t['\u2492'] = '\u0031\u0031\u002E';
  22841. t['\u2493'] = '\u0031\u0032\u002E';
  22842. t['\u2494'] = '\u0031\u0033\u002E';
  22843. t['\u2495'] = '\u0031\u0034\u002E';
  22844. t['\u2496'] = '\u0031\u0035\u002E';
  22845. t['\u2497'] = '\u0031\u0036\u002E';
  22846. t['\u2498'] = '\u0031\u0037\u002E';
  22847. t['\u2499'] = '\u0031\u0038\u002E';
  22848. t['\u249A'] = '\u0031\u0039\u002E';
  22849. t['\u249B'] = '\u0032\u0030\u002E';
  22850. t['\u249C'] = '\u0028\u0061\u0029';
  22851. t['\u249D'] = '\u0028\u0062\u0029';
  22852. t['\u249E'] = '\u0028\u0063\u0029';
  22853. t['\u249F'] = '\u0028\u0064\u0029';
  22854. t['\u24A0'] = '\u0028\u0065\u0029';
  22855. t['\u24A1'] = '\u0028\u0066\u0029';
  22856. t['\u24A2'] = '\u0028\u0067\u0029';
  22857. t['\u24A3'] = '\u0028\u0068\u0029';
  22858. t['\u24A4'] = '\u0028\u0069\u0029';
  22859. t['\u24A5'] = '\u0028\u006A\u0029';
  22860. t['\u24A6'] = '\u0028\u006B\u0029';
  22861. t['\u24A7'] = '\u0028\u006C\u0029';
  22862. t['\u24A8'] = '\u0028\u006D\u0029';
  22863. t['\u24A9'] = '\u0028\u006E\u0029';
  22864. t['\u24AA'] = '\u0028\u006F\u0029';
  22865. t['\u24AB'] = '\u0028\u0070\u0029';
  22866. t['\u24AC'] = '\u0028\u0071\u0029';
  22867. t['\u24AD'] = '\u0028\u0072\u0029';
  22868. t['\u24AE'] = '\u0028\u0073\u0029';
  22869. t['\u24AF'] = '\u0028\u0074\u0029';
  22870. t['\u24B0'] = '\u0028\u0075\u0029';
  22871. t['\u24B1'] = '\u0028\u0076\u0029';
  22872. t['\u24B2'] = '\u0028\u0077\u0029';
  22873. t['\u24B3'] = '\u0028\u0078\u0029';
  22874. t['\u24B4'] = '\u0028\u0079\u0029';
  22875. t['\u24B5'] = '\u0028\u007A\u0029';
  22876. t['\u2A0C'] = '\u222B\u222B\u222B\u222B';
  22877. t['\u2A74'] = '\u003A\u003A\u003D';
  22878. t['\u2A75'] = '\u003D\u003D';
  22879. t['\u2A76'] = '\u003D\u003D\u003D';
  22880. t['\u2E9F'] = '\u6BCD';
  22881. t['\u2EF3'] = '\u9F9F';
  22882. t['\u2F00'] = '\u4E00';
  22883. t['\u2F01'] = '\u4E28';
  22884. t['\u2F02'] = '\u4E36';
  22885. t['\u2F03'] = '\u4E3F';
  22886. t['\u2F04'] = '\u4E59';
  22887. t['\u2F05'] = '\u4E85';
  22888. t['\u2F06'] = '\u4E8C';
  22889. t['\u2F07'] = '\u4EA0';
  22890. t['\u2F08'] = '\u4EBA';
  22891. t['\u2F09'] = '\u513F';
  22892. t['\u2F0A'] = '\u5165';
  22893. t['\u2F0B'] = '\u516B';
  22894. t['\u2F0C'] = '\u5182';
  22895. t['\u2F0D'] = '\u5196';
  22896. t['\u2F0E'] = '\u51AB';
  22897. t['\u2F0F'] = '\u51E0';
  22898. t['\u2F10'] = '\u51F5';
  22899. t['\u2F11'] = '\u5200';
  22900. t['\u2F12'] = '\u529B';
  22901. t['\u2F13'] = '\u52F9';
  22902. t['\u2F14'] = '\u5315';
  22903. t['\u2F15'] = '\u531A';
  22904. t['\u2F16'] = '\u5338';
  22905. t['\u2F17'] = '\u5341';
  22906. t['\u2F18'] = '\u535C';
  22907. t['\u2F19'] = '\u5369';
  22908. t['\u2F1A'] = '\u5382';
  22909. t['\u2F1B'] = '\u53B6';
  22910. t['\u2F1C'] = '\u53C8';
  22911. t['\u2F1D'] = '\u53E3';
  22912. t['\u2F1E'] = '\u56D7';
  22913. t['\u2F1F'] = '\u571F';
  22914. t['\u2F20'] = '\u58EB';
  22915. t['\u2F21'] = '\u5902';
  22916. t['\u2F22'] = '\u590A';
  22917. t['\u2F23'] = '\u5915';
  22918. t['\u2F24'] = '\u5927';
  22919. t['\u2F25'] = '\u5973';
  22920. t['\u2F26'] = '\u5B50';
  22921. t['\u2F27'] = '\u5B80';
  22922. t['\u2F28'] = '\u5BF8';
  22923. t['\u2F29'] = '\u5C0F';
  22924. t['\u2F2A'] = '\u5C22';
  22925. t['\u2F2B'] = '\u5C38';
  22926. t['\u2F2C'] = '\u5C6E';
  22927. t['\u2F2D'] = '\u5C71';
  22928. t['\u2F2E'] = '\u5DDB';
  22929. t['\u2F2F'] = '\u5DE5';
  22930. t['\u2F30'] = '\u5DF1';
  22931. t['\u2F31'] = '\u5DFE';
  22932. t['\u2F32'] = '\u5E72';
  22933. t['\u2F33'] = '\u5E7A';
  22934. t['\u2F34'] = '\u5E7F';
  22935. t['\u2F35'] = '\u5EF4';
  22936. t['\u2F36'] = '\u5EFE';
  22937. t['\u2F37'] = '\u5F0B';
  22938. t['\u2F38'] = '\u5F13';
  22939. t['\u2F39'] = '\u5F50';
  22940. t['\u2F3A'] = '\u5F61';
  22941. t['\u2F3B'] = '\u5F73';
  22942. t['\u2F3C'] = '\u5FC3';
  22943. t['\u2F3D'] = '\u6208';
  22944. t['\u2F3E'] = '\u6236';
  22945. t['\u2F3F'] = '\u624B';
  22946. t['\u2F40'] = '\u652F';
  22947. t['\u2F41'] = '\u6534';
  22948. t['\u2F42'] = '\u6587';
  22949. t['\u2F43'] = '\u6597';
  22950. t['\u2F44'] = '\u65A4';
  22951. t['\u2F45'] = '\u65B9';
  22952. t['\u2F46'] = '\u65E0';
  22953. t['\u2F47'] = '\u65E5';
  22954. t['\u2F48'] = '\u66F0';
  22955. t['\u2F49'] = '\u6708';
  22956. t['\u2F4A'] = '\u6728';
  22957. t['\u2F4B'] = '\u6B20';
  22958. t['\u2F4C'] = '\u6B62';
  22959. t['\u2F4D'] = '\u6B79';
  22960. t['\u2F4E'] = '\u6BB3';
  22961. t['\u2F4F'] = '\u6BCB';
  22962. t['\u2F50'] = '\u6BD4';
  22963. t['\u2F51'] = '\u6BDB';
  22964. t['\u2F52'] = '\u6C0F';
  22965. t['\u2F53'] = '\u6C14';
  22966. t['\u2F54'] = '\u6C34';
  22967. t['\u2F55'] = '\u706B';
  22968. t['\u2F56'] = '\u722A';
  22969. t['\u2F57'] = '\u7236';
  22970. t['\u2F58'] = '\u723B';
  22971. t['\u2F59'] = '\u723F';
  22972. t['\u2F5A'] = '\u7247';
  22973. t['\u2F5B'] = '\u7259';
  22974. t['\u2F5C'] = '\u725B';
  22975. t['\u2F5D'] = '\u72AC';
  22976. t['\u2F5E'] = '\u7384';
  22977. t['\u2F5F'] = '\u7389';
  22978. t['\u2F60'] = '\u74DC';
  22979. t['\u2F61'] = '\u74E6';
  22980. t['\u2F62'] = '\u7518';
  22981. t['\u2F63'] = '\u751F';
  22982. t['\u2F64'] = '\u7528';
  22983. t['\u2F65'] = '\u7530';
  22984. t['\u2F66'] = '\u758B';
  22985. t['\u2F67'] = '\u7592';
  22986. t['\u2F68'] = '\u7676';
  22987. t['\u2F69'] = '\u767D';
  22988. t['\u2F6A'] = '\u76AE';
  22989. t['\u2F6B'] = '\u76BF';
  22990. t['\u2F6C'] = '\u76EE';
  22991. t['\u2F6D'] = '\u77DB';
  22992. t['\u2F6E'] = '\u77E2';
  22993. t['\u2F6F'] = '\u77F3';
  22994. t['\u2F70'] = '\u793A';
  22995. t['\u2F71'] = '\u79B8';
  22996. t['\u2F72'] = '\u79BE';
  22997. t['\u2F73'] = '\u7A74';
  22998. t['\u2F74'] = '\u7ACB';
  22999. t['\u2F75'] = '\u7AF9';
  23000. t['\u2F76'] = '\u7C73';
  23001. t['\u2F77'] = '\u7CF8';
  23002. t['\u2F78'] = '\u7F36';
  23003. t['\u2F79'] = '\u7F51';
  23004. t['\u2F7A'] = '\u7F8A';
  23005. t['\u2F7B'] = '\u7FBD';
  23006. t['\u2F7C'] = '\u8001';
  23007. t['\u2F7D'] = '\u800C';
  23008. t['\u2F7E'] = '\u8012';
  23009. t['\u2F7F'] = '\u8033';
  23010. t['\u2F80'] = '\u807F';
  23011. t['\u2F81'] = '\u8089';
  23012. t['\u2F82'] = '\u81E3';
  23013. t['\u2F83'] = '\u81EA';
  23014. t['\u2F84'] = '\u81F3';
  23015. t['\u2F85'] = '\u81FC';
  23016. t['\u2F86'] = '\u820C';
  23017. t['\u2F87'] = '\u821B';
  23018. t['\u2F88'] = '\u821F';
  23019. t['\u2F89'] = '\u826E';
  23020. t['\u2F8A'] = '\u8272';
  23021. t['\u2F8B'] = '\u8278';
  23022. t['\u2F8C'] = '\u864D';
  23023. t['\u2F8D'] = '\u866B';
  23024. t['\u2F8E'] = '\u8840';
  23025. t['\u2F8F'] = '\u884C';
  23026. t['\u2F90'] = '\u8863';
  23027. t['\u2F91'] = '\u897E';
  23028. t['\u2F92'] = '\u898B';
  23029. t['\u2F93'] = '\u89D2';
  23030. t['\u2F94'] = '\u8A00';
  23031. t['\u2F95'] = '\u8C37';
  23032. t['\u2F96'] = '\u8C46';
  23033. t['\u2F97'] = '\u8C55';
  23034. t['\u2F98'] = '\u8C78';
  23035. t['\u2F99'] = '\u8C9D';
  23036. t['\u2F9A'] = '\u8D64';
  23037. t['\u2F9B'] = '\u8D70';
  23038. t['\u2F9C'] = '\u8DB3';
  23039. t['\u2F9D'] = '\u8EAB';
  23040. t['\u2F9E'] = '\u8ECA';
  23041. t['\u2F9F'] = '\u8F9B';
  23042. t['\u2FA0'] = '\u8FB0';
  23043. t['\u2FA1'] = '\u8FB5';
  23044. t['\u2FA2'] = '\u9091';
  23045. t['\u2FA3'] = '\u9149';
  23046. t['\u2FA4'] = '\u91C6';
  23047. t['\u2FA5'] = '\u91CC';
  23048. t['\u2FA6'] = '\u91D1';
  23049. t['\u2FA7'] = '\u9577';
  23050. t['\u2FA8'] = '\u9580';
  23051. t['\u2FA9'] = '\u961C';
  23052. t['\u2FAA'] = '\u96B6';
  23053. t['\u2FAB'] = '\u96B9';
  23054. t['\u2FAC'] = '\u96E8';
  23055. t['\u2FAD'] = '\u9751';
  23056. t['\u2FAE'] = '\u975E';
  23057. t['\u2FAF'] = '\u9762';
  23058. t['\u2FB0'] = '\u9769';
  23059. t['\u2FB1'] = '\u97CB';
  23060. t['\u2FB2'] = '\u97ED';
  23061. t['\u2FB3'] = '\u97F3';
  23062. t['\u2FB4'] = '\u9801';
  23063. t['\u2FB5'] = '\u98A8';
  23064. t['\u2FB6'] = '\u98DB';
  23065. t['\u2FB7'] = '\u98DF';
  23066. t['\u2FB8'] = '\u9996';
  23067. t['\u2FB9'] = '\u9999';
  23068. t['\u2FBA'] = '\u99AC';
  23069. t['\u2FBB'] = '\u9AA8';
  23070. t['\u2FBC'] = '\u9AD8';
  23071. t['\u2FBD'] = '\u9ADF';
  23072. t['\u2FBE'] = '\u9B25';
  23073. t['\u2FBF'] = '\u9B2F';
  23074. t['\u2FC0'] = '\u9B32';
  23075. t['\u2FC1'] = '\u9B3C';
  23076. t['\u2FC2'] = '\u9B5A';
  23077. t['\u2FC3'] = '\u9CE5';
  23078. t['\u2FC4'] = '\u9E75';
  23079. t['\u2FC5'] = '\u9E7F';
  23080. t['\u2FC6'] = '\u9EA5';
  23081. t['\u2FC7'] = '\u9EBB';
  23082. t['\u2FC8'] = '\u9EC3';
  23083. t['\u2FC9'] = '\u9ECD';
  23084. t['\u2FCA'] = '\u9ED1';
  23085. t['\u2FCB'] = '\u9EF9';
  23086. t['\u2FCC'] = '\u9EFD';
  23087. t['\u2FCD'] = '\u9F0E';
  23088. t['\u2FCE'] = '\u9F13';
  23089. t['\u2FCF'] = '\u9F20';
  23090. t['\u2FD0'] = '\u9F3B';
  23091. t['\u2FD1'] = '\u9F4A';
  23092. t['\u2FD2'] = '\u9F52';
  23093. t['\u2FD3'] = '\u9F8D';
  23094. t['\u2FD4'] = '\u9F9C';
  23095. t['\u2FD5'] = '\u9FA0';
  23096. t['\u3036'] = '\u3012';
  23097. t['\u3038'] = '\u5341';
  23098. t['\u3039'] = '\u5344';
  23099. t['\u303A'] = '\u5345';
  23100. t['\u309B'] = '\u0020\u3099';
  23101. t['\u309C'] = '\u0020\u309A';
  23102. t['\u3131'] = '\u1100';
  23103. t['\u3132'] = '\u1101';
  23104. t['\u3133'] = '\u11AA';
  23105. t['\u3134'] = '\u1102';
  23106. t['\u3135'] = '\u11AC';
  23107. t['\u3136'] = '\u11AD';
  23108. t['\u3137'] = '\u1103';
  23109. t['\u3138'] = '\u1104';
  23110. t['\u3139'] = '\u1105';
  23111. t['\u313A'] = '\u11B0';
  23112. t['\u313B'] = '\u11B1';
  23113. t['\u313C'] = '\u11B2';
  23114. t['\u313D'] = '\u11B3';
  23115. t['\u313E'] = '\u11B4';
  23116. t['\u313F'] = '\u11B5';
  23117. t['\u3140'] = '\u111A';
  23118. t['\u3141'] = '\u1106';
  23119. t['\u3142'] = '\u1107';
  23120. t['\u3143'] = '\u1108';
  23121. t['\u3144'] = '\u1121';
  23122. t['\u3145'] = '\u1109';
  23123. t['\u3146'] = '\u110A';
  23124. t['\u3147'] = '\u110B';
  23125. t['\u3148'] = '\u110C';
  23126. t['\u3149'] = '\u110D';
  23127. t['\u314A'] = '\u110E';
  23128. t['\u314B'] = '\u110F';
  23129. t['\u314C'] = '\u1110';
  23130. t['\u314D'] = '\u1111';
  23131. t['\u314E'] = '\u1112';
  23132. t['\u314F'] = '\u1161';
  23133. t['\u3150'] = '\u1162';
  23134. t['\u3151'] = '\u1163';
  23135. t['\u3152'] = '\u1164';
  23136. t['\u3153'] = '\u1165';
  23137. t['\u3154'] = '\u1166';
  23138. t['\u3155'] = '\u1167';
  23139. t['\u3156'] = '\u1168';
  23140. t['\u3157'] = '\u1169';
  23141. t['\u3158'] = '\u116A';
  23142. t['\u3159'] = '\u116B';
  23143. t['\u315A'] = '\u116C';
  23144. t['\u315B'] = '\u116D';
  23145. t['\u315C'] = '\u116E';
  23146. t['\u315D'] = '\u116F';
  23147. t['\u315E'] = '\u1170';
  23148. t['\u315F'] = '\u1171';
  23149. t['\u3160'] = '\u1172';
  23150. t['\u3161'] = '\u1173';
  23151. t['\u3162'] = '\u1174';
  23152. t['\u3163'] = '\u1175';
  23153. t['\u3164'] = '\u1160';
  23154. t['\u3165'] = '\u1114';
  23155. t['\u3166'] = '\u1115';
  23156. t['\u3167'] = '\u11C7';
  23157. t['\u3168'] = '\u11C8';
  23158. t['\u3169'] = '\u11CC';
  23159. t['\u316A'] = '\u11CE';
  23160. t['\u316B'] = '\u11D3';
  23161. t['\u316C'] = '\u11D7';
  23162. t['\u316D'] = '\u11D9';
  23163. t['\u316E'] = '\u111C';
  23164. t['\u316F'] = '\u11DD';
  23165. t['\u3170'] = '\u11DF';
  23166. t['\u3171'] = '\u111D';
  23167. t['\u3172'] = '\u111E';
  23168. t['\u3173'] = '\u1120';
  23169. t['\u3174'] = '\u1122';
  23170. t['\u3175'] = '\u1123';
  23171. t['\u3176'] = '\u1127';
  23172. t['\u3177'] = '\u1129';
  23173. t['\u3178'] = '\u112B';
  23174. t['\u3179'] = '\u112C';
  23175. t['\u317A'] = '\u112D';
  23176. t['\u317B'] = '\u112E';
  23177. t['\u317C'] = '\u112F';
  23178. t['\u317D'] = '\u1132';
  23179. t['\u317E'] = '\u1136';
  23180. t['\u317F'] = '\u1140';
  23181. t['\u3180'] = '\u1147';
  23182. t['\u3181'] = '\u114C';
  23183. t['\u3182'] = '\u11F1';
  23184. t['\u3183'] = '\u11F2';
  23185. t['\u3184'] = '\u1157';
  23186. t['\u3185'] = '\u1158';
  23187. t['\u3186'] = '\u1159';
  23188. t['\u3187'] = '\u1184';
  23189. t['\u3188'] = '\u1185';
  23190. t['\u3189'] = '\u1188';
  23191. t['\u318A'] = '\u1191';
  23192. t['\u318B'] = '\u1192';
  23193. t['\u318C'] = '\u1194';
  23194. t['\u318D'] = '\u119E';
  23195. t['\u318E'] = '\u11A1';
  23196. t['\u3200'] = '\u0028\u1100\u0029';
  23197. t['\u3201'] = '\u0028\u1102\u0029';
  23198. t['\u3202'] = '\u0028\u1103\u0029';
  23199. t['\u3203'] = '\u0028\u1105\u0029';
  23200. t['\u3204'] = '\u0028\u1106\u0029';
  23201. t['\u3205'] = '\u0028\u1107\u0029';
  23202. t['\u3206'] = '\u0028\u1109\u0029';
  23203. t['\u3207'] = '\u0028\u110B\u0029';
  23204. t['\u3208'] = '\u0028\u110C\u0029';
  23205. t['\u3209'] = '\u0028\u110E\u0029';
  23206. t['\u320A'] = '\u0028\u110F\u0029';
  23207. t['\u320B'] = '\u0028\u1110\u0029';
  23208. t['\u320C'] = '\u0028\u1111\u0029';
  23209. t['\u320D'] = '\u0028\u1112\u0029';
  23210. t['\u320E'] = '\u0028\u1100\u1161\u0029';
  23211. t['\u320F'] = '\u0028\u1102\u1161\u0029';
  23212. t['\u3210'] = '\u0028\u1103\u1161\u0029';
  23213. t['\u3211'] = '\u0028\u1105\u1161\u0029';
  23214. t['\u3212'] = '\u0028\u1106\u1161\u0029';
  23215. t['\u3213'] = '\u0028\u1107\u1161\u0029';
  23216. t['\u3214'] = '\u0028\u1109\u1161\u0029';
  23217. t['\u3215'] = '\u0028\u110B\u1161\u0029';
  23218. t['\u3216'] = '\u0028\u110C\u1161\u0029';
  23219. t['\u3217'] = '\u0028\u110E\u1161\u0029';
  23220. t['\u3218'] = '\u0028\u110F\u1161\u0029';
  23221. t['\u3219'] = '\u0028\u1110\u1161\u0029';
  23222. t['\u321A'] = '\u0028\u1111\u1161\u0029';
  23223. t['\u321B'] = '\u0028\u1112\u1161\u0029';
  23224. t['\u321C'] = '\u0028\u110C\u116E\u0029';
  23225. t['\u321D'] = '\u0028\u110B\u1169\u110C\u1165\u11AB\u0029';
  23226. t['\u321E'] = '\u0028\u110B\u1169\u1112\u116E\u0029';
  23227. t['\u3220'] = '\u0028\u4E00\u0029';
  23228. t['\u3221'] = '\u0028\u4E8C\u0029';
  23229. t['\u3222'] = '\u0028\u4E09\u0029';
  23230. t['\u3223'] = '\u0028\u56DB\u0029';
  23231. t['\u3224'] = '\u0028\u4E94\u0029';
  23232. t['\u3225'] = '\u0028\u516D\u0029';
  23233. t['\u3226'] = '\u0028\u4E03\u0029';
  23234. t['\u3227'] = '\u0028\u516B\u0029';
  23235. t['\u3228'] = '\u0028\u4E5D\u0029';
  23236. t['\u3229'] = '\u0028\u5341\u0029';
  23237. t['\u322A'] = '\u0028\u6708\u0029';
  23238. t['\u322B'] = '\u0028\u706B\u0029';
  23239. t['\u322C'] = '\u0028\u6C34\u0029';
  23240. t['\u322D'] = '\u0028\u6728\u0029';
  23241. t['\u322E'] = '\u0028\u91D1\u0029';
  23242. t['\u322F'] = '\u0028\u571F\u0029';
  23243. t['\u3230'] = '\u0028\u65E5\u0029';
  23244. t['\u3231'] = '\u0028\u682A\u0029';
  23245. t['\u3232'] = '\u0028\u6709\u0029';
  23246. t['\u3233'] = '\u0028\u793E\u0029';
  23247. t['\u3234'] = '\u0028\u540D\u0029';
  23248. t['\u3235'] = '\u0028\u7279\u0029';
  23249. t['\u3236'] = '\u0028\u8CA1\u0029';
  23250. t['\u3237'] = '\u0028\u795D\u0029';
  23251. t['\u3238'] = '\u0028\u52B4\u0029';
  23252. t['\u3239'] = '\u0028\u4EE3\u0029';
  23253. t['\u323A'] = '\u0028\u547C\u0029';
  23254. t['\u323B'] = '\u0028\u5B66\u0029';
  23255. t['\u323C'] = '\u0028\u76E3\u0029';
  23256. t['\u323D'] = '\u0028\u4F01\u0029';
  23257. t['\u323E'] = '\u0028\u8CC7\u0029';
  23258. t['\u323F'] = '\u0028\u5354\u0029';
  23259. t['\u3240'] = '\u0028\u796D\u0029';
  23260. t['\u3241'] = '\u0028\u4F11\u0029';
  23261. t['\u3242'] = '\u0028\u81EA\u0029';
  23262. t['\u3243'] = '\u0028\u81F3\u0029';
  23263. t['\u32C0'] = '\u0031\u6708';
  23264. t['\u32C1'] = '\u0032\u6708';
  23265. t['\u32C2'] = '\u0033\u6708';
  23266. t['\u32C3'] = '\u0034\u6708';
  23267. t['\u32C4'] = '\u0035\u6708';
  23268. t['\u32C5'] = '\u0036\u6708';
  23269. t['\u32C6'] = '\u0037\u6708';
  23270. t['\u32C7'] = '\u0038\u6708';
  23271. t['\u32C8'] = '\u0039\u6708';
  23272. t['\u32C9'] = '\u0031\u0030\u6708';
  23273. t['\u32CA'] = '\u0031\u0031\u6708';
  23274. t['\u32CB'] = '\u0031\u0032\u6708';
  23275. t['\u3358'] = '\u0030\u70B9';
  23276. t['\u3359'] = '\u0031\u70B9';
  23277. t['\u335A'] = '\u0032\u70B9';
  23278. t['\u335B'] = '\u0033\u70B9';
  23279. t['\u335C'] = '\u0034\u70B9';
  23280. t['\u335D'] = '\u0035\u70B9';
  23281. t['\u335E'] = '\u0036\u70B9';
  23282. t['\u335F'] = '\u0037\u70B9';
  23283. t['\u3360'] = '\u0038\u70B9';
  23284. t['\u3361'] = '\u0039\u70B9';
  23285. t['\u3362'] = '\u0031\u0030\u70B9';
  23286. t['\u3363'] = '\u0031\u0031\u70B9';
  23287. t['\u3364'] = '\u0031\u0032\u70B9';
  23288. t['\u3365'] = '\u0031\u0033\u70B9';
  23289. t['\u3366'] = '\u0031\u0034\u70B9';
  23290. t['\u3367'] = '\u0031\u0035\u70B9';
  23291. t['\u3368'] = '\u0031\u0036\u70B9';
  23292. t['\u3369'] = '\u0031\u0037\u70B9';
  23293. t['\u336A'] = '\u0031\u0038\u70B9';
  23294. t['\u336B'] = '\u0031\u0039\u70B9';
  23295. t['\u336C'] = '\u0032\u0030\u70B9';
  23296. t['\u336D'] = '\u0032\u0031\u70B9';
  23297. t['\u336E'] = '\u0032\u0032\u70B9';
  23298. t['\u336F'] = '\u0032\u0033\u70B9';
  23299. t['\u3370'] = '\u0032\u0034\u70B9';
  23300. t['\u33E0'] = '\u0031\u65E5';
  23301. t['\u33E1'] = '\u0032\u65E5';
  23302. t['\u33E2'] = '\u0033\u65E5';
  23303. t['\u33E3'] = '\u0034\u65E5';
  23304. t['\u33E4'] = '\u0035\u65E5';
  23305. t['\u33E5'] = '\u0036\u65E5';
  23306. t['\u33E6'] = '\u0037\u65E5';
  23307. t['\u33E7'] = '\u0038\u65E5';
  23308. t['\u33E8'] = '\u0039\u65E5';
  23309. t['\u33E9'] = '\u0031\u0030\u65E5';
  23310. t['\u33EA'] = '\u0031\u0031\u65E5';
  23311. t['\u33EB'] = '\u0031\u0032\u65E5';
  23312. t['\u33EC'] = '\u0031\u0033\u65E5';
  23313. t['\u33ED'] = '\u0031\u0034\u65E5';
  23314. t['\u33EE'] = '\u0031\u0035\u65E5';
  23315. t['\u33EF'] = '\u0031\u0036\u65E5';
  23316. t['\u33F0'] = '\u0031\u0037\u65E5';
  23317. t['\u33F1'] = '\u0031\u0038\u65E5';
  23318. t['\u33F2'] = '\u0031\u0039\u65E5';
  23319. t['\u33F3'] = '\u0032\u0030\u65E5';
  23320. t['\u33F4'] = '\u0032\u0031\u65E5';
  23321. t['\u33F5'] = '\u0032\u0032\u65E5';
  23322. t['\u33F6'] = '\u0032\u0033\u65E5';
  23323. t['\u33F7'] = '\u0032\u0034\u65E5';
  23324. t['\u33F8'] = '\u0032\u0035\u65E5';
  23325. t['\u33F9'] = '\u0032\u0036\u65E5';
  23326. t['\u33FA'] = '\u0032\u0037\u65E5';
  23327. t['\u33FB'] = '\u0032\u0038\u65E5';
  23328. t['\u33FC'] = '\u0032\u0039\u65E5';
  23329. t['\u33FD'] = '\u0033\u0030\u65E5';
  23330. t['\u33FE'] = '\u0033\u0031\u65E5';
  23331. t['\uFB00'] = '\u0066\u0066';
  23332. t['\uFB01'] = '\u0066\u0069';
  23333. t['\uFB02'] = '\u0066\u006C';
  23334. t['\uFB03'] = '\u0066\u0066\u0069';
  23335. t['\uFB04'] = '\u0066\u0066\u006C';
  23336. t['\uFB05'] = '\u017F\u0074';
  23337. t['\uFB06'] = '\u0073\u0074';
  23338. t['\uFB13'] = '\u0574\u0576';
  23339. t['\uFB14'] = '\u0574\u0565';
  23340. t['\uFB15'] = '\u0574\u056B';
  23341. t['\uFB16'] = '\u057E\u0576';
  23342. t['\uFB17'] = '\u0574\u056D';
  23343. t['\uFB4F'] = '\u05D0\u05DC';
  23344. t['\uFB50'] = '\u0671';
  23345. t['\uFB51'] = '\u0671';
  23346. t['\uFB52'] = '\u067B';
  23347. t['\uFB53'] = '\u067B';
  23348. t['\uFB54'] = '\u067B';
  23349. t['\uFB55'] = '\u067B';
  23350. t['\uFB56'] = '\u067E';
  23351. t['\uFB57'] = '\u067E';
  23352. t['\uFB58'] = '\u067E';
  23353. t['\uFB59'] = '\u067E';
  23354. t['\uFB5A'] = '\u0680';
  23355. t['\uFB5B'] = '\u0680';
  23356. t['\uFB5C'] = '\u0680';
  23357. t['\uFB5D'] = '\u0680';
  23358. t['\uFB5E'] = '\u067A';
  23359. t['\uFB5F'] = '\u067A';
  23360. t['\uFB60'] = '\u067A';
  23361. t['\uFB61'] = '\u067A';
  23362. t['\uFB62'] = '\u067F';
  23363. t['\uFB63'] = '\u067F';
  23364. t['\uFB64'] = '\u067F';
  23365. t['\uFB65'] = '\u067F';
  23366. t['\uFB66'] = '\u0679';
  23367. t['\uFB67'] = '\u0679';
  23368. t['\uFB68'] = '\u0679';
  23369. t['\uFB69'] = '\u0679';
  23370. t['\uFB6A'] = '\u06A4';
  23371. t['\uFB6B'] = '\u06A4';
  23372. t['\uFB6C'] = '\u06A4';
  23373. t['\uFB6D'] = '\u06A4';
  23374. t['\uFB6E'] = '\u06A6';
  23375. t['\uFB6F'] = '\u06A6';
  23376. t['\uFB70'] = '\u06A6';
  23377. t['\uFB71'] = '\u06A6';
  23378. t['\uFB72'] = '\u0684';
  23379. t['\uFB73'] = '\u0684';
  23380. t['\uFB74'] = '\u0684';
  23381. t['\uFB75'] = '\u0684';
  23382. t['\uFB76'] = '\u0683';
  23383. t['\uFB77'] = '\u0683';
  23384. t['\uFB78'] = '\u0683';
  23385. t['\uFB79'] = '\u0683';
  23386. t['\uFB7A'] = '\u0686';
  23387. t['\uFB7B'] = '\u0686';
  23388. t['\uFB7C'] = '\u0686';
  23389. t['\uFB7D'] = '\u0686';
  23390. t['\uFB7E'] = '\u0687';
  23391. t['\uFB7F'] = '\u0687';
  23392. t['\uFB80'] = '\u0687';
  23393. t['\uFB81'] = '\u0687';
  23394. t['\uFB82'] = '\u068D';
  23395. t['\uFB83'] = '\u068D';
  23396. t['\uFB84'] = '\u068C';
  23397. t['\uFB85'] = '\u068C';
  23398. t['\uFB86'] = '\u068E';
  23399. t['\uFB87'] = '\u068E';
  23400. t['\uFB88'] = '\u0688';
  23401. t['\uFB89'] = '\u0688';
  23402. t['\uFB8A'] = '\u0698';
  23403. t['\uFB8B'] = '\u0698';
  23404. t['\uFB8C'] = '\u0691';
  23405. t['\uFB8D'] = '\u0691';
  23406. t['\uFB8E'] = '\u06A9';
  23407. t['\uFB8F'] = '\u06A9';
  23408. t['\uFB90'] = '\u06A9';
  23409. t['\uFB91'] = '\u06A9';
  23410. t['\uFB92'] = '\u06AF';
  23411. t['\uFB93'] = '\u06AF';
  23412. t['\uFB94'] = '\u06AF';
  23413. t['\uFB95'] = '\u06AF';
  23414. t['\uFB96'] = '\u06B3';
  23415. t['\uFB97'] = '\u06B3';
  23416. t['\uFB98'] = '\u06B3';
  23417. t['\uFB99'] = '\u06B3';
  23418. t['\uFB9A'] = '\u06B1';
  23419. t['\uFB9B'] = '\u06B1';
  23420. t['\uFB9C'] = '\u06B1';
  23421. t['\uFB9D'] = '\u06B1';
  23422. t['\uFB9E'] = '\u06BA';
  23423. t['\uFB9F'] = '\u06BA';
  23424. t['\uFBA0'] = '\u06BB';
  23425. t['\uFBA1'] = '\u06BB';
  23426. t['\uFBA2'] = '\u06BB';
  23427. t['\uFBA3'] = '\u06BB';
  23428. t['\uFBA4'] = '\u06C0';
  23429. t['\uFBA5'] = '\u06C0';
  23430. t['\uFBA6'] = '\u06C1';
  23431. t['\uFBA7'] = '\u06C1';
  23432. t['\uFBA8'] = '\u06C1';
  23433. t['\uFBA9'] = '\u06C1';
  23434. t['\uFBAA'] = '\u06BE';
  23435. t['\uFBAB'] = '\u06BE';
  23436. t['\uFBAC'] = '\u06BE';
  23437. t['\uFBAD'] = '\u06BE';
  23438. t['\uFBAE'] = '\u06D2';
  23439. t['\uFBAF'] = '\u06D2';
  23440. t['\uFBB0'] = '\u06D3';
  23441. t['\uFBB1'] = '\u06D3';
  23442. t['\uFBD3'] = '\u06AD';
  23443. t['\uFBD4'] = '\u06AD';
  23444. t['\uFBD5'] = '\u06AD';
  23445. t['\uFBD6'] = '\u06AD';
  23446. t['\uFBD7'] = '\u06C7';
  23447. t['\uFBD8'] = '\u06C7';
  23448. t['\uFBD9'] = '\u06C6';
  23449. t['\uFBDA'] = '\u06C6';
  23450. t['\uFBDB'] = '\u06C8';
  23451. t['\uFBDC'] = '\u06C8';
  23452. t['\uFBDD'] = '\u0677';
  23453. t['\uFBDE'] = '\u06CB';
  23454. t['\uFBDF'] = '\u06CB';
  23455. t['\uFBE0'] = '\u06C5';
  23456. t['\uFBE1'] = '\u06C5';
  23457. t['\uFBE2'] = '\u06C9';
  23458. t['\uFBE3'] = '\u06C9';
  23459. t['\uFBE4'] = '\u06D0';
  23460. t['\uFBE5'] = '\u06D0';
  23461. t['\uFBE6'] = '\u06D0';
  23462. t['\uFBE7'] = '\u06D0';
  23463. t['\uFBE8'] = '\u0649';
  23464. t['\uFBE9'] = '\u0649';
  23465. t['\uFBEA'] = '\u0626\u0627';
  23466. t['\uFBEB'] = '\u0626\u0627';
  23467. t['\uFBEC'] = '\u0626\u06D5';
  23468. t['\uFBED'] = '\u0626\u06D5';
  23469. t['\uFBEE'] = '\u0626\u0648';
  23470. t['\uFBEF'] = '\u0626\u0648';
  23471. t['\uFBF0'] = '\u0626\u06C7';
  23472. t['\uFBF1'] = '\u0626\u06C7';
  23473. t['\uFBF2'] = '\u0626\u06C6';
  23474. t['\uFBF3'] = '\u0626\u06C6';
  23475. t['\uFBF4'] = '\u0626\u06C8';
  23476. t['\uFBF5'] = '\u0626\u06C8';
  23477. t['\uFBF6'] = '\u0626\u06D0';
  23478. t['\uFBF7'] = '\u0626\u06D0';
  23479. t['\uFBF8'] = '\u0626\u06D0';
  23480. t['\uFBF9'] = '\u0626\u0649';
  23481. t['\uFBFA'] = '\u0626\u0649';
  23482. t['\uFBFB'] = '\u0626\u0649';
  23483. t['\uFBFC'] = '\u06CC';
  23484. t['\uFBFD'] = '\u06CC';
  23485. t['\uFBFE'] = '\u06CC';
  23486. t['\uFBFF'] = '\u06CC';
  23487. t['\uFC00'] = '\u0626\u062C';
  23488. t['\uFC01'] = '\u0626\u062D';
  23489. t['\uFC02'] = '\u0626\u0645';
  23490. t['\uFC03'] = '\u0626\u0649';
  23491. t['\uFC04'] = '\u0626\u064A';
  23492. t['\uFC05'] = '\u0628\u062C';
  23493. t['\uFC06'] = '\u0628\u062D';
  23494. t['\uFC07'] = '\u0628\u062E';
  23495. t['\uFC08'] = '\u0628\u0645';
  23496. t['\uFC09'] = '\u0628\u0649';
  23497. t['\uFC0A'] = '\u0628\u064A';
  23498. t['\uFC0B'] = '\u062A\u062C';
  23499. t['\uFC0C'] = '\u062A\u062D';
  23500. t['\uFC0D'] = '\u062A\u062E';
  23501. t['\uFC0E'] = '\u062A\u0645';
  23502. t['\uFC0F'] = '\u062A\u0649';
  23503. t['\uFC10'] = '\u062A\u064A';
  23504. t['\uFC11'] = '\u062B\u062C';
  23505. t['\uFC12'] = '\u062B\u0645';
  23506. t['\uFC13'] = '\u062B\u0649';
  23507. t['\uFC14'] = '\u062B\u064A';
  23508. t['\uFC15'] = '\u062C\u062D';
  23509. t['\uFC16'] = '\u062C\u0645';
  23510. t['\uFC17'] = '\u062D\u062C';
  23511. t['\uFC18'] = '\u062D\u0645';
  23512. t['\uFC19'] = '\u062E\u062C';
  23513. t['\uFC1A'] = '\u062E\u062D';
  23514. t['\uFC1B'] = '\u062E\u0645';
  23515. t['\uFC1C'] = '\u0633\u062C';
  23516. t['\uFC1D'] = '\u0633\u062D';
  23517. t['\uFC1E'] = '\u0633\u062E';
  23518. t['\uFC1F'] = '\u0633\u0645';
  23519. t['\uFC20'] = '\u0635\u062D';
  23520. t['\uFC21'] = '\u0635\u0645';
  23521. t['\uFC22'] = '\u0636\u062C';
  23522. t['\uFC23'] = '\u0636\u062D';
  23523. t['\uFC24'] = '\u0636\u062E';
  23524. t['\uFC25'] = '\u0636\u0645';
  23525. t['\uFC26'] = '\u0637\u062D';
  23526. t['\uFC27'] = '\u0637\u0645';
  23527. t['\uFC28'] = '\u0638\u0645';
  23528. t['\uFC29'] = '\u0639\u062C';
  23529. t['\uFC2A'] = '\u0639\u0645';
  23530. t['\uFC2B'] = '\u063A\u062C';
  23531. t['\uFC2C'] = '\u063A\u0645';
  23532. t['\uFC2D'] = '\u0641\u062C';
  23533. t['\uFC2E'] = '\u0641\u062D';
  23534. t['\uFC2F'] = '\u0641\u062E';
  23535. t['\uFC30'] = '\u0641\u0645';
  23536. t['\uFC31'] = '\u0641\u0649';
  23537. t['\uFC32'] = '\u0641\u064A';
  23538. t['\uFC33'] = '\u0642\u062D';
  23539. t['\uFC34'] = '\u0642\u0645';
  23540. t['\uFC35'] = '\u0642\u0649';
  23541. t['\uFC36'] = '\u0642\u064A';
  23542. t['\uFC37'] = '\u0643\u0627';
  23543. t['\uFC38'] = '\u0643\u062C';
  23544. t['\uFC39'] = '\u0643\u062D';
  23545. t['\uFC3A'] = '\u0643\u062E';
  23546. t['\uFC3B'] = '\u0643\u0644';
  23547. t['\uFC3C'] = '\u0643\u0645';
  23548. t['\uFC3D'] = '\u0643\u0649';
  23549. t['\uFC3E'] = '\u0643\u064A';
  23550. t['\uFC3F'] = '\u0644\u062C';
  23551. t['\uFC40'] = '\u0644\u062D';
  23552. t['\uFC41'] = '\u0644\u062E';
  23553. t['\uFC42'] = '\u0644\u0645';
  23554. t['\uFC43'] = '\u0644\u0649';
  23555. t['\uFC44'] = '\u0644\u064A';
  23556. t['\uFC45'] = '\u0645\u062C';
  23557. t['\uFC46'] = '\u0645\u062D';
  23558. t['\uFC47'] = '\u0645\u062E';
  23559. t['\uFC48'] = '\u0645\u0645';
  23560. t['\uFC49'] = '\u0645\u0649';
  23561. t['\uFC4A'] = '\u0645\u064A';
  23562. t['\uFC4B'] = '\u0646\u062C';
  23563. t['\uFC4C'] = '\u0646\u062D';
  23564. t['\uFC4D'] = '\u0646\u062E';
  23565. t['\uFC4E'] = '\u0646\u0645';
  23566. t['\uFC4F'] = '\u0646\u0649';
  23567. t['\uFC50'] = '\u0646\u064A';
  23568. t['\uFC51'] = '\u0647\u062C';
  23569. t['\uFC52'] = '\u0647\u0645';
  23570. t['\uFC53'] = '\u0647\u0649';
  23571. t['\uFC54'] = '\u0647\u064A';
  23572. t['\uFC55'] = '\u064A\u062C';
  23573. t['\uFC56'] = '\u064A\u062D';
  23574. t['\uFC57'] = '\u064A\u062E';
  23575. t['\uFC58'] = '\u064A\u0645';
  23576. t['\uFC59'] = '\u064A\u0649';
  23577. t['\uFC5A'] = '\u064A\u064A';
  23578. t['\uFC5B'] = '\u0630\u0670';
  23579. t['\uFC5C'] = '\u0631\u0670';
  23580. t['\uFC5D'] = '\u0649\u0670';
  23581. t['\uFC5E'] = '\u0020\u064C\u0651';
  23582. t['\uFC5F'] = '\u0020\u064D\u0651';
  23583. t['\uFC60'] = '\u0020\u064E\u0651';
  23584. t['\uFC61'] = '\u0020\u064F\u0651';
  23585. t['\uFC62'] = '\u0020\u0650\u0651';
  23586. t['\uFC63'] = '\u0020\u0651\u0670';
  23587. t['\uFC64'] = '\u0626\u0631';
  23588. t['\uFC65'] = '\u0626\u0632';
  23589. t['\uFC66'] = '\u0626\u0645';
  23590. t['\uFC67'] = '\u0626\u0646';
  23591. t['\uFC68'] = '\u0626\u0649';
  23592. t['\uFC69'] = '\u0626\u064A';
  23593. t['\uFC6A'] = '\u0628\u0631';
  23594. t['\uFC6B'] = '\u0628\u0632';
  23595. t['\uFC6C'] = '\u0628\u0645';
  23596. t['\uFC6D'] = '\u0628\u0646';
  23597. t['\uFC6E'] = '\u0628\u0649';
  23598. t['\uFC6F'] = '\u0628\u064A';
  23599. t['\uFC70'] = '\u062A\u0631';
  23600. t['\uFC71'] = '\u062A\u0632';
  23601. t['\uFC72'] = '\u062A\u0645';
  23602. t['\uFC73'] = '\u062A\u0646';
  23603. t['\uFC74'] = '\u062A\u0649';
  23604. t['\uFC75'] = '\u062A\u064A';
  23605. t['\uFC76'] = '\u062B\u0631';
  23606. t['\uFC77'] = '\u062B\u0632';
  23607. t['\uFC78'] = '\u062B\u0645';
  23608. t['\uFC79'] = '\u062B\u0646';
  23609. t['\uFC7A'] = '\u062B\u0649';
  23610. t['\uFC7B'] = '\u062B\u064A';
  23611. t['\uFC7C'] = '\u0641\u0649';
  23612. t['\uFC7D'] = '\u0641\u064A';
  23613. t['\uFC7E'] = '\u0642\u0649';
  23614. t['\uFC7F'] = '\u0642\u064A';
  23615. t['\uFC80'] = '\u0643\u0627';
  23616. t['\uFC81'] = '\u0643\u0644';
  23617. t['\uFC82'] = '\u0643\u0645';
  23618. t['\uFC83'] = '\u0643\u0649';
  23619. t['\uFC84'] = '\u0643\u064A';
  23620. t['\uFC85'] = '\u0644\u0645';
  23621. t['\uFC86'] = '\u0644\u0649';
  23622. t['\uFC87'] = '\u0644\u064A';
  23623. t['\uFC88'] = '\u0645\u0627';
  23624. t['\uFC89'] = '\u0645\u0645';
  23625. t['\uFC8A'] = '\u0646\u0631';
  23626. t['\uFC8B'] = '\u0646\u0632';
  23627. t['\uFC8C'] = '\u0646\u0645';
  23628. t['\uFC8D'] = '\u0646\u0646';
  23629. t['\uFC8E'] = '\u0646\u0649';
  23630. t['\uFC8F'] = '\u0646\u064A';
  23631. t['\uFC90'] = '\u0649\u0670';
  23632. t['\uFC91'] = '\u064A\u0631';
  23633. t['\uFC92'] = '\u064A\u0632';
  23634. t['\uFC93'] = '\u064A\u0645';
  23635. t['\uFC94'] = '\u064A\u0646';
  23636. t['\uFC95'] = '\u064A\u0649';
  23637. t['\uFC96'] = '\u064A\u064A';
  23638. t['\uFC97'] = '\u0626\u062C';
  23639. t['\uFC98'] = '\u0626\u062D';
  23640. t['\uFC99'] = '\u0626\u062E';
  23641. t['\uFC9A'] = '\u0626\u0645';
  23642. t['\uFC9B'] = '\u0626\u0647';
  23643. t['\uFC9C'] = '\u0628\u062C';
  23644. t['\uFC9D'] = '\u0628\u062D';
  23645. t['\uFC9E'] = '\u0628\u062E';
  23646. t['\uFC9F'] = '\u0628\u0645';
  23647. t['\uFCA0'] = '\u0628\u0647';
  23648. t['\uFCA1'] = '\u062A\u062C';
  23649. t['\uFCA2'] = '\u062A\u062D';
  23650. t['\uFCA3'] = '\u062A\u062E';
  23651. t['\uFCA4'] = '\u062A\u0645';
  23652. t['\uFCA5'] = '\u062A\u0647';
  23653. t['\uFCA6'] = '\u062B\u0645';
  23654. t['\uFCA7'] = '\u062C\u062D';
  23655. t['\uFCA8'] = '\u062C\u0645';
  23656. t['\uFCA9'] = '\u062D\u062C';
  23657. t['\uFCAA'] = '\u062D\u0645';
  23658. t['\uFCAB'] = '\u062E\u062C';
  23659. t['\uFCAC'] = '\u062E\u0645';
  23660. t['\uFCAD'] = '\u0633\u062C';
  23661. t['\uFCAE'] = '\u0633\u062D';
  23662. t['\uFCAF'] = '\u0633\u062E';
  23663. t['\uFCB0'] = '\u0633\u0645';
  23664. t['\uFCB1'] = '\u0635\u062D';
  23665. t['\uFCB2'] = '\u0635\u062E';
  23666. t['\uFCB3'] = '\u0635\u0645';
  23667. t['\uFCB4'] = '\u0636\u062C';
  23668. t['\uFCB5'] = '\u0636\u062D';
  23669. t['\uFCB6'] = '\u0636\u062E';
  23670. t['\uFCB7'] = '\u0636\u0645';
  23671. t['\uFCB8'] = '\u0637\u062D';
  23672. t['\uFCB9'] = '\u0638\u0645';
  23673. t['\uFCBA'] = '\u0639\u062C';
  23674. t['\uFCBB'] = '\u0639\u0645';
  23675. t['\uFCBC'] = '\u063A\u062C';
  23676. t['\uFCBD'] = '\u063A\u0645';
  23677. t['\uFCBE'] = '\u0641\u062C';
  23678. t['\uFCBF'] = '\u0641\u062D';
  23679. t['\uFCC0'] = '\u0641\u062E';
  23680. t['\uFCC1'] = '\u0641\u0645';
  23681. t['\uFCC2'] = '\u0642\u062D';
  23682. t['\uFCC3'] = '\u0642\u0645';
  23683. t['\uFCC4'] = '\u0643\u062C';
  23684. t['\uFCC5'] = '\u0643\u062D';
  23685. t['\uFCC6'] = '\u0643\u062E';
  23686. t['\uFCC7'] = '\u0643\u0644';
  23687. t['\uFCC8'] = '\u0643\u0645';
  23688. t['\uFCC9'] = '\u0644\u062C';
  23689. t['\uFCCA'] = '\u0644\u062D';
  23690. t['\uFCCB'] = '\u0644\u062E';
  23691. t['\uFCCC'] = '\u0644\u0645';
  23692. t['\uFCCD'] = '\u0644\u0647';
  23693. t['\uFCCE'] = '\u0645\u062C';
  23694. t['\uFCCF'] = '\u0645\u062D';
  23695. t['\uFCD0'] = '\u0645\u062E';
  23696. t['\uFCD1'] = '\u0645\u0645';
  23697. t['\uFCD2'] = '\u0646\u062C';
  23698. t['\uFCD3'] = '\u0646\u062D';
  23699. t['\uFCD4'] = '\u0646\u062E';
  23700. t['\uFCD5'] = '\u0646\u0645';
  23701. t['\uFCD6'] = '\u0646\u0647';
  23702. t['\uFCD7'] = '\u0647\u062C';
  23703. t['\uFCD8'] = '\u0647\u0645';
  23704. t['\uFCD9'] = '\u0647\u0670';
  23705. t['\uFCDA'] = '\u064A\u062C';
  23706. t['\uFCDB'] = '\u064A\u062D';
  23707. t['\uFCDC'] = '\u064A\u062E';
  23708. t['\uFCDD'] = '\u064A\u0645';
  23709. t['\uFCDE'] = '\u064A\u0647';
  23710. t['\uFCDF'] = '\u0626\u0645';
  23711. t['\uFCE0'] = '\u0626\u0647';
  23712. t['\uFCE1'] = '\u0628\u0645';
  23713. t['\uFCE2'] = '\u0628\u0647';
  23714. t['\uFCE3'] = '\u062A\u0645';
  23715. t['\uFCE4'] = '\u062A\u0647';
  23716. t['\uFCE5'] = '\u062B\u0645';
  23717. t['\uFCE6'] = '\u062B\u0647';
  23718. t['\uFCE7'] = '\u0633\u0645';
  23719. t['\uFCE8'] = '\u0633\u0647';
  23720. t['\uFCE9'] = '\u0634\u0645';
  23721. t['\uFCEA'] = '\u0634\u0647';
  23722. t['\uFCEB'] = '\u0643\u0644';
  23723. t['\uFCEC'] = '\u0643\u0645';
  23724. t['\uFCED'] = '\u0644\u0645';
  23725. t['\uFCEE'] = '\u0646\u0645';
  23726. t['\uFCEF'] = '\u0646\u0647';
  23727. t['\uFCF0'] = '\u064A\u0645';
  23728. t['\uFCF1'] = '\u064A\u0647';
  23729. t['\uFCF2'] = '\u0640\u064E\u0651';
  23730. t['\uFCF3'] = '\u0640\u064F\u0651';
  23731. t['\uFCF4'] = '\u0640\u0650\u0651';
  23732. t['\uFCF5'] = '\u0637\u0649';
  23733. t['\uFCF6'] = '\u0637\u064A';
  23734. t['\uFCF7'] = '\u0639\u0649';
  23735. t['\uFCF8'] = '\u0639\u064A';
  23736. t['\uFCF9'] = '\u063A\u0649';
  23737. t['\uFCFA'] = '\u063A\u064A';
  23738. t['\uFCFB'] = '\u0633\u0649';
  23739. t['\uFCFC'] = '\u0633\u064A';
  23740. t['\uFCFD'] = '\u0634\u0649';
  23741. t['\uFCFE'] = '\u0634\u064A';
  23742. t['\uFCFF'] = '\u062D\u0649';
  23743. t['\uFD00'] = '\u062D\u064A';
  23744. t['\uFD01'] = '\u062C\u0649';
  23745. t['\uFD02'] = '\u062C\u064A';
  23746. t['\uFD03'] = '\u062E\u0649';
  23747. t['\uFD04'] = '\u062E\u064A';
  23748. t['\uFD05'] = '\u0635\u0649';
  23749. t['\uFD06'] = '\u0635\u064A';
  23750. t['\uFD07'] = '\u0636\u0649';
  23751. t['\uFD08'] = '\u0636\u064A';
  23752. t['\uFD09'] = '\u0634\u062C';
  23753. t['\uFD0A'] = '\u0634\u062D';
  23754. t['\uFD0B'] = '\u0634\u062E';
  23755. t['\uFD0C'] = '\u0634\u0645';
  23756. t['\uFD0D'] = '\u0634\u0631';
  23757. t['\uFD0E'] = '\u0633\u0631';
  23758. t['\uFD0F'] = '\u0635\u0631';
  23759. t['\uFD10'] = '\u0636\u0631';
  23760. t['\uFD11'] = '\u0637\u0649';
  23761. t['\uFD12'] = '\u0637\u064A';
  23762. t['\uFD13'] = '\u0639\u0649';
  23763. t['\uFD14'] = '\u0639\u064A';
  23764. t['\uFD15'] = '\u063A\u0649';
  23765. t['\uFD16'] = '\u063A\u064A';
  23766. t['\uFD17'] = '\u0633\u0649';
  23767. t['\uFD18'] = '\u0633\u064A';
  23768. t['\uFD19'] = '\u0634\u0649';
  23769. t['\uFD1A'] = '\u0634\u064A';
  23770. t['\uFD1B'] = '\u062D\u0649';
  23771. t['\uFD1C'] = '\u062D\u064A';
  23772. t['\uFD1D'] = '\u062C\u0649';
  23773. t['\uFD1E'] = '\u062C\u064A';
  23774. t['\uFD1F'] = '\u062E\u0649';
  23775. t['\uFD20'] = '\u062E\u064A';
  23776. t['\uFD21'] = '\u0635\u0649';
  23777. t['\uFD22'] = '\u0635\u064A';
  23778. t['\uFD23'] = '\u0636\u0649';
  23779. t['\uFD24'] = '\u0636\u064A';
  23780. t['\uFD25'] = '\u0634\u062C';
  23781. t['\uFD26'] = '\u0634\u062D';
  23782. t['\uFD27'] = '\u0634\u062E';
  23783. t['\uFD28'] = '\u0634\u0645';
  23784. t['\uFD29'] = '\u0634\u0631';
  23785. t['\uFD2A'] = '\u0633\u0631';
  23786. t['\uFD2B'] = '\u0635\u0631';
  23787. t['\uFD2C'] = '\u0636\u0631';
  23788. t['\uFD2D'] = '\u0634\u062C';
  23789. t['\uFD2E'] = '\u0634\u062D';
  23790. t['\uFD2F'] = '\u0634\u062E';
  23791. t['\uFD30'] = '\u0634\u0645';
  23792. t['\uFD31'] = '\u0633\u0647';
  23793. t['\uFD32'] = '\u0634\u0647';
  23794. t['\uFD33'] = '\u0637\u0645';
  23795. t['\uFD34'] = '\u0633\u062C';
  23796. t['\uFD35'] = '\u0633\u062D';
  23797. t['\uFD36'] = '\u0633\u062E';
  23798. t['\uFD37'] = '\u0634\u062C';
  23799. t['\uFD38'] = '\u0634\u062D';
  23800. t['\uFD39'] = '\u0634\u062E';
  23801. t['\uFD3A'] = '\u0637\u0645';
  23802. t['\uFD3B'] = '\u0638\u0645';
  23803. t['\uFD3C'] = '\u0627\u064B';
  23804. t['\uFD3D'] = '\u0627\u064B';
  23805. t['\uFD50'] = '\u062A\u062C\u0645';
  23806. t['\uFD51'] = '\u062A\u062D\u062C';
  23807. t['\uFD52'] = '\u062A\u062D\u062C';
  23808. t['\uFD53'] = '\u062A\u062D\u0645';
  23809. t['\uFD54'] = '\u062A\u062E\u0645';
  23810. t['\uFD55'] = '\u062A\u0645\u062C';
  23811. t['\uFD56'] = '\u062A\u0645\u062D';
  23812. t['\uFD57'] = '\u062A\u0645\u062E';
  23813. t['\uFD58'] = '\u062C\u0645\u062D';
  23814. t['\uFD59'] = '\u062C\u0645\u062D';
  23815. t['\uFD5A'] = '\u062D\u0645\u064A';
  23816. t['\uFD5B'] = '\u062D\u0645\u0649';
  23817. t['\uFD5C'] = '\u0633\u062D\u062C';
  23818. t['\uFD5D'] = '\u0633\u062C\u062D';
  23819. t['\uFD5E'] = '\u0633\u062C\u0649';
  23820. t['\uFD5F'] = '\u0633\u0645\u062D';
  23821. t['\uFD60'] = '\u0633\u0645\u062D';
  23822. t['\uFD61'] = '\u0633\u0645\u062C';
  23823. t['\uFD62'] = '\u0633\u0645\u0645';
  23824. t['\uFD63'] = '\u0633\u0645\u0645';
  23825. t['\uFD64'] = '\u0635\u062D\u062D';
  23826. t['\uFD65'] = '\u0635\u062D\u062D';
  23827. t['\uFD66'] = '\u0635\u0645\u0645';
  23828. t['\uFD67'] = '\u0634\u062D\u0645';
  23829. t['\uFD68'] = '\u0634\u062D\u0645';
  23830. t['\uFD69'] = '\u0634\u062C\u064A';
  23831. t['\uFD6A'] = '\u0634\u0645\u062E';
  23832. t['\uFD6B'] = '\u0634\u0645\u062E';
  23833. t['\uFD6C'] = '\u0634\u0645\u0645';
  23834. t['\uFD6D'] = '\u0634\u0645\u0645';
  23835. t['\uFD6E'] = '\u0636\u062D\u0649';
  23836. t['\uFD6F'] = '\u0636\u062E\u0645';
  23837. t['\uFD70'] = '\u0636\u062E\u0645';
  23838. t['\uFD71'] = '\u0637\u0645\u062D';
  23839. t['\uFD72'] = '\u0637\u0645\u062D';
  23840. t['\uFD73'] = '\u0637\u0645\u0645';
  23841. t['\uFD74'] = '\u0637\u0645\u064A';
  23842. t['\uFD75'] = '\u0639\u062C\u0645';
  23843. t['\uFD76'] = '\u0639\u0645\u0645';
  23844. t['\uFD77'] = '\u0639\u0645\u0645';
  23845. t['\uFD78'] = '\u0639\u0645\u0649';
  23846. t['\uFD79'] = '\u063A\u0645\u0645';
  23847. t['\uFD7A'] = '\u063A\u0645\u064A';
  23848. t['\uFD7B'] = '\u063A\u0645\u0649';
  23849. t['\uFD7C'] = '\u0641\u062E\u0645';
  23850. t['\uFD7D'] = '\u0641\u062E\u0645';
  23851. t['\uFD7E'] = '\u0642\u0645\u062D';
  23852. t['\uFD7F'] = '\u0642\u0645\u0645';
  23853. t['\uFD80'] = '\u0644\u062D\u0645';
  23854. t['\uFD81'] = '\u0644\u062D\u064A';
  23855. t['\uFD82'] = '\u0644\u062D\u0649';
  23856. t['\uFD83'] = '\u0644\u062C\u062C';
  23857. t['\uFD84'] = '\u0644\u062C\u062C';
  23858. t['\uFD85'] = '\u0644\u062E\u0645';
  23859. t['\uFD86'] = '\u0644\u062E\u0645';
  23860. t['\uFD87'] = '\u0644\u0645\u062D';
  23861. t['\uFD88'] = '\u0644\u0645\u062D';
  23862. t['\uFD89'] = '\u0645\u062D\u062C';
  23863. t['\uFD8A'] = '\u0645\u062D\u0645';
  23864. t['\uFD8B'] = '\u0645\u062D\u064A';
  23865. t['\uFD8C'] = '\u0645\u062C\u062D';
  23866. t['\uFD8D'] = '\u0645\u062C\u0645';
  23867. t['\uFD8E'] = '\u0645\u062E\u062C';
  23868. t['\uFD8F'] = '\u0645\u062E\u0645';
  23869. t['\uFD92'] = '\u0645\u062C\u062E';
  23870. t['\uFD93'] = '\u0647\u0645\u062C';
  23871. t['\uFD94'] = '\u0647\u0645\u0645';
  23872. t['\uFD95'] = '\u0646\u062D\u0645';
  23873. t['\uFD96'] = '\u0646\u062D\u0649';
  23874. t['\uFD97'] = '\u0646\u062C\u0645';
  23875. t['\uFD98'] = '\u0646\u062C\u0645';
  23876. t['\uFD99'] = '\u0646\u062C\u0649';
  23877. t['\uFD9A'] = '\u0646\u0645\u064A';
  23878. t['\uFD9B'] = '\u0646\u0645\u0649';
  23879. t['\uFD9C'] = '\u064A\u0645\u0645';
  23880. t['\uFD9D'] = '\u064A\u0645\u0645';
  23881. t['\uFD9E'] = '\u0628\u062E\u064A';
  23882. t['\uFD9F'] = '\u062A\u062C\u064A';
  23883. t['\uFDA0'] = '\u062A\u062C\u0649';
  23884. t['\uFDA1'] = '\u062A\u062E\u064A';
  23885. t['\uFDA2'] = '\u062A\u062E\u0649';
  23886. t['\uFDA3'] = '\u062A\u0645\u064A';
  23887. t['\uFDA4'] = '\u062A\u0645\u0649';
  23888. t['\uFDA5'] = '\u062C\u0645\u064A';
  23889. t['\uFDA6'] = '\u062C\u062D\u0649';
  23890. t['\uFDA7'] = '\u062C\u0645\u0649';
  23891. t['\uFDA8'] = '\u0633\u062E\u0649';
  23892. t['\uFDA9'] = '\u0635\u062D\u064A';
  23893. t['\uFDAA'] = '\u0634\u062D\u064A';
  23894. t['\uFDAB'] = '\u0636\u062D\u064A';
  23895. t['\uFDAC'] = '\u0644\u062C\u064A';
  23896. t['\uFDAD'] = '\u0644\u0645\u064A';
  23897. t['\uFDAE'] = '\u064A\u062D\u064A';
  23898. t['\uFDAF'] = '\u064A\u062C\u064A';
  23899. t['\uFDB0'] = '\u064A\u0645\u064A';
  23900. t['\uFDB1'] = '\u0645\u0645\u064A';
  23901. t['\uFDB2'] = '\u0642\u0645\u064A';
  23902. t['\uFDB3'] = '\u0646\u062D\u064A';
  23903. t['\uFDB4'] = '\u0642\u0645\u062D';
  23904. t['\uFDB5'] = '\u0644\u062D\u0645';
  23905. t['\uFDB6'] = '\u0639\u0645\u064A';
  23906. t['\uFDB7'] = '\u0643\u0645\u064A';
  23907. t['\uFDB8'] = '\u0646\u062C\u062D';
  23908. t['\uFDB9'] = '\u0645\u062E\u064A';
  23909. t['\uFDBA'] = '\u0644\u062C\u0645';
  23910. t['\uFDBB'] = '\u0643\u0645\u0645';
  23911. t['\uFDBC'] = '\u0644\u062C\u0645';
  23912. t['\uFDBD'] = '\u0646\u062C\u062D';
  23913. t['\uFDBE'] = '\u062C\u062D\u064A';
  23914. t['\uFDBF'] = '\u062D\u062C\u064A';
  23915. t['\uFDC0'] = '\u0645\u062C\u064A';
  23916. t['\uFDC1'] = '\u0641\u0645\u064A';
  23917. t['\uFDC2'] = '\u0628\u062D\u064A';
  23918. t['\uFDC3'] = '\u0643\u0645\u0645';
  23919. t['\uFDC4'] = '\u0639\u062C\u0645';
  23920. t['\uFDC5'] = '\u0635\u0645\u0645';
  23921. t['\uFDC6'] = '\u0633\u062E\u064A';
  23922. t['\uFDC7'] = '\u0646\u062C\u064A';
  23923. t['\uFE49'] = '\u203E';
  23924. t['\uFE4A'] = '\u203E';
  23925. t['\uFE4B'] = '\u203E';
  23926. t['\uFE4C'] = '\u203E';
  23927. t['\uFE4D'] = '\u005F';
  23928. t['\uFE4E'] = '\u005F';
  23929. t['\uFE4F'] = '\u005F';
  23930. t['\uFE80'] = '\u0621';
  23931. t['\uFE81'] = '\u0622';
  23932. t['\uFE82'] = '\u0622';
  23933. t['\uFE83'] = '\u0623';
  23934. t['\uFE84'] = '\u0623';
  23935. t['\uFE85'] = '\u0624';
  23936. t['\uFE86'] = '\u0624';
  23937. t['\uFE87'] = '\u0625';
  23938. t['\uFE88'] = '\u0625';
  23939. t['\uFE89'] = '\u0626';
  23940. t['\uFE8A'] = '\u0626';
  23941. t['\uFE8B'] = '\u0626';
  23942. t['\uFE8C'] = '\u0626';
  23943. t['\uFE8D'] = '\u0627';
  23944. t['\uFE8E'] = '\u0627';
  23945. t['\uFE8F'] = '\u0628';
  23946. t['\uFE90'] = '\u0628';
  23947. t['\uFE91'] = '\u0628';
  23948. t['\uFE92'] = '\u0628';
  23949. t['\uFE93'] = '\u0629';
  23950. t['\uFE94'] = '\u0629';
  23951. t['\uFE95'] = '\u062A';
  23952. t['\uFE96'] = '\u062A';
  23953. t['\uFE97'] = '\u062A';
  23954. t['\uFE98'] = '\u062A';
  23955. t['\uFE99'] = '\u062B';
  23956. t['\uFE9A'] = '\u062B';
  23957. t['\uFE9B'] = '\u062B';
  23958. t['\uFE9C'] = '\u062B';
  23959. t['\uFE9D'] = '\u062C';
  23960. t['\uFE9E'] = '\u062C';
  23961. t['\uFE9F'] = '\u062C';
  23962. t['\uFEA0'] = '\u062C';
  23963. t['\uFEA1'] = '\u062D';
  23964. t['\uFEA2'] = '\u062D';
  23965. t['\uFEA3'] = '\u062D';
  23966. t['\uFEA4'] = '\u062D';
  23967. t['\uFEA5'] = '\u062E';
  23968. t['\uFEA6'] = '\u062E';
  23969. t['\uFEA7'] = '\u062E';
  23970. t['\uFEA8'] = '\u062E';
  23971. t['\uFEA9'] = '\u062F';
  23972. t['\uFEAA'] = '\u062F';
  23973. t['\uFEAB'] = '\u0630';
  23974. t['\uFEAC'] = '\u0630';
  23975. t['\uFEAD'] = '\u0631';
  23976. t['\uFEAE'] = '\u0631';
  23977. t['\uFEAF'] = '\u0632';
  23978. t['\uFEB0'] = '\u0632';
  23979. t['\uFEB1'] = '\u0633';
  23980. t['\uFEB2'] = '\u0633';
  23981. t['\uFEB3'] = '\u0633';
  23982. t['\uFEB4'] = '\u0633';
  23983. t['\uFEB5'] = '\u0634';
  23984. t['\uFEB6'] = '\u0634';
  23985. t['\uFEB7'] = '\u0634';
  23986. t['\uFEB8'] = '\u0634';
  23987. t['\uFEB9'] = '\u0635';
  23988. t['\uFEBA'] = '\u0635';
  23989. t['\uFEBB'] = '\u0635';
  23990. t['\uFEBC'] = '\u0635';
  23991. t['\uFEBD'] = '\u0636';
  23992. t['\uFEBE'] = '\u0636';
  23993. t['\uFEBF'] = '\u0636';
  23994. t['\uFEC0'] = '\u0636';
  23995. t['\uFEC1'] = '\u0637';
  23996. t['\uFEC2'] = '\u0637';
  23997. t['\uFEC3'] = '\u0637';
  23998. t['\uFEC4'] = '\u0637';
  23999. t['\uFEC5'] = '\u0638';
  24000. t['\uFEC6'] = '\u0638';
  24001. t['\uFEC7'] = '\u0638';
  24002. t['\uFEC8'] = '\u0638';
  24003. t['\uFEC9'] = '\u0639';
  24004. t['\uFECA'] = '\u0639';
  24005. t['\uFECB'] = '\u0639';
  24006. t['\uFECC'] = '\u0639';
  24007. t['\uFECD'] = '\u063A';
  24008. t['\uFECE'] = '\u063A';
  24009. t['\uFECF'] = '\u063A';
  24010. t['\uFED0'] = '\u063A';
  24011. t['\uFED1'] = '\u0641';
  24012. t['\uFED2'] = '\u0641';
  24013. t['\uFED3'] = '\u0641';
  24014. t['\uFED4'] = '\u0641';
  24015. t['\uFED5'] = '\u0642';
  24016. t['\uFED6'] = '\u0642';
  24017. t['\uFED7'] = '\u0642';
  24018. t['\uFED8'] = '\u0642';
  24019. t['\uFED9'] = '\u0643';
  24020. t['\uFEDA'] = '\u0643';
  24021. t['\uFEDB'] = '\u0643';
  24022. t['\uFEDC'] = '\u0643';
  24023. t['\uFEDD'] = '\u0644';
  24024. t['\uFEDE'] = '\u0644';
  24025. t['\uFEDF'] = '\u0644';
  24026. t['\uFEE0'] = '\u0644';
  24027. t['\uFEE1'] = '\u0645';
  24028. t['\uFEE2'] = '\u0645';
  24029. t['\uFEE3'] = '\u0645';
  24030. t['\uFEE4'] = '\u0645';
  24031. t['\uFEE5'] = '\u0646';
  24032. t['\uFEE6'] = '\u0646';
  24033. t['\uFEE7'] = '\u0646';
  24034. t['\uFEE8'] = '\u0646';
  24035. t['\uFEE9'] = '\u0647';
  24036. t['\uFEEA'] = '\u0647';
  24037. t['\uFEEB'] = '\u0647';
  24038. t['\uFEEC'] = '\u0647';
  24039. t['\uFEED'] = '\u0648';
  24040. t['\uFEEE'] = '\u0648';
  24041. t['\uFEEF'] = '\u0649';
  24042. t['\uFEF0'] = '\u0649';
  24043. t['\uFEF1'] = '\u064A';
  24044. t['\uFEF2'] = '\u064A';
  24045. t['\uFEF3'] = '\u064A';
  24046. t['\uFEF4'] = '\u064A';
  24047. t['\uFEF5'] = '\u0644\u0622';
  24048. t['\uFEF6'] = '\u0644\u0622';
  24049. t['\uFEF7'] = '\u0644\u0623';
  24050. t['\uFEF8'] = '\u0644\u0623';
  24051. t['\uFEF9'] = '\u0644\u0625';
  24052. t['\uFEFA'] = '\u0644\u0625';
  24053. t['\uFEFB'] = '\u0644\u0627';
  24054. t['\uFEFC'] = '\u0644\u0627';
  24055. });
  24056. function reverseIfRtl(chars) {
  24057. var charsLength = chars.length;
  24058. //reverse an arabic ligature
  24059. if (charsLength <= 1 || !isRTLRangeFor(chars.charCodeAt(0))) {
  24060. return chars;
  24061. }
  24062. var s = '';
  24063. for (var ii = charsLength - 1; ii >= 0; ii--) {
  24064. s += chars[ii];
  24065. }
  24066. return s;
  24067. }
  24068. exports.mapSpecialUnicodeValues = mapSpecialUnicodeValues;
  24069. exports.reverseIfRtl = reverseIfRtl;
  24070. exports.getUnicodeRangeFor = getUnicodeRangeFor;
  24071. exports.getNormalizedUnicodes = getNormalizedUnicodes;
  24072. exports.getUnicodeForGlyph = getUnicodeForGlyph;
  24073. }));
  24074. (function (root, factory) {
  24075. factory(root.pdfjsCoreStream = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCoreJbig2, root.pdfjsCoreJpg, root.pdfjsCoreJpx);
  24076. }(this, function (exports, sharedUtil, corePrimitives, coreJbig2, coreJpg, coreJpx) {
  24077. var Util = sharedUtil.Util;
  24078. var error = sharedUtil.error;
  24079. var info = sharedUtil.info;
  24080. var isInt = sharedUtil.isInt;
  24081. var isArray = sharedUtil.isArray;
  24082. var createObjectURL = sharedUtil.createObjectURL;
  24083. var shadow = sharedUtil.shadow;
  24084. var warn = sharedUtil.warn;
  24085. var isSpace = sharedUtil.isSpace;
  24086. var Dict = corePrimitives.Dict;
  24087. var isDict = corePrimitives.isDict;
  24088. var isStream = corePrimitives.isStream;
  24089. var Jbig2Image = coreJbig2.Jbig2Image;
  24090. var JpegImage = coreJpg.JpegImage;
  24091. var JpxImage = coreJpx.JpxImage;
  24092. var Stream = function StreamClosure() {
  24093. function Stream(arrayBuffer, start, length, dict) {
  24094. this.bytes = arrayBuffer instanceof Uint8Array ? arrayBuffer : new Uint8Array(arrayBuffer);
  24095. this.start = start || 0;
  24096. this.pos = this.start;
  24097. this.end = start + length || this.bytes.length;
  24098. this.dict = dict;
  24099. }
  24100. // required methods for a stream. if a particular stream does not
  24101. // implement these, an error should be thrown
  24102. Stream.prototype = {
  24103. get length() {
  24104. return this.end - this.start;
  24105. },
  24106. get isEmpty() {
  24107. return this.length === 0;
  24108. },
  24109. getByte: function Stream_getByte() {
  24110. if (this.pos >= this.end) {
  24111. return -1;
  24112. }
  24113. return this.bytes[this.pos++];
  24114. },
  24115. getUint16: function Stream_getUint16() {
  24116. var b0 = this.getByte();
  24117. var b1 = this.getByte();
  24118. if (b0 === -1 || b1 === -1) {
  24119. return -1;
  24120. }
  24121. return (b0 << 8) + b1;
  24122. },
  24123. getInt32: function Stream_getInt32() {
  24124. var b0 = this.getByte();
  24125. var b1 = this.getByte();
  24126. var b2 = this.getByte();
  24127. var b3 = this.getByte();
  24128. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  24129. },
  24130. // returns subarray of original buffer
  24131. // should only be read
  24132. getBytes: function Stream_getBytes(length) {
  24133. var bytes = this.bytes;
  24134. var pos = this.pos;
  24135. var strEnd = this.end;
  24136. if (!length) {
  24137. return bytes.subarray(pos, strEnd);
  24138. }
  24139. var end = pos + length;
  24140. if (end > strEnd) {
  24141. end = strEnd;
  24142. }
  24143. this.pos = end;
  24144. return bytes.subarray(pos, end);
  24145. },
  24146. peekByte: function Stream_peekByte() {
  24147. var peekedByte = this.getByte();
  24148. this.pos--;
  24149. return peekedByte;
  24150. },
  24151. peekBytes: function Stream_peekBytes(length) {
  24152. var bytes = this.getBytes(length);
  24153. this.pos -= bytes.length;
  24154. return bytes;
  24155. },
  24156. skip: function Stream_skip(n) {
  24157. if (!n) {
  24158. n = 1;
  24159. }
  24160. this.pos += n;
  24161. },
  24162. reset: function Stream_reset() {
  24163. this.pos = this.start;
  24164. },
  24165. moveStart: function Stream_moveStart() {
  24166. this.start = this.pos;
  24167. },
  24168. makeSubStream: function Stream_makeSubStream(start, length, dict) {
  24169. return new Stream(this.bytes.buffer, start, length, dict);
  24170. },
  24171. isStream: true
  24172. };
  24173. return Stream;
  24174. }();
  24175. var StringStream = function StringStreamClosure() {
  24176. function StringStream(str) {
  24177. var length = str.length;
  24178. var bytes = new Uint8Array(length);
  24179. for (var n = 0; n < length; ++n) {
  24180. bytes[n] = str.charCodeAt(n);
  24181. }
  24182. Stream.call(this, bytes);
  24183. }
  24184. StringStream.prototype = Stream.prototype;
  24185. return StringStream;
  24186. }();
  24187. // super class for the decoding streams
  24188. var DecodeStream = function DecodeStreamClosure() {
  24189. // Lots of DecodeStreams are created whose buffers are never used. For these
  24190. // we share a single empty buffer. This is (a) space-efficient and (b) avoids
  24191. // having special cases that would be required if we used |null| for an empty
  24192. // buffer.
  24193. var emptyBuffer = new Uint8Array(0);
  24194. function DecodeStream(maybeMinBufferLength) {
  24195. this.pos = 0;
  24196. this.bufferLength = 0;
  24197. this.eof = false;
  24198. this.buffer = emptyBuffer;
  24199. this.minBufferLength = 512;
  24200. if (maybeMinBufferLength) {
  24201. // Compute the first power of two that is as big as maybeMinBufferLength.
  24202. while (this.minBufferLength < maybeMinBufferLength) {
  24203. this.minBufferLength *= 2;
  24204. }
  24205. }
  24206. }
  24207. DecodeStream.prototype = {
  24208. get isEmpty() {
  24209. while (!this.eof && this.bufferLength === 0) {
  24210. this.readBlock();
  24211. }
  24212. return this.bufferLength === 0;
  24213. },
  24214. ensureBuffer: function DecodeStream_ensureBuffer(requested) {
  24215. var buffer = this.buffer;
  24216. if (requested <= buffer.byteLength) {
  24217. return buffer;
  24218. }
  24219. var size = this.minBufferLength;
  24220. while (size < requested) {
  24221. size *= 2;
  24222. }
  24223. var buffer2 = new Uint8Array(size);
  24224. buffer2.set(buffer);
  24225. return this.buffer = buffer2;
  24226. },
  24227. getByte: function DecodeStream_getByte() {
  24228. var pos = this.pos;
  24229. while (this.bufferLength <= pos) {
  24230. if (this.eof) {
  24231. return -1;
  24232. }
  24233. this.readBlock();
  24234. }
  24235. return this.buffer[this.pos++];
  24236. },
  24237. getUint16: function DecodeStream_getUint16() {
  24238. var b0 = this.getByte();
  24239. var b1 = this.getByte();
  24240. if (b0 === -1 || b1 === -1) {
  24241. return -1;
  24242. }
  24243. return (b0 << 8) + b1;
  24244. },
  24245. getInt32: function DecodeStream_getInt32() {
  24246. var b0 = this.getByte();
  24247. var b1 = this.getByte();
  24248. var b2 = this.getByte();
  24249. var b3 = this.getByte();
  24250. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  24251. },
  24252. getBytes: function DecodeStream_getBytes(length) {
  24253. var end, pos = this.pos;
  24254. if (length) {
  24255. this.ensureBuffer(pos + length);
  24256. end = pos + length;
  24257. while (!this.eof && this.bufferLength < end) {
  24258. this.readBlock();
  24259. }
  24260. var bufEnd = this.bufferLength;
  24261. if (end > bufEnd) {
  24262. end = bufEnd;
  24263. }
  24264. } else {
  24265. while (!this.eof) {
  24266. this.readBlock();
  24267. }
  24268. end = this.bufferLength;
  24269. }
  24270. this.pos = end;
  24271. return this.buffer.subarray(pos, end);
  24272. },
  24273. peekByte: function DecodeStream_peekByte() {
  24274. var peekedByte = this.getByte();
  24275. this.pos--;
  24276. return peekedByte;
  24277. },
  24278. peekBytes: function DecodeStream_peekBytes(length) {
  24279. var bytes = this.getBytes(length);
  24280. this.pos -= bytes.length;
  24281. return bytes;
  24282. },
  24283. makeSubStream: function DecodeStream_makeSubStream(start, length, dict) {
  24284. var end = start + length;
  24285. while (this.bufferLength <= end && !this.eof) {
  24286. this.readBlock();
  24287. }
  24288. return new Stream(this.buffer, start, length, dict);
  24289. },
  24290. skip: function DecodeStream_skip(n) {
  24291. if (!n) {
  24292. n = 1;
  24293. }
  24294. this.pos += n;
  24295. },
  24296. reset: function DecodeStream_reset() {
  24297. this.pos = 0;
  24298. },
  24299. getBaseStreams: function DecodeStream_getBaseStreams() {
  24300. if (this.str && this.str.getBaseStreams) {
  24301. return this.str.getBaseStreams();
  24302. }
  24303. return [];
  24304. }
  24305. };
  24306. return DecodeStream;
  24307. }();
  24308. var StreamsSequenceStream = function StreamsSequenceStreamClosure() {
  24309. function StreamsSequenceStream(streams) {
  24310. this.streams = streams;
  24311. DecodeStream.call(this, /* maybeLength = */
  24312. null);
  24313. }
  24314. StreamsSequenceStream.prototype = Object.create(DecodeStream.prototype);
  24315. StreamsSequenceStream.prototype.readBlock = function streamSequenceStreamReadBlock() {
  24316. var streams = this.streams;
  24317. if (streams.length === 0) {
  24318. this.eof = true;
  24319. return;
  24320. }
  24321. var stream = streams.shift();
  24322. var chunk = stream.getBytes();
  24323. var bufferLength = this.bufferLength;
  24324. var newLength = bufferLength + chunk.length;
  24325. var buffer = this.ensureBuffer(newLength);
  24326. buffer.set(chunk, bufferLength);
  24327. this.bufferLength = newLength;
  24328. };
  24329. StreamsSequenceStream.prototype.getBaseStreams = function StreamsSequenceStream_getBaseStreams() {
  24330. var baseStreams = [];
  24331. for (var i = 0, ii = this.streams.length; i < ii; i++) {
  24332. var stream = this.streams[i];
  24333. if (stream.getBaseStreams) {
  24334. Util.appendToArray(baseStreams, stream.getBaseStreams());
  24335. }
  24336. }
  24337. return baseStreams;
  24338. };
  24339. return StreamsSequenceStream;
  24340. }();
  24341. var FlateStream = function FlateStreamClosure() {
  24342. var codeLenCodeMap = new Int32Array([
  24343. 16,
  24344. 17,
  24345. 18,
  24346. 0,
  24347. 8,
  24348. 7,
  24349. 9,
  24350. 6,
  24351. 10,
  24352. 5,
  24353. 11,
  24354. 4,
  24355. 12,
  24356. 3,
  24357. 13,
  24358. 2,
  24359. 14,
  24360. 1,
  24361. 15
  24362. ]);
  24363. var lengthDecode = new Int32Array([
  24364. 0x00003,
  24365. 0x00004,
  24366. 0x00005,
  24367. 0x00006,
  24368. 0x00007,
  24369. 0x00008,
  24370. 0x00009,
  24371. 0x0000a,
  24372. 0x1000b,
  24373. 0x1000d,
  24374. 0x1000f,
  24375. 0x10011,
  24376. 0x20013,
  24377. 0x20017,
  24378. 0x2001b,
  24379. 0x2001f,
  24380. 0x30023,
  24381. 0x3002b,
  24382. 0x30033,
  24383. 0x3003b,
  24384. 0x40043,
  24385. 0x40053,
  24386. 0x40063,
  24387. 0x40073,
  24388. 0x50083,
  24389. 0x500a3,
  24390. 0x500c3,
  24391. 0x500e3,
  24392. 0x00102,
  24393. 0x00102,
  24394. 0x00102
  24395. ]);
  24396. var distDecode = new Int32Array([
  24397. 0x00001,
  24398. 0x00002,
  24399. 0x00003,
  24400. 0x00004,
  24401. 0x10005,
  24402. 0x10007,
  24403. 0x20009,
  24404. 0x2000d,
  24405. 0x30011,
  24406. 0x30019,
  24407. 0x40021,
  24408. 0x40031,
  24409. 0x50041,
  24410. 0x50061,
  24411. 0x60081,
  24412. 0x600c1,
  24413. 0x70101,
  24414. 0x70181,
  24415. 0x80201,
  24416. 0x80301,
  24417. 0x90401,
  24418. 0x90601,
  24419. 0xa0801,
  24420. 0xa0c01,
  24421. 0xb1001,
  24422. 0xb1801,
  24423. 0xc2001,
  24424. 0xc3001,
  24425. 0xd4001,
  24426. 0xd6001
  24427. ]);
  24428. var fixedLitCodeTab = [
  24429. new Int32Array([
  24430. 0x70100,
  24431. 0x80050,
  24432. 0x80010,
  24433. 0x80118,
  24434. 0x70110,
  24435. 0x80070,
  24436. 0x80030,
  24437. 0x900c0,
  24438. 0x70108,
  24439. 0x80060,
  24440. 0x80020,
  24441. 0x900a0,
  24442. 0x80000,
  24443. 0x80080,
  24444. 0x80040,
  24445. 0x900e0,
  24446. 0x70104,
  24447. 0x80058,
  24448. 0x80018,
  24449. 0x90090,
  24450. 0x70114,
  24451. 0x80078,
  24452. 0x80038,
  24453. 0x900d0,
  24454. 0x7010c,
  24455. 0x80068,
  24456. 0x80028,
  24457. 0x900b0,
  24458. 0x80008,
  24459. 0x80088,
  24460. 0x80048,
  24461. 0x900f0,
  24462. 0x70102,
  24463. 0x80054,
  24464. 0x80014,
  24465. 0x8011c,
  24466. 0x70112,
  24467. 0x80074,
  24468. 0x80034,
  24469. 0x900c8,
  24470. 0x7010a,
  24471. 0x80064,
  24472. 0x80024,
  24473. 0x900a8,
  24474. 0x80004,
  24475. 0x80084,
  24476. 0x80044,
  24477. 0x900e8,
  24478. 0x70106,
  24479. 0x8005c,
  24480. 0x8001c,
  24481. 0x90098,
  24482. 0x70116,
  24483. 0x8007c,
  24484. 0x8003c,
  24485. 0x900d8,
  24486. 0x7010e,
  24487. 0x8006c,
  24488. 0x8002c,
  24489. 0x900b8,
  24490. 0x8000c,
  24491. 0x8008c,
  24492. 0x8004c,
  24493. 0x900f8,
  24494. 0x70101,
  24495. 0x80052,
  24496. 0x80012,
  24497. 0x8011a,
  24498. 0x70111,
  24499. 0x80072,
  24500. 0x80032,
  24501. 0x900c4,
  24502. 0x70109,
  24503. 0x80062,
  24504. 0x80022,
  24505. 0x900a4,
  24506. 0x80002,
  24507. 0x80082,
  24508. 0x80042,
  24509. 0x900e4,
  24510. 0x70105,
  24511. 0x8005a,
  24512. 0x8001a,
  24513. 0x90094,
  24514. 0x70115,
  24515. 0x8007a,
  24516. 0x8003a,
  24517. 0x900d4,
  24518. 0x7010d,
  24519. 0x8006a,
  24520. 0x8002a,
  24521. 0x900b4,
  24522. 0x8000a,
  24523. 0x8008a,
  24524. 0x8004a,
  24525. 0x900f4,
  24526. 0x70103,
  24527. 0x80056,
  24528. 0x80016,
  24529. 0x8011e,
  24530. 0x70113,
  24531. 0x80076,
  24532. 0x80036,
  24533. 0x900cc,
  24534. 0x7010b,
  24535. 0x80066,
  24536. 0x80026,
  24537. 0x900ac,
  24538. 0x80006,
  24539. 0x80086,
  24540. 0x80046,
  24541. 0x900ec,
  24542. 0x70107,
  24543. 0x8005e,
  24544. 0x8001e,
  24545. 0x9009c,
  24546. 0x70117,
  24547. 0x8007e,
  24548. 0x8003e,
  24549. 0x900dc,
  24550. 0x7010f,
  24551. 0x8006e,
  24552. 0x8002e,
  24553. 0x900bc,
  24554. 0x8000e,
  24555. 0x8008e,
  24556. 0x8004e,
  24557. 0x900fc,
  24558. 0x70100,
  24559. 0x80051,
  24560. 0x80011,
  24561. 0x80119,
  24562. 0x70110,
  24563. 0x80071,
  24564. 0x80031,
  24565. 0x900c2,
  24566. 0x70108,
  24567. 0x80061,
  24568. 0x80021,
  24569. 0x900a2,
  24570. 0x80001,
  24571. 0x80081,
  24572. 0x80041,
  24573. 0x900e2,
  24574. 0x70104,
  24575. 0x80059,
  24576. 0x80019,
  24577. 0x90092,
  24578. 0x70114,
  24579. 0x80079,
  24580. 0x80039,
  24581. 0x900d2,
  24582. 0x7010c,
  24583. 0x80069,
  24584. 0x80029,
  24585. 0x900b2,
  24586. 0x80009,
  24587. 0x80089,
  24588. 0x80049,
  24589. 0x900f2,
  24590. 0x70102,
  24591. 0x80055,
  24592. 0x80015,
  24593. 0x8011d,
  24594. 0x70112,
  24595. 0x80075,
  24596. 0x80035,
  24597. 0x900ca,
  24598. 0x7010a,
  24599. 0x80065,
  24600. 0x80025,
  24601. 0x900aa,
  24602. 0x80005,
  24603. 0x80085,
  24604. 0x80045,
  24605. 0x900ea,
  24606. 0x70106,
  24607. 0x8005d,
  24608. 0x8001d,
  24609. 0x9009a,
  24610. 0x70116,
  24611. 0x8007d,
  24612. 0x8003d,
  24613. 0x900da,
  24614. 0x7010e,
  24615. 0x8006d,
  24616. 0x8002d,
  24617. 0x900ba,
  24618. 0x8000d,
  24619. 0x8008d,
  24620. 0x8004d,
  24621. 0x900fa,
  24622. 0x70101,
  24623. 0x80053,
  24624. 0x80013,
  24625. 0x8011b,
  24626. 0x70111,
  24627. 0x80073,
  24628. 0x80033,
  24629. 0x900c6,
  24630. 0x70109,
  24631. 0x80063,
  24632. 0x80023,
  24633. 0x900a6,
  24634. 0x80003,
  24635. 0x80083,
  24636. 0x80043,
  24637. 0x900e6,
  24638. 0x70105,
  24639. 0x8005b,
  24640. 0x8001b,
  24641. 0x90096,
  24642. 0x70115,
  24643. 0x8007b,
  24644. 0x8003b,
  24645. 0x900d6,
  24646. 0x7010d,
  24647. 0x8006b,
  24648. 0x8002b,
  24649. 0x900b6,
  24650. 0x8000b,
  24651. 0x8008b,
  24652. 0x8004b,
  24653. 0x900f6,
  24654. 0x70103,
  24655. 0x80057,
  24656. 0x80017,
  24657. 0x8011f,
  24658. 0x70113,
  24659. 0x80077,
  24660. 0x80037,
  24661. 0x900ce,
  24662. 0x7010b,
  24663. 0x80067,
  24664. 0x80027,
  24665. 0x900ae,
  24666. 0x80007,
  24667. 0x80087,
  24668. 0x80047,
  24669. 0x900ee,
  24670. 0x70107,
  24671. 0x8005f,
  24672. 0x8001f,
  24673. 0x9009e,
  24674. 0x70117,
  24675. 0x8007f,
  24676. 0x8003f,
  24677. 0x900de,
  24678. 0x7010f,
  24679. 0x8006f,
  24680. 0x8002f,
  24681. 0x900be,
  24682. 0x8000f,
  24683. 0x8008f,
  24684. 0x8004f,
  24685. 0x900fe,
  24686. 0x70100,
  24687. 0x80050,
  24688. 0x80010,
  24689. 0x80118,
  24690. 0x70110,
  24691. 0x80070,
  24692. 0x80030,
  24693. 0x900c1,
  24694. 0x70108,
  24695. 0x80060,
  24696. 0x80020,
  24697. 0x900a1,
  24698. 0x80000,
  24699. 0x80080,
  24700. 0x80040,
  24701. 0x900e1,
  24702. 0x70104,
  24703. 0x80058,
  24704. 0x80018,
  24705. 0x90091,
  24706. 0x70114,
  24707. 0x80078,
  24708. 0x80038,
  24709. 0x900d1,
  24710. 0x7010c,
  24711. 0x80068,
  24712. 0x80028,
  24713. 0x900b1,
  24714. 0x80008,
  24715. 0x80088,
  24716. 0x80048,
  24717. 0x900f1,
  24718. 0x70102,
  24719. 0x80054,
  24720. 0x80014,
  24721. 0x8011c,
  24722. 0x70112,
  24723. 0x80074,
  24724. 0x80034,
  24725. 0x900c9,
  24726. 0x7010a,
  24727. 0x80064,
  24728. 0x80024,
  24729. 0x900a9,
  24730. 0x80004,
  24731. 0x80084,
  24732. 0x80044,
  24733. 0x900e9,
  24734. 0x70106,
  24735. 0x8005c,
  24736. 0x8001c,
  24737. 0x90099,
  24738. 0x70116,
  24739. 0x8007c,
  24740. 0x8003c,
  24741. 0x900d9,
  24742. 0x7010e,
  24743. 0x8006c,
  24744. 0x8002c,
  24745. 0x900b9,
  24746. 0x8000c,
  24747. 0x8008c,
  24748. 0x8004c,
  24749. 0x900f9,
  24750. 0x70101,
  24751. 0x80052,
  24752. 0x80012,
  24753. 0x8011a,
  24754. 0x70111,
  24755. 0x80072,
  24756. 0x80032,
  24757. 0x900c5,
  24758. 0x70109,
  24759. 0x80062,
  24760. 0x80022,
  24761. 0x900a5,
  24762. 0x80002,
  24763. 0x80082,
  24764. 0x80042,
  24765. 0x900e5,
  24766. 0x70105,
  24767. 0x8005a,
  24768. 0x8001a,
  24769. 0x90095,
  24770. 0x70115,
  24771. 0x8007a,
  24772. 0x8003a,
  24773. 0x900d5,
  24774. 0x7010d,
  24775. 0x8006a,
  24776. 0x8002a,
  24777. 0x900b5,
  24778. 0x8000a,
  24779. 0x8008a,
  24780. 0x8004a,
  24781. 0x900f5,
  24782. 0x70103,
  24783. 0x80056,
  24784. 0x80016,
  24785. 0x8011e,
  24786. 0x70113,
  24787. 0x80076,
  24788. 0x80036,
  24789. 0x900cd,
  24790. 0x7010b,
  24791. 0x80066,
  24792. 0x80026,
  24793. 0x900ad,
  24794. 0x80006,
  24795. 0x80086,
  24796. 0x80046,
  24797. 0x900ed,
  24798. 0x70107,
  24799. 0x8005e,
  24800. 0x8001e,
  24801. 0x9009d,
  24802. 0x70117,
  24803. 0x8007e,
  24804. 0x8003e,
  24805. 0x900dd,
  24806. 0x7010f,
  24807. 0x8006e,
  24808. 0x8002e,
  24809. 0x900bd,
  24810. 0x8000e,
  24811. 0x8008e,
  24812. 0x8004e,
  24813. 0x900fd,
  24814. 0x70100,
  24815. 0x80051,
  24816. 0x80011,
  24817. 0x80119,
  24818. 0x70110,
  24819. 0x80071,
  24820. 0x80031,
  24821. 0x900c3,
  24822. 0x70108,
  24823. 0x80061,
  24824. 0x80021,
  24825. 0x900a3,
  24826. 0x80001,
  24827. 0x80081,
  24828. 0x80041,
  24829. 0x900e3,
  24830. 0x70104,
  24831. 0x80059,
  24832. 0x80019,
  24833. 0x90093,
  24834. 0x70114,
  24835. 0x80079,
  24836. 0x80039,
  24837. 0x900d3,
  24838. 0x7010c,
  24839. 0x80069,
  24840. 0x80029,
  24841. 0x900b3,
  24842. 0x80009,
  24843. 0x80089,
  24844. 0x80049,
  24845. 0x900f3,
  24846. 0x70102,
  24847. 0x80055,
  24848. 0x80015,
  24849. 0x8011d,
  24850. 0x70112,
  24851. 0x80075,
  24852. 0x80035,
  24853. 0x900cb,
  24854. 0x7010a,
  24855. 0x80065,
  24856. 0x80025,
  24857. 0x900ab,
  24858. 0x80005,
  24859. 0x80085,
  24860. 0x80045,
  24861. 0x900eb,
  24862. 0x70106,
  24863. 0x8005d,
  24864. 0x8001d,
  24865. 0x9009b,
  24866. 0x70116,
  24867. 0x8007d,
  24868. 0x8003d,
  24869. 0x900db,
  24870. 0x7010e,
  24871. 0x8006d,
  24872. 0x8002d,
  24873. 0x900bb,
  24874. 0x8000d,
  24875. 0x8008d,
  24876. 0x8004d,
  24877. 0x900fb,
  24878. 0x70101,
  24879. 0x80053,
  24880. 0x80013,
  24881. 0x8011b,
  24882. 0x70111,
  24883. 0x80073,
  24884. 0x80033,
  24885. 0x900c7,
  24886. 0x70109,
  24887. 0x80063,
  24888. 0x80023,
  24889. 0x900a7,
  24890. 0x80003,
  24891. 0x80083,
  24892. 0x80043,
  24893. 0x900e7,
  24894. 0x70105,
  24895. 0x8005b,
  24896. 0x8001b,
  24897. 0x90097,
  24898. 0x70115,
  24899. 0x8007b,
  24900. 0x8003b,
  24901. 0x900d7,
  24902. 0x7010d,
  24903. 0x8006b,
  24904. 0x8002b,
  24905. 0x900b7,
  24906. 0x8000b,
  24907. 0x8008b,
  24908. 0x8004b,
  24909. 0x900f7,
  24910. 0x70103,
  24911. 0x80057,
  24912. 0x80017,
  24913. 0x8011f,
  24914. 0x70113,
  24915. 0x80077,
  24916. 0x80037,
  24917. 0x900cf,
  24918. 0x7010b,
  24919. 0x80067,
  24920. 0x80027,
  24921. 0x900af,
  24922. 0x80007,
  24923. 0x80087,
  24924. 0x80047,
  24925. 0x900ef,
  24926. 0x70107,
  24927. 0x8005f,
  24928. 0x8001f,
  24929. 0x9009f,
  24930. 0x70117,
  24931. 0x8007f,
  24932. 0x8003f,
  24933. 0x900df,
  24934. 0x7010f,
  24935. 0x8006f,
  24936. 0x8002f,
  24937. 0x900bf,
  24938. 0x8000f,
  24939. 0x8008f,
  24940. 0x8004f,
  24941. 0x900ff
  24942. ]),
  24943. 9
  24944. ];
  24945. var fixedDistCodeTab = [
  24946. new Int32Array([
  24947. 0x50000,
  24948. 0x50010,
  24949. 0x50008,
  24950. 0x50018,
  24951. 0x50004,
  24952. 0x50014,
  24953. 0x5000c,
  24954. 0x5001c,
  24955. 0x50002,
  24956. 0x50012,
  24957. 0x5000a,
  24958. 0x5001a,
  24959. 0x50006,
  24960. 0x50016,
  24961. 0x5000e,
  24962. 0x00000,
  24963. 0x50001,
  24964. 0x50011,
  24965. 0x50009,
  24966. 0x50019,
  24967. 0x50005,
  24968. 0x50015,
  24969. 0x5000d,
  24970. 0x5001d,
  24971. 0x50003,
  24972. 0x50013,
  24973. 0x5000b,
  24974. 0x5001b,
  24975. 0x50007,
  24976. 0x50017,
  24977. 0x5000f,
  24978. 0x00000
  24979. ]),
  24980. 5
  24981. ];
  24982. function FlateStream(str, maybeLength) {
  24983. this.str = str;
  24984. this.dict = str.dict;
  24985. var cmf = str.getByte();
  24986. var flg = str.getByte();
  24987. if (cmf === -1 || flg === -1) {
  24988. error('Invalid header in flate stream: ' + cmf + ', ' + flg);
  24989. }
  24990. if ((cmf & 0x0f) !== 0x08) {
  24991. error('Unknown compression method in flate stream: ' + cmf + ', ' + flg);
  24992. }
  24993. if (((cmf << 8) + flg) % 31 !== 0) {
  24994. error('Bad FCHECK in flate stream: ' + cmf + ', ' + flg);
  24995. }
  24996. if (flg & 0x20) {
  24997. error('FDICT bit set in flate stream: ' + cmf + ', ' + flg);
  24998. }
  24999. this.codeSize = 0;
  25000. this.codeBuf = 0;
  25001. DecodeStream.call(this, maybeLength);
  25002. }
  25003. FlateStream.prototype = Object.create(DecodeStream.prototype);
  25004. FlateStream.prototype.getBits = function FlateStream_getBits(bits) {
  25005. var str = this.str;
  25006. var codeSize = this.codeSize;
  25007. var codeBuf = this.codeBuf;
  25008. var b;
  25009. while (codeSize < bits) {
  25010. if ((b = str.getByte()) === -1) {
  25011. error('Bad encoding in flate stream');
  25012. }
  25013. codeBuf |= b << codeSize;
  25014. codeSize += 8;
  25015. }
  25016. b = codeBuf & (1 << bits) - 1;
  25017. this.codeBuf = codeBuf >> bits;
  25018. this.codeSize = codeSize -= bits;
  25019. return b;
  25020. };
  25021. FlateStream.prototype.getCode = function FlateStream_getCode(table) {
  25022. var str = this.str;
  25023. var codes = table[0];
  25024. var maxLen = table[1];
  25025. var codeSize = this.codeSize;
  25026. var codeBuf = this.codeBuf;
  25027. var b;
  25028. while (codeSize < maxLen) {
  25029. if ((b = str.getByte()) === -1) {
  25030. // premature end of stream. code might however still be valid.
  25031. // codeSize < codeLen check below guards against incomplete codeVal.
  25032. break;
  25033. }
  25034. codeBuf |= b << codeSize;
  25035. codeSize += 8;
  25036. }
  25037. var code = codes[codeBuf & (1 << maxLen) - 1];
  25038. var codeLen = code >> 16;
  25039. var codeVal = code & 0xffff;
  25040. if (codeLen < 1 || codeSize < codeLen) {
  25041. error('Bad encoding in flate stream');
  25042. }
  25043. this.codeBuf = codeBuf >> codeLen;
  25044. this.codeSize = codeSize - codeLen;
  25045. return codeVal;
  25046. };
  25047. FlateStream.prototype.generateHuffmanTable = function flateStreamGenerateHuffmanTable(lengths) {
  25048. var n = lengths.length;
  25049. // find max code length
  25050. var maxLen = 0;
  25051. var i;
  25052. for (i = 0; i < n; ++i) {
  25053. if (lengths[i] > maxLen) {
  25054. maxLen = lengths[i];
  25055. }
  25056. }
  25057. // build the table
  25058. var size = 1 << maxLen;
  25059. var codes = new Int32Array(size);
  25060. for (var len = 1, code = 0, skip = 2; len <= maxLen; ++len, code <<= 1, skip <<= 1) {
  25061. for (var val = 0; val < n; ++val) {
  25062. if (lengths[val] === len) {
  25063. // bit-reverse the code
  25064. var code2 = 0;
  25065. var t = code;
  25066. for (i = 0; i < len; ++i) {
  25067. code2 = code2 << 1 | t & 1;
  25068. t >>= 1;
  25069. }
  25070. // fill the table entries
  25071. for (i = code2; i < size; i += skip) {
  25072. codes[i] = len << 16 | val;
  25073. }
  25074. ++code;
  25075. }
  25076. }
  25077. }
  25078. return [
  25079. codes,
  25080. maxLen
  25081. ];
  25082. };
  25083. FlateStream.prototype.readBlock = function FlateStream_readBlock() {
  25084. var buffer, len;
  25085. var str = this.str;
  25086. // read block header
  25087. var hdr = this.getBits(3);
  25088. if (hdr & 1) {
  25089. this.eof = true;
  25090. }
  25091. hdr >>= 1;
  25092. if (hdr === 0) {
  25093. // uncompressed block
  25094. var b;
  25095. if ((b = str.getByte()) === -1) {
  25096. error('Bad block header in flate stream');
  25097. }
  25098. var blockLen = b;
  25099. if ((b = str.getByte()) === -1) {
  25100. error('Bad block header in flate stream');
  25101. }
  25102. blockLen |= b << 8;
  25103. if ((b = str.getByte()) === -1) {
  25104. error('Bad block header in flate stream');
  25105. }
  25106. var check = b;
  25107. if ((b = str.getByte()) === -1) {
  25108. error('Bad block header in flate stream');
  25109. }
  25110. check |= b << 8;
  25111. if (check !== (~blockLen & 0xffff) && (blockLen !== 0 || check !== 0)) {
  25112. // Ignoring error for bad "empty" block (see issue 1277)
  25113. error('Bad uncompressed block length in flate stream');
  25114. }
  25115. this.codeBuf = 0;
  25116. this.codeSize = 0;
  25117. var bufferLength = this.bufferLength;
  25118. buffer = this.ensureBuffer(bufferLength + blockLen);
  25119. var end = bufferLength + blockLen;
  25120. this.bufferLength = end;
  25121. if (blockLen === 0) {
  25122. if (str.peekByte() === -1) {
  25123. this.eof = true;
  25124. }
  25125. } else {
  25126. for (var n = bufferLength; n < end; ++n) {
  25127. if ((b = str.getByte()) === -1) {
  25128. this.eof = true;
  25129. break;
  25130. }
  25131. buffer[n] = b;
  25132. }
  25133. }
  25134. return;
  25135. }
  25136. var litCodeTable;
  25137. var distCodeTable;
  25138. if (hdr === 1) {
  25139. // compressed block, fixed codes
  25140. litCodeTable = fixedLitCodeTab;
  25141. distCodeTable = fixedDistCodeTab;
  25142. } else if (hdr === 2) {
  25143. // compressed block, dynamic codes
  25144. var numLitCodes = this.getBits(5) + 257;
  25145. var numDistCodes = this.getBits(5) + 1;
  25146. var numCodeLenCodes = this.getBits(4) + 4;
  25147. // build the code lengths code table
  25148. var codeLenCodeLengths = new Uint8Array(codeLenCodeMap.length);
  25149. var i;
  25150. for (i = 0; i < numCodeLenCodes; ++i) {
  25151. codeLenCodeLengths[codeLenCodeMap[i]] = this.getBits(3);
  25152. }
  25153. var codeLenCodeTab = this.generateHuffmanTable(codeLenCodeLengths);
  25154. // build the literal and distance code tables
  25155. len = 0;
  25156. i = 0;
  25157. var codes = numLitCodes + numDistCodes;
  25158. var codeLengths = new Uint8Array(codes);
  25159. var bitsLength, bitsOffset, what;
  25160. while (i < codes) {
  25161. var code = this.getCode(codeLenCodeTab);
  25162. if (code === 16) {
  25163. bitsLength = 2;
  25164. bitsOffset = 3;
  25165. what = len;
  25166. } else if (code === 17) {
  25167. bitsLength = 3;
  25168. bitsOffset = 3;
  25169. what = len = 0;
  25170. } else if (code === 18) {
  25171. bitsLength = 7;
  25172. bitsOffset = 11;
  25173. what = len = 0;
  25174. } else {
  25175. codeLengths[i++] = len = code;
  25176. continue;
  25177. }
  25178. var repeatLength = this.getBits(bitsLength) + bitsOffset;
  25179. while (repeatLength-- > 0) {
  25180. codeLengths[i++] = what;
  25181. }
  25182. }
  25183. litCodeTable = this.generateHuffmanTable(codeLengths.subarray(0, numLitCodes));
  25184. distCodeTable = this.generateHuffmanTable(codeLengths.subarray(numLitCodes, codes));
  25185. } else {
  25186. error('Unknown block type in flate stream');
  25187. }
  25188. buffer = this.buffer;
  25189. var limit = buffer ? buffer.length : 0;
  25190. var pos = this.bufferLength;
  25191. while (true) {
  25192. var code1 = this.getCode(litCodeTable);
  25193. if (code1 < 256) {
  25194. if (pos + 1 >= limit) {
  25195. buffer = this.ensureBuffer(pos + 1);
  25196. limit = buffer.length;
  25197. }
  25198. buffer[pos++] = code1;
  25199. continue;
  25200. }
  25201. if (code1 === 256) {
  25202. this.bufferLength = pos;
  25203. return;
  25204. }
  25205. code1 -= 257;
  25206. code1 = lengthDecode[code1];
  25207. var code2 = code1 >> 16;
  25208. if (code2 > 0) {
  25209. code2 = this.getBits(code2);
  25210. }
  25211. len = (code1 & 0xffff) + code2;
  25212. code1 = this.getCode(distCodeTable);
  25213. code1 = distDecode[code1];
  25214. code2 = code1 >> 16;
  25215. if (code2 > 0) {
  25216. code2 = this.getBits(code2);
  25217. }
  25218. var dist = (code1 & 0xffff) + code2;
  25219. if (pos + len >= limit) {
  25220. buffer = this.ensureBuffer(pos + len);
  25221. limit = buffer.length;
  25222. }
  25223. for (var k = 0; k < len; ++k, ++pos) {
  25224. buffer[pos] = buffer[pos - dist];
  25225. }
  25226. }
  25227. };
  25228. return FlateStream;
  25229. }();
  25230. var PredictorStream = function PredictorStreamClosure() {
  25231. function PredictorStream(str, maybeLength, params) {
  25232. if (!isDict(params)) {
  25233. return str;
  25234. }
  25235. // no prediction
  25236. var predictor = this.predictor = params.get('Predictor') || 1;
  25237. if (predictor <= 1) {
  25238. return str;
  25239. }
  25240. // no prediction
  25241. if (predictor !== 2 && (predictor < 10 || predictor > 15)) {
  25242. error('Unsupported predictor: ' + predictor);
  25243. }
  25244. if (predictor === 2) {
  25245. this.readBlock = this.readBlockTiff;
  25246. } else {
  25247. this.readBlock = this.readBlockPng;
  25248. }
  25249. this.str = str;
  25250. this.dict = str.dict;
  25251. var colors = this.colors = params.get('Colors') || 1;
  25252. var bits = this.bits = params.get('BitsPerComponent') || 8;
  25253. var columns = this.columns = params.get('Columns') || 1;
  25254. this.pixBytes = colors * bits + 7 >> 3;
  25255. this.rowBytes = columns * colors * bits + 7 >> 3;
  25256. DecodeStream.call(this, maybeLength);
  25257. return this;
  25258. }
  25259. PredictorStream.prototype = Object.create(DecodeStream.prototype);
  25260. PredictorStream.prototype.readBlockTiff = function predictorStreamReadBlockTiff() {
  25261. var rowBytes = this.rowBytes;
  25262. var bufferLength = this.bufferLength;
  25263. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  25264. var bits = this.bits;
  25265. var colors = this.colors;
  25266. var rawBytes = this.str.getBytes(rowBytes);
  25267. this.eof = !rawBytes.length;
  25268. if (this.eof) {
  25269. return;
  25270. }
  25271. var inbuf = 0, outbuf = 0;
  25272. var inbits = 0, outbits = 0;
  25273. var pos = bufferLength;
  25274. var i;
  25275. if (bits === 1) {
  25276. for (i = 0; i < rowBytes; ++i) {
  25277. var c = rawBytes[i];
  25278. inbuf = inbuf << 8 | c;
  25279. // bitwise addition is exclusive or
  25280. // first shift inbuf and then add
  25281. buffer[pos++] = (c ^ inbuf >> colors) & 0xFF;
  25282. // truncate inbuf (assumes colors < 16)
  25283. inbuf &= 0xFFFF;
  25284. }
  25285. } else if (bits === 8) {
  25286. for (i = 0; i < colors; ++i) {
  25287. buffer[pos++] = rawBytes[i];
  25288. }
  25289. for (; i < rowBytes; ++i) {
  25290. buffer[pos] = buffer[pos - colors] + rawBytes[i];
  25291. pos++;
  25292. }
  25293. } else {
  25294. var compArray = new Uint8Array(colors + 1);
  25295. var bitMask = (1 << bits) - 1;
  25296. var j = 0, k = bufferLength;
  25297. var columns = this.columns;
  25298. for (i = 0; i < columns; ++i) {
  25299. for (var kk = 0; kk < colors; ++kk) {
  25300. if (inbits < bits) {
  25301. inbuf = inbuf << 8 | rawBytes[j++] & 0xFF;
  25302. inbits += 8;
  25303. }
  25304. compArray[kk] = compArray[kk] + (inbuf >> inbits - bits) & bitMask;
  25305. inbits -= bits;
  25306. outbuf = outbuf << bits | compArray[kk];
  25307. outbits += bits;
  25308. if (outbits >= 8) {
  25309. buffer[k++] = outbuf >> outbits - 8 & 0xFF;
  25310. outbits -= 8;
  25311. }
  25312. }
  25313. }
  25314. if (outbits > 0) {
  25315. buffer[k++] = (outbuf << 8 - outbits) + (inbuf & (1 << 8 - outbits) - 1);
  25316. }
  25317. }
  25318. this.bufferLength += rowBytes;
  25319. };
  25320. PredictorStream.prototype.readBlockPng = function predictorStreamReadBlockPng() {
  25321. var rowBytes = this.rowBytes;
  25322. var pixBytes = this.pixBytes;
  25323. var predictor = this.str.getByte();
  25324. var rawBytes = this.str.getBytes(rowBytes);
  25325. this.eof = !rawBytes.length;
  25326. if (this.eof) {
  25327. return;
  25328. }
  25329. var bufferLength = this.bufferLength;
  25330. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  25331. var prevRow = buffer.subarray(bufferLength - rowBytes, bufferLength);
  25332. if (prevRow.length === 0) {
  25333. prevRow = new Uint8Array(rowBytes);
  25334. }
  25335. var i, j = bufferLength, up, c;
  25336. switch (predictor) {
  25337. case 0:
  25338. for (i = 0; i < rowBytes; ++i) {
  25339. buffer[j++] = rawBytes[i];
  25340. }
  25341. break;
  25342. case 1:
  25343. for (i = 0; i < pixBytes; ++i) {
  25344. buffer[j++] = rawBytes[i];
  25345. }
  25346. for (; i < rowBytes; ++i) {
  25347. buffer[j] = buffer[j - pixBytes] + rawBytes[i] & 0xFF;
  25348. j++;
  25349. }
  25350. break;
  25351. case 2:
  25352. for (i = 0; i < rowBytes; ++i) {
  25353. buffer[j++] = prevRow[i] + rawBytes[i] & 0xFF;
  25354. }
  25355. break;
  25356. case 3:
  25357. for (i = 0; i < pixBytes; ++i) {
  25358. buffer[j++] = (prevRow[i] >> 1) + rawBytes[i];
  25359. }
  25360. for (; i < rowBytes; ++i) {
  25361. buffer[j] = (prevRow[i] + buffer[j - pixBytes] >> 1) + rawBytes[i] & 0xFF;
  25362. j++;
  25363. }
  25364. break;
  25365. case 4:
  25366. // we need to save the up left pixels values. the simplest way
  25367. // is to create a new buffer
  25368. for (i = 0; i < pixBytes; ++i) {
  25369. up = prevRow[i];
  25370. c = rawBytes[i];
  25371. buffer[j++] = up + c;
  25372. }
  25373. for (; i < rowBytes; ++i) {
  25374. up = prevRow[i];
  25375. var upLeft = prevRow[i - pixBytes];
  25376. var left = buffer[j - pixBytes];
  25377. var p = left + up - upLeft;
  25378. var pa = p - left;
  25379. if (pa < 0) {
  25380. pa = -pa;
  25381. }
  25382. var pb = p - up;
  25383. if (pb < 0) {
  25384. pb = -pb;
  25385. }
  25386. var pc = p - upLeft;
  25387. if (pc < 0) {
  25388. pc = -pc;
  25389. }
  25390. c = rawBytes[i];
  25391. if (pa <= pb && pa <= pc) {
  25392. buffer[j++] = left + c;
  25393. } else if (pb <= pc) {
  25394. buffer[j++] = up + c;
  25395. } else {
  25396. buffer[j++] = upLeft + c;
  25397. }
  25398. }
  25399. break;
  25400. default:
  25401. error('Unsupported predictor: ' + predictor);
  25402. }
  25403. this.bufferLength += rowBytes;
  25404. };
  25405. return PredictorStream;
  25406. }();
  25407. /**
  25408. * Depending on the type of JPEG a JpegStream is handled in different ways. For
  25409. * JPEG's that are supported natively such as DeviceGray and DeviceRGB the image
  25410. * data is stored and then loaded by the browser. For unsupported JPEG's we use
  25411. * a library to decode these images and the stream behaves like all the other
  25412. * DecodeStreams.
  25413. */
  25414. var JpegStream = function JpegStreamClosure() {
  25415. function JpegStream(stream, maybeLength, dict, params) {
  25416. // Some images may contain 'junk' before the SOI (start-of-image) marker.
  25417. // Note: this seems to mainly affect inline images.
  25418. var ch;
  25419. while ((ch = stream.getByte()) !== -1) {
  25420. if (ch === 0xFF) {
  25421. // Find the first byte of the SOI marker (0xFFD8).
  25422. stream.skip(-1);
  25423. // Reset the stream position to the SOI.
  25424. break;
  25425. }
  25426. }
  25427. this.stream = stream;
  25428. this.maybeLength = maybeLength;
  25429. this.dict = dict;
  25430. this.params = params;
  25431. DecodeStream.call(this, maybeLength);
  25432. }
  25433. JpegStream.prototype = Object.create(DecodeStream.prototype);
  25434. Object.defineProperty(JpegStream.prototype, 'bytes', {
  25435. get: function JpegStream_bytes() {
  25436. // If this.maybeLength is null, we'll get the entire stream.
  25437. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  25438. },
  25439. configurable: true
  25440. });
  25441. JpegStream.prototype.ensureBuffer = function JpegStream_ensureBuffer(req) {
  25442. if (this.bufferLength) {
  25443. return;
  25444. }
  25445. var jpegImage = new JpegImage();
  25446. // Checking if values need to be transformed before conversion.
  25447. var decodeArr = this.dict.getArray('Decode', 'D');
  25448. if (this.forceRGB && isArray(decodeArr)) {
  25449. var bitsPerComponent = this.dict.get('BitsPerComponent') || 8;
  25450. var decodeArrLength = decodeArr.length;
  25451. var transform = new Int32Array(decodeArrLength);
  25452. var transformNeeded = false;
  25453. var maxValue = (1 << bitsPerComponent) - 1;
  25454. for (var i = 0; i < decodeArrLength; i += 2) {
  25455. transform[i] = (decodeArr[i + 1] - decodeArr[i]) * 256 | 0;
  25456. transform[i + 1] = decodeArr[i] * maxValue | 0;
  25457. if (transform[i] !== 256 || transform[i + 1] !== 0) {
  25458. transformNeeded = true;
  25459. }
  25460. }
  25461. if (transformNeeded) {
  25462. jpegImage.decodeTransform = transform;
  25463. }
  25464. }
  25465. // Fetching the 'ColorTransform' entry, if it exists.
  25466. if (isDict(this.params)) {
  25467. var colorTransform = this.params.get('ColorTransform');
  25468. if (isInt(colorTransform)) {
  25469. jpegImage.colorTransform = colorTransform;
  25470. }
  25471. }
  25472. jpegImage.parse(this.bytes);
  25473. var data = jpegImage.getData(this.drawWidth, this.drawHeight, this.forceRGB);
  25474. this.buffer = data;
  25475. this.bufferLength = data.length;
  25476. this.eof = true;
  25477. };
  25478. JpegStream.prototype.getBytes = function JpegStream_getBytes(length) {
  25479. this.ensureBuffer();
  25480. return this.buffer;
  25481. };
  25482. JpegStream.prototype.getIR = function JpegStream_getIR(forceDataSchema) {
  25483. return createObjectURL(this.bytes, 'image/jpeg', forceDataSchema);
  25484. };
  25485. return JpegStream;
  25486. }();
  25487. /**
  25488. * For JPEG 2000's we use a library to decode these images and
  25489. * the stream behaves like all the other DecodeStreams.
  25490. */
  25491. var JpxStream = function JpxStreamClosure() {
  25492. function JpxStream(stream, maybeLength, dict, params) {
  25493. this.stream = stream;
  25494. this.maybeLength = maybeLength;
  25495. this.dict = dict;
  25496. this.params = params;
  25497. DecodeStream.call(this, maybeLength);
  25498. }
  25499. JpxStream.prototype = Object.create(DecodeStream.prototype);
  25500. Object.defineProperty(JpxStream.prototype, 'bytes', {
  25501. get: function JpxStream_bytes() {
  25502. // If this.maybeLength is null, we'll get the entire stream.
  25503. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  25504. },
  25505. configurable: true
  25506. });
  25507. JpxStream.prototype.ensureBuffer = function JpxStream_ensureBuffer(req) {
  25508. if (this.bufferLength) {
  25509. return;
  25510. }
  25511. var jpxImage = new JpxImage();
  25512. jpxImage.parse(this.bytes);
  25513. var width = jpxImage.width;
  25514. var height = jpxImage.height;
  25515. var componentsCount = jpxImage.componentsCount;
  25516. var tileCount = jpxImage.tiles.length;
  25517. if (tileCount === 1) {
  25518. this.buffer = jpxImage.tiles[0].items;
  25519. } else {
  25520. var data = new Uint8Array(width * height * componentsCount);
  25521. for (var k = 0; k < tileCount; k++) {
  25522. var tileComponents = jpxImage.tiles[k];
  25523. var tileWidth = tileComponents.width;
  25524. var tileHeight = tileComponents.height;
  25525. var tileLeft = tileComponents.left;
  25526. var tileTop = tileComponents.top;
  25527. var src = tileComponents.items;
  25528. var srcPosition = 0;
  25529. var dataPosition = (width * tileTop + tileLeft) * componentsCount;
  25530. var imgRowSize = width * componentsCount;
  25531. var tileRowSize = tileWidth * componentsCount;
  25532. for (var j = 0; j < tileHeight; j++) {
  25533. var rowBytes = src.subarray(srcPosition, srcPosition + tileRowSize);
  25534. data.set(rowBytes, dataPosition);
  25535. srcPosition += tileRowSize;
  25536. dataPosition += imgRowSize;
  25537. }
  25538. }
  25539. this.buffer = data;
  25540. }
  25541. this.bufferLength = this.buffer.length;
  25542. this.eof = true;
  25543. };
  25544. return JpxStream;
  25545. }();
  25546. /**
  25547. * For JBIG2's we use a library to decode these images and
  25548. * the stream behaves like all the other DecodeStreams.
  25549. */
  25550. var Jbig2Stream = function Jbig2StreamClosure() {
  25551. function Jbig2Stream(stream, maybeLength, dict, params) {
  25552. this.stream = stream;
  25553. this.maybeLength = maybeLength;
  25554. this.dict = dict;
  25555. this.params = params;
  25556. DecodeStream.call(this, maybeLength);
  25557. }
  25558. Jbig2Stream.prototype = Object.create(DecodeStream.prototype);
  25559. Object.defineProperty(Jbig2Stream.prototype, 'bytes', {
  25560. get: function Jbig2Stream_bytes() {
  25561. // If this.maybeLength is null, we'll get the entire stream.
  25562. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  25563. },
  25564. configurable: true
  25565. });
  25566. Jbig2Stream.prototype.ensureBuffer = function Jbig2Stream_ensureBuffer(req) {
  25567. if (this.bufferLength) {
  25568. return;
  25569. }
  25570. var jbig2Image = new Jbig2Image();
  25571. var chunks = [];
  25572. if (isDict(this.params)) {
  25573. var globalsStream = this.params.get('JBIG2Globals');
  25574. if (isStream(globalsStream)) {
  25575. var globals = globalsStream.getBytes();
  25576. chunks.push({
  25577. data: globals,
  25578. start: 0,
  25579. end: globals.length
  25580. });
  25581. }
  25582. }
  25583. chunks.push({
  25584. data: this.bytes,
  25585. start: 0,
  25586. end: this.bytes.length
  25587. });
  25588. var data = jbig2Image.parseChunks(chunks);
  25589. var dataLength = data.length;
  25590. // JBIG2 had black as 1 and white as 0, inverting the colors
  25591. for (var i = 0; i < dataLength; i++) {
  25592. data[i] ^= 0xFF;
  25593. }
  25594. this.buffer = data;
  25595. this.bufferLength = dataLength;
  25596. this.eof = true;
  25597. };
  25598. return Jbig2Stream;
  25599. }();
  25600. var DecryptStream = function DecryptStreamClosure() {
  25601. function DecryptStream(str, maybeLength, decrypt) {
  25602. this.str = str;
  25603. this.dict = str.dict;
  25604. this.decrypt = decrypt;
  25605. this.nextChunk = null;
  25606. this.initialized = false;
  25607. DecodeStream.call(this, maybeLength);
  25608. }
  25609. var chunkSize = 512;
  25610. DecryptStream.prototype = Object.create(DecodeStream.prototype);
  25611. DecryptStream.prototype.readBlock = function DecryptStream_readBlock() {
  25612. var chunk;
  25613. if (this.initialized) {
  25614. chunk = this.nextChunk;
  25615. } else {
  25616. chunk = this.str.getBytes(chunkSize);
  25617. this.initialized = true;
  25618. }
  25619. if (!chunk || chunk.length === 0) {
  25620. this.eof = true;
  25621. return;
  25622. }
  25623. this.nextChunk = this.str.getBytes(chunkSize);
  25624. var hasMoreData = this.nextChunk && this.nextChunk.length > 0;
  25625. var decrypt = this.decrypt;
  25626. chunk = decrypt(chunk, !hasMoreData);
  25627. var bufferLength = this.bufferLength;
  25628. var i, n = chunk.length;
  25629. var buffer = this.ensureBuffer(bufferLength + n);
  25630. for (i = 0; i < n; i++) {
  25631. buffer[bufferLength++] = chunk[i];
  25632. }
  25633. this.bufferLength = bufferLength;
  25634. };
  25635. return DecryptStream;
  25636. }();
  25637. var Ascii85Stream = function Ascii85StreamClosure() {
  25638. function Ascii85Stream(str, maybeLength) {
  25639. this.str = str;
  25640. this.dict = str.dict;
  25641. this.input = new Uint8Array(5);
  25642. // Most streams increase in size when decoded, but Ascii85 streams
  25643. // typically shrink by ~20%.
  25644. if (maybeLength) {
  25645. maybeLength = 0.8 * maybeLength;
  25646. }
  25647. DecodeStream.call(this, maybeLength);
  25648. }
  25649. Ascii85Stream.prototype = Object.create(DecodeStream.prototype);
  25650. Ascii85Stream.prototype.readBlock = function Ascii85Stream_readBlock() {
  25651. var TILDA_CHAR = 0x7E;
  25652. // '~'
  25653. var Z_LOWER_CHAR = 0x7A;
  25654. // 'z'
  25655. var EOF = -1;
  25656. var str = this.str;
  25657. var c = str.getByte();
  25658. while (isSpace(c)) {
  25659. c = str.getByte();
  25660. }
  25661. if (c === EOF || c === TILDA_CHAR) {
  25662. this.eof = true;
  25663. return;
  25664. }
  25665. var bufferLength = this.bufferLength, buffer;
  25666. var i;
  25667. // special code for z
  25668. if (c === Z_LOWER_CHAR) {
  25669. buffer = this.ensureBuffer(bufferLength + 4);
  25670. for (i = 0; i < 4; ++i) {
  25671. buffer[bufferLength + i] = 0;
  25672. }
  25673. this.bufferLength += 4;
  25674. } else {
  25675. var input = this.input;
  25676. input[0] = c;
  25677. for (i = 1; i < 5; ++i) {
  25678. c = str.getByte();
  25679. while (isSpace(c)) {
  25680. c = str.getByte();
  25681. }
  25682. input[i] = c;
  25683. if (c === EOF || c === TILDA_CHAR) {
  25684. break;
  25685. }
  25686. }
  25687. buffer = this.ensureBuffer(bufferLength + i - 1);
  25688. this.bufferLength += i - 1;
  25689. // partial ending;
  25690. if (i < 5) {
  25691. for (; i < 5; ++i) {
  25692. input[i] = 0x21 + 84;
  25693. }
  25694. this.eof = true;
  25695. }
  25696. var t = 0;
  25697. for (i = 0; i < 5; ++i) {
  25698. t = t * 85 + (input[i] - 0x21);
  25699. }
  25700. for (i = 3; i >= 0; --i) {
  25701. buffer[bufferLength + i] = t & 0xFF;
  25702. t >>= 8;
  25703. }
  25704. }
  25705. };
  25706. return Ascii85Stream;
  25707. }();
  25708. var AsciiHexStream = function AsciiHexStreamClosure() {
  25709. function AsciiHexStream(str, maybeLength) {
  25710. this.str = str;
  25711. this.dict = str.dict;
  25712. this.firstDigit = -1;
  25713. // Most streams increase in size when decoded, but AsciiHex streams shrink
  25714. // by 50%.
  25715. if (maybeLength) {
  25716. maybeLength = 0.5 * maybeLength;
  25717. }
  25718. DecodeStream.call(this, maybeLength);
  25719. }
  25720. AsciiHexStream.prototype = Object.create(DecodeStream.prototype);
  25721. AsciiHexStream.prototype.readBlock = function AsciiHexStream_readBlock() {
  25722. var UPSTREAM_BLOCK_SIZE = 8000;
  25723. var bytes = this.str.getBytes(UPSTREAM_BLOCK_SIZE);
  25724. if (!bytes.length) {
  25725. this.eof = true;
  25726. return;
  25727. }
  25728. var maxDecodeLength = bytes.length + 1 >> 1;
  25729. var buffer = this.ensureBuffer(this.bufferLength + maxDecodeLength);
  25730. var bufferLength = this.bufferLength;
  25731. var firstDigit = this.firstDigit;
  25732. for (var i = 0, ii = bytes.length; i < ii; i++) {
  25733. var ch = bytes[i], digit;
  25734. if (ch >= 0x30 && ch <= 0x39) {
  25735. // '0'-'9'
  25736. digit = ch & 0x0F;
  25737. } else if (ch >= 0x41 && ch <= 0x46 || ch >= 0x61 && ch <= 0x66) {
  25738. // 'A'-'Z', 'a'-'z'
  25739. digit = (ch & 0x0F) + 9;
  25740. } else if (ch === 0x3E) {
  25741. // '>'
  25742. this.eof = true;
  25743. break;
  25744. } else {
  25745. // probably whitespace
  25746. continue;
  25747. }
  25748. // ignoring
  25749. if (firstDigit < 0) {
  25750. firstDigit = digit;
  25751. } else {
  25752. buffer[bufferLength++] = firstDigit << 4 | digit;
  25753. firstDigit = -1;
  25754. }
  25755. }
  25756. if (firstDigit >= 0 && this.eof) {
  25757. // incomplete byte
  25758. buffer[bufferLength++] = firstDigit << 4;
  25759. firstDigit = -1;
  25760. }
  25761. this.firstDigit = firstDigit;
  25762. this.bufferLength = bufferLength;
  25763. };
  25764. return AsciiHexStream;
  25765. }();
  25766. var RunLengthStream = function RunLengthStreamClosure() {
  25767. function RunLengthStream(str, maybeLength) {
  25768. this.str = str;
  25769. this.dict = str.dict;
  25770. DecodeStream.call(this, maybeLength);
  25771. }
  25772. RunLengthStream.prototype = Object.create(DecodeStream.prototype);
  25773. RunLengthStream.prototype.readBlock = function RunLengthStream_readBlock() {
  25774. // The repeatHeader has following format. The first byte defines type of run
  25775. // and amount of bytes to repeat/copy: n = 0 through 127 - copy next n bytes
  25776. // (in addition to the second byte from the header), n = 129 through 255 -
  25777. // duplicate the second byte from the header (257 - n) times, n = 128 - end.
  25778. var repeatHeader = this.str.getBytes(2);
  25779. if (!repeatHeader || repeatHeader.length < 2 || repeatHeader[0] === 128) {
  25780. this.eof = true;
  25781. return;
  25782. }
  25783. var buffer;
  25784. var bufferLength = this.bufferLength;
  25785. var n = repeatHeader[0];
  25786. if (n < 128) {
  25787. // copy n bytes
  25788. buffer = this.ensureBuffer(bufferLength + n + 1);
  25789. buffer[bufferLength++] = repeatHeader[1];
  25790. if (n > 0) {
  25791. var source = this.str.getBytes(n);
  25792. buffer.set(source, bufferLength);
  25793. bufferLength += n;
  25794. }
  25795. } else {
  25796. n = 257 - n;
  25797. var b = repeatHeader[1];
  25798. buffer = this.ensureBuffer(bufferLength + n + 1);
  25799. for (var i = 0; i < n; i++) {
  25800. buffer[bufferLength++] = b;
  25801. }
  25802. }
  25803. this.bufferLength = bufferLength;
  25804. };
  25805. return RunLengthStream;
  25806. }();
  25807. var CCITTFaxStream = function CCITTFaxStreamClosure() {
  25808. var ccittEOL = -2;
  25809. var ccittEOF = -1;
  25810. var twoDimPass = 0;
  25811. var twoDimHoriz = 1;
  25812. var twoDimVert0 = 2;
  25813. var twoDimVertR1 = 3;
  25814. var twoDimVertL1 = 4;
  25815. var twoDimVertR2 = 5;
  25816. var twoDimVertL2 = 6;
  25817. var twoDimVertR3 = 7;
  25818. var twoDimVertL3 = 8;
  25819. var twoDimTable = [
  25820. [
  25821. -1,
  25822. -1
  25823. ],
  25824. [
  25825. -1,
  25826. -1
  25827. ],
  25828. // 000000x
  25829. [
  25830. 7,
  25831. twoDimVertL3
  25832. ],
  25833. // 0000010
  25834. [
  25835. 7,
  25836. twoDimVertR3
  25837. ],
  25838. // 0000011
  25839. [
  25840. 6,
  25841. twoDimVertL2
  25842. ],
  25843. [
  25844. 6,
  25845. twoDimVertL2
  25846. ],
  25847. // 000010x
  25848. [
  25849. 6,
  25850. twoDimVertR2
  25851. ],
  25852. [
  25853. 6,
  25854. twoDimVertR2
  25855. ],
  25856. // 000011x
  25857. [
  25858. 4,
  25859. twoDimPass
  25860. ],
  25861. [
  25862. 4,
  25863. twoDimPass
  25864. ],
  25865. // 0001xxx
  25866. [
  25867. 4,
  25868. twoDimPass
  25869. ],
  25870. [
  25871. 4,
  25872. twoDimPass
  25873. ],
  25874. [
  25875. 4,
  25876. twoDimPass
  25877. ],
  25878. [
  25879. 4,
  25880. twoDimPass
  25881. ],
  25882. [
  25883. 4,
  25884. twoDimPass
  25885. ],
  25886. [
  25887. 4,
  25888. twoDimPass
  25889. ],
  25890. [
  25891. 3,
  25892. twoDimHoriz
  25893. ],
  25894. [
  25895. 3,
  25896. twoDimHoriz
  25897. ],
  25898. // 001xxxx
  25899. [
  25900. 3,
  25901. twoDimHoriz
  25902. ],
  25903. [
  25904. 3,
  25905. twoDimHoriz
  25906. ],
  25907. [
  25908. 3,
  25909. twoDimHoriz
  25910. ],
  25911. [
  25912. 3,
  25913. twoDimHoriz
  25914. ],
  25915. [
  25916. 3,
  25917. twoDimHoriz
  25918. ],
  25919. [
  25920. 3,
  25921. twoDimHoriz
  25922. ],
  25923. [
  25924. 3,
  25925. twoDimHoriz
  25926. ],
  25927. [
  25928. 3,
  25929. twoDimHoriz
  25930. ],
  25931. [
  25932. 3,
  25933. twoDimHoriz
  25934. ],
  25935. [
  25936. 3,
  25937. twoDimHoriz
  25938. ],
  25939. [
  25940. 3,
  25941. twoDimHoriz
  25942. ],
  25943. [
  25944. 3,
  25945. twoDimHoriz
  25946. ],
  25947. [
  25948. 3,
  25949. twoDimHoriz
  25950. ],
  25951. [
  25952. 3,
  25953. twoDimHoriz
  25954. ],
  25955. [
  25956. 3,
  25957. twoDimVertL1
  25958. ],
  25959. [
  25960. 3,
  25961. twoDimVertL1
  25962. ],
  25963. // 010xxxx
  25964. [
  25965. 3,
  25966. twoDimVertL1
  25967. ],
  25968. [
  25969. 3,
  25970. twoDimVertL1
  25971. ],
  25972. [
  25973. 3,
  25974. twoDimVertL1
  25975. ],
  25976. [
  25977. 3,
  25978. twoDimVertL1
  25979. ],
  25980. [
  25981. 3,
  25982. twoDimVertL1
  25983. ],
  25984. [
  25985. 3,
  25986. twoDimVertL1
  25987. ],
  25988. [
  25989. 3,
  25990. twoDimVertL1
  25991. ],
  25992. [
  25993. 3,
  25994. twoDimVertL1
  25995. ],
  25996. [
  25997. 3,
  25998. twoDimVertL1
  25999. ],
  26000. [
  26001. 3,
  26002. twoDimVertL1
  26003. ],
  26004. [
  26005. 3,
  26006. twoDimVertL1
  26007. ],
  26008. [
  26009. 3,
  26010. twoDimVertL1
  26011. ],
  26012. [
  26013. 3,
  26014. twoDimVertL1
  26015. ],
  26016. [
  26017. 3,
  26018. twoDimVertL1
  26019. ],
  26020. [
  26021. 3,
  26022. twoDimVertR1
  26023. ],
  26024. [
  26025. 3,
  26026. twoDimVertR1
  26027. ],
  26028. // 011xxxx
  26029. [
  26030. 3,
  26031. twoDimVertR1
  26032. ],
  26033. [
  26034. 3,
  26035. twoDimVertR1
  26036. ],
  26037. [
  26038. 3,
  26039. twoDimVertR1
  26040. ],
  26041. [
  26042. 3,
  26043. twoDimVertR1
  26044. ],
  26045. [
  26046. 3,
  26047. twoDimVertR1
  26048. ],
  26049. [
  26050. 3,
  26051. twoDimVertR1
  26052. ],
  26053. [
  26054. 3,
  26055. twoDimVertR1
  26056. ],
  26057. [
  26058. 3,
  26059. twoDimVertR1
  26060. ],
  26061. [
  26062. 3,
  26063. twoDimVertR1
  26064. ],
  26065. [
  26066. 3,
  26067. twoDimVertR1
  26068. ],
  26069. [
  26070. 3,
  26071. twoDimVertR1
  26072. ],
  26073. [
  26074. 3,
  26075. twoDimVertR1
  26076. ],
  26077. [
  26078. 3,
  26079. twoDimVertR1
  26080. ],
  26081. [
  26082. 3,
  26083. twoDimVertR1
  26084. ],
  26085. [
  26086. 1,
  26087. twoDimVert0
  26088. ],
  26089. [
  26090. 1,
  26091. twoDimVert0
  26092. ],
  26093. // 1xxxxxx
  26094. [
  26095. 1,
  26096. twoDimVert0
  26097. ],
  26098. [
  26099. 1,
  26100. twoDimVert0
  26101. ],
  26102. [
  26103. 1,
  26104. twoDimVert0
  26105. ],
  26106. [
  26107. 1,
  26108. twoDimVert0
  26109. ],
  26110. [
  26111. 1,
  26112. twoDimVert0
  26113. ],
  26114. [
  26115. 1,
  26116. twoDimVert0
  26117. ],
  26118. [
  26119. 1,
  26120. twoDimVert0
  26121. ],
  26122. [
  26123. 1,
  26124. twoDimVert0
  26125. ],
  26126. [
  26127. 1,
  26128. twoDimVert0
  26129. ],
  26130. [
  26131. 1,
  26132. twoDimVert0
  26133. ],
  26134. [
  26135. 1,
  26136. twoDimVert0
  26137. ],
  26138. [
  26139. 1,
  26140. twoDimVert0
  26141. ],
  26142. [
  26143. 1,
  26144. twoDimVert0
  26145. ],
  26146. [
  26147. 1,
  26148. twoDimVert0
  26149. ],
  26150. [
  26151. 1,
  26152. twoDimVert0
  26153. ],
  26154. [
  26155. 1,
  26156. twoDimVert0
  26157. ],
  26158. [
  26159. 1,
  26160. twoDimVert0
  26161. ],
  26162. [
  26163. 1,
  26164. twoDimVert0
  26165. ],
  26166. [
  26167. 1,
  26168. twoDimVert0
  26169. ],
  26170. [
  26171. 1,
  26172. twoDimVert0
  26173. ],
  26174. [
  26175. 1,
  26176. twoDimVert0
  26177. ],
  26178. [
  26179. 1,
  26180. twoDimVert0
  26181. ],
  26182. [
  26183. 1,
  26184. twoDimVert0
  26185. ],
  26186. [
  26187. 1,
  26188. twoDimVert0
  26189. ],
  26190. [
  26191. 1,
  26192. twoDimVert0
  26193. ],
  26194. [
  26195. 1,
  26196. twoDimVert0
  26197. ],
  26198. [
  26199. 1,
  26200. twoDimVert0
  26201. ],
  26202. [
  26203. 1,
  26204. twoDimVert0
  26205. ],
  26206. [
  26207. 1,
  26208. twoDimVert0
  26209. ],
  26210. [
  26211. 1,
  26212. twoDimVert0
  26213. ],
  26214. [
  26215. 1,
  26216. twoDimVert0
  26217. ],
  26218. [
  26219. 1,
  26220. twoDimVert0
  26221. ],
  26222. [
  26223. 1,
  26224. twoDimVert0
  26225. ],
  26226. [
  26227. 1,
  26228. twoDimVert0
  26229. ],
  26230. [
  26231. 1,
  26232. twoDimVert0
  26233. ],
  26234. [
  26235. 1,
  26236. twoDimVert0
  26237. ],
  26238. [
  26239. 1,
  26240. twoDimVert0
  26241. ],
  26242. [
  26243. 1,
  26244. twoDimVert0
  26245. ],
  26246. [
  26247. 1,
  26248. twoDimVert0
  26249. ],
  26250. [
  26251. 1,
  26252. twoDimVert0
  26253. ],
  26254. [
  26255. 1,
  26256. twoDimVert0
  26257. ],
  26258. [
  26259. 1,
  26260. twoDimVert0
  26261. ],
  26262. [
  26263. 1,
  26264. twoDimVert0
  26265. ],
  26266. [
  26267. 1,
  26268. twoDimVert0
  26269. ],
  26270. [
  26271. 1,
  26272. twoDimVert0
  26273. ],
  26274. [
  26275. 1,
  26276. twoDimVert0
  26277. ],
  26278. [
  26279. 1,
  26280. twoDimVert0
  26281. ],
  26282. [
  26283. 1,
  26284. twoDimVert0
  26285. ],
  26286. [
  26287. 1,
  26288. twoDimVert0
  26289. ],
  26290. [
  26291. 1,
  26292. twoDimVert0
  26293. ],
  26294. [
  26295. 1,
  26296. twoDimVert0
  26297. ],
  26298. [
  26299. 1,
  26300. twoDimVert0
  26301. ],
  26302. [
  26303. 1,
  26304. twoDimVert0
  26305. ],
  26306. [
  26307. 1,
  26308. twoDimVert0
  26309. ],
  26310. [
  26311. 1,
  26312. twoDimVert0
  26313. ],
  26314. [
  26315. 1,
  26316. twoDimVert0
  26317. ],
  26318. [
  26319. 1,
  26320. twoDimVert0
  26321. ],
  26322. [
  26323. 1,
  26324. twoDimVert0
  26325. ],
  26326. [
  26327. 1,
  26328. twoDimVert0
  26329. ],
  26330. [
  26331. 1,
  26332. twoDimVert0
  26333. ],
  26334. [
  26335. 1,
  26336. twoDimVert0
  26337. ],
  26338. [
  26339. 1,
  26340. twoDimVert0
  26341. ]
  26342. ];
  26343. var whiteTable1 = [
  26344. [
  26345. -1,
  26346. -1
  26347. ],
  26348. // 00000
  26349. [
  26350. 12,
  26351. ccittEOL
  26352. ],
  26353. // 00001
  26354. [
  26355. -1,
  26356. -1
  26357. ],
  26358. [
  26359. -1,
  26360. -1
  26361. ],
  26362. // 0001x
  26363. [
  26364. -1,
  26365. -1
  26366. ],
  26367. [
  26368. -1,
  26369. -1
  26370. ],
  26371. [
  26372. -1,
  26373. -1
  26374. ],
  26375. [
  26376. -1,
  26377. -1
  26378. ],
  26379. // 001xx
  26380. [
  26381. -1,
  26382. -1
  26383. ],
  26384. [
  26385. -1,
  26386. -1
  26387. ],
  26388. [
  26389. -1,
  26390. -1
  26391. ],
  26392. [
  26393. -1,
  26394. -1
  26395. ],
  26396. // 010xx
  26397. [
  26398. -1,
  26399. -1
  26400. ],
  26401. [
  26402. -1,
  26403. -1
  26404. ],
  26405. [
  26406. -1,
  26407. -1
  26408. ],
  26409. [
  26410. -1,
  26411. -1
  26412. ],
  26413. // 011xx
  26414. [
  26415. 11,
  26416. 1792
  26417. ],
  26418. [
  26419. 11,
  26420. 1792
  26421. ],
  26422. // 1000x
  26423. [
  26424. 12,
  26425. 1984
  26426. ],
  26427. // 10010
  26428. [
  26429. 12,
  26430. 2048
  26431. ],
  26432. // 10011
  26433. [
  26434. 12,
  26435. 2112
  26436. ],
  26437. // 10100
  26438. [
  26439. 12,
  26440. 2176
  26441. ],
  26442. // 10101
  26443. [
  26444. 12,
  26445. 2240
  26446. ],
  26447. // 10110
  26448. [
  26449. 12,
  26450. 2304
  26451. ],
  26452. // 10111
  26453. [
  26454. 11,
  26455. 1856
  26456. ],
  26457. [
  26458. 11,
  26459. 1856
  26460. ],
  26461. // 1100x
  26462. [
  26463. 11,
  26464. 1920
  26465. ],
  26466. [
  26467. 11,
  26468. 1920
  26469. ],
  26470. // 1101x
  26471. [
  26472. 12,
  26473. 2368
  26474. ],
  26475. // 11100
  26476. [
  26477. 12,
  26478. 2432
  26479. ],
  26480. // 11101
  26481. [
  26482. 12,
  26483. 2496
  26484. ],
  26485. // 11110
  26486. [
  26487. 12,
  26488. 2560
  26489. ]
  26490. ];
  26491. // 11111
  26492. var whiteTable2 = [
  26493. [
  26494. -1,
  26495. -1
  26496. ],
  26497. [
  26498. -1,
  26499. -1
  26500. ],
  26501. [
  26502. -1,
  26503. -1
  26504. ],
  26505. [
  26506. -1,
  26507. -1
  26508. ],
  26509. // 0000000xx
  26510. [
  26511. 8,
  26512. 29
  26513. ],
  26514. [
  26515. 8,
  26516. 29
  26517. ],
  26518. // 00000010x
  26519. [
  26520. 8,
  26521. 30
  26522. ],
  26523. [
  26524. 8,
  26525. 30
  26526. ],
  26527. // 00000011x
  26528. [
  26529. 8,
  26530. 45
  26531. ],
  26532. [
  26533. 8,
  26534. 45
  26535. ],
  26536. // 00000100x
  26537. [
  26538. 8,
  26539. 46
  26540. ],
  26541. [
  26542. 8,
  26543. 46
  26544. ],
  26545. // 00000101x
  26546. [
  26547. 7,
  26548. 22
  26549. ],
  26550. [
  26551. 7,
  26552. 22
  26553. ],
  26554. [
  26555. 7,
  26556. 22
  26557. ],
  26558. [
  26559. 7,
  26560. 22
  26561. ],
  26562. // 0000011xx
  26563. [
  26564. 7,
  26565. 23
  26566. ],
  26567. [
  26568. 7,
  26569. 23
  26570. ],
  26571. [
  26572. 7,
  26573. 23
  26574. ],
  26575. [
  26576. 7,
  26577. 23
  26578. ],
  26579. // 0000100xx
  26580. [
  26581. 8,
  26582. 47
  26583. ],
  26584. [
  26585. 8,
  26586. 47
  26587. ],
  26588. // 00001010x
  26589. [
  26590. 8,
  26591. 48
  26592. ],
  26593. [
  26594. 8,
  26595. 48
  26596. ],
  26597. // 00001011x
  26598. [
  26599. 6,
  26600. 13
  26601. ],
  26602. [
  26603. 6,
  26604. 13
  26605. ],
  26606. [
  26607. 6,
  26608. 13
  26609. ],
  26610. [
  26611. 6,
  26612. 13
  26613. ],
  26614. // 000011xxx
  26615. [
  26616. 6,
  26617. 13
  26618. ],
  26619. [
  26620. 6,
  26621. 13
  26622. ],
  26623. [
  26624. 6,
  26625. 13
  26626. ],
  26627. [
  26628. 6,
  26629. 13
  26630. ],
  26631. [
  26632. 7,
  26633. 20
  26634. ],
  26635. [
  26636. 7,
  26637. 20
  26638. ],
  26639. [
  26640. 7,
  26641. 20
  26642. ],
  26643. [
  26644. 7,
  26645. 20
  26646. ],
  26647. // 0001000xx
  26648. [
  26649. 8,
  26650. 33
  26651. ],
  26652. [
  26653. 8,
  26654. 33
  26655. ],
  26656. // 00010010x
  26657. [
  26658. 8,
  26659. 34
  26660. ],
  26661. [
  26662. 8,
  26663. 34
  26664. ],
  26665. // 00010011x
  26666. [
  26667. 8,
  26668. 35
  26669. ],
  26670. [
  26671. 8,
  26672. 35
  26673. ],
  26674. // 00010100x
  26675. [
  26676. 8,
  26677. 36
  26678. ],
  26679. [
  26680. 8,
  26681. 36
  26682. ],
  26683. // 00010101x
  26684. [
  26685. 8,
  26686. 37
  26687. ],
  26688. [
  26689. 8,
  26690. 37
  26691. ],
  26692. // 00010110x
  26693. [
  26694. 8,
  26695. 38
  26696. ],
  26697. [
  26698. 8,
  26699. 38
  26700. ],
  26701. // 00010111x
  26702. [
  26703. 7,
  26704. 19
  26705. ],
  26706. [
  26707. 7,
  26708. 19
  26709. ],
  26710. [
  26711. 7,
  26712. 19
  26713. ],
  26714. [
  26715. 7,
  26716. 19
  26717. ],
  26718. // 0001100xx
  26719. [
  26720. 8,
  26721. 31
  26722. ],
  26723. [
  26724. 8,
  26725. 31
  26726. ],
  26727. // 00011010x
  26728. [
  26729. 8,
  26730. 32
  26731. ],
  26732. [
  26733. 8,
  26734. 32
  26735. ],
  26736. // 00011011x
  26737. [
  26738. 6,
  26739. 1
  26740. ],
  26741. [
  26742. 6,
  26743. 1
  26744. ],
  26745. [
  26746. 6,
  26747. 1
  26748. ],
  26749. [
  26750. 6,
  26751. 1
  26752. ],
  26753. // 000111xxx
  26754. [
  26755. 6,
  26756. 1
  26757. ],
  26758. [
  26759. 6,
  26760. 1
  26761. ],
  26762. [
  26763. 6,
  26764. 1
  26765. ],
  26766. [
  26767. 6,
  26768. 1
  26769. ],
  26770. [
  26771. 6,
  26772. 12
  26773. ],
  26774. [
  26775. 6,
  26776. 12
  26777. ],
  26778. [
  26779. 6,
  26780. 12
  26781. ],
  26782. [
  26783. 6,
  26784. 12
  26785. ],
  26786. // 001000xxx
  26787. [
  26788. 6,
  26789. 12
  26790. ],
  26791. [
  26792. 6,
  26793. 12
  26794. ],
  26795. [
  26796. 6,
  26797. 12
  26798. ],
  26799. [
  26800. 6,
  26801. 12
  26802. ],
  26803. [
  26804. 8,
  26805. 53
  26806. ],
  26807. [
  26808. 8,
  26809. 53
  26810. ],
  26811. // 00100100x
  26812. [
  26813. 8,
  26814. 54
  26815. ],
  26816. [
  26817. 8,
  26818. 54
  26819. ],
  26820. // 00100101x
  26821. [
  26822. 7,
  26823. 26
  26824. ],
  26825. [
  26826. 7,
  26827. 26
  26828. ],
  26829. [
  26830. 7,
  26831. 26
  26832. ],
  26833. [
  26834. 7,
  26835. 26
  26836. ],
  26837. // 0010011xx
  26838. [
  26839. 8,
  26840. 39
  26841. ],
  26842. [
  26843. 8,
  26844. 39
  26845. ],
  26846. // 00101000x
  26847. [
  26848. 8,
  26849. 40
  26850. ],
  26851. [
  26852. 8,
  26853. 40
  26854. ],
  26855. // 00101001x
  26856. [
  26857. 8,
  26858. 41
  26859. ],
  26860. [
  26861. 8,
  26862. 41
  26863. ],
  26864. // 00101010x
  26865. [
  26866. 8,
  26867. 42
  26868. ],
  26869. [
  26870. 8,
  26871. 42
  26872. ],
  26873. // 00101011x
  26874. [
  26875. 8,
  26876. 43
  26877. ],
  26878. [
  26879. 8,
  26880. 43
  26881. ],
  26882. // 00101100x
  26883. [
  26884. 8,
  26885. 44
  26886. ],
  26887. [
  26888. 8,
  26889. 44
  26890. ],
  26891. // 00101101x
  26892. [
  26893. 7,
  26894. 21
  26895. ],
  26896. [
  26897. 7,
  26898. 21
  26899. ],
  26900. [
  26901. 7,
  26902. 21
  26903. ],
  26904. [
  26905. 7,
  26906. 21
  26907. ],
  26908. // 0010111xx
  26909. [
  26910. 7,
  26911. 28
  26912. ],
  26913. [
  26914. 7,
  26915. 28
  26916. ],
  26917. [
  26918. 7,
  26919. 28
  26920. ],
  26921. [
  26922. 7,
  26923. 28
  26924. ],
  26925. // 0011000xx
  26926. [
  26927. 8,
  26928. 61
  26929. ],
  26930. [
  26931. 8,
  26932. 61
  26933. ],
  26934. // 00110010x
  26935. [
  26936. 8,
  26937. 62
  26938. ],
  26939. [
  26940. 8,
  26941. 62
  26942. ],
  26943. // 00110011x
  26944. [
  26945. 8,
  26946. 63
  26947. ],
  26948. [
  26949. 8,
  26950. 63
  26951. ],
  26952. // 00110100x
  26953. [
  26954. 8,
  26955. 0
  26956. ],
  26957. [
  26958. 8,
  26959. 0
  26960. ],
  26961. // 00110101x
  26962. [
  26963. 8,
  26964. 320
  26965. ],
  26966. [
  26967. 8,
  26968. 320
  26969. ],
  26970. // 00110110x
  26971. [
  26972. 8,
  26973. 384
  26974. ],
  26975. [
  26976. 8,
  26977. 384
  26978. ],
  26979. // 00110111x
  26980. [
  26981. 5,
  26982. 10
  26983. ],
  26984. [
  26985. 5,
  26986. 10
  26987. ],
  26988. [
  26989. 5,
  26990. 10
  26991. ],
  26992. [
  26993. 5,
  26994. 10
  26995. ],
  26996. // 00111xxxx
  26997. [
  26998. 5,
  26999. 10
  27000. ],
  27001. [
  27002. 5,
  27003. 10
  27004. ],
  27005. [
  27006. 5,
  27007. 10
  27008. ],
  27009. [
  27010. 5,
  27011. 10
  27012. ],
  27013. [
  27014. 5,
  27015. 10
  27016. ],
  27017. [
  27018. 5,
  27019. 10
  27020. ],
  27021. [
  27022. 5,
  27023. 10
  27024. ],
  27025. [
  27026. 5,
  27027. 10
  27028. ],
  27029. [
  27030. 5,
  27031. 10
  27032. ],
  27033. [
  27034. 5,
  27035. 10
  27036. ],
  27037. [
  27038. 5,
  27039. 10
  27040. ],
  27041. [
  27042. 5,
  27043. 10
  27044. ],
  27045. [
  27046. 5,
  27047. 11
  27048. ],
  27049. [
  27050. 5,
  27051. 11
  27052. ],
  27053. [
  27054. 5,
  27055. 11
  27056. ],
  27057. [
  27058. 5,
  27059. 11
  27060. ],
  27061. // 01000xxxx
  27062. [
  27063. 5,
  27064. 11
  27065. ],
  27066. [
  27067. 5,
  27068. 11
  27069. ],
  27070. [
  27071. 5,
  27072. 11
  27073. ],
  27074. [
  27075. 5,
  27076. 11
  27077. ],
  27078. [
  27079. 5,
  27080. 11
  27081. ],
  27082. [
  27083. 5,
  27084. 11
  27085. ],
  27086. [
  27087. 5,
  27088. 11
  27089. ],
  27090. [
  27091. 5,
  27092. 11
  27093. ],
  27094. [
  27095. 5,
  27096. 11
  27097. ],
  27098. [
  27099. 5,
  27100. 11
  27101. ],
  27102. [
  27103. 5,
  27104. 11
  27105. ],
  27106. [
  27107. 5,
  27108. 11
  27109. ],
  27110. [
  27111. 7,
  27112. 27
  27113. ],
  27114. [
  27115. 7,
  27116. 27
  27117. ],
  27118. [
  27119. 7,
  27120. 27
  27121. ],
  27122. [
  27123. 7,
  27124. 27
  27125. ],
  27126. // 0100100xx
  27127. [
  27128. 8,
  27129. 59
  27130. ],
  27131. [
  27132. 8,
  27133. 59
  27134. ],
  27135. // 01001010x
  27136. [
  27137. 8,
  27138. 60
  27139. ],
  27140. [
  27141. 8,
  27142. 60
  27143. ],
  27144. // 01001011x
  27145. [
  27146. 9,
  27147. 1472
  27148. ],
  27149. // 010011000
  27150. [
  27151. 9,
  27152. 1536
  27153. ],
  27154. // 010011001
  27155. [
  27156. 9,
  27157. 1600
  27158. ],
  27159. // 010011010
  27160. [
  27161. 9,
  27162. 1728
  27163. ],
  27164. // 010011011
  27165. [
  27166. 7,
  27167. 18
  27168. ],
  27169. [
  27170. 7,
  27171. 18
  27172. ],
  27173. [
  27174. 7,
  27175. 18
  27176. ],
  27177. [
  27178. 7,
  27179. 18
  27180. ],
  27181. // 0100111xx
  27182. [
  27183. 7,
  27184. 24
  27185. ],
  27186. [
  27187. 7,
  27188. 24
  27189. ],
  27190. [
  27191. 7,
  27192. 24
  27193. ],
  27194. [
  27195. 7,
  27196. 24
  27197. ],
  27198. // 0101000xx
  27199. [
  27200. 8,
  27201. 49
  27202. ],
  27203. [
  27204. 8,
  27205. 49
  27206. ],
  27207. // 01010010x
  27208. [
  27209. 8,
  27210. 50
  27211. ],
  27212. [
  27213. 8,
  27214. 50
  27215. ],
  27216. // 01010011x
  27217. [
  27218. 8,
  27219. 51
  27220. ],
  27221. [
  27222. 8,
  27223. 51
  27224. ],
  27225. // 01010100x
  27226. [
  27227. 8,
  27228. 52
  27229. ],
  27230. [
  27231. 8,
  27232. 52
  27233. ],
  27234. // 01010101x
  27235. [
  27236. 7,
  27237. 25
  27238. ],
  27239. [
  27240. 7,
  27241. 25
  27242. ],
  27243. [
  27244. 7,
  27245. 25
  27246. ],
  27247. [
  27248. 7,
  27249. 25
  27250. ],
  27251. // 0101011xx
  27252. [
  27253. 8,
  27254. 55
  27255. ],
  27256. [
  27257. 8,
  27258. 55
  27259. ],
  27260. // 01011000x
  27261. [
  27262. 8,
  27263. 56
  27264. ],
  27265. [
  27266. 8,
  27267. 56
  27268. ],
  27269. // 01011001x
  27270. [
  27271. 8,
  27272. 57
  27273. ],
  27274. [
  27275. 8,
  27276. 57
  27277. ],
  27278. // 01011010x
  27279. [
  27280. 8,
  27281. 58
  27282. ],
  27283. [
  27284. 8,
  27285. 58
  27286. ],
  27287. // 01011011x
  27288. [
  27289. 6,
  27290. 192
  27291. ],
  27292. [
  27293. 6,
  27294. 192
  27295. ],
  27296. [
  27297. 6,
  27298. 192
  27299. ],
  27300. [
  27301. 6,
  27302. 192
  27303. ],
  27304. // 010111xxx
  27305. [
  27306. 6,
  27307. 192
  27308. ],
  27309. [
  27310. 6,
  27311. 192
  27312. ],
  27313. [
  27314. 6,
  27315. 192
  27316. ],
  27317. [
  27318. 6,
  27319. 192
  27320. ],
  27321. [
  27322. 6,
  27323. 1664
  27324. ],
  27325. [
  27326. 6,
  27327. 1664
  27328. ],
  27329. [
  27330. 6,
  27331. 1664
  27332. ],
  27333. [
  27334. 6,
  27335. 1664
  27336. ],
  27337. // 011000xxx
  27338. [
  27339. 6,
  27340. 1664
  27341. ],
  27342. [
  27343. 6,
  27344. 1664
  27345. ],
  27346. [
  27347. 6,
  27348. 1664
  27349. ],
  27350. [
  27351. 6,
  27352. 1664
  27353. ],
  27354. [
  27355. 8,
  27356. 448
  27357. ],
  27358. [
  27359. 8,
  27360. 448
  27361. ],
  27362. // 01100100x
  27363. [
  27364. 8,
  27365. 512
  27366. ],
  27367. [
  27368. 8,
  27369. 512
  27370. ],
  27371. // 01100101x
  27372. [
  27373. 9,
  27374. 704
  27375. ],
  27376. // 011001100
  27377. [
  27378. 9,
  27379. 768
  27380. ],
  27381. // 011001101
  27382. [
  27383. 8,
  27384. 640
  27385. ],
  27386. [
  27387. 8,
  27388. 640
  27389. ],
  27390. // 01100111x
  27391. [
  27392. 8,
  27393. 576
  27394. ],
  27395. [
  27396. 8,
  27397. 576
  27398. ],
  27399. // 01101000x
  27400. [
  27401. 9,
  27402. 832
  27403. ],
  27404. // 011010010
  27405. [
  27406. 9,
  27407. 896
  27408. ],
  27409. // 011010011
  27410. [
  27411. 9,
  27412. 960
  27413. ],
  27414. // 011010100
  27415. [
  27416. 9,
  27417. 1024
  27418. ],
  27419. // 011010101
  27420. [
  27421. 9,
  27422. 1088
  27423. ],
  27424. // 011010110
  27425. [
  27426. 9,
  27427. 1152
  27428. ],
  27429. // 011010111
  27430. [
  27431. 9,
  27432. 1216
  27433. ],
  27434. // 011011000
  27435. [
  27436. 9,
  27437. 1280
  27438. ],
  27439. // 011011001
  27440. [
  27441. 9,
  27442. 1344
  27443. ],
  27444. // 011011010
  27445. [
  27446. 9,
  27447. 1408
  27448. ],
  27449. // 011011011
  27450. [
  27451. 7,
  27452. 256
  27453. ],
  27454. [
  27455. 7,
  27456. 256
  27457. ],
  27458. [
  27459. 7,
  27460. 256
  27461. ],
  27462. [
  27463. 7,
  27464. 256
  27465. ],
  27466. // 0110111xx
  27467. [
  27468. 4,
  27469. 2
  27470. ],
  27471. [
  27472. 4,
  27473. 2
  27474. ],
  27475. [
  27476. 4,
  27477. 2
  27478. ],
  27479. [
  27480. 4,
  27481. 2
  27482. ],
  27483. // 0111xxxxx
  27484. [
  27485. 4,
  27486. 2
  27487. ],
  27488. [
  27489. 4,
  27490. 2
  27491. ],
  27492. [
  27493. 4,
  27494. 2
  27495. ],
  27496. [
  27497. 4,
  27498. 2
  27499. ],
  27500. [
  27501. 4,
  27502. 2
  27503. ],
  27504. [
  27505. 4,
  27506. 2
  27507. ],
  27508. [
  27509. 4,
  27510. 2
  27511. ],
  27512. [
  27513. 4,
  27514. 2
  27515. ],
  27516. [
  27517. 4,
  27518. 2
  27519. ],
  27520. [
  27521. 4,
  27522. 2
  27523. ],
  27524. [
  27525. 4,
  27526. 2
  27527. ],
  27528. [
  27529. 4,
  27530. 2
  27531. ],
  27532. [
  27533. 4,
  27534. 2
  27535. ],
  27536. [
  27537. 4,
  27538. 2
  27539. ],
  27540. [
  27541. 4,
  27542. 2
  27543. ],
  27544. [
  27545. 4,
  27546. 2
  27547. ],
  27548. [
  27549. 4,
  27550. 2
  27551. ],
  27552. [
  27553. 4,
  27554. 2
  27555. ],
  27556. [
  27557. 4,
  27558. 2
  27559. ],
  27560. [
  27561. 4,
  27562. 2
  27563. ],
  27564. [
  27565. 4,
  27566. 2
  27567. ],
  27568. [
  27569. 4,
  27570. 2
  27571. ],
  27572. [
  27573. 4,
  27574. 2
  27575. ],
  27576. [
  27577. 4,
  27578. 2
  27579. ],
  27580. [
  27581. 4,
  27582. 2
  27583. ],
  27584. [
  27585. 4,
  27586. 2
  27587. ],
  27588. [
  27589. 4,
  27590. 2
  27591. ],
  27592. [
  27593. 4,
  27594. 2
  27595. ],
  27596. [
  27597. 4,
  27598. 3
  27599. ],
  27600. [
  27601. 4,
  27602. 3
  27603. ],
  27604. [
  27605. 4,
  27606. 3
  27607. ],
  27608. [
  27609. 4,
  27610. 3
  27611. ],
  27612. // 1000xxxxx
  27613. [
  27614. 4,
  27615. 3
  27616. ],
  27617. [
  27618. 4,
  27619. 3
  27620. ],
  27621. [
  27622. 4,
  27623. 3
  27624. ],
  27625. [
  27626. 4,
  27627. 3
  27628. ],
  27629. [
  27630. 4,
  27631. 3
  27632. ],
  27633. [
  27634. 4,
  27635. 3
  27636. ],
  27637. [
  27638. 4,
  27639. 3
  27640. ],
  27641. [
  27642. 4,
  27643. 3
  27644. ],
  27645. [
  27646. 4,
  27647. 3
  27648. ],
  27649. [
  27650. 4,
  27651. 3
  27652. ],
  27653. [
  27654. 4,
  27655. 3
  27656. ],
  27657. [
  27658. 4,
  27659. 3
  27660. ],
  27661. [
  27662. 4,
  27663. 3
  27664. ],
  27665. [
  27666. 4,
  27667. 3
  27668. ],
  27669. [
  27670. 4,
  27671. 3
  27672. ],
  27673. [
  27674. 4,
  27675. 3
  27676. ],
  27677. [
  27678. 4,
  27679. 3
  27680. ],
  27681. [
  27682. 4,
  27683. 3
  27684. ],
  27685. [
  27686. 4,
  27687. 3
  27688. ],
  27689. [
  27690. 4,
  27691. 3
  27692. ],
  27693. [
  27694. 4,
  27695. 3
  27696. ],
  27697. [
  27698. 4,
  27699. 3
  27700. ],
  27701. [
  27702. 4,
  27703. 3
  27704. ],
  27705. [
  27706. 4,
  27707. 3
  27708. ],
  27709. [
  27710. 4,
  27711. 3
  27712. ],
  27713. [
  27714. 4,
  27715. 3
  27716. ],
  27717. [
  27718. 4,
  27719. 3
  27720. ],
  27721. [
  27722. 4,
  27723. 3
  27724. ],
  27725. [
  27726. 5,
  27727. 128
  27728. ],
  27729. [
  27730. 5,
  27731. 128
  27732. ],
  27733. [
  27734. 5,
  27735. 128
  27736. ],
  27737. [
  27738. 5,
  27739. 128
  27740. ],
  27741. // 10010xxxx
  27742. [
  27743. 5,
  27744. 128
  27745. ],
  27746. [
  27747. 5,
  27748. 128
  27749. ],
  27750. [
  27751. 5,
  27752. 128
  27753. ],
  27754. [
  27755. 5,
  27756. 128
  27757. ],
  27758. [
  27759. 5,
  27760. 128
  27761. ],
  27762. [
  27763. 5,
  27764. 128
  27765. ],
  27766. [
  27767. 5,
  27768. 128
  27769. ],
  27770. [
  27771. 5,
  27772. 128
  27773. ],
  27774. [
  27775. 5,
  27776. 128
  27777. ],
  27778. [
  27779. 5,
  27780. 128
  27781. ],
  27782. [
  27783. 5,
  27784. 128
  27785. ],
  27786. [
  27787. 5,
  27788. 128
  27789. ],
  27790. [
  27791. 5,
  27792. 8
  27793. ],
  27794. [
  27795. 5,
  27796. 8
  27797. ],
  27798. [
  27799. 5,
  27800. 8
  27801. ],
  27802. [
  27803. 5,
  27804. 8
  27805. ],
  27806. // 10011xxxx
  27807. [
  27808. 5,
  27809. 8
  27810. ],
  27811. [
  27812. 5,
  27813. 8
  27814. ],
  27815. [
  27816. 5,
  27817. 8
  27818. ],
  27819. [
  27820. 5,
  27821. 8
  27822. ],
  27823. [
  27824. 5,
  27825. 8
  27826. ],
  27827. [
  27828. 5,
  27829. 8
  27830. ],
  27831. [
  27832. 5,
  27833. 8
  27834. ],
  27835. [
  27836. 5,
  27837. 8
  27838. ],
  27839. [
  27840. 5,
  27841. 8
  27842. ],
  27843. [
  27844. 5,
  27845. 8
  27846. ],
  27847. [
  27848. 5,
  27849. 8
  27850. ],
  27851. [
  27852. 5,
  27853. 8
  27854. ],
  27855. [
  27856. 5,
  27857. 9
  27858. ],
  27859. [
  27860. 5,
  27861. 9
  27862. ],
  27863. [
  27864. 5,
  27865. 9
  27866. ],
  27867. [
  27868. 5,
  27869. 9
  27870. ],
  27871. // 10100xxxx
  27872. [
  27873. 5,
  27874. 9
  27875. ],
  27876. [
  27877. 5,
  27878. 9
  27879. ],
  27880. [
  27881. 5,
  27882. 9
  27883. ],
  27884. [
  27885. 5,
  27886. 9
  27887. ],
  27888. [
  27889. 5,
  27890. 9
  27891. ],
  27892. [
  27893. 5,
  27894. 9
  27895. ],
  27896. [
  27897. 5,
  27898. 9
  27899. ],
  27900. [
  27901. 5,
  27902. 9
  27903. ],
  27904. [
  27905. 5,
  27906. 9
  27907. ],
  27908. [
  27909. 5,
  27910. 9
  27911. ],
  27912. [
  27913. 5,
  27914. 9
  27915. ],
  27916. [
  27917. 5,
  27918. 9
  27919. ],
  27920. [
  27921. 6,
  27922. 16
  27923. ],
  27924. [
  27925. 6,
  27926. 16
  27927. ],
  27928. [
  27929. 6,
  27930. 16
  27931. ],
  27932. [
  27933. 6,
  27934. 16
  27935. ],
  27936. // 101010xxx
  27937. [
  27938. 6,
  27939. 16
  27940. ],
  27941. [
  27942. 6,
  27943. 16
  27944. ],
  27945. [
  27946. 6,
  27947. 16
  27948. ],
  27949. [
  27950. 6,
  27951. 16
  27952. ],
  27953. [
  27954. 6,
  27955. 17
  27956. ],
  27957. [
  27958. 6,
  27959. 17
  27960. ],
  27961. [
  27962. 6,
  27963. 17
  27964. ],
  27965. [
  27966. 6,
  27967. 17
  27968. ],
  27969. // 101011xxx
  27970. [
  27971. 6,
  27972. 17
  27973. ],
  27974. [
  27975. 6,
  27976. 17
  27977. ],
  27978. [
  27979. 6,
  27980. 17
  27981. ],
  27982. [
  27983. 6,
  27984. 17
  27985. ],
  27986. [
  27987. 4,
  27988. 4
  27989. ],
  27990. [
  27991. 4,
  27992. 4
  27993. ],
  27994. [
  27995. 4,
  27996. 4
  27997. ],
  27998. [
  27999. 4,
  28000. 4
  28001. ],
  28002. // 1011xxxxx
  28003. [
  28004. 4,
  28005. 4
  28006. ],
  28007. [
  28008. 4,
  28009. 4
  28010. ],
  28011. [
  28012. 4,
  28013. 4
  28014. ],
  28015. [
  28016. 4,
  28017. 4
  28018. ],
  28019. [
  28020. 4,
  28021. 4
  28022. ],
  28023. [
  28024. 4,
  28025. 4
  28026. ],
  28027. [
  28028. 4,
  28029. 4
  28030. ],
  28031. [
  28032. 4,
  28033. 4
  28034. ],
  28035. [
  28036. 4,
  28037. 4
  28038. ],
  28039. [
  28040. 4,
  28041. 4
  28042. ],
  28043. [
  28044. 4,
  28045. 4
  28046. ],
  28047. [
  28048. 4,
  28049. 4
  28050. ],
  28051. [
  28052. 4,
  28053. 4
  28054. ],
  28055. [
  28056. 4,
  28057. 4
  28058. ],
  28059. [
  28060. 4,
  28061. 4
  28062. ],
  28063. [
  28064. 4,
  28065. 4
  28066. ],
  28067. [
  28068. 4,
  28069. 4
  28070. ],
  28071. [
  28072. 4,
  28073. 4
  28074. ],
  28075. [
  28076. 4,
  28077. 4
  28078. ],
  28079. [
  28080. 4,
  28081. 4
  28082. ],
  28083. [
  28084. 4,
  28085. 4
  28086. ],
  28087. [
  28088. 4,
  28089. 4
  28090. ],
  28091. [
  28092. 4,
  28093. 4
  28094. ],
  28095. [
  28096. 4,
  28097. 4
  28098. ],
  28099. [
  28100. 4,
  28101. 4
  28102. ],
  28103. [
  28104. 4,
  28105. 4
  28106. ],
  28107. [
  28108. 4,
  28109. 4
  28110. ],
  28111. [
  28112. 4,
  28113. 4
  28114. ],
  28115. [
  28116. 4,
  28117. 5
  28118. ],
  28119. [
  28120. 4,
  28121. 5
  28122. ],
  28123. [
  28124. 4,
  28125. 5
  28126. ],
  28127. [
  28128. 4,
  28129. 5
  28130. ],
  28131. // 1100xxxxx
  28132. [
  28133. 4,
  28134. 5
  28135. ],
  28136. [
  28137. 4,
  28138. 5
  28139. ],
  28140. [
  28141. 4,
  28142. 5
  28143. ],
  28144. [
  28145. 4,
  28146. 5
  28147. ],
  28148. [
  28149. 4,
  28150. 5
  28151. ],
  28152. [
  28153. 4,
  28154. 5
  28155. ],
  28156. [
  28157. 4,
  28158. 5
  28159. ],
  28160. [
  28161. 4,
  28162. 5
  28163. ],
  28164. [
  28165. 4,
  28166. 5
  28167. ],
  28168. [
  28169. 4,
  28170. 5
  28171. ],
  28172. [
  28173. 4,
  28174. 5
  28175. ],
  28176. [
  28177. 4,
  28178. 5
  28179. ],
  28180. [
  28181. 4,
  28182. 5
  28183. ],
  28184. [
  28185. 4,
  28186. 5
  28187. ],
  28188. [
  28189. 4,
  28190. 5
  28191. ],
  28192. [
  28193. 4,
  28194. 5
  28195. ],
  28196. [
  28197. 4,
  28198. 5
  28199. ],
  28200. [
  28201. 4,
  28202. 5
  28203. ],
  28204. [
  28205. 4,
  28206. 5
  28207. ],
  28208. [
  28209. 4,
  28210. 5
  28211. ],
  28212. [
  28213. 4,
  28214. 5
  28215. ],
  28216. [
  28217. 4,
  28218. 5
  28219. ],
  28220. [
  28221. 4,
  28222. 5
  28223. ],
  28224. [
  28225. 4,
  28226. 5
  28227. ],
  28228. [
  28229. 4,
  28230. 5
  28231. ],
  28232. [
  28233. 4,
  28234. 5
  28235. ],
  28236. [
  28237. 4,
  28238. 5
  28239. ],
  28240. [
  28241. 4,
  28242. 5
  28243. ],
  28244. [
  28245. 6,
  28246. 14
  28247. ],
  28248. [
  28249. 6,
  28250. 14
  28251. ],
  28252. [
  28253. 6,
  28254. 14
  28255. ],
  28256. [
  28257. 6,
  28258. 14
  28259. ],
  28260. // 110100xxx
  28261. [
  28262. 6,
  28263. 14
  28264. ],
  28265. [
  28266. 6,
  28267. 14
  28268. ],
  28269. [
  28270. 6,
  28271. 14
  28272. ],
  28273. [
  28274. 6,
  28275. 14
  28276. ],
  28277. [
  28278. 6,
  28279. 15
  28280. ],
  28281. [
  28282. 6,
  28283. 15
  28284. ],
  28285. [
  28286. 6,
  28287. 15
  28288. ],
  28289. [
  28290. 6,
  28291. 15
  28292. ],
  28293. // 110101xxx
  28294. [
  28295. 6,
  28296. 15
  28297. ],
  28298. [
  28299. 6,
  28300. 15
  28301. ],
  28302. [
  28303. 6,
  28304. 15
  28305. ],
  28306. [
  28307. 6,
  28308. 15
  28309. ],
  28310. [
  28311. 5,
  28312. 64
  28313. ],
  28314. [
  28315. 5,
  28316. 64
  28317. ],
  28318. [
  28319. 5,
  28320. 64
  28321. ],
  28322. [
  28323. 5,
  28324. 64
  28325. ],
  28326. // 11011xxxx
  28327. [
  28328. 5,
  28329. 64
  28330. ],
  28331. [
  28332. 5,
  28333. 64
  28334. ],
  28335. [
  28336. 5,
  28337. 64
  28338. ],
  28339. [
  28340. 5,
  28341. 64
  28342. ],
  28343. [
  28344. 5,
  28345. 64
  28346. ],
  28347. [
  28348. 5,
  28349. 64
  28350. ],
  28351. [
  28352. 5,
  28353. 64
  28354. ],
  28355. [
  28356. 5,
  28357. 64
  28358. ],
  28359. [
  28360. 5,
  28361. 64
  28362. ],
  28363. [
  28364. 5,
  28365. 64
  28366. ],
  28367. [
  28368. 5,
  28369. 64
  28370. ],
  28371. [
  28372. 5,
  28373. 64
  28374. ],
  28375. [
  28376. 4,
  28377. 6
  28378. ],
  28379. [
  28380. 4,
  28381. 6
  28382. ],
  28383. [
  28384. 4,
  28385. 6
  28386. ],
  28387. [
  28388. 4,
  28389. 6
  28390. ],
  28391. // 1110xxxxx
  28392. [
  28393. 4,
  28394. 6
  28395. ],
  28396. [
  28397. 4,
  28398. 6
  28399. ],
  28400. [
  28401. 4,
  28402. 6
  28403. ],
  28404. [
  28405. 4,
  28406. 6
  28407. ],
  28408. [
  28409. 4,
  28410. 6
  28411. ],
  28412. [
  28413. 4,
  28414. 6
  28415. ],
  28416. [
  28417. 4,
  28418. 6
  28419. ],
  28420. [
  28421. 4,
  28422. 6
  28423. ],
  28424. [
  28425. 4,
  28426. 6
  28427. ],
  28428. [
  28429. 4,
  28430. 6
  28431. ],
  28432. [
  28433. 4,
  28434. 6
  28435. ],
  28436. [
  28437. 4,
  28438. 6
  28439. ],
  28440. [
  28441. 4,
  28442. 6
  28443. ],
  28444. [
  28445. 4,
  28446. 6
  28447. ],
  28448. [
  28449. 4,
  28450. 6
  28451. ],
  28452. [
  28453. 4,
  28454. 6
  28455. ],
  28456. [
  28457. 4,
  28458. 6
  28459. ],
  28460. [
  28461. 4,
  28462. 6
  28463. ],
  28464. [
  28465. 4,
  28466. 6
  28467. ],
  28468. [
  28469. 4,
  28470. 6
  28471. ],
  28472. [
  28473. 4,
  28474. 6
  28475. ],
  28476. [
  28477. 4,
  28478. 6
  28479. ],
  28480. [
  28481. 4,
  28482. 6
  28483. ],
  28484. [
  28485. 4,
  28486. 6
  28487. ],
  28488. [
  28489. 4,
  28490. 6
  28491. ],
  28492. [
  28493. 4,
  28494. 6
  28495. ],
  28496. [
  28497. 4,
  28498. 6
  28499. ],
  28500. [
  28501. 4,
  28502. 6
  28503. ],
  28504. [
  28505. 4,
  28506. 7
  28507. ],
  28508. [
  28509. 4,
  28510. 7
  28511. ],
  28512. [
  28513. 4,
  28514. 7
  28515. ],
  28516. [
  28517. 4,
  28518. 7
  28519. ],
  28520. // 1111xxxxx
  28521. [
  28522. 4,
  28523. 7
  28524. ],
  28525. [
  28526. 4,
  28527. 7
  28528. ],
  28529. [
  28530. 4,
  28531. 7
  28532. ],
  28533. [
  28534. 4,
  28535. 7
  28536. ],
  28537. [
  28538. 4,
  28539. 7
  28540. ],
  28541. [
  28542. 4,
  28543. 7
  28544. ],
  28545. [
  28546. 4,
  28547. 7
  28548. ],
  28549. [
  28550. 4,
  28551. 7
  28552. ],
  28553. [
  28554. 4,
  28555. 7
  28556. ],
  28557. [
  28558. 4,
  28559. 7
  28560. ],
  28561. [
  28562. 4,
  28563. 7
  28564. ],
  28565. [
  28566. 4,
  28567. 7
  28568. ],
  28569. [
  28570. 4,
  28571. 7
  28572. ],
  28573. [
  28574. 4,
  28575. 7
  28576. ],
  28577. [
  28578. 4,
  28579. 7
  28580. ],
  28581. [
  28582. 4,
  28583. 7
  28584. ],
  28585. [
  28586. 4,
  28587. 7
  28588. ],
  28589. [
  28590. 4,
  28591. 7
  28592. ],
  28593. [
  28594. 4,
  28595. 7
  28596. ],
  28597. [
  28598. 4,
  28599. 7
  28600. ],
  28601. [
  28602. 4,
  28603. 7
  28604. ],
  28605. [
  28606. 4,
  28607. 7
  28608. ],
  28609. [
  28610. 4,
  28611. 7
  28612. ],
  28613. [
  28614. 4,
  28615. 7
  28616. ],
  28617. [
  28618. 4,
  28619. 7
  28620. ],
  28621. [
  28622. 4,
  28623. 7
  28624. ],
  28625. [
  28626. 4,
  28627. 7
  28628. ],
  28629. [
  28630. 4,
  28631. 7
  28632. ]
  28633. ];
  28634. var blackTable1 = [
  28635. [
  28636. -1,
  28637. -1
  28638. ],
  28639. [
  28640. -1,
  28641. -1
  28642. ],
  28643. // 000000000000x
  28644. [
  28645. 12,
  28646. ccittEOL
  28647. ],
  28648. [
  28649. 12,
  28650. ccittEOL
  28651. ],
  28652. // 000000000001x
  28653. [
  28654. -1,
  28655. -1
  28656. ],
  28657. [
  28658. -1,
  28659. -1
  28660. ],
  28661. [
  28662. -1,
  28663. -1
  28664. ],
  28665. [
  28666. -1,
  28667. -1
  28668. ],
  28669. // 00000000001xx
  28670. [
  28671. -1,
  28672. -1
  28673. ],
  28674. [
  28675. -1,
  28676. -1
  28677. ],
  28678. [
  28679. -1,
  28680. -1
  28681. ],
  28682. [
  28683. -1,
  28684. -1
  28685. ],
  28686. // 00000000010xx
  28687. [
  28688. -1,
  28689. -1
  28690. ],
  28691. [
  28692. -1,
  28693. -1
  28694. ],
  28695. [
  28696. -1,
  28697. -1
  28698. ],
  28699. [
  28700. -1,
  28701. -1
  28702. ],
  28703. // 00000000011xx
  28704. [
  28705. -1,
  28706. -1
  28707. ],
  28708. [
  28709. -1,
  28710. -1
  28711. ],
  28712. [
  28713. -1,
  28714. -1
  28715. ],
  28716. [
  28717. -1,
  28718. -1
  28719. ],
  28720. // 00000000100xx
  28721. [
  28722. -1,
  28723. -1
  28724. ],
  28725. [
  28726. -1,
  28727. -1
  28728. ],
  28729. [
  28730. -1,
  28731. -1
  28732. ],
  28733. [
  28734. -1,
  28735. -1
  28736. ],
  28737. // 00000000101xx
  28738. [
  28739. -1,
  28740. -1
  28741. ],
  28742. [
  28743. -1,
  28744. -1
  28745. ],
  28746. [
  28747. -1,
  28748. -1
  28749. ],
  28750. [
  28751. -1,
  28752. -1
  28753. ],
  28754. // 00000000110xx
  28755. [
  28756. -1,
  28757. -1
  28758. ],
  28759. [
  28760. -1,
  28761. -1
  28762. ],
  28763. [
  28764. -1,
  28765. -1
  28766. ],
  28767. [
  28768. -1,
  28769. -1
  28770. ],
  28771. // 00000000111xx
  28772. [
  28773. 11,
  28774. 1792
  28775. ],
  28776. [
  28777. 11,
  28778. 1792
  28779. ],
  28780. [
  28781. 11,
  28782. 1792
  28783. ],
  28784. [
  28785. 11,
  28786. 1792
  28787. ],
  28788. // 00000001000xx
  28789. [
  28790. 12,
  28791. 1984
  28792. ],
  28793. [
  28794. 12,
  28795. 1984
  28796. ],
  28797. // 000000010010x
  28798. [
  28799. 12,
  28800. 2048
  28801. ],
  28802. [
  28803. 12,
  28804. 2048
  28805. ],
  28806. // 000000010011x
  28807. [
  28808. 12,
  28809. 2112
  28810. ],
  28811. [
  28812. 12,
  28813. 2112
  28814. ],
  28815. // 000000010100x
  28816. [
  28817. 12,
  28818. 2176
  28819. ],
  28820. [
  28821. 12,
  28822. 2176
  28823. ],
  28824. // 000000010101x
  28825. [
  28826. 12,
  28827. 2240
  28828. ],
  28829. [
  28830. 12,
  28831. 2240
  28832. ],
  28833. // 000000010110x
  28834. [
  28835. 12,
  28836. 2304
  28837. ],
  28838. [
  28839. 12,
  28840. 2304
  28841. ],
  28842. // 000000010111x
  28843. [
  28844. 11,
  28845. 1856
  28846. ],
  28847. [
  28848. 11,
  28849. 1856
  28850. ],
  28851. [
  28852. 11,
  28853. 1856
  28854. ],
  28855. [
  28856. 11,
  28857. 1856
  28858. ],
  28859. // 00000001100xx
  28860. [
  28861. 11,
  28862. 1920
  28863. ],
  28864. [
  28865. 11,
  28866. 1920
  28867. ],
  28868. [
  28869. 11,
  28870. 1920
  28871. ],
  28872. [
  28873. 11,
  28874. 1920
  28875. ],
  28876. // 00000001101xx
  28877. [
  28878. 12,
  28879. 2368
  28880. ],
  28881. [
  28882. 12,
  28883. 2368
  28884. ],
  28885. // 000000011100x
  28886. [
  28887. 12,
  28888. 2432
  28889. ],
  28890. [
  28891. 12,
  28892. 2432
  28893. ],
  28894. // 000000011101x
  28895. [
  28896. 12,
  28897. 2496
  28898. ],
  28899. [
  28900. 12,
  28901. 2496
  28902. ],
  28903. // 000000011110x
  28904. [
  28905. 12,
  28906. 2560
  28907. ],
  28908. [
  28909. 12,
  28910. 2560
  28911. ],
  28912. // 000000011111x
  28913. [
  28914. 10,
  28915. 18
  28916. ],
  28917. [
  28918. 10,
  28919. 18
  28920. ],
  28921. [
  28922. 10,
  28923. 18
  28924. ],
  28925. [
  28926. 10,
  28927. 18
  28928. ],
  28929. // 0000001000xxx
  28930. [
  28931. 10,
  28932. 18
  28933. ],
  28934. [
  28935. 10,
  28936. 18
  28937. ],
  28938. [
  28939. 10,
  28940. 18
  28941. ],
  28942. [
  28943. 10,
  28944. 18
  28945. ],
  28946. [
  28947. 12,
  28948. 52
  28949. ],
  28950. [
  28951. 12,
  28952. 52
  28953. ],
  28954. // 000000100100x
  28955. [
  28956. 13,
  28957. 640
  28958. ],
  28959. // 0000001001010
  28960. [
  28961. 13,
  28962. 704
  28963. ],
  28964. // 0000001001011
  28965. [
  28966. 13,
  28967. 768
  28968. ],
  28969. // 0000001001100
  28970. [
  28971. 13,
  28972. 832
  28973. ],
  28974. // 0000001001101
  28975. [
  28976. 12,
  28977. 55
  28978. ],
  28979. [
  28980. 12,
  28981. 55
  28982. ],
  28983. // 000000100111x
  28984. [
  28985. 12,
  28986. 56
  28987. ],
  28988. [
  28989. 12,
  28990. 56
  28991. ],
  28992. // 000000101000x
  28993. [
  28994. 13,
  28995. 1280
  28996. ],
  28997. // 0000001010010
  28998. [
  28999. 13,
  29000. 1344
  29001. ],
  29002. // 0000001010011
  29003. [
  29004. 13,
  29005. 1408
  29006. ],
  29007. // 0000001010100
  29008. [
  29009. 13,
  29010. 1472
  29011. ],
  29012. // 0000001010101
  29013. [
  29014. 12,
  29015. 59
  29016. ],
  29017. [
  29018. 12,
  29019. 59
  29020. ],
  29021. // 000000101011x
  29022. [
  29023. 12,
  29024. 60
  29025. ],
  29026. [
  29027. 12,
  29028. 60
  29029. ],
  29030. // 000000101100x
  29031. [
  29032. 13,
  29033. 1536
  29034. ],
  29035. // 0000001011010
  29036. [
  29037. 13,
  29038. 1600
  29039. ],
  29040. // 0000001011011
  29041. [
  29042. 11,
  29043. 24
  29044. ],
  29045. [
  29046. 11,
  29047. 24
  29048. ],
  29049. [
  29050. 11,
  29051. 24
  29052. ],
  29053. [
  29054. 11,
  29055. 24
  29056. ],
  29057. // 00000010111xx
  29058. [
  29059. 11,
  29060. 25
  29061. ],
  29062. [
  29063. 11,
  29064. 25
  29065. ],
  29066. [
  29067. 11,
  29068. 25
  29069. ],
  29070. [
  29071. 11,
  29072. 25
  29073. ],
  29074. // 00000011000xx
  29075. [
  29076. 13,
  29077. 1664
  29078. ],
  29079. // 0000001100100
  29080. [
  29081. 13,
  29082. 1728
  29083. ],
  29084. // 0000001100101
  29085. [
  29086. 12,
  29087. 320
  29088. ],
  29089. [
  29090. 12,
  29091. 320
  29092. ],
  29093. // 000000110011x
  29094. [
  29095. 12,
  29096. 384
  29097. ],
  29098. [
  29099. 12,
  29100. 384
  29101. ],
  29102. // 000000110100x
  29103. [
  29104. 12,
  29105. 448
  29106. ],
  29107. [
  29108. 12,
  29109. 448
  29110. ],
  29111. // 000000110101x
  29112. [
  29113. 13,
  29114. 512
  29115. ],
  29116. // 0000001101100
  29117. [
  29118. 13,
  29119. 576
  29120. ],
  29121. // 0000001101101
  29122. [
  29123. 12,
  29124. 53
  29125. ],
  29126. [
  29127. 12,
  29128. 53
  29129. ],
  29130. // 000000110111x
  29131. [
  29132. 12,
  29133. 54
  29134. ],
  29135. [
  29136. 12,
  29137. 54
  29138. ],
  29139. // 000000111000x
  29140. [
  29141. 13,
  29142. 896
  29143. ],
  29144. // 0000001110010
  29145. [
  29146. 13,
  29147. 960
  29148. ],
  29149. // 0000001110011
  29150. [
  29151. 13,
  29152. 1024
  29153. ],
  29154. // 0000001110100
  29155. [
  29156. 13,
  29157. 1088
  29158. ],
  29159. // 0000001110101
  29160. [
  29161. 13,
  29162. 1152
  29163. ],
  29164. // 0000001110110
  29165. [
  29166. 13,
  29167. 1216
  29168. ],
  29169. // 0000001110111
  29170. [
  29171. 10,
  29172. 64
  29173. ],
  29174. [
  29175. 10,
  29176. 64
  29177. ],
  29178. [
  29179. 10,
  29180. 64
  29181. ],
  29182. [
  29183. 10,
  29184. 64
  29185. ],
  29186. // 0000001111xxx
  29187. [
  29188. 10,
  29189. 64
  29190. ],
  29191. [
  29192. 10,
  29193. 64
  29194. ],
  29195. [
  29196. 10,
  29197. 64
  29198. ],
  29199. [
  29200. 10,
  29201. 64
  29202. ]
  29203. ];
  29204. var blackTable2 = [
  29205. [
  29206. 8,
  29207. 13
  29208. ],
  29209. [
  29210. 8,
  29211. 13
  29212. ],
  29213. [
  29214. 8,
  29215. 13
  29216. ],
  29217. [
  29218. 8,
  29219. 13
  29220. ],
  29221. // 00000100xxxx
  29222. [
  29223. 8,
  29224. 13
  29225. ],
  29226. [
  29227. 8,
  29228. 13
  29229. ],
  29230. [
  29231. 8,
  29232. 13
  29233. ],
  29234. [
  29235. 8,
  29236. 13
  29237. ],
  29238. [
  29239. 8,
  29240. 13
  29241. ],
  29242. [
  29243. 8,
  29244. 13
  29245. ],
  29246. [
  29247. 8,
  29248. 13
  29249. ],
  29250. [
  29251. 8,
  29252. 13
  29253. ],
  29254. [
  29255. 8,
  29256. 13
  29257. ],
  29258. [
  29259. 8,
  29260. 13
  29261. ],
  29262. [
  29263. 8,
  29264. 13
  29265. ],
  29266. [
  29267. 8,
  29268. 13
  29269. ],
  29270. [
  29271. 11,
  29272. 23
  29273. ],
  29274. [
  29275. 11,
  29276. 23
  29277. ],
  29278. // 00000101000x
  29279. [
  29280. 12,
  29281. 50
  29282. ],
  29283. // 000001010010
  29284. [
  29285. 12,
  29286. 51
  29287. ],
  29288. // 000001010011
  29289. [
  29290. 12,
  29291. 44
  29292. ],
  29293. // 000001010100
  29294. [
  29295. 12,
  29296. 45
  29297. ],
  29298. // 000001010101
  29299. [
  29300. 12,
  29301. 46
  29302. ],
  29303. // 000001010110
  29304. [
  29305. 12,
  29306. 47
  29307. ],
  29308. // 000001010111
  29309. [
  29310. 12,
  29311. 57
  29312. ],
  29313. // 000001011000
  29314. [
  29315. 12,
  29316. 58
  29317. ],
  29318. // 000001011001
  29319. [
  29320. 12,
  29321. 61
  29322. ],
  29323. // 000001011010
  29324. [
  29325. 12,
  29326. 256
  29327. ],
  29328. // 000001011011
  29329. [
  29330. 10,
  29331. 16
  29332. ],
  29333. [
  29334. 10,
  29335. 16
  29336. ],
  29337. [
  29338. 10,
  29339. 16
  29340. ],
  29341. [
  29342. 10,
  29343. 16
  29344. ],
  29345. // 0000010111xx
  29346. [
  29347. 10,
  29348. 17
  29349. ],
  29350. [
  29351. 10,
  29352. 17
  29353. ],
  29354. [
  29355. 10,
  29356. 17
  29357. ],
  29358. [
  29359. 10,
  29360. 17
  29361. ],
  29362. // 0000011000xx
  29363. [
  29364. 12,
  29365. 48
  29366. ],
  29367. // 000001100100
  29368. [
  29369. 12,
  29370. 49
  29371. ],
  29372. // 000001100101
  29373. [
  29374. 12,
  29375. 62
  29376. ],
  29377. // 000001100110
  29378. [
  29379. 12,
  29380. 63
  29381. ],
  29382. // 000001100111
  29383. [
  29384. 12,
  29385. 30
  29386. ],
  29387. // 000001101000
  29388. [
  29389. 12,
  29390. 31
  29391. ],
  29392. // 000001101001
  29393. [
  29394. 12,
  29395. 32
  29396. ],
  29397. // 000001101010
  29398. [
  29399. 12,
  29400. 33
  29401. ],
  29402. // 000001101011
  29403. [
  29404. 12,
  29405. 40
  29406. ],
  29407. // 000001101100
  29408. [
  29409. 12,
  29410. 41
  29411. ],
  29412. // 000001101101
  29413. [
  29414. 11,
  29415. 22
  29416. ],
  29417. [
  29418. 11,
  29419. 22
  29420. ],
  29421. // 00000110111x
  29422. [
  29423. 8,
  29424. 14
  29425. ],
  29426. [
  29427. 8,
  29428. 14
  29429. ],
  29430. [
  29431. 8,
  29432. 14
  29433. ],
  29434. [
  29435. 8,
  29436. 14
  29437. ],
  29438. // 00000111xxxx
  29439. [
  29440. 8,
  29441. 14
  29442. ],
  29443. [
  29444. 8,
  29445. 14
  29446. ],
  29447. [
  29448. 8,
  29449. 14
  29450. ],
  29451. [
  29452. 8,
  29453. 14
  29454. ],
  29455. [
  29456. 8,
  29457. 14
  29458. ],
  29459. [
  29460. 8,
  29461. 14
  29462. ],
  29463. [
  29464. 8,
  29465. 14
  29466. ],
  29467. [
  29468. 8,
  29469. 14
  29470. ],
  29471. [
  29472. 8,
  29473. 14
  29474. ],
  29475. [
  29476. 8,
  29477. 14
  29478. ],
  29479. [
  29480. 8,
  29481. 14
  29482. ],
  29483. [
  29484. 8,
  29485. 14
  29486. ],
  29487. [
  29488. 7,
  29489. 10
  29490. ],
  29491. [
  29492. 7,
  29493. 10
  29494. ],
  29495. [
  29496. 7,
  29497. 10
  29498. ],
  29499. [
  29500. 7,
  29501. 10
  29502. ],
  29503. // 0000100xxxxx
  29504. [
  29505. 7,
  29506. 10
  29507. ],
  29508. [
  29509. 7,
  29510. 10
  29511. ],
  29512. [
  29513. 7,
  29514. 10
  29515. ],
  29516. [
  29517. 7,
  29518. 10
  29519. ],
  29520. [
  29521. 7,
  29522. 10
  29523. ],
  29524. [
  29525. 7,
  29526. 10
  29527. ],
  29528. [
  29529. 7,
  29530. 10
  29531. ],
  29532. [
  29533. 7,
  29534. 10
  29535. ],
  29536. [
  29537. 7,
  29538. 10
  29539. ],
  29540. [
  29541. 7,
  29542. 10
  29543. ],
  29544. [
  29545. 7,
  29546. 10
  29547. ],
  29548. [
  29549. 7,
  29550. 10
  29551. ],
  29552. [
  29553. 7,
  29554. 10
  29555. ],
  29556. [
  29557. 7,
  29558. 10
  29559. ],
  29560. [
  29561. 7,
  29562. 10
  29563. ],
  29564. [
  29565. 7,
  29566. 10
  29567. ],
  29568. [
  29569. 7,
  29570. 10
  29571. ],
  29572. [
  29573. 7,
  29574. 10
  29575. ],
  29576. [
  29577. 7,
  29578. 10
  29579. ],
  29580. [
  29581. 7,
  29582. 10
  29583. ],
  29584. [
  29585. 7,
  29586. 10
  29587. ],
  29588. [
  29589. 7,
  29590. 10
  29591. ],
  29592. [
  29593. 7,
  29594. 10
  29595. ],
  29596. [
  29597. 7,
  29598. 10
  29599. ],
  29600. [
  29601. 7,
  29602. 10
  29603. ],
  29604. [
  29605. 7,
  29606. 10
  29607. ],
  29608. [
  29609. 7,
  29610. 10
  29611. ],
  29612. [
  29613. 7,
  29614. 10
  29615. ],
  29616. [
  29617. 7,
  29618. 11
  29619. ],
  29620. [
  29621. 7,
  29622. 11
  29623. ],
  29624. [
  29625. 7,
  29626. 11
  29627. ],
  29628. [
  29629. 7,
  29630. 11
  29631. ],
  29632. // 0000101xxxxx
  29633. [
  29634. 7,
  29635. 11
  29636. ],
  29637. [
  29638. 7,
  29639. 11
  29640. ],
  29641. [
  29642. 7,
  29643. 11
  29644. ],
  29645. [
  29646. 7,
  29647. 11
  29648. ],
  29649. [
  29650. 7,
  29651. 11
  29652. ],
  29653. [
  29654. 7,
  29655. 11
  29656. ],
  29657. [
  29658. 7,
  29659. 11
  29660. ],
  29661. [
  29662. 7,
  29663. 11
  29664. ],
  29665. [
  29666. 7,
  29667. 11
  29668. ],
  29669. [
  29670. 7,
  29671. 11
  29672. ],
  29673. [
  29674. 7,
  29675. 11
  29676. ],
  29677. [
  29678. 7,
  29679. 11
  29680. ],
  29681. [
  29682. 7,
  29683. 11
  29684. ],
  29685. [
  29686. 7,
  29687. 11
  29688. ],
  29689. [
  29690. 7,
  29691. 11
  29692. ],
  29693. [
  29694. 7,
  29695. 11
  29696. ],
  29697. [
  29698. 7,
  29699. 11
  29700. ],
  29701. [
  29702. 7,
  29703. 11
  29704. ],
  29705. [
  29706. 7,
  29707. 11
  29708. ],
  29709. [
  29710. 7,
  29711. 11
  29712. ],
  29713. [
  29714. 7,
  29715. 11
  29716. ],
  29717. [
  29718. 7,
  29719. 11
  29720. ],
  29721. [
  29722. 7,
  29723. 11
  29724. ],
  29725. [
  29726. 7,
  29727. 11
  29728. ],
  29729. [
  29730. 7,
  29731. 11
  29732. ],
  29733. [
  29734. 7,
  29735. 11
  29736. ],
  29737. [
  29738. 7,
  29739. 11
  29740. ],
  29741. [
  29742. 7,
  29743. 11
  29744. ],
  29745. [
  29746. 9,
  29747. 15
  29748. ],
  29749. [
  29750. 9,
  29751. 15
  29752. ],
  29753. [
  29754. 9,
  29755. 15
  29756. ],
  29757. [
  29758. 9,
  29759. 15
  29760. ],
  29761. // 000011000xxx
  29762. [
  29763. 9,
  29764. 15
  29765. ],
  29766. [
  29767. 9,
  29768. 15
  29769. ],
  29770. [
  29771. 9,
  29772. 15
  29773. ],
  29774. [
  29775. 9,
  29776. 15
  29777. ],
  29778. [
  29779. 12,
  29780. 128
  29781. ],
  29782. // 000011001000
  29783. [
  29784. 12,
  29785. 192
  29786. ],
  29787. // 000011001001
  29788. [
  29789. 12,
  29790. 26
  29791. ],
  29792. // 000011001010
  29793. [
  29794. 12,
  29795. 27
  29796. ],
  29797. // 000011001011
  29798. [
  29799. 12,
  29800. 28
  29801. ],
  29802. // 000011001100
  29803. [
  29804. 12,
  29805. 29
  29806. ],
  29807. // 000011001101
  29808. [
  29809. 11,
  29810. 19
  29811. ],
  29812. [
  29813. 11,
  29814. 19
  29815. ],
  29816. // 00001100111x
  29817. [
  29818. 11,
  29819. 20
  29820. ],
  29821. [
  29822. 11,
  29823. 20
  29824. ],
  29825. // 00001101000x
  29826. [
  29827. 12,
  29828. 34
  29829. ],
  29830. // 000011010010
  29831. [
  29832. 12,
  29833. 35
  29834. ],
  29835. // 000011010011
  29836. [
  29837. 12,
  29838. 36
  29839. ],
  29840. // 000011010100
  29841. [
  29842. 12,
  29843. 37
  29844. ],
  29845. // 000011010101
  29846. [
  29847. 12,
  29848. 38
  29849. ],
  29850. // 000011010110
  29851. [
  29852. 12,
  29853. 39
  29854. ],
  29855. // 000011010111
  29856. [
  29857. 11,
  29858. 21
  29859. ],
  29860. [
  29861. 11,
  29862. 21
  29863. ],
  29864. // 00001101100x
  29865. [
  29866. 12,
  29867. 42
  29868. ],
  29869. // 000011011010
  29870. [
  29871. 12,
  29872. 43
  29873. ],
  29874. // 000011011011
  29875. [
  29876. 10,
  29877. 0
  29878. ],
  29879. [
  29880. 10,
  29881. 0
  29882. ],
  29883. [
  29884. 10,
  29885. 0
  29886. ],
  29887. [
  29888. 10,
  29889. 0
  29890. ],
  29891. // 0000110111xx
  29892. [
  29893. 7,
  29894. 12
  29895. ],
  29896. [
  29897. 7,
  29898. 12
  29899. ],
  29900. [
  29901. 7,
  29902. 12
  29903. ],
  29904. [
  29905. 7,
  29906. 12
  29907. ],
  29908. // 0000111xxxxx
  29909. [
  29910. 7,
  29911. 12
  29912. ],
  29913. [
  29914. 7,
  29915. 12
  29916. ],
  29917. [
  29918. 7,
  29919. 12
  29920. ],
  29921. [
  29922. 7,
  29923. 12
  29924. ],
  29925. [
  29926. 7,
  29927. 12
  29928. ],
  29929. [
  29930. 7,
  29931. 12
  29932. ],
  29933. [
  29934. 7,
  29935. 12
  29936. ],
  29937. [
  29938. 7,
  29939. 12
  29940. ],
  29941. [
  29942. 7,
  29943. 12
  29944. ],
  29945. [
  29946. 7,
  29947. 12
  29948. ],
  29949. [
  29950. 7,
  29951. 12
  29952. ],
  29953. [
  29954. 7,
  29955. 12
  29956. ],
  29957. [
  29958. 7,
  29959. 12
  29960. ],
  29961. [
  29962. 7,
  29963. 12
  29964. ],
  29965. [
  29966. 7,
  29967. 12
  29968. ],
  29969. [
  29970. 7,
  29971. 12
  29972. ],
  29973. [
  29974. 7,
  29975. 12
  29976. ],
  29977. [
  29978. 7,
  29979. 12
  29980. ],
  29981. [
  29982. 7,
  29983. 12
  29984. ],
  29985. [
  29986. 7,
  29987. 12
  29988. ],
  29989. [
  29990. 7,
  29991. 12
  29992. ],
  29993. [
  29994. 7,
  29995. 12
  29996. ],
  29997. [
  29998. 7,
  29999. 12
  30000. ],
  30001. [
  30002. 7,
  30003. 12
  30004. ],
  30005. [
  30006. 7,
  30007. 12
  30008. ],
  30009. [
  30010. 7,
  30011. 12
  30012. ],
  30013. [
  30014. 7,
  30015. 12
  30016. ],
  30017. [
  30018. 7,
  30019. 12
  30020. ]
  30021. ];
  30022. var blackTable3 = [
  30023. [
  30024. -1,
  30025. -1
  30026. ],
  30027. [
  30028. -1,
  30029. -1
  30030. ],
  30031. [
  30032. -1,
  30033. -1
  30034. ],
  30035. [
  30036. -1,
  30037. -1
  30038. ],
  30039. // 0000xx
  30040. [
  30041. 6,
  30042. 9
  30043. ],
  30044. // 000100
  30045. [
  30046. 6,
  30047. 8
  30048. ],
  30049. // 000101
  30050. [
  30051. 5,
  30052. 7
  30053. ],
  30054. [
  30055. 5,
  30056. 7
  30057. ],
  30058. // 00011x
  30059. [
  30060. 4,
  30061. 6
  30062. ],
  30063. [
  30064. 4,
  30065. 6
  30066. ],
  30067. [
  30068. 4,
  30069. 6
  30070. ],
  30071. [
  30072. 4,
  30073. 6
  30074. ],
  30075. // 0010xx
  30076. [
  30077. 4,
  30078. 5
  30079. ],
  30080. [
  30081. 4,
  30082. 5
  30083. ],
  30084. [
  30085. 4,
  30086. 5
  30087. ],
  30088. [
  30089. 4,
  30090. 5
  30091. ],
  30092. // 0011xx
  30093. [
  30094. 3,
  30095. 1
  30096. ],
  30097. [
  30098. 3,
  30099. 1
  30100. ],
  30101. [
  30102. 3,
  30103. 1
  30104. ],
  30105. [
  30106. 3,
  30107. 1
  30108. ],
  30109. // 010xxx
  30110. [
  30111. 3,
  30112. 1
  30113. ],
  30114. [
  30115. 3,
  30116. 1
  30117. ],
  30118. [
  30119. 3,
  30120. 1
  30121. ],
  30122. [
  30123. 3,
  30124. 1
  30125. ],
  30126. [
  30127. 3,
  30128. 4
  30129. ],
  30130. [
  30131. 3,
  30132. 4
  30133. ],
  30134. [
  30135. 3,
  30136. 4
  30137. ],
  30138. [
  30139. 3,
  30140. 4
  30141. ],
  30142. // 011xxx
  30143. [
  30144. 3,
  30145. 4
  30146. ],
  30147. [
  30148. 3,
  30149. 4
  30150. ],
  30151. [
  30152. 3,
  30153. 4
  30154. ],
  30155. [
  30156. 3,
  30157. 4
  30158. ],
  30159. [
  30160. 2,
  30161. 3
  30162. ],
  30163. [
  30164. 2,
  30165. 3
  30166. ],
  30167. [
  30168. 2,
  30169. 3
  30170. ],
  30171. [
  30172. 2,
  30173. 3
  30174. ],
  30175. // 10xxxx
  30176. [
  30177. 2,
  30178. 3
  30179. ],
  30180. [
  30181. 2,
  30182. 3
  30183. ],
  30184. [
  30185. 2,
  30186. 3
  30187. ],
  30188. [
  30189. 2,
  30190. 3
  30191. ],
  30192. [
  30193. 2,
  30194. 3
  30195. ],
  30196. [
  30197. 2,
  30198. 3
  30199. ],
  30200. [
  30201. 2,
  30202. 3
  30203. ],
  30204. [
  30205. 2,
  30206. 3
  30207. ],
  30208. [
  30209. 2,
  30210. 3
  30211. ],
  30212. [
  30213. 2,
  30214. 3
  30215. ],
  30216. [
  30217. 2,
  30218. 3
  30219. ],
  30220. [
  30221. 2,
  30222. 3
  30223. ],
  30224. [
  30225. 2,
  30226. 2
  30227. ],
  30228. [
  30229. 2,
  30230. 2
  30231. ],
  30232. [
  30233. 2,
  30234. 2
  30235. ],
  30236. [
  30237. 2,
  30238. 2
  30239. ],
  30240. // 11xxxx
  30241. [
  30242. 2,
  30243. 2
  30244. ],
  30245. [
  30246. 2,
  30247. 2
  30248. ],
  30249. [
  30250. 2,
  30251. 2
  30252. ],
  30253. [
  30254. 2,
  30255. 2
  30256. ],
  30257. [
  30258. 2,
  30259. 2
  30260. ],
  30261. [
  30262. 2,
  30263. 2
  30264. ],
  30265. [
  30266. 2,
  30267. 2
  30268. ],
  30269. [
  30270. 2,
  30271. 2
  30272. ],
  30273. [
  30274. 2,
  30275. 2
  30276. ],
  30277. [
  30278. 2,
  30279. 2
  30280. ],
  30281. [
  30282. 2,
  30283. 2
  30284. ],
  30285. [
  30286. 2,
  30287. 2
  30288. ]
  30289. ];
  30290. function CCITTFaxStream(str, maybeLength, params) {
  30291. this.str = str;
  30292. this.dict = str.dict;
  30293. params = params || Dict.empty;
  30294. this.encoding = params.get('K') || 0;
  30295. this.eoline = params.get('EndOfLine') || false;
  30296. this.byteAlign = params.get('EncodedByteAlign') || false;
  30297. this.columns = params.get('Columns') || 1728;
  30298. this.rows = params.get('Rows') || 0;
  30299. var eoblock = params.get('EndOfBlock');
  30300. if (eoblock === null || eoblock === undefined) {
  30301. eoblock = true;
  30302. }
  30303. this.eoblock = eoblock;
  30304. this.black = params.get('BlackIs1') || false;
  30305. this.codingLine = new Uint32Array(this.columns + 1);
  30306. this.refLine = new Uint32Array(this.columns + 2);
  30307. this.codingLine[0] = this.columns;
  30308. this.codingPos = 0;
  30309. this.row = 0;
  30310. this.nextLine2D = this.encoding < 0;
  30311. this.inputBits = 0;
  30312. this.inputBuf = 0;
  30313. this.outputBits = 0;
  30314. var code1;
  30315. while ((code1 = this.lookBits(12)) === 0) {
  30316. this.eatBits(1);
  30317. }
  30318. if (code1 === 1) {
  30319. this.eatBits(12);
  30320. }
  30321. if (this.encoding > 0) {
  30322. this.nextLine2D = !this.lookBits(1);
  30323. this.eatBits(1);
  30324. }
  30325. DecodeStream.call(this, maybeLength);
  30326. }
  30327. CCITTFaxStream.prototype = Object.create(DecodeStream.prototype);
  30328. CCITTFaxStream.prototype.readBlock = function CCITTFaxStream_readBlock() {
  30329. while (!this.eof) {
  30330. var c = this.lookChar();
  30331. this.ensureBuffer(this.bufferLength + 1);
  30332. this.buffer[this.bufferLength++] = c;
  30333. }
  30334. };
  30335. CCITTFaxStream.prototype.addPixels = function ccittFaxStreamAddPixels(a1, blackPixels) {
  30336. var codingLine = this.codingLine;
  30337. var codingPos = this.codingPos;
  30338. if (a1 > codingLine[codingPos]) {
  30339. if (a1 > this.columns) {
  30340. info('row is wrong length');
  30341. this.err = true;
  30342. a1 = this.columns;
  30343. }
  30344. if (codingPos & 1 ^ blackPixels) {
  30345. ++codingPos;
  30346. }
  30347. codingLine[codingPos] = a1;
  30348. }
  30349. this.codingPos = codingPos;
  30350. };
  30351. CCITTFaxStream.prototype.addPixelsNeg = function ccittFaxStreamAddPixelsNeg(a1, blackPixels) {
  30352. var codingLine = this.codingLine;
  30353. var codingPos = this.codingPos;
  30354. if (a1 > codingLine[codingPos]) {
  30355. if (a1 > this.columns) {
  30356. info('row is wrong length');
  30357. this.err = true;
  30358. a1 = this.columns;
  30359. }
  30360. if (codingPos & 1 ^ blackPixels) {
  30361. ++codingPos;
  30362. }
  30363. codingLine[codingPos] = a1;
  30364. } else if (a1 < codingLine[codingPos]) {
  30365. if (a1 < 0) {
  30366. info('invalid code');
  30367. this.err = true;
  30368. a1 = 0;
  30369. }
  30370. while (codingPos > 0 && a1 < codingLine[codingPos - 1]) {
  30371. --codingPos;
  30372. }
  30373. codingLine[codingPos] = a1;
  30374. }
  30375. this.codingPos = codingPos;
  30376. };
  30377. CCITTFaxStream.prototype.lookChar = function CCITTFaxStream_lookChar() {
  30378. var refLine = this.refLine;
  30379. var codingLine = this.codingLine;
  30380. var columns = this.columns;
  30381. var refPos, blackPixels, bits, i;
  30382. if (this.outputBits === 0) {
  30383. if (this.eof) {
  30384. return null;
  30385. }
  30386. this.err = false;
  30387. var code1, code2, code3;
  30388. if (this.nextLine2D) {
  30389. for (i = 0; codingLine[i] < columns; ++i) {
  30390. refLine[i] = codingLine[i];
  30391. }
  30392. refLine[i++] = columns;
  30393. refLine[i] = columns;
  30394. codingLine[0] = 0;
  30395. this.codingPos = 0;
  30396. refPos = 0;
  30397. blackPixels = 0;
  30398. while (codingLine[this.codingPos] < columns) {
  30399. code1 = this.getTwoDimCode();
  30400. switch (code1) {
  30401. case twoDimPass:
  30402. this.addPixels(refLine[refPos + 1], blackPixels);
  30403. if (refLine[refPos + 1] < columns) {
  30404. refPos += 2;
  30405. }
  30406. break;
  30407. case twoDimHoriz:
  30408. code1 = code2 = 0;
  30409. if (blackPixels) {
  30410. do {
  30411. code1 += code3 = this.getBlackCode();
  30412. } while (code3 >= 64);
  30413. do {
  30414. code2 += code3 = this.getWhiteCode();
  30415. } while (code3 >= 64);
  30416. } else {
  30417. do {
  30418. code1 += code3 = this.getWhiteCode();
  30419. } while (code3 >= 64);
  30420. do {
  30421. code2 += code3 = this.getBlackCode();
  30422. } while (code3 >= 64);
  30423. }
  30424. this.addPixels(codingLine[this.codingPos] + code1, blackPixels);
  30425. if (codingLine[this.codingPos] < columns) {
  30426. this.addPixels(codingLine[this.codingPos] + code2, blackPixels ^ 1);
  30427. }
  30428. while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
  30429. refPos += 2;
  30430. }
  30431. break;
  30432. case twoDimVertR3:
  30433. this.addPixels(refLine[refPos] + 3, blackPixels);
  30434. blackPixels ^= 1;
  30435. if (codingLine[this.codingPos] < columns) {
  30436. ++refPos;
  30437. while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
  30438. refPos += 2;
  30439. }
  30440. }
  30441. break;
  30442. case twoDimVertR2:
  30443. this.addPixels(refLine[refPos] + 2, blackPixels);
  30444. blackPixels ^= 1;
  30445. if (codingLine[this.codingPos] < columns) {
  30446. ++refPos;
  30447. while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
  30448. refPos += 2;
  30449. }
  30450. }
  30451. break;
  30452. case twoDimVertR1:
  30453. this.addPixels(refLine[refPos] + 1, blackPixels);
  30454. blackPixels ^= 1;
  30455. if (codingLine[this.codingPos] < columns) {
  30456. ++refPos;
  30457. while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
  30458. refPos += 2;
  30459. }
  30460. }
  30461. break;
  30462. case twoDimVert0:
  30463. this.addPixels(refLine[refPos], blackPixels);
  30464. blackPixels ^= 1;
  30465. if (codingLine[this.codingPos] < columns) {
  30466. ++refPos;
  30467. while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
  30468. refPos += 2;
  30469. }
  30470. }
  30471. break;
  30472. case twoDimVertL3:
  30473. this.addPixelsNeg(refLine[refPos] - 3, blackPixels);
  30474. blackPixels ^= 1;
  30475. if (codingLine[this.codingPos] < columns) {
  30476. if (refPos > 0) {
  30477. --refPos;
  30478. } else {
  30479. ++refPos;
  30480. }
  30481. while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
  30482. refPos += 2;
  30483. }
  30484. }
  30485. break;
  30486. case twoDimVertL2:
  30487. this.addPixelsNeg(refLine[refPos] - 2, blackPixels);
  30488. blackPixels ^= 1;
  30489. if (codingLine[this.codingPos] < columns) {
  30490. if (refPos > 0) {
  30491. --refPos;
  30492. } else {
  30493. ++refPos;
  30494. }
  30495. while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
  30496. refPos += 2;
  30497. }
  30498. }
  30499. break;
  30500. case twoDimVertL1:
  30501. this.addPixelsNeg(refLine[refPos] - 1, blackPixels);
  30502. blackPixels ^= 1;
  30503. if (codingLine[this.codingPos] < columns) {
  30504. if (refPos > 0) {
  30505. --refPos;
  30506. } else {
  30507. ++refPos;
  30508. }
  30509. while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
  30510. refPos += 2;
  30511. }
  30512. }
  30513. break;
  30514. case ccittEOF:
  30515. this.addPixels(columns, 0);
  30516. this.eof = true;
  30517. break;
  30518. default:
  30519. info('bad 2d code');
  30520. this.addPixels(columns, 0);
  30521. this.err = true;
  30522. }
  30523. }
  30524. } else {
  30525. codingLine[0] = 0;
  30526. this.codingPos = 0;
  30527. blackPixels = 0;
  30528. while (codingLine[this.codingPos] < columns) {
  30529. code1 = 0;
  30530. if (blackPixels) {
  30531. do {
  30532. code1 += code3 = this.getBlackCode();
  30533. } while (code3 >= 64);
  30534. } else {
  30535. do {
  30536. code1 += code3 = this.getWhiteCode();
  30537. } while (code3 >= 64);
  30538. }
  30539. this.addPixels(codingLine[this.codingPos] + code1, blackPixels);
  30540. blackPixels ^= 1;
  30541. }
  30542. }
  30543. var gotEOL = false;
  30544. if (this.byteAlign) {
  30545. this.inputBits &= ~7;
  30546. }
  30547. if (!this.eoblock && this.row === this.rows - 1) {
  30548. this.eof = true;
  30549. } else {
  30550. code1 = this.lookBits(12);
  30551. if (this.eoline) {
  30552. while (code1 !== ccittEOF && code1 !== 1) {
  30553. this.eatBits(1);
  30554. code1 = this.lookBits(12);
  30555. }
  30556. } else {
  30557. while (code1 === 0) {
  30558. this.eatBits(1);
  30559. code1 = this.lookBits(12);
  30560. }
  30561. }
  30562. if (code1 === 1) {
  30563. this.eatBits(12);
  30564. gotEOL = true;
  30565. } else if (code1 === ccittEOF) {
  30566. this.eof = true;
  30567. }
  30568. }
  30569. if (!this.eof && this.encoding > 0) {
  30570. this.nextLine2D = !this.lookBits(1);
  30571. this.eatBits(1);
  30572. }
  30573. if (this.eoblock && gotEOL && this.byteAlign) {
  30574. code1 = this.lookBits(12);
  30575. if (code1 === 1) {
  30576. this.eatBits(12);
  30577. if (this.encoding > 0) {
  30578. this.lookBits(1);
  30579. this.eatBits(1);
  30580. }
  30581. if (this.encoding >= 0) {
  30582. for (i = 0; i < 4; ++i) {
  30583. code1 = this.lookBits(12);
  30584. if (code1 !== 1) {
  30585. info('bad rtc code: ' + code1);
  30586. }
  30587. this.eatBits(12);
  30588. if (this.encoding > 0) {
  30589. this.lookBits(1);
  30590. this.eatBits(1);
  30591. }
  30592. }
  30593. }
  30594. this.eof = true;
  30595. }
  30596. } else if (this.err && this.eoline) {
  30597. while (true) {
  30598. code1 = this.lookBits(13);
  30599. if (code1 === ccittEOF) {
  30600. this.eof = true;
  30601. return null;
  30602. }
  30603. if (code1 >> 1 === 1) {
  30604. break;
  30605. }
  30606. this.eatBits(1);
  30607. }
  30608. this.eatBits(12);
  30609. if (this.encoding > 0) {
  30610. this.eatBits(1);
  30611. this.nextLine2D = !(code1 & 1);
  30612. }
  30613. }
  30614. if (codingLine[0] > 0) {
  30615. this.outputBits = codingLine[this.codingPos = 0];
  30616. } else {
  30617. this.outputBits = codingLine[this.codingPos = 1];
  30618. }
  30619. this.row++;
  30620. }
  30621. var c;
  30622. if (this.outputBits >= 8) {
  30623. c = this.codingPos & 1 ? 0 : 0xFF;
  30624. this.outputBits -= 8;
  30625. if (this.outputBits === 0 && codingLine[this.codingPos] < columns) {
  30626. this.codingPos++;
  30627. this.outputBits = codingLine[this.codingPos] - codingLine[this.codingPos - 1];
  30628. }
  30629. } else {
  30630. bits = 8;
  30631. c = 0;
  30632. do {
  30633. if (this.outputBits > bits) {
  30634. c <<= bits;
  30635. if (!(this.codingPos & 1)) {
  30636. c |= 0xFF >> 8 - bits;
  30637. }
  30638. this.outputBits -= bits;
  30639. bits = 0;
  30640. } else {
  30641. c <<= this.outputBits;
  30642. if (!(this.codingPos & 1)) {
  30643. c |= 0xFF >> 8 - this.outputBits;
  30644. }
  30645. bits -= this.outputBits;
  30646. this.outputBits = 0;
  30647. if (codingLine[this.codingPos] < columns) {
  30648. this.codingPos++;
  30649. this.outputBits = codingLine[this.codingPos] - codingLine[this.codingPos - 1];
  30650. } else if (bits > 0) {
  30651. c <<= bits;
  30652. bits = 0;
  30653. }
  30654. }
  30655. } while (bits);
  30656. }
  30657. if (this.black) {
  30658. c ^= 0xFF;
  30659. }
  30660. return c;
  30661. };
  30662. // This functions returns the code found from the table.
  30663. // The start and end parameters set the boundaries for searching the table.
  30664. // The limit parameter is optional. Function returns an array with three
  30665. // values. The first array element indicates whether a valid code is being
  30666. // returned. The second array element is the actual code. The third array
  30667. // element indicates whether EOF was reached.
  30668. CCITTFaxStream.prototype.findTableCode = function ccittFaxStreamFindTableCode(start, end, table, limit) {
  30669. var limitValue = limit || 0;
  30670. for (var i = start; i <= end; ++i) {
  30671. var code = this.lookBits(i);
  30672. if (code === ccittEOF) {
  30673. return [
  30674. true,
  30675. 1,
  30676. false
  30677. ];
  30678. }
  30679. if (i < end) {
  30680. code <<= end - i;
  30681. }
  30682. if (!limitValue || code >= limitValue) {
  30683. var p = table[code - limitValue];
  30684. if (p[0] === i) {
  30685. this.eatBits(i);
  30686. return [
  30687. true,
  30688. p[1],
  30689. true
  30690. ];
  30691. }
  30692. }
  30693. }
  30694. return [
  30695. false,
  30696. 0,
  30697. false
  30698. ];
  30699. };
  30700. CCITTFaxStream.prototype.getTwoDimCode = function ccittFaxStreamGetTwoDimCode() {
  30701. var code = 0;
  30702. var p;
  30703. if (this.eoblock) {
  30704. code = this.lookBits(7);
  30705. p = twoDimTable[code];
  30706. if (p && p[0] > 0) {
  30707. this.eatBits(p[0]);
  30708. return p[1];
  30709. }
  30710. } else {
  30711. var result = this.findTableCode(1, 7, twoDimTable);
  30712. if (result[0] && result[2]) {
  30713. return result[1];
  30714. }
  30715. }
  30716. info('Bad two dim code');
  30717. return ccittEOF;
  30718. };
  30719. CCITTFaxStream.prototype.getWhiteCode = function ccittFaxStreamGetWhiteCode() {
  30720. var code = 0;
  30721. var p;
  30722. if (this.eoblock) {
  30723. code = this.lookBits(12);
  30724. if (code === ccittEOF) {
  30725. return 1;
  30726. }
  30727. if (code >> 5 === 0) {
  30728. p = whiteTable1[code];
  30729. } else {
  30730. p = whiteTable2[code >> 3];
  30731. }
  30732. if (p[0] > 0) {
  30733. this.eatBits(p[0]);
  30734. return p[1];
  30735. }
  30736. } else {
  30737. var result = this.findTableCode(1, 9, whiteTable2);
  30738. if (result[0]) {
  30739. return result[1];
  30740. }
  30741. result = this.findTableCode(11, 12, whiteTable1);
  30742. if (result[0]) {
  30743. return result[1];
  30744. }
  30745. }
  30746. info('bad white code');
  30747. this.eatBits(1);
  30748. return 1;
  30749. };
  30750. CCITTFaxStream.prototype.getBlackCode = function ccittFaxStreamGetBlackCode() {
  30751. var code, p;
  30752. if (this.eoblock) {
  30753. code = this.lookBits(13);
  30754. if (code === ccittEOF) {
  30755. return 1;
  30756. }
  30757. if (code >> 7 === 0) {
  30758. p = blackTable1[code];
  30759. } else if (code >> 9 === 0 && code >> 7 !== 0) {
  30760. p = blackTable2[(code >> 1) - 64];
  30761. } else {
  30762. p = blackTable3[code >> 7];
  30763. }
  30764. if (p[0] > 0) {
  30765. this.eatBits(p[0]);
  30766. return p[1];
  30767. }
  30768. } else {
  30769. var result = this.findTableCode(2, 6, blackTable3);
  30770. if (result[0]) {
  30771. return result[1];
  30772. }
  30773. result = this.findTableCode(7, 12, blackTable2, 64);
  30774. if (result[0]) {
  30775. return result[1];
  30776. }
  30777. result = this.findTableCode(10, 13, blackTable1);
  30778. if (result[0]) {
  30779. return result[1];
  30780. }
  30781. }
  30782. info('bad black code');
  30783. this.eatBits(1);
  30784. return 1;
  30785. };
  30786. CCITTFaxStream.prototype.lookBits = function CCITTFaxStream_lookBits(n) {
  30787. var c;
  30788. while (this.inputBits < n) {
  30789. if ((c = this.str.getByte()) === -1) {
  30790. if (this.inputBits === 0) {
  30791. return ccittEOF;
  30792. }
  30793. return this.inputBuf << n - this.inputBits & 0xFFFF >> 16 - n;
  30794. }
  30795. this.inputBuf = this.inputBuf << 8 | c;
  30796. this.inputBits += 8;
  30797. }
  30798. return this.inputBuf >> this.inputBits - n & 0xFFFF >> 16 - n;
  30799. };
  30800. CCITTFaxStream.prototype.eatBits = function CCITTFaxStream_eatBits(n) {
  30801. if ((this.inputBits -= n) < 0) {
  30802. this.inputBits = 0;
  30803. }
  30804. };
  30805. return CCITTFaxStream;
  30806. }();
  30807. var LZWStream = function LZWStreamClosure() {
  30808. function LZWStream(str, maybeLength, earlyChange) {
  30809. this.str = str;
  30810. this.dict = str.dict;
  30811. this.cachedData = 0;
  30812. this.bitsCached = 0;
  30813. var maxLzwDictionarySize = 4096;
  30814. var lzwState = {
  30815. earlyChange: earlyChange,
  30816. codeLength: 9,
  30817. nextCode: 258,
  30818. dictionaryValues: new Uint8Array(maxLzwDictionarySize),
  30819. dictionaryLengths: new Uint16Array(maxLzwDictionarySize),
  30820. dictionaryPrevCodes: new Uint16Array(maxLzwDictionarySize),
  30821. currentSequence: new Uint8Array(maxLzwDictionarySize),
  30822. currentSequenceLength: 0
  30823. };
  30824. for (var i = 0; i < 256; ++i) {
  30825. lzwState.dictionaryValues[i] = i;
  30826. lzwState.dictionaryLengths[i] = 1;
  30827. }
  30828. this.lzwState = lzwState;
  30829. DecodeStream.call(this, maybeLength);
  30830. }
  30831. LZWStream.prototype = Object.create(DecodeStream.prototype);
  30832. LZWStream.prototype.readBits = function LZWStream_readBits(n) {
  30833. var bitsCached = this.bitsCached;
  30834. var cachedData = this.cachedData;
  30835. while (bitsCached < n) {
  30836. var c = this.str.getByte();
  30837. if (c === -1) {
  30838. this.eof = true;
  30839. return null;
  30840. }
  30841. cachedData = cachedData << 8 | c;
  30842. bitsCached += 8;
  30843. }
  30844. this.bitsCached = bitsCached -= n;
  30845. this.cachedData = cachedData;
  30846. this.lastCode = null;
  30847. return cachedData >>> bitsCached & (1 << n) - 1;
  30848. };
  30849. LZWStream.prototype.readBlock = function LZWStream_readBlock() {
  30850. var blockSize = 512;
  30851. var estimatedDecodedSize = blockSize * 2, decodedSizeDelta = blockSize;
  30852. var i, j, q;
  30853. var lzwState = this.lzwState;
  30854. if (!lzwState) {
  30855. return;
  30856. }
  30857. // eof was found
  30858. var earlyChange = lzwState.earlyChange;
  30859. var nextCode = lzwState.nextCode;
  30860. var dictionaryValues = lzwState.dictionaryValues;
  30861. var dictionaryLengths = lzwState.dictionaryLengths;
  30862. var dictionaryPrevCodes = lzwState.dictionaryPrevCodes;
  30863. var codeLength = lzwState.codeLength;
  30864. var prevCode = lzwState.prevCode;
  30865. var currentSequence = lzwState.currentSequence;
  30866. var currentSequenceLength = lzwState.currentSequenceLength;
  30867. var decodedLength = 0;
  30868. var currentBufferLength = this.bufferLength;
  30869. var buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  30870. for (i = 0; i < blockSize; i++) {
  30871. var code = this.readBits(codeLength);
  30872. var hasPrev = currentSequenceLength > 0;
  30873. if (code < 256) {
  30874. currentSequence[0] = code;
  30875. currentSequenceLength = 1;
  30876. } else if (code >= 258) {
  30877. if (code < nextCode) {
  30878. currentSequenceLength = dictionaryLengths[code];
  30879. for (j = currentSequenceLength - 1, q = code; j >= 0; j--) {
  30880. currentSequence[j] = dictionaryValues[q];
  30881. q = dictionaryPrevCodes[q];
  30882. }
  30883. } else {
  30884. currentSequence[currentSequenceLength++] = currentSequence[0];
  30885. }
  30886. } else if (code === 256) {
  30887. codeLength = 9;
  30888. nextCode = 258;
  30889. currentSequenceLength = 0;
  30890. continue;
  30891. } else {
  30892. this.eof = true;
  30893. delete this.lzwState;
  30894. break;
  30895. }
  30896. if (hasPrev) {
  30897. dictionaryPrevCodes[nextCode] = prevCode;
  30898. dictionaryLengths[nextCode] = dictionaryLengths[prevCode] + 1;
  30899. dictionaryValues[nextCode] = currentSequence[0];
  30900. nextCode++;
  30901. codeLength = nextCode + earlyChange & nextCode + earlyChange - 1 ? codeLength : Math.min(Math.log(nextCode + earlyChange) / 0.6931471805599453 + 1, 12) | 0;
  30902. }
  30903. prevCode = code;
  30904. decodedLength += currentSequenceLength;
  30905. if (estimatedDecodedSize < decodedLength) {
  30906. do {
  30907. estimatedDecodedSize += decodedSizeDelta;
  30908. } while (estimatedDecodedSize < decodedLength);
  30909. buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  30910. }
  30911. for (j = 0; j < currentSequenceLength; j++) {
  30912. buffer[currentBufferLength++] = currentSequence[j];
  30913. }
  30914. }
  30915. lzwState.nextCode = nextCode;
  30916. lzwState.codeLength = codeLength;
  30917. lzwState.prevCode = prevCode;
  30918. lzwState.currentSequenceLength = currentSequenceLength;
  30919. this.bufferLength = currentBufferLength;
  30920. };
  30921. return LZWStream;
  30922. }();
  30923. var NullStream = function NullStreamClosure() {
  30924. function NullStream() {
  30925. Stream.call(this, new Uint8Array(0));
  30926. }
  30927. NullStream.prototype = Stream.prototype;
  30928. return NullStream;
  30929. }();
  30930. exports.Ascii85Stream = Ascii85Stream;
  30931. exports.AsciiHexStream = AsciiHexStream;
  30932. exports.CCITTFaxStream = CCITTFaxStream;
  30933. exports.DecryptStream = DecryptStream;
  30934. exports.DecodeStream = DecodeStream;
  30935. exports.FlateStream = FlateStream;
  30936. exports.Jbig2Stream = Jbig2Stream;
  30937. exports.JpegStream = JpegStream;
  30938. exports.JpxStream = JpxStream;
  30939. exports.NullStream = NullStream;
  30940. exports.PredictorStream = PredictorStream;
  30941. exports.RunLengthStream = RunLengthStream;
  30942. exports.Stream = Stream;
  30943. exports.StreamsSequenceStream = StreamsSequenceStream;
  30944. exports.StringStream = StringStream;
  30945. exports.LZWStream = LZWStream;
  30946. }));
  30947. (function (root, factory) {
  30948. factory(root.pdfjsCoreCrypto = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCoreStream);
  30949. }(this, function (exports, sharedUtil, corePrimitives, coreStream) {
  30950. var PasswordException = sharedUtil.PasswordException;
  30951. var PasswordResponses = sharedUtil.PasswordResponses;
  30952. var bytesToString = sharedUtil.bytesToString;
  30953. var warn = sharedUtil.warn;
  30954. var error = sharedUtil.error;
  30955. var assert = sharedUtil.assert;
  30956. var isInt = sharedUtil.isInt;
  30957. var stringToBytes = sharedUtil.stringToBytes;
  30958. var utf8StringToString = sharedUtil.utf8StringToString;
  30959. var Name = corePrimitives.Name;
  30960. var isName = corePrimitives.isName;
  30961. var isDict = corePrimitives.isDict;
  30962. var DecryptStream = coreStream.DecryptStream;
  30963. var ARCFourCipher = function ARCFourCipherClosure() {
  30964. function ARCFourCipher(key) {
  30965. this.a = 0;
  30966. this.b = 0;
  30967. var s = new Uint8Array(256);
  30968. var i, j = 0, tmp, keyLength = key.length;
  30969. for (i = 0; i < 256; ++i) {
  30970. s[i] = i;
  30971. }
  30972. for (i = 0; i < 256; ++i) {
  30973. tmp = s[i];
  30974. j = j + tmp + key[i % keyLength] & 0xFF;
  30975. s[i] = s[j];
  30976. s[j] = tmp;
  30977. }
  30978. this.s = s;
  30979. }
  30980. ARCFourCipher.prototype = {
  30981. encryptBlock: function ARCFourCipher_encryptBlock(data) {
  30982. var i, n = data.length, tmp, tmp2;
  30983. var a = this.a, b = this.b, s = this.s;
  30984. var output = new Uint8Array(n);
  30985. for (i = 0; i < n; ++i) {
  30986. a = a + 1 & 0xFF;
  30987. tmp = s[a];
  30988. b = b + tmp & 0xFF;
  30989. tmp2 = s[b];
  30990. s[a] = tmp2;
  30991. s[b] = tmp;
  30992. output[i] = data[i] ^ s[tmp + tmp2 & 0xFF];
  30993. }
  30994. this.a = a;
  30995. this.b = b;
  30996. return output;
  30997. }
  30998. };
  30999. ARCFourCipher.prototype.decryptBlock = ARCFourCipher.prototype.encryptBlock;
  31000. return ARCFourCipher;
  31001. }();
  31002. var calculateMD5 = function calculateMD5Closure() {
  31003. var r = new Uint8Array([
  31004. 7,
  31005. 12,
  31006. 17,
  31007. 22,
  31008. 7,
  31009. 12,
  31010. 17,
  31011. 22,
  31012. 7,
  31013. 12,
  31014. 17,
  31015. 22,
  31016. 7,
  31017. 12,
  31018. 17,
  31019. 22,
  31020. 5,
  31021. 9,
  31022. 14,
  31023. 20,
  31024. 5,
  31025. 9,
  31026. 14,
  31027. 20,
  31028. 5,
  31029. 9,
  31030. 14,
  31031. 20,
  31032. 5,
  31033. 9,
  31034. 14,
  31035. 20,
  31036. 4,
  31037. 11,
  31038. 16,
  31039. 23,
  31040. 4,
  31041. 11,
  31042. 16,
  31043. 23,
  31044. 4,
  31045. 11,
  31046. 16,
  31047. 23,
  31048. 4,
  31049. 11,
  31050. 16,
  31051. 23,
  31052. 6,
  31053. 10,
  31054. 15,
  31055. 21,
  31056. 6,
  31057. 10,
  31058. 15,
  31059. 21,
  31060. 6,
  31061. 10,
  31062. 15,
  31063. 21,
  31064. 6,
  31065. 10,
  31066. 15,
  31067. 21
  31068. ]);
  31069. var k = new Int32Array([
  31070. -680876936,
  31071. -389564586,
  31072. 606105819,
  31073. -1044525330,
  31074. -176418897,
  31075. 1200080426,
  31076. -1473231341,
  31077. -45705983,
  31078. 1770035416,
  31079. -1958414417,
  31080. -42063,
  31081. -1990404162,
  31082. 1804603682,
  31083. -40341101,
  31084. -1502002290,
  31085. 1236535329,
  31086. -165796510,
  31087. -1069501632,
  31088. 643717713,
  31089. -373897302,
  31090. -701558691,
  31091. 38016083,
  31092. -660478335,
  31093. -405537848,
  31094. 568446438,
  31095. -1019803690,
  31096. -187363961,
  31097. 1163531501,
  31098. -1444681467,
  31099. -51403784,
  31100. 1735328473,
  31101. -1926607734,
  31102. -378558,
  31103. -2022574463,
  31104. 1839030562,
  31105. -35309556,
  31106. -1530992060,
  31107. 1272893353,
  31108. -155497632,
  31109. -1094730640,
  31110. 681279174,
  31111. -358537222,
  31112. -722521979,
  31113. 76029189,
  31114. -640364487,
  31115. -421815835,
  31116. 530742520,
  31117. -995338651,
  31118. -198630844,
  31119. 1126891415,
  31120. -1416354905,
  31121. -57434055,
  31122. 1700485571,
  31123. -1894986606,
  31124. -1051523,
  31125. -2054922799,
  31126. 1873313359,
  31127. -30611744,
  31128. -1560198380,
  31129. 1309151649,
  31130. -145523070,
  31131. -1120210379,
  31132. 718787259,
  31133. -343485551
  31134. ]);
  31135. function hash(data, offset, length) {
  31136. var h0 = 1732584193, h1 = -271733879, h2 = -1732584194, h3 = 271733878;
  31137. // pre-processing
  31138. var paddedLength = length + 72 & ~63;
  31139. // data + 9 extra bytes
  31140. var padded = new Uint8Array(paddedLength);
  31141. var i, j, n;
  31142. for (i = 0; i < length; ++i) {
  31143. padded[i] = data[offset++];
  31144. }
  31145. padded[i++] = 0x80;
  31146. n = paddedLength - 8;
  31147. while (i < n) {
  31148. padded[i++] = 0;
  31149. }
  31150. padded[i++] = length << 3 & 0xFF;
  31151. padded[i++] = length >> 5 & 0xFF;
  31152. padded[i++] = length >> 13 & 0xFF;
  31153. padded[i++] = length >> 21 & 0xFF;
  31154. padded[i++] = length >>> 29 & 0xFF;
  31155. padded[i++] = 0;
  31156. padded[i++] = 0;
  31157. padded[i++] = 0;
  31158. var w = new Int32Array(16);
  31159. for (i = 0; i < paddedLength;) {
  31160. for (j = 0; j < 16; ++j, i += 4) {
  31161. w[j] = padded[i] | padded[i + 1] << 8 | padded[i + 2] << 16 | padded[i + 3] << 24;
  31162. }
  31163. var a = h0, b = h1, c = h2, d = h3, f, g;
  31164. for (j = 0; j < 64; ++j) {
  31165. if (j < 16) {
  31166. f = b & c | ~b & d;
  31167. g = j;
  31168. } else if (j < 32) {
  31169. f = d & b | ~d & c;
  31170. g = 5 * j + 1 & 15;
  31171. } else if (j < 48) {
  31172. f = b ^ c ^ d;
  31173. g = 3 * j + 5 & 15;
  31174. } else {
  31175. f = c ^ (b | ~d);
  31176. g = 7 * j & 15;
  31177. }
  31178. var tmp = d, rotateArg = a + f + k[j] + w[g] | 0, rotate = r[j];
  31179. d = c;
  31180. c = b;
  31181. b = b + (rotateArg << rotate | rotateArg >>> 32 - rotate) | 0;
  31182. a = tmp;
  31183. }
  31184. h0 = h0 + a | 0;
  31185. h1 = h1 + b | 0;
  31186. h2 = h2 + c | 0;
  31187. h3 = h3 + d | 0;
  31188. }
  31189. return new Uint8Array([
  31190. h0 & 0xFF,
  31191. h0 >> 8 & 0xFF,
  31192. h0 >> 16 & 0xFF,
  31193. h0 >>> 24 & 0xFF,
  31194. h1 & 0xFF,
  31195. h1 >> 8 & 0xFF,
  31196. h1 >> 16 & 0xFF,
  31197. h1 >>> 24 & 0xFF,
  31198. h2 & 0xFF,
  31199. h2 >> 8 & 0xFF,
  31200. h2 >> 16 & 0xFF,
  31201. h2 >>> 24 & 0xFF,
  31202. h3 & 0xFF,
  31203. h3 >> 8 & 0xFF,
  31204. h3 >> 16 & 0xFF,
  31205. h3 >>> 24 & 0xFF
  31206. ]);
  31207. }
  31208. return hash;
  31209. }();
  31210. var Word64 = function Word64Closure() {
  31211. function Word64(highInteger, lowInteger) {
  31212. this.high = highInteger | 0;
  31213. this.low = lowInteger | 0;
  31214. }
  31215. Word64.prototype = {
  31216. and: function Word64_and(word) {
  31217. this.high &= word.high;
  31218. this.low &= word.low;
  31219. },
  31220. xor: function Word64_xor(word) {
  31221. this.high ^= word.high;
  31222. this.low ^= word.low;
  31223. },
  31224. or: function Word64_or(word) {
  31225. this.high |= word.high;
  31226. this.low |= word.low;
  31227. },
  31228. shiftRight: function Word64_shiftRight(places) {
  31229. if (places >= 32) {
  31230. this.low = this.high >>> places - 32 | 0;
  31231. this.high = 0;
  31232. } else {
  31233. this.low = this.low >>> places | this.high << 32 - places;
  31234. this.high = this.high >>> places | 0;
  31235. }
  31236. },
  31237. shiftLeft: function Word64_shiftLeft(places) {
  31238. if (places >= 32) {
  31239. this.high = this.low << places - 32;
  31240. this.low = 0;
  31241. } else {
  31242. this.high = this.high << places | this.low >>> 32 - places;
  31243. this.low = this.low << places;
  31244. }
  31245. },
  31246. rotateRight: function Word64_rotateRight(places) {
  31247. var low, high;
  31248. if (places & 32) {
  31249. high = this.low;
  31250. low = this.high;
  31251. } else {
  31252. low = this.low;
  31253. high = this.high;
  31254. }
  31255. places &= 31;
  31256. this.low = low >>> places | high << 32 - places;
  31257. this.high = high >>> places | low << 32 - places;
  31258. },
  31259. not: function Word64_not() {
  31260. this.high = ~this.high;
  31261. this.low = ~this.low;
  31262. },
  31263. add: function Word64_add(word) {
  31264. var lowAdd = (this.low >>> 0) + (word.low >>> 0);
  31265. var highAdd = (this.high >>> 0) + (word.high >>> 0);
  31266. if (lowAdd > 0xFFFFFFFF) {
  31267. highAdd += 1;
  31268. }
  31269. this.low = lowAdd | 0;
  31270. this.high = highAdd | 0;
  31271. },
  31272. copyTo: function Word64_copyTo(bytes, offset) {
  31273. bytes[offset] = this.high >>> 24 & 0xFF;
  31274. bytes[offset + 1] = this.high >> 16 & 0xFF;
  31275. bytes[offset + 2] = this.high >> 8 & 0xFF;
  31276. bytes[offset + 3] = this.high & 0xFF;
  31277. bytes[offset + 4] = this.low >>> 24 & 0xFF;
  31278. bytes[offset + 5] = this.low >> 16 & 0xFF;
  31279. bytes[offset + 6] = this.low >> 8 & 0xFF;
  31280. bytes[offset + 7] = this.low & 0xFF;
  31281. },
  31282. assign: function Word64_assign(word) {
  31283. this.high = word.high;
  31284. this.low = word.low;
  31285. }
  31286. };
  31287. return Word64;
  31288. }();
  31289. var calculateSHA256 = function calculateSHA256Closure() {
  31290. function rotr(x, n) {
  31291. return x >>> n | x << 32 - n;
  31292. }
  31293. function ch(x, y, z) {
  31294. return x & y ^ ~x & z;
  31295. }
  31296. function maj(x, y, z) {
  31297. return x & y ^ x & z ^ y & z;
  31298. }
  31299. function sigma(x) {
  31300. return rotr(x, 2) ^ rotr(x, 13) ^ rotr(x, 22);
  31301. }
  31302. function sigmaPrime(x) {
  31303. return rotr(x, 6) ^ rotr(x, 11) ^ rotr(x, 25);
  31304. }
  31305. function littleSigma(x) {
  31306. return rotr(x, 7) ^ rotr(x, 18) ^ x >>> 3;
  31307. }
  31308. function littleSigmaPrime(x) {
  31309. return rotr(x, 17) ^ rotr(x, 19) ^ x >>> 10;
  31310. }
  31311. var k = [
  31312. 0x428a2f98,
  31313. 0x71374491,
  31314. 0xb5c0fbcf,
  31315. 0xe9b5dba5,
  31316. 0x3956c25b,
  31317. 0x59f111f1,
  31318. 0x923f82a4,
  31319. 0xab1c5ed5,
  31320. 0xd807aa98,
  31321. 0x12835b01,
  31322. 0x243185be,
  31323. 0x550c7dc3,
  31324. 0x72be5d74,
  31325. 0x80deb1fe,
  31326. 0x9bdc06a7,
  31327. 0xc19bf174,
  31328. 0xe49b69c1,
  31329. 0xefbe4786,
  31330. 0x0fc19dc6,
  31331. 0x240ca1cc,
  31332. 0x2de92c6f,
  31333. 0x4a7484aa,
  31334. 0x5cb0a9dc,
  31335. 0x76f988da,
  31336. 0x983e5152,
  31337. 0xa831c66d,
  31338. 0xb00327c8,
  31339. 0xbf597fc7,
  31340. 0xc6e00bf3,
  31341. 0xd5a79147,
  31342. 0x06ca6351,
  31343. 0x14292967,
  31344. 0x27b70a85,
  31345. 0x2e1b2138,
  31346. 0x4d2c6dfc,
  31347. 0x53380d13,
  31348. 0x650a7354,
  31349. 0x766a0abb,
  31350. 0x81c2c92e,
  31351. 0x92722c85,
  31352. 0xa2bfe8a1,
  31353. 0xa81a664b,
  31354. 0xc24b8b70,
  31355. 0xc76c51a3,
  31356. 0xd192e819,
  31357. 0xd6990624,
  31358. 0xf40e3585,
  31359. 0x106aa070,
  31360. 0x19a4c116,
  31361. 0x1e376c08,
  31362. 0x2748774c,
  31363. 0x34b0bcb5,
  31364. 0x391c0cb3,
  31365. 0x4ed8aa4a,
  31366. 0x5b9cca4f,
  31367. 0x682e6ff3,
  31368. 0x748f82ee,
  31369. 0x78a5636f,
  31370. 0x84c87814,
  31371. 0x8cc70208,
  31372. 0x90befffa,
  31373. 0xa4506ceb,
  31374. 0xbef9a3f7,
  31375. 0xc67178f2
  31376. ];
  31377. function hash(data, offset, length) {
  31378. // initial hash values
  31379. var h0 = 0x6a09e667, h1 = 0xbb67ae85, h2 = 0x3c6ef372, h3 = 0xa54ff53a, h4 = 0x510e527f, h5 = 0x9b05688c, h6 = 0x1f83d9ab, h7 = 0x5be0cd19;
  31380. // pre-processing
  31381. var paddedLength = Math.ceil((length + 9) / 64) * 64;
  31382. var padded = new Uint8Array(paddedLength);
  31383. var i, j, n;
  31384. for (i = 0; i < length; ++i) {
  31385. padded[i] = data[offset++];
  31386. }
  31387. padded[i++] = 0x80;
  31388. n = paddedLength - 8;
  31389. while (i < n) {
  31390. padded[i++] = 0;
  31391. }
  31392. padded[i++] = 0;
  31393. padded[i++] = 0;
  31394. padded[i++] = 0;
  31395. padded[i++] = length >>> 29 & 0xFF;
  31396. padded[i++] = length >> 21 & 0xFF;
  31397. padded[i++] = length >> 13 & 0xFF;
  31398. padded[i++] = length >> 5 & 0xFF;
  31399. padded[i++] = length << 3 & 0xFF;
  31400. var w = new Uint32Array(64);
  31401. // for each 512 bit block
  31402. for (i = 0; i < paddedLength;) {
  31403. for (j = 0; j < 16; ++j) {
  31404. w[j] = padded[i] << 24 | padded[i + 1] << 16 | padded[i + 2] << 8 | padded[i + 3];
  31405. i += 4;
  31406. }
  31407. for (j = 16; j < 64; ++j) {
  31408. w[j] = littleSigmaPrime(w[j - 2]) + w[j - 7] + littleSigma(w[j - 15]) + w[j - 16] | 0;
  31409. }
  31410. var a = h0, b = h1, c = h2, d = h3, e = h4, f = h5, g = h6, h = h7, t1, t2;
  31411. for (j = 0; j < 64; ++j) {
  31412. t1 = h + sigmaPrime(e) + ch(e, f, g) + k[j] + w[j];
  31413. t2 = sigma(a) + maj(a, b, c);
  31414. h = g;
  31415. g = f;
  31416. f = e;
  31417. e = d + t1 | 0;
  31418. d = c;
  31419. c = b;
  31420. b = a;
  31421. a = t1 + t2 | 0;
  31422. }
  31423. h0 = h0 + a | 0;
  31424. h1 = h1 + b | 0;
  31425. h2 = h2 + c | 0;
  31426. h3 = h3 + d | 0;
  31427. h4 = h4 + e | 0;
  31428. h5 = h5 + f | 0;
  31429. h6 = h6 + g | 0;
  31430. h7 = h7 + h | 0;
  31431. }
  31432. return new Uint8Array([
  31433. h0 >> 24 & 0xFF,
  31434. h0 >> 16 & 0xFF,
  31435. h0 >> 8 & 0xFF,
  31436. h0 & 0xFF,
  31437. h1 >> 24 & 0xFF,
  31438. h1 >> 16 & 0xFF,
  31439. h1 >> 8 & 0xFF,
  31440. h1 & 0xFF,
  31441. h2 >> 24 & 0xFF,
  31442. h2 >> 16 & 0xFF,
  31443. h2 >> 8 & 0xFF,
  31444. h2 & 0xFF,
  31445. h3 >> 24 & 0xFF,
  31446. h3 >> 16 & 0xFF,
  31447. h3 >> 8 & 0xFF,
  31448. h3 & 0xFF,
  31449. h4 >> 24 & 0xFF,
  31450. h4 >> 16 & 0xFF,
  31451. h4 >> 8 & 0xFF,
  31452. h4 & 0xFF,
  31453. h5 >> 24 & 0xFF,
  31454. h5 >> 16 & 0xFF,
  31455. h5 >> 8 & 0xFF,
  31456. h5 & 0xFF,
  31457. h6 >> 24 & 0xFF,
  31458. h6 >> 16 & 0xFF,
  31459. h6 >> 8 & 0xFF,
  31460. h6 & 0xFF,
  31461. h7 >> 24 & 0xFF,
  31462. h7 >> 16 & 0xFF,
  31463. h7 >> 8 & 0xFF,
  31464. h7 & 0xFF
  31465. ]);
  31466. }
  31467. return hash;
  31468. }();
  31469. var calculateSHA512 = function calculateSHA512Closure() {
  31470. function ch(result, x, y, z, tmp) {
  31471. result.assign(x);
  31472. result.and(y);
  31473. tmp.assign(x);
  31474. tmp.not();
  31475. tmp.and(z);
  31476. result.xor(tmp);
  31477. }
  31478. function maj(result, x, y, z, tmp) {
  31479. result.assign(x);
  31480. result.and(y);
  31481. tmp.assign(x);
  31482. tmp.and(z);
  31483. result.xor(tmp);
  31484. tmp.assign(y);
  31485. tmp.and(z);
  31486. result.xor(tmp);
  31487. }
  31488. function sigma(result, x, tmp) {
  31489. result.assign(x);
  31490. result.rotateRight(28);
  31491. tmp.assign(x);
  31492. tmp.rotateRight(34);
  31493. result.xor(tmp);
  31494. tmp.assign(x);
  31495. tmp.rotateRight(39);
  31496. result.xor(tmp);
  31497. }
  31498. function sigmaPrime(result, x, tmp) {
  31499. result.assign(x);
  31500. result.rotateRight(14);
  31501. tmp.assign(x);
  31502. tmp.rotateRight(18);
  31503. result.xor(tmp);
  31504. tmp.assign(x);
  31505. tmp.rotateRight(41);
  31506. result.xor(tmp);
  31507. }
  31508. function littleSigma(result, x, tmp) {
  31509. result.assign(x);
  31510. result.rotateRight(1);
  31511. tmp.assign(x);
  31512. tmp.rotateRight(8);
  31513. result.xor(tmp);
  31514. tmp.assign(x);
  31515. tmp.shiftRight(7);
  31516. result.xor(tmp);
  31517. }
  31518. function littleSigmaPrime(result, x, tmp) {
  31519. result.assign(x);
  31520. result.rotateRight(19);
  31521. tmp.assign(x);
  31522. tmp.rotateRight(61);
  31523. result.xor(tmp);
  31524. tmp.assign(x);
  31525. tmp.shiftRight(6);
  31526. result.xor(tmp);
  31527. }
  31528. var k = [
  31529. new Word64(0x428a2f98, 0xd728ae22),
  31530. new Word64(0x71374491, 0x23ef65cd),
  31531. new Word64(0xb5c0fbcf, 0xec4d3b2f),
  31532. new Word64(0xe9b5dba5, 0x8189dbbc),
  31533. new Word64(0x3956c25b, 0xf348b538),
  31534. new Word64(0x59f111f1, 0xb605d019),
  31535. new Word64(0x923f82a4, 0xaf194f9b),
  31536. new Word64(0xab1c5ed5, 0xda6d8118),
  31537. new Word64(0xd807aa98, 0xa3030242),
  31538. new Word64(0x12835b01, 0x45706fbe),
  31539. new Word64(0x243185be, 0x4ee4b28c),
  31540. new Word64(0x550c7dc3, 0xd5ffb4e2),
  31541. new Word64(0x72be5d74, 0xf27b896f),
  31542. new Word64(0x80deb1fe, 0x3b1696b1),
  31543. new Word64(0x9bdc06a7, 0x25c71235),
  31544. new Word64(0xc19bf174, 0xcf692694),
  31545. new Word64(0xe49b69c1, 0x9ef14ad2),
  31546. new Word64(0xefbe4786, 0x384f25e3),
  31547. new Word64(0x0fc19dc6, 0x8b8cd5b5),
  31548. new Word64(0x240ca1cc, 0x77ac9c65),
  31549. new Word64(0x2de92c6f, 0x592b0275),
  31550. new Word64(0x4a7484aa, 0x6ea6e483),
  31551. new Word64(0x5cb0a9dc, 0xbd41fbd4),
  31552. new Word64(0x76f988da, 0x831153b5),
  31553. new Word64(0x983e5152, 0xee66dfab),
  31554. new Word64(0xa831c66d, 0x2db43210),
  31555. new Word64(0xb00327c8, 0x98fb213f),
  31556. new Word64(0xbf597fc7, 0xbeef0ee4),
  31557. new Word64(0xc6e00bf3, 0x3da88fc2),
  31558. new Word64(0xd5a79147, 0x930aa725),
  31559. new Word64(0x06ca6351, 0xe003826f),
  31560. new Word64(0x14292967, 0x0a0e6e70),
  31561. new Word64(0x27b70a85, 0x46d22ffc),
  31562. new Word64(0x2e1b2138, 0x5c26c926),
  31563. new Word64(0x4d2c6dfc, 0x5ac42aed),
  31564. new Word64(0x53380d13, 0x9d95b3df),
  31565. new Word64(0x650a7354, 0x8baf63de),
  31566. new Word64(0x766a0abb, 0x3c77b2a8),
  31567. new Word64(0x81c2c92e, 0x47edaee6),
  31568. new Word64(0x92722c85, 0x1482353b),
  31569. new Word64(0xa2bfe8a1, 0x4cf10364),
  31570. new Word64(0xa81a664b, 0xbc423001),
  31571. new Word64(0xc24b8b70, 0xd0f89791),
  31572. new Word64(0xc76c51a3, 0x0654be30),
  31573. new Word64(0xd192e819, 0xd6ef5218),
  31574. new Word64(0xd6990624, 0x5565a910),
  31575. new Word64(0xf40e3585, 0x5771202a),
  31576. new Word64(0x106aa070, 0x32bbd1b8),
  31577. new Word64(0x19a4c116, 0xb8d2d0c8),
  31578. new Word64(0x1e376c08, 0x5141ab53),
  31579. new Word64(0x2748774c, 0xdf8eeb99),
  31580. new Word64(0x34b0bcb5, 0xe19b48a8),
  31581. new Word64(0x391c0cb3, 0xc5c95a63),
  31582. new Word64(0x4ed8aa4a, 0xe3418acb),
  31583. new Word64(0x5b9cca4f, 0x7763e373),
  31584. new Word64(0x682e6ff3, 0xd6b2b8a3),
  31585. new Word64(0x748f82ee, 0x5defb2fc),
  31586. new Word64(0x78a5636f, 0x43172f60),
  31587. new Word64(0x84c87814, 0xa1f0ab72),
  31588. new Word64(0x8cc70208, 0x1a6439ec),
  31589. new Word64(0x90befffa, 0x23631e28),
  31590. new Word64(0xa4506ceb, 0xde82bde9),
  31591. new Word64(0xbef9a3f7, 0xb2c67915),
  31592. new Word64(0xc67178f2, 0xe372532b),
  31593. new Word64(0xca273ece, 0xea26619c),
  31594. new Word64(0xd186b8c7, 0x21c0c207),
  31595. new Word64(0xeada7dd6, 0xcde0eb1e),
  31596. new Word64(0xf57d4f7f, 0xee6ed178),
  31597. new Word64(0x06f067aa, 0x72176fba),
  31598. new Word64(0x0a637dc5, 0xa2c898a6),
  31599. new Word64(0x113f9804, 0xbef90dae),
  31600. new Word64(0x1b710b35, 0x131c471b),
  31601. new Word64(0x28db77f5, 0x23047d84),
  31602. new Word64(0x32caab7b, 0x40c72493),
  31603. new Word64(0x3c9ebe0a, 0x15c9bebc),
  31604. new Word64(0x431d67c4, 0x9c100d4c),
  31605. new Word64(0x4cc5d4be, 0xcb3e42b6),
  31606. new Word64(0x597f299c, 0xfc657e2a),
  31607. new Word64(0x5fcb6fab, 0x3ad6faec),
  31608. new Word64(0x6c44198c, 0x4a475817)
  31609. ];
  31610. function hash(data, offset, length, mode384) {
  31611. mode384 = !!mode384;
  31612. // initial hash values
  31613. var h0, h1, h2, h3, h4, h5, h6, h7;
  31614. if (!mode384) {
  31615. h0 = new Word64(0x6a09e667, 0xf3bcc908);
  31616. h1 = new Word64(0xbb67ae85, 0x84caa73b);
  31617. h2 = new Word64(0x3c6ef372, 0xfe94f82b);
  31618. h3 = new Word64(0xa54ff53a, 0x5f1d36f1);
  31619. h4 = new Word64(0x510e527f, 0xade682d1);
  31620. h5 = new Word64(0x9b05688c, 0x2b3e6c1f);
  31621. h6 = new Word64(0x1f83d9ab, 0xfb41bd6b);
  31622. h7 = new Word64(0x5be0cd19, 0x137e2179);
  31623. } else {
  31624. // SHA384 is exactly the same
  31625. // except with different starting values and a trimmed result
  31626. h0 = new Word64(0xcbbb9d5d, 0xc1059ed8);
  31627. h1 = new Word64(0x629a292a, 0x367cd507);
  31628. h2 = new Word64(0x9159015a, 0x3070dd17);
  31629. h3 = new Word64(0x152fecd8, 0xf70e5939);
  31630. h4 = new Word64(0x67332667, 0xffc00b31);
  31631. h5 = new Word64(0x8eb44a87, 0x68581511);
  31632. h6 = new Word64(0xdb0c2e0d, 0x64f98fa7);
  31633. h7 = new Word64(0x47b5481d, 0xbefa4fa4);
  31634. }
  31635. // pre-processing
  31636. var paddedLength = Math.ceil((length + 17) / 128) * 128;
  31637. var padded = new Uint8Array(paddedLength);
  31638. var i, j, n;
  31639. for (i = 0; i < length; ++i) {
  31640. padded[i] = data[offset++];
  31641. }
  31642. padded[i++] = 0x80;
  31643. n = paddedLength - 16;
  31644. while (i < n) {
  31645. padded[i++] = 0;
  31646. }
  31647. padded[i++] = 0;
  31648. padded[i++] = 0;
  31649. padded[i++] = 0;
  31650. padded[i++] = 0;
  31651. padded[i++] = 0;
  31652. padded[i++] = 0;
  31653. padded[i++] = 0;
  31654. padded[i++] = 0;
  31655. padded[i++] = 0;
  31656. padded[i++] = 0;
  31657. padded[i++] = 0;
  31658. padded[i++] = length >>> 29 & 0xFF;
  31659. padded[i++] = length >> 21 & 0xFF;
  31660. padded[i++] = length >> 13 & 0xFF;
  31661. padded[i++] = length >> 5 & 0xFF;
  31662. padded[i++] = length << 3 & 0xFF;
  31663. var w = new Array(80);
  31664. for (i = 0; i < 80; i++) {
  31665. w[i] = new Word64(0, 0);
  31666. }
  31667. var a = new Word64(0, 0), b = new Word64(0, 0), c = new Word64(0, 0);
  31668. var d = new Word64(0, 0), e = new Word64(0, 0), f = new Word64(0, 0);
  31669. var g = new Word64(0, 0), h = new Word64(0, 0);
  31670. var t1 = new Word64(0, 0), t2 = new Word64(0, 0);
  31671. var tmp1 = new Word64(0, 0), tmp2 = new Word64(0, 0), tmp3;
  31672. // for each 1024 bit block
  31673. for (i = 0; i < paddedLength;) {
  31674. for (j = 0; j < 16; ++j) {
  31675. w[j].high = padded[i] << 24 | padded[i + 1] << 16 | padded[i + 2] << 8 | padded[i + 3];
  31676. w[j].low = padded[i + 4] << 24 | padded[i + 5] << 16 | padded[i + 6] << 8 | padded[i + 7];
  31677. i += 8;
  31678. }
  31679. for (j = 16; j < 80; ++j) {
  31680. tmp3 = w[j];
  31681. littleSigmaPrime(tmp3, w[j - 2], tmp2);
  31682. tmp3.add(w[j - 7]);
  31683. littleSigma(tmp1, w[j - 15], tmp2);
  31684. tmp3.add(tmp1);
  31685. tmp3.add(w[j - 16]);
  31686. }
  31687. a.assign(h0);
  31688. b.assign(h1);
  31689. c.assign(h2);
  31690. d.assign(h3);
  31691. e.assign(h4);
  31692. f.assign(h5);
  31693. g.assign(h6);
  31694. h.assign(h7);
  31695. for (j = 0; j < 80; ++j) {
  31696. t1.assign(h);
  31697. sigmaPrime(tmp1, e, tmp2);
  31698. t1.add(tmp1);
  31699. ch(tmp1, e, f, g, tmp2);
  31700. t1.add(tmp1);
  31701. t1.add(k[j]);
  31702. t1.add(w[j]);
  31703. sigma(t2, a, tmp2);
  31704. maj(tmp1, a, b, c, tmp2);
  31705. t2.add(tmp1);
  31706. tmp3 = h;
  31707. h = g;
  31708. g = f;
  31709. f = e;
  31710. d.add(t1);
  31711. e = d;
  31712. d = c;
  31713. c = b;
  31714. b = a;
  31715. tmp3.assign(t1);
  31716. tmp3.add(t2);
  31717. a = tmp3;
  31718. }
  31719. h0.add(a);
  31720. h1.add(b);
  31721. h2.add(c);
  31722. h3.add(d);
  31723. h4.add(e);
  31724. h5.add(f);
  31725. h6.add(g);
  31726. h7.add(h);
  31727. }
  31728. var result;
  31729. if (!mode384) {
  31730. result = new Uint8Array(64);
  31731. h0.copyTo(result, 0);
  31732. h1.copyTo(result, 8);
  31733. h2.copyTo(result, 16);
  31734. h3.copyTo(result, 24);
  31735. h4.copyTo(result, 32);
  31736. h5.copyTo(result, 40);
  31737. h6.copyTo(result, 48);
  31738. h7.copyTo(result, 56);
  31739. } else {
  31740. result = new Uint8Array(48);
  31741. h0.copyTo(result, 0);
  31742. h1.copyTo(result, 8);
  31743. h2.copyTo(result, 16);
  31744. h3.copyTo(result, 24);
  31745. h4.copyTo(result, 32);
  31746. h5.copyTo(result, 40);
  31747. }
  31748. return result;
  31749. }
  31750. return hash;
  31751. }();
  31752. var calculateSHA384 = function calculateSHA384Closure() {
  31753. function hash(data, offset, length) {
  31754. return calculateSHA512(data, offset, length, true);
  31755. }
  31756. return hash;
  31757. }();
  31758. var NullCipher = function NullCipherClosure() {
  31759. function NullCipher() {
  31760. }
  31761. NullCipher.prototype = {
  31762. decryptBlock: function NullCipher_decryptBlock(data) {
  31763. return data;
  31764. }
  31765. };
  31766. return NullCipher;
  31767. }();
  31768. var AES128Cipher = function AES128CipherClosure() {
  31769. var rcon = new Uint8Array([
  31770. 0x8d,
  31771. 0x01,
  31772. 0x02,
  31773. 0x04,
  31774. 0x08,
  31775. 0x10,
  31776. 0x20,
  31777. 0x40,
  31778. 0x80,
  31779. 0x1b,
  31780. 0x36,
  31781. 0x6c,
  31782. 0xd8,
  31783. 0xab,
  31784. 0x4d,
  31785. 0x9a,
  31786. 0x2f,
  31787. 0x5e,
  31788. 0xbc,
  31789. 0x63,
  31790. 0xc6,
  31791. 0x97,
  31792. 0x35,
  31793. 0x6a,
  31794. 0xd4,
  31795. 0xb3,
  31796. 0x7d,
  31797. 0xfa,
  31798. 0xef,
  31799. 0xc5,
  31800. 0x91,
  31801. 0x39,
  31802. 0x72,
  31803. 0xe4,
  31804. 0xd3,
  31805. 0xbd,
  31806. 0x61,
  31807. 0xc2,
  31808. 0x9f,
  31809. 0x25,
  31810. 0x4a,
  31811. 0x94,
  31812. 0x33,
  31813. 0x66,
  31814. 0xcc,
  31815. 0x83,
  31816. 0x1d,
  31817. 0x3a,
  31818. 0x74,
  31819. 0xe8,
  31820. 0xcb,
  31821. 0x8d,
  31822. 0x01,
  31823. 0x02,
  31824. 0x04,
  31825. 0x08,
  31826. 0x10,
  31827. 0x20,
  31828. 0x40,
  31829. 0x80,
  31830. 0x1b,
  31831. 0x36,
  31832. 0x6c,
  31833. 0xd8,
  31834. 0xab,
  31835. 0x4d,
  31836. 0x9a,
  31837. 0x2f,
  31838. 0x5e,
  31839. 0xbc,
  31840. 0x63,
  31841. 0xc6,
  31842. 0x97,
  31843. 0x35,
  31844. 0x6a,
  31845. 0xd4,
  31846. 0xb3,
  31847. 0x7d,
  31848. 0xfa,
  31849. 0xef,
  31850. 0xc5,
  31851. 0x91,
  31852. 0x39,
  31853. 0x72,
  31854. 0xe4,
  31855. 0xd3,
  31856. 0xbd,
  31857. 0x61,
  31858. 0xc2,
  31859. 0x9f,
  31860. 0x25,
  31861. 0x4a,
  31862. 0x94,
  31863. 0x33,
  31864. 0x66,
  31865. 0xcc,
  31866. 0x83,
  31867. 0x1d,
  31868. 0x3a,
  31869. 0x74,
  31870. 0xe8,
  31871. 0xcb,
  31872. 0x8d,
  31873. 0x01,
  31874. 0x02,
  31875. 0x04,
  31876. 0x08,
  31877. 0x10,
  31878. 0x20,
  31879. 0x40,
  31880. 0x80,
  31881. 0x1b,
  31882. 0x36,
  31883. 0x6c,
  31884. 0xd8,
  31885. 0xab,
  31886. 0x4d,
  31887. 0x9a,
  31888. 0x2f,
  31889. 0x5e,
  31890. 0xbc,
  31891. 0x63,
  31892. 0xc6,
  31893. 0x97,
  31894. 0x35,
  31895. 0x6a,
  31896. 0xd4,
  31897. 0xb3,
  31898. 0x7d,
  31899. 0xfa,
  31900. 0xef,
  31901. 0xc5,
  31902. 0x91,
  31903. 0x39,
  31904. 0x72,
  31905. 0xe4,
  31906. 0xd3,
  31907. 0xbd,
  31908. 0x61,
  31909. 0xc2,
  31910. 0x9f,
  31911. 0x25,
  31912. 0x4a,
  31913. 0x94,
  31914. 0x33,
  31915. 0x66,
  31916. 0xcc,
  31917. 0x83,
  31918. 0x1d,
  31919. 0x3a,
  31920. 0x74,
  31921. 0xe8,
  31922. 0xcb,
  31923. 0x8d,
  31924. 0x01,
  31925. 0x02,
  31926. 0x04,
  31927. 0x08,
  31928. 0x10,
  31929. 0x20,
  31930. 0x40,
  31931. 0x80,
  31932. 0x1b,
  31933. 0x36,
  31934. 0x6c,
  31935. 0xd8,
  31936. 0xab,
  31937. 0x4d,
  31938. 0x9a,
  31939. 0x2f,
  31940. 0x5e,
  31941. 0xbc,
  31942. 0x63,
  31943. 0xc6,
  31944. 0x97,
  31945. 0x35,
  31946. 0x6a,
  31947. 0xd4,
  31948. 0xb3,
  31949. 0x7d,
  31950. 0xfa,
  31951. 0xef,
  31952. 0xc5,
  31953. 0x91,
  31954. 0x39,
  31955. 0x72,
  31956. 0xe4,
  31957. 0xd3,
  31958. 0xbd,
  31959. 0x61,
  31960. 0xc2,
  31961. 0x9f,
  31962. 0x25,
  31963. 0x4a,
  31964. 0x94,
  31965. 0x33,
  31966. 0x66,
  31967. 0xcc,
  31968. 0x83,
  31969. 0x1d,
  31970. 0x3a,
  31971. 0x74,
  31972. 0xe8,
  31973. 0xcb,
  31974. 0x8d,
  31975. 0x01,
  31976. 0x02,
  31977. 0x04,
  31978. 0x08,
  31979. 0x10,
  31980. 0x20,
  31981. 0x40,
  31982. 0x80,
  31983. 0x1b,
  31984. 0x36,
  31985. 0x6c,
  31986. 0xd8,
  31987. 0xab,
  31988. 0x4d,
  31989. 0x9a,
  31990. 0x2f,
  31991. 0x5e,
  31992. 0xbc,
  31993. 0x63,
  31994. 0xc6,
  31995. 0x97,
  31996. 0x35,
  31997. 0x6a,
  31998. 0xd4,
  31999. 0xb3,
  32000. 0x7d,
  32001. 0xfa,
  32002. 0xef,
  32003. 0xc5,
  32004. 0x91,
  32005. 0x39,
  32006. 0x72,
  32007. 0xe4,
  32008. 0xd3,
  32009. 0xbd,
  32010. 0x61,
  32011. 0xc2,
  32012. 0x9f,
  32013. 0x25,
  32014. 0x4a,
  32015. 0x94,
  32016. 0x33,
  32017. 0x66,
  32018. 0xcc,
  32019. 0x83,
  32020. 0x1d,
  32021. 0x3a,
  32022. 0x74,
  32023. 0xe8,
  32024. 0xcb,
  32025. 0x8d
  32026. ]);
  32027. var s = new Uint8Array([
  32028. 0x63,
  32029. 0x7c,
  32030. 0x77,
  32031. 0x7b,
  32032. 0xf2,
  32033. 0x6b,
  32034. 0x6f,
  32035. 0xc5,
  32036. 0x30,
  32037. 0x01,
  32038. 0x67,
  32039. 0x2b,
  32040. 0xfe,
  32041. 0xd7,
  32042. 0xab,
  32043. 0x76,
  32044. 0xca,
  32045. 0x82,
  32046. 0xc9,
  32047. 0x7d,
  32048. 0xfa,
  32049. 0x59,
  32050. 0x47,
  32051. 0xf0,
  32052. 0xad,
  32053. 0xd4,
  32054. 0xa2,
  32055. 0xaf,
  32056. 0x9c,
  32057. 0xa4,
  32058. 0x72,
  32059. 0xc0,
  32060. 0xb7,
  32061. 0xfd,
  32062. 0x93,
  32063. 0x26,
  32064. 0x36,
  32065. 0x3f,
  32066. 0xf7,
  32067. 0xcc,
  32068. 0x34,
  32069. 0xa5,
  32070. 0xe5,
  32071. 0xf1,
  32072. 0x71,
  32073. 0xd8,
  32074. 0x31,
  32075. 0x15,
  32076. 0x04,
  32077. 0xc7,
  32078. 0x23,
  32079. 0xc3,
  32080. 0x18,
  32081. 0x96,
  32082. 0x05,
  32083. 0x9a,
  32084. 0x07,
  32085. 0x12,
  32086. 0x80,
  32087. 0xe2,
  32088. 0xeb,
  32089. 0x27,
  32090. 0xb2,
  32091. 0x75,
  32092. 0x09,
  32093. 0x83,
  32094. 0x2c,
  32095. 0x1a,
  32096. 0x1b,
  32097. 0x6e,
  32098. 0x5a,
  32099. 0xa0,
  32100. 0x52,
  32101. 0x3b,
  32102. 0xd6,
  32103. 0xb3,
  32104. 0x29,
  32105. 0xe3,
  32106. 0x2f,
  32107. 0x84,
  32108. 0x53,
  32109. 0xd1,
  32110. 0x00,
  32111. 0xed,
  32112. 0x20,
  32113. 0xfc,
  32114. 0xb1,
  32115. 0x5b,
  32116. 0x6a,
  32117. 0xcb,
  32118. 0xbe,
  32119. 0x39,
  32120. 0x4a,
  32121. 0x4c,
  32122. 0x58,
  32123. 0xcf,
  32124. 0xd0,
  32125. 0xef,
  32126. 0xaa,
  32127. 0xfb,
  32128. 0x43,
  32129. 0x4d,
  32130. 0x33,
  32131. 0x85,
  32132. 0x45,
  32133. 0xf9,
  32134. 0x02,
  32135. 0x7f,
  32136. 0x50,
  32137. 0x3c,
  32138. 0x9f,
  32139. 0xa8,
  32140. 0x51,
  32141. 0xa3,
  32142. 0x40,
  32143. 0x8f,
  32144. 0x92,
  32145. 0x9d,
  32146. 0x38,
  32147. 0xf5,
  32148. 0xbc,
  32149. 0xb6,
  32150. 0xda,
  32151. 0x21,
  32152. 0x10,
  32153. 0xff,
  32154. 0xf3,
  32155. 0xd2,
  32156. 0xcd,
  32157. 0x0c,
  32158. 0x13,
  32159. 0xec,
  32160. 0x5f,
  32161. 0x97,
  32162. 0x44,
  32163. 0x17,
  32164. 0xc4,
  32165. 0xa7,
  32166. 0x7e,
  32167. 0x3d,
  32168. 0x64,
  32169. 0x5d,
  32170. 0x19,
  32171. 0x73,
  32172. 0x60,
  32173. 0x81,
  32174. 0x4f,
  32175. 0xdc,
  32176. 0x22,
  32177. 0x2a,
  32178. 0x90,
  32179. 0x88,
  32180. 0x46,
  32181. 0xee,
  32182. 0xb8,
  32183. 0x14,
  32184. 0xde,
  32185. 0x5e,
  32186. 0x0b,
  32187. 0xdb,
  32188. 0xe0,
  32189. 0x32,
  32190. 0x3a,
  32191. 0x0a,
  32192. 0x49,
  32193. 0x06,
  32194. 0x24,
  32195. 0x5c,
  32196. 0xc2,
  32197. 0xd3,
  32198. 0xac,
  32199. 0x62,
  32200. 0x91,
  32201. 0x95,
  32202. 0xe4,
  32203. 0x79,
  32204. 0xe7,
  32205. 0xc8,
  32206. 0x37,
  32207. 0x6d,
  32208. 0x8d,
  32209. 0xd5,
  32210. 0x4e,
  32211. 0xa9,
  32212. 0x6c,
  32213. 0x56,
  32214. 0xf4,
  32215. 0xea,
  32216. 0x65,
  32217. 0x7a,
  32218. 0xae,
  32219. 0x08,
  32220. 0xba,
  32221. 0x78,
  32222. 0x25,
  32223. 0x2e,
  32224. 0x1c,
  32225. 0xa6,
  32226. 0xb4,
  32227. 0xc6,
  32228. 0xe8,
  32229. 0xdd,
  32230. 0x74,
  32231. 0x1f,
  32232. 0x4b,
  32233. 0xbd,
  32234. 0x8b,
  32235. 0x8a,
  32236. 0x70,
  32237. 0x3e,
  32238. 0xb5,
  32239. 0x66,
  32240. 0x48,
  32241. 0x03,
  32242. 0xf6,
  32243. 0x0e,
  32244. 0x61,
  32245. 0x35,
  32246. 0x57,
  32247. 0xb9,
  32248. 0x86,
  32249. 0xc1,
  32250. 0x1d,
  32251. 0x9e,
  32252. 0xe1,
  32253. 0xf8,
  32254. 0x98,
  32255. 0x11,
  32256. 0x69,
  32257. 0xd9,
  32258. 0x8e,
  32259. 0x94,
  32260. 0x9b,
  32261. 0x1e,
  32262. 0x87,
  32263. 0xe9,
  32264. 0xce,
  32265. 0x55,
  32266. 0x28,
  32267. 0xdf,
  32268. 0x8c,
  32269. 0xa1,
  32270. 0x89,
  32271. 0x0d,
  32272. 0xbf,
  32273. 0xe6,
  32274. 0x42,
  32275. 0x68,
  32276. 0x41,
  32277. 0x99,
  32278. 0x2d,
  32279. 0x0f,
  32280. 0xb0,
  32281. 0x54,
  32282. 0xbb,
  32283. 0x16
  32284. ]);
  32285. var inv_s = new Uint8Array([
  32286. 0x52,
  32287. 0x09,
  32288. 0x6a,
  32289. 0xd5,
  32290. 0x30,
  32291. 0x36,
  32292. 0xa5,
  32293. 0x38,
  32294. 0xbf,
  32295. 0x40,
  32296. 0xa3,
  32297. 0x9e,
  32298. 0x81,
  32299. 0xf3,
  32300. 0xd7,
  32301. 0xfb,
  32302. 0x7c,
  32303. 0xe3,
  32304. 0x39,
  32305. 0x82,
  32306. 0x9b,
  32307. 0x2f,
  32308. 0xff,
  32309. 0x87,
  32310. 0x34,
  32311. 0x8e,
  32312. 0x43,
  32313. 0x44,
  32314. 0xc4,
  32315. 0xde,
  32316. 0xe9,
  32317. 0xcb,
  32318. 0x54,
  32319. 0x7b,
  32320. 0x94,
  32321. 0x32,
  32322. 0xa6,
  32323. 0xc2,
  32324. 0x23,
  32325. 0x3d,
  32326. 0xee,
  32327. 0x4c,
  32328. 0x95,
  32329. 0x0b,
  32330. 0x42,
  32331. 0xfa,
  32332. 0xc3,
  32333. 0x4e,
  32334. 0x08,
  32335. 0x2e,
  32336. 0xa1,
  32337. 0x66,
  32338. 0x28,
  32339. 0xd9,
  32340. 0x24,
  32341. 0xb2,
  32342. 0x76,
  32343. 0x5b,
  32344. 0xa2,
  32345. 0x49,
  32346. 0x6d,
  32347. 0x8b,
  32348. 0xd1,
  32349. 0x25,
  32350. 0x72,
  32351. 0xf8,
  32352. 0xf6,
  32353. 0x64,
  32354. 0x86,
  32355. 0x68,
  32356. 0x98,
  32357. 0x16,
  32358. 0xd4,
  32359. 0xa4,
  32360. 0x5c,
  32361. 0xcc,
  32362. 0x5d,
  32363. 0x65,
  32364. 0xb6,
  32365. 0x92,
  32366. 0x6c,
  32367. 0x70,
  32368. 0x48,
  32369. 0x50,
  32370. 0xfd,
  32371. 0xed,
  32372. 0xb9,
  32373. 0xda,
  32374. 0x5e,
  32375. 0x15,
  32376. 0x46,
  32377. 0x57,
  32378. 0xa7,
  32379. 0x8d,
  32380. 0x9d,
  32381. 0x84,
  32382. 0x90,
  32383. 0xd8,
  32384. 0xab,
  32385. 0x00,
  32386. 0x8c,
  32387. 0xbc,
  32388. 0xd3,
  32389. 0x0a,
  32390. 0xf7,
  32391. 0xe4,
  32392. 0x58,
  32393. 0x05,
  32394. 0xb8,
  32395. 0xb3,
  32396. 0x45,
  32397. 0x06,
  32398. 0xd0,
  32399. 0x2c,
  32400. 0x1e,
  32401. 0x8f,
  32402. 0xca,
  32403. 0x3f,
  32404. 0x0f,
  32405. 0x02,
  32406. 0xc1,
  32407. 0xaf,
  32408. 0xbd,
  32409. 0x03,
  32410. 0x01,
  32411. 0x13,
  32412. 0x8a,
  32413. 0x6b,
  32414. 0x3a,
  32415. 0x91,
  32416. 0x11,
  32417. 0x41,
  32418. 0x4f,
  32419. 0x67,
  32420. 0xdc,
  32421. 0xea,
  32422. 0x97,
  32423. 0xf2,
  32424. 0xcf,
  32425. 0xce,
  32426. 0xf0,
  32427. 0xb4,
  32428. 0xe6,
  32429. 0x73,
  32430. 0x96,
  32431. 0xac,
  32432. 0x74,
  32433. 0x22,
  32434. 0xe7,
  32435. 0xad,
  32436. 0x35,
  32437. 0x85,
  32438. 0xe2,
  32439. 0xf9,
  32440. 0x37,
  32441. 0xe8,
  32442. 0x1c,
  32443. 0x75,
  32444. 0xdf,
  32445. 0x6e,
  32446. 0x47,
  32447. 0xf1,
  32448. 0x1a,
  32449. 0x71,
  32450. 0x1d,
  32451. 0x29,
  32452. 0xc5,
  32453. 0x89,
  32454. 0x6f,
  32455. 0xb7,
  32456. 0x62,
  32457. 0x0e,
  32458. 0xaa,
  32459. 0x18,
  32460. 0xbe,
  32461. 0x1b,
  32462. 0xfc,
  32463. 0x56,
  32464. 0x3e,
  32465. 0x4b,
  32466. 0xc6,
  32467. 0xd2,
  32468. 0x79,
  32469. 0x20,
  32470. 0x9a,
  32471. 0xdb,
  32472. 0xc0,
  32473. 0xfe,
  32474. 0x78,
  32475. 0xcd,
  32476. 0x5a,
  32477. 0xf4,
  32478. 0x1f,
  32479. 0xdd,
  32480. 0xa8,
  32481. 0x33,
  32482. 0x88,
  32483. 0x07,
  32484. 0xc7,
  32485. 0x31,
  32486. 0xb1,
  32487. 0x12,
  32488. 0x10,
  32489. 0x59,
  32490. 0x27,
  32491. 0x80,
  32492. 0xec,
  32493. 0x5f,
  32494. 0x60,
  32495. 0x51,
  32496. 0x7f,
  32497. 0xa9,
  32498. 0x19,
  32499. 0xb5,
  32500. 0x4a,
  32501. 0x0d,
  32502. 0x2d,
  32503. 0xe5,
  32504. 0x7a,
  32505. 0x9f,
  32506. 0x93,
  32507. 0xc9,
  32508. 0x9c,
  32509. 0xef,
  32510. 0xa0,
  32511. 0xe0,
  32512. 0x3b,
  32513. 0x4d,
  32514. 0xae,
  32515. 0x2a,
  32516. 0xf5,
  32517. 0xb0,
  32518. 0xc8,
  32519. 0xeb,
  32520. 0xbb,
  32521. 0x3c,
  32522. 0x83,
  32523. 0x53,
  32524. 0x99,
  32525. 0x61,
  32526. 0x17,
  32527. 0x2b,
  32528. 0x04,
  32529. 0x7e,
  32530. 0xba,
  32531. 0x77,
  32532. 0xd6,
  32533. 0x26,
  32534. 0xe1,
  32535. 0x69,
  32536. 0x14,
  32537. 0x63,
  32538. 0x55,
  32539. 0x21,
  32540. 0x0c,
  32541. 0x7d
  32542. ]);
  32543. var mixCol = new Uint8Array(256);
  32544. for (var i = 0; i < 256; i++) {
  32545. if (i < 128) {
  32546. mixCol[i] = i << 1;
  32547. } else {
  32548. mixCol[i] = i << 1 ^ 0x1b;
  32549. }
  32550. }
  32551. var mix = new Uint32Array([
  32552. 0x00000000,
  32553. 0x0e090d0b,
  32554. 0x1c121a16,
  32555. 0x121b171d,
  32556. 0x3824342c,
  32557. 0x362d3927,
  32558. 0x24362e3a,
  32559. 0x2a3f2331,
  32560. 0x70486858,
  32561. 0x7e416553,
  32562. 0x6c5a724e,
  32563. 0x62537f45,
  32564. 0x486c5c74,
  32565. 0x4665517f,
  32566. 0x547e4662,
  32567. 0x5a774b69,
  32568. 0xe090d0b0,
  32569. 0xee99ddbb,
  32570. 0xfc82caa6,
  32571. 0xf28bc7ad,
  32572. 0xd8b4e49c,
  32573. 0xd6bde997,
  32574. 0xc4a6fe8a,
  32575. 0xcaaff381,
  32576. 0x90d8b8e8,
  32577. 0x9ed1b5e3,
  32578. 0x8ccaa2fe,
  32579. 0x82c3aff5,
  32580. 0xa8fc8cc4,
  32581. 0xa6f581cf,
  32582. 0xb4ee96d2,
  32583. 0xbae79bd9,
  32584. 0xdb3bbb7b,
  32585. 0xd532b670,
  32586. 0xc729a16d,
  32587. 0xc920ac66,
  32588. 0xe31f8f57,
  32589. 0xed16825c,
  32590. 0xff0d9541,
  32591. 0xf104984a,
  32592. 0xab73d323,
  32593. 0xa57ade28,
  32594. 0xb761c935,
  32595. 0xb968c43e,
  32596. 0x9357e70f,
  32597. 0x9d5eea04,
  32598. 0x8f45fd19,
  32599. 0x814cf012,
  32600. 0x3bab6bcb,
  32601. 0x35a266c0,
  32602. 0x27b971dd,
  32603. 0x29b07cd6,
  32604. 0x038f5fe7,
  32605. 0x0d8652ec,
  32606. 0x1f9d45f1,
  32607. 0x119448fa,
  32608. 0x4be30393,
  32609. 0x45ea0e98,
  32610. 0x57f11985,
  32611. 0x59f8148e,
  32612. 0x73c737bf,
  32613. 0x7dce3ab4,
  32614. 0x6fd52da9,
  32615. 0x61dc20a2,
  32616. 0xad766df6,
  32617. 0xa37f60fd,
  32618. 0xb16477e0,
  32619. 0xbf6d7aeb,
  32620. 0x955259da,
  32621. 0x9b5b54d1,
  32622. 0x894043cc,
  32623. 0x87494ec7,
  32624. 0xdd3e05ae,
  32625. 0xd33708a5,
  32626. 0xc12c1fb8,
  32627. 0xcf2512b3,
  32628. 0xe51a3182,
  32629. 0xeb133c89,
  32630. 0xf9082b94,
  32631. 0xf701269f,
  32632. 0x4de6bd46,
  32633. 0x43efb04d,
  32634. 0x51f4a750,
  32635. 0x5ffdaa5b,
  32636. 0x75c2896a,
  32637. 0x7bcb8461,
  32638. 0x69d0937c,
  32639. 0x67d99e77,
  32640. 0x3daed51e,
  32641. 0x33a7d815,
  32642. 0x21bccf08,
  32643. 0x2fb5c203,
  32644. 0x058ae132,
  32645. 0x0b83ec39,
  32646. 0x1998fb24,
  32647. 0x1791f62f,
  32648. 0x764dd68d,
  32649. 0x7844db86,
  32650. 0x6a5fcc9b,
  32651. 0x6456c190,
  32652. 0x4e69e2a1,
  32653. 0x4060efaa,
  32654. 0x527bf8b7,
  32655. 0x5c72f5bc,
  32656. 0x0605bed5,
  32657. 0x080cb3de,
  32658. 0x1a17a4c3,
  32659. 0x141ea9c8,
  32660. 0x3e218af9,
  32661. 0x302887f2,
  32662. 0x223390ef,
  32663. 0x2c3a9de4,
  32664. 0x96dd063d,
  32665. 0x98d40b36,
  32666. 0x8acf1c2b,
  32667. 0x84c61120,
  32668. 0xaef93211,
  32669. 0xa0f03f1a,
  32670. 0xb2eb2807,
  32671. 0xbce2250c,
  32672. 0xe6956e65,
  32673. 0xe89c636e,
  32674. 0xfa877473,
  32675. 0xf48e7978,
  32676. 0xdeb15a49,
  32677. 0xd0b85742,
  32678. 0xc2a3405f,
  32679. 0xccaa4d54,
  32680. 0x41ecdaf7,
  32681. 0x4fe5d7fc,
  32682. 0x5dfec0e1,
  32683. 0x53f7cdea,
  32684. 0x79c8eedb,
  32685. 0x77c1e3d0,
  32686. 0x65daf4cd,
  32687. 0x6bd3f9c6,
  32688. 0x31a4b2af,
  32689. 0x3fadbfa4,
  32690. 0x2db6a8b9,
  32691. 0x23bfa5b2,
  32692. 0x09808683,
  32693. 0x07898b88,
  32694. 0x15929c95,
  32695. 0x1b9b919e,
  32696. 0xa17c0a47,
  32697. 0xaf75074c,
  32698. 0xbd6e1051,
  32699. 0xb3671d5a,
  32700. 0x99583e6b,
  32701. 0x97513360,
  32702. 0x854a247d,
  32703. 0x8b432976,
  32704. 0xd134621f,
  32705. 0xdf3d6f14,
  32706. 0xcd267809,
  32707. 0xc32f7502,
  32708. 0xe9105633,
  32709. 0xe7195b38,
  32710. 0xf5024c25,
  32711. 0xfb0b412e,
  32712. 0x9ad7618c,
  32713. 0x94de6c87,
  32714. 0x86c57b9a,
  32715. 0x88cc7691,
  32716. 0xa2f355a0,
  32717. 0xacfa58ab,
  32718. 0xbee14fb6,
  32719. 0xb0e842bd,
  32720. 0xea9f09d4,
  32721. 0xe49604df,
  32722. 0xf68d13c2,
  32723. 0xf8841ec9,
  32724. 0xd2bb3df8,
  32725. 0xdcb230f3,
  32726. 0xcea927ee,
  32727. 0xc0a02ae5,
  32728. 0x7a47b13c,
  32729. 0x744ebc37,
  32730. 0x6655ab2a,
  32731. 0x685ca621,
  32732. 0x42638510,
  32733. 0x4c6a881b,
  32734. 0x5e719f06,
  32735. 0x5078920d,
  32736. 0x0a0fd964,
  32737. 0x0406d46f,
  32738. 0x161dc372,
  32739. 0x1814ce79,
  32740. 0x322bed48,
  32741. 0x3c22e043,
  32742. 0x2e39f75e,
  32743. 0x2030fa55,
  32744. 0xec9ab701,
  32745. 0xe293ba0a,
  32746. 0xf088ad17,
  32747. 0xfe81a01c,
  32748. 0xd4be832d,
  32749. 0xdab78e26,
  32750. 0xc8ac993b,
  32751. 0xc6a59430,
  32752. 0x9cd2df59,
  32753. 0x92dbd252,
  32754. 0x80c0c54f,
  32755. 0x8ec9c844,
  32756. 0xa4f6eb75,
  32757. 0xaaffe67e,
  32758. 0xb8e4f163,
  32759. 0xb6edfc68,
  32760. 0x0c0a67b1,
  32761. 0x02036aba,
  32762. 0x10187da7,
  32763. 0x1e1170ac,
  32764. 0x342e539d,
  32765. 0x3a275e96,
  32766. 0x283c498b,
  32767. 0x26354480,
  32768. 0x7c420fe9,
  32769. 0x724b02e2,
  32770. 0x605015ff,
  32771. 0x6e5918f4,
  32772. 0x44663bc5,
  32773. 0x4a6f36ce,
  32774. 0x587421d3,
  32775. 0x567d2cd8,
  32776. 0x37a10c7a,
  32777. 0x39a80171,
  32778. 0x2bb3166c,
  32779. 0x25ba1b67,
  32780. 0x0f853856,
  32781. 0x018c355d,
  32782. 0x13972240,
  32783. 0x1d9e2f4b,
  32784. 0x47e96422,
  32785. 0x49e06929,
  32786. 0x5bfb7e34,
  32787. 0x55f2733f,
  32788. 0x7fcd500e,
  32789. 0x71c45d05,
  32790. 0x63df4a18,
  32791. 0x6dd64713,
  32792. 0xd731dcca,
  32793. 0xd938d1c1,
  32794. 0xcb23c6dc,
  32795. 0xc52acbd7,
  32796. 0xef15e8e6,
  32797. 0xe11ce5ed,
  32798. 0xf307f2f0,
  32799. 0xfd0efffb,
  32800. 0xa779b492,
  32801. 0xa970b999,
  32802. 0xbb6bae84,
  32803. 0xb562a38f,
  32804. 0x9f5d80be,
  32805. 0x91548db5,
  32806. 0x834f9aa8,
  32807. 0x8d4697a3
  32808. ]);
  32809. function expandKey128(cipherKey) {
  32810. var b = 176, result = new Uint8Array(b);
  32811. result.set(cipherKey);
  32812. for (var j = 16, i = 1; j < b; ++i) {
  32813. // RotWord
  32814. var t1 = result[j - 3], t2 = result[j - 2], t3 = result[j - 1], t4 = result[j - 4];
  32815. // SubWord
  32816. t1 = s[t1];
  32817. t2 = s[t2];
  32818. t3 = s[t3];
  32819. t4 = s[t4];
  32820. // Rcon
  32821. t1 = t1 ^ rcon[i];
  32822. for (var n = 0; n < 4; ++n) {
  32823. result[j] = t1 ^= result[j - 16];
  32824. j++;
  32825. result[j] = t2 ^= result[j - 16];
  32826. j++;
  32827. result[j] = t3 ^= result[j - 16];
  32828. j++;
  32829. result[j] = t4 ^= result[j - 16];
  32830. j++;
  32831. }
  32832. }
  32833. return result;
  32834. }
  32835. function decrypt128(input, key) {
  32836. var state = new Uint8Array(16);
  32837. state.set(input);
  32838. var i, j, k;
  32839. var t, u, v;
  32840. // AddRoundKey
  32841. for (j = 0, k = 160; j < 16; ++j, ++k) {
  32842. state[j] ^= key[k];
  32843. }
  32844. for (i = 9; i >= 1; --i) {
  32845. // InvShiftRows
  32846. t = state[13];
  32847. state[13] = state[9];
  32848. state[9] = state[5];
  32849. state[5] = state[1];
  32850. state[1] = t;
  32851. t = state[14];
  32852. u = state[10];
  32853. state[14] = state[6];
  32854. state[10] = state[2];
  32855. state[6] = t;
  32856. state[2] = u;
  32857. t = state[15];
  32858. u = state[11];
  32859. v = state[7];
  32860. state[15] = state[3];
  32861. state[11] = t;
  32862. state[7] = u;
  32863. state[3] = v;
  32864. // InvSubBytes
  32865. for (j = 0; j < 16; ++j) {
  32866. state[j] = inv_s[state[j]];
  32867. }
  32868. // AddRoundKey
  32869. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  32870. state[j] ^= key[k];
  32871. }
  32872. // InvMixColumns
  32873. for (j = 0; j < 16; j += 4) {
  32874. var s0 = mix[state[j]], s1 = mix[state[j + 1]], s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  32875. t = s0 ^ s1 >>> 8 ^ s1 << 24 ^ s2 >>> 16 ^ s2 << 16 ^ s3 >>> 24 ^ s3 << 8;
  32876. state[j] = t >>> 24 & 0xFF;
  32877. state[j + 1] = t >> 16 & 0xFF;
  32878. state[j + 2] = t >> 8 & 0xFF;
  32879. state[j + 3] = t & 0xFF;
  32880. }
  32881. }
  32882. // InvShiftRows
  32883. t = state[13];
  32884. state[13] = state[9];
  32885. state[9] = state[5];
  32886. state[5] = state[1];
  32887. state[1] = t;
  32888. t = state[14];
  32889. u = state[10];
  32890. state[14] = state[6];
  32891. state[10] = state[2];
  32892. state[6] = t;
  32893. state[2] = u;
  32894. t = state[15];
  32895. u = state[11];
  32896. v = state[7];
  32897. state[15] = state[3];
  32898. state[11] = t;
  32899. state[7] = u;
  32900. state[3] = v;
  32901. for (j = 0; j < 16; ++j) {
  32902. // InvSubBytes
  32903. state[j] = inv_s[state[j]];
  32904. // AddRoundKey
  32905. state[j] ^= key[j];
  32906. }
  32907. return state;
  32908. }
  32909. function encrypt128(input, key) {
  32910. var t, u, v, k;
  32911. var state = new Uint8Array(16);
  32912. state.set(input);
  32913. for (j = 0; j < 16; ++j) {
  32914. // AddRoundKey
  32915. state[j] ^= key[j];
  32916. }
  32917. for (i = 1; i < 10; i++) {
  32918. //SubBytes
  32919. for (j = 0; j < 16; ++j) {
  32920. state[j] = s[state[j]];
  32921. }
  32922. //ShiftRows
  32923. v = state[1];
  32924. state[1] = state[5];
  32925. state[5] = state[9];
  32926. state[9] = state[13];
  32927. state[13] = v;
  32928. v = state[2];
  32929. u = state[6];
  32930. state[2] = state[10];
  32931. state[6] = state[14];
  32932. state[10] = v;
  32933. state[14] = u;
  32934. v = state[3];
  32935. u = state[7];
  32936. t = state[11];
  32937. state[3] = state[15];
  32938. state[7] = v;
  32939. state[11] = u;
  32940. state[15] = t;
  32941. //MixColumns
  32942. for (var j = 0; j < 16; j += 4) {
  32943. var s0 = state[j + 0], s1 = state[j + 1];
  32944. var s2 = state[j + 2], s3 = state[j + 3];
  32945. t = s0 ^ s1 ^ s2 ^ s3;
  32946. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  32947. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  32948. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  32949. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  32950. }
  32951. //AddRoundKey
  32952. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  32953. state[j] ^= key[k];
  32954. }
  32955. }
  32956. //SubBytes
  32957. for (j = 0; j < 16; ++j) {
  32958. state[j] = s[state[j]];
  32959. }
  32960. //ShiftRows
  32961. v = state[1];
  32962. state[1] = state[5];
  32963. state[5] = state[9];
  32964. state[9] = state[13];
  32965. state[13] = v;
  32966. v = state[2];
  32967. u = state[6];
  32968. state[2] = state[10];
  32969. state[6] = state[14];
  32970. state[10] = v;
  32971. state[14] = u;
  32972. v = state[3];
  32973. u = state[7];
  32974. t = state[11];
  32975. state[3] = state[15];
  32976. state[7] = v;
  32977. state[11] = u;
  32978. state[15] = t;
  32979. //AddRoundKey
  32980. for (j = 0, k = 160; j < 16; ++j, ++k) {
  32981. state[j] ^= key[k];
  32982. }
  32983. return state;
  32984. }
  32985. function AES128Cipher(key) {
  32986. this.key = expandKey128(key);
  32987. this.buffer = new Uint8Array(16);
  32988. this.bufferPosition = 0;
  32989. }
  32990. function decryptBlock2(data, finalize) {
  32991. var i, j, ii, sourceLength = data.length, buffer = this.buffer, bufferLength = this.bufferPosition, result = [], iv = this.iv;
  32992. for (i = 0; i < sourceLength; ++i) {
  32993. buffer[bufferLength] = data[i];
  32994. ++bufferLength;
  32995. if (bufferLength < 16) {
  32996. continue;
  32997. }
  32998. // buffer is full, decrypting
  32999. var plain = decrypt128(buffer, this.key);
  33000. // xor-ing the IV vector to get plain text
  33001. for (j = 0; j < 16; ++j) {
  33002. plain[j] ^= iv[j];
  33003. }
  33004. iv = buffer;
  33005. result.push(plain);
  33006. buffer = new Uint8Array(16);
  33007. bufferLength = 0;
  33008. }
  33009. // saving incomplete buffer
  33010. this.buffer = buffer;
  33011. this.bufferLength = bufferLength;
  33012. this.iv = iv;
  33013. if (result.length === 0) {
  33014. return new Uint8Array([]);
  33015. }
  33016. // combining plain text blocks into one
  33017. var outputLength = 16 * result.length;
  33018. if (finalize) {
  33019. // undo a padding that is described in RFC 2898
  33020. var lastBlock = result[result.length - 1];
  33021. var psLen = lastBlock[15];
  33022. if (psLen <= 16) {
  33023. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  33024. if (lastBlock[i] !== psLen) {
  33025. // Invalid padding, assume that the block has no padding.
  33026. psLen = 0;
  33027. break;
  33028. }
  33029. }
  33030. outputLength -= psLen;
  33031. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  33032. }
  33033. }
  33034. var output = new Uint8Array(outputLength);
  33035. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  33036. output.set(result[i], j);
  33037. }
  33038. return output;
  33039. }
  33040. AES128Cipher.prototype = {
  33041. decryptBlock: function AES128Cipher_decryptBlock(data, finalize) {
  33042. var i, sourceLength = data.length;
  33043. var buffer = this.buffer, bufferLength = this.bufferPosition;
  33044. // waiting for IV values -- they are at the start of the stream
  33045. for (i = 0; bufferLength < 16 && i < sourceLength; ++i, ++bufferLength) {
  33046. buffer[bufferLength] = data[i];
  33047. }
  33048. if (bufferLength < 16) {
  33049. // need more data
  33050. this.bufferLength = bufferLength;
  33051. return new Uint8Array([]);
  33052. }
  33053. this.iv = buffer;
  33054. this.buffer = new Uint8Array(16);
  33055. this.bufferLength = 0;
  33056. // starting decryption
  33057. this.decryptBlock = decryptBlock2;
  33058. return this.decryptBlock(data.subarray(16), finalize);
  33059. },
  33060. encrypt: function AES128Cipher_encrypt(data, iv) {
  33061. var i, j, ii, sourceLength = data.length, buffer = this.buffer, bufferLength = this.bufferPosition, result = [];
  33062. if (!iv) {
  33063. iv = new Uint8Array(16);
  33064. }
  33065. for (i = 0; i < sourceLength; ++i) {
  33066. buffer[bufferLength] = data[i];
  33067. ++bufferLength;
  33068. if (bufferLength < 16) {
  33069. continue;
  33070. }
  33071. for (j = 0; j < 16; ++j) {
  33072. buffer[j] ^= iv[j];
  33073. }
  33074. // buffer is full, encrypting
  33075. var cipher = encrypt128(buffer, this.key);
  33076. iv = cipher;
  33077. result.push(cipher);
  33078. buffer = new Uint8Array(16);
  33079. bufferLength = 0;
  33080. }
  33081. // saving incomplete buffer
  33082. this.buffer = buffer;
  33083. this.bufferLength = bufferLength;
  33084. this.iv = iv;
  33085. if (result.length === 0) {
  33086. return new Uint8Array([]);
  33087. }
  33088. // combining plain text blocks into one
  33089. var outputLength = 16 * result.length;
  33090. var output = new Uint8Array(outputLength);
  33091. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  33092. output.set(result[i], j);
  33093. }
  33094. return output;
  33095. }
  33096. };
  33097. return AES128Cipher;
  33098. }();
  33099. var AES256Cipher = function AES256CipherClosure() {
  33100. var rcon = new Uint8Array([
  33101. 0x8d,
  33102. 0x01,
  33103. 0x02,
  33104. 0x04,
  33105. 0x08,
  33106. 0x10,
  33107. 0x20,
  33108. 0x40,
  33109. 0x80,
  33110. 0x1b,
  33111. 0x36,
  33112. 0x6c,
  33113. 0xd8,
  33114. 0xab,
  33115. 0x4d,
  33116. 0x9a,
  33117. 0x2f,
  33118. 0x5e,
  33119. 0xbc,
  33120. 0x63,
  33121. 0xc6,
  33122. 0x97,
  33123. 0x35,
  33124. 0x6a,
  33125. 0xd4,
  33126. 0xb3,
  33127. 0x7d,
  33128. 0xfa,
  33129. 0xef,
  33130. 0xc5,
  33131. 0x91,
  33132. 0x39,
  33133. 0x72,
  33134. 0xe4,
  33135. 0xd3,
  33136. 0xbd,
  33137. 0x61,
  33138. 0xc2,
  33139. 0x9f,
  33140. 0x25,
  33141. 0x4a,
  33142. 0x94,
  33143. 0x33,
  33144. 0x66,
  33145. 0xcc,
  33146. 0x83,
  33147. 0x1d,
  33148. 0x3a,
  33149. 0x74,
  33150. 0xe8,
  33151. 0xcb,
  33152. 0x8d,
  33153. 0x01,
  33154. 0x02,
  33155. 0x04,
  33156. 0x08,
  33157. 0x10,
  33158. 0x20,
  33159. 0x40,
  33160. 0x80,
  33161. 0x1b,
  33162. 0x36,
  33163. 0x6c,
  33164. 0xd8,
  33165. 0xab,
  33166. 0x4d,
  33167. 0x9a,
  33168. 0x2f,
  33169. 0x5e,
  33170. 0xbc,
  33171. 0x63,
  33172. 0xc6,
  33173. 0x97,
  33174. 0x35,
  33175. 0x6a,
  33176. 0xd4,
  33177. 0xb3,
  33178. 0x7d,
  33179. 0xfa,
  33180. 0xef,
  33181. 0xc5,
  33182. 0x91,
  33183. 0x39,
  33184. 0x72,
  33185. 0xe4,
  33186. 0xd3,
  33187. 0xbd,
  33188. 0x61,
  33189. 0xc2,
  33190. 0x9f,
  33191. 0x25,
  33192. 0x4a,
  33193. 0x94,
  33194. 0x33,
  33195. 0x66,
  33196. 0xcc,
  33197. 0x83,
  33198. 0x1d,
  33199. 0x3a,
  33200. 0x74,
  33201. 0xe8,
  33202. 0xcb,
  33203. 0x8d,
  33204. 0x01,
  33205. 0x02,
  33206. 0x04,
  33207. 0x08,
  33208. 0x10,
  33209. 0x20,
  33210. 0x40,
  33211. 0x80,
  33212. 0x1b,
  33213. 0x36,
  33214. 0x6c,
  33215. 0xd8,
  33216. 0xab,
  33217. 0x4d,
  33218. 0x9a,
  33219. 0x2f,
  33220. 0x5e,
  33221. 0xbc,
  33222. 0x63,
  33223. 0xc6,
  33224. 0x97,
  33225. 0x35,
  33226. 0x6a,
  33227. 0xd4,
  33228. 0xb3,
  33229. 0x7d,
  33230. 0xfa,
  33231. 0xef,
  33232. 0xc5,
  33233. 0x91,
  33234. 0x39,
  33235. 0x72,
  33236. 0xe4,
  33237. 0xd3,
  33238. 0xbd,
  33239. 0x61,
  33240. 0xc2,
  33241. 0x9f,
  33242. 0x25,
  33243. 0x4a,
  33244. 0x94,
  33245. 0x33,
  33246. 0x66,
  33247. 0xcc,
  33248. 0x83,
  33249. 0x1d,
  33250. 0x3a,
  33251. 0x74,
  33252. 0xe8,
  33253. 0xcb,
  33254. 0x8d,
  33255. 0x01,
  33256. 0x02,
  33257. 0x04,
  33258. 0x08,
  33259. 0x10,
  33260. 0x20,
  33261. 0x40,
  33262. 0x80,
  33263. 0x1b,
  33264. 0x36,
  33265. 0x6c,
  33266. 0xd8,
  33267. 0xab,
  33268. 0x4d,
  33269. 0x9a,
  33270. 0x2f,
  33271. 0x5e,
  33272. 0xbc,
  33273. 0x63,
  33274. 0xc6,
  33275. 0x97,
  33276. 0x35,
  33277. 0x6a,
  33278. 0xd4,
  33279. 0xb3,
  33280. 0x7d,
  33281. 0xfa,
  33282. 0xef,
  33283. 0xc5,
  33284. 0x91,
  33285. 0x39,
  33286. 0x72,
  33287. 0xe4,
  33288. 0xd3,
  33289. 0xbd,
  33290. 0x61,
  33291. 0xc2,
  33292. 0x9f,
  33293. 0x25,
  33294. 0x4a,
  33295. 0x94,
  33296. 0x33,
  33297. 0x66,
  33298. 0xcc,
  33299. 0x83,
  33300. 0x1d,
  33301. 0x3a,
  33302. 0x74,
  33303. 0xe8,
  33304. 0xcb,
  33305. 0x8d,
  33306. 0x01,
  33307. 0x02,
  33308. 0x04,
  33309. 0x08,
  33310. 0x10,
  33311. 0x20,
  33312. 0x40,
  33313. 0x80,
  33314. 0x1b,
  33315. 0x36,
  33316. 0x6c,
  33317. 0xd8,
  33318. 0xab,
  33319. 0x4d,
  33320. 0x9a,
  33321. 0x2f,
  33322. 0x5e,
  33323. 0xbc,
  33324. 0x63,
  33325. 0xc6,
  33326. 0x97,
  33327. 0x35,
  33328. 0x6a,
  33329. 0xd4,
  33330. 0xb3,
  33331. 0x7d,
  33332. 0xfa,
  33333. 0xef,
  33334. 0xc5,
  33335. 0x91,
  33336. 0x39,
  33337. 0x72,
  33338. 0xe4,
  33339. 0xd3,
  33340. 0xbd,
  33341. 0x61,
  33342. 0xc2,
  33343. 0x9f,
  33344. 0x25,
  33345. 0x4a,
  33346. 0x94,
  33347. 0x33,
  33348. 0x66,
  33349. 0xcc,
  33350. 0x83,
  33351. 0x1d,
  33352. 0x3a,
  33353. 0x74,
  33354. 0xe8,
  33355. 0xcb,
  33356. 0x8d
  33357. ]);
  33358. var s = new Uint8Array([
  33359. 0x63,
  33360. 0x7c,
  33361. 0x77,
  33362. 0x7b,
  33363. 0xf2,
  33364. 0x6b,
  33365. 0x6f,
  33366. 0xc5,
  33367. 0x30,
  33368. 0x01,
  33369. 0x67,
  33370. 0x2b,
  33371. 0xfe,
  33372. 0xd7,
  33373. 0xab,
  33374. 0x76,
  33375. 0xca,
  33376. 0x82,
  33377. 0xc9,
  33378. 0x7d,
  33379. 0xfa,
  33380. 0x59,
  33381. 0x47,
  33382. 0xf0,
  33383. 0xad,
  33384. 0xd4,
  33385. 0xa2,
  33386. 0xaf,
  33387. 0x9c,
  33388. 0xa4,
  33389. 0x72,
  33390. 0xc0,
  33391. 0xb7,
  33392. 0xfd,
  33393. 0x93,
  33394. 0x26,
  33395. 0x36,
  33396. 0x3f,
  33397. 0xf7,
  33398. 0xcc,
  33399. 0x34,
  33400. 0xa5,
  33401. 0xe5,
  33402. 0xf1,
  33403. 0x71,
  33404. 0xd8,
  33405. 0x31,
  33406. 0x15,
  33407. 0x04,
  33408. 0xc7,
  33409. 0x23,
  33410. 0xc3,
  33411. 0x18,
  33412. 0x96,
  33413. 0x05,
  33414. 0x9a,
  33415. 0x07,
  33416. 0x12,
  33417. 0x80,
  33418. 0xe2,
  33419. 0xeb,
  33420. 0x27,
  33421. 0xb2,
  33422. 0x75,
  33423. 0x09,
  33424. 0x83,
  33425. 0x2c,
  33426. 0x1a,
  33427. 0x1b,
  33428. 0x6e,
  33429. 0x5a,
  33430. 0xa0,
  33431. 0x52,
  33432. 0x3b,
  33433. 0xd6,
  33434. 0xb3,
  33435. 0x29,
  33436. 0xe3,
  33437. 0x2f,
  33438. 0x84,
  33439. 0x53,
  33440. 0xd1,
  33441. 0x00,
  33442. 0xed,
  33443. 0x20,
  33444. 0xfc,
  33445. 0xb1,
  33446. 0x5b,
  33447. 0x6a,
  33448. 0xcb,
  33449. 0xbe,
  33450. 0x39,
  33451. 0x4a,
  33452. 0x4c,
  33453. 0x58,
  33454. 0xcf,
  33455. 0xd0,
  33456. 0xef,
  33457. 0xaa,
  33458. 0xfb,
  33459. 0x43,
  33460. 0x4d,
  33461. 0x33,
  33462. 0x85,
  33463. 0x45,
  33464. 0xf9,
  33465. 0x02,
  33466. 0x7f,
  33467. 0x50,
  33468. 0x3c,
  33469. 0x9f,
  33470. 0xa8,
  33471. 0x51,
  33472. 0xa3,
  33473. 0x40,
  33474. 0x8f,
  33475. 0x92,
  33476. 0x9d,
  33477. 0x38,
  33478. 0xf5,
  33479. 0xbc,
  33480. 0xb6,
  33481. 0xda,
  33482. 0x21,
  33483. 0x10,
  33484. 0xff,
  33485. 0xf3,
  33486. 0xd2,
  33487. 0xcd,
  33488. 0x0c,
  33489. 0x13,
  33490. 0xec,
  33491. 0x5f,
  33492. 0x97,
  33493. 0x44,
  33494. 0x17,
  33495. 0xc4,
  33496. 0xa7,
  33497. 0x7e,
  33498. 0x3d,
  33499. 0x64,
  33500. 0x5d,
  33501. 0x19,
  33502. 0x73,
  33503. 0x60,
  33504. 0x81,
  33505. 0x4f,
  33506. 0xdc,
  33507. 0x22,
  33508. 0x2a,
  33509. 0x90,
  33510. 0x88,
  33511. 0x46,
  33512. 0xee,
  33513. 0xb8,
  33514. 0x14,
  33515. 0xde,
  33516. 0x5e,
  33517. 0x0b,
  33518. 0xdb,
  33519. 0xe0,
  33520. 0x32,
  33521. 0x3a,
  33522. 0x0a,
  33523. 0x49,
  33524. 0x06,
  33525. 0x24,
  33526. 0x5c,
  33527. 0xc2,
  33528. 0xd3,
  33529. 0xac,
  33530. 0x62,
  33531. 0x91,
  33532. 0x95,
  33533. 0xe4,
  33534. 0x79,
  33535. 0xe7,
  33536. 0xc8,
  33537. 0x37,
  33538. 0x6d,
  33539. 0x8d,
  33540. 0xd5,
  33541. 0x4e,
  33542. 0xa9,
  33543. 0x6c,
  33544. 0x56,
  33545. 0xf4,
  33546. 0xea,
  33547. 0x65,
  33548. 0x7a,
  33549. 0xae,
  33550. 0x08,
  33551. 0xba,
  33552. 0x78,
  33553. 0x25,
  33554. 0x2e,
  33555. 0x1c,
  33556. 0xa6,
  33557. 0xb4,
  33558. 0xc6,
  33559. 0xe8,
  33560. 0xdd,
  33561. 0x74,
  33562. 0x1f,
  33563. 0x4b,
  33564. 0xbd,
  33565. 0x8b,
  33566. 0x8a,
  33567. 0x70,
  33568. 0x3e,
  33569. 0xb5,
  33570. 0x66,
  33571. 0x48,
  33572. 0x03,
  33573. 0xf6,
  33574. 0x0e,
  33575. 0x61,
  33576. 0x35,
  33577. 0x57,
  33578. 0xb9,
  33579. 0x86,
  33580. 0xc1,
  33581. 0x1d,
  33582. 0x9e,
  33583. 0xe1,
  33584. 0xf8,
  33585. 0x98,
  33586. 0x11,
  33587. 0x69,
  33588. 0xd9,
  33589. 0x8e,
  33590. 0x94,
  33591. 0x9b,
  33592. 0x1e,
  33593. 0x87,
  33594. 0xe9,
  33595. 0xce,
  33596. 0x55,
  33597. 0x28,
  33598. 0xdf,
  33599. 0x8c,
  33600. 0xa1,
  33601. 0x89,
  33602. 0x0d,
  33603. 0xbf,
  33604. 0xe6,
  33605. 0x42,
  33606. 0x68,
  33607. 0x41,
  33608. 0x99,
  33609. 0x2d,
  33610. 0x0f,
  33611. 0xb0,
  33612. 0x54,
  33613. 0xbb,
  33614. 0x16
  33615. ]);
  33616. var inv_s = new Uint8Array([
  33617. 0x52,
  33618. 0x09,
  33619. 0x6a,
  33620. 0xd5,
  33621. 0x30,
  33622. 0x36,
  33623. 0xa5,
  33624. 0x38,
  33625. 0xbf,
  33626. 0x40,
  33627. 0xa3,
  33628. 0x9e,
  33629. 0x81,
  33630. 0xf3,
  33631. 0xd7,
  33632. 0xfb,
  33633. 0x7c,
  33634. 0xe3,
  33635. 0x39,
  33636. 0x82,
  33637. 0x9b,
  33638. 0x2f,
  33639. 0xff,
  33640. 0x87,
  33641. 0x34,
  33642. 0x8e,
  33643. 0x43,
  33644. 0x44,
  33645. 0xc4,
  33646. 0xde,
  33647. 0xe9,
  33648. 0xcb,
  33649. 0x54,
  33650. 0x7b,
  33651. 0x94,
  33652. 0x32,
  33653. 0xa6,
  33654. 0xc2,
  33655. 0x23,
  33656. 0x3d,
  33657. 0xee,
  33658. 0x4c,
  33659. 0x95,
  33660. 0x0b,
  33661. 0x42,
  33662. 0xfa,
  33663. 0xc3,
  33664. 0x4e,
  33665. 0x08,
  33666. 0x2e,
  33667. 0xa1,
  33668. 0x66,
  33669. 0x28,
  33670. 0xd9,
  33671. 0x24,
  33672. 0xb2,
  33673. 0x76,
  33674. 0x5b,
  33675. 0xa2,
  33676. 0x49,
  33677. 0x6d,
  33678. 0x8b,
  33679. 0xd1,
  33680. 0x25,
  33681. 0x72,
  33682. 0xf8,
  33683. 0xf6,
  33684. 0x64,
  33685. 0x86,
  33686. 0x68,
  33687. 0x98,
  33688. 0x16,
  33689. 0xd4,
  33690. 0xa4,
  33691. 0x5c,
  33692. 0xcc,
  33693. 0x5d,
  33694. 0x65,
  33695. 0xb6,
  33696. 0x92,
  33697. 0x6c,
  33698. 0x70,
  33699. 0x48,
  33700. 0x50,
  33701. 0xfd,
  33702. 0xed,
  33703. 0xb9,
  33704. 0xda,
  33705. 0x5e,
  33706. 0x15,
  33707. 0x46,
  33708. 0x57,
  33709. 0xa7,
  33710. 0x8d,
  33711. 0x9d,
  33712. 0x84,
  33713. 0x90,
  33714. 0xd8,
  33715. 0xab,
  33716. 0x00,
  33717. 0x8c,
  33718. 0xbc,
  33719. 0xd3,
  33720. 0x0a,
  33721. 0xf7,
  33722. 0xe4,
  33723. 0x58,
  33724. 0x05,
  33725. 0xb8,
  33726. 0xb3,
  33727. 0x45,
  33728. 0x06,
  33729. 0xd0,
  33730. 0x2c,
  33731. 0x1e,
  33732. 0x8f,
  33733. 0xca,
  33734. 0x3f,
  33735. 0x0f,
  33736. 0x02,
  33737. 0xc1,
  33738. 0xaf,
  33739. 0xbd,
  33740. 0x03,
  33741. 0x01,
  33742. 0x13,
  33743. 0x8a,
  33744. 0x6b,
  33745. 0x3a,
  33746. 0x91,
  33747. 0x11,
  33748. 0x41,
  33749. 0x4f,
  33750. 0x67,
  33751. 0xdc,
  33752. 0xea,
  33753. 0x97,
  33754. 0xf2,
  33755. 0xcf,
  33756. 0xce,
  33757. 0xf0,
  33758. 0xb4,
  33759. 0xe6,
  33760. 0x73,
  33761. 0x96,
  33762. 0xac,
  33763. 0x74,
  33764. 0x22,
  33765. 0xe7,
  33766. 0xad,
  33767. 0x35,
  33768. 0x85,
  33769. 0xe2,
  33770. 0xf9,
  33771. 0x37,
  33772. 0xe8,
  33773. 0x1c,
  33774. 0x75,
  33775. 0xdf,
  33776. 0x6e,
  33777. 0x47,
  33778. 0xf1,
  33779. 0x1a,
  33780. 0x71,
  33781. 0x1d,
  33782. 0x29,
  33783. 0xc5,
  33784. 0x89,
  33785. 0x6f,
  33786. 0xb7,
  33787. 0x62,
  33788. 0x0e,
  33789. 0xaa,
  33790. 0x18,
  33791. 0xbe,
  33792. 0x1b,
  33793. 0xfc,
  33794. 0x56,
  33795. 0x3e,
  33796. 0x4b,
  33797. 0xc6,
  33798. 0xd2,
  33799. 0x79,
  33800. 0x20,
  33801. 0x9a,
  33802. 0xdb,
  33803. 0xc0,
  33804. 0xfe,
  33805. 0x78,
  33806. 0xcd,
  33807. 0x5a,
  33808. 0xf4,
  33809. 0x1f,
  33810. 0xdd,
  33811. 0xa8,
  33812. 0x33,
  33813. 0x88,
  33814. 0x07,
  33815. 0xc7,
  33816. 0x31,
  33817. 0xb1,
  33818. 0x12,
  33819. 0x10,
  33820. 0x59,
  33821. 0x27,
  33822. 0x80,
  33823. 0xec,
  33824. 0x5f,
  33825. 0x60,
  33826. 0x51,
  33827. 0x7f,
  33828. 0xa9,
  33829. 0x19,
  33830. 0xb5,
  33831. 0x4a,
  33832. 0x0d,
  33833. 0x2d,
  33834. 0xe5,
  33835. 0x7a,
  33836. 0x9f,
  33837. 0x93,
  33838. 0xc9,
  33839. 0x9c,
  33840. 0xef,
  33841. 0xa0,
  33842. 0xe0,
  33843. 0x3b,
  33844. 0x4d,
  33845. 0xae,
  33846. 0x2a,
  33847. 0xf5,
  33848. 0xb0,
  33849. 0xc8,
  33850. 0xeb,
  33851. 0xbb,
  33852. 0x3c,
  33853. 0x83,
  33854. 0x53,
  33855. 0x99,
  33856. 0x61,
  33857. 0x17,
  33858. 0x2b,
  33859. 0x04,
  33860. 0x7e,
  33861. 0xba,
  33862. 0x77,
  33863. 0xd6,
  33864. 0x26,
  33865. 0xe1,
  33866. 0x69,
  33867. 0x14,
  33868. 0x63,
  33869. 0x55,
  33870. 0x21,
  33871. 0x0c,
  33872. 0x7d
  33873. ]);
  33874. var mixCol = new Uint8Array(256);
  33875. for (var i = 0; i < 256; i++) {
  33876. if (i < 128) {
  33877. mixCol[i] = i << 1;
  33878. } else {
  33879. mixCol[i] = i << 1 ^ 0x1b;
  33880. }
  33881. }
  33882. var mix = new Uint32Array([
  33883. 0x00000000,
  33884. 0x0e090d0b,
  33885. 0x1c121a16,
  33886. 0x121b171d,
  33887. 0x3824342c,
  33888. 0x362d3927,
  33889. 0x24362e3a,
  33890. 0x2a3f2331,
  33891. 0x70486858,
  33892. 0x7e416553,
  33893. 0x6c5a724e,
  33894. 0x62537f45,
  33895. 0x486c5c74,
  33896. 0x4665517f,
  33897. 0x547e4662,
  33898. 0x5a774b69,
  33899. 0xe090d0b0,
  33900. 0xee99ddbb,
  33901. 0xfc82caa6,
  33902. 0xf28bc7ad,
  33903. 0xd8b4e49c,
  33904. 0xd6bde997,
  33905. 0xc4a6fe8a,
  33906. 0xcaaff381,
  33907. 0x90d8b8e8,
  33908. 0x9ed1b5e3,
  33909. 0x8ccaa2fe,
  33910. 0x82c3aff5,
  33911. 0xa8fc8cc4,
  33912. 0xa6f581cf,
  33913. 0xb4ee96d2,
  33914. 0xbae79bd9,
  33915. 0xdb3bbb7b,
  33916. 0xd532b670,
  33917. 0xc729a16d,
  33918. 0xc920ac66,
  33919. 0xe31f8f57,
  33920. 0xed16825c,
  33921. 0xff0d9541,
  33922. 0xf104984a,
  33923. 0xab73d323,
  33924. 0xa57ade28,
  33925. 0xb761c935,
  33926. 0xb968c43e,
  33927. 0x9357e70f,
  33928. 0x9d5eea04,
  33929. 0x8f45fd19,
  33930. 0x814cf012,
  33931. 0x3bab6bcb,
  33932. 0x35a266c0,
  33933. 0x27b971dd,
  33934. 0x29b07cd6,
  33935. 0x038f5fe7,
  33936. 0x0d8652ec,
  33937. 0x1f9d45f1,
  33938. 0x119448fa,
  33939. 0x4be30393,
  33940. 0x45ea0e98,
  33941. 0x57f11985,
  33942. 0x59f8148e,
  33943. 0x73c737bf,
  33944. 0x7dce3ab4,
  33945. 0x6fd52da9,
  33946. 0x61dc20a2,
  33947. 0xad766df6,
  33948. 0xa37f60fd,
  33949. 0xb16477e0,
  33950. 0xbf6d7aeb,
  33951. 0x955259da,
  33952. 0x9b5b54d1,
  33953. 0x894043cc,
  33954. 0x87494ec7,
  33955. 0xdd3e05ae,
  33956. 0xd33708a5,
  33957. 0xc12c1fb8,
  33958. 0xcf2512b3,
  33959. 0xe51a3182,
  33960. 0xeb133c89,
  33961. 0xf9082b94,
  33962. 0xf701269f,
  33963. 0x4de6bd46,
  33964. 0x43efb04d,
  33965. 0x51f4a750,
  33966. 0x5ffdaa5b,
  33967. 0x75c2896a,
  33968. 0x7bcb8461,
  33969. 0x69d0937c,
  33970. 0x67d99e77,
  33971. 0x3daed51e,
  33972. 0x33a7d815,
  33973. 0x21bccf08,
  33974. 0x2fb5c203,
  33975. 0x058ae132,
  33976. 0x0b83ec39,
  33977. 0x1998fb24,
  33978. 0x1791f62f,
  33979. 0x764dd68d,
  33980. 0x7844db86,
  33981. 0x6a5fcc9b,
  33982. 0x6456c190,
  33983. 0x4e69e2a1,
  33984. 0x4060efaa,
  33985. 0x527bf8b7,
  33986. 0x5c72f5bc,
  33987. 0x0605bed5,
  33988. 0x080cb3de,
  33989. 0x1a17a4c3,
  33990. 0x141ea9c8,
  33991. 0x3e218af9,
  33992. 0x302887f2,
  33993. 0x223390ef,
  33994. 0x2c3a9de4,
  33995. 0x96dd063d,
  33996. 0x98d40b36,
  33997. 0x8acf1c2b,
  33998. 0x84c61120,
  33999. 0xaef93211,
  34000. 0xa0f03f1a,
  34001. 0xb2eb2807,
  34002. 0xbce2250c,
  34003. 0xe6956e65,
  34004. 0xe89c636e,
  34005. 0xfa877473,
  34006. 0xf48e7978,
  34007. 0xdeb15a49,
  34008. 0xd0b85742,
  34009. 0xc2a3405f,
  34010. 0xccaa4d54,
  34011. 0x41ecdaf7,
  34012. 0x4fe5d7fc,
  34013. 0x5dfec0e1,
  34014. 0x53f7cdea,
  34015. 0x79c8eedb,
  34016. 0x77c1e3d0,
  34017. 0x65daf4cd,
  34018. 0x6bd3f9c6,
  34019. 0x31a4b2af,
  34020. 0x3fadbfa4,
  34021. 0x2db6a8b9,
  34022. 0x23bfa5b2,
  34023. 0x09808683,
  34024. 0x07898b88,
  34025. 0x15929c95,
  34026. 0x1b9b919e,
  34027. 0xa17c0a47,
  34028. 0xaf75074c,
  34029. 0xbd6e1051,
  34030. 0xb3671d5a,
  34031. 0x99583e6b,
  34032. 0x97513360,
  34033. 0x854a247d,
  34034. 0x8b432976,
  34035. 0xd134621f,
  34036. 0xdf3d6f14,
  34037. 0xcd267809,
  34038. 0xc32f7502,
  34039. 0xe9105633,
  34040. 0xe7195b38,
  34041. 0xf5024c25,
  34042. 0xfb0b412e,
  34043. 0x9ad7618c,
  34044. 0x94de6c87,
  34045. 0x86c57b9a,
  34046. 0x88cc7691,
  34047. 0xa2f355a0,
  34048. 0xacfa58ab,
  34049. 0xbee14fb6,
  34050. 0xb0e842bd,
  34051. 0xea9f09d4,
  34052. 0xe49604df,
  34053. 0xf68d13c2,
  34054. 0xf8841ec9,
  34055. 0xd2bb3df8,
  34056. 0xdcb230f3,
  34057. 0xcea927ee,
  34058. 0xc0a02ae5,
  34059. 0x7a47b13c,
  34060. 0x744ebc37,
  34061. 0x6655ab2a,
  34062. 0x685ca621,
  34063. 0x42638510,
  34064. 0x4c6a881b,
  34065. 0x5e719f06,
  34066. 0x5078920d,
  34067. 0x0a0fd964,
  34068. 0x0406d46f,
  34069. 0x161dc372,
  34070. 0x1814ce79,
  34071. 0x322bed48,
  34072. 0x3c22e043,
  34073. 0x2e39f75e,
  34074. 0x2030fa55,
  34075. 0xec9ab701,
  34076. 0xe293ba0a,
  34077. 0xf088ad17,
  34078. 0xfe81a01c,
  34079. 0xd4be832d,
  34080. 0xdab78e26,
  34081. 0xc8ac993b,
  34082. 0xc6a59430,
  34083. 0x9cd2df59,
  34084. 0x92dbd252,
  34085. 0x80c0c54f,
  34086. 0x8ec9c844,
  34087. 0xa4f6eb75,
  34088. 0xaaffe67e,
  34089. 0xb8e4f163,
  34090. 0xb6edfc68,
  34091. 0x0c0a67b1,
  34092. 0x02036aba,
  34093. 0x10187da7,
  34094. 0x1e1170ac,
  34095. 0x342e539d,
  34096. 0x3a275e96,
  34097. 0x283c498b,
  34098. 0x26354480,
  34099. 0x7c420fe9,
  34100. 0x724b02e2,
  34101. 0x605015ff,
  34102. 0x6e5918f4,
  34103. 0x44663bc5,
  34104. 0x4a6f36ce,
  34105. 0x587421d3,
  34106. 0x567d2cd8,
  34107. 0x37a10c7a,
  34108. 0x39a80171,
  34109. 0x2bb3166c,
  34110. 0x25ba1b67,
  34111. 0x0f853856,
  34112. 0x018c355d,
  34113. 0x13972240,
  34114. 0x1d9e2f4b,
  34115. 0x47e96422,
  34116. 0x49e06929,
  34117. 0x5bfb7e34,
  34118. 0x55f2733f,
  34119. 0x7fcd500e,
  34120. 0x71c45d05,
  34121. 0x63df4a18,
  34122. 0x6dd64713,
  34123. 0xd731dcca,
  34124. 0xd938d1c1,
  34125. 0xcb23c6dc,
  34126. 0xc52acbd7,
  34127. 0xef15e8e6,
  34128. 0xe11ce5ed,
  34129. 0xf307f2f0,
  34130. 0xfd0efffb,
  34131. 0xa779b492,
  34132. 0xa970b999,
  34133. 0xbb6bae84,
  34134. 0xb562a38f,
  34135. 0x9f5d80be,
  34136. 0x91548db5,
  34137. 0x834f9aa8,
  34138. 0x8d4697a3
  34139. ]);
  34140. function expandKey256(cipherKey) {
  34141. var b = 240, result = new Uint8Array(b);
  34142. var r = 1;
  34143. result.set(cipherKey);
  34144. for (var j = 32, i = 1; j < b; ++i) {
  34145. if (j % 32 === 16) {
  34146. t1 = s[t1];
  34147. t2 = s[t2];
  34148. t3 = s[t3];
  34149. t4 = s[t4];
  34150. } else if (j % 32 === 0) {
  34151. // RotWord
  34152. var t1 = result[j - 3], t2 = result[j - 2], t3 = result[j - 1], t4 = result[j - 4];
  34153. // SubWord
  34154. t1 = s[t1];
  34155. t2 = s[t2];
  34156. t3 = s[t3];
  34157. t4 = s[t4];
  34158. // Rcon
  34159. t1 = t1 ^ r;
  34160. if ((r <<= 1) >= 256) {
  34161. r = (r ^ 0x1b) & 0xFF;
  34162. }
  34163. }
  34164. for (var n = 0; n < 4; ++n) {
  34165. result[j] = t1 ^= result[j - 32];
  34166. j++;
  34167. result[j] = t2 ^= result[j - 32];
  34168. j++;
  34169. result[j] = t3 ^= result[j - 32];
  34170. j++;
  34171. result[j] = t4 ^= result[j - 32];
  34172. j++;
  34173. }
  34174. }
  34175. return result;
  34176. }
  34177. function decrypt256(input, key) {
  34178. var state = new Uint8Array(16);
  34179. state.set(input);
  34180. var i, j, k;
  34181. var t, u, v;
  34182. // AddRoundKey
  34183. for (j = 0, k = 224; j < 16; ++j, ++k) {
  34184. state[j] ^= key[k];
  34185. }
  34186. for (i = 13; i >= 1; --i) {
  34187. // InvShiftRows
  34188. t = state[13];
  34189. state[13] = state[9];
  34190. state[9] = state[5];
  34191. state[5] = state[1];
  34192. state[1] = t;
  34193. t = state[14];
  34194. u = state[10];
  34195. state[14] = state[6];
  34196. state[10] = state[2];
  34197. state[6] = t;
  34198. state[2] = u;
  34199. t = state[15];
  34200. u = state[11];
  34201. v = state[7];
  34202. state[15] = state[3];
  34203. state[11] = t;
  34204. state[7] = u;
  34205. state[3] = v;
  34206. // InvSubBytes
  34207. for (j = 0; j < 16; ++j) {
  34208. state[j] = inv_s[state[j]];
  34209. }
  34210. // AddRoundKey
  34211. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  34212. state[j] ^= key[k];
  34213. }
  34214. // InvMixColumns
  34215. for (j = 0; j < 16; j += 4) {
  34216. var s0 = mix[state[j]], s1 = mix[state[j + 1]], s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  34217. t = s0 ^ s1 >>> 8 ^ s1 << 24 ^ s2 >>> 16 ^ s2 << 16 ^ s3 >>> 24 ^ s3 << 8;
  34218. state[j] = t >>> 24 & 0xFF;
  34219. state[j + 1] = t >> 16 & 0xFF;
  34220. state[j + 2] = t >> 8 & 0xFF;
  34221. state[j + 3] = t & 0xFF;
  34222. }
  34223. }
  34224. // InvShiftRows
  34225. t = state[13];
  34226. state[13] = state[9];
  34227. state[9] = state[5];
  34228. state[5] = state[1];
  34229. state[1] = t;
  34230. t = state[14];
  34231. u = state[10];
  34232. state[14] = state[6];
  34233. state[10] = state[2];
  34234. state[6] = t;
  34235. state[2] = u;
  34236. t = state[15];
  34237. u = state[11];
  34238. v = state[7];
  34239. state[15] = state[3];
  34240. state[11] = t;
  34241. state[7] = u;
  34242. state[3] = v;
  34243. for (j = 0; j < 16; ++j) {
  34244. // InvSubBytes
  34245. state[j] = inv_s[state[j]];
  34246. // AddRoundKey
  34247. state[j] ^= key[j];
  34248. }
  34249. return state;
  34250. }
  34251. function encrypt256(input, key) {
  34252. var t, u, v, k;
  34253. var state = new Uint8Array(16);
  34254. state.set(input);
  34255. for (j = 0; j < 16; ++j) {
  34256. // AddRoundKey
  34257. state[j] ^= key[j];
  34258. }
  34259. for (i = 1; i < 14; i++) {
  34260. //SubBytes
  34261. for (j = 0; j < 16; ++j) {
  34262. state[j] = s[state[j]];
  34263. }
  34264. //ShiftRows
  34265. v = state[1];
  34266. state[1] = state[5];
  34267. state[5] = state[9];
  34268. state[9] = state[13];
  34269. state[13] = v;
  34270. v = state[2];
  34271. u = state[6];
  34272. state[2] = state[10];
  34273. state[6] = state[14];
  34274. state[10] = v;
  34275. state[14] = u;
  34276. v = state[3];
  34277. u = state[7];
  34278. t = state[11];
  34279. state[3] = state[15];
  34280. state[7] = v;
  34281. state[11] = u;
  34282. state[15] = t;
  34283. //MixColumns
  34284. for (var j = 0; j < 16; j += 4) {
  34285. var s0 = state[j + 0], s1 = state[j + 1];
  34286. var s2 = state[j + 2], s3 = state[j + 3];
  34287. t = s0 ^ s1 ^ s2 ^ s3;
  34288. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  34289. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  34290. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  34291. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  34292. }
  34293. //AddRoundKey
  34294. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  34295. state[j] ^= key[k];
  34296. }
  34297. }
  34298. //SubBytes
  34299. for (j = 0; j < 16; ++j) {
  34300. state[j] = s[state[j]];
  34301. }
  34302. //ShiftRows
  34303. v = state[1];
  34304. state[1] = state[5];
  34305. state[5] = state[9];
  34306. state[9] = state[13];
  34307. state[13] = v;
  34308. v = state[2];
  34309. u = state[6];
  34310. state[2] = state[10];
  34311. state[6] = state[14];
  34312. state[10] = v;
  34313. state[14] = u;
  34314. v = state[3];
  34315. u = state[7];
  34316. t = state[11];
  34317. state[3] = state[15];
  34318. state[7] = v;
  34319. state[11] = u;
  34320. state[15] = t;
  34321. //AddRoundKey
  34322. for (j = 0, k = 224; j < 16; ++j, ++k) {
  34323. state[j] ^= key[k];
  34324. }
  34325. return state;
  34326. }
  34327. function AES256Cipher(key) {
  34328. this.key = expandKey256(key);
  34329. this.buffer = new Uint8Array(16);
  34330. this.bufferPosition = 0;
  34331. }
  34332. function decryptBlock2(data, finalize) {
  34333. var i, j, ii, sourceLength = data.length, buffer = this.buffer, bufferLength = this.bufferPosition, result = [], iv = this.iv;
  34334. for (i = 0; i < sourceLength; ++i) {
  34335. buffer[bufferLength] = data[i];
  34336. ++bufferLength;
  34337. if (bufferLength < 16) {
  34338. continue;
  34339. }
  34340. // buffer is full, decrypting
  34341. var plain = decrypt256(buffer, this.key);
  34342. // xor-ing the IV vector to get plain text
  34343. for (j = 0; j < 16; ++j) {
  34344. plain[j] ^= iv[j];
  34345. }
  34346. iv = buffer;
  34347. result.push(plain);
  34348. buffer = new Uint8Array(16);
  34349. bufferLength = 0;
  34350. }
  34351. // saving incomplete buffer
  34352. this.buffer = buffer;
  34353. this.bufferLength = bufferLength;
  34354. this.iv = iv;
  34355. if (result.length === 0) {
  34356. return new Uint8Array([]);
  34357. }
  34358. // combining plain text blocks into one
  34359. var outputLength = 16 * result.length;
  34360. if (finalize) {
  34361. // undo a padding that is described in RFC 2898
  34362. var lastBlock = result[result.length - 1];
  34363. var psLen = lastBlock[15];
  34364. if (psLen <= 16) {
  34365. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  34366. if (lastBlock[i] !== psLen) {
  34367. // Invalid padding, assume that the block has no padding.
  34368. psLen = 0;
  34369. break;
  34370. }
  34371. }
  34372. outputLength -= psLen;
  34373. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  34374. }
  34375. }
  34376. var output = new Uint8Array(outputLength);
  34377. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  34378. output.set(result[i], j);
  34379. }
  34380. return output;
  34381. }
  34382. AES256Cipher.prototype = {
  34383. decryptBlock: function AES256Cipher_decryptBlock(data, finalize, iv) {
  34384. var i, sourceLength = data.length;
  34385. var buffer = this.buffer, bufferLength = this.bufferPosition;
  34386. // if not supplied an IV wait for IV values
  34387. // they are at the start of the stream
  34388. if (iv) {
  34389. this.iv = iv;
  34390. } else {
  34391. for (i = 0; bufferLength < 16 && i < sourceLength; ++i, ++bufferLength) {
  34392. buffer[bufferLength] = data[i];
  34393. }
  34394. if (bufferLength < 16) {
  34395. //need more data
  34396. this.bufferLength = bufferLength;
  34397. return new Uint8Array([]);
  34398. }
  34399. this.iv = buffer;
  34400. data = data.subarray(16);
  34401. }
  34402. this.buffer = new Uint8Array(16);
  34403. this.bufferLength = 0;
  34404. // starting decryption
  34405. this.decryptBlock = decryptBlock2;
  34406. return this.decryptBlock(data, finalize);
  34407. },
  34408. encrypt: function AES256Cipher_encrypt(data, iv) {
  34409. var i, j, ii, sourceLength = data.length, buffer = this.buffer, bufferLength = this.bufferPosition, result = [];
  34410. if (!iv) {
  34411. iv = new Uint8Array(16);
  34412. }
  34413. for (i = 0; i < sourceLength; ++i) {
  34414. buffer[bufferLength] = data[i];
  34415. ++bufferLength;
  34416. if (bufferLength < 16) {
  34417. continue;
  34418. }
  34419. for (j = 0; j < 16; ++j) {
  34420. buffer[j] ^= iv[j];
  34421. }
  34422. // buffer is full, encrypting
  34423. var cipher = encrypt256(buffer, this.key);
  34424. this.iv = cipher;
  34425. result.push(cipher);
  34426. buffer = new Uint8Array(16);
  34427. bufferLength = 0;
  34428. }
  34429. // saving incomplete buffer
  34430. this.buffer = buffer;
  34431. this.bufferLength = bufferLength;
  34432. this.iv = iv;
  34433. if (result.length === 0) {
  34434. return new Uint8Array([]);
  34435. }
  34436. // combining plain text blocks into one
  34437. var outputLength = 16 * result.length;
  34438. var output = new Uint8Array(outputLength);
  34439. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  34440. output.set(result[i], j);
  34441. }
  34442. return output;
  34443. }
  34444. };
  34445. return AES256Cipher;
  34446. }();
  34447. var PDF17 = function PDF17Closure() {
  34448. function compareByteArrays(array1, array2) {
  34449. if (array1.length !== array2.length) {
  34450. return false;
  34451. }
  34452. for (var i = 0; i < array1.length; i++) {
  34453. if (array1[i] !== array2[i]) {
  34454. return false;
  34455. }
  34456. }
  34457. return true;
  34458. }
  34459. function PDF17() {
  34460. }
  34461. PDF17.prototype = {
  34462. checkOwnerPassword: function PDF17_checkOwnerPassword(password, ownerValidationSalt, userBytes, ownerPassword) {
  34463. var hashData = new Uint8Array(password.length + 56);
  34464. hashData.set(password, 0);
  34465. hashData.set(ownerValidationSalt, password.length);
  34466. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  34467. var result = calculateSHA256(hashData, 0, hashData.length);
  34468. return compareByteArrays(result, ownerPassword);
  34469. },
  34470. checkUserPassword: function PDF17_checkUserPassword(password, userValidationSalt, userPassword) {
  34471. var hashData = new Uint8Array(password.length + 8);
  34472. hashData.set(password, 0);
  34473. hashData.set(userValidationSalt, password.length);
  34474. var result = calculateSHA256(hashData, 0, hashData.length);
  34475. return compareByteArrays(result, userPassword);
  34476. },
  34477. getOwnerKey: function PDF17_getOwnerKey(password, ownerKeySalt, userBytes, ownerEncryption) {
  34478. var hashData = new Uint8Array(password.length + 56);
  34479. hashData.set(password, 0);
  34480. hashData.set(ownerKeySalt, password.length);
  34481. hashData.set(userBytes, password.length + ownerKeySalt.length);
  34482. var key = calculateSHA256(hashData, 0, hashData.length);
  34483. var cipher = new AES256Cipher(key);
  34484. return cipher.decryptBlock(ownerEncryption, false, new Uint8Array(16));
  34485. },
  34486. getUserKey: function PDF17_getUserKey(password, userKeySalt, userEncryption) {
  34487. var hashData = new Uint8Array(password.length + 8);
  34488. hashData.set(password, 0);
  34489. hashData.set(userKeySalt, password.length);
  34490. //key is the decryption key for the UE string
  34491. var key = calculateSHA256(hashData, 0, hashData.length);
  34492. var cipher = new AES256Cipher(key);
  34493. return cipher.decryptBlock(userEncryption, false, new Uint8Array(16));
  34494. }
  34495. };
  34496. return PDF17;
  34497. }();
  34498. var PDF20 = function PDF20Closure() {
  34499. function concatArrays(array1, array2) {
  34500. var t = new Uint8Array(array1.length + array2.length);
  34501. t.set(array1, 0);
  34502. t.set(array2, array1.length);
  34503. return t;
  34504. }
  34505. function calculatePDF20Hash(password, input, userBytes) {
  34506. //This refers to Algorithm 2.B as defined in ISO 32000-2
  34507. var k = calculateSHA256(input, 0, input.length).subarray(0, 32);
  34508. var e = [0];
  34509. var i = 0;
  34510. while (i < 64 || e[e.length - 1] > i - 32) {
  34511. var arrayLength = password.length + k.length + userBytes.length;
  34512. var k1 = new Uint8Array(arrayLength * 64);
  34513. var array = concatArrays(password, k);
  34514. array = concatArrays(array, userBytes);
  34515. for (var j = 0, pos = 0; j < 64; j++, pos += arrayLength) {
  34516. k1.set(array, pos);
  34517. }
  34518. //AES128 CBC NO PADDING with
  34519. //first 16 bytes of k as the key and the second 16 as the iv.
  34520. var cipher = new AES128Cipher(k.subarray(0, 16));
  34521. e = cipher.encrypt(k1, k.subarray(16, 32));
  34522. //Now we have to take the first 16 bytes of an unsigned
  34523. //big endian integer... and compute the remainder
  34524. //modulo 3.... That is a fairly large number and
  34525. //JavaScript isn't going to handle that well...
  34526. //So we're using a trick that allows us to perform
  34527. //modulo math byte by byte
  34528. var remainder = 0;
  34529. for (var z = 0; z < 16; z++) {
  34530. remainder *= 256 % 3;
  34531. remainder %= 3;
  34532. remainder += (e[z] >>> 0) % 3;
  34533. remainder %= 3;
  34534. }
  34535. if (remainder === 0) {
  34536. k = calculateSHA256(e, 0, e.length);
  34537. } else if (remainder === 1) {
  34538. k = calculateSHA384(e, 0, e.length);
  34539. } else if (remainder === 2) {
  34540. k = calculateSHA512(e, 0, e.length);
  34541. }
  34542. i++;
  34543. }
  34544. return k.subarray(0, 32);
  34545. }
  34546. function PDF20() {
  34547. }
  34548. function compareByteArrays(array1, array2) {
  34549. if (array1.length !== array2.length) {
  34550. return false;
  34551. }
  34552. for (var i = 0; i < array1.length; i++) {
  34553. if (array1[i] !== array2[i]) {
  34554. return false;
  34555. }
  34556. }
  34557. return true;
  34558. }
  34559. PDF20.prototype = {
  34560. hash: function PDF20_hash(password, concatBytes, userBytes) {
  34561. return calculatePDF20Hash(password, concatBytes, userBytes);
  34562. },
  34563. checkOwnerPassword: function PDF20_checkOwnerPassword(password, ownerValidationSalt, userBytes, ownerPassword) {
  34564. var hashData = new Uint8Array(password.length + 56);
  34565. hashData.set(password, 0);
  34566. hashData.set(ownerValidationSalt, password.length);
  34567. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  34568. var result = calculatePDF20Hash(password, hashData, userBytes);
  34569. return compareByteArrays(result, ownerPassword);
  34570. },
  34571. checkUserPassword: function PDF20_checkUserPassword(password, userValidationSalt, userPassword) {
  34572. var hashData = new Uint8Array(password.length + 8);
  34573. hashData.set(password, 0);
  34574. hashData.set(userValidationSalt, password.length);
  34575. var result = calculatePDF20Hash(password, hashData, []);
  34576. return compareByteArrays(result, userPassword);
  34577. },
  34578. getOwnerKey: function PDF20_getOwnerKey(password, ownerKeySalt, userBytes, ownerEncryption) {
  34579. var hashData = new Uint8Array(password.length + 56);
  34580. hashData.set(password, 0);
  34581. hashData.set(ownerKeySalt, password.length);
  34582. hashData.set(userBytes, password.length + ownerKeySalt.length);
  34583. var key = calculatePDF20Hash(password, hashData, userBytes);
  34584. var cipher = new AES256Cipher(key);
  34585. return cipher.decryptBlock(ownerEncryption, false, new Uint8Array(16));
  34586. },
  34587. getUserKey: function PDF20_getUserKey(password, userKeySalt, userEncryption) {
  34588. var hashData = new Uint8Array(password.length + 8);
  34589. hashData.set(password, 0);
  34590. hashData.set(userKeySalt, password.length);
  34591. //key is the decryption key for the UE string
  34592. var key = calculatePDF20Hash(password, hashData, []);
  34593. var cipher = new AES256Cipher(key);
  34594. return cipher.decryptBlock(userEncryption, false, new Uint8Array(16));
  34595. }
  34596. };
  34597. return PDF20;
  34598. }();
  34599. var CipherTransform = function CipherTransformClosure() {
  34600. function CipherTransform(stringCipherConstructor, streamCipherConstructor) {
  34601. this.stringCipherConstructor = stringCipherConstructor;
  34602. this.streamCipherConstructor = streamCipherConstructor;
  34603. }
  34604. CipherTransform.prototype = {
  34605. createStream: function CipherTransform_createStream(stream, length) {
  34606. var cipher = new this.streamCipherConstructor();
  34607. return new DecryptStream(stream, length, function cipherTransformDecryptStream(data, finalize) {
  34608. return cipher.decryptBlock(data, finalize);
  34609. });
  34610. },
  34611. decryptString: function CipherTransform_decryptString(s) {
  34612. var cipher = new this.stringCipherConstructor();
  34613. var data = stringToBytes(s);
  34614. data = cipher.decryptBlock(data, true);
  34615. return bytesToString(data);
  34616. }
  34617. };
  34618. return CipherTransform;
  34619. }();
  34620. var CipherTransformFactory = function CipherTransformFactoryClosure() {
  34621. var defaultPasswordBytes = new Uint8Array([
  34622. 0x28,
  34623. 0xBF,
  34624. 0x4E,
  34625. 0x5E,
  34626. 0x4E,
  34627. 0x75,
  34628. 0x8A,
  34629. 0x41,
  34630. 0x64,
  34631. 0x00,
  34632. 0x4E,
  34633. 0x56,
  34634. 0xFF,
  34635. 0xFA,
  34636. 0x01,
  34637. 0x08,
  34638. 0x2E,
  34639. 0x2E,
  34640. 0x00,
  34641. 0xB6,
  34642. 0xD0,
  34643. 0x68,
  34644. 0x3E,
  34645. 0x80,
  34646. 0x2F,
  34647. 0x0C,
  34648. 0xA9,
  34649. 0xFE,
  34650. 0x64,
  34651. 0x53,
  34652. 0x69,
  34653. 0x7A
  34654. ]);
  34655. function createEncryptionKey20(revision, password, ownerPassword, ownerValidationSalt, ownerKeySalt, uBytes, userPassword, userValidationSalt, userKeySalt, ownerEncryption, userEncryption, perms) {
  34656. if (password) {
  34657. var passwordLength = Math.min(127, password.length);
  34658. password = password.subarray(0, passwordLength);
  34659. } else {
  34660. password = [];
  34661. }
  34662. var pdfAlgorithm;
  34663. if (revision === 6) {
  34664. pdfAlgorithm = new PDF20();
  34665. } else {
  34666. pdfAlgorithm = new PDF17();
  34667. }
  34668. if (pdfAlgorithm.checkUserPassword(password, userValidationSalt, userPassword)) {
  34669. return pdfAlgorithm.getUserKey(password, userKeySalt, userEncryption);
  34670. } else if (password.length && pdfAlgorithm.checkOwnerPassword(password, ownerValidationSalt, uBytes, ownerPassword)) {
  34671. return pdfAlgorithm.getOwnerKey(password, ownerKeySalt, uBytes, ownerEncryption);
  34672. }
  34673. return null;
  34674. }
  34675. function prepareKeyData(fileId, password, ownerPassword, userPassword, flags, revision, keyLength, encryptMetadata) {
  34676. var hashDataSize = 40 + ownerPassword.length + fileId.length;
  34677. var hashData = new Uint8Array(hashDataSize), i = 0, j, n;
  34678. if (password) {
  34679. n = Math.min(32, password.length);
  34680. for (; i < n; ++i) {
  34681. hashData[i] = password[i];
  34682. }
  34683. }
  34684. j = 0;
  34685. while (i < 32) {
  34686. hashData[i++] = defaultPasswordBytes[j++];
  34687. }
  34688. // as now the padded password in the hashData[0..i]
  34689. for (j = 0, n = ownerPassword.length; j < n; ++j) {
  34690. hashData[i++] = ownerPassword[j];
  34691. }
  34692. hashData[i++] = flags & 0xFF;
  34693. hashData[i++] = flags >> 8 & 0xFF;
  34694. hashData[i++] = flags >> 16 & 0xFF;
  34695. hashData[i++] = flags >>> 24 & 0xFF;
  34696. for (j = 0, n = fileId.length; j < n; ++j) {
  34697. hashData[i++] = fileId[j];
  34698. }
  34699. if (revision >= 4 && !encryptMetadata) {
  34700. hashData[i++] = 0xFF;
  34701. hashData[i++] = 0xFF;
  34702. hashData[i++] = 0xFF;
  34703. hashData[i++] = 0xFF;
  34704. }
  34705. var hash = calculateMD5(hashData, 0, i);
  34706. var keyLengthInBytes = keyLength >> 3;
  34707. if (revision >= 3) {
  34708. for (j = 0; j < 50; ++j) {
  34709. hash = calculateMD5(hash, 0, keyLengthInBytes);
  34710. }
  34711. }
  34712. var encryptionKey = hash.subarray(0, keyLengthInBytes);
  34713. var cipher, checkData;
  34714. if (revision >= 3) {
  34715. for (i = 0; i < 32; ++i) {
  34716. hashData[i] = defaultPasswordBytes[i];
  34717. }
  34718. for (j = 0, n = fileId.length; j < n; ++j) {
  34719. hashData[i++] = fileId[j];
  34720. }
  34721. cipher = new ARCFourCipher(encryptionKey);
  34722. checkData = cipher.encryptBlock(calculateMD5(hashData, 0, i));
  34723. n = encryptionKey.length;
  34724. var derivedKey = new Uint8Array(n), k;
  34725. for (j = 1; j <= 19; ++j) {
  34726. for (k = 0; k < n; ++k) {
  34727. derivedKey[k] = encryptionKey[k] ^ j;
  34728. }
  34729. cipher = new ARCFourCipher(derivedKey);
  34730. checkData = cipher.encryptBlock(checkData);
  34731. }
  34732. for (j = 0, n = checkData.length; j < n; ++j) {
  34733. if (userPassword[j] !== checkData[j]) {
  34734. return null;
  34735. }
  34736. }
  34737. } else {
  34738. cipher = new ARCFourCipher(encryptionKey);
  34739. checkData = cipher.encryptBlock(defaultPasswordBytes);
  34740. for (j = 0, n = checkData.length; j < n; ++j) {
  34741. if (userPassword[j] !== checkData[j]) {
  34742. return null;
  34743. }
  34744. }
  34745. }
  34746. return encryptionKey;
  34747. }
  34748. function decodeUserPassword(password, ownerPassword, revision, keyLength) {
  34749. var hashData = new Uint8Array(32), i = 0, j, n;
  34750. n = Math.min(32, password.length);
  34751. for (; i < n; ++i) {
  34752. hashData[i] = password[i];
  34753. }
  34754. j = 0;
  34755. while (i < 32) {
  34756. hashData[i++] = defaultPasswordBytes[j++];
  34757. }
  34758. var hash = calculateMD5(hashData, 0, i);
  34759. var keyLengthInBytes = keyLength >> 3;
  34760. if (revision >= 3) {
  34761. for (j = 0; j < 50; ++j) {
  34762. hash = calculateMD5(hash, 0, hash.length);
  34763. }
  34764. }
  34765. var cipher, userPassword;
  34766. if (revision >= 3) {
  34767. userPassword = ownerPassword;
  34768. var derivedKey = new Uint8Array(keyLengthInBytes), k;
  34769. for (j = 19; j >= 0; j--) {
  34770. for (k = 0; k < keyLengthInBytes; ++k) {
  34771. derivedKey[k] = hash[k] ^ j;
  34772. }
  34773. cipher = new ARCFourCipher(derivedKey);
  34774. userPassword = cipher.encryptBlock(userPassword);
  34775. }
  34776. } else {
  34777. cipher = new ARCFourCipher(hash.subarray(0, keyLengthInBytes));
  34778. userPassword = cipher.encryptBlock(ownerPassword);
  34779. }
  34780. return userPassword;
  34781. }
  34782. var identityName = Name.get('Identity');
  34783. function CipherTransformFactory(dict, fileId, password) {
  34784. var filter = dict.get('Filter');
  34785. if (!isName(filter, 'Standard')) {
  34786. error('unknown encryption method');
  34787. }
  34788. this.dict = dict;
  34789. var algorithm = dict.get('V');
  34790. if (!isInt(algorithm) || algorithm !== 1 && algorithm !== 2 && algorithm !== 4 && algorithm !== 5) {
  34791. error('unsupported encryption algorithm');
  34792. }
  34793. this.algorithm = algorithm;
  34794. var keyLength = dict.get('Length');
  34795. if (!keyLength) {
  34796. // Spec asks to rely on encryption dictionary's Length entry, however
  34797. // some PDFs don't have it. Trying to recover.
  34798. if (algorithm <= 3) {
  34799. // For 1 and 2 it's fixed to 40-bit, for 3 40-bit is a minimal value.
  34800. keyLength = 40;
  34801. } else {
  34802. // Trying to find default handler -- it usually has Length.
  34803. var cfDict = dict.get('CF');
  34804. var streamCryptoName = dict.get('StmF');
  34805. if (isDict(cfDict) && isName(streamCryptoName)) {
  34806. cfDict.suppressEncryption = true;
  34807. // See comment below.
  34808. var handlerDict = cfDict.get(streamCryptoName.name);
  34809. keyLength = handlerDict && handlerDict.get('Length') || 128;
  34810. if (keyLength < 40) {
  34811. // Sometimes it's incorrect value of bits, generators specify bytes.
  34812. keyLength <<= 3;
  34813. }
  34814. }
  34815. }
  34816. }
  34817. if (!isInt(keyLength) || keyLength < 40 || keyLength % 8 !== 0) {
  34818. error('invalid key length');
  34819. }
  34820. // prepare keys
  34821. var ownerPassword = stringToBytes(dict.get('O')).subarray(0, 32);
  34822. var userPassword = stringToBytes(dict.get('U')).subarray(0, 32);
  34823. var flags = dict.get('P');
  34824. var revision = dict.get('R');
  34825. // meaningful when V is 4 or 5
  34826. var encryptMetadata = (algorithm === 4 || algorithm === 5) && dict.get('EncryptMetadata') !== false;
  34827. this.encryptMetadata = encryptMetadata;
  34828. var fileIdBytes = stringToBytes(fileId);
  34829. var passwordBytes;
  34830. if (password) {
  34831. if (revision === 6) {
  34832. try {
  34833. password = utf8StringToString(password);
  34834. } catch (ex) {
  34835. warn('CipherTransformFactory: ' + 'Unable to convert UTF8 encoded password.');
  34836. }
  34837. }
  34838. passwordBytes = stringToBytes(password);
  34839. }
  34840. var encryptionKey;
  34841. if (algorithm !== 5) {
  34842. encryptionKey = prepareKeyData(fileIdBytes, passwordBytes, ownerPassword, userPassword, flags, revision, keyLength, encryptMetadata);
  34843. } else {
  34844. var ownerValidationSalt = stringToBytes(dict.get('O')).subarray(32, 40);
  34845. var ownerKeySalt = stringToBytes(dict.get('O')).subarray(40, 48);
  34846. var uBytes = stringToBytes(dict.get('U')).subarray(0, 48);
  34847. var userValidationSalt = stringToBytes(dict.get('U')).subarray(32, 40);
  34848. var userKeySalt = stringToBytes(dict.get('U')).subarray(40, 48);
  34849. var ownerEncryption = stringToBytes(dict.get('OE'));
  34850. var userEncryption = stringToBytes(dict.get('UE'));
  34851. var perms = stringToBytes(dict.get('Perms'));
  34852. encryptionKey = createEncryptionKey20(revision, passwordBytes, ownerPassword, ownerValidationSalt, ownerKeySalt, uBytes, userPassword, userValidationSalt, userKeySalt, ownerEncryption, userEncryption, perms);
  34853. }
  34854. if (!encryptionKey && !password) {
  34855. throw new PasswordException('No password given', PasswordResponses.NEED_PASSWORD);
  34856. } else if (!encryptionKey && password) {
  34857. // Attempting use the password as an owner password
  34858. var decodedPassword = decodeUserPassword(passwordBytes, ownerPassword, revision, keyLength);
  34859. encryptionKey = prepareKeyData(fileIdBytes, decodedPassword, ownerPassword, userPassword, flags, revision, keyLength, encryptMetadata);
  34860. }
  34861. if (!encryptionKey) {
  34862. throw new PasswordException('Incorrect Password', PasswordResponses.INCORRECT_PASSWORD);
  34863. }
  34864. this.encryptionKey = encryptionKey;
  34865. if (algorithm >= 4) {
  34866. var cf = dict.get('CF');
  34867. if (isDict(cf)) {
  34868. // The 'CF' dictionary itself should not be encrypted, and by setting
  34869. // `suppressEncryption` we can prevent an infinite loop inside of
  34870. // `XRef_fetchUncompressed` if the dictionary contains indirect objects
  34871. // (fixes issue7665.pdf).
  34872. cf.suppressEncryption = true;
  34873. }
  34874. this.cf = cf;
  34875. this.stmf = dict.get('StmF') || identityName;
  34876. this.strf = dict.get('StrF') || identityName;
  34877. this.eff = dict.get('EFF') || this.stmf;
  34878. }
  34879. }
  34880. function buildObjectKey(num, gen, encryptionKey, isAes) {
  34881. var key = new Uint8Array(encryptionKey.length + 9), i, n;
  34882. for (i = 0, n = encryptionKey.length; i < n; ++i) {
  34883. key[i] = encryptionKey[i];
  34884. }
  34885. key[i++] = num & 0xFF;
  34886. key[i++] = num >> 8 & 0xFF;
  34887. key[i++] = num >> 16 & 0xFF;
  34888. key[i++] = gen & 0xFF;
  34889. key[i++] = gen >> 8 & 0xFF;
  34890. if (isAes) {
  34891. key[i++] = 0x73;
  34892. key[i++] = 0x41;
  34893. key[i++] = 0x6C;
  34894. key[i++] = 0x54;
  34895. }
  34896. var hash = calculateMD5(key, 0, i);
  34897. return hash.subarray(0, Math.min(encryptionKey.length + 5, 16));
  34898. }
  34899. function buildCipherConstructor(cf, name, num, gen, key) {
  34900. assert(isName(name), 'Invalid crypt filter name.');
  34901. var cryptFilter = cf.get(name.name);
  34902. var cfm;
  34903. if (cryptFilter !== null && cryptFilter !== undefined) {
  34904. cfm = cryptFilter.get('CFM');
  34905. }
  34906. if (!cfm || cfm.name === 'None') {
  34907. return function cipherTransformFactoryBuildCipherConstructorNone() {
  34908. return new NullCipher();
  34909. };
  34910. }
  34911. if ('V2' === cfm.name) {
  34912. return function cipherTransformFactoryBuildCipherConstructorV2() {
  34913. return new ARCFourCipher(buildObjectKey(num, gen, key, false));
  34914. };
  34915. }
  34916. if ('AESV2' === cfm.name) {
  34917. return function cipherTransformFactoryBuildCipherConstructorAESV2() {
  34918. return new AES128Cipher(buildObjectKey(num, gen, key, true));
  34919. };
  34920. }
  34921. if ('AESV3' === cfm.name) {
  34922. return function cipherTransformFactoryBuildCipherConstructorAESV3() {
  34923. return new AES256Cipher(key);
  34924. };
  34925. }
  34926. error('Unknown crypto method');
  34927. }
  34928. CipherTransformFactory.prototype = {
  34929. createCipherTransform: function CipherTransformFactory_createCipherTransform(num, gen) {
  34930. if (this.algorithm === 4 || this.algorithm === 5) {
  34931. return new CipherTransform(buildCipherConstructor(this.cf, this.stmf, num, gen, this.encryptionKey), buildCipherConstructor(this.cf, this.strf, num, gen, this.encryptionKey));
  34932. }
  34933. // algorithms 1 and 2
  34934. var key = buildObjectKey(num, gen, this.encryptionKey, false);
  34935. var cipherConstructor = function buildCipherCipherConstructor() {
  34936. return new ARCFourCipher(key);
  34937. };
  34938. return new CipherTransform(cipherConstructor, cipherConstructor);
  34939. }
  34940. };
  34941. return CipherTransformFactory;
  34942. }();
  34943. exports.AES128Cipher = AES128Cipher;
  34944. exports.AES256Cipher = AES256Cipher;
  34945. exports.ARCFourCipher = ARCFourCipher;
  34946. exports.CipherTransformFactory = CipherTransformFactory;
  34947. exports.PDF17 = PDF17;
  34948. exports.PDF20 = PDF20;
  34949. exports.calculateMD5 = calculateMD5;
  34950. exports.calculateSHA256 = calculateSHA256;
  34951. exports.calculateSHA384 = calculateSHA384;
  34952. exports.calculateSHA512 = calculateSHA512;
  34953. }));
  34954. (function (root, factory) {
  34955. factory(root.pdfjsCoreFontRenderer = {}, root.pdfjsSharedUtil, root.pdfjsCoreStream, root.pdfjsCoreGlyphList, root.pdfjsCoreEncodings, root.pdfjsCoreCFFParser);
  34956. }(this, function (exports, sharedUtil, coreStream, coreGlyphList, coreEncodings, coreCFFParser) {
  34957. var Util = sharedUtil.Util;
  34958. var bytesToString = sharedUtil.bytesToString;
  34959. var error = sharedUtil.error;
  34960. var Stream = coreStream.Stream;
  34961. var getGlyphsUnicode = coreGlyphList.getGlyphsUnicode;
  34962. var StandardEncoding = coreEncodings.StandardEncoding;
  34963. var CFFParser = coreCFFParser.CFFParser;
  34964. var FontRendererFactory = function FontRendererFactoryClosure() {
  34965. function getLong(data, offset) {
  34966. return data[offset] << 24 | data[offset + 1] << 16 | data[offset + 2] << 8 | data[offset + 3];
  34967. }
  34968. function getUshort(data, offset) {
  34969. return data[offset] << 8 | data[offset + 1];
  34970. }
  34971. function parseCmap(data, start, end) {
  34972. var offset = getUshort(data, start + 2) === 1 ? getLong(data, start + 8) : getLong(data, start + 16);
  34973. var format = getUshort(data, start + offset);
  34974. var length, ranges, p, i;
  34975. if (format === 4) {
  34976. length = getUshort(data, start + offset + 2);
  34977. var segCount = getUshort(data, start + offset + 6) >> 1;
  34978. p = start + offset + 14;
  34979. ranges = [];
  34980. for (i = 0; i < segCount; i++, p += 2) {
  34981. ranges[i] = { end: getUshort(data, p) };
  34982. }
  34983. p += 2;
  34984. for (i = 0; i < segCount; i++, p += 2) {
  34985. ranges[i].start = getUshort(data, p);
  34986. }
  34987. for (i = 0; i < segCount; i++, p += 2) {
  34988. ranges[i].idDelta = getUshort(data, p);
  34989. }
  34990. for (i = 0; i < segCount; i++, p += 2) {
  34991. var idOffset = getUshort(data, p);
  34992. if (idOffset === 0) {
  34993. continue;
  34994. }
  34995. ranges[i].ids = [];
  34996. for (var j = 0, jj = ranges[i].end - ranges[i].start + 1; j < jj; j++) {
  34997. ranges[i].ids[j] = getUshort(data, p + idOffset);
  34998. idOffset += 2;
  34999. }
  35000. }
  35001. return ranges;
  35002. } else if (format === 12) {
  35003. length = getLong(data, start + offset + 4);
  35004. var groups = getLong(data, start + offset + 12);
  35005. p = start + offset + 16;
  35006. ranges = [];
  35007. for (i = 0; i < groups; i++) {
  35008. ranges.push({
  35009. start: getLong(data, p),
  35010. end: getLong(data, p + 4),
  35011. idDelta: getLong(data, p + 8) - getLong(data, p)
  35012. });
  35013. p += 12;
  35014. }
  35015. return ranges;
  35016. }
  35017. error('not supported cmap: ' + format);
  35018. }
  35019. function parseCff(data, start, end, seacAnalysisEnabled) {
  35020. var properties = {};
  35021. var parser = new CFFParser(new Stream(data, start, end - start), properties, seacAnalysisEnabled);
  35022. var cff = parser.parse();
  35023. return {
  35024. glyphs: cff.charStrings.objects,
  35025. subrs: cff.topDict.privateDict && cff.topDict.privateDict.subrsIndex && cff.topDict.privateDict.subrsIndex.objects,
  35026. gsubrs: cff.globalSubrIndex && cff.globalSubrIndex.objects
  35027. };
  35028. }
  35029. function parseGlyfTable(glyf, loca, isGlyphLocationsLong) {
  35030. var itemSize, itemDecode;
  35031. if (isGlyphLocationsLong) {
  35032. itemSize = 4;
  35033. itemDecode = function fontItemDecodeLong(data, offset) {
  35034. return data[offset] << 24 | data[offset + 1] << 16 | data[offset + 2] << 8 | data[offset + 3];
  35035. };
  35036. } else {
  35037. itemSize = 2;
  35038. itemDecode = function fontItemDecode(data, offset) {
  35039. return data[offset] << 9 | data[offset + 1] << 1;
  35040. };
  35041. }
  35042. var glyphs = [];
  35043. var startOffset = itemDecode(loca, 0);
  35044. for (var j = itemSize; j < loca.length; j += itemSize) {
  35045. var endOffset = itemDecode(loca, j);
  35046. glyphs.push(glyf.subarray(startOffset, endOffset));
  35047. startOffset = endOffset;
  35048. }
  35049. return glyphs;
  35050. }
  35051. function lookupCmap(ranges, unicode) {
  35052. var code = unicode.charCodeAt(0), gid = 0;
  35053. var l = 0, r = ranges.length - 1;
  35054. while (l < r) {
  35055. var c = l + r + 1 >> 1;
  35056. if (code < ranges[c].start) {
  35057. r = c - 1;
  35058. } else {
  35059. l = c;
  35060. }
  35061. }
  35062. if (ranges[l].start <= code && code <= ranges[l].end) {
  35063. gid = ranges[l].idDelta + (ranges[l].ids ? ranges[l].ids[code - ranges[l].start] : code) & 0xFFFF;
  35064. }
  35065. return {
  35066. charCode: code,
  35067. glyphId: gid
  35068. };
  35069. }
  35070. function compileGlyf(code, cmds, font) {
  35071. function moveTo(x, y) {
  35072. cmds.push({
  35073. cmd: 'moveTo',
  35074. args: [
  35075. x,
  35076. y
  35077. ]
  35078. });
  35079. }
  35080. function lineTo(x, y) {
  35081. cmds.push({
  35082. cmd: 'lineTo',
  35083. args: [
  35084. x,
  35085. y
  35086. ]
  35087. });
  35088. }
  35089. function quadraticCurveTo(xa, ya, x, y) {
  35090. cmds.push({
  35091. cmd: 'quadraticCurveTo',
  35092. args: [
  35093. xa,
  35094. ya,
  35095. x,
  35096. y
  35097. ]
  35098. });
  35099. }
  35100. var i = 0;
  35101. var numberOfContours = (code[i] << 24 | code[i + 1] << 16) >> 16;
  35102. var flags;
  35103. var x = 0, y = 0;
  35104. i += 10;
  35105. if (numberOfContours < 0) {
  35106. // composite glyph
  35107. do {
  35108. flags = code[i] << 8 | code[i + 1];
  35109. var glyphIndex = code[i + 2] << 8 | code[i + 3];
  35110. i += 4;
  35111. var arg1, arg2;
  35112. if (flags & 0x01) {
  35113. arg1 = (code[i] << 24 | code[i + 1] << 16) >> 16;
  35114. arg2 = (code[i + 2] << 24 | code[i + 3] << 16) >> 16;
  35115. i += 4;
  35116. } else {
  35117. arg1 = code[i++];
  35118. arg2 = code[i++];
  35119. }
  35120. if (flags & 0x02) {
  35121. x = arg1;
  35122. y = arg2;
  35123. } else {
  35124. x = 0;
  35125. y = 0;
  35126. }
  35127. // TODO "they are points" ?
  35128. var scaleX = 1, scaleY = 1, scale01 = 0, scale10 = 0;
  35129. if (flags & 0x08) {
  35130. scaleX = scaleY = (code[i] << 24 | code[i + 1] << 16) / 1073741824;
  35131. i += 2;
  35132. } else if (flags & 0x40) {
  35133. scaleX = (code[i] << 24 | code[i + 1] << 16) / 1073741824;
  35134. scaleY = (code[i + 2] << 24 | code[i + 3] << 16) / 1073741824;
  35135. i += 4;
  35136. } else if (flags & 0x80) {
  35137. scaleX = (code[i] << 24 | code[i + 1] << 16) / 1073741824;
  35138. scale01 = (code[i + 2] << 24 | code[i + 3] << 16) / 1073741824;
  35139. scale10 = (code[i + 4] << 24 | code[i + 5] << 16) / 1073741824;
  35140. scaleY = (code[i + 6] << 24 | code[i + 7] << 16) / 1073741824;
  35141. i += 8;
  35142. }
  35143. var subglyph = font.glyphs[glyphIndex];
  35144. if (subglyph) {
  35145. cmds.push({ cmd: 'save' });
  35146. cmds.push({
  35147. cmd: 'transform',
  35148. args: [
  35149. scaleX,
  35150. scale01,
  35151. scale10,
  35152. scaleY,
  35153. x,
  35154. y
  35155. ]
  35156. });
  35157. compileGlyf(subglyph, cmds, font);
  35158. cmds.push({ cmd: 'restore' });
  35159. }
  35160. } while (flags & 0x20);
  35161. } else {
  35162. // simple glyph
  35163. var endPtsOfContours = [];
  35164. var j, jj;
  35165. for (j = 0; j < numberOfContours; j++) {
  35166. endPtsOfContours.push(code[i] << 8 | code[i + 1]);
  35167. i += 2;
  35168. }
  35169. var instructionLength = code[i] << 8 | code[i + 1];
  35170. i += 2 + instructionLength;
  35171. // skipping the instructions
  35172. var numberOfPoints = endPtsOfContours[endPtsOfContours.length - 1] + 1;
  35173. var points = [];
  35174. while (points.length < numberOfPoints) {
  35175. flags = code[i++];
  35176. var repeat = 1;
  35177. if (flags & 0x08) {
  35178. repeat += code[i++];
  35179. }
  35180. while (repeat-- > 0) {
  35181. points.push({ flags: flags });
  35182. }
  35183. }
  35184. for (j = 0; j < numberOfPoints; j++) {
  35185. switch (points[j].flags & 0x12) {
  35186. case 0x00:
  35187. x += (code[i] << 24 | code[i + 1] << 16) >> 16;
  35188. i += 2;
  35189. break;
  35190. case 0x02:
  35191. x -= code[i++];
  35192. break;
  35193. case 0x12:
  35194. x += code[i++];
  35195. break;
  35196. }
  35197. points[j].x = x;
  35198. }
  35199. for (j = 0; j < numberOfPoints; j++) {
  35200. switch (points[j].flags & 0x24) {
  35201. case 0x00:
  35202. y += (code[i] << 24 | code[i + 1] << 16) >> 16;
  35203. i += 2;
  35204. break;
  35205. case 0x04:
  35206. y -= code[i++];
  35207. break;
  35208. case 0x24:
  35209. y += code[i++];
  35210. break;
  35211. }
  35212. points[j].y = y;
  35213. }
  35214. var startPoint = 0;
  35215. for (i = 0; i < numberOfContours; i++) {
  35216. var endPoint = endPtsOfContours[i];
  35217. // contours might have implicit points, which is located in the middle
  35218. // between two neighboring off-curve points
  35219. var contour = points.slice(startPoint, endPoint + 1);
  35220. if (contour[0].flags & 1) {
  35221. contour.push(contour[0]);
  35222. } else // using start point at the contour end
  35223. if (contour[contour.length - 1].flags & 1) {
  35224. // first is off-curve point, trying to use one from the end
  35225. contour.unshift(contour[contour.length - 1]);
  35226. } else {
  35227. // start and end are off-curve points, creating implicit one
  35228. var p = {
  35229. flags: 1,
  35230. x: (contour[0].x + contour[contour.length - 1].x) / 2,
  35231. y: (contour[0].y + contour[contour.length - 1].y) / 2
  35232. };
  35233. contour.unshift(p);
  35234. contour.push(p);
  35235. }
  35236. moveTo(contour[0].x, contour[0].y);
  35237. for (j = 1, jj = contour.length; j < jj; j++) {
  35238. if (contour[j].flags & 1) {
  35239. lineTo(contour[j].x, contour[j].y);
  35240. } else if (contour[j + 1].flags & 1) {
  35241. quadraticCurveTo(contour[j].x, contour[j].y, contour[j + 1].x, contour[j + 1].y);
  35242. j++;
  35243. } else {
  35244. quadraticCurveTo(contour[j].x, contour[j].y, (contour[j].x + contour[j + 1].x) / 2, (contour[j].y + contour[j + 1].y) / 2);
  35245. }
  35246. }
  35247. startPoint = endPoint + 1;
  35248. }
  35249. }
  35250. }
  35251. function compileCharString(code, cmds, font) {
  35252. var stack = [];
  35253. var x = 0, y = 0;
  35254. var stems = 0;
  35255. function moveTo(x, y) {
  35256. cmds.push({
  35257. cmd: 'moveTo',
  35258. args: [
  35259. x,
  35260. y
  35261. ]
  35262. });
  35263. }
  35264. function lineTo(x, y) {
  35265. cmds.push({
  35266. cmd: 'lineTo',
  35267. args: [
  35268. x,
  35269. y
  35270. ]
  35271. });
  35272. }
  35273. function bezierCurveTo(x1, y1, x2, y2, x, y) {
  35274. cmds.push({
  35275. cmd: 'bezierCurveTo',
  35276. args: [
  35277. x1,
  35278. y1,
  35279. x2,
  35280. y2,
  35281. x,
  35282. y
  35283. ]
  35284. });
  35285. }
  35286. function parse(code) {
  35287. var i = 0;
  35288. while (i < code.length) {
  35289. var stackClean = false;
  35290. var v = code[i++];
  35291. var xa, xb, ya, yb, y1, y2, y3, n, subrCode;
  35292. switch (v) {
  35293. case 1:
  35294. // hstem
  35295. stems += stack.length >> 1;
  35296. stackClean = true;
  35297. break;
  35298. case 3:
  35299. // vstem
  35300. stems += stack.length >> 1;
  35301. stackClean = true;
  35302. break;
  35303. case 4:
  35304. // vmoveto
  35305. y += stack.pop();
  35306. moveTo(x, y);
  35307. stackClean = true;
  35308. break;
  35309. case 5:
  35310. // rlineto
  35311. while (stack.length > 0) {
  35312. x += stack.shift();
  35313. y += stack.shift();
  35314. lineTo(x, y);
  35315. }
  35316. break;
  35317. case 6:
  35318. // hlineto
  35319. while (stack.length > 0) {
  35320. x += stack.shift();
  35321. lineTo(x, y);
  35322. if (stack.length === 0) {
  35323. break;
  35324. }
  35325. y += stack.shift();
  35326. lineTo(x, y);
  35327. }
  35328. break;
  35329. case 7:
  35330. // vlineto
  35331. while (stack.length > 0) {
  35332. y += stack.shift();
  35333. lineTo(x, y);
  35334. if (stack.length === 0) {
  35335. break;
  35336. }
  35337. x += stack.shift();
  35338. lineTo(x, y);
  35339. }
  35340. break;
  35341. case 8:
  35342. // rrcurveto
  35343. while (stack.length > 0) {
  35344. xa = x + stack.shift();
  35345. ya = y + stack.shift();
  35346. xb = xa + stack.shift();
  35347. yb = ya + stack.shift();
  35348. x = xb + stack.shift();
  35349. y = yb + stack.shift();
  35350. bezierCurveTo(xa, ya, xb, yb, x, y);
  35351. }
  35352. break;
  35353. case 10:
  35354. // callsubr
  35355. n = stack.pop() + font.subrsBias;
  35356. subrCode = font.subrs[n];
  35357. if (subrCode) {
  35358. parse(subrCode);
  35359. }
  35360. break;
  35361. case 11:
  35362. // return
  35363. return;
  35364. case 12:
  35365. v = code[i++];
  35366. switch (v) {
  35367. case 34:
  35368. // flex
  35369. xa = x + stack.shift();
  35370. xb = xa + stack.shift();
  35371. y1 = y + stack.shift();
  35372. x = xb + stack.shift();
  35373. bezierCurveTo(xa, y, xb, y1, x, y1);
  35374. xa = x + stack.shift();
  35375. xb = xa + stack.shift();
  35376. x = xb + stack.shift();
  35377. bezierCurveTo(xa, y1, xb, y, x, y);
  35378. break;
  35379. case 35:
  35380. // flex
  35381. xa = x + stack.shift();
  35382. ya = y + stack.shift();
  35383. xb = xa + stack.shift();
  35384. yb = ya + stack.shift();
  35385. x = xb + stack.shift();
  35386. y = yb + stack.shift();
  35387. bezierCurveTo(xa, ya, xb, yb, x, y);
  35388. xa = x + stack.shift();
  35389. ya = y + stack.shift();
  35390. xb = xa + stack.shift();
  35391. yb = ya + stack.shift();
  35392. x = xb + stack.shift();
  35393. y = yb + stack.shift();
  35394. bezierCurveTo(xa, ya, xb, yb, x, y);
  35395. stack.pop();
  35396. // fd
  35397. break;
  35398. case 36:
  35399. // hflex1
  35400. xa = x + stack.shift();
  35401. y1 = y + stack.shift();
  35402. xb = xa + stack.shift();
  35403. y2 = y1 + stack.shift();
  35404. x = xb + stack.shift();
  35405. bezierCurveTo(xa, y1, xb, y2, x, y2);
  35406. xa = x + stack.shift();
  35407. xb = xa + stack.shift();
  35408. y3 = y2 + stack.shift();
  35409. x = xb + stack.shift();
  35410. bezierCurveTo(xa, y2, xb, y3, x, y);
  35411. break;
  35412. case 37:
  35413. // flex1
  35414. var x0 = x, y0 = y;
  35415. xa = x + stack.shift();
  35416. ya = y + stack.shift();
  35417. xb = xa + stack.shift();
  35418. yb = ya + stack.shift();
  35419. x = xb + stack.shift();
  35420. y = yb + stack.shift();
  35421. bezierCurveTo(xa, ya, xb, yb, x, y);
  35422. xa = x + stack.shift();
  35423. ya = y + stack.shift();
  35424. xb = xa + stack.shift();
  35425. yb = ya + stack.shift();
  35426. x = xb;
  35427. y = yb;
  35428. if (Math.abs(x - x0) > Math.abs(y - y0)) {
  35429. x += stack.shift();
  35430. } else {
  35431. y += stack.shift();
  35432. }
  35433. bezierCurveTo(xa, ya, xb, yb, x, y);
  35434. break;
  35435. default:
  35436. error('unknown operator: 12 ' + v);
  35437. }
  35438. break;
  35439. case 14:
  35440. // endchar
  35441. if (stack.length >= 4) {
  35442. var achar = stack.pop();
  35443. var bchar = stack.pop();
  35444. y = stack.pop();
  35445. x = stack.pop();
  35446. cmds.push({ cmd: 'save' });
  35447. cmds.push({
  35448. cmd: 'translate',
  35449. args: [
  35450. x,
  35451. y
  35452. ]
  35453. });
  35454. var cmap = lookupCmap(font.cmap, String.fromCharCode(font.glyphNameMap[StandardEncoding[achar]]));
  35455. compileCharString(font.glyphs[cmap.glyphId], cmds, font);
  35456. cmds.push({ cmd: 'restore' });
  35457. cmap = lookupCmap(font.cmap, String.fromCharCode(font.glyphNameMap[StandardEncoding[bchar]]));
  35458. compileCharString(font.glyphs[cmap.glyphId], cmds, font);
  35459. }
  35460. return;
  35461. case 18:
  35462. // hstemhm
  35463. stems += stack.length >> 1;
  35464. stackClean = true;
  35465. break;
  35466. case 19:
  35467. // hintmask
  35468. stems += stack.length >> 1;
  35469. i += stems + 7 >> 3;
  35470. stackClean = true;
  35471. break;
  35472. case 20:
  35473. // cntrmask
  35474. stems += stack.length >> 1;
  35475. i += stems + 7 >> 3;
  35476. stackClean = true;
  35477. break;
  35478. case 21:
  35479. // rmoveto
  35480. y += stack.pop();
  35481. x += stack.pop();
  35482. moveTo(x, y);
  35483. stackClean = true;
  35484. break;
  35485. case 22:
  35486. // hmoveto
  35487. x += stack.pop();
  35488. moveTo(x, y);
  35489. stackClean = true;
  35490. break;
  35491. case 23:
  35492. // vstemhm
  35493. stems += stack.length >> 1;
  35494. stackClean = true;
  35495. break;
  35496. case 24:
  35497. // rcurveline
  35498. while (stack.length > 2) {
  35499. xa = x + stack.shift();
  35500. ya = y + stack.shift();
  35501. xb = xa + stack.shift();
  35502. yb = ya + stack.shift();
  35503. x = xb + stack.shift();
  35504. y = yb + stack.shift();
  35505. bezierCurveTo(xa, ya, xb, yb, x, y);
  35506. }
  35507. x += stack.shift();
  35508. y += stack.shift();
  35509. lineTo(x, y);
  35510. break;
  35511. case 25:
  35512. // rlinecurve
  35513. while (stack.length > 6) {
  35514. x += stack.shift();
  35515. y += stack.shift();
  35516. lineTo(x, y);
  35517. }
  35518. xa = x + stack.shift();
  35519. ya = y + stack.shift();
  35520. xb = xa + stack.shift();
  35521. yb = ya + stack.shift();
  35522. x = xb + stack.shift();
  35523. y = yb + stack.shift();
  35524. bezierCurveTo(xa, ya, xb, yb, x, y);
  35525. break;
  35526. case 26:
  35527. // vvcurveto
  35528. if (stack.length % 2) {
  35529. x += stack.shift();
  35530. }
  35531. while (stack.length > 0) {
  35532. xa = x;
  35533. ya = y + stack.shift();
  35534. xb = xa + stack.shift();
  35535. yb = ya + stack.shift();
  35536. x = xb;
  35537. y = yb + stack.shift();
  35538. bezierCurveTo(xa, ya, xb, yb, x, y);
  35539. }
  35540. break;
  35541. case 27:
  35542. // hhcurveto
  35543. if (stack.length % 2) {
  35544. y += stack.shift();
  35545. }
  35546. while (stack.length > 0) {
  35547. xa = x + stack.shift();
  35548. ya = y;
  35549. xb = xa + stack.shift();
  35550. yb = ya + stack.shift();
  35551. x = xb + stack.shift();
  35552. y = yb;
  35553. bezierCurveTo(xa, ya, xb, yb, x, y);
  35554. }
  35555. break;
  35556. case 28:
  35557. stack.push((code[i] << 24 | code[i + 1] << 16) >> 16);
  35558. i += 2;
  35559. break;
  35560. case 29:
  35561. // callgsubr
  35562. n = stack.pop() + font.gsubrsBias;
  35563. subrCode = font.gsubrs[n];
  35564. if (subrCode) {
  35565. parse(subrCode);
  35566. }
  35567. break;
  35568. case 30:
  35569. // vhcurveto
  35570. while (stack.length > 0) {
  35571. xa = x;
  35572. ya = y + stack.shift();
  35573. xb = xa + stack.shift();
  35574. yb = ya + stack.shift();
  35575. x = xb + stack.shift();
  35576. y = yb + (stack.length === 1 ? stack.shift() : 0);
  35577. bezierCurveTo(xa, ya, xb, yb, x, y);
  35578. if (stack.length === 0) {
  35579. break;
  35580. }
  35581. xa = x + stack.shift();
  35582. ya = y;
  35583. xb = xa + stack.shift();
  35584. yb = ya + stack.shift();
  35585. y = yb + stack.shift();
  35586. x = xb + (stack.length === 1 ? stack.shift() : 0);
  35587. bezierCurveTo(xa, ya, xb, yb, x, y);
  35588. }
  35589. break;
  35590. case 31:
  35591. // hvcurveto
  35592. while (stack.length > 0) {
  35593. xa = x + stack.shift();
  35594. ya = y;
  35595. xb = xa + stack.shift();
  35596. yb = ya + stack.shift();
  35597. y = yb + stack.shift();
  35598. x = xb + (stack.length === 1 ? stack.shift() : 0);
  35599. bezierCurveTo(xa, ya, xb, yb, x, y);
  35600. if (stack.length === 0) {
  35601. break;
  35602. }
  35603. xa = x;
  35604. ya = y + stack.shift();
  35605. xb = xa + stack.shift();
  35606. yb = ya + stack.shift();
  35607. x = xb + stack.shift();
  35608. y = yb + (stack.length === 1 ? stack.shift() : 0);
  35609. bezierCurveTo(xa, ya, xb, yb, x, y);
  35610. }
  35611. break;
  35612. default:
  35613. if (v < 32) {
  35614. error('unknown operator: ' + v);
  35615. }
  35616. if (v < 247) {
  35617. stack.push(v - 139);
  35618. } else if (v < 251) {
  35619. stack.push((v - 247) * 256 + code[i++] + 108);
  35620. } else if (v < 255) {
  35621. stack.push(-(v - 251) * 256 - code[i++] - 108);
  35622. } else {
  35623. stack.push((code[i] << 24 | code[i + 1] << 16 | code[i + 2] << 8 | code[i + 3]) / 65536);
  35624. i += 4;
  35625. }
  35626. break;
  35627. }
  35628. if (stackClean) {
  35629. stack.length = 0;
  35630. }
  35631. }
  35632. }
  35633. parse(code);
  35634. }
  35635. var noop = '';
  35636. function CompiledFont(fontMatrix) {
  35637. this.compiledGlyphs = Object.create(null);
  35638. this.compiledCharCodeToGlyphId = Object.create(null);
  35639. this.fontMatrix = fontMatrix;
  35640. }
  35641. CompiledFont.prototype = {
  35642. getPathJs: function (unicode) {
  35643. var cmap = lookupCmap(this.cmap, unicode);
  35644. var fn = this.compiledGlyphs[cmap.glyphId];
  35645. if (!fn) {
  35646. fn = this.compileGlyph(this.glyphs[cmap.glyphId]);
  35647. this.compiledGlyphs[cmap.glyphId] = fn;
  35648. }
  35649. if (this.compiledCharCodeToGlyphId[cmap.charCode] === undefined) {
  35650. this.compiledCharCodeToGlyphId[cmap.charCode] = cmap.glyphId;
  35651. }
  35652. return fn;
  35653. },
  35654. compileGlyph: function (code) {
  35655. if (!code || code.length === 0 || code[0] === 14) {
  35656. return noop;
  35657. }
  35658. var cmds = [];
  35659. cmds.push({ cmd: 'save' });
  35660. cmds.push({
  35661. cmd: 'transform',
  35662. args: this.fontMatrix.slice()
  35663. });
  35664. cmds.push({
  35665. cmd: 'scale',
  35666. args: [
  35667. 'size',
  35668. '-size'
  35669. ]
  35670. });
  35671. this.compileGlyphImpl(code, cmds);
  35672. cmds.push({ cmd: 'restore' });
  35673. return cmds;
  35674. },
  35675. compileGlyphImpl: function () {
  35676. error('Children classes should implement this.');
  35677. },
  35678. hasBuiltPath: function (unicode) {
  35679. var cmap = lookupCmap(this.cmap, unicode);
  35680. return this.compiledGlyphs[cmap.glyphId] !== undefined && this.compiledCharCodeToGlyphId[cmap.charCode] !== undefined;
  35681. }
  35682. };
  35683. function TrueTypeCompiled(glyphs, cmap, fontMatrix) {
  35684. fontMatrix = fontMatrix || [
  35685. 0.000488,
  35686. 0,
  35687. 0,
  35688. 0.000488,
  35689. 0,
  35690. 0
  35691. ];
  35692. CompiledFont.call(this, fontMatrix);
  35693. this.glyphs = glyphs;
  35694. this.cmap = cmap;
  35695. }
  35696. Util.inherit(TrueTypeCompiled, CompiledFont, {
  35697. compileGlyphImpl: function (code, cmds) {
  35698. compileGlyf(code, cmds, this);
  35699. }
  35700. });
  35701. function Type2Compiled(cffInfo, cmap, fontMatrix, glyphNameMap) {
  35702. fontMatrix = fontMatrix || [
  35703. 0.001,
  35704. 0,
  35705. 0,
  35706. 0.001,
  35707. 0,
  35708. 0
  35709. ];
  35710. CompiledFont.call(this, fontMatrix);
  35711. this.glyphs = cffInfo.glyphs;
  35712. this.gsubrs = cffInfo.gsubrs || [];
  35713. this.subrs = cffInfo.subrs || [];
  35714. this.cmap = cmap;
  35715. this.glyphNameMap = glyphNameMap || getGlyphsUnicode();
  35716. this.gsubrsBias = this.gsubrs.length < 1240 ? 107 : this.gsubrs.length < 33900 ? 1131 : 32768;
  35717. this.subrsBias = this.subrs.length < 1240 ? 107 : this.subrs.length < 33900 ? 1131 : 32768;
  35718. }
  35719. Util.inherit(Type2Compiled, CompiledFont, {
  35720. compileGlyphImpl: function (code, cmds) {
  35721. compileCharString(code, cmds, this);
  35722. }
  35723. });
  35724. return {
  35725. create: function FontRendererFactory_create(font, seacAnalysisEnabled) {
  35726. var data = new Uint8Array(font.data);
  35727. var cmap, glyf, loca, cff, indexToLocFormat, unitsPerEm;
  35728. var numTables = getUshort(data, 4);
  35729. for (var i = 0, p = 12; i < numTables; i++, p += 16) {
  35730. var tag = bytesToString(data.subarray(p, p + 4));
  35731. var offset = getLong(data, p + 8);
  35732. var length = getLong(data, p + 12);
  35733. switch (tag) {
  35734. case 'cmap':
  35735. cmap = parseCmap(data, offset, offset + length);
  35736. break;
  35737. case 'glyf':
  35738. glyf = data.subarray(offset, offset + length);
  35739. break;
  35740. case 'loca':
  35741. loca = data.subarray(offset, offset + length);
  35742. break;
  35743. case 'head':
  35744. unitsPerEm = getUshort(data, offset + 18);
  35745. indexToLocFormat = getUshort(data, offset + 50);
  35746. break;
  35747. case 'CFF ':
  35748. cff = parseCff(data, offset, offset + length, seacAnalysisEnabled);
  35749. break;
  35750. }
  35751. }
  35752. if (glyf) {
  35753. var fontMatrix = !unitsPerEm ? font.fontMatrix : [
  35754. 1 / unitsPerEm,
  35755. 0,
  35756. 0,
  35757. 1 / unitsPerEm,
  35758. 0,
  35759. 0
  35760. ];
  35761. return new TrueTypeCompiled(parseGlyfTable(glyf, loca, indexToLocFormat), cmap, fontMatrix);
  35762. } else {
  35763. return new Type2Compiled(cff, cmap, font.fontMatrix, font.glyphNameMap);
  35764. }
  35765. }
  35766. };
  35767. }();
  35768. exports.FontRendererFactory = FontRendererFactory;
  35769. }));
  35770. (function (root, factory) {
  35771. factory(root.pdfjsCoreParser = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCoreStream);
  35772. }(this, function (exports, sharedUtil, corePrimitives, coreStream) {
  35773. var MissingDataException = sharedUtil.MissingDataException;
  35774. var StreamType = sharedUtil.StreamType;
  35775. var assert = sharedUtil.assert;
  35776. var error = sharedUtil.error;
  35777. var info = sharedUtil.info;
  35778. var isArray = sharedUtil.isArray;
  35779. var isInt = sharedUtil.isInt;
  35780. var isNum = sharedUtil.isNum;
  35781. var isString = sharedUtil.isString;
  35782. var warn = sharedUtil.warn;
  35783. var Cmd = corePrimitives.Cmd;
  35784. var Dict = corePrimitives.Dict;
  35785. var Name = corePrimitives.Name;
  35786. var Ref = corePrimitives.Ref;
  35787. var isCmd = corePrimitives.isCmd;
  35788. var isDict = corePrimitives.isDict;
  35789. var isName = corePrimitives.isName;
  35790. var Ascii85Stream = coreStream.Ascii85Stream;
  35791. var AsciiHexStream = coreStream.AsciiHexStream;
  35792. var CCITTFaxStream = coreStream.CCITTFaxStream;
  35793. var FlateStream = coreStream.FlateStream;
  35794. var Jbig2Stream = coreStream.Jbig2Stream;
  35795. var JpegStream = coreStream.JpegStream;
  35796. var JpxStream = coreStream.JpxStream;
  35797. var LZWStream = coreStream.LZWStream;
  35798. var NullStream = coreStream.NullStream;
  35799. var PredictorStream = coreStream.PredictorStream;
  35800. var RunLengthStream = coreStream.RunLengthStream;
  35801. var EOF = {};
  35802. function isEOF(v) {
  35803. return v === EOF;
  35804. }
  35805. var MAX_LENGTH_TO_CACHE = 1000;
  35806. var Parser = function ParserClosure() {
  35807. function Parser(lexer, allowStreams, xref, recoveryMode) {
  35808. this.lexer = lexer;
  35809. this.allowStreams = allowStreams;
  35810. this.xref = xref;
  35811. this.recoveryMode = recoveryMode || false;
  35812. this.imageCache = Object.create(null);
  35813. this.refill();
  35814. }
  35815. Parser.prototype = {
  35816. refill: function Parser_refill() {
  35817. this.buf1 = this.lexer.getObj();
  35818. this.buf2 = this.lexer.getObj();
  35819. },
  35820. shift: function Parser_shift() {
  35821. if (isCmd(this.buf2, 'ID')) {
  35822. this.buf1 = this.buf2;
  35823. this.buf2 = null;
  35824. } else {
  35825. this.buf1 = this.buf2;
  35826. this.buf2 = this.lexer.getObj();
  35827. }
  35828. },
  35829. tryShift: function Parser_tryShift() {
  35830. try {
  35831. this.shift();
  35832. return true;
  35833. } catch (e) {
  35834. if (e instanceof MissingDataException) {
  35835. throw e;
  35836. }
  35837. // Upon failure, the caller should reset this.lexer.pos to a known good
  35838. // state and call this.shift() twice to reset the buffers.
  35839. return false;
  35840. }
  35841. },
  35842. getObj: function Parser_getObj(cipherTransform) {
  35843. var buf1 = this.buf1;
  35844. this.shift();
  35845. if (buf1 instanceof Cmd) {
  35846. switch (buf1.cmd) {
  35847. case 'BI':
  35848. // inline image
  35849. return this.makeInlineImage(cipherTransform);
  35850. case '[':
  35851. // array
  35852. var array = [];
  35853. while (!isCmd(this.buf1, ']') && !isEOF(this.buf1)) {
  35854. array.push(this.getObj(cipherTransform));
  35855. }
  35856. if (isEOF(this.buf1)) {
  35857. if (!this.recoveryMode) {
  35858. error('End of file inside array');
  35859. }
  35860. return array;
  35861. }
  35862. this.shift();
  35863. return array;
  35864. case '<<':
  35865. // dictionary or stream
  35866. var dict = new Dict(this.xref);
  35867. while (!isCmd(this.buf1, '>>') && !isEOF(this.buf1)) {
  35868. if (!isName(this.buf1)) {
  35869. info('Malformed dictionary: key must be a name object');
  35870. this.shift();
  35871. continue;
  35872. }
  35873. var key = this.buf1.name;
  35874. this.shift();
  35875. if (isEOF(this.buf1)) {
  35876. break;
  35877. }
  35878. dict.set(key, this.getObj(cipherTransform));
  35879. }
  35880. if (isEOF(this.buf1)) {
  35881. if (!this.recoveryMode) {
  35882. error('End of file inside dictionary');
  35883. }
  35884. return dict;
  35885. }
  35886. // Stream objects are not allowed inside content streams or
  35887. // object streams.
  35888. if (isCmd(this.buf2, 'stream')) {
  35889. return this.allowStreams ? this.makeStream(dict, cipherTransform) : dict;
  35890. }
  35891. this.shift();
  35892. return dict;
  35893. default:
  35894. // simple object
  35895. return buf1;
  35896. }
  35897. }
  35898. if (isInt(buf1)) {
  35899. // indirect reference or integer
  35900. var num = buf1;
  35901. if (isInt(this.buf1) && isCmd(this.buf2, 'R')) {
  35902. var ref = new Ref(num, this.buf1);
  35903. this.shift();
  35904. this.shift();
  35905. return ref;
  35906. }
  35907. return num;
  35908. }
  35909. if (isString(buf1)) {
  35910. // string
  35911. var str = buf1;
  35912. if (cipherTransform) {
  35913. str = cipherTransform.decryptString(str);
  35914. }
  35915. return str;
  35916. }
  35917. // simple object
  35918. return buf1;
  35919. },
  35920. /**
  35921. * Find the end of the stream by searching for the /EI\s/.
  35922. * @returns {number} The inline stream length.
  35923. */
  35924. findDefaultInlineStreamEnd: function Parser_findDefaultInlineStreamEnd(stream) {
  35925. var E = 0x45, I = 0x49, SPACE = 0x20, LF = 0xA, CR = 0xD;
  35926. var startPos = stream.pos, state = 0, ch, i, n, followingBytes;
  35927. while ((ch = stream.getByte()) !== -1) {
  35928. if (state === 0) {
  35929. state = ch === E ? 1 : 0;
  35930. } else if (state === 1) {
  35931. state = ch === I ? 2 : 0;
  35932. } else {
  35933. assert(state === 2);
  35934. if (ch === SPACE || ch === LF || ch === CR) {
  35935. // Let's check the next five bytes are ASCII... just be sure.
  35936. n = 5;
  35937. followingBytes = stream.peekBytes(n);
  35938. for (i = 0; i < n; i++) {
  35939. ch = followingBytes[i];
  35940. if (ch !== LF && ch !== CR && (ch < SPACE || ch > 0x7F)) {
  35941. // Not a LF, CR, SPACE or any visible ASCII character, i.e.
  35942. // it's binary stuff. Resetting the state.
  35943. state = 0;
  35944. break;
  35945. }
  35946. }
  35947. if (state === 2) {
  35948. break;
  35949. }
  35950. } else
  35951. // Finished!
  35952. {
  35953. state = 0;
  35954. }
  35955. }
  35956. }
  35957. return stream.pos - 4 - startPos;
  35958. },
  35959. /**
  35960. * Find the EOI (end-of-image) marker 0xFFD9 of the stream.
  35961. * @returns {number} The inline stream length.
  35962. */
  35963. findDCTDecodeInlineStreamEnd: function Parser_findDCTDecodeInlineStreamEnd(stream) {
  35964. var startPos = stream.pos, foundEOI = false, b, markerLength, length;
  35965. while ((b = stream.getByte()) !== -1) {
  35966. if (b !== 0xFF) {
  35967. // Not a valid marker.
  35968. continue;
  35969. }
  35970. switch (stream.getByte()) {
  35971. case 0x00:
  35972. // Byte stuffing.
  35973. // 0xFF00 appears to be a very common byte sequence in JPEG images.
  35974. break;
  35975. case 0xFF:
  35976. // Fill byte.
  35977. // Avoid skipping a valid marker, resetting the stream position.
  35978. stream.skip(-1);
  35979. break;
  35980. case 0xD9:
  35981. // EOI
  35982. foundEOI = true;
  35983. break;
  35984. case 0xC0:
  35985. // SOF0
  35986. case 0xC1:
  35987. // SOF1
  35988. case 0xC2:
  35989. // SOF2
  35990. case 0xC3:
  35991. // SOF3
  35992. case 0xC5:
  35993. // SOF5
  35994. case 0xC6:
  35995. // SOF6
  35996. case 0xC7:
  35997. // SOF7
  35998. case 0xC9:
  35999. // SOF9
  36000. case 0xCA:
  36001. // SOF10
  36002. case 0xCB:
  36003. // SOF11
  36004. case 0xCD:
  36005. // SOF13
  36006. case 0xCE:
  36007. // SOF14
  36008. case 0xCF:
  36009. // SOF15
  36010. case 0xC4:
  36011. // DHT
  36012. case 0xCC:
  36013. // DAC
  36014. case 0xDA:
  36015. // SOS
  36016. case 0xDB:
  36017. // DQT
  36018. case 0xDC:
  36019. // DNL
  36020. case 0xDD:
  36021. // DRI
  36022. case 0xDE:
  36023. // DHP
  36024. case 0xDF:
  36025. // EXP
  36026. case 0xE0:
  36027. // APP0
  36028. case 0xE1:
  36029. // APP1
  36030. case 0xE2:
  36031. // APP2
  36032. case 0xE3:
  36033. // APP3
  36034. case 0xE4:
  36035. // APP4
  36036. case 0xE5:
  36037. // APP5
  36038. case 0xE6:
  36039. // APP6
  36040. case 0xE7:
  36041. // APP7
  36042. case 0xE8:
  36043. // APP8
  36044. case 0xE9:
  36045. // APP9
  36046. case 0xEA:
  36047. // APP10
  36048. case 0xEB:
  36049. // APP11
  36050. case 0xEC:
  36051. // APP12
  36052. case 0xED:
  36053. // APP13
  36054. case 0xEE:
  36055. // APP14
  36056. case 0xEF:
  36057. // APP15
  36058. case 0xFE:
  36059. // COM
  36060. // The marker should be followed by the length of the segment.
  36061. markerLength = stream.getUint16();
  36062. if (markerLength > 2) {
  36063. // |markerLength| contains the byte length of the marker segment,
  36064. // including its own length (2 bytes) and excluding the marker.
  36065. stream.skip(markerLength - 2);
  36066. } else
  36067. // Jump to the next marker.
  36068. {
  36069. // The marker length is invalid, resetting the stream position.
  36070. stream.skip(-2);
  36071. }
  36072. break;
  36073. }
  36074. if (foundEOI) {
  36075. break;
  36076. }
  36077. }
  36078. length = stream.pos - startPos;
  36079. if (b === -1) {
  36080. warn('Inline DCTDecode image stream: ' + 'EOI marker not found, searching for /EI/ instead.');
  36081. stream.skip(-length);
  36082. // Reset the stream position.
  36083. return this.findDefaultInlineStreamEnd(stream);
  36084. }
  36085. this.inlineStreamSkipEI(stream);
  36086. return length;
  36087. },
  36088. /**
  36089. * Find the EOD (end-of-data) marker '~>' (i.e. TILDE + GT) of the stream.
  36090. * @returns {number} The inline stream length.
  36091. */
  36092. findASCII85DecodeInlineStreamEnd: function Parser_findASCII85DecodeInlineStreamEnd(stream) {
  36093. var TILDE = 0x7E, GT = 0x3E;
  36094. var startPos = stream.pos, ch, length;
  36095. while ((ch = stream.getByte()) !== -1) {
  36096. if (ch === TILDE && stream.peekByte() === GT) {
  36097. stream.skip();
  36098. break;
  36099. }
  36100. }
  36101. length = stream.pos - startPos;
  36102. if (ch === -1) {
  36103. warn('Inline ASCII85Decode image stream: ' + 'EOD marker not found, searching for /EI/ instead.');
  36104. stream.skip(-length);
  36105. // Reset the stream position.
  36106. return this.findDefaultInlineStreamEnd(stream);
  36107. }
  36108. this.inlineStreamSkipEI(stream);
  36109. return length;
  36110. },
  36111. /**
  36112. * Find the EOD (end-of-data) marker '>' (i.e. GT) of the stream.
  36113. * @returns {number} The inline stream length.
  36114. */
  36115. findASCIIHexDecodeInlineStreamEnd: function Parser_findASCIIHexDecodeInlineStreamEnd(stream) {
  36116. var GT = 0x3E;
  36117. var startPos = stream.pos, ch, length;
  36118. while ((ch = stream.getByte()) !== -1) {
  36119. if (ch === GT) {
  36120. break;
  36121. }
  36122. }
  36123. length = stream.pos - startPos;
  36124. if (ch === -1) {
  36125. warn('Inline ASCIIHexDecode image stream: ' + 'EOD marker not found, searching for /EI/ instead.');
  36126. stream.skip(-length);
  36127. // Reset the stream position.
  36128. return this.findDefaultInlineStreamEnd(stream);
  36129. }
  36130. this.inlineStreamSkipEI(stream);
  36131. return length;
  36132. },
  36133. /**
  36134. * Skip over the /EI/ for streams where we search for an EOD marker.
  36135. */
  36136. inlineStreamSkipEI: function Parser_inlineStreamSkipEI(stream) {
  36137. var E = 0x45, I = 0x49;
  36138. var state = 0, ch;
  36139. while ((ch = stream.getByte()) !== -1) {
  36140. if (state === 0) {
  36141. state = ch === E ? 1 : 0;
  36142. } else if (state === 1) {
  36143. state = ch === I ? 2 : 0;
  36144. } else if (state === 2) {
  36145. break;
  36146. }
  36147. }
  36148. },
  36149. makeInlineImage: function Parser_makeInlineImage(cipherTransform) {
  36150. var lexer = this.lexer;
  36151. var stream = lexer.stream;
  36152. // Parse dictionary.
  36153. var dict = new Dict(this.xref);
  36154. while (!isCmd(this.buf1, 'ID') && !isEOF(this.buf1)) {
  36155. if (!isName(this.buf1)) {
  36156. error('Dictionary key must be a name object');
  36157. }
  36158. var key = this.buf1.name;
  36159. this.shift();
  36160. if (isEOF(this.buf1)) {
  36161. break;
  36162. }
  36163. dict.set(key, this.getObj(cipherTransform));
  36164. }
  36165. // Extract the name of the first (i.e. the current) image filter.
  36166. var filter = dict.get('Filter', 'F'), filterName;
  36167. if (isName(filter)) {
  36168. filterName = filter.name;
  36169. } else if (isArray(filter) && isName(filter[0])) {
  36170. filterName = filter[0].name;
  36171. }
  36172. // Parse image stream.
  36173. var startPos = stream.pos, length, i, ii;
  36174. if (filterName === 'DCTDecode' || filterName === 'DCT') {
  36175. length = this.findDCTDecodeInlineStreamEnd(stream);
  36176. } else if (filterName === 'ASCII85Decide' || filterName === 'A85') {
  36177. length = this.findASCII85DecodeInlineStreamEnd(stream);
  36178. } else if (filterName === 'ASCIIHexDecode' || filterName === 'AHx') {
  36179. length = this.findASCIIHexDecodeInlineStreamEnd(stream);
  36180. } else {
  36181. length = this.findDefaultInlineStreamEnd(stream);
  36182. }
  36183. var imageStream = stream.makeSubStream(startPos, length, dict);
  36184. // Cache all images below the MAX_LENGTH_TO_CACHE threshold by their
  36185. // adler32 checksum.
  36186. var adler32;
  36187. if (length < MAX_LENGTH_TO_CACHE) {
  36188. var imageBytes = imageStream.getBytes();
  36189. imageStream.reset();
  36190. var a = 1;
  36191. var b = 0;
  36192. for (i = 0, ii = imageBytes.length; i < ii; ++i) {
  36193. // No modulo required in the loop if imageBytes.length < 5552.
  36194. a += imageBytes[i] & 0xff;
  36195. b += a;
  36196. }
  36197. adler32 = b % 65521 << 16 | a % 65521;
  36198. if (this.imageCache.adler32 === adler32) {
  36199. this.buf2 = Cmd.get('EI');
  36200. this.shift();
  36201. this.imageCache[adler32].reset();
  36202. return this.imageCache[adler32];
  36203. }
  36204. }
  36205. if (cipherTransform) {
  36206. imageStream = cipherTransform.createStream(imageStream, length);
  36207. }
  36208. imageStream = this.filter(imageStream, dict, length);
  36209. imageStream.dict = dict;
  36210. if (adler32 !== undefined) {
  36211. imageStream.cacheKey = 'inline_' + length + '_' + adler32;
  36212. this.imageCache[adler32] = imageStream;
  36213. }
  36214. this.buf2 = Cmd.get('EI');
  36215. this.shift();
  36216. return imageStream;
  36217. },
  36218. makeStream: function Parser_makeStream(dict, cipherTransform) {
  36219. var lexer = this.lexer;
  36220. var stream = lexer.stream;
  36221. // get stream start position
  36222. lexer.skipToNextLine();
  36223. var pos = stream.pos - 1;
  36224. // get length
  36225. var length = dict.get('Length');
  36226. if (!isInt(length)) {
  36227. info('Bad ' + length + ' attribute in stream');
  36228. length = 0;
  36229. }
  36230. // skip over the stream data
  36231. stream.pos = pos + length;
  36232. lexer.nextChar();
  36233. // Shift '>>' and check whether the new object marks the end of the stream
  36234. if (this.tryShift() && isCmd(this.buf2, 'endstream')) {
  36235. this.shift();
  36236. } else
  36237. // 'stream'
  36238. {
  36239. // bad stream length, scanning for endstream
  36240. stream.pos = pos;
  36241. var SCAN_BLOCK_SIZE = 2048;
  36242. var ENDSTREAM_SIGNATURE_LENGTH = 9;
  36243. var ENDSTREAM_SIGNATURE = [
  36244. 0x65,
  36245. 0x6E,
  36246. 0x64,
  36247. 0x73,
  36248. 0x74,
  36249. 0x72,
  36250. 0x65,
  36251. 0x61,
  36252. 0x6D
  36253. ];
  36254. var skipped = 0, found = false, i, j;
  36255. while (stream.pos < stream.end) {
  36256. var scanBytes = stream.peekBytes(SCAN_BLOCK_SIZE);
  36257. var scanLength = scanBytes.length - ENDSTREAM_SIGNATURE_LENGTH;
  36258. if (scanLength <= 0) {
  36259. break;
  36260. }
  36261. found = false;
  36262. i = 0;
  36263. while (i < scanLength) {
  36264. j = 0;
  36265. while (j < ENDSTREAM_SIGNATURE_LENGTH && scanBytes[i + j] === ENDSTREAM_SIGNATURE[j]) {
  36266. j++;
  36267. }
  36268. if (j >= ENDSTREAM_SIGNATURE_LENGTH) {
  36269. found = true;
  36270. break;
  36271. }
  36272. i++;
  36273. }
  36274. if (found) {
  36275. skipped += i;
  36276. stream.pos += i;
  36277. break;
  36278. }
  36279. skipped += scanLength;
  36280. stream.pos += scanLength;
  36281. }
  36282. if (!found) {
  36283. error('Missing endstream');
  36284. }
  36285. length = skipped;
  36286. lexer.nextChar();
  36287. this.shift();
  36288. this.shift();
  36289. }
  36290. this.shift();
  36291. // 'endstream'
  36292. stream = stream.makeSubStream(pos, length, dict);
  36293. if (cipherTransform) {
  36294. stream = cipherTransform.createStream(stream, length);
  36295. }
  36296. stream = this.filter(stream, dict, length);
  36297. stream.dict = dict;
  36298. return stream;
  36299. },
  36300. filter: function Parser_filter(stream, dict, length) {
  36301. var filter = dict.get('Filter', 'F');
  36302. var params = dict.get('DecodeParms', 'DP');
  36303. if (isName(filter)) {
  36304. if (isArray(params)) {
  36305. params = params[0];
  36306. }
  36307. return this.makeFilter(stream, filter.name, length, params);
  36308. }
  36309. var maybeLength = length;
  36310. if (isArray(filter)) {
  36311. var filterArray = filter;
  36312. var paramsArray = params;
  36313. for (var i = 0, ii = filterArray.length; i < ii; ++i) {
  36314. filter = filterArray[i];
  36315. if (!isName(filter)) {
  36316. error('Bad filter name: ' + filter);
  36317. }
  36318. params = null;
  36319. if (isArray(paramsArray) && i in paramsArray) {
  36320. params = paramsArray[i];
  36321. }
  36322. stream = this.makeFilter(stream, filter.name, maybeLength, params);
  36323. // after the first stream the length variable is invalid
  36324. maybeLength = null;
  36325. }
  36326. }
  36327. return stream;
  36328. },
  36329. makeFilter: function Parser_makeFilter(stream, name, maybeLength, params) {
  36330. // Since the 'Length' entry in the stream dictionary can be completely
  36331. // wrong, e.g. zero for non-empty streams, only skip parsing the stream
  36332. // when we can be absolutely certain that it actually is empty.
  36333. if (maybeLength === 0) {
  36334. warn('Empty "' + name + '" stream.');
  36335. return new NullStream(stream);
  36336. }
  36337. try {
  36338. if (params && this.xref) {
  36339. params = this.xref.fetchIfRef(params);
  36340. }
  36341. var xrefStreamStats = this.xref.stats.streamTypes;
  36342. if (name === 'FlateDecode' || name === 'Fl') {
  36343. xrefStreamStats[StreamType.FLATE] = true;
  36344. if (params) {
  36345. return new PredictorStream(new FlateStream(stream, maybeLength), maybeLength, params);
  36346. }
  36347. return new FlateStream(stream, maybeLength);
  36348. }
  36349. if (name === 'LZWDecode' || name === 'LZW') {
  36350. xrefStreamStats[StreamType.LZW] = true;
  36351. var earlyChange = 1;
  36352. if (params) {
  36353. if (params.has('EarlyChange')) {
  36354. earlyChange = params.get('EarlyChange');
  36355. }
  36356. return new PredictorStream(new LZWStream(stream, maybeLength, earlyChange), maybeLength, params);
  36357. }
  36358. return new LZWStream(stream, maybeLength, earlyChange);
  36359. }
  36360. if (name === 'DCTDecode' || name === 'DCT') {
  36361. xrefStreamStats[StreamType.DCT] = true;
  36362. return new JpegStream(stream, maybeLength, stream.dict, params);
  36363. }
  36364. if (name === 'JPXDecode' || name === 'JPX') {
  36365. xrefStreamStats[StreamType.JPX] = true;
  36366. return new JpxStream(stream, maybeLength, stream.dict, params);
  36367. }
  36368. if (name === 'ASCII85Decode' || name === 'A85') {
  36369. xrefStreamStats[StreamType.A85] = true;
  36370. return new Ascii85Stream(stream, maybeLength);
  36371. }
  36372. if (name === 'ASCIIHexDecode' || name === 'AHx') {
  36373. xrefStreamStats[StreamType.AHX] = true;
  36374. return new AsciiHexStream(stream, maybeLength);
  36375. }
  36376. if (name === 'CCITTFaxDecode' || name === 'CCF') {
  36377. xrefStreamStats[StreamType.CCF] = true;
  36378. return new CCITTFaxStream(stream, maybeLength, params);
  36379. }
  36380. if (name === 'RunLengthDecode' || name === 'RL') {
  36381. xrefStreamStats[StreamType.RL] = true;
  36382. return new RunLengthStream(stream, maybeLength);
  36383. }
  36384. if (name === 'JBIG2Decode') {
  36385. xrefStreamStats[StreamType.JBIG] = true;
  36386. return new Jbig2Stream(stream, maybeLength, stream.dict, params);
  36387. }
  36388. warn('filter "' + name + '" not supported yet');
  36389. return stream;
  36390. } catch (ex) {
  36391. if (ex instanceof MissingDataException) {
  36392. throw ex;
  36393. }
  36394. warn('Invalid stream: \"' + ex + '\"');
  36395. return new NullStream(stream);
  36396. }
  36397. }
  36398. };
  36399. return Parser;
  36400. }();
  36401. var Lexer = function LexerClosure() {
  36402. function Lexer(stream, knownCommands) {
  36403. this.stream = stream;
  36404. this.nextChar();
  36405. // While lexing, we build up many strings one char at a time. Using += for
  36406. // this can result in lots of garbage strings. It's better to build an
  36407. // array of single-char strings and then join() them together at the end.
  36408. // And reusing a single array (i.e. |this.strBuf|) over and over for this
  36409. // purpose uses less memory than using a new array for each string.
  36410. this.strBuf = [];
  36411. // The PDFs might have "glued" commands with other commands, operands or
  36412. // literals, e.g. "q1". The knownCommands is a dictionary of the valid
  36413. // commands and their prefixes. The prefixes are built the following way:
  36414. // if there a command that is a prefix of the other valid command or
  36415. // literal (e.g. 'f' and 'false') the following prefixes must be included,
  36416. // 'fa', 'fal', 'fals'. The prefixes are not needed, if the command has no
  36417. // other commands or literals as a prefix. The knowCommands is optional.
  36418. this.knownCommands = knownCommands;
  36419. }
  36420. // A '1' in this array means the character is white space. A '1' or
  36421. // '2' means the character ends a name or command.
  36422. var specialChars = [
  36423. 1,
  36424. 0,
  36425. 0,
  36426. 0,
  36427. 0,
  36428. 0,
  36429. 0,
  36430. 0,
  36431. 0,
  36432. 1,
  36433. 1,
  36434. 0,
  36435. 1,
  36436. 1,
  36437. 0,
  36438. 0,
  36439. // 0x
  36440. 0,
  36441. 0,
  36442. 0,
  36443. 0,
  36444. 0,
  36445. 0,
  36446. 0,
  36447. 0,
  36448. 0,
  36449. 0,
  36450. 0,
  36451. 0,
  36452. 0,
  36453. 0,
  36454. 0,
  36455. 0,
  36456. // 1x
  36457. 1,
  36458. 0,
  36459. 0,
  36460. 0,
  36461. 0,
  36462. 2,
  36463. 0,
  36464. 0,
  36465. 2,
  36466. 2,
  36467. 0,
  36468. 0,
  36469. 0,
  36470. 0,
  36471. 0,
  36472. 2,
  36473. // 2x
  36474. 0,
  36475. 0,
  36476. 0,
  36477. 0,
  36478. 0,
  36479. 0,
  36480. 0,
  36481. 0,
  36482. 0,
  36483. 0,
  36484. 0,
  36485. 0,
  36486. 2,
  36487. 0,
  36488. 2,
  36489. 0,
  36490. // 3x
  36491. 0,
  36492. 0,
  36493. 0,
  36494. 0,
  36495. 0,
  36496. 0,
  36497. 0,
  36498. 0,
  36499. 0,
  36500. 0,
  36501. 0,
  36502. 0,
  36503. 0,
  36504. 0,
  36505. 0,
  36506. 0,
  36507. // 4x
  36508. 0,
  36509. 0,
  36510. 0,
  36511. 0,
  36512. 0,
  36513. 0,
  36514. 0,
  36515. 0,
  36516. 0,
  36517. 0,
  36518. 0,
  36519. 2,
  36520. 0,
  36521. 2,
  36522. 0,
  36523. 0,
  36524. // 5x
  36525. 0,
  36526. 0,
  36527. 0,
  36528. 0,
  36529. 0,
  36530. 0,
  36531. 0,
  36532. 0,
  36533. 0,
  36534. 0,
  36535. 0,
  36536. 0,
  36537. 0,
  36538. 0,
  36539. 0,
  36540. 0,
  36541. // 6x
  36542. 0,
  36543. 0,
  36544. 0,
  36545. 0,
  36546. 0,
  36547. 0,
  36548. 0,
  36549. 0,
  36550. 0,
  36551. 0,
  36552. 0,
  36553. 2,
  36554. 0,
  36555. 2,
  36556. 0,
  36557. 0,
  36558. // 7x
  36559. 0,
  36560. 0,
  36561. 0,
  36562. 0,
  36563. 0,
  36564. 0,
  36565. 0,
  36566. 0,
  36567. 0,
  36568. 0,
  36569. 0,
  36570. 0,
  36571. 0,
  36572. 0,
  36573. 0,
  36574. 0,
  36575. // 8x
  36576. 0,
  36577. 0,
  36578. 0,
  36579. 0,
  36580. 0,
  36581. 0,
  36582. 0,
  36583. 0,
  36584. 0,
  36585. 0,
  36586. 0,
  36587. 0,
  36588. 0,
  36589. 0,
  36590. 0,
  36591. 0,
  36592. // 9x
  36593. 0,
  36594. 0,
  36595. 0,
  36596. 0,
  36597. 0,
  36598. 0,
  36599. 0,
  36600. 0,
  36601. 0,
  36602. 0,
  36603. 0,
  36604. 0,
  36605. 0,
  36606. 0,
  36607. 0,
  36608. 0,
  36609. // ax
  36610. 0,
  36611. 0,
  36612. 0,
  36613. 0,
  36614. 0,
  36615. 0,
  36616. 0,
  36617. 0,
  36618. 0,
  36619. 0,
  36620. 0,
  36621. 0,
  36622. 0,
  36623. 0,
  36624. 0,
  36625. 0,
  36626. // bx
  36627. 0,
  36628. 0,
  36629. 0,
  36630. 0,
  36631. 0,
  36632. 0,
  36633. 0,
  36634. 0,
  36635. 0,
  36636. 0,
  36637. 0,
  36638. 0,
  36639. 0,
  36640. 0,
  36641. 0,
  36642. 0,
  36643. // cx
  36644. 0,
  36645. 0,
  36646. 0,
  36647. 0,
  36648. 0,
  36649. 0,
  36650. 0,
  36651. 0,
  36652. 0,
  36653. 0,
  36654. 0,
  36655. 0,
  36656. 0,
  36657. 0,
  36658. 0,
  36659. 0,
  36660. // dx
  36661. 0,
  36662. 0,
  36663. 0,
  36664. 0,
  36665. 0,
  36666. 0,
  36667. 0,
  36668. 0,
  36669. 0,
  36670. 0,
  36671. 0,
  36672. 0,
  36673. 0,
  36674. 0,
  36675. 0,
  36676. 0,
  36677. // ex
  36678. 0,
  36679. 0,
  36680. 0,
  36681. 0,
  36682. 0,
  36683. 0,
  36684. 0,
  36685. 0,
  36686. 0,
  36687. 0,
  36688. 0,
  36689. 0,
  36690. 0,
  36691. 0,
  36692. 0,
  36693. 0
  36694. ];
  36695. // fx
  36696. function toHexDigit(ch) {
  36697. if (ch >= 0x30 && ch <= 0x39) {
  36698. // '0'-'9'
  36699. return ch & 0x0F;
  36700. }
  36701. if (ch >= 0x41 && ch <= 0x46 || ch >= 0x61 && ch <= 0x66) {
  36702. // 'A'-'F', 'a'-'f'
  36703. return (ch & 0x0F) + 9;
  36704. }
  36705. return -1;
  36706. }
  36707. Lexer.prototype = {
  36708. nextChar: function Lexer_nextChar() {
  36709. return this.currentChar = this.stream.getByte();
  36710. },
  36711. peekChar: function Lexer_peekChar() {
  36712. return this.stream.peekByte();
  36713. },
  36714. getNumber: function Lexer_getNumber() {
  36715. var ch = this.currentChar;
  36716. var eNotation = false;
  36717. var divideBy = 0;
  36718. // different from 0 if it's a floating point value
  36719. var sign = 1;
  36720. if (ch === 0x2D) {
  36721. // '-'
  36722. sign = -1;
  36723. ch = this.nextChar();
  36724. if (ch === 0x2D) {
  36725. // '-'
  36726. // Ignore double negative (this is consistent with Adobe Reader).
  36727. ch = this.nextChar();
  36728. }
  36729. } else if (ch === 0x2B) {
  36730. // '+'
  36731. ch = this.nextChar();
  36732. }
  36733. if (ch === 0x2E) {
  36734. // '.'
  36735. divideBy = 10;
  36736. ch = this.nextChar();
  36737. }
  36738. if (ch < 0x30 || ch > 0x39) {
  36739. // '0' - '9'
  36740. error('Invalid number: ' + String.fromCharCode(ch));
  36741. return 0;
  36742. }
  36743. var baseValue = ch - 0x30;
  36744. // '0'
  36745. var powerValue = 0;
  36746. var powerValueSign = 1;
  36747. while ((ch = this.nextChar()) >= 0) {
  36748. if (0x30 <= ch && ch <= 0x39) {
  36749. // '0' - '9'
  36750. var currentDigit = ch - 0x30;
  36751. // '0'
  36752. if (eNotation) {
  36753. // We are after an 'e' or 'E'
  36754. powerValue = powerValue * 10 + currentDigit;
  36755. } else {
  36756. if (divideBy !== 0) {
  36757. // We are after a point
  36758. divideBy *= 10;
  36759. }
  36760. baseValue = baseValue * 10 + currentDigit;
  36761. }
  36762. } else if (ch === 0x2E) {
  36763. // '.'
  36764. if (divideBy === 0) {
  36765. divideBy = 1;
  36766. } else {
  36767. // A number can have only one '.'
  36768. break;
  36769. }
  36770. } else if (ch === 0x2D) {
  36771. // '-'
  36772. // ignore minus signs in the middle of numbers to match
  36773. // Adobe's behavior
  36774. warn('Badly formatted number');
  36775. } else if (ch === 0x45 || ch === 0x65) {
  36776. // 'E', 'e'
  36777. // 'E' can be either a scientific notation or the beginning of a new
  36778. // operator
  36779. ch = this.peekChar();
  36780. if (ch === 0x2B || ch === 0x2D) {
  36781. // '+', '-'
  36782. powerValueSign = ch === 0x2D ? -1 : 1;
  36783. this.nextChar();
  36784. } else // Consume the sign character
  36785. if (ch < 0x30 || ch > 0x39) {
  36786. // '0' - '9'
  36787. // The 'E' must be the beginning of a new operator
  36788. break;
  36789. }
  36790. eNotation = true;
  36791. } else {
  36792. // the last character doesn't belong to us
  36793. break;
  36794. }
  36795. }
  36796. if (divideBy !== 0) {
  36797. baseValue /= divideBy;
  36798. }
  36799. if (eNotation) {
  36800. baseValue *= Math.pow(10, powerValueSign * powerValue);
  36801. }
  36802. return sign * baseValue;
  36803. },
  36804. getString: function Lexer_getString() {
  36805. var numParen = 1;
  36806. var done = false;
  36807. var strBuf = this.strBuf;
  36808. strBuf.length = 0;
  36809. var ch = this.nextChar();
  36810. while (true) {
  36811. var charBuffered = false;
  36812. switch (ch | 0) {
  36813. case -1:
  36814. warn('Unterminated string');
  36815. done = true;
  36816. break;
  36817. case 0x28:
  36818. // '('
  36819. ++numParen;
  36820. strBuf.push('(');
  36821. break;
  36822. case 0x29:
  36823. // ')'
  36824. if (--numParen === 0) {
  36825. this.nextChar();
  36826. // consume strings ')'
  36827. done = true;
  36828. } else {
  36829. strBuf.push(')');
  36830. }
  36831. break;
  36832. case 0x5C:
  36833. // '\\'
  36834. ch = this.nextChar();
  36835. switch (ch) {
  36836. case -1:
  36837. warn('Unterminated string');
  36838. done = true;
  36839. break;
  36840. case 0x6E:
  36841. // 'n'
  36842. strBuf.push('\n');
  36843. break;
  36844. case 0x72:
  36845. // 'r'
  36846. strBuf.push('\r');
  36847. break;
  36848. case 0x74:
  36849. // 't'
  36850. strBuf.push('\t');
  36851. break;
  36852. case 0x62:
  36853. // 'b'
  36854. strBuf.push('\b');
  36855. break;
  36856. case 0x66:
  36857. // 'f'
  36858. strBuf.push('\f');
  36859. break;
  36860. case 0x5C:
  36861. // '\'
  36862. case 0x28:
  36863. // '('
  36864. case 0x29:
  36865. // ')'
  36866. strBuf.push(String.fromCharCode(ch));
  36867. break;
  36868. case 0x30:
  36869. case 0x31:
  36870. case 0x32:
  36871. case 0x33:
  36872. // '0'-'3'
  36873. case 0x34:
  36874. case 0x35:
  36875. case 0x36:
  36876. case 0x37:
  36877. // '4'-'7'
  36878. var x = ch & 0x0F;
  36879. ch = this.nextChar();
  36880. charBuffered = true;
  36881. if (ch >= 0x30 && ch <= 0x37) {
  36882. // '0'-'7'
  36883. x = (x << 3) + (ch & 0x0F);
  36884. ch = this.nextChar();
  36885. if (ch >= 0x30 && ch <= 0x37) {
  36886. // '0'-'7'
  36887. charBuffered = false;
  36888. x = (x << 3) + (ch & 0x0F);
  36889. }
  36890. }
  36891. strBuf.push(String.fromCharCode(x));
  36892. break;
  36893. case 0x0D:
  36894. // CR
  36895. if (this.peekChar() === 0x0A) {
  36896. // LF
  36897. this.nextChar();
  36898. }
  36899. break;
  36900. case 0x0A:
  36901. // LF
  36902. break;
  36903. default:
  36904. strBuf.push(String.fromCharCode(ch));
  36905. break;
  36906. }
  36907. break;
  36908. default:
  36909. strBuf.push(String.fromCharCode(ch));
  36910. break;
  36911. }
  36912. if (done) {
  36913. break;
  36914. }
  36915. if (!charBuffered) {
  36916. ch = this.nextChar();
  36917. }
  36918. }
  36919. return strBuf.join('');
  36920. },
  36921. getName: function Lexer_getName() {
  36922. var ch, previousCh;
  36923. var strBuf = this.strBuf;
  36924. strBuf.length = 0;
  36925. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  36926. if (ch === 0x23) {
  36927. // '#'
  36928. ch = this.nextChar();
  36929. if (specialChars[ch]) {
  36930. warn('Lexer_getName: ' + 'NUMBER SIGN (#) should be followed by a hexadecimal number.');
  36931. strBuf.push('#');
  36932. break;
  36933. }
  36934. var x = toHexDigit(ch);
  36935. if (x !== -1) {
  36936. previousCh = ch;
  36937. ch = this.nextChar();
  36938. var x2 = toHexDigit(ch);
  36939. if (x2 === -1) {
  36940. warn('Lexer_getName: Illegal digit (' + String.fromCharCode(ch) + ') in hexadecimal number.');
  36941. strBuf.push('#', String.fromCharCode(previousCh));
  36942. if (specialChars[ch]) {
  36943. break;
  36944. }
  36945. strBuf.push(String.fromCharCode(ch));
  36946. continue;
  36947. }
  36948. strBuf.push(String.fromCharCode(x << 4 | x2));
  36949. } else {
  36950. strBuf.push('#', String.fromCharCode(ch));
  36951. }
  36952. } else {
  36953. strBuf.push(String.fromCharCode(ch));
  36954. }
  36955. }
  36956. if (strBuf.length > 127) {
  36957. warn('name token is longer than allowed by the spec: ' + strBuf.length);
  36958. }
  36959. return Name.get(strBuf.join(''));
  36960. },
  36961. getHexString: function Lexer_getHexString() {
  36962. var strBuf = this.strBuf;
  36963. strBuf.length = 0;
  36964. var ch = this.currentChar;
  36965. var isFirstHex = true;
  36966. var firstDigit;
  36967. var secondDigit;
  36968. while (true) {
  36969. if (ch < 0) {
  36970. warn('Unterminated hex string');
  36971. break;
  36972. } else if (ch === 0x3E) {
  36973. // '>'
  36974. this.nextChar();
  36975. break;
  36976. } else if (specialChars[ch] === 1) {
  36977. ch = this.nextChar();
  36978. continue;
  36979. } else {
  36980. if (isFirstHex) {
  36981. firstDigit = toHexDigit(ch);
  36982. if (firstDigit === -1) {
  36983. warn('Ignoring invalid character "' + ch + '" in hex string');
  36984. ch = this.nextChar();
  36985. continue;
  36986. }
  36987. } else {
  36988. secondDigit = toHexDigit(ch);
  36989. if (secondDigit === -1) {
  36990. warn('Ignoring invalid character "' + ch + '" in hex string');
  36991. ch = this.nextChar();
  36992. continue;
  36993. }
  36994. strBuf.push(String.fromCharCode(firstDigit << 4 | secondDigit));
  36995. }
  36996. isFirstHex = !isFirstHex;
  36997. ch = this.nextChar();
  36998. }
  36999. }
  37000. return strBuf.join('');
  37001. },
  37002. getObj: function Lexer_getObj() {
  37003. // skip whitespace and comments
  37004. var comment = false;
  37005. var ch = this.currentChar;
  37006. while (true) {
  37007. if (ch < 0) {
  37008. return EOF;
  37009. }
  37010. if (comment) {
  37011. if (ch === 0x0A || ch === 0x0D) {
  37012. // LF, CR
  37013. comment = false;
  37014. }
  37015. } else if (ch === 0x25) {
  37016. // '%'
  37017. comment = true;
  37018. } else if (specialChars[ch] !== 1) {
  37019. break;
  37020. }
  37021. ch = this.nextChar();
  37022. }
  37023. // start reading token
  37024. switch (ch | 0) {
  37025. case 0x30:
  37026. case 0x31:
  37027. case 0x32:
  37028. case 0x33:
  37029. case 0x34:
  37030. // '0'-'4'
  37031. case 0x35:
  37032. case 0x36:
  37033. case 0x37:
  37034. case 0x38:
  37035. case 0x39:
  37036. // '5'-'9'
  37037. case 0x2B:
  37038. case 0x2D:
  37039. case 0x2E:
  37040. // '+', '-', '.'
  37041. return this.getNumber();
  37042. case 0x28:
  37043. // '('
  37044. return this.getString();
  37045. case 0x2F:
  37046. // '/'
  37047. return this.getName();
  37048. // array punctuation
  37049. case 0x5B:
  37050. // '['
  37051. this.nextChar();
  37052. return Cmd.get('[');
  37053. case 0x5D:
  37054. // ']'
  37055. this.nextChar();
  37056. return Cmd.get(']');
  37057. // hex string or dict punctuation
  37058. case 0x3C:
  37059. // '<'
  37060. ch = this.nextChar();
  37061. if (ch === 0x3C) {
  37062. // dict punctuation
  37063. this.nextChar();
  37064. return Cmd.get('<<');
  37065. }
  37066. return this.getHexString();
  37067. // dict punctuation
  37068. case 0x3E:
  37069. // '>'
  37070. ch = this.nextChar();
  37071. if (ch === 0x3E) {
  37072. this.nextChar();
  37073. return Cmd.get('>>');
  37074. }
  37075. return Cmd.get('>');
  37076. case 0x7B:
  37077. // '{'
  37078. this.nextChar();
  37079. return Cmd.get('{');
  37080. case 0x7D:
  37081. // '}'
  37082. this.nextChar();
  37083. return Cmd.get('}');
  37084. case 0x29:
  37085. // ')'
  37086. error('Illegal character: ' + ch);
  37087. break;
  37088. }
  37089. // command
  37090. var str = String.fromCharCode(ch);
  37091. var knownCommands = this.knownCommands;
  37092. var knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  37093. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  37094. // stop if known command is found and next character does not make
  37095. // the str a command
  37096. var possibleCommand = str + String.fromCharCode(ch);
  37097. if (knownCommandFound && knownCommands[possibleCommand] === undefined) {
  37098. break;
  37099. }
  37100. if (str.length === 128) {
  37101. error('Command token too long: ' + str.length);
  37102. }
  37103. str = possibleCommand;
  37104. knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  37105. }
  37106. if (str === 'true') {
  37107. return true;
  37108. }
  37109. if (str === 'false') {
  37110. return false;
  37111. }
  37112. if (str === 'null') {
  37113. return null;
  37114. }
  37115. return Cmd.get(str);
  37116. },
  37117. skipToNextLine: function Lexer_skipToNextLine() {
  37118. var ch = this.currentChar;
  37119. while (ch >= 0) {
  37120. if (ch === 0x0D) {
  37121. // CR
  37122. ch = this.nextChar();
  37123. if (ch === 0x0A) {
  37124. // LF
  37125. this.nextChar();
  37126. }
  37127. break;
  37128. } else if (ch === 0x0A) {
  37129. // LF
  37130. this.nextChar();
  37131. break;
  37132. }
  37133. ch = this.nextChar();
  37134. }
  37135. }
  37136. };
  37137. return Lexer;
  37138. }();
  37139. var Linearization = {
  37140. create: function LinearizationCreate(stream) {
  37141. function getInt(name, allowZeroValue) {
  37142. var obj = linDict.get(name);
  37143. if (isInt(obj) && (allowZeroValue ? obj >= 0 : obj > 0)) {
  37144. return obj;
  37145. }
  37146. throw new Error('The "' + name + '" parameter in the linearization ' + 'dictionary is invalid.');
  37147. }
  37148. function getHints() {
  37149. var hints = linDict.get('H'), hintsLength, item;
  37150. if (isArray(hints) && ((hintsLength = hints.length) === 2 || hintsLength === 4)) {
  37151. for (var index = 0; index < hintsLength; index++) {
  37152. if (!(isInt(item = hints[index]) && item > 0)) {
  37153. throw new Error('Hint (' + index + ') in the linearization dictionary is invalid.');
  37154. }
  37155. }
  37156. return hints;
  37157. }
  37158. throw new Error('Hint array in the linearization dictionary is invalid.');
  37159. }
  37160. var parser = new Parser(new Lexer(stream), false, null);
  37161. var obj1 = parser.getObj();
  37162. var obj2 = parser.getObj();
  37163. var obj3 = parser.getObj();
  37164. var linDict = parser.getObj();
  37165. var obj, length;
  37166. if (!(isInt(obj1) && isInt(obj2) && isCmd(obj3, 'obj') && isDict(linDict) && isNum(obj = linDict.get('Linearized')) && obj > 0)) {
  37167. return null;
  37168. } else // No valid linearization dictionary found.
  37169. if ((length = getInt('L')) !== stream.length) {
  37170. throw new Error('The "L" parameter in the linearization dictionary ' + 'does not equal the stream length.');
  37171. }
  37172. return {
  37173. length: length,
  37174. hints: getHints(),
  37175. objectNumberFirst: getInt('O'),
  37176. endFirst: getInt('E'),
  37177. numPages: getInt('N'),
  37178. mainXRefEntriesOffset: getInt('T'),
  37179. pageFirst: linDict.has('P') ? getInt('P', true) : 0
  37180. };
  37181. }
  37182. };
  37183. exports.EOF = EOF;
  37184. exports.Lexer = Lexer;
  37185. exports.Linearization = Linearization;
  37186. exports.Parser = Parser;
  37187. exports.isEOF = isEOF;
  37188. }));
  37189. (function (root, factory) {
  37190. factory(root.pdfjsCoreType1Parser = {}, root.pdfjsSharedUtil, root.pdfjsCoreStream, root.pdfjsCoreEncodings);
  37191. }(this, function (exports, sharedUtil, coreStream, coreEncodings) {
  37192. var warn = sharedUtil.warn;
  37193. var isSpace = sharedUtil.isSpace;
  37194. var Stream = coreStream.Stream;
  37195. var getEncoding = coreEncodings.getEncoding;
  37196. // Hinting is currently disabled due to unknown problems on windows
  37197. // in tracemonkey and various other pdfs with type1 fonts.
  37198. var HINTING_ENABLED = false;
  37199. /*
  37200. * CharStrings are encoded following the the CharString Encoding sequence
  37201. * describe in Chapter 6 of the "Adobe Type1 Font Format" specification.
  37202. * The value in a byte indicates a command, a number, or subsequent bytes
  37203. * that are to be interpreted in a special way.
  37204. *
  37205. * CharString Number Encoding:
  37206. * A CharString byte containing the values from 32 through 255 inclusive
  37207. * indicate an integer. These values are decoded in four ranges.
  37208. *
  37209. * 1. A CharString byte containing a value, v, between 32 and 246 inclusive,
  37210. * indicate the integer v - 139. Thus, the integer values from -107 through
  37211. * 107 inclusive may be encoded in single byte.
  37212. *
  37213. * 2. A CharString byte containing a value, v, between 247 and 250 inclusive,
  37214. * indicates an integer involving the next byte, w, according to the formula:
  37215. * [(v - 247) x 256] + w + 108
  37216. *
  37217. * 3. A CharString byte containing a value, v, between 251 and 254 inclusive,
  37218. * indicates an integer involving the next byte, w, according to the formula:
  37219. * -[(v - 251) * 256] - w - 108
  37220. *
  37221. * 4. A CharString containing the value 255 indicates that the next 4 bytes
  37222. * are a two complement signed integer. The first of these bytes contains the
  37223. * highest order bits, the second byte contains the next higher order bits
  37224. * and the fourth byte contain the lowest order bits.
  37225. *
  37226. *
  37227. * CharString Command Encoding:
  37228. * CharStrings commands are encoded in 1 or 2 bytes.
  37229. *
  37230. * Single byte commands are encoded in 1 byte that contains a value between
  37231. * 0 and 31 inclusive.
  37232. * If a command byte contains the value 12, then the value in the next byte
  37233. * indicates a command. This "escape" mechanism allows many extra commands
  37234. * to be encoded and this encoding technique helps to minimize the length of
  37235. * the charStrings.
  37236. */
  37237. var Type1CharString = function Type1CharStringClosure() {
  37238. var COMMAND_MAP = {
  37239. 'hstem': [1],
  37240. 'vstem': [3],
  37241. 'vmoveto': [4],
  37242. 'rlineto': [5],
  37243. 'hlineto': [6],
  37244. 'vlineto': [7],
  37245. 'rrcurveto': [8],
  37246. 'callsubr': [10],
  37247. 'flex': [
  37248. 12,
  37249. 35
  37250. ],
  37251. 'drop': [
  37252. 12,
  37253. 18
  37254. ],
  37255. 'endchar': [14],
  37256. 'rmoveto': [21],
  37257. 'hmoveto': [22],
  37258. 'vhcurveto': [30],
  37259. 'hvcurveto': [31]
  37260. };
  37261. function Type1CharString() {
  37262. this.width = 0;
  37263. this.lsb = 0;
  37264. this.flexing = false;
  37265. this.output = [];
  37266. this.stack = [];
  37267. }
  37268. Type1CharString.prototype = {
  37269. convert: function Type1CharString_convert(encoded, subrs, seacAnalysisEnabled) {
  37270. var count = encoded.length;
  37271. var error = false;
  37272. var wx, sbx, subrNumber;
  37273. for (var i = 0; i < count; i++) {
  37274. var value = encoded[i];
  37275. if (value < 32) {
  37276. if (value === 12) {
  37277. value = (value << 8) + encoded[++i];
  37278. }
  37279. switch (value) {
  37280. case 1:
  37281. // hstem
  37282. if (!HINTING_ENABLED) {
  37283. this.stack = [];
  37284. break;
  37285. }
  37286. error = this.executeCommand(2, COMMAND_MAP.hstem);
  37287. break;
  37288. case 3:
  37289. // vstem
  37290. if (!HINTING_ENABLED) {
  37291. this.stack = [];
  37292. break;
  37293. }
  37294. error = this.executeCommand(2, COMMAND_MAP.vstem);
  37295. break;
  37296. case 4:
  37297. // vmoveto
  37298. if (this.flexing) {
  37299. if (this.stack.length < 1) {
  37300. error = true;
  37301. break;
  37302. }
  37303. // Add the dx for flex and but also swap the values so they are
  37304. // the right order.
  37305. var dy = this.stack.pop();
  37306. this.stack.push(0, dy);
  37307. break;
  37308. }
  37309. error = this.executeCommand(1, COMMAND_MAP.vmoveto);
  37310. break;
  37311. case 5:
  37312. // rlineto
  37313. error = this.executeCommand(2, COMMAND_MAP.rlineto);
  37314. break;
  37315. case 6:
  37316. // hlineto
  37317. error = this.executeCommand(1, COMMAND_MAP.hlineto);
  37318. break;
  37319. case 7:
  37320. // vlineto
  37321. error = this.executeCommand(1, COMMAND_MAP.vlineto);
  37322. break;
  37323. case 8:
  37324. // rrcurveto
  37325. error = this.executeCommand(6, COMMAND_MAP.rrcurveto);
  37326. break;
  37327. case 9:
  37328. // closepath
  37329. // closepath is a Type1 command that does not take argument and is
  37330. // useless in Type2 and it can simply be ignored.
  37331. this.stack = [];
  37332. break;
  37333. case 10:
  37334. // callsubr
  37335. if (this.stack.length < 1) {
  37336. error = true;
  37337. break;
  37338. }
  37339. subrNumber = this.stack.pop();
  37340. error = this.convert(subrs[subrNumber], subrs, seacAnalysisEnabled);
  37341. break;
  37342. case 11:
  37343. // return
  37344. return error;
  37345. case 13:
  37346. // hsbw
  37347. if (this.stack.length < 2) {
  37348. error = true;
  37349. break;
  37350. }
  37351. // To convert to type2 we have to move the width value to the
  37352. // first part of the charstring and then use hmoveto with lsb.
  37353. wx = this.stack.pop();
  37354. sbx = this.stack.pop();
  37355. this.lsb = sbx;
  37356. this.width = wx;
  37357. this.stack.push(wx, sbx);
  37358. error = this.executeCommand(2, COMMAND_MAP.hmoveto);
  37359. break;
  37360. case 14:
  37361. // endchar
  37362. this.output.push(COMMAND_MAP.endchar[0]);
  37363. break;
  37364. case 21:
  37365. // rmoveto
  37366. if (this.flexing) {
  37367. break;
  37368. }
  37369. error = this.executeCommand(2, COMMAND_MAP.rmoveto);
  37370. break;
  37371. case 22:
  37372. // hmoveto
  37373. if (this.flexing) {
  37374. // Add the dy for flex.
  37375. this.stack.push(0);
  37376. break;
  37377. }
  37378. error = this.executeCommand(1, COMMAND_MAP.hmoveto);
  37379. break;
  37380. case 30:
  37381. // vhcurveto
  37382. error = this.executeCommand(4, COMMAND_MAP.vhcurveto);
  37383. break;
  37384. case 31:
  37385. // hvcurveto
  37386. error = this.executeCommand(4, COMMAND_MAP.hvcurveto);
  37387. break;
  37388. case (12 << 8) + 0:
  37389. // dotsection
  37390. // dotsection is a Type1 command to specify some hinting feature
  37391. // for dots that do not take a parameter and it can safely be
  37392. // ignored for Type2.
  37393. this.stack = [];
  37394. break;
  37395. case (12 << 8) + 1:
  37396. // vstem3
  37397. if (!HINTING_ENABLED) {
  37398. this.stack = [];
  37399. break;
  37400. }
  37401. // [vh]stem3 are Type1 only and Type2 supports [vh]stem with
  37402. // multiple parameters, so instead of returning [vh]stem3 take a
  37403. // shortcut and return [vhstem] instead.
  37404. error = this.executeCommand(2, COMMAND_MAP.vstem);
  37405. break;
  37406. case (12 << 8) + 2:
  37407. // hstem3
  37408. if (!HINTING_ENABLED) {
  37409. this.stack = [];
  37410. break;
  37411. }
  37412. // See vstem3.
  37413. error = this.executeCommand(2, COMMAND_MAP.hstem);
  37414. break;
  37415. case (12 << 8) + 6:
  37416. // seac
  37417. // seac is like type 2's special endchar but it doesn't use the
  37418. // first argument asb, so remove it.
  37419. if (seacAnalysisEnabled) {
  37420. this.seac = this.stack.splice(-4, 4);
  37421. error = this.executeCommand(0, COMMAND_MAP.endchar);
  37422. } else {
  37423. error = this.executeCommand(4, COMMAND_MAP.endchar);
  37424. }
  37425. break;
  37426. case (12 << 8) + 7:
  37427. // sbw
  37428. if (this.stack.length < 4) {
  37429. error = true;
  37430. break;
  37431. }
  37432. // To convert to type2 we have to move the width value to the
  37433. // first part of the charstring and then use rmoveto with
  37434. // (dx, dy). The height argument will not be used for vmtx and
  37435. // vhea tables reconstruction -- ignoring it.
  37436. var wy = this.stack.pop();
  37437. wx = this.stack.pop();
  37438. var sby = this.stack.pop();
  37439. sbx = this.stack.pop();
  37440. this.lsb = sbx;
  37441. this.width = wx;
  37442. this.stack.push(wx, sbx, sby);
  37443. error = this.executeCommand(3, COMMAND_MAP.rmoveto);
  37444. break;
  37445. case (12 << 8) + 12:
  37446. // div
  37447. if (this.stack.length < 2) {
  37448. error = true;
  37449. break;
  37450. }
  37451. var num2 = this.stack.pop();
  37452. var num1 = this.stack.pop();
  37453. this.stack.push(num1 / num2);
  37454. break;
  37455. case (12 << 8) + 16:
  37456. // callothersubr
  37457. if (this.stack.length < 2) {
  37458. error = true;
  37459. break;
  37460. }
  37461. subrNumber = this.stack.pop();
  37462. var numArgs = this.stack.pop();
  37463. if (subrNumber === 0 && numArgs === 3) {
  37464. var flexArgs = this.stack.splice(this.stack.length - 17, 17);
  37465. this.stack.push(flexArgs[2] + flexArgs[0], // bcp1x + rpx
  37466. flexArgs[3] + flexArgs[1], // bcp1y + rpy
  37467. flexArgs[4], // bcp2x
  37468. flexArgs[5], // bcp2y
  37469. flexArgs[6], // p2x
  37470. flexArgs[7], // p2y
  37471. flexArgs[8], // bcp3x
  37472. flexArgs[9], // bcp3y
  37473. flexArgs[10], // bcp4x
  37474. flexArgs[11], // bcp4y
  37475. flexArgs[12], // p3x
  37476. flexArgs[13], // p3y
  37477. flexArgs[14]);
  37478. // flexDepth
  37479. // 15 = finalx unused by flex
  37480. // 16 = finaly unused by flex
  37481. error = this.executeCommand(13, COMMAND_MAP.flex, true);
  37482. this.flexing = false;
  37483. this.stack.push(flexArgs[15], flexArgs[16]);
  37484. } else if (subrNumber === 1 && numArgs === 0) {
  37485. this.flexing = true;
  37486. }
  37487. break;
  37488. case (12 << 8) + 17:
  37489. // pop
  37490. // Ignore this since it is only used with othersubr.
  37491. break;
  37492. case (12 << 8) + 33:
  37493. // setcurrentpoint
  37494. // Ignore for now.
  37495. this.stack = [];
  37496. break;
  37497. default:
  37498. warn('Unknown type 1 charstring command of "' + value + '"');
  37499. break;
  37500. }
  37501. if (error) {
  37502. break;
  37503. }
  37504. continue;
  37505. } else if (value <= 246) {
  37506. value = value - 139;
  37507. } else if (value <= 250) {
  37508. value = (value - 247) * 256 + encoded[++i] + 108;
  37509. } else if (value <= 254) {
  37510. value = -((value - 251) * 256) - encoded[++i] - 108;
  37511. } else {
  37512. value = (encoded[++i] & 0xff) << 24 | (encoded[++i] & 0xff) << 16 | (encoded[++i] & 0xff) << 8 | (encoded[++i] & 0xff) << 0;
  37513. }
  37514. this.stack.push(value);
  37515. }
  37516. return error;
  37517. },
  37518. executeCommand: function (howManyArgs, command, keepStack) {
  37519. var stackLength = this.stack.length;
  37520. if (howManyArgs > stackLength) {
  37521. return true;
  37522. }
  37523. var start = stackLength - howManyArgs;
  37524. for (var i = start; i < stackLength; i++) {
  37525. var value = this.stack[i];
  37526. if (value === (value | 0)) {
  37527. // int
  37528. this.output.push(28, value >> 8 & 0xff, value & 0xff);
  37529. } else {
  37530. // fixed point
  37531. value = 65536 * value | 0;
  37532. this.output.push(255, value >> 24 & 0xFF, value >> 16 & 0xFF, value >> 8 & 0xFF, value & 0xFF);
  37533. }
  37534. }
  37535. this.output.push.apply(this.output, command);
  37536. if (keepStack) {
  37537. this.stack.splice(start, howManyArgs);
  37538. } else {
  37539. this.stack.length = 0;
  37540. }
  37541. return false;
  37542. }
  37543. };
  37544. return Type1CharString;
  37545. }();
  37546. /*
  37547. * Type1Parser encapsulate the needed code for parsing a Type1 font
  37548. * program. Some of its logic depends on the Type2 charstrings
  37549. * structure.
  37550. * Note: this doesn't really parse the font since that would require evaluation
  37551. * of PostScript, but it is possible in most cases to extract what we need
  37552. * without a full parse.
  37553. */
  37554. var Type1Parser = function Type1ParserClosure() {
  37555. /*
  37556. * Decrypt a Sequence of Ciphertext Bytes to Produce the Original Sequence
  37557. * of Plaintext Bytes. The function took a key as a parameter which can be
  37558. * for decrypting the eexec block of for decoding charStrings.
  37559. */
  37560. var EEXEC_ENCRYPT_KEY = 55665;
  37561. var CHAR_STRS_ENCRYPT_KEY = 4330;
  37562. function isHexDigit(code) {
  37563. return code >= 48 && code <= 57 || // '0'-'9'
  37564. code >= 65 && code <= 70 || // 'A'-'F'
  37565. code >= 97 && code <= 102;
  37566. }
  37567. // 'a'-'f'
  37568. function decrypt(data, key, discardNumber) {
  37569. if (discardNumber >= data.length) {
  37570. return new Uint8Array(0);
  37571. }
  37572. var r = key | 0, c1 = 52845, c2 = 22719, i, j;
  37573. for (i = 0; i < discardNumber; i++) {
  37574. r = (data[i] + r) * c1 + c2 & (1 << 16) - 1;
  37575. }
  37576. var count = data.length - discardNumber;
  37577. var decrypted = new Uint8Array(count);
  37578. for (i = discardNumber, j = 0; j < count; i++, j++) {
  37579. var value = data[i];
  37580. decrypted[j] = value ^ r >> 8;
  37581. r = (value + r) * c1 + c2 & (1 << 16) - 1;
  37582. }
  37583. return decrypted;
  37584. }
  37585. function decryptAscii(data, key, discardNumber) {
  37586. var r = key | 0, c1 = 52845, c2 = 22719;
  37587. var count = data.length, maybeLength = count >>> 1;
  37588. var decrypted = new Uint8Array(maybeLength);
  37589. var i, j;
  37590. for (i = 0, j = 0; i < count; i++) {
  37591. var digit1 = data[i];
  37592. if (!isHexDigit(digit1)) {
  37593. continue;
  37594. }
  37595. i++;
  37596. var digit2;
  37597. while (i < count && !isHexDigit(digit2 = data[i])) {
  37598. i++;
  37599. }
  37600. if (i < count) {
  37601. var value = parseInt(String.fromCharCode(digit1, digit2), 16);
  37602. decrypted[j++] = value ^ r >> 8;
  37603. r = (value + r) * c1 + c2 & (1 << 16) - 1;
  37604. }
  37605. }
  37606. return Array.prototype.slice.call(decrypted, discardNumber, j);
  37607. }
  37608. function isSpecial(c) {
  37609. return c === 0x2F || // '/'
  37610. c === 0x5B || c === 0x5D || // '[', ']'
  37611. c === 0x7B || c === 0x7D || // '{', '}'
  37612. c === 0x28 || c === 0x29;
  37613. }
  37614. // '(', ')'
  37615. function Type1Parser(stream, encrypted, seacAnalysisEnabled) {
  37616. if (encrypted) {
  37617. var data = stream.getBytes();
  37618. var isBinary = !(isHexDigit(data[0]) && isHexDigit(data[1]) && isHexDigit(data[2]) && isHexDigit(data[3]));
  37619. stream = new Stream(isBinary ? decrypt(data, EEXEC_ENCRYPT_KEY, 4) : decryptAscii(data, EEXEC_ENCRYPT_KEY, 4));
  37620. }
  37621. this.seacAnalysisEnabled = !!seacAnalysisEnabled;
  37622. this.stream = stream;
  37623. this.nextChar();
  37624. }
  37625. Type1Parser.prototype = {
  37626. readNumberArray: function Type1Parser_readNumberArray() {
  37627. this.getToken();
  37628. // read '[' or '{' (arrays can start with either)
  37629. var array = [];
  37630. while (true) {
  37631. var token = this.getToken();
  37632. if (token === null || token === ']' || token === '}') {
  37633. break;
  37634. }
  37635. array.push(parseFloat(token || 0));
  37636. }
  37637. return array;
  37638. },
  37639. readNumber: function Type1Parser_readNumber() {
  37640. var token = this.getToken();
  37641. return parseFloat(token || 0);
  37642. },
  37643. readInt: function Type1Parser_readInt() {
  37644. // Use '| 0' to prevent setting a double into length such as the double
  37645. // does not flow into the loop variable.
  37646. var token = this.getToken();
  37647. return parseInt(token || 0, 10) | 0;
  37648. },
  37649. readBoolean: function Type1Parser_readBoolean() {
  37650. var token = this.getToken();
  37651. // Use 1 and 0 since that's what type2 charstrings use.
  37652. return token === 'true' ? 1 : 0;
  37653. },
  37654. nextChar: function Type1_nextChar() {
  37655. return this.currentChar = this.stream.getByte();
  37656. },
  37657. getToken: function Type1Parser_getToken() {
  37658. // Eat whitespace and comments.
  37659. var comment = false;
  37660. var ch = this.currentChar;
  37661. while (true) {
  37662. if (ch === -1) {
  37663. return null;
  37664. }
  37665. if (comment) {
  37666. if (ch === 0x0A || ch === 0x0D) {
  37667. comment = false;
  37668. }
  37669. } else if (ch === 0x25) {
  37670. // '%'
  37671. comment = true;
  37672. } else if (!isSpace(ch)) {
  37673. break;
  37674. }
  37675. ch = this.nextChar();
  37676. }
  37677. if (isSpecial(ch)) {
  37678. this.nextChar();
  37679. return String.fromCharCode(ch);
  37680. }
  37681. var token = '';
  37682. do {
  37683. token += String.fromCharCode(ch);
  37684. ch = this.nextChar();
  37685. } while (ch >= 0 && !isSpace(ch) && !isSpecial(ch));
  37686. return token;
  37687. },
  37688. /*
  37689. * Returns an object containing a Subrs array and a CharStrings
  37690. * array extracted from and eexec encrypted block of data
  37691. */
  37692. extractFontProgram: function Type1Parser_extractFontProgram() {
  37693. var stream = this.stream;
  37694. var subrs = [], charstrings = [];
  37695. var privateData = Object.create(null);
  37696. privateData['lenIV'] = 4;
  37697. var program = {
  37698. subrs: [],
  37699. charstrings: [],
  37700. properties: { 'privateData': privateData }
  37701. };
  37702. var token, length, data, lenIV, encoded;
  37703. while ((token = this.getToken()) !== null) {
  37704. if (token !== '/') {
  37705. continue;
  37706. }
  37707. token = this.getToken();
  37708. switch (token) {
  37709. case 'CharStrings':
  37710. // The number immediately following CharStrings must be greater or
  37711. // equal to the number of CharStrings.
  37712. this.getToken();
  37713. this.getToken();
  37714. // read in 'dict'
  37715. this.getToken();
  37716. // read in 'dup'
  37717. this.getToken();
  37718. // read in 'begin'
  37719. while (true) {
  37720. token = this.getToken();
  37721. if (token === null || token === 'end') {
  37722. break;
  37723. }
  37724. if (token !== '/') {
  37725. continue;
  37726. }
  37727. var glyph = this.getToken();
  37728. length = this.readInt();
  37729. this.getToken();
  37730. // read in 'RD' or '-|'
  37731. data = stream.makeSubStream(stream.pos, length);
  37732. lenIV = program.properties.privateData['lenIV'];
  37733. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  37734. // Skip past the required space and binary data.
  37735. stream.skip(length);
  37736. this.nextChar();
  37737. token = this.getToken();
  37738. // read in 'ND' or '|-'
  37739. if (token === 'noaccess') {
  37740. this.getToken();
  37741. }
  37742. // read in 'def'
  37743. charstrings.push({
  37744. glyph: glyph,
  37745. encoded: encoded
  37746. });
  37747. }
  37748. break;
  37749. case 'Subrs':
  37750. var num = this.readInt();
  37751. this.getToken();
  37752. // read in 'array'
  37753. while ((token = this.getToken()) === 'dup') {
  37754. var index = this.readInt();
  37755. length = this.readInt();
  37756. this.getToken();
  37757. // read in 'RD' or '-|'
  37758. data = stream.makeSubStream(stream.pos, length);
  37759. lenIV = program.properties.privateData['lenIV'];
  37760. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  37761. // Skip past the required space and binary data.
  37762. stream.skip(length);
  37763. this.nextChar();
  37764. token = this.getToken();
  37765. // read in 'NP' or '|'
  37766. if (token === 'noaccess') {
  37767. this.getToken();
  37768. }
  37769. // read in 'put'
  37770. subrs[index] = encoded;
  37771. }
  37772. break;
  37773. case 'BlueValues':
  37774. case 'OtherBlues':
  37775. case 'FamilyBlues':
  37776. case 'FamilyOtherBlues':
  37777. var blueArray = this.readNumberArray();
  37778. // *Blue* values may contain invalid data: disables reading of
  37779. // those values when hinting is disabled.
  37780. if (blueArray.length > 0 && blueArray.length % 2 === 0 && HINTING_ENABLED) {
  37781. program.properties.privateData[token] = blueArray;
  37782. }
  37783. break;
  37784. case 'StemSnapH':
  37785. case 'StemSnapV':
  37786. program.properties.privateData[token] = this.readNumberArray();
  37787. break;
  37788. case 'StdHW':
  37789. case 'StdVW':
  37790. program.properties.privateData[token] = this.readNumberArray()[0];
  37791. break;
  37792. case 'BlueShift':
  37793. case 'lenIV':
  37794. case 'BlueFuzz':
  37795. case 'BlueScale':
  37796. case 'LanguageGroup':
  37797. case 'ExpansionFactor':
  37798. program.properties.privateData[token] = this.readNumber();
  37799. break;
  37800. case 'ForceBold':
  37801. program.properties.privateData[token] = this.readBoolean();
  37802. break;
  37803. }
  37804. }
  37805. for (var i = 0; i < charstrings.length; i++) {
  37806. glyph = charstrings[i].glyph;
  37807. encoded = charstrings[i].encoded;
  37808. var charString = new Type1CharString();
  37809. var error = charString.convert(encoded, subrs, this.seacAnalysisEnabled);
  37810. var output = charString.output;
  37811. if (error) {
  37812. // It seems when FreeType encounters an error while evaluating a glyph
  37813. // that it completely ignores the glyph so we'll mimic that behaviour
  37814. // here and put an endchar to make the validator happy.
  37815. output = [14];
  37816. }
  37817. program.charstrings.push({
  37818. glyphName: glyph,
  37819. charstring: output,
  37820. width: charString.width,
  37821. lsb: charString.lsb,
  37822. seac: charString.seac
  37823. });
  37824. }
  37825. return program;
  37826. },
  37827. extractFontHeader: function Type1Parser_extractFontHeader(properties) {
  37828. var token;
  37829. while ((token = this.getToken()) !== null) {
  37830. if (token !== '/') {
  37831. continue;
  37832. }
  37833. token = this.getToken();
  37834. switch (token) {
  37835. case 'FontMatrix':
  37836. var matrix = this.readNumberArray();
  37837. properties.fontMatrix = matrix;
  37838. break;
  37839. case 'Encoding':
  37840. var encodingArg = this.getToken();
  37841. var encoding;
  37842. if (!/^\d+$/.test(encodingArg)) {
  37843. // encoding name is specified
  37844. encoding = getEncoding(encodingArg);
  37845. } else {
  37846. encoding = [];
  37847. var size = parseInt(encodingArg, 10) | 0;
  37848. this.getToken();
  37849. // read in 'array'
  37850. for (var j = 0; j < size; j++) {
  37851. token = this.getToken();
  37852. // skipping till first dup or def (e.g. ignoring for statement)
  37853. while (token !== 'dup' && token !== 'def') {
  37854. token = this.getToken();
  37855. if (token === null) {
  37856. return;
  37857. }
  37858. }
  37859. // invalid header
  37860. if (token === 'def') {
  37861. break;
  37862. }
  37863. // read all array data
  37864. var index = this.readInt();
  37865. this.getToken();
  37866. // read in '/'
  37867. var glyph = this.getToken();
  37868. encoding[index] = glyph;
  37869. this.getToken();
  37870. }
  37871. }
  37872. // read the in 'put'
  37873. properties.builtInEncoding = encoding;
  37874. break;
  37875. case 'FontBBox':
  37876. var fontBBox = this.readNumberArray();
  37877. // adjusting ascent/descent
  37878. properties.ascent = fontBBox[3];
  37879. properties.descent = fontBBox[1];
  37880. properties.ascentScaled = true;
  37881. break;
  37882. }
  37883. }
  37884. }
  37885. };
  37886. return Type1Parser;
  37887. }();
  37888. exports.Type1Parser = Type1Parser;
  37889. }));
  37890. (function (root, factory) {
  37891. factory(root.pdfjsCoreCMap = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreParser);
  37892. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreParser) {
  37893. var Util = sharedUtil.Util;
  37894. var assert = sharedUtil.assert;
  37895. var warn = sharedUtil.warn;
  37896. var error = sharedUtil.error;
  37897. var isInt = sharedUtil.isInt;
  37898. var isString = sharedUtil.isString;
  37899. var MissingDataException = sharedUtil.MissingDataException;
  37900. var isName = corePrimitives.isName;
  37901. var isCmd = corePrimitives.isCmd;
  37902. var isStream = corePrimitives.isStream;
  37903. var StringStream = coreStream.StringStream;
  37904. var Lexer = coreParser.Lexer;
  37905. var isEOF = coreParser.isEOF;
  37906. var BUILT_IN_CMAPS = [
  37907. // << Start unicode maps.
  37908. 'Adobe-GB1-UCS2',
  37909. 'Adobe-CNS1-UCS2',
  37910. 'Adobe-Japan1-UCS2',
  37911. 'Adobe-Korea1-UCS2',
  37912. // >> End unicode maps.
  37913. '78-EUC-H',
  37914. '78-EUC-V',
  37915. '78-H',
  37916. '78-RKSJ-H',
  37917. '78-RKSJ-V',
  37918. '78-V',
  37919. '78ms-RKSJ-H',
  37920. '78ms-RKSJ-V',
  37921. '83pv-RKSJ-H',
  37922. '90ms-RKSJ-H',
  37923. '90ms-RKSJ-V',
  37924. '90msp-RKSJ-H',
  37925. '90msp-RKSJ-V',
  37926. '90pv-RKSJ-H',
  37927. '90pv-RKSJ-V',
  37928. 'Add-H',
  37929. 'Add-RKSJ-H',
  37930. 'Add-RKSJ-V',
  37931. 'Add-V',
  37932. 'Adobe-CNS1-0',
  37933. 'Adobe-CNS1-1',
  37934. 'Adobe-CNS1-2',
  37935. 'Adobe-CNS1-3',
  37936. 'Adobe-CNS1-4',
  37937. 'Adobe-CNS1-5',
  37938. 'Adobe-CNS1-6',
  37939. 'Adobe-GB1-0',
  37940. 'Adobe-GB1-1',
  37941. 'Adobe-GB1-2',
  37942. 'Adobe-GB1-3',
  37943. 'Adobe-GB1-4',
  37944. 'Adobe-GB1-5',
  37945. 'Adobe-Japan1-0',
  37946. 'Adobe-Japan1-1',
  37947. 'Adobe-Japan1-2',
  37948. 'Adobe-Japan1-3',
  37949. 'Adobe-Japan1-4',
  37950. 'Adobe-Japan1-5',
  37951. 'Adobe-Japan1-6',
  37952. 'Adobe-Korea1-0',
  37953. 'Adobe-Korea1-1',
  37954. 'Adobe-Korea1-2',
  37955. 'B5-H',
  37956. 'B5-V',
  37957. 'B5pc-H',
  37958. 'B5pc-V',
  37959. 'CNS-EUC-H',
  37960. 'CNS-EUC-V',
  37961. 'CNS1-H',
  37962. 'CNS1-V',
  37963. 'CNS2-H',
  37964. 'CNS2-V',
  37965. 'ETHK-B5-H',
  37966. 'ETHK-B5-V',
  37967. 'ETen-B5-H',
  37968. 'ETen-B5-V',
  37969. 'ETenms-B5-H',
  37970. 'ETenms-B5-V',
  37971. 'EUC-H',
  37972. 'EUC-V',
  37973. 'Ext-H',
  37974. 'Ext-RKSJ-H',
  37975. 'Ext-RKSJ-V',
  37976. 'Ext-V',
  37977. 'GB-EUC-H',
  37978. 'GB-EUC-V',
  37979. 'GB-H',
  37980. 'GB-V',
  37981. 'GBK-EUC-H',
  37982. 'GBK-EUC-V',
  37983. 'GBK2K-H',
  37984. 'GBK2K-V',
  37985. 'GBKp-EUC-H',
  37986. 'GBKp-EUC-V',
  37987. 'GBT-EUC-H',
  37988. 'GBT-EUC-V',
  37989. 'GBT-H',
  37990. 'GBT-V',
  37991. 'GBTpc-EUC-H',
  37992. 'GBTpc-EUC-V',
  37993. 'GBpc-EUC-H',
  37994. 'GBpc-EUC-V',
  37995. 'H',
  37996. 'HKdla-B5-H',
  37997. 'HKdla-B5-V',
  37998. 'HKdlb-B5-H',
  37999. 'HKdlb-B5-V',
  38000. 'HKgccs-B5-H',
  38001. 'HKgccs-B5-V',
  38002. 'HKm314-B5-H',
  38003. 'HKm314-B5-V',
  38004. 'HKm471-B5-H',
  38005. 'HKm471-B5-V',
  38006. 'HKscs-B5-H',
  38007. 'HKscs-B5-V',
  38008. 'Hankaku',
  38009. 'Hiragana',
  38010. 'KSC-EUC-H',
  38011. 'KSC-EUC-V',
  38012. 'KSC-H',
  38013. 'KSC-Johab-H',
  38014. 'KSC-Johab-V',
  38015. 'KSC-V',
  38016. 'KSCms-UHC-H',
  38017. 'KSCms-UHC-HW-H',
  38018. 'KSCms-UHC-HW-V',
  38019. 'KSCms-UHC-V',
  38020. 'KSCpc-EUC-H',
  38021. 'KSCpc-EUC-V',
  38022. 'Katakana',
  38023. 'NWP-H',
  38024. 'NWP-V',
  38025. 'RKSJ-H',
  38026. 'RKSJ-V',
  38027. 'Roman',
  38028. 'UniCNS-UCS2-H',
  38029. 'UniCNS-UCS2-V',
  38030. 'UniCNS-UTF16-H',
  38031. 'UniCNS-UTF16-V',
  38032. 'UniCNS-UTF32-H',
  38033. 'UniCNS-UTF32-V',
  38034. 'UniCNS-UTF8-H',
  38035. 'UniCNS-UTF8-V',
  38036. 'UniGB-UCS2-H',
  38037. 'UniGB-UCS2-V',
  38038. 'UniGB-UTF16-H',
  38039. 'UniGB-UTF16-V',
  38040. 'UniGB-UTF32-H',
  38041. 'UniGB-UTF32-V',
  38042. 'UniGB-UTF8-H',
  38043. 'UniGB-UTF8-V',
  38044. 'UniJIS-UCS2-H',
  38045. 'UniJIS-UCS2-HW-H',
  38046. 'UniJIS-UCS2-HW-V',
  38047. 'UniJIS-UCS2-V',
  38048. 'UniJIS-UTF16-H',
  38049. 'UniJIS-UTF16-V',
  38050. 'UniJIS-UTF32-H',
  38051. 'UniJIS-UTF32-V',
  38052. 'UniJIS-UTF8-H',
  38053. 'UniJIS-UTF8-V',
  38054. 'UniJIS2004-UTF16-H',
  38055. 'UniJIS2004-UTF16-V',
  38056. 'UniJIS2004-UTF32-H',
  38057. 'UniJIS2004-UTF32-V',
  38058. 'UniJIS2004-UTF8-H',
  38059. 'UniJIS2004-UTF8-V',
  38060. 'UniJISPro-UCS2-HW-V',
  38061. 'UniJISPro-UCS2-V',
  38062. 'UniJISPro-UTF8-V',
  38063. 'UniJISX0213-UTF32-H',
  38064. 'UniJISX0213-UTF32-V',
  38065. 'UniJISX02132004-UTF32-H',
  38066. 'UniJISX02132004-UTF32-V',
  38067. 'UniKS-UCS2-H',
  38068. 'UniKS-UCS2-V',
  38069. 'UniKS-UTF16-H',
  38070. 'UniKS-UTF16-V',
  38071. 'UniKS-UTF32-H',
  38072. 'UniKS-UTF32-V',
  38073. 'UniKS-UTF8-H',
  38074. 'UniKS-UTF8-V',
  38075. 'V',
  38076. 'WP-Symbol'
  38077. ];
  38078. // CMap, not to be confused with TrueType's cmap.
  38079. var CMap = function CMapClosure() {
  38080. function CMap(builtInCMap) {
  38081. // Codespace ranges are stored as follows:
  38082. // [[1BytePairs], [2BytePairs], [3BytePairs], [4BytePairs]]
  38083. // where nBytePairs are ranges e.g. [low1, high1, low2, high2, ...]
  38084. this.codespaceRanges = [
  38085. [],
  38086. [],
  38087. [],
  38088. []
  38089. ];
  38090. this.numCodespaceRanges = 0;
  38091. // Map entries have one of two forms.
  38092. // - cid chars are 16-bit unsigned integers, stored as integers.
  38093. // - bf chars are variable-length byte sequences, stored as strings, with
  38094. // one byte per character.
  38095. this._map = [];
  38096. this.name = '';
  38097. this.vertical = false;
  38098. this.useCMap = null;
  38099. this.builtInCMap = builtInCMap;
  38100. }
  38101. CMap.prototype = {
  38102. addCodespaceRange: function (n, low, high) {
  38103. this.codespaceRanges[n - 1].push(low, high);
  38104. this.numCodespaceRanges++;
  38105. },
  38106. mapCidRange: function (low, high, dstLow) {
  38107. while (low <= high) {
  38108. this._map[low++] = dstLow++;
  38109. }
  38110. },
  38111. mapBfRange: function (low, high, dstLow) {
  38112. var lastByte = dstLow.length - 1;
  38113. while (low <= high) {
  38114. this._map[low++] = dstLow;
  38115. // Only the last byte has to be incremented.
  38116. dstLow = dstLow.substr(0, lastByte) + String.fromCharCode(dstLow.charCodeAt(lastByte) + 1);
  38117. }
  38118. },
  38119. mapBfRangeToArray: function (low, high, array) {
  38120. var i = 0, ii = array.length;
  38121. while (low <= high && i < ii) {
  38122. this._map[low] = array[i++];
  38123. ++low;
  38124. }
  38125. },
  38126. // This is used for both bf and cid chars.
  38127. mapOne: function (src, dst) {
  38128. this._map[src] = dst;
  38129. },
  38130. lookup: function (code) {
  38131. return this._map[code];
  38132. },
  38133. contains: function (code) {
  38134. return this._map[code] !== undefined;
  38135. },
  38136. forEach: function (callback) {
  38137. // Most maps have fewer than 65536 entries, and for those we use normal
  38138. // array iteration. But really sparse tables are possible -- e.g. with
  38139. // indices in the *billions*. For such tables we use for..in, which isn't
  38140. // ideal because it stringifies the indices for all present elements, but
  38141. // it does avoid iterating over every undefined entry.
  38142. var map = this._map;
  38143. var length = map.length;
  38144. var i;
  38145. if (length <= 0x10000) {
  38146. for (i = 0; i < length; i++) {
  38147. if (map[i] !== undefined) {
  38148. callback(i, map[i]);
  38149. }
  38150. }
  38151. } else {
  38152. for (i in this._map) {
  38153. callback(i, map[i]);
  38154. }
  38155. }
  38156. },
  38157. charCodeOf: function (value) {
  38158. return this._map.indexOf(value);
  38159. },
  38160. getMap: function () {
  38161. return this._map;
  38162. },
  38163. readCharCode: function (str, offset, out) {
  38164. var c = 0;
  38165. var codespaceRanges = this.codespaceRanges;
  38166. var codespaceRangesLen = this.codespaceRanges.length;
  38167. // 9.7.6.2 CMap Mapping
  38168. // The code length is at most 4.
  38169. for (var n = 0; n < codespaceRangesLen; n++) {
  38170. c = (c << 8 | str.charCodeAt(offset + n)) >>> 0;
  38171. // Check each codespace range to see if it falls within.
  38172. var codespaceRange = codespaceRanges[n];
  38173. for (var k = 0, kk = codespaceRange.length; k < kk;) {
  38174. var low = codespaceRange[k++];
  38175. var high = codespaceRange[k++];
  38176. if (c >= low && c <= high) {
  38177. out.charcode = c;
  38178. out.length = n + 1;
  38179. return;
  38180. }
  38181. }
  38182. }
  38183. out.charcode = 0;
  38184. out.length = 1;
  38185. },
  38186. get length() {
  38187. return this._map.length;
  38188. },
  38189. get isIdentityCMap() {
  38190. if (!(this.name === 'Identity-H' || this.name === 'Identity-V')) {
  38191. return false;
  38192. }
  38193. if (this._map.length !== 0x10000) {
  38194. return false;
  38195. }
  38196. for (var i = 0; i < 0x10000; i++) {
  38197. if (this._map[i] !== i) {
  38198. return false;
  38199. }
  38200. }
  38201. return true;
  38202. }
  38203. };
  38204. return CMap;
  38205. }();
  38206. // A special case of CMap, where the _map array implicitly has a length of
  38207. // 65536 and each element is equal to its index.
  38208. var IdentityCMap = function IdentityCMapClosure() {
  38209. function IdentityCMap(vertical, n) {
  38210. CMap.call(this);
  38211. this.vertical = vertical;
  38212. this.addCodespaceRange(n, 0, 0xffff);
  38213. }
  38214. Util.inherit(IdentityCMap, CMap, {});
  38215. IdentityCMap.prototype = {
  38216. addCodespaceRange: CMap.prototype.addCodespaceRange,
  38217. mapCidRange: function (low, high, dstLow) {
  38218. error('should not call mapCidRange');
  38219. },
  38220. mapBfRange: function (low, high, dstLow) {
  38221. error('should not call mapBfRange');
  38222. },
  38223. mapBfRangeToArray: function (low, high, array) {
  38224. error('should not call mapBfRangeToArray');
  38225. },
  38226. mapOne: function (src, dst) {
  38227. error('should not call mapCidOne');
  38228. },
  38229. lookup: function (code) {
  38230. return isInt(code) && code <= 0xffff ? code : undefined;
  38231. },
  38232. contains: function (code) {
  38233. return isInt(code) && code <= 0xffff;
  38234. },
  38235. forEach: function (callback) {
  38236. for (var i = 0; i <= 0xffff; i++) {
  38237. callback(i, i);
  38238. }
  38239. },
  38240. charCodeOf: function (value) {
  38241. return isInt(value) && value <= 0xffff ? value : -1;
  38242. },
  38243. getMap: function () {
  38244. // Sometimes identity maps must be instantiated, but it's rare.
  38245. var map = new Array(0x10000);
  38246. for (var i = 0; i <= 0xffff; i++) {
  38247. map[i] = i;
  38248. }
  38249. return map;
  38250. },
  38251. readCharCode: CMap.prototype.readCharCode,
  38252. get length() {
  38253. return 0x10000;
  38254. },
  38255. get isIdentityCMap() {
  38256. error('should not access .isIdentityCMap');
  38257. }
  38258. };
  38259. return IdentityCMap;
  38260. }();
  38261. var BinaryCMapReader = function BinaryCMapReaderClosure() {
  38262. function fetchBinaryData(url) {
  38263. return new Promise(function (resolve, reject) {
  38264. var request = new XMLHttpRequest();
  38265. request.open('GET', url, true);
  38266. request.responseType = 'arraybuffer';
  38267. request.onreadystatechange = function () {
  38268. if (request.readyState === XMLHttpRequest.DONE) {
  38269. if (!request.response || request.status !== 200 && request.status !== 0) {
  38270. reject(new Error('Unable to get binary cMap at: ' + url));
  38271. } else {
  38272. resolve(new Uint8Array(request.response));
  38273. }
  38274. }
  38275. };
  38276. request.send(null);
  38277. });
  38278. }
  38279. function hexToInt(a, size) {
  38280. var n = 0;
  38281. for (var i = 0; i <= size; i++) {
  38282. n = n << 8 | a[i];
  38283. }
  38284. return n >>> 0;
  38285. }
  38286. function hexToStr(a, size) {
  38287. // This code is hot. Special-case some common values to avoid creating an
  38288. // object with subarray().
  38289. if (size === 1) {
  38290. return String.fromCharCode(a[0], a[1]);
  38291. }
  38292. if (size === 3) {
  38293. return String.fromCharCode(a[0], a[1], a[2], a[3]);
  38294. }
  38295. return String.fromCharCode.apply(null, a.subarray(0, size + 1));
  38296. }
  38297. function addHex(a, b, size) {
  38298. var c = 0;
  38299. for (var i = size; i >= 0; i--) {
  38300. c += a[i] + b[i];
  38301. a[i] = c & 255;
  38302. c >>= 8;
  38303. }
  38304. }
  38305. function incHex(a, size) {
  38306. var c = 1;
  38307. for (var i = size; i >= 0 && c > 0; i--) {
  38308. c += a[i];
  38309. a[i] = c & 255;
  38310. c >>= 8;
  38311. }
  38312. }
  38313. var MAX_NUM_SIZE = 16;
  38314. var MAX_ENCODED_NUM_SIZE = 19;
  38315. // ceil(MAX_NUM_SIZE * 7 / 8)
  38316. function BinaryCMapStream(data) {
  38317. this.buffer = data;
  38318. this.pos = 0;
  38319. this.end = data.length;
  38320. this.tmpBuf = new Uint8Array(MAX_ENCODED_NUM_SIZE);
  38321. }
  38322. BinaryCMapStream.prototype = {
  38323. readByte: function () {
  38324. if (this.pos >= this.end) {
  38325. return -1;
  38326. }
  38327. return this.buffer[this.pos++];
  38328. },
  38329. readNumber: function () {
  38330. var n = 0;
  38331. var last;
  38332. do {
  38333. var b = this.readByte();
  38334. if (b < 0) {
  38335. error('unexpected EOF in bcmap');
  38336. }
  38337. last = !(b & 0x80);
  38338. n = n << 7 | b & 0x7F;
  38339. } while (!last);
  38340. return n;
  38341. },
  38342. readSigned: function () {
  38343. var n = this.readNumber();
  38344. return n & 1 ? ~(n >>> 1) : n >>> 1;
  38345. },
  38346. readHex: function (num, size) {
  38347. num.set(this.buffer.subarray(this.pos, this.pos + size + 1));
  38348. this.pos += size + 1;
  38349. },
  38350. readHexNumber: function (num, size) {
  38351. var last;
  38352. var stack = this.tmpBuf, sp = 0;
  38353. do {
  38354. var b = this.readByte();
  38355. if (b < 0) {
  38356. error('unexpected EOF in bcmap');
  38357. }
  38358. last = !(b & 0x80);
  38359. stack[sp++] = b & 0x7F;
  38360. } while (!last);
  38361. var i = size, buffer = 0, bufferSize = 0;
  38362. while (i >= 0) {
  38363. while (bufferSize < 8 && stack.length > 0) {
  38364. buffer = stack[--sp] << bufferSize | buffer;
  38365. bufferSize += 7;
  38366. }
  38367. num[i] = buffer & 255;
  38368. i--;
  38369. buffer >>= 8;
  38370. bufferSize -= 8;
  38371. }
  38372. },
  38373. readHexSigned: function (num, size) {
  38374. this.readHexNumber(num, size);
  38375. var sign = num[size] & 1 ? 255 : 0;
  38376. var c = 0;
  38377. for (var i = 0; i <= size; i++) {
  38378. c = (c & 1) << 8 | num[i];
  38379. num[i] = c >> 1 ^ sign;
  38380. }
  38381. },
  38382. readString: function () {
  38383. var len = this.readNumber();
  38384. var s = '';
  38385. for (var i = 0; i < len; i++) {
  38386. s += String.fromCharCode(this.readNumber());
  38387. }
  38388. return s;
  38389. }
  38390. };
  38391. function processBinaryCMap(url, cMap, extend) {
  38392. return fetchBinaryData(url).then(function (data) {
  38393. var stream = new BinaryCMapStream(data);
  38394. var header = stream.readByte();
  38395. cMap.vertical = !!(header & 1);
  38396. var useCMap = null;
  38397. var start = new Uint8Array(MAX_NUM_SIZE);
  38398. var end = new Uint8Array(MAX_NUM_SIZE);
  38399. var char = new Uint8Array(MAX_NUM_SIZE);
  38400. var charCode = new Uint8Array(MAX_NUM_SIZE);
  38401. var tmp = new Uint8Array(MAX_NUM_SIZE);
  38402. var code;
  38403. var b;
  38404. while ((b = stream.readByte()) >= 0) {
  38405. var type = b >> 5;
  38406. if (type === 7) {
  38407. // metadata, e.g. comment or usecmap
  38408. switch (b & 0x1F) {
  38409. case 0:
  38410. stream.readString();
  38411. // skipping comment
  38412. break;
  38413. case 1:
  38414. useCMap = stream.readString();
  38415. break;
  38416. }
  38417. continue;
  38418. }
  38419. var sequence = !!(b & 0x10);
  38420. var dataSize = b & 15;
  38421. assert(dataSize + 1 <= MAX_NUM_SIZE);
  38422. var ucs2DataSize = 1;
  38423. var subitemsCount = stream.readNumber();
  38424. var i;
  38425. switch (type) {
  38426. case 0:
  38427. // codespacerange
  38428. stream.readHex(start, dataSize);
  38429. stream.readHexNumber(end, dataSize);
  38430. addHex(end, start, dataSize);
  38431. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize), hexToInt(end, dataSize));
  38432. for (i = 1; i < subitemsCount; i++) {
  38433. incHex(end, dataSize);
  38434. stream.readHexNumber(start, dataSize);
  38435. addHex(start, end, dataSize);
  38436. stream.readHexNumber(end, dataSize);
  38437. addHex(end, start, dataSize);
  38438. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize), hexToInt(end, dataSize));
  38439. }
  38440. break;
  38441. case 1:
  38442. // notdefrange
  38443. stream.readHex(start, dataSize);
  38444. stream.readHexNumber(end, dataSize);
  38445. addHex(end, start, dataSize);
  38446. code = stream.readNumber();
  38447. // undefined range, skipping
  38448. for (i = 1; i < subitemsCount; i++) {
  38449. incHex(end, dataSize);
  38450. stream.readHexNumber(start, dataSize);
  38451. addHex(start, end, dataSize);
  38452. stream.readHexNumber(end, dataSize);
  38453. addHex(end, start, dataSize);
  38454. code = stream.readNumber();
  38455. }
  38456. // nop
  38457. break;
  38458. case 2:
  38459. // cidchar
  38460. stream.readHex(char, dataSize);
  38461. code = stream.readNumber();
  38462. cMap.mapOne(hexToInt(char, dataSize), code);
  38463. for (i = 1; i < subitemsCount; i++) {
  38464. incHex(char, dataSize);
  38465. if (!sequence) {
  38466. stream.readHexNumber(tmp, dataSize);
  38467. addHex(char, tmp, dataSize);
  38468. }
  38469. code = stream.readSigned() + (code + 1);
  38470. cMap.mapOne(hexToInt(char, dataSize), code);
  38471. }
  38472. break;
  38473. case 3:
  38474. // cidrange
  38475. stream.readHex(start, dataSize);
  38476. stream.readHexNumber(end, dataSize);
  38477. addHex(end, start, dataSize);
  38478. code = stream.readNumber();
  38479. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize), code);
  38480. for (i = 1; i < subitemsCount; i++) {
  38481. incHex(end, dataSize);
  38482. if (!sequence) {
  38483. stream.readHexNumber(start, dataSize);
  38484. addHex(start, end, dataSize);
  38485. } else {
  38486. start.set(end);
  38487. }
  38488. stream.readHexNumber(end, dataSize);
  38489. addHex(end, start, dataSize);
  38490. code = stream.readNumber();
  38491. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize), code);
  38492. }
  38493. break;
  38494. case 4:
  38495. // bfchar
  38496. stream.readHex(char, ucs2DataSize);
  38497. stream.readHex(charCode, dataSize);
  38498. cMap.mapOne(hexToInt(char, ucs2DataSize), hexToStr(charCode, dataSize));
  38499. for (i = 1; i < subitemsCount; i++) {
  38500. incHex(char, ucs2DataSize);
  38501. if (!sequence) {
  38502. stream.readHexNumber(tmp, ucs2DataSize);
  38503. addHex(char, tmp, ucs2DataSize);
  38504. }
  38505. incHex(charCode, dataSize);
  38506. stream.readHexSigned(tmp, dataSize);
  38507. addHex(charCode, tmp, dataSize);
  38508. cMap.mapOne(hexToInt(char, ucs2DataSize), hexToStr(charCode, dataSize));
  38509. }
  38510. break;
  38511. case 5:
  38512. // bfrange
  38513. stream.readHex(start, ucs2DataSize);
  38514. stream.readHexNumber(end, ucs2DataSize);
  38515. addHex(end, start, ucs2DataSize);
  38516. stream.readHex(charCode, dataSize);
  38517. cMap.mapBfRange(hexToInt(start, ucs2DataSize), hexToInt(end, ucs2DataSize), hexToStr(charCode, dataSize));
  38518. for (i = 1; i < subitemsCount; i++) {
  38519. incHex(end, ucs2DataSize);
  38520. if (!sequence) {
  38521. stream.readHexNumber(start, ucs2DataSize);
  38522. addHex(start, end, ucs2DataSize);
  38523. } else {
  38524. start.set(end);
  38525. }
  38526. stream.readHexNumber(end, ucs2DataSize);
  38527. addHex(end, start, ucs2DataSize);
  38528. stream.readHex(charCode, dataSize);
  38529. cMap.mapBfRange(hexToInt(start, ucs2DataSize), hexToInt(end, ucs2DataSize), hexToStr(charCode, dataSize));
  38530. }
  38531. break;
  38532. default:
  38533. error('Unknown type: ' + type);
  38534. break;
  38535. }
  38536. }
  38537. if (useCMap) {
  38538. return extend(useCMap);
  38539. }
  38540. return cMap;
  38541. });
  38542. }
  38543. function BinaryCMapReader() {
  38544. }
  38545. BinaryCMapReader.prototype = { read: processBinaryCMap };
  38546. return BinaryCMapReader;
  38547. }();
  38548. var CMapFactory = function CMapFactoryClosure() {
  38549. function strToInt(str) {
  38550. var a = 0;
  38551. for (var i = 0; i < str.length; i++) {
  38552. a = a << 8 | str.charCodeAt(i);
  38553. }
  38554. return a >>> 0;
  38555. }
  38556. function expectString(obj) {
  38557. if (!isString(obj)) {
  38558. error('Malformed CMap: expected string.');
  38559. }
  38560. }
  38561. function expectInt(obj) {
  38562. if (!isInt(obj)) {
  38563. error('Malformed CMap: expected int.');
  38564. }
  38565. }
  38566. function parseBfChar(cMap, lexer) {
  38567. while (true) {
  38568. var obj = lexer.getObj();
  38569. if (isEOF(obj)) {
  38570. break;
  38571. }
  38572. if (isCmd(obj, 'endbfchar')) {
  38573. return;
  38574. }
  38575. expectString(obj);
  38576. var src = strToInt(obj);
  38577. obj = lexer.getObj();
  38578. // TODO are /dstName used?
  38579. expectString(obj);
  38580. var dst = obj;
  38581. cMap.mapOne(src, dst);
  38582. }
  38583. }
  38584. function parseBfRange(cMap, lexer) {
  38585. while (true) {
  38586. var obj = lexer.getObj();
  38587. if (isEOF(obj)) {
  38588. break;
  38589. }
  38590. if (isCmd(obj, 'endbfrange')) {
  38591. return;
  38592. }
  38593. expectString(obj);
  38594. var low = strToInt(obj);
  38595. obj = lexer.getObj();
  38596. expectString(obj);
  38597. var high = strToInt(obj);
  38598. obj = lexer.getObj();
  38599. if (isInt(obj) || isString(obj)) {
  38600. var dstLow = isInt(obj) ? String.fromCharCode(obj) : obj;
  38601. cMap.mapBfRange(low, high, dstLow);
  38602. } else if (isCmd(obj, '[')) {
  38603. obj = lexer.getObj();
  38604. var array = [];
  38605. while (!isCmd(obj, ']') && !isEOF(obj)) {
  38606. array.push(obj);
  38607. obj = lexer.getObj();
  38608. }
  38609. cMap.mapBfRangeToArray(low, high, array);
  38610. } else {
  38611. break;
  38612. }
  38613. }
  38614. error('Invalid bf range.');
  38615. }
  38616. function parseCidChar(cMap, lexer) {
  38617. while (true) {
  38618. var obj = lexer.getObj();
  38619. if (isEOF(obj)) {
  38620. break;
  38621. }
  38622. if (isCmd(obj, 'endcidchar')) {
  38623. return;
  38624. }
  38625. expectString(obj);
  38626. var src = strToInt(obj);
  38627. obj = lexer.getObj();
  38628. expectInt(obj);
  38629. var dst = obj;
  38630. cMap.mapOne(src, dst);
  38631. }
  38632. }
  38633. function parseCidRange(cMap, lexer) {
  38634. while (true) {
  38635. var obj = lexer.getObj();
  38636. if (isEOF(obj)) {
  38637. break;
  38638. }
  38639. if (isCmd(obj, 'endcidrange')) {
  38640. return;
  38641. }
  38642. expectString(obj);
  38643. var low = strToInt(obj);
  38644. obj = lexer.getObj();
  38645. expectString(obj);
  38646. var high = strToInt(obj);
  38647. obj = lexer.getObj();
  38648. expectInt(obj);
  38649. var dstLow = obj;
  38650. cMap.mapCidRange(low, high, dstLow);
  38651. }
  38652. }
  38653. function parseCodespaceRange(cMap, lexer) {
  38654. while (true) {
  38655. var obj = lexer.getObj();
  38656. if (isEOF(obj)) {
  38657. break;
  38658. }
  38659. if (isCmd(obj, 'endcodespacerange')) {
  38660. return;
  38661. }
  38662. if (!isString(obj)) {
  38663. break;
  38664. }
  38665. var low = strToInt(obj);
  38666. obj = lexer.getObj();
  38667. if (!isString(obj)) {
  38668. break;
  38669. }
  38670. var high = strToInt(obj);
  38671. cMap.addCodespaceRange(obj.length, low, high);
  38672. }
  38673. error('Invalid codespace range.');
  38674. }
  38675. function parseWMode(cMap, lexer) {
  38676. var obj = lexer.getObj();
  38677. if (isInt(obj)) {
  38678. cMap.vertical = !!obj;
  38679. }
  38680. }
  38681. function parseCMapName(cMap, lexer) {
  38682. var obj = lexer.getObj();
  38683. if (isName(obj) && isString(obj.name)) {
  38684. cMap.name = obj.name;
  38685. }
  38686. }
  38687. function parseCMap(cMap, lexer, builtInCMapParams, useCMap) {
  38688. var previous;
  38689. var embededUseCMap;
  38690. objLoop:
  38691. while (true) {
  38692. try {
  38693. var obj = lexer.getObj();
  38694. if (isEOF(obj)) {
  38695. break;
  38696. } else if (isName(obj)) {
  38697. if (obj.name === 'WMode') {
  38698. parseWMode(cMap, lexer);
  38699. } else if (obj.name === 'CMapName') {
  38700. parseCMapName(cMap, lexer);
  38701. }
  38702. previous = obj;
  38703. } else if (isCmd(obj)) {
  38704. switch (obj.cmd) {
  38705. case 'endcmap':
  38706. break objLoop;
  38707. case 'usecmap':
  38708. if (isName(previous)) {
  38709. embededUseCMap = previous.name;
  38710. }
  38711. break;
  38712. case 'begincodespacerange':
  38713. parseCodespaceRange(cMap, lexer);
  38714. break;
  38715. case 'beginbfchar':
  38716. parseBfChar(cMap, lexer);
  38717. break;
  38718. case 'begincidchar':
  38719. parseCidChar(cMap, lexer);
  38720. break;
  38721. case 'beginbfrange':
  38722. parseBfRange(cMap, lexer);
  38723. break;
  38724. case 'begincidrange':
  38725. parseCidRange(cMap, lexer);
  38726. break;
  38727. }
  38728. }
  38729. } catch (ex) {
  38730. if (ex instanceof MissingDataException) {
  38731. throw ex;
  38732. }
  38733. warn('Invalid cMap data: ' + ex);
  38734. continue;
  38735. }
  38736. }
  38737. if (!useCMap && embededUseCMap) {
  38738. // Load the usecmap definition from the file only if there wasn't one
  38739. // specified.
  38740. useCMap = embededUseCMap;
  38741. }
  38742. if (useCMap) {
  38743. return extendCMap(cMap, builtInCMapParams, useCMap);
  38744. }
  38745. return Promise.resolve(cMap);
  38746. }
  38747. function extendCMap(cMap, builtInCMapParams, useCMap) {
  38748. return createBuiltInCMap(useCMap, builtInCMapParams).then(function (newCMap) {
  38749. cMap.useCMap = newCMap;
  38750. // If there aren't any code space ranges defined clone all the parent ones
  38751. // into this cMap.
  38752. if (cMap.numCodespaceRanges === 0) {
  38753. var useCodespaceRanges = cMap.useCMap.codespaceRanges;
  38754. for (var i = 0; i < useCodespaceRanges.length; i++) {
  38755. cMap.codespaceRanges[i] = useCodespaceRanges[i].slice();
  38756. }
  38757. cMap.numCodespaceRanges = cMap.useCMap.numCodespaceRanges;
  38758. }
  38759. // Merge the map into the current one, making sure not to override
  38760. // any previously defined entries.
  38761. cMap.useCMap.forEach(function (key, value) {
  38762. if (!cMap.contains(key)) {
  38763. cMap.mapOne(key, cMap.useCMap.lookup(key));
  38764. }
  38765. });
  38766. return cMap;
  38767. });
  38768. }
  38769. function parseBinaryCMap(name, builtInCMapParams) {
  38770. var url = builtInCMapParams.url + name + '.bcmap';
  38771. var cMap = new CMap(true);
  38772. return new BinaryCMapReader().read(url, cMap, function (useCMap) {
  38773. return extendCMap(cMap, builtInCMapParams, useCMap);
  38774. });
  38775. }
  38776. function createBuiltInCMap(name, builtInCMapParams) {
  38777. if (name === 'Identity-H') {
  38778. return Promise.resolve(new IdentityCMap(false, 2));
  38779. } else if (name === 'Identity-V') {
  38780. return Promise.resolve(new IdentityCMap(true, 2));
  38781. }
  38782. if (BUILT_IN_CMAPS.indexOf(name) === -1) {
  38783. return Promise.reject(new Error('Unknown cMap name: ' + name));
  38784. }
  38785. assert(builtInCMapParams, 'built-in cMap parameters are not provided');
  38786. if (builtInCMapParams.packed) {
  38787. return parseBinaryCMap(name, builtInCMapParams);
  38788. }
  38789. return new Promise(function (resolve, reject) {
  38790. var url = builtInCMapParams.url + name;
  38791. var request = new XMLHttpRequest();
  38792. request.onreadystatechange = function () {
  38793. if (request.readyState === XMLHttpRequest.DONE) {
  38794. if (request.status === 200 || request.status === 0) {
  38795. var cMap = new CMap(true);
  38796. var lexer = new Lexer(new StringStream(request.responseText));
  38797. parseCMap(cMap, lexer, builtInCMapParams, null).then(function (parsedCMap) {
  38798. resolve(parsedCMap);
  38799. });
  38800. } else {
  38801. reject(new Error('Unable to get cMap at: ' + url));
  38802. }
  38803. }
  38804. };
  38805. request.open('GET', url, true);
  38806. request.send(null);
  38807. });
  38808. }
  38809. return {
  38810. create: function (encoding, builtInCMapParams, useCMap) {
  38811. if (isName(encoding)) {
  38812. return createBuiltInCMap(encoding.name, builtInCMapParams);
  38813. } else if (isStream(encoding)) {
  38814. var cMap = new CMap();
  38815. var lexer = new Lexer(encoding);
  38816. return parseCMap(cMap, lexer, builtInCMapParams, useCMap).then(function (parsedCMap) {
  38817. if (parsedCMap.isIdentityCMap) {
  38818. return createBuiltInCMap(parsedCMap.name, builtInCMapParams);
  38819. }
  38820. return parsedCMap;
  38821. });
  38822. }
  38823. return Promise.reject(new Error('Encoding required.'));
  38824. }
  38825. };
  38826. }();
  38827. exports.CMap = CMap;
  38828. exports.CMapFactory = CMapFactory;
  38829. exports.IdentityCMap = IdentityCMap;
  38830. }));
  38831. (function (root, factory) {
  38832. factory(root.pdfjsCoreFonts = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreGlyphList, root.pdfjsCoreFontRenderer, root.pdfjsCoreEncodings, root.pdfjsCoreStandardFonts, root.pdfjsCoreUnicode, root.pdfjsCoreType1Parser, root.pdfjsCoreCFFParser);
  38833. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreGlyphList, coreFontRenderer, coreEncodings, coreStandardFonts, coreUnicode, coreType1Parser, coreCFFParser) {
  38834. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  38835. var FontType = sharedUtil.FontType;
  38836. var assert = sharedUtil.assert;
  38837. var bytesToString = sharedUtil.bytesToString;
  38838. var error = sharedUtil.error;
  38839. var info = sharedUtil.info;
  38840. var isArray = sharedUtil.isArray;
  38841. var isInt = sharedUtil.isInt;
  38842. var isNum = sharedUtil.isNum;
  38843. var readUint32 = sharedUtil.readUint32;
  38844. var shadow = sharedUtil.shadow;
  38845. var string32 = sharedUtil.string32;
  38846. var warn = sharedUtil.warn;
  38847. var MissingDataException = sharedUtil.MissingDataException;
  38848. var isSpace = sharedUtil.isSpace;
  38849. var Stream = coreStream.Stream;
  38850. var getGlyphsUnicode = coreGlyphList.getGlyphsUnicode;
  38851. var getDingbatsGlyphsUnicode = coreGlyphList.getDingbatsGlyphsUnicode;
  38852. var FontRendererFactory = coreFontRenderer.FontRendererFactory;
  38853. var StandardEncoding = coreEncodings.StandardEncoding;
  38854. var MacRomanEncoding = coreEncodings.MacRomanEncoding;
  38855. var SymbolSetEncoding = coreEncodings.SymbolSetEncoding;
  38856. var ZapfDingbatsEncoding = coreEncodings.ZapfDingbatsEncoding;
  38857. var getEncoding = coreEncodings.getEncoding;
  38858. var getStdFontMap = coreStandardFonts.getStdFontMap;
  38859. var getNonStdFontMap = coreStandardFonts.getNonStdFontMap;
  38860. var getGlyphMapForStandardFonts = coreStandardFonts.getGlyphMapForStandardFonts;
  38861. var getSupplementalGlyphMapForArialBlack = coreStandardFonts.getSupplementalGlyphMapForArialBlack;
  38862. var getUnicodeRangeFor = coreUnicode.getUnicodeRangeFor;
  38863. var mapSpecialUnicodeValues = coreUnicode.mapSpecialUnicodeValues;
  38864. var getUnicodeForGlyph = coreUnicode.getUnicodeForGlyph;
  38865. var Type1Parser = coreType1Parser.Type1Parser;
  38866. var CFFStandardStrings = coreCFFParser.CFFStandardStrings;
  38867. var CFFParser = coreCFFParser.CFFParser;
  38868. var CFFCompiler = coreCFFParser.CFFCompiler;
  38869. var CFF = coreCFFParser.CFF;
  38870. var CFFHeader = coreCFFParser.CFFHeader;
  38871. var CFFTopDict = coreCFFParser.CFFTopDict;
  38872. var CFFPrivateDict = coreCFFParser.CFFPrivateDict;
  38873. var CFFStrings = coreCFFParser.CFFStrings;
  38874. var CFFIndex = coreCFFParser.CFFIndex;
  38875. var CFFCharset = coreCFFParser.CFFCharset;
  38876. // Unicode Private Use Area
  38877. var PRIVATE_USE_OFFSET_START = 0xE000;
  38878. var PRIVATE_USE_OFFSET_END = 0xF8FF;
  38879. var SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = false;
  38880. // PDF Glyph Space Units are one Thousandth of a TextSpace Unit
  38881. // except for Type 3 fonts
  38882. var PDF_GLYPH_SPACE_UNITS = 1000;
  38883. // Accented charactars are not displayed properly on Windows, using this flag
  38884. // to control analysis of seac charstrings.
  38885. var SEAC_ANALYSIS_ENABLED = false;
  38886. var FontFlags = {
  38887. FixedPitch: 1,
  38888. Serif: 2,
  38889. Symbolic: 4,
  38890. Script: 8,
  38891. Nonsymbolic: 32,
  38892. Italic: 64,
  38893. AllCap: 65536,
  38894. SmallCap: 131072,
  38895. ForceBold: 262144
  38896. };
  38897. var MacStandardGlyphOrdering = [
  38898. '.notdef',
  38899. '.null',
  38900. 'nonmarkingreturn',
  38901. 'space',
  38902. 'exclam',
  38903. 'quotedbl',
  38904. 'numbersign',
  38905. 'dollar',
  38906. 'percent',
  38907. 'ampersand',
  38908. 'quotesingle',
  38909. 'parenleft',
  38910. 'parenright',
  38911. 'asterisk',
  38912. 'plus',
  38913. 'comma',
  38914. 'hyphen',
  38915. 'period',
  38916. 'slash',
  38917. 'zero',
  38918. 'one',
  38919. 'two',
  38920. 'three',
  38921. 'four',
  38922. 'five',
  38923. 'six',
  38924. 'seven',
  38925. 'eight',
  38926. 'nine',
  38927. 'colon',
  38928. 'semicolon',
  38929. 'less',
  38930. 'equal',
  38931. 'greater',
  38932. 'question',
  38933. 'at',
  38934. 'A',
  38935. 'B',
  38936. 'C',
  38937. 'D',
  38938. 'E',
  38939. 'F',
  38940. 'G',
  38941. 'H',
  38942. 'I',
  38943. 'J',
  38944. 'K',
  38945. 'L',
  38946. 'M',
  38947. 'N',
  38948. 'O',
  38949. 'P',
  38950. 'Q',
  38951. 'R',
  38952. 'S',
  38953. 'T',
  38954. 'U',
  38955. 'V',
  38956. 'W',
  38957. 'X',
  38958. 'Y',
  38959. 'Z',
  38960. 'bracketleft',
  38961. 'backslash',
  38962. 'bracketright',
  38963. 'asciicircum',
  38964. 'underscore',
  38965. 'grave',
  38966. 'a',
  38967. 'b',
  38968. 'c',
  38969. 'd',
  38970. 'e',
  38971. 'f',
  38972. 'g',
  38973. 'h',
  38974. 'i',
  38975. 'j',
  38976. 'k',
  38977. 'l',
  38978. 'm',
  38979. 'n',
  38980. 'o',
  38981. 'p',
  38982. 'q',
  38983. 'r',
  38984. 's',
  38985. 't',
  38986. 'u',
  38987. 'v',
  38988. 'w',
  38989. 'x',
  38990. 'y',
  38991. 'z',
  38992. 'braceleft',
  38993. 'bar',
  38994. 'braceright',
  38995. 'asciitilde',
  38996. 'Adieresis',
  38997. 'Aring',
  38998. 'Ccedilla',
  38999. 'Eacute',
  39000. 'Ntilde',
  39001. 'Odieresis',
  39002. 'Udieresis',
  39003. 'aacute',
  39004. 'agrave',
  39005. 'acircumflex',
  39006. 'adieresis',
  39007. 'atilde',
  39008. 'aring',
  39009. 'ccedilla',
  39010. 'eacute',
  39011. 'egrave',
  39012. 'ecircumflex',
  39013. 'edieresis',
  39014. 'iacute',
  39015. 'igrave',
  39016. 'icircumflex',
  39017. 'idieresis',
  39018. 'ntilde',
  39019. 'oacute',
  39020. 'ograve',
  39021. 'ocircumflex',
  39022. 'odieresis',
  39023. 'otilde',
  39024. 'uacute',
  39025. 'ugrave',
  39026. 'ucircumflex',
  39027. 'udieresis',
  39028. 'dagger',
  39029. 'degree',
  39030. 'cent',
  39031. 'sterling',
  39032. 'section',
  39033. 'bullet',
  39034. 'paragraph',
  39035. 'germandbls',
  39036. 'registered',
  39037. 'copyright',
  39038. 'trademark',
  39039. 'acute',
  39040. 'dieresis',
  39041. 'notequal',
  39042. 'AE',
  39043. 'Oslash',
  39044. 'infinity',
  39045. 'plusminus',
  39046. 'lessequal',
  39047. 'greaterequal',
  39048. 'yen',
  39049. 'mu',
  39050. 'partialdiff',
  39051. 'summation',
  39052. 'product',
  39053. 'pi',
  39054. 'integral',
  39055. 'ordfeminine',
  39056. 'ordmasculine',
  39057. 'Omega',
  39058. 'ae',
  39059. 'oslash',
  39060. 'questiondown',
  39061. 'exclamdown',
  39062. 'logicalnot',
  39063. 'radical',
  39064. 'florin',
  39065. 'approxequal',
  39066. 'Delta',
  39067. 'guillemotleft',
  39068. 'guillemotright',
  39069. 'ellipsis',
  39070. 'nonbreakingspace',
  39071. 'Agrave',
  39072. 'Atilde',
  39073. 'Otilde',
  39074. 'OE',
  39075. 'oe',
  39076. 'endash',
  39077. 'emdash',
  39078. 'quotedblleft',
  39079. 'quotedblright',
  39080. 'quoteleft',
  39081. 'quoteright',
  39082. 'divide',
  39083. 'lozenge',
  39084. 'ydieresis',
  39085. 'Ydieresis',
  39086. 'fraction',
  39087. 'currency',
  39088. 'guilsinglleft',
  39089. 'guilsinglright',
  39090. 'fi',
  39091. 'fl',
  39092. 'daggerdbl',
  39093. 'periodcentered',
  39094. 'quotesinglbase',
  39095. 'quotedblbase',
  39096. 'perthousand',
  39097. 'Acircumflex',
  39098. 'Ecircumflex',
  39099. 'Aacute',
  39100. 'Edieresis',
  39101. 'Egrave',
  39102. 'Iacute',
  39103. 'Icircumflex',
  39104. 'Idieresis',
  39105. 'Igrave',
  39106. 'Oacute',
  39107. 'Ocircumflex',
  39108. 'apple',
  39109. 'Ograve',
  39110. 'Uacute',
  39111. 'Ucircumflex',
  39112. 'Ugrave',
  39113. 'dotlessi',
  39114. 'circumflex',
  39115. 'tilde',
  39116. 'macron',
  39117. 'breve',
  39118. 'dotaccent',
  39119. 'ring',
  39120. 'cedilla',
  39121. 'hungarumlaut',
  39122. 'ogonek',
  39123. 'caron',
  39124. 'Lslash',
  39125. 'lslash',
  39126. 'Scaron',
  39127. 'scaron',
  39128. 'Zcaron',
  39129. 'zcaron',
  39130. 'brokenbar',
  39131. 'Eth',
  39132. 'eth',
  39133. 'Yacute',
  39134. 'yacute',
  39135. 'Thorn',
  39136. 'thorn',
  39137. 'minus',
  39138. 'multiply',
  39139. 'onesuperior',
  39140. 'twosuperior',
  39141. 'threesuperior',
  39142. 'onehalf',
  39143. 'onequarter',
  39144. 'threequarters',
  39145. 'franc',
  39146. 'Gbreve',
  39147. 'gbreve',
  39148. 'Idotaccent',
  39149. 'Scedilla',
  39150. 'scedilla',
  39151. 'Cacute',
  39152. 'cacute',
  39153. 'Ccaron',
  39154. 'ccaron',
  39155. 'dcroat'
  39156. ];
  39157. function adjustWidths(properties) {
  39158. if (!properties.fontMatrix) {
  39159. return;
  39160. }
  39161. if (properties.fontMatrix[0] === FONT_IDENTITY_MATRIX[0]) {
  39162. return;
  39163. }
  39164. // adjusting width to fontMatrix scale
  39165. var scale = 0.001 / properties.fontMatrix[0];
  39166. var glyphsWidths = properties.widths;
  39167. for (var glyph in glyphsWidths) {
  39168. glyphsWidths[glyph] *= scale;
  39169. }
  39170. properties.defaultWidth *= scale;
  39171. }
  39172. function adjustToUnicode(properties, builtInEncoding) {
  39173. if (properties.hasIncludedToUnicodeMap) {
  39174. return;
  39175. }
  39176. // The font dictionary has a `ToUnicode` entry.
  39177. if (properties.hasEncoding) {
  39178. return;
  39179. }
  39180. // The font dictionary has an `Encoding` entry.
  39181. if (builtInEncoding === properties.defaultEncoding) {
  39182. return;
  39183. }
  39184. // No point in trying to adjust `toUnicode` if the encodings match.
  39185. if (properties.toUnicode instanceof IdentityToUnicodeMap) {
  39186. return;
  39187. }
  39188. var toUnicode = [], glyphsUnicodeMap = getGlyphsUnicode();
  39189. for (var charCode in builtInEncoding) {
  39190. var glyphName = builtInEncoding[charCode];
  39191. var unicode = getUnicodeForGlyph(glyphName, glyphsUnicodeMap);
  39192. if (unicode !== -1) {
  39193. toUnicode[charCode] = String.fromCharCode(unicode);
  39194. }
  39195. }
  39196. properties.toUnicode.amend(toUnicode);
  39197. }
  39198. function getFontType(type, subtype) {
  39199. switch (type) {
  39200. case 'Type1':
  39201. return subtype === 'Type1C' ? FontType.TYPE1C : FontType.TYPE1;
  39202. case 'CIDFontType0':
  39203. return subtype === 'CIDFontType0C' ? FontType.CIDFONTTYPE0C : FontType.CIDFONTTYPE0;
  39204. case 'OpenType':
  39205. return FontType.OPENTYPE;
  39206. case 'TrueType':
  39207. return FontType.TRUETYPE;
  39208. case 'CIDFontType2':
  39209. return FontType.CIDFONTTYPE2;
  39210. case 'MMType1':
  39211. return FontType.MMTYPE1;
  39212. case 'Type0':
  39213. return FontType.TYPE0;
  39214. default:
  39215. return FontType.UNKNOWN;
  39216. }
  39217. }
  39218. // Some bad PDF generators, e.g. Scribus PDF, include glyph names
  39219. // in a 'uniXXXX' format -- attempting to recover proper ones.
  39220. function recoverGlyphName(name, glyphsUnicodeMap) {
  39221. if (glyphsUnicodeMap[name] !== undefined) {
  39222. return name;
  39223. }
  39224. // The glyph name is non-standard, trying to recover.
  39225. var unicode = getUnicodeForGlyph(name, glyphsUnicodeMap);
  39226. if (unicode !== -1) {
  39227. for (var key in glyphsUnicodeMap) {
  39228. if (glyphsUnicodeMap[key] === unicode) {
  39229. return key;
  39230. }
  39231. }
  39232. }
  39233. info('Unable to recover a standard glyph name for: ' + name);
  39234. return name;
  39235. }
  39236. var Glyph = function GlyphClosure() {
  39237. function Glyph(fontChar, unicode, accent, width, vmetric, operatorListId, isSpace, isInFont) {
  39238. this.fontChar = fontChar;
  39239. this.unicode = unicode;
  39240. this.accent = accent;
  39241. this.width = width;
  39242. this.vmetric = vmetric;
  39243. this.operatorListId = operatorListId;
  39244. this.isSpace = isSpace;
  39245. this.isInFont = isInFont;
  39246. }
  39247. Glyph.prototype.matchesForCache = function (fontChar, unicode, accent, width, vmetric, operatorListId, isSpace, isInFont) {
  39248. return this.fontChar === fontChar && this.unicode === unicode && this.accent === accent && this.width === width && this.vmetric === vmetric && this.operatorListId === operatorListId && this.isSpace === isSpace && this.isInFont === isInFont;
  39249. };
  39250. return Glyph;
  39251. }();
  39252. var ToUnicodeMap = function ToUnicodeMapClosure() {
  39253. function ToUnicodeMap(cmap) {
  39254. // The elements of this._map can be integers or strings, depending on how
  39255. // |cmap| was created.
  39256. this._map = cmap;
  39257. }
  39258. ToUnicodeMap.prototype = {
  39259. get length() {
  39260. return this._map.length;
  39261. },
  39262. forEach: function (callback) {
  39263. for (var charCode in this._map) {
  39264. callback(charCode, this._map[charCode].charCodeAt(0));
  39265. }
  39266. },
  39267. has: function (i) {
  39268. return this._map[i] !== undefined;
  39269. },
  39270. get: function (i) {
  39271. return this._map[i];
  39272. },
  39273. charCodeOf: function (v) {
  39274. return this._map.indexOf(v);
  39275. },
  39276. amend: function (map) {
  39277. for (var charCode in map) {
  39278. this._map[charCode] = map[charCode];
  39279. }
  39280. }
  39281. };
  39282. return ToUnicodeMap;
  39283. }();
  39284. var IdentityToUnicodeMap = function IdentityToUnicodeMapClosure() {
  39285. function IdentityToUnicodeMap(firstChar, lastChar) {
  39286. this.firstChar = firstChar;
  39287. this.lastChar = lastChar;
  39288. }
  39289. IdentityToUnicodeMap.prototype = {
  39290. get length() {
  39291. return this.lastChar + 1 - this.firstChar;
  39292. },
  39293. forEach: function (callback) {
  39294. for (var i = this.firstChar, ii = this.lastChar; i <= ii; i++) {
  39295. callback(i, i);
  39296. }
  39297. },
  39298. has: function (i) {
  39299. return this.firstChar <= i && i <= this.lastChar;
  39300. },
  39301. get: function (i) {
  39302. if (this.firstChar <= i && i <= this.lastChar) {
  39303. return String.fromCharCode(i);
  39304. }
  39305. return undefined;
  39306. },
  39307. charCodeOf: function (v) {
  39308. return isInt(v) && v >= this.firstChar && v <= this.lastChar ? v : -1;
  39309. },
  39310. amend: function (map) {
  39311. error('Should not call amend()');
  39312. }
  39313. };
  39314. return IdentityToUnicodeMap;
  39315. }();
  39316. var OpenTypeFileBuilder = function OpenTypeFileBuilderClosure() {
  39317. function writeInt16(dest, offset, num) {
  39318. dest[offset] = num >> 8 & 0xFF;
  39319. dest[offset + 1] = num & 0xFF;
  39320. }
  39321. function writeInt32(dest, offset, num) {
  39322. dest[offset] = num >> 24 & 0xFF;
  39323. dest[offset + 1] = num >> 16 & 0xFF;
  39324. dest[offset + 2] = num >> 8 & 0xFF;
  39325. dest[offset + 3] = num & 0xFF;
  39326. }
  39327. function writeData(dest, offset, data) {
  39328. var i, ii;
  39329. if (data instanceof Uint8Array) {
  39330. dest.set(data, offset);
  39331. } else if (typeof data === 'string') {
  39332. for (i = 0, ii = data.length; i < ii; i++) {
  39333. dest[offset++] = data.charCodeAt(i) & 0xFF;
  39334. }
  39335. } else {
  39336. // treating everything else as array
  39337. for (i = 0, ii = data.length; i < ii; i++) {
  39338. dest[offset++] = data[i] & 0xFF;
  39339. }
  39340. }
  39341. }
  39342. function OpenTypeFileBuilder(sfnt) {
  39343. this.sfnt = sfnt;
  39344. this.tables = Object.create(null);
  39345. }
  39346. OpenTypeFileBuilder.getSearchParams = function OpenTypeFileBuilder_getSearchParams(entriesCount, entrySize) {
  39347. var maxPower2 = 1, log2 = 0;
  39348. while ((maxPower2 ^ entriesCount) > maxPower2) {
  39349. maxPower2 <<= 1;
  39350. log2++;
  39351. }
  39352. var searchRange = maxPower2 * entrySize;
  39353. return {
  39354. range: searchRange,
  39355. entry: log2,
  39356. rangeShift: entrySize * entriesCount - searchRange
  39357. };
  39358. };
  39359. var OTF_HEADER_SIZE = 12;
  39360. var OTF_TABLE_ENTRY_SIZE = 16;
  39361. OpenTypeFileBuilder.prototype = {
  39362. toArray: function OpenTypeFileBuilder_toArray() {
  39363. var sfnt = this.sfnt;
  39364. // Tables needs to be written by ascendant alphabetic order
  39365. var tables = this.tables;
  39366. var tablesNames = Object.keys(tables);
  39367. tablesNames.sort();
  39368. var numTables = tablesNames.length;
  39369. var i, j, jj, table, tableName;
  39370. // layout the tables data
  39371. var offset = OTF_HEADER_SIZE + numTables * OTF_TABLE_ENTRY_SIZE;
  39372. var tableOffsets = [offset];
  39373. for (i = 0; i < numTables; i++) {
  39374. table = tables[tablesNames[i]];
  39375. var paddedLength = (table.length + 3 & ~3) >>> 0;
  39376. offset += paddedLength;
  39377. tableOffsets.push(offset);
  39378. }
  39379. var file = new Uint8Array(offset);
  39380. // write the table data first (mostly for checksum)
  39381. for (i = 0; i < numTables; i++) {
  39382. table = tables[tablesNames[i]];
  39383. writeData(file, tableOffsets[i], table);
  39384. }
  39385. // sfnt version (4 bytes)
  39386. if (sfnt === 'true') {
  39387. // Windows hates the Mac TrueType sfnt version number
  39388. sfnt = string32(0x00010000);
  39389. }
  39390. file[0] = sfnt.charCodeAt(0) & 0xFF;
  39391. file[1] = sfnt.charCodeAt(1) & 0xFF;
  39392. file[2] = sfnt.charCodeAt(2) & 0xFF;
  39393. file[3] = sfnt.charCodeAt(3) & 0xFF;
  39394. // numTables (2 bytes)
  39395. writeInt16(file, 4, numTables);
  39396. var searchParams = OpenTypeFileBuilder.getSearchParams(numTables, 16);
  39397. // searchRange (2 bytes)
  39398. writeInt16(file, 6, searchParams.range);
  39399. // entrySelector (2 bytes)
  39400. writeInt16(file, 8, searchParams.entry);
  39401. // rangeShift (2 bytes)
  39402. writeInt16(file, 10, searchParams.rangeShift);
  39403. offset = OTF_HEADER_SIZE;
  39404. // writing table entries
  39405. for (i = 0; i < numTables; i++) {
  39406. tableName = tablesNames[i];
  39407. file[offset] = tableName.charCodeAt(0) & 0xFF;
  39408. file[offset + 1] = tableName.charCodeAt(1) & 0xFF;
  39409. file[offset + 2] = tableName.charCodeAt(2) & 0xFF;
  39410. file[offset + 3] = tableName.charCodeAt(3) & 0xFF;
  39411. // checksum
  39412. var checksum = 0;
  39413. for (j = tableOffsets[i], jj = tableOffsets[i + 1]; j < jj; j += 4) {
  39414. var quad = readUint32(file, j);
  39415. checksum = checksum + quad >>> 0;
  39416. }
  39417. writeInt32(file, offset + 4, checksum);
  39418. // offset
  39419. writeInt32(file, offset + 8, tableOffsets[i]);
  39420. // length
  39421. writeInt32(file, offset + 12, tables[tableName].length);
  39422. offset += OTF_TABLE_ENTRY_SIZE;
  39423. }
  39424. return file;
  39425. },
  39426. addTable: function OpenTypeFileBuilder_addTable(tag, data) {
  39427. if (tag in this.tables) {
  39428. throw new Error('Table ' + tag + ' already exists');
  39429. }
  39430. this.tables[tag] = data;
  39431. }
  39432. };
  39433. return OpenTypeFileBuilder;
  39434. }();
  39435. // Problematic Unicode characters in the fonts that needs to be moved to avoid
  39436. // issues when they are painted on the canvas, e.g. complex-script shaping or
  39437. // control/whitespace characters. The ranges are listed in pairs: the first item
  39438. // is a code of the first problematic code, the second one is the next
  39439. // non-problematic code. The ranges must be in sorted order.
  39440. var ProblematicCharRanges = new Int32Array([
  39441. // Control characters.
  39442. 0x0000,
  39443. 0x0020,
  39444. 0x007F,
  39445. 0x00A1,
  39446. 0x00AD,
  39447. 0x00AE,
  39448. // Chars that is used in complex-script shaping.
  39449. 0x0600,
  39450. 0x0780,
  39451. 0x08A0,
  39452. 0x10A0,
  39453. 0x1780,
  39454. 0x1800,
  39455. 0x1C00,
  39456. 0x1C50,
  39457. // General punctuation chars.
  39458. 0x2000,
  39459. 0x2010,
  39460. 0x2011,
  39461. 0x2012,
  39462. 0x2028,
  39463. 0x2030,
  39464. 0x205F,
  39465. 0x2070,
  39466. 0x25CC,
  39467. 0x25CD,
  39468. 0x3000,
  39469. 0x3001,
  39470. // Chars that is used in complex-script shaping.
  39471. 0xAA60,
  39472. 0xAA80,
  39473. // Specials Unicode block.
  39474. 0xFFF0,
  39475. 0x10000
  39476. ]);
  39477. /**
  39478. * 'Font' is the class the outside world should use, it encapsulate all the font
  39479. * decoding logics whatever type it is (assuming the font type is supported).
  39480. *
  39481. * For example to read a Type1 font and to attach it to the document:
  39482. * var type1Font = new Font("MyFontName", binaryFile, propertiesObject);
  39483. * type1Font.bind();
  39484. */
  39485. var Font = function FontClosure() {
  39486. function Font(name, file, properties) {
  39487. var charCode, glyphName, unicode;
  39488. this.name = name;
  39489. this.loadedName = properties.loadedName;
  39490. this.isType3Font = properties.isType3Font;
  39491. this.sizes = [];
  39492. this.missingFile = false;
  39493. this.glyphCache = Object.create(null);
  39494. var names = name.split('+');
  39495. names = names.length > 1 ? names[1] : names[0];
  39496. names = names.split(/[-,_]/g)[0];
  39497. this.isSerifFont = !!(properties.flags & FontFlags.Serif);
  39498. this.isSymbolicFont = !!(properties.flags & FontFlags.Symbolic);
  39499. this.isMonospace = !!(properties.flags & FontFlags.FixedPitch);
  39500. var type = properties.type;
  39501. var subtype = properties.subtype;
  39502. this.type = type;
  39503. this.fallbackName = this.isMonospace ? 'monospace' : this.isSerifFont ? 'serif' : 'sans-serif';
  39504. this.differences = properties.differences;
  39505. this.widths = properties.widths;
  39506. this.defaultWidth = properties.defaultWidth;
  39507. this.composite = properties.composite;
  39508. this.wideChars = properties.wideChars;
  39509. this.cMap = properties.cMap;
  39510. this.ascent = properties.ascent / PDF_GLYPH_SPACE_UNITS;
  39511. this.descent = properties.descent / PDF_GLYPH_SPACE_UNITS;
  39512. this.fontMatrix = properties.fontMatrix;
  39513. this.bbox = properties.bbox;
  39514. this.toUnicode = properties.toUnicode;
  39515. this.toFontChar = [];
  39516. if (properties.type === 'Type3') {
  39517. for (charCode = 0; charCode < 256; charCode++) {
  39518. this.toFontChar[charCode] = this.differences[charCode] || properties.defaultEncoding[charCode];
  39519. }
  39520. this.fontType = FontType.TYPE3;
  39521. return;
  39522. }
  39523. this.cidEncoding = properties.cidEncoding;
  39524. this.vertical = properties.vertical;
  39525. if (this.vertical) {
  39526. this.vmetrics = properties.vmetrics;
  39527. this.defaultVMetrics = properties.defaultVMetrics;
  39528. }
  39529. var glyphsUnicodeMap;
  39530. if (!file || file.isEmpty) {
  39531. if (file) {
  39532. // Some bad PDF generators will include empty font files,
  39533. // attempting to recover by assuming that no file exists.
  39534. warn('Font file is empty in "' + name + '" (' + this.loadedName + ')');
  39535. }
  39536. this.missingFile = true;
  39537. // The file data is not specified. Trying to fix the font name
  39538. // to be used with the canvas.font.
  39539. var fontName = name.replace(/[,_]/g, '-');
  39540. var stdFontMap = getStdFontMap(), nonStdFontMap = getNonStdFontMap();
  39541. var isStandardFont = !!stdFontMap[fontName] || !!(nonStdFontMap[fontName] && stdFontMap[nonStdFontMap[fontName]]);
  39542. fontName = stdFontMap[fontName] || nonStdFontMap[fontName] || fontName;
  39543. this.bold = fontName.search(/bold/gi) !== -1;
  39544. this.italic = fontName.search(/oblique/gi) !== -1 || fontName.search(/italic/gi) !== -1;
  39545. // Use 'name' instead of 'fontName' here because the original
  39546. // name ArialBlack for example will be replaced by Helvetica.
  39547. this.black = name.search(/Black/g) !== -1;
  39548. // if at least one width is present, remeasure all chars when exists
  39549. this.remeasure = Object.keys(this.widths).length > 0;
  39550. if (isStandardFont && type === 'CIDFontType2' && properties.cidEncoding.indexOf('Identity-') === 0) {
  39551. var GlyphMapForStandardFonts = getGlyphMapForStandardFonts();
  39552. // Standard fonts might be embedded as CID font without glyph mapping.
  39553. // Building one based on GlyphMapForStandardFonts.
  39554. var map = [];
  39555. for (charCode in GlyphMapForStandardFonts) {
  39556. map[+charCode] = GlyphMapForStandardFonts[charCode];
  39557. }
  39558. if (/ArialBlack/i.test(name)) {
  39559. var SupplementalGlyphMapForArialBlack = getSupplementalGlyphMapForArialBlack();
  39560. for (charCode in SupplementalGlyphMapForArialBlack) {
  39561. map[+charCode] = SupplementalGlyphMapForArialBlack[charCode];
  39562. }
  39563. }
  39564. var isIdentityUnicode = this.toUnicode instanceof IdentityToUnicodeMap;
  39565. if (!isIdentityUnicode) {
  39566. this.toUnicode.forEach(function (charCode, unicodeCharCode) {
  39567. map[+charCode] = unicodeCharCode;
  39568. });
  39569. }
  39570. this.toFontChar = map;
  39571. this.toUnicode = new ToUnicodeMap(map);
  39572. } else if (/Symbol/i.test(fontName)) {
  39573. this.toFontChar = buildToFontChar(SymbolSetEncoding, getGlyphsUnicode(), properties.differences);
  39574. } else if (/Dingbats/i.test(fontName)) {
  39575. if (/Wingdings/i.test(name)) {
  39576. warn('Non-embedded Wingdings font, falling back to ZapfDingbats.');
  39577. }
  39578. this.toFontChar = buildToFontChar(ZapfDingbatsEncoding, getDingbatsGlyphsUnicode(), properties.differences);
  39579. } else if (isStandardFont) {
  39580. this.toFontChar = buildToFontChar(properties.defaultEncoding, getGlyphsUnicode(), properties.differences);
  39581. } else {
  39582. glyphsUnicodeMap = getGlyphsUnicode();
  39583. this.toUnicode.forEach(function (charCode, unicodeCharCode) {
  39584. if (!this.composite) {
  39585. glyphName = properties.differences[charCode] || properties.defaultEncoding[charCode];
  39586. unicode = getUnicodeForGlyph(glyphName, glyphsUnicodeMap);
  39587. if (unicode !== -1) {
  39588. unicodeCharCode = unicode;
  39589. }
  39590. }
  39591. this.toFontChar[charCode] = unicodeCharCode;
  39592. }.bind(this));
  39593. }
  39594. this.loadedName = fontName.split('-')[0];
  39595. this.loading = false;
  39596. this.fontType = getFontType(type, subtype);
  39597. return;
  39598. }
  39599. // Some fonts might use wrong font types for Type1C or CIDFontType0C
  39600. if (subtype === 'Type1C') {
  39601. if (type !== 'Type1' && type !== 'MMType1') {
  39602. // Some TrueType fonts by mistake claim Type1C
  39603. if (isTrueTypeFile(file)) {
  39604. subtype = 'TrueType';
  39605. } else {
  39606. type = 'Type1';
  39607. }
  39608. } else if (isOpenTypeFile(file)) {
  39609. // Sometimes the type/subtype can be a complete lie (see issue7598.pdf).
  39610. type = subtype = 'OpenType';
  39611. }
  39612. }
  39613. if (subtype === 'CIDFontType0C' && type !== 'CIDFontType0') {
  39614. type = 'CIDFontType0';
  39615. }
  39616. if (subtype === 'OpenType') {
  39617. type = 'OpenType';
  39618. }
  39619. // Some CIDFontType0C fonts by mistake claim CIDFontType0.
  39620. if (type === 'CIDFontType0') {
  39621. if (isType1File(file)) {
  39622. subtype = 'CIDFontType0';
  39623. } else if (isOpenTypeFile(file)) {
  39624. // Sometimes the type/subtype can be a complete lie (see issue6782.pdf).
  39625. type = subtype = 'OpenType';
  39626. } else {
  39627. subtype = 'CIDFontType0C';
  39628. }
  39629. }
  39630. var data;
  39631. switch (type) {
  39632. case 'MMType1':
  39633. info('MMType1 font (' + name + '), falling back to Type1.');
  39634. case 'Type1':
  39635. case 'CIDFontType0':
  39636. this.mimetype = 'font/opentype';
  39637. var cff = subtype === 'Type1C' || subtype === 'CIDFontType0C' ? new CFFFont(file, properties) : new Type1Font(name, file, properties);
  39638. adjustWidths(properties);
  39639. // Wrap the CFF data inside an OTF font file
  39640. data = this.convert(name, cff, properties);
  39641. break;
  39642. case 'OpenType':
  39643. case 'TrueType':
  39644. case 'CIDFontType2':
  39645. this.mimetype = 'font/opentype';
  39646. // Repair the TrueType file. It is can be damaged in the point of
  39647. // view of the sanitizer
  39648. data = this.checkAndRepair(name, file, properties);
  39649. if (this.isOpenType) {
  39650. adjustWidths(properties);
  39651. type = 'OpenType';
  39652. }
  39653. break;
  39654. default:
  39655. error('Font ' + type + ' is not supported');
  39656. break;
  39657. }
  39658. this.data = data;
  39659. this.fontType = getFontType(type, subtype);
  39660. // Transfer some properties again that could change during font conversion
  39661. this.fontMatrix = properties.fontMatrix;
  39662. this.widths = properties.widths;
  39663. this.defaultWidth = properties.defaultWidth;
  39664. this.toUnicode = properties.toUnicode;
  39665. this.encoding = properties.baseEncoding;
  39666. this.seacMap = properties.seacMap;
  39667. this.loading = true;
  39668. }
  39669. Font.getFontID = function () {
  39670. var ID = 1;
  39671. return function Font_getFontID() {
  39672. return String(ID++);
  39673. };
  39674. }();
  39675. function int16(b0, b1) {
  39676. return (b0 << 8) + b1;
  39677. }
  39678. function signedInt16(b0, b1) {
  39679. var value = (b0 << 8) + b1;
  39680. return value & 1 << 15 ? value - 0x10000 : value;
  39681. }
  39682. function int32(b0, b1, b2, b3) {
  39683. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  39684. }
  39685. function string16(value) {
  39686. return String.fromCharCode(value >> 8 & 0xff, value & 0xff);
  39687. }
  39688. function safeString16(value) {
  39689. // clamp value to the 16-bit int range
  39690. value = value > 0x7FFF ? 0x7FFF : value < -0x8000 ? -0x8000 : value;
  39691. return String.fromCharCode(value >> 8 & 0xff, value & 0xff);
  39692. }
  39693. function isTrueTypeFile(file) {
  39694. var header = file.peekBytes(4);
  39695. return readUint32(header, 0) === 0x00010000;
  39696. }
  39697. function isOpenTypeFile(file) {
  39698. var header = file.peekBytes(4);
  39699. return bytesToString(header) === 'OTTO';
  39700. }
  39701. function isType1File(file) {
  39702. var header = file.peekBytes(2);
  39703. // All Type1 font programs must begin with the comment '%!' (0x25 + 0x21).
  39704. if (header[0] === 0x25 && header[1] === 0x21) {
  39705. return true;
  39706. }
  39707. // ... obviously some fonts violate that part of the specification,
  39708. // please refer to the comment in |Type1Font| below.
  39709. if (header[0] === 0x80 && header[1] === 0x01) {
  39710. // pfb file header.
  39711. return true;
  39712. }
  39713. return false;
  39714. }
  39715. function buildToFontChar(encoding, glyphsUnicodeMap, differences) {
  39716. var toFontChar = [], unicode;
  39717. for (var i = 0, ii = encoding.length; i < ii; i++) {
  39718. unicode = getUnicodeForGlyph(encoding[i], glyphsUnicodeMap);
  39719. if (unicode !== -1) {
  39720. toFontChar[i] = unicode;
  39721. }
  39722. }
  39723. for (var charCode in differences) {
  39724. unicode = getUnicodeForGlyph(differences[charCode], glyphsUnicodeMap);
  39725. if (unicode !== -1) {
  39726. toFontChar[+charCode] = unicode;
  39727. }
  39728. }
  39729. return toFontChar;
  39730. }
  39731. /**
  39732. * Helper function for |adjustMapping|.
  39733. * @return {boolean}
  39734. */
  39735. function isProblematicUnicodeLocation(code) {
  39736. // Using binary search to find a range start.
  39737. var i = 0, j = ProblematicCharRanges.length - 1;
  39738. while (i < j) {
  39739. var c = i + j + 1 >> 1;
  39740. if (code < ProblematicCharRanges[c]) {
  39741. j = c - 1;
  39742. } else {
  39743. i = c;
  39744. }
  39745. }
  39746. // Even index means code in problematic range.
  39747. return !(i & 1);
  39748. }
  39749. /**
  39750. * Rebuilds the char code to glyph ID map by trying to replace the char codes
  39751. * with their unicode value. It also moves char codes that are in known
  39752. * problematic locations.
  39753. * @return {Object} Two properties:
  39754. * 'toFontChar' - maps original char codes(the value that will be read
  39755. * from commands such as show text) to the char codes that will be used in the
  39756. * font that we build
  39757. * 'charCodeToGlyphId' - maps the new font char codes to glyph ids
  39758. */
  39759. function adjustMapping(charCodeToGlyphId, properties) {
  39760. var toUnicode = properties.toUnicode;
  39761. var isSymbolic = !!(properties.flags & FontFlags.Symbolic);
  39762. var isIdentityUnicode = properties.toUnicode instanceof IdentityToUnicodeMap;
  39763. var newMap = Object.create(null);
  39764. var toFontChar = [];
  39765. var usedFontCharCodes = [];
  39766. var nextAvailableFontCharCode = PRIVATE_USE_OFFSET_START;
  39767. for (var originalCharCode in charCodeToGlyphId) {
  39768. originalCharCode |= 0;
  39769. var glyphId = charCodeToGlyphId[originalCharCode];
  39770. var fontCharCode = originalCharCode;
  39771. // First try to map the value to a unicode position if a non identity map
  39772. // was created.
  39773. if (!isIdentityUnicode && toUnicode.has(originalCharCode)) {
  39774. var unicode = toUnicode.get(fontCharCode);
  39775. // TODO: Try to map ligatures to the correct spot.
  39776. if (unicode.length === 1) {
  39777. fontCharCode = unicode.charCodeAt(0);
  39778. }
  39779. }
  39780. // Try to move control characters, special characters and already mapped
  39781. // characters to the private use area since they will not be drawn by
  39782. // canvas if left in their current position. Also, move characters if the
  39783. // font was symbolic and there is only an identity unicode map since the
  39784. // characters probably aren't in the correct position (fixes an issue
  39785. // with firefox and thuluthfont).
  39786. if ((usedFontCharCodes[fontCharCode] !== undefined || isProblematicUnicodeLocation(fontCharCode) || isSymbolic && isIdentityUnicode) && nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END) {
  39787. // Room left.
  39788. // Loop to try and find a free spot in the private use area.
  39789. do {
  39790. fontCharCode = nextAvailableFontCharCode++;
  39791. if (SKIP_PRIVATE_USE_RANGE_F000_TO_F01F && fontCharCode === 0xF000) {
  39792. fontCharCode = 0xF020;
  39793. nextAvailableFontCharCode = fontCharCode + 1;
  39794. }
  39795. } while (usedFontCharCodes[fontCharCode] !== undefined && nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END);
  39796. }
  39797. newMap[fontCharCode] = glyphId;
  39798. toFontChar[originalCharCode] = fontCharCode;
  39799. usedFontCharCodes[fontCharCode] = true;
  39800. }
  39801. return {
  39802. toFontChar: toFontChar,
  39803. charCodeToGlyphId: newMap,
  39804. nextAvailableFontCharCode: nextAvailableFontCharCode
  39805. };
  39806. }
  39807. function getRanges(glyphs, numGlyphs) {
  39808. // Array.sort() sorts by characters, not numerically, so convert to an
  39809. // array of characters.
  39810. var codes = [];
  39811. for (var charCode in glyphs) {
  39812. // Remove an invalid glyph ID mappings to make OTS happy.
  39813. if (glyphs[charCode] >= numGlyphs) {
  39814. continue;
  39815. }
  39816. codes.push({
  39817. fontCharCode: charCode | 0,
  39818. glyphId: glyphs[charCode]
  39819. });
  39820. }
  39821. codes.sort(function fontGetRangesSort(a, b) {
  39822. return a.fontCharCode - b.fontCharCode;
  39823. });
  39824. // Split the sorted codes into ranges.
  39825. var ranges = [];
  39826. var length = codes.length;
  39827. for (var n = 0; n < length;) {
  39828. var start = codes[n].fontCharCode;
  39829. var codeIndices = [codes[n].glyphId];
  39830. ++n;
  39831. var end = start;
  39832. while (n < length && end + 1 === codes[n].fontCharCode) {
  39833. codeIndices.push(codes[n].glyphId);
  39834. ++end;
  39835. ++n;
  39836. if (end === 0xFFFF) {
  39837. break;
  39838. }
  39839. }
  39840. ranges.push([
  39841. start,
  39842. end,
  39843. codeIndices
  39844. ]);
  39845. }
  39846. return ranges;
  39847. }
  39848. function createCmapTable(glyphs, numGlyphs) {
  39849. var ranges = getRanges(glyphs, numGlyphs);
  39850. var numTables = ranges[ranges.length - 1][1] > 0xFFFF ? 2 : 1;
  39851. var cmap = '\x00\x00' + // version
  39852. string16(numTables) + // numTables
  39853. '\x00\x03' + // platformID
  39854. '\x00\x01' + // encodingID
  39855. string32(4 + numTables * 8);
  39856. // start of the table record
  39857. var i, ii, j, jj;
  39858. for (i = ranges.length - 1; i >= 0; --i) {
  39859. if (ranges[i][0] <= 0xFFFF) {
  39860. break;
  39861. }
  39862. }
  39863. var bmpLength = i + 1;
  39864. if (ranges[i][0] < 0xFFFF && ranges[i][1] === 0xFFFF) {
  39865. ranges[i][1] = 0xFFFE;
  39866. }
  39867. var trailingRangesCount = ranges[i][1] < 0xFFFF ? 1 : 0;
  39868. var segCount = bmpLength + trailingRangesCount;
  39869. var searchParams = OpenTypeFileBuilder.getSearchParams(segCount, 2);
  39870. // Fill up the 4 parallel arrays describing the segments.
  39871. var startCount = '';
  39872. var endCount = '';
  39873. var idDeltas = '';
  39874. var idRangeOffsets = '';
  39875. var glyphsIds = '';
  39876. var bias = 0;
  39877. var range, start, end, codes;
  39878. for (i = 0, ii = bmpLength; i < ii; i++) {
  39879. range = ranges[i];
  39880. start = range[0];
  39881. end = range[1];
  39882. startCount += string16(start);
  39883. endCount += string16(end);
  39884. codes = range[2];
  39885. var contiguous = true;
  39886. for (j = 1, jj = codes.length; j < jj; ++j) {
  39887. if (codes[j] !== codes[j - 1] + 1) {
  39888. contiguous = false;
  39889. break;
  39890. }
  39891. }
  39892. if (!contiguous) {
  39893. var offset = (segCount - i) * 2 + bias * 2;
  39894. bias += end - start + 1;
  39895. idDeltas += string16(0);
  39896. idRangeOffsets += string16(offset);
  39897. for (j = 0, jj = codes.length; j < jj; ++j) {
  39898. glyphsIds += string16(codes[j]);
  39899. }
  39900. } else {
  39901. var startCode = codes[0];
  39902. idDeltas += string16(startCode - start & 0xFFFF);
  39903. idRangeOffsets += string16(0);
  39904. }
  39905. }
  39906. if (trailingRangesCount > 0) {
  39907. endCount += '\xFF\xFF';
  39908. startCount += '\xFF\xFF';
  39909. idDeltas += '\x00\x01';
  39910. idRangeOffsets += '\x00\x00';
  39911. }
  39912. var format314 = '\x00\x00' + // language
  39913. string16(2 * segCount) + string16(searchParams.range) + string16(searchParams.entry) + string16(searchParams.rangeShift) + endCount + '\x00\x00' + startCount + idDeltas + idRangeOffsets + glyphsIds;
  39914. var format31012 = '';
  39915. var header31012 = '';
  39916. if (numTables > 1) {
  39917. cmap += '\x00\x03' + // platformID
  39918. '\x00\x0A' + // encodingID
  39919. string32(4 + numTables * 8 + 4 + format314.length);
  39920. // start of the table record
  39921. format31012 = '';
  39922. for (i = 0, ii = ranges.length; i < ii; i++) {
  39923. range = ranges[i];
  39924. start = range[0];
  39925. codes = range[2];
  39926. var code = codes[0];
  39927. for (j = 1, jj = codes.length; j < jj; ++j) {
  39928. if (codes[j] !== codes[j - 1] + 1) {
  39929. end = range[0] + j - 1;
  39930. format31012 += string32(start) + // startCharCode
  39931. string32(end) + // endCharCode
  39932. string32(code);
  39933. // startGlyphID
  39934. start = end + 1;
  39935. code = codes[j];
  39936. }
  39937. }
  39938. format31012 += string32(start) + // startCharCode
  39939. string32(range[1]) + // endCharCode
  39940. string32(code);
  39941. }
  39942. // startGlyphID
  39943. header31012 = '\x00\x0C' + // format
  39944. '\x00\x00' + // reserved
  39945. string32(format31012.length + 16) + // length
  39946. '\x00\x00\x00\x00' + // language
  39947. string32(format31012.length / 12);
  39948. }
  39949. // nGroups
  39950. return cmap + '\x00\x04' + // format
  39951. string16(format314.length + 4) + // length
  39952. format314 + header31012 + format31012;
  39953. }
  39954. function validateOS2Table(os2) {
  39955. var stream = new Stream(os2.data);
  39956. var version = stream.getUint16();
  39957. // TODO verify all OS/2 tables fields, but currently we validate only those
  39958. // that give us issues
  39959. stream.getBytes(60);
  39960. // skipping type, misc sizes, panose, unicode ranges
  39961. var selection = stream.getUint16();
  39962. if (version < 4 && selection & 0x0300) {
  39963. return false;
  39964. }
  39965. var firstChar = stream.getUint16();
  39966. var lastChar = stream.getUint16();
  39967. if (firstChar > lastChar) {
  39968. return false;
  39969. }
  39970. stream.getBytes(6);
  39971. // skipping sTypoAscender/Descender/LineGap
  39972. var usWinAscent = stream.getUint16();
  39973. if (usWinAscent === 0) {
  39974. // makes font unreadable by windows
  39975. return false;
  39976. }
  39977. // OS/2 appears to be valid, resetting some fields
  39978. os2.data[8] = os2.data[9] = 0;
  39979. // IE rejects fonts if fsType != 0
  39980. return true;
  39981. }
  39982. function createOS2Table(properties, charstrings, override) {
  39983. override = override || {
  39984. unitsPerEm: 0,
  39985. yMax: 0,
  39986. yMin: 0,
  39987. ascent: 0,
  39988. descent: 0
  39989. };
  39990. var ulUnicodeRange1 = 0;
  39991. var ulUnicodeRange2 = 0;
  39992. var ulUnicodeRange3 = 0;
  39993. var ulUnicodeRange4 = 0;
  39994. var firstCharIndex = null;
  39995. var lastCharIndex = 0;
  39996. if (charstrings) {
  39997. for (var code in charstrings) {
  39998. code |= 0;
  39999. if (firstCharIndex > code || !firstCharIndex) {
  40000. firstCharIndex = code;
  40001. }
  40002. if (lastCharIndex < code) {
  40003. lastCharIndex = code;
  40004. }
  40005. var position = getUnicodeRangeFor(code);
  40006. if (position < 32) {
  40007. ulUnicodeRange1 |= 1 << position;
  40008. } else if (position < 64) {
  40009. ulUnicodeRange2 |= 1 << position - 32;
  40010. } else if (position < 96) {
  40011. ulUnicodeRange3 |= 1 << position - 64;
  40012. } else if (position < 123) {
  40013. ulUnicodeRange4 |= 1 << position - 96;
  40014. } else {
  40015. error('Unicode ranges Bits > 123 are reserved for internal usage');
  40016. }
  40017. }
  40018. } else {
  40019. // TODO
  40020. firstCharIndex = 0;
  40021. lastCharIndex = 255;
  40022. }
  40023. var bbox = properties.bbox || [
  40024. 0,
  40025. 0,
  40026. 0,
  40027. 0
  40028. ];
  40029. var unitsPerEm = override.unitsPerEm || 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0];
  40030. // if the font units differ to the PDF glyph space units
  40031. // then scale up the values
  40032. var scale = properties.ascentScaled ? 1.0 : unitsPerEm / PDF_GLYPH_SPACE_UNITS;
  40033. var typoAscent = override.ascent || Math.round(scale * (properties.ascent || bbox[3]));
  40034. var typoDescent = override.descent || Math.round(scale * (properties.descent || bbox[1]));
  40035. if (typoDescent > 0 && properties.descent > 0 && bbox[1] < 0) {
  40036. typoDescent = -typoDescent;
  40037. }
  40038. // fixing incorrect descent
  40039. var winAscent = override.yMax || typoAscent;
  40040. var winDescent = -override.yMin || -typoDescent;
  40041. return '\x00\x03' + // version
  40042. '\x02\x24' + // xAvgCharWidth
  40043. '\x01\xF4' + // usWeightClass
  40044. '\x00\x05' + // usWidthClass
  40045. '\x00\x00' + // fstype (0 to let the font loads via font-face on IE)
  40046. '\x02\x8A' + // ySubscriptXSize
  40047. '\x02\xBB' + // ySubscriptYSize
  40048. '\x00\x00' + // ySubscriptXOffset
  40049. '\x00\x8C' + // ySubscriptYOffset
  40050. '\x02\x8A' + // ySuperScriptXSize
  40051. '\x02\xBB' + // ySuperScriptYSize
  40052. '\x00\x00' + // ySuperScriptXOffset
  40053. '\x01\xDF' + // ySuperScriptYOffset
  40054. '\x00\x31' + // yStrikeOutSize
  40055. '\x01\x02' + // yStrikeOutPosition
  40056. '\x00\x00' + // sFamilyClass
  40057. '\x00\x00\x06' + String.fromCharCode(properties.fixedPitch ? 0x09 : 0x00) + '\x00\x00\x00\x00\x00\x00' + // Panose
  40058. string32(ulUnicodeRange1) + // ulUnicodeRange1 (Bits 0-31)
  40059. string32(ulUnicodeRange2) + // ulUnicodeRange2 (Bits 32-63)
  40060. string32(ulUnicodeRange3) + // ulUnicodeRange3 (Bits 64-95)
  40061. string32(ulUnicodeRange4) + // ulUnicodeRange4 (Bits 96-127)
  40062. '\x2A\x32\x31\x2A' + // achVendID
  40063. string16(properties.italicAngle ? 1 : 0) + // fsSelection
  40064. string16(firstCharIndex || properties.firstChar) + // usFirstCharIndex
  40065. string16(lastCharIndex || properties.lastChar) + // usLastCharIndex
  40066. string16(typoAscent) + // sTypoAscender
  40067. string16(typoDescent) + // sTypoDescender
  40068. '\x00\x64' + // sTypoLineGap (7%-10% of the unitsPerEM value)
  40069. string16(winAscent) + // usWinAscent
  40070. string16(winDescent) + // usWinDescent
  40071. '\x00\x00\x00\x00' + // ulCodePageRange1 (Bits 0-31)
  40072. '\x00\x00\x00\x00' + // ulCodePageRange2 (Bits 32-63)
  40073. string16(properties.xHeight) + // sxHeight
  40074. string16(properties.capHeight) + // sCapHeight
  40075. string16(0) + // usDefaultChar
  40076. string16(firstCharIndex || properties.firstChar) + // usBreakChar
  40077. '\x00\x03';
  40078. }
  40079. // usMaxContext
  40080. function createPostTable(properties) {
  40081. var angle = Math.floor(properties.italicAngle * Math.pow(2, 16));
  40082. return '\x00\x03\x00\x00' + // Version number
  40083. string32(angle) + // italicAngle
  40084. '\x00\x00' + // underlinePosition
  40085. '\x00\x00' + // underlineThickness
  40086. string32(properties.fixedPitch) + // isFixedPitch
  40087. '\x00\x00\x00\x00' + // minMemType42
  40088. '\x00\x00\x00\x00' + // maxMemType42
  40089. '\x00\x00\x00\x00' + // minMemType1
  40090. '\x00\x00\x00\x00';
  40091. }
  40092. // maxMemType1
  40093. function createNameTable(name, proto) {
  40094. if (!proto) {
  40095. proto = [
  40096. [],
  40097. []
  40098. ];
  40099. }
  40100. // no strings and unicode strings
  40101. var strings = [
  40102. proto[0][0] || 'Original licence',
  40103. // 0.Copyright
  40104. proto[0][1] || name,
  40105. // 1.Font family
  40106. proto[0][2] || 'Unknown',
  40107. // 2.Font subfamily (font weight)
  40108. proto[0][3] || 'uniqueID',
  40109. // 3.Unique ID
  40110. proto[0][4] || name,
  40111. // 4.Full font name
  40112. proto[0][5] || 'Version 0.11',
  40113. // 5.Version
  40114. proto[0][6] || '',
  40115. // 6.Postscript name
  40116. proto[0][7] || 'Unknown',
  40117. // 7.Trademark
  40118. proto[0][8] || 'Unknown',
  40119. // 8.Manufacturer
  40120. proto[0][9] || 'Unknown'
  40121. ];
  40122. // 9.Designer
  40123. // Mac want 1-byte per character strings while Windows want
  40124. // 2-bytes per character, so duplicate the names table
  40125. var stringsUnicode = [];
  40126. var i, ii, j, jj, str;
  40127. for (i = 0, ii = strings.length; i < ii; i++) {
  40128. str = proto[1][i] || strings[i];
  40129. var strBufUnicode = [];
  40130. for (j = 0, jj = str.length; j < jj; j++) {
  40131. strBufUnicode.push(string16(str.charCodeAt(j)));
  40132. }
  40133. stringsUnicode.push(strBufUnicode.join(''));
  40134. }
  40135. var names = [
  40136. strings,
  40137. stringsUnicode
  40138. ];
  40139. var platforms = [
  40140. '\x00\x01',
  40141. '\x00\x03'
  40142. ];
  40143. var encodings = [
  40144. '\x00\x00',
  40145. '\x00\x01'
  40146. ];
  40147. var languages = [
  40148. '\x00\x00',
  40149. '\x04\x09'
  40150. ];
  40151. var namesRecordCount = strings.length * platforms.length;
  40152. var nameTable = '\x00\x00' + // format
  40153. string16(namesRecordCount) + // Number of names Record
  40154. string16(namesRecordCount * 12 + 6);
  40155. // Storage
  40156. // Build the name records field
  40157. var strOffset = 0;
  40158. for (i = 0, ii = platforms.length; i < ii; i++) {
  40159. var strs = names[i];
  40160. for (j = 0, jj = strs.length; j < jj; j++) {
  40161. str = strs[j];
  40162. var nameRecord = platforms[i] + // platform ID
  40163. encodings[i] + // encoding ID
  40164. languages[i] + // language ID
  40165. string16(j) + // name ID
  40166. string16(str.length) + string16(strOffset);
  40167. nameTable += nameRecord;
  40168. strOffset += str.length;
  40169. }
  40170. }
  40171. nameTable += strings.join('') + stringsUnicode.join('');
  40172. return nameTable;
  40173. }
  40174. Font.prototype = {
  40175. name: null,
  40176. font: null,
  40177. mimetype: null,
  40178. encoding: null,
  40179. get renderer() {
  40180. var renderer = FontRendererFactory.create(this, SEAC_ANALYSIS_ENABLED);
  40181. return shadow(this, 'renderer', renderer);
  40182. },
  40183. exportData: function Font_exportData() {
  40184. // TODO remove enumerating of the properties, e.g. hardcode exact names.
  40185. var data = {};
  40186. for (var i in this) {
  40187. if (this.hasOwnProperty(i)) {
  40188. data[i] = this[i];
  40189. }
  40190. }
  40191. return data;
  40192. },
  40193. checkAndRepair: function Font_checkAndRepair(name, font, properties) {
  40194. function readTableEntry(file) {
  40195. var tag = bytesToString(file.getBytes(4));
  40196. var checksum = file.getInt32() >>> 0;
  40197. var offset = file.getInt32() >>> 0;
  40198. var length = file.getInt32() >>> 0;
  40199. // Read the table associated data
  40200. var previousPosition = file.pos;
  40201. file.pos = file.start ? file.start : 0;
  40202. file.skip(offset);
  40203. var data = file.getBytes(length);
  40204. file.pos = previousPosition;
  40205. if (tag === 'head') {
  40206. // clearing checksum adjustment
  40207. data[8] = data[9] = data[10] = data[11] = 0;
  40208. data[17] |= 0x20;
  40209. }
  40210. //Set font optimized for cleartype flag
  40211. return {
  40212. tag: tag,
  40213. checksum: checksum,
  40214. length: length,
  40215. offset: offset,
  40216. data: data
  40217. };
  40218. }
  40219. function readOpenTypeHeader(ttf) {
  40220. return {
  40221. version: bytesToString(ttf.getBytes(4)),
  40222. numTables: ttf.getUint16(),
  40223. searchRange: ttf.getUint16(),
  40224. entrySelector: ttf.getUint16(),
  40225. rangeShift: ttf.getUint16()
  40226. };
  40227. }
  40228. /**
  40229. * Read the appropriate subtable from the cmap according to 9.6.6.4 from
  40230. * PDF spec
  40231. */
  40232. function readCmapTable(cmap, font, isSymbolicFont, hasEncoding) {
  40233. if (!cmap) {
  40234. warn('No cmap table available.');
  40235. return {
  40236. platformId: -1,
  40237. encodingId: -1,
  40238. mappings: [],
  40239. hasShortCmap: false
  40240. };
  40241. }
  40242. var segment;
  40243. var start = (font.start ? font.start : 0) + cmap.offset;
  40244. font.pos = start;
  40245. var version = font.getUint16();
  40246. var numTables = font.getUint16();
  40247. var potentialTable;
  40248. var canBreak = false;
  40249. // There's an order of preference in terms of which cmap subtable to
  40250. // use:
  40251. // - non-symbolic fonts the preference is a 3,1 table then a 1,0 table
  40252. // - symbolic fonts the preference is a 3,0 table then a 1,0 table
  40253. // The following takes advantage of the fact that the tables are sorted
  40254. // to work.
  40255. for (var i = 0; i < numTables; i++) {
  40256. var platformId = font.getUint16();
  40257. var encodingId = font.getUint16();
  40258. var offset = font.getInt32() >>> 0;
  40259. var useTable = false;
  40260. if (platformId === 0 && encodingId === 0) {
  40261. useTable = true;
  40262. } else // Continue the loop since there still may be a higher priority
  40263. // table.
  40264. if (platformId === 1 && encodingId === 0) {
  40265. useTable = true;
  40266. } else // Continue the loop since there still may be a higher priority
  40267. // table.
  40268. if (platformId === 3 && encodingId === 1 && (!isSymbolicFont && hasEncoding || !potentialTable)) {
  40269. useTable = true;
  40270. if (!isSymbolicFont) {
  40271. canBreak = true;
  40272. }
  40273. } else if (isSymbolicFont && platformId === 3 && encodingId === 0) {
  40274. useTable = true;
  40275. canBreak = true;
  40276. }
  40277. if (useTable) {
  40278. potentialTable = {
  40279. platformId: platformId,
  40280. encodingId: encodingId,
  40281. offset: offset
  40282. };
  40283. }
  40284. if (canBreak) {
  40285. break;
  40286. }
  40287. }
  40288. if (potentialTable) {
  40289. font.pos = start + potentialTable.offset;
  40290. }
  40291. if (!potentialTable || font.peekByte() === -1) {
  40292. warn('Could not find a preferred cmap table.');
  40293. return {
  40294. platformId: -1,
  40295. encodingId: -1,
  40296. mappings: [],
  40297. hasShortCmap: false
  40298. };
  40299. }
  40300. var format = font.getUint16();
  40301. var length = font.getUint16();
  40302. var language = font.getUint16();
  40303. var hasShortCmap = false;
  40304. var mappings = [];
  40305. var j, glyphId;
  40306. // TODO(mack): refactor this cmap subtable reading logic out
  40307. if (format === 0) {
  40308. for (j = 0; j < 256; j++) {
  40309. var index = font.getByte();
  40310. if (!index) {
  40311. continue;
  40312. }
  40313. mappings.push({
  40314. charCode: j,
  40315. glyphId: index
  40316. });
  40317. }
  40318. hasShortCmap = true;
  40319. } else if (format === 4) {
  40320. // re-creating the table in format 4 since the encoding
  40321. // might be changed
  40322. var segCount = font.getUint16() >> 1;
  40323. font.getBytes(6);
  40324. // skipping range fields
  40325. var segIndex, segments = [];
  40326. for (segIndex = 0; segIndex < segCount; segIndex++) {
  40327. segments.push({ end: font.getUint16() });
  40328. }
  40329. font.getUint16();
  40330. for (segIndex = 0; segIndex < segCount; segIndex++) {
  40331. segments[segIndex].start = font.getUint16();
  40332. }
  40333. for (segIndex = 0; segIndex < segCount; segIndex++) {
  40334. segments[segIndex].delta = font.getUint16();
  40335. }
  40336. var offsetsCount = 0;
  40337. for (segIndex = 0; segIndex < segCount; segIndex++) {
  40338. segment = segments[segIndex];
  40339. var rangeOffset = font.getUint16();
  40340. if (!rangeOffset) {
  40341. segment.offsetIndex = -1;
  40342. continue;
  40343. }
  40344. var offsetIndex = (rangeOffset >> 1) - (segCount - segIndex);
  40345. segment.offsetIndex = offsetIndex;
  40346. offsetsCount = Math.max(offsetsCount, offsetIndex + segment.end - segment.start + 1);
  40347. }
  40348. var offsets = [];
  40349. for (j = 0; j < offsetsCount; j++) {
  40350. offsets.push(font.getUint16());
  40351. }
  40352. for (segIndex = 0; segIndex < segCount; segIndex++) {
  40353. segment = segments[segIndex];
  40354. start = segment.start;
  40355. var end = segment.end;
  40356. var delta = segment.delta;
  40357. offsetIndex = segment.offsetIndex;
  40358. for (j = start; j <= end; j++) {
  40359. if (j === 0xFFFF) {
  40360. continue;
  40361. }
  40362. glyphId = offsetIndex < 0 ? j : offsets[offsetIndex + j - start];
  40363. glyphId = glyphId + delta & 0xFFFF;
  40364. if (glyphId === 0) {
  40365. continue;
  40366. }
  40367. mappings.push({
  40368. charCode: j,
  40369. glyphId: glyphId
  40370. });
  40371. }
  40372. }
  40373. } else if (format === 6) {
  40374. // Format 6 is a 2-bytes dense mapping, which means the font data
  40375. // lives glue together even if they are pretty far in the unicode
  40376. // table. (This looks weird, so I can have missed something), this
  40377. // works on Linux but seems to fails on Mac so let's rewrite the
  40378. // cmap table to a 3-1-4 style
  40379. var firstCode = font.getUint16();
  40380. var entryCount = font.getUint16();
  40381. for (j = 0; j < entryCount; j++) {
  40382. glyphId = font.getUint16();
  40383. var charCode = firstCode + j;
  40384. mappings.push({
  40385. charCode: charCode,
  40386. glyphId: glyphId
  40387. });
  40388. }
  40389. } else {
  40390. warn('cmap table has unsupported format: ' + format);
  40391. return {
  40392. platformId: -1,
  40393. encodingId: -1,
  40394. mappings: [],
  40395. hasShortCmap: false
  40396. };
  40397. }
  40398. // removing duplicate entries
  40399. mappings.sort(function (a, b) {
  40400. return a.charCode - b.charCode;
  40401. });
  40402. for (i = 1; i < mappings.length; i++) {
  40403. if (mappings[i - 1].charCode === mappings[i].charCode) {
  40404. mappings.splice(i, 1);
  40405. i--;
  40406. }
  40407. }
  40408. return {
  40409. platformId: potentialTable.platformId,
  40410. encodingId: potentialTable.encodingId,
  40411. mappings: mappings,
  40412. hasShortCmap: hasShortCmap
  40413. };
  40414. }
  40415. function sanitizeMetrics(font, header, metrics, numGlyphs) {
  40416. if (!header) {
  40417. if (metrics) {
  40418. metrics.data = null;
  40419. }
  40420. return;
  40421. }
  40422. font.pos = (font.start ? font.start : 0) + header.offset;
  40423. font.pos += header.length - 2;
  40424. var numOfMetrics = font.getUint16();
  40425. if (numOfMetrics > numGlyphs) {
  40426. info('The numOfMetrics (' + numOfMetrics + ') should not be ' + 'greater than the numGlyphs (' + numGlyphs + ')');
  40427. // Reduce numOfMetrics if it is greater than numGlyphs
  40428. numOfMetrics = numGlyphs;
  40429. header.data[34] = (numOfMetrics & 0xff00) >> 8;
  40430. header.data[35] = numOfMetrics & 0x00ff;
  40431. }
  40432. var numOfSidebearings = numGlyphs - numOfMetrics;
  40433. var numMissing = numOfSidebearings - (metrics.length - numOfMetrics * 4 >> 1);
  40434. if (numMissing > 0) {
  40435. // For each missing glyph, we set both the width and lsb to 0 (zero).
  40436. // Since we need to add two properties for each glyph, this explains
  40437. // the use of |numMissing * 2| when initializing the typed array.
  40438. var entries = new Uint8Array(metrics.length + numMissing * 2);
  40439. entries.set(metrics.data);
  40440. metrics.data = entries;
  40441. }
  40442. }
  40443. function sanitizeGlyph(source, sourceStart, sourceEnd, dest, destStart, hintsValid) {
  40444. if (sourceEnd - sourceStart <= 12) {
  40445. // glyph with data less than 12 is invalid one
  40446. return 0;
  40447. }
  40448. var glyf = source.subarray(sourceStart, sourceEnd);
  40449. var contoursCount = glyf[0] << 8 | glyf[1];
  40450. if (contoursCount & 0x8000) {
  40451. // complex glyph, writing as is
  40452. dest.set(glyf, destStart);
  40453. return glyf.length;
  40454. }
  40455. var i, j = 10, flagsCount = 0;
  40456. for (i = 0; i < contoursCount; i++) {
  40457. var endPoint = glyf[j] << 8 | glyf[j + 1];
  40458. flagsCount = endPoint + 1;
  40459. j += 2;
  40460. }
  40461. // skipping instructions
  40462. var instructionsStart = j;
  40463. var instructionsLength = glyf[j] << 8 | glyf[j + 1];
  40464. j += 2 + instructionsLength;
  40465. var instructionsEnd = j;
  40466. // validating flags
  40467. var coordinatesLength = 0;
  40468. for (i = 0; i < flagsCount; i++) {
  40469. var flag = glyf[j++];
  40470. if (flag & 0xC0) {
  40471. // reserved flags must be zero, cleaning up
  40472. glyf[j - 1] = flag & 0x3F;
  40473. }
  40474. var xyLength = (flag & 2 ? 1 : flag & 16 ? 0 : 2) + (flag & 4 ? 1 : flag & 32 ? 0 : 2);
  40475. coordinatesLength += xyLength;
  40476. if (flag & 8) {
  40477. var repeat = glyf[j++];
  40478. i += repeat;
  40479. coordinatesLength += repeat * xyLength;
  40480. }
  40481. }
  40482. // glyph without coordinates will be rejected
  40483. if (coordinatesLength === 0) {
  40484. return 0;
  40485. }
  40486. var glyphDataLength = j + coordinatesLength;
  40487. if (glyphDataLength > glyf.length) {
  40488. // not enough data for coordinates
  40489. return 0;
  40490. }
  40491. if (!hintsValid && instructionsLength > 0) {
  40492. dest.set(glyf.subarray(0, instructionsStart), destStart);
  40493. dest.set([
  40494. 0,
  40495. 0
  40496. ], destStart + instructionsStart);
  40497. dest.set(glyf.subarray(instructionsEnd, glyphDataLength), destStart + instructionsStart + 2);
  40498. glyphDataLength -= instructionsLength;
  40499. if (glyf.length - glyphDataLength > 3) {
  40500. glyphDataLength = glyphDataLength + 3 & ~3;
  40501. }
  40502. return glyphDataLength;
  40503. }
  40504. if (glyf.length - glyphDataLength > 3) {
  40505. // truncating and aligning to 4 bytes the long glyph data
  40506. glyphDataLength = glyphDataLength + 3 & ~3;
  40507. dest.set(glyf.subarray(0, glyphDataLength), destStart);
  40508. return glyphDataLength;
  40509. }
  40510. // glyph data is fine
  40511. dest.set(glyf, destStart);
  40512. return glyf.length;
  40513. }
  40514. function sanitizeHead(head, numGlyphs, locaLength) {
  40515. var data = head.data;
  40516. // Validate version:
  40517. // Should always be 0x00010000
  40518. var version = int32(data[0], data[1], data[2], data[3]);
  40519. if (version >> 16 !== 1) {
  40520. info('Attempting to fix invalid version in head table: ' + version);
  40521. data[0] = 0;
  40522. data[1] = 1;
  40523. data[2] = 0;
  40524. data[3] = 0;
  40525. }
  40526. var indexToLocFormat = int16(data[50], data[51]);
  40527. if (indexToLocFormat < 0 || indexToLocFormat > 1) {
  40528. info('Attempting to fix invalid indexToLocFormat in head table: ' + indexToLocFormat);
  40529. // The value of indexToLocFormat should be 0 if the loca table
  40530. // consists of short offsets, and should be 1 if the loca table
  40531. // consists of long offsets.
  40532. //
  40533. // The number of entries in the loca table should be numGlyphs + 1.
  40534. //
  40535. // Using this information, we can work backwards to deduce if the
  40536. // size of each offset in the loca table, and thus figure out the
  40537. // appropriate value for indexToLocFormat.
  40538. var numGlyphsPlusOne = numGlyphs + 1;
  40539. if (locaLength === numGlyphsPlusOne << 1) {
  40540. // 0x0000 indicates the loca table consists of short offsets
  40541. data[50] = 0;
  40542. data[51] = 0;
  40543. } else if (locaLength === numGlyphsPlusOne << 2) {
  40544. // 0x0001 indicates the loca table consists of long offsets
  40545. data[50] = 0;
  40546. data[51] = 1;
  40547. } else {
  40548. warn('Could not fix indexToLocFormat: ' + indexToLocFormat);
  40549. }
  40550. }
  40551. }
  40552. function sanitizeGlyphLocations(loca, glyf, numGlyphs, isGlyphLocationsLong, hintsValid, dupFirstEntry) {
  40553. var itemSize, itemDecode, itemEncode;
  40554. if (isGlyphLocationsLong) {
  40555. itemSize = 4;
  40556. itemDecode = function fontItemDecodeLong(data, offset) {
  40557. return data[offset] << 24 | data[offset + 1] << 16 | data[offset + 2] << 8 | data[offset + 3];
  40558. };
  40559. itemEncode = function fontItemEncodeLong(data, offset, value) {
  40560. data[offset] = value >>> 24 & 0xFF;
  40561. data[offset + 1] = value >> 16 & 0xFF;
  40562. data[offset + 2] = value >> 8 & 0xFF;
  40563. data[offset + 3] = value & 0xFF;
  40564. };
  40565. } else {
  40566. itemSize = 2;
  40567. itemDecode = function fontItemDecode(data, offset) {
  40568. return data[offset] << 9 | data[offset + 1] << 1;
  40569. };
  40570. itemEncode = function fontItemEncode(data, offset, value) {
  40571. data[offset] = value >> 9 & 0xFF;
  40572. data[offset + 1] = value >> 1 & 0xFF;
  40573. };
  40574. }
  40575. var locaData = loca.data;
  40576. var locaDataSize = itemSize * (1 + numGlyphs);
  40577. // is loca.data too short or long?
  40578. if (locaData.length !== locaDataSize) {
  40579. locaData = new Uint8Array(locaDataSize);
  40580. locaData.set(loca.data.subarray(0, locaDataSize));
  40581. loca.data = locaData;
  40582. }
  40583. // removing the invalid glyphs
  40584. var oldGlyfData = glyf.data;
  40585. var oldGlyfDataLength = oldGlyfData.length;
  40586. var newGlyfData = new Uint8Array(oldGlyfDataLength);
  40587. var startOffset = itemDecode(locaData, 0);
  40588. var writeOffset = 0;
  40589. var missingGlyphData = Object.create(null);
  40590. itemEncode(locaData, 0, writeOffset);
  40591. var i, j;
  40592. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  40593. var endOffset = itemDecode(locaData, j);
  40594. if (endOffset > oldGlyfDataLength && (oldGlyfDataLength + 3 & ~3) === endOffset) {
  40595. // Aspose breaks fonts by aligning the glyphs to the qword, but not
  40596. // the glyf table size, which makes last glyph out of range.
  40597. endOffset = oldGlyfDataLength;
  40598. }
  40599. if (endOffset > oldGlyfDataLength) {
  40600. // glyph end offset points outside glyf data, rejecting the glyph
  40601. itemEncode(locaData, j, writeOffset);
  40602. startOffset = endOffset;
  40603. continue;
  40604. }
  40605. if (startOffset === endOffset) {
  40606. missingGlyphData[i] = true;
  40607. }
  40608. var newLength = sanitizeGlyph(oldGlyfData, startOffset, endOffset, newGlyfData, writeOffset, hintsValid);
  40609. writeOffset += newLength;
  40610. itemEncode(locaData, j, writeOffset);
  40611. startOffset = endOffset;
  40612. }
  40613. if (writeOffset === 0) {
  40614. // glyf table cannot be empty -- redoing the glyf and loca tables
  40615. // to have single glyph with one point
  40616. var simpleGlyph = new Uint8Array([
  40617. 0,
  40618. 1,
  40619. 0,
  40620. 0,
  40621. 0,
  40622. 0,
  40623. 0,
  40624. 0,
  40625. 0,
  40626. 0,
  40627. 0,
  40628. 0,
  40629. 0,
  40630. 0,
  40631. 49,
  40632. 0
  40633. ]);
  40634. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  40635. itemEncode(locaData, j, simpleGlyph.length);
  40636. }
  40637. glyf.data = simpleGlyph;
  40638. return missingGlyphData;
  40639. }
  40640. if (dupFirstEntry) {
  40641. var firstEntryLength = itemDecode(locaData, itemSize);
  40642. if (newGlyfData.length > firstEntryLength + writeOffset) {
  40643. glyf.data = newGlyfData.subarray(0, firstEntryLength + writeOffset);
  40644. } else {
  40645. glyf.data = new Uint8Array(firstEntryLength + writeOffset);
  40646. glyf.data.set(newGlyfData.subarray(0, writeOffset));
  40647. }
  40648. glyf.data.set(newGlyfData.subarray(0, firstEntryLength), writeOffset);
  40649. itemEncode(loca.data, locaData.length - itemSize, writeOffset + firstEntryLength);
  40650. } else {
  40651. glyf.data = newGlyfData.subarray(0, writeOffset);
  40652. }
  40653. return missingGlyphData;
  40654. }
  40655. function readPostScriptTable(post, properties, maxpNumGlyphs) {
  40656. var start = (font.start ? font.start : 0) + post.offset;
  40657. font.pos = start;
  40658. var length = post.length, end = start + length;
  40659. var version = font.getInt32();
  40660. // skip rest to the tables
  40661. font.getBytes(28);
  40662. var glyphNames;
  40663. var valid = true;
  40664. var i;
  40665. switch (version) {
  40666. case 0x00010000:
  40667. glyphNames = MacStandardGlyphOrdering;
  40668. break;
  40669. case 0x00020000:
  40670. var numGlyphs = font.getUint16();
  40671. if (numGlyphs !== maxpNumGlyphs) {
  40672. valid = false;
  40673. break;
  40674. }
  40675. var glyphNameIndexes = [];
  40676. for (i = 0; i < numGlyphs; ++i) {
  40677. var index = font.getUint16();
  40678. if (index >= 32768) {
  40679. valid = false;
  40680. break;
  40681. }
  40682. glyphNameIndexes.push(index);
  40683. }
  40684. if (!valid) {
  40685. break;
  40686. }
  40687. var customNames = [];
  40688. var strBuf = [];
  40689. while (font.pos < end) {
  40690. var stringLength = font.getByte();
  40691. strBuf.length = stringLength;
  40692. for (i = 0; i < stringLength; ++i) {
  40693. strBuf[i] = String.fromCharCode(font.getByte());
  40694. }
  40695. customNames.push(strBuf.join(''));
  40696. }
  40697. glyphNames = [];
  40698. for (i = 0; i < numGlyphs; ++i) {
  40699. var j = glyphNameIndexes[i];
  40700. if (j < 258) {
  40701. glyphNames.push(MacStandardGlyphOrdering[j]);
  40702. continue;
  40703. }
  40704. glyphNames.push(customNames[j - 258]);
  40705. }
  40706. break;
  40707. case 0x00030000:
  40708. break;
  40709. default:
  40710. warn('Unknown/unsupported post table version ' + version);
  40711. valid = false;
  40712. if (properties.defaultEncoding) {
  40713. glyphNames = properties.defaultEncoding;
  40714. }
  40715. break;
  40716. }
  40717. properties.glyphNames = glyphNames;
  40718. return valid;
  40719. }
  40720. function readNameTable(nameTable) {
  40721. var start = (font.start ? font.start : 0) + nameTable.offset;
  40722. font.pos = start;
  40723. var names = [
  40724. [],
  40725. []
  40726. ];
  40727. var length = nameTable.length, end = start + length;
  40728. var format = font.getUint16();
  40729. var FORMAT_0_HEADER_LENGTH = 6;
  40730. if (format !== 0 || length < FORMAT_0_HEADER_LENGTH) {
  40731. // unsupported name table format or table "too" small
  40732. return names;
  40733. }
  40734. var numRecords = font.getUint16();
  40735. var stringsStart = font.getUint16();
  40736. var records = [];
  40737. var NAME_RECORD_LENGTH = 12;
  40738. var i, ii;
  40739. for (i = 0; i < numRecords && font.pos + NAME_RECORD_LENGTH <= end; i++) {
  40740. var r = {
  40741. platform: font.getUint16(),
  40742. encoding: font.getUint16(),
  40743. language: font.getUint16(),
  40744. name: font.getUint16(),
  40745. length: font.getUint16(),
  40746. offset: font.getUint16()
  40747. };
  40748. // using only Macintosh and Windows platform/encoding names
  40749. if (r.platform === 1 && r.encoding === 0 && r.language === 0 || r.platform === 3 && r.encoding === 1 && r.language === 0x409) {
  40750. records.push(r);
  40751. }
  40752. }
  40753. for (i = 0, ii = records.length; i < ii; i++) {
  40754. var record = records[i];
  40755. if (record.length <= 0) {
  40756. continue;
  40757. }
  40758. // Nothing to process, ignoring.
  40759. var pos = start + stringsStart + record.offset;
  40760. if (pos + record.length > end) {
  40761. continue;
  40762. }
  40763. // outside of name table, ignoring
  40764. font.pos = pos;
  40765. var nameIndex = record.name;
  40766. if (record.encoding) {
  40767. // unicode
  40768. var str = '';
  40769. for (var j = 0, jj = record.length; j < jj; j += 2) {
  40770. str += String.fromCharCode(font.getUint16());
  40771. }
  40772. names[1][nameIndex] = str;
  40773. } else {
  40774. names[0][nameIndex] = bytesToString(font.getBytes(record.length));
  40775. }
  40776. }
  40777. return names;
  40778. }
  40779. var TTOpsStackDeltas = [
  40780. 0,
  40781. 0,
  40782. 0,
  40783. 0,
  40784. 0,
  40785. 0,
  40786. 0,
  40787. 0,
  40788. -2,
  40789. -2,
  40790. -2,
  40791. -2,
  40792. 0,
  40793. 0,
  40794. -2,
  40795. -5,
  40796. -1,
  40797. -1,
  40798. -1,
  40799. -1,
  40800. -1,
  40801. -1,
  40802. -1,
  40803. -1,
  40804. 0,
  40805. 0,
  40806. -1,
  40807. 0,
  40808. -1,
  40809. -1,
  40810. -1,
  40811. -1,
  40812. 1,
  40813. -1,
  40814. -999,
  40815. 0,
  40816. 1,
  40817. 0,
  40818. -1,
  40819. -2,
  40820. 0,
  40821. -1,
  40822. -2,
  40823. -1,
  40824. -1,
  40825. 0,
  40826. -1,
  40827. -1,
  40828. 0,
  40829. 0,
  40830. -999,
  40831. -999,
  40832. -1,
  40833. -1,
  40834. -1,
  40835. -1,
  40836. -2,
  40837. -999,
  40838. -2,
  40839. -2,
  40840. -999,
  40841. 0,
  40842. -2,
  40843. -2,
  40844. 0,
  40845. 0,
  40846. -2,
  40847. 0,
  40848. -2,
  40849. 0,
  40850. 0,
  40851. 0,
  40852. -2,
  40853. -1,
  40854. -1,
  40855. 1,
  40856. 1,
  40857. 0,
  40858. 0,
  40859. -1,
  40860. -1,
  40861. -1,
  40862. -1,
  40863. -1,
  40864. -1,
  40865. -1,
  40866. 0,
  40867. 0,
  40868. -1,
  40869. 0,
  40870. -1,
  40871. -1,
  40872. 0,
  40873. -999,
  40874. -1,
  40875. -1,
  40876. -1,
  40877. -1,
  40878. -1,
  40879. -1,
  40880. 0,
  40881. 0,
  40882. 0,
  40883. 0,
  40884. 0,
  40885. 0,
  40886. 0,
  40887. 0,
  40888. 0,
  40889. 0,
  40890. 0,
  40891. 0,
  40892. -2,
  40893. -999,
  40894. -999,
  40895. -999,
  40896. -999,
  40897. -999,
  40898. -1,
  40899. -1,
  40900. -2,
  40901. -2,
  40902. 0,
  40903. 0,
  40904. 0,
  40905. 0,
  40906. -1,
  40907. -1,
  40908. -999,
  40909. -2,
  40910. -2,
  40911. 0,
  40912. 0,
  40913. -1,
  40914. -2,
  40915. -2,
  40916. 0,
  40917. 0,
  40918. 0,
  40919. -1,
  40920. -1,
  40921. -1,
  40922. -2
  40923. ];
  40924. // 0xC0-DF == -1 and 0xE0-FF == -2
  40925. function sanitizeTTProgram(table, ttContext) {
  40926. var data = table.data;
  40927. var i = 0, j, n, b, funcId, pc, lastEndf = 0, lastDeff = 0;
  40928. var stack = [];
  40929. var callstack = [];
  40930. var functionsCalled = [];
  40931. var tooComplexToFollowFunctions = ttContext.tooComplexToFollowFunctions;
  40932. var inFDEF = false, ifLevel = 0, inELSE = 0;
  40933. for (var ii = data.length; i < ii;) {
  40934. var op = data[i++];
  40935. // The TrueType instruction set docs can be found at
  40936. // https://developer.apple.com/fonts/TTRefMan/RM05/Chap5.html
  40937. if (op === 0x40) {
  40938. // NPUSHB - pushes n bytes
  40939. n = data[i++];
  40940. if (inFDEF || inELSE) {
  40941. i += n;
  40942. } else {
  40943. for (j = 0; j < n; j++) {
  40944. stack.push(data[i++]);
  40945. }
  40946. }
  40947. } else if (op === 0x41) {
  40948. // NPUSHW - pushes n words
  40949. n = data[i++];
  40950. if (inFDEF || inELSE) {
  40951. i += n * 2;
  40952. } else {
  40953. for (j = 0; j < n; j++) {
  40954. b = data[i++];
  40955. stack.push(b << 8 | data[i++]);
  40956. }
  40957. }
  40958. } else if ((op & 0xF8) === 0xB0) {
  40959. // PUSHB - pushes bytes
  40960. n = op - 0xB0 + 1;
  40961. if (inFDEF || inELSE) {
  40962. i += n;
  40963. } else {
  40964. for (j = 0; j < n; j++) {
  40965. stack.push(data[i++]);
  40966. }
  40967. }
  40968. } else if ((op & 0xF8) === 0xB8) {
  40969. // PUSHW - pushes words
  40970. n = op - 0xB8 + 1;
  40971. if (inFDEF || inELSE) {
  40972. i += n * 2;
  40973. } else {
  40974. for (j = 0; j < n; j++) {
  40975. b = data[i++];
  40976. stack.push(b << 8 | data[i++]);
  40977. }
  40978. }
  40979. } else if (op === 0x2B && !tooComplexToFollowFunctions) {
  40980. // CALL
  40981. if (!inFDEF && !inELSE) {
  40982. // collecting inforamtion about which functions are used
  40983. funcId = stack[stack.length - 1];
  40984. ttContext.functionsUsed[funcId] = true;
  40985. if (funcId in ttContext.functionsStackDeltas) {
  40986. stack.length += ttContext.functionsStackDeltas[funcId];
  40987. } else if (funcId in ttContext.functionsDefined && functionsCalled.indexOf(funcId) < 0) {
  40988. callstack.push({
  40989. data: data,
  40990. i: i,
  40991. stackTop: stack.length - 1
  40992. });
  40993. functionsCalled.push(funcId);
  40994. pc = ttContext.functionsDefined[funcId];
  40995. if (!pc) {
  40996. warn('TT: CALL non-existent function');
  40997. ttContext.hintsValid = false;
  40998. return;
  40999. }
  41000. data = pc.data;
  41001. i = pc.i;
  41002. }
  41003. }
  41004. } else if (op === 0x2C && !tooComplexToFollowFunctions) {
  41005. // FDEF
  41006. if (inFDEF || inELSE) {
  41007. warn('TT: nested FDEFs not allowed');
  41008. tooComplexToFollowFunctions = true;
  41009. }
  41010. inFDEF = true;
  41011. // collecting inforamtion about which functions are defined
  41012. lastDeff = i;
  41013. funcId = stack.pop();
  41014. ttContext.functionsDefined[funcId] = {
  41015. data: data,
  41016. i: i
  41017. };
  41018. } else if (op === 0x2D) {
  41019. // ENDF - end of function
  41020. if (inFDEF) {
  41021. inFDEF = false;
  41022. lastEndf = i;
  41023. } else {
  41024. pc = callstack.pop();
  41025. if (!pc) {
  41026. warn('TT: ENDF bad stack');
  41027. ttContext.hintsValid = false;
  41028. return;
  41029. }
  41030. funcId = functionsCalled.pop();
  41031. data = pc.data;
  41032. i = pc.i;
  41033. ttContext.functionsStackDeltas[funcId] = stack.length - pc.stackTop;
  41034. }
  41035. } else if (op === 0x89) {
  41036. // IDEF - instruction definition
  41037. if (inFDEF || inELSE) {
  41038. warn('TT: nested IDEFs not allowed');
  41039. tooComplexToFollowFunctions = true;
  41040. }
  41041. inFDEF = true;
  41042. // recording it as a function to track ENDF
  41043. lastDeff = i;
  41044. } else if (op === 0x58) {
  41045. // IF
  41046. ++ifLevel;
  41047. } else if (op === 0x1B) {
  41048. // ELSE
  41049. inELSE = ifLevel;
  41050. } else if (op === 0x59) {
  41051. // EIF
  41052. if (inELSE === ifLevel) {
  41053. inELSE = 0;
  41054. }
  41055. --ifLevel;
  41056. } else if (op === 0x1C) {
  41057. // JMPR
  41058. if (!inFDEF && !inELSE) {
  41059. var offset = stack[stack.length - 1];
  41060. // only jumping forward to prevent infinite loop
  41061. if (offset > 0) {
  41062. i += offset - 1;
  41063. }
  41064. }
  41065. }
  41066. // Adjusting stack not extactly, but just enough to get function id
  41067. if (!inFDEF && !inELSE) {
  41068. var stackDelta = op <= 0x8E ? TTOpsStackDeltas[op] : op >= 0xC0 && op <= 0xDF ? -1 : op >= 0xE0 ? -2 : 0;
  41069. if (op >= 0x71 && op <= 0x75) {
  41070. n = stack.pop();
  41071. if (n === n) {
  41072. stackDelta = -n * 2;
  41073. }
  41074. }
  41075. while (stackDelta < 0 && stack.length > 0) {
  41076. stack.pop();
  41077. stackDelta++;
  41078. }
  41079. while (stackDelta > 0) {
  41080. stack.push(NaN);
  41081. // pushing any number into stack
  41082. stackDelta--;
  41083. }
  41084. }
  41085. }
  41086. ttContext.tooComplexToFollowFunctions = tooComplexToFollowFunctions;
  41087. var content = [data];
  41088. if (i > data.length) {
  41089. content.push(new Uint8Array(i - data.length));
  41090. }
  41091. if (lastDeff > lastEndf) {
  41092. warn('TT: complementing a missing function tail');
  41093. // new function definition started, but not finished
  41094. // complete function by [CLEAR, ENDF]
  41095. content.push(new Uint8Array([
  41096. 0x22,
  41097. 0x2D
  41098. ]));
  41099. }
  41100. foldTTTable(table, content);
  41101. }
  41102. function checkInvalidFunctions(ttContext, maxFunctionDefs) {
  41103. if (ttContext.tooComplexToFollowFunctions) {
  41104. return;
  41105. }
  41106. if (ttContext.functionsDefined.length > maxFunctionDefs) {
  41107. warn('TT: more functions defined than expected');
  41108. ttContext.hintsValid = false;
  41109. return;
  41110. }
  41111. for (var j = 0, jj = ttContext.functionsUsed.length; j < jj; j++) {
  41112. if (j > maxFunctionDefs) {
  41113. warn('TT: invalid function id: ' + j);
  41114. ttContext.hintsValid = false;
  41115. return;
  41116. }
  41117. if (ttContext.functionsUsed[j] && !ttContext.functionsDefined[j]) {
  41118. warn('TT: undefined function: ' + j);
  41119. ttContext.hintsValid = false;
  41120. return;
  41121. }
  41122. }
  41123. }
  41124. function foldTTTable(table, content) {
  41125. if (content.length > 1) {
  41126. // concatenating the content items
  41127. var newLength = 0;
  41128. var j, jj;
  41129. for (j = 0, jj = content.length; j < jj; j++) {
  41130. newLength += content[j].length;
  41131. }
  41132. newLength = newLength + 3 & ~3;
  41133. var result = new Uint8Array(newLength);
  41134. var pos = 0;
  41135. for (j = 0, jj = content.length; j < jj; j++) {
  41136. result.set(content[j], pos);
  41137. pos += content[j].length;
  41138. }
  41139. table.data = result;
  41140. table.length = newLength;
  41141. }
  41142. }
  41143. function sanitizeTTPrograms(fpgm, prep, cvt, maxFunctionDefs) {
  41144. var ttContext = {
  41145. functionsDefined: [],
  41146. functionsUsed: [],
  41147. functionsStackDeltas: [],
  41148. tooComplexToFollowFunctions: false,
  41149. hintsValid: true
  41150. };
  41151. if (fpgm) {
  41152. sanitizeTTProgram(fpgm, ttContext);
  41153. }
  41154. if (prep) {
  41155. sanitizeTTProgram(prep, ttContext);
  41156. }
  41157. if (fpgm) {
  41158. checkInvalidFunctions(ttContext, maxFunctionDefs);
  41159. }
  41160. if (cvt && cvt.length & 1) {
  41161. var cvtData = new Uint8Array(cvt.length + 1);
  41162. cvtData.set(cvt.data);
  41163. cvt.data = cvtData;
  41164. }
  41165. return ttContext.hintsValid;
  41166. }
  41167. // The following steps modify the original font data, making copy
  41168. font = new Stream(new Uint8Array(font.getBytes()));
  41169. var VALID_TABLES = [
  41170. 'OS/2',
  41171. 'cmap',
  41172. 'head',
  41173. 'hhea',
  41174. 'hmtx',
  41175. 'maxp',
  41176. 'name',
  41177. 'post',
  41178. 'loca',
  41179. 'glyf',
  41180. 'fpgm',
  41181. 'prep',
  41182. 'cvt ',
  41183. 'CFF '
  41184. ];
  41185. var header = readOpenTypeHeader(font);
  41186. var numTables = header.numTables;
  41187. var cff, cffFile;
  41188. var tables = Object.create(null);
  41189. tables['OS/2'] = null;
  41190. tables['cmap'] = null;
  41191. tables['head'] = null;
  41192. tables['hhea'] = null;
  41193. tables['hmtx'] = null;
  41194. tables['maxp'] = null;
  41195. tables['name'] = null;
  41196. tables['post'] = null;
  41197. var table;
  41198. for (var i = 0; i < numTables; i++) {
  41199. table = readTableEntry(font);
  41200. if (VALID_TABLES.indexOf(table.tag) < 0) {
  41201. continue;
  41202. }
  41203. // skipping table if it's not a required or optional table
  41204. if (table.length === 0) {
  41205. continue;
  41206. }
  41207. // skipping empty tables
  41208. tables[table.tag] = table;
  41209. }
  41210. var isTrueType = !tables['CFF '];
  41211. if (!isTrueType) {
  41212. // OpenType font
  41213. if (header.version === 'OTTO' && properties.type !== 'CIDFontType2' || !tables['head'] || !tables['hhea'] || !tables['maxp'] || !tables['post']) {
  41214. // no major tables: throwing everything at CFFFont
  41215. cffFile = new Stream(tables['CFF '].data);
  41216. cff = new CFFFont(cffFile, properties);
  41217. adjustWidths(properties);
  41218. return this.convert(name, cff, properties);
  41219. }
  41220. delete tables['glyf'];
  41221. delete tables['loca'];
  41222. delete tables['fpgm'];
  41223. delete tables['prep'];
  41224. delete tables['cvt '];
  41225. this.isOpenType = true;
  41226. } else {
  41227. if (!tables['loca']) {
  41228. error('Required "loca" table is not found');
  41229. }
  41230. if (!tables['glyf']) {
  41231. warn('Required "glyf" table is not found -- trying to recover.');
  41232. // Note: We use `sanitizeGlyphLocations` to add dummy glyf data below.
  41233. tables['glyf'] = {
  41234. tag: 'glyf',
  41235. data: new Uint8Array(0)
  41236. };
  41237. }
  41238. this.isOpenType = false;
  41239. }
  41240. if (!tables['maxp']) {
  41241. error('Required "maxp" table is not found');
  41242. }
  41243. font.pos = (font.start || 0) + tables['maxp'].offset;
  41244. var version = font.getInt32();
  41245. var numGlyphs = font.getUint16();
  41246. var maxFunctionDefs = 0;
  41247. if (version >= 0x00010000 && tables['maxp'].length >= 22) {
  41248. // maxZones can be invalid
  41249. font.pos += 8;
  41250. var maxZones = font.getUint16();
  41251. if (maxZones > 2) {
  41252. // reset to 2 if font has invalid maxZones
  41253. tables['maxp'].data[14] = 0;
  41254. tables['maxp'].data[15] = 2;
  41255. }
  41256. font.pos += 4;
  41257. maxFunctionDefs = font.getUint16();
  41258. }
  41259. var dupFirstEntry = false;
  41260. if (properties.type === 'CIDFontType2' && properties.toUnicode && properties.toUnicode.get(0) > '\u0000') {
  41261. // oracle's defect (see 3427), duplicating first entry
  41262. dupFirstEntry = true;
  41263. numGlyphs++;
  41264. tables['maxp'].data[4] = numGlyphs >> 8;
  41265. tables['maxp'].data[5] = numGlyphs & 255;
  41266. }
  41267. var hintsValid = sanitizeTTPrograms(tables['fpgm'], tables['prep'], tables['cvt '], maxFunctionDefs);
  41268. if (!hintsValid) {
  41269. delete tables['fpgm'];
  41270. delete tables['prep'];
  41271. delete tables['cvt '];
  41272. }
  41273. // Ensure the hmtx table contains the advance width and
  41274. // sidebearings information for numGlyphs in the maxp table
  41275. sanitizeMetrics(font, tables['hhea'], tables['hmtx'], numGlyphs);
  41276. if (!tables['head']) {
  41277. error('Required "head" table is not found');
  41278. }
  41279. sanitizeHead(tables['head'], numGlyphs, isTrueType ? tables['loca'].length : 0);
  41280. var missingGlyphs = Object.create(null);
  41281. if (isTrueType) {
  41282. var isGlyphLocationsLong = int16(tables['head'].data[50], tables['head'].data[51]);
  41283. missingGlyphs = sanitizeGlyphLocations(tables['loca'], tables['glyf'], numGlyphs, isGlyphLocationsLong, hintsValid, dupFirstEntry);
  41284. }
  41285. if (!tables['hhea']) {
  41286. error('Required "hhea" table is not found');
  41287. }
  41288. // Sanitizer reduces the glyph advanceWidth to the maxAdvanceWidth
  41289. // Sometimes it's 0. That needs to be fixed
  41290. if (tables['hhea'].data[10] === 0 && tables['hhea'].data[11] === 0) {
  41291. tables['hhea'].data[10] = 0xFF;
  41292. tables['hhea'].data[11] = 0xFF;
  41293. }
  41294. // Extract some more font properties from the OpenType head and
  41295. // hhea tables; yMin and descent value are always negative.
  41296. var metricsOverride = {
  41297. unitsPerEm: int16(tables['head'].data[18], tables['head'].data[19]),
  41298. yMax: int16(tables['head'].data[42], tables['head'].data[43]),
  41299. yMin: signedInt16(tables['head'].data[38], tables['head'].data[39]),
  41300. ascent: int16(tables['hhea'].data[4], tables['hhea'].data[5]),
  41301. descent: signedInt16(tables['hhea'].data[6], tables['hhea'].data[7])
  41302. };
  41303. // PDF FontDescriptor metrics lie -- using data from actual font.
  41304. this.ascent = metricsOverride.ascent / metricsOverride.unitsPerEm;
  41305. this.descent = metricsOverride.descent / metricsOverride.unitsPerEm;
  41306. // The 'post' table has glyphs names.
  41307. if (tables['post']) {
  41308. var valid = readPostScriptTable(tables['post'], properties, numGlyphs);
  41309. if (!valid) {
  41310. tables['post'] = null;
  41311. }
  41312. }
  41313. var charCodeToGlyphId = [], charCode;
  41314. var toUnicode = properties.toUnicode, widths = properties.widths;
  41315. var skipToUnicode = toUnicode instanceof IdentityToUnicodeMap || toUnicode.length === 0x10000;
  41316. // Helper function to try to skip mapping of empty glyphs.
  41317. // Note: In some cases, just relying on the glyph data doesn't work,
  41318. // hence we also use a few heuristics to fix various PDF files.
  41319. function hasGlyph(glyphId, charCode, widthCode) {
  41320. if (!missingGlyphs[glyphId]) {
  41321. return true;
  41322. }
  41323. if (!skipToUnicode && charCode >= 0 && toUnicode.has(charCode)) {
  41324. return true;
  41325. }
  41326. if (widths && widthCode >= 0 && isNum(widths[widthCode])) {
  41327. return true;
  41328. }
  41329. return false;
  41330. }
  41331. if (properties.type === 'CIDFontType2') {
  41332. var cidToGidMap = properties.cidToGidMap || [];
  41333. var isCidToGidMapEmpty = cidToGidMap.length === 0;
  41334. properties.cMap.forEach(function (charCode, cid) {
  41335. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  41336. var glyphId = -1;
  41337. if (isCidToGidMapEmpty) {
  41338. glyphId = cid;
  41339. } else if (cidToGidMap[cid] !== undefined) {
  41340. glyphId = cidToGidMap[cid];
  41341. }
  41342. if (glyphId >= 0 && glyphId < numGlyphs && hasGlyph(glyphId, charCode, cid)) {
  41343. charCodeToGlyphId[charCode] = glyphId;
  41344. }
  41345. });
  41346. if (dupFirstEntry && (isCidToGidMapEmpty || !charCodeToGlyphId[0])) {
  41347. // We don't duplicate the first entry in the `charCodeToGlyphId` map
  41348. // if the font has a `CIDToGIDMap` which has already mapped the first
  41349. // entry to a non-zero `glyphId` (fixes issue7544.pdf).
  41350. charCodeToGlyphId[0] = numGlyphs - 1;
  41351. }
  41352. } else {
  41353. // Most of the following logic in this code branch is based on the
  41354. // 9.6.6.4 of the PDF spec.
  41355. var cmapTable = readCmapTable(tables['cmap'], font, this.isSymbolicFont, properties.hasEncoding);
  41356. var cmapPlatformId = cmapTable.platformId;
  41357. var cmapEncodingId = cmapTable.encodingId;
  41358. var cmapMappings = cmapTable.mappings;
  41359. var cmapMappingsLength = cmapMappings.length;
  41360. // The spec seems to imply that if the font is symbolic the encoding
  41361. // should be ignored, this doesn't appear to work for 'preistabelle.pdf'
  41362. // where the the font is symbolic and it has an encoding.
  41363. if (properties.hasEncoding && (cmapPlatformId === 3 && cmapEncodingId === 1 || cmapPlatformId === 1 && cmapEncodingId === 0) || cmapPlatformId === -1 && cmapEncodingId === -1 && // Temporary hack
  41364. !!getEncoding(properties.baseEncodingName)) {
  41365. // Temporary hack
  41366. // When no preferred cmap table was found and |baseEncodingName| is
  41367. // one of the predefined encodings, we seem to obtain a better
  41368. // |charCodeToGlyphId| map from the code below (fixes bug 1057544).
  41369. // TODO: Note that this is a hack which should be removed as soon as
  41370. // we have proper support for more exotic cmap tables.
  41371. var baseEncoding = [];
  41372. if (properties.baseEncodingName === 'MacRomanEncoding' || properties.baseEncodingName === 'WinAnsiEncoding') {
  41373. baseEncoding = getEncoding(properties.baseEncodingName);
  41374. }
  41375. var glyphsUnicodeMap = getGlyphsUnicode();
  41376. for (charCode = 0; charCode < 256; charCode++) {
  41377. var glyphName, standardGlyphName;
  41378. if (this.differences && charCode in this.differences) {
  41379. glyphName = this.differences[charCode];
  41380. } else if (charCode in baseEncoding && baseEncoding[charCode] !== '') {
  41381. glyphName = baseEncoding[charCode];
  41382. } else {
  41383. glyphName = StandardEncoding[charCode];
  41384. }
  41385. if (!glyphName) {
  41386. continue;
  41387. }
  41388. // Ensure that non-standard glyph names are resolved to valid ones.
  41389. standardGlyphName = recoverGlyphName(glyphName, glyphsUnicodeMap);
  41390. var unicodeOrCharCode, isUnicode = false;
  41391. if (cmapPlatformId === 3 && cmapEncodingId === 1) {
  41392. unicodeOrCharCode = glyphsUnicodeMap[standardGlyphName];
  41393. isUnicode = true;
  41394. } else if (cmapPlatformId === 1 && cmapEncodingId === 0) {
  41395. // TODO: the encoding needs to be updated with mac os table.
  41396. unicodeOrCharCode = MacRomanEncoding.indexOf(standardGlyphName);
  41397. }
  41398. var found = false;
  41399. for (i = 0; i < cmapMappingsLength; ++i) {
  41400. if (cmapMappings[i].charCode !== unicodeOrCharCode) {
  41401. continue;
  41402. }
  41403. var code = isUnicode ? charCode : unicodeOrCharCode;
  41404. if (hasGlyph(cmapMappings[i].glyphId, code, -1)) {
  41405. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  41406. found = true;
  41407. break;
  41408. }
  41409. }
  41410. if (!found && properties.glyphNames) {
  41411. // Try to map using the post table.
  41412. var glyphId = properties.glyphNames.indexOf(glyphName);
  41413. // The post table ought to use the same kind of glyph names as the
  41414. // `differences` array, but check the standard ones as a fallback.
  41415. if (glyphId === -1 && standardGlyphName !== glyphName) {
  41416. glyphId = properties.glyphNames.indexOf(standardGlyphName);
  41417. }
  41418. if (glyphId > 0 && hasGlyph(glyphId, -1, -1)) {
  41419. charCodeToGlyphId[charCode] = glyphId;
  41420. found = true;
  41421. }
  41422. }
  41423. if (!found) {
  41424. charCodeToGlyphId[charCode] = 0;
  41425. }
  41426. }
  41427. } else // notdef
  41428. if (cmapPlatformId === 0 && cmapEncodingId === 0) {
  41429. // Default Unicode semantics, use the charcodes as is.
  41430. for (i = 0; i < cmapMappingsLength; ++i) {
  41431. charCodeToGlyphId[cmapMappings[i].charCode] = cmapMappings[i].glyphId;
  41432. }
  41433. } else {
  41434. // For (3, 0) cmap tables:
  41435. // The charcode key being stored in charCodeToGlyphId is the lower
  41436. // byte of the two-byte charcodes of the cmap table since according to
  41437. // the spec: 'each byte from the string shall be prepended with the
  41438. // high byte of the range [of charcodes in the cmap table], to form
  41439. // a two-byte character, which shall be used to select the
  41440. // associated glyph description from the subtable'.
  41441. //
  41442. // For (1, 0) cmap tables:
  41443. // 'single bytes from the string shall be used to look up the
  41444. // associated glyph descriptions from the subtable'. This means
  41445. // charcodes in the cmap will be single bytes, so no-op since
  41446. // glyph.charCode & 0xFF === glyph.charCode
  41447. for (i = 0; i < cmapMappingsLength; ++i) {
  41448. charCode = cmapMappings[i].charCode & 0xFF;
  41449. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  41450. }
  41451. }
  41452. }
  41453. if (charCodeToGlyphId.length === 0) {
  41454. // defines at least one glyph
  41455. charCodeToGlyphId[0] = 0;
  41456. }
  41457. // Converting glyphs and ids into font's cmap table
  41458. var newMapping = adjustMapping(charCodeToGlyphId, properties);
  41459. this.toFontChar = newMapping.toFontChar;
  41460. tables['cmap'] = {
  41461. tag: 'cmap',
  41462. data: createCmapTable(newMapping.charCodeToGlyphId, numGlyphs)
  41463. };
  41464. if (!tables['OS/2'] || !validateOS2Table(tables['OS/2'])) {
  41465. tables['OS/2'] = {
  41466. tag: 'OS/2',
  41467. data: createOS2Table(properties, newMapping.charCodeToGlyphId, metricsOverride)
  41468. };
  41469. }
  41470. // Rewrite the 'post' table if needed
  41471. if (!tables['post']) {
  41472. tables['post'] = {
  41473. tag: 'post',
  41474. data: createPostTable(properties)
  41475. };
  41476. }
  41477. if (!isTrueType) {
  41478. try {
  41479. // Trying to repair CFF file
  41480. cffFile = new Stream(tables['CFF '].data);
  41481. var parser = new CFFParser(cffFile, properties, SEAC_ANALYSIS_ENABLED);
  41482. cff = parser.parse();
  41483. var compiler = new CFFCompiler(cff);
  41484. tables['CFF '].data = compiler.compile();
  41485. } catch (e) {
  41486. warn('Failed to compile font ' + properties.loadedName);
  41487. }
  41488. }
  41489. // Re-creating 'name' table
  41490. if (!tables['name']) {
  41491. tables['name'] = {
  41492. tag: 'name',
  41493. data: createNameTable(this.name)
  41494. };
  41495. } else {
  41496. // ... using existing 'name' table as prototype
  41497. var namePrototype = readNameTable(tables['name']);
  41498. tables['name'].data = createNameTable(name, namePrototype);
  41499. }
  41500. var builder = new OpenTypeFileBuilder(header.version);
  41501. for (var tableTag in tables) {
  41502. builder.addTable(tableTag, tables[tableTag].data);
  41503. }
  41504. return builder.toArray();
  41505. },
  41506. convert: function Font_convert(fontName, font, properties) {
  41507. // TODO: Check the charstring widths to determine this.
  41508. properties.fixedPitch = false;
  41509. if (properties.builtInEncoding) {
  41510. // For Type1 fonts that do not include either `ToUnicode` or `Encoding`
  41511. // data, attempt to use the `builtInEncoding` to improve text selection.
  41512. adjustToUnicode(properties, properties.builtInEncoding);
  41513. }
  41514. var mapping = font.getGlyphMapping(properties);
  41515. var newMapping = adjustMapping(mapping, properties);
  41516. this.toFontChar = newMapping.toFontChar;
  41517. var numGlyphs = font.numGlyphs;
  41518. function getCharCodes(charCodeToGlyphId, glyphId) {
  41519. var charCodes = null;
  41520. for (var charCode in charCodeToGlyphId) {
  41521. if (glyphId === charCodeToGlyphId[charCode]) {
  41522. if (!charCodes) {
  41523. charCodes = [];
  41524. }
  41525. charCodes.push(charCode | 0);
  41526. }
  41527. }
  41528. return charCodes;
  41529. }
  41530. function createCharCode(charCodeToGlyphId, glyphId) {
  41531. for (var charCode in charCodeToGlyphId) {
  41532. if (glyphId === charCodeToGlyphId[charCode]) {
  41533. return charCode | 0;
  41534. }
  41535. }
  41536. newMapping.charCodeToGlyphId[newMapping.nextAvailableFontCharCode] = glyphId;
  41537. return newMapping.nextAvailableFontCharCode++;
  41538. }
  41539. var seacs = font.seacs;
  41540. if (SEAC_ANALYSIS_ENABLED && seacs && seacs.length) {
  41541. var matrix = properties.fontMatrix || FONT_IDENTITY_MATRIX;
  41542. var charset = font.getCharset();
  41543. var seacMap = Object.create(null);
  41544. for (var glyphId in seacs) {
  41545. glyphId |= 0;
  41546. var seac = seacs[glyphId];
  41547. var baseGlyphName = StandardEncoding[seac[2]];
  41548. var accentGlyphName = StandardEncoding[seac[3]];
  41549. var baseGlyphId = charset.indexOf(baseGlyphName);
  41550. var accentGlyphId = charset.indexOf(accentGlyphName);
  41551. if (baseGlyphId < 0 || accentGlyphId < 0) {
  41552. continue;
  41553. }
  41554. var accentOffset = {
  41555. x: seac[0] * matrix[0] + seac[1] * matrix[2] + matrix[4],
  41556. y: seac[0] * matrix[1] + seac[1] * matrix[3] + matrix[5]
  41557. };
  41558. var charCodes = getCharCodes(mapping, glyphId);
  41559. if (!charCodes) {
  41560. // There's no point in mapping it if the char code was never mapped
  41561. // to begin with.
  41562. continue;
  41563. }
  41564. for (var i = 0, ii = charCodes.length; i < ii; i++) {
  41565. var charCode = charCodes[i];
  41566. // Find a fontCharCode that maps to the base and accent glyphs.
  41567. // If one doesn't exists, create it.
  41568. var charCodeToGlyphId = newMapping.charCodeToGlyphId;
  41569. var baseFontCharCode = createCharCode(charCodeToGlyphId, baseGlyphId);
  41570. var accentFontCharCode = createCharCode(charCodeToGlyphId, accentGlyphId);
  41571. seacMap[charCode] = {
  41572. baseFontCharCode: baseFontCharCode,
  41573. accentFontCharCode: accentFontCharCode,
  41574. accentOffset: accentOffset
  41575. };
  41576. }
  41577. }
  41578. properties.seacMap = seacMap;
  41579. }
  41580. var unitsPerEm = 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0];
  41581. var builder = new OpenTypeFileBuilder('\x4F\x54\x54\x4F');
  41582. // PostScript Font Program
  41583. builder.addTable('CFF ', font.data);
  41584. // OS/2 and Windows Specific metrics
  41585. builder.addTable('OS/2', createOS2Table(properties, newMapping.charCodeToGlyphId));
  41586. // Character to glyphs mapping
  41587. builder.addTable('cmap', createCmapTable(newMapping.charCodeToGlyphId, numGlyphs));
  41588. // Font header
  41589. builder.addTable('head', '\x00\x01\x00\x00' + // Version number
  41590. '\x00\x00\x10\x00' + // fontRevision
  41591. '\x00\x00\x00\x00' + // checksumAdjustement
  41592. '\x5F\x0F\x3C\xF5' + // magicNumber
  41593. '\x00\x00' + // Flags
  41594. safeString16(unitsPerEm) + // unitsPerEM
  41595. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // creation date
  41596. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // modifification date
  41597. '\x00\x00' + // xMin
  41598. safeString16(properties.descent) + // yMin
  41599. '\x0F\xFF' + // xMax
  41600. safeString16(properties.ascent) + // yMax
  41601. string16(properties.italicAngle ? 2 : 0) + // macStyle
  41602. '\x00\x11' + // lowestRecPPEM
  41603. '\x00\x00' + // fontDirectionHint
  41604. '\x00\x00' + // indexToLocFormat
  41605. '\x00\x00');
  41606. // glyphDataFormat
  41607. // Horizontal header
  41608. builder.addTable('hhea', '\x00\x01\x00\x00' + // Version number
  41609. safeString16(properties.ascent) + // Typographic Ascent
  41610. safeString16(properties.descent) + // Typographic Descent
  41611. '\x00\x00' + // Line Gap
  41612. '\xFF\xFF' + // advanceWidthMax
  41613. '\x00\x00' + // minLeftSidebearing
  41614. '\x00\x00' + // minRightSidebearing
  41615. '\x00\x00' + // xMaxExtent
  41616. safeString16(properties.capHeight) + // caretSlopeRise
  41617. safeString16(Math.tan(properties.italicAngle) * properties.xHeight) + // caretSlopeRun
  41618. '\x00\x00' + // caretOffset
  41619. '\x00\x00' + // -reserved-
  41620. '\x00\x00' + // -reserved-
  41621. '\x00\x00' + // -reserved-
  41622. '\x00\x00' + // -reserved-
  41623. '\x00\x00' + // metricDataFormat
  41624. string16(numGlyphs));
  41625. // Number of HMetrics
  41626. // Horizontal metrics
  41627. builder.addTable('hmtx', function fontFieldsHmtx() {
  41628. var charstrings = font.charstrings;
  41629. var cffWidths = font.cff ? font.cff.widths : null;
  41630. var hmtx = '\x00\x00\x00\x00';
  41631. // Fake .notdef
  41632. for (var i = 1, ii = numGlyphs; i < ii; i++) {
  41633. var width = 0;
  41634. if (charstrings) {
  41635. var charstring = charstrings[i - 1];
  41636. width = 'width' in charstring ? charstring.width : 0;
  41637. } else if (cffWidths) {
  41638. width = Math.ceil(cffWidths[i] || 0);
  41639. }
  41640. hmtx += string16(width) + string16(0);
  41641. }
  41642. return hmtx;
  41643. }());
  41644. // Maximum profile
  41645. builder.addTable('maxp', '\x00\x00\x50\x00' + // Version number
  41646. string16(numGlyphs));
  41647. // Num of glyphs
  41648. // Naming tables
  41649. builder.addTable('name', createNameTable(fontName));
  41650. // PostScript information
  41651. builder.addTable('post', createPostTable(properties));
  41652. return builder.toArray();
  41653. },
  41654. get spaceWidth() {
  41655. if ('_shadowWidth' in this) {
  41656. return this._shadowWidth;
  41657. }
  41658. // trying to estimate space character width
  41659. var possibleSpaceReplacements = [
  41660. 'space',
  41661. 'minus',
  41662. 'one',
  41663. 'i',
  41664. 'I'
  41665. ];
  41666. var width;
  41667. for (var i = 0, ii = possibleSpaceReplacements.length; i < ii; i++) {
  41668. var glyphName = possibleSpaceReplacements[i];
  41669. // if possible, getting width by glyph name
  41670. if (glyphName in this.widths) {
  41671. width = this.widths[glyphName];
  41672. break;
  41673. }
  41674. var glyphsUnicodeMap = getGlyphsUnicode();
  41675. var glyphUnicode = glyphsUnicodeMap[glyphName];
  41676. // finding the charcode via unicodeToCID map
  41677. var charcode = 0;
  41678. if (this.composite) {
  41679. if (this.cMap.contains(glyphUnicode)) {
  41680. charcode = this.cMap.lookup(glyphUnicode);
  41681. }
  41682. }
  41683. // ... via toUnicode map
  41684. if (!charcode && this.toUnicode) {
  41685. charcode = this.toUnicode.charCodeOf(glyphUnicode);
  41686. }
  41687. // setting it to unicode if negative or undefined
  41688. if (charcode <= 0) {
  41689. charcode = glyphUnicode;
  41690. }
  41691. // trying to get width via charcode
  41692. width = this.widths[charcode];
  41693. if (width) {
  41694. break;
  41695. }
  41696. }
  41697. // the non-zero width found
  41698. width = width || this.defaultWidth;
  41699. // Do not shadow the property here. See discussion:
  41700. // https://github.com/mozilla/pdf.js/pull/2127#discussion_r1662280
  41701. this._shadowWidth = width;
  41702. return width;
  41703. },
  41704. charToGlyph: function Font_charToGlyph(charcode, isSpace) {
  41705. var fontCharCode, width, operatorListId;
  41706. var widthCode = charcode;
  41707. if (this.cMap && this.cMap.contains(charcode)) {
  41708. widthCode = this.cMap.lookup(charcode);
  41709. }
  41710. width = this.widths[widthCode];
  41711. width = isNum(width) ? width : this.defaultWidth;
  41712. var vmetric = this.vmetrics && this.vmetrics[widthCode];
  41713. var unicode = this.toUnicode.get(charcode) || charcode;
  41714. if (typeof unicode === 'number') {
  41715. unicode = String.fromCharCode(unicode);
  41716. }
  41717. var isInFont = charcode in this.toFontChar;
  41718. // First try the toFontChar map, if it's not there then try falling
  41719. // back to the char code.
  41720. fontCharCode = this.toFontChar[charcode] || charcode;
  41721. if (this.missingFile) {
  41722. fontCharCode = mapSpecialUnicodeValues(fontCharCode);
  41723. }
  41724. if (this.isType3Font) {
  41725. // Font char code in this case is actually a glyph name.
  41726. operatorListId = fontCharCode;
  41727. }
  41728. var accent = null;
  41729. if (this.seacMap && this.seacMap[charcode]) {
  41730. isInFont = true;
  41731. var seac = this.seacMap[charcode];
  41732. fontCharCode = seac.baseFontCharCode;
  41733. accent = {
  41734. fontChar: String.fromCharCode(seac.accentFontCharCode),
  41735. offset: seac.accentOffset
  41736. };
  41737. }
  41738. var fontChar = String.fromCharCode(fontCharCode);
  41739. var glyph = this.glyphCache[charcode];
  41740. if (!glyph || !glyph.matchesForCache(fontChar, unicode, accent, width, vmetric, operatorListId, isSpace, isInFont)) {
  41741. glyph = new Glyph(fontChar, unicode, accent, width, vmetric, operatorListId, isSpace, isInFont);
  41742. this.glyphCache[charcode] = glyph;
  41743. }
  41744. return glyph;
  41745. },
  41746. charsToGlyphs: function Font_charsToGlyphs(chars) {
  41747. var charsCache = this.charsCache;
  41748. var glyphs, glyph, charcode;
  41749. // if we translated this string before, just grab it from the cache
  41750. if (charsCache) {
  41751. glyphs = charsCache[chars];
  41752. if (glyphs) {
  41753. return glyphs;
  41754. }
  41755. }
  41756. // lazily create the translation cache
  41757. if (!charsCache) {
  41758. charsCache = this.charsCache = Object.create(null);
  41759. }
  41760. glyphs = [];
  41761. var charsCacheKey = chars;
  41762. var i = 0, ii;
  41763. if (this.cMap) {
  41764. // composite fonts have multi-byte strings convert the string from
  41765. // single-byte to multi-byte
  41766. var c = Object.create(null);
  41767. while (i < chars.length) {
  41768. this.cMap.readCharCode(chars, i, c);
  41769. charcode = c.charcode;
  41770. var length = c.length;
  41771. i += length;
  41772. // Space is char with code 0x20 and length 1 in multiple-byte codes.
  41773. var isSpace = length === 1 && chars.charCodeAt(i - 1) === 0x20;
  41774. glyph = this.charToGlyph(charcode, isSpace);
  41775. glyphs.push(glyph);
  41776. }
  41777. } else {
  41778. for (i = 0, ii = chars.length; i < ii; ++i) {
  41779. charcode = chars.charCodeAt(i);
  41780. glyph = this.charToGlyph(charcode, charcode === 0x20);
  41781. glyphs.push(glyph);
  41782. }
  41783. }
  41784. // Enter the translated string into the cache
  41785. return charsCache[charsCacheKey] = glyphs;
  41786. }
  41787. };
  41788. return Font;
  41789. }();
  41790. var ErrorFont = function ErrorFontClosure() {
  41791. function ErrorFont(error) {
  41792. this.error = error;
  41793. this.loadedName = 'g_font_error';
  41794. this.loading = false;
  41795. }
  41796. ErrorFont.prototype = {
  41797. charsToGlyphs: function ErrorFont_charsToGlyphs() {
  41798. return [];
  41799. },
  41800. exportData: function ErrorFont_exportData() {
  41801. return { error: this.error };
  41802. }
  41803. };
  41804. return ErrorFont;
  41805. }();
  41806. /**
  41807. * Shared logic for building a char code to glyph id mapping for Type1 and
  41808. * simple CFF fonts. See section 9.6.6.2 of the spec.
  41809. * @param {Object} properties Font properties object.
  41810. * @param {Object} builtInEncoding The encoding contained within the actual font
  41811. * data.
  41812. * @param {Array} glyphNames Array of glyph names where the index is the
  41813. * glyph ID.
  41814. * @returns {Object} A char code to glyph ID map.
  41815. */
  41816. function type1FontGlyphMapping(properties, builtInEncoding, glyphNames) {
  41817. var charCodeToGlyphId = Object.create(null);
  41818. var glyphId, charCode, baseEncoding;
  41819. if (properties.baseEncodingName) {
  41820. // If a valid base encoding name was used, the mapping is initialized with
  41821. // that.
  41822. baseEncoding = getEncoding(properties.baseEncodingName);
  41823. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  41824. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  41825. if (glyphId >= 0) {
  41826. charCodeToGlyphId[charCode] = glyphId;
  41827. } else {
  41828. charCodeToGlyphId[charCode] = 0;
  41829. }
  41830. }
  41831. } else // notdef
  41832. if (!!(properties.flags & FontFlags.Symbolic)) {
  41833. // For a symbolic font the encoding should be the fonts built-in
  41834. // encoding.
  41835. for (charCode in builtInEncoding) {
  41836. charCodeToGlyphId[charCode] = builtInEncoding[charCode];
  41837. }
  41838. } else {
  41839. // For non-symbolic fonts that don't have a base encoding the standard
  41840. // encoding should be used.
  41841. baseEncoding = StandardEncoding;
  41842. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  41843. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  41844. if (glyphId >= 0) {
  41845. charCodeToGlyphId[charCode] = glyphId;
  41846. } else {
  41847. charCodeToGlyphId[charCode] = 0;
  41848. }
  41849. }
  41850. }
  41851. // notdef
  41852. // Lastly, merge in the differences.
  41853. var differences = properties.differences, glyphsUnicodeMap;
  41854. if (differences) {
  41855. for (charCode in differences) {
  41856. var glyphName = differences[charCode];
  41857. glyphId = glyphNames.indexOf(glyphName);
  41858. if (glyphId === -1) {
  41859. if (!glyphsUnicodeMap) {
  41860. glyphsUnicodeMap = getGlyphsUnicode();
  41861. }
  41862. var standardGlyphName = recoverGlyphName(glyphName, glyphsUnicodeMap);
  41863. if (standardGlyphName !== glyphName) {
  41864. glyphId = glyphNames.indexOf(standardGlyphName);
  41865. }
  41866. }
  41867. if (glyphId >= 0) {
  41868. charCodeToGlyphId[charCode] = glyphId;
  41869. } else {
  41870. charCodeToGlyphId[charCode] = 0;
  41871. }
  41872. }
  41873. }
  41874. // notdef
  41875. return charCodeToGlyphId;
  41876. }
  41877. // Type1Font is also a CIDFontType0.
  41878. var Type1Font = function Type1FontClosure() {
  41879. function findBlock(streamBytes, signature, startIndex) {
  41880. var streamBytesLength = streamBytes.length;
  41881. var signatureLength = signature.length;
  41882. var scanLength = streamBytesLength - signatureLength;
  41883. var i = startIndex, j, found = false;
  41884. while (i < scanLength) {
  41885. j = 0;
  41886. while (j < signatureLength && streamBytes[i + j] === signature[j]) {
  41887. j++;
  41888. }
  41889. if (j >= signatureLength) {
  41890. // `signature` found, skip over whitespace.
  41891. i += j;
  41892. while (i < streamBytesLength && isSpace(streamBytes[i])) {
  41893. i++;
  41894. }
  41895. found = true;
  41896. break;
  41897. }
  41898. i++;
  41899. }
  41900. return {
  41901. found: found,
  41902. length: i
  41903. };
  41904. }
  41905. function getHeaderBlock(stream, suggestedLength) {
  41906. var EEXEC_SIGNATURE = [
  41907. 0x65,
  41908. 0x65,
  41909. 0x78,
  41910. 0x65,
  41911. 0x63
  41912. ];
  41913. var streamStartPos = stream.pos;
  41914. // Save the initial stream position.
  41915. var headerBytes, headerBytesLength, block;
  41916. try {
  41917. headerBytes = stream.getBytes(suggestedLength);
  41918. headerBytesLength = headerBytes.length;
  41919. } catch (ex) {
  41920. if (ex instanceof MissingDataException) {
  41921. throw ex;
  41922. }
  41923. }
  41924. // Ignore errors if the `suggestedLength` is huge enough that a Uint8Array
  41925. // cannot hold the result of `getBytes`, and fallback to simply checking
  41926. // the entire stream (fixes issue3928.pdf).
  41927. if (headerBytesLength === suggestedLength) {
  41928. // Most of the time `suggestedLength` is correct, so to speed things up we
  41929. // initially only check the last few bytes to see if the header was found.
  41930. // Otherwise we (potentially) check the entire stream to prevent errors in
  41931. // `Type1Parser` (fixes issue5686.pdf).
  41932. block = findBlock(headerBytes, EEXEC_SIGNATURE, suggestedLength - 2 * EEXEC_SIGNATURE.length);
  41933. if (block.found && block.length === suggestedLength) {
  41934. return {
  41935. stream: new Stream(headerBytes),
  41936. length: suggestedLength
  41937. };
  41938. }
  41939. }
  41940. warn('Invalid "Length1" property in Type1 font -- trying to recover.');
  41941. stream.pos = streamStartPos;
  41942. // Reset the stream position.
  41943. var SCAN_BLOCK_LENGTH = 2048;
  41944. var actualLength;
  41945. while (true) {
  41946. var scanBytes = stream.peekBytes(SCAN_BLOCK_LENGTH);
  41947. block = findBlock(scanBytes, EEXEC_SIGNATURE, 0);
  41948. if (block.length === 0) {
  41949. break;
  41950. }
  41951. stream.pos += block.length;
  41952. // Update the stream position.
  41953. if (block.found) {
  41954. actualLength = stream.pos - streamStartPos;
  41955. break;
  41956. }
  41957. }
  41958. stream.pos = streamStartPos;
  41959. // Reset the stream position.
  41960. if (actualLength) {
  41961. return {
  41962. stream: new Stream(stream.getBytes(actualLength)),
  41963. length: actualLength
  41964. };
  41965. }
  41966. warn('Unable to recover "Length1" property in Type1 font -- using as is.');
  41967. return {
  41968. stream: new Stream(stream.getBytes(suggestedLength)),
  41969. length: suggestedLength
  41970. };
  41971. }
  41972. function getEexecBlock(stream, suggestedLength) {
  41973. // We should ideally parse the eexec block to ensure that `suggestedLength`
  41974. // is correct, so we don't truncate the block data if it's too small.
  41975. // However, this would also require checking if the fixed-content portion
  41976. // exists (using the 'Length3' property), and ensuring that it's valid.
  41977. //
  41978. // Given that `suggestedLength` almost always is correct, all the validation
  41979. // would require a great deal of unnecessary parsing for most fonts.
  41980. // To save time, we always fetch the entire stream instead, which also avoid
  41981. // issues if `suggestedLength` is huge (see comment in `getHeaderBlock`).
  41982. //
  41983. // NOTE: This means that the function can include the fixed-content portion
  41984. // in the returned eexec block. In practice this does *not* seem to matter,
  41985. // since `Type1Parser_extractFontProgram` will skip over any non-commands.
  41986. var eexecBytes = stream.getBytes();
  41987. return {
  41988. stream: new Stream(eexecBytes),
  41989. length: eexecBytes.length
  41990. };
  41991. }
  41992. function Type1Font(name, file, properties) {
  41993. // Some bad generators embed pfb file as is, we have to strip 6-byte header.
  41994. // Also, length1 and length2 might be off by 6 bytes as well.
  41995. // http://www.math.ubc.ca/~cass/piscript/type1.pdf
  41996. var PFB_HEADER_SIZE = 6;
  41997. var headerBlockLength = properties.length1;
  41998. var eexecBlockLength = properties.length2;
  41999. var pfbHeader = file.peekBytes(PFB_HEADER_SIZE);
  42000. var pfbHeaderPresent = pfbHeader[0] === 0x80 && pfbHeader[1] === 0x01;
  42001. if (pfbHeaderPresent) {
  42002. file.skip(PFB_HEADER_SIZE);
  42003. headerBlockLength = pfbHeader[5] << 24 | pfbHeader[4] << 16 | pfbHeader[3] << 8 | pfbHeader[2];
  42004. }
  42005. // Get the data block containing glyphs and subrs information
  42006. var headerBlock = getHeaderBlock(file, headerBlockLength);
  42007. headerBlockLength = headerBlock.length;
  42008. var headerBlockParser = new Type1Parser(headerBlock.stream, false, SEAC_ANALYSIS_ENABLED);
  42009. headerBlockParser.extractFontHeader(properties);
  42010. if (pfbHeaderPresent) {
  42011. pfbHeader = file.getBytes(PFB_HEADER_SIZE);
  42012. eexecBlockLength = pfbHeader[5] << 24 | pfbHeader[4] << 16 | pfbHeader[3] << 8 | pfbHeader[2];
  42013. }
  42014. // Decrypt the data blocks and retrieve it's content
  42015. var eexecBlock = getEexecBlock(file, eexecBlockLength);
  42016. eexecBlockLength = eexecBlock.length;
  42017. var eexecBlockParser = new Type1Parser(eexecBlock.stream, true, SEAC_ANALYSIS_ENABLED);
  42018. var data = eexecBlockParser.extractFontProgram();
  42019. for (var info in data.properties) {
  42020. properties[info] = data.properties[info];
  42021. }
  42022. var charstrings = data.charstrings;
  42023. var type2Charstrings = this.getType2Charstrings(charstrings);
  42024. var subrs = this.getType2Subrs(data.subrs);
  42025. this.charstrings = charstrings;
  42026. this.data = this.wrap(name, type2Charstrings, this.charstrings, subrs, properties);
  42027. this.seacs = this.getSeacs(data.charstrings);
  42028. }
  42029. Type1Font.prototype = {
  42030. get numGlyphs() {
  42031. return this.charstrings.length + 1;
  42032. },
  42033. getCharset: function Type1Font_getCharset() {
  42034. var charset = ['.notdef'];
  42035. var charstrings = this.charstrings;
  42036. for (var glyphId = 0; glyphId < charstrings.length; glyphId++) {
  42037. charset.push(charstrings[glyphId].glyphName);
  42038. }
  42039. return charset;
  42040. },
  42041. getGlyphMapping: function Type1Font_getGlyphMapping(properties) {
  42042. var charstrings = this.charstrings;
  42043. var glyphNames = ['.notdef'], glyphId;
  42044. for (glyphId = 0; glyphId < charstrings.length; glyphId++) {
  42045. glyphNames.push(charstrings[glyphId].glyphName);
  42046. }
  42047. var encoding = properties.builtInEncoding;
  42048. if (encoding) {
  42049. var builtInEncoding = Object.create(null);
  42050. for (var charCode in encoding) {
  42051. glyphId = glyphNames.indexOf(encoding[charCode]);
  42052. if (glyphId >= 0) {
  42053. builtInEncoding[charCode] = glyphId;
  42054. }
  42055. }
  42056. }
  42057. return type1FontGlyphMapping(properties, builtInEncoding, glyphNames);
  42058. },
  42059. getSeacs: function Type1Font_getSeacs(charstrings) {
  42060. var i, ii;
  42061. var seacMap = [];
  42062. for (i = 0, ii = charstrings.length; i < ii; i++) {
  42063. var charstring = charstrings[i];
  42064. if (charstring.seac) {
  42065. // Offset by 1 for .notdef
  42066. seacMap[i + 1] = charstring.seac;
  42067. }
  42068. }
  42069. return seacMap;
  42070. },
  42071. getType2Charstrings: function Type1Font_getType2Charstrings(type1Charstrings) {
  42072. var type2Charstrings = [];
  42073. for (var i = 0, ii = type1Charstrings.length; i < ii; i++) {
  42074. type2Charstrings.push(type1Charstrings[i].charstring);
  42075. }
  42076. return type2Charstrings;
  42077. },
  42078. getType2Subrs: function Type1Font_getType2Subrs(type1Subrs) {
  42079. var bias = 0;
  42080. var count = type1Subrs.length;
  42081. if (count < 1133) {
  42082. bias = 107;
  42083. } else if (count < 33769) {
  42084. bias = 1131;
  42085. } else {
  42086. bias = 32768;
  42087. }
  42088. // Add a bunch of empty subrs to deal with the Type2 bias
  42089. var type2Subrs = [];
  42090. var i;
  42091. for (i = 0; i < bias; i++) {
  42092. type2Subrs.push([0x0B]);
  42093. }
  42094. for (i = 0; i < count; i++) {
  42095. type2Subrs.push(type1Subrs[i]);
  42096. }
  42097. return type2Subrs;
  42098. },
  42099. wrap: function Type1Font_wrap(name, glyphs, charstrings, subrs, properties) {
  42100. var cff = new CFF();
  42101. cff.header = new CFFHeader(1, 0, 4, 4);
  42102. cff.names = [name];
  42103. var topDict = new CFFTopDict();
  42104. // CFF strings IDs 0...390 are predefined names, so refering
  42105. // to entries in our own String INDEX starts at SID 391.
  42106. topDict.setByName('version', 391);
  42107. topDict.setByName('Notice', 392);
  42108. topDict.setByName('FullName', 393);
  42109. topDict.setByName('FamilyName', 394);
  42110. topDict.setByName('Weight', 395);
  42111. topDict.setByName('Encoding', null);
  42112. // placeholder
  42113. topDict.setByName('FontMatrix', properties.fontMatrix);
  42114. topDict.setByName('FontBBox', properties.bbox);
  42115. topDict.setByName('charset', null);
  42116. // placeholder
  42117. topDict.setByName('CharStrings', null);
  42118. // placeholder
  42119. topDict.setByName('Private', null);
  42120. // placeholder
  42121. cff.topDict = topDict;
  42122. var strings = new CFFStrings();
  42123. strings.add('Version 0.11');
  42124. // Version
  42125. strings.add('See original notice');
  42126. // Notice
  42127. strings.add(name);
  42128. // FullName
  42129. strings.add(name);
  42130. // FamilyName
  42131. strings.add('Medium');
  42132. // Weight
  42133. cff.strings = strings;
  42134. cff.globalSubrIndex = new CFFIndex();
  42135. var count = glyphs.length;
  42136. var charsetArray = [0];
  42137. var i, ii;
  42138. for (i = 0; i < count; i++) {
  42139. var index = CFFStandardStrings.indexOf(charstrings[i].glyphName);
  42140. // TODO: Insert the string and correctly map it. Previously it was
  42141. // thought mapping names that aren't in the standard strings to .notdef
  42142. // was fine, however in issue818 when mapping them all to .notdef the
  42143. // adieresis glyph no longer worked.
  42144. if (index === -1) {
  42145. index = 0;
  42146. }
  42147. charsetArray.push(index >> 8 & 0xff, index & 0xff);
  42148. }
  42149. cff.charset = new CFFCharset(false, 0, [], charsetArray);
  42150. var charStringsIndex = new CFFIndex();
  42151. charStringsIndex.add([
  42152. 0x8B,
  42153. 0x0E
  42154. ]);
  42155. // .notdef
  42156. for (i = 0; i < count; i++) {
  42157. var glyph = glyphs[i];
  42158. // If the CharString outline is empty, replace it with .notdef to
  42159. // prevent OTS from rejecting the font (fixes bug1252420.pdf).
  42160. if (glyph.length === 0) {
  42161. charStringsIndex.add([
  42162. 0x8B,
  42163. 0x0E
  42164. ]);
  42165. // .notdef
  42166. continue;
  42167. }
  42168. charStringsIndex.add(glyph);
  42169. }
  42170. cff.charStrings = charStringsIndex;
  42171. var privateDict = new CFFPrivateDict();
  42172. privateDict.setByName('Subrs', null);
  42173. // placeholder
  42174. var fields = [
  42175. 'BlueValues',
  42176. 'OtherBlues',
  42177. 'FamilyBlues',
  42178. 'FamilyOtherBlues',
  42179. 'StemSnapH',
  42180. 'StemSnapV',
  42181. 'BlueShift',
  42182. 'BlueFuzz',
  42183. 'BlueScale',
  42184. 'LanguageGroup',
  42185. 'ExpansionFactor',
  42186. 'ForceBold',
  42187. 'StdHW',
  42188. 'StdVW'
  42189. ];
  42190. for (i = 0, ii = fields.length; i < ii; i++) {
  42191. var field = fields[i];
  42192. if (!(field in properties.privateData)) {
  42193. continue;
  42194. }
  42195. var value = properties.privateData[field];
  42196. if (isArray(value)) {
  42197. // All of the private dictionary array data in CFF must be stored as
  42198. // "delta-encoded" numbers.
  42199. for (var j = value.length - 1; j > 0; j--) {
  42200. value[j] -= value[j - 1];
  42201. }
  42202. }
  42203. // ... difference from previous value
  42204. privateDict.setByName(field, value);
  42205. }
  42206. cff.topDict.privateDict = privateDict;
  42207. var subrIndex = new CFFIndex();
  42208. for (i = 0, ii = subrs.length; i < ii; i++) {
  42209. subrIndex.add(subrs[i]);
  42210. }
  42211. privateDict.subrsIndex = subrIndex;
  42212. var compiler = new CFFCompiler(cff);
  42213. return compiler.compile();
  42214. }
  42215. };
  42216. return Type1Font;
  42217. }();
  42218. var CFFFont = function CFFFontClosure() {
  42219. function CFFFont(file, properties) {
  42220. this.properties = properties;
  42221. var parser = new CFFParser(file, properties, SEAC_ANALYSIS_ENABLED);
  42222. this.cff = parser.parse();
  42223. var compiler = new CFFCompiler(this.cff);
  42224. this.seacs = this.cff.seacs;
  42225. try {
  42226. this.data = compiler.compile();
  42227. } catch (e) {
  42228. warn('Failed to compile font ' + properties.loadedName);
  42229. // There may have just been an issue with the compiler, set the data
  42230. // anyway and hope the font loaded.
  42231. this.data = file;
  42232. }
  42233. }
  42234. CFFFont.prototype = {
  42235. get numGlyphs() {
  42236. return this.cff.charStrings.count;
  42237. },
  42238. getCharset: function CFFFont_getCharset() {
  42239. return this.cff.charset.charset;
  42240. },
  42241. getGlyphMapping: function CFFFont_getGlyphMapping() {
  42242. var cff = this.cff;
  42243. var properties = this.properties;
  42244. var charsets = cff.charset.charset;
  42245. var charCodeToGlyphId;
  42246. var glyphId;
  42247. if (properties.composite) {
  42248. charCodeToGlyphId = Object.create(null);
  42249. if (cff.isCIDFont) {
  42250. // If the font is actually a CID font then we should use the charset
  42251. // to map CIDs to GIDs.
  42252. for (glyphId = 0; glyphId < charsets.length; glyphId++) {
  42253. var cid = charsets[glyphId];
  42254. var charCode = properties.cMap.charCodeOf(cid);
  42255. charCodeToGlyphId[charCode] = glyphId;
  42256. }
  42257. } else {
  42258. // If it is NOT actually a CID font then CIDs should be mapped
  42259. // directly to GIDs.
  42260. for (glyphId = 0; glyphId < cff.charStrings.count; glyphId++) {
  42261. charCodeToGlyphId[glyphId] = glyphId;
  42262. }
  42263. }
  42264. return charCodeToGlyphId;
  42265. }
  42266. var encoding = cff.encoding ? cff.encoding.encoding : null;
  42267. charCodeToGlyphId = type1FontGlyphMapping(properties, encoding, charsets);
  42268. return charCodeToGlyphId;
  42269. }
  42270. };
  42271. return CFFFont;
  42272. }();
  42273. // Workaround for seac on Windows.
  42274. (function checkSeacSupport() {
  42275. if (typeof navigator !== 'undefined' && /Windows/.test(navigator.userAgent)) {
  42276. SEAC_ANALYSIS_ENABLED = true;
  42277. }
  42278. }());
  42279. // Workaround for Private Use Area characters in Chrome on Windows
  42280. // http://code.google.com/p/chromium/issues/detail?id=122465
  42281. // https://github.com/mozilla/pdf.js/issues/1689
  42282. (function checkChromeWindows() {
  42283. if (typeof navigator !== 'undefined' && /Windows.*Chrome/.test(navigator.userAgent)) {
  42284. SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = true;
  42285. }
  42286. }());
  42287. exports.ErrorFont = ErrorFont;
  42288. exports.Font = Font;
  42289. exports.FontFlags = FontFlags;
  42290. exports.IdentityToUnicodeMap = IdentityToUnicodeMap;
  42291. exports.ToUnicodeMap = ToUnicodeMap;
  42292. exports.getFontType = getFontType;
  42293. }));
  42294. (function (root, factory) {
  42295. factory(root.pdfjsCorePsParser = {}, root.pdfjsSharedUtil, root.pdfjsCoreParser);
  42296. }(this, function (exports, sharedUtil, coreParser) {
  42297. var error = sharedUtil.error;
  42298. var isSpace = sharedUtil.isSpace;
  42299. var EOF = coreParser.EOF;
  42300. var PostScriptParser = function PostScriptParserClosure() {
  42301. function PostScriptParser(lexer) {
  42302. this.lexer = lexer;
  42303. this.operators = [];
  42304. this.token = null;
  42305. this.prev = null;
  42306. }
  42307. PostScriptParser.prototype = {
  42308. nextToken: function PostScriptParser_nextToken() {
  42309. this.prev = this.token;
  42310. this.token = this.lexer.getToken();
  42311. },
  42312. accept: function PostScriptParser_accept(type) {
  42313. if (this.token.type === type) {
  42314. this.nextToken();
  42315. return true;
  42316. }
  42317. return false;
  42318. },
  42319. expect: function PostScriptParser_expect(type) {
  42320. if (this.accept(type)) {
  42321. return true;
  42322. }
  42323. error('Unexpected symbol: found ' + this.token.type + ' expected ' + type + '.');
  42324. },
  42325. parse: function PostScriptParser_parse() {
  42326. this.nextToken();
  42327. this.expect(PostScriptTokenTypes.LBRACE);
  42328. this.parseBlock();
  42329. this.expect(PostScriptTokenTypes.RBRACE);
  42330. return this.operators;
  42331. },
  42332. parseBlock: function PostScriptParser_parseBlock() {
  42333. while (true) {
  42334. if (this.accept(PostScriptTokenTypes.NUMBER)) {
  42335. this.operators.push(this.prev.value);
  42336. } else if (this.accept(PostScriptTokenTypes.OPERATOR)) {
  42337. this.operators.push(this.prev.value);
  42338. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  42339. this.parseCondition();
  42340. } else {
  42341. return;
  42342. }
  42343. }
  42344. },
  42345. parseCondition: function PostScriptParser_parseCondition() {
  42346. // Add two place holders that will be updated later
  42347. var conditionLocation = this.operators.length;
  42348. this.operators.push(null, null);
  42349. this.parseBlock();
  42350. this.expect(PostScriptTokenTypes.RBRACE);
  42351. if (this.accept(PostScriptTokenTypes.IF)) {
  42352. // The true block is right after the 'if' so it just falls through on
  42353. // true else it jumps and skips the true block.
  42354. this.operators[conditionLocation] = this.operators.length;
  42355. this.operators[conditionLocation + 1] = 'jz';
  42356. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  42357. var jumpLocation = this.operators.length;
  42358. this.operators.push(null, null);
  42359. var endOfTrue = this.operators.length;
  42360. this.parseBlock();
  42361. this.expect(PostScriptTokenTypes.RBRACE);
  42362. this.expect(PostScriptTokenTypes.IFELSE);
  42363. // The jump is added at the end of the true block to skip the false
  42364. // block.
  42365. this.operators[jumpLocation] = this.operators.length;
  42366. this.operators[jumpLocation + 1] = 'j';
  42367. this.operators[conditionLocation] = endOfTrue;
  42368. this.operators[conditionLocation + 1] = 'jz';
  42369. } else {
  42370. error('PS Function: error parsing conditional.');
  42371. }
  42372. }
  42373. };
  42374. return PostScriptParser;
  42375. }();
  42376. var PostScriptTokenTypes = {
  42377. LBRACE: 0,
  42378. RBRACE: 1,
  42379. NUMBER: 2,
  42380. OPERATOR: 3,
  42381. IF: 4,
  42382. IFELSE: 5
  42383. };
  42384. var PostScriptToken = function PostScriptTokenClosure() {
  42385. function PostScriptToken(type, value) {
  42386. this.type = type;
  42387. this.value = value;
  42388. }
  42389. var opCache = Object.create(null);
  42390. PostScriptToken.getOperator = function PostScriptToken_getOperator(op) {
  42391. var opValue = opCache[op];
  42392. if (opValue) {
  42393. return opValue;
  42394. }
  42395. return opCache[op] = new PostScriptToken(PostScriptTokenTypes.OPERATOR, op);
  42396. };
  42397. PostScriptToken.LBRACE = new PostScriptToken(PostScriptTokenTypes.LBRACE, '{');
  42398. PostScriptToken.RBRACE = new PostScriptToken(PostScriptTokenTypes.RBRACE, '}');
  42399. PostScriptToken.IF = new PostScriptToken(PostScriptTokenTypes.IF, 'IF');
  42400. PostScriptToken.IFELSE = new PostScriptToken(PostScriptTokenTypes.IFELSE, 'IFELSE');
  42401. return PostScriptToken;
  42402. }();
  42403. var PostScriptLexer = function PostScriptLexerClosure() {
  42404. function PostScriptLexer(stream) {
  42405. this.stream = stream;
  42406. this.nextChar();
  42407. this.strBuf = [];
  42408. }
  42409. PostScriptLexer.prototype = {
  42410. nextChar: function PostScriptLexer_nextChar() {
  42411. return this.currentChar = this.stream.getByte();
  42412. },
  42413. getToken: function PostScriptLexer_getToken() {
  42414. var comment = false;
  42415. var ch = this.currentChar;
  42416. // skip comments
  42417. while (true) {
  42418. if (ch < 0) {
  42419. return EOF;
  42420. }
  42421. if (comment) {
  42422. if (ch === 0x0A || ch === 0x0D) {
  42423. comment = false;
  42424. }
  42425. } else if (ch === 0x25) {
  42426. // '%'
  42427. comment = true;
  42428. } else if (!isSpace(ch)) {
  42429. break;
  42430. }
  42431. ch = this.nextChar();
  42432. }
  42433. switch (ch | 0) {
  42434. case 0x30:
  42435. case 0x31:
  42436. case 0x32:
  42437. case 0x33:
  42438. case 0x34:
  42439. // '0'-'4'
  42440. case 0x35:
  42441. case 0x36:
  42442. case 0x37:
  42443. case 0x38:
  42444. case 0x39:
  42445. // '5'-'9'
  42446. case 0x2B:
  42447. case 0x2D:
  42448. case 0x2E:
  42449. // '+', '-', '.'
  42450. return new PostScriptToken(PostScriptTokenTypes.NUMBER, this.getNumber());
  42451. case 0x7B:
  42452. // '{'
  42453. this.nextChar();
  42454. return PostScriptToken.LBRACE;
  42455. case 0x7D:
  42456. // '}'
  42457. this.nextChar();
  42458. return PostScriptToken.RBRACE;
  42459. }
  42460. // operator
  42461. var strBuf = this.strBuf;
  42462. strBuf.length = 0;
  42463. strBuf[0] = String.fromCharCode(ch);
  42464. while ((ch = this.nextChar()) >= 0 && // and 'A'-'Z', 'a'-'z'
  42465. (ch >= 0x41 && ch <= 0x5A || ch >= 0x61 && ch <= 0x7A)) {
  42466. strBuf.push(String.fromCharCode(ch));
  42467. }
  42468. var str = strBuf.join('');
  42469. switch (str.toLowerCase()) {
  42470. case 'if':
  42471. return PostScriptToken.IF;
  42472. case 'ifelse':
  42473. return PostScriptToken.IFELSE;
  42474. default:
  42475. return PostScriptToken.getOperator(str);
  42476. }
  42477. },
  42478. getNumber: function PostScriptLexer_getNumber() {
  42479. var ch = this.currentChar;
  42480. var strBuf = this.strBuf;
  42481. strBuf.length = 0;
  42482. strBuf[0] = String.fromCharCode(ch);
  42483. while ((ch = this.nextChar()) >= 0) {
  42484. if (ch >= 0x30 && ch <= 0x39 || // '0'-'9'
  42485. ch === 0x2D || ch === 0x2E) {
  42486. // '-', '.'
  42487. strBuf.push(String.fromCharCode(ch));
  42488. } else {
  42489. break;
  42490. }
  42491. }
  42492. var value = parseFloat(strBuf.join(''));
  42493. if (isNaN(value)) {
  42494. error('Invalid floating point number: ' + value);
  42495. }
  42496. return value;
  42497. }
  42498. };
  42499. return PostScriptLexer;
  42500. }();
  42501. exports.PostScriptLexer = PostScriptLexer;
  42502. exports.PostScriptParser = PostScriptParser;
  42503. }));
  42504. (function (root, factory) {
  42505. factory(root.pdfjsCoreFunction = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCorePsParser);
  42506. }(this, function (exports, sharedUtil, corePrimitives, corePsParser) {
  42507. var error = sharedUtil.error;
  42508. var info = sharedUtil.info;
  42509. var isArray = sharedUtil.isArray;
  42510. var isBool = sharedUtil.isBool;
  42511. var isDict = corePrimitives.isDict;
  42512. var isStream = corePrimitives.isStream;
  42513. var PostScriptLexer = corePsParser.PostScriptLexer;
  42514. var PostScriptParser = corePsParser.PostScriptParser;
  42515. var PDFFunction = function PDFFunctionClosure() {
  42516. var CONSTRUCT_SAMPLED = 0;
  42517. var CONSTRUCT_INTERPOLATED = 2;
  42518. var CONSTRUCT_STICHED = 3;
  42519. var CONSTRUCT_POSTSCRIPT = 4;
  42520. return {
  42521. getSampleArray: function PDFFunction_getSampleArray(size, outputSize, bps, str) {
  42522. var i, ii;
  42523. var length = 1;
  42524. for (i = 0, ii = size.length; i < ii; i++) {
  42525. length *= size[i];
  42526. }
  42527. length *= outputSize;
  42528. var array = new Array(length);
  42529. var codeSize = 0;
  42530. var codeBuf = 0;
  42531. // 32 is a valid bps so shifting won't work
  42532. var sampleMul = 1.0 / (Math.pow(2.0, bps) - 1);
  42533. var strBytes = str.getBytes((length * bps + 7) / 8);
  42534. var strIdx = 0;
  42535. for (i = 0; i < length; i++) {
  42536. while (codeSize < bps) {
  42537. codeBuf <<= 8;
  42538. codeBuf |= strBytes[strIdx++];
  42539. codeSize += 8;
  42540. }
  42541. codeSize -= bps;
  42542. array[i] = (codeBuf >> codeSize) * sampleMul;
  42543. codeBuf &= (1 << codeSize) - 1;
  42544. }
  42545. return array;
  42546. },
  42547. getIR: function PDFFunction_getIR(xref, fn) {
  42548. var dict = fn.dict;
  42549. if (!dict) {
  42550. dict = fn;
  42551. }
  42552. var types = [
  42553. this.constructSampled,
  42554. null,
  42555. this.constructInterpolated,
  42556. this.constructStiched,
  42557. this.constructPostScript
  42558. ];
  42559. var typeNum = dict.get('FunctionType');
  42560. var typeFn = types[typeNum];
  42561. if (!typeFn) {
  42562. error('Unknown type of function');
  42563. }
  42564. return typeFn.call(this, fn, dict, xref);
  42565. },
  42566. fromIR: function PDFFunction_fromIR(IR) {
  42567. var type = IR[0];
  42568. switch (type) {
  42569. case CONSTRUCT_SAMPLED:
  42570. return this.constructSampledFromIR(IR);
  42571. case CONSTRUCT_INTERPOLATED:
  42572. return this.constructInterpolatedFromIR(IR);
  42573. case CONSTRUCT_STICHED:
  42574. return this.constructStichedFromIR(IR);
  42575. //case CONSTRUCT_POSTSCRIPT:
  42576. default:
  42577. return this.constructPostScriptFromIR(IR);
  42578. }
  42579. },
  42580. parse: function PDFFunction_parse(xref, fn) {
  42581. var IR = this.getIR(xref, fn);
  42582. return this.fromIR(IR);
  42583. },
  42584. parseArray: function PDFFunction_parseArray(xref, fnObj) {
  42585. if (!isArray(fnObj)) {
  42586. // not an array -- parsing as regular function
  42587. return this.parse(xref, fnObj);
  42588. }
  42589. var fnArray = [];
  42590. for (var j = 0, jj = fnObj.length; j < jj; j++) {
  42591. var obj = xref.fetchIfRef(fnObj[j]);
  42592. fnArray.push(PDFFunction.parse(xref, obj));
  42593. }
  42594. return function (src, srcOffset, dest, destOffset) {
  42595. for (var i = 0, ii = fnArray.length; i < ii; i++) {
  42596. fnArray[i](src, srcOffset, dest, destOffset + i);
  42597. }
  42598. };
  42599. },
  42600. constructSampled: function PDFFunction_constructSampled(str, dict) {
  42601. function toMultiArray(arr) {
  42602. var inputLength = arr.length;
  42603. var out = [];
  42604. var index = 0;
  42605. for (var i = 0; i < inputLength; i += 2) {
  42606. out[index] = [
  42607. arr[i],
  42608. arr[i + 1]
  42609. ];
  42610. ++index;
  42611. }
  42612. return out;
  42613. }
  42614. var domain = dict.getArray('Domain');
  42615. var range = dict.getArray('Range');
  42616. if (!domain || !range) {
  42617. error('No domain or range');
  42618. }
  42619. var inputSize = domain.length / 2;
  42620. var outputSize = range.length / 2;
  42621. domain = toMultiArray(domain);
  42622. range = toMultiArray(range);
  42623. var size = dict.get('Size');
  42624. var bps = dict.get('BitsPerSample');
  42625. var order = dict.get('Order') || 1;
  42626. if (order !== 1) {
  42627. // No description how cubic spline interpolation works in PDF32000:2008
  42628. // As in poppler, ignoring order, linear interpolation may work as good
  42629. info('No support for cubic spline interpolation: ' + order);
  42630. }
  42631. var encode = dict.getArray('Encode');
  42632. if (!encode) {
  42633. encode = [];
  42634. for (var i = 0; i < inputSize; ++i) {
  42635. encode.push(0);
  42636. encode.push(size[i] - 1);
  42637. }
  42638. }
  42639. encode = toMultiArray(encode);
  42640. var decode = dict.getArray('Decode');
  42641. if (!decode) {
  42642. decode = range;
  42643. } else {
  42644. decode = toMultiArray(decode);
  42645. }
  42646. var samples = this.getSampleArray(size, outputSize, bps, str);
  42647. return [
  42648. CONSTRUCT_SAMPLED,
  42649. inputSize,
  42650. domain,
  42651. encode,
  42652. decode,
  42653. samples,
  42654. size,
  42655. outputSize,
  42656. Math.pow(2, bps) - 1,
  42657. range
  42658. ];
  42659. },
  42660. constructSampledFromIR: function PDFFunction_constructSampledFromIR(IR) {
  42661. // See chapter 3, page 109 of the PDF reference
  42662. function interpolate(x, xmin, xmax, ymin, ymax) {
  42663. return ymin + (x - xmin) * ((ymax - ymin) / (xmax - xmin));
  42664. }
  42665. return function constructSampledFromIRResult(src, srcOffset, dest, destOffset) {
  42666. // See chapter 3, page 110 of the PDF reference.
  42667. var m = IR[1];
  42668. var domain = IR[2];
  42669. var encode = IR[3];
  42670. var decode = IR[4];
  42671. var samples = IR[5];
  42672. var size = IR[6];
  42673. var n = IR[7];
  42674. //var mask = IR[8];
  42675. var range = IR[9];
  42676. // Building the cube vertices: its part and sample index
  42677. // http://rjwagner49.com/Mathematics/Interpolation.pdf
  42678. var cubeVertices = 1 << m;
  42679. var cubeN = new Float64Array(cubeVertices);
  42680. var cubeVertex = new Uint32Array(cubeVertices);
  42681. var i, j;
  42682. for (j = 0; j < cubeVertices; j++) {
  42683. cubeN[j] = 1;
  42684. }
  42685. var k = n, pos = 1;
  42686. // Map x_i to y_j for 0 <= i < m using the sampled function.
  42687. for (i = 0; i < m; ++i) {
  42688. // x_i' = min(max(x_i, Domain_2i), Domain_2i+1)
  42689. var domain_2i = domain[i][0];
  42690. var domain_2i_1 = domain[i][1];
  42691. var xi = Math.min(Math.max(src[srcOffset + i], domain_2i), domain_2i_1);
  42692. // e_i = Interpolate(x_i', Domain_2i, Domain_2i+1,
  42693. // Encode_2i, Encode_2i+1)
  42694. var e = interpolate(xi, domain_2i, domain_2i_1, encode[i][0], encode[i][1]);
  42695. // e_i' = min(max(e_i, 0), Size_i - 1)
  42696. var size_i = size[i];
  42697. e = Math.min(Math.max(e, 0), size_i - 1);
  42698. // Adjusting the cube: N and vertex sample index
  42699. var e0 = e < size_i - 1 ? Math.floor(e) : e - 1;
  42700. // e1 = e0 + 1;
  42701. var n0 = e0 + 1 - e;
  42702. // (e1 - e) / (e1 - e0);
  42703. var n1 = e - e0;
  42704. // (e - e0) / (e1 - e0);
  42705. var offset0 = e0 * k;
  42706. var offset1 = offset0 + k;
  42707. // e1 * k
  42708. for (j = 0; j < cubeVertices; j++) {
  42709. if (j & pos) {
  42710. cubeN[j] *= n1;
  42711. cubeVertex[j] += offset1;
  42712. } else {
  42713. cubeN[j] *= n0;
  42714. cubeVertex[j] += offset0;
  42715. }
  42716. }
  42717. k *= size_i;
  42718. pos <<= 1;
  42719. }
  42720. for (j = 0; j < n; ++j) {
  42721. // Sum all cube vertices' samples portions
  42722. var rj = 0;
  42723. for (i = 0; i < cubeVertices; i++) {
  42724. rj += samples[cubeVertex[i] + j] * cubeN[i];
  42725. }
  42726. // r_j' = Interpolate(r_j, 0, 2^BitsPerSample - 1,
  42727. // Decode_2j, Decode_2j+1)
  42728. rj = interpolate(rj, 0, 1, decode[j][0], decode[j][1]);
  42729. // y_j = min(max(r_j, range_2j), range_2j+1)
  42730. dest[destOffset + j] = Math.min(Math.max(rj, range[j][0]), range[j][1]);
  42731. }
  42732. };
  42733. },
  42734. constructInterpolated: function PDFFunction_constructInterpolated(str, dict) {
  42735. var c0 = dict.getArray('C0') || [0];
  42736. var c1 = dict.getArray('C1') || [1];
  42737. var n = dict.get('N');
  42738. if (!isArray(c0) || !isArray(c1)) {
  42739. error('Illegal dictionary for interpolated function');
  42740. }
  42741. var length = c0.length;
  42742. var diff = [];
  42743. for (var i = 0; i < length; ++i) {
  42744. diff.push(c1[i] - c0[i]);
  42745. }
  42746. return [
  42747. CONSTRUCT_INTERPOLATED,
  42748. c0,
  42749. diff,
  42750. n
  42751. ];
  42752. },
  42753. constructInterpolatedFromIR: function PDFFunction_constructInterpolatedFromIR(IR) {
  42754. var c0 = IR[1];
  42755. var diff = IR[2];
  42756. var n = IR[3];
  42757. var length = diff.length;
  42758. return function constructInterpolatedFromIRResult(src, srcOffset, dest, destOffset) {
  42759. var x = n === 1 ? src[srcOffset] : Math.pow(src[srcOffset], n);
  42760. for (var j = 0; j < length; ++j) {
  42761. dest[destOffset + j] = c0[j] + x * diff[j];
  42762. }
  42763. };
  42764. },
  42765. constructStiched: function PDFFunction_constructStiched(fn, dict, xref) {
  42766. var domain = dict.getArray('Domain');
  42767. if (!domain) {
  42768. error('No domain');
  42769. }
  42770. var inputSize = domain.length / 2;
  42771. if (inputSize !== 1) {
  42772. error('Bad domain for stiched function');
  42773. }
  42774. var fnRefs = dict.get('Functions');
  42775. var fns = [];
  42776. for (var i = 0, ii = fnRefs.length; i < ii; ++i) {
  42777. fns.push(PDFFunction.getIR(xref, xref.fetchIfRef(fnRefs[i])));
  42778. }
  42779. var bounds = dict.getArray('Bounds');
  42780. var encode = dict.getArray('Encode');
  42781. return [
  42782. CONSTRUCT_STICHED,
  42783. domain,
  42784. bounds,
  42785. encode,
  42786. fns
  42787. ];
  42788. },
  42789. constructStichedFromIR: function PDFFunction_constructStichedFromIR(IR) {
  42790. var domain = IR[1];
  42791. var bounds = IR[2];
  42792. var encode = IR[3];
  42793. var fnsIR = IR[4];
  42794. var fns = [];
  42795. var tmpBuf = new Float32Array(1);
  42796. for (var i = 0, ii = fnsIR.length; i < ii; i++) {
  42797. fns.push(PDFFunction.fromIR(fnsIR[i]));
  42798. }
  42799. return function constructStichedFromIRResult(src, srcOffset, dest, destOffset) {
  42800. var clip = function constructStichedFromIRClip(v, min, max) {
  42801. if (v > max) {
  42802. v = max;
  42803. } else if (v < min) {
  42804. v = min;
  42805. }
  42806. return v;
  42807. };
  42808. // clip to domain
  42809. var v = clip(src[srcOffset], domain[0], domain[1]);
  42810. // calculate which bound the value is in
  42811. for (var i = 0, ii = bounds.length; i < ii; ++i) {
  42812. if (v < bounds[i]) {
  42813. break;
  42814. }
  42815. }
  42816. // encode value into domain of function
  42817. var dmin = domain[0];
  42818. if (i > 0) {
  42819. dmin = bounds[i - 1];
  42820. }
  42821. var dmax = domain[1];
  42822. if (i < bounds.length) {
  42823. dmax = bounds[i];
  42824. }
  42825. var rmin = encode[2 * i];
  42826. var rmax = encode[2 * i + 1];
  42827. // Prevent the value from becoming NaN as a result
  42828. // of division by zero (fixes issue6113.pdf).
  42829. tmpBuf[0] = dmin === dmax ? rmin : rmin + (v - dmin) * (rmax - rmin) / (dmax - dmin);
  42830. // call the appropriate function
  42831. fns[i](tmpBuf, 0, dest, destOffset);
  42832. };
  42833. },
  42834. constructPostScript: function PDFFunction_constructPostScript(fn, dict, xref) {
  42835. var domain = dict.getArray('Domain');
  42836. var range = dict.getArray('Range');
  42837. if (!domain) {
  42838. error('No domain.');
  42839. }
  42840. if (!range) {
  42841. error('No range.');
  42842. }
  42843. var lexer = new PostScriptLexer(fn);
  42844. var parser = new PostScriptParser(lexer);
  42845. var code = parser.parse();
  42846. return [
  42847. CONSTRUCT_POSTSCRIPT,
  42848. domain,
  42849. range,
  42850. code
  42851. ];
  42852. },
  42853. constructPostScriptFromIR: function PDFFunction_constructPostScriptFromIR(IR) {
  42854. var domain = IR[1];
  42855. var range = IR[2];
  42856. var code = IR[3];
  42857. var compiled = new PostScriptCompiler().compile(code, domain, range);
  42858. if (compiled) {
  42859. // Compiled function consists of simple expressions such as addition,
  42860. // subtraction, Math.max, and also contains 'var' and 'return'
  42861. // statements. See the generation in the PostScriptCompiler below.
  42862. return new Function('src', 'srcOffset', 'dest', 'destOffset', compiled);
  42863. }
  42864. info('Unable to compile PS function');
  42865. var numOutputs = range.length >> 1;
  42866. var numInputs = domain.length >> 1;
  42867. var evaluator = new PostScriptEvaluator(code);
  42868. // Cache the values for a big speed up, the cache size is limited though
  42869. // since the number of possible values can be huge from a PS function.
  42870. var cache = Object.create(null);
  42871. // The MAX_CACHE_SIZE is set to ~4x the maximum number of distinct values
  42872. // seen in our tests.
  42873. var MAX_CACHE_SIZE = 2048 * 4;
  42874. var cache_available = MAX_CACHE_SIZE;
  42875. var tmpBuf = new Float32Array(numInputs);
  42876. return function constructPostScriptFromIRResult(src, srcOffset, dest, destOffset) {
  42877. var i, value;
  42878. var key = '';
  42879. var input = tmpBuf;
  42880. for (i = 0; i < numInputs; i++) {
  42881. value = src[srcOffset + i];
  42882. input[i] = value;
  42883. key += value + '_';
  42884. }
  42885. var cachedValue = cache[key];
  42886. if (cachedValue !== undefined) {
  42887. dest.set(cachedValue, destOffset);
  42888. return;
  42889. }
  42890. var output = new Float32Array(numOutputs);
  42891. var stack = evaluator.execute(input);
  42892. var stackIndex = stack.length - numOutputs;
  42893. for (i = 0; i < numOutputs; i++) {
  42894. value = stack[stackIndex + i];
  42895. var bound = range[i * 2];
  42896. if (value < bound) {
  42897. value = bound;
  42898. } else {
  42899. bound = range[i * 2 + 1];
  42900. if (value > bound) {
  42901. value = bound;
  42902. }
  42903. }
  42904. output[i] = value;
  42905. }
  42906. if (cache_available > 0) {
  42907. cache_available--;
  42908. cache[key] = output;
  42909. }
  42910. dest.set(output, destOffset);
  42911. };
  42912. }
  42913. };
  42914. }();
  42915. function isPDFFunction(v) {
  42916. var fnDict;
  42917. if (typeof v !== 'object') {
  42918. return false;
  42919. } else if (isDict(v)) {
  42920. fnDict = v;
  42921. } else if (isStream(v)) {
  42922. fnDict = v.dict;
  42923. } else {
  42924. return false;
  42925. }
  42926. return fnDict.has('FunctionType');
  42927. }
  42928. var PostScriptStack = function PostScriptStackClosure() {
  42929. var MAX_STACK_SIZE = 100;
  42930. function PostScriptStack(initialStack) {
  42931. this.stack = !initialStack ? [] : Array.prototype.slice.call(initialStack, 0);
  42932. }
  42933. PostScriptStack.prototype = {
  42934. push: function PostScriptStack_push(value) {
  42935. if (this.stack.length >= MAX_STACK_SIZE) {
  42936. error('PostScript function stack overflow.');
  42937. }
  42938. this.stack.push(value);
  42939. },
  42940. pop: function PostScriptStack_pop() {
  42941. if (this.stack.length <= 0) {
  42942. error('PostScript function stack underflow.');
  42943. }
  42944. return this.stack.pop();
  42945. },
  42946. copy: function PostScriptStack_copy(n) {
  42947. if (this.stack.length + n >= MAX_STACK_SIZE) {
  42948. error('PostScript function stack overflow.');
  42949. }
  42950. var stack = this.stack;
  42951. for (var i = stack.length - n, j = n - 1; j >= 0; j--, i++) {
  42952. stack.push(stack[i]);
  42953. }
  42954. },
  42955. index: function PostScriptStack_index(n) {
  42956. this.push(this.stack[this.stack.length - n - 1]);
  42957. },
  42958. // rotate the last n stack elements p times
  42959. roll: function PostScriptStack_roll(n, p) {
  42960. var stack = this.stack;
  42961. var l = stack.length - n;
  42962. var r = stack.length - 1, c = l + (p - Math.floor(p / n) * n), i, j, t;
  42963. for (i = l, j = r; i < j; i++, j--) {
  42964. t = stack[i];
  42965. stack[i] = stack[j];
  42966. stack[j] = t;
  42967. }
  42968. for (i = l, j = c - 1; i < j; i++, j--) {
  42969. t = stack[i];
  42970. stack[i] = stack[j];
  42971. stack[j] = t;
  42972. }
  42973. for (i = c, j = r; i < j; i++, j--) {
  42974. t = stack[i];
  42975. stack[i] = stack[j];
  42976. stack[j] = t;
  42977. }
  42978. }
  42979. };
  42980. return PostScriptStack;
  42981. }();
  42982. var PostScriptEvaluator = function PostScriptEvaluatorClosure() {
  42983. function PostScriptEvaluator(operators) {
  42984. this.operators = operators;
  42985. }
  42986. PostScriptEvaluator.prototype = {
  42987. execute: function PostScriptEvaluator_execute(initialStack) {
  42988. var stack = new PostScriptStack(initialStack);
  42989. var counter = 0;
  42990. var operators = this.operators;
  42991. var length = operators.length;
  42992. var operator, a, b;
  42993. while (counter < length) {
  42994. operator = operators[counter++];
  42995. if (typeof operator === 'number') {
  42996. // Operator is really an operand and should be pushed to the stack.
  42997. stack.push(operator);
  42998. continue;
  42999. }
  43000. switch (operator) {
  43001. // non standard ps operators
  43002. case 'jz':
  43003. // jump if false
  43004. b = stack.pop();
  43005. a = stack.pop();
  43006. if (!a) {
  43007. counter = b;
  43008. }
  43009. break;
  43010. case 'j':
  43011. // jump
  43012. a = stack.pop();
  43013. counter = a;
  43014. break;
  43015. // all ps operators in alphabetical order (excluding if/ifelse)
  43016. case 'abs':
  43017. a = stack.pop();
  43018. stack.push(Math.abs(a));
  43019. break;
  43020. case 'add':
  43021. b = stack.pop();
  43022. a = stack.pop();
  43023. stack.push(a + b);
  43024. break;
  43025. case 'and':
  43026. b = stack.pop();
  43027. a = stack.pop();
  43028. if (isBool(a) && isBool(b)) {
  43029. stack.push(a && b);
  43030. } else {
  43031. stack.push(a & b);
  43032. }
  43033. break;
  43034. case 'atan':
  43035. a = stack.pop();
  43036. stack.push(Math.atan(a));
  43037. break;
  43038. case 'bitshift':
  43039. b = stack.pop();
  43040. a = stack.pop();
  43041. if (a > 0) {
  43042. stack.push(a << b);
  43043. } else {
  43044. stack.push(a >> b);
  43045. }
  43046. break;
  43047. case 'ceiling':
  43048. a = stack.pop();
  43049. stack.push(Math.ceil(a));
  43050. break;
  43051. case 'copy':
  43052. a = stack.pop();
  43053. stack.copy(a);
  43054. break;
  43055. case 'cos':
  43056. a = stack.pop();
  43057. stack.push(Math.cos(a));
  43058. break;
  43059. case 'cvi':
  43060. a = stack.pop() | 0;
  43061. stack.push(a);
  43062. break;
  43063. case 'cvr':
  43064. // noop
  43065. break;
  43066. case 'div':
  43067. b = stack.pop();
  43068. a = stack.pop();
  43069. stack.push(a / b);
  43070. break;
  43071. case 'dup':
  43072. stack.copy(1);
  43073. break;
  43074. case 'eq':
  43075. b = stack.pop();
  43076. a = stack.pop();
  43077. stack.push(a === b);
  43078. break;
  43079. case 'exch':
  43080. stack.roll(2, 1);
  43081. break;
  43082. case 'exp':
  43083. b = stack.pop();
  43084. a = stack.pop();
  43085. stack.push(Math.pow(a, b));
  43086. break;
  43087. case 'false':
  43088. stack.push(false);
  43089. break;
  43090. case 'floor':
  43091. a = stack.pop();
  43092. stack.push(Math.floor(a));
  43093. break;
  43094. case 'ge':
  43095. b = stack.pop();
  43096. a = stack.pop();
  43097. stack.push(a >= b);
  43098. break;
  43099. case 'gt':
  43100. b = stack.pop();
  43101. a = stack.pop();
  43102. stack.push(a > b);
  43103. break;
  43104. case 'idiv':
  43105. b = stack.pop();
  43106. a = stack.pop();
  43107. stack.push(a / b | 0);
  43108. break;
  43109. case 'index':
  43110. a = stack.pop();
  43111. stack.index(a);
  43112. break;
  43113. case 'le':
  43114. b = stack.pop();
  43115. a = stack.pop();
  43116. stack.push(a <= b);
  43117. break;
  43118. case 'ln':
  43119. a = stack.pop();
  43120. stack.push(Math.log(a));
  43121. break;
  43122. case 'log':
  43123. a = stack.pop();
  43124. stack.push(Math.log(a) / Math.LN10);
  43125. break;
  43126. case 'lt':
  43127. b = stack.pop();
  43128. a = stack.pop();
  43129. stack.push(a < b);
  43130. break;
  43131. case 'mod':
  43132. b = stack.pop();
  43133. a = stack.pop();
  43134. stack.push(a % b);
  43135. break;
  43136. case 'mul':
  43137. b = stack.pop();
  43138. a = stack.pop();
  43139. stack.push(a * b);
  43140. break;
  43141. case 'ne':
  43142. b = stack.pop();
  43143. a = stack.pop();
  43144. stack.push(a !== b);
  43145. break;
  43146. case 'neg':
  43147. a = stack.pop();
  43148. stack.push(-a);
  43149. break;
  43150. case 'not':
  43151. a = stack.pop();
  43152. if (isBool(a)) {
  43153. stack.push(!a);
  43154. } else {
  43155. stack.push(~a);
  43156. }
  43157. break;
  43158. case 'or':
  43159. b = stack.pop();
  43160. a = stack.pop();
  43161. if (isBool(a) && isBool(b)) {
  43162. stack.push(a || b);
  43163. } else {
  43164. stack.push(a | b);
  43165. }
  43166. break;
  43167. case 'pop':
  43168. stack.pop();
  43169. break;
  43170. case 'roll':
  43171. b = stack.pop();
  43172. a = stack.pop();
  43173. stack.roll(a, b);
  43174. break;
  43175. case 'round':
  43176. a = stack.pop();
  43177. stack.push(Math.round(a));
  43178. break;
  43179. case 'sin':
  43180. a = stack.pop();
  43181. stack.push(Math.sin(a));
  43182. break;
  43183. case 'sqrt':
  43184. a = stack.pop();
  43185. stack.push(Math.sqrt(a));
  43186. break;
  43187. case 'sub':
  43188. b = stack.pop();
  43189. a = stack.pop();
  43190. stack.push(a - b);
  43191. break;
  43192. case 'true':
  43193. stack.push(true);
  43194. break;
  43195. case 'truncate':
  43196. a = stack.pop();
  43197. a = a < 0 ? Math.ceil(a) : Math.floor(a);
  43198. stack.push(a);
  43199. break;
  43200. case 'xor':
  43201. b = stack.pop();
  43202. a = stack.pop();
  43203. if (isBool(a) && isBool(b)) {
  43204. stack.push(a !== b);
  43205. } else {
  43206. stack.push(a ^ b);
  43207. }
  43208. break;
  43209. default:
  43210. error('Unknown operator ' + operator);
  43211. break;
  43212. }
  43213. }
  43214. return stack.stack;
  43215. }
  43216. };
  43217. return PostScriptEvaluator;
  43218. }();
  43219. // Most of the PDFs functions consist of simple operations such as:
  43220. // roll, exch, sub, cvr, pop, index, dup, mul, if, gt, add.
  43221. //
  43222. // We can compile most of such programs, and at the same moment, we can
  43223. // optimize some expressions using basic math properties. Keeping track of
  43224. // min/max values will allow us to avoid extra Math.min/Math.max calls.
  43225. var PostScriptCompiler = function PostScriptCompilerClosure() {
  43226. function AstNode(type) {
  43227. this.type = type;
  43228. }
  43229. AstNode.prototype.visit = function (visitor) {
  43230. throw new Error('abstract method');
  43231. };
  43232. function AstArgument(index, min, max) {
  43233. AstNode.call(this, 'args');
  43234. this.index = index;
  43235. this.min = min;
  43236. this.max = max;
  43237. }
  43238. AstArgument.prototype = Object.create(AstNode.prototype);
  43239. AstArgument.prototype.visit = function (visitor) {
  43240. visitor.visitArgument(this);
  43241. };
  43242. function AstLiteral(number) {
  43243. AstNode.call(this, 'literal');
  43244. this.number = number;
  43245. this.min = number;
  43246. this.max = number;
  43247. }
  43248. AstLiteral.prototype = Object.create(AstNode.prototype);
  43249. AstLiteral.prototype.visit = function (visitor) {
  43250. visitor.visitLiteral(this);
  43251. };
  43252. function AstBinaryOperation(op, arg1, arg2, min, max) {
  43253. AstNode.call(this, 'binary');
  43254. this.op = op;
  43255. this.arg1 = arg1;
  43256. this.arg2 = arg2;
  43257. this.min = min;
  43258. this.max = max;
  43259. }
  43260. AstBinaryOperation.prototype = Object.create(AstNode.prototype);
  43261. AstBinaryOperation.prototype.visit = function (visitor) {
  43262. visitor.visitBinaryOperation(this);
  43263. };
  43264. function AstMin(arg, max) {
  43265. AstNode.call(this, 'max');
  43266. this.arg = arg;
  43267. this.min = arg.min;
  43268. this.max = max;
  43269. }
  43270. AstMin.prototype = Object.create(AstNode.prototype);
  43271. AstMin.prototype.visit = function (visitor) {
  43272. visitor.visitMin(this);
  43273. };
  43274. function AstVariable(index, min, max) {
  43275. AstNode.call(this, 'var');
  43276. this.index = index;
  43277. this.min = min;
  43278. this.max = max;
  43279. }
  43280. AstVariable.prototype = Object.create(AstNode.prototype);
  43281. AstVariable.prototype.visit = function (visitor) {
  43282. visitor.visitVariable(this);
  43283. };
  43284. function AstVariableDefinition(variable, arg) {
  43285. AstNode.call(this, 'definition');
  43286. this.variable = variable;
  43287. this.arg = arg;
  43288. }
  43289. AstVariableDefinition.prototype = Object.create(AstNode.prototype);
  43290. AstVariableDefinition.prototype.visit = function (visitor) {
  43291. visitor.visitVariableDefinition(this);
  43292. };
  43293. function ExpressionBuilderVisitor() {
  43294. this.parts = [];
  43295. }
  43296. ExpressionBuilderVisitor.prototype = {
  43297. visitArgument: function (arg) {
  43298. this.parts.push('Math.max(', arg.min, ', Math.min(', arg.max, ', src[srcOffset + ', arg.index, ']))');
  43299. },
  43300. visitVariable: function (variable) {
  43301. this.parts.push('v', variable.index);
  43302. },
  43303. visitLiteral: function (literal) {
  43304. this.parts.push(literal.number);
  43305. },
  43306. visitBinaryOperation: function (operation) {
  43307. this.parts.push('(');
  43308. operation.arg1.visit(this);
  43309. this.parts.push(' ', operation.op, ' ');
  43310. operation.arg2.visit(this);
  43311. this.parts.push(')');
  43312. },
  43313. visitVariableDefinition: function (definition) {
  43314. this.parts.push('var ');
  43315. definition.variable.visit(this);
  43316. this.parts.push(' = ');
  43317. definition.arg.visit(this);
  43318. this.parts.push(';');
  43319. },
  43320. visitMin: function (max) {
  43321. this.parts.push('Math.min(');
  43322. max.arg.visit(this);
  43323. this.parts.push(', ', max.max, ')');
  43324. },
  43325. toString: function () {
  43326. return this.parts.join('');
  43327. }
  43328. };
  43329. function buildAddOperation(num1, num2) {
  43330. if (num2.type === 'literal' && num2.number === 0) {
  43331. // optimization: second operand is 0
  43332. return num1;
  43333. }
  43334. if (num1.type === 'literal' && num1.number === 0) {
  43335. // optimization: first operand is 0
  43336. return num2;
  43337. }
  43338. if (num2.type === 'literal' && num1.type === 'literal') {
  43339. // optimization: operands operand are literals
  43340. return new AstLiteral(num1.number + num2.number);
  43341. }
  43342. return new AstBinaryOperation('+', num1, num2, num1.min + num2.min, num1.max + num2.max);
  43343. }
  43344. function buildMulOperation(num1, num2) {
  43345. if (num2.type === 'literal') {
  43346. // optimization: second operands is a literal...
  43347. if (num2.number === 0) {
  43348. return new AstLiteral(0);
  43349. } else // and it's 0
  43350. if (num2.number === 1) {
  43351. return num1;
  43352. } else // and it's 1
  43353. if (num1.type === 'literal') {
  43354. // ... and first operands is a literal too
  43355. return new AstLiteral(num1.number * num2.number);
  43356. }
  43357. }
  43358. if (num1.type === 'literal') {
  43359. // optimization: first operands is a literal...
  43360. if (num1.number === 0) {
  43361. return new AstLiteral(0);
  43362. } else // and it's 0
  43363. if (num1.number === 1) {
  43364. return num2;
  43365. }
  43366. }
  43367. // and it's 1
  43368. var min = Math.min(num1.min * num2.min, num1.min * num2.max, num1.max * num2.min, num1.max * num2.max);
  43369. var max = Math.max(num1.min * num2.min, num1.min * num2.max, num1.max * num2.min, num1.max * num2.max);
  43370. return new AstBinaryOperation('*', num1, num2, min, max);
  43371. }
  43372. function buildSubOperation(num1, num2) {
  43373. if (num2.type === 'literal') {
  43374. // optimization: second operands is a literal...
  43375. if (num2.number === 0) {
  43376. return num1;
  43377. } else // ... and it's 0
  43378. if (num1.type === 'literal') {
  43379. // ... and first operands is a literal too
  43380. return new AstLiteral(num1.number - num2.number);
  43381. }
  43382. }
  43383. if (num2.type === 'binary' && num2.op === '-' && num1.type === 'literal' && num1.number === 1 && num2.arg1.type === 'literal' && num2.arg1.number === 1) {
  43384. // optimization for case: 1 - (1 - x)
  43385. return num2.arg2;
  43386. }
  43387. return new AstBinaryOperation('-', num1, num2, num1.min - num2.max, num1.max - num2.min);
  43388. }
  43389. function buildMinOperation(num1, max) {
  43390. if (num1.min >= max) {
  43391. // optimization: num1 min value is not less than required max
  43392. return new AstLiteral(max);
  43393. } else // just returning max
  43394. if (num1.max <= max) {
  43395. // optimization: num1 max value is not greater than required max
  43396. return num1;
  43397. }
  43398. // just returning an argument
  43399. return new AstMin(num1, max);
  43400. }
  43401. function PostScriptCompiler() {
  43402. }
  43403. PostScriptCompiler.prototype = {
  43404. compile: function PostScriptCompiler_compile(code, domain, range) {
  43405. var stack = [];
  43406. var i, ii;
  43407. var instructions = [];
  43408. var inputSize = domain.length >> 1, outputSize = range.length >> 1;
  43409. var lastRegister = 0;
  43410. var n, j;
  43411. var num1, num2, ast1, ast2, tmpVar, item;
  43412. for (i = 0; i < inputSize; i++) {
  43413. stack.push(new AstArgument(i, domain[i * 2], domain[i * 2 + 1]));
  43414. }
  43415. for (i = 0, ii = code.length; i < ii; i++) {
  43416. item = code[i];
  43417. if (typeof item === 'number') {
  43418. stack.push(new AstLiteral(item));
  43419. continue;
  43420. }
  43421. switch (item) {
  43422. case 'add':
  43423. if (stack.length < 2) {
  43424. return null;
  43425. }
  43426. num2 = stack.pop();
  43427. num1 = stack.pop();
  43428. stack.push(buildAddOperation(num1, num2));
  43429. break;
  43430. case 'cvr':
  43431. if (stack.length < 1) {
  43432. return null;
  43433. }
  43434. break;
  43435. case 'mul':
  43436. if (stack.length < 2) {
  43437. return null;
  43438. }
  43439. num2 = stack.pop();
  43440. num1 = stack.pop();
  43441. stack.push(buildMulOperation(num1, num2));
  43442. break;
  43443. case 'sub':
  43444. if (stack.length < 2) {
  43445. return null;
  43446. }
  43447. num2 = stack.pop();
  43448. num1 = stack.pop();
  43449. stack.push(buildSubOperation(num1, num2));
  43450. break;
  43451. case 'exch':
  43452. if (stack.length < 2) {
  43453. return null;
  43454. }
  43455. ast1 = stack.pop();
  43456. ast2 = stack.pop();
  43457. stack.push(ast1, ast2);
  43458. break;
  43459. case 'pop':
  43460. if (stack.length < 1) {
  43461. return null;
  43462. }
  43463. stack.pop();
  43464. break;
  43465. case 'index':
  43466. if (stack.length < 1) {
  43467. return null;
  43468. }
  43469. num1 = stack.pop();
  43470. if (num1.type !== 'literal') {
  43471. return null;
  43472. }
  43473. n = num1.number;
  43474. if (n < 0 || (n | 0) !== n || stack.length < n) {
  43475. return null;
  43476. }
  43477. ast1 = stack[stack.length - n - 1];
  43478. if (ast1.type === 'literal' || ast1.type === 'var') {
  43479. stack.push(ast1);
  43480. break;
  43481. }
  43482. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  43483. stack[stack.length - n - 1] = tmpVar;
  43484. stack.push(tmpVar);
  43485. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  43486. break;
  43487. case 'dup':
  43488. if (stack.length < 1) {
  43489. return null;
  43490. }
  43491. if (typeof code[i + 1] === 'number' && code[i + 2] === 'gt' && code[i + 3] === i + 7 && code[i + 4] === 'jz' && code[i + 5] === 'pop' && code[i + 6] === code[i + 1]) {
  43492. // special case of the commands sequence for the min operation
  43493. num1 = stack.pop();
  43494. stack.push(buildMinOperation(num1, code[i + 1]));
  43495. i += 6;
  43496. break;
  43497. }
  43498. ast1 = stack[stack.length - 1];
  43499. if (ast1.type === 'literal' || ast1.type === 'var') {
  43500. // we don't have to save into intermediate variable a literal or
  43501. // variable.
  43502. stack.push(ast1);
  43503. break;
  43504. }
  43505. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  43506. stack[stack.length - 1] = tmpVar;
  43507. stack.push(tmpVar);
  43508. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  43509. break;
  43510. case 'roll':
  43511. if (stack.length < 2) {
  43512. return null;
  43513. }
  43514. num2 = stack.pop();
  43515. num1 = stack.pop();
  43516. if (num2.type !== 'literal' || num1.type !== 'literal') {
  43517. // both roll operands must be numbers
  43518. return null;
  43519. }
  43520. j = num2.number;
  43521. n = num1.number;
  43522. if (n <= 0 || (n | 0) !== n || (j | 0) !== j || stack.length < n) {
  43523. // ... and integers
  43524. return null;
  43525. }
  43526. j = (j % n + n) % n;
  43527. if (j === 0) {
  43528. break;
  43529. }
  43530. // just skipping -- there are nothing to rotate
  43531. Array.prototype.push.apply(stack, stack.splice(stack.length - n, n - j));
  43532. break;
  43533. default:
  43534. return null;
  43535. }
  43536. }
  43537. // unsupported operator
  43538. if (stack.length !== outputSize) {
  43539. return null;
  43540. }
  43541. var result = [];
  43542. instructions.forEach(function (instruction) {
  43543. var statementBuilder = new ExpressionBuilderVisitor();
  43544. instruction.visit(statementBuilder);
  43545. result.push(statementBuilder.toString());
  43546. });
  43547. stack.forEach(function (expr, i) {
  43548. var statementBuilder = new ExpressionBuilderVisitor();
  43549. expr.visit(statementBuilder);
  43550. var min = range[i * 2], max = range[i * 2 + 1];
  43551. var out = [statementBuilder.toString()];
  43552. if (min > expr.min) {
  43553. out.unshift('Math.max(', min, ', ');
  43554. out.push(')');
  43555. }
  43556. if (max < expr.max) {
  43557. out.unshift('Math.min(', max, ', ');
  43558. out.push(')');
  43559. }
  43560. out.unshift('dest[destOffset + ', i, '] = ');
  43561. out.push(';');
  43562. result.push(out.join(''));
  43563. });
  43564. return result.join('\n');
  43565. }
  43566. };
  43567. return PostScriptCompiler;
  43568. }();
  43569. exports.isPDFFunction = isPDFFunction;
  43570. exports.PDFFunction = PDFFunction;
  43571. exports.PostScriptEvaluator = PostScriptEvaluator;
  43572. exports.PostScriptCompiler = PostScriptCompiler;
  43573. }));
  43574. (function (root, factory) {
  43575. factory(root.pdfjsCoreColorSpace = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCoreFunction);
  43576. }(this, function (exports, sharedUtil, corePrimitives, coreFunction) {
  43577. var error = sharedUtil.error;
  43578. var info = sharedUtil.info;
  43579. var isArray = sharedUtil.isArray;
  43580. var isString = sharedUtil.isString;
  43581. var shadow = sharedUtil.shadow;
  43582. var warn = sharedUtil.warn;
  43583. var isDict = corePrimitives.isDict;
  43584. var isName = corePrimitives.isName;
  43585. var isStream = corePrimitives.isStream;
  43586. var PDFFunction = coreFunction.PDFFunction;
  43587. var ColorSpace = function ColorSpaceClosure() {
  43588. /**
  43589. * Resizes an RGB image with 3 components.
  43590. * @param {TypedArray} src - The source buffer.
  43591. * @param {Number} bpc - Number of bits per component.
  43592. * @param {Number} w1 - Original width.
  43593. * @param {Number} h1 - Original height.
  43594. * @param {Number} w2 - New width.
  43595. * @param {Number} h2 - New height.
  43596. * @param {Number} alpha01 - Size reserved for the alpha channel.
  43597. * @param {TypedArray} dest - The destination buffer.
  43598. */
  43599. function resizeRgbImage(src, bpc, w1, h1, w2, h2, alpha01, dest) {
  43600. var COMPONENTS = 3;
  43601. alpha01 = alpha01 !== 1 ? 0 : alpha01;
  43602. var xRatio = w1 / w2;
  43603. var yRatio = h1 / h2;
  43604. var i, j, py, newIndex = 0, oldIndex;
  43605. var xScaled = new Uint16Array(w2);
  43606. var w1Scanline = w1 * COMPONENTS;
  43607. for (i = 0; i < w2; i++) {
  43608. xScaled[i] = Math.floor(i * xRatio) * COMPONENTS;
  43609. }
  43610. for (i = 0; i < h2; i++) {
  43611. py = Math.floor(i * yRatio) * w1Scanline;
  43612. for (j = 0; j < w2; j++) {
  43613. oldIndex = py + xScaled[j];
  43614. dest[newIndex++] = src[oldIndex++];
  43615. dest[newIndex++] = src[oldIndex++];
  43616. dest[newIndex++] = src[oldIndex++];
  43617. newIndex += alpha01;
  43618. }
  43619. }
  43620. }
  43621. // Constructor should define this.numComps, this.defaultColor, this.name
  43622. function ColorSpace() {
  43623. error('should not call ColorSpace constructor');
  43624. }
  43625. ColorSpace.prototype = {
  43626. /**
  43627. * Converts the color value to the RGB color. The color components are
  43628. * located in the src array starting from the srcOffset. Returns the array
  43629. * of the rgb components, each value ranging from [0,255].
  43630. */
  43631. getRgb: function ColorSpace_getRgb(src, srcOffset) {
  43632. var rgb = new Uint8Array(3);
  43633. this.getRgbItem(src, srcOffset, rgb, 0);
  43634. return rgb;
  43635. },
  43636. /**
  43637. * Converts the color value to the RGB color, similar to the getRgb method.
  43638. * The result placed into the dest array starting from the destOffset.
  43639. */
  43640. getRgbItem: function ColorSpace_getRgbItem(src, srcOffset, dest, destOffset) {
  43641. error('Should not call ColorSpace.getRgbItem');
  43642. },
  43643. /**
  43644. * Converts the specified number of the color values to the RGB colors.
  43645. * The colors are located in the src array starting from the srcOffset.
  43646. * The result is placed into the dest array starting from the destOffset.
  43647. * The src array items shall be in [0,2^bits) range, the dest array items
  43648. * will be in [0,255] range. alpha01 indicates how many alpha components
  43649. * there are in the dest array; it will be either 0 (RGB array) or 1 (RGBA
  43650. * array).
  43651. */
  43652. getRgbBuffer: function ColorSpace_getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
  43653. error('Should not call ColorSpace.getRgbBuffer');
  43654. },
  43655. /**
  43656. * Determines the number of bytes required to store the result of the
  43657. * conversion done by the getRgbBuffer method. As in getRgbBuffer,
  43658. * |alpha01| is either 0 (RGB output) or 1 (RGBA output).
  43659. */
  43660. getOutputLength: function ColorSpace_getOutputLength(inputLength, alpha01) {
  43661. error('Should not call ColorSpace.getOutputLength');
  43662. },
  43663. /**
  43664. * Returns true if source data will be equal the result/output data.
  43665. */
  43666. isPassthrough: function ColorSpace_isPassthrough(bits) {
  43667. return false;
  43668. },
  43669. /**
  43670. * Fills in the RGB colors in the destination buffer. alpha01 indicates
  43671. * how many alpha components there are in the dest array; it will be either
  43672. * 0 (RGB array) or 1 (RGBA array).
  43673. */
  43674. fillRgb: function ColorSpace_fillRgb(dest, originalWidth, originalHeight, width, height, actualHeight, bpc, comps, alpha01) {
  43675. var count = originalWidth * originalHeight;
  43676. var rgbBuf = null;
  43677. var numComponentColors = 1 << bpc;
  43678. var needsResizing = originalHeight !== height || originalWidth !== width;
  43679. var i, ii;
  43680. if (this.isPassthrough(bpc)) {
  43681. rgbBuf = comps;
  43682. } else if (this.numComps === 1 && count > numComponentColors && this.name !== 'DeviceGray' && this.name !== 'DeviceRGB') {
  43683. // Optimization: create a color map when there is just one component and
  43684. // we are converting more colors than the size of the color map. We
  43685. // don't build the map if the colorspace is gray or rgb since those
  43686. // methods are faster than building a map. This mainly offers big speed
  43687. // ups for indexed and alternate colorspaces.
  43688. //
  43689. // TODO it may be worth while to cache the color map. While running
  43690. // testing I never hit a cache so I will leave that out for now (perhaps
  43691. // we are reparsing colorspaces too much?).
  43692. var allColors = bpc <= 8 ? new Uint8Array(numComponentColors) : new Uint16Array(numComponentColors);
  43693. var key;
  43694. for (i = 0; i < numComponentColors; i++) {
  43695. allColors[i] = i;
  43696. }
  43697. var colorMap = new Uint8Array(numComponentColors * 3);
  43698. this.getRgbBuffer(allColors, 0, numComponentColors, colorMap, 0, bpc, /* alpha01 = */
  43699. 0);
  43700. var destPos, rgbPos;
  43701. if (!needsResizing) {
  43702. // Fill in the RGB values directly into |dest|.
  43703. destPos = 0;
  43704. for (i = 0; i < count; ++i) {
  43705. key = comps[i] * 3;
  43706. dest[destPos++] = colorMap[key];
  43707. dest[destPos++] = colorMap[key + 1];
  43708. dest[destPos++] = colorMap[key + 2];
  43709. destPos += alpha01;
  43710. }
  43711. } else {
  43712. rgbBuf = new Uint8Array(count * 3);
  43713. rgbPos = 0;
  43714. for (i = 0; i < count; ++i) {
  43715. key = comps[i] * 3;
  43716. rgbBuf[rgbPos++] = colorMap[key];
  43717. rgbBuf[rgbPos++] = colorMap[key + 1];
  43718. rgbBuf[rgbPos++] = colorMap[key + 2];
  43719. }
  43720. }
  43721. } else {
  43722. if (!needsResizing) {
  43723. // Fill in the RGB values directly into |dest|.
  43724. this.getRgbBuffer(comps, 0, width * actualHeight, dest, 0, bpc, alpha01);
  43725. } else {
  43726. rgbBuf = new Uint8Array(count * 3);
  43727. this.getRgbBuffer(comps, 0, count, rgbBuf, 0, bpc, /* alpha01 = */
  43728. 0);
  43729. }
  43730. }
  43731. if (rgbBuf) {
  43732. if (needsResizing) {
  43733. resizeRgbImage(rgbBuf, bpc, originalWidth, originalHeight, width, height, alpha01, dest);
  43734. } else {
  43735. rgbPos = 0;
  43736. destPos = 0;
  43737. for (i = 0, ii = width * actualHeight; i < ii; i++) {
  43738. dest[destPos++] = rgbBuf[rgbPos++];
  43739. dest[destPos++] = rgbBuf[rgbPos++];
  43740. dest[destPos++] = rgbBuf[rgbPos++];
  43741. destPos += alpha01;
  43742. }
  43743. }
  43744. }
  43745. },
  43746. /**
  43747. * True if the colorspace has components in the default range of [0, 1].
  43748. * This should be true for all colorspaces except for lab color spaces
  43749. * which are [0,100], [-128, 127], [-128, 127].
  43750. */
  43751. usesZeroToOneRange: true
  43752. };
  43753. ColorSpace.parse = function ColorSpace_parse(cs, xref, res) {
  43754. var IR = ColorSpace.parseToIR(cs, xref, res);
  43755. if (IR instanceof AlternateCS) {
  43756. return IR;
  43757. }
  43758. return ColorSpace.fromIR(IR);
  43759. };
  43760. ColorSpace.fromIR = function ColorSpace_fromIR(IR) {
  43761. var name = isArray(IR) ? IR[0] : IR;
  43762. var whitePoint, blackPoint, gamma;
  43763. switch (name) {
  43764. case 'DeviceGrayCS':
  43765. return this.singletons.gray;
  43766. case 'DeviceRgbCS':
  43767. return this.singletons.rgb;
  43768. case 'DeviceCmykCS':
  43769. return this.singletons.cmyk;
  43770. case 'CalGrayCS':
  43771. whitePoint = IR[1];
  43772. blackPoint = IR[2];
  43773. gamma = IR[3];
  43774. return new CalGrayCS(whitePoint, blackPoint, gamma);
  43775. case 'CalRGBCS':
  43776. whitePoint = IR[1];
  43777. blackPoint = IR[2];
  43778. gamma = IR[3];
  43779. var matrix = IR[4];
  43780. return new CalRGBCS(whitePoint, blackPoint, gamma, matrix);
  43781. case 'PatternCS':
  43782. var basePatternCS = IR[1];
  43783. if (basePatternCS) {
  43784. basePatternCS = ColorSpace.fromIR(basePatternCS);
  43785. }
  43786. return new PatternCS(basePatternCS);
  43787. case 'IndexedCS':
  43788. var baseIndexedCS = IR[1];
  43789. var hiVal = IR[2];
  43790. var lookup = IR[3];
  43791. return new IndexedCS(ColorSpace.fromIR(baseIndexedCS), hiVal, lookup);
  43792. case 'AlternateCS':
  43793. var numComps = IR[1];
  43794. var alt = IR[2];
  43795. var tintFnIR = IR[3];
  43796. return new AlternateCS(numComps, ColorSpace.fromIR(alt), PDFFunction.fromIR(tintFnIR));
  43797. case 'LabCS':
  43798. whitePoint = IR[1];
  43799. blackPoint = IR[2];
  43800. var range = IR[3];
  43801. return new LabCS(whitePoint, blackPoint, range);
  43802. default:
  43803. error('Unknown name ' + name);
  43804. }
  43805. return null;
  43806. };
  43807. ColorSpace.parseToIR = function ColorSpace_parseToIR(cs, xref, res) {
  43808. if (isName(cs)) {
  43809. var colorSpaces = res.get('ColorSpace');
  43810. if (isDict(colorSpaces)) {
  43811. var refcs = colorSpaces.get(cs.name);
  43812. if (refcs) {
  43813. cs = refcs;
  43814. }
  43815. }
  43816. }
  43817. cs = xref.fetchIfRef(cs);
  43818. var mode;
  43819. if (isName(cs)) {
  43820. mode = cs.name;
  43821. this.mode = mode;
  43822. switch (mode) {
  43823. case 'DeviceGray':
  43824. case 'G':
  43825. return 'DeviceGrayCS';
  43826. case 'DeviceRGB':
  43827. case 'RGB':
  43828. return 'DeviceRgbCS';
  43829. case 'DeviceCMYK':
  43830. case 'CMYK':
  43831. return 'DeviceCmykCS';
  43832. case 'Pattern':
  43833. return [
  43834. 'PatternCS',
  43835. null
  43836. ];
  43837. default:
  43838. error('unrecognized colorspace ' + mode);
  43839. }
  43840. } else if (isArray(cs)) {
  43841. mode = xref.fetchIfRef(cs[0]).name;
  43842. this.mode = mode;
  43843. var numComps, params, alt, whitePoint, blackPoint, gamma;
  43844. switch (mode) {
  43845. case 'DeviceGray':
  43846. case 'G':
  43847. return 'DeviceGrayCS';
  43848. case 'DeviceRGB':
  43849. case 'RGB':
  43850. return 'DeviceRgbCS';
  43851. case 'DeviceCMYK':
  43852. case 'CMYK':
  43853. return 'DeviceCmykCS';
  43854. case 'CalGray':
  43855. params = xref.fetchIfRef(cs[1]);
  43856. whitePoint = params.getArray('WhitePoint');
  43857. blackPoint = params.getArray('BlackPoint');
  43858. gamma = params.get('Gamma');
  43859. return [
  43860. 'CalGrayCS',
  43861. whitePoint,
  43862. blackPoint,
  43863. gamma
  43864. ];
  43865. case 'CalRGB':
  43866. params = xref.fetchIfRef(cs[1]);
  43867. whitePoint = params.getArray('WhitePoint');
  43868. blackPoint = params.getArray('BlackPoint');
  43869. gamma = params.getArray('Gamma');
  43870. var matrix = params.getArray('Matrix');
  43871. return [
  43872. 'CalRGBCS',
  43873. whitePoint,
  43874. blackPoint,
  43875. gamma,
  43876. matrix
  43877. ];
  43878. case 'ICCBased':
  43879. var stream = xref.fetchIfRef(cs[1]);
  43880. var dict = stream.dict;
  43881. numComps = dict.get('N');
  43882. alt = dict.get('Alternate');
  43883. if (alt) {
  43884. var altIR = ColorSpace.parseToIR(alt, xref, res);
  43885. // Parse the /Alternate CS to ensure that the number of components
  43886. // are correct, and also (indirectly) that it is not a PatternCS.
  43887. var altCS = ColorSpace.fromIR(altIR);
  43888. if (altCS.numComps === numComps) {
  43889. return altIR;
  43890. }
  43891. warn('ICCBased color space: Ignoring incorrect /Alternate entry.');
  43892. }
  43893. if (numComps === 1) {
  43894. return 'DeviceGrayCS';
  43895. } else if (numComps === 3) {
  43896. return 'DeviceRgbCS';
  43897. } else if (numComps === 4) {
  43898. return 'DeviceCmykCS';
  43899. }
  43900. break;
  43901. case 'Pattern':
  43902. var basePatternCS = cs[1] || null;
  43903. if (basePatternCS) {
  43904. basePatternCS = ColorSpace.parseToIR(basePatternCS, xref, res);
  43905. }
  43906. return [
  43907. 'PatternCS',
  43908. basePatternCS
  43909. ];
  43910. case 'Indexed':
  43911. case 'I':
  43912. var baseIndexedCS = ColorSpace.parseToIR(cs[1], xref, res);
  43913. var hiVal = xref.fetchIfRef(cs[2]) + 1;
  43914. var lookup = xref.fetchIfRef(cs[3]);
  43915. if (isStream(lookup)) {
  43916. lookup = lookup.getBytes();
  43917. }
  43918. return [
  43919. 'IndexedCS',
  43920. baseIndexedCS,
  43921. hiVal,
  43922. lookup
  43923. ];
  43924. case 'Separation':
  43925. case 'DeviceN':
  43926. var name = xref.fetchIfRef(cs[1]);
  43927. numComps = 1;
  43928. if (isName(name)) {
  43929. numComps = 1;
  43930. } else if (isArray(name)) {
  43931. numComps = name.length;
  43932. }
  43933. alt = ColorSpace.parseToIR(cs[2], xref, res);
  43934. var tintFnIR = PDFFunction.getIR(xref, xref.fetchIfRef(cs[3]));
  43935. return [
  43936. 'AlternateCS',
  43937. numComps,
  43938. alt,
  43939. tintFnIR
  43940. ];
  43941. case 'Lab':
  43942. params = xref.fetchIfRef(cs[1]);
  43943. whitePoint = params.getArray('WhitePoint');
  43944. blackPoint = params.getArray('BlackPoint');
  43945. var range = params.getArray('Range');
  43946. return [
  43947. 'LabCS',
  43948. whitePoint,
  43949. blackPoint,
  43950. range
  43951. ];
  43952. default:
  43953. error('unimplemented color space object "' + mode + '"');
  43954. }
  43955. } else {
  43956. error('unrecognized color space object: "' + cs + '"');
  43957. }
  43958. return null;
  43959. };
  43960. /**
  43961. * Checks if a decode map matches the default decode map for a color space.
  43962. * This handles the general decode maps where there are two values per
  43963. * component. e.g. [0, 1, 0, 1, 0, 1] for a RGB color.
  43964. * This does not handle Lab, Indexed, or Pattern decode maps since they are
  43965. * slightly different.
  43966. * @param {Array} decode Decode map (usually from an image).
  43967. * @param {Number} n Number of components the color space has.
  43968. */
  43969. ColorSpace.isDefaultDecode = function ColorSpace_isDefaultDecode(decode, n) {
  43970. if (!isArray(decode)) {
  43971. return true;
  43972. }
  43973. if (n * 2 !== decode.length) {
  43974. warn('The decode map is not the correct length');
  43975. return true;
  43976. }
  43977. for (var i = 0, ii = decode.length; i < ii; i += 2) {
  43978. if (decode[i] !== 0 || decode[i + 1] !== 1) {
  43979. return false;
  43980. }
  43981. }
  43982. return true;
  43983. };
  43984. ColorSpace.singletons = {
  43985. get gray() {
  43986. return shadow(this, 'gray', new DeviceGrayCS());
  43987. },
  43988. get rgb() {
  43989. return shadow(this, 'rgb', new DeviceRgbCS());
  43990. },
  43991. get cmyk() {
  43992. return shadow(this, 'cmyk', new DeviceCmykCS());
  43993. }
  43994. };
  43995. return ColorSpace;
  43996. }();
  43997. /**
  43998. * Alternate color space handles both Separation and DeviceN color spaces. A
  43999. * Separation color space is actually just a DeviceN with one color component.
  44000. * Both color spaces use a tinting function to convert colors to a base color
  44001. * space.
  44002. */
  44003. var AlternateCS = function AlternateCSClosure() {
  44004. function AlternateCS(numComps, base, tintFn) {
  44005. this.name = 'Alternate';
  44006. this.numComps = numComps;
  44007. this.defaultColor = new Float32Array(numComps);
  44008. for (var i = 0; i < numComps; ++i) {
  44009. this.defaultColor[i] = 1;
  44010. }
  44011. this.base = base;
  44012. this.tintFn = tintFn;
  44013. this.tmpBuf = new Float32Array(base.numComps);
  44014. }
  44015. AlternateCS.prototype = {
  44016. getRgb: ColorSpace.prototype.getRgb,
  44017. getRgbItem: function AlternateCS_getRgbItem(src, srcOffset, dest, destOffset) {
  44018. var tmpBuf = this.tmpBuf;
  44019. this.tintFn(src, srcOffset, tmpBuf, 0);
  44020. this.base.getRgbItem(tmpBuf, 0, dest, destOffset);
  44021. },
  44022. getRgbBuffer: function AlternateCS_getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
  44023. var tintFn = this.tintFn;
  44024. var base = this.base;
  44025. var scale = 1 / ((1 << bits) - 1);
  44026. var baseNumComps = base.numComps;
  44027. var usesZeroToOneRange = base.usesZeroToOneRange;
  44028. var isPassthrough = (base.isPassthrough(8) || !usesZeroToOneRange) && alpha01 === 0;
  44029. var pos = isPassthrough ? destOffset : 0;
  44030. var baseBuf = isPassthrough ? dest : new Uint8Array(baseNumComps * count);
  44031. var numComps = this.numComps;
  44032. var scaled = new Float32Array(numComps);
  44033. var tinted = new Float32Array(baseNumComps);
  44034. var i, j;
  44035. if (usesZeroToOneRange) {
  44036. for (i = 0; i < count; i++) {
  44037. for (j = 0; j < numComps; j++) {
  44038. scaled[j] = src[srcOffset++] * scale;
  44039. }
  44040. tintFn(scaled, 0, tinted, 0);
  44041. for (j = 0; j < baseNumComps; j++) {
  44042. baseBuf[pos++] = tinted[j] * 255;
  44043. }
  44044. }
  44045. } else {
  44046. for (i = 0; i < count; i++) {
  44047. for (j = 0; j < numComps; j++) {
  44048. scaled[j] = src[srcOffset++] * scale;
  44049. }
  44050. tintFn(scaled, 0, tinted, 0);
  44051. base.getRgbItem(tinted, 0, baseBuf, pos);
  44052. pos += baseNumComps;
  44053. }
  44054. }
  44055. if (!isPassthrough) {
  44056. base.getRgbBuffer(baseBuf, 0, count, dest, destOffset, 8, alpha01);
  44057. }
  44058. },
  44059. getOutputLength: function AlternateCS_getOutputLength(inputLength, alpha01) {
  44060. return this.base.getOutputLength(inputLength * this.base.numComps / this.numComps, alpha01);
  44061. },
  44062. isPassthrough: ColorSpace.prototype.isPassthrough,
  44063. fillRgb: ColorSpace.prototype.fillRgb,
  44064. isDefaultDecode: function AlternateCS_isDefaultDecode(decodeMap) {
  44065. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  44066. },
  44067. usesZeroToOneRange: true
  44068. };
  44069. return AlternateCS;
  44070. }();
  44071. var PatternCS = function PatternCSClosure() {
  44072. function PatternCS(baseCS) {
  44073. this.name = 'Pattern';
  44074. this.base = baseCS;
  44075. }
  44076. PatternCS.prototype = {};
  44077. return PatternCS;
  44078. }();
  44079. var IndexedCS = function IndexedCSClosure() {
  44080. function IndexedCS(base, highVal, lookup) {
  44081. this.name = 'Indexed';
  44082. this.numComps = 1;
  44083. this.defaultColor = new Uint8Array([0]);
  44084. this.base = base;
  44085. this.highVal = highVal;
  44086. var baseNumComps = base.numComps;
  44087. var length = baseNumComps * highVal;
  44088. var lookupArray;
  44089. if (isStream(lookup)) {
  44090. lookupArray = new Uint8Array(length);
  44091. var bytes = lookup.getBytes(length);
  44092. lookupArray.set(bytes);
  44093. } else if (isString(lookup)) {
  44094. lookupArray = new Uint8Array(length);
  44095. for (var i = 0; i < length; ++i) {
  44096. lookupArray[i] = lookup.charCodeAt(i);
  44097. }
  44098. } else if (lookup instanceof Uint8Array || lookup instanceof Array) {
  44099. lookupArray = lookup;
  44100. } else {
  44101. error('Unrecognized lookup table: ' + lookup);
  44102. }
  44103. this.lookup = lookupArray;
  44104. }
  44105. IndexedCS.prototype = {
  44106. getRgb: ColorSpace.prototype.getRgb,
  44107. getRgbItem: function IndexedCS_getRgbItem(src, srcOffset, dest, destOffset) {
  44108. var numComps = this.base.numComps;
  44109. var start = src[srcOffset] * numComps;
  44110. this.base.getRgbItem(this.lookup, start, dest, destOffset);
  44111. },
  44112. getRgbBuffer: function IndexedCS_getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
  44113. var base = this.base;
  44114. var numComps = base.numComps;
  44115. var outputDelta = base.getOutputLength(numComps, alpha01);
  44116. var lookup = this.lookup;
  44117. for (var i = 0; i < count; ++i) {
  44118. var lookupPos = src[srcOffset++] * numComps;
  44119. base.getRgbBuffer(lookup, lookupPos, 1, dest, destOffset, 8, alpha01);
  44120. destOffset += outputDelta;
  44121. }
  44122. },
  44123. getOutputLength: function IndexedCS_getOutputLength(inputLength, alpha01) {
  44124. return this.base.getOutputLength(inputLength * this.base.numComps, alpha01);
  44125. },
  44126. isPassthrough: ColorSpace.prototype.isPassthrough,
  44127. fillRgb: ColorSpace.prototype.fillRgb,
  44128. isDefaultDecode: function IndexedCS_isDefaultDecode(decodeMap) {
  44129. // indexed color maps shouldn't be changed
  44130. return true;
  44131. },
  44132. usesZeroToOneRange: true
  44133. };
  44134. return IndexedCS;
  44135. }();
  44136. var DeviceGrayCS = function DeviceGrayCSClosure() {
  44137. function DeviceGrayCS() {
  44138. this.name = 'DeviceGray';
  44139. this.numComps = 1;
  44140. this.defaultColor = new Float32Array([0]);
  44141. }
  44142. DeviceGrayCS.prototype = {
  44143. getRgb: ColorSpace.prototype.getRgb,
  44144. getRgbItem: function DeviceGrayCS_getRgbItem(src, srcOffset, dest, destOffset) {
  44145. var c = src[srcOffset] * 255 | 0;
  44146. c = c < 0 ? 0 : c > 255 ? 255 : c;
  44147. dest[destOffset] = dest[destOffset + 1] = dest[destOffset + 2] = c;
  44148. },
  44149. getRgbBuffer: function DeviceGrayCS_getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
  44150. var scale = 255 / ((1 << bits) - 1);
  44151. var j = srcOffset, q = destOffset;
  44152. for (var i = 0; i < count; ++i) {
  44153. var c = scale * src[j++] | 0;
  44154. dest[q++] = c;
  44155. dest[q++] = c;
  44156. dest[q++] = c;
  44157. q += alpha01;
  44158. }
  44159. },
  44160. getOutputLength: function DeviceGrayCS_getOutputLength(inputLength, alpha01) {
  44161. return inputLength * (3 + alpha01);
  44162. },
  44163. isPassthrough: ColorSpace.prototype.isPassthrough,
  44164. fillRgb: ColorSpace.prototype.fillRgb,
  44165. isDefaultDecode: function DeviceGrayCS_isDefaultDecode(decodeMap) {
  44166. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  44167. },
  44168. usesZeroToOneRange: true
  44169. };
  44170. return DeviceGrayCS;
  44171. }();
  44172. var DeviceRgbCS = function DeviceRgbCSClosure() {
  44173. function DeviceRgbCS() {
  44174. this.name = 'DeviceRGB';
  44175. this.numComps = 3;
  44176. this.defaultColor = new Float32Array([
  44177. 0,
  44178. 0,
  44179. 0
  44180. ]);
  44181. }
  44182. DeviceRgbCS.prototype = {
  44183. getRgb: ColorSpace.prototype.getRgb,
  44184. getRgbItem: function DeviceRgbCS_getRgbItem(src, srcOffset, dest, destOffset) {
  44185. var r = src[srcOffset] * 255 | 0;
  44186. var g = src[srcOffset + 1] * 255 | 0;
  44187. var b = src[srcOffset + 2] * 255 | 0;
  44188. dest[destOffset] = r < 0 ? 0 : r > 255 ? 255 : r;
  44189. dest[destOffset + 1] = g < 0 ? 0 : g > 255 ? 255 : g;
  44190. dest[destOffset + 2] = b < 0 ? 0 : b > 255 ? 255 : b;
  44191. },
  44192. getRgbBuffer: function DeviceRgbCS_getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
  44193. if (bits === 8 && alpha01 === 0) {
  44194. dest.set(src.subarray(srcOffset, srcOffset + count * 3), destOffset);
  44195. return;
  44196. }
  44197. var scale = 255 / ((1 << bits) - 1);
  44198. var j = srcOffset, q = destOffset;
  44199. for (var i = 0; i < count; ++i) {
  44200. dest[q++] = scale * src[j++] | 0;
  44201. dest[q++] = scale * src[j++] | 0;
  44202. dest[q++] = scale * src[j++] | 0;
  44203. q += alpha01;
  44204. }
  44205. },
  44206. getOutputLength: function DeviceRgbCS_getOutputLength(inputLength, alpha01) {
  44207. return inputLength * (3 + alpha01) / 3 | 0;
  44208. },
  44209. isPassthrough: function DeviceRgbCS_isPassthrough(bits) {
  44210. return bits === 8;
  44211. },
  44212. fillRgb: ColorSpace.prototype.fillRgb,
  44213. isDefaultDecode: function DeviceRgbCS_isDefaultDecode(decodeMap) {
  44214. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  44215. },
  44216. usesZeroToOneRange: true
  44217. };
  44218. return DeviceRgbCS;
  44219. }();
  44220. var DeviceCmykCS = function DeviceCmykCSClosure() {
  44221. // The coefficients below was found using numerical analysis: the method of
  44222. // steepest descent for the sum((f_i - color_value_i)^2) for r/g/b colors,
  44223. // where color_value is the tabular value from the table of sampled RGB colors
  44224. // from CMYK US Web Coated (SWOP) colorspace, and f_i is the corresponding
  44225. // CMYK color conversion using the estimation below:
  44226. // f(A, B,.. N) = Acc+Bcm+Ccy+Dck+c+Fmm+Gmy+Hmk+Im+Jyy+Kyk+Ly+Mkk+Nk+255
  44227. function convertToRgb(src, srcOffset, srcScale, dest, destOffset) {
  44228. var c = src[srcOffset + 0] * srcScale;
  44229. var m = src[srcOffset + 1] * srcScale;
  44230. var y = src[srcOffset + 2] * srcScale;
  44231. var k = src[srcOffset + 3] * srcScale;
  44232. var r = c * (-4.387332384609988 * c + 54.48615194189176 * m + 18.82290502165302 * y + 212.25662451639585 * k + -285.2331026137004) + m * (1.7149763477362134 * m - 5.6096736904047315 * y + -17.873870861415444 * k - 5.497006427196366) + y * (-2.5217340131683033 * y - 21.248923337353073 * k + 17.5119270841813) + k * (-21.86122147463605 * k - 189.48180835922747) + 255 | 0;
  44233. var g = c * (8.841041422036149 * c + 60.118027045597366 * m + 6.871425592049007 * y + 31.159100130055922 * k + -79.2970844816548) + m * (-15.310361306967817 * m + 17.575251261109482 * y + 131.35250912493976 * k - 190.9453302588951) + y * (4.444339102852739 * y + 9.8632861493405 * k - 24.86741582555878) + k * (-20.737325471181034 * k - 187.80453709719578) + 255 | 0;
  44234. var b = c * (0.8842522430003296 * c + 8.078677503112928 * m + 30.89978309703729 * y - 0.23883238689178934 * k + -14.183576799673286) + m * (10.49593273432072 * m + 63.02378494754052 * y + 50.606957656360734 * k - 112.23884253719248) + y * (0.03296041114873217 * y + 115.60384449646641 * k + -193.58209356861505) + k * (-22.33816807309886 * k - 180.12613974708367) + 255 | 0;
  44235. dest[destOffset] = r > 255 ? 255 : r < 0 ? 0 : r;
  44236. dest[destOffset + 1] = g > 255 ? 255 : g < 0 ? 0 : g;
  44237. dest[destOffset + 2] = b > 255 ? 255 : b < 0 ? 0 : b;
  44238. }
  44239. function DeviceCmykCS() {
  44240. this.name = 'DeviceCMYK';
  44241. this.numComps = 4;
  44242. this.defaultColor = new Float32Array([
  44243. 0,
  44244. 0,
  44245. 0,
  44246. 1
  44247. ]);
  44248. }
  44249. DeviceCmykCS.prototype = {
  44250. getRgb: ColorSpace.prototype.getRgb,
  44251. getRgbItem: function DeviceCmykCS_getRgbItem(src, srcOffset, dest, destOffset) {
  44252. convertToRgb(src, srcOffset, 1, dest, destOffset);
  44253. },
  44254. getRgbBuffer: function DeviceCmykCS_getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
  44255. var scale = 1 / ((1 << bits) - 1);
  44256. for (var i = 0; i < count; i++) {
  44257. convertToRgb(src, srcOffset, scale, dest, destOffset);
  44258. srcOffset += 4;
  44259. destOffset += 3 + alpha01;
  44260. }
  44261. },
  44262. getOutputLength: function DeviceCmykCS_getOutputLength(inputLength, alpha01) {
  44263. return inputLength / 4 * (3 + alpha01) | 0;
  44264. },
  44265. isPassthrough: ColorSpace.prototype.isPassthrough,
  44266. fillRgb: ColorSpace.prototype.fillRgb,
  44267. isDefaultDecode: function DeviceCmykCS_isDefaultDecode(decodeMap) {
  44268. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  44269. },
  44270. usesZeroToOneRange: true
  44271. };
  44272. return DeviceCmykCS;
  44273. }();
  44274. //
  44275. // CalGrayCS: Based on "PDF Reference, Sixth Ed", p.245
  44276. //
  44277. var CalGrayCS = function CalGrayCSClosure() {
  44278. function CalGrayCS(whitePoint, blackPoint, gamma) {
  44279. this.name = 'CalGray';
  44280. this.numComps = 1;
  44281. this.defaultColor = new Float32Array([0]);
  44282. if (!whitePoint) {
  44283. error('WhitePoint missing - required for color space CalGray');
  44284. }
  44285. blackPoint = blackPoint || [
  44286. 0,
  44287. 0,
  44288. 0
  44289. ];
  44290. gamma = gamma || 1;
  44291. // Translate arguments to spec variables.
  44292. this.XW = whitePoint[0];
  44293. this.YW = whitePoint[1];
  44294. this.ZW = whitePoint[2];
  44295. this.XB = blackPoint[0];
  44296. this.YB = blackPoint[1];
  44297. this.ZB = blackPoint[2];
  44298. this.G = gamma;
  44299. // Validate variables as per spec.
  44300. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  44301. error('Invalid WhitePoint components for ' + this.name + ', no fallback available');
  44302. }
  44303. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  44304. info('Invalid BlackPoint for ' + this.name + ', falling back to default');
  44305. this.XB = this.YB = this.ZB = 0;
  44306. }
  44307. if (this.XB !== 0 || this.YB !== 0 || this.ZB !== 0) {
  44308. warn(this.name + ', BlackPoint: XB: ' + this.XB + ', YB: ' + this.YB + ', ZB: ' + this.ZB + ', only default values are supported.');
  44309. }
  44310. if (this.G < 1) {
  44311. info('Invalid Gamma: ' + this.G + ' for ' + this.name + ', falling back to default');
  44312. this.G = 1;
  44313. }
  44314. }
  44315. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  44316. // A represents a gray component of a calibrated gray space.
  44317. // A <---> AG in the spec
  44318. var A = src[srcOffset] * scale;
  44319. var AG = Math.pow(A, cs.G);
  44320. // Computes L as per spec. ( = cs.YW * AG )
  44321. // Except if other than default BlackPoint values are used.
  44322. var L = cs.YW * AG;
  44323. // http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html, Ch 4.
  44324. // Convert values to rgb range [0, 255].
  44325. var val = Math.max(295.8 * Math.pow(L, 0.333333333333333333) - 40.8, 0) | 0;
  44326. dest[destOffset] = val;
  44327. dest[destOffset + 1] = val;
  44328. dest[destOffset + 2] = val;
  44329. }
  44330. CalGrayCS.prototype = {
  44331. getRgb: ColorSpace.prototype.getRgb,
  44332. getRgbItem: function CalGrayCS_getRgbItem(src, srcOffset, dest, destOffset) {
  44333. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  44334. },
  44335. getRgbBuffer: function CalGrayCS_getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
  44336. var scale = 1 / ((1 << bits) - 1);
  44337. for (var i = 0; i < count; ++i) {
  44338. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  44339. srcOffset += 1;
  44340. destOffset += 3 + alpha01;
  44341. }
  44342. },
  44343. getOutputLength: function CalGrayCS_getOutputLength(inputLength, alpha01) {
  44344. return inputLength * (3 + alpha01);
  44345. },
  44346. isPassthrough: ColorSpace.prototype.isPassthrough,
  44347. fillRgb: ColorSpace.prototype.fillRgb,
  44348. isDefaultDecode: function CalGrayCS_isDefaultDecode(decodeMap) {
  44349. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  44350. },
  44351. usesZeroToOneRange: true
  44352. };
  44353. return CalGrayCS;
  44354. }();
  44355. //
  44356. // CalRGBCS: Based on "PDF Reference, Sixth Ed", p.247
  44357. //
  44358. var CalRGBCS = function CalRGBCSClosure() {
  44359. // See http://www.brucelindbloom.com/index.html?Eqn_ChromAdapt.html for these
  44360. // matrices.
  44361. var BRADFORD_SCALE_MATRIX = new Float32Array([
  44362. 0.8951,
  44363. 0.2664,
  44364. -0.1614,
  44365. -0.7502,
  44366. 1.7135,
  44367. 0.0367,
  44368. 0.0389,
  44369. -0.0685,
  44370. 1.0296
  44371. ]);
  44372. var BRADFORD_SCALE_INVERSE_MATRIX = new Float32Array([
  44373. 0.9869929,
  44374. -0.1470543,
  44375. 0.1599627,
  44376. 0.4323053,
  44377. 0.5183603,
  44378. 0.0492912,
  44379. -0.0085287,
  44380. 0.0400428,
  44381. 0.9684867
  44382. ]);
  44383. // See http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html.
  44384. var SRGB_D65_XYZ_TO_RGB_MATRIX = new Float32Array([
  44385. 3.2404542,
  44386. -1.5371385,
  44387. -0.4985314,
  44388. -0.9692660,
  44389. 1.8760108,
  44390. 0.0415560,
  44391. 0.0556434,
  44392. -0.2040259,
  44393. 1.0572252
  44394. ]);
  44395. var FLAT_WHITEPOINT_MATRIX = new Float32Array([
  44396. 1,
  44397. 1,
  44398. 1
  44399. ]);
  44400. var tempNormalizeMatrix = new Float32Array(3);
  44401. var tempConvertMatrix1 = new Float32Array(3);
  44402. var tempConvertMatrix2 = new Float32Array(3);
  44403. var DECODE_L_CONSTANT = Math.pow((8 + 16) / 116, 3) / 8.0;
  44404. function CalRGBCS(whitePoint, blackPoint, gamma, matrix) {
  44405. this.name = 'CalRGB';
  44406. this.numComps = 3;
  44407. this.defaultColor = new Float32Array(3);
  44408. if (!whitePoint) {
  44409. error('WhitePoint missing - required for color space CalRGB');
  44410. }
  44411. blackPoint = blackPoint || new Float32Array(3);
  44412. gamma = gamma || new Float32Array([
  44413. 1,
  44414. 1,
  44415. 1
  44416. ]);
  44417. matrix = matrix || new Float32Array([
  44418. 1,
  44419. 0,
  44420. 0,
  44421. 0,
  44422. 1,
  44423. 0,
  44424. 0,
  44425. 0,
  44426. 1
  44427. ]);
  44428. // Translate arguments to spec variables.
  44429. var XW = whitePoint[0];
  44430. var YW = whitePoint[1];
  44431. var ZW = whitePoint[2];
  44432. this.whitePoint = whitePoint;
  44433. var XB = blackPoint[0];
  44434. var YB = blackPoint[1];
  44435. var ZB = blackPoint[2];
  44436. this.blackPoint = blackPoint;
  44437. this.GR = gamma[0];
  44438. this.GG = gamma[1];
  44439. this.GB = gamma[2];
  44440. this.MXA = matrix[0];
  44441. this.MYA = matrix[1];
  44442. this.MZA = matrix[2];
  44443. this.MXB = matrix[3];
  44444. this.MYB = matrix[4];
  44445. this.MZB = matrix[5];
  44446. this.MXC = matrix[6];
  44447. this.MYC = matrix[7];
  44448. this.MZC = matrix[8];
  44449. // Validate variables as per spec.
  44450. if (XW < 0 || ZW < 0 || YW !== 1) {
  44451. error('Invalid WhitePoint components for ' + this.name + ', no fallback available');
  44452. }
  44453. if (XB < 0 || YB < 0 || ZB < 0) {
  44454. info('Invalid BlackPoint for ' + this.name + ' [' + XB + ', ' + YB + ', ' + ZB + '], falling back to default');
  44455. this.blackPoint = new Float32Array(3);
  44456. }
  44457. if (this.GR < 0 || this.GG < 0 || this.GB < 0) {
  44458. info('Invalid Gamma [' + this.GR + ', ' + this.GG + ', ' + this.GB + '] for ' + this.name + ', falling back to default');
  44459. this.GR = this.GG = this.GB = 1;
  44460. }
  44461. if (this.MXA < 0 || this.MYA < 0 || this.MZA < 0 || this.MXB < 0 || this.MYB < 0 || this.MZB < 0 || this.MXC < 0 || this.MYC < 0 || this.MZC < 0) {
  44462. info('Invalid Matrix for ' + this.name + ' [' + this.MXA + ', ' + this.MYA + ', ' + this.MZA + this.MXB + ', ' + this.MYB + ', ' + this.MZB + this.MXC + ', ' + this.MYC + ', ' + this.MZC + '], falling back to default');
  44463. this.MXA = this.MYB = this.MZC = 1;
  44464. this.MXB = this.MYA = this.MZA = this.MXC = this.MYC = this.MZB = 0;
  44465. }
  44466. }
  44467. function matrixProduct(a, b, result) {
  44468. result[0] = a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
  44469. result[1] = a[3] * b[0] + a[4] * b[1] + a[5] * b[2];
  44470. result[2] = a[6] * b[0] + a[7] * b[1] + a[8] * b[2];
  44471. }
  44472. function convertToFlat(sourceWhitePoint, LMS, result) {
  44473. result[0] = LMS[0] * 1 / sourceWhitePoint[0];
  44474. result[1] = LMS[1] * 1 / sourceWhitePoint[1];
  44475. result[2] = LMS[2] * 1 / sourceWhitePoint[2];
  44476. }
  44477. function convertToD65(sourceWhitePoint, LMS, result) {
  44478. var D65X = 0.95047;
  44479. var D65Y = 1;
  44480. var D65Z = 1.08883;
  44481. result[0] = LMS[0] * D65X / sourceWhitePoint[0];
  44482. result[1] = LMS[1] * D65Y / sourceWhitePoint[1];
  44483. result[2] = LMS[2] * D65Z / sourceWhitePoint[2];
  44484. }
  44485. function sRGBTransferFunction(color) {
  44486. // See http://en.wikipedia.org/wiki/SRGB.
  44487. if (color <= 0.0031308) {
  44488. return adjustToRange(0, 1, 12.92 * color);
  44489. }
  44490. return adjustToRange(0, 1, (1 + 0.055) * Math.pow(color, 1 / 2.4) - 0.055);
  44491. }
  44492. function adjustToRange(min, max, value) {
  44493. return Math.max(min, Math.min(max, value));
  44494. }
  44495. function decodeL(L) {
  44496. if (L < 0) {
  44497. return -decodeL(-L);
  44498. }
  44499. if (L > 8.0) {
  44500. return Math.pow((L + 16) / 116, 3);
  44501. }
  44502. return L * DECODE_L_CONSTANT;
  44503. }
  44504. function compensateBlackPoint(sourceBlackPoint, XYZ_Flat, result) {
  44505. // In case the blackPoint is already the default blackPoint then there is
  44506. // no need to do compensation.
  44507. if (sourceBlackPoint[0] === 0 && sourceBlackPoint[1] === 0 && sourceBlackPoint[2] === 0) {
  44508. result[0] = XYZ_Flat[0];
  44509. result[1] = XYZ_Flat[1];
  44510. result[2] = XYZ_Flat[2];
  44511. return;
  44512. }
  44513. // For the blackPoint calculation details, please see
  44514. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  44515. // AdobeBPC.pdf.
  44516. // The destination blackPoint is the default blackPoint [0, 0, 0].
  44517. var zeroDecodeL = decodeL(0);
  44518. var X_DST = zeroDecodeL;
  44519. var X_SRC = decodeL(sourceBlackPoint[0]);
  44520. var Y_DST = zeroDecodeL;
  44521. var Y_SRC = decodeL(sourceBlackPoint[1]);
  44522. var Z_DST = zeroDecodeL;
  44523. var Z_SRC = decodeL(sourceBlackPoint[2]);
  44524. var X_Scale = (1 - X_DST) / (1 - X_SRC);
  44525. var X_Offset = 1 - X_Scale;
  44526. var Y_Scale = (1 - Y_DST) / (1 - Y_SRC);
  44527. var Y_Offset = 1 - Y_Scale;
  44528. var Z_Scale = (1 - Z_DST) / (1 - Z_SRC);
  44529. var Z_Offset = 1 - Z_Scale;
  44530. result[0] = XYZ_Flat[0] * X_Scale + X_Offset;
  44531. result[1] = XYZ_Flat[1] * Y_Scale + Y_Offset;
  44532. result[2] = XYZ_Flat[2] * Z_Scale + Z_Offset;
  44533. }
  44534. function normalizeWhitePointToFlat(sourceWhitePoint, XYZ_In, result) {
  44535. // In case the whitePoint is already flat then there is no need to do
  44536. // normalization.
  44537. if (sourceWhitePoint[0] === 1 && sourceWhitePoint[2] === 1) {
  44538. result[0] = XYZ_In[0];
  44539. result[1] = XYZ_In[1];
  44540. result[2] = XYZ_In[2];
  44541. return;
  44542. }
  44543. var LMS = result;
  44544. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  44545. var LMS_Flat = tempNormalizeMatrix;
  44546. convertToFlat(sourceWhitePoint, LMS, LMS_Flat);
  44547. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_Flat, result);
  44548. }
  44549. function normalizeWhitePointToD65(sourceWhitePoint, XYZ_In, result) {
  44550. var LMS = result;
  44551. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  44552. var LMS_D65 = tempNormalizeMatrix;
  44553. convertToD65(sourceWhitePoint, LMS, LMS_D65);
  44554. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_D65, result);
  44555. }
  44556. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  44557. // A, B and C represent a red, green and blue components of a calibrated
  44558. // rgb space.
  44559. var A = adjustToRange(0, 1, src[srcOffset] * scale);
  44560. var B = adjustToRange(0, 1, src[srcOffset + 1] * scale);
  44561. var C = adjustToRange(0, 1, src[srcOffset + 2] * scale);
  44562. // A <---> AGR in the spec
  44563. // B <---> BGG in the spec
  44564. // C <---> CGB in the spec
  44565. var AGR = Math.pow(A, cs.GR);
  44566. var BGG = Math.pow(B, cs.GG);
  44567. var CGB = Math.pow(C, cs.GB);
  44568. // Computes intermediate variables L, M, N as per spec.
  44569. // To decode X, Y, Z values map L, M, N directly to them.
  44570. var X = cs.MXA * AGR + cs.MXB * BGG + cs.MXC * CGB;
  44571. var Y = cs.MYA * AGR + cs.MYB * BGG + cs.MYC * CGB;
  44572. var Z = cs.MZA * AGR + cs.MZB * BGG + cs.MZC * CGB;
  44573. // The following calculations are based on this document:
  44574. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  44575. // AdobeBPC.pdf.
  44576. var XYZ = tempConvertMatrix1;
  44577. XYZ[0] = X;
  44578. XYZ[1] = Y;
  44579. XYZ[2] = Z;
  44580. var XYZ_Flat = tempConvertMatrix2;
  44581. normalizeWhitePointToFlat(cs.whitePoint, XYZ, XYZ_Flat);
  44582. var XYZ_Black = tempConvertMatrix1;
  44583. compensateBlackPoint(cs.blackPoint, XYZ_Flat, XYZ_Black);
  44584. var XYZ_D65 = tempConvertMatrix2;
  44585. normalizeWhitePointToD65(FLAT_WHITEPOINT_MATRIX, XYZ_Black, XYZ_D65);
  44586. var SRGB = tempConvertMatrix1;
  44587. matrixProduct(SRGB_D65_XYZ_TO_RGB_MATRIX, XYZ_D65, SRGB);
  44588. var sR = sRGBTransferFunction(SRGB[0]);
  44589. var sG = sRGBTransferFunction(SRGB[1]);
  44590. var sB = sRGBTransferFunction(SRGB[2]);
  44591. // Convert the values to rgb range [0, 255].
  44592. dest[destOffset] = Math.round(sR * 255);
  44593. dest[destOffset + 1] = Math.round(sG * 255);
  44594. dest[destOffset + 2] = Math.round(sB * 255);
  44595. }
  44596. CalRGBCS.prototype = {
  44597. getRgb: function CalRGBCS_getRgb(src, srcOffset) {
  44598. var rgb = new Uint8Array(3);
  44599. this.getRgbItem(src, srcOffset, rgb, 0);
  44600. return rgb;
  44601. },
  44602. getRgbItem: function CalRGBCS_getRgbItem(src, srcOffset, dest, destOffset) {
  44603. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  44604. },
  44605. getRgbBuffer: function CalRGBCS_getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
  44606. var scale = 1 / ((1 << bits) - 1);
  44607. for (var i = 0; i < count; ++i) {
  44608. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  44609. srcOffset += 3;
  44610. destOffset += 3 + alpha01;
  44611. }
  44612. },
  44613. getOutputLength: function CalRGBCS_getOutputLength(inputLength, alpha01) {
  44614. return inputLength * (3 + alpha01) / 3 | 0;
  44615. },
  44616. isPassthrough: ColorSpace.prototype.isPassthrough,
  44617. fillRgb: ColorSpace.prototype.fillRgb,
  44618. isDefaultDecode: function CalRGBCS_isDefaultDecode(decodeMap) {
  44619. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  44620. },
  44621. usesZeroToOneRange: true
  44622. };
  44623. return CalRGBCS;
  44624. }();
  44625. //
  44626. // LabCS: Based on "PDF Reference, Sixth Ed", p.250
  44627. //
  44628. var LabCS = function LabCSClosure() {
  44629. function LabCS(whitePoint, blackPoint, range) {
  44630. this.name = 'Lab';
  44631. this.numComps = 3;
  44632. this.defaultColor = new Float32Array([
  44633. 0,
  44634. 0,
  44635. 0
  44636. ]);
  44637. if (!whitePoint) {
  44638. error('WhitePoint missing - required for color space Lab');
  44639. }
  44640. blackPoint = blackPoint || [
  44641. 0,
  44642. 0,
  44643. 0
  44644. ];
  44645. range = range || [
  44646. -100,
  44647. 100,
  44648. -100,
  44649. 100
  44650. ];
  44651. // Translate args to spec variables
  44652. this.XW = whitePoint[0];
  44653. this.YW = whitePoint[1];
  44654. this.ZW = whitePoint[2];
  44655. this.amin = range[0];
  44656. this.amax = range[1];
  44657. this.bmin = range[2];
  44658. this.bmax = range[3];
  44659. // These are here just for completeness - the spec doesn't offer any
  44660. // formulas that use BlackPoint in Lab
  44661. this.XB = blackPoint[0];
  44662. this.YB = blackPoint[1];
  44663. this.ZB = blackPoint[2];
  44664. // Validate vars as per spec
  44665. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  44666. error('Invalid WhitePoint components, no fallback available');
  44667. }
  44668. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  44669. info('Invalid BlackPoint, falling back to default');
  44670. this.XB = this.YB = this.ZB = 0;
  44671. }
  44672. if (this.amin > this.amax || this.bmin > this.bmax) {
  44673. info('Invalid Range, falling back to defaults');
  44674. this.amin = -100;
  44675. this.amax = 100;
  44676. this.bmin = -100;
  44677. this.bmax = 100;
  44678. }
  44679. }
  44680. // Function g(x) from spec
  44681. function fn_g(x) {
  44682. if (x >= 6 / 29) {
  44683. return x * x * x;
  44684. } else {
  44685. return 108 / 841 * (x - 4 / 29);
  44686. }
  44687. }
  44688. function decode(value, high1, low2, high2) {
  44689. return low2 + value * (high2 - low2) / high1;
  44690. }
  44691. // If decoding is needed maxVal should be 2^bits per component - 1.
  44692. function convertToRgb(cs, src, srcOffset, maxVal, dest, destOffset) {
  44693. // XXX: Lab input is in the range of [0, 100], [amin, amax], [bmin, bmax]
  44694. // not the usual [0, 1]. If a command like setFillColor is used the src
  44695. // values will already be within the correct range. However, if we are
  44696. // converting an image we have to map the values to the correct range given
  44697. // above.
  44698. // Ls,as,bs <---> L*,a*,b* in the spec
  44699. var Ls = src[srcOffset];
  44700. var as = src[srcOffset + 1];
  44701. var bs = src[srcOffset + 2];
  44702. if (maxVal !== false) {
  44703. Ls = decode(Ls, maxVal, 0, 100);
  44704. as = decode(as, maxVal, cs.amin, cs.amax);
  44705. bs = decode(bs, maxVal, cs.bmin, cs.bmax);
  44706. }
  44707. // Adjust limits of 'as' and 'bs'
  44708. as = as > cs.amax ? cs.amax : as < cs.amin ? cs.amin : as;
  44709. bs = bs > cs.bmax ? cs.bmax : bs < cs.bmin ? cs.bmin : bs;
  44710. // Computes intermediate variables X,Y,Z as per spec
  44711. var M = (Ls + 16) / 116;
  44712. var L = M + as / 500;
  44713. var N = M - bs / 200;
  44714. var X = cs.XW * fn_g(L);
  44715. var Y = cs.YW * fn_g(M);
  44716. var Z = cs.ZW * fn_g(N);
  44717. var r, g, b;
  44718. // Using different conversions for D50 and D65 white points,
  44719. // per http://www.color.org/srgb.pdf
  44720. if (cs.ZW < 1) {
  44721. // Assuming D50 (X=0.9642, Y=1.00, Z=0.8249)
  44722. r = X * 3.1339 + Y * -1.6170 + Z * -0.4906;
  44723. g = X * -0.9785 + Y * 1.9160 + Z * 0.0333;
  44724. b = X * 0.0720 + Y * -0.2290 + Z * 1.4057;
  44725. } else {
  44726. // Assuming D65 (X=0.9505, Y=1.00, Z=1.0888)
  44727. r = X * 3.2406 + Y * -1.5372 + Z * -0.4986;
  44728. g = X * -0.9689 + Y * 1.8758 + Z * 0.0415;
  44729. b = X * 0.0557 + Y * -0.2040 + Z * 1.0570;
  44730. }
  44731. // clamp color values to [0,1] range then convert to [0,255] range.
  44732. dest[destOffset] = r <= 0 ? 0 : r >= 1 ? 255 : Math.sqrt(r) * 255 | 0;
  44733. dest[destOffset + 1] = g <= 0 ? 0 : g >= 1 ? 255 : Math.sqrt(g) * 255 | 0;
  44734. dest[destOffset + 2] = b <= 0 ? 0 : b >= 1 ? 255 : Math.sqrt(b) * 255 | 0;
  44735. }
  44736. LabCS.prototype = {
  44737. getRgb: ColorSpace.prototype.getRgb,
  44738. getRgbItem: function LabCS_getRgbItem(src, srcOffset, dest, destOffset) {
  44739. convertToRgb(this, src, srcOffset, false, dest, destOffset);
  44740. },
  44741. getRgbBuffer: function LabCS_getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
  44742. var maxVal = (1 << bits) - 1;
  44743. for (var i = 0; i < count; i++) {
  44744. convertToRgb(this, src, srcOffset, maxVal, dest, destOffset);
  44745. srcOffset += 3;
  44746. destOffset += 3 + alpha01;
  44747. }
  44748. },
  44749. getOutputLength: function LabCS_getOutputLength(inputLength, alpha01) {
  44750. return inputLength * (3 + alpha01) / 3 | 0;
  44751. },
  44752. isPassthrough: ColorSpace.prototype.isPassthrough,
  44753. fillRgb: ColorSpace.prototype.fillRgb,
  44754. isDefaultDecode: function LabCS_isDefaultDecode(decodeMap) {
  44755. // XXX: Decoding is handled with the lab conversion because of the strange
  44756. // ranges that are used.
  44757. return true;
  44758. },
  44759. usesZeroToOneRange: false
  44760. };
  44761. return LabCS;
  44762. }();
  44763. exports.ColorSpace = ColorSpace;
  44764. }));
  44765. (function (root, factory) {
  44766. factory(root.pdfjsCoreImage = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCoreColorSpace, root.pdfjsCoreStream, root.pdfjsCoreJpx);
  44767. }(this, function (exports, sharedUtil, corePrimitives, coreColorSpace, coreStream, coreJpx) {
  44768. var ImageKind = sharedUtil.ImageKind;
  44769. var assert = sharedUtil.assert;
  44770. var error = sharedUtil.error;
  44771. var info = sharedUtil.info;
  44772. var isArray = sharedUtil.isArray;
  44773. var warn = sharedUtil.warn;
  44774. var Name = corePrimitives.Name;
  44775. var isStream = corePrimitives.isStream;
  44776. var ColorSpace = coreColorSpace.ColorSpace;
  44777. var DecodeStream = coreStream.DecodeStream;
  44778. var JpegStream = coreStream.JpegStream;
  44779. var JpxImage = coreJpx.JpxImage;
  44780. var PDFImage = function PDFImageClosure() {
  44781. /**
  44782. * Decodes the image using native decoder if possible. Resolves the promise
  44783. * when the image data is ready.
  44784. */
  44785. function handleImageData(image, nativeDecoder) {
  44786. if (nativeDecoder && nativeDecoder.canDecode(image)) {
  44787. return nativeDecoder.decode(image);
  44788. } else {
  44789. return Promise.resolve(image);
  44790. }
  44791. }
  44792. /**
  44793. * Decode and clamp a value. The formula is different from the spec because we
  44794. * don't decode to float range [0,1], we decode it in the [0,max] range.
  44795. */
  44796. function decodeAndClamp(value, addend, coefficient, max) {
  44797. value = addend + value * coefficient;
  44798. // Clamp the value to the range
  44799. return value < 0 ? 0 : value > max ? max : value;
  44800. }
  44801. /**
  44802. * Resizes an image mask with 1 component.
  44803. * @param {TypedArray} src - The source buffer.
  44804. * @param {Number} bpc - Number of bits per component.
  44805. * @param {Number} w1 - Original width.
  44806. * @param {Number} h1 - Original height.
  44807. * @param {Number} w2 - New width.
  44808. * @param {Number} h2 - New height.
  44809. * @returns {TypedArray} The resized image mask buffer.
  44810. */
  44811. function resizeImageMask(src, bpc, w1, h1, w2, h2) {
  44812. var length = w2 * h2;
  44813. var dest = bpc <= 8 ? new Uint8Array(length) : bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length);
  44814. var xRatio = w1 / w2;
  44815. var yRatio = h1 / h2;
  44816. var i, j, py, newIndex = 0, oldIndex;
  44817. var xScaled = new Uint16Array(w2);
  44818. var w1Scanline = w1;
  44819. for (i = 0; i < w2; i++) {
  44820. xScaled[i] = Math.floor(i * xRatio);
  44821. }
  44822. for (i = 0; i < h2; i++) {
  44823. py = Math.floor(i * yRatio) * w1Scanline;
  44824. for (j = 0; j < w2; j++) {
  44825. oldIndex = py + xScaled[j];
  44826. dest[newIndex++] = src[oldIndex];
  44827. }
  44828. }
  44829. return dest;
  44830. }
  44831. function PDFImage(xref, res, image, inline, smask, mask, isMask) {
  44832. this.image = image;
  44833. var dict = image.dict;
  44834. if (dict.has('Filter')) {
  44835. var filter = dict.get('Filter').name;
  44836. if (filter === 'JPXDecode') {
  44837. var jpxImage = new JpxImage();
  44838. jpxImage.parseImageProperties(image.stream);
  44839. image.stream.reset();
  44840. image.bitsPerComponent = jpxImage.bitsPerComponent;
  44841. image.numComps = jpxImage.componentsCount;
  44842. } else if (filter === 'JBIG2Decode') {
  44843. image.bitsPerComponent = 1;
  44844. image.numComps = 1;
  44845. }
  44846. }
  44847. // TODO cache rendered images?
  44848. this.width = dict.get('Width', 'W');
  44849. this.height = dict.get('Height', 'H');
  44850. if (this.width < 1 || this.height < 1) {
  44851. error('Invalid image width: ' + this.width + ' or height: ' + this.height);
  44852. }
  44853. this.interpolate = dict.get('Interpolate', 'I') || false;
  44854. this.imageMask = dict.get('ImageMask', 'IM') || false;
  44855. this.matte = dict.get('Matte') || false;
  44856. var bitsPerComponent = image.bitsPerComponent;
  44857. if (!bitsPerComponent) {
  44858. bitsPerComponent = dict.get('BitsPerComponent', 'BPC');
  44859. if (!bitsPerComponent) {
  44860. if (this.imageMask) {
  44861. bitsPerComponent = 1;
  44862. } else {
  44863. error('Bits per component missing in image: ' + this.imageMask);
  44864. }
  44865. }
  44866. }
  44867. this.bpc = bitsPerComponent;
  44868. if (!this.imageMask) {
  44869. var colorSpace = dict.get('ColorSpace', 'CS');
  44870. if (!colorSpace) {
  44871. info('JPX images (which do not require color spaces)');
  44872. switch (image.numComps) {
  44873. case 1:
  44874. colorSpace = Name.get('DeviceGray');
  44875. break;
  44876. case 3:
  44877. colorSpace = Name.get('DeviceRGB');
  44878. break;
  44879. case 4:
  44880. colorSpace = Name.get('DeviceCMYK');
  44881. break;
  44882. default:
  44883. error('JPX images with ' + this.numComps + ' color components not supported.');
  44884. }
  44885. }
  44886. this.colorSpace = ColorSpace.parse(colorSpace, xref, res);
  44887. this.numComps = this.colorSpace.numComps;
  44888. }
  44889. this.decode = dict.getArray('Decode', 'D');
  44890. this.needsDecode = false;
  44891. if (this.decode && (this.colorSpace && !this.colorSpace.isDefaultDecode(this.decode) || isMask && !ColorSpace.isDefaultDecode(this.decode, 1))) {
  44892. this.needsDecode = true;
  44893. // Do some preprocessing to avoid more math.
  44894. var max = (1 << bitsPerComponent) - 1;
  44895. this.decodeCoefficients = [];
  44896. this.decodeAddends = [];
  44897. for (var i = 0, j = 0; i < this.decode.length; i += 2, ++j) {
  44898. var dmin = this.decode[i];
  44899. var dmax = this.decode[i + 1];
  44900. this.decodeCoefficients[j] = dmax - dmin;
  44901. this.decodeAddends[j] = max * dmin;
  44902. }
  44903. }
  44904. if (smask) {
  44905. this.smask = new PDFImage(xref, res, smask, false);
  44906. } else if (mask) {
  44907. if (isStream(mask)) {
  44908. var maskDict = mask.dict, imageMask = maskDict.get('ImageMask', 'IM');
  44909. if (!imageMask) {
  44910. warn('Ignoring /Mask in image without /ImageMask.');
  44911. } else {
  44912. this.mask = new PDFImage(xref, res, mask, false, null, null, true);
  44913. }
  44914. } else {
  44915. // Color key mask (just an array).
  44916. this.mask = mask;
  44917. }
  44918. }
  44919. }
  44920. /**
  44921. * Handles processing of image data and returns the Promise that is resolved
  44922. * with a PDFImage when the image is ready to be used.
  44923. */
  44924. PDFImage.buildImage = function PDFImage_buildImage(handler, xref, res, image, inline, nativeDecoder) {
  44925. var imagePromise = handleImageData(image, nativeDecoder);
  44926. var smaskPromise;
  44927. var maskPromise;
  44928. var smask = image.dict.get('SMask');
  44929. var mask = image.dict.get('Mask');
  44930. if (smask) {
  44931. smaskPromise = handleImageData(smask, nativeDecoder);
  44932. maskPromise = Promise.resolve(null);
  44933. } else {
  44934. smaskPromise = Promise.resolve(null);
  44935. if (mask) {
  44936. if (isStream(mask)) {
  44937. maskPromise = handleImageData(mask, nativeDecoder);
  44938. } else if (isArray(mask)) {
  44939. maskPromise = Promise.resolve(mask);
  44940. } else {
  44941. warn('Unsupported mask format.');
  44942. maskPromise = Promise.resolve(null);
  44943. }
  44944. } else {
  44945. maskPromise = Promise.resolve(null);
  44946. }
  44947. }
  44948. return Promise.all([
  44949. imagePromise,
  44950. smaskPromise,
  44951. maskPromise
  44952. ]).then(function (results) {
  44953. var imageData = results[0];
  44954. var smaskData = results[1];
  44955. var maskData = results[2];
  44956. return new PDFImage(xref, res, imageData, inline, smaskData, maskData);
  44957. });
  44958. };
  44959. PDFImage.createMask = function PDFImage_createMask(imgArray, width, height, imageIsFromDecodeStream, inverseDecode) {
  44960. // |imgArray| might not contain full data for every pixel of the mask, so
  44961. // we need to distinguish between |computedLength| and |actualLength|.
  44962. // In particular, if inverseDecode is true, then the array we return must
  44963. // have a length of |computedLength|.
  44964. var computedLength = (width + 7 >> 3) * height;
  44965. var actualLength = imgArray.byteLength;
  44966. var haveFullData = computedLength === actualLength;
  44967. var data, i;
  44968. if (imageIsFromDecodeStream && (!inverseDecode || haveFullData)) {
  44969. // imgArray came from a DecodeStream and its data is in an appropriate
  44970. // form, so we can just transfer it.
  44971. data = imgArray;
  44972. } else if (!inverseDecode) {
  44973. data = new Uint8Array(actualLength);
  44974. data.set(imgArray);
  44975. } else {
  44976. data = new Uint8Array(computedLength);
  44977. data.set(imgArray);
  44978. for (i = actualLength; i < computedLength; i++) {
  44979. data[i] = 0xff;
  44980. }
  44981. }
  44982. // If necessary, invert the original mask data (but not any extra we might
  44983. // have added above). It's safe to modify the array -- whether it's the
  44984. // original or a copy, we're about to transfer it anyway, so nothing else
  44985. // in this thread can be relying on its contents.
  44986. if (inverseDecode) {
  44987. for (i = 0; i < actualLength; i++) {
  44988. data[i] = ~data[i];
  44989. }
  44990. }
  44991. return {
  44992. data: data,
  44993. width: width,
  44994. height: height
  44995. };
  44996. };
  44997. PDFImage.prototype = {
  44998. get drawWidth() {
  44999. return Math.max(this.width, this.smask && this.smask.width || 0, this.mask && this.mask.width || 0);
  45000. },
  45001. get drawHeight() {
  45002. return Math.max(this.height, this.smask && this.smask.height || 0, this.mask && this.mask.height || 0);
  45003. },
  45004. decodeBuffer: function PDFImage_decodeBuffer(buffer) {
  45005. var bpc = this.bpc;
  45006. var numComps = this.numComps;
  45007. var decodeAddends = this.decodeAddends;
  45008. var decodeCoefficients = this.decodeCoefficients;
  45009. var max = (1 << bpc) - 1;
  45010. var i, ii;
  45011. if (bpc === 1) {
  45012. // If the buffer needed decode that means it just needs to be inverted.
  45013. for (i = 0, ii = buffer.length; i < ii; i++) {
  45014. buffer[i] = +!buffer[i];
  45015. }
  45016. return;
  45017. }
  45018. var index = 0;
  45019. for (i = 0, ii = this.width * this.height; i < ii; i++) {
  45020. for (var j = 0; j < numComps; j++) {
  45021. buffer[index] = decodeAndClamp(buffer[index], decodeAddends[j], decodeCoefficients[j], max);
  45022. index++;
  45023. }
  45024. }
  45025. },
  45026. getComponents: function PDFImage_getComponents(buffer) {
  45027. var bpc = this.bpc;
  45028. // This image doesn't require any extra work.
  45029. if (bpc === 8) {
  45030. return buffer;
  45031. }
  45032. var width = this.width;
  45033. var height = this.height;
  45034. var numComps = this.numComps;
  45035. var length = width * height * numComps;
  45036. var bufferPos = 0;
  45037. var output = bpc <= 8 ? new Uint8Array(length) : bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length);
  45038. var rowComps = width * numComps;
  45039. var max = (1 << bpc) - 1;
  45040. var i = 0, ii, buf;
  45041. if (bpc === 1) {
  45042. // Optimization for reading 1 bpc images.
  45043. var mask, loop1End, loop2End;
  45044. for (var j = 0; j < height; j++) {
  45045. loop1End = i + (rowComps & ~7);
  45046. loop2End = i + rowComps;
  45047. // unroll loop for all full bytes
  45048. while (i < loop1End) {
  45049. buf = buffer[bufferPos++];
  45050. output[i] = buf >> 7 & 1;
  45051. output[i + 1] = buf >> 6 & 1;
  45052. output[i + 2] = buf >> 5 & 1;
  45053. output[i + 3] = buf >> 4 & 1;
  45054. output[i + 4] = buf >> 3 & 1;
  45055. output[i + 5] = buf >> 2 & 1;
  45056. output[i + 6] = buf >> 1 & 1;
  45057. output[i + 7] = buf & 1;
  45058. i += 8;
  45059. }
  45060. // handle remaining bits
  45061. if (i < loop2End) {
  45062. buf = buffer[bufferPos++];
  45063. mask = 128;
  45064. while (i < loop2End) {
  45065. output[i++] = +!!(buf & mask);
  45066. mask >>= 1;
  45067. }
  45068. }
  45069. }
  45070. } else {
  45071. // The general case that handles all other bpc values.
  45072. var bits = 0;
  45073. buf = 0;
  45074. for (i = 0, ii = length; i < ii; ++i) {
  45075. if (i % rowComps === 0) {
  45076. buf = 0;
  45077. bits = 0;
  45078. }
  45079. while (bits < bpc) {
  45080. buf = buf << 8 | buffer[bufferPos++];
  45081. bits += 8;
  45082. }
  45083. var remainingBits = bits - bpc;
  45084. var value = buf >> remainingBits;
  45085. output[i] = value < 0 ? 0 : value > max ? max : value;
  45086. buf = buf & (1 << remainingBits) - 1;
  45087. bits = remainingBits;
  45088. }
  45089. }
  45090. return output;
  45091. },
  45092. fillOpacity: function PDFImage_fillOpacity(rgbaBuf, width, height, actualHeight, image) {
  45093. var smask = this.smask;
  45094. var mask = this.mask;
  45095. var alphaBuf, sw, sh, i, ii, j;
  45096. if (smask) {
  45097. sw = smask.width;
  45098. sh = smask.height;
  45099. alphaBuf = new Uint8Array(sw * sh);
  45100. smask.fillGrayBuffer(alphaBuf);
  45101. if (sw !== width || sh !== height) {
  45102. alphaBuf = resizeImageMask(alphaBuf, smask.bpc, sw, sh, width, height);
  45103. }
  45104. } else if (mask) {
  45105. if (mask instanceof PDFImage) {
  45106. sw = mask.width;
  45107. sh = mask.height;
  45108. alphaBuf = new Uint8Array(sw * sh);
  45109. mask.numComps = 1;
  45110. mask.fillGrayBuffer(alphaBuf);
  45111. // Need to invert values in rgbaBuf
  45112. for (i = 0, ii = sw * sh; i < ii; ++i) {
  45113. alphaBuf[i] = 255 - alphaBuf[i];
  45114. }
  45115. if (sw !== width || sh !== height) {
  45116. alphaBuf = resizeImageMask(alphaBuf, mask.bpc, sw, sh, width, height);
  45117. }
  45118. } else if (isArray(mask)) {
  45119. // Color key mask: if any of the components are outside the range
  45120. // then they should be painted.
  45121. alphaBuf = new Uint8Array(width * height);
  45122. var numComps = this.numComps;
  45123. for (i = 0, ii = width * height; i < ii; ++i) {
  45124. var opacity = 0;
  45125. var imageOffset = i * numComps;
  45126. for (j = 0; j < numComps; ++j) {
  45127. var color = image[imageOffset + j];
  45128. var maskOffset = j * 2;
  45129. if (color < mask[maskOffset] || color > mask[maskOffset + 1]) {
  45130. opacity = 255;
  45131. break;
  45132. }
  45133. }
  45134. alphaBuf[i] = opacity;
  45135. }
  45136. } else {
  45137. error('Unknown mask format.');
  45138. }
  45139. }
  45140. if (alphaBuf) {
  45141. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  45142. rgbaBuf[j] = alphaBuf[i];
  45143. }
  45144. } else {
  45145. // No mask.
  45146. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  45147. rgbaBuf[j] = 255;
  45148. }
  45149. }
  45150. },
  45151. undoPreblend: function PDFImage_undoPreblend(buffer, width, height) {
  45152. var matte = this.smask && this.smask.matte;
  45153. if (!matte) {
  45154. return;
  45155. }
  45156. var matteRgb = this.colorSpace.getRgb(matte, 0);
  45157. var matteR = matteRgb[0];
  45158. var matteG = matteRgb[1];
  45159. var matteB = matteRgb[2];
  45160. var length = width * height * 4;
  45161. var r, g, b;
  45162. for (var i = 0; i < length; i += 4) {
  45163. var alpha = buffer[i + 3];
  45164. if (alpha === 0) {
  45165. // according formula we have to get Infinity in all components
  45166. // making it white (typical paper color) should be okay
  45167. buffer[i] = 255;
  45168. buffer[i + 1] = 255;
  45169. buffer[i + 2] = 255;
  45170. continue;
  45171. }
  45172. var k = 255 / alpha;
  45173. r = (buffer[i] - matteR) * k + matteR;
  45174. g = (buffer[i + 1] - matteG) * k + matteG;
  45175. b = (buffer[i + 2] - matteB) * k + matteB;
  45176. buffer[i] = r <= 0 ? 0 : r >= 255 ? 255 : r | 0;
  45177. buffer[i + 1] = g <= 0 ? 0 : g >= 255 ? 255 : g | 0;
  45178. buffer[i + 2] = b <= 0 ? 0 : b >= 255 ? 255 : b | 0;
  45179. }
  45180. },
  45181. createImageData: function PDFImage_createImageData(forceRGBA) {
  45182. var drawWidth = this.drawWidth;
  45183. var drawHeight = this.drawHeight;
  45184. var imgData = {
  45185. // other fields are filled in below
  45186. width: drawWidth,
  45187. height: drawHeight
  45188. };
  45189. var numComps = this.numComps;
  45190. var originalWidth = this.width;
  45191. var originalHeight = this.height;
  45192. var bpc = this.bpc;
  45193. // Rows start at byte boundary.
  45194. var rowBytes = originalWidth * numComps * bpc + 7 >> 3;
  45195. var imgArray;
  45196. if (!forceRGBA) {
  45197. // If it is a 1-bit-per-pixel grayscale (i.e. black-and-white) image
  45198. // without any complications, we pass a same-sized copy to the main
  45199. // thread rather than expanding by 32x to RGBA form. This saves *lots*
  45200. // of memory for many scanned documents. It's also much faster.
  45201. //
  45202. // Similarly, if it is a 24-bit-per pixel RGB image without any
  45203. // complications, we avoid expanding by 1.333x to RGBA form.
  45204. var kind;
  45205. if (this.colorSpace.name === 'DeviceGray' && bpc === 1) {
  45206. kind = ImageKind.GRAYSCALE_1BPP;
  45207. } else if (this.colorSpace.name === 'DeviceRGB' && bpc === 8 && !this.needsDecode) {
  45208. kind = ImageKind.RGB_24BPP;
  45209. }
  45210. if (kind && !this.smask && !this.mask && drawWidth === originalWidth && drawHeight === originalHeight) {
  45211. imgData.kind = kind;
  45212. imgArray = this.getImageBytes(originalHeight * rowBytes);
  45213. // If imgArray came from a DecodeStream, we're safe to transfer it
  45214. // (and thus detach its underlying buffer) because it will constitute
  45215. // the entire DecodeStream's data. But if it came from a Stream, we
  45216. // need to copy it because it'll only be a portion of the Stream's
  45217. // data, and the rest will be read later on.
  45218. if (this.image instanceof DecodeStream) {
  45219. imgData.data = imgArray;
  45220. } else {
  45221. var newArray = new Uint8Array(imgArray.length);
  45222. newArray.set(imgArray);
  45223. imgData.data = newArray;
  45224. }
  45225. if (this.needsDecode) {
  45226. // Invert the buffer (which must be grayscale if we reached here).
  45227. assert(kind === ImageKind.GRAYSCALE_1BPP);
  45228. var buffer = imgData.data;
  45229. for (var i = 0, ii = buffer.length; i < ii; i++) {
  45230. buffer[i] ^= 0xff;
  45231. }
  45232. }
  45233. return imgData;
  45234. }
  45235. if (this.image instanceof JpegStream && !this.smask && !this.mask && (this.colorSpace.name === 'DeviceGray' || this.colorSpace.name === 'DeviceRGB' || this.colorSpace.name === 'DeviceCMYK')) {
  45236. imgData.kind = ImageKind.RGB_24BPP;
  45237. imgData.data = this.getImageBytes(originalHeight * rowBytes, drawWidth, drawHeight, true);
  45238. return imgData;
  45239. }
  45240. }
  45241. imgArray = this.getImageBytes(originalHeight * rowBytes);
  45242. // imgArray can be incomplete (e.g. after CCITT fax encoding).
  45243. var actualHeight = 0 | imgArray.length / rowBytes * drawHeight / originalHeight;
  45244. var comps = this.getComponents(imgArray);
  45245. // If opacity data is present, use RGBA_32BPP form. Otherwise, use the
  45246. // more compact RGB_24BPP form if allowable.
  45247. var alpha01, maybeUndoPreblend;
  45248. if (!forceRGBA && !this.smask && !this.mask) {
  45249. imgData.kind = ImageKind.RGB_24BPP;
  45250. imgData.data = new Uint8Array(drawWidth * drawHeight * 3);
  45251. alpha01 = 0;
  45252. maybeUndoPreblend = false;
  45253. } else {
  45254. imgData.kind = ImageKind.RGBA_32BPP;
  45255. imgData.data = new Uint8Array(drawWidth * drawHeight * 4);
  45256. alpha01 = 1;
  45257. maybeUndoPreblend = true;
  45258. // Color key masking (opacity) must be performed before decoding.
  45259. this.fillOpacity(imgData.data, drawWidth, drawHeight, actualHeight, comps);
  45260. }
  45261. if (this.needsDecode) {
  45262. this.decodeBuffer(comps);
  45263. }
  45264. this.colorSpace.fillRgb(imgData.data, originalWidth, originalHeight, drawWidth, drawHeight, actualHeight, bpc, comps, alpha01);
  45265. if (maybeUndoPreblend) {
  45266. this.undoPreblend(imgData.data, drawWidth, actualHeight);
  45267. }
  45268. return imgData;
  45269. },
  45270. fillGrayBuffer: function PDFImage_fillGrayBuffer(buffer) {
  45271. var numComps = this.numComps;
  45272. if (numComps !== 1) {
  45273. error('Reading gray scale from a color image: ' + numComps);
  45274. }
  45275. var width = this.width;
  45276. var height = this.height;
  45277. var bpc = this.bpc;
  45278. // rows start at byte boundary
  45279. var rowBytes = width * numComps * bpc + 7 >> 3;
  45280. var imgArray = this.getImageBytes(height * rowBytes);
  45281. var comps = this.getComponents(imgArray);
  45282. var i, length;
  45283. if (bpc === 1) {
  45284. // inline decoding (= inversion) for 1 bpc images
  45285. length = width * height;
  45286. if (this.needsDecode) {
  45287. // invert and scale to {0, 255}
  45288. for (i = 0; i < length; ++i) {
  45289. buffer[i] = comps[i] - 1 & 255;
  45290. }
  45291. } else {
  45292. // scale to {0, 255}
  45293. for (i = 0; i < length; ++i) {
  45294. buffer[i] = -comps[i] & 255;
  45295. }
  45296. }
  45297. return;
  45298. }
  45299. if (this.needsDecode) {
  45300. this.decodeBuffer(comps);
  45301. }
  45302. length = width * height;
  45303. // we aren't using a colorspace so we need to scale the value
  45304. var scale = 255 / ((1 << bpc) - 1);
  45305. for (i = 0; i < length; ++i) {
  45306. buffer[i] = scale * comps[i] | 0;
  45307. }
  45308. },
  45309. getImageBytes: function PDFImage_getImageBytes(length, drawWidth, drawHeight, forceRGB) {
  45310. this.image.reset();
  45311. this.image.drawWidth = drawWidth || this.width;
  45312. this.image.drawHeight = drawHeight || this.height;
  45313. this.image.forceRGB = !!forceRGB;
  45314. return this.image.getBytes(length);
  45315. }
  45316. };
  45317. return PDFImage;
  45318. }();
  45319. exports.PDFImage = PDFImage;
  45320. }));
  45321. (function (root, factory) {
  45322. factory(root.pdfjsCoreObj = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCoreCrypto, root.pdfjsCoreParser, root.pdfjsCoreChunkedStream, root.pdfjsCoreColorSpace);
  45323. }(this, function (exports, sharedUtil, corePrimitives, coreCrypto, coreParser, coreChunkedStream, coreColorSpace) {
  45324. var InvalidPDFException = sharedUtil.InvalidPDFException;
  45325. var MissingDataException = sharedUtil.MissingDataException;
  45326. var XRefParseException = sharedUtil.XRefParseException;
  45327. var assert = sharedUtil.assert;
  45328. var bytesToString = sharedUtil.bytesToString;
  45329. var createPromiseCapability = sharedUtil.createPromiseCapability;
  45330. var error = sharedUtil.error;
  45331. var info = sharedUtil.info;
  45332. var isArray = sharedUtil.isArray;
  45333. var isInt = sharedUtil.isInt;
  45334. var isString = sharedUtil.isString;
  45335. var shadow = sharedUtil.shadow;
  45336. var stringToPDFString = sharedUtil.stringToPDFString;
  45337. var stringToUTF8String = sharedUtil.stringToUTF8String;
  45338. var warn = sharedUtil.warn;
  45339. var isValidUrl = sharedUtil.isValidUrl;
  45340. var Util = sharedUtil.Util;
  45341. var Ref = corePrimitives.Ref;
  45342. var RefSet = corePrimitives.RefSet;
  45343. var RefSetCache = corePrimitives.RefSetCache;
  45344. var isName = corePrimitives.isName;
  45345. var isCmd = corePrimitives.isCmd;
  45346. var isDict = corePrimitives.isDict;
  45347. var isRef = corePrimitives.isRef;
  45348. var isRefsEqual = corePrimitives.isRefsEqual;
  45349. var isStream = corePrimitives.isStream;
  45350. var CipherTransformFactory = coreCrypto.CipherTransformFactory;
  45351. var Lexer = coreParser.Lexer;
  45352. var Parser = coreParser.Parser;
  45353. var ChunkedStream = coreChunkedStream.ChunkedStream;
  45354. var ColorSpace = coreColorSpace.ColorSpace;
  45355. var Catalog = function CatalogClosure() {
  45356. function Catalog(pdfManager, xref, pageFactory) {
  45357. this.pdfManager = pdfManager;
  45358. this.xref = xref;
  45359. this.catDict = xref.getCatalogObj();
  45360. this.fontCache = new RefSetCache();
  45361. assert(isDict(this.catDict), 'catalog object is not a dictionary');
  45362. // TODO refactor to move getPage() to the PDFDocument.
  45363. this.pageFactory = pageFactory;
  45364. this.pagePromises = [];
  45365. }
  45366. Catalog.prototype = {
  45367. get metadata() {
  45368. var streamRef = this.catDict.getRaw('Metadata');
  45369. if (!isRef(streamRef)) {
  45370. return shadow(this, 'metadata', null);
  45371. }
  45372. var encryptMetadata = !this.xref.encrypt ? false : this.xref.encrypt.encryptMetadata;
  45373. var stream = this.xref.fetch(streamRef, !encryptMetadata);
  45374. var metadata;
  45375. if (stream && isDict(stream.dict)) {
  45376. var type = stream.dict.get('Type');
  45377. var subtype = stream.dict.get('Subtype');
  45378. if (isName(type, 'Metadata') && isName(subtype, 'XML')) {
  45379. // XXX: This should examine the charset the XML document defines,
  45380. // however since there are currently no real means to decode
  45381. // arbitrary charsets, let's just hope that the author of the PDF
  45382. // was reasonable enough to stick with the XML default charset,
  45383. // which is UTF-8.
  45384. try {
  45385. metadata = stringToUTF8String(bytesToString(stream.getBytes()));
  45386. } catch (e) {
  45387. info('Skipping invalid metadata.');
  45388. }
  45389. }
  45390. }
  45391. return shadow(this, 'metadata', metadata);
  45392. },
  45393. get toplevelPagesDict() {
  45394. var pagesObj = this.catDict.get('Pages');
  45395. assert(isDict(pagesObj), 'invalid top-level pages dictionary');
  45396. // shadow the prototype getter
  45397. return shadow(this, 'toplevelPagesDict', pagesObj);
  45398. },
  45399. get documentOutline() {
  45400. var obj = null;
  45401. try {
  45402. obj = this.readDocumentOutline();
  45403. } catch (ex) {
  45404. if (ex instanceof MissingDataException) {
  45405. throw ex;
  45406. }
  45407. warn('Unable to read document outline');
  45408. }
  45409. return shadow(this, 'documentOutline', obj);
  45410. },
  45411. readDocumentOutline: function Catalog_readDocumentOutline() {
  45412. var obj = this.catDict.get('Outlines');
  45413. if (!isDict(obj)) {
  45414. return null;
  45415. }
  45416. obj = obj.getRaw('First');
  45417. if (!isRef(obj)) {
  45418. return null;
  45419. }
  45420. var root = { items: [] };
  45421. var queue = [{
  45422. obj: obj,
  45423. parent: root
  45424. }];
  45425. // To avoid recursion, keep track of the already processed items.
  45426. var processed = new RefSet();
  45427. processed.put(obj);
  45428. var xref = this.xref, blackColor = new Uint8Array(3);
  45429. while (queue.length > 0) {
  45430. var i = queue.shift();
  45431. var outlineDict = xref.fetchIfRef(i.obj);
  45432. if (outlineDict === null) {
  45433. continue;
  45434. }
  45435. assert(outlineDict.has('Title'), 'Invalid outline item');
  45436. var actionDict = outlineDict.get('A'), dest = null, url = null;
  45437. if (actionDict) {
  45438. var destEntry = actionDict.get('D');
  45439. if (destEntry) {
  45440. dest = destEntry;
  45441. } else {
  45442. var uriEntry = actionDict.get('URI');
  45443. if (isString(uriEntry) && isValidUrl(uriEntry, false)) {
  45444. url = uriEntry;
  45445. }
  45446. }
  45447. } else if (outlineDict.has('Dest')) {
  45448. dest = outlineDict.getRaw('Dest');
  45449. if (isName(dest)) {
  45450. dest = dest.name;
  45451. }
  45452. }
  45453. var title = outlineDict.get('Title');
  45454. var flags = outlineDict.get('F') || 0;
  45455. var color = outlineDict.getArray('C'), rgbColor = blackColor;
  45456. // We only need to parse the color when it's valid, and non-default.
  45457. if (isArray(color) && color.length === 3 && (color[0] !== 0 || color[1] !== 0 || color[2] !== 0)) {
  45458. rgbColor = ColorSpace.singletons.rgb.getRgb(color, 0);
  45459. }
  45460. var outlineItem = {
  45461. dest: dest,
  45462. url: url,
  45463. title: stringToPDFString(title),
  45464. color: rgbColor,
  45465. count: outlineDict.get('Count'),
  45466. bold: !!(flags & 2),
  45467. italic: !!(flags & 1),
  45468. items: []
  45469. };
  45470. i.parent.items.push(outlineItem);
  45471. obj = outlineDict.getRaw('First');
  45472. if (isRef(obj) && !processed.has(obj)) {
  45473. queue.push({
  45474. obj: obj,
  45475. parent: outlineItem
  45476. });
  45477. processed.put(obj);
  45478. }
  45479. obj = outlineDict.getRaw('Next');
  45480. if (isRef(obj) && !processed.has(obj)) {
  45481. queue.push({
  45482. obj: obj,
  45483. parent: i.parent
  45484. });
  45485. processed.put(obj);
  45486. }
  45487. }
  45488. return root.items.length > 0 ? root.items : null;
  45489. },
  45490. get numPages() {
  45491. var obj = this.toplevelPagesDict.get('Count');
  45492. assert(isInt(obj), 'page count in top level pages object is not an integer');
  45493. // shadow the prototype getter
  45494. return shadow(this, 'num', obj);
  45495. },
  45496. get destinations() {
  45497. function fetchDestination(dest) {
  45498. return isDict(dest) ? dest.get('D') : dest;
  45499. }
  45500. var xref = this.xref;
  45501. var dests = {}, nameTreeRef, nameDictionaryRef;
  45502. var obj = this.catDict.get('Names');
  45503. if (obj && obj.has('Dests')) {
  45504. nameTreeRef = obj.getRaw('Dests');
  45505. } else if (this.catDict.has('Dests')) {
  45506. nameDictionaryRef = this.catDict.get('Dests');
  45507. }
  45508. if (nameDictionaryRef) {
  45509. // reading simple destination dictionary
  45510. obj = nameDictionaryRef;
  45511. obj.forEach(function catalogForEach(key, value) {
  45512. if (!value) {
  45513. return;
  45514. }
  45515. dests[key] = fetchDestination(value);
  45516. });
  45517. }
  45518. if (nameTreeRef) {
  45519. var nameTree = new NameTree(nameTreeRef, xref);
  45520. var names = nameTree.getAll();
  45521. for (var name in names) {
  45522. dests[name] = fetchDestination(names[name]);
  45523. }
  45524. }
  45525. return shadow(this, 'destinations', dests);
  45526. },
  45527. getDestination: function Catalog_getDestination(destinationId) {
  45528. function fetchDestination(dest) {
  45529. return isDict(dest) ? dest.get('D') : dest;
  45530. }
  45531. var xref = this.xref;
  45532. var dest = null, nameTreeRef, nameDictionaryRef;
  45533. var obj = this.catDict.get('Names');
  45534. if (obj && obj.has('Dests')) {
  45535. nameTreeRef = obj.getRaw('Dests');
  45536. } else if (this.catDict.has('Dests')) {
  45537. nameDictionaryRef = this.catDict.get('Dests');
  45538. }
  45539. if (nameDictionaryRef) {
  45540. // Simple destination dictionary.
  45541. var value = nameDictionaryRef.get(destinationId);
  45542. if (value) {
  45543. dest = fetchDestination(value);
  45544. }
  45545. }
  45546. if (nameTreeRef) {
  45547. var nameTree = new NameTree(nameTreeRef, xref);
  45548. dest = fetchDestination(nameTree.get(destinationId));
  45549. }
  45550. return dest;
  45551. },
  45552. get pageLabels() {
  45553. var obj = null;
  45554. try {
  45555. obj = this.readPageLabels();
  45556. } catch (ex) {
  45557. if (ex instanceof MissingDataException) {
  45558. throw ex;
  45559. }
  45560. warn('Unable to read page labels.');
  45561. }
  45562. return shadow(this, 'pageLabels', obj);
  45563. },
  45564. readPageLabels: function Catalog_readPageLabels() {
  45565. var obj = this.catDict.getRaw('PageLabels');
  45566. if (!obj) {
  45567. return null;
  45568. }
  45569. var pageLabels = new Array(this.numPages);
  45570. var style = null;
  45571. var prefix = '';
  45572. var start = 1;
  45573. var numberTree = new NumberTree(obj, this.xref);
  45574. var nums = numberTree.getAll();
  45575. var currentLabel = '', currentIndex = 1;
  45576. for (var i = 0, ii = this.numPages; i < ii; i++) {
  45577. if (i in nums) {
  45578. var labelDict = nums[i];
  45579. assert(isDict(labelDict), 'The PageLabel is not a dictionary.');
  45580. var type = labelDict.get('Type');
  45581. assert(!type || isName(type, 'PageLabel'), 'Invalid type in PageLabel dictionary.');
  45582. var s = labelDict.get('S');
  45583. assert(!s || isName(s), 'Invalid style in PageLabel dictionary.');
  45584. style = s ? s.name : null;
  45585. prefix = labelDict.get('P') || '';
  45586. assert(isString(prefix), 'Invalid prefix in PageLabel dictionary.');
  45587. start = labelDict.get('St') || 1;
  45588. assert(isInt(start), 'Invalid start in PageLabel dictionary.');
  45589. currentIndex = start;
  45590. }
  45591. switch (style) {
  45592. case 'D':
  45593. currentLabel = currentIndex;
  45594. break;
  45595. case 'R':
  45596. case 'r':
  45597. currentLabel = Util.toRoman(currentIndex, style === 'r');
  45598. break;
  45599. case 'A':
  45600. case 'a':
  45601. var LIMIT = 26;
  45602. // Use only the characters A--Z, or a--z.
  45603. var A_UPPER_CASE = 0x41, A_LOWER_CASE = 0x61;
  45604. var baseCharCode = style === 'a' ? A_LOWER_CASE : A_UPPER_CASE;
  45605. var letterIndex = currentIndex - 1;
  45606. var character = String.fromCharCode(baseCharCode + letterIndex % LIMIT);
  45607. var charBuf = [];
  45608. for (var j = 0, jj = letterIndex / LIMIT | 0; j <= jj; j++) {
  45609. charBuf.push(character);
  45610. }
  45611. currentLabel = charBuf.join('');
  45612. break;
  45613. default:
  45614. assert(!style, 'Invalid style "' + style + '" in PageLabel dictionary.');
  45615. }
  45616. pageLabels[i] = prefix + currentLabel;
  45617. currentLabel = '';
  45618. currentIndex++;
  45619. }
  45620. return pageLabels;
  45621. },
  45622. get attachments() {
  45623. var xref = this.xref;
  45624. var attachments = null, nameTreeRef;
  45625. var obj = this.catDict.get('Names');
  45626. if (obj) {
  45627. nameTreeRef = obj.getRaw('EmbeddedFiles');
  45628. }
  45629. if (nameTreeRef) {
  45630. var nameTree = new NameTree(nameTreeRef, xref);
  45631. var names = nameTree.getAll();
  45632. for (var name in names) {
  45633. var fs = new FileSpec(names[name], xref);
  45634. if (!attachments) {
  45635. attachments = Object.create(null);
  45636. }
  45637. attachments[stringToPDFString(name)] = fs.serializable;
  45638. }
  45639. }
  45640. return shadow(this, 'attachments', attachments);
  45641. },
  45642. get javaScript() {
  45643. var xref = this.xref;
  45644. var obj = this.catDict.get('Names');
  45645. var javaScript = [];
  45646. function appendIfJavaScriptDict(jsDict) {
  45647. var type = jsDict.get('S');
  45648. if (!isName(type, 'JavaScript')) {
  45649. return;
  45650. }
  45651. var js = jsDict.get('JS');
  45652. if (isStream(js)) {
  45653. js = bytesToString(js.getBytes());
  45654. } else if (!isString(js)) {
  45655. return;
  45656. }
  45657. javaScript.push(stringToPDFString(js));
  45658. }
  45659. if (obj && obj.has('JavaScript')) {
  45660. var nameTree = new NameTree(obj.getRaw('JavaScript'), xref);
  45661. var names = nameTree.getAll();
  45662. for (var name in names) {
  45663. // We don't really use the JavaScript right now. This code is
  45664. // defensive so we don't cause errors on document load.
  45665. var jsDict = names[name];
  45666. if (isDict(jsDict)) {
  45667. appendIfJavaScriptDict(jsDict);
  45668. }
  45669. }
  45670. }
  45671. // Append OpenAction actions to javaScript array
  45672. var openactionDict = this.catDict.get('OpenAction');
  45673. if (isDict(openactionDict, 'Action')) {
  45674. var actionType = openactionDict.get('S');
  45675. if (isName(actionType, 'Named')) {
  45676. // The named Print action is not a part of the PDF 1.7 specification,
  45677. // but is supported by many PDF readers/writers (including Adobe's).
  45678. var action = openactionDict.get('N');
  45679. if (isName(action, 'Print')) {
  45680. javaScript.push('print({});');
  45681. }
  45682. } else {
  45683. appendIfJavaScriptDict(openactionDict);
  45684. }
  45685. }
  45686. return shadow(this, 'javaScript', javaScript);
  45687. },
  45688. cleanup: function Catalog_cleanup() {
  45689. var promises = [];
  45690. this.fontCache.forEach(function (promise) {
  45691. promises.push(promise);
  45692. });
  45693. return Promise.all(promises).then(function (translatedFonts) {
  45694. for (var i = 0, ii = translatedFonts.length; i < ii; i++) {
  45695. var font = translatedFonts[i].dict;
  45696. delete font.translated;
  45697. }
  45698. this.fontCache.clear();
  45699. }.bind(this));
  45700. },
  45701. getPage: function Catalog_getPage(pageIndex) {
  45702. if (!(pageIndex in this.pagePromises)) {
  45703. this.pagePromises[pageIndex] = this.getPageDict(pageIndex).then(function (a) {
  45704. var dict = a[0];
  45705. var ref = a[1];
  45706. return this.pageFactory.createPage(pageIndex, dict, ref, this.fontCache);
  45707. }.bind(this));
  45708. }
  45709. return this.pagePromises[pageIndex];
  45710. },
  45711. getPageDict: function Catalog_getPageDict(pageIndex) {
  45712. var capability = createPromiseCapability();
  45713. var nodesToVisit = [this.catDict.getRaw('Pages')];
  45714. var currentPageIndex = 0;
  45715. var xref = this.xref;
  45716. var checkAllKids = false;
  45717. function next() {
  45718. while (nodesToVisit.length) {
  45719. var currentNode = nodesToVisit.pop();
  45720. if (isRef(currentNode)) {
  45721. xref.fetchAsync(currentNode).then(function (obj) {
  45722. if (isDict(obj, 'Page') || isDict(obj) && !obj.has('Kids')) {
  45723. if (pageIndex === currentPageIndex) {
  45724. capability.resolve([
  45725. obj,
  45726. currentNode
  45727. ]);
  45728. } else {
  45729. currentPageIndex++;
  45730. next();
  45731. }
  45732. return;
  45733. }
  45734. nodesToVisit.push(obj);
  45735. next();
  45736. }, capability.reject);
  45737. return;
  45738. }
  45739. // Must be a child page dictionary.
  45740. assert(isDict(currentNode), 'page dictionary kid reference points to wrong type of object');
  45741. var count = currentNode.get('Count');
  45742. // If the current node doesn't have any children, avoid getting stuck
  45743. // in an empty node further down in the tree (see issue5644.pdf).
  45744. if (count === 0) {
  45745. checkAllKids = true;
  45746. }
  45747. // Skip nodes where the page can't be.
  45748. if (currentPageIndex + count <= pageIndex) {
  45749. currentPageIndex += count;
  45750. continue;
  45751. }
  45752. var kids = currentNode.get('Kids');
  45753. assert(isArray(kids), 'page dictionary kids object is not an array');
  45754. if (!checkAllKids && count === kids.length) {
  45755. // Nodes that don't have the page have been skipped and this is the
  45756. // bottom of the tree which means the page requested must be a
  45757. // descendant of this pages node. Ideally we would just resolve the
  45758. // promise with the page ref here, but there is the case where more
  45759. // pages nodes could link to single a page (see issue 3666 pdf). To
  45760. // handle this push it back on the queue so if it is a pages node it
  45761. // will be descended into.
  45762. nodesToVisit = [kids[pageIndex - currentPageIndex]];
  45763. currentPageIndex = pageIndex;
  45764. continue;
  45765. } else {
  45766. for (var last = kids.length - 1; last >= 0; last--) {
  45767. nodesToVisit.push(kids[last]);
  45768. }
  45769. }
  45770. }
  45771. capability.reject('Page index ' + pageIndex + ' not found.');
  45772. }
  45773. next();
  45774. return capability.promise;
  45775. },
  45776. getPageIndex: function Catalog_getPageIndex(pageRef) {
  45777. // The page tree nodes have the count of all the leaves below them. To get
  45778. // how many pages are before we just have to walk up the tree and keep
  45779. // adding the count of siblings to the left of the node.
  45780. var xref = this.xref;
  45781. function pagesBeforeRef(kidRef) {
  45782. var total = 0;
  45783. var parentRef;
  45784. return xref.fetchAsync(kidRef).then(function (node) {
  45785. if (isRefsEqual(kidRef, pageRef) && !isDict(node, 'Page') && !(isDict(node) && !node.has('Type') && node.has('Contents'))) {
  45786. throw new Error('The reference does not point to a /Page Dict.');
  45787. }
  45788. if (!node) {
  45789. return null;
  45790. }
  45791. assert(isDict(node), 'node must be a Dict.');
  45792. parentRef = node.getRaw('Parent');
  45793. return node.getAsync('Parent');
  45794. }).then(function (parent) {
  45795. if (!parent) {
  45796. return null;
  45797. }
  45798. assert(isDict(parent), 'parent must be a Dict.');
  45799. return parent.getAsync('Kids');
  45800. }).then(function (kids) {
  45801. if (!kids) {
  45802. return null;
  45803. }
  45804. var kidPromises = [];
  45805. var found = false;
  45806. for (var i = 0; i < kids.length; i++) {
  45807. var kid = kids[i];
  45808. assert(isRef(kid), 'kid must be a Ref.');
  45809. if (kid.num === kidRef.num) {
  45810. found = true;
  45811. break;
  45812. }
  45813. kidPromises.push(xref.fetchAsync(kid).then(function (kid) {
  45814. if (kid.has('Count')) {
  45815. var count = kid.get('Count');
  45816. total += count;
  45817. } else {
  45818. // page leaf node
  45819. total++;
  45820. }
  45821. }));
  45822. }
  45823. if (!found) {
  45824. error('kid ref not found in parents kids');
  45825. }
  45826. return Promise.all(kidPromises).then(function () {
  45827. return [
  45828. total,
  45829. parentRef
  45830. ];
  45831. });
  45832. });
  45833. }
  45834. var total = 0;
  45835. function next(ref) {
  45836. return pagesBeforeRef(ref).then(function (args) {
  45837. if (!args) {
  45838. return total;
  45839. }
  45840. var count = args[0];
  45841. var parentRef = args[1];
  45842. total += count;
  45843. return next(parentRef);
  45844. });
  45845. }
  45846. return next(pageRef);
  45847. }
  45848. };
  45849. return Catalog;
  45850. }();
  45851. var XRef = function XRefClosure() {
  45852. function XRef(stream, password) {
  45853. this.stream = stream;
  45854. this.entries = [];
  45855. this.xrefstms = Object.create(null);
  45856. // prepare the XRef cache
  45857. this.cache = [];
  45858. this.password = password;
  45859. this.stats = {
  45860. streamTypes: [],
  45861. fontTypes: []
  45862. };
  45863. }
  45864. XRef.prototype = {
  45865. setStartXRef: function XRef_setStartXRef(startXRef) {
  45866. // Store the starting positions of xref tables as we process them
  45867. // so we can recover from missing data errors
  45868. this.startXRefQueue = [startXRef];
  45869. },
  45870. parse: function XRef_parse(recoveryMode) {
  45871. var trailerDict;
  45872. if (!recoveryMode) {
  45873. trailerDict = this.readXRef();
  45874. } else {
  45875. warn('Indexing all PDF objects');
  45876. trailerDict = this.indexObjects();
  45877. }
  45878. trailerDict.assignXref(this);
  45879. this.trailer = trailerDict;
  45880. var encrypt = trailerDict.get('Encrypt');
  45881. if (encrypt) {
  45882. var ids = trailerDict.get('ID');
  45883. var fileId = ids && ids.length ? ids[0] : '';
  45884. // The 'Encrypt' dictionary itself should not be encrypted, and by
  45885. // setting `suppressEncryption` we can prevent an infinite loop inside
  45886. // of `XRef_fetchUncompressed` if the dictionary contains indirect
  45887. // objects (fixes issue7665.pdf).
  45888. encrypt.suppressEncryption = true;
  45889. this.encrypt = new CipherTransformFactory(encrypt, fileId, this.password);
  45890. }
  45891. // get the root dictionary (catalog) object
  45892. if (!(this.root = trailerDict.get('Root'))) {
  45893. error('Invalid root reference');
  45894. }
  45895. },
  45896. processXRefTable: function XRef_processXRefTable(parser) {
  45897. if (!('tableState' in this)) {
  45898. // Stores state of the table as we process it so we can resume
  45899. // from middle of table in case of missing data error
  45900. this.tableState = {
  45901. entryNum: 0,
  45902. streamPos: parser.lexer.stream.pos,
  45903. parserBuf1: parser.buf1,
  45904. parserBuf2: parser.buf2
  45905. };
  45906. }
  45907. var obj = this.readXRefTable(parser);
  45908. // Sanity check
  45909. if (!isCmd(obj, 'trailer')) {
  45910. error('Invalid XRef table: could not find trailer dictionary');
  45911. }
  45912. // Read trailer dictionary, e.g.
  45913. // trailer
  45914. // << /Size 22
  45915. // /Root 20R
  45916. // /Info 10R
  45917. // /ID [ <81b14aafa313db63dbd6f981e49f94f4> ]
  45918. // >>
  45919. // The parser goes through the entire stream << ... >> and provides
  45920. // a getter interface for the key-value table
  45921. var dict = parser.getObj();
  45922. // The pdflib PDF generator can generate a nested trailer dictionary
  45923. if (!isDict(dict) && dict.dict) {
  45924. dict = dict.dict;
  45925. }
  45926. if (!isDict(dict)) {
  45927. error('Invalid XRef table: could not parse trailer dictionary');
  45928. }
  45929. delete this.tableState;
  45930. return dict;
  45931. },
  45932. readXRefTable: function XRef_readXRefTable(parser) {
  45933. // Example of cross-reference table:
  45934. // xref
  45935. // 0 1 <-- subsection header (first obj #, obj count)
  45936. // 0000000000 65535 f <-- actual object (offset, generation #, f/n)
  45937. // 23 2 <-- subsection header ... and so on ...
  45938. // 0000025518 00002 n
  45939. // 0000025635 00000 n
  45940. // trailer
  45941. // ...
  45942. var stream = parser.lexer.stream;
  45943. var tableState = this.tableState;
  45944. stream.pos = tableState.streamPos;
  45945. parser.buf1 = tableState.parserBuf1;
  45946. parser.buf2 = tableState.parserBuf2;
  45947. // Outer loop is over subsection headers
  45948. var obj;
  45949. while (true) {
  45950. if (!('firstEntryNum' in tableState) || !('entryCount' in tableState)) {
  45951. if (isCmd(obj = parser.getObj(), 'trailer')) {
  45952. break;
  45953. }
  45954. tableState.firstEntryNum = obj;
  45955. tableState.entryCount = parser.getObj();
  45956. }
  45957. var first = tableState.firstEntryNum;
  45958. var count = tableState.entryCount;
  45959. if (!isInt(first) || !isInt(count)) {
  45960. error('Invalid XRef table: wrong types in subsection header');
  45961. }
  45962. // Inner loop is over objects themselves
  45963. for (var i = tableState.entryNum; i < count; i++) {
  45964. tableState.streamPos = stream.pos;
  45965. tableState.entryNum = i;
  45966. tableState.parserBuf1 = parser.buf1;
  45967. tableState.parserBuf2 = parser.buf2;
  45968. var entry = {};
  45969. entry.offset = parser.getObj();
  45970. entry.gen = parser.getObj();
  45971. var type = parser.getObj();
  45972. if (isCmd(type, 'f')) {
  45973. entry.free = true;
  45974. } else if (isCmd(type, 'n')) {
  45975. entry.uncompressed = true;
  45976. }
  45977. // Validate entry obj
  45978. if (!isInt(entry.offset) || !isInt(entry.gen) || !(entry.free || entry.uncompressed)) {
  45979. error('Invalid entry in XRef subsection: ' + first + ', ' + count);
  45980. }
  45981. // The first xref table entry, i.e. obj 0, should be free. Attempting
  45982. // to adjust an incorrect first obj # (fixes issue 3248 and 7229).
  45983. if (i === 0 && entry.free && first === 1) {
  45984. first = 0;
  45985. }
  45986. if (!this.entries[i + first]) {
  45987. this.entries[i + first] = entry;
  45988. }
  45989. }
  45990. tableState.entryNum = 0;
  45991. tableState.streamPos = stream.pos;
  45992. tableState.parserBuf1 = parser.buf1;
  45993. tableState.parserBuf2 = parser.buf2;
  45994. delete tableState.firstEntryNum;
  45995. delete tableState.entryCount;
  45996. }
  45997. // Sanity check: as per spec, first object must be free
  45998. if (this.entries[0] && !this.entries[0].free) {
  45999. error('Invalid XRef table: unexpected first object');
  46000. }
  46001. return obj;
  46002. },
  46003. processXRefStream: function XRef_processXRefStream(stream) {
  46004. if (!('streamState' in this)) {
  46005. // Stores state of the stream as we process it so we can resume
  46006. // from middle of stream in case of missing data error
  46007. var streamParameters = stream.dict;
  46008. var byteWidths = streamParameters.get('W');
  46009. var range = streamParameters.get('Index');
  46010. if (!range) {
  46011. range = [
  46012. 0,
  46013. streamParameters.get('Size')
  46014. ];
  46015. }
  46016. this.streamState = {
  46017. entryRanges: range,
  46018. byteWidths: byteWidths,
  46019. entryNum: 0,
  46020. streamPos: stream.pos
  46021. };
  46022. }
  46023. this.readXRefStream(stream);
  46024. delete this.streamState;
  46025. return stream.dict;
  46026. },
  46027. readXRefStream: function XRef_readXRefStream(stream) {
  46028. var i, j;
  46029. var streamState = this.streamState;
  46030. stream.pos = streamState.streamPos;
  46031. var byteWidths = streamState.byteWidths;
  46032. var typeFieldWidth = byteWidths[0];
  46033. var offsetFieldWidth = byteWidths[1];
  46034. var generationFieldWidth = byteWidths[2];
  46035. var entryRanges = streamState.entryRanges;
  46036. while (entryRanges.length > 0) {
  46037. var first = entryRanges[0];
  46038. var n = entryRanges[1];
  46039. if (!isInt(first) || !isInt(n)) {
  46040. error('Invalid XRef range fields: ' + first + ', ' + n);
  46041. }
  46042. if (!isInt(typeFieldWidth) || !isInt(offsetFieldWidth) || !isInt(generationFieldWidth)) {
  46043. error('Invalid XRef entry fields length: ' + first + ', ' + n);
  46044. }
  46045. for (i = streamState.entryNum; i < n; ++i) {
  46046. streamState.entryNum = i;
  46047. streamState.streamPos = stream.pos;
  46048. var type = 0, offset = 0, generation = 0;
  46049. for (j = 0; j < typeFieldWidth; ++j) {
  46050. type = type << 8 | stream.getByte();
  46051. }
  46052. // if type field is absent, its default value is 1
  46053. if (typeFieldWidth === 0) {
  46054. type = 1;
  46055. }
  46056. for (j = 0; j < offsetFieldWidth; ++j) {
  46057. offset = offset << 8 | stream.getByte();
  46058. }
  46059. for (j = 0; j < generationFieldWidth; ++j) {
  46060. generation = generation << 8 | stream.getByte();
  46061. }
  46062. var entry = {};
  46063. entry.offset = offset;
  46064. entry.gen = generation;
  46065. switch (type) {
  46066. case 0:
  46067. entry.free = true;
  46068. break;
  46069. case 1:
  46070. entry.uncompressed = true;
  46071. break;
  46072. case 2:
  46073. break;
  46074. default:
  46075. error('Invalid XRef entry type: ' + type);
  46076. }
  46077. if (!this.entries[first + i]) {
  46078. this.entries[first + i] = entry;
  46079. }
  46080. }
  46081. streamState.entryNum = 0;
  46082. streamState.streamPos = stream.pos;
  46083. entryRanges.splice(0, 2);
  46084. }
  46085. },
  46086. indexObjects: function XRef_indexObjects() {
  46087. // Simple scan through the PDF content to find objects,
  46088. // trailers and XRef streams.
  46089. var TAB = 0x9, LF = 0xA, CR = 0xD, SPACE = 0x20;
  46090. var PERCENT = 0x25, LT = 0x3C;
  46091. function readToken(data, offset) {
  46092. var token = '', ch = data[offset];
  46093. while (ch !== LF && ch !== CR && ch !== LT) {
  46094. if (++offset >= data.length) {
  46095. break;
  46096. }
  46097. token += String.fromCharCode(ch);
  46098. ch = data[offset];
  46099. }
  46100. return token;
  46101. }
  46102. function skipUntil(data, offset, what) {
  46103. var length = what.length, dataLength = data.length;
  46104. var skipped = 0;
  46105. // finding byte sequence
  46106. while (offset < dataLength) {
  46107. var i = 0;
  46108. while (i < length && data[offset + i] === what[i]) {
  46109. ++i;
  46110. }
  46111. if (i >= length) {
  46112. break;
  46113. }
  46114. // sequence found
  46115. offset++;
  46116. skipped++;
  46117. }
  46118. return skipped;
  46119. }
  46120. var objRegExp = /^(\d+)\s+(\d+)\s+obj\b/;
  46121. var trailerBytes = new Uint8Array([
  46122. 116,
  46123. 114,
  46124. 97,
  46125. 105,
  46126. 108,
  46127. 101,
  46128. 114
  46129. ]);
  46130. var startxrefBytes = new Uint8Array([
  46131. 115,
  46132. 116,
  46133. 97,
  46134. 114,
  46135. 116,
  46136. 120,
  46137. 114,
  46138. 101,
  46139. 102
  46140. ]);
  46141. var endobjBytes = new Uint8Array([
  46142. 101,
  46143. 110,
  46144. 100,
  46145. 111,
  46146. 98,
  46147. 106
  46148. ]);
  46149. var xrefBytes = new Uint8Array([
  46150. 47,
  46151. 88,
  46152. 82,
  46153. 101,
  46154. 102
  46155. ]);
  46156. // Clear out any existing entries, since they may be bogus.
  46157. this.entries.length = 0;
  46158. var stream = this.stream;
  46159. stream.pos = 0;
  46160. var buffer = stream.getBytes();
  46161. var position = stream.start, length = buffer.length;
  46162. var trailers = [], xrefStms = [];
  46163. while (position < length) {
  46164. var ch = buffer[position];
  46165. if (ch === TAB || ch === LF || ch === CR || ch === SPACE) {
  46166. ++position;
  46167. continue;
  46168. }
  46169. if (ch === PERCENT) {
  46170. // %-comment
  46171. do {
  46172. ++position;
  46173. if (position >= length) {
  46174. break;
  46175. }
  46176. ch = buffer[position];
  46177. } while (ch !== LF && ch !== CR);
  46178. continue;
  46179. }
  46180. var token = readToken(buffer, position);
  46181. var m;
  46182. if (token.indexOf('xref') === 0 && (token.length === 4 || /\s/.test(token[4]))) {
  46183. position += skipUntil(buffer, position, trailerBytes);
  46184. trailers.push(position);
  46185. position += skipUntil(buffer, position, startxrefBytes);
  46186. } else if (m = objRegExp.exec(token)) {
  46187. if (typeof this.entries[m[1]] === 'undefined') {
  46188. this.entries[m[1]] = {
  46189. offset: position - stream.start,
  46190. gen: m[2] | 0,
  46191. uncompressed: true
  46192. };
  46193. }
  46194. var contentLength = skipUntil(buffer, position, endobjBytes) + 7;
  46195. var content = buffer.subarray(position, position + contentLength);
  46196. // checking XRef stream suspect
  46197. // (it shall have '/XRef' and next char is not a letter)
  46198. var xrefTagOffset = skipUntil(content, 0, xrefBytes);
  46199. if (xrefTagOffset < contentLength && content[xrefTagOffset + 5] < 64) {
  46200. xrefStms.push(position - stream.start);
  46201. this.xrefstms[position - stream.start] = 1;
  46202. }
  46203. // Avoid recursion
  46204. position += contentLength;
  46205. } else if (token.indexOf('trailer') === 0 && (token.length === 7 || /\s/.test(token[7]))) {
  46206. trailers.push(position);
  46207. position += skipUntil(buffer, position, startxrefBytes);
  46208. } else {
  46209. position += token.length + 1;
  46210. }
  46211. }
  46212. // reading XRef streams
  46213. var i, ii;
  46214. for (i = 0, ii = xrefStms.length; i < ii; ++i) {
  46215. this.startXRefQueue.push(xrefStms[i]);
  46216. this.readXRef(/* recoveryMode */
  46217. true);
  46218. }
  46219. // finding main trailer
  46220. var dict;
  46221. for (i = 0, ii = trailers.length; i < ii; ++i) {
  46222. stream.pos = trailers[i];
  46223. var parser = new Parser(new Lexer(stream), /* allowStreams = */
  46224. true, /* xref = */
  46225. this, /* recoveryMode = */
  46226. true);
  46227. var obj = parser.getObj();
  46228. if (!isCmd(obj, 'trailer')) {
  46229. continue;
  46230. }
  46231. // read the trailer dictionary
  46232. dict = parser.getObj();
  46233. if (!isDict(dict)) {
  46234. continue;
  46235. }
  46236. // taking the first one with 'ID'
  46237. if (dict.has('ID')) {
  46238. return dict;
  46239. }
  46240. }
  46241. // no tailer with 'ID', taking last one (if exists)
  46242. if (dict) {
  46243. return dict;
  46244. }
  46245. // nothing helps
  46246. // calling error() would reject worker with an UnknownErrorException.
  46247. throw new InvalidPDFException('Invalid PDF structure');
  46248. },
  46249. readXRef: function XRef_readXRef(recoveryMode) {
  46250. var stream = this.stream;
  46251. try {
  46252. while (this.startXRefQueue.length) {
  46253. var startXRef = this.startXRefQueue[0];
  46254. stream.pos = startXRef + stream.start;
  46255. var parser = new Parser(new Lexer(stream), true, this);
  46256. var obj = parser.getObj();
  46257. var dict;
  46258. // Get dictionary
  46259. if (isCmd(obj, 'xref')) {
  46260. // Parse end-of-file XRef
  46261. dict = this.processXRefTable(parser);
  46262. if (!this.topDict) {
  46263. this.topDict = dict;
  46264. }
  46265. // Recursively get other XRefs 'XRefStm', if any
  46266. obj = dict.get('XRefStm');
  46267. if (isInt(obj)) {
  46268. var pos = obj;
  46269. // ignore previously loaded xref streams
  46270. // (possible infinite recursion)
  46271. if (!(pos in this.xrefstms)) {
  46272. this.xrefstms[pos] = 1;
  46273. this.startXRefQueue.push(pos);
  46274. }
  46275. }
  46276. } else if (isInt(obj)) {
  46277. // Parse in-stream XRef
  46278. if (!isInt(parser.getObj()) || !isCmd(parser.getObj(), 'obj') || !isStream(obj = parser.getObj())) {
  46279. error('Invalid XRef stream');
  46280. }
  46281. dict = this.processXRefStream(obj);
  46282. if (!this.topDict) {
  46283. this.topDict = dict;
  46284. }
  46285. if (!dict) {
  46286. error('Failed to read XRef stream');
  46287. }
  46288. } else {
  46289. error('Invalid XRef stream header');
  46290. }
  46291. // Recursively get previous dictionary, if any
  46292. obj = dict.get('Prev');
  46293. if (isInt(obj)) {
  46294. this.startXRefQueue.push(obj);
  46295. } else if (isRef(obj)) {
  46296. // The spec says Prev must not be a reference, i.e. "/Prev NNN"
  46297. // This is a fallback for non-compliant PDFs, i.e. "/Prev NNN 0 R"
  46298. this.startXRefQueue.push(obj.num);
  46299. }
  46300. this.startXRefQueue.shift();
  46301. }
  46302. return this.topDict;
  46303. } catch (e) {
  46304. if (e instanceof MissingDataException) {
  46305. throw e;
  46306. }
  46307. info('(while reading XRef): ' + e);
  46308. }
  46309. if (recoveryMode) {
  46310. return;
  46311. }
  46312. throw new XRefParseException();
  46313. },
  46314. getEntry: function XRef_getEntry(i) {
  46315. var xrefEntry = this.entries[i];
  46316. if (xrefEntry && !xrefEntry.free && xrefEntry.offset) {
  46317. return xrefEntry;
  46318. }
  46319. return null;
  46320. },
  46321. fetchIfRef: function XRef_fetchIfRef(obj, suppressEncryption) {
  46322. if (!isRef(obj)) {
  46323. return obj;
  46324. }
  46325. return this.fetch(obj, suppressEncryption);
  46326. },
  46327. fetch: function XRef_fetch(ref, suppressEncryption) {
  46328. assert(isRef(ref), 'ref object is not a reference');
  46329. var num = ref.num;
  46330. if (num in this.cache) {
  46331. var cacheEntry = this.cache[num];
  46332. return cacheEntry;
  46333. }
  46334. var xrefEntry = this.getEntry(num);
  46335. // the referenced entry can be free
  46336. if (xrefEntry === null) {
  46337. return this.cache[num] = null;
  46338. }
  46339. if (xrefEntry.uncompressed) {
  46340. xrefEntry = this.fetchUncompressed(ref, xrefEntry, suppressEncryption);
  46341. } else {
  46342. xrefEntry = this.fetchCompressed(xrefEntry, suppressEncryption);
  46343. }
  46344. if (isDict(xrefEntry)) {
  46345. xrefEntry.objId = ref.toString();
  46346. } else if (isStream(xrefEntry)) {
  46347. xrefEntry.dict.objId = ref.toString();
  46348. }
  46349. return xrefEntry;
  46350. },
  46351. fetchUncompressed: function XRef_fetchUncompressed(ref, xrefEntry, suppressEncryption) {
  46352. var gen = ref.gen;
  46353. var num = ref.num;
  46354. if (xrefEntry.gen !== gen) {
  46355. error('inconsistent generation in XRef');
  46356. }
  46357. var stream = this.stream.makeSubStream(xrefEntry.offset + this.stream.start);
  46358. var parser = new Parser(new Lexer(stream), true, this);
  46359. var obj1 = parser.getObj();
  46360. var obj2 = parser.getObj();
  46361. var obj3 = parser.getObj();
  46362. if (!isInt(obj1) || parseInt(obj1, 10) !== num || !isInt(obj2) || parseInt(obj2, 10) !== gen || !isCmd(obj3)) {
  46363. error('bad XRef entry');
  46364. }
  46365. if (!isCmd(obj3, 'obj')) {
  46366. // some bad PDFs use "obj1234" and really mean 1234
  46367. if (obj3.cmd.indexOf('obj') === 0) {
  46368. num = parseInt(obj3.cmd.substring(3), 10);
  46369. if (!isNaN(num)) {
  46370. return num;
  46371. }
  46372. }
  46373. error('bad XRef entry');
  46374. }
  46375. if (this.encrypt && !suppressEncryption) {
  46376. xrefEntry = parser.getObj(this.encrypt.createCipherTransform(num, gen));
  46377. } else {
  46378. xrefEntry = parser.getObj();
  46379. }
  46380. if (!isStream(xrefEntry)) {
  46381. this.cache[num] = xrefEntry;
  46382. }
  46383. return xrefEntry;
  46384. },
  46385. fetchCompressed: function XRef_fetchCompressed(xrefEntry, suppressEncryption) {
  46386. var tableOffset = xrefEntry.offset;
  46387. var stream = this.fetch(new Ref(tableOffset, 0));
  46388. if (!isStream(stream)) {
  46389. error('bad ObjStm stream');
  46390. }
  46391. var first = stream.dict.get('First');
  46392. var n = stream.dict.get('N');
  46393. if (!isInt(first) || !isInt(n)) {
  46394. error('invalid first and n parameters for ObjStm stream');
  46395. }
  46396. var parser = new Parser(new Lexer(stream), false, this);
  46397. parser.allowStreams = true;
  46398. var i, entries = [], num, nums = [];
  46399. // read the object numbers to populate cache
  46400. for (i = 0; i < n; ++i) {
  46401. num = parser.getObj();
  46402. if (!isInt(num)) {
  46403. error('invalid object number in the ObjStm stream: ' + num);
  46404. }
  46405. nums.push(num);
  46406. var offset = parser.getObj();
  46407. if (!isInt(offset)) {
  46408. error('invalid object offset in the ObjStm stream: ' + offset);
  46409. }
  46410. }
  46411. // read stream objects for cache
  46412. for (i = 0; i < n; ++i) {
  46413. entries.push(parser.getObj());
  46414. // The ObjStm should not contain 'endobj'. If it's present, skip over it
  46415. // to support corrupt PDFs (fixes issue 5241, bug 898610, bug 1037816).
  46416. if (isCmd(parser.buf1, 'endobj')) {
  46417. parser.shift();
  46418. }
  46419. num = nums[i];
  46420. var entry = this.entries[num];
  46421. if (entry && entry.offset === tableOffset && entry.gen === i) {
  46422. this.cache[num] = entries[i];
  46423. }
  46424. }
  46425. xrefEntry = entries[xrefEntry.gen];
  46426. if (xrefEntry === undefined) {
  46427. error('bad XRef entry for compressed object');
  46428. }
  46429. return xrefEntry;
  46430. },
  46431. fetchIfRefAsync: function XRef_fetchIfRefAsync(obj, suppressEncryption) {
  46432. if (!isRef(obj)) {
  46433. return Promise.resolve(obj);
  46434. }
  46435. return this.fetchAsync(obj, suppressEncryption);
  46436. },
  46437. fetchAsync: function XRef_fetchAsync(ref, suppressEncryption) {
  46438. var streamManager = this.stream.manager;
  46439. var xref = this;
  46440. return new Promise(function tryFetch(resolve, reject) {
  46441. try {
  46442. resolve(xref.fetch(ref, suppressEncryption));
  46443. } catch (e) {
  46444. if (e instanceof MissingDataException) {
  46445. streamManager.requestRange(e.begin, e.end).then(function () {
  46446. tryFetch(resolve, reject);
  46447. }, reject);
  46448. return;
  46449. }
  46450. reject(e);
  46451. }
  46452. });
  46453. },
  46454. getCatalogObj: function XRef_getCatalogObj() {
  46455. return this.root;
  46456. }
  46457. };
  46458. return XRef;
  46459. }();
  46460. /**
  46461. * A NameTree/NumberTree is like a Dict but has some advantageous properties,
  46462. * see the specification (7.9.6 and 7.9.7) for additional details.
  46463. * TODO: implement all the Dict functions and make this more efficient.
  46464. */
  46465. var NameOrNumberTree = function NameOrNumberTreeClosure() {
  46466. function NameOrNumberTree(root, xref) {
  46467. throw new Error('Cannot initialize NameOrNumberTree.');
  46468. }
  46469. NameOrNumberTree.prototype = {
  46470. getAll: function NameOrNumberTree_getAll() {
  46471. var dict = Object.create(null);
  46472. if (!this.root) {
  46473. return dict;
  46474. }
  46475. var xref = this.xref;
  46476. // Reading Name/Number tree.
  46477. var processed = new RefSet();
  46478. processed.put(this.root);
  46479. var queue = [this.root];
  46480. while (queue.length > 0) {
  46481. var i, n;
  46482. var obj = xref.fetchIfRef(queue.shift());
  46483. if (!isDict(obj)) {
  46484. continue;
  46485. }
  46486. if (obj.has('Kids')) {
  46487. var kids = obj.get('Kids');
  46488. for (i = 0, n = kids.length; i < n; i++) {
  46489. var kid = kids[i];
  46490. assert(!processed.has(kid), 'Duplicate entry in "' + this._type + '" tree.');
  46491. queue.push(kid);
  46492. processed.put(kid);
  46493. }
  46494. continue;
  46495. }
  46496. var entries = obj.get(this._type);
  46497. if (isArray(entries)) {
  46498. for (i = 0, n = entries.length; i < n; i += 2) {
  46499. dict[xref.fetchIfRef(entries[i])] = xref.fetchIfRef(entries[i + 1]);
  46500. }
  46501. }
  46502. }
  46503. return dict;
  46504. },
  46505. get: function NameOrNumberTree_get(key) {
  46506. if (!this.root) {
  46507. return null;
  46508. }
  46509. var xref = this.xref;
  46510. var kidsOrEntries = xref.fetchIfRef(this.root);
  46511. var loopCount = 0;
  46512. var MAX_LEVELS = 10;
  46513. var l, r, m;
  46514. // Perform a binary search to quickly find the entry that
  46515. // contains the key we are looking for.
  46516. while (kidsOrEntries.has('Kids')) {
  46517. if (++loopCount > MAX_LEVELS) {
  46518. warn('Search depth limit reached for "' + this._type + '" tree.');
  46519. return null;
  46520. }
  46521. var kids = kidsOrEntries.get('Kids');
  46522. if (!isArray(kids)) {
  46523. return null;
  46524. }
  46525. l = 0;
  46526. r = kids.length - 1;
  46527. while (l <= r) {
  46528. m = l + r >> 1;
  46529. var kid = xref.fetchIfRef(kids[m]);
  46530. var limits = kid.get('Limits');
  46531. if (key < xref.fetchIfRef(limits[0])) {
  46532. r = m - 1;
  46533. } else if (key > xref.fetchIfRef(limits[1])) {
  46534. l = m + 1;
  46535. } else {
  46536. kidsOrEntries = xref.fetchIfRef(kids[m]);
  46537. break;
  46538. }
  46539. }
  46540. if (l > r) {
  46541. return null;
  46542. }
  46543. }
  46544. // If we get here, then we have found the right entry. Now go through the
  46545. // entries in the dictionary until we find the key we're looking for.
  46546. var entries = kidsOrEntries.get(this._type);
  46547. if (isArray(entries)) {
  46548. // Perform a binary search to reduce the lookup time.
  46549. l = 0;
  46550. r = entries.length - 2;
  46551. while (l <= r) {
  46552. // Check only even indices (0, 2, 4, ...) because the
  46553. // odd indices contain the actual data.
  46554. m = l + r & ~1;
  46555. var currentKey = xref.fetchIfRef(entries[m]);
  46556. if (key < currentKey) {
  46557. r = m - 2;
  46558. } else if (key > currentKey) {
  46559. l = m + 2;
  46560. } else {
  46561. return xref.fetchIfRef(entries[m + 1]);
  46562. }
  46563. }
  46564. }
  46565. return null;
  46566. }
  46567. };
  46568. return NameOrNumberTree;
  46569. }();
  46570. var NameTree = function NameTreeClosure() {
  46571. function NameTree(root, xref) {
  46572. this.root = root;
  46573. this.xref = xref;
  46574. this._type = 'Names';
  46575. }
  46576. Util.inherit(NameTree, NameOrNumberTree, {});
  46577. return NameTree;
  46578. }();
  46579. var NumberTree = function NumberTreeClosure() {
  46580. function NumberTree(root, xref) {
  46581. this.root = root;
  46582. this.xref = xref;
  46583. this._type = 'Nums';
  46584. }
  46585. Util.inherit(NumberTree, NameOrNumberTree, {});
  46586. return NumberTree;
  46587. }();
  46588. /**
  46589. * "A PDF file can refer to the contents of another file by using a File
  46590. * Specification (PDF 1.1)", see the spec (7.11) for more details.
  46591. * NOTE: Only embedded files are supported (as part of the attachments support)
  46592. * TODO: support the 'URL' file system (with caching if !/V), portable
  46593. * collections attributes and related files (/RF)
  46594. */
  46595. var FileSpec = function FileSpecClosure() {
  46596. function FileSpec(root, xref) {
  46597. if (!root || !isDict(root)) {
  46598. return;
  46599. }
  46600. this.xref = xref;
  46601. this.root = root;
  46602. if (root.has('FS')) {
  46603. this.fs = root.get('FS');
  46604. }
  46605. this.description = root.has('Desc') ? stringToPDFString(root.get('Desc')) : '';
  46606. if (root.has('RF')) {
  46607. warn('Related file specifications are not supported');
  46608. }
  46609. this.contentAvailable = true;
  46610. if (!root.has('EF')) {
  46611. this.contentAvailable = false;
  46612. warn('Non-embedded file specifications are not supported');
  46613. }
  46614. }
  46615. function pickPlatformItem(dict) {
  46616. // Look for the filename in this order:
  46617. // UF, F, Unix, Mac, DOS
  46618. if (dict.has('UF')) {
  46619. return dict.get('UF');
  46620. } else if (dict.has('F')) {
  46621. return dict.get('F');
  46622. } else if (dict.has('Unix')) {
  46623. return dict.get('Unix');
  46624. } else if (dict.has('Mac')) {
  46625. return dict.get('Mac');
  46626. } else if (dict.has('DOS')) {
  46627. return dict.get('DOS');
  46628. } else {
  46629. return null;
  46630. }
  46631. }
  46632. FileSpec.prototype = {
  46633. get filename() {
  46634. if (!this._filename && this.root) {
  46635. var filename = pickPlatformItem(this.root) || 'unnamed';
  46636. this._filename = stringToPDFString(filename).replace(/\\\\/g, '\\').replace(/\\\//g, '/').replace(/\\/g, '/');
  46637. }
  46638. return this._filename;
  46639. },
  46640. get content() {
  46641. if (!this.contentAvailable) {
  46642. return null;
  46643. }
  46644. if (!this.contentRef && this.root) {
  46645. this.contentRef = pickPlatformItem(this.root.get('EF'));
  46646. }
  46647. var content = null;
  46648. if (this.contentRef) {
  46649. var xref = this.xref;
  46650. var fileObj = xref.fetchIfRef(this.contentRef);
  46651. if (fileObj && isStream(fileObj)) {
  46652. content = fileObj.getBytes();
  46653. } else {
  46654. warn('Embedded file specification points to non-existing/invalid ' + 'content');
  46655. }
  46656. } else {
  46657. warn('Embedded file specification does not have a content');
  46658. }
  46659. return content;
  46660. },
  46661. get serializable() {
  46662. return {
  46663. filename: this.filename,
  46664. content: this.content
  46665. };
  46666. }
  46667. };
  46668. return FileSpec;
  46669. }();
  46670. /**
  46671. * A helper for loading missing data in object graphs. It traverses the graph
  46672. * depth first and queues up any objects that have missing data. Once it has
  46673. * has traversed as many objects that are available it attempts to bundle the
  46674. * missing data requests and then resume from the nodes that weren't ready.
  46675. *
  46676. * NOTE: It provides protection from circular references by keeping track of
  46677. * of loaded references. However, you must be careful not to load any graphs
  46678. * that have references to the catalog or other pages since that will cause the
  46679. * entire PDF document object graph to be traversed.
  46680. */
  46681. var ObjectLoader = function () {
  46682. function mayHaveChildren(value) {
  46683. return isRef(value) || isDict(value) || isArray(value) || isStream(value);
  46684. }
  46685. function addChildren(node, nodesToVisit) {
  46686. var value;
  46687. if (isDict(node) || isStream(node)) {
  46688. var map;
  46689. if (isDict(node)) {
  46690. map = node.map;
  46691. } else {
  46692. map = node.dict.map;
  46693. }
  46694. for (var key in map) {
  46695. value = map[key];
  46696. if (mayHaveChildren(value)) {
  46697. nodesToVisit.push(value);
  46698. }
  46699. }
  46700. } else if (isArray(node)) {
  46701. for (var i = 0, ii = node.length; i < ii; i++) {
  46702. value = node[i];
  46703. if (mayHaveChildren(value)) {
  46704. nodesToVisit.push(value);
  46705. }
  46706. }
  46707. }
  46708. }
  46709. function ObjectLoader(obj, keys, xref) {
  46710. this.obj = obj;
  46711. this.keys = keys;
  46712. this.xref = xref;
  46713. this.refSet = null;
  46714. this.capability = null;
  46715. }
  46716. ObjectLoader.prototype = {
  46717. load: function ObjectLoader_load() {
  46718. var keys = this.keys;
  46719. this.capability = createPromiseCapability();
  46720. // Don't walk the graph if all the data is already loaded.
  46721. if (!(this.xref.stream instanceof ChunkedStream) || this.xref.stream.getMissingChunks().length === 0) {
  46722. this.capability.resolve();
  46723. return this.capability.promise;
  46724. }
  46725. this.refSet = new RefSet();
  46726. // Setup the initial nodes to visit.
  46727. var nodesToVisit = [];
  46728. for (var i = 0; i < keys.length; i++) {
  46729. nodesToVisit.push(this.obj[keys[i]]);
  46730. }
  46731. this._walk(nodesToVisit);
  46732. return this.capability.promise;
  46733. },
  46734. _walk: function ObjectLoader_walk(nodesToVisit) {
  46735. var nodesToRevisit = [];
  46736. var pendingRequests = [];
  46737. // DFS walk of the object graph.
  46738. while (nodesToVisit.length) {
  46739. var currentNode = nodesToVisit.pop();
  46740. // Only references or chunked streams can cause missing data exceptions.
  46741. if (isRef(currentNode)) {
  46742. // Skip nodes that have already been visited.
  46743. if (this.refSet.has(currentNode)) {
  46744. continue;
  46745. }
  46746. try {
  46747. var ref = currentNode;
  46748. this.refSet.put(ref);
  46749. currentNode = this.xref.fetch(currentNode);
  46750. } catch (e) {
  46751. if (!(e instanceof MissingDataException)) {
  46752. throw e;
  46753. }
  46754. nodesToRevisit.push(currentNode);
  46755. pendingRequests.push({
  46756. begin: e.begin,
  46757. end: e.end
  46758. });
  46759. }
  46760. }
  46761. if (currentNode && currentNode.getBaseStreams) {
  46762. var baseStreams = currentNode.getBaseStreams();
  46763. var foundMissingData = false;
  46764. for (var i = 0; i < baseStreams.length; i++) {
  46765. var stream = baseStreams[i];
  46766. if (stream.getMissingChunks && stream.getMissingChunks().length) {
  46767. foundMissingData = true;
  46768. pendingRequests.push({
  46769. begin: stream.start,
  46770. end: stream.end
  46771. });
  46772. }
  46773. }
  46774. if (foundMissingData) {
  46775. nodesToRevisit.push(currentNode);
  46776. }
  46777. }
  46778. addChildren(currentNode, nodesToVisit);
  46779. }
  46780. if (pendingRequests.length) {
  46781. this.xref.stream.manager.requestRanges(pendingRequests).then(function pendingRequestCallback() {
  46782. nodesToVisit = nodesToRevisit;
  46783. for (var i = 0; i < nodesToRevisit.length; i++) {
  46784. var node = nodesToRevisit[i];
  46785. // Remove any reference nodes from the currrent refset so they
  46786. // aren't skipped when we revist them.
  46787. if (isRef(node)) {
  46788. this.refSet.remove(node);
  46789. }
  46790. }
  46791. this._walk(nodesToVisit);
  46792. }.bind(this), this.capability.reject);
  46793. return;
  46794. }
  46795. // Everything is loaded.
  46796. this.refSet = null;
  46797. this.capability.resolve();
  46798. }
  46799. };
  46800. return ObjectLoader;
  46801. }();
  46802. exports.Catalog = Catalog;
  46803. exports.ObjectLoader = ObjectLoader;
  46804. exports.XRef = XRef;
  46805. exports.FileSpec = FileSpec;
  46806. }));
  46807. (function (root, factory) {
  46808. factory(root.pdfjsCorePattern = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCoreFunction, root.pdfjsCoreColorSpace);
  46809. }(this, function (exports, sharedUtil, corePrimitives, coreFunction, coreColorSpace) {
  46810. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  46811. var MissingDataException = sharedUtil.MissingDataException;
  46812. var Util = sharedUtil.Util;
  46813. var assert = sharedUtil.assert;
  46814. var error = sharedUtil.error;
  46815. var info = sharedUtil.info;
  46816. var warn = sharedUtil.warn;
  46817. var isStream = corePrimitives.isStream;
  46818. var PDFFunction = coreFunction.PDFFunction;
  46819. var ColorSpace = coreColorSpace.ColorSpace;
  46820. var ShadingType = {
  46821. FUNCTION_BASED: 1,
  46822. AXIAL: 2,
  46823. RADIAL: 3,
  46824. FREE_FORM_MESH: 4,
  46825. LATTICE_FORM_MESH: 5,
  46826. COONS_PATCH_MESH: 6,
  46827. TENSOR_PATCH_MESH: 7
  46828. };
  46829. var Pattern = function PatternClosure() {
  46830. // Constructor should define this.getPattern
  46831. function Pattern() {
  46832. error('should not call Pattern constructor');
  46833. }
  46834. Pattern.prototype = {
  46835. // Input: current Canvas context
  46836. // Output: the appropriate fillStyle or strokeStyle
  46837. getPattern: function Pattern_getPattern(ctx) {
  46838. error('Should not call Pattern.getStyle: ' + ctx);
  46839. }
  46840. };
  46841. Pattern.parseShading = function Pattern_parseShading(shading, matrix, xref, res, handler) {
  46842. var dict = isStream(shading) ? shading.dict : shading;
  46843. var type = dict.get('ShadingType');
  46844. try {
  46845. switch (type) {
  46846. case ShadingType.AXIAL:
  46847. case ShadingType.RADIAL:
  46848. // Both radial and axial shadings are handled by RadialAxial shading.
  46849. return new Shadings.RadialAxial(dict, matrix, xref, res);
  46850. case ShadingType.FREE_FORM_MESH:
  46851. case ShadingType.LATTICE_FORM_MESH:
  46852. case ShadingType.COONS_PATCH_MESH:
  46853. case ShadingType.TENSOR_PATCH_MESH:
  46854. return new Shadings.Mesh(shading, matrix, xref, res);
  46855. default:
  46856. throw new Error('Unsupported ShadingType: ' + type);
  46857. }
  46858. } catch (ex) {
  46859. if (ex instanceof MissingDataException) {
  46860. throw ex;
  46861. }
  46862. handler.send('UnsupportedFeature', { featureId: UNSUPPORTED_FEATURES.shadingPattern });
  46863. warn(ex);
  46864. return new Shadings.Dummy();
  46865. }
  46866. };
  46867. return Pattern;
  46868. }();
  46869. var Shadings = {};
  46870. // A small number to offset the first/last color stops so we can insert ones to
  46871. // support extend. Number.MIN_VALUE is too small and breaks the extend.
  46872. Shadings.SMALL_NUMBER = 1e-6;
  46873. // Radial and axial shading have very similar implementations
  46874. // If needed, the implementations can be broken into two classes
  46875. Shadings.RadialAxial = function RadialAxialClosure() {
  46876. function RadialAxial(dict, matrix, xref, res) {
  46877. this.matrix = matrix;
  46878. this.coordsArr = dict.getArray('Coords');
  46879. this.shadingType = dict.get('ShadingType');
  46880. this.type = 'Pattern';
  46881. var cs = dict.get('ColorSpace', 'CS');
  46882. cs = ColorSpace.parse(cs, xref, res);
  46883. this.cs = cs;
  46884. var t0 = 0.0, t1 = 1.0;
  46885. if (dict.has('Domain')) {
  46886. var domainArr = dict.getArray('Domain');
  46887. t0 = domainArr[0];
  46888. t1 = domainArr[1];
  46889. }
  46890. var extendStart = false, extendEnd = false;
  46891. if (dict.has('Extend')) {
  46892. var extendArr = dict.getArray('Extend');
  46893. extendStart = extendArr[0];
  46894. extendEnd = extendArr[1];
  46895. }
  46896. if (this.shadingType === ShadingType.RADIAL && (!extendStart || !extendEnd)) {
  46897. // Radial gradient only currently works if either circle is fully within
  46898. // the other circle.
  46899. var x1 = this.coordsArr[0];
  46900. var y1 = this.coordsArr[1];
  46901. var r1 = this.coordsArr[2];
  46902. var x2 = this.coordsArr[3];
  46903. var y2 = this.coordsArr[4];
  46904. var r2 = this.coordsArr[5];
  46905. var distance = Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
  46906. if (r1 <= r2 + distance && r2 <= r1 + distance) {
  46907. warn('Unsupported radial gradient.');
  46908. }
  46909. }
  46910. this.extendStart = extendStart;
  46911. this.extendEnd = extendEnd;
  46912. var fnObj = dict.get('Function');
  46913. var fn = PDFFunction.parseArray(xref, fnObj);
  46914. // 10 samples seems good enough for now, but probably won't work
  46915. // if there are sharp color changes. Ideally, we would implement
  46916. // the spec faithfully and add lossless optimizations.
  46917. var diff = t1 - t0;
  46918. var step = diff / 10;
  46919. var colorStops = this.colorStops = [];
  46920. // Protect against bad domains so we don't end up in an infinte loop below.
  46921. if (t0 >= t1 || step <= 0) {
  46922. // Acrobat doesn't seem to handle these cases so we'll ignore for
  46923. // now.
  46924. info('Bad shading domain.');
  46925. return;
  46926. }
  46927. var color = new Float32Array(cs.numComps), ratio = new Float32Array(1);
  46928. var rgbColor;
  46929. for (var i = t0; i <= t1; i += step) {
  46930. ratio[0] = i;
  46931. fn(ratio, 0, color, 0);
  46932. rgbColor = cs.getRgb(color, 0);
  46933. var cssColor = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  46934. colorStops.push([
  46935. (i - t0) / diff,
  46936. cssColor
  46937. ]);
  46938. }
  46939. var background = 'transparent';
  46940. if (dict.has('Background')) {
  46941. rgbColor = cs.getRgb(dict.get('Background'), 0);
  46942. background = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  46943. }
  46944. if (!extendStart) {
  46945. // Insert a color stop at the front and offset the first real color stop
  46946. // so it doesn't conflict with the one we insert.
  46947. colorStops.unshift([
  46948. 0,
  46949. background
  46950. ]);
  46951. colorStops[1][0] += Shadings.SMALL_NUMBER;
  46952. }
  46953. if (!extendEnd) {
  46954. // Same idea as above in extendStart but for the end.
  46955. colorStops[colorStops.length - 1][0] -= Shadings.SMALL_NUMBER;
  46956. colorStops.push([
  46957. 1,
  46958. background
  46959. ]);
  46960. }
  46961. this.colorStops = colorStops;
  46962. }
  46963. RadialAxial.prototype = {
  46964. getIR: function RadialAxial_getIR() {
  46965. var coordsArr = this.coordsArr;
  46966. var shadingType = this.shadingType;
  46967. var type, p0, p1, r0, r1;
  46968. if (shadingType === ShadingType.AXIAL) {
  46969. p0 = [
  46970. coordsArr[0],
  46971. coordsArr[1]
  46972. ];
  46973. p1 = [
  46974. coordsArr[2],
  46975. coordsArr[3]
  46976. ];
  46977. r0 = null;
  46978. r1 = null;
  46979. type = 'axial';
  46980. } else if (shadingType === ShadingType.RADIAL) {
  46981. p0 = [
  46982. coordsArr[0],
  46983. coordsArr[1]
  46984. ];
  46985. p1 = [
  46986. coordsArr[3],
  46987. coordsArr[4]
  46988. ];
  46989. r0 = coordsArr[2];
  46990. r1 = coordsArr[5];
  46991. type = 'radial';
  46992. } else {
  46993. error('getPattern type unknown: ' + shadingType);
  46994. }
  46995. var matrix = this.matrix;
  46996. if (matrix) {
  46997. p0 = Util.applyTransform(p0, matrix);
  46998. p1 = Util.applyTransform(p1, matrix);
  46999. if (shadingType === ShadingType.RADIAL) {
  47000. var scale = Util.singularValueDecompose2dScale(matrix);
  47001. r0 *= scale[0];
  47002. r1 *= scale[1];
  47003. }
  47004. }
  47005. return [
  47006. 'RadialAxial',
  47007. type,
  47008. this.colorStops,
  47009. p0,
  47010. p1,
  47011. r0,
  47012. r1
  47013. ];
  47014. }
  47015. };
  47016. return RadialAxial;
  47017. }();
  47018. // All mesh shading. For now, they will be presented as set of the triangles
  47019. // to be drawn on the canvas and rgb color for each vertex.
  47020. Shadings.Mesh = function MeshClosure() {
  47021. function MeshStreamReader(stream, context) {
  47022. this.stream = stream;
  47023. this.context = context;
  47024. this.buffer = 0;
  47025. this.bufferLength = 0;
  47026. var numComps = context.numComps;
  47027. this.tmpCompsBuf = new Float32Array(numComps);
  47028. var csNumComps = context.colorSpace.numComps;
  47029. this.tmpCsCompsBuf = context.colorFn ? new Float32Array(csNumComps) : this.tmpCompsBuf;
  47030. }
  47031. MeshStreamReader.prototype = {
  47032. get hasData() {
  47033. if (this.stream.end) {
  47034. return this.stream.pos < this.stream.end;
  47035. }
  47036. if (this.bufferLength > 0) {
  47037. return true;
  47038. }
  47039. var nextByte = this.stream.getByte();
  47040. if (nextByte < 0) {
  47041. return false;
  47042. }
  47043. this.buffer = nextByte;
  47044. this.bufferLength = 8;
  47045. return true;
  47046. },
  47047. readBits: function MeshStreamReader_readBits(n) {
  47048. var buffer = this.buffer;
  47049. var bufferLength = this.bufferLength;
  47050. if (n === 32) {
  47051. if (bufferLength === 0) {
  47052. return (this.stream.getByte() << 24 | this.stream.getByte() << 16 | this.stream.getByte() << 8 | this.stream.getByte()) >>> 0;
  47053. }
  47054. buffer = buffer << 24 | this.stream.getByte() << 16 | this.stream.getByte() << 8 | this.stream.getByte();
  47055. var nextByte = this.stream.getByte();
  47056. this.buffer = nextByte & (1 << bufferLength) - 1;
  47057. return (buffer << 8 - bufferLength | (nextByte & 0xFF) >> bufferLength) >>> 0;
  47058. }
  47059. if (n === 8 && bufferLength === 0) {
  47060. return this.stream.getByte();
  47061. }
  47062. while (bufferLength < n) {
  47063. buffer = buffer << 8 | this.stream.getByte();
  47064. bufferLength += 8;
  47065. }
  47066. bufferLength -= n;
  47067. this.bufferLength = bufferLength;
  47068. this.buffer = buffer & (1 << bufferLength) - 1;
  47069. return buffer >> bufferLength;
  47070. },
  47071. align: function MeshStreamReader_align() {
  47072. this.buffer = 0;
  47073. this.bufferLength = 0;
  47074. },
  47075. readFlag: function MeshStreamReader_readFlag() {
  47076. return this.readBits(this.context.bitsPerFlag);
  47077. },
  47078. readCoordinate: function MeshStreamReader_readCoordinate() {
  47079. var bitsPerCoordinate = this.context.bitsPerCoordinate;
  47080. var xi = this.readBits(bitsPerCoordinate);
  47081. var yi = this.readBits(bitsPerCoordinate);
  47082. var decode = this.context.decode;
  47083. var scale = bitsPerCoordinate < 32 ? 1 / ((1 << bitsPerCoordinate) - 1) : 2.3283064365386963e-10;
  47084. // 2 ^ -32
  47085. return [
  47086. xi * scale * (decode[1] - decode[0]) + decode[0],
  47087. yi * scale * (decode[3] - decode[2]) + decode[2]
  47088. ];
  47089. },
  47090. readComponents: function MeshStreamReader_readComponents() {
  47091. var numComps = this.context.numComps;
  47092. var bitsPerComponent = this.context.bitsPerComponent;
  47093. var scale = bitsPerComponent < 32 ? 1 / ((1 << bitsPerComponent) - 1) : 2.3283064365386963e-10;
  47094. // 2 ^ -32
  47095. var decode = this.context.decode;
  47096. var components = this.tmpCompsBuf;
  47097. for (var i = 0, j = 4; i < numComps; i++, j += 2) {
  47098. var ci = this.readBits(bitsPerComponent);
  47099. components[i] = ci * scale * (decode[j + 1] - decode[j]) + decode[j];
  47100. }
  47101. var color = this.tmpCsCompsBuf;
  47102. if (this.context.colorFn) {
  47103. this.context.colorFn(components, 0, color, 0);
  47104. }
  47105. return this.context.colorSpace.getRgb(color, 0);
  47106. }
  47107. };
  47108. function decodeType4Shading(mesh, reader) {
  47109. var coords = mesh.coords;
  47110. var colors = mesh.colors;
  47111. var operators = [];
  47112. var ps = [];
  47113. // not maintaining cs since that will match ps
  47114. var verticesLeft = 0;
  47115. // assuming we have all data to start a new triangle
  47116. while (reader.hasData) {
  47117. var f = reader.readFlag();
  47118. var coord = reader.readCoordinate();
  47119. var color = reader.readComponents();
  47120. if (verticesLeft === 0) {
  47121. // ignoring flags if we started a triangle
  47122. assert(0 <= f && f <= 2, 'Unknown type4 flag');
  47123. switch (f) {
  47124. case 0:
  47125. verticesLeft = 3;
  47126. break;
  47127. case 1:
  47128. ps.push(ps[ps.length - 2], ps[ps.length - 1]);
  47129. verticesLeft = 1;
  47130. break;
  47131. case 2:
  47132. ps.push(ps[ps.length - 3], ps[ps.length - 1]);
  47133. verticesLeft = 1;
  47134. break;
  47135. }
  47136. operators.push(f);
  47137. }
  47138. ps.push(coords.length);
  47139. coords.push(coord);
  47140. colors.push(color);
  47141. verticesLeft--;
  47142. reader.align();
  47143. }
  47144. mesh.figures.push({
  47145. type: 'triangles',
  47146. coords: new Int32Array(ps),
  47147. colors: new Int32Array(ps)
  47148. });
  47149. }
  47150. function decodeType5Shading(mesh, reader, verticesPerRow) {
  47151. var coords = mesh.coords;
  47152. var colors = mesh.colors;
  47153. var ps = [];
  47154. // not maintaining cs since that will match ps
  47155. while (reader.hasData) {
  47156. var coord = reader.readCoordinate();
  47157. var color = reader.readComponents();
  47158. ps.push(coords.length);
  47159. coords.push(coord);
  47160. colors.push(color);
  47161. }
  47162. mesh.figures.push({
  47163. type: 'lattice',
  47164. coords: new Int32Array(ps),
  47165. colors: new Int32Array(ps),
  47166. verticesPerRow: verticesPerRow
  47167. });
  47168. }
  47169. var MIN_SPLIT_PATCH_CHUNKS_AMOUNT = 3;
  47170. var MAX_SPLIT_PATCH_CHUNKS_AMOUNT = 20;
  47171. var TRIANGLE_DENSITY = 20;
  47172. // count of triangles per entire mesh bounds
  47173. var getB = function getBClosure() {
  47174. function buildB(count) {
  47175. var lut = [];
  47176. for (var i = 0; i <= count; i++) {
  47177. var t = i / count, t_ = 1 - t;
  47178. lut.push(new Float32Array([
  47179. t_ * t_ * t_,
  47180. 3 * t * t_ * t_,
  47181. 3 * t * t * t_,
  47182. t * t * t
  47183. ]));
  47184. }
  47185. return lut;
  47186. }
  47187. var cache = [];
  47188. return function getB(count) {
  47189. if (!cache[count]) {
  47190. cache[count] = buildB(count);
  47191. }
  47192. return cache[count];
  47193. };
  47194. }();
  47195. function buildFigureFromPatch(mesh, index) {
  47196. var figure = mesh.figures[index];
  47197. assert(figure.type === 'patch', 'Unexpected patch mesh figure');
  47198. var coords = mesh.coords, colors = mesh.colors;
  47199. var pi = figure.coords;
  47200. var ci = figure.colors;
  47201. var figureMinX = Math.min(coords[pi[0]][0], coords[pi[3]][0], coords[pi[12]][0], coords[pi[15]][0]);
  47202. var figureMinY = Math.min(coords[pi[0]][1], coords[pi[3]][1], coords[pi[12]][1], coords[pi[15]][1]);
  47203. var figureMaxX = Math.max(coords[pi[0]][0], coords[pi[3]][0], coords[pi[12]][0], coords[pi[15]][0]);
  47204. var figureMaxY = Math.max(coords[pi[0]][1], coords[pi[3]][1], coords[pi[12]][1], coords[pi[15]][1]);
  47205. var splitXBy = Math.ceil((figureMaxX - figureMinX) * TRIANGLE_DENSITY / (mesh.bounds[2] - mesh.bounds[0]));
  47206. splitXBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT, Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitXBy));
  47207. var splitYBy = Math.ceil((figureMaxY - figureMinY) * TRIANGLE_DENSITY / (mesh.bounds[3] - mesh.bounds[1]));
  47208. splitYBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT, Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitYBy));
  47209. var verticesPerRow = splitXBy + 1;
  47210. var figureCoords = new Int32Array((splitYBy + 1) * verticesPerRow);
  47211. var figureColors = new Int32Array((splitYBy + 1) * verticesPerRow);
  47212. var k = 0;
  47213. var cl = new Uint8Array(3), cr = new Uint8Array(3);
  47214. var c0 = colors[ci[0]], c1 = colors[ci[1]], c2 = colors[ci[2]], c3 = colors[ci[3]];
  47215. var bRow = getB(splitYBy), bCol = getB(splitXBy);
  47216. for (var row = 0; row <= splitYBy; row++) {
  47217. cl[0] = (c0[0] * (splitYBy - row) + c2[0] * row) / splitYBy | 0;
  47218. cl[1] = (c0[1] * (splitYBy - row) + c2[1] * row) / splitYBy | 0;
  47219. cl[2] = (c0[2] * (splitYBy - row) + c2[2] * row) / splitYBy | 0;
  47220. cr[0] = (c1[0] * (splitYBy - row) + c3[0] * row) / splitYBy | 0;
  47221. cr[1] = (c1[1] * (splitYBy - row) + c3[1] * row) / splitYBy | 0;
  47222. cr[2] = (c1[2] * (splitYBy - row) + c3[2] * row) / splitYBy | 0;
  47223. for (var col = 0; col <= splitXBy; col++, k++) {
  47224. if ((row === 0 || row === splitYBy) && (col === 0 || col === splitXBy)) {
  47225. continue;
  47226. }
  47227. var x = 0, y = 0;
  47228. var q = 0;
  47229. for (var i = 0; i <= 3; i++) {
  47230. for (var j = 0; j <= 3; j++, q++) {
  47231. var m = bRow[row][i] * bCol[col][j];
  47232. x += coords[pi[q]][0] * m;
  47233. y += coords[pi[q]][1] * m;
  47234. }
  47235. }
  47236. figureCoords[k] = coords.length;
  47237. coords.push([
  47238. x,
  47239. y
  47240. ]);
  47241. figureColors[k] = colors.length;
  47242. var newColor = new Uint8Array(3);
  47243. newColor[0] = (cl[0] * (splitXBy - col) + cr[0] * col) / splitXBy | 0;
  47244. newColor[1] = (cl[1] * (splitXBy - col) + cr[1] * col) / splitXBy | 0;
  47245. newColor[2] = (cl[2] * (splitXBy - col) + cr[2] * col) / splitXBy | 0;
  47246. colors.push(newColor);
  47247. }
  47248. }
  47249. figureCoords[0] = pi[0];
  47250. figureColors[0] = ci[0];
  47251. figureCoords[splitXBy] = pi[3];
  47252. figureColors[splitXBy] = ci[1];
  47253. figureCoords[verticesPerRow * splitYBy] = pi[12];
  47254. figureColors[verticesPerRow * splitYBy] = ci[2];
  47255. figureCoords[verticesPerRow * splitYBy + splitXBy] = pi[15];
  47256. figureColors[verticesPerRow * splitYBy + splitXBy] = ci[3];
  47257. mesh.figures[index] = {
  47258. type: 'lattice',
  47259. coords: figureCoords,
  47260. colors: figureColors,
  47261. verticesPerRow: verticesPerRow
  47262. };
  47263. }
  47264. function decodeType6Shading(mesh, reader) {
  47265. // A special case of Type 7. The p11, p12, p21, p22 automatically filled
  47266. var coords = mesh.coords;
  47267. var colors = mesh.colors;
  47268. var ps = new Int32Array(16);
  47269. // p00, p10, ..., p30, p01, ..., p33
  47270. var cs = new Int32Array(4);
  47271. // c00, c30, c03, c33
  47272. while (reader.hasData) {
  47273. var f = reader.readFlag();
  47274. assert(0 <= f && f <= 3, 'Unknown type6 flag');
  47275. var i, ii;
  47276. var pi = coords.length;
  47277. for (i = 0, ii = f !== 0 ? 8 : 12; i < ii; i++) {
  47278. coords.push(reader.readCoordinate());
  47279. }
  47280. var ci = colors.length;
  47281. for (i = 0, ii = f !== 0 ? 2 : 4; i < ii; i++) {
  47282. colors.push(reader.readComponents());
  47283. }
  47284. var tmp1, tmp2, tmp3, tmp4;
  47285. switch (f) {
  47286. case 0:
  47287. ps[12] = pi + 3;
  47288. ps[13] = pi + 4;
  47289. ps[14] = pi + 5;
  47290. ps[15] = pi + 6;
  47291. ps[8] = pi + 2;
  47292. /* values for 5, 6, 9, 10 are */
  47293. ps[11] = pi + 7;
  47294. ps[4] = pi + 1;
  47295. /* calculated below */
  47296. ps[7] = pi + 8;
  47297. ps[0] = pi;
  47298. ps[1] = pi + 11;
  47299. ps[2] = pi + 10;
  47300. ps[3] = pi + 9;
  47301. cs[2] = ci + 1;
  47302. cs[3] = ci + 2;
  47303. cs[0] = ci;
  47304. cs[1] = ci + 3;
  47305. break;
  47306. case 1:
  47307. tmp1 = ps[12];
  47308. tmp2 = ps[13];
  47309. tmp3 = ps[14];
  47310. tmp4 = ps[15];
  47311. ps[12] = tmp4;
  47312. ps[13] = pi + 0;
  47313. ps[14] = pi + 1;
  47314. ps[15] = pi + 2;
  47315. ps[8] = tmp3;
  47316. /* values for 5, 6, 9, 10 are */
  47317. ps[11] = pi + 3;
  47318. ps[4] = tmp2;
  47319. /* calculated below */
  47320. ps[7] = pi + 4;
  47321. ps[0] = tmp1;
  47322. ps[1] = pi + 7;
  47323. ps[2] = pi + 6;
  47324. ps[3] = pi + 5;
  47325. tmp1 = cs[2];
  47326. tmp2 = cs[3];
  47327. cs[2] = tmp2;
  47328. cs[3] = ci;
  47329. cs[0] = tmp1;
  47330. cs[1] = ci + 1;
  47331. break;
  47332. case 2:
  47333. tmp1 = ps[15];
  47334. tmp2 = ps[11];
  47335. ps[12] = ps[3];
  47336. ps[13] = pi + 0;
  47337. ps[14] = pi + 1;
  47338. ps[15] = pi + 2;
  47339. ps[8] = ps[7];
  47340. /* values for 5, 6, 9, 10 are */
  47341. ps[11] = pi + 3;
  47342. ps[4] = tmp2;
  47343. /* calculated below */
  47344. ps[7] = pi + 4;
  47345. ps[0] = tmp1;
  47346. ps[1] = pi + 7;
  47347. ps[2] = pi + 6;
  47348. ps[3] = pi + 5;
  47349. tmp1 = cs[3];
  47350. cs[2] = cs[1];
  47351. cs[3] = ci;
  47352. cs[0] = tmp1;
  47353. cs[1] = ci + 1;
  47354. break;
  47355. case 3:
  47356. ps[12] = ps[0];
  47357. ps[13] = pi + 0;
  47358. ps[14] = pi + 1;
  47359. ps[15] = pi + 2;
  47360. ps[8] = ps[1];
  47361. /* values for 5, 6, 9, 10 are */
  47362. ps[11] = pi + 3;
  47363. ps[4] = ps[2];
  47364. /* calculated below */
  47365. ps[7] = pi + 4;
  47366. ps[0] = ps[3];
  47367. ps[1] = pi + 7;
  47368. ps[2] = pi + 6;
  47369. ps[3] = pi + 5;
  47370. cs[2] = cs[0];
  47371. cs[3] = ci;
  47372. cs[0] = cs[1];
  47373. cs[1] = ci + 1;
  47374. break;
  47375. }
  47376. // set p11, p12, p21, p22
  47377. ps[5] = coords.length;
  47378. coords.push([
  47379. (-4 * coords[ps[0]][0] - coords[ps[15]][0] + 6 * (coords[ps[4]][0] + coords[ps[1]][0]) - 2 * (coords[ps[12]][0] + coords[ps[3]][0]) + 3 * (coords[ps[13]][0] + coords[ps[7]][0])) / 9,
  47380. (-4 * coords[ps[0]][1] - coords[ps[15]][1] + 6 * (coords[ps[4]][1] + coords[ps[1]][1]) - 2 * (coords[ps[12]][1] + coords[ps[3]][1]) + 3 * (coords[ps[13]][1] + coords[ps[7]][1])) / 9
  47381. ]);
  47382. ps[6] = coords.length;
  47383. coords.push([
  47384. (-4 * coords[ps[3]][0] - coords[ps[12]][0] + 6 * (coords[ps[2]][0] + coords[ps[7]][0]) - 2 * (coords[ps[0]][0] + coords[ps[15]][0]) + 3 * (coords[ps[4]][0] + coords[ps[14]][0])) / 9,
  47385. (-4 * coords[ps[3]][1] - coords[ps[12]][1] + 6 * (coords[ps[2]][1] + coords[ps[7]][1]) - 2 * (coords[ps[0]][1] + coords[ps[15]][1]) + 3 * (coords[ps[4]][1] + coords[ps[14]][1])) / 9
  47386. ]);
  47387. ps[9] = coords.length;
  47388. coords.push([
  47389. (-4 * coords[ps[12]][0] - coords[ps[3]][0] + 6 * (coords[ps[8]][0] + coords[ps[13]][0]) - 2 * (coords[ps[0]][0] + coords[ps[15]][0]) + 3 * (coords[ps[11]][0] + coords[ps[1]][0])) / 9,
  47390. (-4 * coords[ps[12]][1] - coords[ps[3]][1] + 6 * (coords[ps[8]][1] + coords[ps[13]][1]) - 2 * (coords[ps[0]][1] + coords[ps[15]][1]) + 3 * (coords[ps[11]][1] + coords[ps[1]][1])) / 9
  47391. ]);
  47392. ps[10] = coords.length;
  47393. coords.push([
  47394. (-4 * coords[ps[15]][0] - coords[ps[0]][0] + 6 * (coords[ps[11]][0] + coords[ps[14]][0]) - 2 * (coords[ps[12]][0] + coords[ps[3]][0]) + 3 * (coords[ps[2]][0] + coords[ps[8]][0])) / 9,
  47395. (-4 * coords[ps[15]][1] - coords[ps[0]][1] + 6 * (coords[ps[11]][1] + coords[ps[14]][1]) - 2 * (coords[ps[12]][1] + coords[ps[3]][1]) + 3 * (coords[ps[2]][1] + coords[ps[8]][1])) / 9
  47396. ]);
  47397. mesh.figures.push({
  47398. type: 'patch',
  47399. coords: new Int32Array(ps),
  47400. // making copies of ps and cs
  47401. colors: new Int32Array(cs)
  47402. });
  47403. }
  47404. }
  47405. function decodeType7Shading(mesh, reader) {
  47406. var coords = mesh.coords;
  47407. var colors = mesh.colors;
  47408. var ps = new Int32Array(16);
  47409. // p00, p10, ..., p30, p01, ..., p33
  47410. var cs = new Int32Array(4);
  47411. // c00, c30, c03, c33
  47412. while (reader.hasData) {
  47413. var f = reader.readFlag();
  47414. assert(0 <= f && f <= 3, 'Unknown type7 flag');
  47415. var i, ii;
  47416. var pi = coords.length;
  47417. for (i = 0, ii = f !== 0 ? 12 : 16; i < ii; i++) {
  47418. coords.push(reader.readCoordinate());
  47419. }
  47420. var ci = colors.length;
  47421. for (i = 0, ii = f !== 0 ? 2 : 4; i < ii; i++) {
  47422. colors.push(reader.readComponents());
  47423. }
  47424. var tmp1, tmp2, tmp3, tmp4;
  47425. switch (f) {
  47426. case 0:
  47427. ps[12] = pi + 3;
  47428. ps[13] = pi + 4;
  47429. ps[14] = pi + 5;
  47430. ps[15] = pi + 6;
  47431. ps[8] = pi + 2;
  47432. ps[9] = pi + 13;
  47433. ps[10] = pi + 14;
  47434. ps[11] = pi + 7;
  47435. ps[4] = pi + 1;
  47436. ps[5] = pi + 12;
  47437. ps[6] = pi + 15;
  47438. ps[7] = pi + 8;
  47439. ps[0] = pi;
  47440. ps[1] = pi + 11;
  47441. ps[2] = pi + 10;
  47442. ps[3] = pi + 9;
  47443. cs[2] = ci + 1;
  47444. cs[3] = ci + 2;
  47445. cs[0] = ci;
  47446. cs[1] = ci + 3;
  47447. break;
  47448. case 1:
  47449. tmp1 = ps[12];
  47450. tmp2 = ps[13];
  47451. tmp3 = ps[14];
  47452. tmp4 = ps[15];
  47453. ps[12] = tmp4;
  47454. ps[13] = pi + 0;
  47455. ps[14] = pi + 1;
  47456. ps[15] = pi + 2;
  47457. ps[8] = tmp3;
  47458. ps[9] = pi + 9;
  47459. ps[10] = pi + 10;
  47460. ps[11] = pi + 3;
  47461. ps[4] = tmp2;
  47462. ps[5] = pi + 8;
  47463. ps[6] = pi + 11;
  47464. ps[7] = pi + 4;
  47465. ps[0] = tmp1;
  47466. ps[1] = pi + 7;
  47467. ps[2] = pi + 6;
  47468. ps[3] = pi + 5;
  47469. tmp1 = cs[2];
  47470. tmp2 = cs[3];
  47471. cs[2] = tmp2;
  47472. cs[3] = ci;
  47473. cs[0] = tmp1;
  47474. cs[1] = ci + 1;
  47475. break;
  47476. case 2:
  47477. tmp1 = ps[15];
  47478. tmp2 = ps[11];
  47479. ps[12] = ps[3];
  47480. ps[13] = pi + 0;
  47481. ps[14] = pi + 1;
  47482. ps[15] = pi + 2;
  47483. ps[8] = ps[7];
  47484. ps[9] = pi + 9;
  47485. ps[10] = pi + 10;
  47486. ps[11] = pi + 3;
  47487. ps[4] = tmp2;
  47488. ps[5] = pi + 8;
  47489. ps[6] = pi + 11;
  47490. ps[7] = pi + 4;
  47491. ps[0] = tmp1;
  47492. ps[1] = pi + 7;
  47493. ps[2] = pi + 6;
  47494. ps[3] = pi + 5;
  47495. tmp1 = cs[3];
  47496. cs[2] = cs[1];
  47497. cs[3] = ci;
  47498. cs[0] = tmp1;
  47499. cs[1] = ci + 1;
  47500. break;
  47501. case 3:
  47502. ps[12] = ps[0];
  47503. ps[13] = pi + 0;
  47504. ps[14] = pi + 1;
  47505. ps[15] = pi + 2;
  47506. ps[8] = ps[1];
  47507. ps[9] = pi + 9;
  47508. ps[10] = pi + 10;
  47509. ps[11] = pi + 3;
  47510. ps[4] = ps[2];
  47511. ps[5] = pi + 8;
  47512. ps[6] = pi + 11;
  47513. ps[7] = pi + 4;
  47514. ps[0] = ps[3];
  47515. ps[1] = pi + 7;
  47516. ps[2] = pi + 6;
  47517. ps[3] = pi + 5;
  47518. cs[2] = cs[0];
  47519. cs[3] = ci;
  47520. cs[0] = cs[1];
  47521. cs[1] = ci + 1;
  47522. break;
  47523. }
  47524. mesh.figures.push({
  47525. type: 'patch',
  47526. coords: new Int32Array(ps),
  47527. // making copies of ps and cs
  47528. colors: new Int32Array(cs)
  47529. });
  47530. }
  47531. }
  47532. function updateBounds(mesh) {
  47533. var minX = mesh.coords[0][0], minY = mesh.coords[0][1], maxX = minX, maxY = minY;
  47534. for (var i = 1, ii = mesh.coords.length; i < ii; i++) {
  47535. var x = mesh.coords[i][0], y = mesh.coords[i][1];
  47536. minX = minX > x ? x : minX;
  47537. minY = minY > y ? y : minY;
  47538. maxX = maxX < x ? x : maxX;
  47539. maxY = maxY < y ? y : maxY;
  47540. }
  47541. mesh.bounds = [
  47542. minX,
  47543. minY,
  47544. maxX,
  47545. maxY
  47546. ];
  47547. }
  47548. function packData(mesh) {
  47549. var i, ii, j, jj;
  47550. var coords = mesh.coords;
  47551. var coordsPacked = new Float32Array(coords.length * 2);
  47552. for (i = 0, j = 0, ii = coords.length; i < ii; i++) {
  47553. var xy = coords[i];
  47554. coordsPacked[j++] = xy[0];
  47555. coordsPacked[j++] = xy[1];
  47556. }
  47557. mesh.coords = coordsPacked;
  47558. var colors = mesh.colors;
  47559. var colorsPacked = new Uint8Array(colors.length * 3);
  47560. for (i = 0, j = 0, ii = colors.length; i < ii; i++) {
  47561. var c = colors[i];
  47562. colorsPacked[j++] = c[0];
  47563. colorsPacked[j++] = c[1];
  47564. colorsPacked[j++] = c[2];
  47565. }
  47566. mesh.colors = colorsPacked;
  47567. var figures = mesh.figures;
  47568. for (i = 0, ii = figures.length; i < ii; i++) {
  47569. var figure = figures[i], ps = figure.coords, cs = figure.colors;
  47570. for (j = 0, jj = ps.length; j < jj; j++) {
  47571. ps[j] *= 2;
  47572. cs[j] *= 3;
  47573. }
  47574. }
  47575. }
  47576. function Mesh(stream, matrix, xref, res) {
  47577. assert(isStream(stream), 'Mesh data is not a stream');
  47578. var dict = stream.dict;
  47579. this.matrix = matrix;
  47580. this.shadingType = dict.get('ShadingType');
  47581. this.type = 'Pattern';
  47582. this.bbox = dict.getArray('BBox');
  47583. var cs = dict.get('ColorSpace', 'CS');
  47584. cs = ColorSpace.parse(cs, xref, res);
  47585. this.cs = cs;
  47586. this.background = dict.has('Background') ? cs.getRgb(dict.get('Background'), 0) : null;
  47587. var fnObj = dict.get('Function');
  47588. var fn = fnObj ? PDFFunction.parseArray(xref, fnObj) : null;
  47589. this.coords = [];
  47590. this.colors = [];
  47591. this.figures = [];
  47592. var decodeContext = {
  47593. bitsPerCoordinate: dict.get('BitsPerCoordinate'),
  47594. bitsPerComponent: dict.get('BitsPerComponent'),
  47595. bitsPerFlag: dict.get('BitsPerFlag'),
  47596. decode: dict.getArray('Decode'),
  47597. colorFn: fn,
  47598. colorSpace: cs,
  47599. numComps: fn ? 1 : cs.numComps
  47600. };
  47601. var reader = new MeshStreamReader(stream, decodeContext);
  47602. var patchMesh = false;
  47603. switch (this.shadingType) {
  47604. case ShadingType.FREE_FORM_MESH:
  47605. decodeType4Shading(this, reader);
  47606. break;
  47607. case ShadingType.LATTICE_FORM_MESH:
  47608. var verticesPerRow = dict.get('VerticesPerRow') | 0;
  47609. assert(verticesPerRow >= 2, 'Invalid VerticesPerRow');
  47610. decodeType5Shading(this, reader, verticesPerRow);
  47611. break;
  47612. case ShadingType.COONS_PATCH_MESH:
  47613. decodeType6Shading(this, reader);
  47614. patchMesh = true;
  47615. break;
  47616. case ShadingType.TENSOR_PATCH_MESH:
  47617. decodeType7Shading(this, reader);
  47618. patchMesh = true;
  47619. break;
  47620. default:
  47621. error('Unsupported mesh type.');
  47622. break;
  47623. }
  47624. if (patchMesh) {
  47625. // dirty bounds calculation for determining, how dense shall be triangles
  47626. updateBounds(this);
  47627. for (var i = 0, ii = this.figures.length; i < ii; i++) {
  47628. buildFigureFromPatch(this, i);
  47629. }
  47630. }
  47631. // calculate bounds
  47632. updateBounds(this);
  47633. packData(this);
  47634. }
  47635. Mesh.prototype = {
  47636. getIR: function Mesh_getIR() {
  47637. return [
  47638. 'Mesh',
  47639. this.shadingType,
  47640. this.coords,
  47641. this.colors,
  47642. this.figures,
  47643. this.bounds,
  47644. this.matrix,
  47645. this.bbox,
  47646. this.background
  47647. ];
  47648. }
  47649. };
  47650. return Mesh;
  47651. }();
  47652. Shadings.Dummy = function DummyClosure() {
  47653. function Dummy() {
  47654. this.type = 'Pattern';
  47655. }
  47656. Dummy.prototype = {
  47657. getIR: function Dummy_getIR() {
  47658. return ['Dummy'];
  47659. }
  47660. };
  47661. return Dummy;
  47662. }();
  47663. function getTilingPatternIR(operatorList, dict, args) {
  47664. var matrix = dict.getArray('Matrix');
  47665. var bbox = dict.getArray('BBox');
  47666. var xstep = dict.get('XStep');
  47667. var ystep = dict.get('YStep');
  47668. var paintType = dict.get('PaintType');
  47669. var tilingType = dict.get('TilingType');
  47670. return [
  47671. 'TilingPattern',
  47672. args,
  47673. operatorList,
  47674. matrix,
  47675. bbox,
  47676. xstep,
  47677. ystep,
  47678. paintType,
  47679. tilingType
  47680. ];
  47681. }
  47682. exports.Pattern = Pattern;
  47683. exports.getTilingPatternIR = getTilingPatternIR;
  47684. }));
  47685. (function (root, factory) {
  47686. factory(root.pdfjsCoreEvaluator = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreParser, root.pdfjsCoreImage, root.pdfjsCoreColorSpace, root.pdfjsCoreMurmurHash3, root.pdfjsCoreFonts, root.pdfjsCoreFunction, root.pdfjsCorePattern, root.pdfjsCoreCMap, root.pdfjsCoreMetrics, root.pdfjsCoreBidi, root.pdfjsCoreEncodings, root.pdfjsCoreStandardFonts, root.pdfjsCoreUnicode, root.pdfjsCoreGlyphList);
  47687. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreParser, coreImage, coreColorSpace, coreMurmurHash3, coreFonts, coreFunction, corePattern, coreCMap, coreMetrics, coreBidi, coreEncodings, coreStandardFonts, coreUnicode, coreGlyphList) {
  47688. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  47689. var IDENTITY_MATRIX = sharedUtil.IDENTITY_MATRIX;
  47690. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  47691. var ImageKind = sharedUtil.ImageKind;
  47692. var OPS = sharedUtil.OPS;
  47693. var TextRenderingMode = sharedUtil.TextRenderingMode;
  47694. var Util = sharedUtil.Util;
  47695. var assert = sharedUtil.assert;
  47696. var createPromiseCapability = sharedUtil.createPromiseCapability;
  47697. var error = sharedUtil.error;
  47698. var info = sharedUtil.info;
  47699. var isArray = sharedUtil.isArray;
  47700. var isNum = sharedUtil.isNum;
  47701. var isString = sharedUtil.isString;
  47702. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  47703. var warn = sharedUtil.warn;
  47704. var Dict = corePrimitives.Dict;
  47705. var Name = corePrimitives.Name;
  47706. var isCmd = corePrimitives.isCmd;
  47707. var isDict = corePrimitives.isDict;
  47708. var isName = corePrimitives.isName;
  47709. var isRef = corePrimitives.isRef;
  47710. var isStream = corePrimitives.isStream;
  47711. var DecodeStream = coreStream.DecodeStream;
  47712. var JpegStream = coreStream.JpegStream;
  47713. var Stream = coreStream.Stream;
  47714. var Lexer = coreParser.Lexer;
  47715. var Parser = coreParser.Parser;
  47716. var isEOF = coreParser.isEOF;
  47717. var PDFImage = coreImage.PDFImage;
  47718. var ColorSpace = coreColorSpace.ColorSpace;
  47719. var MurmurHash3_64 = coreMurmurHash3.MurmurHash3_64;
  47720. var ErrorFont = coreFonts.ErrorFont;
  47721. var FontFlags = coreFonts.FontFlags;
  47722. var Font = coreFonts.Font;
  47723. var IdentityToUnicodeMap = coreFonts.IdentityToUnicodeMap;
  47724. var ToUnicodeMap = coreFonts.ToUnicodeMap;
  47725. var getFontType = coreFonts.getFontType;
  47726. var isPDFFunction = coreFunction.isPDFFunction;
  47727. var PDFFunction = coreFunction.PDFFunction;
  47728. var Pattern = corePattern.Pattern;
  47729. var getTilingPatternIR = corePattern.getTilingPatternIR;
  47730. var CMapFactory = coreCMap.CMapFactory;
  47731. var IdentityCMap = coreCMap.IdentityCMap;
  47732. var getMetrics = coreMetrics.getMetrics;
  47733. var bidi = coreBidi.bidi;
  47734. var WinAnsiEncoding = coreEncodings.WinAnsiEncoding;
  47735. var StandardEncoding = coreEncodings.StandardEncoding;
  47736. var MacRomanEncoding = coreEncodings.MacRomanEncoding;
  47737. var SymbolSetEncoding = coreEncodings.SymbolSetEncoding;
  47738. var ZapfDingbatsEncoding = coreEncodings.ZapfDingbatsEncoding;
  47739. var getEncoding = coreEncodings.getEncoding;
  47740. var getStdFontMap = coreStandardFonts.getStdFontMap;
  47741. var getSerifFonts = coreStandardFonts.getSerifFonts;
  47742. var getSymbolsFonts = coreStandardFonts.getSymbolsFonts;
  47743. var getNormalizedUnicodes = coreUnicode.getNormalizedUnicodes;
  47744. var reverseIfRtl = coreUnicode.reverseIfRtl;
  47745. var getUnicodeForGlyph = coreUnicode.getUnicodeForGlyph;
  47746. var getGlyphsUnicode = coreGlyphList.getGlyphsUnicode;
  47747. var PartialEvaluator = function PartialEvaluatorClosure() {
  47748. var DefaultPartialEvaluatorOptions = {
  47749. forceDataSchema: false,
  47750. maxImageSize: -1,
  47751. disableFontFace: false,
  47752. cMapOptions: {
  47753. url: null,
  47754. packed: false
  47755. }
  47756. };
  47757. function NativeImageDecoder(xref, resources, handler, forceDataSchema) {
  47758. this.xref = xref;
  47759. this.resources = resources;
  47760. this.handler = handler;
  47761. this.forceDataSchema = forceDataSchema;
  47762. }
  47763. NativeImageDecoder.prototype = {
  47764. canDecode: function (image) {
  47765. return image instanceof JpegStream && NativeImageDecoder.isDecodable(image, this.xref, this.resources);
  47766. },
  47767. decode: function (image) {
  47768. // For natively supported JPEGs send them to the main thread for decoding.
  47769. var dict = image.dict;
  47770. var colorSpace = dict.get('ColorSpace', 'CS');
  47771. colorSpace = ColorSpace.parse(colorSpace, this.xref, this.resources);
  47772. var numComps = colorSpace.numComps;
  47773. var decodePromise = this.handler.sendWithPromise('JpegDecode', [
  47774. image.getIR(this.forceDataSchema),
  47775. numComps
  47776. ]);
  47777. return decodePromise.then(function (message) {
  47778. var data = message.data;
  47779. return new Stream(data, 0, data.length, image.dict);
  47780. });
  47781. }
  47782. };
  47783. /**
  47784. * Checks if the image can be decoded and displayed by the browser without any
  47785. * further processing such as color space conversions.
  47786. */
  47787. NativeImageDecoder.isSupported = function NativeImageDecoder_isSupported(image, xref, res) {
  47788. var dict = image.dict;
  47789. if (dict.has('DecodeParms') || dict.has('DP')) {
  47790. return false;
  47791. }
  47792. var cs = ColorSpace.parse(dict.get('ColorSpace', 'CS'), xref, res);
  47793. return (cs.name === 'DeviceGray' || cs.name === 'DeviceRGB') && cs.isDefaultDecode(dict.getArray('Decode', 'D'));
  47794. };
  47795. /**
  47796. * Checks if the image can be decoded by the browser.
  47797. */
  47798. NativeImageDecoder.isDecodable = function NativeImageDecoder_isDecodable(image, xref, res) {
  47799. var dict = image.dict;
  47800. if (dict.has('DecodeParms') || dict.has('DP')) {
  47801. return false;
  47802. }
  47803. var cs = ColorSpace.parse(dict.get('ColorSpace', 'CS'), xref, res);
  47804. return (cs.numComps === 1 || cs.numComps === 3) && cs.isDefaultDecode(dict.getArray('Decode', 'D'));
  47805. };
  47806. function PartialEvaluator(pdfManager, xref, handler, pageIndex, uniquePrefix, idCounters, fontCache, options) {
  47807. this.pdfManager = pdfManager;
  47808. this.xref = xref;
  47809. this.handler = handler;
  47810. this.pageIndex = pageIndex;
  47811. this.uniquePrefix = uniquePrefix;
  47812. this.idCounters = idCounters;
  47813. this.fontCache = fontCache;
  47814. this.options = options || DefaultPartialEvaluatorOptions;
  47815. }
  47816. // Trying to minimize Date.now() usage and check every 100 time
  47817. var TIME_SLOT_DURATION_MS = 20;
  47818. var CHECK_TIME_EVERY = 100;
  47819. function TimeSlotManager() {
  47820. this.reset();
  47821. }
  47822. TimeSlotManager.prototype = {
  47823. check: function TimeSlotManager_check() {
  47824. if (++this.checked < CHECK_TIME_EVERY) {
  47825. return false;
  47826. }
  47827. this.checked = 0;
  47828. return this.endTime <= Date.now();
  47829. },
  47830. reset: function TimeSlotManager_reset() {
  47831. this.endTime = Date.now() + TIME_SLOT_DURATION_MS;
  47832. this.checked = 0;
  47833. }
  47834. };
  47835. var deferred = Promise.resolve();
  47836. var TILING_PATTERN = 1, SHADING_PATTERN = 2;
  47837. PartialEvaluator.prototype = {
  47838. hasBlendModes: function PartialEvaluator_hasBlendModes(resources) {
  47839. if (!isDict(resources)) {
  47840. return false;
  47841. }
  47842. var processed = Object.create(null);
  47843. if (resources.objId) {
  47844. processed[resources.objId] = true;
  47845. }
  47846. var nodes = [resources], xref = this.xref;
  47847. while (nodes.length) {
  47848. var key, i, ii;
  47849. var node = nodes.shift();
  47850. // First check the current resources for blend modes.
  47851. var graphicStates = node.get('ExtGState');
  47852. if (isDict(graphicStates)) {
  47853. var graphicStatesKeys = graphicStates.getKeys();
  47854. for (i = 0, ii = graphicStatesKeys.length; i < ii; i++) {
  47855. key = graphicStatesKeys[i];
  47856. var graphicState = graphicStates.get(key);
  47857. var bm = graphicState.get('BM');
  47858. if (isName(bm) && bm.name !== 'Normal') {
  47859. return true;
  47860. }
  47861. }
  47862. }
  47863. // Descend into the XObjects to look for more resources and blend modes.
  47864. var xObjects = node.get('XObject');
  47865. if (!isDict(xObjects)) {
  47866. continue;
  47867. }
  47868. var xObjectsKeys = xObjects.getKeys();
  47869. for (i = 0, ii = xObjectsKeys.length; i < ii; i++) {
  47870. key = xObjectsKeys[i];
  47871. var xObject = xObjects.getRaw(key);
  47872. if (isRef(xObject)) {
  47873. if (processed[xObject.toString()]) {
  47874. // The XObject has already been processed, and by avoiding a
  47875. // redundant `xref.fetch` we can *significantly* reduce the load
  47876. // time for badly generated PDF files (fixes issue6961.pdf).
  47877. continue;
  47878. }
  47879. xObject = xref.fetch(xObject);
  47880. }
  47881. if (!isStream(xObject)) {
  47882. continue;
  47883. }
  47884. if (xObject.dict.objId) {
  47885. if (processed[xObject.dict.objId]) {
  47886. // stream has objId and is processed already
  47887. continue;
  47888. }
  47889. processed[xObject.dict.objId] = true;
  47890. }
  47891. var xResources = xObject.dict.get('Resources');
  47892. // Checking objId to detect an infinite loop.
  47893. if (isDict(xResources) && (!xResources.objId || !processed[xResources.objId])) {
  47894. nodes.push(xResources);
  47895. if (xResources.objId) {
  47896. processed[xResources.objId] = true;
  47897. }
  47898. }
  47899. }
  47900. }
  47901. return false;
  47902. },
  47903. buildFormXObject: function PartialEvaluator_buildFormXObject(resources, xobj, smask, operatorList, task, initialState) {
  47904. var matrix = xobj.dict.getArray('Matrix');
  47905. var bbox = xobj.dict.getArray('BBox');
  47906. var group = xobj.dict.get('Group');
  47907. if (group) {
  47908. var groupOptions = {
  47909. matrix: matrix,
  47910. bbox: bbox,
  47911. smask: smask,
  47912. isolated: false,
  47913. knockout: false
  47914. };
  47915. var groupSubtype = group.get('S');
  47916. var colorSpace;
  47917. if (isName(groupSubtype, 'Transparency')) {
  47918. groupOptions.isolated = group.get('I') || false;
  47919. groupOptions.knockout = group.get('K') || false;
  47920. colorSpace = group.has('CS') ? ColorSpace.parse(group.get('CS'), this.xref, resources) : null;
  47921. }
  47922. if (smask && smask.backdrop) {
  47923. colorSpace = colorSpace || ColorSpace.singletons.rgb;
  47924. smask.backdrop = colorSpace.getRgb(smask.backdrop, 0);
  47925. }
  47926. operatorList.addOp(OPS.beginGroup, [groupOptions]);
  47927. }
  47928. operatorList.addOp(OPS.paintFormXObjectBegin, [
  47929. matrix,
  47930. bbox
  47931. ]);
  47932. return this.getOperatorList(xobj, task, xobj.dict.get('Resources') || resources, operatorList, initialState).then(function () {
  47933. operatorList.addOp(OPS.paintFormXObjectEnd, []);
  47934. if (group) {
  47935. operatorList.addOp(OPS.endGroup, [groupOptions]);
  47936. }
  47937. });
  47938. },
  47939. buildPaintImageXObject: function PartialEvaluator_buildPaintImageXObject(resources, image, inline, operatorList, cacheKey, imageCache) {
  47940. var self = this;
  47941. var dict = image.dict;
  47942. var w = dict.get('Width', 'W');
  47943. var h = dict.get('Height', 'H');
  47944. if (!(w && isNum(w)) || !(h && isNum(h))) {
  47945. warn('Image dimensions are missing, or not numbers.');
  47946. return;
  47947. }
  47948. var maxImageSize = this.options.maxImageSize;
  47949. if (maxImageSize !== -1 && w * h > maxImageSize) {
  47950. warn('Image exceeded maximum allowed size and was removed.');
  47951. return;
  47952. }
  47953. var imageMask = dict.get('ImageMask', 'IM') || false;
  47954. var imgData, args;
  47955. if (imageMask) {
  47956. // This depends on a tmpCanvas being filled with the
  47957. // current fillStyle, such that processing the pixel
  47958. // data can't be done here. Instead of creating a
  47959. // complete PDFImage, only read the information needed
  47960. // for later.
  47961. var width = dict.get('Width', 'W');
  47962. var height = dict.get('Height', 'H');
  47963. var bitStrideLength = width + 7 >> 3;
  47964. var imgArray = image.getBytes(bitStrideLength * height);
  47965. var decode = dict.getArray('Decode', 'D');
  47966. var inverseDecode = !!decode && decode[0] > 0;
  47967. imgData = PDFImage.createMask(imgArray, width, height, image instanceof DecodeStream, inverseDecode);
  47968. imgData.cached = true;
  47969. args = [imgData];
  47970. operatorList.addOp(OPS.paintImageMaskXObject, args);
  47971. if (cacheKey) {
  47972. imageCache[cacheKey] = {
  47973. fn: OPS.paintImageMaskXObject,
  47974. args: args
  47975. };
  47976. }
  47977. return;
  47978. }
  47979. var softMask = dict.get('SMask', 'SM') || false;
  47980. var mask = dict.get('Mask') || false;
  47981. var SMALL_IMAGE_DIMENSIONS = 200;
  47982. // Inlining small images into the queue as RGB data
  47983. if (inline && !softMask && !mask && !(image instanceof JpegStream) && w + h < SMALL_IMAGE_DIMENSIONS) {
  47984. var imageObj = new PDFImage(this.xref, resources, image, inline, null, null);
  47985. // We force the use of RGBA_32BPP images here, because we can't handle
  47986. // any other kind.
  47987. imgData = imageObj.createImageData(/* forceRGBA = */
  47988. true);
  47989. operatorList.addOp(OPS.paintInlineImageXObject, [imgData]);
  47990. return;
  47991. }
  47992. // If there is no imageMask, create the PDFImage and a lot
  47993. // of image processing can be done here.
  47994. var uniquePrefix = this.uniquePrefix || '';
  47995. var objId = 'img_' + uniquePrefix + ++this.idCounters.obj;
  47996. operatorList.addDependency(objId);
  47997. args = [
  47998. objId,
  47999. w,
  48000. h
  48001. ];
  48002. if (!softMask && !mask && image instanceof JpegStream && NativeImageDecoder.isSupported(image, this.xref, resources)) {
  48003. // These JPEGs don't need any more processing so we can just send it.
  48004. operatorList.addOp(OPS.paintJpegXObject, args);
  48005. this.handler.send('obj', [
  48006. objId,
  48007. this.pageIndex,
  48008. 'JpegStream',
  48009. image.getIR(this.options.forceDataSchema)
  48010. ]);
  48011. return;
  48012. }
  48013. // Creates native image decoder only if a JPEG image or mask is present.
  48014. var nativeImageDecoder = null;
  48015. if (image instanceof JpegStream || mask instanceof JpegStream || softMask instanceof JpegStream) {
  48016. nativeImageDecoder = new NativeImageDecoder(self.xref, resources, self.handler, self.options.forceDataSchema);
  48017. }
  48018. PDFImage.buildImage(self.handler, self.xref, resources, image, inline, nativeImageDecoder).then(function (imageObj) {
  48019. var imgData = imageObj.createImageData(/* forceRGBA = */
  48020. false);
  48021. self.handler.send('obj', [
  48022. objId,
  48023. self.pageIndex,
  48024. 'Image',
  48025. imgData
  48026. ], [imgData.data.buffer]);
  48027. }).then(undefined, function (reason) {
  48028. warn('Unable to decode image: ' + reason);
  48029. self.handler.send('obj', [
  48030. objId,
  48031. self.pageIndex,
  48032. 'Image',
  48033. null
  48034. ]);
  48035. });
  48036. operatorList.addOp(OPS.paintImageXObject, args);
  48037. if (cacheKey) {
  48038. imageCache[cacheKey] = {
  48039. fn: OPS.paintImageXObject,
  48040. args: args
  48041. };
  48042. }
  48043. },
  48044. handleSMask: function PartialEvaluator_handleSmask(smask, resources, operatorList, task, stateManager) {
  48045. var smaskContent = smask.get('G');
  48046. var smaskOptions = {
  48047. subtype: smask.get('S').name,
  48048. backdrop: smask.get('BC')
  48049. };
  48050. // The SMask might have a alpha/luminosity value transfer function --
  48051. // we will build a map of integer values in range 0..255 to be fast.
  48052. var transferObj = smask.get('TR');
  48053. if (isPDFFunction(transferObj)) {
  48054. var transferFn = PDFFunction.parse(this.xref, transferObj);
  48055. var transferMap = new Uint8Array(256);
  48056. var tmp = new Float32Array(1);
  48057. for (var i = 0; i < 256; i++) {
  48058. tmp[0] = i / 255;
  48059. transferFn(tmp, 0, tmp, 0);
  48060. transferMap[i] = tmp[0] * 255 | 0;
  48061. }
  48062. smaskOptions.transferMap = transferMap;
  48063. }
  48064. return this.buildFormXObject(resources, smaskContent, smaskOptions, operatorList, task, stateManager.state.clone());
  48065. },
  48066. handleTilingType: function PartialEvaluator_handleTilingType(fn, args, resources, pattern, patternDict, operatorList, task) {
  48067. // Create an IR of the pattern code.
  48068. var tilingOpList = new OperatorList();
  48069. // Merge the available resources, to prevent issues when the patternDict
  48070. // is missing some /Resources entries (fixes issue6541.pdf).
  48071. var resourcesArray = [
  48072. patternDict.get('Resources'),
  48073. resources
  48074. ];
  48075. var patternResources = Dict.merge(this.xref, resourcesArray);
  48076. return this.getOperatorList(pattern, task, patternResources, tilingOpList).then(function () {
  48077. // Add the dependencies to the parent operator list so they are
  48078. // resolved before sub operator list is executed synchronously.
  48079. operatorList.addDependencies(tilingOpList.dependencies);
  48080. operatorList.addOp(fn, getTilingPatternIR({
  48081. fnArray: tilingOpList.fnArray,
  48082. argsArray: tilingOpList.argsArray
  48083. }, patternDict, args));
  48084. });
  48085. },
  48086. handleSetFont: function PartialEvaluator_handleSetFont(resources, fontArgs, fontRef, operatorList, task, state) {
  48087. // TODO(mack): Not needed?
  48088. var fontName;
  48089. if (fontArgs) {
  48090. fontArgs = fontArgs.slice();
  48091. fontName = fontArgs[0].name;
  48092. }
  48093. var self = this;
  48094. return this.loadFont(fontName, fontRef, this.xref, resources).then(function (translated) {
  48095. if (!translated.font.isType3Font) {
  48096. return translated;
  48097. }
  48098. return translated.loadType3Data(self, resources, operatorList, task).then(function () {
  48099. return translated;
  48100. }, function (reason) {
  48101. // Error in the font data -- sending unsupported feature notification.
  48102. self.handler.send('UnsupportedFeature', { featureId: UNSUPPORTED_FEATURES.font });
  48103. return new TranslatedFont('g_font_error', new ErrorFont('Type3 font load error: ' + reason), translated.font);
  48104. });
  48105. }).then(function (translated) {
  48106. state.font = translated.font;
  48107. translated.send(self.handler);
  48108. return translated.loadedName;
  48109. });
  48110. },
  48111. handleText: function PartialEvaluator_handleText(chars, state) {
  48112. var font = state.font;
  48113. var glyphs = font.charsToGlyphs(chars);
  48114. var isAddToPathSet = !!(state.textRenderingMode & TextRenderingMode.ADD_TO_PATH_FLAG);
  48115. if (font.data && (isAddToPathSet || this.options.disableFontFace)) {
  48116. var buildPath = function (fontChar) {
  48117. if (!font.renderer.hasBuiltPath(fontChar)) {
  48118. var path = font.renderer.getPathJs(fontChar);
  48119. this.handler.send('commonobj', [
  48120. font.loadedName + '_path_' + fontChar,
  48121. 'FontPath',
  48122. path
  48123. ]);
  48124. }
  48125. }.bind(this);
  48126. for (var i = 0, ii = glyphs.length; i < ii; i++) {
  48127. var glyph = glyphs[i];
  48128. buildPath(glyph.fontChar);
  48129. // If the glyph has an accent we need to build a path for its
  48130. // fontChar too, otherwise CanvasGraphics_paintChar will fail.
  48131. var accent = glyph.accent;
  48132. if (accent && accent.fontChar) {
  48133. buildPath(accent.fontChar);
  48134. }
  48135. }
  48136. }
  48137. return glyphs;
  48138. },
  48139. setGState: function PartialEvaluator_setGState(resources, gState, operatorList, task, xref, stateManager) {
  48140. // This array holds the converted/processed state data.
  48141. var gStateObj = [];
  48142. var gStateKeys = gState.getKeys();
  48143. var self = this;
  48144. var promise = Promise.resolve();
  48145. for (var i = 0, ii = gStateKeys.length; i < ii; i++) {
  48146. var key = gStateKeys[i];
  48147. var value = gState.get(key);
  48148. switch (key) {
  48149. case 'Type':
  48150. break;
  48151. case 'LW':
  48152. case 'LC':
  48153. case 'LJ':
  48154. case 'ML':
  48155. case 'D':
  48156. case 'RI':
  48157. case 'FL':
  48158. case 'CA':
  48159. case 'ca':
  48160. gStateObj.push([
  48161. key,
  48162. value
  48163. ]);
  48164. break;
  48165. case 'Font':
  48166. promise = promise.then(function () {
  48167. return self.handleSetFont(resources, null, value[0], operatorList, task, stateManager.state).then(function (loadedName) {
  48168. operatorList.addDependency(loadedName);
  48169. gStateObj.push([
  48170. key,
  48171. [
  48172. loadedName,
  48173. value[1]
  48174. ]
  48175. ]);
  48176. });
  48177. });
  48178. break;
  48179. case 'BM':
  48180. gStateObj.push([
  48181. key,
  48182. value
  48183. ]);
  48184. break;
  48185. case 'SMask':
  48186. if (isName(value, 'None')) {
  48187. gStateObj.push([
  48188. key,
  48189. false
  48190. ]);
  48191. break;
  48192. }
  48193. if (isDict(value)) {
  48194. promise = promise.then(function (dict) {
  48195. return self.handleSMask(dict, resources, operatorList, task, stateManager);
  48196. }.bind(this, value));
  48197. gStateObj.push([
  48198. key,
  48199. true
  48200. ]);
  48201. } else {
  48202. warn('Unsupported SMask type');
  48203. }
  48204. break;
  48205. // Only generate info log messages for the following since
  48206. // they are unlikely to have a big impact on the rendering.
  48207. case 'OP':
  48208. case 'op':
  48209. case 'OPM':
  48210. case 'BG':
  48211. case 'BG2':
  48212. case 'UCR':
  48213. case 'UCR2':
  48214. case 'TR':
  48215. case 'TR2':
  48216. case 'HT':
  48217. case 'SM':
  48218. case 'SA':
  48219. case 'AIS':
  48220. case 'TK':
  48221. // TODO implement these operators.
  48222. info('graphic state operator ' + key);
  48223. break;
  48224. default:
  48225. info('Unknown graphic state operator ' + key);
  48226. break;
  48227. }
  48228. }
  48229. return promise.then(function () {
  48230. if (gStateObj.length > 0) {
  48231. operatorList.addOp(OPS.setGState, [gStateObj]);
  48232. }
  48233. });
  48234. },
  48235. loadFont: function PartialEvaluator_loadFont(fontName, font, xref, resources) {
  48236. function errorFont() {
  48237. return Promise.resolve(new TranslatedFont('g_font_error', new ErrorFont('Font ' + fontName + ' is not available'), font));
  48238. }
  48239. var fontRef;
  48240. if (font) {
  48241. // Loading by ref.
  48242. assert(isRef(font));
  48243. fontRef = font;
  48244. } else {
  48245. // Loading by name.
  48246. var fontRes = resources.get('Font');
  48247. if (fontRes) {
  48248. fontRef = fontRes.getRaw(fontName);
  48249. } else {
  48250. warn('fontRes not available');
  48251. return errorFont();
  48252. }
  48253. }
  48254. if (!fontRef) {
  48255. warn('fontRef not available');
  48256. return errorFont();
  48257. }
  48258. if (this.fontCache.has(fontRef)) {
  48259. return this.fontCache.get(fontRef);
  48260. }
  48261. font = xref.fetchIfRef(fontRef);
  48262. if (!isDict(font)) {
  48263. return errorFont();
  48264. }
  48265. // We are holding `font.translated` references just for `fontRef`s that
  48266. // are not actually `Ref`s, but rather `Dict`s. See explanation below.
  48267. if (font.translated) {
  48268. return font.translated;
  48269. }
  48270. var fontCapability = createPromiseCapability();
  48271. var preEvaluatedFont = this.preEvaluateFont(font, xref);
  48272. var descriptor = preEvaluatedFont.descriptor;
  48273. var fontRefIsRef = isRef(fontRef), fontID;
  48274. if (fontRefIsRef) {
  48275. fontID = fontRef.toString();
  48276. }
  48277. if (isDict(descriptor)) {
  48278. if (!descriptor.fontAliases) {
  48279. descriptor.fontAliases = Object.create(null);
  48280. }
  48281. var fontAliases = descriptor.fontAliases;
  48282. var hash = preEvaluatedFont.hash;
  48283. if (fontAliases[hash]) {
  48284. var aliasFontRef = fontAliases[hash].aliasRef;
  48285. if (fontRefIsRef && aliasFontRef && this.fontCache.has(aliasFontRef)) {
  48286. this.fontCache.putAlias(fontRef, aliasFontRef);
  48287. return this.fontCache.get(fontRef);
  48288. }
  48289. } else {
  48290. fontAliases[hash] = { fontID: Font.getFontID() };
  48291. }
  48292. if (fontRefIsRef) {
  48293. fontAliases[hash].aliasRef = fontRef;
  48294. }
  48295. fontID = fontAliases[hash].fontID;
  48296. }
  48297. // Workaround for bad PDF generators that reference fonts incorrectly,
  48298. // where `fontRef` is a `Dict` rather than a `Ref` (fixes bug946506.pdf).
  48299. // In this case we should not put the font into `this.fontCache` (which is
  48300. // a `RefSetCache`), since it's not meaningful to use a `Dict` as a key.
  48301. //
  48302. // However, if we don't cache the font it's not possible to remove it
  48303. // when `cleanup` is triggered from the API, which causes issues on
  48304. // subsequent rendering operations (see issue7403.pdf).
  48305. // A simple workaround would be to just not hold `font.translated`
  48306. // references in this case, but this would force us to unnecessarily load
  48307. // the same fonts over and over.
  48308. //
  48309. // Instead, we cheat a bit by attempting to use a modified `fontID` as a
  48310. // key in `this.fontCache`, to allow the font to be cached.
  48311. // NOTE: This works because `RefSetCache` calls `toString()` on provided
  48312. // keys. Also, since `fontRef` is used when getting cached fonts,
  48313. // we'll not accidentally match fonts cached with the `fontID`.
  48314. if (fontRefIsRef) {
  48315. this.fontCache.put(fontRef, fontCapability.promise);
  48316. } else {
  48317. if (!fontID) {
  48318. fontID = (this.uniquePrefix || 'F_') + ++this.idCounters.obj;
  48319. }
  48320. this.fontCache.put('id_' + fontID, fontCapability.promise);
  48321. }
  48322. assert(fontID, 'The "fontID" must be defined.');
  48323. // Keep track of each font we translated so the caller can
  48324. // load them asynchronously before calling display on a page.
  48325. font.loadedName = 'g_' + this.pdfManager.docId + '_f' + fontID;
  48326. font.translated = fontCapability.promise;
  48327. // TODO move promises into translate font
  48328. var translatedPromise;
  48329. try {
  48330. translatedPromise = this.translateFont(preEvaluatedFont, xref);
  48331. } catch (e) {
  48332. translatedPromise = Promise.reject(e);
  48333. }
  48334. var self = this;
  48335. translatedPromise.then(function (translatedFont) {
  48336. if (translatedFont.fontType !== undefined) {
  48337. var xrefFontStats = xref.stats.fontTypes;
  48338. xrefFontStats[translatedFont.fontType] = true;
  48339. }
  48340. fontCapability.resolve(new TranslatedFont(font.loadedName, translatedFont, font));
  48341. }, function (reason) {
  48342. // TODO fontCapability.reject?
  48343. // Error in the font data -- sending unsupported feature notification.
  48344. self.handler.send('UnsupportedFeature', { featureId: UNSUPPORTED_FEATURES.font });
  48345. try {
  48346. // error, but it's still nice to have font type reported
  48347. var descriptor = preEvaluatedFont.descriptor;
  48348. var fontFile3 = descriptor && descriptor.get('FontFile3');
  48349. var subtype = fontFile3 && fontFile3.get('Subtype');
  48350. var fontType = getFontType(preEvaluatedFont.type, subtype && subtype.name);
  48351. var xrefFontStats = xref.stats.fontTypes;
  48352. xrefFontStats[fontType] = true;
  48353. } catch (ex) {
  48354. }
  48355. fontCapability.resolve(new TranslatedFont(font.loadedName, new ErrorFont(reason instanceof Error ? reason.message : reason), font));
  48356. });
  48357. return fontCapability.promise;
  48358. },
  48359. buildPath: function PartialEvaluator_buildPath(operatorList, fn, args) {
  48360. var lastIndex = operatorList.length - 1;
  48361. if (!args) {
  48362. args = [];
  48363. }
  48364. if (lastIndex < 0 || operatorList.fnArray[lastIndex] !== OPS.constructPath) {
  48365. operatorList.addOp(OPS.constructPath, [
  48366. [fn],
  48367. args
  48368. ]);
  48369. } else {
  48370. var opArgs = operatorList.argsArray[lastIndex];
  48371. opArgs[0].push(fn);
  48372. Array.prototype.push.apply(opArgs[1], args);
  48373. }
  48374. },
  48375. handleColorN: function PartialEvaluator_handleColorN(operatorList, fn, args, cs, patterns, resources, task, xref) {
  48376. // compile tiling patterns
  48377. var patternName = args[args.length - 1];
  48378. // SCN/scn applies patterns along with normal colors
  48379. var pattern;
  48380. if (isName(patternName) && (pattern = patterns.get(patternName.name))) {
  48381. var dict = isStream(pattern) ? pattern.dict : pattern;
  48382. var typeNum = dict.get('PatternType');
  48383. if (typeNum === TILING_PATTERN) {
  48384. var color = cs.base ? cs.base.getRgb(args, 0) : null;
  48385. return this.handleTilingType(fn, color, resources, pattern, dict, operatorList, task);
  48386. } else if (typeNum === SHADING_PATTERN) {
  48387. var shading = dict.get('Shading');
  48388. var matrix = dict.getArray('Matrix');
  48389. pattern = Pattern.parseShading(shading, matrix, xref, resources, this.handler);
  48390. operatorList.addOp(fn, pattern.getIR());
  48391. return Promise.resolve();
  48392. } else {
  48393. return Promise.reject('Unknown PatternType: ' + typeNum);
  48394. }
  48395. }
  48396. // TODO shall we fail here?
  48397. operatorList.addOp(fn, args);
  48398. return Promise.resolve();
  48399. },
  48400. getOperatorList: function PartialEvaluator_getOperatorList(stream, task, resources, operatorList, initialState) {
  48401. var self = this;
  48402. var xref = this.xref;
  48403. var imageCache = Object.create(null);
  48404. assert(operatorList);
  48405. resources = resources || Dict.empty;
  48406. var xobjs = resources.get('XObject') || Dict.empty;
  48407. var patterns = resources.get('Pattern') || Dict.empty;
  48408. var stateManager = new StateManager(initialState || new EvalState());
  48409. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  48410. var timeSlotManager = new TimeSlotManager();
  48411. return new Promise(function promiseBody(resolve, reject) {
  48412. var next = function (promise) {
  48413. promise.then(function () {
  48414. try {
  48415. promiseBody(resolve, reject);
  48416. } catch (ex) {
  48417. reject(ex);
  48418. }
  48419. }, reject);
  48420. };
  48421. task.ensureNotTerminated();
  48422. timeSlotManager.reset();
  48423. var stop, operation = {}, i, ii, cs;
  48424. while (!(stop = timeSlotManager.check())) {
  48425. // The arguments parsed by read() are used beyond this loop, so we
  48426. // cannot reuse the same array on each iteration. Therefore we pass
  48427. // in |null| as the initial value (see the comment on
  48428. // EvaluatorPreprocessor_read() for why).
  48429. operation.args = null;
  48430. if (!preprocessor.read(operation)) {
  48431. break;
  48432. }
  48433. var args = operation.args;
  48434. var fn = operation.fn;
  48435. switch (fn | 0) {
  48436. case OPS.paintXObject:
  48437. if (args[0].code) {
  48438. break;
  48439. }
  48440. // eagerly compile XForm objects
  48441. var name = args[0].name;
  48442. if (!name) {
  48443. warn('XObject must be referred to by name.');
  48444. continue;
  48445. }
  48446. if (imageCache[name] !== undefined) {
  48447. operatorList.addOp(imageCache[name].fn, imageCache[name].args);
  48448. args = null;
  48449. continue;
  48450. }
  48451. var xobj = xobjs.get(name);
  48452. if (xobj) {
  48453. assert(isStream(xobj), 'XObject should be a stream');
  48454. var type = xobj.dict.get('Subtype');
  48455. assert(isName(type), 'XObject should have a Name subtype');
  48456. if (type.name === 'Form') {
  48457. stateManager.save();
  48458. next(self.buildFormXObject(resources, xobj, null, operatorList, task, stateManager.state.clone()).then(function () {
  48459. stateManager.restore();
  48460. }));
  48461. return;
  48462. } else if (type.name === 'Image') {
  48463. self.buildPaintImageXObject(resources, xobj, false, operatorList, name, imageCache);
  48464. args = null;
  48465. continue;
  48466. } else if (type.name === 'PS') {
  48467. // PostScript XObjects are unused when viewing documents.
  48468. // See section 4.7.1 of Adobe's PDF reference.
  48469. info('Ignored XObject subtype PS');
  48470. continue;
  48471. } else {
  48472. error('Unhandled XObject subtype ' + type.name);
  48473. }
  48474. }
  48475. break;
  48476. case OPS.setFont:
  48477. var fontSize = args[1];
  48478. // eagerly collect all fonts
  48479. next(self.handleSetFont(resources, args, null, operatorList, task, stateManager.state).then(function (loadedName) {
  48480. operatorList.addDependency(loadedName);
  48481. operatorList.addOp(OPS.setFont, [
  48482. loadedName,
  48483. fontSize
  48484. ]);
  48485. }));
  48486. return;
  48487. case OPS.endInlineImage:
  48488. var cacheKey = args[0].cacheKey;
  48489. if (cacheKey) {
  48490. var cacheEntry = imageCache[cacheKey];
  48491. if (cacheEntry !== undefined) {
  48492. operatorList.addOp(cacheEntry.fn, cacheEntry.args);
  48493. args = null;
  48494. continue;
  48495. }
  48496. }
  48497. self.buildPaintImageXObject(resources, args[0], true, operatorList, cacheKey, imageCache);
  48498. args = null;
  48499. continue;
  48500. case OPS.showText:
  48501. args[0] = self.handleText(args[0], stateManager.state);
  48502. break;
  48503. case OPS.showSpacedText:
  48504. var arr = args[0];
  48505. var combinedGlyphs = [];
  48506. var arrLength = arr.length;
  48507. var state = stateManager.state;
  48508. for (i = 0; i < arrLength; ++i) {
  48509. var arrItem = arr[i];
  48510. if (isString(arrItem)) {
  48511. Array.prototype.push.apply(combinedGlyphs, self.handleText(arrItem, state));
  48512. } else if (isNum(arrItem)) {
  48513. combinedGlyphs.push(arrItem);
  48514. }
  48515. }
  48516. args[0] = combinedGlyphs;
  48517. fn = OPS.showText;
  48518. break;
  48519. case OPS.nextLineShowText:
  48520. operatorList.addOp(OPS.nextLine);
  48521. args[0] = self.handleText(args[0], stateManager.state);
  48522. fn = OPS.showText;
  48523. break;
  48524. case OPS.nextLineSetSpacingShowText:
  48525. operatorList.addOp(OPS.nextLine);
  48526. operatorList.addOp(OPS.setWordSpacing, [args.shift()]);
  48527. operatorList.addOp(OPS.setCharSpacing, [args.shift()]);
  48528. args[0] = self.handleText(args[0], stateManager.state);
  48529. fn = OPS.showText;
  48530. break;
  48531. case OPS.setTextRenderingMode:
  48532. stateManager.state.textRenderingMode = args[0];
  48533. break;
  48534. case OPS.setFillColorSpace:
  48535. stateManager.state.fillColorSpace = ColorSpace.parse(args[0], xref, resources);
  48536. continue;
  48537. case OPS.setStrokeColorSpace:
  48538. stateManager.state.strokeColorSpace = ColorSpace.parse(args[0], xref, resources);
  48539. continue;
  48540. case OPS.setFillColor:
  48541. cs = stateManager.state.fillColorSpace;
  48542. args = cs.getRgb(args, 0);
  48543. fn = OPS.setFillRGBColor;
  48544. break;
  48545. case OPS.setStrokeColor:
  48546. cs = stateManager.state.strokeColorSpace;
  48547. args = cs.getRgb(args, 0);
  48548. fn = OPS.setStrokeRGBColor;
  48549. break;
  48550. case OPS.setFillGray:
  48551. stateManager.state.fillColorSpace = ColorSpace.singletons.gray;
  48552. args = ColorSpace.singletons.gray.getRgb(args, 0);
  48553. fn = OPS.setFillRGBColor;
  48554. break;
  48555. case OPS.setStrokeGray:
  48556. stateManager.state.strokeColorSpace = ColorSpace.singletons.gray;
  48557. args = ColorSpace.singletons.gray.getRgb(args, 0);
  48558. fn = OPS.setStrokeRGBColor;
  48559. break;
  48560. case OPS.setFillCMYKColor:
  48561. stateManager.state.fillColorSpace = ColorSpace.singletons.cmyk;
  48562. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  48563. fn = OPS.setFillRGBColor;
  48564. break;
  48565. case OPS.setStrokeCMYKColor:
  48566. stateManager.state.strokeColorSpace = ColorSpace.singletons.cmyk;
  48567. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  48568. fn = OPS.setStrokeRGBColor;
  48569. break;
  48570. case OPS.setFillRGBColor:
  48571. stateManager.state.fillColorSpace = ColorSpace.singletons.rgb;
  48572. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  48573. break;
  48574. case OPS.setStrokeRGBColor:
  48575. stateManager.state.strokeColorSpace = ColorSpace.singletons.rgb;
  48576. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  48577. break;
  48578. case OPS.setFillColorN:
  48579. cs = stateManager.state.fillColorSpace;
  48580. if (cs.name === 'Pattern') {
  48581. next(self.handleColorN(operatorList, OPS.setFillColorN, args, cs, patterns, resources, task, xref));
  48582. return;
  48583. }
  48584. args = cs.getRgb(args, 0);
  48585. fn = OPS.setFillRGBColor;
  48586. break;
  48587. case OPS.setStrokeColorN:
  48588. cs = stateManager.state.strokeColorSpace;
  48589. if (cs.name === 'Pattern') {
  48590. next(self.handleColorN(operatorList, OPS.setStrokeColorN, args, cs, patterns, resources, task, xref));
  48591. return;
  48592. }
  48593. args = cs.getRgb(args, 0);
  48594. fn = OPS.setStrokeRGBColor;
  48595. break;
  48596. case OPS.shadingFill:
  48597. var shadingRes = resources.get('Shading');
  48598. if (!shadingRes) {
  48599. error('No shading resource found');
  48600. }
  48601. var shading = shadingRes.get(args[0].name);
  48602. if (!shading) {
  48603. error('No shading object found');
  48604. }
  48605. var shadingFill = Pattern.parseShading(shading, null, xref, resources, self.handler);
  48606. var patternIR = shadingFill.getIR();
  48607. args = [patternIR];
  48608. fn = OPS.shadingFill;
  48609. break;
  48610. case OPS.setGState:
  48611. var dictName = args[0];
  48612. var extGState = resources.get('ExtGState');
  48613. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  48614. break;
  48615. }
  48616. var gState = extGState.get(dictName.name);
  48617. next(self.setGState(resources, gState, operatorList, task, xref, stateManager));
  48618. return;
  48619. case OPS.moveTo:
  48620. case OPS.lineTo:
  48621. case OPS.curveTo:
  48622. case OPS.curveTo2:
  48623. case OPS.curveTo3:
  48624. case OPS.closePath:
  48625. self.buildPath(operatorList, fn, args);
  48626. continue;
  48627. case OPS.rectangle:
  48628. self.buildPath(operatorList, fn, args);
  48629. continue;
  48630. case OPS.markPoint:
  48631. case OPS.markPointProps:
  48632. case OPS.beginMarkedContent:
  48633. case OPS.beginMarkedContentProps:
  48634. case OPS.endMarkedContent:
  48635. case OPS.beginCompat:
  48636. case OPS.endCompat:
  48637. // Ignore operators where the corresponding handlers are known to
  48638. // be no-op in CanvasGraphics (display/canvas.js). This prevents
  48639. // serialization errors and is also a bit more efficient.
  48640. // We could also try to serialize all objects in a general way,
  48641. // e.g. as done in https://github.com/mozilla/pdf.js/pull/6266,
  48642. // but doing so is meaningless without knowing the semantics.
  48643. continue;
  48644. default:
  48645. // Note: Ignore the operator if it has `Dict` arguments, since
  48646. // those are non-serializable, otherwise postMessage will throw
  48647. // "An object could not be cloned.".
  48648. if (args !== null) {
  48649. for (i = 0, ii = args.length; i < ii; i++) {
  48650. if (args[i] instanceof Dict) {
  48651. break;
  48652. }
  48653. }
  48654. if (i < ii) {
  48655. warn('getOperatorList - ignoring operator: ' + fn);
  48656. continue;
  48657. }
  48658. }
  48659. }
  48660. operatorList.addOp(fn, args);
  48661. }
  48662. if (stop) {
  48663. next(deferred);
  48664. return;
  48665. }
  48666. // Some PDFs don't close all restores inside object/form.
  48667. // Closing those for them.
  48668. for (i = 0, ii = preprocessor.savedStatesDepth; i < ii; i++) {
  48669. operatorList.addOp(OPS.restore, []);
  48670. }
  48671. resolve();
  48672. });
  48673. },
  48674. getTextContent: function PartialEvaluator_getTextContent(stream, task, resources, stateManager, normalizeWhitespace, combineTextItems) {
  48675. stateManager = stateManager || new StateManager(new TextState());
  48676. var WhitespaceRegexp = /\s/g;
  48677. var textContent = {
  48678. items: [],
  48679. styles: Object.create(null)
  48680. };
  48681. var textContentItem = {
  48682. initialized: false,
  48683. str: [],
  48684. width: 0,
  48685. height: 0,
  48686. vertical: false,
  48687. lastAdvanceWidth: 0,
  48688. lastAdvanceHeight: 0,
  48689. textAdvanceScale: 0,
  48690. spaceWidth: 0,
  48691. fakeSpaceMin: Infinity,
  48692. fakeMultiSpaceMin: Infinity,
  48693. fakeMultiSpaceMax: -0,
  48694. textRunBreakAllowed: false,
  48695. transform: null,
  48696. fontName: null
  48697. };
  48698. var SPACE_FACTOR = 0.3;
  48699. var MULTI_SPACE_FACTOR = 1.5;
  48700. var MULTI_SPACE_FACTOR_MAX = 4;
  48701. var self = this;
  48702. var xref = this.xref;
  48703. resources = xref.fetchIfRef(resources) || Dict.empty;
  48704. // The xobj is parsed iff it's needed, e.g. if there is a `DO` cmd.
  48705. var xobjs = null;
  48706. var xobjsCache = Object.create(null);
  48707. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  48708. var textState;
  48709. function ensureTextContentItem() {
  48710. if (textContentItem.initialized) {
  48711. return textContentItem;
  48712. }
  48713. var font = textState.font;
  48714. if (!(font.loadedName in textContent.styles)) {
  48715. textContent.styles[font.loadedName] = {
  48716. fontFamily: font.fallbackName,
  48717. ascent: font.ascent,
  48718. descent: font.descent,
  48719. vertical: font.vertical
  48720. };
  48721. }
  48722. textContentItem.fontName = font.loadedName;
  48723. // 9.4.4 Text Space Details
  48724. var tsm = [
  48725. textState.fontSize * textState.textHScale,
  48726. 0,
  48727. 0,
  48728. textState.fontSize,
  48729. 0,
  48730. textState.textRise
  48731. ];
  48732. if (font.isType3Font && textState.fontMatrix !== FONT_IDENTITY_MATRIX && textState.fontSize === 1) {
  48733. var glyphHeight = font.bbox[3] - font.bbox[1];
  48734. if (glyphHeight > 0) {
  48735. glyphHeight = glyphHeight * textState.fontMatrix[3];
  48736. tsm[3] *= glyphHeight;
  48737. }
  48738. }
  48739. var trm = Util.transform(textState.ctm, Util.transform(textState.textMatrix, tsm));
  48740. textContentItem.transform = trm;
  48741. if (!font.vertical) {
  48742. textContentItem.width = 0;
  48743. textContentItem.height = Math.sqrt(trm[2] * trm[2] + trm[3] * trm[3]);
  48744. textContentItem.vertical = false;
  48745. } else {
  48746. textContentItem.width = Math.sqrt(trm[0] * trm[0] + trm[1] * trm[1]);
  48747. textContentItem.height = 0;
  48748. textContentItem.vertical = true;
  48749. }
  48750. var a = textState.textLineMatrix[0];
  48751. var b = textState.textLineMatrix[1];
  48752. var scaleLineX = Math.sqrt(a * a + b * b);
  48753. a = textState.ctm[0];
  48754. b = textState.ctm[1];
  48755. var scaleCtmX = Math.sqrt(a * a + b * b);
  48756. textContentItem.textAdvanceScale = scaleCtmX * scaleLineX;
  48757. textContentItem.lastAdvanceWidth = 0;
  48758. textContentItem.lastAdvanceHeight = 0;
  48759. var spaceWidth = font.spaceWidth / 1000 * textState.fontSize;
  48760. if (spaceWidth) {
  48761. textContentItem.spaceWidth = spaceWidth;
  48762. textContentItem.fakeSpaceMin = spaceWidth * SPACE_FACTOR;
  48763. textContentItem.fakeMultiSpaceMin = spaceWidth * MULTI_SPACE_FACTOR;
  48764. textContentItem.fakeMultiSpaceMax = spaceWidth * MULTI_SPACE_FACTOR_MAX;
  48765. // It's okay for monospace fonts to fake as much space as needed.
  48766. textContentItem.textRunBreakAllowed = !font.isMonospace;
  48767. } else {
  48768. textContentItem.spaceWidth = 0;
  48769. textContentItem.fakeSpaceMin = Infinity;
  48770. textContentItem.fakeMultiSpaceMin = Infinity;
  48771. textContentItem.fakeMultiSpaceMax = 0;
  48772. textContentItem.textRunBreakAllowed = false;
  48773. }
  48774. textContentItem.initialized = true;
  48775. return textContentItem;
  48776. }
  48777. function replaceWhitespace(str) {
  48778. // Replaces all whitespaces with standard spaces (0x20), to avoid
  48779. // alignment issues between the textLayer and the canvas if the text
  48780. // contains e.g. tabs (fixes issue6612.pdf).
  48781. var i = 0, ii = str.length, code;
  48782. while (i < ii && (code = str.charCodeAt(i)) >= 0x20 && code <= 0x7F) {
  48783. i++;
  48784. }
  48785. return i < ii ? str.replace(WhitespaceRegexp, ' ') : str;
  48786. }
  48787. function runBidiTransform(textChunk) {
  48788. var str = textChunk.str.join('');
  48789. var bidiResult = bidi(str, -1, textChunk.vertical);
  48790. return {
  48791. str: normalizeWhitespace ? replaceWhitespace(bidiResult.str) : bidiResult.str,
  48792. dir: bidiResult.dir,
  48793. width: textChunk.width,
  48794. height: textChunk.height,
  48795. transform: textChunk.transform,
  48796. fontName: textChunk.fontName
  48797. };
  48798. }
  48799. function handleSetFont(fontName, fontRef) {
  48800. return self.loadFont(fontName, fontRef, xref, resources).then(function (translated) {
  48801. textState.font = translated.font;
  48802. textState.fontMatrix = translated.font.fontMatrix || FONT_IDENTITY_MATRIX;
  48803. });
  48804. }
  48805. function buildTextContentItem(chars) {
  48806. var font = textState.font;
  48807. var textChunk = ensureTextContentItem();
  48808. var width = 0;
  48809. var height = 0;
  48810. var glyphs = font.charsToGlyphs(chars);
  48811. var defaultVMetrics = font.defaultVMetrics;
  48812. for (var i = 0; i < glyphs.length; i++) {
  48813. var glyph = glyphs[i];
  48814. var vMetricX = null;
  48815. var vMetricY = null;
  48816. var glyphWidth = null;
  48817. if (font.vertical) {
  48818. if (glyph.vmetric) {
  48819. glyphWidth = glyph.vmetric[0];
  48820. vMetricX = glyph.vmetric[1];
  48821. vMetricY = glyph.vmetric[2];
  48822. } else {
  48823. glyphWidth = glyph.width;
  48824. vMetricX = glyph.width * 0.5;
  48825. vMetricY = defaultVMetrics[2];
  48826. }
  48827. } else {
  48828. glyphWidth = glyph.width;
  48829. }
  48830. var glyphUnicode = glyph.unicode;
  48831. var NormalizedUnicodes = getNormalizedUnicodes();
  48832. if (NormalizedUnicodes[glyphUnicode] !== undefined) {
  48833. glyphUnicode = NormalizedUnicodes[glyphUnicode];
  48834. }
  48835. glyphUnicode = reverseIfRtl(glyphUnicode);
  48836. // The following will calculate the x and y of the individual glyphs.
  48837. // if (font.vertical) {
  48838. // tsm[4] -= vMetricX * Math.abs(textState.fontSize) *
  48839. // textState.fontMatrix[0];
  48840. // tsm[5] -= vMetricY * textState.fontSize *
  48841. // textState.fontMatrix[0];
  48842. // }
  48843. // var trm = Util.transform(textState.textMatrix, tsm);
  48844. // var pt = Util.applyTransform([trm[4], trm[5]], textState.ctm);
  48845. // var x = pt[0];
  48846. // var y = pt[1];
  48847. var charSpacing = textState.charSpacing;
  48848. if (glyph.isSpace) {
  48849. var wordSpacing = textState.wordSpacing;
  48850. charSpacing += wordSpacing;
  48851. if (wordSpacing > 0) {
  48852. addFakeSpaces(wordSpacing, textChunk.str);
  48853. }
  48854. }
  48855. var tx = 0;
  48856. var ty = 0;
  48857. if (!font.vertical) {
  48858. var w0 = glyphWidth * textState.fontMatrix[0];
  48859. tx = (w0 * textState.fontSize + charSpacing) * textState.textHScale;
  48860. width += tx;
  48861. } else {
  48862. var w1 = glyphWidth * textState.fontMatrix[0];
  48863. ty = w1 * textState.fontSize + charSpacing;
  48864. height += ty;
  48865. }
  48866. textState.translateTextMatrix(tx, ty);
  48867. textChunk.str.push(glyphUnicode);
  48868. }
  48869. if (!font.vertical) {
  48870. textChunk.lastAdvanceWidth = width;
  48871. textChunk.width += width * textChunk.textAdvanceScale;
  48872. } else {
  48873. textChunk.lastAdvanceHeight = height;
  48874. textChunk.height += Math.abs(height * textChunk.textAdvanceScale);
  48875. }
  48876. return textChunk;
  48877. }
  48878. function addFakeSpaces(width, strBuf) {
  48879. if (width < textContentItem.fakeSpaceMin) {
  48880. return;
  48881. }
  48882. if (width < textContentItem.fakeMultiSpaceMin) {
  48883. strBuf.push(' ');
  48884. return;
  48885. }
  48886. var fakeSpaces = Math.round(width / textContentItem.spaceWidth);
  48887. while (fakeSpaces-- > 0) {
  48888. strBuf.push(' ');
  48889. }
  48890. }
  48891. function flushTextContentItem() {
  48892. if (!textContentItem.initialized) {
  48893. return;
  48894. }
  48895. textContent.items.push(runBidiTransform(textContentItem));
  48896. textContentItem.initialized = false;
  48897. textContentItem.str.length = 0;
  48898. }
  48899. var timeSlotManager = new TimeSlotManager();
  48900. return new Promise(function promiseBody(resolve, reject) {
  48901. var next = function (promise) {
  48902. promise.then(function () {
  48903. try {
  48904. promiseBody(resolve, reject);
  48905. } catch (ex) {
  48906. reject(ex);
  48907. }
  48908. }, reject);
  48909. };
  48910. task.ensureNotTerminated();
  48911. timeSlotManager.reset();
  48912. var stop, operation = {}, args = [];
  48913. while (!(stop = timeSlotManager.check())) {
  48914. // The arguments parsed by read() are not used beyond this loop, so
  48915. // we can reuse the same array on every iteration, thus avoiding
  48916. // unnecessary allocations.
  48917. args.length = 0;
  48918. operation.args = args;
  48919. if (!preprocessor.read(operation)) {
  48920. break;
  48921. }
  48922. textState = stateManager.state;
  48923. var fn = operation.fn;
  48924. args = operation.args;
  48925. var advance, diff;
  48926. switch (fn | 0) {
  48927. case OPS.setFont:
  48928. // Optimization to ignore multiple identical Tf commands.
  48929. var fontNameArg = args[0].name, fontSizeArg = args[1];
  48930. if (textState.font && fontNameArg === textState.fontName && fontSizeArg === textState.fontSize) {
  48931. break;
  48932. }
  48933. flushTextContentItem();
  48934. textState.fontName = fontNameArg;
  48935. textState.fontSize = fontSizeArg;
  48936. next(handleSetFont(fontNameArg, null));
  48937. return;
  48938. case OPS.setTextRise:
  48939. flushTextContentItem();
  48940. textState.textRise = args[0];
  48941. break;
  48942. case OPS.setHScale:
  48943. flushTextContentItem();
  48944. textState.textHScale = args[0] / 100;
  48945. break;
  48946. case OPS.setLeading:
  48947. flushTextContentItem();
  48948. textState.leading = args[0];
  48949. break;
  48950. case OPS.moveText:
  48951. // Optimization to treat same line movement as advance
  48952. var isSameTextLine = !textState.font ? false : (textState.font.vertical ? args[0] : args[1]) === 0;
  48953. advance = args[0] - args[1];
  48954. if (combineTextItems && isSameTextLine && textContentItem.initialized && advance > 0 && advance <= textContentItem.fakeMultiSpaceMax) {
  48955. textState.translateTextLineMatrix(args[0], args[1]);
  48956. textContentItem.width += args[0] - textContentItem.lastAdvanceWidth;
  48957. textContentItem.height += args[1] - textContentItem.lastAdvanceHeight;
  48958. diff = args[0] - textContentItem.lastAdvanceWidth - (args[1] - textContentItem.lastAdvanceHeight);
  48959. addFakeSpaces(diff, textContentItem.str);
  48960. break;
  48961. }
  48962. flushTextContentItem();
  48963. textState.translateTextLineMatrix(args[0], args[1]);
  48964. textState.textMatrix = textState.textLineMatrix.slice();
  48965. break;
  48966. case OPS.setLeadingMoveText:
  48967. flushTextContentItem();
  48968. textState.leading = -args[1];
  48969. textState.translateTextLineMatrix(args[0], args[1]);
  48970. textState.textMatrix = textState.textLineMatrix.slice();
  48971. break;
  48972. case OPS.nextLine:
  48973. flushTextContentItem();
  48974. textState.carriageReturn();
  48975. break;
  48976. case OPS.setTextMatrix:
  48977. // Optimization to treat same line movement as advance.
  48978. advance = textState.calcTextLineMatrixAdvance(args[0], args[1], args[2], args[3], args[4], args[5]);
  48979. if (combineTextItems && advance !== null && textContentItem.initialized && advance.value > 0 && advance.value <= textContentItem.fakeMultiSpaceMax) {
  48980. textState.translateTextLineMatrix(advance.width, advance.height);
  48981. textContentItem.width += advance.width - textContentItem.lastAdvanceWidth;
  48982. textContentItem.height += advance.height - textContentItem.lastAdvanceHeight;
  48983. diff = advance.width - textContentItem.lastAdvanceWidth - (advance.height - textContentItem.lastAdvanceHeight);
  48984. addFakeSpaces(diff, textContentItem.str);
  48985. break;
  48986. }
  48987. flushTextContentItem();
  48988. textState.setTextMatrix(args[0], args[1], args[2], args[3], args[4], args[5]);
  48989. textState.setTextLineMatrix(args[0], args[1], args[2], args[3], args[4], args[5]);
  48990. break;
  48991. case OPS.setCharSpacing:
  48992. textState.charSpacing = args[0];
  48993. break;
  48994. case OPS.setWordSpacing:
  48995. textState.wordSpacing = args[0];
  48996. break;
  48997. case OPS.beginText:
  48998. flushTextContentItem();
  48999. textState.textMatrix = IDENTITY_MATRIX.slice();
  49000. textState.textLineMatrix = IDENTITY_MATRIX.slice();
  49001. break;
  49002. case OPS.showSpacedText:
  49003. var items = args[0];
  49004. var offset;
  49005. for (var j = 0, jj = items.length; j < jj; j++) {
  49006. if (typeof items[j] === 'string') {
  49007. buildTextContentItem(items[j]);
  49008. } else if (isNum(items[j])) {
  49009. ensureTextContentItem();
  49010. // PDF Specification 5.3.2 states:
  49011. // The number is expressed in thousandths of a unit of text
  49012. // space.
  49013. // This amount is subtracted from the current horizontal or
  49014. // vertical coordinate, depending on the writing mode.
  49015. // In the default coordinate system, a positive adjustment
  49016. // has the effect of moving the next glyph painted either to
  49017. // the left or down by the given amount.
  49018. advance = items[j] * textState.fontSize / 1000;
  49019. var breakTextRun = false;
  49020. if (textState.font.vertical) {
  49021. offset = advance * (textState.textHScale * textState.textMatrix[2] + textState.textMatrix[3]);
  49022. textState.translateTextMatrix(0, advance);
  49023. breakTextRun = textContentItem.textRunBreakAllowed && advance > textContentItem.fakeMultiSpaceMax;
  49024. if (!breakTextRun) {
  49025. // Value needs to be added to height to paint down.
  49026. textContentItem.height += offset;
  49027. }
  49028. } else {
  49029. advance = -advance;
  49030. offset = advance * (textState.textHScale * textState.textMatrix[0] + textState.textMatrix[1]);
  49031. textState.translateTextMatrix(advance, 0);
  49032. breakTextRun = textContentItem.textRunBreakAllowed && advance > textContentItem.fakeMultiSpaceMax;
  49033. if (!breakTextRun) {
  49034. // Value needs to be subtracted from width to paint left.
  49035. textContentItem.width += offset;
  49036. }
  49037. }
  49038. if (breakTextRun) {
  49039. flushTextContentItem();
  49040. } else if (advance > 0) {
  49041. addFakeSpaces(advance, textContentItem.str);
  49042. }
  49043. }
  49044. }
  49045. break;
  49046. case OPS.showText:
  49047. buildTextContentItem(args[0]);
  49048. break;
  49049. case OPS.nextLineShowText:
  49050. flushTextContentItem();
  49051. textState.carriageReturn();
  49052. buildTextContentItem(args[0]);
  49053. break;
  49054. case OPS.nextLineSetSpacingShowText:
  49055. flushTextContentItem();
  49056. textState.wordSpacing = args[0];
  49057. textState.charSpacing = args[1];
  49058. textState.carriageReturn();
  49059. buildTextContentItem(args[2]);
  49060. break;
  49061. case OPS.paintXObject:
  49062. flushTextContentItem();
  49063. if (args[0].code) {
  49064. break;
  49065. }
  49066. if (!xobjs) {
  49067. xobjs = resources.get('XObject') || Dict.empty;
  49068. }
  49069. var name = args[0].name;
  49070. if (xobjsCache.key === name) {
  49071. if (xobjsCache.texts) {
  49072. Util.appendToArray(textContent.items, xobjsCache.texts.items);
  49073. Util.extendObj(textContent.styles, xobjsCache.texts.styles);
  49074. }
  49075. break;
  49076. }
  49077. var xobj = xobjs.get(name);
  49078. if (!xobj) {
  49079. break;
  49080. }
  49081. assert(isStream(xobj), 'XObject should be a stream');
  49082. var type = xobj.dict.get('Subtype');
  49083. assert(isName(type), 'XObject should have a Name subtype');
  49084. if ('Form' !== type.name) {
  49085. xobjsCache.key = name;
  49086. xobjsCache.texts = null;
  49087. break;
  49088. }
  49089. stateManager.save();
  49090. var matrix = xobj.dict.getArray('Matrix');
  49091. if (isArray(matrix) && matrix.length === 6) {
  49092. stateManager.transform(matrix);
  49093. }
  49094. next(self.getTextContent(xobj, task, xobj.dict.get('Resources') || resources, stateManager, normalizeWhitespace, combineTextItems).then(function (formTextContent) {
  49095. Util.appendToArray(textContent.items, formTextContent.items);
  49096. Util.extendObj(textContent.styles, formTextContent.styles);
  49097. stateManager.restore();
  49098. xobjsCache.key = name;
  49099. xobjsCache.texts = formTextContent;
  49100. }));
  49101. return;
  49102. case OPS.setGState:
  49103. flushTextContentItem();
  49104. var dictName = args[0];
  49105. var extGState = resources.get('ExtGState');
  49106. if (!isDict(extGState) || !isName(dictName)) {
  49107. break;
  49108. }
  49109. var gState = extGState.get(dictName.name);
  49110. if (!isDict(gState)) {
  49111. break;
  49112. }
  49113. var gStateFont = gState.get('Font');
  49114. if (gStateFont) {
  49115. textState.fontName = null;
  49116. textState.fontSize = gStateFont[1];
  49117. next(handleSetFont(null, gStateFont[0]));
  49118. return;
  49119. }
  49120. break;
  49121. }
  49122. }
  49123. // switch
  49124. // while
  49125. if (stop) {
  49126. next(deferred);
  49127. return;
  49128. }
  49129. flushTextContentItem();
  49130. resolve(textContent);
  49131. });
  49132. },
  49133. extractDataStructures: function PartialEvaluator_extractDataStructures(dict, baseDict, xref, properties) {
  49134. // 9.10.2
  49135. var toUnicode = dict.get('ToUnicode') || baseDict.get('ToUnicode');
  49136. var toUnicodePromise = toUnicode ? this.readToUnicode(toUnicode) : Promise.resolve(undefined);
  49137. if (properties.composite) {
  49138. // CIDSystemInfo helps to match CID to glyphs
  49139. var cidSystemInfo = dict.get('CIDSystemInfo');
  49140. if (isDict(cidSystemInfo)) {
  49141. properties.cidSystemInfo = {
  49142. registry: cidSystemInfo.get('Registry'),
  49143. ordering: cidSystemInfo.get('Ordering'),
  49144. supplement: cidSystemInfo.get('Supplement')
  49145. };
  49146. }
  49147. var cidToGidMap = dict.get('CIDToGIDMap');
  49148. if (isStream(cidToGidMap)) {
  49149. properties.cidToGidMap = this.readCidToGidMap(cidToGidMap);
  49150. }
  49151. }
  49152. // Based on 9.6.6 of the spec the encoding can come from multiple places
  49153. // and depends on the font type. The base encoding and differences are
  49154. // read here, but the encoding that is actually used is chosen during
  49155. // glyph mapping in the font.
  49156. // TODO: Loading the built in encoding in the font would allow the
  49157. // differences to be merged in here not require us to hold on to it.
  49158. var differences = [];
  49159. var baseEncodingName = null;
  49160. var encoding;
  49161. if (dict.has('Encoding')) {
  49162. encoding = dict.get('Encoding');
  49163. if (isDict(encoding)) {
  49164. baseEncodingName = encoding.get('BaseEncoding');
  49165. baseEncodingName = isName(baseEncodingName) ? baseEncodingName.name : null;
  49166. // Load the differences between the base and original
  49167. if (encoding.has('Differences')) {
  49168. var diffEncoding = encoding.get('Differences');
  49169. var index = 0;
  49170. for (var j = 0, jj = diffEncoding.length; j < jj; j++) {
  49171. var data = xref.fetchIfRef(diffEncoding[j]);
  49172. if (isNum(data)) {
  49173. index = data;
  49174. } else if (isName(data)) {
  49175. differences[index++] = data.name;
  49176. } else {
  49177. error('Invalid entry in \'Differences\' array: ' + data);
  49178. }
  49179. }
  49180. }
  49181. } else if (isName(encoding)) {
  49182. baseEncodingName = encoding.name;
  49183. } else {
  49184. error('Encoding is not a Name nor a Dict');
  49185. }
  49186. // According to table 114 if the encoding is a named encoding it must be
  49187. // one of these predefined encodings.
  49188. if (baseEncodingName !== 'MacRomanEncoding' && baseEncodingName !== 'MacExpertEncoding' && baseEncodingName !== 'WinAnsiEncoding') {
  49189. baseEncodingName = null;
  49190. }
  49191. }
  49192. if (baseEncodingName) {
  49193. properties.defaultEncoding = getEncoding(baseEncodingName).slice();
  49194. } else {
  49195. encoding = properties.type === 'TrueType' ? WinAnsiEncoding : StandardEncoding;
  49196. // The Symbolic attribute can be misused for regular fonts
  49197. // Heuristic: we have to check if the font is a standard one also
  49198. if (!!(properties.flags & FontFlags.Symbolic)) {
  49199. encoding = MacRomanEncoding;
  49200. if (!properties.file) {
  49201. if (/Symbol/i.test(properties.name)) {
  49202. encoding = SymbolSetEncoding;
  49203. } else if (/Dingbats/i.test(properties.name)) {
  49204. encoding = ZapfDingbatsEncoding;
  49205. }
  49206. }
  49207. }
  49208. properties.defaultEncoding = encoding;
  49209. }
  49210. properties.differences = differences;
  49211. properties.baseEncodingName = baseEncodingName;
  49212. properties.hasEncoding = !!baseEncodingName || differences.length > 0;
  49213. properties.dict = dict;
  49214. return toUnicodePromise.then(function (toUnicode) {
  49215. properties.toUnicode = toUnicode;
  49216. return this.buildToUnicode(properties);
  49217. }.bind(this)).then(function (toUnicode) {
  49218. properties.toUnicode = toUnicode;
  49219. return properties;
  49220. });
  49221. },
  49222. /**
  49223. * Builds a char code to unicode map based on section 9.10 of the spec.
  49224. * @param {Object} properties Font properties object.
  49225. * @return {Promise} A Promise that is resolved with a
  49226. * {ToUnicodeMap|IdentityToUnicodeMap} object.
  49227. */
  49228. buildToUnicode: function PartialEvaluator_buildToUnicode(properties) {
  49229. properties.hasIncludedToUnicodeMap = !!properties.toUnicode && properties.toUnicode.length > 0;
  49230. // Section 9.10.2 Mapping Character Codes to Unicode Values
  49231. if (properties.hasIncludedToUnicodeMap) {
  49232. return Promise.resolve(properties.toUnicode);
  49233. }
  49234. // According to the spec if the font is a simple font we should only map
  49235. // to unicode if the base encoding is MacRoman, MacExpert, or WinAnsi or
  49236. // the differences array only contains adobe standard or symbol set names,
  49237. // in pratice it seems better to always try to create a toUnicode
  49238. // map based of the default encoding.
  49239. var toUnicode, charcode, glyphName;
  49240. if (!properties.composite)
  49241. /* is simple font */
  49242. {
  49243. toUnicode = [];
  49244. var encoding = properties.defaultEncoding.slice();
  49245. var baseEncodingName = properties.baseEncodingName;
  49246. // Merge in the differences array.
  49247. var differences = properties.differences;
  49248. for (charcode in differences) {
  49249. glyphName = differences[charcode];
  49250. if (glyphName === '.notdef') {
  49251. // Skip .notdef to prevent rendering errors, e.g. boxes appearing
  49252. // where there should be spaces (fixes issue5256.pdf).
  49253. continue;
  49254. }
  49255. encoding[charcode] = glyphName;
  49256. }
  49257. var glyphsUnicodeMap = getGlyphsUnicode();
  49258. for (charcode in encoding) {
  49259. // a) Map the character code to a character name.
  49260. glyphName = encoding[charcode];
  49261. // b) Look up the character name in the Adobe Glyph List (see the
  49262. // Bibliography) to obtain the corresponding Unicode value.
  49263. if (glyphName === '') {
  49264. continue;
  49265. } else if (glyphsUnicodeMap[glyphName] === undefined) {
  49266. // (undocumented) c) Few heuristics to recognize unknown glyphs
  49267. // NOTE: Adobe Reader does not do this step, but OSX Preview does
  49268. var code = 0;
  49269. switch (glyphName[0]) {
  49270. case 'G':
  49271. // Gxx glyph
  49272. if (glyphName.length === 3) {
  49273. code = parseInt(glyphName.substr(1), 16);
  49274. }
  49275. break;
  49276. case 'g':
  49277. // g00xx glyph
  49278. if (glyphName.length === 5) {
  49279. code = parseInt(glyphName.substr(1), 16);
  49280. }
  49281. break;
  49282. case 'C':
  49283. // Cddd glyph
  49284. case 'c':
  49285. // cddd glyph
  49286. if (glyphName.length >= 3) {
  49287. code = +glyphName.substr(1);
  49288. }
  49289. break;
  49290. default:
  49291. // 'uniXXXX'/'uXXXX{XX}' glyphs
  49292. var unicode = getUnicodeForGlyph(glyphName, glyphsUnicodeMap);
  49293. if (unicode !== -1) {
  49294. code = unicode;
  49295. }
  49296. }
  49297. if (code) {
  49298. // If |baseEncodingName| is one the predefined encodings,
  49299. // and |code| equals |charcode|, using the glyph defined in the
  49300. // baseEncoding seems to yield a better |toUnicode| mapping
  49301. // (fixes issue 5070).
  49302. if (baseEncodingName && code === +charcode) {
  49303. var baseEncoding = getEncoding(baseEncodingName);
  49304. if (baseEncoding && (glyphName = baseEncoding[charcode])) {
  49305. toUnicode[charcode] = String.fromCharCode(glyphsUnicodeMap[glyphName]);
  49306. continue;
  49307. }
  49308. }
  49309. toUnicode[charcode] = String.fromCharCode(code);
  49310. }
  49311. continue;
  49312. }
  49313. toUnicode[charcode] = String.fromCharCode(glyphsUnicodeMap[glyphName]);
  49314. }
  49315. return Promise.resolve(new ToUnicodeMap(toUnicode));
  49316. }
  49317. // If the font is a composite font that uses one of the predefined CMaps
  49318. // listed in Table 118 (except Identity–H and Identity–V) or whose
  49319. // descendant CIDFont uses the Adobe-GB1, Adobe-CNS1, Adobe-Japan1, or
  49320. // Adobe-Korea1 character collection:
  49321. if (properties.composite && (properties.cMap.builtInCMap && !(properties.cMap instanceof IdentityCMap) || properties.cidSystemInfo.registry === 'Adobe' && (properties.cidSystemInfo.ordering === 'GB1' || properties.cidSystemInfo.ordering === 'CNS1' || properties.cidSystemInfo.ordering === 'Japan1' || properties.cidSystemInfo.ordering === 'Korea1'))) {
  49322. // Then:
  49323. // a) Map the character code to a character identifier (CID) according
  49324. // to the font’s CMap.
  49325. // b) Obtain the registry and ordering of the character collection used
  49326. // by the font’s CMap (for example, Adobe and Japan1) from its
  49327. // CIDSystemInfo dictionary.
  49328. var registry = properties.cidSystemInfo.registry;
  49329. var ordering = properties.cidSystemInfo.ordering;
  49330. // c) Construct a second CMap name by concatenating the registry and
  49331. // ordering obtained in step (b) in the format registry–ordering–UCS2
  49332. // (for example, Adobe–Japan1–UCS2).
  49333. var ucs2CMapName = Name.get(registry + '-' + ordering + '-UCS2');
  49334. // d) Obtain the CMap with the name constructed in step (c) (available
  49335. // from the ASN Web site; see the Bibliography).
  49336. return CMapFactory.create(ucs2CMapName, this.options.cMapOptions, null).then(function (ucs2CMap) {
  49337. var cMap = properties.cMap;
  49338. toUnicode = [];
  49339. cMap.forEach(function (charcode, cid) {
  49340. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  49341. // e) Map the CID obtained in step (a) according to the CMap
  49342. // obtained in step (d), producing a Unicode value.
  49343. var ucs2 = ucs2CMap.lookup(cid);
  49344. if (ucs2) {
  49345. toUnicode[charcode] = String.fromCharCode((ucs2.charCodeAt(0) << 8) + ucs2.charCodeAt(1));
  49346. }
  49347. });
  49348. return new ToUnicodeMap(toUnicode);
  49349. });
  49350. }
  49351. // The viewer's choice, just use an identity map.
  49352. return Promise.resolve(new IdentityToUnicodeMap(properties.firstChar, properties.lastChar));
  49353. },
  49354. readToUnicode: function PartialEvaluator_readToUnicode(toUnicode) {
  49355. var cmapObj = toUnicode;
  49356. if (isName(cmapObj)) {
  49357. return CMapFactory.create(cmapObj, this.options.cMapOptions, null).then(function (cmap) {
  49358. if (cmap instanceof IdentityCMap) {
  49359. return new IdentityToUnicodeMap(0, 0xFFFF);
  49360. }
  49361. return new ToUnicodeMap(cmap.getMap());
  49362. });
  49363. } else if (isStream(cmapObj)) {
  49364. return CMapFactory.create(cmapObj, this.options.cMapOptions, null).then(function (cmap) {
  49365. if (cmap instanceof IdentityCMap) {
  49366. return new IdentityToUnicodeMap(0, 0xFFFF);
  49367. }
  49368. var map = new Array(cmap.length);
  49369. // Convert UTF-16BE
  49370. // NOTE: cmap can be a sparse array, so use forEach instead of for(;;)
  49371. // to iterate over all keys.
  49372. cmap.forEach(function (charCode, token) {
  49373. var str = [];
  49374. for (var k = 0; k < token.length; k += 2) {
  49375. var w1 = token.charCodeAt(k) << 8 | token.charCodeAt(k + 1);
  49376. if ((w1 & 0xF800) !== 0xD800) {
  49377. // w1 < 0xD800 || w1 > 0xDFFF
  49378. str.push(w1);
  49379. continue;
  49380. }
  49381. k += 2;
  49382. var w2 = token.charCodeAt(k) << 8 | token.charCodeAt(k + 1);
  49383. str.push(((w1 & 0x3ff) << 10) + (w2 & 0x3ff) + 0x10000);
  49384. }
  49385. map[charCode] = String.fromCharCode.apply(String, str);
  49386. });
  49387. return new ToUnicodeMap(map);
  49388. });
  49389. }
  49390. return Promise.resolve(null);
  49391. },
  49392. readCidToGidMap: function PartialEvaluator_readCidToGidMap(cidToGidStream) {
  49393. // Extract the encoding from the CIDToGIDMap
  49394. var glyphsData = cidToGidStream.getBytes();
  49395. // Set encoding 0 to later verify the font has an encoding
  49396. var result = [];
  49397. for (var j = 0, jj = glyphsData.length; j < jj; j++) {
  49398. var glyphID = glyphsData[j++] << 8 | glyphsData[j];
  49399. if (glyphID === 0) {
  49400. continue;
  49401. }
  49402. var code = j >> 1;
  49403. result[code] = glyphID;
  49404. }
  49405. return result;
  49406. },
  49407. extractWidths: function PartialEvaluator_extractWidths(dict, xref, descriptor, properties) {
  49408. var glyphsWidths = [];
  49409. var defaultWidth = 0;
  49410. var glyphsVMetrics = [];
  49411. var defaultVMetrics;
  49412. var i, ii, j, jj, start, code, widths;
  49413. if (properties.composite) {
  49414. defaultWidth = dict.get('DW') || 1000;
  49415. widths = dict.get('W');
  49416. if (widths) {
  49417. for (i = 0, ii = widths.length; i < ii; i++) {
  49418. start = widths[i++];
  49419. code = xref.fetchIfRef(widths[i]);
  49420. if (isArray(code)) {
  49421. for (j = 0, jj = code.length; j < jj; j++) {
  49422. glyphsWidths[start++] = code[j];
  49423. }
  49424. } else {
  49425. var width = widths[++i];
  49426. for (j = start; j <= code; j++) {
  49427. glyphsWidths[j] = width;
  49428. }
  49429. }
  49430. }
  49431. }
  49432. if (properties.vertical) {
  49433. var vmetrics = dict.get('DW2') || [
  49434. 880,
  49435. -1000
  49436. ];
  49437. defaultVMetrics = [
  49438. vmetrics[1],
  49439. defaultWidth * 0.5,
  49440. vmetrics[0]
  49441. ];
  49442. vmetrics = dict.get('W2');
  49443. if (vmetrics) {
  49444. for (i = 0, ii = vmetrics.length; i < ii; i++) {
  49445. start = vmetrics[i++];
  49446. code = xref.fetchIfRef(vmetrics[i]);
  49447. if (isArray(code)) {
  49448. for (j = 0, jj = code.length; j < jj; j++) {
  49449. glyphsVMetrics[start++] = [
  49450. code[j++],
  49451. code[j++],
  49452. code[j]
  49453. ];
  49454. }
  49455. } else {
  49456. var vmetric = [
  49457. vmetrics[++i],
  49458. vmetrics[++i],
  49459. vmetrics[++i]
  49460. ];
  49461. for (j = start; j <= code; j++) {
  49462. glyphsVMetrics[j] = vmetric;
  49463. }
  49464. }
  49465. }
  49466. }
  49467. }
  49468. } else {
  49469. var firstChar = properties.firstChar;
  49470. widths = dict.get('Widths');
  49471. if (widths) {
  49472. j = firstChar;
  49473. for (i = 0, ii = widths.length; i < ii; i++) {
  49474. glyphsWidths[j++] = widths[i];
  49475. }
  49476. defaultWidth = parseFloat(descriptor.get('MissingWidth')) || 0;
  49477. } else {
  49478. // Trying get the BaseFont metrics (see comment above).
  49479. var baseFontName = dict.get('BaseFont');
  49480. if (isName(baseFontName)) {
  49481. var metrics = this.getBaseFontMetrics(baseFontName.name);
  49482. glyphsWidths = this.buildCharCodeToWidth(metrics.widths, properties);
  49483. defaultWidth = metrics.defaultWidth;
  49484. }
  49485. }
  49486. }
  49487. // Heuristic: detection of monospace font by checking all non-zero widths
  49488. var isMonospace = true;
  49489. var firstWidth = defaultWidth;
  49490. for (var glyph in glyphsWidths) {
  49491. var glyphWidth = glyphsWidths[glyph];
  49492. if (!glyphWidth) {
  49493. continue;
  49494. }
  49495. if (!firstWidth) {
  49496. firstWidth = glyphWidth;
  49497. continue;
  49498. }
  49499. if (firstWidth !== glyphWidth) {
  49500. isMonospace = false;
  49501. break;
  49502. }
  49503. }
  49504. if (isMonospace) {
  49505. properties.flags |= FontFlags.FixedPitch;
  49506. }
  49507. properties.defaultWidth = defaultWidth;
  49508. properties.widths = glyphsWidths;
  49509. properties.defaultVMetrics = defaultVMetrics;
  49510. properties.vmetrics = glyphsVMetrics;
  49511. },
  49512. isSerifFont: function PartialEvaluator_isSerifFont(baseFontName) {
  49513. // Simulating descriptor flags attribute
  49514. var fontNameWoStyle = baseFontName.split('-')[0];
  49515. return fontNameWoStyle in getSerifFonts() || fontNameWoStyle.search(/serif/gi) !== -1;
  49516. },
  49517. getBaseFontMetrics: function PartialEvaluator_getBaseFontMetrics(name) {
  49518. var defaultWidth = 0;
  49519. var widths = [];
  49520. var monospace = false;
  49521. var stdFontMap = getStdFontMap();
  49522. var lookupName = stdFontMap[name] || name;
  49523. var Metrics = getMetrics();
  49524. if (!(lookupName in Metrics)) {
  49525. // Use default fonts for looking up font metrics if the passed
  49526. // font is not a base font
  49527. if (this.isSerifFont(name)) {
  49528. lookupName = 'Times-Roman';
  49529. } else {
  49530. lookupName = 'Helvetica';
  49531. }
  49532. }
  49533. var glyphWidths = Metrics[lookupName];
  49534. if (isNum(glyphWidths)) {
  49535. defaultWidth = glyphWidths;
  49536. monospace = true;
  49537. } else {
  49538. widths = glyphWidths();
  49539. }
  49540. // expand lazy widths array
  49541. return {
  49542. defaultWidth: defaultWidth,
  49543. monospace: monospace,
  49544. widths: widths
  49545. };
  49546. },
  49547. buildCharCodeToWidth: function PartialEvaluator_bulildCharCodeToWidth(widthsByGlyphName, properties) {
  49548. var widths = Object.create(null);
  49549. var differences = properties.differences;
  49550. var encoding = properties.defaultEncoding;
  49551. for (var charCode = 0; charCode < 256; charCode++) {
  49552. if (charCode in differences && widthsByGlyphName[differences[charCode]]) {
  49553. widths[charCode] = widthsByGlyphName[differences[charCode]];
  49554. continue;
  49555. }
  49556. if (charCode in encoding && widthsByGlyphName[encoding[charCode]]) {
  49557. widths[charCode] = widthsByGlyphName[encoding[charCode]];
  49558. continue;
  49559. }
  49560. }
  49561. return widths;
  49562. },
  49563. preEvaluateFont: function PartialEvaluator_preEvaluateFont(dict, xref) {
  49564. var baseDict = dict;
  49565. var type = dict.get('Subtype');
  49566. assert(isName(type), 'invalid font Subtype');
  49567. var composite = false;
  49568. var uint8array;
  49569. if (type.name === 'Type0') {
  49570. // If font is a composite
  49571. // - get the descendant font
  49572. // - set the type according to the descendant font
  49573. // - get the FontDescriptor from the descendant font
  49574. var df = dict.get('DescendantFonts');
  49575. if (!df) {
  49576. error('Descendant fonts are not specified');
  49577. }
  49578. dict = isArray(df) ? xref.fetchIfRef(df[0]) : df;
  49579. type = dict.get('Subtype');
  49580. assert(isName(type), 'invalid font Subtype');
  49581. composite = true;
  49582. }
  49583. var descriptor = dict.get('FontDescriptor');
  49584. if (descriptor) {
  49585. var hash = new MurmurHash3_64();
  49586. var encoding = baseDict.getRaw('Encoding');
  49587. if (isName(encoding)) {
  49588. hash.update(encoding.name);
  49589. } else if (isRef(encoding)) {
  49590. hash.update(encoding.toString());
  49591. } else if (isDict(encoding)) {
  49592. var keys = encoding.getKeys();
  49593. for (var i = 0, ii = keys.length; i < ii; i++) {
  49594. var entry = encoding.getRaw(keys[i]);
  49595. if (isName(entry)) {
  49596. hash.update(entry.name);
  49597. } else if (isRef(entry)) {
  49598. hash.update(entry.toString());
  49599. } else if (isArray(entry)) {
  49600. // 'Differences' entry.
  49601. // Ideally we should check the contents of the array, but to avoid
  49602. // parsing it here and then again in |extractDataStructures|,
  49603. // we only use the array length for now (fixes bug1157493.pdf).
  49604. hash.update(entry.length.toString());
  49605. }
  49606. }
  49607. }
  49608. var toUnicode = dict.get('ToUnicode') || baseDict.get('ToUnicode');
  49609. if (isStream(toUnicode)) {
  49610. var stream = toUnicode.str || toUnicode;
  49611. uint8array = stream.buffer ? new Uint8Array(stream.buffer.buffer, 0, stream.bufferLength) : new Uint8Array(stream.bytes.buffer, stream.start, stream.end - stream.start);
  49612. hash.update(uint8array);
  49613. } else if (isName(toUnicode)) {
  49614. hash.update(toUnicode.name);
  49615. }
  49616. var widths = dict.get('Widths') || baseDict.get('Widths');
  49617. if (widths) {
  49618. uint8array = new Uint8Array(new Uint32Array(widths).buffer);
  49619. hash.update(uint8array);
  49620. }
  49621. }
  49622. return {
  49623. descriptor: descriptor,
  49624. dict: dict,
  49625. baseDict: baseDict,
  49626. composite: composite,
  49627. type: type.name,
  49628. hash: hash ? hash.hexdigest() : ''
  49629. };
  49630. },
  49631. translateFont: function PartialEvaluator_translateFont(preEvaluatedFont, xref) {
  49632. var baseDict = preEvaluatedFont.baseDict;
  49633. var dict = preEvaluatedFont.dict;
  49634. var composite = preEvaluatedFont.composite;
  49635. var descriptor = preEvaluatedFont.descriptor;
  49636. var type = preEvaluatedFont.type;
  49637. var maxCharIndex = composite ? 0xFFFF : 0xFF;
  49638. var cMapOptions = this.options.cMapOptions;
  49639. var properties;
  49640. if (!descriptor) {
  49641. if (type === 'Type3') {
  49642. // FontDescriptor is only required for Type3 fonts when the document
  49643. // is a tagged pdf. Create a barbebones one to get by.
  49644. descriptor = new Dict(null);
  49645. descriptor.set('FontName', Name.get(type));
  49646. descriptor.set('FontBBox', dict.getArray('FontBBox'));
  49647. } else {
  49648. // Before PDF 1.5 if the font was one of the base 14 fonts, having a
  49649. // FontDescriptor was not required.
  49650. // This case is here for compatibility.
  49651. var baseFontName = dict.get('BaseFont');
  49652. if (!isName(baseFontName)) {
  49653. error('Base font is not specified');
  49654. }
  49655. // Using base font name as a font name.
  49656. baseFontName = baseFontName.name.replace(/[,_]/g, '-');
  49657. var metrics = this.getBaseFontMetrics(baseFontName);
  49658. // Simulating descriptor flags attribute
  49659. var fontNameWoStyle = baseFontName.split('-')[0];
  49660. var flags = (this.isSerifFont(fontNameWoStyle) ? FontFlags.Serif : 0) | (metrics.monospace ? FontFlags.FixedPitch : 0) | (getSymbolsFonts()[fontNameWoStyle] ? FontFlags.Symbolic : FontFlags.Nonsymbolic);
  49661. properties = {
  49662. type: type,
  49663. name: baseFontName,
  49664. widths: metrics.widths,
  49665. defaultWidth: metrics.defaultWidth,
  49666. flags: flags,
  49667. firstChar: 0,
  49668. lastChar: maxCharIndex
  49669. };
  49670. return this.extractDataStructures(dict, dict, xref, properties).then(function (properties) {
  49671. properties.widths = this.buildCharCodeToWidth(metrics.widths, properties);
  49672. return new Font(baseFontName, null, properties);
  49673. }.bind(this));
  49674. }
  49675. }
  49676. // According to the spec if 'FontDescriptor' is declared, 'FirstChar',
  49677. // 'LastChar' and 'Widths' should exist too, but some PDF encoders seem
  49678. // to ignore this rule when a variant of a standard font is used.
  49679. // TODO Fill the width array depending on which of the base font this is
  49680. // a variant.
  49681. var firstChar = dict.get('FirstChar') || 0;
  49682. var lastChar = dict.get('LastChar') || maxCharIndex;
  49683. var fontName = descriptor.get('FontName');
  49684. var baseFont = dict.get('BaseFont');
  49685. // Some bad PDFs have a string as the font name.
  49686. if (isString(fontName)) {
  49687. fontName = Name.get(fontName);
  49688. }
  49689. if (isString(baseFont)) {
  49690. baseFont = Name.get(baseFont);
  49691. }
  49692. if (type !== 'Type3') {
  49693. var fontNameStr = fontName && fontName.name;
  49694. var baseFontStr = baseFont && baseFont.name;
  49695. if (fontNameStr !== baseFontStr) {
  49696. info('The FontDescriptor\'s FontName is "' + fontNameStr + '" but should be the same as the Font\'s BaseFont "' + baseFontStr + '"');
  49697. // Workaround for cases where e.g. fontNameStr = 'Arial' and
  49698. // baseFontStr = 'Arial,Bold' (needed when no font file is embedded).
  49699. if (fontNameStr && baseFontStr && baseFontStr.indexOf(fontNameStr) === 0) {
  49700. fontName = baseFont;
  49701. }
  49702. }
  49703. }
  49704. fontName = fontName || baseFont;
  49705. assert(isName(fontName), 'invalid font name');
  49706. var fontFile = descriptor.get('FontFile', 'FontFile2', 'FontFile3');
  49707. if (fontFile) {
  49708. if (fontFile.dict) {
  49709. var subtype = fontFile.dict.get('Subtype');
  49710. if (subtype) {
  49711. subtype = subtype.name;
  49712. }
  49713. var length1 = fontFile.dict.get('Length1');
  49714. var length2 = fontFile.dict.get('Length2');
  49715. var length3 = fontFile.dict.get('Length3');
  49716. }
  49717. }
  49718. properties = {
  49719. type: type,
  49720. name: fontName.name,
  49721. subtype: subtype,
  49722. file: fontFile,
  49723. length1: length1,
  49724. length2: length2,
  49725. length3: length3,
  49726. loadedName: baseDict.loadedName,
  49727. composite: composite,
  49728. wideChars: composite,
  49729. fixedPitch: false,
  49730. fontMatrix: dict.getArray('FontMatrix') || FONT_IDENTITY_MATRIX,
  49731. firstChar: firstChar || 0,
  49732. lastChar: lastChar || maxCharIndex,
  49733. bbox: descriptor.getArray('FontBBox'),
  49734. ascent: descriptor.get('Ascent'),
  49735. descent: descriptor.get('Descent'),
  49736. xHeight: descriptor.get('XHeight'),
  49737. capHeight: descriptor.get('CapHeight'),
  49738. flags: descriptor.get('Flags'),
  49739. italicAngle: descriptor.get('ItalicAngle'),
  49740. coded: false
  49741. };
  49742. var cMapPromise;
  49743. if (composite) {
  49744. var cidEncoding = baseDict.get('Encoding');
  49745. if (isName(cidEncoding)) {
  49746. properties.cidEncoding = cidEncoding.name;
  49747. }
  49748. cMapPromise = CMapFactory.create(cidEncoding, cMapOptions, null).then(function (cMap) {
  49749. properties.cMap = cMap;
  49750. properties.vertical = properties.cMap.vertical;
  49751. });
  49752. } else {
  49753. cMapPromise = Promise.resolve(undefined);
  49754. }
  49755. return cMapPromise.then(function () {
  49756. return this.extractDataStructures(dict, baseDict, xref, properties);
  49757. }.bind(this)).then(function (properties) {
  49758. this.extractWidths(dict, xref, descriptor, properties);
  49759. if (type === 'Type3') {
  49760. properties.isType3Font = true;
  49761. }
  49762. return new Font(fontName.name, fontFile, properties);
  49763. }.bind(this));
  49764. }
  49765. };
  49766. return PartialEvaluator;
  49767. }();
  49768. var TranslatedFont = function TranslatedFontClosure() {
  49769. function TranslatedFont(loadedName, font, dict) {
  49770. this.loadedName = loadedName;
  49771. this.font = font;
  49772. this.dict = dict;
  49773. this.type3Loaded = null;
  49774. this.sent = false;
  49775. }
  49776. TranslatedFont.prototype = {
  49777. send: function (handler) {
  49778. if (this.sent) {
  49779. return;
  49780. }
  49781. var fontData = this.font.exportData();
  49782. handler.send('commonobj', [
  49783. this.loadedName,
  49784. 'Font',
  49785. fontData
  49786. ]);
  49787. this.sent = true;
  49788. },
  49789. loadType3Data: function (evaluator, resources, parentOperatorList, task) {
  49790. assert(this.font.isType3Font);
  49791. if (this.type3Loaded) {
  49792. return this.type3Loaded;
  49793. }
  49794. var translatedFont = this.font;
  49795. var loadCharProcsPromise = Promise.resolve();
  49796. var charProcs = this.dict.get('CharProcs');
  49797. var fontResources = this.dict.get('Resources') || resources;
  49798. var charProcKeys = charProcs.getKeys();
  49799. var charProcOperatorList = Object.create(null);
  49800. for (var i = 0, n = charProcKeys.length; i < n; ++i) {
  49801. loadCharProcsPromise = loadCharProcsPromise.then(function (key) {
  49802. var glyphStream = charProcs.get(key);
  49803. var operatorList = new OperatorList();
  49804. return evaluator.getOperatorList(glyphStream, task, fontResources, operatorList).then(function () {
  49805. charProcOperatorList[key] = operatorList.getIR();
  49806. // Add the dependencies to the parent operator list so they are
  49807. // resolved before sub operator list is executed synchronously.
  49808. parentOperatorList.addDependencies(operatorList.dependencies);
  49809. }, function (reason) {
  49810. warn('Type3 font resource \"' + key + '\" is not available');
  49811. var operatorList = new OperatorList();
  49812. charProcOperatorList[key] = operatorList.getIR();
  49813. });
  49814. }.bind(this, charProcKeys[i]));
  49815. }
  49816. this.type3Loaded = loadCharProcsPromise.then(function () {
  49817. translatedFont.charProcOperatorList = charProcOperatorList;
  49818. });
  49819. return this.type3Loaded;
  49820. }
  49821. };
  49822. return TranslatedFont;
  49823. }();
  49824. var OperatorList = function OperatorListClosure() {
  49825. var CHUNK_SIZE = 1000;
  49826. var CHUNK_SIZE_ABOUT = CHUNK_SIZE - 5;
  49827. // close to chunk size
  49828. function getTransfers(queue) {
  49829. var transfers = [];
  49830. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  49831. for (var i = 0, ii = queue.length; i < ii; i++) {
  49832. switch (fnArray[i]) {
  49833. case OPS.paintInlineImageXObject:
  49834. case OPS.paintInlineImageXObjectGroup:
  49835. case OPS.paintImageMaskXObject:
  49836. var arg = argsArray[i][0];
  49837. // first param in imgData
  49838. if (!arg.cached) {
  49839. transfers.push(arg.data.buffer);
  49840. }
  49841. break;
  49842. }
  49843. }
  49844. return transfers;
  49845. }
  49846. function OperatorList(intent, messageHandler, pageIndex) {
  49847. this.messageHandler = messageHandler;
  49848. this.fnArray = [];
  49849. this.argsArray = [];
  49850. this.dependencies = Object.create(null);
  49851. this._totalLength = 0;
  49852. this.pageIndex = pageIndex;
  49853. this.intent = intent;
  49854. }
  49855. OperatorList.prototype = {
  49856. get length() {
  49857. return this.argsArray.length;
  49858. },
  49859. /**
  49860. * @returns {number} The total length of the entire operator list,
  49861. * since `this.length === 0` after flushing.
  49862. */
  49863. get totalLength() {
  49864. return this._totalLength + this.length;
  49865. },
  49866. addOp: function (fn, args) {
  49867. this.fnArray.push(fn);
  49868. this.argsArray.push(args);
  49869. if (this.messageHandler) {
  49870. if (this.fnArray.length >= CHUNK_SIZE) {
  49871. this.flush();
  49872. } else if (this.fnArray.length >= CHUNK_SIZE_ABOUT && (fn === OPS.restore || fn === OPS.endText)) {
  49873. // heuristic to flush on boundary of restore or endText
  49874. this.flush();
  49875. }
  49876. }
  49877. },
  49878. addDependency: function (dependency) {
  49879. if (dependency in this.dependencies) {
  49880. return;
  49881. }
  49882. this.dependencies[dependency] = true;
  49883. this.addOp(OPS.dependency, [dependency]);
  49884. },
  49885. addDependencies: function (dependencies) {
  49886. for (var key in dependencies) {
  49887. this.addDependency(key);
  49888. }
  49889. },
  49890. addOpList: function (opList) {
  49891. Util.extendObj(this.dependencies, opList.dependencies);
  49892. for (var i = 0, ii = opList.length; i < ii; i++) {
  49893. this.addOp(opList.fnArray[i], opList.argsArray[i]);
  49894. }
  49895. },
  49896. getIR: function () {
  49897. return {
  49898. fnArray: this.fnArray,
  49899. argsArray: this.argsArray,
  49900. length: this.length
  49901. };
  49902. },
  49903. flush: function (lastChunk) {
  49904. if (this.intent !== 'oplist') {
  49905. new QueueOptimizer().optimize(this);
  49906. }
  49907. var transfers = getTransfers(this);
  49908. var length = this.length;
  49909. this._totalLength += length;
  49910. this.messageHandler.send('RenderPageChunk', {
  49911. operatorList: {
  49912. fnArray: this.fnArray,
  49913. argsArray: this.argsArray,
  49914. lastChunk: lastChunk,
  49915. length: length
  49916. },
  49917. pageIndex: this.pageIndex,
  49918. intent: this.intent
  49919. }, transfers);
  49920. this.dependencies = Object.create(null);
  49921. this.fnArray.length = 0;
  49922. this.argsArray.length = 0;
  49923. }
  49924. };
  49925. return OperatorList;
  49926. }();
  49927. var StateManager = function StateManagerClosure() {
  49928. function StateManager(initialState) {
  49929. this.state = initialState;
  49930. this.stateStack = [];
  49931. }
  49932. StateManager.prototype = {
  49933. save: function () {
  49934. var old = this.state;
  49935. this.stateStack.push(this.state);
  49936. this.state = old.clone();
  49937. },
  49938. restore: function () {
  49939. var prev = this.stateStack.pop();
  49940. if (prev) {
  49941. this.state = prev;
  49942. }
  49943. },
  49944. transform: function (args) {
  49945. this.state.ctm = Util.transform(this.state.ctm, args);
  49946. }
  49947. };
  49948. return StateManager;
  49949. }();
  49950. var TextState = function TextStateClosure() {
  49951. function TextState() {
  49952. this.ctm = new Float32Array(IDENTITY_MATRIX);
  49953. this.fontName = null;
  49954. this.fontSize = 0;
  49955. this.font = null;
  49956. this.fontMatrix = FONT_IDENTITY_MATRIX;
  49957. this.textMatrix = IDENTITY_MATRIX.slice();
  49958. this.textLineMatrix = IDENTITY_MATRIX.slice();
  49959. this.charSpacing = 0;
  49960. this.wordSpacing = 0;
  49961. this.leading = 0;
  49962. this.textHScale = 1;
  49963. this.textRise = 0;
  49964. }
  49965. TextState.prototype = {
  49966. setTextMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  49967. var m = this.textMatrix;
  49968. m[0] = a;
  49969. m[1] = b;
  49970. m[2] = c;
  49971. m[3] = d;
  49972. m[4] = e;
  49973. m[5] = f;
  49974. },
  49975. setTextLineMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  49976. var m = this.textLineMatrix;
  49977. m[0] = a;
  49978. m[1] = b;
  49979. m[2] = c;
  49980. m[3] = d;
  49981. m[4] = e;
  49982. m[5] = f;
  49983. },
  49984. translateTextMatrix: function TextState_translateTextMatrix(x, y) {
  49985. var m = this.textMatrix;
  49986. m[4] = m[0] * x + m[2] * y + m[4];
  49987. m[5] = m[1] * x + m[3] * y + m[5];
  49988. },
  49989. translateTextLineMatrix: function TextState_translateTextMatrix(x, y) {
  49990. var m = this.textLineMatrix;
  49991. m[4] = m[0] * x + m[2] * y + m[4];
  49992. m[5] = m[1] * x + m[3] * y + m[5];
  49993. },
  49994. calcTextLineMatrixAdvance: function TextState_calcTextLineMatrixAdvance(a, b, c, d, e, f) {
  49995. var font = this.font;
  49996. if (!font) {
  49997. return null;
  49998. }
  49999. var m = this.textLineMatrix;
  50000. if (!(a === m[0] && b === m[1] && c === m[2] && d === m[3])) {
  50001. return null;
  50002. }
  50003. var txDiff = e - m[4], tyDiff = f - m[5];
  50004. if (font.vertical && txDiff !== 0 || !font.vertical && tyDiff !== 0) {
  50005. return null;
  50006. }
  50007. var tx, ty, denominator = a * d - b * c;
  50008. if (font.vertical) {
  50009. tx = -tyDiff * c / denominator;
  50010. ty = tyDiff * a / denominator;
  50011. } else {
  50012. tx = txDiff * d / denominator;
  50013. ty = -txDiff * b / denominator;
  50014. }
  50015. return {
  50016. width: tx,
  50017. height: ty,
  50018. value: font.vertical ? ty : tx
  50019. };
  50020. },
  50021. calcRenderMatrix: function TextState_calcRendeMatrix(ctm) {
  50022. // 9.4.4 Text Space Details
  50023. var tsm = [
  50024. this.fontSize * this.textHScale,
  50025. 0,
  50026. 0,
  50027. this.fontSize,
  50028. 0,
  50029. this.textRise
  50030. ];
  50031. return Util.transform(ctm, Util.transform(this.textMatrix, tsm));
  50032. },
  50033. carriageReturn: function TextState_carriageReturn() {
  50034. this.translateTextLineMatrix(0, -this.leading);
  50035. this.textMatrix = this.textLineMatrix.slice();
  50036. },
  50037. clone: function TextState_clone() {
  50038. var clone = Object.create(this);
  50039. clone.textMatrix = this.textMatrix.slice();
  50040. clone.textLineMatrix = this.textLineMatrix.slice();
  50041. clone.fontMatrix = this.fontMatrix.slice();
  50042. return clone;
  50043. }
  50044. };
  50045. return TextState;
  50046. }();
  50047. var EvalState = function EvalStateClosure() {
  50048. function EvalState() {
  50049. this.ctm = new Float32Array(IDENTITY_MATRIX);
  50050. this.font = null;
  50051. this.textRenderingMode = TextRenderingMode.FILL;
  50052. this.fillColorSpace = ColorSpace.singletons.gray;
  50053. this.strokeColorSpace = ColorSpace.singletons.gray;
  50054. }
  50055. EvalState.prototype = {
  50056. clone: function CanvasExtraState_clone() {
  50057. return Object.create(this);
  50058. }
  50059. };
  50060. return EvalState;
  50061. }();
  50062. var EvaluatorPreprocessor = function EvaluatorPreprocessorClosure() {
  50063. // Specifies properties for each command
  50064. //
  50065. // If variableArgs === true: [0, `numArgs`] expected
  50066. // If variableArgs === false: exactly `numArgs` expected
  50067. var getOPMap = getLookupTableFactory(function (t) {
  50068. // Graphic state
  50069. t['w'] = {
  50070. id: OPS.setLineWidth,
  50071. numArgs: 1,
  50072. variableArgs: false
  50073. };
  50074. t['J'] = {
  50075. id: OPS.setLineCap,
  50076. numArgs: 1,
  50077. variableArgs: false
  50078. };
  50079. t['j'] = {
  50080. id: OPS.setLineJoin,
  50081. numArgs: 1,
  50082. variableArgs: false
  50083. };
  50084. t['M'] = {
  50085. id: OPS.setMiterLimit,
  50086. numArgs: 1,
  50087. variableArgs: false
  50088. };
  50089. t['d'] = {
  50090. id: OPS.setDash,
  50091. numArgs: 2,
  50092. variableArgs: false
  50093. };
  50094. t['ri'] = {
  50095. id: OPS.setRenderingIntent,
  50096. numArgs: 1,
  50097. variableArgs: false
  50098. };
  50099. t['i'] = {
  50100. id: OPS.setFlatness,
  50101. numArgs: 1,
  50102. variableArgs: false
  50103. };
  50104. t['gs'] = {
  50105. id: OPS.setGState,
  50106. numArgs: 1,
  50107. variableArgs: false
  50108. };
  50109. t['q'] = {
  50110. id: OPS.save,
  50111. numArgs: 0,
  50112. variableArgs: false
  50113. };
  50114. t['Q'] = {
  50115. id: OPS.restore,
  50116. numArgs: 0,
  50117. variableArgs: false
  50118. };
  50119. t['cm'] = {
  50120. id: OPS.transform,
  50121. numArgs: 6,
  50122. variableArgs: false
  50123. };
  50124. // Path
  50125. t['m'] = {
  50126. id: OPS.moveTo,
  50127. numArgs: 2,
  50128. variableArgs: false
  50129. };
  50130. t['l'] = {
  50131. id: OPS.lineTo,
  50132. numArgs: 2,
  50133. variableArgs: false
  50134. };
  50135. t['c'] = {
  50136. id: OPS.curveTo,
  50137. numArgs: 6,
  50138. variableArgs: false
  50139. };
  50140. t['v'] = {
  50141. id: OPS.curveTo2,
  50142. numArgs: 4,
  50143. variableArgs: false
  50144. };
  50145. t['y'] = {
  50146. id: OPS.curveTo3,
  50147. numArgs: 4,
  50148. variableArgs: false
  50149. };
  50150. t['h'] = {
  50151. id: OPS.closePath,
  50152. numArgs: 0,
  50153. variableArgs: false
  50154. };
  50155. t['re'] = {
  50156. id: OPS.rectangle,
  50157. numArgs: 4,
  50158. variableArgs: false
  50159. };
  50160. t['S'] = {
  50161. id: OPS.stroke,
  50162. numArgs: 0,
  50163. variableArgs: false
  50164. };
  50165. t['s'] = {
  50166. id: OPS.closeStroke,
  50167. numArgs: 0,
  50168. variableArgs: false
  50169. };
  50170. t['f'] = {
  50171. id: OPS.fill,
  50172. numArgs: 0,
  50173. variableArgs: false
  50174. };
  50175. t['F'] = {
  50176. id: OPS.fill,
  50177. numArgs: 0,
  50178. variableArgs: false
  50179. };
  50180. t['f*'] = {
  50181. id: OPS.eoFill,
  50182. numArgs: 0,
  50183. variableArgs: false
  50184. };
  50185. t['B'] = {
  50186. id: OPS.fillStroke,
  50187. numArgs: 0,
  50188. variableArgs: false
  50189. };
  50190. t['B*'] = {
  50191. id: OPS.eoFillStroke,
  50192. numArgs: 0,
  50193. variableArgs: false
  50194. };
  50195. t['b'] = {
  50196. id: OPS.closeFillStroke,
  50197. numArgs: 0,
  50198. variableArgs: false
  50199. };
  50200. t['b*'] = {
  50201. id: OPS.closeEOFillStroke,
  50202. numArgs: 0,
  50203. variableArgs: false
  50204. };
  50205. t['n'] = {
  50206. id: OPS.endPath,
  50207. numArgs: 0,
  50208. variableArgs: false
  50209. };
  50210. // Clipping
  50211. t['W'] = {
  50212. id: OPS.clip,
  50213. numArgs: 0,
  50214. variableArgs: false
  50215. };
  50216. t['W*'] = {
  50217. id: OPS.eoClip,
  50218. numArgs: 0,
  50219. variableArgs: false
  50220. };
  50221. // Text
  50222. t['BT'] = {
  50223. id: OPS.beginText,
  50224. numArgs: 0,
  50225. variableArgs: false
  50226. };
  50227. t['ET'] = {
  50228. id: OPS.endText,
  50229. numArgs: 0,
  50230. variableArgs: false
  50231. };
  50232. t['Tc'] = {
  50233. id: OPS.setCharSpacing,
  50234. numArgs: 1,
  50235. variableArgs: false
  50236. };
  50237. t['Tw'] = {
  50238. id: OPS.setWordSpacing,
  50239. numArgs: 1,
  50240. variableArgs: false
  50241. };
  50242. t['Tz'] = {
  50243. id: OPS.setHScale,
  50244. numArgs: 1,
  50245. variableArgs: false
  50246. };
  50247. t['TL'] = {
  50248. id: OPS.setLeading,
  50249. numArgs: 1,
  50250. variableArgs: false
  50251. };
  50252. t['Tf'] = {
  50253. id: OPS.setFont,
  50254. numArgs: 2,
  50255. variableArgs: false
  50256. };
  50257. t['Tr'] = {
  50258. id: OPS.setTextRenderingMode,
  50259. numArgs: 1,
  50260. variableArgs: false
  50261. };
  50262. t['Ts'] = {
  50263. id: OPS.setTextRise,
  50264. numArgs: 1,
  50265. variableArgs: false
  50266. };
  50267. t['Td'] = {
  50268. id: OPS.moveText,
  50269. numArgs: 2,
  50270. variableArgs: false
  50271. };
  50272. t['TD'] = {
  50273. id: OPS.setLeadingMoveText,
  50274. numArgs: 2,
  50275. variableArgs: false
  50276. };
  50277. t['Tm'] = {
  50278. id: OPS.setTextMatrix,
  50279. numArgs: 6,
  50280. variableArgs: false
  50281. };
  50282. t['T*'] = {
  50283. id: OPS.nextLine,
  50284. numArgs: 0,
  50285. variableArgs: false
  50286. };
  50287. t['Tj'] = {
  50288. id: OPS.showText,
  50289. numArgs: 1,
  50290. variableArgs: false
  50291. };
  50292. t['TJ'] = {
  50293. id: OPS.showSpacedText,
  50294. numArgs: 1,
  50295. variableArgs: false
  50296. };
  50297. t['\''] = {
  50298. id: OPS.nextLineShowText,
  50299. numArgs: 1,
  50300. variableArgs: false
  50301. };
  50302. t['"'] = {
  50303. id: OPS.nextLineSetSpacingShowText,
  50304. numArgs: 3,
  50305. variableArgs: false
  50306. };
  50307. // Type3 fonts
  50308. t['d0'] = {
  50309. id: OPS.setCharWidth,
  50310. numArgs: 2,
  50311. variableArgs: false
  50312. };
  50313. t['d1'] = {
  50314. id: OPS.setCharWidthAndBounds,
  50315. numArgs: 6,
  50316. variableArgs: false
  50317. };
  50318. // Color
  50319. t['CS'] = {
  50320. id: OPS.setStrokeColorSpace,
  50321. numArgs: 1,
  50322. variableArgs: false
  50323. };
  50324. t['cs'] = {
  50325. id: OPS.setFillColorSpace,
  50326. numArgs: 1,
  50327. variableArgs: false
  50328. };
  50329. t['SC'] = {
  50330. id: OPS.setStrokeColor,
  50331. numArgs: 4,
  50332. variableArgs: true
  50333. };
  50334. t['SCN'] = {
  50335. id: OPS.setStrokeColorN,
  50336. numArgs: 33,
  50337. variableArgs: true
  50338. };
  50339. t['sc'] = {
  50340. id: OPS.setFillColor,
  50341. numArgs: 4,
  50342. variableArgs: true
  50343. };
  50344. t['scn'] = {
  50345. id: OPS.setFillColorN,
  50346. numArgs: 33,
  50347. variableArgs: true
  50348. };
  50349. t['G'] = {
  50350. id: OPS.setStrokeGray,
  50351. numArgs: 1,
  50352. variableArgs: false
  50353. };
  50354. t['g'] = {
  50355. id: OPS.setFillGray,
  50356. numArgs: 1,
  50357. variableArgs: false
  50358. };
  50359. t['RG'] = {
  50360. id: OPS.setStrokeRGBColor,
  50361. numArgs: 3,
  50362. variableArgs: false
  50363. };
  50364. t['rg'] = {
  50365. id: OPS.setFillRGBColor,
  50366. numArgs: 3,
  50367. variableArgs: false
  50368. };
  50369. t['K'] = {
  50370. id: OPS.setStrokeCMYKColor,
  50371. numArgs: 4,
  50372. variableArgs: false
  50373. };
  50374. t['k'] = {
  50375. id: OPS.setFillCMYKColor,
  50376. numArgs: 4,
  50377. variableArgs: false
  50378. };
  50379. // Shading
  50380. t['sh'] = {
  50381. id: OPS.shadingFill,
  50382. numArgs: 1,
  50383. variableArgs: false
  50384. };
  50385. // Images
  50386. t['BI'] = {
  50387. id: OPS.beginInlineImage,
  50388. numArgs: 0,
  50389. variableArgs: false
  50390. };
  50391. t['ID'] = {
  50392. id: OPS.beginImageData,
  50393. numArgs: 0,
  50394. variableArgs: false
  50395. };
  50396. t['EI'] = {
  50397. id: OPS.endInlineImage,
  50398. numArgs: 1,
  50399. variableArgs: false
  50400. };
  50401. // XObjects
  50402. t['Do'] = {
  50403. id: OPS.paintXObject,
  50404. numArgs: 1,
  50405. variableArgs: false
  50406. };
  50407. t['MP'] = {
  50408. id: OPS.markPoint,
  50409. numArgs: 1,
  50410. variableArgs: false
  50411. };
  50412. t['DP'] = {
  50413. id: OPS.markPointProps,
  50414. numArgs: 2,
  50415. variableArgs: false
  50416. };
  50417. t['BMC'] = {
  50418. id: OPS.beginMarkedContent,
  50419. numArgs: 1,
  50420. variableArgs: false
  50421. };
  50422. t['BDC'] = {
  50423. id: OPS.beginMarkedContentProps,
  50424. numArgs: 2,
  50425. variableArgs: false
  50426. };
  50427. t['EMC'] = {
  50428. id: OPS.endMarkedContent,
  50429. numArgs: 0,
  50430. variableArgs: false
  50431. };
  50432. // Compatibility
  50433. t['BX'] = {
  50434. id: OPS.beginCompat,
  50435. numArgs: 0,
  50436. variableArgs: false
  50437. };
  50438. t['EX'] = {
  50439. id: OPS.endCompat,
  50440. numArgs: 0,
  50441. variableArgs: false
  50442. };
  50443. // (reserved partial commands for the lexer)
  50444. t['BM'] = null;
  50445. t['BD'] = null;
  50446. t['true'] = null;
  50447. t['fa'] = null;
  50448. t['fal'] = null;
  50449. t['fals'] = null;
  50450. t['false'] = null;
  50451. t['nu'] = null;
  50452. t['nul'] = null;
  50453. t['null'] = null;
  50454. });
  50455. function EvaluatorPreprocessor(stream, xref, stateManager) {
  50456. this.opMap = getOPMap();
  50457. // TODO(mduan): pass array of knownCommands rather than this.opMap
  50458. // dictionary
  50459. this.parser = new Parser(new Lexer(stream, this.opMap), false, xref);
  50460. this.stateManager = stateManager;
  50461. this.nonProcessedArgs = [];
  50462. }
  50463. EvaluatorPreprocessor.prototype = {
  50464. get savedStatesDepth() {
  50465. return this.stateManager.stateStack.length;
  50466. },
  50467. // |operation| is an object with two fields:
  50468. //
  50469. // - |fn| is an out param.
  50470. //
  50471. // - |args| is an inout param. On entry, it should have one of two values.
  50472. //
  50473. // - An empty array. This indicates that the caller is providing the
  50474. // array in which the args will be stored in. The caller should use
  50475. // this value if it can reuse a single array for each call to read().
  50476. //
  50477. // - |null|. This indicates that the caller needs this function to create
  50478. // the array in which any args are stored in. If there are zero args,
  50479. // this function will leave |operation.args| as |null| (thus avoiding
  50480. // allocations that would occur if we used an empty array to represent
  50481. // zero arguments). Otherwise, it will replace |null| with a new array
  50482. // containing the arguments. The caller should use this value if it
  50483. // cannot reuse an array for each call to read().
  50484. //
  50485. // These two modes are present because this function is very hot and so
  50486. // avoiding allocations where possible is worthwhile.
  50487. //
  50488. read: function EvaluatorPreprocessor_read(operation) {
  50489. var args = operation.args;
  50490. while (true) {
  50491. var obj = this.parser.getObj();
  50492. if (isCmd(obj)) {
  50493. var cmd = obj.cmd;
  50494. // Check that the command is valid
  50495. var opSpec = this.opMap[cmd];
  50496. if (!opSpec) {
  50497. warn('Unknown command "' + cmd + '"');
  50498. continue;
  50499. }
  50500. var fn = opSpec.id;
  50501. var numArgs = opSpec.numArgs;
  50502. var argsLength = args !== null ? args.length : 0;
  50503. if (!opSpec.variableArgs) {
  50504. // Postscript commands can be nested, e.g. /F2 /GS2 gs 5.711 Tf
  50505. if (argsLength !== numArgs) {
  50506. var nonProcessedArgs = this.nonProcessedArgs;
  50507. while (argsLength > numArgs) {
  50508. nonProcessedArgs.push(args.shift());
  50509. argsLength--;
  50510. }
  50511. while (argsLength < numArgs && nonProcessedArgs.length !== 0) {
  50512. if (!args) {
  50513. args = [];
  50514. }
  50515. args.unshift(nonProcessedArgs.pop());
  50516. argsLength++;
  50517. }
  50518. }
  50519. if (argsLength < numArgs) {
  50520. // If we receive too few args, it's not possible to possible
  50521. // to execute the command, so skip the command
  50522. info('Command ' + fn + ': because expected ' + numArgs + ' args, but received ' + argsLength + ' args; skipping');
  50523. args = null;
  50524. continue;
  50525. }
  50526. } else if (argsLength > numArgs) {
  50527. info('Command ' + fn + ': expected [0,' + numArgs + '] args, but received ' + argsLength + ' args');
  50528. }
  50529. // TODO figure out how to type-check vararg functions
  50530. this.preprocessCommand(fn, args);
  50531. operation.fn = fn;
  50532. operation.args = args;
  50533. return true;
  50534. } else {
  50535. if (isEOF(obj)) {
  50536. return false;
  50537. }
  50538. // no more commands
  50539. // argument
  50540. if (obj !== null) {
  50541. if (!args) {
  50542. args = [];
  50543. }
  50544. args.push(obj);
  50545. assert(args.length <= 33, 'Too many arguments');
  50546. }
  50547. }
  50548. }
  50549. },
  50550. preprocessCommand: function EvaluatorPreprocessor_preprocessCommand(fn, args) {
  50551. switch (fn | 0) {
  50552. case OPS.save:
  50553. this.stateManager.save();
  50554. break;
  50555. case OPS.restore:
  50556. this.stateManager.restore();
  50557. break;
  50558. case OPS.transform:
  50559. this.stateManager.transform(args);
  50560. break;
  50561. }
  50562. }
  50563. };
  50564. return EvaluatorPreprocessor;
  50565. }();
  50566. var QueueOptimizer = function QueueOptimizerClosure() {
  50567. function addState(parentState, pattern, fn) {
  50568. var state = parentState;
  50569. for (var i = 0, ii = pattern.length - 1; i < ii; i++) {
  50570. var item = pattern[i];
  50571. state = state[item] || (state[item] = []);
  50572. }
  50573. state[pattern[pattern.length - 1]] = fn;
  50574. }
  50575. function handlePaintSolidColorImageMask(iFirstSave, count, fnArray, argsArray) {
  50576. // Handles special case of mainly LaTeX documents which use image masks to
  50577. // draw lines with the current fill style.
  50578. // 'count' groups of (save, transform, paintImageMaskXObject, restore)+
  50579. // have been found at iFirstSave.
  50580. var iFirstPIMXO = iFirstSave + 2;
  50581. for (var i = 0; i < count; i++) {
  50582. var arg = argsArray[iFirstPIMXO + 4 * i];
  50583. var imageMask = arg.length === 1 && arg[0];
  50584. if (imageMask && imageMask.width === 1 && imageMask.height === 1 && (!imageMask.data.length || imageMask.data.length === 1 && imageMask.data[0] === 0)) {
  50585. fnArray[iFirstPIMXO + 4 * i] = OPS.paintSolidColorImageMask;
  50586. continue;
  50587. }
  50588. break;
  50589. }
  50590. return count - i;
  50591. }
  50592. var InitialState = [];
  50593. // This replaces (save, transform, paintInlineImageXObject, restore)+
  50594. // sequences with one |paintInlineImageXObjectGroup| operation.
  50595. addState(InitialState, [
  50596. OPS.save,
  50597. OPS.transform,
  50598. OPS.paintInlineImageXObject,
  50599. OPS.restore
  50600. ], function foundInlineImageGroup(context) {
  50601. var MIN_IMAGES_IN_INLINE_IMAGES_BLOCK = 10;
  50602. var MAX_IMAGES_IN_INLINE_IMAGES_BLOCK = 200;
  50603. var MAX_WIDTH = 1000;
  50604. var IMAGE_PADDING = 1;
  50605. var fnArray = context.fnArray, argsArray = context.argsArray;
  50606. var curr = context.iCurr;
  50607. var iFirstSave = curr - 3;
  50608. var iFirstTransform = curr - 2;
  50609. var iFirstPIIXO = curr - 1;
  50610. // Look for the quartets.
  50611. var i = iFirstSave + 4;
  50612. var ii = fnArray.length;
  50613. while (i + 3 < ii) {
  50614. if (fnArray[i] !== OPS.save || fnArray[i + 1] !== OPS.transform || fnArray[i + 2] !== OPS.paintInlineImageXObject || fnArray[i + 3] !== OPS.restore) {
  50615. break;
  50616. }
  50617. // ops don't match
  50618. i += 4;
  50619. }
  50620. // At this point, i is the index of the first op past the last valid
  50621. // quartet.
  50622. var count = Math.min((i - iFirstSave) / 4, MAX_IMAGES_IN_INLINE_IMAGES_BLOCK);
  50623. if (count < MIN_IMAGES_IN_INLINE_IMAGES_BLOCK) {
  50624. return i;
  50625. }
  50626. // assuming that heights of those image is too small (~1 pixel)
  50627. // packing as much as possible by lines
  50628. var maxX = 0;
  50629. var map = [], maxLineHeight = 0;
  50630. var currentX = IMAGE_PADDING, currentY = IMAGE_PADDING;
  50631. var q;
  50632. for (q = 0; q < count; q++) {
  50633. var transform = argsArray[iFirstTransform + (q << 2)];
  50634. var img = argsArray[iFirstPIIXO + (q << 2)][0];
  50635. if (currentX + img.width > MAX_WIDTH) {
  50636. // starting new line
  50637. maxX = Math.max(maxX, currentX);
  50638. currentY += maxLineHeight + 2 * IMAGE_PADDING;
  50639. currentX = 0;
  50640. maxLineHeight = 0;
  50641. }
  50642. map.push({
  50643. transform: transform,
  50644. x: currentX,
  50645. y: currentY,
  50646. w: img.width,
  50647. h: img.height
  50648. });
  50649. currentX += img.width + 2 * IMAGE_PADDING;
  50650. maxLineHeight = Math.max(maxLineHeight, img.height);
  50651. }
  50652. var imgWidth = Math.max(maxX, currentX) + IMAGE_PADDING;
  50653. var imgHeight = currentY + maxLineHeight + IMAGE_PADDING;
  50654. var imgData = new Uint8Array(imgWidth * imgHeight * 4);
  50655. var imgRowSize = imgWidth << 2;
  50656. for (q = 0; q < count; q++) {
  50657. var data = argsArray[iFirstPIIXO + (q << 2)][0].data;
  50658. // Copy image by lines and extends pixels into padding.
  50659. var rowSize = map[q].w << 2;
  50660. var dataOffset = 0;
  50661. var offset = map[q].x + map[q].y * imgWidth << 2;
  50662. imgData.set(data.subarray(0, rowSize), offset - imgRowSize);
  50663. for (var k = 0, kk = map[q].h; k < kk; k++) {
  50664. imgData.set(data.subarray(dataOffset, dataOffset + rowSize), offset);
  50665. dataOffset += rowSize;
  50666. offset += imgRowSize;
  50667. }
  50668. imgData.set(data.subarray(dataOffset - rowSize, dataOffset), offset);
  50669. while (offset >= 0) {
  50670. data[offset - 4] = data[offset];
  50671. data[offset - 3] = data[offset + 1];
  50672. data[offset - 2] = data[offset + 2];
  50673. data[offset - 1] = data[offset + 3];
  50674. data[offset + rowSize] = data[offset + rowSize - 4];
  50675. data[offset + rowSize + 1] = data[offset + rowSize - 3];
  50676. data[offset + rowSize + 2] = data[offset + rowSize - 2];
  50677. data[offset + rowSize + 3] = data[offset + rowSize - 1];
  50678. offset -= imgRowSize;
  50679. }
  50680. }
  50681. // Replace queue items.
  50682. fnArray.splice(iFirstSave, count * 4, OPS.paintInlineImageXObjectGroup);
  50683. argsArray.splice(iFirstSave, count * 4, [
  50684. {
  50685. width: imgWidth,
  50686. height: imgHeight,
  50687. kind: ImageKind.RGBA_32BPP,
  50688. data: imgData
  50689. },
  50690. map
  50691. ]);
  50692. return iFirstSave + 1;
  50693. });
  50694. // This replaces (save, transform, paintImageMaskXObject, restore)+
  50695. // sequences with one |paintImageMaskXObjectGroup| or one
  50696. // |paintImageMaskXObjectRepeat| operation.
  50697. addState(InitialState, [
  50698. OPS.save,
  50699. OPS.transform,
  50700. OPS.paintImageMaskXObject,
  50701. OPS.restore
  50702. ], function foundImageMaskGroup(context) {
  50703. var MIN_IMAGES_IN_MASKS_BLOCK = 10;
  50704. var MAX_IMAGES_IN_MASKS_BLOCK = 100;
  50705. var MAX_SAME_IMAGES_IN_MASKS_BLOCK = 1000;
  50706. var fnArray = context.fnArray, argsArray = context.argsArray;
  50707. var curr = context.iCurr;
  50708. var iFirstSave = curr - 3;
  50709. var iFirstTransform = curr - 2;
  50710. var iFirstPIMXO = curr - 1;
  50711. // Look for the quartets.
  50712. var i = iFirstSave + 4;
  50713. var ii = fnArray.length;
  50714. while (i + 3 < ii) {
  50715. if (fnArray[i] !== OPS.save || fnArray[i + 1] !== OPS.transform || fnArray[i + 2] !== OPS.paintImageMaskXObject || fnArray[i + 3] !== OPS.restore) {
  50716. break;
  50717. }
  50718. // ops don't match
  50719. i += 4;
  50720. }
  50721. // At this point, i is the index of the first op past the last valid
  50722. // quartet.
  50723. var count = (i - iFirstSave) / 4;
  50724. count = handlePaintSolidColorImageMask(iFirstSave, count, fnArray, argsArray);
  50725. if (count < MIN_IMAGES_IN_MASKS_BLOCK) {
  50726. return i;
  50727. }
  50728. var q;
  50729. var isSameImage = false;
  50730. var iTransform, transformArgs;
  50731. var firstPIMXOArg0 = argsArray[iFirstPIMXO][0];
  50732. if (argsArray[iFirstTransform][1] === 0 && argsArray[iFirstTransform][2] === 0) {
  50733. isSameImage = true;
  50734. var firstTransformArg0 = argsArray[iFirstTransform][0];
  50735. var firstTransformArg3 = argsArray[iFirstTransform][3];
  50736. iTransform = iFirstTransform + 4;
  50737. var iPIMXO = iFirstPIMXO + 4;
  50738. for (q = 1; q < count; q++, iTransform += 4, iPIMXO += 4) {
  50739. transformArgs = argsArray[iTransform];
  50740. if (argsArray[iPIMXO][0] !== firstPIMXOArg0 || transformArgs[0] !== firstTransformArg0 || transformArgs[1] !== 0 || transformArgs[2] !== 0 || transformArgs[3] !== firstTransformArg3) {
  50741. if (q < MIN_IMAGES_IN_MASKS_BLOCK) {
  50742. isSameImage = false;
  50743. } else {
  50744. count = q;
  50745. }
  50746. break;
  50747. }
  50748. }
  50749. }
  50750. // different image or transform
  50751. if (isSameImage) {
  50752. count = Math.min(count, MAX_SAME_IMAGES_IN_MASKS_BLOCK);
  50753. var positions = new Float32Array(count * 2);
  50754. iTransform = iFirstTransform;
  50755. for (q = 0; q < count; q++, iTransform += 4) {
  50756. transformArgs = argsArray[iTransform];
  50757. positions[q << 1] = transformArgs[4];
  50758. positions[(q << 1) + 1] = transformArgs[5];
  50759. }
  50760. // Replace queue items.
  50761. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectRepeat);
  50762. argsArray.splice(iFirstSave, count * 4, [
  50763. firstPIMXOArg0,
  50764. firstTransformArg0,
  50765. firstTransformArg3,
  50766. positions
  50767. ]);
  50768. } else {
  50769. count = Math.min(count, MAX_IMAGES_IN_MASKS_BLOCK);
  50770. var images = [];
  50771. for (q = 0; q < count; q++) {
  50772. transformArgs = argsArray[iFirstTransform + (q << 2)];
  50773. var maskParams = argsArray[iFirstPIMXO + (q << 2)][0];
  50774. images.push({
  50775. data: maskParams.data,
  50776. width: maskParams.width,
  50777. height: maskParams.height,
  50778. transform: transformArgs
  50779. });
  50780. }
  50781. // Replace queue items.
  50782. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectGroup);
  50783. argsArray.splice(iFirstSave, count * 4, [images]);
  50784. }
  50785. return iFirstSave + 1;
  50786. });
  50787. // This replaces (save, transform, paintImageXObject, restore)+ sequences
  50788. // with one paintImageXObjectRepeat operation, if the |transform| and
  50789. // |paintImageXObjectRepeat| ops are appropriate.
  50790. addState(InitialState, [
  50791. OPS.save,
  50792. OPS.transform,
  50793. OPS.paintImageXObject,
  50794. OPS.restore
  50795. ], function (context) {
  50796. var MIN_IMAGES_IN_BLOCK = 3;
  50797. var MAX_IMAGES_IN_BLOCK = 1000;
  50798. var fnArray = context.fnArray, argsArray = context.argsArray;
  50799. var curr = context.iCurr;
  50800. var iFirstSave = curr - 3;
  50801. var iFirstTransform = curr - 2;
  50802. var iFirstPIXO = curr - 1;
  50803. var iFirstRestore = curr;
  50804. if (argsArray[iFirstTransform][1] !== 0 || argsArray[iFirstTransform][2] !== 0) {
  50805. return iFirstRestore + 1;
  50806. }
  50807. // transform has the wrong form
  50808. // Look for the quartets.
  50809. var firstPIXOArg0 = argsArray[iFirstPIXO][0];
  50810. var firstTransformArg0 = argsArray[iFirstTransform][0];
  50811. var firstTransformArg3 = argsArray[iFirstTransform][3];
  50812. var i = iFirstSave + 4;
  50813. var ii = fnArray.length;
  50814. while (i + 3 < ii) {
  50815. if (fnArray[i] !== OPS.save || fnArray[i + 1] !== OPS.transform || fnArray[i + 2] !== OPS.paintImageXObject || fnArray[i + 3] !== OPS.restore) {
  50816. break;
  50817. }
  50818. // ops don't match
  50819. if (argsArray[i + 1][0] !== firstTransformArg0 || argsArray[i + 1][1] !== 0 || argsArray[i + 1][2] !== 0 || argsArray[i + 1][3] !== firstTransformArg3) {
  50820. break;
  50821. }
  50822. // transforms don't match
  50823. if (argsArray[i + 2][0] !== firstPIXOArg0) {
  50824. break;
  50825. }
  50826. // images don't match
  50827. i += 4;
  50828. }
  50829. // At this point, i is the index of the first op past the last valid
  50830. // quartet.
  50831. var count = Math.min((i - iFirstSave) / 4, MAX_IMAGES_IN_BLOCK);
  50832. if (count < MIN_IMAGES_IN_BLOCK) {
  50833. return i;
  50834. }
  50835. // Extract the (x,y) positions from all of the matching transforms.
  50836. var positions = new Float32Array(count * 2);
  50837. var iTransform = iFirstTransform;
  50838. for (var q = 0; q < count; q++, iTransform += 4) {
  50839. var transformArgs = argsArray[iTransform];
  50840. positions[q << 1] = transformArgs[4];
  50841. positions[(q << 1) + 1] = transformArgs[5];
  50842. }
  50843. // Replace queue items.
  50844. var args = [
  50845. firstPIXOArg0,
  50846. firstTransformArg0,
  50847. firstTransformArg3,
  50848. positions
  50849. ];
  50850. fnArray.splice(iFirstSave, count * 4, OPS.paintImageXObjectRepeat);
  50851. argsArray.splice(iFirstSave, count * 4, args);
  50852. return iFirstSave + 1;
  50853. });
  50854. // This replaces (beginText, setFont, setTextMatrix, showText, endText)+
  50855. // sequences with (beginText, setFont, (setTextMatrix, showText)+, endText)+
  50856. // sequences, if the font for each one is the same.
  50857. addState(InitialState, [
  50858. OPS.beginText,
  50859. OPS.setFont,
  50860. OPS.setTextMatrix,
  50861. OPS.showText,
  50862. OPS.endText
  50863. ], function (context) {
  50864. var MIN_CHARS_IN_BLOCK = 3;
  50865. var MAX_CHARS_IN_BLOCK = 1000;
  50866. var fnArray = context.fnArray, argsArray = context.argsArray;
  50867. var curr = context.iCurr;
  50868. var iFirstBeginText = curr - 4;
  50869. var iFirstSetFont = curr - 3;
  50870. var iFirstSetTextMatrix = curr - 2;
  50871. var iFirstShowText = curr - 1;
  50872. var iFirstEndText = curr;
  50873. // Look for the quintets.
  50874. var firstSetFontArg0 = argsArray[iFirstSetFont][0];
  50875. var firstSetFontArg1 = argsArray[iFirstSetFont][1];
  50876. var i = iFirstBeginText + 5;
  50877. var ii = fnArray.length;
  50878. while (i + 4 < ii) {
  50879. if (fnArray[i] !== OPS.beginText || fnArray[i + 1] !== OPS.setFont || fnArray[i + 2] !== OPS.setTextMatrix || fnArray[i + 3] !== OPS.showText || fnArray[i + 4] !== OPS.endText) {
  50880. break;
  50881. }
  50882. // ops don't match
  50883. if (argsArray[i + 1][0] !== firstSetFontArg0 || argsArray[i + 1][1] !== firstSetFontArg1) {
  50884. break;
  50885. }
  50886. // fonts don't match
  50887. i += 5;
  50888. }
  50889. // At this point, i is the index of the first op past the last valid
  50890. // quintet.
  50891. var count = Math.min((i - iFirstBeginText) / 5, MAX_CHARS_IN_BLOCK);
  50892. if (count < MIN_CHARS_IN_BLOCK) {
  50893. return i;
  50894. }
  50895. // If the preceding quintet is (<something>, setFont, setTextMatrix,
  50896. // showText, endText), include that as well. (E.g. <something> might be
  50897. // |dependency|.)
  50898. var iFirst = iFirstBeginText;
  50899. if (iFirstBeginText >= 4 && fnArray[iFirstBeginText - 4] === fnArray[iFirstSetFont] && fnArray[iFirstBeginText - 3] === fnArray[iFirstSetTextMatrix] && fnArray[iFirstBeginText - 2] === fnArray[iFirstShowText] && fnArray[iFirstBeginText - 1] === fnArray[iFirstEndText] && argsArray[iFirstBeginText - 4][0] === firstSetFontArg0 && argsArray[iFirstBeginText - 4][1] === firstSetFontArg1) {
  50900. count++;
  50901. iFirst -= 5;
  50902. }
  50903. // Remove (endText, beginText, setFont) trios.
  50904. var iEndText = iFirst + 4;
  50905. for (var q = 1; q < count; q++) {
  50906. fnArray.splice(iEndText, 3);
  50907. argsArray.splice(iEndText, 3);
  50908. iEndText += 2;
  50909. }
  50910. return iEndText + 1;
  50911. });
  50912. function QueueOptimizer() {
  50913. }
  50914. QueueOptimizer.prototype = {
  50915. optimize: function QueueOptimizer_optimize(queue) {
  50916. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  50917. var context = {
  50918. iCurr: 0,
  50919. fnArray: fnArray,
  50920. argsArray: argsArray
  50921. };
  50922. var state;
  50923. var i = 0, ii = fnArray.length;
  50924. while (i < ii) {
  50925. state = (state || InitialState)[fnArray[i]];
  50926. if (typeof state === 'function') {
  50927. // we found some handler
  50928. context.iCurr = i;
  50929. // state() returns the index of the first non-matching op (if we
  50930. // didn't match) or the first op past the modified ops (if we did
  50931. // match and replace).
  50932. i = state(context);
  50933. state = undefined;
  50934. // reset the state machine
  50935. ii = context.fnArray.length;
  50936. } else {
  50937. i++;
  50938. }
  50939. }
  50940. }
  50941. };
  50942. return QueueOptimizer;
  50943. }();
  50944. exports.OperatorList = OperatorList;
  50945. exports.PartialEvaluator = PartialEvaluator;
  50946. }));
  50947. (function (root, factory) {
  50948. factory(root.pdfjsCoreAnnotation = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreColorSpace, root.pdfjsCoreObj, root.pdfjsCoreEvaluator);
  50949. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreColorSpace, coreObj, coreEvaluator) {
  50950. var AnnotationBorderStyleType = sharedUtil.AnnotationBorderStyleType;
  50951. var AnnotationFieldFlag = sharedUtil.AnnotationFieldFlag;
  50952. var AnnotationFlag = sharedUtil.AnnotationFlag;
  50953. var AnnotationType = sharedUtil.AnnotationType;
  50954. var OPS = sharedUtil.OPS;
  50955. var Util = sharedUtil.Util;
  50956. var isBool = sharedUtil.isBool;
  50957. var isString = sharedUtil.isString;
  50958. var isArray = sharedUtil.isArray;
  50959. var isInt = sharedUtil.isInt;
  50960. var isValidUrl = sharedUtil.isValidUrl;
  50961. var stringToBytes = sharedUtil.stringToBytes;
  50962. var stringToPDFString = sharedUtil.stringToPDFString;
  50963. var stringToUTF8String = sharedUtil.stringToUTF8String;
  50964. var warn = sharedUtil.warn;
  50965. var Dict = corePrimitives.Dict;
  50966. var isDict = corePrimitives.isDict;
  50967. var isName = corePrimitives.isName;
  50968. var isRef = corePrimitives.isRef;
  50969. var Stream = coreStream.Stream;
  50970. var ColorSpace = coreColorSpace.ColorSpace;
  50971. var ObjectLoader = coreObj.ObjectLoader;
  50972. var FileSpec = coreObj.FileSpec;
  50973. var OperatorList = coreEvaluator.OperatorList;
  50974. /**
  50975. * @class
  50976. * @alias AnnotationFactory
  50977. */
  50978. function AnnotationFactory() {
  50979. }
  50980. AnnotationFactory.prototype = /** @lends AnnotationFactory.prototype */
  50981. {
  50982. /**
  50983. * @param {XRef} xref
  50984. * @param {Object} ref
  50985. * @param {string} uniquePrefix
  50986. * @param {Object} idCounters
  50987. * @returns {Annotation}
  50988. */
  50989. create: function AnnotationFactory_create(xref, ref, uniquePrefix, idCounters) {
  50990. var dict = xref.fetchIfRef(ref);
  50991. if (!isDict(dict)) {
  50992. return;
  50993. }
  50994. var id = isRef(ref) ? ref.toString() : 'annot_' + (uniquePrefix || '') + ++idCounters.obj;
  50995. // Determine the annotation's subtype.
  50996. var subtype = dict.get('Subtype');
  50997. subtype = isName(subtype) ? subtype.name : null;
  50998. // Return the right annotation object based on the subtype and field type.
  50999. var parameters = {
  51000. xref: xref,
  51001. dict: dict,
  51002. ref: isRef(ref) ? ref : null,
  51003. subtype: subtype,
  51004. id: id
  51005. };
  51006. switch (subtype) {
  51007. case 'Link':
  51008. return new LinkAnnotation(parameters);
  51009. case 'Text':
  51010. return new TextAnnotation(parameters);
  51011. case 'Widget':
  51012. var fieldType = Util.getInheritableProperty(dict, 'FT');
  51013. fieldType = isName(fieldType) ? fieldType.name : null;
  51014. switch (fieldType) {
  51015. case 'Tx':
  51016. return new TextWidgetAnnotation(parameters);
  51017. case 'Ch':
  51018. return new ChoiceWidgetAnnotation(parameters);
  51019. }
  51020. warn('Unimplemented widget field type "' + fieldType + '", ' + 'falling back to base field type.');
  51021. return new WidgetAnnotation(parameters);
  51022. case 'Popup':
  51023. return new PopupAnnotation(parameters);
  51024. case 'Highlight':
  51025. return new HighlightAnnotation(parameters);
  51026. case 'Underline':
  51027. return new UnderlineAnnotation(parameters);
  51028. case 'Squiggly':
  51029. return new SquigglyAnnotation(parameters);
  51030. case 'StrikeOut':
  51031. return new StrikeOutAnnotation(parameters);
  51032. case 'FileAttachment':
  51033. return new FileAttachmentAnnotation(parameters);
  51034. default:
  51035. if (!subtype) {
  51036. warn('Annotation is missing the required /Subtype.');
  51037. } else {
  51038. warn('Unimplemented annotation type "' + subtype + '", ' + 'falling back to base annotation.');
  51039. }
  51040. return new Annotation(parameters);
  51041. }
  51042. }
  51043. };
  51044. var Annotation = function AnnotationClosure() {
  51045. // 12.5.5: Algorithm: Appearance streams
  51046. function getTransformMatrix(rect, bbox, matrix) {
  51047. var bounds = Util.getAxialAlignedBoundingBox(bbox, matrix);
  51048. var minX = bounds[0];
  51049. var minY = bounds[1];
  51050. var maxX = bounds[2];
  51051. var maxY = bounds[3];
  51052. if (minX === maxX || minY === maxY) {
  51053. // From real-life file, bbox was [0, 0, 0, 0]. In this case,
  51054. // just apply the transform for rect
  51055. return [
  51056. 1,
  51057. 0,
  51058. 0,
  51059. 1,
  51060. rect[0],
  51061. rect[1]
  51062. ];
  51063. }
  51064. var xRatio = (rect[2] - rect[0]) / (maxX - minX);
  51065. var yRatio = (rect[3] - rect[1]) / (maxY - minY);
  51066. return [
  51067. xRatio,
  51068. 0,
  51069. 0,
  51070. yRatio,
  51071. rect[0] - minX * xRatio,
  51072. rect[1] - minY * yRatio
  51073. ];
  51074. }
  51075. function getDefaultAppearance(dict) {
  51076. var appearanceState = dict.get('AP');
  51077. if (!isDict(appearanceState)) {
  51078. return;
  51079. }
  51080. var appearance;
  51081. var appearances = appearanceState.get('N');
  51082. if (isDict(appearances)) {
  51083. var as = dict.get('AS');
  51084. if (as && appearances.has(as.name)) {
  51085. appearance = appearances.get(as.name);
  51086. }
  51087. } else {
  51088. appearance = appearances;
  51089. }
  51090. return appearance;
  51091. }
  51092. function Annotation(params) {
  51093. var dict = params.dict;
  51094. this.setFlags(dict.get('F'));
  51095. this.setRectangle(dict.getArray('Rect'));
  51096. this.setColor(dict.getArray('C'));
  51097. this.setBorderStyle(dict);
  51098. this.appearance = getDefaultAppearance(dict);
  51099. // Expose public properties using a data object.
  51100. this.data = {};
  51101. this.data.id = params.id;
  51102. this.data.subtype = params.subtype;
  51103. this.data.annotationFlags = this.flags;
  51104. this.data.rect = this.rectangle;
  51105. this.data.color = this.color;
  51106. this.data.borderStyle = this.borderStyle;
  51107. this.data.hasAppearance = !!this.appearance;
  51108. }
  51109. Annotation.prototype = {
  51110. /**
  51111. * @private
  51112. */
  51113. _hasFlag: function Annotation_hasFlag(flags, flag) {
  51114. return !!(flags & flag);
  51115. },
  51116. /**
  51117. * @private
  51118. */
  51119. _isViewable: function Annotation_isViewable(flags) {
  51120. return !this._hasFlag(flags, AnnotationFlag.INVISIBLE) && !this._hasFlag(flags, AnnotationFlag.HIDDEN) && !this._hasFlag(flags, AnnotationFlag.NOVIEW);
  51121. },
  51122. /**
  51123. * @private
  51124. */
  51125. _isPrintable: function AnnotationFlag_isPrintable(flags) {
  51126. return this._hasFlag(flags, AnnotationFlag.PRINT) && !this._hasFlag(flags, AnnotationFlag.INVISIBLE) && !this._hasFlag(flags, AnnotationFlag.HIDDEN);
  51127. },
  51128. /**
  51129. * @return {boolean}
  51130. */
  51131. get viewable() {
  51132. if (this.flags === 0) {
  51133. return true;
  51134. }
  51135. return this._isViewable(this.flags);
  51136. },
  51137. /**
  51138. * @return {boolean}
  51139. */
  51140. get printable() {
  51141. if (this.flags === 0) {
  51142. return false;
  51143. }
  51144. return this._isPrintable(this.flags);
  51145. },
  51146. /**
  51147. * Set the flags.
  51148. *
  51149. * @public
  51150. * @memberof Annotation
  51151. * @param {number} flags - Unsigned 32-bit integer specifying annotation
  51152. * characteristics
  51153. * @see {@link shared/util.js}
  51154. */
  51155. setFlags: function Annotation_setFlags(flags) {
  51156. this.flags = isInt(flags) && flags > 0 ? flags : 0;
  51157. },
  51158. /**
  51159. * Check if a provided flag is set.
  51160. *
  51161. * @public
  51162. * @memberof Annotation
  51163. * @param {number} flag - Hexadecimal representation for an annotation
  51164. * characteristic
  51165. * @return {boolean}
  51166. * @see {@link shared/util.js}
  51167. */
  51168. hasFlag: function Annotation_hasFlag(flag) {
  51169. return this._hasFlag(this.flags, flag);
  51170. },
  51171. /**
  51172. * Set the rectangle.
  51173. *
  51174. * @public
  51175. * @memberof Annotation
  51176. * @param {Array} rectangle - The rectangle array with exactly four entries
  51177. */
  51178. setRectangle: function Annotation_setRectangle(rectangle) {
  51179. if (isArray(rectangle) && rectangle.length === 4) {
  51180. this.rectangle = Util.normalizeRect(rectangle);
  51181. } else {
  51182. this.rectangle = [
  51183. 0,
  51184. 0,
  51185. 0,
  51186. 0
  51187. ];
  51188. }
  51189. },
  51190. /**
  51191. * Set the color and take care of color space conversion.
  51192. *
  51193. * @public
  51194. * @memberof Annotation
  51195. * @param {Array} color - The color array containing either 0
  51196. * (transparent), 1 (grayscale), 3 (RGB) or
  51197. * 4 (CMYK) elements
  51198. */
  51199. setColor: function Annotation_setColor(color) {
  51200. var rgbColor = new Uint8Array(3);
  51201. // Black in RGB color space (default)
  51202. if (!isArray(color)) {
  51203. this.color = rgbColor;
  51204. return;
  51205. }
  51206. switch (color.length) {
  51207. case 0:
  51208. // Transparent, which we indicate with a null value
  51209. this.color = null;
  51210. break;
  51211. case 1:
  51212. // Convert grayscale to RGB
  51213. ColorSpace.singletons.gray.getRgbItem(color, 0, rgbColor, 0);
  51214. this.color = rgbColor;
  51215. break;
  51216. case 3:
  51217. // Convert RGB percentages to RGB
  51218. ColorSpace.singletons.rgb.getRgbItem(color, 0, rgbColor, 0);
  51219. this.color = rgbColor;
  51220. break;
  51221. case 4:
  51222. // Convert CMYK to RGB
  51223. ColorSpace.singletons.cmyk.getRgbItem(color, 0, rgbColor, 0);
  51224. this.color = rgbColor;
  51225. break;
  51226. default:
  51227. this.color = rgbColor;
  51228. break;
  51229. }
  51230. },
  51231. /**
  51232. * Set the border style (as AnnotationBorderStyle object).
  51233. *
  51234. * @public
  51235. * @memberof Annotation
  51236. * @param {Dict} borderStyle - The border style dictionary
  51237. */
  51238. setBorderStyle: function Annotation_setBorderStyle(borderStyle) {
  51239. this.borderStyle = new AnnotationBorderStyle();
  51240. if (!isDict(borderStyle)) {
  51241. return;
  51242. }
  51243. if (borderStyle.has('BS')) {
  51244. var dict = borderStyle.get('BS');
  51245. var dictType = dict.get('Type');
  51246. if (!dictType || isName(dictType, 'Border')) {
  51247. this.borderStyle.setWidth(dict.get('W'));
  51248. this.borderStyle.setStyle(dict.get('S'));
  51249. this.borderStyle.setDashArray(dict.getArray('D'));
  51250. }
  51251. } else if (borderStyle.has('Border')) {
  51252. var array = borderStyle.getArray('Border');
  51253. if (isArray(array) && array.length >= 3) {
  51254. this.borderStyle.setHorizontalCornerRadius(array[0]);
  51255. this.borderStyle.setVerticalCornerRadius(array[1]);
  51256. this.borderStyle.setWidth(array[2]);
  51257. if (array.length === 4) {
  51258. // Dash array available
  51259. this.borderStyle.setDashArray(array[3]);
  51260. }
  51261. }
  51262. } else {
  51263. // There are no border entries in the dictionary. According to the
  51264. // specification, we should draw a solid border of width 1 in that
  51265. // case, but Adobe Reader did not implement that part of the
  51266. // specification and instead draws no border at all, so we do the same.
  51267. // See also https://github.com/mozilla/pdf.js/issues/6179.
  51268. this.borderStyle.setWidth(0);
  51269. }
  51270. },
  51271. /**
  51272. * Prepare the annotation for working with a popup in the display layer.
  51273. *
  51274. * @private
  51275. * @memberof Annotation
  51276. * @param {Dict} dict - The annotation's data dictionary
  51277. */
  51278. _preparePopup: function Annotation_preparePopup(dict) {
  51279. if (!dict.has('C')) {
  51280. // Fall back to the default background color.
  51281. this.data.color = null;
  51282. }
  51283. this.data.hasPopup = dict.has('Popup');
  51284. this.data.title = stringToPDFString(dict.get('T') || '');
  51285. this.data.contents = stringToPDFString(dict.get('Contents') || '');
  51286. },
  51287. loadResources: function Annotation_loadResources(keys) {
  51288. return new Promise(function (resolve, reject) {
  51289. this.appearance.dict.getAsync('Resources').then(function (resources) {
  51290. if (!resources) {
  51291. resolve();
  51292. return;
  51293. }
  51294. var objectLoader = new ObjectLoader(resources.map, keys, resources.xref);
  51295. objectLoader.load().then(function () {
  51296. resolve(resources);
  51297. }, reject);
  51298. }, reject);
  51299. }.bind(this));
  51300. },
  51301. getOperatorList: function Annotation_getOperatorList(evaluator, task, renderForms) {
  51302. if (!this.appearance) {
  51303. return Promise.resolve(new OperatorList());
  51304. }
  51305. var data = this.data;
  51306. var appearanceDict = this.appearance.dict;
  51307. var resourcesPromise = this.loadResources([
  51308. 'ExtGState',
  51309. 'ColorSpace',
  51310. 'Pattern',
  51311. 'Shading',
  51312. 'XObject',
  51313. 'Font'
  51314. ]);
  51315. // ProcSet
  51316. // Properties
  51317. var bbox = appearanceDict.getArray('BBox') || [
  51318. 0,
  51319. 0,
  51320. 1,
  51321. 1
  51322. ];
  51323. var matrix = appearanceDict.getArray('Matrix') || [
  51324. 1,
  51325. 0,
  51326. 0,
  51327. 1,
  51328. 0,
  51329. 0
  51330. ];
  51331. var transform = getTransformMatrix(data.rect, bbox, matrix);
  51332. var self = this;
  51333. return resourcesPromise.then(function (resources) {
  51334. var opList = new OperatorList();
  51335. opList.addOp(OPS.beginAnnotation, [
  51336. data.rect,
  51337. transform,
  51338. matrix
  51339. ]);
  51340. return evaluator.getOperatorList(self.appearance, task, resources, opList).then(function () {
  51341. opList.addOp(OPS.endAnnotation, []);
  51342. self.appearance.reset();
  51343. return opList;
  51344. });
  51345. });
  51346. }
  51347. };
  51348. Annotation.appendToOperatorList = function Annotation_appendToOperatorList(annotations, opList, partialEvaluator, task, intent, renderForms) {
  51349. var annotationPromises = [];
  51350. for (var i = 0, n = annotations.length; i < n; ++i) {
  51351. if (intent === 'display' && annotations[i].viewable || intent === 'print' && annotations[i].printable) {
  51352. annotationPromises.push(annotations[i].getOperatorList(partialEvaluator, task, renderForms));
  51353. }
  51354. }
  51355. return Promise.all(annotationPromises).then(function (operatorLists) {
  51356. opList.addOp(OPS.beginAnnotations, []);
  51357. for (var i = 0, n = operatorLists.length; i < n; ++i) {
  51358. opList.addOpList(operatorLists[i]);
  51359. }
  51360. opList.addOp(OPS.endAnnotations, []);
  51361. });
  51362. };
  51363. return Annotation;
  51364. }();
  51365. /**
  51366. * Contains all data regarding an annotation's border style.
  51367. *
  51368. * @class
  51369. */
  51370. var AnnotationBorderStyle = function AnnotationBorderStyleClosure() {
  51371. /**
  51372. * @constructor
  51373. * @private
  51374. */
  51375. function AnnotationBorderStyle() {
  51376. this.width = 1;
  51377. this.style = AnnotationBorderStyleType.SOLID;
  51378. this.dashArray = [3];
  51379. this.horizontalCornerRadius = 0;
  51380. this.verticalCornerRadius = 0;
  51381. }
  51382. AnnotationBorderStyle.prototype = {
  51383. /**
  51384. * Set the width.
  51385. *
  51386. * @public
  51387. * @memberof AnnotationBorderStyle
  51388. * @param {integer} width - The width
  51389. */
  51390. setWidth: function AnnotationBorderStyle_setWidth(width) {
  51391. if (width === (width | 0)) {
  51392. this.width = width;
  51393. }
  51394. },
  51395. /**
  51396. * Set the style.
  51397. *
  51398. * @public
  51399. * @memberof AnnotationBorderStyle
  51400. * @param {Object} style - The style object
  51401. * @see {@link shared/util.js}
  51402. */
  51403. setStyle: function AnnotationBorderStyle_setStyle(style) {
  51404. if (!style) {
  51405. return;
  51406. }
  51407. switch (style.name) {
  51408. case 'S':
  51409. this.style = AnnotationBorderStyleType.SOLID;
  51410. break;
  51411. case 'D':
  51412. this.style = AnnotationBorderStyleType.DASHED;
  51413. break;
  51414. case 'B':
  51415. this.style = AnnotationBorderStyleType.BEVELED;
  51416. break;
  51417. case 'I':
  51418. this.style = AnnotationBorderStyleType.INSET;
  51419. break;
  51420. case 'U':
  51421. this.style = AnnotationBorderStyleType.UNDERLINE;
  51422. break;
  51423. default:
  51424. break;
  51425. }
  51426. },
  51427. /**
  51428. * Set the dash array.
  51429. *
  51430. * @public
  51431. * @memberof AnnotationBorderStyle
  51432. * @param {Array} dashArray - The dash array with at least one element
  51433. */
  51434. setDashArray: function AnnotationBorderStyle_setDashArray(dashArray) {
  51435. // We validate the dash array, but we do not use it because CSS does not
  51436. // allow us to change spacing of dashes. For more information, visit
  51437. // http://www.w3.org/TR/css3-background/#the-border-style.
  51438. if (isArray(dashArray) && dashArray.length > 0) {
  51439. // According to the PDF specification: the elements in a dashArray
  51440. // shall be numbers that are nonnegative and not all equal to zero.
  51441. var isValid = true;
  51442. var allZeros = true;
  51443. for (var i = 0, len = dashArray.length; i < len; i++) {
  51444. var element = dashArray[i];
  51445. var validNumber = +element >= 0;
  51446. if (!validNumber) {
  51447. isValid = false;
  51448. break;
  51449. } else if (element > 0) {
  51450. allZeros = false;
  51451. }
  51452. }
  51453. if (isValid && !allZeros) {
  51454. this.dashArray = dashArray;
  51455. } else {
  51456. this.width = 0;
  51457. }
  51458. } else // Adobe behavior when the array is invalid.
  51459. if (dashArray) {
  51460. this.width = 0;
  51461. }
  51462. },
  51463. // Adobe behavior when the array is invalid.
  51464. /**
  51465. * Set the horizontal corner radius (from a Border dictionary).
  51466. *
  51467. * @public
  51468. * @memberof AnnotationBorderStyle
  51469. * @param {integer} radius - The horizontal corner radius
  51470. */
  51471. setHorizontalCornerRadius: function AnnotationBorderStyle_setHorizontalCornerRadius(radius) {
  51472. if (radius === (radius | 0)) {
  51473. this.horizontalCornerRadius = radius;
  51474. }
  51475. },
  51476. /**
  51477. * Set the vertical corner radius (from a Border dictionary).
  51478. *
  51479. * @public
  51480. * @memberof AnnotationBorderStyle
  51481. * @param {integer} radius - The vertical corner radius
  51482. */
  51483. setVerticalCornerRadius: function AnnotationBorderStyle_setVerticalCornerRadius(radius) {
  51484. if (radius === (radius | 0)) {
  51485. this.verticalCornerRadius = radius;
  51486. }
  51487. }
  51488. };
  51489. return AnnotationBorderStyle;
  51490. }();
  51491. var WidgetAnnotation = function WidgetAnnotationClosure() {
  51492. function WidgetAnnotation(params) {
  51493. Annotation.call(this, params);
  51494. var dict = params.dict;
  51495. var data = this.data;
  51496. data.annotationType = AnnotationType.WIDGET;
  51497. data.fieldValue = Util.getInheritableProperty(dict, 'V', /* getArray = */
  51498. true);
  51499. data.alternativeText = stringToPDFString(dict.get('TU') || '');
  51500. data.defaultAppearance = Util.getInheritableProperty(dict, 'DA') || '';
  51501. var fieldType = Util.getInheritableProperty(dict, 'FT');
  51502. data.fieldType = isName(fieldType) ? fieldType.name : null;
  51503. this.fieldResources = Util.getInheritableProperty(dict, 'DR') || Dict.empty;
  51504. data.fieldFlags = Util.getInheritableProperty(dict, 'Ff');
  51505. if (!isInt(data.fieldFlags) || data.fieldFlags < 0) {
  51506. data.fieldFlags = 0;
  51507. }
  51508. data.readOnly = this.hasFieldFlag(AnnotationFieldFlag.READONLY);
  51509. // Hide signatures because we cannot validate them.
  51510. if (data.fieldType === 'Sig') {
  51511. this.setFlags(AnnotationFlag.HIDDEN);
  51512. }
  51513. // Building the full field name by collecting the field and
  51514. // its ancestors 'T' data and joining them using '.'.
  51515. var fieldName = [];
  51516. var namedItem = dict;
  51517. var ref = params.ref;
  51518. while (namedItem) {
  51519. var parent = namedItem.get('Parent');
  51520. var parentRef = namedItem.getRaw('Parent');
  51521. var name = namedItem.get('T');
  51522. if (name) {
  51523. fieldName.unshift(stringToPDFString(name));
  51524. } else if (parent && ref) {
  51525. // The field name is absent, that means more than one field
  51526. // with the same name may exist. Replacing the empty name
  51527. // with the '`' plus index in the parent's 'Kids' array.
  51528. // This is not in the PDF spec but necessary to id the
  51529. // the input controls.
  51530. var kids = parent.get('Kids');
  51531. var j, jj;
  51532. for (j = 0, jj = kids.length; j < jj; j++) {
  51533. var kidRef = kids[j];
  51534. if (kidRef.num === ref.num && kidRef.gen === ref.gen) {
  51535. break;
  51536. }
  51537. }
  51538. fieldName.unshift('`' + j);
  51539. }
  51540. namedItem = parent;
  51541. ref = parentRef;
  51542. }
  51543. data.fullName = fieldName.join('.');
  51544. }
  51545. Util.inherit(WidgetAnnotation, Annotation, {
  51546. /**
  51547. * Check if a provided field flag is set.
  51548. *
  51549. * @public
  51550. * @memberof WidgetAnnotation
  51551. * @param {number} flag - Hexadecimal representation for an annotation
  51552. * field characteristic
  51553. * @return {boolean}
  51554. * @see {@link shared/util.js}
  51555. */
  51556. hasFieldFlag: function WidgetAnnotation_hasFieldFlag(flag) {
  51557. return !!(this.data.fieldFlags & flag);
  51558. }
  51559. });
  51560. return WidgetAnnotation;
  51561. }();
  51562. var TextWidgetAnnotation = function TextWidgetAnnotationClosure() {
  51563. function TextWidgetAnnotation(params) {
  51564. WidgetAnnotation.call(this, params);
  51565. // The field value is always a string.
  51566. this.data.fieldValue = stringToPDFString(this.data.fieldValue || '');
  51567. // Determine the alignment of text in the field.
  51568. var alignment = Util.getInheritableProperty(params.dict, 'Q');
  51569. if (!isInt(alignment) || alignment < 0 || alignment > 2) {
  51570. alignment = null;
  51571. }
  51572. this.data.textAlignment = alignment;
  51573. // Determine the maximum length of text in the field.
  51574. var maximumLength = Util.getInheritableProperty(params.dict, 'MaxLen');
  51575. if (!isInt(maximumLength) || maximumLength < 0) {
  51576. maximumLength = null;
  51577. }
  51578. this.data.maxLen = maximumLength;
  51579. // Process field flags for the display layer.
  51580. this.data.multiLine = this.hasFieldFlag(AnnotationFieldFlag.MULTILINE);
  51581. this.data.comb = this.hasFieldFlag(AnnotationFieldFlag.COMB) && !this.hasFieldFlag(AnnotationFieldFlag.MULTILINE) && !this.hasFieldFlag(AnnotationFieldFlag.PASSWORD) && !this.hasFieldFlag(AnnotationFieldFlag.FILESELECT) && this.data.maxLen !== null;
  51582. }
  51583. Util.inherit(TextWidgetAnnotation, WidgetAnnotation, {
  51584. getOperatorList: function TextWidgetAnnotation_getOperatorList(evaluator, task, renderForms) {
  51585. var operatorList = new OperatorList();
  51586. // Do not render form elements on the canvas when interactive forms are
  51587. // enabled. The display layer is responsible for rendering them instead.
  51588. if (renderForms) {
  51589. return Promise.resolve(operatorList);
  51590. }
  51591. if (this.appearance) {
  51592. return Annotation.prototype.getOperatorList.call(this, evaluator, task, renderForms);
  51593. }
  51594. // Even if there is an appearance stream, ignore it. This is the
  51595. // behaviour used by Adobe Reader.
  51596. if (!this.data.defaultAppearance) {
  51597. return Promise.resolve(operatorList);
  51598. }
  51599. var stream = new Stream(stringToBytes(this.data.defaultAppearance));
  51600. return evaluator.getOperatorList(stream, task, this.fieldResources, operatorList).then(function () {
  51601. return operatorList;
  51602. });
  51603. }
  51604. });
  51605. return TextWidgetAnnotation;
  51606. }();
  51607. var ChoiceWidgetAnnotation = function ChoiceWidgetAnnotationClosure() {
  51608. function ChoiceWidgetAnnotation(params) {
  51609. WidgetAnnotation.call(this, params);
  51610. // Determine the options. The options array may consist of strings or
  51611. // arrays. If the array consists of arrays, then the first element of
  51612. // each array is the export value and the second element of each array is
  51613. // the display value. If the array consists of strings, then these
  51614. // represent both the export and display value. In this case, we convert
  51615. // it to an array of arrays as well for convenience in the display layer.
  51616. this.data.options = [];
  51617. var options = params.dict.getArray('Opt');
  51618. if (isArray(options)) {
  51619. for (var i = 0, ii = options.length; i < ii; i++) {
  51620. var option = options[i];
  51621. this.data.options[i] = {
  51622. exportValue: isArray(option) ? option[0] : option,
  51623. displayValue: isArray(option) ? option[1] : option
  51624. };
  51625. }
  51626. }
  51627. // Determine the field value. In this case, it may be a string or an
  51628. // array of strings. For convenience in the display layer, convert the
  51629. // string to an array of one string as well.
  51630. if (!isArray(this.data.fieldValue)) {
  51631. this.data.fieldValue = [this.data.fieldValue];
  51632. }
  51633. // Process field flags for the display layer.
  51634. this.data.combo = this.hasFieldFlag(AnnotationFieldFlag.COMBO);
  51635. this.data.multiSelect = this.hasFieldFlag(AnnotationFieldFlag.MULTISELECT);
  51636. }
  51637. Util.inherit(ChoiceWidgetAnnotation, WidgetAnnotation, {
  51638. getOperatorList: function ChoiceWidgetAnnotation_getOperatorList(evaluator, task, renderForms) {
  51639. var operatorList = new OperatorList();
  51640. // Do not render form elements on the canvas when interactive forms are
  51641. // enabled. The display layer is responsible for rendering them instead.
  51642. if (renderForms) {
  51643. return Promise.resolve(operatorList);
  51644. }
  51645. return Annotation.prototype.getOperatorList.call(this, evaluator, task, renderForms);
  51646. }
  51647. });
  51648. return ChoiceWidgetAnnotation;
  51649. }();
  51650. var TextAnnotation = function TextAnnotationClosure() {
  51651. var DEFAULT_ICON_SIZE = 22;
  51652. // px
  51653. function TextAnnotation(parameters) {
  51654. Annotation.call(this, parameters);
  51655. this.data.annotationType = AnnotationType.TEXT;
  51656. if (this.data.hasAppearance) {
  51657. this.data.name = 'NoIcon';
  51658. } else {
  51659. this.data.rect[1] = this.data.rect[3] - DEFAULT_ICON_SIZE;
  51660. this.data.rect[2] = this.data.rect[0] + DEFAULT_ICON_SIZE;
  51661. this.data.name = parameters.dict.has('Name') ? parameters.dict.get('Name').name : 'Note';
  51662. }
  51663. this._preparePopup(parameters.dict);
  51664. }
  51665. Util.inherit(TextAnnotation, Annotation, {});
  51666. return TextAnnotation;
  51667. }();
  51668. var LinkAnnotation = function LinkAnnotationClosure() {
  51669. function LinkAnnotation(params) {
  51670. Annotation.call(this, params);
  51671. var dict = params.dict;
  51672. var data = this.data;
  51673. data.annotationType = AnnotationType.LINK;
  51674. var action = dict.get('A'), url, dest;
  51675. if (action && isDict(action)) {
  51676. var linkType = action.get('S').name;
  51677. switch (linkType) {
  51678. case 'URI':
  51679. url = action.get('URI');
  51680. if (isName(url)) {
  51681. // Some bad PDFs do not put parentheses around relative URLs.
  51682. url = '/' + url.name;
  51683. } else if (url) {
  51684. url = addDefaultProtocolToUrl(url);
  51685. }
  51686. // TODO: pdf spec mentions urls can be relative to a Base
  51687. // entry in the dictionary.
  51688. break;
  51689. case 'GoTo':
  51690. dest = action.get('D');
  51691. break;
  51692. case 'GoToR':
  51693. var urlDict = action.get('F');
  51694. if (isDict(urlDict)) {
  51695. // We assume that we found a FileSpec dictionary
  51696. // and fetch the URL without checking any further.
  51697. url = urlDict.get('F') || null;
  51698. } else if (isString(urlDict)) {
  51699. url = urlDict;
  51700. }
  51701. // NOTE: the destination is relative to the *remote* document.
  51702. var remoteDest = action.get('D');
  51703. if (remoteDest) {
  51704. if (isName(remoteDest)) {
  51705. remoteDest = remoteDest.name;
  51706. }
  51707. if (isString(url)) {
  51708. var baseUrl = url.split('#')[0];
  51709. if (isString(remoteDest)) {
  51710. // In practice, a named destination may contain only a number.
  51711. // If that happens, use the '#nameddest=' form to avoid the link
  51712. // redirecting to a page, instead of the correct destination.
  51713. url = baseUrl + '#' + (/^\d+$/.test(remoteDest) ? 'nameddest=' : '') + remoteDest;
  51714. } else if (isArray(remoteDest)) {
  51715. url = baseUrl + '#' + JSON.stringify(remoteDest);
  51716. }
  51717. }
  51718. }
  51719. // The 'NewWindow' property, equal to `LinkTarget.BLANK`.
  51720. var newWindow = action.get('NewWindow');
  51721. if (isBool(newWindow)) {
  51722. data.newWindow = newWindow;
  51723. }
  51724. break;
  51725. case 'Named':
  51726. data.action = action.get('N').name;
  51727. break;
  51728. default:
  51729. warn('unrecognized link type: ' + linkType);
  51730. }
  51731. } else if (dict.has('Dest')) {
  51732. // Simple destination link.
  51733. dest = dict.get('Dest');
  51734. }
  51735. if (url) {
  51736. if (isValidUrl(url, /* allowRelative = */
  51737. false)) {
  51738. data.url = tryConvertUrlEncoding(url);
  51739. }
  51740. }
  51741. if (dest) {
  51742. data.dest = isName(dest) ? dest.name : dest;
  51743. }
  51744. }
  51745. // Lets URLs beginning with 'www.' default to using the 'http://' protocol.
  51746. function addDefaultProtocolToUrl(url) {
  51747. if (isString(url) && url.indexOf('www.') === 0) {
  51748. return 'http://' + url;
  51749. }
  51750. return url;
  51751. }
  51752. function tryConvertUrlEncoding(url) {
  51753. // According to ISO 32000-1:2008, section 12.6.4.7, URIs should be encoded
  51754. // in 7-bit ASCII. Some bad PDFs use UTF-8 encoding, see Bugzilla 1122280.
  51755. try {
  51756. return stringToUTF8String(url);
  51757. } catch (e) {
  51758. return url;
  51759. }
  51760. }
  51761. Util.inherit(LinkAnnotation, Annotation, {});
  51762. return LinkAnnotation;
  51763. }();
  51764. var PopupAnnotation = function PopupAnnotationClosure() {
  51765. function PopupAnnotation(parameters) {
  51766. Annotation.call(this, parameters);
  51767. this.data.annotationType = AnnotationType.POPUP;
  51768. var dict = parameters.dict;
  51769. var parentItem = dict.get('Parent');
  51770. if (!parentItem) {
  51771. warn('Popup annotation has a missing or invalid parent annotation.');
  51772. return;
  51773. }
  51774. this.data.parentId = dict.getRaw('Parent').toString();
  51775. this.data.title = stringToPDFString(parentItem.get('T') || '');
  51776. this.data.contents = stringToPDFString(parentItem.get('Contents') || '');
  51777. if (!parentItem.has('C')) {
  51778. // Fall back to the default background color.
  51779. this.data.color = null;
  51780. } else {
  51781. this.setColor(parentItem.getArray('C'));
  51782. this.data.color = this.color;
  51783. }
  51784. // If the Popup annotation is not viewable, but the parent annotation is,
  51785. // that is most likely a bug. Fallback to inherit the flags from the parent
  51786. // annotation (this is consistent with the behaviour in Adobe Reader).
  51787. if (!this.viewable) {
  51788. var parentFlags = parentItem.get('F');
  51789. if (this._isViewable(parentFlags)) {
  51790. this.setFlags(parentFlags);
  51791. }
  51792. }
  51793. }
  51794. Util.inherit(PopupAnnotation, Annotation, {});
  51795. return PopupAnnotation;
  51796. }();
  51797. var HighlightAnnotation = function HighlightAnnotationClosure() {
  51798. function HighlightAnnotation(parameters) {
  51799. Annotation.call(this, parameters);
  51800. this.data.annotationType = AnnotationType.HIGHLIGHT;
  51801. this._preparePopup(parameters.dict);
  51802. // PDF viewers completely ignore any border styles.
  51803. this.data.borderStyle.setWidth(0);
  51804. }
  51805. Util.inherit(HighlightAnnotation, Annotation, {});
  51806. return HighlightAnnotation;
  51807. }();
  51808. var UnderlineAnnotation = function UnderlineAnnotationClosure() {
  51809. function UnderlineAnnotation(parameters) {
  51810. Annotation.call(this, parameters);
  51811. this.data.annotationType = AnnotationType.UNDERLINE;
  51812. this._preparePopup(parameters.dict);
  51813. // PDF viewers completely ignore any border styles.
  51814. this.data.borderStyle.setWidth(0);
  51815. }
  51816. Util.inherit(UnderlineAnnotation, Annotation, {});
  51817. return UnderlineAnnotation;
  51818. }();
  51819. var SquigglyAnnotation = function SquigglyAnnotationClosure() {
  51820. function SquigglyAnnotation(parameters) {
  51821. Annotation.call(this, parameters);
  51822. this.data.annotationType = AnnotationType.SQUIGGLY;
  51823. this._preparePopup(parameters.dict);
  51824. // PDF viewers completely ignore any border styles.
  51825. this.data.borderStyle.setWidth(0);
  51826. }
  51827. Util.inherit(SquigglyAnnotation, Annotation, {});
  51828. return SquigglyAnnotation;
  51829. }();
  51830. var StrikeOutAnnotation = function StrikeOutAnnotationClosure() {
  51831. function StrikeOutAnnotation(parameters) {
  51832. Annotation.call(this, parameters);
  51833. this.data.annotationType = AnnotationType.STRIKEOUT;
  51834. this._preparePopup(parameters.dict);
  51835. // PDF viewers completely ignore any border styles.
  51836. this.data.borderStyle.setWidth(0);
  51837. }
  51838. Util.inherit(StrikeOutAnnotation, Annotation, {});
  51839. return StrikeOutAnnotation;
  51840. }();
  51841. var FileAttachmentAnnotation = function FileAttachmentAnnotationClosure() {
  51842. function FileAttachmentAnnotation(parameters) {
  51843. Annotation.call(this, parameters);
  51844. var file = new FileSpec(parameters.dict.get('FS'), parameters.xref);
  51845. this.data.annotationType = AnnotationType.FILEATTACHMENT;
  51846. this.data.file = file.serializable;
  51847. this._preparePopup(parameters.dict);
  51848. }
  51849. Util.inherit(FileAttachmentAnnotation, Annotation, {});
  51850. return FileAttachmentAnnotation;
  51851. }();
  51852. exports.Annotation = Annotation;
  51853. exports.AnnotationBorderStyle = AnnotationBorderStyle;
  51854. exports.AnnotationFactory = AnnotationFactory;
  51855. }));
  51856. (function (root, factory) {
  51857. factory(root.pdfjsCoreDocument = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreObj, root.pdfjsCoreParser, root.pdfjsCoreCrypto, root.pdfjsCoreEvaluator, root.pdfjsCoreAnnotation);
  51858. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreObj, coreParser, coreCrypto, coreEvaluator, coreAnnotation) {
  51859. var MissingDataException = sharedUtil.MissingDataException;
  51860. var Util = sharedUtil.Util;
  51861. var assert = sharedUtil.assert;
  51862. var error = sharedUtil.error;
  51863. var info = sharedUtil.info;
  51864. var isArray = sharedUtil.isArray;
  51865. var isArrayBuffer = sharedUtil.isArrayBuffer;
  51866. var isString = sharedUtil.isString;
  51867. var shadow = sharedUtil.shadow;
  51868. var stringToBytes = sharedUtil.stringToBytes;
  51869. var stringToPDFString = sharedUtil.stringToPDFString;
  51870. var warn = sharedUtil.warn;
  51871. var isSpace = sharedUtil.isSpace;
  51872. var Dict = corePrimitives.Dict;
  51873. var isDict = corePrimitives.isDict;
  51874. var isName = corePrimitives.isName;
  51875. var isStream = corePrimitives.isStream;
  51876. var NullStream = coreStream.NullStream;
  51877. var Stream = coreStream.Stream;
  51878. var StreamsSequenceStream = coreStream.StreamsSequenceStream;
  51879. var Catalog = coreObj.Catalog;
  51880. var ObjectLoader = coreObj.ObjectLoader;
  51881. var XRef = coreObj.XRef;
  51882. var Linearization = coreParser.Linearization;
  51883. var calculateMD5 = coreCrypto.calculateMD5;
  51884. var OperatorList = coreEvaluator.OperatorList;
  51885. var PartialEvaluator = coreEvaluator.PartialEvaluator;
  51886. var Annotation = coreAnnotation.Annotation;
  51887. var AnnotationFactory = coreAnnotation.AnnotationFactory;
  51888. var Page = function PageClosure() {
  51889. var LETTER_SIZE_MEDIABOX = [
  51890. 0,
  51891. 0,
  51892. 612,
  51893. 792
  51894. ];
  51895. function Page(pdfManager, xref, pageIndex, pageDict, ref, fontCache) {
  51896. this.pdfManager = pdfManager;
  51897. this.pageIndex = pageIndex;
  51898. this.pageDict = pageDict;
  51899. this.xref = xref;
  51900. this.ref = ref;
  51901. this.fontCache = fontCache;
  51902. this.uniquePrefix = 'p' + this.pageIndex + '_';
  51903. this.idCounters = { obj: 0 };
  51904. this.evaluatorOptions = pdfManager.evaluatorOptions;
  51905. this.resourcesPromise = null;
  51906. }
  51907. Page.prototype = {
  51908. getPageProp: function Page_getPageProp(key) {
  51909. return this.pageDict.get(key);
  51910. },
  51911. getInheritedPageProp: function Page_getInheritedPageProp(key) {
  51912. var dict = this.pageDict, valueArray = null, loopCount = 0;
  51913. var MAX_LOOP_COUNT = 100;
  51914. // Always walk up the entire parent chain, to be able to find
  51915. // e.g. \Resources placed on multiple levels of the tree.
  51916. while (dict) {
  51917. var value = dict.get(key);
  51918. if (value) {
  51919. if (!valueArray) {
  51920. valueArray = [];
  51921. }
  51922. valueArray.push(value);
  51923. }
  51924. if (++loopCount > MAX_LOOP_COUNT) {
  51925. warn('Page_getInheritedPageProp: maximum loop count exceeded.');
  51926. break;
  51927. }
  51928. dict = dict.get('Parent');
  51929. }
  51930. if (!valueArray) {
  51931. return Dict.empty;
  51932. }
  51933. if (valueArray.length === 1 || !isDict(valueArray[0]) || loopCount > MAX_LOOP_COUNT) {
  51934. return valueArray[0];
  51935. }
  51936. return Dict.merge(this.xref, valueArray);
  51937. },
  51938. get content() {
  51939. return this.getPageProp('Contents');
  51940. },
  51941. get resources() {
  51942. // For robustness: The spec states that a \Resources entry has to be
  51943. // present, but can be empty. Some document omit it still, in this case
  51944. // we return an empty dictionary.
  51945. return shadow(this, 'resources', this.getInheritedPageProp('Resources'));
  51946. },
  51947. get mediaBox() {
  51948. var obj = this.getInheritedPageProp('MediaBox');
  51949. // Reset invalid media box to letter size.
  51950. if (!isArray(obj) || obj.length !== 4) {
  51951. obj = LETTER_SIZE_MEDIABOX;
  51952. }
  51953. return shadow(this, 'mediaBox', obj);
  51954. },
  51955. get view() {
  51956. var mediaBox = this.mediaBox;
  51957. var cropBox = this.getInheritedPageProp('CropBox');
  51958. if (!isArray(cropBox) || cropBox.length !== 4) {
  51959. return shadow(this, 'view', mediaBox);
  51960. }
  51961. // From the spec, 6th ed., p.963:
  51962. // "The crop, bleed, trim, and art boxes should not ordinarily
  51963. // extend beyond the boundaries of the media box. If they do, they are
  51964. // effectively reduced to their intersection with the media box."
  51965. cropBox = Util.intersect(cropBox, mediaBox);
  51966. if (!cropBox) {
  51967. return shadow(this, 'view', mediaBox);
  51968. }
  51969. return shadow(this, 'view', cropBox);
  51970. },
  51971. get rotate() {
  51972. var rotate = this.getInheritedPageProp('Rotate') || 0;
  51973. // Normalize rotation so it's a multiple of 90 and between 0 and 270
  51974. if (rotate % 90 !== 0) {
  51975. rotate = 0;
  51976. } else if (rotate >= 360) {
  51977. rotate = rotate % 360;
  51978. } else if (rotate < 0) {
  51979. // The spec doesn't cover negatives, assume its counterclockwise
  51980. // rotation. The following is the other implementation of modulo.
  51981. rotate = (rotate % 360 + 360) % 360;
  51982. }
  51983. return shadow(this, 'rotate', rotate);
  51984. },
  51985. getContentStream: function Page_getContentStream() {
  51986. var content = this.content;
  51987. var stream;
  51988. if (isArray(content)) {
  51989. // fetching items
  51990. var xref = this.xref;
  51991. var i, n = content.length;
  51992. var streams = [];
  51993. for (i = 0; i < n; ++i) {
  51994. streams.push(xref.fetchIfRef(content[i]));
  51995. }
  51996. stream = new StreamsSequenceStream(streams);
  51997. } else if (isStream(content)) {
  51998. stream = content;
  51999. } else {
  52000. // replacing non-existent page content with empty one
  52001. stream = new NullStream();
  52002. }
  52003. return stream;
  52004. },
  52005. loadResources: function Page_loadResources(keys) {
  52006. if (!this.resourcesPromise) {
  52007. // TODO: add async getInheritedPageProp and remove this.
  52008. this.resourcesPromise = this.pdfManager.ensure(this, 'resources');
  52009. }
  52010. return this.resourcesPromise.then(function resourceSuccess() {
  52011. var objectLoader = new ObjectLoader(this.resources.map, keys, this.xref);
  52012. return objectLoader.load();
  52013. }.bind(this));
  52014. },
  52015. getOperatorList: function Page_getOperatorList(handler, task, intent, renderInteractiveForms) {
  52016. var self = this;
  52017. var pdfManager = this.pdfManager;
  52018. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream', []);
  52019. var resourcesPromise = this.loadResources([
  52020. 'ExtGState',
  52021. 'ColorSpace',
  52022. 'Pattern',
  52023. 'Shading',
  52024. 'XObject',
  52025. 'Font'
  52026. ]);
  52027. // ProcSet
  52028. // Properties
  52029. var partialEvaluator = new PartialEvaluator(pdfManager, this.xref, handler, this.pageIndex, this.uniquePrefix, this.idCounters, this.fontCache, this.evaluatorOptions);
  52030. var dataPromises = Promise.all([
  52031. contentStreamPromise,
  52032. resourcesPromise
  52033. ]);
  52034. var pageListPromise = dataPromises.then(function (data) {
  52035. var contentStream = data[0];
  52036. var opList = new OperatorList(intent, handler, self.pageIndex);
  52037. handler.send('StartRenderPage', {
  52038. transparency: partialEvaluator.hasBlendModes(self.resources),
  52039. pageIndex: self.pageIndex,
  52040. intent: intent
  52041. });
  52042. return partialEvaluator.getOperatorList(contentStream, task, self.resources, opList).then(function () {
  52043. return opList;
  52044. });
  52045. });
  52046. var annotationsPromise = pdfManager.ensure(this, 'annotations');
  52047. return Promise.all([
  52048. pageListPromise,
  52049. annotationsPromise
  52050. ]).then(function (datas) {
  52051. var pageOpList = datas[0];
  52052. var annotations = datas[1];
  52053. if (annotations.length === 0) {
  52054. pageOpList.flush(true);
  52055. return pageOpList;
  52056. }
  52057. var annotationsReadyPromise = Annotation.appendToOperatorList(annotations, pageOpList, partialEvaluator, task, intent, renderInteractiveForms);
  52058. return annotationsReadyPromise.then(function () {
  52059. pageOpList.flush(true);
  52060. return pageOpList;
  52061. });
  52062. });
  52063. },
  52064. extractTextContent: function Page_extractTextContent(task, normalizeWhitespace, combineTextItems) {
  52065. var handler = {
  52066. on: function nullHandlerOn() {
  52067. },
  52068. send: function nullHandlerSend() {
  52069. }
  52070. };
  52071. var self = this;
  52072. var pdfManager = this.pdfManager;
  52073. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream', []);
  52074. var resourcesPromise = this.loadResources([
  52075. 'ExtGState',
  52076. 'XObject',
  52077. 'Font'
  52078. ]);
  52079. var dataPromises = Promise.all([
  52080. contentStreamPromise,
  52081. resourcesPromise
  52082. ]);
  52083. return dataPromises.then(function (data) {
  52084. var contentStream = data[0];
  52085. var partialEvaluator = new PartialEvaluator(pdfManager, self.xref, handler, self.pageIndex, self.uniquePrefix, self.idCounters, self.fontCache, self.evaluatorOptions);
  52086. return partialEvaluator.getTextContent(contentStream, task, self.resources, /* stateManager = */
  52087. null, normalizeWhitespace, combineTextItems);
  52088. });
  52089. },
  52090. getAnnotationsData: function Page_getAnnotationsData(intent) {
  52091. var annotations = this.annotations;
  52092. var annotationsData = [];
  52093. for (var i = 0, n = annotations.length; i < n; ++i) {
  52094. if (intent) {
  52095. if (!(intent === 'display' && annotations[i].viewable) && !(intent === 'print' && annotations[i].printable)) {
  52096. continue;
  52097. }
  52098. }
  52099. annotationsData.push(annotations[i].data);
  52100. }
  52101. return annotationsData;
  52102. },
  52103. get annotations() {
  52104. var annotations = [];
  52105. var annotationRefs = this.getInheritedPageProp('Annots') || [];
  52106. var annotationFactory = new AnnotationFactory();
  52107. for (var i = 0, n = annotationRefs.length; i < n; ++i) {
  52108. var annotationRef = annotationRefs[i];
  52109. var annotation = annotationFactory.create(this.xref, annotationRef, this.uniquePrefix, this.idCounters);
  52110. if (annotation) {
  52111. annotations.push(annotation);
  52112. }
  52113. }
  52114. return shadow(this, 'annotations', annotations);
  52115. }
  52116. };
  52117. return Page;
  52118. }();
  52119. /**
  52120. * The `PDFDocument` holds all the data of the PDF file. Compared to the
  52121. * `PDFDoc`, this one doesn't have any job management code.
  52122. * Right now there exists one PDFDocument on the main thread + one object
  52123. * for each worker. If there is no worker support enabled, there are two
  52124. * `PDFDocument` objects on the main thread created.
  52125. */
  52126. var PDFDocument = function PDFDocumentClosure() {
  52127. var FINGERPRINT_FIRST_BYTES = 1024;
  52128. var EMPTY_FINGERPRINT = '\x00\x00\x00\x00\x00\x00\x00' + '\x00\x00\x00\x00\x00\x00\x00\x00\x00';
  52129. function PDFDocument(pdfManager, arg, password) {
  52130. if (isStream(arg)) {
  52131. init.call(this, pdfManager, arg, password);
  52132. } else if (isArrayBuffer(arg)) {
  52133. init.call(this, pdfManager, new Stream(arg), password);
  52134. } else {
  52135. error('PDFDocument: Unknown argument type');
  52136. }
  52137. }
  52138. function init(pdfManager, stream, password) {
  52139. assert(stream.length > 0, 'stream must have data');
  52140. this.pdfManager = pdfManager;
  52141. this.stream = stream;
  52142. var xref = new XRef(this.stream, password, pdfManager);
  52143. this.xref = xref;
  52144. }
  52145. function find(stream, needle, limit, backwards) {
  52146. var pos = stream.pos;
  52147. var end = stream.end;
  52148. var strBuf = [];
  52149. if (pos + limit > end) {
  52150. limit = end - pos;
  52151. }
  52152. for (var n = 0; n < limit; ++n) {
  52153. strBuf.push(String.fromCharCode(stream.getByte()));
  52154. }
  52155. var str = strBuf.join('');
  52156. stream.pos = pos;
  52157. var index = backwards ? str.lastIndexOf(needle) : str.indexOf(needle);
  52158. if (index === -1) {
  52159. return false;
  52160. }
  52161. /* not found */
  52162. stream.pos += index;
  52163. return true;
  52164. }
  52165. /* found */
  52166. var DocumentInfoValidators = {
  52167. get entries() {
  52168. // Lazily build this since all the validation functions below are not
  52169. // defined until after this file loads.
  52170. return shadow(this, 'entries', {
  52171. Title: isString,
  52172. Author: isString,
  52173. Subject: isString,
  52174. Keywords: isString,
  52175. Creator: isString,
  52176. Producer: isString,
  52177. CreationDate: isString,
  52178. ModDate: isString,
  52179. Trapped: isName
  52180. });
  52181. }
  52182. };
  52183. PDFDocument.prototype = {
  52184. parse: function PDFDocument_parse(recoveryMode) {
  52185. this.setup(recoveryMode);
  52186. var version = this.catalog.catDict.get('Version');
  52187. if (isName(version)) {
  52188. this.pdfFormatVersion = version.name;
  52189. }
  52190. try {
  52191. // checking if AcroForm is present
  52192. this.acroForm = this.catalog.catDict.get('AcroForm');
  52193. if (this.acroForm) {
  52194. this.xfa = this.acroForm.get('XFA');
  52195. var fields = this.acroForm.get('Fields');
  52196. if ((!fields || !isArray(fields) || fields.length === 0) && !this.xfa) {
  52197. // no fields and no XFA -- not a form (?)
  52198. this.acroForm = null;
  52199. }
  52200. }
  52201. } catch (ex) {
  52202. info('Something wrong with AcroForm entry');
  52203. this.acroForm = null;
  52204. }
  52205. },
  52206. get linearization() {
  52207. var linearization = null;
  52208. if (this.stream.length) {
  52209. try {
  52210. linearization = Linearization.create(this.stream);
  52211. } catch (err) {
  52212. if (err instanceof MissingDataException) {
  52213. throw err;
  52214. }
  52215. info(err);
  52216. }
  52217. }
  52218. // shadow the prototype getter with a data property
  52219. return shadow(this, 'linearization', linearization);
  52220. },
  52221. get startXRef() {
  52222. var stream = this.stream;
  52223. var startXRef = 0;
  52224. var linearization = this.linearization;
  52225. if (linearization) {
  52226. // Find end of first obj.
  52227. stream.reset();
  52228. if (find(stream, 'endobj', 1024)) {
  52229. startXRef = stream.pos + 6;
  52230. }
  52231. } else {
  52232. // Find startxref by jumping backward from the end of the file.
  52233. var step = 1024;
  52234. var found = false, pos = stream.end;
  52235. while (!found && pos > 0) {
  52236. pos -= step - 'startxref'.length;
  52237. if (pos < 0) {
  52238. pos = 0;
  52239. }
  52240. stream.pos = pos;
  52241. found = find(stream, 'startxref', step, true);
  52242. }
  52243. if (found) {
  52244. stream.skip(9);
  52245. var ch;
  52246. do {
  52247. ch = stream.getByte();
  52248. } while (isSpace(ch));
  52249. var str = '';
  52250. while (ch >= 0x20 && ch <= 0x39) {
  52251. // < '9'
  52252. str += String.fromCharCode(ch);
  52253. ch = stream.getByte();
  52254. }
  52255. startXRef = parseInt(str, 10);
  52256. if (isNaN(startXRef)) {
  52257. startXRef = 0;
  52258. }
  52259. }
  52260. }
  52261. // shadow the prototype getter with a data property
  52262. return shadow(this, 'startXRef', startXRef);
  52263. },
  52264. get mainXRefEntriesOffset() {
  52265. var mainXRefEntriesOffset = 0;
  52266. var linearization = this.linearization;
  52267. if (linearization) {
  52268. mainXRefEntriesOffset = linearization.mainXRefEntriesOffset;
  52269. }
  52270. // shadow the prototype getter with a data property
  52271. return shadow(this, 'mainXRefEntriesOffset', mainXRefEntriesOffset);
  52272. },
  52273. // Find the header, remove leading garbage and setup the stream
  52274. // starting from the header.
  52275. checkHeader: function PDFDocument_checkHeader() {
  52276. var stream = this.stream;
  52277. stream.reset();
  52278. if (find(stream, '%PDF-', 1024)) {
  52279. // Found the header, trim off any garbage before it.
  52280. stream.moveStart();
  52281. // Reading file format version
  52282. var MAX_VERSION_LENGTH = 12;
  52283. var version = '', ch;
  52284. while ((ch = stream.getByte()) > 0x20) {
  52285. // SPACE
  52286. if (version.length >= MAX_VERSION_LENGTH) {
  52287. break;
  52288. }
  52289. version += String.fromCharCode(ch);
  52290. }
  52291. if (!this.pdfFormatVersion) {
  52292. // removing "%PDF-"-prefix
  52293. this.pdfFormatVersion = version.substring(5);
  52294. }
  52295. return;
  52296. }
  52297. },
  52298. // May not be a PDF file, continue anyway.
  52299. parseStartXRef: function PDFDocument_parseStartXRef() {
  52300. var startXRef = this.startXRef;
  52301. this.xref.setStartXRef(startXRef);
  52302. },
  52303. setup: function PDFDocument_setup(recoveryMode) {
  52304. this.xref.parse(recoveryMode);
  52305. var self = this;
  52306. var pageFactory = {
  52307. createPage: function (pageIndex, dict, ref, fontCache) {
  52308. return new Page(self.pdfManager, self.xref, pageIndex, dict, ref, fontCache);
  52309. }
  52310. };
  52311. this.catalog = new Catalog(this.pdfManager, this.xref, pageFactory);
  52312. },
  52313. get numPages() {
  52314. var linearization = this.linearization;
  52315. var num = linearization ? linearization.numPages : this.catalog.numPages;
  52316. // shadow the prototype getter
  52317. return shadow(this, 'numPages', num);
  52318. },
  52319. get documentInfo() {
  52320. var docInfo = {
  52321. PDFFormatVersion: this.pdfFormatVersion,
  52322. IsAcroFormPresent: !!this.acroForm,
  52323. IsXFAPresent: !!this.xfa
  52324. };
  52325. var infoDict;
  52326. try {
  52327. infoDict = this.xref.trailer.get('Info');
  52328. } catch (err) {
  52329. info('The document information dictionary is invalid.');
  52330. }
  52331. if (infoDict) {
  52332. var validEntries = DocumentInfoValidators.entries;
  52333. // Only fill the document info with valid entries from the spec.
  52334. for (var key in validEntries) {
  52335. if (infoDict.has(key)) {
  52336. var value = infoDict.get(key);
  52337. // Make sure the value conforms to the spec.
  52338. if (validEntries[key](value)) {
  52339. docInfo[key] = typeof value !== 'string' ? value : stringToPDFString(value);
  52340. } else {
  52341. info('Bad value in document info for "' + key + '"');
  52342. }
  52343. }
  52344. }
  52345. }
  52346. return shadow(this, 'documentInfo', docInfo);
  52347. },
  52348. get fingerprint() {
  52349. var xref = this.xref, hash, fileID = '';
  52350. var idArray = xref.trailer.get('ID');
  52351. if (idArray && isArray(idArray) && idArray[0] && isString(idArray[0]) && idArray[0] !== EMPTY_FINGERPRINT) {
  52352. hash = stringToBytes(idArray[0]);
  52353. } else {
  52354. if (this.stream.ensureRange) {
  52355. this.stream.ensureRange(0, Math.min(FINGERPRINT_FIRST_BYTES, this.stream.end));
  52356. }
  52357. hash = calculateMD5(this.stream.bytes.subarray(0, FINGERPRINT_FIRST_BYTES), 0, FINGERPRINT_FIRST_BYTES);
  52358. }
  52359. for (var i = 0, n = hash.length; i < n; i++) {
  52360. var hex = hash[i].toString(16);
  52361. fileID += hex.length === 1 ? '0' + hex : hex;
  52362. }
  52363. return shadow(this, 'fingerprint', fileID);
  52364. },
  52365. getPage: function PDFDocument_getPage(pageIndex) {
  52366. return this.catalog.getPage(pageIndex);
  52367. },
  52368. cleanup: function PDFDocument_cleanup() {
  52369. return this.catalog.cleanup();
  52370. }
  52371. };
  52372. return PDFDocument;
  52373. }();
  52374. exports.Page = Page;
  52375. exports.PDFDocument = PDFDocument;
  52376. }));
  52377. (function (root, factory) {
  52378. factory(root.pdfjsCorePdfManager = {}, root.pdfjsSharedUtil, root.pdfjsCoreStream, root.pdfjsCoreChunkedStream, root.pdfjsCoreDocument);
  52379. }(this, function (exports, sharedUtil, coreStream, coreChunkedStream, coreDocument) {
  52380. var NotImplementedException = sharedUtil.NotImplementedException;
  52381. var MissingDataException = sharedUtil.MissingDataException;
  52382. var createPromiseCapability = sharedUtil.createPromiseCapability;
  52383. var Util = sharedUtil.Util;
  52384. var Stream = coreStream.Stream;
  52385. var ChunkedStreamManager = coreChunkedStream.ChunkedStreamManager;
  52386. var PDFDocument = coreDocument.PDFDocument;
  52387. var BasePdfManager = function BasePdfManagerClosure() {
  52388. function BasePdfManager() {
  52389. throw new Error('Cannot initialize BaseManagerManager');
  52390. }
  52391. BasePdfManager.prototype = {
  52392. get docId() {
  52393. return this._docId;
  52394. },
  52395. onLoadedStream: function BasePdfManager_onLoadedStream() {
  52396. throw new NotImplementedException();
  52397. },
  52398. ensureDoc: function BasePdfManager_ensureDoc(prop, args) {
  52399. return this.ensure(this.pdfDocument, prop, args);
  52400. },
  52401. ensureXRef: function BasePdfManager_ensureXRef(prop, args) {
  52402. return this.ensure(this.pdfDocument.xref, prop, args);
  52403. },
  52404. ensureCatalog: function BasePdfManager_ensureCatalog(prop, args) {
  52405. return this.ensure(this.pdfDocument.catalog, prop, args);
  52406. },
  52407. getPage: function BasePdfManager_getPage(pageIndex) {
  52408. return this.pdfDocument.getPage(pageIndex);
  52409. },
  52410. cleanup: function BasePdfManager_cleanup() {
  52411. return this.pdfDocument.cleanup();
  52412. },
  52413. ensure: function BasePdfManager_ensure(obj, prop, args) {
  52414. return new NotImplementedException();
  52415. },
  52416. requestRange: function BasePdfManager_requestRange(begin, end) {
  52417. return new NotImplementedException();
  52418. },
  52419. requestLoadedStream: function BasePdfManager_requestLoadedStream() {
  52420. return new NotImplementedException();
  52421. },
  52422. sendProgressiveData: function BasePdfManager_sendProgressiveData(chunk) {
  52423. return new NotImplementedException();
  52424. },
  52425. updatePassword: function BasePdfManager_updatePassword(password) {
  52426. this.pdfDocument.xref.password = this.password = password;
  52427. if (this._passwordChangedCapability) {
  52428. this._passwordChangedCapability.resolve();
  52429. }
  52430. },
  52431. passwordChanged: function BasePdfManager_passwordChanged() {
  52432. this._passwordChangedCapability = createPromiseCapability();
  52433. return this._passwordChangedCapability.promise;
  52434. },
  52435. terminate: function BasePdfManager_terminate() {
  52436. return new NotImplementedException();
  52437. }
  52438. };
  52439. return BasePdfManager;
  52440. }();
  52441. var LocalPdfManager = function LocalPdfManagerClosure() {
  52442. function LocalPdfManager(docId, data, password, evaluatorOptions) {
  52443. this._docId = docId;
  52444. this.evaluatorOptions = evaluatorOptions;
  52445. var stream = new Stream(data);
  52446. this.pdfDocument = new PDFDocument(this, stream, password);
  52447. this._loadedStreamCapability = createPromiseCapability();
  52448. this._loadedStreamCapability.resolve(stream);
  52449. }
  52450. Util.inherit(LocalPdfManager, BasePdfManager, {
  52451. ensure: function LocalPdfManager_ensure(obj, prop, args) {
  52452. return new Promise(function (resolve, reject) {
  52453. try {
  52454. var value = obj[prop];
  52455. var result;
  52456. if (typeof value === 'function') {
  52457. result = value.apply(obj, args);
  52458. } else {
  52459. result = value;
  52460. }
  52461. resolve(result);
  52462. } catch (e) {
  52463. reject(e);
  52464. }
  52465. });
  52466. },
  52467. requestRange: function LocalPdfManager_requestRange(begin, end) {
  52468. return Promise.resolve();
  52469. },
  52470. requestLoadedStream: function LocalPdfManager_requestLoadedStream() {
  52471. return;
  52472. },
  52473. onLoadedStream: function LocalPdfManager_onLoadedStream() {
  52474. return this._loadedStreamCapability.promise;
  52475. },
  52476. terminate: function LocalPdfManager_terminate() {
  52477. return;
  52478. }
  52479. });
  52480. return LocalPdfManager;
  52481. }();
  52482. var NetworkPdfManager = function NetworkPdfManagerClosure() {
  52483. function NetworkPdfManager(docId, pdfNetworkStream, args, evaluatorOptions) {
  52484. this._docId = docId;
  52485. this.msgHandler = args.msgHandler;
  52486. this.evaluatorOptions = evaluatorOptions;
  52487. var params = {
  52488. msgHandler: args.msgHandler,
  52489. url: args.url,
  52490. length: args.length,
  52491. disableAutoFetch: args.disableAutoFetch,
  52492. rangeChunkSize: args.rangeChunkSize
  52493. };
  52494. this.streamManager = new ChunkedStreamManager(pdfNetworkStream, params);
  52495. this.pdfDocument = new PDFDocument(this, this.streamManager.getStream(), args.password);
  52496. }
  52497. Util.inherit(NetworkPdfManager, BasePdfManager, {
  52498. ensure: function NetworkPdfManager_ensure(obj, prop, args) {
  52499. var pdfManager = this;
  52500. return new Promise(function (resolve, reject) {
  52501. function ensureHelper() {
  52502. try {
  52503. var result;
  52504. var value = obj[prop];
  52505. if (typeof value === 'function') {
  52506. result = value.apply(obj, args);
  52507. } else {
  52508. result = value;
  52509. }
  52510. resolve(result);
  52511. } catch (e) {
  52512. if (!(e instanceof MissingDataException)) {
  52513. reject(e);
  52514. return;
  52515. }
  52516. pdfManager.streamManager.requestRange(e.begin, e.end).then(ensureHelper, reject);
  52517. }
  52518. }
  52519. ensureHelper();
  52520. });
  52521. },
  52522. requestRange: function NetworkPdfManager_requestRange(begin, end) {
  52523. return this.streamManager.requestRange(begin, end);
  52524. },
  52525. requestLoadedStream: function NetworkPdfManager_requestLoadedStream() {
  52526. this.streamManager.requestAllChunks();
  52527. },
  52528. sendProgressiveData: function NetworkPdfManager_sendProgressiveData(chunk) {
  52529. this.streamManager.onReceiveData({ chunk: chunk });
  52530. },
  52531. onLoadedStream: function NetworkPdfManager_onLoadedStream() {
  52532. return this.streamManager.onLoadedStream();
  52533. },
  52534. terminate: function NetworkPdfManager_terminate() {
  52535. this.streamManager.abort();
  52536. }
  52537. });
  52538. return NetworkPdfManager;
  52539. }();
  52540. exports.LocalPdfManager = LocalPdfManager;
  52541. exports.NetworkPdfManager = NetworkPdfManager;
  52542. }));
  52543. (function (root, factory) {
  52544. factory(root.pdfjsCoreWorker = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCorePdfManager);
  52545. }(this, function (exports, sharedUtil, corePrimitives, corePdfManager) {
  52546. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  52547. var InvalidPDFException = sharedUtil.InvalidPDFException;
  52548. var MessageHandler = sharedUtil.MessageHandler;
  52549. var MissingPDFException = sharedUtil.MissingPDFException;
  52550. var UnexpectedResponseException = sharedUtil.UnexpectedResponseException;
  52551. var PasswordException = sharedUtil.PasswordException;
  52552. var PasswordResponses = sharedUtil.PasswordResponses;
  52553. var UnknownErrorException = sharedUtil.UnknownErrorException;
  52554. var XRefParseException = sharedUtil.XRefParseException;
  52555. var arrayByteLength = sharedUtil.arrayByteLength;
  52556. var arraysToBytes = sharedUtil.arraysToBytes;
  52557. var assert = sharedUtil.assert;
  52558. var createPromiseCapability = sharedUtil.createPromiseCapability;
  52559. var error = sharedUtil.error;
  52560. var info = sharedUtil.info;
  52561. var warn = sharedUtil.warn;
  52562. var setVerbosityLevel = sharedUtil.setVerbosityLevel;
  52563. var Ref = corePrimitives.Ref;
  52564. var LocalPdfManager = corePdfManager.LocalPdfManager;
  52565. var NetworkPdfManager = corePdfManager.NetworkPdfManager;
  52566. var globalScope = sharedUtil.globalScope;
  52567. var WorkerTask = function WorkerTaskClosure() {
  52568. function WorkerTask(name) {
  52569. this.name = name;
  52570. this.terminated = false;
  52571. this._capability = createPromiseCapability();
  52572. }
  52573. WorkerTask.prototype = {
  52574. get finished() {
  52575. return this._capability.promise;
  52576. },
  52577. finish: function () {
  52578. this._capability.resolve();
  52579. },
  52580. terminate: function () {
  52581. this.terminated = true;
  52582. },
  52583. ensureNotTerminated: function () {
  52584. if (this.terminated) {
  52585. throw new Error('Worker task was terminated');
  52586. }
  52587. }
  52588. };
  52589. return WorkerTask;
  52590. }();
  52591. /** @implements {IPDFStream} */
  52592. var PDFWorkerStream = function PDFWorkerStreamClosure() {
  52593. function PDFWorkerStream(params, msgHandler) {
  52594. this._queuedChunks = [];
  52595. var initialData = params.initialData;
  52596. if (initialData && initialData.length > 0) {
  52597. this._queuedChunks.push(initialData);
  52598. }
  52599. this._msgHandler = msgHandler;
  52600. this._isRangeSupported = !params.disableRange;
  52601. this._isStreamingSupported = !params.disableStream;
  52602. this._contentLength = params.length;
  52603. this._fullRequestReader = null;
  52604. this._rangeReaders = [];
  52605. msgHandler.on('OnDataRange', this._onReceiveData.bind(this));
  52606. msgHandler.on('OnDataProgress', this._onProgress.bind(this));
  52607. }
  52608. PDFWorkerStream.prototype = {
  52609. _onReceiveData: function PDFWorkerStream_onReceiveData(args) {
  52610. if (args.begin === undefined) {
  52611. if (this._fullRequestReader) {
  52612. this._fullRequestReader._enqueue(args.chunk);
  52613. } else {
  52614. this._queuedChunks.push(args.chunk);
  52615. }
  52616. } else {
  52617. var found = this._rangeReaders.some(function (rangeReader) {
  52618. if (rangeReader._begin !== args.begin) {
  52619. return false;
  52620. }
  52621. rangeReader._enqueue(args.chunk);
  52622. return true;
  52623. });
  52624. assert(found);
  52625. }
  52626. },
  52627. _onProgress: function PDFWorkerStream_onProgress(evt) {
  52628. if (this._rangeReaders.length > 0) {
  52629. // Reporting to first range reader.
  52630. var firstReader = this._rangeReaders[0];
  52631. if (firstReader.onProgress) {
  52632. firstReader.onProgress({ loaded: evt.loaded });
  52633. }
  52634. }
  52635. },
  52636. _removeRangeReader: function PDFWorkerStream_removeRangeReader(reader) {
  52637. var i = this._rangeReaders.indexOf(reader);
  52638. if (i >= 0) {
  52639. this._rangeReaders.splice(i, 1);
  52640. }
  52641. },
  52642. getFullReader: function PDFWorkerStream_getFullReader() {
  52643. assert(!this._fullRequestReader);
  52644. var queuedChunks = this._queuedChunks;
  52645. this._queuedChunks = null;
  52646. return new PDFWorkerStreamReader(this, queuedChunks);
  52647. },
  52648. getRangeReader: function PDFWorkerStream_getRangeReader(begin, end) {
  52649. var reader = new PDFWorkerStreamRangeReader(this, begin, end);
  52650. this._msgHandler.send('RequestDataRange', {
  52651. begin: begin,
  52652. end: end
  52653. });
  52654. this._rangeReaders.push(reader);
  52655. return reader;
  52656. },
  52657. cancelAllRequests: function PDFWorkerStream_cancelAllRequests(reason) {
  52658. if (this._fullRequestReader) {
  52659. this._fullRequestReader.cancel(reason);
  52660. }
  52661. var readers = this._rangeReaders.slice(0);
  52662. readers.forEach(function (rangeReader) {
  52663. rangeReader.cancel(reason);
  52664. });
  52665. }
  52666. };
  52667. /** @implements {IPDFStreamReader} */
  52668. function PDFWorkerStreamReader(stream, queuedChunks) {
  52669. this._stream = stream;
  52670. this._done = false;
  52671. this._queuedChunks = queuedChunks || [];
  52672. this._requests = [];
  52673. this._headersReady = Promise.resolve();
  52674. stream._fullRequestReader = this;
  52675. this.onProgress = null;
  52676. }
  52677. // not used
  52678. PDFWorkerStreamReader.prototype = {
  52679. _enqueue: function PDFWorkerStreamReader_enqueue(chunk) {
  52680. if (this._done) {
  52681. return;
  52682. }
  52683. // ignore new data
  52684. if (this._requests.length > 0) {
  52685. var requestCapability = this._requests.shift();
  52686. requestCapability.resolve({
  52687. value: chunk,
  52688. done: false
  52689. });
  52690. return;
  52691. }
  52692. this._queuedChunks.push(chunk);
  52693. },
  52694. get headersReady() {
  52695. return this._headersReady;
  52696. },
  52697. get isRangeSupported() {
  52698. return this._stream._isRangeSupported;
  52699. },
  52700. get isStreamingSupported() {
  52701. return this._stream._isStreamingSupported;
  52702. },
  52703. get contentLength() {
  52704. return this._stream._contentLength;
  52705. },
  52706. read: function PDFWorkerStreamReader_read() {
  52707. if (this._queuedChunks.length > 0) {
  52708. var chunk = this._queuedChunks.shift();
  52709. return Promise.resolve({
  52710. value: chunk,
  52711. done: false
  52712. });
  52713. }
  52714. if (this._done) {
  52715. return Promise.resolve({
  52716. value: undefined,
  52717. done: true
  52718. });
  52719. }
  52720. var requestCapability = createPromiseCapability();
  52721. this._requests.push(requestCapability);
  52722. return requestCapability.promise;
  52723. },
  52724. cancel: function PDFWorkerStreamReader_cancel(reason) {
  52725. this._done = true;
  52726. this._requests.forEach(function (requestCapability) {
  52727. requestCapability.resolve({
  52728. value: undefined,
  52729. done: true
  52730. });
  52731. });
  52732. this._requests = [];
  52733. }
  52734. };
  52735. /** @implements {IPDFStreamRangeReader} */
  52736. function PDFWorkerStreamRangeReader(stream, begin, end) {
  52737. this._stream = stream;
  52738. this._begin = begin;
  52739. this._end = end;
  52740. this._queuedChunk = null;
  52741. this._requests = [];
  52742. this._done = false;
  52743. this.onProgress = null;
  52744. }
  52745. PDFWorkerStreamRangeReader.prototype = {
  52746. _enqueue: function PDFWorkerStreamRangeReader_enqueue(chunk) {
  52747. if (this._done) {
  52748. return;
  52749. }
  52750. // ignore new data
  52751. if (this._requests.length === 0) {
  52752. this._queuedChunk = chunk;
  52753. } else {
  52754. var requestsCapability = this._requests.shift();
  52755. requestsCapability.resolve({
  52756. value: chunk,
  52757. done: false
  52758. });
  52759. this._requests.forEach(function (requestCapability) {
  52760. requestCapability.resolve({
  52761. value: undefined,
  52762. done: true
  52763. });
  52764. });
  52765. this._requests = [];
  52766. }
  52767. this._done = true;
  52768. this._stream._removeRangeReader(this);
  52769. },
  52770. get isStreamingSupported() {
  52771. return false;
  52772. },
  52773. read: function PDFWorkerStreamRangeReader_read() {
  52774. if (this._queuedChunk) {
  52775. return Promise.resolve({
  52776. value: this._queuedChunk,
  52777. done: false
  52778. });
  52779. }
  52780. if (this._done) {
  52781. return Promise.resolve({
  52782. value: undefined,
  52783. done: true
  52784. });
  52785. }
  52786. var requestCapability = createPromiseCapability();
  52787. this._requests.push(requestCapability);
  52788. return requestCapability.promise;
  52789. },
  52790. cancel: function PDFWorkerStreamRangeReader_cancel(reason) {
  52791. this._done = true;
  52792. this._requests.forEach(function (requestCapability) {
  52793. requestCapability.resolve({
  52794. value: undefined,
  52795. done: true
  52796. });
  52797. });
  52798. this._requests = [];
  52799. this._stream._removeRangeReader(this);
  52800. }
  52801. };
  52802. return PDFWorkerStream;
  52803. }();
  52804. /** @type IPDFStream */
  52805. var PDFNetworkStream;
  52806. /**
  52807. * Sets PDFNetworkStream class to be used as alternative PDF data transport.
  52808. * @param {IPDFStream} cls - the PDF data transport.
  52809. */
  52810. function setPDFNetworkStreamClass(cls) {
  52811. PDFNetworkStream = cls;
  52812. }
  52813. var WorkerMessageHandler = {
  52814. setup: function wphSetup(handler, port) {
  52815. var testMessageProcessed = false;
  52816. handler.on('test', function wphSetupTest(data) {
  52817. if (testMessageProcessed) {
  52818. return;
  52819. }
  52820. // we already processed 'test' message once
  52821. testMessageProcessed = true;
  52822. // check if Uint8Array can be sent to worker
  52823. if (!(data instanceof Uint8Array)) {
  52824. handler.send('test', 'main', false);
  52825. return;
  52826. }
  52827. // making sure postMessage transfers are working
  52828. var supportTransfers = data[0] === 255;
  52829. handler.postMessageTransfers = supportTransfers;
  52830. // check if the response property is supported by xhr
  52831. var xhr = new XMLHttpRequest();
  52832. var responseExists = 'response' in xhr;
  52833. // check if the property is actually implemented
  52834. try {
  52835. var dummy = xhr.responseType;
  52836. } catch (e) {
  52837. responseExists = false;
  52838. }
  52839. if (!responseExists) {
  52840. handler.send('test', false);
  52841. return;
  52842. }
  52843. handler.send('test', {
  52844. supportTypedArray: true,
  52845. supportTransfers: supportTransfers
  52846. });
  52847. });
  52848. handler.on('configure', function wphConfigure(data) {
  52849. setVerbosityLevel(data.verbosity);
  52850. });
  52851. handler.on('GetDocRequest', function wphSetupDoc(data) {
  52852. return WorkerMessageHandler.createDocumentHandler(data, port);
  52853. });
  52854. },
  52855. createDocumentHandler: function wphCreateDocumentHandler(docParams, port) {
  52856. // This context is actually holds references on pdfManager and handler,
  52857. // until the latter is destroyed.
  52858. var pdfManager;
  52859. var terminated = false;
  52860. var cancelXHRs = null;
  52861. var WorkerTasks = [];
  52862. var docId = docParams.docId;
  52863. var workerHandlerName = docParams.docId + '_worker';
  52864. var handler = new MessageHandler(workerHandlerName, docId, port);
  52865. // Ensure that postMessage transfers are correctly enabled/disabled,
  52866. // to prevent "DataCloneError" in older versions of IE (see issue 6957).
  52867. handler.postMessageTransfers = docParams.postMessageTransfers;
  52868. function ensureNotTerminated() {
  52869. if (terminated) {
  52870. throw new Error('Worker was terminated');
  52871. }
  52872. }
  52873. function startWorkerTask(task) {
  52874. WorkerTasks.push(task);
  52875. }
  52876. function finishWorkerTask(task) {
  52877. task.finish();
  52878. var i = WorkerTasks.indexOf(task);
  52879. WorkerTasks.splice(i, 1);
  52880. }
  52881. function loadDocument(recoveryMode) {
  52882. var loadDocumentCapability = createPromiseCapability();
  52883. var parseSuccess = function parseSuccess() {
  52884. var numPagesPromise = pdfManager.ensureDoc('numPages');
  52885. var fingerprintPromise = pdfManager.ensureDoc('fingerprint');
  52886. var encryptedPromise = pdfManager.ensureXRef('encrypt');
  52887. Promise.all([
  52888. numPagesPromise,
  52889. fingerprintPromise,
  52890. encryptedPromise
  52891. ]).then(function onDocReady(results) {
  52892. var doc = {
  52893. numPages: results[0],
  52894. fingerprint: results[1],
  52895. encrypted: !!results[2]
  52896. };
  52897. loadDocumentCapability.resolve(doc);
  52898. }, parseFailure);
  52899. };
  52900. var parseFailure = function parseFailure(e) {
  52901. loadDocumentCapability.reject(e);
  52902. };
  52903. pdfManager.ensureDoc('checkHeader', []).then(function () {
  52904. pdfManager.ensureDoc('parseStartXRef', []).then(function () {
  52905. pdfManager.ensureDoc('parse', [recoveryMode]).then(parseSuccess, parseFailure);
  52906. }, parseFailure);
  52907. }, parseFailure);
  52908. return loadDocumentCapability.promise;
  52909. }
  52910. function getPdfManager(data, evaluatorOptions) {
  52911. var pdfManagerCapability = createPromiseCapability();
  52912. var pdfManager;
  52913. var source = data.source;
  52914. if (source.data) {
  52915. try {
  52916. pdfManager = new LocalPdfManager(docId, source.data, source.password, evaluatorOptions);
  52917. pdfManagerCapability.resolve(pdfManager);
  52918. } catch (ex) {
  52919. pdfManagerCapability.reject(ex);
  52920. }
  52921. return pdfManagerCapability.promise;
  52922. }
  52923. var pdfStream;
  52924. try {
  52925. if (source.chunkedViewerLoading) {
  52926. pdfStream = new PDFWorkerStream(source, handler);
  52927. } else {
  52928. assert(PDFNetworkStream, 'pdfjs/core/network module is not loaded');
  52929. pdfStream = new PDFNetworkStream(data);
  52930. }
  52931. } catch (ex) {
  52932. pdfManagerCapability.reject(ex);
  52933. return pdfManagerCapability.promise;
  52934. }
  52935. var fullRequest = pdfStream.getFullReader();
  52936. fullRequest.headersReady.then(function () {
  52937. if (!fullRequest.isStreamingSupported || !fullRequest.isRangeSupported) {
  52938. // If stream or range are disabled, it's our only way to report
  52939. // loading progress.
  52940. fullRequest.onProgress = function (evt) {
  52941. handler.send('DocProgress', {
  52942. loaded: evt.loaded,
  52943. total: evt.total
  52944. });
  52945. };
  52946. }
  52947. if (!fullRequest.isRangeSupported) {
  52948. return;
  52949. }
  52950. // We don't need auto-fetch when streaming is enabled.
  52951. var disableAutoFetch = source.disableAutoFetch || fullRequest.isStreamingSupported;
  52952. pdfManager = new NetworkPdfManager(docId, pdfStream, {
  52953. msgHandler: handler,
  52954. url: source.url,
  52955. password: source.password,
  52956. length: fullRequest.contentLength,
  52957. disableAutoFetch: disableAutoFetch,
  52958. rangeChunkSize: source.rangeChunkSize
  52959. }, evaluatorOptions);
  52960. pdfManagerCapability.resolve(pdfManager);
  52961. cancelXHRs = null;
  52962. }).catch(function (reason) {
  52963. pdfManagerCapability.reject(reason);
  52964. cancelXHRs = null;
  52965. });
  52966. var cachedChunks = [], loaded = 0;
  52967. var flushChunks = function () {
  52968. var pdfFile = arraysToBytes(cachedChunks);
  52969. if (source.length && pdfFile.length !== source.length) {
  52970. warn('reported HTTP length is different from actual');
  52971. }
  52972. // the data is array, instantiating directly from it
  52973. try {
  52974. pdfManager = new LocalPdfManager(docId, pdfFile, source.password, evaluatorOptions);
  52975. pdfManagerCapability.resolve(pdfManager);
  52976. } catch (ex) {
  52977. pdfManagerCapability.reject(ex);
  52978. }
  52979. cachedChunks = [];
  52980. };
  52981. var readPromise = new Promise(function (resolve, reject) {
  52982. var readChunk = function (chunk) {
  52983. try {
  52984. ensureNotTerminated();
  52985. if (chunk.done) {
  52986. if (!pdfManager) {
  52987. flushChunks();
  52988. }
  52989. cancelXHRs = null;
  52990. return;
  52991. }
  52992. var data = chunk.value;
  52993. loaded += arrayByteLength(data);
  52994. if (!fullRequest.isStreamingSupported) {
  52995. handler.send('DocProgress', {
  52996. loaded: loaded,
  52997. total: Math.max(loaded, fullRequest.contentLength || 0)
  52998. });
  52999. }
  53000. if (pdfManager) {
  53001. pdfManager.sendProgressiveData(data);
  53002. } else {
  53003. cachedChunks.push(data);
  53004. }
  53005. fullRequest.read().then(readChunk, reject);
  53006. } catch (e) {
  53007. reject(e);
  53008. }
  53009. };
  53010. fullRequest.read().then(readChunk, reject);
  53011. });
  53012. readPromise.catch(function (e) {
  53013. pdfManagerCapability.reject(e);
  53014. cancelXHRs = null;
  53015. });
  53016. cancelXHRs = function () {
  53017. pdfStream.cancelAllRequests('abort');
  53018. };
  53019. return pdfManagerCapability.promise;
  53020. }
  53021. var setupDoc = function (data) {
  53022. var onSuccess = function (doc) {
  53023. ensureNotTerminated();
  53024. handler.send('GetDoc', { pdfInfo: doc });
  53025. };
  53026. var onFailure = function (e) {
  53027. if (e instanceof PasswordException) {
  53028. if (e.code === PasswordResponses.NEED_PASSWORD) {
  53029. handler.send('NeedPassword', e);
  53030. } else if (e.code === PasswordResponses.INCORRECT_PASSWORD) {
  53031. handler.send('IncorrectPassword', e);
  53032. }
  53033. } else if (e instanceof InvalidPDFException) {
  53034. handler.send('InvalidPDF', e);
  53035. } else if (e instanceof MissingPDFException) {
  53036. handler.send('MissingPDF', e);
  53037. } else if (e instanceof UnexpectedResponseException) {
  53038. handler.send('UnexpectedResponse', e);
  53039. } else {
  53040. handler.send('UnknownError', new UnknownErrorException(e.message, e.toString()));
  53041. }
  53042. };
  53043. ensureNotTerminated();
  53044. var cMapOptions = {
  53045. url: data.cMapUrl === undefined ? null : data.cMapUrl,
  53046. packed: data.cMapPacked === true
  53047. };
  53048. var evaluatorOptions = {
  53049. forceDataSchema: data.disableCreateObjectURL,
  53050. maxImageSize: data.maxImageSize === undefined ? -1 : data.maxImageSize,
  53051. disableFontFace: data.disableFontFace,
  53052. cMapOptions: cMapOptions
  53053. };
  53054. getPdfManager(data, evaluatorOptions).then(function (newPdfManager) {
  53055. if (terminated) {
  53056. // We were in a process of setting up the manager, but it got
  53057. // terminated in the middle.
  53058. newPdfManager.terminate();
  53059. throw new Error('Worker was terminated');
  53060. }
  53061. pdfManager = newPdfManager;
  53062. handler.send('PDFManagerReady', null);
  53063. pdfManager.onLoadedStream().then(function (stream) {
  53064. handler.send('DataLoaded', { length: stream.bytes.byteLength });
  53065. });
  53066. }).then(function pdfManagerReady() {
  53067. ensureNotTerminated();
  53068. loadDocument(false).then(onSuccess, function loadFailure(ex) {
  53069. ensureNotTerminated();
  53070. // Try again with recoveryMode == true
  53071. if (!(ex instanceof XRefParseException)) {
  53072. if (ex instanceof PasswordException) {
  53073. // after password exception prepare to receive a new password
  53074. // to repeat loading
  53075. pdfManager.passwordChanged().then(pdfManagerReady);
  53076. }
  53077. onFailure(ex);
  53078. return;
  53079. }
  53080. pdfManager.requestLoadedStream();
  53081. pdfManager.onLoadedStream().then(function () {
  53082. ensureNotTerminated();
  53083. loadDocument(true).then(onSuccess, onFailure);
  53084. });
  53085. }, onFailure);
  53086. }, onFailure);
  53087. };
  53088. handler.on('GetPage', function wphSetupGetPage(data) {
  53089. return pdfManager.getPage(data.pageIndex).then(function (page) {
  53090. var rotatePromise = pdfManager.ensure(page, 'rotate');
  53091. var refPromise = pdfManager.ensure(page, 'ref');
  53092. var viewPromise = pdfManager.ensure(page, 'view');
  53093. return Promise.all([
  53094. rotatePromise,
  53095. refPromise,
  53096. viewPromise
  53097. ]).then(function (results) {
  53098. return {
  53099. rotate: results[0],
  53100. ref: results[1],
  53101. view: results[2]
  53102. };
  53103. });
  53104. });
  53105. });
  53106. handler.on('GetPageIndex', function wphSetupGetPageIndex(data) {
  53107. var ref = new Ref(data.ref.num, data.ref.gen);
  53108. var catalog = pdfManager.pdfDocument.catalog;
  53109. return catalog.getPageIndex(ref);
  53110. });
  53111. handler.on('GetDestinations', function wphSetupGetDestinations(data) {
  53112. return pdfManager.ensureCatalog('destinations');
  53113. });
  53114. handler.on('GetDestination', function wphSetupGetDestination(data) {
  53115. return pdfManager.ensureCatalog('getDestination', [data.id]);
  53116. });
  53117. handler.on('GetPageLabels', function wphSetupGetPageLabels(data) {
  53118. return pdfManager.ensureCatalog('pageLabels');
  53119. });
  53120. handler.on('GetAttachments', function wphSetupGetAttachments(data) {
  53121. return pdfManager.ensureCatalog('attachments');
  53122. });
  53123. handler.on('GetJavaScript', function wphSetupGetJavaScript(data) {
  53124. return pdfManager.ensureCatalog('javaScript');
  53125. });
  53126. handler.on('GetOutline', function wphSetupGetOutline(data) {
  53127. return pdfManager.ensureCatalog('documentOutline');
  53128. });
  53129. handler.on('GetMetadata', function wphSetupGetMetadata(data) {
  53130. return Promise.all([
  53131. pdfManager.ensureDoc('documentInfo'),
  53132. pdfManager.ensureCatalog('metadata')
  53133. ]);
  53134. });
  53135. handler.on('GetData', function wphSetupGetData(data) {
  53136. pdfManager.requestLoadedStream();
  53137. return pdfManager.onLoadedStream().then(function (stream) {
  53138. return stream.bytes;
  53139. });
  53140. });
  53141. handler.on('GetStats', function wphSetupGetStats(data) {
  53142. return pdfManager.pdfDocument.xref.stats;
  53143. });
  53144. handler.on('UpdatePassword', function wphSetupUpdatePassword(data) {
  53145. pdfManager.updatePassword(data);
  53146. });
  53147. handler.on('GetAnnotations', function wphSetupGetAnnotations(data) {
  53148. return pdfManager.getPage(data.pageIndex).then(function (page) {
  53149. return pdfManager.ensure(page, 'getAnnotationsData', [data.intent]);
  53150. });
  53151. });
  53152. handler.on('RenderPageRequest', function wphSetupRenderPage(data) {
  53153. var pageIndex = data.pageIndex;
  53154. pdfManager.getPage(pageIndex).then(function (page) {
  53155. var task = new WorkerTask('RenderPageRequest: page ' + pageIndex);
  53156. startWorkerTask(task);
  53157. var pageNum = pageIndex + 1;
  53158. var start = Date.now();
  53159. // Pre compile the pdf page and fetch the fonts/images.
  53160. page.getOperatorList(handler, task, data.intent, data.renderInteractiveForms).then(function (operatorList) {
  53161. finishWorkerTask(task);
  53162. info('page=' + pageNum + ' - getOperatorList: time=' + (Date.now() - start) + 'ms, len=' + operatorList.totalLength);
  53163. }, function (e) {
  53164. finishWorkerTask(task);
  53165. if (task.terminated) {
  53166. return;
  53167. }
  53168. // ignoring errors from the terminated thread
  53169. // For compatibility with older behavior, generating unknown
  53170. // unsupported feature notification on errors.
  53171. handler.send('UnsupportedFeature', { featureId: UNSUPPORTED_FEATURES.unknown });
  53172. var minimumStackMessage = 'worker.js: while trying to getPage() and getOperatorList()';
  53173. var wrappedException;
  53174. // Turn the error into an obj that can be serialized
  53175. if (typeof e === 'string') {
  53176. wrappedException = {
  53177. message: e,
  53178. stack: minimumStackMessage
  53179. };
  53180. } else if (typeof e === 'object') {
  53181. wrappedException = {
  53182. message: e.message || e.toString(),
  53183. stack: e.stack || minimumStackMessage
  53184. };
  53185. } else {
  53186. wrappedException = {
  53187. message: 'Unknown exception type: ' + typeof e,
  53188. stack: minimumStackMessage
  53189. };
  53190. }
  53191. handler.send('PageError', {
  53192. pageNum: pageNum,
  53193. error: wrappedException,
  53194. intent: data.intent
  53195. });
  53196. });
  53197. });
  53198. }, this);
  53199. handler.on('GetTextContent', function wphExtractText(data) {
  53200. var pageIndex = data.pageIndex;
  53201. var normalizeWhitespace = data.normalizeWhitespace;
  53202. var combineTextItems = data.combineTextItems;
  53203. return pdfManager.getPage(pageIndex).then(function (page) {
  53204. var task = new WorkerTask('GetTextContent: page ' + pageIndex);
  53205. startWorkerTask(task);
  53206. var pageNum = pageIndex + 1;
  53207. var start = Date.now();
  53208. return page.extractTextContent(task, normalizeWhitespace, combineTextItems).then(function (textContent) {
  53209. finishWorkerTask(task);
  53210. info('text indexing: page=' + pageNum + ' - time=' + (Date.now() - start) + 'ms');
  53211. return textContent;
  53212. }, function (reason) {
  53213. finishWorkerTask(task);
  53214. if (task.terminated) {
  53215. return;
  53216. }
  53217. // ignoring errors from the terminated thread
  53218. throw reason;
  53219. });
  53220. });
  53221. });
  53222. handler.on('Cleanup', function wphCleanup(data) {
  53223. return pdfManager.cleanup();
  53224. });
  53225. handler.on('Terminate', function wphTerminate(data) {
  53226. terminated = true;
  53227. if (pdfManager) {
  53228. pdfManager.terminate();
  53229. pdfManager = null;
  53230. }
  53231. if (cancelXHRs) {
  53232. cancelXHRs();
  53233. }
  53234. var waitOn = [];
  53235. WorkerTasks.forEach(function (task) {
  53236. waitOn.push(task.finished);
  53237. task.terminate();
  53238. });
  53239. return Promise.all(waitOn).then(function () {
  53240. // Notice that even if we destroying handler, resolved response promise
  53241. // must be sent back.
  53242. handler.destroy();
  53243. handler = null;
  53244. });
  53245. });
  53246. handler.on('Ready', function wphReady(data) {
  53247. setupDoc(docParams);
  53248. docParams = null;
  53249. });
  53250. // we don't need docParams anymore -- saving memory.
  53251. return workerHandlerName;
  53252. }
  53253. };
  53254. function initializeWorker() {
  53255. if (!('console' in globalScope)) {
  53256. var consoleTimer = {};
  53257. var workerConsole = {
  53258. log: function log() {
  53259. var args = Array.prototype.slice.call(arguments);
  53260. globalScope.postMessage({
  53261. targetName: 'main',
  53262. action: 'console_log',
  53263. data: args
  53264. });
  53265. },
  53266. error: function error() {
  53267. var args = Array.prototype.slice.call(arguments);
  53268. globalScope.postMessage({
  53269. targetName: 'main',
  53270. action: 'console_error',
  53271. data: args
  53272. });
  53273. throw 'pdf.js execution error';
  53274. },
  53275. time: function time(name) {
  53276. consoleTimer[name] = Date.now();
  53277. },
  53278. timeEnd: function timeEnd(name) {
  53279. var time = consoleTimer[name];
  53280. if (!time) {
  53281. error('Unknown timer name ' + name);
  53282. }
  53283. this.log('Timer:', name, Date.now() - time);
  53284. }
  53285. };
  53286. globalScope.console = workerConsole;
  53287. }
  53288. var handler = new MessageHandler('worker', 'main', self);
  53289. WorkerMessageHandler.setup(handler, self);
  53290. handler.send('ready', null);
  53291. }
  53292. // Worker thread (and not node.js)?
  53293. if (typeof window === 'undefined' && !(typeof module !== 'undefined' && module.require)) {
  53294. initializeWorker();
  53295. }
  53296. exports.setPDFNetworkStreamClass = setPDFNetworkStreamClass;
  53297. exports.WorkerTask = WorkerTask;
  53298. exports.WorkerMessageHandler = WorkerMessageHandler;
  53299. }));
  53300. (function (root, factory) {
  53301. factory(root.pdfjsCoreNetwork = {}, root.pdfjsSharedUtil, root.pdfjsCoreWorker);
  53302. }(this, function (exports, sharedUtil, coreWorker) {
  53303. var OK_RESPONSE = 200;
  53304. var PARTIAL_CONTENT_RESPONSE = 206;
  53305. function NetworkManager(url, args) {
  53306. this.url = url;
  53307. args = args || {};
  53308. this.isHttp = /^https?:/i.test(url);
  53309. this.httpHeaders = this.isHttp && args.httpHeaders || {};
  53310. this.withCredentials = args.withCredentials || false;
  53311. this.getXhr = args.getXhr || function NetworkManager_getXhr() {
  53312. return new XMLHttpRequest();
  53313. };
  53314. this.currXhrId = 0;
  53315. this.pendingRequests = Object.create(null);
  53316. this.loadedRequests = Object.create(null);
  53317. }
  53318. function getArrayBuffer(xhr) {
  53319. var data = xhr.response;
  53320. if (typeof data !== 'string') {
  53321. return data;
  53322. }
  53323. var length = data.length;
  53324. var array = new Uint8Array(length);
  53325. for (var i = 0; i < length; i++) {
  53326. array[i] = data.charCodeAt(i) & 0xFF;
  53327. }
  53328. return array.buffer;
  53329. }
  53330. var supportsMozChunked = function supportsMozChunkedClosure() {
  53331. try {
  53332. var x = new XMLHttpRequest();
  53333. // Firefox 37- required .open() to be called before setting responseType.
  53334. // https://bugzilla.mozilla.org/show_bug.cgi?id=707484
  53335. // Even though the URL is not visited, .open() could fail if the URL is
  53336. // blocked, e.g. via the connect-src CSP directive or the NoScript addon.
  53337. // When this error occurs, this feature detection method will mistakenly
  53338. // report that moz-chunked-arraybuffer is not supported in Firefox 37-.
  53339. x.open('GET', 'https://example.com');
  53340. x.responseType = 'moz-chunked-arraybuffer';
  53341. return x.responseType === 'moz-chunked-arraybuffer';
  53342. } catch (e) {
  53343. return false;
  53344. }
  53345. }();
  53346. NetworkManager.prototype = {
  53347. requestRange: function NetworkManager_requestRange(begin, end, listeners) {
  53348. var args = {
  53349. begin: begin,
  53350. end: end
  53351. };
  53352. for (var prop in listeners) {
  53353. args[prop] = listeners[prop];
  53354. }
  53355. return this.request(args);
  53356. },
  53357. requestFull: function NetworkManager_requestFull(listeners) {
  53358. return this.request(listeners);
  53359. },
  53360. request: function NetworkManager_request(args) {
  53361. var xhr = this.getXhr();
  53362. var xhrId = this.currXhrId++;
  53363. var pendingRequest = this.pendingRequests[xhrId] = { xhr: xhr };
  53364. xhr.open('GET', this.url);
  53365. xhr.withCredentials = this.withCredentials;
  53366. for (var property in this.httpHeaders) {
  53367. var value = this.httpHeaders[property];
  53368. if (typeof value === 'undefined') {
  53369. continue;
  53370. }
  53371. xhr.setRequestHeader(property, value);
  53372. }
  53373. if (this.isHttp && 'begin' in args && 'end' in args) {
  53374. var rangeStr = args.begin + '-' + (args.end - 1);
  53375. xhr.setRequestHeader('Range', 'bytes=' + rangeStr);
  53376. pendingRequest.expectedStatus = 206;
  53377. } else {
  53378. pendingRequest.expectedStatus = 200;
  53379. }
  53380. var useMozChunkedLoading = supportsMozChunked && !!args.onProgressiveData;
  53381. if (useMozChunkedLoading) {
  53382. xhr.responseType = 'moz-chunked-arraybuffer';
  53383. pendingRequest.onProgressiveData = args.onProgressiveData;
  53384. pendingRequest.mozChunked = true;
  53385. } else {
  53386. xhr.responseType = 'arraybuffer';
  53387. }
  53388. if (args.onError) {
  53389. xhr.onerror = function (evt) {
  53390. args.onError(xhr.status);
  53391. };
  53392. }
  53393. xhr.onreadystatechange = this.onStateChange.bind(this, xhrId);
  53394. xhr.onprogress = this.onProgress.bind(this, xhrId);
  53395. pendingRequest.onHeadersReceived = args.onHeadersReceived;
  53396. pendingRequest.onDone = args.onDone;
  53397. pendingRequest.onError = args.onError;
  53398. pendingRequest.onProgress = args.onProgress;
  53399. xhr.send(null);
  53400. return xhrId;
  53401. },
  53402. onProgress: function NetworkManager_onProgress(xhrId, evt) {
  53403. var pendingRequest = this.pendingRequests[xhrId];
  53404. if (!pendingRequest) {
  53405. // Maybe abortRequest was called...
  53406. return;
  53407. }
  53408. if (pendingRequest.mozChunked) {
  53409. var chunk = getArrayBuffer(pendingRequest.xhr);
  53410. pendingRequest.onProgressiveData(chunk);
  53411. }
  53412. var onProgress = pendingRequest.onProgress;
  53413. if (onProgress) {
  53414. onProgress(evt);
  53415. }
  53416. },
  53417. onStateChange: function NetworkManager_onStateChange(xhrId, evt) {
  53418. var pendingRequest = this.pendingRequests[xhrId];
  53419. if (!pendingRequest) {
  53420. // Maybe abortRequest was called...
  53421. return;
  53422. }
  53423. var xhr = pendingRequest.xhr;
  53424. if (xhr.readyState >= 2 && pendingRequest.onHeadersReceived) {
  53425. pendingRequest.onHeadersReceived();
  53426. delete pendingRequest.onHeadersReceived;
  53427. }
  53428. if (xhr.readyState !== 4) {
  53429. return;
  53430. }
  53431. if (!(xhrId in this.pendingRequests)) {
  53432. // The XHR request might have been aborted in onHeadersReceived()
  53433. // callback, in which case we should abort request
  53434. return;
  53435. }
  53436. delete this.pendingRequests[xhrId];
  53437. // success status == 0 can be on ftp, file and other protocols
  53438. if (xhr.status === 0 && this.isHttp) {
  53439. if (pendingRequest.onError) {
  53440. pendingRequest.onError(xhr.status);
  53441. }
  53442. return;
  53443. }
  53444. var xhrStatus = xhr.status || OK_RESPONSE;
  53445. // From http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.2:
  53446. // "A server MAY ignore the Range header". This means it's possible to
  53447. // get a 200 rather than a 206 response from a range request.
  53448. var ok_response_on_range_request = xhrStatus === OK_RESPONSE && pendingRequest.expectedStatus === PARTIAL_CONTENT_RESPONSE;
  53449. if (!ok_response_on_range_request && xhrStatus !== pendingRequest.expectedStatus) {
  53450. if (pendingRequest.onError) {
  53451. pendingRequest.onError(xhr.status);
  53452. }
  53453. return;
  53454. }
  53455. this.loadedRequests[xhrId] = true;
  53456. var chunk = getArrayBuffer(xhr);
  53457. if (xhrStatus === PARTIAL_CONTENT_RESPONSE) {
  53458. var rangeHeader = xhr.getResponseHeader('Content-Range');
  53459. var matches = /bytes (\d+)-(\d+)\/(\d+)/.exec(rangeHeader);
  53460. var begin = parseInt(matches[1], 10);
  53461. pendingRequest.onDone({
  53462. begin: begin,
  53463. chunk: chunk
  53464. });
  53465. } else if (pendingRequest.onProgressiveData) {
  53466. pendingRequest.onDone(null);
  53467. } else if (chunk) {
  53468. pendingRequest.onDone({
  53469. begin: 0,
  53470. chunk: chunk
  53471. });
  53472. } else if (pendingRequest.onError) {
  53473. pendingRequest.onError(xhr.status);
  53474. }
  53475. },
  53476. hasPendingRequests: function NetworkManager_hasPendingRequests() {
  53477. for (var xhrId in this.pendingRequests) {
  53478. return true;
  53479. }
  53480. return false;
  53481. },
  53482. getRequestXhr: function NetworkManager_getXhr(xhrId) {
  53483. return this.pendingRequests[xhrId].xhr;
  53484. },
  53485. isStreamingRequest: function NetworkManager_isStreamingRequest(xhrId) {
  53486. return !!this.pendingRequests[xhrId].onProgressiveData;
  53487. },
  53488. isPendingRequest: function NetworkManager_isPendingRequest(xhrId) {
  53489. return xhrId in this.pendingRequests;
  53490. },
  53491. isLoadedRequest: function NetworkManager_isLoadedRequest(xhrId) {
  53492. return xhrId in this.loadedRequests;
  53493. },
  53494. abortAllRequests: function NetworkManager_abortAllRequests() {
  53495. for (var xhrId in this.pendingRequests) {
  53496. this.abortRequest(xhrId | 0);
  53497. }
  53498. },
  53499. abortRequest: function NetworkManager_abortRequest(xhrId) {
  53500. var xhr = this.pendingRequests[xhrId].xhr;
  53501. delete this.pendingRequests[xhrId];
  53502. xhr.abort();
  53503. }
  53504. };
  53505. var assert = sharedUtil.assert;
  53506. var createPromiseCapability = sharedUtil.createPromiseCapability;
  53507. var isInt = sharedUtil.isInt;
  53508. var MissingPDFException = sharedUtil.MissingPDFException;
  53509. var UnexpectedResponseException = sharedUtil.UnexpectedResponseException;
  53510. /** @implements {IPDFStream} */
  53511. function PDFNetworkStream(options) {
  53512. this._options = options;
  53513. var source = options.source;
  53514. this._manager = new NetworkManager(source.url, {
  53515. httpHeaders: source.httpHeaders,
  53516. withCredentials: source.withCredentials
  53517. });
  53518. this._rangeChunkSize = source.rangeChunkSize;
  53519. this._fullRequestReader = null;
  53520. this._rangeRequestReaders = [];
  53521. }
  53522. PDFNetworkStream.prototype = {
  53523. _onRangeRequestReaderClosed: function PDFNetworkStream_onRangeRequestReaderClosed(reader) {
  53524. var i = this._rangeRequestReaders.indexOf(reader);
  53525. if (i >= 0) {
  53526. this._rangeRequestReaders.splice(i, 1);
  53527. }
  53528. },
  53529. getFullReader: function PDFNetworkStream_getFullReader() {
  53530. assert(!this._fullRequestReader);
  53531. this._fullRequestReader = new PDFNetworkStreamFullRequestReader(this._manager, this._options);
  53532. return this._fullRequestReader;
  53533. },
  53534. getRangeReader: function PDFNetworkStream_getRangeReader(begin, end) {
  53535. var reader = new PDFNetworkStreamRangeRequestReader(this._manager, begin, end);
  53536. reader.onClosed = this._onRangeRequestReaderClosed.bind(this);
  53537. this._rangeRequestReaders.push(reader);
  53538. return reader;
  53539. },
  53540. cancelAllRequests: function PDFNetworkStream_cancelAllRequests(reason) {
  53541. if (this._fullRequestReader) {
  53542. this._fullRequestReader.cancel(reason);
  53543. }
  53544. var readers = this._rangeRequestReaders.slice(0);
  53545. readers.forEach(function (reader) {
  53546. reader.cancel(reason);
  53547. });
  53548. }
  53549. };
  53550. /** @implements {IPDFStreamReader} */
  53551. function PDFNetworkStreamFullRequestReader(manager, options) {
  53552. this._manager = manager;
  53553. var source = options.source;
  53554. var args = {
  53555. onHeadersReceived: this._onHeadersReceived.bind(this),
  53556. onProgressiveData: source.disableStream ? null : this._onProgressiveData.bind(this),
  53557. onDone: this._onDone.bind(this),
  53558. onError: this._onError.bind(this),
  53559. onProgress: this._onProgress.bind(this)
  53560. };
  53561. this._url = source.url;
  53562. this._fullRequestId = manager.requestFull(args);
  53563. this._headersReceivedCapability = createPromiseCapability();
  53564. this._disableRange = options.disableRange || false;
  53565. this._contentLength = source.length;
  53566. // optional
  53567. this._rangeChunkSize = source.rangeChunkSize;
  53568. if (!this._rangeChunkSize && !this._disableRange) {
  53569. this._disableRange = true;
  53570. }
  53571. this._isStreamingSupported = false;
  53572. this._isRangeSupported = false;
  53573. this._cachedChunks = [];
  53574. this._requests = [];
  53575. this._done = false;
  53576. this._storedError = undefined;
  53577. this.onProgress = null;
  53578. }
  53579. PDFNetworkStreamFullRequestReader.prototype = {
  53580. _validateRangeRequestCapabilities: function PDFNetworkStreamFullRequestReader_validateRangeRequestCapabilities() {
  53581. if (this._disableRange) {
  53582. return false;
  53583. }
  53584. var networkManager = this._manager;
  53585. var fullRequestXhrId = this._fullRequestId;
  53586. var fullRequestXhr = networkManager.getRequestXhr(fullRequestXhrId);
  53587. if (fullRequestXhr.getResponseHeader('Accept-Ranges') !== 'bytes') {
  53588. return false;
  53589. }
  53590. var contentEncoding = fullRequestXhr.getResponseHeader('Content-Encoding') || 'identity';
  53591. if (contentEncoding !== 'identity') {
  53592. return false;
  53593. }
  53594. var length = fullRequestXhr.getResponseHeader('Content-Length');
  53595. length = parseInt(length, 10);
  53596. if (!isInt(length)) {
  53597. return false;
  53598. }
  53599. this._contentLength = length;
  53600. // setting right content length
  53601. if (length <= 2 * this._rangeChunkSize) {
  53602. // The file size is smaller than the size of two chunks, so it does
  53603. // not make any sense to abort the request and retry with a range
  53604. // request.
  53605. return false;
  53606. }
  53607. return true;
  53608. },
  53609. _onHeadersReceived: function PDFNetworkStreamFullRequestReader_onHeadersReceived() {
  53610. if (this._validateRangeRequestCapabilities()) {
  53611. this._isRangeSupported = true;
  53612. }
  53613. var networkManager = this._manager;
  53614. var fullRequestXhrId = this._fullRequestId;
  53615. if (networkManager.isStreamingRequest(fullRequestXhrId)) {
  53616. // We can continue fetching when progressive loading is enabled,
  53617. // and we don't need the autoFetch feature.
  53618. this._isStreamingSupported = true;
  53619. } else if (this._isRangeSupported) {
  53620. // NOTE: by cancelling the full request, and then issuing range
  53621. // requests, there will be an issue for sites where you can only
  53622. // request the pdf once. However, if this is the case, then the
  53623. // server should not be returning that it can support range
  53624. // requests.
  53625. networkManager.abortRequest(fullRequestXhrId);
  53626. }
  53627. this._headersReceivedCapability.resolve();
  53628. },
  53629. _onProgressiveData: function PDFNetworkStreamFullRequestReader_onProgressiveData(chunk) {
  53630. if (this._requests.length > 0) {
  53631. var requestCapability = this._requests.shift();
  53632. requestCapability.resolve({
  53633. value: chunk,
  53634. done: false
  53635. });
  53636. } else {
  53637. this._cachedChunks.push(chunk);
  53638. }
  53639. },
  53640. _onDone: function PDFNetworkStreamFullRequestReader_onDone(args) {
  53641. if (args) {
  53642. this._onProgressiveData(args.chunk);
  53643. }
  53644. this._done = true;
  53645. if (this._cachedChunks.length > 0) {
  53646. return;
  53647. }
  53648. this._requests.forEach(function (requestCapability) {
  53649. requestCapability.resolve({
  53650. value: undefined,
  53651. done: true
  53652. });
  53653. });
  53654. this._requests = [];
  53655. },
  53656. _onError: function PDFNetworkStreamFullRequestReader_onError(status) {
  53657. var url = this._url;
  53658. var exception;
  53659. if (status === 404 || status === 0 && /^file:/.test(url)) {
  53660. exception = new MissingPDFException('Missing PDF "' + url + '".');
  53661. } else {
  53662. exception = new UnexpectedResponseException('Unexpected server response (' + status + ') while retrieving PDF "' + url + '".', status);
  53663. }
  53664. this._storedError = exception;
  53665. this._headersReceivedCapability.reject(exception);
  53666. this._requests.forEach(function (requestCapability) {
  53667. requestCapability.reject(exception);
  53668. });
  53669. this._requests = [];
  53670. this._cachedChunks = [];
  53671. },
  53672. _onProgress: function PDFNetworkStreamFullRequestReader_onProgress(data) {
  53673. if (this.onProgress) {
  53674. this.onProgress({
  53675. loaded: data.loaded,
  53676. total: data.lengthComputable ? data.total : this._contentLength
  53677. });
  53678. }
  53679. },
  53680. get isRangeSupported() {
  53681. return this._isRangeSupported;
  53682. },
  53683. get isStreamingSupported() {
  53684. return this._isStreamingSupported;
  53685. },
  53686. get contentLength() {
  53687. return this._contentLength;
  53688. },
  53689. get headersReady() {
  53690. return this._headersReceivedCapability.promise;
  53691. },
  53692. read: function PDFNetworkStreamFullRequestReader_read() {
  53693. if (this._storedError) {
  53694. return Promise.reject(this._storedError);
  53695. }
  53696. if (this._cachedChunks.length > 0) {
  53697. var chunk = this._cachedChunks.shift();
  53698. return Promise.resolve(chunk);
  53699. }
  53700. if (this._done) {
  53701. return Promise.resolve({
  53702. value: undefined,
  53703. done: true
  53704. });
  53705. }
  53706. var requestCapability = createPromiseCapability();
  53707. this._requests.push(requestCapability);
  53708. return requestCapability.promise;
  53709. },
  53710. cancel: function PDFNetworkStreamFullRequestReader_cancel(reason) {
  53711. this._done = true;
  53712. this._headersReceivedCapability.reject(reason);
  53713. this._requests.forEach(function (requestCapability) {
  53714. requestCapability.resolve({
  53715. value: undefined,
  53716. done: true
  53717. });
  53718. });
  53719. this._requests = [];
  53720. if (this._manager.isPendingRequest(this._fullRequestId)) {
  53721. this._manager.abortRequest(this._fullRequestId);
  53722. }
  53723. this._fullRequestReader = null;
  53724. }
  53725. };
  53726. /** @implements {IPDFStreamRangeReader} */
  53727. function PDFNetworkStreamRangeRequestReader(manager, begin, end) {
  53728. this._manager = manager;
  53729. var args = {
  53730. onDone: this._onDone.bind(this),
  53731. onProgress: this._onProgress.bind(this)
  53732. };
  53733. this._requestId = manager.requestRange(begin, end, args);
  53734. this._requests = [];
  53735. this._queuedChunk = null;
  53736. this._done = false;
  53737. this.onProgress = null;
  53738. this.onClosed = null;
  53739. }
  53740. PDFNetworkStreamRangeRequestReader.prototype = {
  53741. _close: function PDFNetworkStreamRangeRequestReader_close() {
  53742. if (this.onClosed) {
  53743. this.onClosed(this);
  53744. }
  53745. },
  53746. _onDone: function PDFNetworkStreamRangeRequestReader_onDone(data) {
  53747. var chunk = data.chunk;
  53748. if (this._requests.length > 0) {
  53749. var requestCapability = this._requests.shift();
  53750. requestCapability.resolve({
  53751. value: chunk,
  53752. done: false
  53753. });
  53754. } else {
  53755. this._queuedChunk = chunk;
  53756. }
  53757. this._done = true;
  53758. this._requests.forEach(function (requestCapability) {
  53759. requestCapability.resolve({
  53760. value: undefined,
  53761. done: true
  53762. });
  53763. });
  53764. this._requests = [];
  53765. this._close();
  53766. },
  53767. _onProgress: function PDFNetworkStreamRangeRequestReader_onProgress(evt) {
  53768. if (!this.isStreamingSupported && this.onProgress) {
  53769. this.onProgress({ loaded: evt.loaded });
  53770. }
  53771. },
  53772. get isStreamingSupported() {
  53773. return false;
  53774. },
  53775. // TODO allow progressive range bytes loading
  53776. read: function PDFNetworkStreamRangeRequestReader_read() {
  53777. if (this._queuedChunk !== null) {
  53778. var chunk = this._queuedChunk;
  53779. this._queuedChunk = null;
  53780. return Promise.resolve({
  53781. value: chunk,
  53782. done: false
  53783. });
  53784. }
  53785. if (this._done) {
  53786. return Promise.resolve({
  53787. value: undefined,
  53788. done: true
  53789. });
  53790. }
  53791. var requestCapability = createPromiseCapability();
  53792. this._requests.push(requestCapability);
  53793. return requestCapability.promise;
  53794. },
  53795. cancel: function PDFNetworkStreamRangeRequestReader_cancel(reason) {
  53796. this._done = true;
  53797. this._requests.forEach(function (requestCapability) {
  53798. requestCapability.resolve({
  53799. value: undefined,
  53800. done: true
  53801. });
  53802. });
  53803. this._requests = [];
  53804. if (this._manager.isPendingRequest(this._requestId)) {
  53805. this._manager.abortRequest(this._requestId);
  53806. }
  53807. this._close();
  53808. }
  53809. };
  53810. coreWorker.setPDFNetworkStreamClass(PDFNetworkStream);
  53811. exports.PDFNetworkStream = PDFNetworkStream;
  53812. exports.NetworkManager = NetworkManager;
  53813. }));
  53814. }.call(pdfjsLibs));
  53815. exports.WorkerMessageHandler = pdfjsLibs.pdfjsCoreWorker.WorkerMessageHandler;
  53816. }));