pdf.worker.js 1.7 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843368443684536846368473684836849368503685136852368533685436855368563685736858368593686036861368623686336864368653686636867368683686936870368713687236873368743687536876368773687836879368803688136882368833688436885368863688736888368893689036891368923689336894368953689636897368983689936900369013690236903369043690536906369073690836909369103691136912369133691436915369163691736918369193692036921369223692336924369253692636927369283692936930369313693236933369343693536936369373693836939369403694136942369433694436945369463694736948369493695036951369523695336954369553695636957369583695936960369613696236963369643696536966369673696836969369703697136972369733697436975369763697736978369793698036981369823698336984369853698636987369883698936990369913699236993369943699536996369973699836999370003700137002370033700437005370063700737008370093701037011370123701337014370153701637017370183701937020370213702237023370243702537026370273702837029370303703137032370333703437035370363703737038370393704037041370423704337044370453704637047370483704937050370513705237053370543705537056370573705837059370603706137062370633706437065370663706737068370693707037071370723707337074370753707637077370783707937080370813708237083370843708537086370873708837089370903709137092370933709437095370963709737098370993710037101371023710337104371053710637107371083710937110371113711237113371143711537116371173711837119371203712137122371233712437125371263712737128371293713037131371323713337134371353713637137371383713937140371413714237143371443714537146371473714837149371503715137152371533715437155371563715737158371593716037161371623716337164371653716637167371683716937170371713717237173371743717537176371773717837179371803718137182371833718437185371863718737188371893719037191371923719337194371953719637197371983719937200372013720237203372043720537206372073720837209372103721137212372133721437215372163721737218372193722037221372223722337224372253722637227372283722937230372313723237233372343723537236372373723837239372403724137242372433724437245372463724737248372493725037251372523725337254372553725637257372583725937260372613726237263372643726537266372673726837269372703727137272372733727437275372763727737278372793728037281372823728337284372853728637287372883728937290372913729237293372943729537296372973729837299373003730137302373033730437305373063730737308373093731037311373123731337314373153731637317373183731937320373213732237323373243732537326373273732837329373303733137332373333733437335373363733737338373393734037341373423734337344373453734637347373483734937350373513735237353373543735537356373573735837359373603736137362373633736437365373663736737368373693737037371373723737337374373753737637377373783737937380373813738237383373843738537386373873738837389373903739137392373933739437395373963739737398373993740037401374023740337404374053740637407374083740937410374113741237413374143741537416374173741837419374203742137422374233742437425374263742737428374293743037431374323743337434374353743637437374383743937440374413744237443374443744537446374473744837449374503745137452374533745437455374563745737458374593746037461374623746337464374653746637467374683746937470374713747237473374743747537476374773747837479374803748137482374833748437485374863748737488374893749037491374923749337494374953749637497374983749937500375013750237503375043750537506375073750837509375103751137512375133751437515375163751737518375193752037521375223752337524375253752637527375283752937530375313753237533375343753537536375373753837539375403754137542375433754437545375463754737548375493755037551375523755337554375553755637557375583755937560375613756237563375643756537566375673756837569375703757137572375733757437575375763757737578375793758037581375823758337584375853758637587375883758937590375913759237593375943759537596375973759837599376003760137602376033760437605376063760737608376093761037611376123761337614376153761637617376183761937620376213762237623376243762537626376273762837629376303763137632376333763437635376363763737638376393764037641376423764337644376453764637647376483764937650376513765237653376543765537656376573765837659376603766137662376633766437665376663766737668376693767037671376723767337674376753767637677376783767937680376813768237683376843768537686376873768837689376903769137692376933769437695376963769737698376993770037701377023770337704377053770637707377083770937710377113771237713377143771537716377173771837719377203772137722377233772437725377263772737728377293773037731377323773337734377353773637737377383773937740377413774237743377443774537746377473774837749377503775137752377533775437755377563775737758377593776037761377623776337764377653776637767377683776937770377713777237773377743777537776377773777837779377803778137782377833778437785377863778737788377893779037791377923779337794377953779637797377983779937800378013780237803378043780537806378073780837809378103781137812378133781437815378163781737818378193782037821378223782337824378253782637827378283782937830378313783237833378343783537836378373783837839378403784137842378433784437845378463784737848378493785037851378523785337854378553785637857378583785937860378613786237863378643786537866378673786837869378703787137872378733787437875378763787737878378793788037881378823788337884378853788637887378883788937890378913789237893378943789537896378973789837899379003790137902379033790437905379063790737908379093791037911379123791337914379153791637917379183791937920379213792237923379243792537926379273792837929379303793137932379333793437935379363793737938379393794037941379423794337944379453794637947379483794937950379513795237953379543795537956379573795837959379603796137962379633796437965379663796737968379693797037971379723797337974379753797637977379783797937980379813798237983379843798537986379873798837989379903799137992379933799437995379963799737998379993800038001380023800338004380053800638007380083800938010380113801238013380143801538016380173801838019380203802138022380233802438025380263802738028380293803038031380323803338034380353803638037380383803938040380413804238043380443804538046380473804838049380503805138052380533805438055380563805738058380593806038061380623806338064380653806638067380683806938070380713807238073380743807538076380773807838079380803808138082380833808438085380863808738088380893809038091380923809338094380953809638097380983809938100381013810238103381043810538106381073810838109381103811138112381133811438115381163811738118381193812038121381223812338124381253812638127381283812938130381313813238133381343813538136381373813838139381403814138142381433814438145381463814738148381493815038151381523815338154381553815638157381583815938160381613816238163381643816538166381673816838169381703817138172381733817438175381763817738178381793818038181381823818338184381853818638187381883818938190381913819238193381943819538196381973819838199382003820138202382033820438205382063820738208382093821038211382123821338214382153821638217382183821938220382213822238223382243822538226382273822838229382303823138232382333823438235382363823738238382393824038241382423824338244382453824638247382483824938250382513825238253382543825538256382573825838259382603826138262382633826438265382663826738268382693827038271382723827338274382753827638277382783827938280382813828238283382843828538286382873828838289382903829138292382933829438295382963829738298382993830038301383023830338304383053830638307383083830938310383113831238313383143831538316383173831838319383203832138322383233832438325383263832738328383293833038331383323833338334383353833638337383383833938340383413834238343383443834538346383473834838349383503835138352383533835438355383563835738358383593836038361383623836338364383653836638367383683836938370383713837238373383743837538376383773837838379383803838138382383833838438385383863838738388383893839038391383923839338394383953839638397383983839938400384013840238403384043840538406384073840838409384103841138412384133841438415384163841738418384193842038421384223842338424384253842638427384283842938430384313843238433384343843538436384373843838439384403844138442384433844438445384463844738448384493845038451384523845338454384553845638457384583845938460384613846238463384643846538466384673846838469384703847138472384733847438475384763847738478384793848038481384823848338484384853848638487384883848938490384913849238493384943849538496384973849838499385003850138502385033850438505385063850738508385093851038511385123851338514385153851638517385183851938520385213852238523385243852538526385273852838529385303853138532385333853438535385363853738538385393854038541385423854338544385453854638547385483854938550385513855238553385543855538556385573855838559385603856138562385633856438565385663856738568385693857038571385723857338574385753857638577385783857938580385813858238583385843858538586385873858838589385903859138592385933859438595385963859738598385993860038601386023860338604386053860638607386083860938610386113861238613386143861538616386173861838619386203862138622386233862438625386263862738628386293863038631386323863338634386353863638637386383863938640386413864238643386443864538646386473864838649386503865138652386533865438655386563865738658386593866038661386623866338664386653866638667386683866938670386713867238673386743867538676386773867838679386803868138682386833868438685386863868738688386893869038691386923869338694386953869638697386983869938700387013870238703387043870538706387073870838709387103871138712387133871438715387163871738718387193872038721387223872338724387253872638727387283872938730387313873238733387343873538736387373873838739387403874138742387433874438745387463874738748387493875038751387523875338754387553875638757387583875938760387613876238763387643876538766387673876838769387703877138772387733877438775387763877738778387793878038781387823878338784387853878638787387883878938790387913879238793387943879538796387973879838799388003880138802388033880438805388063880738808388093881038811388123881338814388153881638817388183881938820388213882238823388243882538826388273882838829388303883138832388333883438835388363883738838388393884038841388423884338844388453884638847388483884938850388513885238853388543885538856388573885838859388603886138862388633886438865388663886738868388693887038871388723887338874388753887638877388783887938880388813888238883388843888538886388873888838889388903889138892388933889438895388963889738898388993890038901389023890338904389053890638907389083890938910389113891238913389143891538916389173891838919389203892138922389233892438925389263892738928389293893038931389323893338934389353893638937389383893938940389413894238943389443894538946389473894838949389503895138952389533895438955389563895738958389593896038961389623896338964389653896638967389683896938970389713897238973389743897538976389773897838979389803898138982389833898438985389863898738988389893899038991389923899338994389953899638997389983899939000390013900239003390043900539006390073900839009390103901139012390133901439015390163901739018390193902039021390223902339024390253902639027390283902939030390313903239033390343903539036390373903839039390403904139042390433904439045390463904739048390493905039051390523905339054390553905639057390583905939060390613906239063390643906539066390673906839069390703907139072390733907439075390763907739078390793908039081390823908339084390853908639087390883908939090390913909239093390943909539096390973909839099391003910139102391033910439105391063910739108391093911039111391123911339114391153911639117391183911939120391213912239123391243912539126391273912839129391303913139132391333913439135391363913739138391393914039141391423914339144391453914639147391483914939150391513915239153391543915539156391573915839159391603916139162391633916439165391663916739168391693917039171391723917339174391753917639177391783917939180391813918239183391843918539186391873918839189391903919139192391933919439195391963919739198391993920039201392023920339204392053920639207392083920939210392113921239213392143921539216392173921839219392203922139222392233922439225392263922739228392293923039231392323923339234392353923639237392383923939240392413924239243392443924539246392473924839249392503925139252392533925439255392563925739258392593926039261392623926339264392653926639267392683926939270392713927239273392743927539276392773927839279392803928139282392833928439285392863928739288392893929039291392923929339294392953929639297392983929939300393013930239303393043930539306393073930839309393103931139312393133931439315393163931739318393193932039321393223932339324393253932639327393283932939330393313933239333393343933539336393373933839339393403934139342393433934439345393463934739348393493935039351393523935339354393553935639357393583935939360393613936239363393643936539366393673936839369393703937139372393733937439375393763937739378393793938039381393823938339384393853938639387393883938939390393913939239393393943939539396393973939839399394003940139402394033940439405394063940739408394093941039411394123941339414394153941639417394183941939420394213942239423394243942539426394273942839429394303943139432394333943439435394363943739438394393944039441394423944339444394453944639447394483944939450394513945239453394543945539456394573945839459394603946139462394633946439465394663946739468394693947039471394723947339474394753947639477394783947939480394813948239483394843948539486394873948839489394903949139492394933949439495394963949739498394993950039501395023950339504395053950639507395083950939510395113951239513395143951539516395173951839519395203952139522395233952439525395263952739528395293953039531395323953339534395353953639537395383953939540395413954239543395443954539546395473954839549395503955139552395533955439555395563955739558395593956039561395623956339564395653956639567395683956939570395713957239573395743957539576395773957839579395803958139582395833958439585395863958739588395893959039591395923959339594395953959639597395983959939600396013960239603396043960539606396073960839609396103961139612396133961439615396163961739618396193962039621396223962339624396253962639627396283962939630396313963239633396343963539636396373963839639396403964139642396433964439645396463964739648396493965039651396523965339654396553965639657396583965939660396613966239663396643966539666396673966839669396703967139672396733967439675396763967739678396793968039681396823968339684396853968639687396883968939690396913969239693396943969539696396973969839699397003970139702397033970439705397063970739708397093971039711397123971339714397153971639717397183971939720397213972239723397243972539726397273972839729397303973139732397333973439735397363973739738397393974039741397423974339744397453974639747397483974939750397513975239753397543975539756397573975839759397603976139762397633976439765397663976739768397693977039771397723977339774397753977639777397783977939780397813978239783397843978539786397873978839789397903979139792397933979439795397963979739798397993980039801398023980339804398053980639807398083980939810398113981239813398143981539816398173981839819398203982139822398233982439825398263982739828398293983039831398323983339834398353983639837398383983939840398413984239843398443984539846398473984839849398503985139852398533985439855398563985739858398593986039861398623986339864398653986639867398683986939870398713987239873398743987539876398773987839879398803988139882398833988439885398863988739888398893989039891398923989339894398953989639897398983989939900399013990239903399043990539906399073990839909399103991139912399133991439915399163991739918399193992039921399223992339924399253992639927399283992939930399313993239933399343993539936399373993839939399403994139942399433994439945399463994739948399493995039951399523995339954399553995639957399583995939960399613996239963399643996539966399673996839969399703997139972399733997439975399763997739978399793998039981399823998339984399853998639987399883998939990399913999239993399943999539996399973999839999400004000140002400034000440005400064000740008400094001040011400124001340014400154001640017400184001940020400214002240023400244002540026400274002840029400304003140032400334003440035400364003740038400394004040041400424004340044400454004640047400484004940050400514005240053400544005540056400574005840059400604006140062400634006440065400664006740068400694007040071400724007340074400754007640077400784007940080400814008240083400844008540086400874008840089400904009140092400934009440095400964009740098400994010040101401024010340104401054010640107401084010940110401114011240113401144011540116401174011840119401204012140122401234012440125401264012740128401294013040131401324013340134401354013640137401384013940140401414014240143401444014540146401474014840149401504015140152401534015440155401564015740158401594016040161401624016340164401654016640167401684016940170401714017240173401744017540176401774017840179401804018140182401834018440185401864018740188401894019040191401924019340194401954019640197401984019940200402014020240203402044020540206402074020840209402104021140212402134021440215402164021740218402194022040221402224022340224402254022640227402284022940230402314023240233402344023540236402374023840239402404024140242402434024440245402464024740248402494025040251402524025340254402554025640257402584025940260402614026240263402644026540266402674026840269402704027140272402734027440275402764027740278402794028040281402824028340284402854028640287402884028940290402914029240293402944029540296402974029840299403004030140302403034030440305403064030740308403094031040311403124031340314403154031640317403184031940320403214032240323403244032540326403274032840329403304033140332403334033440335403364033740338403394034040341403424034340344403454034640347403484034940350403514035240353403544035540356403574035840359403604036140362403634036440365403664036740368403694037040371403724037340374403754037640377403784037940380403814038240383403844038540386403874038840389403904039140392403934039440395403964039740398403994040040401404024040340404404054040640407404084040940410404114041240413404144041540416404174041840419404204042140422404234042440425404264042740428404294043040431404324043340434404354043640437404384043940440404414044240443404444044540446404474044840449404504045140452404534045440455404564045740458404594046040461404624046340464404654046640467404684046940470404714047240473404744047540476404774047840479404804048140482404834048440485404864048740488404894049040491404924049340494404954049640497404984049940500405014050240503405044050540506405074050840509405104051140512405134051440515405164051740518405194052040521405224052340524405254052640527405284052940530405314053240533405344053540536405374053840539405404054140542405434054440545405464054740548405494055040551405524055340554405554055640557405584055940560405614056240563405644056540566405674056840569405704057140572405734057440575405764057740578405794058040581405824058340584405854058640587405884058940590405914059240593405944059540596405974059840599406004060140602406034060440605406064060740608406094061040611406124061340614406154061640617406184061940620406214062240623406244062540626406274062840629406304063140632406334063440635406364063740638406394064040641406424064340644406454064640647406484064940650406514065240653406544065540656406574065840659406604066140662406634066440665406664066740668406694067040671406724067340674406754067640677406784067940680406814068240683406844068540686406874068840689406904069140692406934069440695406964069740698406994070040701407024070340704407054070640707407084070940710407114071240713407144071540716407174071840719407204072140722407234072440725407264072740728407294073040731407324073340734407354073640737407384073940740407414074240743407444074540746407474074840749407504075140752407534075440755407564075740758407594076040761407624076340764407654076640767407684076940770407714077240773407744077540776407774077840779407804078140782407834078440785407864078740788407894079040791407924079340794407954079640797407984079940800408014080240803408044080540806408074080840809408104081140812408134081440815408164081740818408194082040821408224082340824408254082640827408284082940830408314083240833408344083540836408374083840839408404084140842408434084440845408464084740848408494085040851408524085340854408554085640857408584085940860408614086240863408644086540866408674086840869408704087140872408734087440875408764087740878408794088040881408824088340884408854088640887408884088940890408914089240893408944089540896408974089840899409004090140902409034090440905409064090740908409094091040911409124091340914409154091640917409184091940920409214092240923409244092540926409274092840929409304093140932409334093440935409364093740938409394094040941409424094340944409454094640947409484094940950409514095240953409544095540956409574095840959409604096140962409634096440965409664096740968409694097040971409724097340974409754097640977409784097940980409814098240983409844098540986409874098840989409904099140992409934099440995409964099740998409994100041001410024100341004410054100641007410084100941010410114101241013410144101541016410174101841019410204102141022410234102441025410264102741028410294103041031410324103341034410354103641037410384103941040410414104241043410444104541046410474104841049410504105141052410534105441055410564105741058410594106041061410624106341064410654106641067410684106941070410714107241073410744107541076410774107841079410804108141082410834108441085410864108741088410894109041091410924109341094410954109641097410984109941100411014110241103411044110541106411074110841109411104111141112411134111441115411164111741118411194112041121411224112341124411254112641127411284112941130411314113241133411344113541136411374113841139411404114141142411434114441145411464114741148411494115041151411524115341154411554115641157411584115941160411614116241163411644116541166411674116841169411704117141172411734117441175411764117741178411794118041181411824118341184411854118641187411884118941190411914119241193411944119541196411974119841199412004120141202412034120441205412064120741208412094121041211412124121341214412154121641217412184121941220412214122241223412244122541226412274122841229412304123141232412334123441235412364123741238412394124041241412424124341244412454124641247412484124941250412514125241253412544125541256412574125841259412604126141262412634126441265412664126741268412694127041271412724127341274412754127641277412784127941280412814128241283412844128541286412874128841289412904129141292412934129441295412964129741298412994130041301413024130341304413054130641307413084130941310413114131241313413144131541316413174131841319413204132141322413234132441325413264132741328413294133041331413324133341334413354133641337413384133941340413414134241343413444134541346413474134841349413504135141352413534135441355413564135741358413594136041361413624136341364413654136641367413684136941370413714137241373413744137541376413774137841379413804138141382413834138441385413864138741388413894139041391413924139341394413954139641397413984139941400414014140241403414044140541406414074140841409414104141141412414134141441415414164141741418414194142041421414224142341424414254142641427414284142941430414314143241433414344143541436414374143841439414404144141442414434144441445414464144741448414494145041451414524145341454414554145641457414584145941460414614146241463414644146541466414674146841469414704147141472414734147441475414764147741478414794148041481414824148341484414854148641487414884148941490414914149241493414944149541496414974149841499415004150141502415034150441505415064150741508415094151041511415124151341514415154151641517415184151941520415214152241523415244152541526415274152841529415304153141532415334153441535415364153741538415394154041541415424154341544415454154641547415484154941550415514155241553415544155541556415574155841559415604156141562415634156441565415664156741568415694157041571415724157341574415754157641577415784157941580415814158241583415844158541586415874158841589415904159141592415934159441595415964159741598415994160041601416024160341604416054160641607416084160941610416114161241613416144161541616416174161841619416204162141622416234162441625416264162741628416294163041631416324163341634416354163641637416384163941640416414164241643416444164541646416474164841649416504165141652416534165441655416564165741658416594166041661416624166341664416654166641667416684166941670416714167241673416744167541676416774167841679416804168141682416834168441685416864168741688416894169041691416924169341694416954169641697416984169941700417014170241703417044170541706417074170841709417104171141712417134171441715417164171741718417194172041721417224172341724417254172641727417284172941730417314173241733417344173541736417374173841739417404174141742417434174441745417464174741748417494175041751417524175341754417554175641757417584175941760417614176241763417644176541766417674176841769417704177141772417734177441775417764177741778417794178041781417824178341784417854178641787417884178941790417914179241793417944179541796417974179841799418004180141802418034180441805418064180741808418094181041811418124181341814418154181641817418184181941820418214182241823418244182541826418274182841829418304183141832418334183441835418364183741838418394184041841418424184341844418454184641847418484184941850418514185241853418544185541856418574185841859418604186141862418634186441865418664186741868418694187041871418724187341874418754187641877418784187941880418814188241883418844188541886418874188841889418904189141892418934189441895418964189741898418994190041901419024190341904419054190641907419084190941910419114191241913419144191541916419174191841919419204192141922419234192441925419264192741928419294193041931419324193341934419354193641937419384193941940419414194241943419444194541946419474194841949419504195141952419534195441955419564195741958419594196041961419624196341964419654196641967419684196941970419714197241973419744197541976419774197841979419804198141982419834198441985419864198741988419894199041991419924199341994419954199641997419984199942000420014200242003420044200542006420074200842009420104201142012420134201442015420164201742018420194202042021420224202342024420254202642027420284202942030420314203242033420344203542036420374203842039420404204142042420434204442045420464204742048420494205042051420524205342054420554205642057420584205942060420614206242063420644206542066420674206842069420704207142072420734207442075420764207742078420794208042081420824208342084420854208642087420884208942090420914209242093420944209542096420974209842099421004210142102421034210442105421064210742108421094211042111421124211342114421154211642117421184211942120421214212242123421244212542126421274212842129421304213142132421334213442135421364213742138421394214042141421424214342144421454214642147421484214942150421514215242153421544215542156421574215842159421604216142162421634216442165421664216742168421694217042171421724217342174421754217642177421784217942180421814218242183421844218542186421874218842189421904219142192421934219442195421964219742198421994220042201422024220342204422054220642207422084220942210422114221242213422144221542216422174221842219422204222142222422234222442225422264222742228422294223042231422324223342234422354223642237422384223942240422414224242243422444224542246422474224842249422504225142252422534225442255422564225742258422594226042261422624226342264422654226642267422684226942270422714227242273422744227542276422774227842279422804228142282422834228442285422864228742288422894229042291422924229342294422954229642297422984229942300423014230242303423044230542306423074230842309423104231142312423134231442315423164231742318423194232042321423224232342324423254232642327423284232942330423314233242333423344233542336423374233842339423404234142342423434234442345423464234742348423494235042351423524235342354423554235642357423584235942360423614236242363423644236542366423674236842369423704237142372423734237442375423764237742378423794238042381423824238342384423854238642387423884238942390423914239242393423944239542396423974239842399424004240142402424034240442405424064240742408424094241042411424124241342414424154241642417424184241942420424214242242423424244242542426424274242842429424304243142432424334243442435424364243742438424394244042441424424244342444424454244642447424484244942450424514245242453424544245542456424574245842459424604246142462424634246442465424664246742468424694247042471424724247342474424754247642477424784247942480424814248242483424844248542486424874248842489424904249142492424934249442495424964249742498424994250042501425024250342504425054250642507425084250942510425114251242513425144251542516425174251842519425204252142522425234252442525425264252742528425294253042531425324253342534425354253642537425384253942540425414254242543425444254542546425474254842549425504255142552425534255442555425564255742558425594256042561425624256342564425654256642567425684256942570425714257242573425744257542576425774257842579425804258142582425834258442585425864258742588425894259042591425924259342594425954259642597425984259942600426014260242603426044260542606426074260842609426104261142612426134261442615426164261742618426194262042621426224262342624426254262642627426284262942630426314263242633426344263542636426374263842639426404264142642426434264442645426464264742648426494265042651426524265342654426554265642657426584265942660426614266242663426644266542666426674266842669426704267142672426734267442675426764267742678426794268042681426824268342684426854268642687426884268942690426914269242693426944269542696426974269842699427004270142702427034270442705427064270742708427094271042711427124271342714427154271642717427184271942720427214272242723427244272542726427274272842729427304273142732427334273442735427364273742738427394274042741427424274342744427454274642747427484274942750427514275242753427544275542756427574275842759427604276142762427634276442765427664276742768427694277042771427724277342774427754277642777427784277942780427814278242783427844278542786427874278842789427904279142792427934279442795427964279742798427994280042801428024280342804428054280642807428084280942810428114281242813428144281542816428174281842819428204282142822428234282442825428264282742828428294283042831428324283342834428354283642837428384283942840428414284242843428444284542846428474284842849428504285142852428534285442855428564285742858428594286042861428624286342864428654286642867428684286942870428714287242873428744287542876428774287842879428804288142882428834288442885428864288742888428894289042891428924289342894428954289642897428984289942900429014290242903429044290542906429074290842909429104291142912429134291442915429164291742918429194292042921429224292342924429254292642927429284292942930429314293242933429344293542936429374293842939429404294142942429434294442945429464294742948429494295042951429524295342954429554295642957429584295942960429614296242963429644296542966429674296842969429704297142972429734297442975429764297742978429794298042981429824298342984429854298642987429884298942990429914299242993429944299542996429974299842999430004300143002430034300443005430064300743008430094301043011430124301343014430154301643017430184301943020430214302243023430244302543026430274302843029430304303143032430334303443035430364303743038430394304043041430424304343044430454304643047430484304943050430514305243053430544305543056430574305843059430604306143062430634306443065430664306743068430694307043071430724307343074430754307643077430784307943080430814308243083430844308543086430874308843089430904309143092430934309443095430964309743098430994310043101431024310343104431054310643107431084310943110431114311243113431144311543116431174311843119431204312143122431234312443125431264312743128431294313043131431324313343134431354313643137431384313943140431414314243143431444314543146431474314843149431504315143152431534315443155431564315743158431594316043161431624316343164431654316643167431684316943170431714317243173431744317543176431774317843179431804318143182431834318443185431864318743188431894319043191431924319343194431954319643197431984319943200432014320243203432044320543206432074320843209432104321143212432134321443215432164321743218432194322043221432224322343224432254322643227432284322943230432314323243233432344323543236432374323843239432404324143242432434324443245432464324743248432494325043251432524325343254432554325643257432584325943260432614326243263432644326543266432674326843269432704327143272432734327443275432764327743278432794328043281432824328343284432854328643287432884328943290432914329243293432944329543296432974329843299433004330143302433034330443305433064330743308433094331043311433124331343314433154331643317433184331943320433214332243323433244332543326433274332843329433304333143332433334333443335433364333743338433394334043341433424334343344433454334643347433484334943350433514335243353433544335543356433574335843359433604336143362433634336443365433664336743368433694337043371433724337343374433754337643377433784337943380433814338243383433844338543386433874338843389433904339143392433934339443395433964339743398433994340043401434024340343404434054340643407434084340943410434114341243413434144341543416434174341843419434204342143422434234342443425434264342743428434294343043431434324343343434434354343643437434384343943440434414344243443434444344543446434474344843449434504345143452434534345443455434564345743458434594346043461434624346343464434654346643467434684346943470434714347243473434744347543476434774347843479434804348143482434834348443485434864348743488434894349043491434924349343494434954349643497434984349943500435014350243503435044350543506435074350843509435104351143512435134351443515435164351743518435194352043521435224352343524435254352643527435284352943530435314353243533435344353543536435374353843539435404354143542435434354443545435464354743548435494355043551435524355343554435554355643557435584355943560435614356243563435644356543566435674356843569435704357143572435734357443575435764357743578435794358043581435824358343584435854358643587435884358943590435914359243593435944359543596435974359843599436004360143602436034360443605436064360743608436094361043611436124361343614436154361643617436184361943620436214362243623436244362543626436274362843629436304363143632436334363443635436364363743638436394364043641436424364343644436454364643647436484364943650436514365243653436544365543656436574365843659436604366143662436634366443665436664366743668436694367043671436724367343674436754367643677436784367943680436814368243683436844368543686436874368843689436904369143692436934369443695436964369743698436994370043701437024370343704437054370643707437084370943710437114371243713437144371543716437174371843719437204372143722437234372443725437264372743728437294373043731437324373343734437354373643737437384373943740437414374243743437444374543746437474374843749437504375143752437534375443755437564375743758437594376043761437624376343764437654376643767437684376943770437714377243773437744377543776437774377843779437804378143782437834378443785437864378743788437894379043791437924379343794437954379643797437984379943800438014380243803438044380543806438074380843809438104381143812438134381443815438164381743818438194382043821438224382343824438254382643827438284382943830438314383243833438344383543836438374383843839438404384143842438434384443845438464384743848438494385043851438524385343854438554385643857438584385943860438614386243863438644386543866438674386843869438704387143872438734387443875438764387743878438794388043881438824388343884438854388643887438884388943890438914389243893438944389543896438974389843899439004390143902439034390443905439064390743908439094391043911439124391343914439154391643917439184391943920439214392243923439244392543926439274392843929439304393143932439334393443935439364393743938439394394043941439424394343944439454394643947439484394943950439514395243953439544395543956439574395843959439604396143962439634396443965439664396743968439694397043971439724397343974439754397643977439784397943980439814398243983439844398543986439874398843989439904399143992439934399443995439964399743998439994400044001440024400344004440054400644007440084400944010440114401244013440144401544016440174401844019440204402144022440234402444025440264402744028440294403044031440324403344034440354403644037440384403944040440414404244043440444404544046440474404844049440504405144052440534405444055440564405744058440594406044061440624406344064440654406644067440684406944070440714407244073440744407544076440774407844079440804408144082440834408444085440864408744088440894409044091440924409344094440954409644097440984409944100441014410244103441044410544106441074410844109441104411144112441134411444115441164411744118441194412044121441224412344124441254412644127441284412944130441314413244133441344413544136441374413844139441404414144142441434414444145441464414744148441494415044151441524415344154441554415644157441584415944160441614416244163441644416544166441674416844169441704417144172441734417444175441764417744178441794418044181441824418344184441854418644187441884418944190441914419244193441944419544196441974419844199442004420144202442034420444205442064420744208442094421044211442124421344214442154421644217442184421944220442214422244223442244422544226442274422844229442304423144232442334423444235442364423744238442394424044241442424424344244442454424644247442484424944250442514425244253442544425544256442574425844259442604426144262442634426444265442664426744268442694427044271442724427344274442754427644277442784427944280442814428244283442844428544286442874428844289442904429144292442934429444295442964429744298442994430044301443024430344304443054430644307443084430944310443114431244313443144431544316443174431844319443204432144322443234432444325443264432744328443294433044331443324433344334443354433644337443384433944340443414434244343443444434544346443474434844349443504435144352443534435444355443564435744358443594436044361443624436344364443654436644367443684436944370443714437244373443744437544376443774437844379443804438144382443834438444385443864438744388443894439044391443924439344394443954439644397443984439944400444014440244403444044440544406444074440844409444104441144412444134441444415444164441744418444194442044421444224442344424444254442644427444284442944430444314443244433444344443544436444374443844439444404444144442444434444444445444464444744448444494445044451444524445344454444554445644457444584445944460444614446244463444644446544466444674446844469444704447144472444734447444475444764447744478444794448044481444824448344484444854448644487444884448944490444914449244493444944449544496444974449844499445004450144502445034450444505445064450744508445094451044511445124451344514445154451644517445184451944520445214452244523445244452544526445274452844529445304453144532445334453444535445364453744538445394454044541445424454344544445454454644547445484454944550445514455244553445544455544556445574455844559445604456144562445634456444565445664456744568445694457044571445724457344574445754457644577445784457944580445814458244583445844458544586445874458844589445904459144592445934459444595445964459744598445994460044601446024460344604446054460644607446084460944610446114461244613446144461544616446174461844619446204462144622446234462444625446264462744628446294463044631446324463344634446354463644637446384463944640446414464244643446444464544646446474464844649446504465144652446534465444655446564465744658446594466044661446624466344664446654466644667446684466944670446714467244673446744467544676446774467844679446804468144682446834468444685446864468744688446894469044691446924469344694446954469644697446984469944700447014470244703447044470544706447074470844709447104471144712447134471444715447164471744718447194472044721447224472344724447254472644727447284472944730447314473244733447344473544736447374473844739447404474144742447434474444745447464474744748447494475044751447524475344754447554475644757447584475944760447614476244763447644476544766447674476844769447704477144772447734477444775447764477744778447794478044781447824478344784447854478644787447884478944790447914479244793447944479544796447974479844799448004480144802448034480444805448064480744808448094481044811448124481344814448154481644817448184481944820448214482244823448244482544826448274482844829448304483144832448334483444835448364483744838448394484044841448424484344844448454484644847448484484944850448514485244853448544485544856448574485844859448604486144862448634486444865448664486744868448694487044871448724487344874448754487644877448784487944880448814488244883448844488544886448874488844889448904489144892448934489444895448964489744898448994490044901449024490344904449054490644907449084490944910449114491244913449144491544916449174491844919449204492144922449234492444925449264492744928449294493044931449324493344934449354493644937449384493944940449414494244943449444494544946449474494844949449504495144952449534495444955449564495744958449594496044961449624496344964449654496644967449684496944970449714497244973449744497544976449774497844979449804498144982449834498444985449864498744988449894499044991449924499344994449954499644997449984499945000450014500245003450044500545006450074500845009450104501145012450134501445015450164501745018450194502045021450224502345024450254502645027450284502945030450314503245033450344503545036450374503845039450404504145042450434504445045450464504745048450494505045051450524505345054450554505645057450584505945060450614506245063450644506545066450674506845069450704507145072450734507445075450764507745078450794508045081450824508345084450854508645087450884508945090450914509245093450944509545096450974509845099451004510145102451034510445105451064510745108451094511045111451124511345114451154511645117451184511945120451214512245123451244512545126451274512845129451304513145132451334513445135451364513745138451394514045141451424514345144451454514645147451484514945150451514515245153451544515545156451574515845159451604516145162451634516445165451664516745168451694517045171451724517345174451754517645177451784517945180451814518245183451844518545186451874518845189451904519145192451934519445195451964519745198451994520045201452024520345204452054520645207452084520945210452114521245213452144521545216452174521845219452204522145222452234522445225452264522745228452294523045231452324523345234452354523645237452384523945240452414524245243452444524545246452474524845249452504525145252452534525445255452564525745258452594526045261452624526345264452654526645267452684526945270452714527245273452744527545276452774527845279452804528145282452834528445285452864528745288452894529045291452924529345294452954529645297452984529945300453014530245303453044530545306453074530845309453104531145312453134531445315453164531745318453194532045321453224532345324453254532645327453284532945330453314533245333453344533545336453374533845339453404534145342453434534445345453464534745348453494535045351453524535345354453554535645357453584535945360453614536245363453644536545366453674536845369453704537145372453734537445375453764537745378453794538045381453824538345384453854538645387453884538945390453914539245393453944539545396453974539845399454004540145402454034540445405454064540745408454094541045411454124541345414454154541645417454184541945420454214542245423454244542545426454274542845429454304543145432454334543445435454364543745438454394544045441454424544345444454454544645447454484544945450454514545245453454544545545456454574545845459454604546145462454634546445465454664546745468454694547045471454724547345474454754547645477454784547945480454814548245483454844548545486454874548845489454904549145492454934549445495454964549745498454994550045501455024550345504455054550645507455084550945510455114551245513455144551545516455174551845519455204552145522455234552445525455264552745528455294553045531455324553345534455354553645537455384553945540455414554245543455444554545546455474554845549455504555145552455534555445555455564555745558455594556045561455624556345564455654556645567455684556945570455714557245573455744557545576455774557845579455804558145582455834558445585455864558745588455894559045591455924559345594455954559645597455984559945600456014560245603456044560545606456074560845609456104561145612456134561445615456164561745618456194562045621456224562345624456254562645627456284562945630456314563245633456344563545636456374563845639456404564145642456434564445645456464564745648456494565045651456524565345654456554565645657456584565945660456614566245663456644566545666456674566845669456704567145672456734567445675456764567745678456794568045681456824568345684456854568645687456884568945690456914569245693456944569545696456974569845699457004570145702457034570445705457064570745708457094571045711457124571345714457154571645717457184571945720457214572245723457244572545726457274572845729457304573145732457334573445735457364573745738457394574045741457424574345744457454574645747457484574945750457514575245753457544575545756457574575845759457604576145762457634576445765457664576745768457694577045771457724577345774457754577645777457784577945780457814578245783457844578545786457874578845789457904579145792457934579445795457964579745798457994580045801458024580345804458054580645807458084580945810458114581245813458144581545816458174581845819458204582145822458234582445825458264582745828458294583045831458324583345834458354583645837458384583945840458414584245843458444584545846458474584845849458504585145852458534585445855458564585745858458594586045861458624586345864458654586645867458684586945870458714587245873458744587545876458774587845879458804588145882458834588445885458864588745888458894589045891458924589345894458954589645897458984589945900459014590245903459044590545906459074590845909459104591145912459134591445915459164591745918459194592045921459224592345924459254592645927459284592945930459314593245933459344593545936459374593845939459404594145942459434594445945459464594745948459494595045951459524595345954459554595645957459584595945960459614596245963459644596545966459674596845969459704597145972459734597445975459764597745978459794598045981459824598345984459854598645987459884598945990459914599245993459944599545996459974599845999460004600146002460034600446005460064600746008460094601046011460124601346014460154601646017460184601946020460214602246023460244602546026460274602846029460304603146032460334603446035460364603746038460394604046041460424604346044460454604646047460484604946050460514605246053460544605546056460574605846059460604606146062460634606446065460664606746068460694607046071460724607346074460754607646077460784607946080460814608246083460844608546086460874608846089460904609146092460934609446095460964609746098460994610046101461024610346104461054610646107461084610946110461114611246113461144611546116461174611846119461204612146122461234612446125461264612746128461294613046131461324613346134461354613646137461384613946140461414614246143461444614546146461474614846149461504615146152461534615446155461564615746158461594616046161461624616346164461654616646167461684616946170461714617246173461744617546176461774617846179461804618146182461834618446185461864618746188461894619046191461924619346194461954619646197461984619946200462014620246203462044620546206462074620846209462104621146212462134621446215462164621746218462194622046221462224622346224462254622646227462284622946230462314623246233462344623546236462374623846239462404624146242462434624446245462464624746248462494625046251462524625346254462554625646257462584625946260462614626246263462644626546266462674626846269462704627146272462734627446275462764627746278462794628046281462824628346284462854628646287462884628946290462914629246293462944629546296462974629846299463004630146302463034630446305463064630746308463094631046311463124631346314463154631646317463184631946320463214632246323463244632546326463274632846329463304633146332463334633446335463364633746338463394634046341463424634346344463454634646347463484634946350463514635246353463544635546356463574635846359463604636146362463634636446365463664636746368463694637046371463724637346374463754637646377463784637946380463814638246383463844638546386463874638846389463904639146392463934639446395463964639746398463994640046401464024640346404464054640646407464084640946410464114641246413464144641546416464174641846419464204642146422464234642446425464264642746428464294643046431464324643346434464354643646437464384643946440464414644246443464444644546446464474644846449464504645146452464534645446455464564645746458464594646046461464624646346464464654646646467464684646946470464714647246473464744647546476464774647846479464804648146482464834648446485464864648746488464894649046491464924649346494464954649646497464984649946500465014650246503465044650546506465074650846509465104651146512465134651446515465164651746518465194652046521465224652346524465254652646527465284652946530465314653246533465344653546536465374653846539465404654146542465434654446545465464654746548465494655046551465524655346554465554655646557465584655946560465614656246563465644656546566465674656846569465704657146572465734657446575465764657746578465794658046581465824658346584465854658646587465884658946590465914659246593465944659546596465974659846599466004660146602466034660446605466064660746608466094661046611466124661346614466154661646617466184661946620466214662246623466244662546626466274662846629466304663146632466334663446635466364663746638466394664046641466424664346644466454664646647466484664946650466514665246653466544665546656466574665846659466604666146662466634666446665466664666746668466694667046671466724667346674466754667646677466784667946680466814668246683466844668546686466874668846689466904669146692466934669446695466964669746698466994670046701467024670346704467054670646707467084670946710467114671246713467144671546716467174671846719467204672146722467234672446725467264672746728467294673046731467324673346734467354673646737467384673946740467414674246743467444674546746467474674846749467504675146752467534675446755467564675746758467594676046761467624676346764467654676646767467684676946770467714677246773467744677546776467774677846779467804678146782467834678446785467864678746788467894679046791467924679346794467954679646797467984679946800468014680246803468044680546806468074680846809468104681146812468134681446815468164681746818468194682046821468224682346824468254682646827468284682946830468314683246833468344683546836468374683846839468404684146842468434684446845468464684746848468494685046851468524685346854468554685646857468584685946860468614686246863468644686546866468674686846869468704687146872468734687446875468764687746878468794688046881468824688346884468854688646887468884688946890468914689246893468944689546896468974689846899469004690146902469034690446905469064690746908469094691046911469124691346914469154691646917469184691946920469214692246923469244692546926469274692846929469304693146932469334693446935469364693746938469394694046941469424694346944469454694646947469484694946950469514695246953469544695546956469574695846959469604696146962469634696446965469664696746968469694697046971469724697346974469754697646977469784697946980469814698246983469844698546986469874698846989469904699146992469934699446995469964699746998469994700047001470024700347004470054700647007470084700947010470114701247013470144701547016470174701847019470204702147022470234702447025470264702747028470294703047031470324703347034470354703647037470384703947040470414704247043470444704547046470474704847049470504705147052470534705447055470564705747058470594706047061470624706347064470654706647067470684706947070470714707247073470744707547076470774707847079470804708147082470834708447085470864708747088470894709047091470924709347094470954709647097470984709947100471014710247103471044710547106471074710847109471104711147112471134711447115471164711747118471194712047121471224712347124471254712647127471284712947130471314713247133471344713547136471374713847139471404714147142471434714447145471464714747148471494715047151471524715347154471554715647157471584715947160471614716247163471644716547166471674716847169471704717147172471734717447175471764717747178471794718047181471824718347184471854718647187471884718947190471914719247193471944719547196471974719847199472004720147202472034720447205472064720747208472094721047211472124721347214472154721647217472184721947220472214722247223472244722547226472274722847229472304723147232472334723447235472364723747238472394724047241472424724347244472454724647247472484724947250472514725247253472544725547256472574725847259472604726147262472634726447265472664726747268472694727047271472724727347274472754727647277472784727947280472814728247283472844728547286472874728847289472904729147292472934729447295472964729747298472994730047301473024730347304473054730647307473084730947310473114731247313473144731547316473174731847319473204732147322473234732447325473264732747328473294733047331473324733347334473354733647337473384733947340473414734247343473444734547346473474734847349473504735147352473534735447355473564735747358473594736047361473624736347364473654736647367473684736947370473714737247373473744737547376473774737847379473804738147382473834738447385473864738747388473894739047391473924739347394473954739647397473984739947400474014740247403474044740547406474074740847409474104741147412474134741447415474164741747418474194742047421474224742347424474254742647427474284742947430474314743247433474344743547436474374743847439474404744147442474434744447445474464744747448474494745047451474524745347454474554745647457474584745947460474614746247463474644746547466474674746847469474704747147472474734747447475474764747747478474794748047481474824748347484474854748647487474884748947490474914749247493474944749547496474974749847499475004750147502475034750447505475064750747508475094751047511475124751347514475154751647517475184751947520475214752247523475244752547526475274752847529475304753147532475334753447535475364753747538475394754047541475424754347544475454754647547475484754947550475514755247553475544755547556475574755847559475604756147562475634756447565475664756747568475694757047571475724757347574475754757647577475784757947580475814758247583475844758547586475874758847589475904759147592475934759447595475964759747598475994760047601476024760347604476054760647607476084760947610476114761247613476144761547616476174761847619476204762147622476234762447625476264762747628476294763047631476324763347634476354763647637476384763947640476414764247643476444764547646476474764847649476504765147652476534765447655476564765747658476594766047661476624766347664476654766647667476684766947670476714767247673476744767547676476774767847679476804768147682476834768447685476864768747688476894769047691476924769347694476954769647697476984769947700477014770247703477044770547706477074770847709477104771147712477134771447715477164771747718477194772047721477224772347724477254772647727477284772947730477314773247733477344773547736477374773847739477404774147742477434774447745477464774747748477494775047751477524775347754477554775647757477584775947760477614776247763477644776547766477674776847769477704777147772477734777447775477764777747778477794778047781477824778347784477854778647787477884778947790477914779247793477944779547796477974779847799478004780147802478034780447805478064780747808478094781047811478124781347814478154781647817478184781947820478214782247823478244782547826478274782847829478304783147832478334783447835478364783747838478394784047841478424784347844478454784647847478484784947850478514785247853478544785547856478574785847859478604786147862478634786447865478664786747868478694787047871478724787347874478754787647877478784787947880478814788247883478844788547886478874788847889478904789147892478934789447895478964789747898478994790047901479024790347904479054790647907479084790947910479114791247913479144791547916479174791847919479204792147922479234792447925479264792747928479294793047931479324793347934479354793647937479384793947940479414794247943479444794547946479474794847949479504795147952479534795447955479564795747958479594796047961479624796347964479654796647967479684796947970479714797247973479744797547976479774797847979479804798147982479834798447985479864798747988479894799047991479924799347994479954799647997479984799948000480014800248003480044800548006480074800848009480104801148012480134801448015480164801748018480194802048021480224802348024480254802648027480284802948030480314803248033480344803548036480374803848039480404804148042480434804448045480464804748048480494805048051480524805348054480554805648057480584805948060480614806248063480644806548066480674806848069480704807148072480734807448075480764807748078480794808048081480824808348084480854808648087480884808948090480914809248093480944809548096480974809848099481004810148102481034810448105481064810748108481094811048111481124811348114481154811648117481184811948120481214812248123481244812548126481274812848129481304813148132481334813448135481364813748138481394814048141481424814348144481454814648147481484814948150481514815248153481544815548156481574815848159481604816148162481634816448165481664816748168481694817048171481724817348174481754817648177481784817948180481814818248183481844818548186481874818848189481904819148192481934819448195481964819748198481994820048201482024820348204482054820648207482084820948210482114821248213482144821548216482174821848219482204822148222482234822448225482264822748228482294823048231482324823348234482354823648237482384823948240482414824248243482444824548246482474824848249482504825148252482534825448255482564825748258482594826048261482624826348264482654826648267482684826948270482714827248273482744827548276482774827848279482804828148282482834828448285482864828748288482894829048291482924829348294482954829648297482984829948300483014830248303483044830548306483074830848309483104831148312483134831448315483164831748318483194832048321483224832348324483254832648327483284832948330483314833248333483344833548336483374833848339483404834148342483434834448345483464834748348483494835048351483524835348354483554835648357483584835948360483614836248363483644836548366483674836848369483704837148372483734837448375483764837748378483794838048381483824838348384483854838648387483884838948390483914839248393483944839548396483974839848399484004840148402484034840448405484064840748408484094841048411484124841348414484154841648417484184841948420484214842248423484244842548426484274842848429484304843148432484334843448435484364843748438484394844048441484424844348444484454844648447484484844948450484514845248453484544845548456484574845848459484604846148462484634846448465484664846748468484694847048471484724847348474484754847648477484784847948480484814848248483484844848548486484874848848489484904849148492484934849448495484964849748498484994850048501485024850348504485054850648507485084850948510485114851248513485144851548516485174851848519485204852148522485234852448525485264852748528485294853048531485324853348534485354853648537485384853948540485414854248543485444854548546485474854848549485504855148552485534855448555485564855748558485594856048561485624856348564485654856648567485684856948570485714857248573485744857548576485774857848579485804858148582485834858448585485864858748588485894859048591485924859348594485954859648597485984859948600486014860248603486044860548606486074860848609486104861148612486134861448615486164861748618486194862048621486224862348624486254862648627486284862948630486314863248633486344863548636486374863848639486404864148642486434864448645486464864748648486494865048651486524865348654486554865648657486584865948660486614866248663486644866548666486674866848669486704867148672486734867448675486764867748678486794868048681486824868348684486854868648687486884868948690486914869248693486944869548696486974869848699487004870148702487034870448705487064870748708487094871048711487124871348714487154871648717487184871948720487214872248723487244872548726487274872848729487304873148732487334873448735487364873748738487394874048741487424874348744487454874648747487484874948750487514875248753487544875548756487574875848759487604876148762487634876448765487664876748768487694877048771487724877348774487754877648777487784877948780487814878248783487844878548786487874878848789487904879148792487934879448795487964879748798487994880048801488024880348804488054880648807488084880948810488114881248813488144881548816488174881848819488204882148822488234882448825488264882748828488294883048831488324883348834488354883648837488384883948840488414884248843488444884548846488474884848849488504885148852488534885448855488564885748858488594886048861488624886348864488654886648867488684886948870488714887248873488744887548876488774887848879488804888148882488834888448885488864888748888488894889048891488924889348894488954889648897488984889948900489014890248903489044890548906489074890848909489104891148912489134891448915489164891748918489194892048921489224892348924489254892648927489284892948930489314893248933489344893548936489374893848939489404894148942489434894448945489464894748948489494895048951489524895348954489554895648957489584895948960489614896248963489644896548966489674896848969489704897148972489734897448975489764897748978489794898048981489824898348984489854898648987489884898948990489914899248993489944899548996489974899848999490004900149002490034900449005490064900749008490094901049011490124901349014490154901649017490184901949020490214902249023490244902549026490274902849029490304903149032490334903449035490364903749038490394904049041490424904349044490454904649047490484904949050490514905249053490544905549056490574905849059490604906149062490634906449065490664906749068490694907049071490724907349074490754907649077490784907949080490814908249083490844908549086490874908849089490904909149092490934909449095490964909749098490994910049101491024910349104491054910649107491084910949110491114911249113491144911549116491174911849119491204912149122491234912449125491264912749128491294913049131491324913349134491354913649137491384913949140491414914249143491444914549146491474914849149491504915149152491534915449155491564915749158491594916049161491624916349164491654916649167491684916949170491714917249173491744917549176491774917849179491804918149182491834918449185491864918749188491894919049191491924919349194491954919649197491984919949200492014920249203492044920549206492074920849209492104921149212492134921449215492164921749218492194922049221492224922349224492254922649227492284922949230492314923249233492344923549236492374923849239492404924149242492434924449245492464924749248492494925049251492524925349254492554925649257492584925949260492614926249263492644926549266492674926849269492704927149272492734927449275492764927749278492794928049281492824928349284492854928649287492884928949290492914929249293492944929549296492974929849299493004930149302493034930449305493064930749308493094931049311493124931349314493154931649317493184931949320493214932249323493244932549326493274932849329493304933149332493334933449335493364933749338493394934049341493424934349344493454934649347493484934949350493514935249353493544935549356493574935849359493604936149362493634936449365493664936749368493694937049371493724937349374493754937649377493784937949380493814938249383493844938549386493874938849389493904939149392493934939449395493964939749398493994940049401494024940349404494054940649407494084940949410494114941249413494144941549416494174941849419494204942149422494234942449425494264942749428494294943049431494324943349434494354943649437494384943949440494414944249443494444944549446494474944849449494504945149452494534945449455494564945749458494594946049461494624946349464494654946649467494684946949470494714947249473494744947549476494774947849479494804948149482494834948449485494864948749488494894949049491494924949349494494954949649497494984949949500495014950249503495044950549506495074950849509495104951149512495134951449515495164951749518495194952049521495224952349524495254952649527495284952949530495314953249533495344953549536495374953849539495404954149542495434954449545495464954749548495494955049551495524955349554495554955649557495584955949560495614956249563495644956549566495674956849569495704957149572495734957449575495764957749578495794958049581495824958349584495854958649587495884958949590495914959249593495944959549596495974959849599496004960149602496034960449605496064960749608496094961049611496124961349614496154961649617496184961949620496214962249623496244962549626496274962849629496304963149632496334963449635496364963749638496394964049641496424964349644496454964649647496484964949650496514965249653496544965549656496574965849659496604966149662496634966449665496664966749668496694967049671496724967349674496754967649677496784967949680496814968249683496844968549686496874968849689496904969149692496934969449695496964969749698496994970049701497024970349704497054970649707497084970949710497114971249713497144971549716497174971849719497204972149722497234972449725497264972749728497294973049731497324973349734497354973649737497384973949740497414974249743497444974549746497474974849749497504975149752497534975449755497564975749758497594976049761497624976349764497654976649767497684976949770497714977249773497744977549776497774977849779497804978149782497834978449785497864978749788497894979049791497924979349794497954979649797497984979949800498014980249803498044980549806498074980849809498104981149812498134981449815498164981749818498194982049821498224982349824498254982649827498284982949830498314983249833498344983549836498374983849839498404984149842498434984449845498464984749848498494985049851498524985349854498554985649857498584985949860498614986249863498644986549866498674986849869498704987149872498734987449875498764987749878498794988049881498824988349884498854988649887498884988949890498914989249893498944989549896498974989849899499004990149902499034990449905499064990749908499094991049911499124991349914499154991649917499184991949920499214992249923499244992549926499274992849929499304993149932499334993449935499364993749938499394994049941499424994349944499454994649947499484994949950499514995249953499544995549956499574995849959499604996149962499634996449965499664996749968499694997049971499724997349974499754997649977499784997949980499814998249983499844998549986499874998849989499904999149992499934999449995499964999749998499995000050001500025000350004500055000650007500085000950010500115001250013500145001550016500175001850019500205002150022500235002450025500265002750028500295003050031500325003350034500355003650037500385003950040500415004250043500445004550046500475004850049500505005150052500535005450055500565005750058500595006050061500625006350064500655006650067500685006950070500715007250073500745007550076500775007850079500805008150082500835008450085500865008750088500895009050091500925009350094500955009650097500985009950100501015010250103501045010550106501075010850109501105011150112501135011450115501165011750118501195012050121501225012350124501255012650127501285012950130501315013250133501345013550136501375013850139501405014150142501435014450145501465014750148501495015050151501525015350154501555015650157501585015950160501615016250163501645016550166501675016850169501705017150172501735017450175501765017750178501795018050181501825018350184501855018650187501885018950190501915019250193501945019550196501975019850199502005020150202502035020450205502065020750208502095021050211502125021350214502155021650217502185021950220502215022250223502245022550226502275022850229502305023150232502335023450235502365023750238502395024050241502425024350244502455024650247502485024950250502515025250253502545025550256502575025850259502605026150262502635026450265502665026750268502695027050271502725027350274502755027650277502785027950280502815028250283502845028550286502875028850289502905029150292502935029450295502965029750298502995030050301503025030350304503055030650307503085030950310503115031250313503145031550316503175031850319503205032150322503235032450325503265032750328503295033050331503325033350334503355033650337503385033950340503415034250343503445034550346503475034850349503505035150352503535035450355503565035750358503595036050361503625036350364503655036650367503685036950370503715037250373503745037550376503775037850379503805038150382503835038450385503865038750388503895039050391503925039350394503955039650397503985039950400504015040250403504045040550406504075040850409504105041150412504135041450415504165041750418504195042050421504225042350424504255042650427504285042950430504315043250433504345043550436504375043850439504405044150442504435044450445504465044750448504495045050451504525045350454504555045650457504585045950460504615046250463504645046550466504675046850469504705047150472504735047450475504765047750478504795048050481504825048350484504855048650487504885048950490504915049250493504945049550496504975049850499505005050150502505035050450505505065050750508505095051050511505125051350514505155051650517505185051950520505215052250523505245052550526505275052850529505305053150532505335053450535505365053750538505395054050541505425054350544505455054650547505485054950550505515055250553505545055550556505575055850559505605056150562505635056450565505665056750568505695057050571505725057350574505755057650577505785057950580505815058250583505845058550586505875058850589505905059150592505935059450595505965059750598505995060050601506025060350604506055060650607506085060950610506115061250613506145061550616506175061850619506205062150622506235062450625506265062750628506295063050631506325063350634506355063650637506385063950640506415064250643506445064550646506475064850649506505065150652506535065450655506565065750658506595066050661506625066350664506655066650667506685066950670506715067250673506745067550676506775067850679506805068150682506835068450685506865068750688506895069050691506925069350694506955069650697506985069950700507015070250703507045070550706507075070850709507105071150712507135071450715507165071750718507195072050721507225072350724507255072650727507285072950730507315073250733507345073550736507375073850739507405074150742507435074450745507465074750748507495075050751507525075350754507555075650757507585075950760507615076250763507645076550766507675076850769507705077150772507735077450775507765077750778507795078050781507825078350784507855078650787507885078950790507915079250793507945079550796507975079850799508005080150802508035080450805508065080750808508095081050811508125081350814508155081650817508185081950820508215082250823508245082550826508275082850829508305083150832508335083450835508365083750838508395084050841508425084350844508455084650847508485084950850508515085250853508545085550856508575085850859508605086150862508635086450865508665086750868508695087050871508725087350874508755087650877508785087950880508815088250883508845088550886508875088850889508905089150892508935089450895508965089750898508995090050901509025090350904509055090650907509085090950910509115091250913509145091550916509175091850919509205092150922509235092450925509265092750928509295093050931509325093350934509355093650937509385093950940509415094250943509445094550946509475094850949509505095150952509535095450955509565095750958509595096050961509625096350964509655096650967509685096950970509715097250973509745097550976509775097850979509805098150982509835098450985509865098750988509895099050991509925099350994509955099650997509985099951000510015100251003510045100551006510075100851009510105101151012510135101451015510165101751018510195102051021510225102351024510255102651027510285102951030510315103251033510345103551036510375103851039510405104151042510435104451045510465104751048510495105051051510525105351054510555105651057510585105951060510615106251063510645106551066510675106851069510705107151072510735107451075510765107751078510795108051081510825108351084510855108651087510885108951090510915109251093510945109551096510975109851099511005110151102511035110451105511065110751108511095111051111511125111351114511155111651117511185111951120511215112251123511245112551126511275112851129511305113151132511335113451135511365113751138511395114051141511425114351144511455114651147511485114951150511515115251153511545115551156511575115851159511605116151162511635116451165511665116751168511695117051171511725117351174511755117651177511785117951180511815118251183511845118551186511875118851189511905119151192511935119451195511965119751198511995120051201512025120351204512055120651207512085120951210512115121251213512145121551216512175121851219512205122151222512235122451225512265122751228512295123051231512325123351234512355123651237512385123951240512415124251243512445124551246512475124851249512505125151252512535125451255512565125751258512595126051261512625126351264512655126651267512685126951270512715127251273512745127551276512775127851279512805128151282512835128451285512865128751288512895129051291512925129351294512955129651297512985129951300513015130251303513045130551306513075130851309513105131151312513135131451315513165131751318513195132051321513225132351324513255132651327513285132951330513315133251333513345133551336513375133851339513405134151342513435134451345513465134751348513495135051351513525135351354513555135651357513585135951360513615136251363513645136551366513675136851369513705137151372513735137451375513765137751378513795138051381513825138351384513855138651387513885138951390513915139251393513945139551396513975139851399514005140151402514035140451405514065140751408514095141051411514125141351414514155141651417514185141951420514215142251423514245142551426514275142851429514305143151432514335143451435514365143751438514395144051441514425144351444514455144651447514485144951450514515145251453514545145551456514575145851459514605146151462514635146451465514665146751468514695147051471514725147351474514755147651477514785147951480514815148251483514845148551486514875148851489514905149151492514935149451495514965149751498514995150051501515025150351504515055150651507515085150951510515115151251513515145151551516515175151851519515205152151522515235152451525515265152751528515295153051531515325153351534515355153651537515385153951540515415154251543515445154551546515475154851549515505155151552515535155451555515565155751558515595156051561515625156351564515655156651567515685156951570515715157251573515745157551576515775157851579515805158151582515835158451585515865158751588515895159051591515925159351594515955159651597515985159951600516015160251603516045160551606516075160851609516105161151612516135161451615516165161751618516195162051621516225162351624516255162651627516285162951630516315163251633516345163551636516375163851639516405164151642516435164451645516465164751648516495165051651516525165351654516555165651657516585165951660516615166251663516645166551666516675166851669516705167151672516735167451675516765167751678516795168051681516825168351684516855168651687516885168951690516915169251693516945169551696516975169851699517005170151702517035170451705517065170751708517095171051711517125171351714517155171651717517185171951720517215172251723517245172551726517275172851729517305173151732517335173451735517365173751738517395174051741517425174351744517455174651747517485174951750517515175251753517545175551756517575175851759517605176151762517635176451765517665176751768517695177051771517725177351774517755177651777517785177951780517815178251783517845178551786517875178851789517905179151792517935179451795517965179751798517995180051801518025180351804518055180651807518085180951810518115181251813518145181551816518175181851819518205182151822518235182451825518265182751828518295183051831518325183351834518355183651837518385183951840518415184251843518445184551846518475184851849518505185151852518535185451855518565185751858518595186051861518625186351864518655186651867518685186951870518715187251873518745187551876518775187851879518805188151882518835188451885518865188751888518895189051891518925189351894518955189651897518985189951900519015190251903519045190551906519075190851909519105191151912519135191451915519165191751918519195192051921519225192351924519255192651927519285192951930519315193251933519345193551936519375193851939519405194151942519435194451945519465194751948519495195051951519525195351954519555195651957519585195951960519615196251963519645196551966519675196851969519705197151972519735197451975519765197751978519795198051981519825198351984519855198651987519885198951990519915199251993519945199551996519975199851999520005200152002520035200452005520065200752008520095201052011520125201352014520155201652017520185201952020520215202252023520245202552026520275202852029520305203152032520335203452035520365203752038520395204052041520425204352044520455204652047520485204952050520515205252053520545205552056520575205852059520605206152062520635206452065520665206752068520695207052071520725207352074520755207652077520785207952080520815208252083520845208552086520875208852089520905209152092520935209452095520965209752098520995210052101521025210352104521055210652107521085210952110521115211252113521145211552116521175211852119521205212152122521235212452125521265212752128521295213052131521325213352134521355213652137521385213952140521415214252143521445214552146521475214852149521505215152152521535215452155521565215752158521595216052161521625216352164521655216652167521685216952170521715217252173521745217552176521775217852179521805218152182521835218452185521865218752188521895219052191521925219352194521955219652197521985219952200522015220252203522045220552206522075220852209522105221152212522135221452215522165221752218522195222052221522225222352224522255222652227522285222952230522315223252233522345223552236522375223852239522405224152242522435224452245522465224752248522495225052251522525225352254522555225652257522585225952260522615226252263522645226552266522675226852269522705227152272522735227452275522765227752278522795228052281522825228352284522855228652287522885228952290522915229252293522945229552296522975229852299523005230152302523035230452305523065230752308523095231052311523125231352314523155231652317523185231952320523215232252323523245232552326523275232852329523305233152332523335233452335523365233752338523395234052341523425234352344523455234652347523485234952350523515235252353523545235552356523575235852359523605236152362523635236452365523665236752368523695237052371523725237352374523755237652377523785237952380523815238252383523845238552386523875238852389523905239152392523935239452395523965239752398523995240052401524025240352404524055240652407524085240952410524115241252413524145241552416524175241852419524205242152422524235242452425524265242752428524295243052431524325243352434524355243652437524385243952440524415244252443524445244552446524475244852449524505245152452524535245452455524565245752458524595246052461524625246352464524655246652467524685246952470524715247252473524745247552476524775247852479524805248152482524835248452485524865248752488524895249052491524925249352494524955249652497524985249952500525015250252503525045250552506525075250852509525105251152512525135251452515525165251752518525195252052521525225252352524525255252652527525285252952530525315253252533525345253552536525375253852539525405254152542525435254452545525465254752548525495255052551525525255352554525555255652557525585255952560525615256252563525645256552566525675256852569525705257152572525735257452575525765257752578525795258052581525825258352584525855258652587525885258952590525915259252593525945259552596525975259852599526005260152602526035260452605526065260752608526095261052611526125261352614526155261652617526185261952620526215262252623526245262552626526275262852629526305263152632526335263452635526365263752638526395264052641526425264352644526455264652647526485264952650526515265252653526545265552656526575265852659526605266152662526635266452665526665266752668526695267052671526725267352674526755267652677526785267952680526815268252683526845268552686526875268852689526905269152692526935269452695526965269752698526995270052701527025270352704527055270652707527085270952710527115271252713527145271552716527175271852719527205272152722527235272452725527265272752728527295273052731527325273352734527355273652737527385273952740527415274252743527445274552746527475274852749527505275152752527535275452755527565275752758527595276052761527625276352764527655276652767527685276952770527715277252773527745277552776527775277852779527805278152782527835278452785527865278752788527895279052791527925279352794527955279652797527985279952800528015280252803528045280552806528075280852809528105281152812528135281452815528165281752818528195282052821528225282352824528255282652827528285282952830528315283252833528345283552836528375283852839528405284152842528435284452845528465284752848528495285052851528525285352854528555285652857528585285952860528615286252863528645286552866528675286852869528705287152872528735287452875528765287752878528795288052881528825288352884528855288652887528885288952890528915289252893528945289552896528975289852899529005290152902529035290452905529065290752908529095291052911529125291352914529155291652917529185291952920529215292252923529245292552926529275292852929529305293152932529335293452935529365293752938529395294052941529425294352944529455294652947529485294952950529515295252953529545295552956529575295852959529605296152962529635296452965529665296752968529695297052971529725297352974529755297652977529785297952980529815298252983529845298552986529875298852989529905299152992529935299452995529965299752998529995300053001530025300353004530055300653007530085300953010530115301253013530145301553016530175301853019530205302153022530235302453025530265302753028530295303053031530325303353034530355303653037530385303953040530415304253043530445304553046530475304853049530505305153052530535305453055530565305753058530595306053061530625306353064530655306653067530685306953070530715307253073530745307553076530775307853079530805308153082530835308453085530865308753088530895309053091530925309353094530955309653097530985309953100531015310253103531045310553106531075310853109531105311153112531135311453115531165311753118531195312053121531225312353124531255312653127531285312953130531315313253133531345313553136531375313853139531405314153142531435314453145531465314753148531495315053151531525315353154531555315653157531585315953160531615316253163531645316553166531675316853169531705317153172531735317453175531765317753178531795318053181531825318353184531855318653187531885318953190531915319253193531945319553196531975319853199532005320153202532035320453205532065320753208532095321053211532125321353214532155321653217532185321953220532215322253223532245322553226532275322853229532305323153232532335323453235532365323753238532395324053241532425324353244532455324653247532485324953250532515325253253532545325553256532575325853259532605326153262532635326453265532665326753268532695327053271532725327353274532755327653277532785327953280532815328253283532845328553286532875328853289532905329153292532935329453295532965329753298532995330053301533025330353304533055330653307533085330953310533115331253313533145331553316533175331853319533205332153322533235332453325533265332753328533295333053331533325333353334533355333653337533385333953340533415334253343533445334553346533475334853349533505335153352533535335453355533565335753358533595336053361533625336353364533655336653367533685336953370533715337253373533745337553376533775337853379533805338153382533835338453385533865338753388533895339053391533925339353394533955339653397533985339953400534015340253403534045340553406534075340853409534105341153412534135341453415534165341753418534195342053421534225342353424534255342653427534285342953430534315343253433534345343553436534375343853439534405344153442534435344453445534465344753448534495345053451534525345353454534555345653457534585345953460534615346253463534645346553466534675346853469534705347153472534735347453475534765347753478534795348053481534825348353484534855348653487534885348953490534915349253493534945349553496534975349853499535005350153502535035350453505535065350753508535095351053511535125351353514535155351653517535185351953520535215352253523535245352553526535275352853529535305353153532535335353453535535365353753538535395354053541535425354353544535455354653547535485354953550535515355253553535545355553556535575355853559535605356153562535635356453565535665356753568535695357053571535725357353574535755357653577535785357953580535815358253583535845358553586535875358853589535905359153592535935359453595535965359753598535995360053601536025360353604536055360653607536085360953610536115361253613536145361553616536175361853619536205362153622536235362453625536265362753628536295363053631536325363353634536355363653637536385363953640536415364253643536445364553646536475364853649536505365153652536535365453655536565365753658536595366053661536625366353664536655366653667536685366953670536715367253673536745367553676536775367853679536805368153682536835368453685536865368753688536895369053691536925369353694536955369653697536985369953700537015370253703537045370553706537075370853709537105371153712537135371453715537165371753718537195372053721537225372353724537255372653727537285372953730537315373253733537345373553736537375373853739537405374153742537435374453745537465374753748537495375053751537525375353754537555375653757537585375953760537615376253763537645376553766537675376853769537705377153772537735377453775537765377753778537795378053781537825378353784537855378653787537885378953790537915379253793537945379553796537975379853799538005380153802538035380453805538065380753808538095381053811538125381353814538155381653817538185381953820538215382253823538245382553826538275382853829538305383153832538335383453835538365383753838538395384053841538425384353844538455384653847538485384953850538515385253853538545385553856538575385853859538605386153862538635386453865538665386753868538695387053871538725387353874538755387653877
  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.268';
  28. var pdfjsBuild = 'a28a710';
  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. // Checks if URLs use one of the whitelisted protocols, e.g. to avoid XSS.
  3880. function isValidProtocol(url) {
  3881. if (!url) {
  3882. return false;
  3883. }
  3884. switch (url.protocol) {
  3885. case 'http:':
  3886. case 'https:':
  3887. case 'ftp:':
  3888. case 'mailto:':
  3889. case 'tel:':
  3890. return true;
  3891. default:
  3892. return false;
  3893. }
  3894. }
  3895. /**
  3896. * Attempts to create a valid absolute URL (utilizing `isValidProtocol`).
  3897. * @param {URL|string} url - An absolute, or relative, URL.
  3898. * @param {URL|string} baseUrl - An absolute URL.
  3899. * @returns Either a valid {URL}, or `null` otherwise.
  3900. */
  3901. function createValidAbsoluteUrl(url, baseUrl) {
  3902. if (!url) {
  3903. return null;
  3904. }
  3905. try {
  3906. var absoluteUrl = baseUrl ? new URL(url, baseUrl) : new URL(url);
  3907. if (isValidProtocol(absoluteUrl)) {
  3908. return absoluteUrl;
  3909. }
  3910. } catch (ex) {
  3911. }
  3912. return null;
  3913. }
  3914. function shadow(obj, prop, value) {
  3915. Object.defineProperty(obj, prop, {
  3916. value: value,
  3917. enumerable: true,
  3918. configurable: true,
  3919. writable: false
  3920. });
  3921. return value;
  3922. }
  3923. function getLookupTableFactory(initializer) {
  3924. var lookup;
  3925. return function () {
  3926. if (initializer) {
  3927. lookup = Object.create(null);
  3928. initializer(lookup);
  3929. initializer = null;
  3930. }
  3931. return lookup;
  3932. };
  3933. }
  3934. var PasswordResponses = {
  3935. NEED_PASSWORD: 1,
  3936. INCORRECT_PASSWORD: 2
  3937. };
  3938. var PasswordException = function PasswordExceptionClosure() {
  3939. function PasswordException(msg, code) {
  3940. this.name = 'PasswordException';
  3941. this.message = msg;
  3942. this.code = code;
  3943. }
  3944. PasswordException.prototype = new Error();
  3945. PasswordException.constructor = PasswordException;
  3946. return PasswordException;
  3947. }();
  3948. var UnknownErrorException = function UnknownErrorExceptionClosure() {
  3949. function UnknownErrorException(msg, details) {
  3950. this.name = 'UnknownErrorException';
  3951. this.message = msg;
  3952. this.details = details;
  3953. }
  3954. UnknownErrorException.prototype = new Error();
  3955. UnknownErrorException.constructor = UnknownErrorException;
  3956. return UnknownErrorException;
  3957. }();
  3958. var InvalidPDFException = function InvalidPDFExceptionClosure() {
  3959. function InvalidPDFException(msg) {
  3960. this.name = 'InvalidPDFException';
  3961. this.message = msg;
  3962. }
  3963. InvalidPDFException.prototype = new Error();
  3964. InvalidPDFException.constructor = InvalidPDFException;
  3965. return InvalidPDFException;
  3966. }();
  3967. var MissingPDFException = function MissingPDFExceptionClosure() {
  3968. function MissingPDFException(msg) {
  3969. this.name = 'MissingPDFException';
  3970. this.message = msg;
  3971. }
  3972. MissingPDFException.prototype = new Error();
  3973. MissingPDFException.constructor = MissingPDFException;
  3974. return MissingPDFException;
  3975. }();
  3976. var UnexpectedResponseException = function UnexpectedResponseExceptionClosure() {
  3977. function UnexpectedResponseException(msg, status) {
  3978. this.name = 'UnexpectedResponseException';
  3979. this.message = msg;
  3980. this.status = status;
  3981. }
  3982. UnexpectedResponseException.prototype = new Error();
  3983. UnexpectedResponseException.constructor = UnexpectedResponseException;
  3984. return UnexpectedResponseException;
  3985. }();
  3986. var NotImplementedException = function NotImplementedExceptionClosure() {
  3987. function NotImplementedException(msg) {
  3988. this.message = msg;
  3989. }
  3990. NotImplementedException.prototype = new Error();
  3991. NotImplementedException.prototype.name = 'NotImplementedException';
  3992. NotImplementedException.constructor = NotImplementedException;
  3993. return NotImplementedException;
  3994. }();
  3995. var MissingDataException = function MissingDataExceptionClosure() {
  3996. function MissingDataException(begin, end) {
  3997. this.begin = begin;
  3998. this.end = end;
  3999. this.message = 'Missing data [' + begin + ', ' + end + ')';
  4000. }
  4001. MissingDataException.prototype = new Error();
  4002. MissingDataException.prototype.name = 'MissingDataException';
  4003. MissingDataException.constructor = MissingDataException;
  4004. return MissingDataException;
  4005. }();
  4006. var XRefParseException = function XRefParseExceptionClosure() {
  4007. function XRefParseException(msg) {
  4008. this.message = msg;
  4009. }
  4010. XRefParseException.prototype = new Error();
  4011. XRefParseException.prototype.name = 'XRefParseException';
  4012. XRefParseException.constructor = XRefParseException;
  4013. return XRefParseException;
  4014. }();
  4015. var NullCharactersRegExp = /\x00/g;
  4016. function removeNullCharacters(str) {
  4017. if (typeof str !== 'string') {
  4018. warn('The argument for removeNullCharacters must be a string.');
  4019. return str;
  4020. }
  4021. return str.replace(NullCharactersRegExp, '');
  4022. }
  4023. function bytesToString(bytes) {
  4024. assert(bytes !== null && typeof bytes === 'object' && bytes.length !== undefined, 'Invalid argument for bytesToString');
  4025. var length = bytes.length;
  4026. var MAX_ARGUMENT_COUNT = 8192;
  4027. if (length < MAX_ARGUMENT_COUNT) {
  4028. return String.fromCharCode.apply(null, bytes);
  4029. }
  4030. var strBuf = [];
  4031. for (var i = 0; i < length; i += MAX_ARGUMENT_COUNT) {
  4032. var chunkEnd = Math.min(i + MAX_ARGUMENT_COUNT, length);
  4033. var chunk = bytes.subarray(i, chunkEnd);
  4034. strBuf.push(String.fromCharCode.apply(null, chunk));
  4035. }
  4036. return strBuf.join('');
  4037. }
  4038. function stringToBytes(str) {
  4039. assert(typeof str === 'string', 'Invalid argument for stringToBytes');
  4040. var length = str.length;
  4041. var bytes = new Uint8Array(length);
  4042. for (var i = 0; i < length; ++i) {
  4043. bytes[i] = str.charCodeAt(i) & 0xFF;
  4044. }
  4045. return bytes;
  4046. }
  4047. /**
  4048. * Gets length of the array (Array, Uint8Array, or string) in bytes.
  4049. * @param {Array|Uint8Array|string} arr
  4050. * @returns {number}
  4051. */
  4052. function arrayByteLength(arr) {
  4053. if (arr.length !== undefined) {
  4054. return arr.length;
  4055. }
  4056. assert(arr.byteLength !== undefined);
  4057. return arr.byteLength;
  4058. }
  4059. /**
  4060. * Combines array items (arrays) into single Uint8Array object.
  4061. * @param {Array} arr - the array of the arrays (Array, Uint8Array, or string).
  4062. * @returns {Uint8Array}
  4063. */
  4064. function arraysToBytes(arr) {
  4065. // Shortcut: if first and only item is Uint8Array, return it.
  4066. if (arr.length === 1 && arr[0] instanceof Uint8Array) {
  4067. return arr[0];
  4068. }
  4069. var resultLength = 0;
  4070. var i, ii = arr.length;
  4071. var item, itemLength;
  4072. for (i = 0; i < ii; i++) {
  4073. item = arr[i];
  4074. itemLength = arrayByteLength(item);
  4075. resultLength += itemLength;
  4076. }
  4077. var pos = 0;
  4078. var data = new Uint8Array(resultLength);
  4079. for (i = 0; i < ii; i++) {
  4080. item = arr[i];
  4081. if (!(item instanceof Uint8Array)) {
  4082. if (typeof item === 'string') {
  4083. item = stringToBytes(item);
  4084. } else {
  4085. item = new Uint8Array(item);
  4086. }
  4087. }
  4088. itemLength = item.byteLength;
  4089. data.set(item, pos);
  4090. pos += itemLength;
  4091. }
  4092. return data;
  4093. }
  4094. function string32(value) {
  4095. return String.fromCharCode(value >> 24 & 0xff, value >> 16 & 0xff, value >> 8 & 0xff, value & 0xff);
  4096. }
  4097. function log2(x) {
  4098. var n = 1, i = 0;
  4099. while (x > n) {
  4100. n <<= 1;
  4101. i++;
  4102. }
  4103. return i;
  4104. }
  4105. function readInt8(data, start) {
  4106. return data[start] << 24 >> 24;
  4107. }
  4108. function readUint16(data, offset) {
  4109. return data[offset] << 8 | data[offset + 1];
  4110. }
  4111. function readUint32(data, offset) {
  4112. return (data[offset] << 24 | data[offset + 1] << 16 | data[offset + 2] << 8 | data[offset + 3]) >>> 0;
  4113. }
  4114. // Lazy test the endianness of the platform
  4115. // NOTE: This will be 'true' for simulated TypedArrays
  4116. function isLittleEndian() {
  4117. var buffer8 = new Uint8Array(2);
  4118. buffer8[0] = 1;
  4119. var buffer16 = new Uint16Array(buffer8.buffer);
  4120. return buffer16[0] === 1;
  4121. }
  4122. // Checks if it's possible to eval JS expressions.
  4123. function isEvalSupported() {
  4124. try {
  4125. new Function('');
  4126. return true;
  4127. } catch (e) {
  4128. return false;
  4129. }
  4130. }
  4131. var Uint32ArrayView = function Uint32ArrayViewClosure() {
  4132. function Uint32ArrayView(buffer, length) {
  4133. this.buffer = buffer;
  4134. this.byteLength = buffer.length;
  4135. this.length = length === undefined ? this.byteLength >> 2 : length;
  4136. ensureUint32ArrayViewProps(this.length);
  4137. }
  4138. Uint32ArrayView.prototype = Object.create(null);
  4139. var uint32ArrayViewSetters = 0;
  4140. function createUint32ArrayProp(index) {
  4141. return {
  4142. get: function () {
  4143. var buffer = this.buffer, offset = index << 2;
  4144. return (buffer[offset] | buffer[offset + 1] << 8 | buffer[offset + 2] << 16 | buffer[offset + 3] << 24) >>> 0;
  4145. },
  4146. set: function (value) {
  4147. var buffer = this.buffer, offset = index << 2;
  4148. buffer[offset] = value & 255;
  4149. buffer[offset + 1] = value >> 8 & 255;
  4150. buffer[offset + 2] = value >> 16 & 255;
  4151. buffer[offset + 3] = value >>> 24 & 255;
  4152. }
  4153. };
  4154. }
  4155. function ensureUint32ArrayViewProps(length) {
  4156. while (uint32ArrayViewSetters < length) {
  4157. Object.defineProperty(Uint32ArrayView.prototype, uint32ArrayViewSetters, createUint32ArrayProp(uint32ArrayViewSetters));
  4158. uint32ArrayViewSetters++;
  4159. }
  4160. }
  4161. return Uint32ArrayView;
  4162. }();
  4163. exports.Uint32ArrayView = Uint32ArrayView;
  4164. var IDENTITY_MATRIX = [
  4165. 1,
  4166. 0,
  4167. 0,
  4168. 1,
  4169. 0,
  4170. 0
  4171. ];
  4172. var Util = function UtilClosure() {
  4173. function Util() {
  4174. }
  4175. var rgbBuf = [
  4176. 'rgb(',
  4177. 0,
  4178. ',',
  4179. 0,
  4180. ',',
  4181. 0,
  4182. ')'
  4183. ];
  4184. // makeCssRgb() can be called thousands of times. Using |rgbBuf| avoids
  4185. // creating many intermediate strings.
  4186. Util.makeCssRgb = function Util_makeCssRgb(r, g, b) {
  4187. rgbBuf[1] = r;
  4188. rgbBuf[3] = g;
  4189. rgbBuf[5] = b;
  4190. return rgbBuf.join('');
  4191. };
  4192. // Concatenates two transformation matrices together and returns the result.
  4193. Util.transform = function Util_transform(m1, m2) {
  4194. return [
  4195. m1[0] * m2[0] + m1[2] * m2[1],
  4196. m1[1] * m2[0] + m1[3] * m2[1],
  4197. m1[0] * m2[2] + m1[2] * m2[3],
  4198. m1[1] * m2[2] + m1[3] * m2[3],
  4199. m1[0] * m2[4] + m1[2] * m2[5] + m1[4],
  4200. m1[1] * m2[4] + m1[3] * m2[5] + m1[5]
  4201. ];
  4202. };
  4203. // For 2d affine transforms
  4204. Util.applyTransform = function Util_applyTransform(p, m) {
  4205. var xt = p[0] * m[0] + p[1] * m[2] + m[4];
  4206. var yt = p[0] * m[1] + p[1] * m[3] + m[5];
  4207. return [
  4208. xt,
  4209. yt
  4210. ];
  4211. };
  4212. Util.applyInverseTransform = function Util_applyInverseTransform(p, m) {
  4213. var d = m[0] * m[3] - m[1] * m[2];
  4214. var xt = (p[0] * m[3] - p[1] * m[2] + m[2] * m[5] - m[4] * m[3]) / d;
  4215. var yt = (-p[0] * m[1] + p[1] * m[0] + m[4] * m[1] - m[5] * m[0]) / d;
  4216. return [
  4217. xt,
  4218. yt
  4219. ];
  4220. };
  4221. // Applies the transform to the rectangle and finds the minimum axially
  4222. // aligned bounding box.
  4223. Util.getAxialAlignedBoundingBox = function Util_getAxialAlignedBoundingBox(r, m) {
  4224. var p1 = Util.applyTransform(r, m);
  4225. var p2 = Util.applyTransform(r.slice(2, 4), m);
  4226. var p3 = Util.applyTransform([
  4227. r[0],
  4228. r[3]
  4229. ], m);
  4230. var p4 = Util.applyTransform([
  4231. r[2],
  4232. r[1]
  4233. ], m);
  4234. return [
  4235. Math.min(p1[0], p2[0], p3[0], p4[0]),
  4236. Math.min(p1[1], p2[1], p3[1], p4[1]),
  4237. Math.max(p1[0], p2[0], p3[0], p4[0]),
  4238. Math.max(p1[1], p2[1], p3[1], p4[1])
  4239. ];
  4240. };
  4241. Util.inverseTransform = function Util_inverseTransform(m) {
  4242. var d = m[0] * m[3] - m[1] * m[2];
  4243. return [
  4244. m[3] / d,
  4245. -m[1] / d,
  4246. -m[2] / d,
  4247. m[0] / d,
  4248. (m[2] * m[5] - m[4] * m[3]) / d,
  4249. (m[4] * m[1] - m[5] * m[0]) / d
  4250. ];
  4251. };
  4252. // Apply a generic 3d matrix M on a 3-vector v:
  4253. // | a b c | | X |
  4254. // | d e f | x | Y |
  4255. // | g h i | | Z |
  4256. // M is assumed to be serialized as [a,b,c,d,e,f,g,h,i],
  4257. // with v as [X,Y,Z]
  4258. Util.apply3dTransform = function Util_apply3dTransform(m, v) {
  4259. return [
  4260. m[0] * v[0] + m[1] * v[1] + m[2] * v[2],
  4261. m[3] * v[0] + m[4] * v[1] + m[5] * v[2],
  4262. m[6] * v[0] + m[7] * v[1] + m[8] * v[2]
  4263. ];
  4264. };
  4265. // This calculation uses Singular Value Decomposition.
  4266. // The SVD can be represented with formula A = USV. We are interested in the
  4267. // matrix S here because it represents the scale values.
  4268. Util.singularValueDecompose2dScale = function Util_singularValueDecompose2dScale(m) {
  4269. var transpose = [
  4270. m[0],
  4271. m[2],
  4272. m[1],
  4273. m[3]
  4274. ];
  4275. // Multiply matrix m with its transpose.
  4276. var a = m[0] * transpose[0] + m[1] * transpose[2];
  4277. var b = m[0] * transpose[1] + m[1] * transpose[3];
  4278. var c = m[2] * transpose[0] + m[3] * transpose[2];
  4279. var d = m[2] * transpose[1] + m[3] * transpose[3];
  4280. // Solve the second degree polynomial to get roots.
  4281. var first = (a + d) / 2;
  4282. var second = Math.sqrt((a + d) * (a + d) - 4 * (a * d - c * b)) / 2;
  4283. var sx = first + second || 1;
  4284. var sy = first - second || 1;
  4285. // Scale values are the square roots of the eigenvalues.
  4286. return [
  4287. Math.sqrt(sx),
  4288. Math.sqrt(sy)
  4289. ];
  4290. };
  4291. // Normalize rectangle rect=[x1, y1, x2, y2] so that (x1,y1) < (x2,y2)
  4292. // For coordinate systems whose origin lies in the bottom-left, this
  4293. // means normalization to (BL,TR) ordering. For systems with origin in the
  4294. // top-left, this means (TL,BR) ordering.
  4295. Util.normalizeRect = function Util_normalizeRect(rect) {
  4296. var r = rect.slice(0);
  4297. // clone rect
  4298. if (rect[0] > rect[2]) {
  4299. r[0] = rect[2];
  4300. r[2] = rect[0];
  4301. }
  4302. if (rect[1] > rect[3]) {
  4303. r[1] = rect[3];
  4304. r[3] = rect[1];
  4305. }
  4306. return r;
  4307. };
  4308. // Returns a rectangle [x1, y1, x2, y2] corresponding to the
  4309. // intersection of rect1 and rect2. If no intersection, returns 'false'
  4310. // The rectangle coordinates of rect1, rect2 should be [x1, y1, x2, y2]
  4311. Util.intersect = function Util_intersect(rect1, rect2) {
  4312. function compare(a, b) {
  4313. return a - b;
  4314. }
  4315. // Order points along the axes
  4316. var orderedX = [
  4317. rect1[0],
  4318. rect1[2],
  4319. rect2[0],
  4320. rect2[2]
  4321. ].sort(compare), orderedY = [
  4322. rect1[1],
  4323. rect1[3],
  4324. rect2[1],
  4325. rect2[3]
  4326. ].sort(compare), result = [];
  4327. rect1 = Util.normalizeRect(rect1);
  4328. rect2 = Util.normalizeRect(rect2);
  4329. // X: first and second points belong to different rectangles?
  4330. if (orderedX[0] === rect1[0] && orderedX[1] === rect2[0] || orderedX[0] === rect2[0] && orderedX[1] === rect1[0]) {
  4331. // Intersection must be between second and third points
  4332. result[0] = orderedX[1];
  4333. result[2] = orderedX[2];
  4334. } else {
  4335. return false;
  4336. }
  4337. // Y: first and second points belong to different rectangles?
  4338. if (orderedY[0] === rect1[1] && orderedY[1] === rect2[1] || orderedY[0] === rect2[1] && orderedY[1] === rect1[1]) {
  4339. // Intersection must be between second and third points
  4340. result[1] = orderedY[1];
  4341. result[3] = orderedY[2];
  4342. } else {
  4343. return false;
  4344. }
  4345. return result;
  4346. };
  4347. Util.sign = function Util_sign(num) {
  4348. return num < 0 ? -1 : 1;
  4349. };
  4350. var ROMAN_NUMBER_MAP = [
  4351. '',
  4352. 'C',
  4353. 'CC',
  4354. 'CCC',
  4355. 'CD',
  4356. 'D',
  4357. 'DC',
  4358. 'DCC',
  4359. 'DCCC',
  4360. 'CM',
  4361. '',
  4362. 'X',
  4363. 'XX',
  4364. 'XXX',
  4365. 'XL',
  4366. 'L',
  4367. 'LX',
  4368. 'LXX',
  4369. 'LXXX',
  4370. 'XC',
  4371. '',
  4372. 'I',
  4373. 'II',
  4374. 'III',
  4375. 'IV',
  4376. 'V',
  4377. 'VI',
  4378. 'VII',
  4379. 'VIII',
  4380. 'IX'
  4381. ];
  4382. /**
  4383. * Converts positive integers to (upper case) Roman numerals.
  4384. * @param {integer} number - The number that should be converted.
  4385. * @param {boolean} lowerCase - Indicates if the result should be converted
  4386. * to lower case letters. The default is false.
  4387. * @return {string} The resulting Roman number.
  4388. */
  4389. Util.toRoman = function Util_toRoman(number, lowerCase) {
  4390. assert(isInt(number) && number > 0, 'The number should be a positive integer.');
  4391. var pos, romanBuf = [];
  4392. // Thousands
  4393. while (number >= 1000) {
  4394. number -= 1000;
  4395. romanBuf.push('M');
  4396. }
  4397. // Hundreds
  4398. pos = number / 100 | 0;
  4399. number %= 100;
  4400. romanBuf.push(ROMAN_NUMBER_MAP[pos]);
  4401. // Tens
  4402. pos = number / 10 | 0;
  4403. number %= 10;
  4404. romanBuf.push(ROMAN_NUMBER_MAP[10 + pos]);
  4405. // Ones
  4406. romanBuf.push(ROMAN_NUMBER_MAP[20 + number]);
  4407. var romanStr = romanBuf.join('');
  4408. return lowerCase ? romanStr.toLowerCase() : romanStr;
  4409. };
  4410. Util.appendToArray = function Util_appendToArray(arr1, arr2) {
  4411. Array.prototype.push.apply(arr1, arr2);
  4412. };
  4413. Util.prependToArray = function Util_prependToArray(arr1, arr2) {
  4414. Array.prototype.unshift.apply(arr1, arr2);
  4415. };
  4416. Util.extendObj = function extendObj(obj1, obj2) {
  4417. for (var key in obj2) {
  4418. obj1[key] = obj2[key];
  4419. }
  4420. };
  4421. Util.getInheritableProperty = function Util_getInheritableProperty(dict, name, getArray) {
  4422. while (dict && !dict.has(name)) {
  4423. dict = dict.get('Parent');
  4424. }
  4425. if (!dict) {
  4426. return null;
  4427. }
  4428. return getArray ? dict.getArray(name) : dict.get(name);
  4429. };
  4430. Util.inherit = function Util_inherit(sub, base, prototype) {
  4431. sub.prototype = Object.create(base.prototype);
  4432. sub.prototype.constructor = sub;
  4433. for (var prop in prototype) {
  4434. sub.prototype[prop] = prototype[prop];
  4435. }
  4436. };
  4437. Util.loadScript = function Util_loadScript(src, callback) {
  4438. var script = document.createElement('script');
  4439. var loaded = false;
  4440. script.setAttribute('src', src);
  4441. if (callback) {
  4442. script.onload = function () {
  4443. if (!loaded) {
  4444. callback();
  4445. }
  4446. loaded = true;
  4447. };
  4448. }
  4449. document.getElementsByTagName('head')[0].appendChild(script);
  4450. };
  4451. return Util;
  4452. }();
  4453. /**
  4454. * PDF page viewport created based on scale, rotation and offset.
  4455. * @class
  4456. * @alias PageViewport
  4457. */
  4458. var PageViewport = function PageViewportClosure() {
  4459. /**
  4460. * @constructor
  4461. * @private
  4462. * @param viewBox {Array} xMin, yMin, xMax and yMax coordinates.
  4463. * @param scale {number} scale of the viewport.
  4464. * @param rotation {number} rotations of the viewport in degrees.
  4465. * @param offsetX {number} offset X
  4466. * @param offsetY {number} offset Y
  4467. * @param dontFlip {boolean} if true, axis Y will not be flipped.
  4468. */
  4469. function PageViewport(viewBox, scale, rotation, offsetX, offsetY, dontFlip) {
  4470. this.viewBox = viewBox;
  4471. this.scale = scale;
  4472. this.rotation = rotation;
  4473. this.offsetX = offsetX;
  4474. this.offsetY = offsetY;
  4475. // creating transform to convert pdf coordinate system to the normal
  4476. // canvas like coordinates taking in account scale and rotation
  4477. var centerX = (viewBox[2] + viewBox[0]) / 2;
  4478. var centerY = (viewBox[3] + viewBox[1]) / 2;
  4479. var rotateA, rotateB, rotateC, rotateD;
  4480. rotation = rotation % 360;
  4481. rotation = rotation < 0 ? rotation + 360 : rotation;
  4482. switch (rotation) {
  4483. case 180:
  4484. rotateA = -1;
  4485. rotateB = 0;
  4486. rotateC = 0;
  4487. rotateD = 1;
  4488. break;
  4489. case 90:
  4490. rotateA = 0;
  4491. rotateB = 1;
  4492. rotateC = 1;
  4493. rotateD = 0;
  4494. break;
  4495. case 270:
  4496. rotateA = 0;
  4497. rotateB = -1;
  4498. rotateC = -1;
  4499. rotateD = 0;
  4500. break;
  4501. //case 0:
  4502. default:
  4503. rotateA = 1;
  4504. rotateB = 0;
  4505. rotateC = 0;
  4506. rotateD = -1;
  4507. break;
  4508. }
  4509. if (dontFlip) {
  4510. rotateC = -rotateC;
  4511. rotateD = -rotateD;
  4512. }
  4513. var offsetCanvasX, offsetCanvasY;
  4514. var width, height;
  4515. if (rotateA === 0) {
  4516. offsetCanvasX = Math.abs(centerY - viewBox[1]) * scale + offsetX;
  4517. offsetCanvasY = Math.abs(centerX - viewBox[0]) * scale + offsetY;
  4518. width = Math.abs(viewBox[3] - viewBox[1]) * scale;
  4519. height = Math.abs(viewBox[2] - viewBox[0]) * scale;
  4520. } else {
  4521. offsetCanvasX = Math.abs(centerX - viewBox[0]) * scale + offsetX;
  4522. offsetCanvasY = Math.abs(centerY - viewBox[1]) * scale + offsetY;
  4523. width = Math.abs(viewBox[2] - viewBox[0]) * scale;
  4524. height = Math.abs(viewBox[3] - viewBox[1]) * scale;
  4525. }
  4526. // creating transform for the following operations:
  4527. // translate(-centerX, -centerY), rotate and flip vertically,
  4528. // scale, and translate(offsetCanvasX, offsetCanvasY)
  4529. this.transform = [
  4530. rotateA * scale,
  4531. rotateB * scale,
  4532. rotateC * scale,
  4533. rotateD * scale,
  4534. offsetCanvasX - rotateA * scale * centerX - rotateC * scale * centerY,
  4535. offsetCanvasY - rotateB * scale * centerX - rotateD * scale * centerY
  4536. ];
  4537. this.width = width;
  4538. this.height = height;
  4539. this.fontScale = scale;
  4540. }
  4541. PageViewport.prototype = /** @lends PageViewport.prototype */
  4542. {
  4543. /**
  4544. * Clones viewport with additional properties.
  4545. * @param args {Object} (optional) If specified, may contain the 'scale' or
  4546. * 'rotation' properties to override the corresponding properties in
  4547. * the cloned viewport.
  4548. * @returns {PageViewport} Cloned viewport.
  4549. */
  4550. clone: function PageViewPort_clone(args) {
  4551. args = args || {};
  4552. var scale = 'scale' in args ? args.scale : this.scale;
  4553. var rotation = 'rotation' in args ? args.rotation : this.rotation;
  4554. return new PageViewport(this.viewBox.slice(), scale, rotation, this.offsetX, this.offsetY, args.dontFlip);
  4555. },
  4556. /**
  4557. * Converts PDF point to the viewport coordinates. For examples, useful for
  4558. * converting PDF location into canvas pixel coordinates.
  4559. * @param x {number} X coordinate.
  4560. * @param y {number} Y coordinate.
  4561. * @returns {Object} Object that contains 'x' and 'y' properties of the
  4562. * point in the viewport coordinate space.
  4563. * @see {@link convertToPdfPoint}
  4564. * @see {@link convertToViewportRectangle}
  4565. */
  4566. convertToViewportPoint: function PageViewport_convertToViewportPoint(x, y) {
  4567. return Util.applyTransform([
  4568. x,
  4569. y
  4570. ], this.transform);
  4571. },
  4572. /**
  4573. * Converts PDF rectangle to the viewport coordinates.
  4574. * @param rect {Array} xMin, yMin, xMax and yMax coordinates.
  4575. * @returns {Array} Contains corresponding coordinates of the rectangle
  4576. * in the viewport coordinate space.
  4577. * @see {@link convertToViewportPoint}
  4578. */
  4579. convertToViewportRectangle: function PageViewport_convertToViewportRectangle(rect) {
  4580. var tl = Util.applyTransform([
  4581. rect[0],
  4582. rect[1]
  4583. ], this.transform);
  4584. var br = Util.applyTransform([
  4585. rect[2],
  4586. rect[3]
  4587. ], this.transform);
  4588. return [
  4589. tl[0],
  4590. tl[1],
  4591. br[0],
  4592. br[1]
  4593. ];
  4594. },
  4595. /**
  4596. * Converts viewport coordinates to the PDF location. For examples, useful
  4597. * for converting canvas pixel location into PDF one.
  4598. * @param x {number} X coordinate.
  4599. * @param y {number} Y coordinate.
  4600. * @returns {Object} Object that contains 'x' and 'y' properties of the
  4601. * point in the PDF coordinate space.
  4602. * @see {@link convertToViewportPoint}
  4603. */
  4604. convertToPdfPoint: function PageViewport_convertToPdfPoint(x, y) {
  4605. return Util.applyInverseTransform([
  4606. x,
  4607. y
  4608. ], this.transform);
  4609. }
  4610. };
  4611. return PageViewport;
  4612. }();
  4613. var PDFStringTranslateTable = [
  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. 0,
  4627. 0,
  4628. 0,
  4629. 0,
  4630. 0,
  4631. 0,
  4632. 0,
  4633. 0,
  4634. 0,
  4635. 0,
  4636. 0,
  4637. 0,
  4638. 0x2D8,
  4639. 0x2C7,
  4640. 0x2C6,
  4641. 0x2D9,
  4642. 0x2DD,
  4643. 0x2DB,
  4644. 0x2DA,
  4645. 0x2DC,
  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. 0,
  4731. 0,
  4732. 0,
  4733. 0,
  4734. 0,
  4735. 0,
  4736. 0,
  4737. 0,
  4738. 0,
  4739. 0,
  4740. 0,
  4741. 0,
  4742. 0x2022,
  4743. 0x2020,
  4744. 0x2021,
  4745. 0x2026,
  4746. 0x2014,
  4747. 0x2013,
  4748. 0x192,
  4749. 0x2044,
  4750. 0x2039,
  4751. 0x203A,
  4752. 0x2212,
  4753. 0x2030,
  4754. 0x201E,
  4755. 0x201C,
  4756. 0x201D,
  4757. 0x2018,
  4758. 0x2019,
  4759. 0x201A,
  4760. 0x2122,
  4761. 0xFB01,
  4762. 0xFB02,
  4763. 0x141,
  4764. 0x152,
  4765. 0x160,
  4766. 0x178,
  4767. 0x17D,
  4768. 0x131,
  4769. 0x142,
  4770. 0x153,
  4771. 0x161,
  4772. 0x17E,
  4773. 0,
  4774. 0x20AC
  4775. ];
  4776. function stringToPDFString(str) {
  4777. var i, n = str.length, strBuf = [];
  4778. if (str[0] === '\xFE' && str[1] === '\xFF') {
  4779. // UTF16BE BOM
  4780. for (i = 2; i < n; i += 2) {
  4781. strBuf.push(String.fromCharCode(str.charCodeAt(i) << 8 | str.charCodeAt(i + 1)));
  4782. }
  4783. } else {
  4784. for (i = 0; i < n; ++i) {
  4785. var code = PDFStringTranslateTable[str.charCodeAt(i)];
  4786. strBuf.push(code ? String.fromCharCode(code) : str.charAt(i));
  4787. }
  4788. }
  4789. return strBuf.join('');
  4790. }
  4791. function stringToUTF8String(str) {
  4792. return decodeURIComponent(escape(str));
  4793. }
  4794. function utf8StringToString(str) {
  4795. return unescape(encodeURIComponent(str));
  4796. }
  4797. function isEmptyObj(obj) {
  4798. for (var key in obj) {
  4799. return false;
  4800. }
  4801. return true;
  4802. }
  4803. function isBool(v) {
  4804. return typeof v === 'boolean';
  4805. }
  4806. function isInt(v) {
  4807. return typeof v === 'number' && (v | 0) === v;
  4808. }
  4809. function isNum(v) {
  4810. return typeof v === 'number';
  4811. }
  4812. function isString(v) {
  4813. return typeof v === 'string';
  4814. }
  4815. function isArray(v) {
  4816. return v instanceof Array;
  4817. }
  4818. function isArrayBuffer(v) {
  4819. return typeof v === 'object' && v !== null && v.byteLength !== undefined;
  4820. }
  4821. // Checks if ch is one of the following characters: SPACE, TAB, CR or LF.
  4822. function isSpace(ch) {
  4823. return ch === 0x20 || ch === 0x09 || ch === 0x0D || ch === 0x0A;
  4824. }
  4825. /**
  4826. * Promise Capability object.
  4827. *
  4828. * @typedef {Object} PromiseCapability
  4829. * @property {Promise} promise - A promise object.
  4830. * @property {function} resolve - Fulfills the promise.
  4831. * @property {function} reject - Rejects the promise.
  4832. */
  4833. /**
  4834. * Creates a promise capability object.
  4835. * @alias createPromiseCapability
  4836. *
  4837. * @return {PromiseCapability} A capability object contains:
  4838. * - a Promise, resolve and reject methods.
  4839. */
  4840. function createPromiseCapability() {
  4841. var capability = {};
  4842. capability.promise = new Promise(function (resolve, reject) {
  4843. capability.resolve = resolve;
  4844. capability.reject = reject;
  4845. });
  4846. return capability;
  4847. }
  4848. /**
  4849. * Polyfill for Promises:
  4850. * The following promise implementation tries to generally implement the
  4851. * Promise/A+ spec. Some notable differences from other promise libraries are:
  4852. * - There currently isn't a separate deferred and promise object.
  4853. * - Unhandled rejections eventually show an error if they aren't handled.
  4854. *
  4855. * Based off of the work in:
  4856. * https://bugzilla.mozilla.org/show_bug.cgi?id=810490
  4857. */
  4858. (function PromiseClosure() {
  4859. if (globalScope.Promise) {
  4860. // Promises existing in the DOM/Worker, checking presence of all/resolve
  4861. if (typeof globalScope.Promise.all !== 'function') {
  4862. globalScope.Promise.all = function (iterable) {
  4863. var count = 0, results = [], resolve, reject;
  4864. var promise = new globalScope.Promise(function (resolve_, reject_) {
  4865. resolve = resolve_;
  4866. reject = reject_;
  4867. });
  4868. iterable.forEach(function (p, i) {
  4869. count++;
  4870. p.then(function (result) {
  4871. results[i] = result;
  4872. count--;
  4873. if (count === 0) {
  4874. resolve(results);
  4875. }
  4876. }, reject);
  4877. });
  4878. if (count === 0) {
  4879. resolve(results);
  4880. }
  4881. return promise;
  4882. };
  4883. }
  4884. if (typeof globalScope.Promise.resolve !== 'function') {
  4885. globalScope.Promise.resolve = function (value) {
  4886. return new globalScope.Promise(function (resolve) {
  4887. resolve(value);
  4888. });
  4889. };
  4890. }
  4891. if (typeof globalScope.Promise.reject !== 'function') {
  4892. globalScope.Promise.reject = function (reason) {
  4893. return new globalScope.Promise(function (resolve, reject) {
  4894. reject(reason);
  4895. });
  4896. };
  4897. }
  4898. if (typeof globalScope.Promise.prototype.catch !== 'function') {
  4899. globalScope.Promise.prototype.catch = function (onReject) {
  4900. return globalScope.Promise.prototype.then(undefined, onReject);
  4901. };
  4902. }
  4903. return;
  4904. }
  4905. var STATUS_PENDING = 0;
  4906. var STATUS_RESOLVED = 1;
  4907. var STATUS_REJECTED = 2;
  4908. // In an attempt to avoid silent exceptions, unhandled rejections are
  4909. // tracked and if they aren't handled in a certain amount of time an
  4910. // error is logged.
  4911. var REJECTION_TIMEOUT = 500;
  4912. var HandlerManager = {
  4913. handlers: [],
  4914. running: false,
  4915. unhandledRejections: [],
  4916. pendingRejectionCheck: false,
  4917. scheduleHandlers: function scheduleHandlers(promise) {
  4918. if (promise._status === STATUS_PENDING) {
  4919. return;
  4920. }
  4921. this.handlers = this.handlers.concat(promise._handlers);
  4922. promise._handlers = [];
  4923. if (this.running) {
  4924. return;
  4925. }
  4926. this.running = true;
  4927. setTimeout(this.runHandlers.bind(this), 0);
  4928. },
  4929. runHandlers: function runHandlers() {
  4930. var RUN_TIMEOUT = 1;
  4931. // ms
  4932. var timeoutAt = Date.now() + RUN_TIMEOUT;
  4933. while (this.handlers.length > 0) {
  4934. var handler = this.handlers.shift();
  4935. var nextStatus = handler.thisPromise._status;
  4936. var nextValue = handler.thisPromise._value;
  4937. try {
  4938. if (nextStatus === STATUS_RESOLVED) {
  4939. if (typeof handler.onResolve === 'function') {
  4940. nextValue = handler.onResolve(nextValue);
  4941. }
  4942. } else if (typeof handler.onReject === 'function') {
  4943. nextValue = handler.onReject(nextValue);
  4944. nextStatus = STATUS_RESOLVED;
  4945. if (handler.thisPromise._unhandledRejection) {
  4946. this.removeUnhandeledRejection(handler.thisPromise);
  4947. }
  4948. }
  4949. } catch (ex) {
  4950. nextStatus = STATUS_REJECTED;
  4951. nextValue = ex;
  4952. }
  4953. handler.nextPromise._updateStatus(nextStatus, nextValue);
  4954. if (Date.now() >= timeoutAt) {
  4955. break;
  4956. }
  4957. }
  4958. if (this.handlers.length > 0) {
  4959. setTimeout(this.runHandlers.bind(this), 0);
  4960. return;
  4961. }
  4962. this.running = false;
  4963. },
  4964. addUnhandledRejection: function addUnhandledRejection(promise) {
  4965. this.unhandledRejections.push({
  4966. promise: promise,
  4967. time: Date.now()
  4968. });
  4969. this.scheduleRejectionCheck();
  4970. },
  4971. removeUnhandeledRejection: function removeUnhandeledRejection(promise) {
  4972. promise._unhandledRejection = false;
  4973. for (var i = 0; i < this.unhandledRejections.length; i++) {
  4974. if (this.unhandledRejections[i].promise === promise) {
  4975. this.unhandledRejections.splice(i);
  4976. i--;
  4977. }
  4978. }
  4979. },
  4980. scheduleRejectionCheck: function scheduleRejectionCheck() {
  4981. if (this.pendingRejectionCheck) {
  4982. return;
  4983. }
  4984. this.pendingRejectionCheck = true;
  4985. setTimeout(function rejectionCheck() {
  4986. this.pendingRejectionCheck = false;
  4987. var now = Date.now();
  4988. for (var i = 0; i < this.unhandledRejections.length; i++) {
  4989. if (now - this.unhandledRejections[i].time > REJECTION_TIMEOUT) {
  4990. var unhandled = this.unhandledRejections[i].promise._value;
  4991. var msg = 'Unhandled rejection: ' + unhandled;
  4992. if (unhandled.stack) {
  4993. msg += '\n' + unhandled.stack;
  4994. }
  4995. warn(msg);
  4996. this.unhandledRejections.splice(i);
  4997. i--;
  4998. }
  4999. }
  5000. if (this.unhandledRejections.length) {
  5001. this.scheduleRejectionCheck();
  5002. }
  5003. }.bind(this), REJECTION_TIMEOUT);
  5004. }
  5005. };
  5006. var Promise = function Promise(resolver) {
  5007. this._status = STATUS_PENDING;
  5008. this._handlers = [];
  5009. try {
  5010. resolver.call(this, this._resolve.bind(this), this._reject.bind(this));
  5011. } catch (e) {
  5012. this._reject(e);
  5013. }
  5014. };
  5015. /**
  5016. * Builds a promise that is resolved when all the passed in promises are
  5017. * resolved.
  5018. * @param {array} promises array of data and/or promises to wait for.
  5019. * @return {Promise} New dependent promise.
  5020. */
  5021. Promise.all = function Promise_all(promises) {
  5022. var resolveAll, rejectAll;
  5023. var deferred = new Promise(function (resolve, reject) {
  5024. resolveAll = resolve;
  5025. rejectAll = reject;
  5026. });
  5027. var unresolved = promises.length;
  5028. var results = [];
  5029. if (unresolved === 0) {
  5030. resolveAll(results);
  5031. return deferred;
  5032. }
  5033. function reject(reason) {
  5034. if (deferred._status === STATUS_REJECTED) {
  5035. return;
  5036. }
  5037. results = [];
  5038. rejectAll(reason);
  5039. }
  5040. for (var i = 0, ii = promises.length; i < ii; ++i) {
  5041. var promise = promises[i];
  5042. var resolve = function (i) {
  5043. return function (value) {
  5044. if (deferred._status === STATUS_REJECTED) {
  5045. return;
  5046. }
  5047. results[i] = value;
  5048. unresolved--;
  5049. if (unresolved === 0) {
  5050. resolveAll(results);
  5051. }
  5052. };
  5053. }(i);
  5054. if (Promise.isPromise(promise)) {
  5055. promise.then(resolve, reject);
  5056. } else {
  5057. resolve(promise);
  5058. }
  5059. }
  5060. return deferred;
  5061. };
  5062. /**
  5063. * Checks if the value is likely a promise (has a 'then' function).
  5064. * @return {boolean} true if value is thenable
  5065. */
  5066. Promise.isPromise = function Promise_isPromise(value) {
  5067. return value && typeof value.then === 'function';
  5068. };
  5069. /**
  5070. * Creates resolved promise
  5071. * @param value resolve value
  5072. * @returns {Promise}
  5073. */
  5074. Promise.resolve = function Promise_resolve(value) {
  5075. return new Promise(function (resolve) {
  5076. resolve(value);
  5077. });
  5078. };
  5079. /**
  5080. * Creates rejected promise
  5081. * @param reason rejection value
  5082. * @returns {Promise}
  5083. */
  5084. Promise.reject = function Promise_reject(reason) {
  5085. return new Promise(function (resolve, reject) {
  5086. reject(reason);
  5087. });
  5088. };
  5089. Promise.prototype = {
  5090. _status: null,
  5091. _value: null,
  5092. _handlers: null,
  5093. _unhandledRejection: null,
  5094. _updateStatus: function Promise__updateStatus(status, value) {
  5095. if (this._status === STATUS_RESOLVED || this._status === STATUS_REJECTED) {
  5096. return;
  5097. }
  5098. if (status === STATUS_RESOLVED && Promise.isPromise(value)) {
  5099. value.then(this._updateStatus.bind(this, STATUS_RESOLVED), this._updateStatus.bind(this, STATUS_REJECTED));
  5100. return;
  5101. }
  5102. this._status = status;
  5103. this._value = value;
  5104. if (status === STATUS_REJECTED && this._handlers.length === 0) {
  5105. this._unhandledRejection = true;
  5106. HandlerManager.addUnhandledRejection(this);
  5107. }
  5108. HandlerManager.scheduleHandlers(this);
  5109. },
  5110. _resolve: function Promise_resolve(value) {
  5111. this._updateStatus(STATUS_RESOLVED, value);
  5112. },
  5113. _reject: function Promise_reject(reason) {
  5114. this._updateStatus(STATUS_REJECTED, reason);
  5115. },
  5116. then: function Promise_then(onResolve, onReject) {
  5117. var nextPromise = new Promise(function (resolve, reject) {
  5118. this.resolve = resolve;
  5119. this.reject = reject;
  5120. });
  5121. this._handlers.push({
  5122. thisPromise: this,
  5123. onResolve: onResolve,
  5124. onReject: onReject,
  5125. nextPromise: nextPromise
  5126. });
  5127. HandlerManager.scheduleHandlers(this);
  5128. return nextPromise;
  5129. },
  5130. catch: function Promise_catch(onReject) {
  5131. return this.then(undefined, onReject);
  5132. }
  5133. };
  5134. globalScope.Promise = Promise;
  5135. }());
  5136. (function WeakMapClosure() {
  5137. if (globalScope.WeakMap) {
  5138. return;
  5139. }
  5140. var id = 0;
  5141. function WeakMap() {
  5142. this.id = '$weakmap' + id++;
  5143. }
  5144. WeakMap.prototype = {
  5145. has: function (obj) {
  5146. return !!Object.getOwnPropertyDescriptor(obj, this.id);
  5147. },
  5148. get: function (obj, defaultValue) {
  5149. return this.has(obj) ? obj[this.id] : defaultValue;
  5150. },
  5151. set: function (obj, value) {
  5152. Object.defineProperty(obj, this.id, {
  5153. value: value,
  5154. enumerable: false,
  5155. configurable: true
  5156. });
  5157. },
  5158. delete: function (obj) {
  5159. delete obj[this.id];
  5160. }
  5161. };
  5162. globalScope.WeakMap = WeakMap;
  5163. }());
  5164. var StatTimer = function StatTimerClosure() {
  5165. function rpad(str, pad, length) {
  5166. while (str.length < length) {
  5167. str += pad;
  5168. }
  5169. return str;
  5170. }
  5171. function StatTimer() {
  5172. this.started = Object.create(null);
  5173. this.times = [];
  5174. this.enabled = true;
  5175. }
  5176. StatTimer.prototype = {
  5177. time: function StatTimer_time(name) {
  5178. if (!this.enabled) {
  5179. return;
  5180. }
  5181. if (name in this.started) {
  5182. warn('Timer is already running for ' + name);
  5183. }
  5184. this.started[name] = Date.now();
  5185. },
  5186. timeEnd: function StatTimer_timeEnd(name) {
  5187. if (!this.enabled) {
  5188. return;
  5189. }
  5190. if (!(name in this.started)) {
  5191. warn('Timer has not been started for ' + name);
  5192. }
  5193. this.times.push({
  5194. 'name': name,
  5195. 'start': this.started[name],
  5196. 'end': Date.now()
  5197. });
  5198. // Remove timer from started so it can be called again.
  5199. delete this.started[name];
  5200. },
  5201. toString: function StatTimer_toString() {
  5202. var i, ii;
  5203. var times = this.times;
  5204. var out = '';
  5205. // Find the longest name for padding purposes.
  5206. var longest = 0;
  5207. for (i = 0, ii = times.length; i < ii; ++i) {
  5208. var name = times[i]['name'];
  5209. if (name.length > longest) {
  5210. longest = name.length;
  5211. }
  5212. }
  5213. for (i = 0, ii = times.length; i < ii; ++i) {
  5214. var span = times[i];
  5215. var duration = span.end - span.start;
  5216. out += rpad(span['name'], ' ', longest) + ' ' + duration + 'ms\n';
  5217. }
  5218. return out;
  5219. }
  5220. };
  5221. return StatTimer;
  5222. }();
  5223. var createBlob = function createBlob(data, contentType) {
  5224. if (typeof Blob !== 'undefined') {
  5225. return new Blob([data], { type: contentType });
  5226. }
  5227. warn('The "Blob" constructor is not supported.');
  5228. };
  5229. var createObjectURL = function createObjectURLClosure() {
  5230. // Blob/createObjectURL is not available, falling back to data schema.
  5231. var digits = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
  5232. return function createObjectURL(data, contentType, forceDataSchema) {
  5233. if (!forceDataSchema && typeof URL !== 'undefined' && URL.createObjectURL) {
  5234. var blob = createBlob(data, contentType);
  5235. return URL.createObjectURL(blob);
  5236. }
  5237. var buffer = 'data:' + contentType + ';base64,';
  5238. for (var i = 0, ii = data.length; i < ii; i += 3) {
  5239. var b1 = data[i] & 0xFF;
  5240. var b2 = data[i + 1] & 0xFF;
  5241. var b3 = data[i + 2] & 0xFF;
  5242. var d1 = b1 >> 2, d2 = (b1 & 3) << 4 | b2 >> 4;
  5243. var d3 = i + 1 < ii ? (b2 & 0xF) << 2 | b3 >> 6 : 64;
  5244. var d4 = i + 2 < ii ? b3 & 0x3F : 64;
  5245. buffer += digits[d1] + digits[d2] + digits[d3] + digits[d4];
  5246. }
  5247. return buffer;
  5248. };
  5249. }();
  5250. function MessageHandler(sourceName, targetName, comObj) {
  5251. this.sourceName = sourceName;
  5252. this.targetName = targetName;
  5253. this.comObj = comObj;
  5254. this.callbackIndex = 1;
  5255. this.postMessageTransfers = true;
  5256. var callbacksCapabilities = this.callbacksCapabilities = Object.create(null);
  5257. var ah = this.actionHandler = Object.create(null);
  5258. this._onComObjOnMessage = function messageHandlerComObjOnMessage(event) {
  5259. var data = event.data;
  5260. if (data.targetName !== this.sourceName) {
  5261. return;
  5262. }
  5263. if (data.isReply) {
  5264. var callbackId = data.callbackId;
  5265. if (data.callbackId in callbacksCapabilities) {
  5266. var callback = callbacksCapabilities[callbackId];
  5267. delete callbacksCapabilities[callbackId];
  5268. if ('error' in data) {
  5269. callback.reject(data.error);
  5270. } else {
  5271. callback.resolve(data.data);
  5272. }
  5273. } else {
  5274. error('Cannot resolve callback ' + callbackId);
  5275. }
  5276. } else if (data.action in ah) {
  5277. var action = ah[data.action];
  5278. if (data.callbackId) {
  5279. var sourceName = this.sourceName;
  5280. var targetName = data.sourceName;
  5281. Promise.resolve().then(function () {
  5282. return action[0].call(action[1], data.data);
  5283. }).then(function (result) {
  5284. comObj.postMessage({
  5285. sourceName: sourceName,
  5286. targetName: targetName,
  5287. isReply: true,
  5288. callbackId: data.callbackId,
  5289. data: result
  5290. });
  5291. }, function (reason) {
  5292. if (reason instanceof Error) {
  5293. // Serialize error to avoid "DataCloneError"
  5294. reason = reason + '';
  5295. }
  5296. comObj.postMessage({
  5297. sourceName: sourceName,
  5298. targetName: targetName,
  5299. isReply: true,
  5300. callbackId: data.callbackId,
  5301. error: reason
  5302. });
  5303. });
  5304. } else {
  5305. action[0].call(action[1], data.data);
  5306. }
  5307. } else {
  5308. error('Unknown action from worker: ' + data.action);
  5309. }
  5310. }.bind(this);
  5311. comObj.addEventListener('message', this._onComObjOnMessage);
  5312. }
  5313. MessageHandler.prototype = {
  5314. on: function messageHandlerOn(actionName, handler, scope) {
  5315. var ah = this.actionHandler;
  5316. if (ah[actionName]) {
  5317. error('There is already an actionName called "' + actionName + '"');
  5318. }
  5319. ah[actionName] = [
  5320. handler,
  5321. scope
  5322. ];
  5323. },
  5324. /**
  5325. * Sends a message to the comObj to invoke the action with the supplied data.
  5326. * @param {String} actionName Action to call.
  5327. * @param {JSON} data JSON data to send.
  5328. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers
  5329. */
  5330. send: function messageHandlerSend(actionName, data, transfers) {
  5331. var message = {
  5332. sourceName: this.sourceName,
  5333. targetName: this.targetName,
  5334. action: actionName,
  5335. data: data
  5336. };
  5337. this.postMessage(message, transfers);
  5338. },
  5339. /**
  5340. * Sends a message to the comObj to invoke the action with the supplied data.
  5341. * Expects that other side will callback with the response.
  5342. * @param {String} actionName Action to call.
  5343. * @param {JSON} data JSON data to send.
  5344. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers.
  5345. * @returns {Promise} Promise to be resolved with response data.
  5346. */
  5347. sendWithPromise: function messageHandlerSendWithPromise(actionName, data, transfers) {
  5348. var callbackId = this.callbackIndex++;
  5349. var message = {
  5350. sourceName: this.sourceName,
  5351. targetName: this.targetName,
  5352. action: actionName,
  5353. data: data,
  5354. callbackId: callbackId
  5355. };
  5356. var capability = createPromiseCapability();
  5357. this.callbacksCapabilities[callbackId] = capability;
  5358. try {
  5359. this.postMessage(message, transfers);
  5360. } catch (e) {
  5361. capability.reject(e);
  5362. }
  5363. return capability.promise;
  5364. },
  5365. /**
  5366. * Sends raw message to the comObj.
  5367. * @private
  5368. * @param message {Object} Raw message.
  5369. * @param transfers List of transfers/ArrayBuffers, or undefined.
  5370. */
  5371. postMessage: function (message, transfers) {
  5372. if (transfers && this.postMessageTransfers) {
  5373. this.comObj.postMessage(message, transfers);
  5374. } else {
  5375. this.comObj.postMessage(message);
  5376. }
  5377. },
  5378. destroy: function () {
  5379. this.comObj.removeEventListener('message', this._onComObjOnMessage);
  5380. }
  5381. };
  5382. function loadJpegStream(id, imageUrl, objs) {
  5383. var img = new Image();
  5384. img.onload = function loadJpegStream_onloadClosure() {
  5385. objs.resolve(id, img);
  5386. };
  5387. img.onerror = function loadJpegStream_onerrorClosure() {
  5388. objs.resolve(id, null);
  5389. warn('Error during JPEG image loading');
  5390. };
  5391. img.src = imageUrl;
  5392. }
  5393. // Polyfill from https://github.com/Polymer/URL
  5394. /* Any copyright is dedicated to the Public Domain.
  5395. * http://creativecommons.org/publicdomain/zero/1.0/ */
  5396. (function checkURLConstructor(scope) {
  5397. // feature detect for URL constructor
  5398. var hasWorkingUrl = false;
  5399. try {
  5400. if (typeof URL === 'function' && typeof URL.prototype === 'object' && 'origin' in URL.prototype) {
  5401. var u = new URL('b', 'http://a');
  5402. u.pathname = 'c%20d';
  5403. hasWorkingUrl = u.href === 'http://a/c%20d';
  5404. }
  5405. } catch (e) {
  5406. }
  5407. if (hasWorkingUrl) {
  5408. return;
  5409. }
  5410. var relative = Object.create(null);
  5411. relative['ftp'] = 21;
  5412. relative['file'] = 0;
  5413. relative['gopher'] = 70;
  5414. relative['http'] = 80;
  5415. relative['https'] = 443;
  5416. relative['ws'] = 80;
  5417. relative['wss'] = 443;
  5418. var relativePathDotMapping = Object.create(null);
  5419. relativePathDotMapping['%2e'] = '.';
  5420. relativePathDotMapping['.%2e'] = '..';
  5421. relativePathDotMapping['%2e.'] = '..';
  5422. relativePathDotMapping['%2e%2e'] = '..';
  5423. function isRelativeScheme(scheme) {
  5424. return relative[scheme] !== undefined;
  5425. }
  5426. function invalid() {
  5427. clear.call(this);
  5428. this._isInvalid = true;
  5429. }
  5430. function IDNAToASCII(h) {
  5431. if ('' === h) {
  5432. invalid.call(this);
  5433. }
  5434. // XXX
  5435. return h.toLowerCase();
  5436. }
  5437. function percentEscape(c) {
  5438. var unicode = c.charCodeAt(0);
  5439. if (unicode > 0x20 && unicode < 0x7F && // " # < > ? `
  5440. [
  5441. 0x22,
  5442. 0x23,
  5443. 0x3C,
  5444. 0x3E,
  5445. 0x3F,
  5446. 0x60
  5447. ].indexOf(unicode) === -1) {
  5448. return c;
  5449. }
  5450. return encodeURIComponent(c);
  5451. }
  5452. function percentEscapeQuery(c) {
  5453. // XXX This actually needs to encode c using encoding and then
  5454. // convert the bytes one-by-one.
  5455. var unicode = c.charCodeAt(0);
  5456. if (unicode > 0x20 && unicode < 0x7F && // " # < > ` (do not escape '?')
  5457. [
  5458. 0x22,
  5459. 0x23,
  5460. 0x3C,
  5461. 0x3E,
  5462. 0x60
  5463. ].indexOf(unicode) === -1) {
  5464. return c;
  5465. }
  5466. return encodeURIComponent(c);
  5467. }
  5468. var EOF, ALPHA = /[a-zA-Z]/, ALPHANUMERIC = /[a-zA-Z0-9\+\-\.]/;
  5469. function parse(input, stateOverride, base) {
  5470. function err(message) {
  5471. errors.push(message);
  5472. }
  5473. var state = stateOverride || 'scheme start', cursor = 0, buffer = '', seenAt = false, seenBracket = false, errors = [];
  5474. loop:
  5475. while ((input[cursor - 1] !== EOF || cursor === 0) && !this._isInvalid) {
  5476. var c = input[cursor];
  5477. switch (state) {
  5478. case 'scheme start':
  5479. if (c && ALPHA.test(c)) {
  5480. buffer += c.toLowerCase();
  5481. // ASCII-safe
  5482. state = 'scheme';
  5483. } else if (!stateOverride) {
  5484. buffer = '';
  5485. state = 'no scheme';
  5486. continue;
  5487. } else {
  5488. err('Invalid scheme.');
  5489. break loop;
  5490. }
  5491. break;
  5492. case 'scheme':
  5493. if (c && ALPHANUMERIC.test(c)) {
  5494. buffer += c.toLowerCase();
  5495. } else // ASCII-safe
  5496. if (':' === c) {
  5497. this._scheme = buffer;
  5498. buffer = '';
  5499. if (stateOverride) {
  5500. break loop;
  5501. }
  5502. if (isRelativeScheme(this._scheme)) {
  5503. this._isRelative = true;
  5504. }
  5505. if ('file' === this._scheme) {
  5506. state = 'relative';
  5507. } else if (this._isRelative && base && base._scheme === this._scheme) {
  5508. state = 'relative or authority';
  5509. } else if (this._isRelative) {
  5510. state = 'authority first slash';
  5511. } else {
  5512. state = 'scheme data';
  5513. }
  5514. } else if (!stateOverride) {
  5515. buffer = '';
  5516. cursor = 0;
  5517. state = 'no scheme';
  5518. continue;
  5519. } else if (EOF === c) {
  5520. break loop;
  5521. } else {
  5522. err('Code point not allowed in scheme: ' + c);
  5523. break loop;
  5524. }
  5525. break;
  5526. case 'scheme data':
  5527. if ('?' === c) {
  5528. this._query = '?';
  5529. state = 'query';
  5530. } else if ('#' === c) {
  5531. this._fragment = '#';
  5532. state = 'fragment';
  5533. } else {
  5534. // XXX error handling
  5535. if (EOF !== c && '\t' !== c && '\n' !== c && '\r' !== c) {
  5536. this._schemeData += percentEscape(c);
  5537. }
  5538. }
  5539. break;
  5540. case 'no scheme':
  5541. if (!base || !isRelativeScheme(base._scheme)) {
  5542. err('Missing scheme.');
  5543. invalid.call(this);
  5544. } else {
  5545. state = 'relative';
  5546. continue;
  5547. }
  5548. break;
  5549. case 'relative or authority':
  5550. if ('/' === c && '/' === input[cursor + 1]) {
  5551. state = 'authority ignore slashes';
  5552. } else {
  5553. err('Expected /, got: ' + c);
  5554. state = 'relative';
  5555. continue;
  5556. }
  5557. break;
  5558. case 'relative':
  5559. this._isRelative = true;
  5560. if ('file' !== this._scheme) {
  5561. this._scheme = base._scheme;
  5562. }
  5563. if (EOF === c) {
  5564. this._host = base._host;
  5565. this._port = base._port;
  5566. this._path = base._path.slice();
  5567. this._query = base._query;
  5568. this._username = base._username;
  5569. this._password = base._password;
  5570. break loop;
  5571. } else if ('/' === c || '\\' === c) {
  5572. if ('\\' === c) {
  5573. err('\\ is an invalid code point.');
  5574. }
  5575. state = 'relative slash';
  5576. } else if ('?' === c) {
  5577. this._host = base._host;
  5578. this._port = base._port;
  5579. this._path = base._path.slice();
  5580. this._query = '?';
  5581. this._username = base._username;
  5582. this._password = base._password;
  5583. state = 'query';
  5584. } else if ('#' === c) {
  5585. this._host = base._host;
  5586. this._port = base._port;
  5587. this._path = base._path.slice();
  5588. this._query = base._query;
  5589. this._fragment = '#';
  5590. this._username = base._username;
  5591. this._password = base._password;
  5592. state = 'fragment';
  5593. } else {
  5594. var nextC = input[cursor + 1];
  5595. var nextNextC = input[cursor + 2];
  5596. if ('file' !== this._scheme || !ALPHA.test(c) || nextC !== ':' && nextC !== '|' || EOF !== nextNextC && '/' !== nextNextC && '\\' !== nextNextC && '?' !== nextNextC && '#' !== nextNextC) {
  5597. this._host = base._host;
  5598. this._port = base._port;
  5599. this._username = base._username;
  5600. this._password = base._password;
  5601. this._path = base._path.slice();
  5602. this._path.pop();
  5603. }
  5604. state = 'relative path';
  5605. continue;
  5606. }
  5607. break;
  5608. case 'relative slash':
  5609. if ('/' === c || '\\' === c) {
  5610. if ('\\' === c) {
  5611. err('\\ is an invalid code point.');
  5612. }
  5613. if ('file' === this._scheme) {
  5614. state = 'file host';
  5615. } else {
  5616. state = 'authority ignore slashes';
  5617. }
  5618. } else {
  5619. if ('file' !== this._scheme) {
  5620. this._host = base._host;
  5621. this._port = base._port;
  5622. this._username = base._username;
  5623. this._password = base._password;
  5624. }
  5625. state = 'relative path';
  5626. continue;
  5627. }
  5628. break;
  5629. case 'authority first slash':
  5630. if ('/' === c) {
  5631. state = 'authority second slash';
  5632. } else {
  5633. err('Expected \'/\', got: ' + c);
  5634. state = 'authority ignore slashes';
  5635. continue;
  5636. }
  5637. break;
  5638. case 'authority second slash':
  5639. state = 'authority ignore slashes';
  5640. if ('/' !== c) {
  5641. err('Expected \'/\', got: ' + c);
  5642. continue;
  5643. }
  5644. break;
  5645. case 'authority ignore slashes':
  5646. if ('/' !== c && '\\' !== c) {
  5647. state = 'authority';
  5648. continue;
  5649. } else {
  5650. err('Expected authority, got: ' + c);
  5651. }
  5652. break;
  5653. case 'authority':
  5654. if ('@' === c) {
  5655. if (seenAt) {
  5656. err('@ already seen.');
  5657. buffer += '%40';
  5658. }
  5659. seenAt = true;
  5660. for (var i = 0; i < buffer.length; i++) {
  5661. var cp = buffer[i];
  5662. if ('\t' === cp || '\n' === cp || '\r' === cp) {
  5663. err('Invalid whitespace in authority.');
  5664. continue;
  5665. }
  5666. // XXX check URL code points
  5667. if (':' === cp && null === this._password) {
  5668. this._password = '';
  5669. continue;
  5670. }
  5671. var tempC = percentEscape(cp);
  5672. if (null !== this._password) {
  5673. this._password += tempC;
  5674. } else {
  5675. this._username += tempC;
  5676. }
  5677. }
  5678. buffer = '';
  5679. } else if (EOF === c || '/' === c || '\\' === c || '?' === c || '#' === c) {
  5680. cursor -= buffer.length;
  5681. buffer = '';
  5682. state = 'host';
  5683. continue;
  5684. } else {
  5685. buffer += c;
  5686. }
  5687. break;
  5688. case 'file host':
  5689. if (EOF === c || '/' === c || '\\' === c || '?' === c || '#' === c) {
  5690. if (buffer.length === 2 && ALPHA.test(buffer[0]) && (buffer[1] === ':' || buffer[1] === '|')) {
  5691. state = 'relative path';
  5692. } else if (buffer.length === 0) {
  5693. state = 'relative path start';
  5694. } else {
  5695. this._host = IDNAToASCII.call(this, buffer);
  5696. buffer = '';
  5697. state = 'relative path start';
  5698. }
  5699. continue;
  5700. } else if ('\t' === c || '\n' === c || '\r' === c) {
  5701. err('Invalid whitespace in file host.');
  5702. } else {
  5703. buffer += c;
  5704. }
  5705. break;
  5706. case 'host':
  5707. case 'hostname':
  5708. if (':' === c && !seenBracket) {
  5709. // XXX host parsing
  5710. this._host = IDNAToASCII.call(this, buffer);
  5711. buffer = '';
  5712. state = 'port';
  5713. if ('hostname' === stateOverride) {
  5714. break loop;
  5715. }
  5716. } else if (EOF === c || '/' === c || '\\' === c || '?' === c || '#' === c) {
  5717. this._host = IDNAToASCII.call(this, buffer);
  5718. buffer = '';
  5719. state = 'relative path start';
  5720. if (stateOverride) {
  5721. break loop;
  5722. }
  5723. continue;
  5724. } else if ('\t' !== c && '\n' !== c && '\r' !== c) {
  5725. if ('[' === c) {
  5726. seenBracket = true;
  5727. } else if (']' === c) {
  5728. seenBracket = false;
  5729. }
  5730. buffer += c;
  5731. } else {
  5732. err('Invalid code point in host/hostname: ' + c);
  5733. }
  5734. break;
  5735. case 'port':
  5736. if (/[0-9]/.test(c)) {
  5737. buffer += c;
  5738. } else if (EOF === c || '/' === c || '\\' === c || '?' === c || '#' === c || stateOverride) {
  5739. if ('' !== buffer) {
  5740. var temp = parseInt(buffer, 10);
  5741. if (temp !== relative[this._scheme]) {
  5742. this._port = temp + '';
  5743. }
  5744. buffer = '';
  5745. }
  5746. if (stateOverride) {
  5747. break loop;
  5748. }
  5749. state = 'relative path start';
  5750. continue;
  5751. } else if ('\t' === c || '\n' === c || '\r' === c) {
  5752. err('Invalid code point in port: ' + c);
  5753. } else {
  5754. invalid.call(this);
  5755. }
  5756. break;
  5757. case 'relative path start':
  5758. if ('\\' === c) {
  5759. err('\'\\\' not allowed in path.');
  5760. }
  5761. state = 'relative path';
  5762. if ('/' !== c && '\\' !== c) {
  5763. continue;
  5764. }
  5765. break;
  5766. case 'relative path':
  5767. if (EOF === c || '/' === c || '\\' === c || !stateOverride && ('?' === c || '#' === c)) {
  5768. if ('\\' === c) {
  5769. err('\\ not allowed in relative path.');
  5770. }
  5771. var tmp;
  5772. if (tmp = relativePathDotMapping[buffer.toLowerCase()]) {
  5773. buffer = tmp;
  5774. }
  5775. if ('..' === buffer) {
  5776. this._path.pop();
  5777. if ('/' !== c && '\\' !== c) {
  5778. this._path.push('');
  5779. }
  5780. } else if ('.' === buffer && '/' !== c && '\\' !== c) {
  5781. this._path.push('');
  5782. } else if ('.' !== buffer) {
  5783. if ('file' === this._scheme && this._path.length === 0 && buffer.length === 2 && ALPHA.test(buffer[0]) && buffer[1] === '|') {
  5784. buffer = buffer[0] + ':';
  5785. }
  5786. this._path.push(buffer);
  5787. }
  5788. buffer = '';
  5789. if ('?' === c) {
  5790. this._query = '?';
  5791. state = 'query';
  5792. } else if ('#' === c) {
  5793. this._fragment = '#';
  5794. state = 'fragment';
  5795. }
  5796. } else if ('\t' !== c && '\n' !== c && '\r' !== c) {
  5797. buffer += percentEscape(c);
  5798. }
  5799. break;
  5800. case 'query':
  5801. if (!stateOverride && '#' === c) {
  5802. this._fragment = '#';
  5803. state = 'fragment';
  5804. } else if (EOF !== c && '\t' !== c && '\n' !== c && '\r' !== c) {
  5805. this._query += percentEscapeQuery(c);
  5806. }
  5807. break;
  5808. case 'fragment':
  5809. if (EOF !== c && '\t' !== c && '\n' !== c && '\r' !== c) {
  5810. this._fragment += c;
  5811. }
  5812. break;
  5813. }
  5814. cursor++;
  5815. }
  5816. }
  5817. function clear() {
  5818. this._scheme = '';
  5819. this._schemeData = '';
  5820. this._username = '';
  5821. this._password = null;
  5822. this._host = '';
  5823. this._port = '';
  5824. this._path = [];
  5825. this._query = '';
  5826. this._fragment = '';
  5827. this._isInvalid = false;
  5828. this._isRelative = false;
  5829. }
  5830. // Does not process domain names or IP addresses.
  5831. // Does not handle encoding for the query parameter.
  5832. function JURL(url, base)
  5833. /* , encoding */
  5834. {
  5835. if (base !== undefined && !(base instanceof JURL)) {
  5836. base = new JURL(String(base));
  5837. }
  5838. this._url = url;
  5839. clear.call(this);
  5840. var input = url.replace(/^[ \t\r\n\f]+|[ \t\r\n\f]+$/g, '');
  5841. // encoding = encoding || 'utf-8'
  5842. parse.call(this, input, null, base);
  5843. }
  5844. JURL.prototype = {
  5845. toString: function () {
  5846. return this.href;
  5847. },
  5848. get href() {
  5849. if (this._isInvalid) {
  5850. return this._url;
  5851. }
  5852. var authority = '';
  5853. if ('' !== this._username || null !== this._password) {
  5854. authority = this._username + (null !== this._password ? ':' + this._password : '') + '@';
  5855. }
  5856. return this.protocol + (this._isRelative ? '//' + authority + this.host : '') + this.pathname + this._query + this._fragment;
  5857. },
  5858. set href(href) {
  5859. clear.call(this);
  5860. parse.call(this, href);
  5861. },
  5862. get protocol() {
  5863. return this._scheme + ':';
  5864. },
  5865. set protocol(protocol) {
  5866. if (this._isInvalid) {
  5867. return;
  5868. }
  5869. parse.call(this, protocol + ':', 'scheme start');
  5870. },
  5871. get host() {
  5872. return this._isInvalid ? '' : this._port ? this._host + ':' + this._port : this._host;
  5873. },
  5874. set host(host) {
  5875. if (this._isInvalid || !this._isRelative) {
  5876. return;
  5877. }
  5878. parse.call(this, host, 'host');
  5879. },
  5880. get hostname() {
  5881. return this._host;
  5882. },
  5883. set hostname(hostname) {
  5884. if (this._isInvalid || !this._isRelative) {
  5885. return;
  5886. }
  5887. parse.call(this, hostname, 'hostname');
  5888. },
  5889. get port() {
  5890. return this._port;
  5891. },
  5892. set port(port) {
  5893. if (this._isInvalid || !this._isRelative) {
  5894. return;
  5895. }
  5896. parse.call(this, port, 'port');
  5897. },
  5898. get pathname() {
  5899. return this._isInvalid ? '' : this._isRelative ? '/' + this._path.join('/') : this._schemeData;
  5900. },
  5901. set pathname(pathname) {
  5902. if (this._isInvalid || !this._isRelative) {
  5903. return;
  5904. }
  5905. this._path = [];
  5906. parse.call(this, pathname, 'relative path start');
  5907. },
  5908. get search() {
  5909. return this._isInvalid || !this._query || '?' === this._query ? '' : this._query;
  5910. },
  5911. set search(search) {
  5912. if (this._isInvalid || !this._isRelative) {
  5913. return;
  5914. }
  5915. this._query = '?';
  5916. if ('?' === search[0]) {
  5917. search = search.slice(1);
  5918. }
  5919. parse.call(this, search, 'query');
  5920. },
  5921. get hash() {
  5922. return this._isInvalid || !this._fragment || '#' === this._fragment ? '' : this._fragment;
  5923. },
  5924. set hash(hash) {
  5925. if (this._isInvalid) {
  5926. return;
  5927. }
  5928. this._fragment = '#';
  5929. if ('#' === hash[0]) {
  5930. hash = hash.slice(1);
  5931. }
  5932. parse.call(this, hash, 'fragment');
  5933. },
  5934. get origin() {
  5935. var host;
  5936. if (this._isInvalid || !this._scheme) {
  5937. return '';
  5938. }
  5939. // javascript: Gecko returns String(""), WebKit/Blink String("null")
  5940. // Gecko throws error for "data://"
  5941. // data: Gecko returns "", Blink returns "data://", WebKit returns "null"
  5942. // Gecko returns String("") for file: mailto:
  5943. // WebKit/Blink returns String("SCHEME://") for file: mailto:
  5944. switch (this._scheme) {
  5945. case 'data':
  5946. case 'file':
  5947. case 'javascript':
  5948. case 'mailto':
  5949. return 'null';
  5950. }
  5951. host = this.host;
  5952. if (!host) {
  5953. return '';
  5954. }
  5955. return this._scheme + '://' + host;
  5956. }
  5957. };
  5958. // Copy over the static methods
  5959. var OriginalURL = scope.URL;
  5960. if (OriginalURL) {
  5961. JURL.createObjectURL = function (blob) {
  5962. // IE extension allows a second optional options argument.
  5963. // http://msdn.microsoft.com/en-us/library/ie/hh772302(v=vs.85).aspx
  5964. return OriginalURL.createObjectURL.apply(OriginalURL, arguments);
  5965. };
  5966. JURL.revokeObjectURL = function (url) {
  5967. OriginalURL.revokeObjectURL(url);
  5968. };
  5969. }
  5970. scope.URL = JURL;
  5971. }(globalScope));
  5972. exports.FONT_IDENTITY_MATRIX = FONT_IDENTITY_MATRIX;
  5973. exports.IDENTITY_MATRIX = IDENTITY_MATRIX;
  5974. exports.OPS = OPS;
  5975. exports.VERBOSITY_LEVELS = VERBOSITY_LEVELS;
  5976. exports.UNSUPPORTED_FEATURES = UNSUPPORTED_FEATURES;
  5977. exports.AnnotationBorderStyleType = AnnotationBorderStyleType;
  5978. exports.AnnotationFieldFlag = AnnotationFieldFlag;
  5979. exports.AnnotationFlag = AnnotationFlag;
  5980. exports.AnnotationType = AnnotationType;
  5981. exports.FontType = FontType;
  5982. exports.ImageKind = ImageKind;
  5983. exports.InvalidPDFException = InvalidPDFException;
  5984. exports.MessageHandler = MessageHandler;
  5985. exports.MissingDataException = MissingDataException;
  5986. exports.MissingPDFException = MissingPDFException;
  5987. exports.NotImplementedException = NotImplementedException;
  5988. exports.PageViewport = PageViewport;
  5989. exports.PasswordException = PasswordException;
  5990. exports.PasswordResponses = PasswordResponses;
  5991. exports.StatTimer = StatTimer;
  5992. exports.StreamType = StreamType;
  5993. exports.TextRenderingMode = TextRenderingMode;
  5994. exports.UnexpectedResponseException = UnexpectedResponseException;
  5995. exports.UnknownErrorException = UnknownErrorException;
  5996. exports.Util = Util;
  5997. exports.XRefParseException = XRefParseException;
  5998. exports.arrayByteLength = arrayByteLength;
  5999. exports.arraysToBytes = arraysToBytes;
  6000. exports.assert = assert;
  6001. exports.bytesToString = bytesToString;
  6002. exports.createBlob = createBlob;
  6003. exports.createPromiseCapability = createPromiseCapability;
  6004. exports.createObjectURL = createObjectURL;
  6005. exports.deprecated = deprecated;
  6006. exports.error = error;
  6007. exports.getLookupTableFactory = getLookupTableFactory;
  6008. exports.getVerbosityLevel = getVerbosityLevel;
  6009. exports.globalScope = globalScope;
  6010. exports.info = info;
  6011. exports.isArray = isArray;
  6012. exports.isArrayBuffer = isArrayBuffer;
  6013. exports.isBool = isBool;
  6014. exports.isEmptyObj = isEmptyObj;
  6015. exports.isInt = isInt;
  6016. exports.isNum = isNum;
  6017. exports.isString = isString;
  6018. exports.isSpace = isSpace;
  6019. exports.isSameOrigin = isSameOrigin;
  6020. exports.createValidAbsoluteUrl = createValidAbsoluteUrl;
  6021. exports.isLittleEndian = isLittleEndian;
  6022. exports.isEvalSupported = isEvalSupported;
  6023. exports.loadJpegStream = loadJpegStream;
  6024. exports.log2 = log2;
  6025. exports.readInt8 = readInt8;
  6026. exports.readUint16 = readUint16;
  6027. exports.readUint32 = readUint32;
  6028. exports.removeNullCharacters = removeNullCharacters;
  6029. exports.setVerbosityLevel = setVerbosityLevel;
  6030. exports.shadow = shadow;
  6031. exports.string32 = string32;
  6032. exports.stringToBytes = stringToBytes;
  6033. exports.stringToPDFString = stringToPDFString;
  6034. exports.stringToUTF8String = stringToUTF8String;
  6035. exports.utf8StringToString = utf8StringToString;
  6036. exports.warn = warn;
  6037. }));
  6038. (function (root, factory) {
  6039. factory(root.pdfjsCoreCFFParser = {}, root.pdfjsSharedUtil, root.pdfjsCoreCharsets, root.pdfjsCoreEncodings);
  6040. }(this, function (exports, sharedUtil, coreCharsets, coreEncodings) {
  6041. var error = sharedUtil.error;
  6042. var info = sharedUtil.info;
  6043. var bytesToString = sharedUtil.bytesToString;
  6044. var warn = sharedUtil.warn;
  6045. var isArray = sharedUtil.isArray;
  6046. var Util = sharedUtil.Util;
  6047. var stringToBytes = sharedUtil.stringToBytes;
  6048. var assert = sharedUtil.assert;
  6049. var ISOAdobeCharset = coreCharsets.ISOAdobeCharset;
  6050. var ExpertCharset = coreCharsets.ExpertCharset;
  6051. var ExpertSubsetCharset = coreCharsets.ExpertSubsetCharset;
  6052. var StandardEncoding = coreEncodings.StandardEncoding;
  6053. var ExpertEncoding = coreEncodings.ExpertEncoding;
  6054. // Maximum subroutine call depth of type 2 chartrings. Matches OTS.
  6055. var MAX_SUBR_NESTING = 10;
  6056. /**
  6057. * The CFF class takes a Type1 file and wrap it into a
  6058. * 'Compact Font Format' which itself embed Type2 charstrings.
  6059. */
  6060. var CFFStandardStrings = [
  6061. '.notdef',
  6062. 'space',
  6063. 'exclam',
  6064. 'quotedbl',
  6065. 'numbersign',
  6066. 'dollar',
  6067. 'percent',
  6068. 'ampersand',
  6069. 'quoteright',
  6070. 'parenleft',
  6071. 'parenright',
  6072. 'asterisk',
  6073. 'plus',
  6074. 'comma',
  6075. 'hyphen',
  6076. 'period',
  6077. 'slash',
  6078. 'zero',
  6079. 'one',
  6080. 'two',
  6081. 'three',
  6082. 'four',
  6083. 'five',
  6084. 'six',
  6085. 'seven',
  6086. 'eight',
  6087. 'nine',
  6088. 'colon',
  6089. 'semicolon',
  6090. 'less',
  6091. 'equal',
  6092. 'greater',
  6093. 'question',
  6094. 'at',
  6095. 'A',
  6096. 'B',
  6097. 'C',
  6098. 'D',
  6099. 'E',
  6100. 'F',
  6101. 'G',
  6102. 'H',
  6103. 'I',
  6104. 'J',
  6105. 'K',
  6106. 'L',
  6107. 'M',
  6108. 'N',
  6109. 'O',
  6110. 'P',
  6111. 'Q',
  6112. 'R',
  6113. 'S',
  6114. 'T',
  6115. 'U',
  6116. 'V',
  6117. 'W',
  6118. 'X',
  6119. 'Y',
  6120. 'Z',
  6121. 'bracketleft',
  6122. 'backslash',
  6123. 'bracketright',
  6124. 'asciicircum',
  6125. 'underscore',
  6126. 'quoteleft',
  6127. 'a',
  6128. 'b',
  6129. 'c',
  6130. 'd',
  6131. 'e',
  6132. 'f',
  6133. 'g',
  6134. 'h',
  6135. 'i',
  6136. 'j',
  6137. 'k',
  6138. 'l',
  6139. 'm',
  6140. 'n',
  6141. 'o',
  6142. 'p',
  6143. 'q',
  6144. 'r',
  6145. 's',
  6146. 't',
  6147. 'u',
  6148. 'v',
  6149. 'w',
  6150. 'x',
  6151. 'y',
  6152. 'z',
  6153. 'braceleft',
  6154. 'bar',
  6155. 'braceright',
  6156. 'asciitilde',
  6157. 'exclamdown',
  6158. 'cent',
  6159. 'sterling',
  6160. 'fraction',
  6161. 'yen',
  6162. 'florin',
  6163. 'section',
  6164. 'currency',
  6165. 'quotesingle',
  6166. 'quotedblleft',
  6167. 'guillemotleft',
  6168. 'guilsinglleft',
  6169. 'guilsinglright',
  6170. 'fi',
  6171. 'fl',
  6172. 'endash',
  6173. 'dagger',
  6174. 'daggerdbl',
  6175. 'periodcentered',
  6176. 'paragraph',
  6177. 'bullet',
  6178. 'quotesinglbase',
  6179. 'quotedblbase',
  6180. 'quotedblright',
  6181. 'guillemotright',
  6182. 'ellipsis',
  6183. 'perthousand',
  6184. 'questiondown',
  6185. 'grave',
  6186. 'acute',
  6187. 'circumflex',
  6188. 'tilde',
  6189. 'macron',
  6190. 'breve',
  6191. 'dotaccent',
  6192. 'dieresis',
  6193. 'ring',
  6194. 'cedilla',
  6195. 'hungarumlaut',
  6196. 'ogonek',
  6197. 'caron',
  6198. 'emdash',
  6199. 'AE',
  6200. 'ordfeminine',
  6201. 'Lslash',
  6202. 'Oslash',
  6203. 'OE',
  6204. 'ordmasculine',
  6205. 'ae',
  6206. 'dotlessi',
  6207. 'lslash',
  6208. 'oslash',
  6209. 'oe',
  6210. 'germandbls',
  6211. 'onesuperior',
  6212. 'logicalnot',
  6213. 'mu',
  6214. 'trademark',
  6215. 'Eth',
  6216. 'onehalf',
  6217. 'plusminus',
  6218. 'Thorn',
  6219. 'onequarter',
  6220. 'divide',
  6221. 'brokenbar',
  6222. 'degree',
  6223. 'thorn',
  6224. 'threequarters',
  6225. 'twosuperior',
  6226. 'registered',
  6227. 'minus',
  6228. 'eth',
  6229. 'multiply',
  6230. 'threesuperior',
  6231. 'copyright',
  6232. 'Aacute',
  6233. 'Acircumflex',
  6234. 'Adieresis',
  6235. 'Agrave',
  6236. 'Aring',
  6237. 'Atilde',
  6238. 'Ccedilla',
  6239. 'Eacute',
  6240. 'Ecircumflex',
  6241. 'Edieresis',
  6242. 'Egrave',
  6243. 'Iacute',
  6244. 'Icircumflex',
  6245. 'Idieresis',
  6246. 'Igrave',
  6247. 'Ntilde',
  6248. 'Oacute',
  6249. 'Ocircumflex',
  6250. 'Odieresis',
  6251. 'Ograve',
  6252. 'Otilde',
  6253. 'Scaron',
  6254. 'Uacute',
  6255. 'Ucircumflex',
  6256. 'Udieresis',
  6257. 'Ugrave',
  6258. 'Yacute',
  6259. 'Ydieresis',
  6260. 'Zcaron',
  6261. 'aacute',
  6262. 'acircumflex',
  6263. 'adieresis',
  6264. 'agrave',
  6265. 'aring',
  6266. 'atilde',
  6267. 'ccedilla',
  6268. 'eacute',
  6269. 'ecircumflex',
  6270. 'edieresis',
  6271. 'egrave',
  6272. 'iacute',
  6273. 'icircumflex',
  6274. 'idieresis',
  6275. 'igrave',
  6276. 'ntilde',
  6277. 'oacute',
  6278. 'ocircumflex',
  6279. 'odieresis',
  6280. 'ograve',
  6281. 'otilde',
  6282. 'scaron',
  6283. 'uacute',
  6284. 'ucircumflex',
  6285. 'udieresis',
  6286. 'ugrave',
  6287. 'yacute',
  6288. 'ydieresis',
  6289. 'zcaron',
  6290. 'exclamsmall',
  6291. 'Hungarumlautsmall',
  6292. 'dollaroldstyle',
  6293. 'dollarsuperior',
  6294. 'ampersandsmall',
  6295. 'Acutesmall',
  6296. 'parenleftsuperior',
  6297. 'parenrightsuperior',
  6298. 'twodotenleader',
  6299. 'onedotenleader',
  6300. 'zerooldstyle',
  6301. 'oneoldstyle',
  6302. 'twooldstyle',
  6303. 'threeoldstyle',
  6304. 'fouroldstyle',
  6305. 'fiveoldstyle',
  6306. 'sixoldstyle',
  6307. 'sevenoldstyle',
  6308. 'eightoldstyle',
  6309. 'nineoldstyle',
  6310. 'commasuperior',
  6311. 'threequartersemdash',
  6312. 'periodsuperior',
  6313. 'questionsmall',
  6314. 'asuperior',
  6315. 'bsuperior',
  6316. 'centsuperior',
  6317. 'dsuperior',
  6318. 'esuperior',
  6319. 'isuperior',
  6320. 'lsuperior',
  6321. 'msuperior',
  6322. 'nsuperior',
  6323. 'osuperior',
  6324. 'rsuperior',
  6325. 'ssuperior',
  6326. 'tsuperior',
  6327. 'ff',
  6328. 'ffi',
  6329. 'ffl',
  6330. 'parenleftinferior',
  6331. 'parenrightinferior',
  6332. 'Circumflexsmall',
  6333. 'hyphensuperior',
  6334. 'Gravesmall',
  6335. 'Asmall',
  6336. 'Bsmall',
  6337. 'Csmall',
  6338. 'Dsmall',
  6339. 'Esmall',
  6340. 'Fsmall',
  6341. 'Gsmall',
  6342. 'Hsmall',
  6343. 'Ismall',
  6344. 'Jsmall',
  6345. 'Ksmall',
  6346. 'Lsmall',
  6347. 'Msmall',
  6348. 'Nsmall',
  6349. 'Osmall',
  6350. 'Psmall',
  6351. 'Qsmall',
  6352. 'Rsmall',
  6353. 'Ssmall',
  6354. 'Tsmall',
  6355. 'Usmall',
  6356. 'Vsmall',
  6357. 'Wsmall',
  6358. 'Xsmall',
  6359. 'Ysmall',
  6360. 'Zsmall',
  6361. 'colonmonetary',
  6362. 'onefitted',
  6363. 'rupiah',
  6364. 'Tildesmall',
  6365. 'exclamdownsmall',
  6366. 'centoldstyle',
  6367. 'Lslashsmall',
  6368. 'Scaronsmall',
  6369. 'Zcaronsmall',
  6370. 'Dieresissmall',
  6371. 'Brevesmall',
  6372. 'Caronsmall',
  6373. 'Dotaccentsmall',
  6374. 'Macronsmall',
  6375. 'figuredash',
  6376. 'hypheninferior',
  6377. 'Ogoneksmall',
  6378. 'Ringsmall',
  6379. 'Cedillasmall',
  6380. 'questiondownsmall',
  6381. 'oneeighth',
  6382. 'threeeighths',
  6383. 'fiveeighths',
  6384. 'seveneighths',
  6385. 'onethird',
  6386. 'twothirds',
  6387. 'zerosuperior',
  6388. 'foursuperior',
  6389. 'fivesuperior',
  6390. 'sixsuperior',
  6391. 'sevensuperior',
  6392. 'eightsuperior',
  6393. 'ninesuperior',
  6394. 'zeroinferior',
  6395. 'oneinferior',
  6396. 'twoinferior',
  6397. 'threeinferior',
  6398. 'fourinferior',
  6399. 'fiveinferior',
  6400. 'sixinferior',
  6401. 'seveninferior',
  6402. 'eightinferior',
  6403. 'nineinferior',
  6404. 'centinferior',
  6405. 'dollarinferior',
  6406. 'periodinferior',
  6407. 'commainferior',
  6408. 'Agravesmall',
  6409. 'Aacutesmall',
  6410. 'Acircumflexsmall',
  6411. 'Atildesmall',
  6412. 'Adieresissmall',
  6413. 'Aringsmall',
  6414. 'AEsmall',
  6415. 'Ccedillasmall',
  6416. 'Egravesmall',
  6417. 'Eacutesmall',
  6418. 'Ecircumflexsmall',
  6419. 'Edieresissmall',
  6420. 'Igravesmall',
  6421. 'Iacutesmall',
  6422. 'Icircumflexsmall',
  6423. 'Idieresissmall',
  6424. 'Ethsmall',
  6425. 'Ntildesmall',
  6426. 'Ogravesmall',
  6427. 'Oacutesmall',
  6428. 'Ocircumflexsmall',
  6429. 'Otildesmall',
  6430. 'Odieresissmall',
  6431. 'OEsmall',
  6432. 'Oslashsmall',
  6433. 'Ugravesmall',
  6434. 'Uacutesmall',
  6435. 'Ucircumflexsmall',
  6436. 'Udieresissmall',
  6437. 'Yacutesmall',
  6438. 'Thornsmall',
  6439. 'Ydieresissmall',
  6440. '001.000',
  6441. '001.001',
  6442. '001.002',
  6443. '001.003',
  6444. 'Black',
  6445. 'Bold',
  6446. 'Book',
  6447. 'Light',
  6448. 'Medium',
  6449. 'Regular',
  6450. 'Roman',
  6451. 'Semibold'
  6452. ];
  6453. var CFFParser = function CFFParserClosure() {
  6454. var CharstringValidationData = [
  6455. null,
  6456. {
  6457. id: 'hstem',
  6458. min: 2,
  6459. stackClearing: true,
  6460. stem: true
  6461. },
  6462. null,
  6463. {
  6464. id: 'vstem',
  6465. min: 2,
  6466. stackClearing: true,
  6467. stem: true
  6468. },
  6469. {
  6470. id: 'vmoveto',
  6471. min: 1,
  6472. stackClearing: true
  6473. },
  6474. {
  6475. id: 'rlineto',
  6476. min: 2,
  6477. resetStack: true
  6478. },
  6479. {
  6480. id: 'hlineto',
  6481. min: 1,
  6482. resetStack: true
  6483. },
  6484. {
  6485. id: 'vlineto',
  6486. min: 1,
  6487. resetStack: true
  6488. },
  6489. {
  6490. id: 'rrcurveto',
  6491. min: 6,
  6492. resetStack: true
  6493. },
  6494. null,
  6495. {
  6496. id: 'callsubr',
  6497. min: 1,
  6498. undefStack: true
  6499. },
  6500. {
  6501. id: 'return',
  6502. min: 0,
  6503. undefStack: true
  6504. },
  6505. null,
  6506. // 12
  6507. null,
  6508. {
  6509. id: 'endchar',
  6510. min: 0,
  6511. stackClearing: true
  6512. },
  6513. null,
  6514. null,
  6515. null,
  6516. {
  6517. id: 'hstemhm',
  6518. min: 2,
  6519. stackClearing: true,
  6520. stem: true
  6521. },
  6522. {
  6523. id: 'hintmask',
  6524. min: 0,
  6525. stackClearing: true
  6526. },
  6527. {
  6528. id: 'cntrmask',
  6529. min: 0,
  6530. stackClearing: true
  6531. },
  6532. {
  6533. id: 'rmoveto',
  6534. min: 2,
  6535. stackClearing: true
  6536. },
  6537. {
  6538. id: 'hmoveto',
  6539. min: 1,
  6540. stackClearing: true
  6541. },
  6542. {
  6543. id: 'vstemhm',
  6544. min: 2,
  6545. stackClearing: true,
  6546. stem: true
  6547. },
  6548. {
  6549. id: 'rcurveline',
  6550. min: 8,
  6551. resetStack: true
  6552. },
  6553. {
  6554. id: 'rlinecurve',
  6555. min: 8,
  6556. resetStack: true
  6557. },
  6558. {
  6559. id: 'vvcurveto',
  6560. min: 4,
  6561. resetStack: true
  6562. },
  6563. {
  6564. id: 'hhcurveto',
  6565. min: 4,
  6566. resetStack: true
  6567. },
  6568. null,
  6569. // shortint
  6570. {
  6571. id: 'callgsubr',
  6572. min: 1,
  6573. undefStack: true
  6574. },
  6575. {
  6576. id: 'vhcurveto',
  6577. min: 4,
  6578. resetStack: true
  6579. },
  6580. {
  6581. id: 'hvcurveto',
  6582. min: 4,
  6583. resetStack: true
  6584. }
  6585. ];
  6586. var CharstringValidationData12 = [
  6587. null,
  6588. null,
  6589. null,
  6590. {
  6591. id: 'and',
  6592. min: 2,
  6593. stackDelta: -1
  6594. },
  6595. {
  6596. id: 'or',
  6597. min: 2,
  6598. stackDelta: -1
  6599. },
  6600. {
  6601. id: 'not',
  6602. min: 1,
  6603. stackDelta: 0
  6604. },
  6605. null,
  6606. null,
  6607. null,
  6608. {
  6609. id: 'abs',
  6610. min: 1,
  6611. stackDelta: 0
  6612. },
  6613. {
  6614. id: 'add',
  6615. min: 2,
  6616. stackDelta: -1,
  6617. stackFn: function stack_div(stack, index) {
  6618. stack[index - 2] = stack[index - 2] + stack[index - 1];
  6619. }
  6620. },
  6621. {
  6622. id: 'sub',
  6623. min: 2,
  6624. stackDelta: -1,
  6625. stackFn: function stack_div(stack, index) {
  6626. stack[index - 2] = stack[index - 2] - stack[index - 1];
  6627. }
  6628. },
  6629. {
  6630. id: 'div',
  6631. min: 2,
  6632. stackDelta: -1,
  6633. stackFn: function stack_div(stack, index) {
  6634. stack[index - 2] = stack[index - 2] / stack[index - 1];
  6635. }
  6636. },
  6637. null,
  6638. {
  6639. id: 'neg',
  6640. min: 1,
  6641. stackDelta: 0,
  6642. stackFn: function stack_div(stack, index) {
  6643. stack[index - 1] = -stack[index - 1];
  6644. }
  6645. },
  6646. {
  6647. id: 'eq',
  6648. min: 2,
  6649. stackDelta: -1
  6650. },
  6651. null,
  6652. null,
  6653. {
  6654. id: 'drop',
  6655. min: 1,
  6656. stackDelta: -1
  6657. },
  6658. null,
  6659. {
  6660. id: 'put',
  6661. min: 2,
  6662. stackDelta: -2
  6663. },
  6664. {
  6665. id: 'get',
  6666. min: 1,
  6667. stackDelta: 0
  6668. },
  6669. {
  6670. id: 'ifelse',
  6671. min: 4,
  6672. stackDelta: -3
  6673. },
  6674. {
  6675. id: 'random',
  6676. min: 0,
  6677. stackDelta: 1
  6678. },
  6679. {
  6680. id: 'mul',
  6681. min: 2,
  6682. stackDelta: -1,
  6683. stackFn: function stack_div(stack, index) {
  6684. stack[index - 2] = stack[index - 2] * stack[index - 1];
  6685. }
  6686. },
  6687. null,
  6688. {
  6689. id: 'sqrt',
  6690. min: 1,
  6691. stackDelta: 0
  6692. },
  6693. {
  6694. id: 'dup',
  6695. min: 1,
  6696. stackDelta: 1
  6697. },
  6698. {
  6699. id: 'exch',
  6700. min: 2,
  6701. stackDelta: 0
  6702. },
  6703. {
  6704. id: 'index',
  6705. min: 2,
  6706. stackDelta: 0
  6707. },
  6708. {
  6709. id: 'roll',
  6710. min: 3,
  6711. stackDelta: -2
  6712. },
  6713. null,
  6714. null,
  6715. null,
  6716. {
  6717. id: 'hflex',
  6718. min: 7,
  6719. resetStack: true
  6720. },
  6721. {
  6722. id: 'flex',
  6723. min: 13,
  6724. resetStack: true
  6725. },
  6726. {
  6727. id: 'hflex1',
  6728. min: 9,
  6729. resetStack: true
  6730. },
  6731. {
  6732. id: 'flex1',
  6733. min: 11,
  6734. resetStack: true
  6735. }
  6736. ];
  6737. function CFFParser(file, properties, seacAnalysisEnabled) {
  6738. this.bytes = file.getBytes();
  6739. this.properties = properties;
  6740. this.seacAnalysisEnabled = !!seacAnalysisEnabled;
  6741. }
  6742. CFFParser.prototype = {
  6743. parse: function CFFParser_parse() {
  6744. var properties = this.properties;
  6745. var cff = new CFF();
  6746. this.cff = cff;
  6747. // The first five sections must be in order, all the others are reached
  6748. // via offsets contained in one of the below.
  6749. var header = this.parseHeader();
  6750. var nameIndex = this.parseIndex(header.endPos);
  6751. var topDictIndex = this.parseIndex(nameIndex.endPos);
  6752. var stringIndex = this.parseIndex(topDictIndex.endPos);
  6753. var globalSubrIndex = this.parseIndex(stringIndex.endPos);
  6754. var topDictParsed = this.parseDict(topDictIndex.obj.get(0));
  6755. var topDict = this.createDict(CFFTopDict, topDictParsed, cff.strings);
  6756. cff.header = header.obj;
  6757. cff.names = this.parseNameIndex(nameIndex.obj);
  6758. cff.strings = this.parseStringIndex(stringIndex.obj);
  6759. cff.topDict = topDict;
  6760. cff.globalSubrIndex = globalSubrIndex.obj;
  6761. this.parsePrivateDict(cff.topDict);
  6762. cff.isCIDFont = topDict.hasName('ROS');
  6763. var charStringOffset = topDict.getByName('CharStrings');
  6764. var charStringIndex = this.parseIndex(charStringOffset).obj;
  6765. var fontMatrix = topDict.getByName('FontMatrix');
  6766. if (fontMatrix) {
  6767. properties.fontMatrix = fontMatrix;
  6768. }
  6769. var fontBBox = topDict.getByName('FontBBox');
  6770. if (fontBBox) {
  6771. // adjusting ascent/descent
  6772. properties.ascent = fontBBox[3];
  6773. properties.descent = fontBBox[1];
  6774. properties.ascentScaled = true;
  6775. }
  6776. var charset, encoding;
  6777. if (cff.isCIDFont) {
  6778. var fdArrayIndex = this.parseIndex(topDict.getByName('FDArray')).obj;
  6779. for (var i = 0, ii = fdArrayIndex.count; i < ii; ++i) {
  6780. var dictRaw = fdArrayIndex.get(i);
  6781. var fontDict = this.createDict(CFFTopDict, this.parseDict(dictRaw), cff.strings);
  6782. this.parsePrivateDict(fontDict);
  6783. cff.fdArray.push(fontDict);
  6784. }
  6785. // cid fonts don't have an encoding
  6786. encoding = null;
  6787. charset = this.parseCharsets(topDict.getByName('charset'), charStringIndex.count, cff.strings, true);
  6788. cff.fdSelect = this.parseFDSelect(topDict.getByName('FDSelect'), charStringIndex.count);
  6789. } else {
  6790. charset = this.parseCharsets(topDict.getByName('charset'), charStringIndex.count, cff.strings, false);
  6791. encoding = this.parseEncoding(topDict.getByName('Encoding'), properties, cff.strings, charset.charset);
  6792. }
  6793. cff.charset = charset;
  6794. cff.encoding = encoding;
  6795. var charStringsAndSeacs = this.parseCharStrings(charStringIndex, topDict.privateDict.subrsIndex, globalSubrIndex.obj, cff.fdSelect, cff.fdArray);
  6796. cff.charStrings = charStringsAndSeacs.charStrings;
  6797. cff.seacs = charStringsAndSeacs.seacs;
  6798. cff.widths = charStringsAndSeacs.widths;
  6799. return cff;
  6800. },
  6801. parseHeader: function CFFParser_parseHeader() {
  6802. var bytes = this.bytes;
  6803. var bytesLength = bytes.length;
  6804. var offset = 0;
  6805. // Prevent an infinite loop, by checking that the offset is within the
  6806. // bounds of the bytes array. Necessary in empty, or invalid, font files.
  6807. while (offset < bytesLength && bytes[offset] !== 1) {
  6808. ++offset;
  6809. }
  6810. if (offset >= bytesLength) {
  6811. error('Invalid CFF header');
  6812. } else if (offset !== 0) {
  6813. info('cff data is shifted');
  6814. bytes = bytes.subarray(offset);
  6815. this.bytes = bytes;
  6816. }
  6817. var major = bytes[0];
  6818. var minor = bytes[1];
  6819. var hdrSize = bytes[2];
  6820. var offSize = bytes[3];
  6821. var header = new CFFHeader(major, minor, hdrSize, offSize);
  6822. return {
  6823. obj: header,
  6824. endPos: hdrSize
  6825. };
  6826. },
  6827. parseDict: function CFFParser_parseDict(dict) {
  6828. var pos = 0;
  6829. function parseOperand() {
  6830. var value = dict[pos++];
  6831. if (value === 30) {
  6832. return parseFloatOperand();
  6833. } else if (value === 28) {
  6834. value = dict[pos++];
  6835. value = (value << 24 | dict[pos++] << 16) >> 16;
  6836. return value;
  6837. } else if (value === 29) {
  6838. value = dict[pos++];
  6839. value = value << 8 | dict[pos++];
  6840. value = value << 8 | dict[pos++];
  6841. value = value << 8 | dict[pos++];
  6842. return value;
  6843. } else if (value >= 32 && value <= 246) {
  6844. return value - 139;
  6845. } else if (value >= 247 && value <= 250) {
  6846. return (value - 247) * 256 + dict[pos++] + 108;
  6847. } else if (value >= 251 && value <= 254) {
  6848. return -((value - 251) * 256) - dict[pos++] - 108;
  6849. } else {
  6850. error('255 is not a valid DICT command');
  6851. }
  6852. return -1;
  6853. }
  6854. function parseFloatOperand() {
  6855. var str = '';
  6856. var eof = 15;
  6857. var lookup = [
  6858. '0',
  6859. '1',
  6860. '2',
  6861. '3',
  6862. '4',
  6863. '5',
  6864. '6',
  6865. '7',
  6866. '8',
  6867. '9',
  6868. '.',
  6869. 'E',
  6870. 'E-',
  6871. null,
  6872. '-'
  6873. ];
  6874. var length = dict.length;
  6875. while (pos < length) {
  6876. var b = dict[pos++];
  6877. var b1 = b >> 4;
  6878. var b2 = b & 15;
  6879. if (b1 === eof) {
  6880. break;
  6881. }
  6882. str += lookup[b1];
  6883. if (b2 === eof) {
  6884. break;
  6885. }
  6886. str += lookup[b2];
  6887. }
  6888. return parseFloat(str);
  6889. }
  6890. var operands = [];
  6891. var entries = [];
  6892. pos = 0;
  6893. var end = dict.length;
  6894. while (pos < end) {
  6895. var b = dict[pos];
  6896. if (b <= 21) {
  6897. if (b === 12) {
  6898. b = b << 8 | dict[++pos];
  6899. }
  6900. entries.push([
  6901. b,
  6902. operands
  6903. ]);
  6904. operands = [];
  6905. ++pos;
  6906. } else {
  6907. operands.push(parseOperand());
  6908. }
  6909. }
  6910. return entries;
  6911. },
  6912. parseIndex: function CFFParser_parseIndex(pos) {
  6913. var cffIndex = new CFFIndex();
  6914. var bytes = this.bytes;
  6915. var count = bytes[pos++] << 8 | bytes[pos++];
  6916. var offsets = [];
  6917. var end = pos;
  6918. var i, ii;
  6919. if (count !== 0) {
  6920. var offsetSize = bytes[pos++];
  6921. // add 1 for offset to determine size of last object
  6922. var startPos = pos + (count + 1) * offsetSize - 1;
  6923. for (i = 0, ii = count + 1; i < ii; ++i) {
  6924. var offset = 0;
  6925. for (var j = 0; j < offsetSize; ++j) {
  6926. offset <<= 8;
  6927. offset += bytes[pos++];
  6928. }
  6929. offsets.push(startPos + offset);
  6930. }
  6931. end = offsets[count];
  6932. }
  6933. for (i = 0, ii = offsets.length - 1; i < ii; ++i) {
  6934. var offsetStart = offsets[i];
  6935. var offsetEnd = offsets[i + 1];
  6936. cffIndex.add(bytes.subarray(offsetStart, offsetEnd));
  6937. }
  6938. return {
  6939. obj: cffIndex,
  6940. endPos: end
  6941. };
  6942. },
  6943. parseNameIndex: function CFFParser_parseNameIndex(index) {
  6944. var names = [];
  6945. for (var i = 0, ii = index.count; i < ii; ++i) {
  6946. var name = index.get(i);
  6947. // OTS doesn't allow names to be over 127 characters.
  6948. var length = Math.min(name.length, 127);
  6949. var data = [];
  6950. // OTS also only permits certain characters in the name.
  6951. for (var j = 0; j < length; ++j) {
  6952. var c = name[j];
  6953. if (j === 0 && c === 0) {
  6954. data[j] = c;
  6955. continue;
  6956. }
  6957. if (c < 33 || c > 126 || c === 91 || /* [ */
  6958. c === 93 || /* ] */
  6959. c === 40 || /* ( */
  6960. c === 41 || /* ) */
  6961. c === 123 || /* { */
  6962. c === 125 || /* } */
  6963. c === 60 || /* < */
  6964. c === 62 || /* > */
  6965. c === 47 || /* / */
  6966. c === 37 || /* % */
  6967. c === 35)
  6968. /* # */
  6969. {
  6970. data[j] = 95;
  6971. continue;
  6972. }
  6973. data[j] = c;
  6974. }
  6975. names.push(bytesToString(data));
  6976. }
  6977. return names;
  6978. },
  6979. parseStringIndex: function CFFParser_parseStringIndex(index) {
  6980. var strings = new CFFStrings();
  6981. for (var i = 0, ii = index.count; i < ii; ++i) {
  6982. var data = index.get(i);
  6983. strings.add(bytesToString(data));
  6984. }
  6985. return strings;
  6986. },
  6987. createDict: function CFFParser_createDict(Type, dict, strings) {
  6988. var cffDict = new Type(strings);
  6989. for (var i = 0, ii = dict.length; i < ii; ++i) {
  6990. var pair = dict[i];
  6991. var key = pair[0];
  6992. var value = pair[1];
  6993. cffDict.setByKey(key, value);
  6994. }
  6995. return cffDict;
  6996. },
  6997. parseCharString: function CFFParser_parseCharString(state, data, localSubrIndex, globalSubrIndex) {
  6998. if (state.callDepth > MAX_SUBR_NESTING) {
  6999. return false;
  7000. }
  7001. var stackSize = state.stackSize;
  7002. var stack = state.stack;
  7003. var length = data.length;
  7004. for (var j = 0; j < length;) {
  7005. var value = data[j++];
  7006. var validationCommand = null;
  7007. if (value === 12) {
  7008. var q = data[j++];
  7009. if (q === 0) {
  7010. // The CFF specification state that the 'dotsection' command
  7011. // (12, 0) is deprecated and treated as a no-op, but all Type2
  7012. // charstrings processors should support them. Unfortunately
  7013. // the font sanitizer don't. As a workaround the sequence (12, 0)
  7014. // is replaced by a useless (0, hmoveto).
  7015. data[j - 2] = 139;
  7016. data[j - 1] = 22;
  7017. stackSize = 0;
  7018. } else {
  7019. validationCommand = CharstringValidationData12[q];
  7020. }
  7021. } else if (value === 28) {
  7022. // number (16 bit)
  7023. stack[stackSize] = (data[j] << 24 | data[j + 1] << 16) >> 16;
  7024. j += 2;
  7025. stackSize++;
  7026. } else if (value === 14) {
  7027. if (stackSize >= 4) {
  7028. stackSize -= 4;
  7029. if (this.seacAnalysisEnabled) {
  7030. state.seac = stack.slice(stackSize, stackSize + 4);
  7031. return false;
  7032. }
  7033. }
  7034. validationCommand = CharstringValidationData[value];
  7035. } else if (value >= 32 && value <= 246) {
  7036. // number
  7037. stack[stackSize] = value - 139;
  7038. stackSize++;
  7039. } else if (value >= 247 && value <= 254) {
  7040. // number (+1 bytes)
  7041. stack[stackSize] = value < 251 ? (value - 247 << 8) + data[j] + 108 : -(value - 251 << 8) - data[j] - 108;
  7042. j++;
  7043. stackSize++;
  7044. } else if (value === 255) {
  7045. // number (32 bit)
  7046. stack[stackSize] = (data[j] << 24 | data[j + 1] << 16 | data[j + 2] << 8 | data[j + 3]) / 65536;
  7047. j += 4;
  7048. stackSize++;
  7049. } else if (value === 19 || value === 20) {
  7050. state.hints += stackSize >> 1;
  7051. // skipping right amount of hints flag data
  7052. j += state.hints + 7 >> 3;
  7053. stackSize %= 2;
  7054. validationCommand = CharstringValidationData[value];
  7055. } else if (value === 10 || value === 29) {
  7056. var subrsIndex;
  7057. if (value === 10) {
  7058. subrsIndex = localSubrIndex;
  7059. } else {
  7060. subrsIndex = globalSubrIndex;
  7061. }
  7062. if (!subrsIndex) {
  7063. validationCommand = CharstringValidationData[value];
  7064. warn('Missing subrsIndex for ' + validationCommand.id);
  7065. return false;
  7066. }
  7067. var bias = 32768;
  7068. if (subrsIndex.count < 1240) {
  7069. bias = 107;
  7070. } else if (subrsIndex.count < 33900) {
  7071. bias = 1131;
  7072. }
  7073. var subrNumber = stack[--stackSize] + bias;
  7074. if (subrNumber < 0 || subrNumber >= subrsIndex.count) {
  7075. validationCommand = CharstringValidationData[value];
  7076. warn('Out of bounds subrIndex for ' + validationCommand.id);
  7077. return false;
  7078. }
  7079. state.stackSize = stackSize;
  7080. state.callDepth++;
  7081. var valid = this.parseCharString(state, subrsIndex.get(subrNumber), localSubrIndex, globalSubrIndex);
  7082. if (!valid) {
  7083. return false;
  7084. }
  7085. state.callDepth--;
  7086. stackSize = state.stackSize;
  7087. continue;
  7088. } else if (value === 11) {
  7089. state.stackSize = stackSize;
  7090. return true;
  7091. } else {
  7092. validationCommand = CharstringValidationData[value];
  7093. }
  7094. if (validationCommand) {
  7095. if (validationCommand.stem) {
  7096. state.hints += stackSize >> 1;
  7097. }
  7098. if ('min' in validationCommand) {
  7099. if (!state.undefStack && stackSize < validationCommand.min) {
  7100. warn('Not enough parameters for ' + validationCommand.id + '; actual: ' + stackSize + ', expected: ' + validationCommand.min);
  7101. return false;
  7102. }
  7103. }
  7104. if (state.firstStackClearing && validationCommand.stackClearing) {
  7105. state.firstStackClearing = false;
  7106. // the optional character width can be found before the first
  7107. // stack-clearing command arguments
  7108. stackSize -= validationCommand.min;
  7109. if (stackSize >= 2 && validationCommand.stem) {
  7110. // there are even amount of arguments for stem commands
  7111. stackSize %= 2;
  7112. } else if (stackSize > 1) {
  7113. warn('Found too many parameters for stack-clearing command');
  7114. }
  7115. if (stackSize > 0 && stack[stackSize - 1] >= 0) {
  7116. state.width = stack[stackSize - 1];
  7117. }
  7118. }
  7119. if ('stackDelta' in validationCommand) {
  7120. if ('stackFn' in validationCommand) {
  7121. validationCommand.stackFn(stack, stackSize);
  7122. }
  7123. stackSize += validationCommand.stackDelta;
  7124. } else if (validationCommand.stackClearing) {
  7125. stackSize = 0;
  7126. } else if (validationCommand.resetStack) {
  7127. stackSize = 0;
  7128. state.undefStack = false;
  7129. } else if (validationCommand.undefStack) {
  7130. stackSize = 0;
  7131. state.undefStack = true;
  7132. state.firstStackClearing = false;
  7133. }
  7134. }
  7135. }
  7136. state.stackSize = stackSize;
  7137. return true;
  7138. },
  7139. parseCharStrings: function CFFParser_parseCharStrings(charStrings, localSubrIndex, globalSubrIndex, fdSelect, fdArray) {
  7140. var seacs = [];
  7141. var widths = [];
  7142. var count = charStrings.count;
  7143. for (var i = 0; i < count; i++) {
  7144. var charstring = charStrings.get(i);
  7145. var state = {
  7146. callDepth: 0,
  7147. stackSize: 0,
  7148. stack: [],
  7149. undefStack: true,
  7150. hints: 0,
  7151. firstStackClearing: true,
  7152. seac: null,
  7153. width: null
  7154. };
  7155. var valid = true;
  7156. var localSubrToUse = null;
  7157. if (fdSelect && fdArray.length) {
  7158. var fdIndex = fdSelect.getFDIndex(i);
  7159. if (fdIndex === -1) {
  7160. warn('Glyph index is not in fd select.');
  7161. valid = false;
  7162. }
  7163. if (fdIndex >= fdArray.length) {
  7164. warn('Invalid fd index for glyph index.');
  7165. valid = false;
  7166. }
  7167. if (valid) {
  7168. localSubrToUse = fdArray[fdIndex].privateDict.subrsIndex;
  7169. }
  7170. } else if (localSubrIndex) {
  7171. localSubrToUse = localSubrIndex;
  7172. }
  7173. if (valid) {
  7174. valid = this.parseCharString(state, charstring, localSubrToUse, globalSubrIndex);
  7175. }
  7176. if (state.width !== null) {
  7177. widths[i] = state.width;
  7178. }
  7179. if (state.seac !== null) {
  7180. seacs[i] = state.seac;
  7181. }
  7182. if (!valid) {
  7183. // resetting invalid charstring to single 'endchar'
  7184. charStrings.set(i, new Uint8Array([14]));
  7185. }
  7186. }
  7187. return {
  7188. charStrings: charStrings,
  7189. seacs: seacs,
  7190. widths: widths
  7191. };
  7192. },
  7193. emptyPrivateDictionary: function CFFParser_emptyPrivateDictionary(parentDict) {
  7194. var privateDict = this.createDict(CFFPrivateDict, [], parentDict.strings);
  7195. parentDict.setByKey(18, [
  7196. 0,
  7197. 0
  7198. ]);
  7199. parentDict.privateDict = privateDict;
  7200. },
  7201. parsePrivateDict: function CFFParser_parsePrivateDict(parentDict) {
  7202. // no private dict, do nothing
  7203. if (!parentDict.hasName('Private')) {
  7204. this.emptyPrivateDictionary(parentDict);
  7205. return;
  7206. }
  7207. var privateOffset = parentDict.getByName('Private');
  7208. // make sure the params are formatted correctly
  7209. if (!isArray(privateOffset) || privateOffset.length !== 2) {
  7210. parentDict.removeByName('Private');
  7211. return;
  7212. }
  7213. var size = privateOffset[0];
  7214. var offset = privateOffset[1];
  7215. // remove empty dicts or ones that refer to invalid location
  7216. if (size === 0 || offset >= this.bytes.length) {
  7217. this.emptyPrivateDictionary(parentDict);
  7218. return;
  7219. }
  7220. var privateDictEnd = offset + size;
  7221. var dictData = this.bytes.subarray(offset, privateDictEnd);
  7222. var dict = this.parseDict(dictData);
  7223. var privateDict = this.createDict(CFFPrivateDict, dict, parentDict.strings);
  7224. parentDict.privateDict = privateDict;
  7225. // Parse the Subrs index also since it's relative to the private dict.
  7226. if (!privateDict.getByName('Subrs')) {
  7227. return;
  7228. }
  7229. var subrsOffset = privateDict.getByName('Subrs');
  7230. var relativeOffset = offset + subrsOffset;
  7231. // Validate the offset.
  7232. if (subrsOffset === 0 || relativeOffset >= this.bytes.length) {
  7233. this.emptyPrivateDictionary(parentDict);
  7234. return;
  7235. }
  7236. var subrsIndex = this.parseIndex(relativeOffset);
  7237. privateDict.subrsIndex = subrsIndex.obj;
  7238. },
  7239. parseCharsets: function CFFParser_parseCharsets(pos, length, strings, cid) {
  7240. if (pos === 0) {
  7241. return new CFFCharset(true, CFFCharsetPredefinedTypes.ISO_ADOBE, ISOAdobeCharset);
  7242. } else if (pos === 1) {
  7243. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT, ExpertCharset);
  7244. } else if (pos === 2) {
  7245. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT_SUBSET, ExpertSubsetCharset);
  7246. }
  7247. var bytes = this.bytes;
  7248. var start = pos;
  7249. var format = bytes[pos++];
  7250. var charset = ['.notdef'];
  7251. var id, count, i;
  7252. // subtract 1 for the .notdef glyph
  7253. length -= 1;
  7254. switch (format) {
  7255. case 0:
  7256. for (i = 0; i < length; i++) {
  7257. id = bytes[pos++] << 8 | bytes[pos++];
  7258. charset.push(cid ? id : strings.get(id));
  7259. }
  7260. break;
  7261. case 1:
  7262. while (charset.length <= length) {
  7263. id = bytes[pos++] << 8 | bytes[pos++];
  7264. count = bytes[pos++];
  7265. for (i = 0; i <= count; i++) {
  7266. charset.push(cid ? id++ : strings.get(id++));
  7267. }
  7268. }
  7269. break;
  7270. case 2:
  7271. while (charset.length <= length) {
  7272. id = bytes[pos++] << 8 | bytes[pos++];
  7273. count = bytes[pos++] << 8 | bytes[pos++];
  7274. for (i = 0; i <= count; i++) {
  7275. charset.push(cid ? id++ : strings.get(id++));
  7276. }
  7277. }
  7278. break;
  7279. default:
  7280. error('Unknown charset format');
  7281. }
  7282. // Raw won't be needed if we actually compile the charset.
  7283. var end = pos;
  7284. var raw = bytes.subarray(start, end);
  7285. return new CFFCharset(false, format, charset, raw);
  7286. },
  7287. parseEncoding: function CFFParser_parseEncoding(pos, properties, strings, charset) {
  7288. var encoding = Object.create(null);
  7289. var bytes = this.bytes;
  7290. var predefined = false;
  7291. var hasSupplement = false;
  7292. var format, i, ii;
  7293. var raw = null;
  7294. function readSupplement() {
  7295. var supplementsCount = bytes[pos++];
  7296. for (i = 0; i < supplementsCount; i++) {
  7297. var code = bytes[pos++];
  7298. var sid = (bytes[pos++] << 8) + (bytes[pos++] & 0xff);
  7299. encoding[code] = charset.indexOf(strings.get(sid));
  7300. }
  7301. }
  7302. if (pos === 0 || pos === 1) {
  7303. predefined = true;
  7304. format = pos;
  7305. var baseEncoding = pos ? ExpertEncoding : StandardEncoding;
  7306. for (i = 0, ii = charset.length; i < ii; i++) {
  7307. var index = baseEncoding.indexOf(charset[i]);
  7308. if (index !== -1) {
  7309. encoding[index] = i;
  7310. }
  7311. }
  7312. } else {
  7313. var dataStart = pos;
  7314. format = bytes[pos++];
  7315. switch (format & 0x7f) {
  7316. case 0:
  7317. var glyphsCount = bytes[pos++];
  7318. for (i = 1; i <= glyphsCount; i++) {
  7319. encoding[bytes[pos++]] = i;
  7320. }
  7321. break;
  7322. case 1:
  7323. var rangesCount = bytes[pos++];
  7324. var gid = 1;
  7325. for (i = 0; i < rangesCount; i++) {
  7326. var start = bytes[pos++];
  7327. var left = bytes[pos++];
  7328. for (var j = start; j <= start + left; j++) {
  7329. encoding[j] = gid++;
  7330. }
  7331. }
  7332. break;
  7333. default:
  7334. error('Unknown encoding format: ' + format + ' in CFF');
  7335. break;
  7336. }
  7337. var dataEnd = pos;
  7338. if (format & 0x80) {
  7339. // The font sanitizer does not support CFF encoding with a
  7340. // supplement, since the encoding is not really used to map
  7341. // between gid to glyph, let's overwrite what is declared in
  7342. // the top dictionary to let the sanitizer think the font use
  7343. // StandardEncoding, that's a lie but that's ok.
  7344. bytes[dataStart] &= 0x7f;
  7345. readSupplement();
  7346. hasSupplement = true;
  7347. }
  7348. raw = bytes.subarray(dataStart, dataEnd);
  7349. }
  7350. format = format & 0x7f;
  7351. return new CFFEncoding(predefined, format, encoding, raw);
  7352. },
  7353. parseFDSelect: function CFFParser_parseFDSelect(pos, length) {
  7354. var start = pos;
  7355. var bytes = this.bytes;
  7356. var format = bytes[pos++];
  7357. var fdSelect = [], rawBytes;
  7358. var i, invalidFirstGID = false;
  7359. switch (format) {
  7360. case 0:
  7361. for (i = 0; i < length; ++i) {
  7362. var id = bytes[pos++];
  7363. fdSelect.push(id);
  7364. }
  7365. rawBytes = bytes.subarray(start, pos);
  7366. break;
  7367. case 3:
  7368. var rangesCount = bytes[pos++] << 8 | bytes[pos++];
  7369. for (i = 0; i < rangesCount; ++i) {
  7370. var first = bytes[pos++] << 8 | bytes[pos++];
  7371. if (i === 0 && first !== 0) {
  7372. warn('parseFDSelect: The first range must have a first GID of 0' + ' -- trying to recover.');
  7373. invalidFirstGID = true;
  7374. first = 0;
  7375. }
  7376. var fdIndex = bytes[pos++];
  7377. var next = bytes[pos] << 8 | bytes[pos + 1];
  7378. for (var j = first; j < next; ++j) {
  7379. fdSelect.push(fdIndex);
  7380. }
  7381. }
  7382. // Advance past the sentinel(next).
  7383. pos += 2;
  7384. rawBytes = bytes.subarray(start, pos);
  7385. if (invalidFirstGID) {
  7386. rawBytes[3] = rawBytes[4] = 0;
  7387. }
  7388. // Adjust the first range, first GID.
  7389. break;
  7390. default:
  7391. error('parseFDSelect: Unknown format "' + format + '".');
  7392. break;
  7393. }
  7394. assert(fdSelect.length === length, 'parseFDSelect: Invalid font data.');
  7395. return new CFFFDSelect(fdSelect, rawBytes);
  7396. }
  7397. };
  7398. return CFFParser;
  7399. }();
  7400. // Compact Font Format
  7401. var CFF = function CFFClosure() {
  7402. function CFF() {
  7403. this.header = null;
  7404. this.names = [];
  7405. this.topDict = null;
  7406. this.strings = new CFFStrings();
  7407. this.globalSubrIndex = null;
  7408. // The following could really be per font, but since we only have one font
  7409. // store them here.
  7410. this.encoding = null;
  7411. this.charset = null;
  7412. this.charStrings = null;
  7413. this.fdArray = [];
  7414. this.fdSelect = null;
  7415. this.isCIDFont = false;
  7416. }
  7417. return CFF;
  7418. }();
  7419. var CFFHeader = function CFFHeaderClosure() {
  7420. function CFFHeader(major, minor, hdrSize, offSize) {
  7421. this.major = major;
  7422. this.minor = minor;
  7423. this.hdrSize = hdrSize;
  7424. this.offSize = offSize;
  7425. }
  7426. return CFFHeader;
  7427. }();
  7428. var CFFStrings = function CFFStringsClosure() {
  7429. function CFFStrings() {
  7430. this.strings = [];
  7431. }
  7432. CFFStrings.prototype = {
  7433. get: function CFFStrings_get(index) {
  7434. if (index >= 0 && index <= 390) {
  7435. return CFFStandardStrings[index];
  7436. }
  7437. if (index - 391 <= this.strings.length) {
  7438. return this.strings[index - 391];
  7439. }
  7440. return CFFStandardStrings[0];
  7441. },
  7442. add: function CFFStrings_add(value) {
  7443. this.strings.push(value);
  7444. },
  7445. get count() {
  7446. return this.strings.length;
  7447. }
  7448. };
  7449. return CFFStrings;
  7450. }();
  7451. var CFFIndex = function CFFIndexClosure() {
  7452. function CFFIndex() {
  7453. this.objects = [];
  7454. this.length = 0;
  7455. }
  7456. CFFIndex.prototype = {
  7457. add: function CFFIndex_add(data) {
  7458. this.length += data.length;
  7459. this.objects.push(data);
  7460. },
  7461. set: function CFFIndex_set(index, data) {
  7462. this.length += data.length - this.objects[index].length;
  7463. this.objects[index] = data;
  7464. },
  7465. get: function CFFIndex_get(index) {
  7466. return this.objects[index];
  7467. },
  7468. get count() {
  7469. return this.objects.length;
  7470. }
  7471. };
  7472. return CFFIndex;
  7473. }();
  7474. var CFFDict = function CFFDictClosure() {
  7475. function CFFDict(tables, strings) {
  7476. this.keyToNameMap = tables.keyToNameMap;
  7477. this.nameToKeyMap = tables.nameToKeyMap;
  7478. this.defaults = tables.defaults;
  7479. this.types = tables.types;
  7480. this.opcodes = tables.opcodes;
  7481. this.order = tables.order;
  7482. this.strings = strings;
  7483. this.values = Object.create(null);
  7484. }
  7485. CFFDict.prototype = {
  7486. // value should always be an array
  7487. setByKey: function CFFDict_setByKey(key, value) {
  7488. if (!(key in this.keyToNameMap)) {
  7489. return false;
  7490. }
  7491. // ignore empty values
  7492. if (value.length === 0) {
  7493. return true;
  7494. }
  7495. var type = this.types[key];
  7496. // remove the array wrapping these types of values
  7497. if (type === 'num' || type === 'sid' || type === 'offset') {
  7498. value = value[0];
  7499. // Ignore invalid values (fixes bug 1068432).
  7500. if (isNaN(value)) {
  7501. warn('Invalid CFFDict value: ' + value + ', for key: ' + key + '.');
  7502. return true;
  7503. }
  7504. }
  7505. this.values[key] = value;
  7506. return true;
  7507. },
  7508. setByName: function CFFDict_setByName(name, value) {
  7509. if (!(name in this.nameToKeyMap)) {
  7510. error('Invalid dictionary name "' + name + '"');
  7511. }
  7512. this.values[this.nameToKeyMap[name]] = value;
  7513. },
  7514. hasName: function CFFDict_hasName(name) {
  7515. return this.nameToKeyMap[name] in this.values;
  7516. },
  7517. getByName: function CFFDict_getByName(name) {
  7518. if (!(name in this.nameToKeyMap)) {
  7519. error('Invalid dictionary name "' + name + '"');
  7520. }
  7521. var key = this.nameToKeyMap[name];
  7522. if (!(key in this.values)) {
  7523. return this.defaults[key];
  7524. }
  7525. return this.values[key];
  7526. },
  7527. removeByName: function CFFDict_removeByName(name) {
  7528. delete this.values[this.nameToKeyMap[name]];
  7529. }
  7530. };
  7531. CFFDict.createTables = function CFFDict_createTables(layout) {
  7532. var tables = {
  7533. keyToNameMap: {},
  7534. nameToKeyMap: {},
  7535. defaults: {},
  7536. types: {},
  7537. opcodes: {},
  7538. order: []
  7539. };
  7540. for (var i = 0, ii = layout.length; i < ii; ++i) {
  7541. var entry = layout[i];
  7542. var key = isArray(entry[0]) ? (entry[0][0] << 8) + entry[0][1] : entry[0];
  7543. tables.keyToNameMap[key] = entry[1];
  7544. tables.nameToKeyMap[entry[1]] = key;
  7545. tables.types[key] = entry[2];
  7546. tables.defaults[key] = entry[3];
  7547. tables.opcodes[key] = isArray(entry[0]) ? entry[0] : [entry[0]];
  7548. tables.order.push(key);
  7549. }
  7550. return tables;
  7551. };
  7552. return CFFDict;
  7553. }();
  7554. var CFFTopDict = function CFFTopDictClosure() {
  7555. var layout = [
  7556. [
  7557. [
  7558. 12,
  7559. 30
  7560. ],
  7561. 'ROS',
  7562. [
  7563. 'sid',
  7564. 'sid',
  7565. 'num'
  7566. ],
  7567. null
  7568. ],
  7569. [
  7570. [
  7571. 12,
  7572. 20
  7573. ],
  7574. 'SyntheticBase',
  7575. 'num',
  7576. null
  7577. ],
  7578. [
  7579. 0,
  7580. 'version',
  7581. 'sid',
  7582. null
  7583. ],
  7584. [
  7585. 1,
  7586. 'Notice',
  7587. 'sid',
  7588. null
  7589. ],
  7590. [
  7591. [
  7592. 12,
  7593. 0
  7594. ],
  7595. 'Copyright',
  7596. 'sid',
  7597. null
  7598. ],
  7599. [
  7600. 2,
  7601. 'FullName',
  7602. 'sid',
  7603. null
  7604. ],
  7605. [
  7606. 3,
  7607. 'FamilyName',
  7608. 'sid',
  7609. null
  7610. ],
  7611. [
  7612. 4,
  7613. 'Weight',
  7614. 'sid',
  7615. null
  7616. ],
  7617. [
  7618. [
  7619. 12,
  7620. 1
  7621. ],
  7622. 'isFixedPitch',
  7623. 'num',
  7624. 0
  7625. ],
  7626. [
  7627. [
  7628. 12,
  7629. 2
  7630. ],
  7631. 'ItalicAngle',
  7632. 'num',
  7633. 0
  7634. ],
  7635. [
  7636. [
  7637. 12,
  7638. 3
  7639. ],
  7640. 'UnderlinePosition',
  7641. 'num',
  7642. -100
  7643. ],
  7644. [
  7645. [
  7646. 12,
  7647. 4
  7648. ],
  7649. 'UnderlineThickness',
  7650. 'num',
  7651. 50
  7652. ],
  7653. [
  7654. [
  7655. 12,
  7656. 5
  7657. ],
  7658. 'PaintType',
  7659. 'num',
  7660. 0
  7661. ],
  7662. [
  7663. [
  7664. 12,
  7665. 6
  7666. ],
  7667. 'CharstringType',
  7668. 'num',
  7669. 2
  7670. ],
  7671. [
  7672. [
  7673. 12,
  7674. 7
  7675. ],
  7676. 'FontMatrix',
  7677. [
  7678. 'num',
  7679. 'num',
  7680. 'num',
  7681. 'num',
  7682. 'num',
  7683. 'num'
  7684. ],
  7685. [
  7686. 0.001,
  7687. 0,
  7688. 0,
  7689. 0.001,
  7690. 0,
  7691. 0
  7692. ]
  7693. ],
  7694. [
  7695. 13,
  7696. 'UniqueID',
  7697. 'num',
  7698. null
  7699. ],
  7700. [
  7701. 5,
  7702. 'FontBBox',
  7703. [
  7704. 'num',
  7705. 'num',
  7706. 'num',
  7707. 'num'
  7708. ],
  7709. [
  7710. 0,
  7711. 0,
  7712. 0,
  7713. 0
  7714. ]
  7715. ],
  7716. [
  7717. [
  7718. 12,
  7719. 8
  7720. ],
  7721. 'StrokeWidth',
  7722. 'num',
  7723. 0
  7724. ],
  7725. [
  7726. 14,
  7727. 'XUID',
  7728. 'array',
  7729. null
  7730. ],
  7731. [
  7732. 15,
  7733. 'charset',
  7734. 'offset',
  7735. 0
  7736. ],
  7737. [
  7738. 16,
  7739. 'Encoding',
  7740. 'offset',
  7741. 0
  7742. ],
  7743. [
  7744. 17,
  7745. 'CharStrings',
  7746. 'offset',
  7747. 0
  7748. ],
  7749. [
  7750. 18,
  7751. 'Private',
  7752. [
  7753. 'offset',
  7754. 'offset'
  7755. ],
  7756. null
  7757. ],
  7758. [
  7759. [
  7760. 12,
  7761. 21
  7762. ],
  7763. 'PostScript',
  7764. 'sid',
  7765. null
  7766. ],
  7767. [
  7768. [
  7769. 12,
  7770. 22
  7771. ],
  7772. 'BaseFontName',
  7773. 'sid',
  7774. null
  7775. ],
  7776. [
  7777. [
  7778. 12,
  7779. 23
  7780. ],
  7781. 'BaseFontBlend',
  7782. 'delta',
  7783. null
  7784. ],
  7785. [
  7786. [
  7787. 12,
  7788. 31
  7789. ],
  7790. 'CIDFontVersion',
  7791. 'num',
  7792. 0
  7793. ],
  7794. [
  7795. [
  7796. 12,
  7797. 32
  7798. ],
  7799. 'CIDFontRevision',
  7800. 'num',
  7801. 0
  7802. ],
  7803. [
  7804. [
  7805. 12,
  7806. 33
  7807. ],
  7808. 'CIDFontType',
  7809. 'num',
  7810. 0
  7811. ],
  7812. [
  7813. [
  7814. 12,
  7815. 34
  7816. ],
  7817. 'CIDCount',
  7818. 'num',
  7819. 8720
  7820. ],
  7821. [
  7822. [
  7823. 12,
  7824. 35
  7825. ],
  7826. 'UIDBase',
  7827. 'num',
  7828. null
  7829. ],
  7830. // XXX: CID Fonts on DirectWrite 6.1 only seem to work if FDSelect comes
  7831. // before FDArray.
  7832. [
  7833. [
  7834. 12,
  7835. 37
  7836. ],
  7837. 'FDSelect',
  7838. 'offset',
  7839. null
  7840. ],
  7841. [
  7842. [
  7843. 12,
  7844. 36
  7845. ],
  7846. 'FDArray',
  7847. 'offset',
  7848. null
  7849. ],
  7850. [
  7851. [
  7852. 12,
  7853. 38
  7854. ],
  7855. 'FontName',
  7856. 'sid',
  7857. null
  7858. ]
  7859. ];
  7860. var tables = null;
  7861. function CFFTopDict(strings) {
  7862. if (tables === null) {
  7863. tables = CFFDict.createTables(layout);
  7864. }
  7865. CFFDict.call(this, tables, strings);
  7866. this.privateDict = null;
  7867. }
  7868. CFFTopDict.prototype = Object.create(CFFDict.prototype);
  7869. return CFFTopDict;
  7870. }();
  7871. var CFFPrivateDict = function CFFPrivateDictClosure() {
  7872. var layout = [
  7873. [
  7874. 6,
  7875. 'BlueValues',
  7876. 'delta',
  7877. null
  7878. ],
  7879. [
  7880. 7,
  7881. 'OtherBlues',
  7882. 'delta',
  7883. null
  7884. ],
  7885. [
  7886. 8,
  7887. 'FamilyBlues',
  7888. 'delta',
  7889. null
  7890. ],
  7891. [
  7892. 9,
  7893. 'FamilyOtherBlues',
  7894. 'delta',
  7895. null
  7896. ],
  7897. [
  7898. [
  7899. 12,
  7900. 9
  7901. ],
  7902. 'BlueScale',
  7903. 'num',
  7904. 0.039625
  7905. ],
  7906. [
  7907. [
  7908. 12,
  7909. 10
  7910. ],
  7911. 'BlueShift',
  7912. 'num',
  7913. 7
  7914. ],
  7915. [
  7916. [
  7917. 12,
  7918. 11
  7919. ],
  7920. 'BlueFuzz',
  7921. 'num',
  7922. 1
  7923. ],
  7924. [
  7925. 10,
  7926. 'StdHW',
  7927. 'num',
  7928. null
  7929. ],
  7930. [
  7931. 11,
  7932. 'StdVW',
  7933. 'num',
  7934. null
  7935. ],
  7936. [
  7937. [
  7938. 12,
  7939. 12
  7940. ],
  7941. 'StemSnapH',
  7942. 'delta',
  7943. null
  7944. ],
  7945. [
  7946. [
  7947. 12,
  7948. 13
  7949. ],
  7950. 'StemSnapV',
  7951. 'delta',
  7952. null
  7953. ],
  7954. [
  7955. [
  7956. 12,
  7957. 14
  7958. ],
  7959. 'ForceBold',
  7960. 'num',
  7961. 0
  7962. ],
  7963. [
  7964. [
  7965. 12,
  7966. 17
  7967. ],
  7968. 'LanguageGroup',
  7969. 'num',
  7970. 0
  7971. ],
  7972. [
  7973. [
  7974. 12,
  7975. 18
  7976. ],
  7977. 'ExpansionFactor',
  7978. 'num',
  7979. 0.06
  7980. ],
  7981. [
  7982. [
  7983. 12,
  7984. 19
  7985. ],
  7986. 'initialRandomSeed',
  7987. 'num',
  7988. 0
  7989. ],
  7990. [
  7991. 20,
  7992. 'defaultWidthX',
  7993. 'num',
  7994. 0
  7995. ],
  7996. [
  7997. 21,
  7998. 'nominalWidthX',
  7999. 'num',
  8000. 0
  8001. ],
  8002. [
  8003. 19,
  8004. 'Subrs',
  8005. 'offset',
  8006. null
  8007. ]
  8008. ];
  8009. var tables = null;
  8010. function CFFPrivateDict(strings) {
  8011. if (tables === null) {
  8012. tables = CFFDict.createTables(layout);
  8013. }
  8014. CFFDict.call(this, tables, strings);
  8015. this.subrsIndex = null;
  8016. }
  8017. CFFPrivateDict.prototype = Object.create(CFFDict.prototype);
  8018. return CFFPrivateDict;
  8019. }();
  8020. var CFFCharsetPredefinedTypes = {
  8021. ISO_ADOBE: 0,
  8022. EXPERT: 1,
  8023. EXPERT_SUBSET: 2
  8024. };
  8025. var CFFCharset = function CFFCharsetClosure() {
  8026. function CFFCharset(predefined, format, charset, raw) {
  8027. this.predefined = predefined;
  8028. this.format = format;
  8029. this.charset = charset;
  8030. this.raw = raw;
  8031. }
  8032. return CFFCharset;
  8033. }();
  8034. var CFFEncoding = function CFFEncodingClosure() {
  8035. function CFFEncoding(predefined, format, encoding, raw) {
  8036. this.predefined = predefined;
  8037. this.format = format;
  8038. this.encoding = encoding;
  8039. this.raw = raw;
  8040. }
  8041. return CFFEncoding;
  8042. }();
  8043. var CFFFDSelect = function CFFFDSelectClosure() {
  8044. function CFFFDSelect(fdSelect, raw) {
  8045. this.fdSelect = fdSelect;
  8046. this.raw = raw;
  8047. }
  8048. CFFFDSelect.prototype = {
  8049. getFDIndex: function CFFFDSelect_get(glyphIndex) {
  8050. if (glyphIndex < 0 || glyphIndex >= this.fdSelect.length) {
  8051. return -1;
  8052. }
  8053. return this.fdSelect[glyphIndex];
  8054. }
  8055. };
  8056. return CFFFDSelect;
  8057. }();
  8058. // Helper class to keep track of where an offset is within the data and helps
  8059. // filling in that offset once it's known.
  8060. var CFFOffsetTracker = function CFFOffsetTrackerClosure() {
  8061. function CFFOffsetTracker() {
  8062. this.offsets = Object.create(null);
  8063. }
  8064. CFFOffsetTracker.prototype = {
  8065. isTracking: function CFFOffsetTracker_isTracking(key) {
  8066. return key in this.offsets;
  8067. },
  8068. track: function CFFOffsetTracker_track(key, location) {
  8069. if (key in this.offsets) {
  8070. error('Already tracking location of ' + key);
  8071. }
  8072. this.offsets[key] = location;
  8073. },
  8074. offset: function CFFOffsetTracker_offset(value) {
  8075. for (var key in this.offsets) {
  8076. this.offsets[key] += value;
  8077. }
  8078. },
  8079. setEntryLocation: function CFFOffsetTracker_setEntryLocation(key, values, output) {
  8080. if (!(key in this.offsets)) {
  8081. error('Not tracking location of ' + key);
  8082. }
  8083. var data = output.data;
  8084. var dataOffset = this.offsets[key];
  8085. var size = 5;
  8086. for (var i = 0, ii = values.length; i < ii; ++i) {
  8087. var offset0 = i * size + dataOffset;
  8088. var offset1 = offset0 + 1;
  8089. var offset2 = offset0 + 2;
  8090. var offset3 = offset0 + 3;
  8091. var offset4 = offset0 + 4;
  8092. // It's easy to screw up offsets so perform this sanity check.
  8093. if (data[offset0] !== 0x1d || data[offset1] !== 0 || data[offset2] !== 0 || data[offset3] !== 0 || data[offset4] !== 0) {
  8094. error('writing to an offset that is not empty');
  8095. }
  8096. var value = values[i];
  8097. data[offset0] = 0x1d;
  8098. data[offset1] = value >> 24 & 0xFF;
  8099. data[offset2] = value >> 16 & 0xFF;
  8100. data[offset3] = value >> 8 & 0xFF;
  8101. data[offset4] = value & 0xFF;
  8102. }
  8103. }
  8104. };
  8105. return CFFOffsetTracker;
  8106. }();
  8107. // Takes a CFF and converts it to the binary representation.
  8108. var CFFCompiler = function CFFCompilerClosure() {
  8109. function CFFCompiler(cff) {
  8110. this.cff = cff;
  8111. }
  8112. CFFCompiler.prototype = {
  8113. compile: function CFFCompiler_compile() {
  8114. var cff = this.cff;
  8115. var output = {
  8116. data: [],
  8117. length: 0,
  8118. add: function CFFCompiler_add(data) {
  8119. this.data = this.data.concat(data);
  8120. this.length = this.data.length;
  8121. }
  8122. };
  8123. // Compile the five entries that must be in order.
  8124. var header = this.compileHeader(cff.header);
  8125. output.add(header);
  8126. var nameIndex = this.compileNameIndex(cff.names);
  8127. output.add(nameIndex);
  8128. if (cff.isCIDFont) {
  8129. // The spec is unclear on how font matrices should relate to each other
  8130. // when there is one in the main top dict and the sub top dicts.
  8131. // Windows handles this differently than linux and osx so we have to
  8132. // normalize to work on all.
  8133. // Rules based off of some mailing list discussions:
  8134. // - If main font has a matrix and subfont doesn't, use the main matrix.
  8135. // - If no main font matrix and there is a subfont matrix, use the
  8136. // subfont matrix.
  8137. // - If both have matrices, concat together.
  8138. // - If neither have matrices, use default.
  8139. // To make this work on all platforms we move the top matrix into each
  8140. // sub top dict and concat if necessary.
  8141. if (cff.topDict.hasName('FontMatrix')) {
  8142. var base = cff.topDict.getByName('FontMatrix');
  8143. cff.topDict.removeByName('FontMatrix');
  8144. for (var i = 0, ii = cff.fdArray.length; i < ii; i++) {
  8145. var subDict = cff.fdArray[i];
  8146. var matrix = base.slice(0);
  8147. if (subDict.hasName('FontMatrix')) {
  8148. matrix = Util.transform(matrix, subDict.getByName('FontMatrix'));
  8149. }
  8150. subDict.setByName('FontMatrix', matrix);
  8151. }
  8152. }
  8153. }
  8154. var compiled = this.compileTopDicts([cff.topDict], output.length, cff.isCIDFont);
  8155. output.add(compiled.output);
  8156. var topDictTracker = compiled.trackers[0];
  8157. var stringIndex = this.compileStringIndex(cff.strings.strings);
  8158. output.add(stringIndex);
  8159. var globalSubrIndex = this.compileIndex(cff.globalSubrIndex);
  8160. output.add(globalSubrIndex);
  8161. // Now start on the other entries that have no specific order.
  8162. if (cff.encoding && cff.topDict.hasName('Encoding')) {
  8163. if (cff.encoding.predefined) {
  8164. topDictTracker.setEntryLocation('Encoding', [cff.encoding.format], output);
  8165. } else {
  8166. var encoding = this.compileEncoding(cff.encoding);
  8167. topDictTracker.setEntryLocation('Encoding', [output.length], output);
  8168. output.add(encoding);
  8169. }
  8170. }
  8171. if (cff.charset && cff.topDict.hasName('charset')) {
  8172. if (cff.charset.predefined) {
  8173. topDictTracker.setEntryLocation('charset', [cff.charset.format], output);
  8174. } else {
  8175. var charset = this.compileCharset(cff.charset);
  8176. topDictTracker.setEntryLocation('charset', [output.length], output);
  8177. output.add(charset);
  8178. }
  8179. }
  8180. var charStrings = this.compileCharStrings(cff.charStrings);
  8181. topDictTracker.setEntryLocation('CharStrings', [output.length], output);
  8182. output.add(charStrings);
  8183. if (cff.isCIDFont) {
  8184. // For some reason FDSelect must be in front of FDArray on windows. OSX
  8185. // and linux don't seem to care.
  8186. topDictTracker.setEntryLocation('FDSelect', [output.length], output);
  8187. var fdSelect = this.compileFDSelect(cff.fdSelect.raw);
  8188. output.add(fdSelect);
  8189. // It is unclear if the sub font dictionary can have CID related
  8190. // dictionary keys, but the sanitizer doesn't like them so remove them.
  8191. compiled = this.compileTopDicts(cff.fdArray, output.length, true);
  8192. topDictTracker.setEntryLocation('FDArray', [output.length], output);
  8193. output.add(compiled.output);
  8194. var fontDictTrackers = compiled.trackers;
  8195. this.compilePrivateDicts(cff.fdArray, fontDictTrackers, output);
  8196. }
  8197. this.compilePrivateDicts([cff.topDict], [topDictTracker], output);
  8198. // If the font data ends with INDEX whose object data is zero-length,
  8199. // the sanitizer will bail out. Add a dummy byte to avoid that.
  8200. output.add([0]);
  8201. return output.data;
  8202. },
  8203. encodeNumber: function CFFCompiler_encodeNumber(value) {
  8204. if (parseFloat(value) === parseInt(value, 10) && !isNaN(value)) {
  8205. // isInt
  8206. return this.encodeInteger(value);
  8207. } else {
  8208. return this.encodeFloat(value);
  8209. }
  8210. },
  8211. encodeFloat: function CFFCompiler_encodeFloat(num) {
  8212. var value = num.toString();
  8213. // rounding inaccurate doubles
  8214. var m = /\.(\d*?)(?:9{5,20}|0{5,20})\d{0,2}(?:e(.+)|$)/.exec(value);
  8215. if (m) {
  8216. var epsilon = parseFloat('1e' + ((m[2] ? +m[2] : 0) + m[1].length));
  8217. value = (Math.round(num * epsilon) / epsilon).toString();
  8218. }
  8219. var nibbles = '';
  8220. var i, ii;
  8221. for (i = 0, ii = value.length; i < ii; ++i) {
  8222. var a = value[i];
  8223. if (a === 'e') {
  8224. nibbles += value[++i] === '-' ? 'c' : 'b';
  8225. } else if (a === '.') {
  8226. nibbles += 'a';
  8227. } else if (a === '-') {
  8228. nibbles += 'e';
  8229. } else {
  8230. nibbles += a;
  8231. }
  8232. }
  8233. nibbles += nibbles.length & 1 ? 'f' : 'ff';
  8234. var out = [30];
  8235. for (i = 0, ii = nibbles.length; i < ii; i += 2) {
  8236. out.push(parseInt(nibbles.substr(i, 2), 16));
  8237. }
  8238. return out;
  8239. },
  8240. encodeInteger: function CFFCompiler_encodeInteger(value) {
  8241. var code;
  8242. if (value >= -107 && value <= 107) {
  8243. code = [value + 139];
  8244. } else if (value >= 108 && value <= 1131) {
  8245. value = value - 108;
  8246. code = [
  8247. (value >> 8) + 247,
  8248. value & 0xFF
  8249. ];
  8250. } else if (value >= -1131 && value <= -108) {
  8251. value = -value - 108;
  8252. code = [
  8253. (value >> 8) + 251,
  8254. value & 0xFF
  8255. ];
  8256. } else if (value >= -32768 && value <= 32767) {
  8257. code = [
  8258. 0x1c,
  8259. value >> 8 & 0xFF,
  8260. value & 0xFF
  8261. ];
  8262. } else {
  8263. code = [
  8264. 0x1d,
  8265. value >> 24 & 0xFF,
  8266. value >> 16 & 0xFF,
  8267. value >> 8 & 0xFF,
  8268. value & 0xFF
  8269. ];
  8270. }
  8271. return code;
  8272. },
  8273. compileHeader: function CFFCompiler_compileHeader(header) {
  8274. return [
  8275. header.major,
  8276. header.minor,
  8277. header.hdrSize,
  8278. header.offSize
  8279. ];
  8280. },
  8281. compileNameIndex: function CFFCompiler_compileNameIndex(names) {
  8282. var nameIndex = new CFFIndex();
  8283. for (var i = 0, ii = names.length; i < ii; ++i) {
  8284. nameIndex.add(stringToBytes(names[i]));
  8285. }
  8286. return this.compileIndex(nameIndex);
  8287. },
  8288. compileTopDicts: function CFFCompiler_compileTopDicts(dicts, length, removeCidKeys) {
  8289. var fontDictTrackers = [];
  8290. var fdArrayIndex = new CFFIndex();
  8291. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  8292. var fontDict = dicts[i];
  8293. if (removeCidKeys) {
  8294. fontDict.removeByName('CIDFontVersion');
  8295. fontDict.removeByName('CIDFontRevision');
  8296. fontDict.removeByName('CIDFontType');
  8297. fontDict.removeByName('CIDCount');
  8298. fontDict.removeByName('UIDBase');
  8299. }
  8300. var fontDictTracker = new CFFOffsetTracker();
  8301. var fontDictData = this.compileDict(fontDict, fontDictTracker);
  8302. fontDictTrackers.push(fontDictTracker);
  8303. fdArrayIndex.add(fontDictData);
  8304. fontDictTracker.offset(length);
  8305. }
  8306. fdArrayIndex = this.compileIndex(fdArrayIndex, fontDictTrackers);
  8307. return {
  8308. trackers: fontDictTrackers,
  8309. output: fdArrayIndex
  8310. };
  8311. },
  8312. compilePrivateDicts: function CFFCompiler_compilePrivateDicts(dicts, trackers, output) {
  8313. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  8314. var fontDict = dicts[i];
  8315. assert(fontDict.privateDict && fontDict.hasName('Private'), 'There must be an private dictionary.');
  8316. var privateDict = fontDict.privateDict;
  8317. var privateDictTracker = new CFFOffsetTracker();
  8318. var privateDictData = this.compileDict(privateDict, privateDictTracker);
  8319. var outputLength = output.length;
  8320. privateDictTracker.offset(outputLength);
  8321. if (!privateDictData.length) {
  8322. // The private dictionary was empty, set the output length to zero to
  8323. // ensure the offset length isn't out of bounds in the eyes of the
  8324. // sanitizer.
  8325. outputLength = 0;
  8326. }
  8327. trackers[i].setEntryLocation('Private', [
  8328. privateDictData.length,
  8329. outputLength
  8330. ], output);
  8331. output.add(privateDictData);
  8332. if (privateDict.subrsIndex && privateDict.hasName('Subrs')) {
  8333. var subrs = this.compileIndex(privateDict.subrsIndex);
  8334. privateDictTracker.setEntryLocation('Subrs', [privateDictData.length], output);
  8335. output.add(subrs);
  8336. }
  8337. }
  8338. },
  8339. compileDict: function CFFCompiler_compileDict(dict, offsetTracker) {
  8340. var out = [];
  8341. // The dictionary keys must be in a certain order.
  8342. var order = dict.order;
  8343. for (var i = 0; i < order.length; ++i) {
  8344. var key = order[i];
  8345. if (!(key in dict.values)) {
  8346. continue;
  8347. }
  8348. var values = dict.values[key];
  8349. var types = dict.types[key];
  8350. if (!isArray(types)) {
  8351. types = [types];
  8352. }
  8353. if (!isArray(values)) {
  8354. values = [values];
  8355. }
  8356. // Remove any empty dict values.
  8357. if (values.length === 0) {
  8358. continue;
  8359. }
  8360. for (var j = 0, jj = types.length; j < jj; ++j) {
  8361. var type = types[j];
  8362. var value = values[j];
  8363. switch (type) {
  8364. case 'num':
  8365. case 'sid':
  8366. out = out.concat(this.encodeNumber(value));
  8367. break;
  8368. case 'offset':
  8369. // For offsets we just insert a 32bit integer so we don't have to
  8370. // deal with figuring out the length of the offset when it gets
  8371. // replaced later on by the compiler.
  8372. var name = dict.keyToNameMap[key];
  8373. // Some offsets have the offset and the length, so just record the
  8374. // position of the first one.
  8375. if (!offsetTracker.isTracking(name)) {
  8376. offsetTracker.track(name, out.length);
  8377. }
  8378. out = out.concat([
  8379. 0x1d,
  8380. 0,
  8381. 0,
  8382. 0,
  8383. 0
  8384. ]);
  8385. break;
  8386. case 'array':
  8387. case 'delta':
  8388. out = out.concat(this.encodeNumber(value));
  8389. for (var k = 1, kk = values.length; k < kk; ++k) {
  8390. out = out.concat(this.encodeNumber(values[k]));
  8391. }
  8392. break;
  8393. default:
  8394. error('Unknown data type of ' + type);
  8395. break;
  8396. }
  8397. }
  8398. out = out.concat(dict.opcodes[key]);
  8399. }
  8400. return out;
  8401. },
  8402. compileStringIndex: function CFFCompiler_compileStringIndex(strings) {
  8403. var stringIndex = new CFFIndex();
  8404. for (var i = 0, ii = strings.length; i < ii; ++i) {
  8405. stringIndex.add(stringToBytes(strings[i]));
  8406. }
  8407. return this.compileIndex(stringIndex);
  8408. },
  8409. compileGlobalSubrIndex: function CFFCompiler_compileGlobalSubrIndex() {
  8410. var globalSubrIndex = this.cff.globalSubrIndex;
  8411. this.out.writeByteArray(this.compileIndex(globalSubrIndex));
  8412. },
  8413. compileCharStrings: function CFFCompiler_compileCharStrings(charStrings) {
  8414. return this.compileIndex(charStrings);
  8415. },
  8416. compileCharset: function CFFCompiler_compileCharset(charset) {
  8417. return this.compileTypedArray(charset.raw);
  8418. },
  8419. compileEncoding: function CFFCompiler_compileEncoding(encoding) {
  8420. return this.compileTypedArray(encoding.raw);
  8421. },
  8422. compileFDSelect: function CFFCompiler_compileFDSelect(fdSelect) {
  8423. return this.compileTypedArray(fdSelect);
  8424. },
  8425. compileTypedArray: function CFFCompiler_compileTypedArray(data) {
  8426. var out = [];
  8427. for (var i = 0, ii = data.length; i < ii; ++i) {
  8428. out[i] = data[i];
  8429. }
  8430. return out;
  8431. },
  8432. compileIndex: function CFFCompiler_compileIndex(index, trackers) {
  8433. trackers = trackers || [];
  8434. var objects = index.objects;
  8435. // First 2 bytes contains the number of objects contained into this index
  8436. var count = objects.length;
  8437. // If there is no object, just create an index. This technically
  8438. // should just be [0, 0] but OTS has an issue with that.
  8439. if (count === 0) {
  8440. return [
  8441. 0,
  8442. 0,
  8443. 0
  8444. ];
  8445. }
  8446. var data = [
  8447. count >> 8 & 0xFF,
  8448. count & 0xff
  8449. ];
  8450. var lastOffset = 1, i;
  8451. for (i = 0; i < count; ++i) {
  8452. lastOffset += objects[i].length;
  8453. }
  8454. var offsetSize;
  8455. if (lastOffset < 0x100) {
  8456. offsetSize = 1;
  8457. } else if (lastOffset < 0x10000) {
  8458. offsetSize = 2;
  8459. } else if (lastOffset < 0x1000000) {
  8460. offsetSize = 3;
  8461. } else {
  8462. offsetSize = 4;
  8463. }
  8464. // Next byte contains the offset size use to reference object in the file
  8465. data.push(offsetSize);
  8466. // Add another offset after this one because we need a new offset
  8467. var relativeOffset = 1;
  8468. for (i = 0; i < count + 1; i++) {
  8469. if (offsetSize === 1) {
  8470. data.push(relativeOffset & 0xFF);
  8471. } else if (offsetSize === 2) {
  8472. data.push(relativeOffset >> 8 & 0xFF, relativeOffset & 0xFF);
  8473. } else if (offsetSize === 3) {
  8474. data.push(relativeOffset >> 16 & 0xFF, relativeOffset >> 8 & 0xFF, relativeOffset & 0xFF);
  8475. } else {
  8476. data.push(relativeOffset >>> 24 & 0xFF, relativeOffset >> 16 & 0xFF, relativeOffset >> 8 & 0xFF, relativeOffset & 0xFF);
  8477. }
  8478. if (objects[i]) {
  8479. relativeOffset += objects[i].length;
  8480. }
  8481. }
  8482. for (i = 0; i < count; i++) {
  8483. // Notify the tracker where the object will be offset in the data.
  8484. if (trackers[i]) {
  8485. trackers[i].offset(data.length);
  8486. }
  8487. for (var j = 0, jj = objects[i].length; j < jj; j++) {
  8488. data.push(objects[i][j]);
  8489. }
  8490. }
  8491. return data;
  8492. }
  8493. };
  8494. return CFFCompiler;
  8495. }();
  8496. exports.CFFStandardStrings = CFFStandardStrings;
  8497. exports.CFFParser = CFFParser;
  8498. exports.CFF = CFF;
  8499. exports.CFFHeader = CFFHeader;
  8500. exports.CFFStrings = CFFStrings;
  8501. exports.CFFIndex = CFFIndex;
  8502. exports.CFFCharset = CFFCharset;
  8503. exports.CFFTopDict = CFFTopDict;
  8504. exports.CFFPrivateDict = CFFPrivateDict;
  8505. exports.CFFCompiler = CFFCompiler;
  8506. }));
  8507. (function (root, factory) {
  8508. factory(root.pdfjsCoreChunkedStream = {}, root.pdfjsSharedUtil);
  8509. }(this, function (exports, sharedUtil) {
  8510. var MissingDataException = sharedUtil.MissingDataException;
  8511. var arrayByteLength = sharedUtil.arrayByteLength;
  8512. var arraysToBytes = sharedUtil.arraysToBytes;
  8513. var assert = sharedUtil.assert;
  8514. var createPromiseCapability = sharedUtil.createPromiseCapability;
  8515. var isInt = sharedUtil.isInt;
  8516. var isEmptyObj = sharedUtil.isEmptyObj;
  8517. var ChunkedStream = function ChunkedStreamClosure() {
  8518. function ChunkedStream(length, chunkSize, manager) {
  8519. this.bytes = new Uint8Array(length);
  8520. this.start = 0;
  8521. this.pos = 0;
  8522. this.end = length;
  8523. this.chunkSize = chunkSize;
  8524. this.loadedChunks = [];
  8525. this.numChunksLoaded = 0;
  8526. this.numChunks = Math.ceil(length / chunkSize);
  8527. this.manager = manager;
  8528. this.progressiveDataLength = 0;
  8529. this.lastSuccessfulEnsureByteChunk = -1;
  8530. }
  8531. // a single-entry cache
  8532. // required methods for a stream. if a particular stream does not
  8533. // implement these, an error should be thrown
  8534. ChunkedStream.prototype = {
  8535. getMissingChunks: function ChunkedStream_getMissingChunks() {
  8536. var chunks = [];
  8537. for (var chunk = 0, n = this.numChunks; chunk < n; ++chunk) {
  8538. if (!this.loadedChunks[chunk]) {
  8539. chunks.push(chunk);
  8540. }
  8541. }
  8542. return chunks;
  8543. },
  8544. getBaseStreams: function ChunkedStream_getBaseStreams() {
  8545. return [this];
  8546. },
  8547. allChunksLoaded: function ChunkedStream_allChunksLoaded() {
  8548. return this.numChunksLoaded === this.numChunks;
  8549. },
  8550. onReceiveData: function ChunkedStream_onReceiveData(begin, chunk) {
  8551. var end = begin + chunk.byteLength;
  8552. assert(begin % this.chunkSize === 0, 'Bad begin offset: ' + begin);
  8553. // Using this.length is inaccurate here since this.start can be moved
  8554. // See ChunkedStream.moveStart()
  8555. var length = this.bytes.length;
  8556. assert(end % this.chunkSize === 0 || end === length, 'Bad end offset: ' + end);
  8557. this.bytes.set(new Uint8Array(chunk), begin);
  8558. var chunkSize = this.chunkSize;
  8559. var beginChunk = Math.floor(begin / chunkSize);
  8560. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  8561. var curChunk;
  8562. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  8563. if (!this.loadedChunks[curChunk]) {
  8564. this.loadedChunks[curChunk] = true;
  8565. ++this.numChunksLoaded;
  8566. }
  8567. }
  8568. },
  8569. onReceiveProgressiveData: function ChunkedStream_onReceiveProgressiveData(data) {
  8570. var position = this.progressiveDataLength;
  8571. var beginChunk = Math.floor(position / this.chunkSize);
  8572. this.bytes.set(new Uint8Array(data), position);
  8573. position += data.byteLength;
  8574. this.progressiveDataLength = position;
  8575. var endChunk = position >= this.end ? this.numChunks : Math.floor(position / this.chunkSize);
  8576. var curChunk;
  8577. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  8578. if (!this.loadedChunks[curChunk]) {
  8579. this.loadedChunks[curChunk] = true;
  8580. ++this.numChunksLoaded;
  8581. }
  8582. }
  8583. },
  8584. ensureByte: function ChunkedStream_ensureByte(pos) {
  8585. var chunk = Math.floor(pos / this.chunkSize);
  8586. if (chunk === this.lastSuccessfulEnsureByteChunk) {
  8587. return;
  8588. }
  8589. if (!this.loadedChunks[chunk]) {
  8590. throw new MissingDataException(pos, pos + 1);
  8591. }
  8592. this.lastSuccessfulEnsureByteChunk = chunk;
  8593. },
  8594. ensureRange: function ChunkedStream_ensureRange(begin, end) {
  8595. if (begin >= end) {
  8596. return;
  8597. }
  8598. if (end <= this.progressiveDataLength) {
  8599. return;
  8600. }
  8601. var chunkSize = this.chunkSize;
  8602. var beginChunk = Math.floor(begin / chunkSize);
  8603. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  8604. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  8605. if (!this.loadedChunks[chunk]) {
  8606. throw new MissingDataException(begin, end);
  8607. }
  8608. }
  8609. },
  8610. nextEmptyChunk: function ChunkedStream_nextEmptyChunk(beginChunk) {
  8611. var chunk, numChunks = this.numChunks;
  8612. for (var i = 0; i < numChunks; ++i) {
  8613. chunk = (beginChunk + i) % numChunks;
  8614. // Wrap around to beginning
  8615. if (!this.loadedChunks[chunk]) {
  8616. return chunk;
  8617. }
  8618. }
  8619. return null;
  8620. },
  8621. hasChunk: function ChunkedStream_hasChunk(chunk) {
  8622. return !!this.loadedChunks[chunk];
  8623. },
  8624. get length() {
  8625. return this.end - this.start;
  8626. },
  8627. get isEmpty() {
  8628. return this.length === 0;
  8629. },
  8630. getByte: function ChunkedStream_getByte() {
  8631. var pos = this.pos;
  8632. if (pos >= this.end) {
  8633. return -1;
  8634. }
  8635. this.ensureByte(pos);
  8636. return this.bytes[this.pos++];
  8637. },
  8638. getUint16: function ChunkedStream_getUint16() {
  8639. var b0 = this.getByte();
  8640. var b1 = this.getByte();
  8641. if (b0 === -1 || b1 === -1) {
  8642. return -1;
  8643. }
  8644. return (b0 << 8) + b1;
  8645. },
  8646. getInt32: function ChunkedStream_getInt32() {
  8647. var b0 = this.getByte();
  8648. var b1 = this.getByte();
  8649. var b2 = this.getByte();
  8650. var b3 = this.getByte();
  8651. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  8652. },
  8653. // returns subarray of original buffer
  8654. // should only be read
  8655. getBytes: function ChunkedStream_getBytes(length) {
  8656. var bytes = this.bytes;
  8657. var pos = this.pos;
  8658. var strEnd = this.end;
  8659. if (!length) {
  8660. this.ensureRange(pos, strEnd);
  8661. return bytes.subarray(pos, strEnd);
  8662. }
  8663. var end = pos + length;
  8664. if (end > strEnd) {
  8665. end = strEnd;
  8666. }
  8667. this.ensureRange(pos, end);
  8668. this.pos = end;
  8669. return bytes.subarray(pos, end);
  8670. },
  8671. peekByte: function ChunkedStream_peekByte() {
  8672. var peekedByte = this.getByte();
  8673. this.pos--;
  8674. return peekedByte;
  8675. },
  8676. peekBytes: function ChunkedStream_peekBytes(length) {
  8677. var bytes = this.getBytes(length);
  8678. this.pos -= bytes.length;
  8679. return bytes;
  8680. },
  8681. getByteRange: function ChunkedStream_getBytes(begin, end) {
  8682. this.ensureRange(begin, end);
  8683. return this.bytes.subarray(begin, end);
  8684. },
  8685. skip: function ChunkedStream_skip(n) {
  8686. if (!n) {
  8687. n = 1;
  8688. }
  8689. this.pos += n;
  8690. },
  8691. reset: function ChunkedStream_reset() {
  8692. this.pos = this.start;
  8693. },
  8694. moveStart: function ChunkedStream_moveStart() {
  8695. this.start = this.pos;
  8696. },
  8697. makeSubStream: function ChunkedStream_makeSubStream(start, length, dict) {
  8698. this.ensureRange(start, start + length);
  8699. function ChunkedStreamSubstream() {
  8700. }
  8701. ChunkedStreamSubstream.prototype = Object.create(this);
  8702. ChunkedStreamSubstream.prototype.getMissingChunks = function () {
  8703. var chunkSize = this.chunkSize;
  8704. var beginChunk = Math.floor(this.start / chunkSize);
  8705. var endChunk = Math.floor((this.end - 1) / chunkSize) + 1;
  8706. var missingChunks = [];
  8707. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  8708. if (!this.loadedChunks[chunk]) {
  8709. missingChunks.push(chunk);
  8710. }
  8711. }
  8712. return missingChunks;
  8713. };
  8714. var subStream = new ChunkedStreamSubstream();
  8715. subStream.pos = subStream.start = start;
  8716. subStream.end = start + length || this.end;
  8717. subStream.dict = dict;
  8718. return subStream;
  8719. },
  8720. isStream: true
  8721. };
  8722. return ChunkedStream;
  8723. }();
  8724. var ChunkedStreamManager = function ChunkedStreamManagerClosure() {
  8725. function ChunkedStreamManager(pdfNetworkStream, args) {
  8726. var chunkSize = args.rangeChunkSize;
  8727. var length = args.length;
  8728. this.stream = new ChunkedStream(length, chunkSize, this);
  8729. this.length = length;
  8730. this.chunkSize = chunkSize;
  8731. this.pdfNetworkStream = pdfNetworkStream;
  8732. this.url = args.url;
  8733. this.disableAutoFetch = args.disableAutoFetch;
  8734. this.msgHandler = args.msgHandler;
  8735. this.currRequestId = 0;
  8736. this.chunksNeededByRequest = Object.create(null);
  8737. this.requestsByChunk = Object.create(null);
  8738. this.promisesByRequest = Object.create(null);
  8739. this.progressiveDataLength = 0;
  8740. this.aborted = false;
  8741. this._loadedStreamCapability = createPromiseCapability();
  8742. }
  8743. ChunkedStreamManager.prototype = {
  8744. onLoadedStream: function ChunkedStreamManager_getLoadedStream() {
  8745. return this._loadedStreamCapability.promise;
  8746. },
  8747. sendRequest: function ChunkedStreamManager_sendRequest(begin, end) {
  8748. var rangeReader = this.pdfNetworkStream.getRangeReader(begin, end);
  8749. if (!rangeReader.isStreamingSupported) {
  8750. rangeReader.onProgress = this.onProgress.bind(this);
  8751. }
  8752. var chunks = [], loaded = 0;
  8753. var manager = this;
  8754. var promise = new Promise(function (resolve, reject) {
  8755. var readChunk = function (chunk) {
  8756. try {
  8757. if (!chunk.done) {
  8758. var data = chunk.value;
  8759. chunks.push(data);
  8760. loaded += arrayByteLength(data);
  8761. if (rangeReader.isStreamingSupported) {
  8762. manager.onProgress({ loaded: loaded });
  8763. }
  8764. rangeReader.read().then(readChunk, reject);
  8765. return;
  8766. }
  8767. var chunkData = arraysToBytes(chunks);
  8768. chunks = null;
  8769. resolve(chunkData);
  8770. } catch (e) {
  8771. reject(e);
  8772. }
  8773. };
  8774. rangeReader.read().then(readChunk, reject);
  8775. });
  8776. promise.then(function (data) {
  8777. if (this.aborted) {
  8778. return;
  8779. }
  8780. // ignoring any data after abort
  8781. this.onReceiveData({
  8782. chunk: data,
  8783. begin: begin
  8784. });
  8785. }.bind(this));
  8786. },
  8787. // TODO check errors
  8788. // Get all the chunks that are not yet loaded and groups them into
  8789. // contiguous ranges to load in as few requests as possible
  8790. requestAllChunks: function ChunkedStreamManager_requestAllChunks() {
  8791. var missingChunks = this.stream.getMissingChunks();
  8792. this._requestChunks(missingChunks);
  8793. return this._loadedStreamCapability.promise;
  8794. },
  8795. _requestChunks: function ChunkedStreamManager_requestChunks(chunks) {
  8796. var requestId = this.currRequestId++;
  8797. var i, ii;
  8798. var chunksNeeded = Object.create(null);
  8799. this.chunksNeededByRequest[requestId] = chunksNeeded;
  8800. for (i = 0, ii = chunks.length; i < ii; i++) {
  8801. if (!this.stream.hasChunk(chunks[i])) {
  8802. chunksNeeded[chunks[i]] = true;
  8803. }
  8804. }
  8805. if (isEmptyObj(chunksNeeded)) {
  8806. return Promise.resolve();
  8807. }
  8808. var capability = createPromiseCapability();
  8809. this.promisesByRequest[requestId] = capability;
  8810. var chunksToRequest = [];
  8811. for (var chunk in chunksNeeded) {
  8812. chunk = chunk | 0;
  8813. if (!(chunk in this.requestsByChunk)) {
  8814. this.requestsByChunk[chunk] = [];
  8815. chunksToRequest.push(chunk);
  8816. }
  8817. this.requestsByChunk[chunk].push(requestId);
  8818. }
  8819. if (!chunksToRequest.length) {
  8820. return capability.promise;
  8821. }
  8822. var groupedChunksToRequest = this.groupChunks(chunksToRequest);
  8823. for (i = 0; i < groupedChunksToRequest.length; ++i) {
  8824. var groupedChunk = groupedChunksToRequest[i];
  8825. var begin = groupedChunk.beginChunk * this.chunkSize;
  8826. var end = Math.min(groupedChunk.endChunk * this.chunkSize, this.length);
  8827. this.sendRequest(begin, end);
  8828. }
  8829. return capability.promise;
  8830. },
  8831. getStream: function ChunkedStreamManager_getStream() {
  8832. return this.stream;
  8833. },
  8834. // Loads any chunks in the requested range that are not yet loaded
  8835. requestRange: function ChunkedStreamManager_requestRange(begin, end) {
  8836. end = Math.min(end, this.length);
  8837. var beginChunk = this.getBeginChunk(begin);
  8838. var endChunk = this.getEndChunk(end);
  8839. var chunks = [];
  8840. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  8841. chunks.push(chunk);
  8842. }
  8843. return this._requestChunks(chunks);
  8844. },
  8845. requestRanges: function ChunkedStreamManager_requestRanges(ranges) {
  8846. ranges = ranges || [];
  8847. var chunksToRequest = [];
  8848. for (var i = 0; i < ranges.length; i++) {
  8849. var beginChunk = this.getBeginChunk(ranges[i].begin);
  8850. var endChunk = this.getEndChunk(ranges[i].end);
  8851. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  8852. if (chunksToRequest.indexOf(chunk) < 0) {
  8853. chunksToRequest.push(chunk);
  8854. }
  8855. }
  8856. }
  8857. chunksToRequest.sort(function (a, b) {
  8858. return a - b;
  8859. });
  8860. return this._requestChunks(chunksToRequest);
  8861. },
  8862. // Groups a sorted array of chunks into as few contiguous larger
  8863. // chunks as possible
  8864. groupChunks: function ChunkedStreamManager_groupChunks(chunks) {
  8865. var groupedChunks = [];
  8866. var beginChunk = -1;
  8867. var prevChunk = -1;
  8868. for (var i = 0; i < chunks.length; ++i) {
  8869. var chunk = chunks[i];
  8870. if (beginChunk < 0) {
  8871. beginChunk = chunk;
  8872. }
  8873. if (prevChunk >= 0 && prevChunk + 1 !== chunk) {
  8874. groupedChunks.push({
  8875. beginChunk: beginChunk,
  8876. endChunk: prevChunk + 1
  8877. });
  8878. beginChunk = chunk;
  8879. }
  8880. if (i + 1 === chunks.length) {
  8881. groupedChunks.push({
  8882. beginChunk: beginChunk,
  8883. endChunk: chunk + 1
  8884. });
  8885. }
  8886. prevChunk = chunk;
  8887. }
  8888. return groupedChunks;
  8889. },
  8890. onProgress: function ChunkedStreamManager_onProgress(args) {
  8891. var bytesLoaded = this.stream.numChunksLoaded * this.chunkSize + args.loaded;
  8892. this.msgHandler.send('DocProgress', {
  8893. loaded: bytesLoaded,
  8894. total: this.length
  8895. });
  8896. },
  8897. onReceiveData: function ChunkedStreamManager_onReceiveData(args) {
  8898. var chunk = args.chunk;
  8899. var isProgressive = args.begin === undefined;
  8900. var begin = isProgressive ? this.progressiveDataLength : args.begin;
  8901. var end = begin + chunk.byteLength;
  8902. var beginChunk = Math.floor(begin / this.chunkSize);
  8903. var endChunk = end < this.length ? Math.floor(end / this.chunkSize) : Math.ceil(end / this.chunkSize);
  8904. if (isProgressive) {
  8905. this.stream.onReceiveProgressiveData(chunk);
  8906. this.progressiveDataLength = end;
  8907. } else {
  8908. this.stream.onReceiveData(begin, chunk);
  8909. }
  8910. if (this.stream.allChunksLoaded()) {
  8911. this._loadedStreamCapability.resolve(this.stream);
  8912. }
  8913. var loadedRequests = [];
  8914. var i, requestId;
  8915. for (chunk = beginChunk; chunk < endChunk; ++chunk) {
  8916. // The server might return more chunks than requested
  8917. var requestIds = this.requestsByChunk[chunk] || [];
  8918. delete this.requestsByChunk[chunk];
  8919. for (i = 0; i < requestIds.length; ++i) {
  8920. requestId = requestIds[i];
  8921. var chunksNeeded = this.chunksNeededByRequest[requestId];
  8922. if (chunk in chunksNeeded) {
  8923. delete chunksNeeded[chunk];
  8924. }
  8925. if (!isEmptyObj(chunksNeeded)) {
  8926. continue;
  8927. }
  8928. loadedRequests.push(requestId);
  8929. }
  8930. }
  8931. // If there are no pending requests, automatically fetch the next
  8932. // unfetched chunk of the PDF
  8933. if (!this.disableAutoFetch && isEmptyObj(this.requestsByChunk)) {
  8934. var nextEmptyChunk;
  8935. if (this.stream.numChunksLoaded === 1) {
  8936. // This is a special optimization so that after fetching the first
  8937. // chunk, rather than fetching the second chunk, we fetch the last
  8938. // chunk.
  8939. var lastChunk = this.stream.numChunks - 1;
  8940. if (!this.stream.hasChunk(lastChunk)) {
  8941. nextEmptyChunk = lastChunk;
  8942. }
  8943. } else {
  8944. nextEmptyChunk = this.stream.nextEmptyChunk(endChunk);
  8945. }
  8946. if (isInt(nextEmptyChunk)) {
  8947. this._requestChunks([nextEmptyChunk]);
  8948. }
  8949. }
  8950. for (i = 0; i < loadedRequests.length; ++i) {
  8951. requestId = loadedRequests[i];
  8952. var capability = this.promisesByRequest[requestId];
  8953. delete this.promisesByRequest[requestId];
  8954. capability.resolve();
  8955. }
  8956. this.msgHandler.send('DocProgress', {
  8957. loaded: this.stream.numChunksLoaded * this.chunkSize,
  8958. total: this.length
  8959. });
  8960. },
  8961. onError: function ChunkedStreamManager_onError(err) {
  8962. this._loadedStreamCapability.reject(err);
  8963. },
  8964. getBeginChunk: function ChunkedStreamManager_getBeginChunk(begin) {
  8965. var chunk = Math.floor(begin / this.chunkSize);
  8966. return chunk;
  8967. },
  8968. getEndChunk: function ChunkedStreamManager_getEndChunk(end) {
  8969. var chunk = Math.floor((end - 1) / this.chunkSize) + 1;
  8970. return chunk;
  8971. },
  8972. abort: function ChunkedStreamManager_abort() {
  8973. this.aborted = true;
  8974. if (this.pdfNetworkStream) {
  8975. this.pdfNetworkStream.cancelAllRequests('abort');
  8976. }
  8977. for (var requestId in this.promisesByRequest) {
  8978. var capability = this.promisesByRequest[requestId];
  8979. capability.reject(new Error('Request was aborted'));
  8980. }
  8981. }
  8982. };
  8983. return ChunkedStreamManager;
  8984. }();
  8985. exports.ChunkedStream = ChunkedStream;
  8986. exports.ChunkedStreamManager = ChunkedStreamManager;
  8987. }));
  8988. (function (root, factory) {
  8989. factory(root.pdfjsCoreGlyphList = {}, root.pdfjsSharedUtil);
  8990. }(this, function (exports, sharedUtil) {
  8991. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  8992. var getGlyphsUnicode = getLookupTableFactory(function (t) {
  8993. t['A'] = 0x0041;
  8994. t['AE'] = 0x00C6;
  8995. t['AEacute'] = 0x01FC;
  8996. t['AEmacron'] = 0x01E2;
  8997. t['AEsmall'] = 0xF7E6;
  8998. t['Aacute'] = 0x00C1;
  8999. t['Aacutesmall'] = 0xF7E1;
  9000. t['Abreve'] = 0x0102;
  9001. t['Abreveacute'] = 0x1EAE;
  9002. t['Abrevecyrillic'] = 0x04D0;
  9003. t['Abrevedotbelow'] = 0x1EB6;
  9004. t['Abrevegrave'] = 0x1EB0;
  9005. t['Abrevehookabove'] = 0x1EB2;
  9006. t['Abrevetilde'] = 0x1EB4;
  9007. t['Acaron'] = 0x01CD;
  9008. t['Acircle'] = 0x24B6;
  9009. t['Acircumflex'] = 0x00C2;
  9010. t['Acircumflexacute'] = 0x1EA4;
  9011. t['Acircumflexdotbelow'] = 0x1EAC;
  9012. t['Acircumflexgrave'] = 0x1EA6;
  9013. t['Acircumflexhookabove'] = 0x1EA8;
  9014. t['Acircumflexsmall'] = 0xF7E2;
  9015. t['Acircumflextilde'] = 0x1EAA;
  9016. t['Acute'] = 0xF6C9;
  9017. t['Acutesmall'] = 0xF7B4;
  9018. t['Acyrillic'] = 0x0410;
  9019. t['Adblgrave'] = 0x0200;
  9020. t['Adieresis'] = 0x00C4;
  9021. t['Adieresiscyrillic'] = 0x04D2;
  9022. t['Adieresismacron'] = 0x01DE;
  9023. t['Adieresissmall'] = 0xF7E4;
  9024. t['Adotbelow'] = 0x1EA0;
  9025. t['Adotmacron'] = 0x01E0;
  9026. t['Agrave'] = 0x00C0;
  9027. t['Agravesmall'] = 0xF7E0;
  9028. t['Ahookabove'] = 0x1EA2;
  9029. t['Aiecyrillic'] = 0x04D4;
  9030. t['Ainvertedbreve'] = 0x0202;
  9031. t['Alpha'] = 0x0391;
  9032. t['Alphatonos'] = 0x0386;
  9033. t['Amacron'] = 0x0100;
  9034. t['Amonospace'] = 0xFF21;
  9035. t['Aogonek'] = 0x0104;
  9036. t['Aring'] = 0x00C5;
  9037. t['Aringacute'] = 0x01FA;
  9038. t['Aringbelow'] = 0x1E00;
  9039. t['Aringsmall'] = 0xF7E5;
  9040. t['Asmall'] = 0xF761;
  9041. t['Atilde'] = 0x00C3;
  9042. t['Atildesmall'] = 0xF7E3;
  9043. t['Aybarmenian'] = 0x0531;
  9044. t['B'] = 0x0042;
  9045. t['Bcircle'] = 0x24B7;
  9046. t['Bdotaccent'] = 0x1E02;
  9047. t['Bdotbelow'] = 0x1E04;
  9048. t['Becyrillic'] = 0x0411;
  9049. t['Benarmenian'] = 0x0532;
  9050. t['Beta'] = 0x0392;
  9051. t['Bhook'] = 0x0181;
  9052. t['Blinebelow'] = 0x1E06;
  9053. t['Bmonospace'] = 0xFF22;
  9054. t['Brevesmall'] = 0xF6F4;
  9055. t['Bsmall'] = 0xF762;
  9056. t['Btopbar'] = 0x0182;
  9057. t['C'] = 0x0043;
  9058. t['Caarmenian'] = 0x053E;
  9059. t['Cacute'] = 0x0106;
  9060. t['Caron'] = 0xF6CA;
  9061. t['Caronsmall'] = 0xF6F5;
  9062. t['Ccaron'] = 0x010C;
  9063. t['Ccedilla'] = 0x00C7;
  9064. t['Ccedillaacute'] = 0x1E08;
  9065. t['Ccedillasmall'] = 0xF7E7;
  9066. t['Ccircle'] = 0x24B8;
  9067. t['Ccircumflex'] = 0x0108;
  9068. t['Cdot'] = 0x010A;
  9069. t['Cdotaccent'] = 0x010A;
  9070. t['Cedillasmall'] = 0xF7B8;
  9071. t['Chaarmenian'] = 0x0549;
  9072. t['Cheabkhasiancyrillic'] = 0x04BC;
  9073. t['Checyrillic'] = 0x0427;
  9074. t['Chedescenderabkhasiancyrillic'] = 0x04BE;
  9075. t['Chedescendercyrillic'] = 0x04B6;
  9076. t['Chedieresiscyrillic'] = 0x04F4;
  9077. t['Cheharmenian'] = 0x0543;
  9078. t['Chekhakassiancyrillic'] = 0x04CB;
  9079. t['Cheverticalstrokecyrillic'] = 0x04B8;
  9080. t['Chi'] = 0x03A7;
  9081. t['Chook'] = 0x0187;
  9082. t['Circumflexsmall'] = 0xF6F6;
  9083. t['Cmonospace'] = 0xFF23;
  9084. t['Coarmenian'] = 0x0551;
  9085. t['Csmall'] = 0xF763;
  9086. t['D'] = 0x0044;
  9087. t['DZ'] = 0x01F1;
  9088. t['DZcaron'] = 0x01C4;
  9089. t['Daarmenian'] = 0x0534;
  9090. t['Dafrican'] = 0x0189;
  9091. t['Dcaron'] = 0x010E;
  9092. t['Dcedilla'] = 0x1E10;
  9093. t['Dcircle'] = 0x24B9;
  9094. t['Dcircumflexbelow'] = 0x1E12;
  9095. t['Dcroat'] = 0x0110;
  9096. t['Ddotaccent'] = 0x1E0A;
  9097. t['Ddotbelow'] = 0x1E0C;
  9098. t['Decyrillic'] = 0x0414;
  9099. t['Deicoptic'] = 0x03EE;
  9100. t['Delta'] = 0x2206;
  9101. t['Deltagreek'] = 0x0394;
  9102. t['Dhook'] = 0x018A;
  9103. t['Dieresis'] = 0xF6CB;
  9104. t['DieresisAcute'] = 0xF6CC;
  9105. t['DieresisGrave'] = 0xF6CD;
  9106. t['Dieresissmall'] = 0xF7A8;
  9107. t['Digammagreek'] = 0x03DC;
  9108. t['Djecyrillic'] = 0x0402;
  9109. t['Dlinebelow'] = 0x1E0E;
  9110. t['Dmonospace'] = 0xFF24;
  9111. t['Dotaccentsmall'] = 0xF6F7;
  9112. t['Dslash'] = 0x0110;
  9113. t['Dsmall'] = 0xF764;
  9114. t['Dtopbar'] = 0x018B;
  9115. t['Dz'] = 0x01F2;
  9116. t['Dzcaron'] = 0x01C5;
  9117. t['Dzeabkhasiancyrillic'] = 0x04E0;
  9118. t['Dzecyrillic'] = 0x0405;
  9119. t['Dzhecyrillic'] = 0x040F;
  9120. t['E'] = 0x0045;
  9121. t['Eacute'] = 0x00C9;
  9122. t['Eacutesmall'] = 0xF7E9;
  9123. t['Ebreve'] = 0x0114;
  9124. t['Ecaron'] = 0x011A;
  9125. t['Ecedillabreve'] = 0x1E1C;
  9126. t['Echarmenian'] = 0x0535;
  9127. t['Ecircle'] = 0x24BA;
  9128. t['Ecircumflex'] = 0x00CA;
  9129. t['Ecircumflexacute'] = 0x1EBE;
  9130. t['Ecircumflexbelow'] = 0x1E18;
  9131. t['Ecircumflexdotbelow'] = 0x1EC6;
  9132. t['Ecircumflexgrave'] = 0x1EC0;
  9133. t['Ecircumflexhookabove'] = 0x1EC2;
  9134. t['Ecircumflexsmall'] = 0xF7EA;
  9135. t['Ecircumflextilde'] = 0x1EC4;
  9136. t['Ecyrillic'] = 0x0404;
  9137. t['Edblgrave'] = 0x0204;
  9138. t['Edieresis'] = 0x00CB;
  9139. t['Edieresissmall'] = 0xF7EB;
  9140. t['Edot'] = 0x0116;
  9141. t['Edotaccent'] = 0x0116;
  9142. t['Edotbelow'] = 0x1EB8;
  9143. t['Efcyrillic'] = 0x0424;
  9144. t['Egrave'] = 0x00C8;
  9145. t['Egravesmall'] = 0xF7E8;
  9146. t['Eharmenian'] = 0x0537;
  9147. t['Ehookabove'] = 0x1EBA;
  9148. t['Eightroman'] = 0x2167;
  9149. t['Einvertedbreve'] = 0x0206;
  9150. t['Eiotifiedcyrillic'] = 0x0464;
  9151. t['Elcyrillic'] = 0x041B;
  9152. t['Elevenroman'] = 0x216A;
  9153. t['Emacron'] = 0x0112;
  9154. t['Emacronacute'] = 0x1E16;
  9155. t['Emacrongrave'] = 0x1E14;
  9156. t['Emcyrillic'] = 0x041C;
  9157. t['Emonospace'] = 0xFF25;
  9158. t['Encyrillic'] = 0x041D;
  9159. t['Endescendercyrillic'] = 0x04A2;
  9160. t['Eng'] = 0x014A;
  9161. t['Enghecyrillic'] = 0x04A4;
  9162. t['Enhookcyrillic'] = 0x04C7;
  9163. t['Eogonek'] = 0x0118;
  9164. t['Eopen'] = 0x0190;
  9165. t['Epsilon'] = 0x0395;
  9166. t['Epsilontonos'] = 0x0388;
  9167. t['Ercyrillic'] = 0x0420;
  9168. t['Ereversed'] = 0x018E;
  9169. t['Ereversedcyrillic'] = 0x042D;
  9170. t['Escyrillic'] = 0x0421;
  9171. t['Esdescendercyrillic'] = 0x04AA;
  9172. t['Esh'] = 0x01A9;
  9173. t['Esmall'] = 0xF765;
  9174. t['Eta'] = 0x0397;
  9175. t['Etarmenian'] = 0x0538;
  9176. t['Etatonos'] = 0x0389;
  9177. t['Eth'] = 0x00D0;
  9178. t['Ethsmall'] = 0xF7F0;
  9179. t['Etilde'] = 0x1EBC;
  9180. t['Etildebelow'] = 0x1E1A;
  9181. t['Euro'] = 0x20AC;
  9182. t['Ezh'] = 0x01B7;
  9183. t['Ezhcaron'] = 0x01EE;
  9184. t['Ezhreversed'] = 0x01B8;
  9185. t['F'] = 0x0046;
  9186. t['Fcircle'] = 0x24BB;
  9187. t['Fdotaccent'] = 0x1E1E;
  9188. t['Feharmenian'] = 0x0556;
  9189. t['Feicoptic'] = 0x03E4;
  9190. t['Fhook'] = 0x0191;
  9191. t['Fitacyrillic'] = 0x0472;
  9192. t['Fiveroman'] = 0x2164;
  9193. t['Fmonospace'] = 0xFF26;
  9194. t['Fourroman'] = 0x2163;
  9195. t['Fsmall'] = 0xF766;
  9196. t['G'] = 0x0047;
  9197. t['GBsquare'] = 0x3387;
  9198. t['Gacute'] = 0x01F4;
  9199. t['Gamma'] = 0x0393;
  9200. t['Gammaafrican'] = 0x0194;
  9201. t['Gangiacoptic'] = 0x03EA;
  9202. t['Gbreve'] = 0x011E;
  9203. t['Gcaron'] = 0x01E6;
  9204. t['Gcedilla'] = 0x0122;
  9205. t['Gcircle'] = 0x24BC;
  9206. t['Gcircumflex'] = 0x011C;
  9207. t['Gcommaaccent'] = 0x0122;
  9208. t['Gdot'] = 0x0120;
  9209. t['Gdotaccent'] = 0x0120;
  9210. t['Gecyrillic'] = 0x0413;
  9211. t['Ghadarmenian'] = 0x0542;
  9212. t['Ghemiddlehookcyrillic'] = 0x0494;
  9213. t['Ghestrokecyrillic'] = 0x0492;
  9214. t['Gheupturncyrillic'] = 0x0490;
  9215. t['Ghook'] = 0x0193;
  9216. t['Gimarmenian'] = 0x0533;
  9217. t['Gjecyrillic'] = 0x0403;
  9218. t['Gmacron'] = 0x1E20;
  9219. t['Gmonospace'] = 0xFF27;
  9220. t['Grave'] = 0xF6CE;
  9221. t['Gravesmall'] = 0xF760;
  9222. t['Gsmall'] = 0xF767;
  9223. t['Gsmallhook'] = 0x029B;
  9224. t['Gstroke'] = 0x01E4;
  9225. t['H'] = 0x0048;
  9226. t['H18533'] = 0x25CF;
  9227. t['H18543'] = 0x25AA;
  9228. t['H18551'] = 0x25AB;
  9229. t['H22073'] = 0x25A1;
  9230. t['HPsquare'] = 0x33CB;
  9231. t['Haabkhasiancyrillic'] = 0x04A8;
  9232. t['Hadescendercyrillic'] = 0x04B2;
  9233. t['Hardsigncyrillic'] = 0x042A;
  9234. t['Hbar'] = 0x0126;
  9235. t['Hbrevebelow'] = 0x1E2A;
  9236. t['Hcedilla'] = 0x1E28;
  9237. t['Hcircle'] = 0x24BD;
  9238. t['Hcircumflex'] = 0x0124;
  9239. t['Hdieresis'] = 0x1E26;
  9240. t['Hdotaccent'] = 0x1E22;
  9241. t['Hdotbelow'] = 0x1E24;
  9242. t['Hmonospace'] = 0xFF28;
  9243. t['Hoarmenian'] = 0x0540;
  9244. t['Horicoptic'] = 0x03E8;
  9245. t['Hsmall'] = 0xF768;
  9246. t['Hungarumlaut'] = 0xF6CF;
  9247. t['Hungarumlautsmall'] = 0xF6F8;
  9248. t['Hzsquare'] = 0x3390;
  9249. t['I'] = 0x0049;
  9250. t['IAcyrillic'] = 0x042F;
  9251. t['IJ'] = 0x0132;
  9252. t['IUcyrillic'] = 0x042E;
  9253. t['Iacute'] = 0x00CD;
  9254. t['Iacutesmall'] = 0xF7ED;
  9255. t['Ibreve'] = 0x012C;
  9256. t['Icaron'] = 0x01CF;
  9257. t['Icircle'] = 0x24BE;
  9258. t['Icircumflex'] = 0x00CE;
  9259. t['Icircumflexsmall'] = 0xF7EE;
  9260. t['Icyrillic'] = 0x0406;
  9261. t['Idblgrave'] = 0x0208;
  9262. t['Idieresis'] = 0x00CF;
  9263. t['Idieresisacute'] = 0x1E2E;
  9264. t['Idieresiscyrillic'] = 0x04E4;
  9265. t['Idieresissmall'] = 0xF7EF;
  9266. t['Idot'] = 0x0130;
  9267. t['Idotaccent'] = 0x0130;
  9268. t['Idotbelow'] = 0x1ECA;
  9269. t['Iebrevecyrillic'] = 0x04D6;
  9270. t['Iecyrillic'] = 0x0415;
  9271. t['Ifraktur'] = 0x2111;
  9272. t['Igrave'] = 0x00CC;
  9273. t['Igravesmall'] = 0xF7EC;
  9274. t['Ihookabove'] = 0x1EC8;
  9275. t['Iicyrillic'] = 0x0418;
  9276. t['Iinvertedbreve'] = 0x020A;
  9277. t['Iishortcyrillic'] = 0x0419;
  9278. t['Imacron'] = 0x012A;
  9279. t['Imacroncyrillic'] = 0x04E2;
  9280. t['Imonospace'] = 0xFF29;
  9281. t['Iniarmenian'] = 0x053B;
  9282. t['Iocyrillic'] = 0x0401;
  9283. t['Iogonek'] = 0x012E;
  9284. t['Iota'] = 0x0399;
  9285. t['Iotaafrican'] = 0x0196;
  9286. t['Iotadieresis'] = 0x03AA;
  9287. t['Iotatonos'] = 0x038A;
  9288. t['Ismall'] = 0xF769;
  9289. t['Istroke'] = 0x0197;
  9290. t['Itilde'] = 0x0128;
  9291. t['Itildebelow'] = 0x1E2C;
  9292. t['Izhitsacyrillic'] = 0x0474;
  9293. t['Izhitsadblgravecyrillic'] = 0x0476;
  9294. t['J'] = 0x004A;
  9295. t['Jaarmenian'] = 0x0541;
  9296. t['Jcircle'] = 0x24BF;
  9297. t['Jcircumflex'] = 0x0134;
  9298. t['Jecyrillic'] = 0x0408;
  9299. t['Jheharmenian'] = 0x054B;
  9300. t['Jmonospace'] = 0xFF2A;
  9301. t['Jsmall'] = 0xF76A;
  9302. t['K'] = 0x004B;
  9303. t['KBsquare'] = 0x3385;
  9304. t['KKsquare'] = 0x33CD;
  9305. t['Kabashkircyrillic'] = 0x04A0;
  9306. t['Kacute'] = 0x1E30;
  9307. t['Kacyrillic'] = 0x041A;
  9308. t['Kadescendercyrillic'] = 0x049A;
  9309. t['Kahookcyrillic'] = 0x04C3;
  9310. t['Kappa'] = 0x039A;
  9311. t['Kastrokecyrillic'] = 0x049E;
  9312. t['Kaverticalstrokecyrillic'] = 0x049C;
  9313. t['Kcaron'] = 0x01E8;
  9314. t['Kcedilla'] = 0x0136;
  9315. t['Kcircle'] = 0x24C0;
  9316. t['Kcommaaccent'] = 0x0136;
  9317. t['Kdotbelow'] = 0x1E32;
  9318. t['Keharmenian'] = 0x0554;
  9319. t['Kenarmenian'] = 0x053F;
  9320. t['Khacyrillic'] = 0x0425;
  9321. t['Kheicoptic'] = 0x03E6;
  9322. t['Khook'] = 0x0198;
  9323. t['Kjecyrillic'] = 0x040C;
  9324. t['Klinebelow'] = 0x1E34;
  9325. t['Kmonospace'] = 0xFF2B;
  9326. t['Koppacyrillic'] = 0x0480;
  9327. t['Koppagreek'] = 0x03DE;
  9328. t['Ksicyrillic'] = 0x046E;
  9329. t['Ksmall'] = 0xF76B;
  9330. t['L'] = 0x004C;
  9331. t['LJ'] = 0x01C7;
  9332. t['LL'] = 0xF6BF;
  9333. t['Lacute'] = 0x0139;
  9334. t['Lambda'] = 0x039B;
  9335. t['Lcaron'] = 0x013D;
  9336. t['Lcedilla'] = 0x013B;
  9337. t['Lcircle'] = 0x24C1;
  9338. t['Lcircumflexbelow'] = 0x1E3C;
  9339. t['Lcommaaccent'] = 0x013B;
  9340. t['Ldot'] = 0x013F;
  9341. t['Ldotaccent'] = 0x013F;
  9342. t['Ldotbelow'] = 0x1E36;
  9343. t['Ldotbelowmacron'] = 0x1E38;
  9344. t['Liwnarmenian'] = 0x053C;
  9345. t['Lj'] = 0x01C8;
  9346. t['Ljecyrillic'] = 0x0409;
  9347. t['Llinebelow'] = 0x1E3A;
  9348. t['Lmonospace'] = 0xFF2C;
  9349. t['Lslash'] = 0x0141;
  9350. t['Lslashsmall'] = 0xF6F9;
  9351. t['Lsmall'] = 0xF76C;
  9352. t['M'] = 0x004D;
  9353. t['MBsquare'] = 0x3386;
  9354. t['Macron'] = 0xF6D0;
  9355. t['Macronsmall'] = 0xF7AF;
  9356. t['Macute'] = 0x1E3E;
  9357. t['Mcircle'] = 0x24C2;
  9358. t['Mdotaccent'] = 0x1E40;
  9359. t['Mdotbelow'] = 0x1E42;
  9360. t['Menarmenian'] = 0x0544;
  9361. t['Mmonospace'] = 0xFF2D;
  9362. t['Msmall'] = 0xF76D;
  9363. t['Mturned'] = 0x019C;
  9364. t['Mu'] = 0x039C;
  9365. t['N'] = 0x004E;
  9366. t['NJ'] = 0x01CA;
  9367. t['Nacute'] = 0x0143;
  9368. t['Ncaron'] = 0x0147;
  9369. t['Ncedilla'] = 0x0145;
  9370. t['Ncircle'] = 0x24C3;
  9371. t['Ncircumflexbelow'] = 0x1E4A;
  9372. t['Ncommaaccent'] = 0x0145;
  9373. t['Ndotaccent'] = 0x1E44;
  9374. t['Ndotbelow'] = 0x1E46;
  9375. t['Nhookleft'] = 0x019D;
  9376. t['Nineroman'] = 0x2168;
  9377. t['Nj'] = 0x01CB;
  9378. t['Njecyrillic'] = 0x040A;
  9379. t['Nlinebelow'] = 0x1E48;
  9380. t['Nmonospace'] = 0xFF2E;
  9381. t['Nowarmenian'] = 0x0546;
  9382. t['Nsmall'] = 0xF76E;
  9383. t['Ntilde'] = 0x00D1;
  9384. t['Ntildesmall'] = 0xF7F1;
  9385. t['Nu'] = 0x039D;
  9386. t['O'] = 0x004F;
  9387. t['OE'] = 0x0152;
  9388. t['OEsmall'] = 0xF6FA;
  9389. t['Oacute'] = 0x00D3;
  9390. t['Oacutesmall'] = 0xF7F3;
  9391. t['Obarredcyrillic'] = 0x04E8;
  9392. t['Obarreddieresiscyrillic'] = 0x04EA;
  9393. t['Obreve'] = 0x014E;
  9394. t['Ocaron'] = 0x01D1;
  9395. t['Ocenteredtilde'] = 0x019F;
  9396. t['Ocircle'] = 0x24C4;
  9397. t['Ocircumflex'] = 0x00D4;
  9398. t['Ocircumflexacute'] = 0x1ED0;
  9399. t['Ocircumflexdotbelow'] = 0x1ED8;
  9400. t['Ocircumflexgrave'] = 0x1ED2;
  9401. t['Ocircumflexhookabove'] = 0x1ED4;
  9402. t['Ocircumflexsmall'] = 0xF7F4;
  9403. t['Ocircumflextilde'] = 0x1ED6;
  9404. t['Ocyrillic'] = 0x041E;
  9405. t['Odblacute'] = 0x0150;
  9406. t['Odblgrave'] = 0x020C;
  9407. t['Odieresis'] = 0x00D6;
  9408. t['Odieresiscyrillic'] = 0x04E6;
  9409. t['Odieresissmall'] = 0xF7F6;
  9410. t['Odotbelow'] = 0x1ECC;
  9411. t['Ogoneksmall'] = 0xF6FB;
  9412. t['Ograve'] = 0x00D2;
  9413. t['Ogravesmall'] = 0xF7F2;
  9414. t['Oharmenian'] = 0x0555;
  9415. t['Ohm'] = 0x2126;
  9416. t['Ohookabove'] = 0x1ECE;
  9417. t['Ohorn'] = 0x01A0;
  9418. t['Ohornacute'] = 0x1EDA;
  9419. t['Ohorndotbelow'] = 0x1EE2;
  9420. t['Ohorngrave'] = 0x1EDC;
  9421. t['Ohornhookabove'] = 0x1EDE;
  9422. t['Ohorntilde'] = 0x1EE0;
  9423. t['Ohungarumlaut'] = 0x0150;
  9424. t['Oi'] = 0x01A2;
  9425. t['Oinvertedbreve'] = 0x020E;
  9426. t['Omacron'] = 0x014C;
  9427. t['Omacronacute'] = 0x1E52;
  9428. t['Omacrongrave'] = 0x1E50;
  9429. t['Omega'] = 0x2126;
  9430. t['Omegacyrillic'] = 0x0460;
  9431. t['Omegagreek'] = 0x03A9;
  9432. t['Omegaroundcyrillic'] = 0x047A;
  9433. t['Omegatitlocyrillic'] = 0x047C;
  9434. t['Omegatonos'] = 0x038F;
  9435. t['Omicron'] = 0x039F;
  9436. t['Omicrontonos'] = 0x038C;
  9437. t['Omonospace'] = 0xFF2F;
  9438. t['Oneroman'] = 0x2160;
  9439. t['Oogonek'] = 0x01EA;
  9440. t['Oogonekmacron'] = 0x01EC;
  9441. t['Oopen'] = 0x0186;
  9442. t['Oslash'] = 0x00D8;
  9443. t['Oslashacute'] = 0x01FE;
  9444. t['Oslashsmall'] = 0xF7F8;
  9445. t['Osmall'] = 0xF76F;
  9446. t['Ostrokeacute'] = 0x01FE;
  9447. t['Otcyrillic'] = 0x047E;
  9448. t['Otilde'] = 0x00D5;
  9449. t['Otildeacute'] = 0x1E4C;
  9450. t['Otildedieresis'] = 0x1E4E;
  9451. t['Otildesmall'] = 0xF7F5;
  9452. t['P'] = 0x0050;
  9453. t['Pacute'] = 0x1E54;
  9454. t['Pcircle'] = 0x24C5;
  9455. t['Pdotaccent'] = 0x1E56;
  9456. t['Pecyrillic'] = 0x041F;
  9457. t['Peharmenian'] = 0x054A;
  9458. t['Pemiddlehookcyrillic'] = 0x04A6;
  9459. t['Phi'] = 0x03A6;
  9460. t['Phook'] = 0x01A4;
  9461. t['Pi'] = 0x03A0;
  9462. t['Piwrarmenian'] = 0x0553;
  9463. t['Pmonospace'] = 0xFF30;
  9464. t['Psi'] = 0x03A8;
  9465. t['Psicyrillic'] = 0x0470;
  9466. t['Psmall'] = 0xF770;
  9467. t['Q'] = 0x0051;
  9468. t['Qcircle'] = 0x24C6;
  9469. t['Qmonospace'] = 0xFF31;
  9470. t['Qsmall'] = 0xF771;
  9471. t['R'] = 0x0052;
  9472. t['Raarmenian'] = 0x054C;
  9473. t['Racute'] = 0x0154;
  9474. t['Rcaron'] = 0x0158;
  9475. t['Rcedilla'] = 0x0156;
  9476. t['Rcircle'] = 0x24C7;
  9477. t['Rcommaaccent'] = 0x0156;
  9478. t['Rdblgrave'] = 0x0210;
  9479. t['Rdotaccent'] = 0x1E58;
  9480. t['Rdotbelow'] = 0x1E5A;
  9481. t['Rdotbelowmacron'] = 0x1E5C;
  9482. t['Reharmenian'] = 0x0550;
  9483. t['Rfraktur'] = 0x211C;
  9484. t['Rho'] = 0x03A1;
  9485. t['Ringsmall'] = 0xF6FC;
  9486. t['Rinvertedbreve'] = 0x0212;
  9487. t['Rlinebelow'] = 0x1E5E;
  9488. t['Rmonospace'] = 0xFF32;
  9489. t['Rsmall'] = 0xF772;
  9490. t['Rsmallinverted'] = 0x0281;
  9491. t['Rsmallinvertedsuperior'] = 0x02B6;
  9492. t['S'] = 0x0053;
  9493. t['SF010000'] = 0x250C;
  9494. t['SF020000'] = 0x2514;
  9495. t['SF030000'] = 0x2510;
  9496. t['SF040000'] = 0x2518;
  9497. t['SF050000'] = 0x253C;
  9498. t['SF060000'] = 0x252C;
  9499. t['SF070000'] = 0x2534;
  9500. t['SF080000'] = 0x251C;
  9501. t['SF090000'] = 0x2524;
  9502. t['SF100000'] = 0x2500;
  9503. t['SF110000'] = 0x2502;
  9504. t['SF190000'] = 0x2561;
  9505. t['SF200000'] = 0x2562;
  9506. t['SF210000'] = 0x2556;
  9507. t['SF220000'] = 0x2555;
  9508. t['SF230000'] = 0x2563;
  9509. t['SF240000'] = 0x2551;
  9510. t['SF250000'] = 0x2557;
  9511. t['SF260000'] = 0x255D;
  9512. t['SF270000'] = 0x255C;
  9513. t['SF280000'] = 0x255B;
  9514. t['SF360000'] = 0x255E;
  9515. t['SF370000'] = 0x255F;
  9516. t['SF380000'] = 0x255A;
  9517. t['SF390000'] = 0x2554;
  9518. t['SF400000'] = 0x2569;
  9519. t['SF410000'] = 0x2566;
  9520. t['SF420000'] = 0x2560;
  9521. t['SF430000'] = 0x2550;
  9522. t['SF440000'] = 0x256C;
  9523. t['SF450000'] = 0x2567;
  9524. t['SF460000'] = 0x2568;
  9525. t['SF470000'] = 0x2564;
  9526. t['SF480000'] = 0x2565;
  9527. t['SF490000'] = 0x2559;
  9528. t['SF500000'] = 0x2558;
  9529. t['SF510000'] = 0x2552;
  9530. t['SF520000'] = 0x2553;
  9531. t['SF530000'] = 0x256B;
  9532. t['SF540000'] = 0x256A;
  9533. t['Sacute'] = 0x015A;
  9534. t['Sacutedotaccent'] = 0x1E64;
  9535. t['Sampigreek'] = 0x03E0;
  9536. t['Scaron'] = 0x0160;
  9537. t['Scarondotaccent'] = 0x1E66;
  9538. t['Scaronsmall'] = 0xF6FD;
  9539. t['Scedilla'] = 0x015E;
  9540. t['Schwa'] = 0x018F;
  9541. t['Schwacyrillic'] = 0x04D8;
  9542. t['Schwadieresiscyrillic'] = 0x04DA;
  9543. t['Scircle'] = 0x24C8;
  9544. t['Scircumflex'] = 0x015C;
  9545. t['Scommaaccent'] = 0x0218;
  9546. t['Sdotaccent'] = 0x1E60;
  9547. t['Sdotbelow'] = 0x1E62;
  9548. t['Sdotbelowdotaccent'] = 0x1E68;
  9549. t['Seharmenian'] = 0x054D;
  9550. t['Sevenroman'] = 0x2166;
  9551. t['Shaarmenian'] = 0x0547;
  9552. t['Shacyrillic'] = 0x0428;
  9553. t['Shchacyrillic'] = 0x0429;
  9554. t['Sheicoptic'] = 0x03E2;
  9555. t['Shhacyrillic'] = 0x04BA;
  9556. t['Shimacoptic'] = 0x03EC;
  9557. t['Sigma'] = 0x03A3;
  9558. t['Sixroman'] = 0x2165;
  9559. t['Smonospace'] = 0xFF33;
  9560. t['Softsigncyrillic'] = 0x042C;
  9561. t['Ssmall'] = 0xF773;
  9562. t['Stigmagreek'] = 0x03DA;
  9563. t['T'] = 0x0054;
  9564. t['Tau'] = 0x03A4;
  9565. t['Tbar'] = 0x0166;
  9566. t['Tcaron'] = 0x0164;
  9567. t['Tcedilla'] = 0x0162;
  9568. t['Tcircle'] = 0x24C9;
  9569. t['Tcircumflexbelow'] = 0x1E70;
  9570. t['Tcommaaccent'] = 0x0162;
  9571. t['Tdotaccent'] = 0x1E6A;
  9572. t['Tdotbelow'] = 0x1E6C;
  9573. t['Tecyrillic'] = 0x0422;
  9574. t['Tedescendercyrillic'] = 0x04AC;
  9575. t['Tenroman'] = 0x2169;
  9576. t['Tetsecyrillic'] = 0x04B4;
  9577. t['Theta'] = 0x0398;
  9578. t['Thook'] = 0x01AC;
  9579. t['Thorn'] = 0x00DE;
  9580. t['Thornsmall'] = 0xF7FE;
  9581. t['Threeroman'] = 0x2162;
  9582. t['Tildesmall'] = 0xF6FE;
  9583. t['Tiwnarmenian'] = 0x054F;
  9584. t['Tlinebelow'] = 0x1E6E;
  9585. t['Tmonospace'] = 0xFF34;
  9586. t['Toarmenian'] = 0x0539;
  9587. t['Tonefive'] = 0x01BC;
  9588. t['Tonesix'] = 0x0184;
  9589. t['Tonetwo'] = 0x01A7;
  9590. t['Tretroflexhook'] = 0x01AE;
  9591. t['Tsecyrillic'] = 0x0426;
  9592. t['Tshecyrillic'] = 0x040B;
  9593. t['Tsmall'] = 0xF774;
  9594. t['Twelveroman'] = 0x216B;
  9595. t['Tworoman'] = 0x2161;
  9596. t['U'] = 0x0055;
  9597. t['Uacute'] = 0x00DA;
  9598. t['Uacutesmall'] = 0xF7FA;
  9599. t['Ubreve'] = 0x016C;
  9600. t['Ucaron'] = 0x01D3;
  9601. t['Ucircle'] = 0x24CA;
  9602. t['Ucircumflex'] = 0x00DB;
  9603. t['Ucircumflexbelow'] = 0x1E76;
  9604. t['Ucircumflexsmall'] = 0xF7FB;
  9605. t['Ucyrillic'] = 0x0423;
  9606. t['Udblacute'] = 0x0170;
  9607. t['Udblgrave'] = 0x0214;
  9608. t['Udieresis'] = 0x00DC;
  9609. t['Udieresisacute'] = 0x01D7;
  9610. t['Udieresisbelow'] = 0x1E72;
  9611. t['Udieresiscaron'] = 0x01D9;
  9612. t['Udieresiscyrillic'] = 0x04F0;
  9613. t['Udieresisgrave'] = 0x01DB;
  9614. t['Udieresismacron'] = 0x01D5;
  9615. t['Udieresissmall'] = 0xF7FC;
  9616. t['Udotbelow'] = 0x1EE4;
  9617. t['Ugrave'] = 0x00D9;
  9618. t['Ugravesmall'] = 0xF7F9;
  9619. t['Uhookabove'] = 0x1EE6;
  9620. t['Uhorn'] = 0x01AF;
  9621. t['Uhornacute'] = 0x1EE8;
  9622. t['Uhorndotbelow'] = 0x1EF0;
  9623. t['Uhorngrave'] = 0x1EEA;
  9624. t['Uhornhookabove'] = 0x1EEC;
  9625. t['Uhorntilde'] = 0x1EEE;
  9626. t['Uhungarumlaut'] = 0x0170;
  9627. t['Uhungarumlautcyrillic'] = 0x04F2;
  9628. t['Uinvertedbreve'] = 0x0216;
  9629. t['Ukcyrillic'] = 0x0478;
  9630. t['Umacron'] = 0x016A;
  9631. t['Umacroncyrillic'] = 0x04EE;
  9632. t['Umacrondieresis'] = 0x1E7A;
  9633. t['Umonospace'] = 0xFF35;
  9634. t['Uogonek'] = 0x0172;
  9635. t['Upsilon'] = 0x03A5;
  9636. t['Upsilon1'] = 0x03D2;
  9637. t['Upsilonacutehooksymbolgreek'] = 0x03D3;
  9638. t['Upsilonafrican'] = 0x01B1;
  9639. t['Upsilondieresis'] = 0x03AB;
  9640. t['Upsilondieresishooksymbolgreek'] = 0x03D4;
  9641. t['Upsilonhooksymbol'] = 0x03D2;
  9642. t['Upsilontonos'] = 0x038E;
  9643. t['Uring'] = 0x016E;
  9644. t['Ushortcyrillic'] = 0x040E;
  9645. t['Usmall'] = 0xF775;
  9646. t['Ustraightcyrillic'] = 0x04AE;
  9647. t['Ustraightstrokecyrillic'] = 0x04B0;
  9648. t['Utilde'] = 0x0168;
  9649. t['Utildeacute'] = 0x1E78;
  9650. t['Utildebelow'] = 0x1E74;
  9651. t['V'] = 0x0056;
  9652. t['Vcircle'] = 0x24CB;
  9653. t['Vdotbelow'] = 0x1E7E;
  9654. t['Vecyrillic'] = 0x0412;
  9655. t['Vewarmenian'] = 0x054E;
  9656. t['Vhook'] = 0x01B2;
  9657. t['Vmonospace'] = 0xFF36;
  9658. t['Voarmenian'] = 0x0548;
  9659. t['Vsmall'] = 0xF776;
  9660. t['Vtilde'] = 0x1E7C;
  9661. t['W'] = 0x0057;
  9662. t['Wacute'] = 0x1E82;
  9663. t['Wcircle'] = 0x24CC;
  9664. t['Wcircumflex'] = 0x0174;
  9665. t['Wdieresis'] = 0x1E84;
  9666. t['Wdotaccent'] = 0x1E86;
  9667. t['Wdotbelow'] = 0x1E88;
  9668. t['Wgrave'] = 0x1E80;
  9669. t['Wmonospace'] = 0xFF37;
  9670. t['Wsmall'] = 0xF777;
  9671. t['X'] = 0x0058;
  9672. t['Xcircle'] = 0x24CD;
  9673. t['Xdieresis'] = 0x1E8C;
  9674. t['Xdotaccent'] = 0x1E8A;
  9675. t['Xeharmenian'] = 0x053D;
  9676. t['Xi'] = 0x039E;
  9677. t['Xmonospace'] = 0xFF38;
  9678. t['Xsmall'] = 0xF778;
  9679. t['Y'] = 0x0059;
  9680. t['Yacute'] = 0x00DD;
  9681. t['Yacutesmall'] = 0xF7FD;
  9682. t['Yatcyrillic'] = 0x0462;
  9683. t['Ycircle'] = 0x24CE;
  9684. t['Ycircumflex'] = 0x0176;
  9685. t['Ydieresis'] = 0x0178;
  9686. t['Ydieresissmall'] = 0xF7FF;
  9687. t['Ydotaccent'] = 0x1E8E;
  9688. t['Ydotbelow'] = 0x1EF4;
  9689. t['Yericyrillic'] = 0x042B;
  9690. t['Yerudieresiscyrillic'] = 0x04F8;
  9691. t['Ygrave'] = 0x1EF2;
  9692. t['Yhook'] = 0x01B3;
  9693. t['Yhookabove'] = 0x1EF6;
  9694. t['Yiarmenian'] = 0x0545;
  9695. t['Yicyrillic'] = 0x0407;
  9696. t['Yiwnarmenian'] = 0x0552;
  9697. t['Ymonospace'] = 0xFF39;
  9698. t['Ysmall'] = 0xF779;
  9699. t['Ytilde'] = 0x1EF8;
  9700. t['Yusbigcyrillic'] = 0x046A;
  9701. t['Yusbigiotifiedcyrillic'] = 0x046C;
  9702. t['Yuslittlecyrillic'] = 0x0466;
  9703. t['Yuslittleiotifiedcyrillic'] = 0x0468;
  9704. t['Z'] = 0x005A;
  9705. t['Zaarmenian'] = 0x0536;
  9706. t['Zacute'] = 0x0179;
  9707. t['Zcaron'] = 0x017D;
  9708. t['Zcaronsmall'] = 0xF6FF;
  9709. t['Zcircle'] = 0x24CF;
  9710. t['Zcircumflex'] = 0x1E90;
  9711. t['Zdot'] = 0x017B;
  9712. t['Zdotaccent'] = 0x017B;
  9713. t['Zdotbelow'] = 0x1E92;
  9714. t['Zecyrillic'] = 0x0417;
  9715. t['Zedescendercyrillic'] = 0x0498;
  9716. t['Zedieresiscyrillic'] = 0x04DE;
  9717. t['Zeta'] = 0x0396;
  9718. t['Zhearmenian'] = 0x053A;
  9719. t['Zhebrevecyrillic'] = 0x04C1;
  9720. t['Zhecyrillic'] = 0x0416;
  9721. t['Zhedescendercyrillic'] = 0x0496;
  9722. t['Zhedieresiscyrillic'] = 0x04DC;
  9723. t['Zlinebelow'] = 0x1E94;
  9724. t['Zmonospace'] = 0xFF3A;
  9725. t['Zsmall'] = 0xF77A;
  9726. t['Zstroke'] = 0x01B5;
  9727. t['a'] = 0x0061;
  9728. t['aabengali'] = 0x0986;
  9729. t['aacute'] = 0x00E1;
  9730. t['aadeva'] = 0x0906;
  9731. t['aagujarati'] = 0x0A86;
  9732. t['aagurmukhi'] = 0x0A06;
  9733. t['aamatragurmukhi'] = 0x0A3E;
  9734. t['aarusquare'] = 0x3303;
  9735. t['aavowelsignbengali'] = 0x09BE;
  9736. t['aavowelsigndeva'] = 0x093E;
  9737. t['aavowelsigngujarati'] = 0x0ABE;
  9738. t['abbreviationmarkarmenian'] = 0x055F;
  9739. t['abbreviationsigndeva'] = 0x0970;
  9740. t['abengali'] = 0x0985;
  9741. t['abopomofo'] = 0x311A;
  9742. t['abreve'] = 0x0103;
  9743. t['abreveacute'] = 0x1EAF;
  9744. t['abrevecyrillic'] = 0x04D1;
  9745. t['abrevedotbelow'] = 0x1EB7;
  9746. t['abrevegrave'] = 0x1EB1;
  9747. t['abrevehookabove'] = 0x1EB3;
  9748. t['abrevetilde'] = 0x1EB5;
  9749. t['acaron'] = 0x01CE;
  9750. t['acircle'] = 0x24D0;
  9751. t['acircumflex'] = 0x00E2;
  9752. t['acircumflexacute'] = 0x1EA5;
  9753. t['acircumflexdotbelow'] = 0x1EAD;
  9754. t['acircumflexgrave'] = 0x1EA7;
  9755. t['acircumflexhookabove'] = 0x1EA9;
  9756. t['acircumflextilde'] = 0x1EAB;
  9757. t['acute'] = 0x00B4;
  9758. t['acutebelowcmb'] = 0x0317;
  9759. t['acutecmb'] = 0x0301;
  9760. t['acutecomb'] = 0x0301;
  9761. t['acutedeva'] = 0x0954;
  9762. t['acutelowmod'] = 0x02CF;
  9763. t['acutetonecmb'] = 0x0341;
  9764. t['acyrillic'] = 0x0430;
  9765. t['adblgrave'] = 0x0201;
  9766. t['addakgurmukhi'] = 0x0A71;
  9767. t['adeva'] = 0x0905;
  9768. t['adieresis'] = 0x00E4;
  9769. t['adieresiscyrillic'] = 0x04D3;
  9770. t['adieresismacron'] = 0x01DF;
  9771. t['adotbelow'] = 0x1EA1;
  9772. t['adotmacron'] = 0x01E1;
  9773. t['ae'] = 0x00E6;
  9774. t['aeacute'] = 0x01FD;
  9775. t['aekorean'] = 0x3150;
  9776. t['aemacron'] = 0x01E3;
  9777. t['afii00208'] = 0x2015;
  9778. t['afii08941'] = 0x20A4;
  9779. t['afii10017'] = 0x0410;
  9780. t['afii10018'] = 0x0411;
  9781. t['afii10019'] = 0x0412;
  9782. t['afii10020'] = 0x0413;
  9783. t['afii10021'] = 0x0414;
  9784. t['afii10022'] = 0x0415;
  9785. t['afii10023'] = 0x0401;
  9786. t['afii10024'] = 0x0416;
  9787. t['afii10025'] = 0x0417;
  9788. t['afii10026'] = 0x0418;
  9789. t['afii10027'] = 0x0419;
  9790. t['afii10028'] = 0x041A;
  9791. t['afii10029'] = 0x041B;
  9792. t['afii10030'] = 0x041C;
  9793. t['afii10031'] = 0x041D;
  9794. t['afii10032'] = 0x041E;
  9795. t['afii10033'] = 0x041F;
  9796. t['afii10034'] = 0x0420;
  9797. t['afii10035'] = 0x0421;
  9798. t['afii10036'] = 0x0422;
  9799. t['afii10037'] = 0x0423;
  9800. t['afii10038'] = 0x0424;
  9801. t['afii10039'] = 0x0425;
  9802. t['afii10040'] = 0x0426;
  9803. t['afii10041'] = 0x0427;
  9804. t['afii10042'] = 0x0428;
  9805. t['afii10043'] = 0x0429;
  9806. t['afii10044'] = 0x042A;
  9807. t['afii10045'] = 0x042B;
  9808. t['afii10046'] = 0x042C;
  9809. t['afii10047'] = 0x042D;
  9810. t['afii10048'] = 0x042E;
  9811. t['afii10049'] = 0x042F;
  9812. t['afii10050'] = 0x0490;
  9813. t['afii10051'] = 0x0402;
  9814. t['afii10052'] = 0x0403;
  9815. t['afii10053'] = 0x0404;
  9816. t['afii10054'] = 0x0405;
  9817. t['afii10055'] = 0x0406;
  9818. t['afii10056'] = 0x0407;
  9819. t['afii10057'] = 0x0408;
  9820. t['afii10058'] = 0x0409;
  9821. t['afii10059'] = 0x040A;
  9822. t['afii10060'] = 0x040B;
  9823. t['afii10061'] = 0x040C;
  9824. t['afii10062'] = 0x040E;
  9825. t['afii10063'] = 0xF6C4;
  9826. t['afii10064'] = 0xF6C5;
  9827. t['afii10065'] = 0x0430;
  9828. t['afii10066'] = 0x0431;
  9829. t['afii10067'] = 0x0432;
  9830. t['afii10068'] = 0x0433;
  9831. t['afii10069'] = 0x0434;
  9832. t['afii10070'] = 0x0435;
  9833. t['afii10071'] = 0x0451;
  9834. t['afii10072'] = 0x0436;
  9835. t['afii10073'] = 0x0437;
  9836. t['afii10074'] = 0x0438;
  9837. t['afii10075'] = 0x0439;
  9838. t['afii10076'] = 0x043A;
  9839. t['afii10077'] = 0x043B;
  9840. t['afii10078'] = 0x043C;
  9841. t['afii10079'] = 0x043D;
  9842. t['afii10080'] = 0x043E;
  9843. t['afii10081'] = 0x043F;
  9844. t['afii10082'] = 0x0440;
  9845. t['afii10083'] = 0x0441;
  9846. t['afii10084'] = 0x0442;
  9847. t['afii10085'] = 0x0443;
  9848. t['afii10086'] = 0x0444;
  9849. t['afii10087'] = 0x0445;
  9850. t['afii10088'] = 0x0446;
  9851. t['afii10089'] = 0x0447;
  9852. t['afii10090'] = 0x0448;
  9853. t['afii10091'] = 0x0449;
  9854. t['afii10092'] = 0x044A;
  9855. t['afii10093'] = 0x044B;
  9856. t['afii10094'] = 0x044C;
  9857. t['afii10095'] = 0x044D;
  9858. t['afii10096'] = 0x044E;
  9859. t['afii10097'] = 0x044F;
  9860. t['afii10098'] = 0x0491;
  9861. t['afii10099'] = 0x0452;
  9862. t['afii10100'] = 0x0453;
  9863. t['afii10101'] = 0x0454;
  9864. t['afii10102'] = 0x0455;
  9865. t['afii10103'] = 0x0456;
  9866. t['afii10104'] = 0x0457;
  9867. t['afii10105'] = 0x0458;
  9868. t['afii10106'] = 0x0459;
  9869. t['afii10107'] = 0x045A;
  9870. t['afii10108'] = 0x045B;
  9871. t['afii10109'] = 0x045C;
  9872. t['afii10110'] = 0x045E;
  9873. t['afii10145'] = 0x040F;
  9874. t['afii10146'] = 0x0462;
  9875. t['afii10147'] = 0x0472;
  9876. t['afii10148'] = 0x0474;
  9877. t['afii10192'] = 0xF6C6;
  9878. t['afii10193'] = 0x045F;
  9879. t['afii10194'] = 0x0463;
  9880. t['afii10195'] = 0x0473;
  9881. t['afii10196'] = 0x0475;
  9882. t['afii10831'] = 0xF6C7;
  9883. t['afii10832'] = 0xF6C8;
  9884. t['afii10846'] = 0x04D9;
  9885. t['afii299'] = 0x200E;
  9886. t['afii300'] = 0x200F;
  9887. t['afii301'] = 0x200D;
  9888. t['afii57381'] = 0x066A;
  9889. t['afii57388'] = 0x060C;
  9890. t['afii57392'] = 0x0660;
  9891. t['afii57393'] = 0x0661;
  9892. t['afii57394'] = 0x0662;
  9893. t['afii57395'] = 0x0663;
  9894. t['afii57396'] = 0x0664;
  9895. t['afii57397'] = 0x0665;
  9896. t['afii57398'] = 0x0666;
  9897. t['afii57399'] = 0x0667;
  9898. t['afii57400'] = 0x0668;
  9899. t['afii57401'] = 0x0669;
  9900. t['afii57403'] = 0x061B;
  9901. t['afii57407'] = 0x061F;
  9902. t['afii57409'] = 0x0621;
  9903. t['afii57410'] = 0x0622;
  9904. t['afii57411'] = 0x0623;
  9905. t['afii57412'] = 0x0624;
  9906. t['afii57413'] = 0x0625;
  9907. t['afii57414'] = 0x0626;
  9908. t['afii57415'] = 0x0627;
  9909. t['afii57416'] = 0x0628;
  9910. t['afii57417'] = 0x0629;
  9911. t['afii57418'] = 0x062A;
  9912. t['afii57419'] = 0x062B;
  9913. t['afii57420'] = 0x062C;
  9914. t['afii57421'] = 0x062D;
  9915. t['afii57422'] = 0x062E;
  9916. t['afii57423'] = 0x062F;
  9917. t['afii57424'] = 0x0630;
  9918. t['afii57425'] = 0x0631;
  9919. t['afii57426'] = 0x0632;
  9920. t['afii57427'] = 0x0633;
  9921. t['afii57428'] = 0x0634;
  9922. t['afii57429'] = 0x0635;
  9923. t['afii57430'] = 0x0636;
  9924. t['afii57431'] = 0x0637;
  9925. t['afii57432'] = 0x0638;
  9926. t['afii57433'] = 0x0639;
  9927. t['afii57434'] = 0x063A;
  9928. t['afii57440'] = 0x0640;
  9929. t['afii57441'] = 0x0641;
  9930. t['afii57442'] = 0x0642;
  9931. t['afii57443'] = 0x0643;
  9932. t['afii57444'] = 0x0644;
  9933. t['afii57445'] = 0x0645;
  9934. t['afii57446'] = 0x0646;
  9935. t['afii57448'] = 0x0648;
  9936. t['afii57449'] = 0x0649;
  9937. t['afii57450'] = 0x064A;
  9938. t['afii57451'] = 0x064B;
  9939. t['afii57452'] = 0x064C;
  9940. t['afii57453'] = 0x064D;
  9941. t['afii57454'] = 0x064E;
  9942. t['afii57455'] = 0x064F;
  9943. t['afii57456'] = 0x0650;
  9944. t['afii57457'] = 0x0651;
  9945. t['afii57458'] = 0x0652;
  9946. t['afii57470'] = 0x0647;
  9947. t['afii57505'] = 0x06A4;
  9948. t['afii57506'] = 0x067E;
  9949. t['afii57507'] = 0x0686;
  9950. t['afii57508'] = 0x0698;
  9951. t['afii57509'] = 0x06AF;
  9952. t['afii57511'] = 0x0679;
  9953. t['afii57512'] = 0x0688;
  9954. t['afii57513'] = 0x0691;
  9955. t['afii57514'] = 0x06BA;
  9956. t['afii57519'] = 0x06D2;
  9957. t['afii57534'] = 0x06D5;
  9958. t['afii57636'] = 0x20AA;
  9959. t['afii57645'] = 0x05BE;
  9960. t['afii57658'] = 0x05C3;
  9961. t['afii57664'] = 0x05D0;
  9962. t['afii57665'] = 0x05D1;
  9963. t['afii57666'] = 0x05D2;
  9964. t['afii57667'] = 0x05D3;
  9965. t['afii57668'] = 0x05D4;
  9966. t['afii57669'] = 0x05D5;
  9967. t['afii57670'] = 0x05D6;
  9968. t['afii57671'] = 0x05D7;
  9969. t['afii57672'] = 0x05D8;
  9970. t['afii57673'] = 0x05D9;
  9971. t['afii57674'] = 0x05DA;
  9972. t['afii57675'] = 0x05DB;
  9973. t['afii57676'] = 0x05DC;
  9974. t['afii57677'] = 0x05DD;
  9975. t['afii57678'] = 0x05DE;
  9976. t['afii57679'] = 0x05DF;
  9977. t['afii57680'] = 0x05E0;
  9978. t['afii57681'] = 0x05E1;
  9979. t['afii57682'] = 0x05E2;
  9980. t['afii57683'] = 0x05E3;
  9981. t['afii57684'] = 0x05E4;
  9982. t['afii57685'] = 0x05E5;
  9983. t['afii57686'] = 0x05E6;
  9984. t['afii57687'] = 0x05E7;
  9985. t['afii57688'] = 0x05E8;
  9986. t['afii57689'] = 0x05E9;
  9987. t['afii57690'] = 0x05EA;
  9988. t['afii57694'] = 0xFB2A;
  9989. t['afii57695'] = 0xFB2B;
  9990. t['afii57700'] = 0xFB4B;
  9991. t['afii57705'] = 0xFB1F;
  9992. t['afii57716'] = 0x05F0;
  9993. t['afii57717'] = 0x05F1;
  9994. t['afii57718'] = 0x05F2;
  9995. t['afii57723'] = 0xFB35;
  9996. t['afii57793'] = 0x05B4;
  9997. t['afii57794'] = 0x05B5;
  9998. t['afii57795'] = 0x05B6;
  9999. t['afii57796'] = 0x05BB;
  10000. t['afii57797'] = 0x05B8;
  10001. t['afii57798'] = 0x05B7;
  10002. t['afii57799'] = 0x05B0;
  10003. t['afii57800'] = 0x05B2;
  10004. t['afii57801'] = 0x05B1;
  10005. t['afii57802'] = 0x05B3;
  10006. t['afii57803'] = 0x05C2;
  10007. t['afii57804'] = 0x05C1;
  10008. t['afii57806'] = 0x05B9;
  10009. t['afii57807'] = 0x05BC;
  10010. t['afii57839'] = 0x05BD;
  10011. t['afii57841'] = 0x05BF;
  10012. t['afii57842'] = 0x05C0;
  10013. t['afii57929'] = 0x02BC;
  10014. t['afii61248'] = 0x2105;
  10015. t['afii61289'] = 0x2113;
  10016. t['afii61352'] = 0x2116;
  10017. t['afii61573'] = 0x202C;
  10018. t['afii61574'] = 0x202D;
  10019. t['afii61575'] = 0x202E;
  10020. t['afii61664'] = 0x200C;
  10021. t['afii63167'] = 0x066D;
  10022. t['afii64937'] = 0x02BD;
  10023. t['agrave'] = 0x00E0;
  10024. t['agujarati'] = 0x0A85;
  10025. t['agurmukhi'] = 0x0A05;
  10026. t['ahiragana'] = 0x3042;
  10027. t['ahookabove'] = 0x1EA3;
  10028. t['aibengali'] = 0x0990;
  10029. t['aibopomofo'] = 0x311E;
  10030. t['aideva'] = 0x0910;
  10031. t['aiecyrillic'] = 0x04D5;
  10032. t['aigujarati'] = 0x0A90;
  10033. t['aigurmukhi'] = 0x0A10;
  10034. t['aimatragurmukhi'] = 0x0A48;
  10035. t['ainarabic'] = 0x0639;
  10036. t['ainfinalarabic'] = 0xFECA;
  10037. t['aininitialarabic'] = 0xFECB;
  10038. t['ainmedialarabic'] = 0xFECC;
  10039. t['ainvertedbreve'] = 0x0203;
  10040. t['aivowelsignbengali'] = 0x09C8;
  10041. t['aivowelsigndeva'] = 0x0948;
  10042. t['aivowelsigngujarati'] = 0x0AC8;
  10043. t['akatakana'] = 0x30A2;
  10044. t['akatakanahalfwidth'] = 0xFF71;
  10045. t['akorean'] = 0x314F;
  10046. t['alef'] = 0x05D0;
  10047. t['alefarabic'] = 0x0627;
  10048. t['alefdageshhebrew'] = 0xFB30;
  10049. t['aleffinalarabic'] = 0xFE8E;
  10050. t['alefhamzaabovearabic'] = 0x0623;
  10051. t['alefhamzaabovefinalarabic'] = 0xFE84;
  10052. t['alefhamzabelowarabic'] = 0x0625;
  10053. t['alefhamzabelowfinalarabic'] = 0xFE88;
  10054. t['alefhebrew'] = 0x05D0;
  10055. t['aleflamedhebrew'] = 0xFB4F;
  10056. t['alefmaddaabovearabic'] = 0x0622;
  10057. t['alefmaddaabovefinalarabic'] = 0xFE82;
  10058. t['alefmaksuraarabic'] = 0x0649;
  10059. t['alefmaksurafinalarabic'] = 0xFEF0;
  10060. t['alefmaksurainitialarabic'] = 0xFEF3;
  10061. t['alefmaksuramedialarabic'] = 0xFEF4;
  10062. t['alefpatahhebrew'] = 0xFB2E;
  10063. t['alefqamatshebrew'] = 0xFB2F;
  10064. t['aleph'] = 0x2135;
  10065. t['allequal'] = 0x224C;
  10066. t['alpha'] = 0x03B1;
  10067. t['alphatonos'] = 0x03AC;
  10068. t['amacron'] = 0x0101;
  10069. t['amonospace'] = 0xFF41;
  10070. t['ampersand'] = 0x0026;
  10071. t['ampersandmonospace'] = 0xFF06;
  10072. t['ampersandsmall'] = 0xF726;
  10073. t['amsquare'] = 0x33C2;
  10074. t['anbopomofo'] = 0x3122;
  10075. t['angbopomofo'] = 0x3124;
  10076. t['angbracketleft'] = 0x3008;
  10077. // Glyph is missing from Adobe's original list.
  10078. t['angbracketright'] = 0x3009;
  10079. // Glyph is missing from Adobe's original list.
  10080. t['angkhankhuthai'] = 0x0E5A;
  10081. t['angle'] = 0x2220;
  10082. t['anglebracketleft'] = 0x3008;
  10083. t['anglebracketleftvertical'] = 0xFE3F;
  10084. t['anglebracketright'] = 0x3009;
  10085. t['anglebracketrightvertical'] = 0xFE40;
  10086. t['angleleft'] = 0x2329;
  10087. t['angleright'] = 0x232A;
  10088. t['angstrom'] = 0x212B;
  10089. t['anoteleia'] = 0x0387;
  10090. t['anudattadeva'] = 0x0952;
  10091. t['anusvarabengali'] = 0x0982;
  10092. t['anusvaradeva'] = 0x0902;
  10093. t['anusvaragujarati'] = 0x0A82;
  10094. t['aogonek'] = 0x0105;
  10095. t['apaatosquare'] = 0x3300;
  10096. t['aparen'] = 0x249C;
  10097. t['apostrophearmenian'] = 0x055A;
  10098. t['apostrophemod'] = 0x02BC;
  10099. t['apple'] = 0xF8FF;
  10100. t['approaches'] = 0x2250;
  10101. t['approxequal'] = 0x2248;
  10102. t['approxequalorimage'] = 0x2252;
  10103. t['approximatelyequal'] = 0x2245;
  10104. t['araeaekorean'] = 0x318E;
  10105. t['araeakorean'] = 0x318D;
  10106. t['arc'] = 0x2312;
  10107. t['arighthalfring'] = 0x1E9A;
  10108. t['aring'] = 0x00E5;
  10109. t['aringacute'] = 0x01FB;
  10110. t['aringbelow'] = 0x1E01;
  10111. t['arrowboth'] = 0x2194;
  10112. t['arrowdashdown'] = 0x21E3;
  10113. t['arrowdashleft'] = 0x21E0;
  10114. t['arrowdashright'] = 0x21E2;
  10115. t['arrowdashup'] = 0x21E1;
  10116. t['arrowdblboth'] = 0x21D4;
  10117. t['arrowdbldown'] = 0x21D3;
  10118. t['arrowdblleft'] = 0x21D0;
  10119. t['arrowdblright'] = 0x21D2;
  10120. t['arrowdblup'] = 0x21D1;
  10121. t['arrowdown'] = 0x2193;
  10122. t['arrowdownleft'] = 0x2199;
  10123. t['arrowdownright'] = 0x2198;
  10124. t['arrowdownwhite'] = 0x21E9;
  10125. t['arrowheaddownmod'] = 0x02C5;
  10126. t['arrowheadleftmod'] = 0x02C2;
  10127. t['arrowheadrightmod'] = 0x02C3;
  10128. t['arrowheadupmod'] = 0x02C4;
  10129. t['arrowhorizex'] = 0xF8E7;
  10130. t['arrowleft'] = 0x2190;
  10131. t['arrowleftdbl'] = 0x21D0;
  10132. t['arrowleftdblstroke'] = 0x21CD;
  10133. t['arrowleftoverright'] = 0x21C6;
  10134. t['arrowleftwhite'] = 0x21E6;
  10135. t['arrowright'] = 0x2192;
  10136. t['arrowrightdblstroke'] = 0x21CF;
  10137. t['arrowrightheavy'] = 0x279E;
  10138. t['arrowrightoverleft'] = 0x21C4;
  10139. t['arrowrightwhite'] = 0x21E8;
  10140. t['arrowtableft'] = 0x21E4;
  10141. t['arrowtabright'] = 0x21E5;
  10142. t['arrowup'] = 0x2191;
  10143. t['arrowupdn'] = 0x2195;
  10144. t['arrowupdnbse'] = 0x21A8;
  10145. t['arrowupdownbase'] = 0x21A8;
  10146. t['arrowupleft'] = 0x2196;
  10147. t['arrowupleftofdown'] = 0x21C5;
  10148. t['arrowupright'] = 0x2197;
  10149. t['arrowupwhite'] = 0x21E7;
  10150. t['arrowvertex'] = 0xF8E6;
  10151. t['asciicircum'] = 0x005E;
  10152. t['asciicircummonospace'] = 0xFF3E;
  10153. t['asciitilde'] = 0x007E;
  10154. t['asciitildemonospace'] = 0xFF5E;
  10155. t['ascript'] = 0x0251;
  10156. t['ascriptturned'] = 0x0252;
  10157. t['asmallhiragana'] = 0x3041;
  10158. t['asmallkatakana'] = 0x30A1;
  10159. t['asmallkatakanahalfwidth'] = 0xFF67;
  10160. t['asterisk'] = 0x002A;
  10161. t['asteriskaltonearabic'] = 0x066D;
  10162. t['asteriskarabic'] = 0x066D;
  10163. t['asteriskmath'] = 0x2217;
  10164. t['asteriskmonospace'] = 0xFF0A;
  10165. t['asterisksmall'] = 0xFE61;
  10166. t['asterism'] = 0x2042;
  10167. t['asuperior'] = 0xF6E9;
  10168. t['asymptoticallyequal'] = 0x2243;
  10169. t['at'] = 0x0040;
  10170. t['atilde'] = 0x00E3;
  10171. t['atmonospace'] = 0xFF20;
  10172. t['atsmall'] = 0xFE6B;
  10173. t['aturned'] = 0x0250;
  10174. t['aubengali'] = 0x0994;
  10175. t['aubopomofo'] = 0x3120;
  10176. t['audeva'] = 0x0914;
  10177. t['augujarati'] = 0x0A94;
  10178. t['augurmukhi'] = 0x0A14;
  10179. t['aulengthmarkbengali'] = 0x09D7;
  10180. t['aumatragurmukhi'] = 0x0A4C;
  10181. t['auvowelsignbengali'] = 0x09CC;
  10182. t['auvowelsigndeva'] = 0x094C;
  10183. t['auvowelsigngujarati'] = 0x0ACC;
  10184. t['avagrahadeva'] = 0x093D;
  10185. t['aybarmenian'] = 0x0561;
  10186. t['ayin'] = 0x05E2;
  10187. t['ayinaltonehebrew'] = 0xFB20;
  10188. t['ayinhebrew'] = 0x05E2;
  10189. t['b'] = 0x0062;
  10190. t['babengali'] = 0x09AC;
  10191. t['backslash'] = 0x005C;
  10192. t['backslashmonospace'] = 0xFF3C;
  10193. t['badeva'] = 0x092C;
  10194. t['bagujarati'] = 0x0AAC;
  10195. t['bagurmukhi'] = 0x0A2C;
  10196. t['bahiragana'] = 0x3070;
  10197. t['bahtthai'] = 0x0E3F;
  10198. t['bakatakana'] = 0x30D0;
  10199. t['bar'] = 0x007C;
  10200. t['barmonospace'] = 0xFF5C;
  10201. t['bbopomofo'] = 0x3105;
  10202. t['bcircle'] = 0x24D1;
  10203. t['bdotaccent'] = 0x1E03;
  10204. t['bdotbelow'] = 0x1E05;
  10205. t['beamedsixteenthnotes'] = 0x266C;
  10206. t['because'] = 0x2235;
  10207. t['becyrillic'] = 0x0431;
  10208. t['beharabic'] = 0x0628;
  10209. t['behfinalarabic'] = 0xFE90;
  10210. t['behinitialarabic'] = 0xFE91;
  10211. t['behiragana'] = 0x3079;
  10212. t['behmedialarabic'] = 0xFE92;
  10213. t['behmeeminitialarabic'] = 0xFC9F;
  10214. t['behmeemisolatedarabic'] = 0xFC08;
  10215. t['behnoonfinalarabic'] = 0xFC6D;
  10216. t['bekatakana'] = 0x30D9;
  10217. t['benarmenian'] = 0x0562;
  10218. t['bet'] = 0x05D1;
  10219. t['beta'] = 0x03B2;
  10220. t['betasymbolgreek'] = 0x03D0;
  10221. t['betdagesh'] = 0xFB31;
  10222. t['betdageshhebrew'] = 0xFB31;
  10223. t['bethebrew'] = 0x05D1;
  10224. t['betrafehebrew'] = 0xFB4C;
  10225. t['bhabengali'] = 0x09AD;
  10226. t['bhadeva'] = 0x092D;
  10227. t['bhagujarati'] = 0x0AAD;
  10228. t['bhagurmukhi'] = 0x0A2D;
  10229. t['bhook'] = 0x0253;
  10230. t['bihiragana'] = 0x3073;
  10231. t['bikatakana'] = 0x30D3;
  10232. t['bilabialclick'] = 0x0298;
  10233. t['bindigurmukhi'] = 0x0A02;
  10234. t['birusquare'] = 0x3331;
  10235. t['blackcircle'] = 0x25CF;
  10236. t['blackdiamond'] = 0x25C6;
  10237. t['blackdownpointingtriangle'] = 0x25BC;
  10238. t['blackleftpointingpointer'] = 0x25C4;
  10239. t['blackleftpointingtriangle'] = 0x25C0;
  10240. t['blacklenticularbracketleft'] = 0x3010;
  10241. t['blacklenticularbracketleftvertical'] = 0xFE3B;
  10242. t['blacklenticularbracketright'] = 0x3011;
  10243. t['blacklenticularbracketrightvertical'] = 0xFE3C;
  10244. t['blacklowerlefttriangle'] = 0x25E3;
  10245. t['blacklowerrighttriangle'] = 0x25E2;
  10246. t['blackrectangle'] = 0x25AC;
  10247. t['blackrightpointingpointer'] = 0x25BA;
  10248. t['blackrightpointingtriangle'] = 0x25B6;
  10249. t['blacksmallsquare'] = 0x25AA;
  10250. t['blacksmilingface'] = 0x263B;
  10251. t['blacksquare'] = 0x25A0;
  10252. t['blackstar'] = 0x2605;
  10253. t['blackupperlefttriangle'] = 0x25E4;
  10254. t['blackupperrighttriangle'] = 0x25E5;
  10255. t['blackuppointingsmalltriangle'] = 0x25B4;
  10256. t['blackuppointingtriangle'] = 0x25B2;
  10257. t['blank'] = 0x2423;
  10258. t['blinebelow'] = 0x1E07;
  10259. t['block'] = 0x2588;
  10260. t['bmonospace'] = 0xFF42;
  10261. t['bobaimaithai'] = 0x0E1A;
  10262. t['bohiragana'] = 0x307C;
  10263. t['bokatakana'] = 0x30DC;
  10264. t['bparen'] = 0x249D;
  10265. t['bqsquare'] = 0x33C3;
  10266. t['braceex'] = 0xF8F4;
  10267. t['braceleft'] = 0x007B;
  10268. t['braceleftbt'] = 0xF8F3;
  10269. t['braceleftmid'] = 0xF8F2;
  10270. t['braceleftmonospace'] = 0xFF5B;
  10271. t['braceleftsmall'] = 0xFE5B;
  10272. t['bracelefttp'] = 0xF8F1;
  10273. t['braceleftvertical'] = 0xFE37;
  10274. t['braceright'] = 0x007D;
  10275. t['bracerightbt'] = 0xF8FE;
  10276. t['bracerightmid'] = 0xF8FD;
  10277. t['bracerightmonospace'] = 0xFF5D;
  10278. t['bracerightsmall'] = 0xFE5C;
  10279. t['bracerighttp'] = 0xF8FC;
  10280. t['bracerightvertical'] = 0xFE38;
  10281. t['bracketleft'] = 0x005B;
  10282. t['bracketleftbt'] = 0xF8F0;
  10283. t['bracketleftex'] = 0xF8EF;
  10284. t['bracketleftmonospace'] = 0xFF3B;
  10285. t['bracketlefttp'] = 0xF8EE;
  10286. t['bracketright'] = 0x005D;
  10287. t['bracketrightbt'] = 0xF8FB;
  10288. t['bracketrightex'] = 0xF8FA;
  10289. t['bracketrightmonospace'] = 0xFF3D;
  10290. t['bracketrighttp'] = 0xF8F9;
  10291. t['breve'] = 0x02D8;
  10292. t['brevebelowcmb'] = 0x032E;
  10293. t['brevecmb'] = 0x0306;
  10294. t['breveinvertedbelowcmb'] = 0x032F;
  10295. t['breveinvertedcmb'] = 0x0311;
  10296. t['breveinverteddoublecmb'] = 0x0361;
  10297. t['bridgebelowcmb'] = 0x032A;
  10298. t['bridgeinvertedbelowcmb'] = 0x033A;
  10299. t['brokenbar'] = 0x00A6;
  10300. t['bstroke'] = 0x0180;
  10301. t['bsuperior'] = 0xF6EA;
  10302. t['btopbar'] = 0x0183;
  10303. t['buhiragana'] = 0x3076;
  10304. t['bukatakana'] = 0x30D6;
  10305. t['bullet'] = 0x2022;
  10306. t['bulletinverse'] = 0x25D8;
  10307. t['bulletoperator'] = 0x2219;
  10308. t['bullseye'] = 0x25CE;
  10309. t['c'] = 0x0063;
  10310. t['caarmenian'] = 0x056E;
  10311. t['cabengali'] = 0x099A;
  10312. t['cacute'] = 0x0107;
  10313. t['cadeva'] = 0x091A;
  10314. t['cagujarati'] = 0x0A9A;
  10315. t['cagurmukhi'] = 0x0A1A;
  10316. t['calsquare'] = 0x3388;
  10317. t['candrabindubengali'] = 0x0981;
  10318. t['candrabinducmb'] = 0x0310;
  10319. t['candrabindudeva'] = 0x0901;
  10320. t['candrabindugujarati'] = 0x0A81;
  10321. t['capslock'] = 0x21EA;
  10322. t['careof'] = 0x2105;
  10323. t['caron'] = 0x02C7;
  10324. t['caronbelowcmb'] = 0x032C;
  10325. t['caroncmb'] = 0x030C;
  10326. t['carriagereturn'] = 0x21B5;
  10327. t['cbopomofo'] = 0x3118;
  10328. t['ccaron'] = 0x010D;
  10329. t['ccedilla'] = 0x00E7;
  10330. t['ccedillaacute'] = 0x1E09;
  10331. t['ccircle'] = 0x24D2;
  10332. t['ccircumflex'] = 0x0109;
  10333. t['ccurl'] = 0x0255;
  10334. t['cdot'] = 0x010B;
  10335. t['cdotaccent'] = 0x010B;
  10336. t['cdsquare'] = 0x33C5;
  10337. t['cedilla'] = 0x00B8;
  10338. t['cedillacmb'] = 0x0327;
  10339. t['cent'] = 0x00A2;
  10340. t['centigrade'] = 0x2103;
  10341. t['centinferior'] = 0xF6DF;
  10342. t['centmonospace'] = 0xFFE0;
  10343. t['centoldstyle'] = 0xF7A2;
  10344. t['centsuperior'] = 0xF6E0;
  10345. t['chaarmenian'] = 0x0579;
  10346. t['chabengali'] = 0x099B;
  10347. t['chadeva'] = 0x091B;
  10348. t['chagujarati'] = 0x0A9B;
  10349. t['chagurmukhi'] = 0x0A1B;
  10350. t['chbopomofo'] = 0x3114;
  10351. t['cheabkhasiancyrillic'] = 0x04BD;
  10352. t['checkmark'] = 0x2713;
  10353. t['checyrillic'] = 0x0447;
  10354. t['chedescenderabkhasiancyrillic'] = 0x04BF;
  10355. t['chedescendercyrillic'] = 0x04B7;
  10356. t['chedieresiscyrillic'] = 0x04F5;
  10357. t['cheharmenian'] = 0x0573;
  10358. t['chekhakassiancyrillic'] = 0x04CC;
  10359. t['cheverticalstrokecyrillic'] = 0x04B9;
  10360. t['chi'] = 0x03C7;
  10361. t['chieuchacirclekorean'] = 0x3277;
  10362. t['chieuchaparenkorean'] = 0x3217;
  10363. t['chieuchcirclekorean'] = 0x3269;
  10364. t['chieuchkorean'] = 0x314A;
  10365. t['chieuchparenkorean'] = 0x3209;
  10366. t['chochangthai'] = 0x0E0A;
  10367. t['chochanthai'] = 0x0E08;
  10368. t['chochingthai'] = 0x0E09;
  10369. t['chochoethai'] = 0x0E0C;
  10370. t['chook'] = 0x0188;
  10371. t['cieucacirclekorean'] = 0x3276;
  10372. t['cieucaparenkorean'] = 0x3216;
  10373. t['cieuccirclekorean'] = 0x3268;
  10374. t['cieuckorean'] = 0x3148;
  10375. t['cieucparenkorean'] = 0x3208;
  10376. t['cieucuparenkorean'] = 0x321C;
  10377. t['circle'] = 0x25CB;
  10378. t['circlecopyrt'] = 0x00A9;
  10379. // Glyph is missing from Adobe's original list.
  10380. t['circlemultiply'] = 0x2297;
  10381. t['circleot'] = 0x2299;
  10382. t['circleplus'] = 0x2295;
  10383. t['circlepostalmark'] = 0x3036;
  10384. t['circlewithlefthalfblack'] = 0x25D0;
  10385. t['circlewithrighthalfblack'] = 0x25D1;
  10386. t['circumflex'] = 0x02C6;
  10387. t['circumflexbelowcmb'] = 0x032D;
  10388. t['circumflexcmb'] = 0x0302;
  10389. t['clear'] = 0x2327;
  10390. t['clickalveolar'] = 0x01C2;
  10391. t['clickdental'] = 0x01C0;
  10392. t['clicklateral'] = 0x01C1;
  10393. t['clickretroflex'] = 0x01C3;
  10394. t['club'] = 0x2663;
  10395. t['clubsuitblack'] = 0x2663;
  10396. t['clubsuitwhite'] = 0x2667;
  10397. t['cmcubedsquare'] = 0x33A4;
  10398. t['cmonospace'] = 0xFF43;
  10399. t['cmsquaredsquare'] = 0x33A0;
  10400. t['coarmenian'] = 0x0581;
  10401. t['colon'] = 0x003A;
  10402. t['colonmonetary'] = 0x20A1;
  10403. t['colonmonospace'] = 0xFF1A;
  10404. t['colonsign'] = 0x20A1;
  10405. t['colonsmall'] = 0xFE55;
  10406. t['colontriangularhalfmod'] = 0x02D1;
  10407. t['colontriangularmod'] = 0x02D0;
  10408. t['comma'] = 0x002C;
  10409. t['commaabovecmb'] = 0x0313;
  10410. t['commaaboverightcmb'] = 0x0315;
  10411. t['commaaccent'] = 0xF6C3;
  10412. t['commaarabic'] = 0x060C;
  10413. t['commaarmenian'] = 0x055D;
  10414. t['commainferior'] = 0xF6E1;
  10415. t['commamonospace'] = 0xFF0C;
  10416. t['commareversedabovecmb'] = 0x0314;
  10417. t['commareversedmod'] = 0x02BD;
  10418. t['commasmall'] = 0xFE50;
  10419. t['commasuperior'] = 0xF6E2;
  10420. t['commaturnedabovecmb'] = 0x0312;
  10421. t['commaturnedmod'] = 0x02BB;
  10422. t['compass'] = 0x263C;
  10423. t['congruent'] = 0x2245;
  10424. t['contourintegral'] = 0x222E;
  10425. t['control'] = 0x2303;
  10426. t['controlACK'] = 0x0006;
  10427. t['controlBEL'] = 0x0007;
  10428. t['controlBS'] = 0x0008;
  10429. t['controlCAN'] = 0x0018;
  10430. t['controlCR'] = 0x000D;
  10431. t['controlDC1'] = 0x0011;
  10432. t['controlDC2'] = 0x0012;
  10433. t['controlDC3'] = 0x0013;
  10434. t['controlDC4'] = 0x0014;
  10435. t['controlDEL'] = 0x007F;
  10436. t['controlDLE'] = 0x0010;
  10437. t['controlEM'] = 0x0019;
  10438. t['controlENQ'] = 0x0005;
  10439. t['controlEOT'] = 0x0004;
  10440. t['controlESC'] = 0x001B;
  10441. t['controlETB'] = 0x0017;
  10442. t['controlETX'] = 0x0003;
  10443. t['controlFF'] = 0x000C;
  10444. t['controlFS'] = 0x001C;
  10445. t['controlGS'] = 0x001D;
  10446. t['controlHT'] = 0x0009;
  10447. t['controlLF'] = 0x000A;
  10448. t['controlNAK'] = 0x0015;
  10449. t['controlRS'] = 0x001E;
  10450. t['controlSI'] = 0x000F;
  10451. t['controlSO'] = 0x000E;
  10452. t['controlSOT'] = 0x0002;
  10453. t['controlSTX'] = 0x0001;
  10454. t['controlSUB'] = 0x001A;
  10455. t['controlSYN'] = 0x0016;
  10456. t['controlUS'] = 0x001F;
  10457. t['controlVT'] = 0x000B;
  10458. t['copyright'] = 0x00A9;
  10459. t['copyrightsans'] = 0xF8E9;
  10460. t['copyrightserif'] = 0xF6D9;
  10461. t['cornerbracketleft'] = 0x300C;
  10462. t['cornerbracketlefthalfwidth'] = 0xFF62;
  10463. t['cornerbracketleftvertical'] = 0xFE41;
  10464. t['cornerbracketright'] = 0x300D;
  10465. t['cornerbracketrighthalfwidth'] = 0xFF63;
  10466. t['cornerbracketrightvertical'] = 0xFE42;
  10467. t['corporationsquare'] = 0x337F;
  10468. t['cosquare'] = 0x33C7;
  10469. t['coverkgsquare'] = 0x33C6;
  10470. t['cparen'] = 0x249E;
  10471. t['cruzeiro'] = 0x20A2;
  10472. t['cstretched'] = 0x0297;
  10473. t['curlyand'] = 0x22CF;
  10474. t['curlyor'] = 0x22CE;
  10475. t['currency'] = 0x00A4;
  10476. t['cyrBreve'] = 0xF6D1;
  10477. t['cyrFlex'] = 0xF6D2;
  10478. t['cyrbreve'] = 0xF6D4;
  10479. t['cyrflex'] = 0xF6D5;
  10480. t['d'] = 0x0064;
  10481. t['daarmenian'] = 0x0564;
  10482. t['dabengali'] = 0x09A6;
  10483. t['dadarabic'] = 0x0636;
  10484. t['dadeva'] = 0x0926;
  10485. t['dadfinalarabic'] = 0xFEBE;
  10486. t['dadinitialarabic'] = 0xFEBF;
  10487. t['dadmedialarabic'] = 0xFEC0;
  10488. t['dagesh'] = 0x05BC;
  10489. t['dageshhebrew'] = 0x05BC;
  10490. t['dagger'] = 0x2020;
  10491. t['daggerdbl'] = 0x2021;
  10492. t['dagujarati'] = 0x0AA6;
  10493. t['dagurmukhi'] = 0x0A26;
  10494. t['dahiragana'] = 0x3060;
  10495. t['dakatakana'] = 0x30C0;
  10496. t['dalarabic'] = 0x062F;
  10497. t['dalet'] = 0x05D3;
  10498. t['daletdagesh'] = 0xFB33;
  10499. t['daletdageshhebrew'] = 0xFB33;
  10500. t['dalethebrew'] = 0x05D3;
  10501. t['dalfinalarabic'] = 0xFEAA;
  10502. t['dammaarabic'] = 0x064F;
  10503. t['dammalowarabic'] = 0x064F;
  10504. t['dammatanaltonearabic'] = 0x064C;
  10505. t['dammatanarabic'] = 0x064C;
  10506. t['danda'] = 0x0964;
  10507. t['dargahebrew'] = 0x05A7;
  10508. t['dargalefthebrew'] = 0x05A7;
  10509. t['dasiapneumatacyrilliccmb'] = 0x0485;
  10510. t['dblGrave'] = 0xF6D3;
  10511. t['dblanglebracketleft'] = 0x300A;
  10512. t['dblanglebracketleftvertical'] = 0xFE3D;
  10513. t['dblanglebracketright'] = 0x300B;
  10514. t['dblanglebracketrightvertical'] = 0xFE3E;
  10515. t['dblarchinvertedbelowcmb'] = 0x032B;
  10516. t['dblarrowleft'] = 0x21D4;
  10517. t['dblarrowright'] = 0x21D2;
  10518. t['dbldanda'] = 0x0965;
  10519. t['dblgrave'] = 0xF6D6;
  10520. t['dblgravecmb'] = 0x030F;
  10521. t['dblintegral'] = 0x222C;
  10522. t['dbllowline'] = 0x2017;
  10523. t['dbllowlinecmb'] = 0x0333;
  10524. t['dbloverlinecmb'] = 0x033F;
  10525. t['dblprimemod'] = 0x02BA;
  10526. t['dblverticalbar'] = 0x2016;
  10527. t['dblverticallineabovecmb'] = 0x030E;
  10528. t['dbopomofo'] = 0x3109;
  10529. t['dbsquare'] = 0x33C8;
  10530. t['dcaron'] = 0x010F;
  10531. t['dcedilla'] = 0x1E11;
  10532. t['dcircle'] = 0x24D3;
  10533. t['dcircumflexbelow'] = 0x1E13;
  10534. t['dcroat'] = 0x0111;
  10535. t['ddabengali'] = 0x09A1;
  10536. t['ddadeva'] = 0x0921;
  10537. t['ddagujarati'] = 0x0AA1;
  10538. t['ddagurmukhi'] = 0x0A21;
  10539. t['ddalarabic'] = 0x0688;
  10540. t['ddalfinalarabic'] = 0xFB89;
  10541. t['dddhadeva'] = 0x095C;
  10542. t['ddhabengali'] = 0x09A2;
  10543. t['ddhadeva'] = 0x0922;
  10544. t['ddhagujarati'] = 0x0AA2;
  10545. t['ddhagurmukhi'] = 0x0A22;
  10546. t['ddotaccent'] = 0x1E0B;
  10547. t['ddotbelow'] = 0x1E0D;
  10548. t['decimalseparatorarabic'] = 0x066B;
  10549. t['decimalseparatorpersian'] = 0x066B;
  10550. t['decyrillic'] = 0x0434;
  10551. t['degree'] = 0x00B0;
  10552. t['dehihebrew'] = 0x05AD;
  10553. t['dehiragana'] = 0x3067;
  10554. t['deicoptic'] = 0x03EF;
  10555. t['dekatakana'] = 0x30C7;
  10556. t['deleteleft'] = 0x232B;
  10557. t['deleteright'] = 0x2326;
  10558. t['delta'] = 0x03B4;
  10559. t['deltaturned'] = 0x018D;
  10560. t['denominatorminusonenumeratorbengali'] = 0x09F8;
  10561. t['dezh'] = 0x02A4;
  10562. t['dhabengali'] = 0x09A7;
  10563. t['dhadeva'] = 0x0927;
  10564. t['dhagujarati'] = 0x0AA7;
  10565. t['dhagurmukhi'] = 0x0A27;
  10566. t['dhook'] = 0x0257;
  10567. t['dialytikatonos'] = 0x0385;
  10568. t['dialytikatonoscmb'] = 0x0344;
  10569. t['diamond'] = 0x2666;
  10570. t['diamondsuitwhite'] = 0x2662;
  10571. t['dieresis'] = 0x00A8;
  10572. t['dieresisacute'] = 0xF6D7;
  10573. t['dieresisbelowcmb'] = 0x0324;
  10574. t['dieresiscmb'] = 0x0308;
  10575. t['dieresisgrave'] = 0xF6D8;
  10576. t['dieresistonos'] = 0x0385;
  10577. t['dihiragana'] = 0x3062;
  10578. t['dikatakana'] = 0x30C2;
  10579. t['dittomark'] = 0x3003;
  10580. t['divide'] = 0x00F7;
  10581. t['divides'] = 0x2223;
  10582. t['divisionslash'] = 0x2215;
  10583. t['djecyrillic'] = 0x0452;
  10584. t['dkshade'] = 0x2593;
  10585. t['dlinebelow'] = 0x1E0F;
  10586. t['dlsquare'] = 0x3397;
  10587. t['dmacron'] = 0x0111;
  10588. t['dmonospace'] = 0xFF44;
  10589. t['dnblock'] = 0x2584;
  10590. t['dochadathai'] = 0x0E0E;
  10591. t['dodekthai'] = 0x0E14;
  10592. t['dohiragana'] = 0x3069;
  10593. t['dokatakana'] = 0x30C9;
  10594. t['dollar'] = 0x0024;
  10595. t['dollarinferior'] = 0xF6E3;
  10596. t['dollarmonospace'] = 0xFF04;
  10597. t['dollaroldstyle'] = 0xF724;
  10598. t['dollarsmall'] = 0xFE69;
  10599. t['dollarsuperior'] = 0xF6E4;
  10600. t['dong'] = 0x20AB;
  10601. t['dorusquare'] = 0x3326;
  10602. t['dotaccent'] = 0x02D9;
  10603. t['dotaccentcmb'] = 0x0307;
  10604. t['dotbelowcmb'] = 0x0323;
  10605. t['dotbelowcomb'] = 0x0323;
  10606. t['dotkatakana'] = 0x30FB;
  10607. t['dotlessi'] = 0x0131;
  10608. t['dotlessj'] = 0xF6BE;
  10609. t['dotlessjstrokehook'] = 0x0284;
  10610. t['dotmath'] = 0x22C5;
  10611. t['dottedcircle'] = 0x25CC;
  10612. t['doubleyodpatah'] = 0xFB1F;
  10613. t['doubleyodpatahhebrew'] = 0xFB1F;
  10614. t['downtackbelowcmb'] = 0x031E;
  10615. t['downtackmod'] = 0x02D5;
  10616. t['dparen'] = 0x249F;
  10617. t['dsuperior'] = 0xF6EB;
  10618. t['dtail'] = 0x0256;
  10619. t['dtopbar'] = 0x018C;
  10620. t['duhiragana'] = 0x3065;
  10621. t['dukatakana'] = 0x30C5;
  10622. t['dz'] = 0x01F3;
  10623. t['dzaltone'] = 0x02A3;
  10624. t['dzcaron'] = 0x01C6;
  10625. t['dzcurl'] = 0x02A5;
  10626. t['dzeabkhasiancyrillic'] = 0x04E1;
  10627. t['dzecyrillic'] = 0x0455;
  10628. t['dzhecyrillic'] = 0x045F;
  10629. t['e'] = 0x0065;
  10630. t['eacute'] = 0x00E9;
  10631. t['earth'] = 0x2641;
  10632. t['ebengali'] = 0x098F;
  10633. t['ebopomofo'] = 0x311C;
  10634. t['ebreve'] = 0x0115;
  10635. t['ecandradeva'] = 0x090D;
  10636. t['ecandragujarati'] = 0x0A8D;
  10637. t['ecandravowelsigndeva'] = 0x0945;
  10638. t['ecandravowelsigngujarati'] = 0x0AC5;
  10639. t['ecaron'] = 0x011B;
  10640. t['ecedillabreve'] = 0x1E1D;
  10641. t['echarmenian'] = 0x0565;
  10642. t['echyiwnarmenian'] = 0x0587;
  10643. t['ecircle'] = 0x24D4;
  10644. t['ecircumflex'] = 0x00EA;
  10645. t['ecircumflexacute'] = 0x1EBF;
  10646. t['ecircumflexbelow'] = 0x1E19;
  10647. t['ecircumflexdotbelow'] = 0x1EC7;
  10648. t['ecircumflexgrave'] = 0x1EC1;
  10649. t['ecircumflexhookabove'] = 0x1EC3;
  10650. t['ecircumflextilde'] = 0x1EC5;
  10651. t['ecyrillic'] = 0x0454;
  10652. t['edblgrave'] = 0x0205;
  10653. t['edeva'] = 0x090F;
  10654. t['edieresis'] = 0x00EB;
  10655. t['edot'] = 0x0117;
  10656. t['edotaccent'] = 0x0117;
  10657. t['edotbelow'] = 0x1EB9;
  10658. t['eegurmukhi'] = 0x0A0F;
  10659. t['eematragurmukhi'] = 0x0A47;
  10660. t['efcyrillic'] = 0x0444;
  10661. t['egrave'] = 0x00E8;
  10662. t['egujarati'] = 0x0A8F;
  10663. t['eharmenian'] = 0x0567;
  10664. t['ehbopomofo'] = 0x311D;
  10665. t['ehiragana'] = 0x3048;
  10666. t['ehookabove'] = 0x1EBB;
  10667. t['eibopomofo'] = 0x311F;
  10668. t['eight'] = 0x0038;
  10669. t['eightarabic'] = 0x0668;
  10670. t['eightbengali'] = 0x09EE;
  10671. t['eightcircle'] = 0x2467;
  10672. t['eightcircleinversesansserif'] = 0x2791;
  10673. t['eightdeva'] = 0x096E;
  10674. t['eighteencircle'] = 0x2471;
  10675. t['eighteenparen'] = 0x2485;
  10676. t['eighteenperiod'] = 0x2499;
  10677. t['eightgujarati'] = 0x0AEE;
  10678. t['eightgurmukhi'] = 0x0A6E;
  10679. t['eighthackarabic'] = 0x0668;
  10680. t['eighthangzhou'] = 0x3028;
  10681. t['eighthnotebeamed'] = 0x266B;
  10682. t['eightideographicparen'] = 0x3227;
  10683. t['eightinferior'] = 0x2088;
  10684. t['eightmonospace'] = 0xFF18;
  10685. t['eightoldstyle'] = 0xF738;
  10686. t['eightparen'] = 0x247B;
  10687. t['eightperiod'] = 0x248F;
  10688. t['eightpersian'] = 0x06F8;
  10689. t['eightroman'] = 0x2177;
  10690. t['eightsuperior'] = 0x2078;
  10691. t['eightthai'] = 0x0E58;
  10692. t['einvertedbreve'] = 0x0207;
  10693. t['eiotifiedcyrillic'] = 0x0465;
  10694. t['ekatakana'] = 0x30A8;
  10695. t['ekatakanahalfwidth'] = 0xFF74;
  10696. t['ekonkargurmukhi'] = 0x0A74;
  10697. t['ekorean'] = 0x3154;
  10698. t['elcyrillic'] = 0x043B;
  10699. t['element'] = 0x2208;
  10700. t['elevencircle'] = 0x246A;
  10701. t['elevenparen'] = 0x247E;
  10702. t['elevenperiod'] = 0x2492;
  10703. t['elevenroman'] = 0x217A;
  10704. t['ellipsis'] = 0x2026;
  10705. t['ellipsisvertical'] = 0x22EE;
  10706. t['emacron'] = 0x0113;
  10707. t['emacronacute'] = 0x1E17;
  10708. t['emacrongrave'] = 0x1E15;
  10709. t['emcyrillic'] = 0x043C;
  10710. t['emdash'] = 0x2014;
  10711. t['emdashvertical'] = 0xFE31;
  10712. t['emonospace'] = 0xFF45;
  10713. t['emphasismarkarmenian'] = 0x055B;
  10714. t['emptyset'] = 0x2205;
  10715. t['enbopomofo'] = 0x3123;
  10716. t['encyrillic'] = 0x043D;
  10717. t['endash'] = 0x2013;
  10718. t['endashvertical'] = 0xFE32;
  10719. t['endescendercyrillic'] = 0x04A3;
  10720. t['eng'] = 0x014B;
  10721. t['engbopomofo'] = 0x3125;
  10722. t['enghecyrillic'] = 0x04A5;
  10723. t['enhookcyrillic'] = 0x04C8;
  10724. t['enspace'] = 0x2002;
  10725. t['eogonek'] = 0x0119;
  10726. t['eokorean'] = 0x3153;
  10727. t['eopen'] = 0x025B;
  10728. t['eopenclosed'] = 0x029A;
  10729. t['eopenreversed'] = 0x025C;
  10730. t['eopenreversedclosed'] = 0x025E;
  10731. t['eopenreversedhook'] = 0x025D;
  10732. t['eparen'] = 0x24A0;
  10733. t['epsilon'] = 0x03B5;
  10734. t['epsilontonos'] = 0x03AD;
  10735. t['equal'] = 0x003D;
  10736. t['equalmonospace'] = 0xFF1D;
  10737. t['equalsmall'] = 0xFE66;
  10738. t['equalsuperior'] = 0x207C;
  10739. t['equivalence'] = 0x2261;
  10740. t['erbopomofo'] = 0x3126;
  10741. t['ercyrillic'] = 0x0440;
  10742. t['ereversed'] = 0x0258;
  10743. t['ereversedcyrillic'] = 0x044D;
  10744. t['escyrillic'] = 0x0441;
  10745. t['esdescendercyrillic'] = 0x04AB;
  10746. t['esh'] = 0x0283;
  10747. t['eshcurl'] = 0x0286;
  10748. t['eshortdeva'] = 0x090E;
  10749. t['eshortvowelsigndeva'] = 0x0946;
  10750. t['eshreversedloop'] = 0x01AA;
  10751. t['eshsquatreversed'] = 0x0285;
  10752. t['esmallhiragana'] = 0x3047;
  10753. t['esmallkatakana'] = 0x30A7;
  10754. t['esmallkatakanahalfwidth'] = 0xFF6A;
  10755. t['estimated'] = 0x212E;
  10756. t['esuperior'] = 0xF6EC;
  10757. t['eta'] = 0x03B7;
  10758. t['etarmenian'] = 0x0568;
  10759. t['etatonos'] = 0x03AE;
  10760. t['eth'] = 0x00F0;
  10761. t['etilde'] = 0x1EBD;
  10762. t['etildebelow'] = 0x1E1B;
  10763. t['etnahtafoukhhebrew'] = 0x0591;
  10764. t['etnahtafoukhlefthebrew'] = 0x0591;
  10765. t['etnahtahebrew'] = 0x0591;
  10766. t['etnahtalefthebrew'] = 0x0591;
  10767. t['eturned'] = 0x01DD;
  10768. t['eukorean'] = 0x3161;
  10769. t['euro'] = 0x20AC;
  10770. t['evowelsignbengali'] = 0x09C7;
  10771. t['evowelsigndeva'] = 0x0947;
  10772. t['evowelsigngujarati'] = 0x0AC7;
  10773. t['exclam'] = 0x0021;
  10774. t['exclamarmenian'] = 0x055C;
  10775. t['exclamdbl'] = 0x203C;
  10776. t['exclamdown'] = 0x00A1;
  10777. t['exclamdownsmall'] = 0xF7A1;
  10778. t['exclammonospace'] = 0xFF01;
  10779. t['exclamsmall'] = 0xF721;
  10780. t['existential'] = 0x2203;
  10781. t['ezh'] = 0x0292;
  10782. t['ezhcaron'] = 0x01EF;
  10783. t['ezhcurl'] = 0x0293;
  10784. t['ezhreversed'] = 0x01B9;
  10785. t['ezhtail'] = 0x01BA;
  10786. t['f'] = 0x0066;
  10787. t['fadeva'] = 0x095E;
  10788. t['fagurmukhi'] = 0x0A5E;
  10789. t['fahrenheit'] = 0x2109;
  10790. t['fathaarabic'] = 0x064E;
  10791. t['fathalowarabic'] = 0x064E;
  10792. t['fathatanarabic'] = 0x064B;
  10793. t['fbopomofo'] = 0x3108;
  10794. t['fcircle'] = 0x24D5;
  10795. t['fdotaccent'] = 0x1E1F;
  10796. t['feharabic'] = 0x0641;
  10797. t['feharmenian'] = 0x0586;
  10798. t['fehfinalarabic'] = 0xFED2;
  10799. t['fehinitialarabic'] = 0xFED3;
  10800. t['fehmedialarabic'] = 0xFED4;
  10801. t['feicoptic'] = 0x03E5;
  10802. t['female'] = 0x2640;
  10803. t['ff'] = 0xFB00;
  10804. t['ffi'] = 0xFB03;
  10805. t['ffl'] = 0xFB04;
  10806. t['fi'] = 0xFB01;
  10807. t['fifteencircle'] = 0x246E;
  10808. t['fifteenparen'] = 0x2482;
  10809. t['fifteenperiod'] = 0x2496;
  10810. t['figuredash'] = 0x2012;
  10811. t['filledbox'] = 0x25A0;
  10812. t['filledrect'] = 0x25AC;
  10813. t['finalkaf'] = 0x05DA;
  10814. t['finalkafdagesh'] = 0xFB3A;
  10815. t['finalkafdageshhebrew'] = 0xFB3A;
  10816. t['finalkafhebrew'] = 0x05DA;
  10817. t['finalmem'] = 0x05DD;
  10818. t['finalmemhebrew'] = 0x05DD;
  10819. t['finalnun'] = 0x05DF;
  10820. t['finalnunhebrew'] = 0x05DF;
  10821. t['finalpe'] = 0x05E3;
  10822. t['finalpehebrew'] = 0x05E3;
  10823. t['finaltsadi'] = 0x05E5;
  10824. t['finaltsadihebrew'] = 0x05E5;
  10825. t['firsttonechinese'] = 0x02C9;
  10826. t['fisheye'] = 0x25C9;
  10827. t['fitacyrillic'] = 0x0473;
  10828. t['five'] = 0x0035;
  10829. t['fivearabic'] = 0x0665;
  10830. t['fivebengali'] = 0x09EB;
  10831. t['fivecircle'] = 0x2464;
  10832. t['fivecircleinversesansserif'] = 0x278E;
  10833. t['fivedeva'] = 0x096B;
  10834. t['fiveeighths'] = 0x215D;
  10835. t['fivegujarati'] = 0x0AEB;
  10836. t['fivegurmukhi'] = 0x0A6B;
  10837. t['fivehackarabic'] = 0x0665;
  10838. t['fivehangzhou'] = 0x3025;
  10839. t['fiveideographicparen'] = 0x3224;
  10840. t['fiveinferior'] = 0x2085;
  10841. t['fivemonospace'] = 0xFF15;
  10842. t['fiveoldstyle'] = 0xF735;
  10843. t['fiveparen'] = 0x2478;
  10844. t['fiveperiod'] = 0x248C;
  10845. t['fivepersian'] = 0x06F5;
  10846. t['fiveroman'] = 0x2174;
  10847. t['fivesuperior'] = 0x2075;
  10848. t['fivethai'] = 0x0E55;
  10849. t['fl'] = 0xFB02;
  10850. t['florin'] = 0x0192;
  10851. t['fmonospace'] = 0xFF46;
  10852. t['fmsquare'] = 0x3399;
  10853. t['fofanthai'] = 0x0E1F;
  10854. t['fofathai'] = 0x0E1D;
  10855. t['fongmanthai'] = 0x0E4F;
  10856. t['forall'] = 0x2200;
  10857. t['four'] = 0x0034;
  10858. t['fourarabic'] = 0x0664;
  10859. t['fourbengali'] = 0x09EA;
  10860. t['fourcircle'] = 0x2463;
  10861. t['fourcircleinversesansserif'] = 0x278D;
  10862. t['fourdeva'] = 0x096A;
  10863. t['fourgujarati'] = 0x0AEA;
  10864. t['fourgurmukhi'] = 0x0A6A;
  10865. t['fourhackarabic'] = 0x0664;
  10866. t['fourhangzhou'] = 0x3024;
  10867. t['fourideographicparen'] = 0x3223;
  10868. t['fourinferior'] = 0x2084;
  10869. t['fourmonospace'] = 0xFF14;
  10870. t['fournumeratorbengali'] = 0x09F7;
  10871. t['fouroldstyle'] = 0xF734;
  10872. t['fourparen'] = 0x2477;
  10873. t['fourperiod'] = 0x248B;
  10874. t['fourpersian'] = 0x06F4;
  10875. t['fourroman'] = 0x2173;
  10876. t['foursuperior'] = 0x2074;
  10877. t['fourteencircle'] = 0x246D;
  10878. t['fourteenparen'] = 0x2481;
  10879. t['fourteenperiod'] = 0x2495;
  10880. t['fourthai'] = 0x0E54;
  10881. t['fourthtonechinese'] = 0x02CB;
  10882. t['fparen'] = 0x24A1;
  10883. t['fraction'] = 0x2044;
  10884. t['franc'] = 0x20A3;
  10885. t['g'] = 0x0067;
  10886. t['gabengali'] = 0x0997;
  10887. t['gacute'] = 0x01F5;
  10888. t['gadeva'] = 0x0917;
  10889. t['gafarabic'] = 0x06AF;
  10890. t['gaffinalarabic'] = 0xFB93;
  10891. t['gafinitialarabic'] = 0xFB94;
  10892. t['gafmedialarabic'] = 0xFB95;
  10893. t['gagujarati'] = 0x0A97;
  10894. t['gagurmukhi'] = 0x0A17;
  10895. t['gahiragana'] = 0x304C;
  10896. t['gakatakana'] = 0x30AC;
  10897. t['gamma'] = 0x03B3;
  10898. t['gammalatinsmall'] = 0x0263;
  10899. t['gammasuperior'] = 0x02E0;
  10900. t['gangiacoptic'] = 0x03EB;
  10901. t['gbopomofo'] = 0x310D;
  10902. t['gbreve'] = 0x011F;
  10903. t['gcaron'] = 0x01E7;
  10904. t['gcedilla'] = 0x0123;
  10905. t['gcircle'] = 0x24D6;
  10906. t['gcircumflex'] = 0x011D;
  10907. t['gcommaaccent'] = 0x0123;
  10908. t['gdot'] = 0x0121;
  10909. t['gdotaccent'] = 0x0121;
  10910. t['gecyrillic'] = 0x0433;
  10911. t['gehiragana'] = 0x3052;
  10912. t['gekatakana'] = 0x30B2;
  10913. t['geometricallyequal'] = 0x2251;
  10914. t['gereshaccenthebrew'] = 0x059C;
  10915. t['gereshhebrew'] = 0x05F3;
  10916. t['gereshmuqdamhebrew'] = 0x059D;
  10917. t['germandbls'] = 0x00DF;
  10918. t['gershayimaccenthebrew'] = 0x059E;
  10919. t['gershayimhebrew'] = 0x05F4;
  10920. t['getamark'] = 0x3013;
  10921. t['ghabengali'] = 0x0998;
  10922. t['ghadarmenian'] = 0x0572;
  10923. t['ghadeva'] = 0x0918;
  10924. t['ghagujarati'] = 0x0A98;
  10925. t['ghagurmukhi'] = 0x0A18;
  10926. t['ghainarabic'] = 0x063A;
  10927. t['ghainfinalarabic'] = 0xFECE;
  10928. t['ghaininitialarabic'] = 0xFECF;
  10929. t['ghainmedialarabic'] = 0xFED0;
  10930. t['ghemiddlehookcyrillic'] = 0x0495;
  10931. t['ghestrokecyrillic'] = 0x0493;
  10932. t['gheupturncyrillic'] = 0x0491;
  10933. t['ghhadeva'] = 0x095A;
  10934. t['ghhagurmukhi'] = 0x0A5A;
  10935. t['ghook'] = 0x0260;
  10936. t['ghzsquare'] = 0x3393;
  10937. t['gihiragana'] = 0x304E;
  10938. t['gikatakana'] = 0x30AE;
  10939. t['gimarmenian'] = 0x0563;
  10940. t['gimel'] = 0x05D2;
  10941. t['gimeldagesh'] = 0xFB32;
  10942. t['gimeldageshhebrew'] = 0xFB32;
  10943. t['gimelhebrew'] = 0x05D2;
  10944. t['gjecyrillic'] = 0x0453;
  10945. t['glottalinvertedstroke'] = 0x01BE;
  10946. t['glottalstop'] = 0x0294;
  10947. t['glottalstopinverted'] = 0x0296;
  10948. t['glottalstopmod'] = 0x02C0;
  10949. t['glottalstopreversed'] = 0x0295;
  10950. t['glottalstopreversedmod'] = 0x02C1;
  10951. t['glottalstopreversedsuperior'] = 0x02E4;
  10952. t['glottalstopstroke'] = 0x02A1;
  10953. t['glottalstopstrokereversed'] = 0x02A2;
  10954. t['gmacron'] = 0x1E21;
  10955. t['gmonospace'] = 0xFF47;
  10956. t['gohiragana'] = 0x3054;
  10957. t['gokatakana'] = 0x30B4;
  10958. t['gparen'] = 0x24A2;
  10959. t['gpasquare'] = 0x33AC;
  10960. t['gradient'] = 0x2207;
  10961. t['grave'] = 0x0060;
  10962. t['gravebelowcmb'] = 0x0316;
  10963. t['gravecmb'] = 0x0300;
  10964. t['gravecomb'] = 0x0300;
  10965. t['gravedeva'] = 0x0953;
  10966. t['gravelowmod'] = 0x02CE;
  10967. t['gravemonospace'] = 0xFF40;
  10968. t['gravetonecmb'] = 0x0340;
  10969. t['greater'] = 0x003E;
  10970. t['greaterequal'] = 0x2265;
  10971. t['greaterequalorless'] = 0x22DB;
  10972. t['greatermonospace'] = 0xFF1E;
  10973. t['greaterorequivalent'] = 0x2273;
  10974. t['greaterorless'] = 0x2277;
  10975. t['greateroverequal'] = 0x2267;
  10976. t['greatersmall'] = 0xFE65;
  10977. t['gscript'] = 0x0261;
  10978. t['gstroke'] = 0x01E5;
  10979. t['guhiragana'] = 0x3050;
  10980. t['guillemotleft'] = 0x00AB;
  10981. t['guillemotright'] = 0x00BB;
  10982. t['guilsinglleft'] = 0x2039;
  10983. t['guilsinglright'] = 0x203A;
  10984. t['gukatakana'] = 0x30B0;
  10985. t['guramusquare'] = 0x3318;
  10986. t['gysquare'] = 0x33C9;
  10987. t['h'] = 0x0068;
  10988. t['haabkhasiancyrillic'] = 0x04A9;
  10989. t['haaltonearabic'] = 0x06C1;
  10990. t['habengali'] = 0x09B9;
  10991. t['hadescendercyrillic'] = 0x04B3;
  10992. t['hadeva'] = 0x0939;
  10993. t['hagujarati'] = 0x0AB9;
  10994. t['hagurmukhi'] = 0x0A39;
  10995. t['haharabic'] = 0x062D;
  10996. t['hahfinalarabic'] = 0xFEA2;
  10997. t['hahinitialarabic'] = 0xFEA3;
  10998. t['hahiragana'] = 0x306F;
  10999. t['hahmedialarabic'] = 0xFEA4;
  11000. t['haitusquare'] = 0x332A;
  11001. t['hakatakana'] = 0x30CF;
  11002. t['hakatakanahalfwidth'] = 0xFF8A;
  11003. t['halantgurmukhi'] = 0x0A4D;
  11004. t['hamzaarabic'] = 0x0621;
  11005. t['hamzalowarabic'] = 0x0621;
  11006. t['hangulfiller'] = 0x3164;
  11007. t['hardsigncyrillic'] = 0x044A;
  11008. t['harpoonleftbarbup'] = 0x21BC;
  11009. t['harpoonrightbarbup'] = 0x21C0;
  11010. t['hasquare'] = 0x33CA;
  11011. t['hatafpatah'] = 0x05B2;
  11012. t['hatafpatah16'] = 0x05B2;
  11013. t['hatafpatah23'] = 0x05B2;
  11014. t['hatafpatah2f'] = 0x05B2;
  11015. t['hatafpatahhebrew'] = 0x05B2;
  11016. t['hatafpatahnarrowhebrew'] = 0x05B2;
  11017. t['hatafpatahquarterhebrew'] = 0x05B2;
  11018. t['hatafpatahwidehebrew'] = 0x05B2;
  11019. t['hatafqamats'] = 0x05B3;
  11020. t['hatafqamats1b'] = 0x05B3;
  11021. t['hatafqamats28'] = 0x05B3;
  11022. t['hatafqamats34'] = 0x05B3;
  11023. t['hatafqamatshebrew'] = 0x05B3;
  11024. t['hatafqamatsnarrowhebrew'] = 0x05B3;
  11025. t['hatafqamatsquarterhebrew'] = 0x05B3;
  11026. t['hatafqamatswidehebrew'] = 0x05B3;
  11027. t['hatafsegol'] = 0x05B1;
  11028. t['hatafsegol17'] = 0x05B1;
  11029. t['hatafsegol24'] = 0x05B1;
  11030. t['hatafsegol30'] = 0x05B1;
  11031. t['hatafsegolhebrew'] = 0x05B1;
  11032. t['hatafsegolnarrowhebrew'] = 0x05B1;
  11033. t['hatafsegolquarterhebrew'] = 0x05B1;
  11034. t['hatafsegolwidehebrew'] = 0x05B1;
  11035. t['hbar'] = 0x0127;
  11036. t['hbopomofo'] = 0x310F;
  11037. t['hbrevebelow'] = 0x1E2B;
  11038. t['hcedilla'] = 0x1E29;
  11039. t['hcircle'] = 0x24D7;
  11040. t['hcircumflex'] = 0x0125;
  11041. t['hdieresis'] = 0x1E27;
  11042. t['hdotaccent'] = 0x1E23;
  11043. t['hdotbelow'] = 0x1E25;
  11044. t['he'] = 0x05D4;
  11045. t['heart'] = 0x2665;
  11046. t['heartsuitblack'] = 0x2665;
  11047. t['heartsuitwhite'] = 0x2661;
  11048. t['hedagesh'] = 0xFB34;
  11049. t['hedageshhebrew'] = 0xFB34;
  11050. t['hehaltonearabic'] = 0x06C1;
  11051. t['heharabic'] = 0x0647;
  11052. t['hehebrew'] = 0x05D4;
  11053. t['hehfinalaltonearabic'] = 0xFBA7;
  11054. t['hehfinalalttwoarabic'] = 0xFEEA;
  11055. t['hehfinalarabic'] = 0xFEEA;
  11056. t['hehhamzaabovefinalarabic'] = 0xFBA5;
  11057. t['hehhamzaaboveisolatedarabic'] = 0xFBA4;
  11058. t['hehinitialaltonearabic'] = 0xFBA8;
  11059. t['hehinitialarabic'] = 0xFEEB;
  11060. t['hehiragana'] = 0x3078;
  11061. t['hehmedialaltonearabic'] = 0xFBA9;
  11062. t['hehmedialarabic'] = 0xFEEC;
  11063. t['heiseierasquare'] = 0x337B;
  11064. t['hekatakana'] = 0x30D8;
  11065. t['hekatakanahalfwidth'] = 0xFF8D;
  11066. t['hekutaarusquare'] = 0x3336;
  11067. t['henghook'] = 0x0267;
  11068. t['herutusquare'] = 0x3339;
  11069. t['het'] = 0x05D7;
  11070. t['hethebrew'] = 0x05D7;
  11071. t['hhook'] = 0x0266;
  11072. t['hhooksuperior'] = 0x02B1;
  11073. t['hieuhacirclekorean'] = 0x327B;
  11074. t['hieuhaparenkorean'] = 0x321B;
  11075. t['hieuhcirclekorean'] = 0x326D;
  11076. t['hieuhkorean'] = 0x314E;
  11077. t['hieuhparenkorean'] = 0x320D;
  11078. t['hihiragana'] = 0x3072;
  11079. t['hikatakana'] = 0x30D2;
  11080. t['hikatakanahalfwidth'] = 0xFF8B;
  11081. t['hiriq'] = 0x05B4;
  11082. t['hiriq14'] = 0x05B4;
  11083. t['hiriq21'] = 0x05B4;
  11084. t['hiriq2d'] = 0x05B4;
  11085. t['hiriqhebrew'] = 0x05B4;
  11086. t['hiriqnarrowhebrew'] = 0x05B4;
  11087. t['hiriqquarterhebrew'] = 0x05B4;
  11088. t['hiriqwidehebrew'] = 0x05B4;
  11089. t['hlinebelow'] = 0x1E96;
  11090. t['hmonospace'] = 0xFF48;
  11091. t['hoarmenian'] = 0x0570;
  11092. t['hohipthai'] = 0x0E2B;
  11093. t['hohiragana'] = 0x307B;
  11094. t['hokatakana'] = 0x30DB;
  11095. t['hokatakanahalfwidth'] = 0xFF8E;
  11096. t['holam'] = 0x05B9;
  11097. t['holam19'] = 0x05B9;
  11098. t['holam26'] = 0x05B9;
  11099. t['holam32'] = 0x05B9;
  11100. t['holamhebrew'] = 0x05B9;
  11101. t['holamnarrowhebrew'] = 0x05B9;
  11102. t['holamquarterhebrew'] = 0x05B9;
  11103. t['holamwidehebrew'] = 0x05B9;
  11104. t['honokhukthai'] = 0x0E2E;
  11105. t['hookabovecomb'] = 0x0309;
  11106. t['hookcmb'] = 0x0309;
  11107. t['hookpalatalizedbelowcmb'] = 0x0321;
  11108. t['hookretroflexbelowcmb'] = 0x0322;
  11109. t['hoonsquare'] = 0x3342;
  11110. t['horicoptic'] = 0x03E9;
  11111. t['horizontalbar'] = 0x2015;
  11112. t['horncmb'] = 0x031B;
  11113. t['hotsprings'] = 0x2668;
  11114. t['house'] = 0x2302;
  11115. t['hparen'] = 0x24A3;
  11116. t['hsuperior'] = 0x02B0;
  11117. t['hturned'] = 0x0265;
  11118. t['huhiragana'] = 0x3075;
  11119. t['huiitosquare'] = 0x3333;
  11120. t['hukatakana'] = 0x30D5;
  11121. t['hukatakanahalfwidth'] = 0xFF8C;
  11122. t['hungarumlaut'] = 0x02DD;
  11123. t['hungarumlautcmb'] = 0x030B;
  11124. t['hv'] = 0x0195;
  11125. t['hyphen'] = 0x002D;
  11126. t['hypheninferior'] = 0xF6E5;
  11127. t['hyphenmonospace'] = 0xFF0D;
  11128. t['hyphensmall'] = 0xFE63;
  11129. t['hyphensuperior'] = 0xF6E6;
  11130. t['hyphentwo'] = 0x2010;
  11131. t['i'] = 0x0069;
  11132. t['iacute'] = 0x00ED;
  11133. t['iacyrillic'] = 0x044F;
  11134. t['ibengali'] = 0x0987;
  11135. t['ibopomofo'] = 0x3127;
  11136. t['ibreve'] = 0x012D;
  11137. t['icaron'] = 0x01D0;
  11138. t['icircle'] = 0x24D8;
  11139. t['icircumflex'] = 0x00EE;
  11140. t['icyrillic'] = 0x0456;
  11141. t['idblgrave'] = 0x0209;
  11142. t['ideographearthcircle'] = 0x328F;
  11143. t['ideographfirecircle'] = 0x328B;
  11144. t['ideographicallianceparen'] = 0x323F;
  11145. t['ideographiccallparen'] = 0x323A;
  11146. t['ideographiccentrecircle'] = 0x32A5;
  11147. t['ideographicclose'] = 0x3006;
  11148. t['ideographiccomma'] = 0x3001;
  11149. t['ideographiccommaleft'] = 0xFF64;
  11150. t['ideographiccongratulationparen'] = 0x3237;
  11151. t['ideographiccorrectcircle'] = 0x32A3;
  11152. t['ideographicearthparen'] = 0x322F;
  11153. t['ideographicenterpriseparen'] = 0x323D;
  11154. t['ideographicexcellentcircle'] = 0x329D;
  11155. t['ideographicfestivalparen'] = 0x3240;
  11156. t['ideographicfinancialcircle'] = 0x3296;
  11157. t['ideographicfinancialparen'] = 0x3236;
  11158. t['ideographicfireparen'] = 0x322B;
  11159. t['ideographichaveparen'] = 0x3232;
  11160. t['ideographichighcircle'] = 0x32A4;
  11161. t['ideographiciterationmark'] = 0x3005;
  11162. t['ideographiclaborcircle'] = 0x3298;
  11163. t['ideographiclaborparen'] = 0x3238;
  11164. t['ideographicleftcircle'] = 0x32A7;
  11165. t['ideographiclowcircle'] = 0x32A6;
  11166. t['ideographicmedicinecircle'] = 0x32A9;
  11167. t['ideographicmetalparen'] = 0x322E;
  11168. t['ideographicmoonparen'] = 0x322A;
  11169. t['ideographicnameparen'] = 0x3234;
  11170. t['ideographicperiod'] = 0x3002;
  11171. t['ideographicprintcircle'] = 0x329E;
  11172. t['ideographicreachparen'] = 0x3243;
  11173. t['ideographicrepresentparen'] = 0x3239;
  11174. t['ideographicresourceparen'] = 0x323E;
  11175. t['ideographicrightcircle'] = 0x32A8;
  11176. t['ideographicsecretcircle'] = 0x3299;
  11177. t['ideographicselfparen'] = 0x3242;
  11178. t['ideographicsocietyparen'] = 0x3233;
  11179. t['ideographicspace'] = 0x3000;
  11180. t['ideographicspecialparen'] = 0x3235;
  11181. t['ideographicstockparen'] = 0x3231;
  11182. t['ideographicstudyparen'] = 0x323B;
  11183. t['ideographicsunparen'] = 0x3230;
  11184. t['ideographicsuperviseparen'] = 0x323C;
  11185. t['ideographicwaterparen'] = 0x322C;
  11186. t['ideographicwoodparen'] = 0x322D;
  11187. t['ideographiczero'] = 0x3007;
  11188. t['ideographmetalcircle'] = 0x328E;
  11189. t['ideographmooncircle'] = 0x328A;
  11190. t['ideographnamecircle'] = 0x3294;
  11191. t['ideographsuncircle'] = 0x3290;
  11192. t['ideographwatercircle'] = 0x328C;
  11193. t['ideographwoodcircle'] = 0x328D;
  11194. t['ideva'] = 0x0907;
  11195. t['idieresis'] = 0x00EF;
  11196. t['idieresisacute'] = 0x1E2F;
  11197. t['idieresiscyrillic'] = 0x04E5;
  11198. t['idotbelow'] = 0x1ECB;
  11199. t['iebrevecyrillic'] = 0x04D7;
  11200. t['iecyrillic'] = 0x0435;
  11201. t['ieungacirclekorean'] = 0x3275;
  11202. t['ieungaparenkorean'] = 0x3215;
  11203. t['ieungcirclekorean'] = 0x3267;
  11204. t['ieungkorean'] = 0x3147;
  11205. t['ieungparenkorean'] = 0x3207;
  11206. t['igrave'] = 0x00EC;
  11207. t['igujarati'] = 0x0A87;
  11208. t['igurmukhi'] = 0x0A07;
  11209. t['ihiragana'] = 0x3044;
  11210. t['ihookabove'] = 0x1EC9;
  11211. t['iibengali'] = 0x0988;
  11212. t['iicyrillic'] = 0x0438;
  11213. t['iideva'] = 0x0908;
  11214. t['iigujarati'] = 0x0A88;
  11215. t['iigurmukhi'] = 0x0A08;
  11216. t['iimatragurmukhi'] = 0x0A40;
  11217. t['iinvertedbreve'] = 0x020B;
  11218. t['iishortcyrillic'] = 0x0439;
  11219. t['iivowelsignbengali'] = 0x09C0;
  11220. t['iivowelsigndeva'] = 0x0940;
  11221. t['iivowelsigngujarati'] = 0x0AC0;
  11222. t['ij'] = 0x0133;
  11223. t['ikatakana'] = 0x30A4;
  11224. t['ikatakanahalfwidth'] = 0xFF72;
  11225. t['ikorean'] = 0x3163;
  11226. t['ilde'] = 0x02DC;
  11227. t['iluyhebrew'] = 0x05AC;
  11228. t['imacron'] = 0x012B;
  11229. t['imacroncyrillic'] = 0x04E3;
  11230. t['imageorapproximatelyequal'] = 0x2253;
  11231. t['imatragurmukhi'] = 0x0A3F;
  11232. t['imonospace'] = 0xFF49;
  11233. t['increment'] = 0x2206;
  11234. t['infinity'] = 0x221E;
  11235. t['iniarmenian'] = 0x056B;
  11236. t['integral'] = 0x222B;
  11237. t['integralbottom'] = 0x2321;
  11238. t['integralbt'] = 0x2321;
  11239. t['integralex'] = 0xF8F5;
  11240. t['integraltop'] = 0x2320;
  11241. t['integraltp'] = 0x2320;
  11242. t['intersection'] = 0x2229;
  11243. t['intisquare'] = 0x3305;
  11244. t['invbullet'] = 0x25D8;
  11245. t['invcircle'] = 0x25D9;
  11246. t['invsmileface'] = 0x263B;
  11247. t['iocyrillic'] = 0x0451;
  11248. t['iogonek'] = 0x012F;
  11249. t['iota'] = 0x03B9;
  11250. t['iotadieresis'] = 0x03CA;
  11251. t['iotadieresistonos'] = 0x0390;
  11252. t['iotalatin'] = 0x0269;
  11253. t['iotatonos'] = 0x03AF;
  11254. t['iparen'] = 0x24A4;
  11255. t['irigurmukhi'] = 0x0A72;
  11256. t['ismallhiragana'] = 0x3043;
  11257. t['ismallkatakana'] = 0x30A3;
  11258. t['ismallkatakanahalfwidth'] = 0xFF68;
  11259. t['issharbengali'] = 0x09FA;
  11260. t['istroke'] = 0x0268;
  11261. t['isuperior'] = 0xF6ED;
  11262. t['iterationhiragana'] = 0x309D;
  11263. t['iterationkatakana'] = 0x30FD;
  11264. t['itilde'] = 0x0129;
  11265. t['itildebelow'] = 0x1E2D;
  11266. t['iubopomofo'] = 0x3129;
  11267. t['iucyrillic'] = 0x044E;
  11268. t['ivowelsignbengali'] = 0x09BF;
  11269. t['ivowelsigndeva'] = 0x093F;
  11270. t['ivowelsigngujarati'] = 0x0ABF;
  11271. t['izhitsacyrillic'] = 0x0475;
  11272. t['izhitsadblgravecyrillic'] = 0x0477;
  11273. t['j'] = 0x006A;
  11274. t['jaarmenian'] = 0x0571;
  11275. t['jabengali'] = 0x099C;
  11276. t['jadeva'] = 0x091C;
  11277. t['jagujarati'] = 0x0A9C;
  11278. t['jagurmukhi'] = 0x0A1C;
  11279. t['jbopomofo'] = 0x3110;
  11280. t['jcaron'] = 0x01F0;
  11281. t['jcircle'] = 0x24D9;
  11282. t['jcircumflex'] = 0x0135;
  11283. t['jcrossedtail'] = 0x029D;
  11284. t['jdotlessstroke'] = 0x025F;
  11285. t['jecyrillic'] = 0x0458;
  11286. t['jeemarabic'] = 0x062C;
  11287. t['jeemfinalarabic'] = 0xFE9E;
  11288. t['jeeminitialarabic'] = 0xFE9F;
  11289. t['jeemmedialarabic'] = 0xFEA0;
  11290. t['jeharabic'] = 0x0698;
  11291. t['jehfinalarabic'] = 0xFB8B;
  11292. t['jhabengali'] = 0x099D;
  11293. t['jhadeva'] = 0x091D;
  11294. t['jhagujarati'] = 0x0A9D;
  11295. t['jhagurmukhi'] = 0x0A1D;
  11296. t['jheharmenian'] = 0x057B;
  11297. t['jis'] = 0x3004;
  11298. t['jmonospace'] = 0xFF4A;
  11299. t['jparen'] = 0x24A5;
  11300. t['jsuperior'] = 0x02B2;
  11301. t['k'] = 0x006B;
  11302. t['kabashkircyrillic'] = 0x04A1;
  11303. t['kabengali'] = 0x0995;
  11304. t['kacute'] = 0x1E31;
  11305. t['kacyrillic'] = 0x043A;
  11306. t['kadescendercyrillic'] = 0x049B;
  11307. t['kadeva'] = 0x0915;
  11308. t['kaf'] = 0x05DB;
  11309. t['kafarabic'] = 0x0643;
  11310. t['kafdagesh'] = 0xFB3B;
  11311. t['kafdageshhebrew'] = 0xFB3B;
  11312. t['kaffinalarabic'] = 0xFEDA;
  11313. t['kafhebrew'] = 0x05DB;
  11314. t['kafinitialarabic'] = 0xFEDB;
  11315. t['kafmedialarabic'] = 0xFEDC;
  11316. t['kafrafehebrew'] = 0xFB4D;
  11317. t['kagujarati'] = 0x0A95;
  11318. t['kagurmukhi'] = 0x0A15;
  11319. t['kahiragana'] = 0x304B;
  11320. t['kahookcyrillic'] = 0x04C4;
  11321. t['kakatakana'] = 0x30AB;
  11322. t['kakatakanahalfwidth'] = 0xFF76;
  11323. t['kappa'] = 0x03BA;
  11324. t['kappasymbolgreek'] = 0x03F0;
  11325. t['kapyeounmieumkorean'] = 0x3171;
  11326. t['kapyeounphieuphkorean'] = 0x3184;
  11327. t['kapyeounpieupkorean'] = 0x3178;
  11328. t['kapyeounssangpieupkorean'] = 0x3179;
  11329. t['karoriisquare'] = 0x330D;
  11330. t['kashidaautoarabic'] = 0x0640;
  11331. t['kashidaautonosidebearingarabic'] = 0x0640;
  11332. t['kasmallkatakana'] = 0x30F5;
  11333. t['kasquare'] = 0x3384;
  11334. t['kasraarabic'] = 0x0650;
  11335. t['kasratanarabic'] = 0x064D;
  11336. t['kastrokecyrillic'] = 0x049F;
  11337. t['katahiraprolongmarkhalfwidth'] = 0xFF70;
  11338. t['kaverticalstrokecyrillic'] = 0x049D;
  11339. t['kbopomofo'] = 0x310E;
  11340. t['kcalsquare'] = 0x3389;
  11341. t['kcaron'] = 0x01E9;
  11342. t['kcedilla'] = 0x0137;
  11343. t['kcircle'] = 0x24DA;
  11344. t['kcommaaccent'] = 0x0137;
  11345. t['kdotbelow'] = 0x1E33;
  11346. t['keharmenian'] = 0x0584;
  11347. t['kehiragana'] = 0x3051;
  11348. t['kekatakana'] = 0x30B1;
  11349. t['kekatakanahalfwidth'] = 0xFF79;
  11350. t['kenarmenian'] = 0x056F;
  11351. t['kesmallkatakana'] = 0x30F6;
  11352. t['kgreenlandic'] = 0x0138;
  11353. t['khabengali'] = 0x0996;
  11354. t['khacyrillic'] = 0x0445;
  11355. t['khadeva'] = 0x0916;
  11356. t['khagujarati'] = 0x0A96;
  11357. t['khagurmukhi'] = 0x0A16;
  11358. t['khaharabic'] = 0x062E;
  11359. t['khahfinalarabic'] = 0xFEA6;
  11360. t['khahinitialarabic'] = 0xFEA7;
  11361. t['khahmedialarabic'] = 0xFEA8;
  11362. t['kheicoptic'] = 0x03E7;
  11363. t['khhadeva'] = 0x0959;
  11364. t['khhagurmukhi'] = 0x0A59;
  11365. t['khieukhacirclekorean'] = 0x3278;
  11366. t['khieukhaparenkorean'] = 0x3218;
  11367. t['khieukhcirclekorean'] = 0x326A;
  11368. t['khieukhkorean'] = 0x314B;
  11369. t['khieukhparenkorean'] = 0x320A;
  11370. t['khokhaithai'] = 0x0E02;
  11371. t['khokhonthai'] = 0x0E05;
  11372. t['khokhuatthai'] = 0x0E03;
  11373. t['khokhwaithai'] = 0x0E04;
  11374. t['khomutthai'] = 0x0E5B;
  11375. t['khook'] = 0x0199;
  11376. t['khorakhangthai'] = 0x0E06;
  11377. t['khzsquare'] = 0x3391;
  11378. t['kihiragana'] = 0x304D;
  11379. t['kikatakana'] = 0x30AD;
  11380. t['kikatakanahalfwidth'] = 0xFF77;
  11381. t['kiroguramusquare'] = 0x3315;
  11382. t['kiromeetorusquare'] = 0x3316;
  11383. t['kirosquare'] = 0x3314;
  11384. t['kiyeokacirclekorean'] = 0x326E;
  11385. t['kiyeokaparenkorean'] = 0x320E;
  11386. t['kiyeokcirclekorean'] = 0x3260;
  11387. t['kiyeokkorean'] = 0x3131;
  11388. t['kiyeokparenkorean'] = 0x3200;
  11389. t['kiyeoksioskorean'] = 0x3133;
  11390. t['kjecyrillic'] = 0x045C;
  11391. t['klinebelow'] = 0x1E35;
  11392. t['klsquare'] = 0x3398;
  11393. t['kmcubedsquare'] = 0x33A6;
  11394. t['kmonospace'] = 0xFF4B;
  11395. t['kmsquaredsquare'] = 0x33A2;
  11396. t['kohiragana'] = 0x3053;
  11397. t['kohmsquare'] = 0x33C0;
  11398. t['kokaithai'] = 0x0E01;
  11399. t['kokatakana'] = 0x30B3;
  11400. t['kokatakanahalfwidth'] = 0xFF7A;
  11401. t['kooposquare'] = 0x331E;
  11402. t['koppacyrillic'] = 0x0481;
  11403. t['koreanstandardsymbol'] = 0x327F;
  11404. t['koroniscmb'] = 0x0343;
  11405. t['kparen'] = 0x24A6;
  11406. t['kpasquare'] = 0x33AA;
  11407. t['ksicyrillic'] = 0x046F;
  11408. t['ktsquare'] = 0x33CF;
  11409. t['kturned'] = 0x029E;
  11410. t['kuhiragana'] = 0x304F;
  11411. t['kukatakana'] = 0x30AF;
  11412. t['kukatakanahalfwidth'] = 0xFF78;
  11413. t['kvsquare'] = 0x33B8;
  11414. t['kwsquare'] = 0x33BE;
  11415. t['l'] = 0x006C;
  11416. t['labengali'] = 0x09B2;
  11417. t['lacute'] = 0x013A;
  11418. t['ladeva'] = 0x0932;
  11419. t['lagujarati'] = 0x0AB2;
  11420. t['lagurmukhi'] = 0x0A32;
  11421. t['lakkhangyaothai'] = 0x0E45;
  11422. t['lamaleffinalarabic'] = 0xFEFC;
  11423. t['lamalefhamzaabovefinalarabic'] = 0xFEF8;
  11424. t['lamalefhamzaaboveisolatedarabic'] = 0xFEF7;
  11425. t['lamalefhamzabelowfinalarabic'] = 0xFEFA;
  11426. t['lamalefhamzabelowisolatedarabic'] = 0xFEF9;
  11427. t['lamalefisolatedarabic'] = 0xFEFB;
  11428. t['lamalefmaddaabovefinalarabic'] = 0xFEF6;
  11429. t['lamalefmaddaaboveisolatedarabic'] = 0xFEF5;
  11430. t['lamarabic'] = 0x0644;
  11431. t['lambda'] = 0x03BB;
  11432. t['lambdastroke'] = 0x019B;
  11433. t['lamed'] = 0x05DC;
  11434. t['lameddagesh'] = 0xFB3C;
  11435. t['lameddageshhebrew'] = 0xFB3C;
  11436. t['lamedhebrew'] = 0x05DC;
  11437. t['lamfinalarabic'] = 0xFEDE;
  11438. t['lamhahinitialarabic'] = 0xFCCA;
  11439. t['laminitialarabic'] = 0xFEDF;
  11440. t['lamjeeminitialarabic'] = 0xFCC9;
  11441. t['lamkhahinitialarabic'] = 0xFCCB;
  11442. t['lamlamhehisolatedarabic'] = 0xFDF2;
  11443. t['lammedialarabic'] = 0xFEE0;
  11444. t['lammeemhahinitialarabic'] = 0xFD88;
  11445. t['lammeeminitialarabic'] = 0xFCCC;
  11446. t['largecircle'] = 0x25EF;
  11447. t['lbar'] = 0x019A;
  11448. t['lbelt'] = 0x026C;
  11449. t['lbopomofo'] = 0x310C;
  11450. t['lcaron'] = 0x013E;
  11451. t['lcedilla'] = 0x013C;
  11452. t['lcircle'] = 0x24DB;
  11453. t['lcircumflexbelow'] = 0x1E3D;
  11454. t['lcommaaccent'] = 0x013C;
  11455. t['ldot'] = 0x0140;
  11456. t['ldotaccent'] = 0x0140;
  11457. t['ldotbelow'] = 0x1E37;
  11458. t['ldotbelowmacron'] = 0x1E39;
  11459. t['leftangleabovecmb'] = 0x031A;
  11460. t['lefttackbelowcmb'] = 0x0318;
  11461. t['less'] = 0x003C;
  11462. t['lessequal'] = 0x2264;
  11463. t['lessequalorgreater'] = 0x22DA;
  11464. t['lessmonospace'] = 0xFF1C;
  11465. t['lessorequivalent'] = 0x2272;
  11466. t['lessorgreater'] = 0x2276;
  11467. t['lessoverequal'] = 0x2266;
  11468. t['lesssmall'] = 0xFE64;
  11469. t['lezh'] = 0x026E;
  11470. t['lfblock'] = 0x258C;
  11471. t['lhookretroflex'] = 0x026D;
  11472. t['lira'] = 0x20A4;
  11473. t['liwnarmenian'] = 0x056C;
  11474. t['lj'] = 0x01C9;
  11475. t['ljecyrillic'] = 0x0459;
  11476. t['ll'] = 0xF6C0;
  11477. t['lladeva'] = 0x0933;
  11478. t['llagujarati'] = 0x0AB3;
  11479. t['llinebelow'] = 0x1E3B;
  11480. t['llladeva'] = 0x0934;
  11481. t['llvocalicbengali'] = 0x09E1;
  11482. t['llvocalicdeva'] = 0x0961;
  11483. t['llvocalicvowelsignbengali'] = 0x09E3;
  11484. t['llvocalicvowelsigndeva'] = 0x0963;
  11485. t['lmiddletilde'] = 0x026B;
  11486. t['lmonospace'] = 0xFF4C;
  11487. t['lmsquare'] = 0x33D0;
  11488. t['lochulathai'] = 0x0E2C;
  11489. t['logicaland'] = 0x2227;
  11490. t['logicalnot'] = 0x00AC;
  11491. t['logicalnotreversed'] = 0x2310;
  11492. t['logicalor'] = 0x2228;
  11493. t['lolingthai'] = 0x0E25;
  11494. t['longs'] = 0x017F;
  11495. t['lowlinecenterline'] = 0xFE4E;
  11496. t['lowlinecmb'] = 0x0332;
  11497. t['lowlinedashed'] = 0xFE4D;
  11498. t['lozenge'] = 0x25CA;
  11499. t['lparen'] = 0x24A7;
  11500. t['lslash'] = 0x0142;
  11501. t['lsquare'] = 0x2113;
  11502. t['lsuperior'] = 0xF6EE;
  11503. t['ltshade'] = 0x2591;
  11504. t['luthai'] = 0x0E26;
  11505. t['lvocalicbengali'] = 0x098C;
  11506. t['lvocalicdeva'] = 0x090C;
  11507. t['lvocalicvowelsignbengali'] = 0x09E2;
  11508. t['lvocalicvowelsigndeva'] = 0x0962;
  11509. t['lxsquare'] = 0x33D3;
  11510. t['m'] = 0x006D;
  11511. t['mabengali'] = 0x09AE;
  11512. t['macron'] = 0x00AF;
  11513. t['macronbelowcmb'] = 0x0331;
  11514. t['macroncmb'] = 0x0304;
  11515. t['macronlowmod'] = 0x02CD;
  11516. t['macronmonospace'] = 0xFFE3;
  11517. t['macute'] = 0x1E3F;
  11518. t['madeva'] = 0x092E;
  11519. t['magujarati'] = 0x0AAE;
  11520. t['magurmukhi'] = 0x0A2E;
  11521. t['mahapakhhebrew'] = 0x05A4;
  11522. t['mahapakhlefthebrew'] = 0x05A4;
  11523. t['mahiragana'] = 0x307E;
  11524. t['maichattawalowleftthai'] = 0xF895;
  11525. t['maichattawalowrightthai'] = 0xF894;
  11526. t['maichattawathai'] = 0x0E4B;
  11527. t['maichattawaupperleftthai'] = 0xF893;
  11528. t['maieklowleftthai'] = 0xF88C;
  11529. t['maieklowrightthai'] = 0xF88B;
  11530. t['maiekthai'] = 0x0E48;
  11531. t['maiekupperleftthai'] = 0xF88A;
  11532. t['maihanakatleftthai'] = 0xF884;
  11533. t['maihanakatthai'] = 0x0E31;
  11534. t['maitaikhuleftthai'] = 0xF889;
  11535. t['maitaikhuthai'] = 0x0E47;
  11536. t['maitholowleftthai'] = 0xF88F;
  11537. t['maitholowrightthai'] = 0xF88E;
  11538. t['maithothai'] = 0x0E49;
  11539. t['maithoupperleftthai'] = 0xF88D;
  11540. t['maitrilowleftthai'] = 0xF892;
  11541. t['maitrilowrightthai'] = 0xF891;
  11542. t['maitrithai'] = 0x0E4A;
  11543. t['maitriupperleftthai'] = 0xF890;
  11544. t['maiyamokthai'] = 0x0E46;
  11545. t['makatakana'] = 0x30DE;
  11546. t['makatakanahalfwidth'] = 0xFF8F;
  11547. t['male'] = 0x2642;
  11548. t['mansyonsquare'] = 0x3347;
  11549. t['maqafhebrew'] = 0x05BE;
  11550. t['mars'] = 0x2642;
  11551. t['masoracirclehebrew'] = 0x05AF;
  11552. t['masquare'] = 0x3383;
  11553. t['mbopomofo'] = 0x3107;
  11554. t['mbsquare'] = 0x33D4;
  11555. t['mcircle'] = 0x24DC;
  11556. t['mcubedsquare'] = 0x33A5;
  11557. t['mdotaccent'] = 0x1E41;
  11558. t['mdotbelow'] = 0x1E43;
  11559. t['meemarabic'] = 0x0645;
  11560. t['meemfinalarabic'] = 0xFEE2;
  11561. t['meeminitialarabic'] = 0xFEE3;
  11562. t['meemmedialarabic'] = 0xFEE4;
  11563. t['meemmeeminitialarabic'] = 0xFCD1;
  11564. t['meemmeemisolatedarabic'] = 0xFC48;
  11565. t['meetorusquare'] = 0x334D;
  11566. t['mehiragana'] = 0x3081;
  11567. t['meizierasquare'] = 0x337E;
  11568. t['mekatakana'] = 0x30E1;
  11569. t['mekatakanahalfwidth'] = 0xFF92;
  11570. t['mem'] = 0x05DE;
  11571. t['memdagesh'] = 0xFB3E;
  11572. t['memdageshhebrew'] = 0xFB3E;
  11573. t['memhebrew'] = 0x05DE;
  11574. t['menarmenian'] = 0x0574;
  11575. t['merkhahebrew'] = 0x05A5;
  11576. t['merkhakefulahebrew'] = 0x05A6;
  11577. t['merkhakefulalefthebrew'] = 0x05A6;
  11578. t['merkhalefthebrew'] = 0x05A5;
  11579. t['mhook'] = 0x0271;
  11580. t['mhzsquare'] = 0x3392;
  11581. t['middledotkatakanahalfwidth'] = 0xFF65;
  11582. t['middot'] = 0x00B7;
  11583. t['mieumacirclekorean'] = 0x3272;
  11584. t['mieumaparenkorean'] = 0x3212;
  11585. t['mieumcirclekorean'] = 0x3264;
  11586. t['mieumkorean'] = 0x3141;
  11587. t['mieumpansioskorean'] = 0x3170;
  11588. t['mieumparenkorean'] = 0x3204;
  11589. t['mieumpieupkorean'] = 0x316E;
  11590. t['mieumsioskorean'] = 0x316F;
  11591. t['mihiragana'] = 0x307F;
  11592. t['mikatakana'] = 0x30DF;
  11593. t['mikatakanahalfwidth'] = 0xFF90;
  11594. t['minus'] = 0x2212;
  11595. t['minusbelowcmb'] = 0x0320;
  11596. t['minuscircle'] = 0x2296;
  11597. t['minusmod'] = 0x02D7;
  11598. t['minusplus'] = 0x2213;
  11599. t['minute'] = 0x2032;
  11600. t['miribaarusquare'] = 0x334A;
  11601. t['mirisquare'] = 0x3349;
  11602. t['mlonglegturned'] = 0x0270;
  11603. t['mlsquare'] = 0x3396;
  11604. t['mmcubedsquare'] = 0x33A3;
  11605. t['mmonospace'] = 0xFF4D;
  11606. t['mmsquaredsquare'] = 0x339F;
  11607. t['mohiragana'] = 0x3082;
  11608. t['mohmsquare'] = 0x33C1;
  11609. t['mokatakana'] = 0x30E2;
  11610. t['mokatakanahalfwidth'] = 0xFF93;
  11611. t['molsquare'] = 0x33D6;
  11612. t['momathai'] = 0x0E21;
  11613. t['moverssquare'] = 0x33A7;
  11614. t['moverssquaredsquare'] = 0x33A8;
  11615. t['mparen'] = 0x24A8;
  11616. t['mpasquare'] = 0x33AB;
  11617. t['mssquare'] = 0x33B3;
  11618. t['msuperior'] = 0xF6EF;
  11619. t['mturned'] = 0x026F;
  11620. t['mu'] = 0x00B5;
  11621. t['mu1'] = 0x00B5;
  11622. t['muasquare'] = 0x3382;
  11623. t['muchgreater'] = 0x226B;
  11624. t['muchless'] = 0x226A;
  11625. t['mufsquare'] = 0x338C;
  11626. t['mugreek'] = 0x03BC;
  11627. t['mugsquare'] = 0x338D;
  11628. t['muhiragana'] = 0x3080;
  11629. t['mukatakana'] = 0x30E0;
  11630. t['mukatakanahalfwidth'] = 0xFF91;
  11631. t['mulsquare'] = 0x3395;
  11632. t['multiply'] = 0x00D7;
  11633. t['mumsquare'] = 0x339B;
  11634. t['munahhebrew'] = 0x05A3;
  11635. t['munahlefthebrew'] = 0x05A3;
  11636. t['musicalnote'] = 0x266A;
  11637. t['musicalnotedbl'] = 0x266B;
  11638. t['musicflatsign'] = 0x266D;
  11639. t['musicsharpsign'] = 0x266F;
  11640. t['mussquare'] = 0x33B2;
  11641. t['muvsquare'] = 0x33B6;
  11642. t['muwsquare'] = 0x33BC;
  11643. t['mvmegasquare'] = 0x33B9;
  11644. t['mvsquare'] = 0x33B7;
  11645. t['mwmegasquare'] = 0x33BF;
  11646. t['mwsquare'] = 0x33BD;
  11647. t['n'] = 0x006E;
  11648. t['nabengali'] = 0x09A8;
  11649. t['nabla'] = 0x2207;
  11650. t['nacute'] = 0x0144;
  11651. t['nadeva'] = 0x0928;
  11652. t['nagujarati'] = 0x0AA8;
  11653. t['nagurmukhi'] = 0x0A28;
  11654. t['nahiragana'] = 0x306A;
  11655. t['nakatakana'] = 0x30CA;
  11656. t['nakatakanahalfwidth'] = 0xFF85;
  11657. t['napostrophe'] = 0x0149;
  11658. t['nasquare'] = 0x3381;
  11659. t['nbopomofo'] = 0x310B;
  11660. t['nbspace'] = 0x00A0;
  11661. t['ncaron'] = 0x0148;
  11662. t['ncedilla'] = 0x0146;
  11663. t['ncircle'] = 0x24DD;
  11664. t['ncircumflexbelow'] = 0x1E4B;
  11665. t['ncommaaccent'] = 0x0146;
  11666. t['ndotaccent'] = 0x1E45;
  11667. t['ndotbelow'] = 0x1E47;
  11668. t['nehiragana'] = 0x306D;
  11669. t['nekatakana'] = 0x30CD;
  11670. t['nekatakanahalfwidth'] = 0xFF88;
  11671. t['newsheqelsign'] = 0x20AA;
  11672. t['nfsquare'] = 0x338B;
  11673. t['ngabengali'] = 0x0999;
  11674. t['ngadeva'] = 0x0919;
  11675. t['ngagujarati'] = 0x0A99;
  11676. t['ngagurmukhi'] = 0x0A19;
  11677. t['ngonguthai'] = 0x0E07;
  11678. t['nhiragana'] = 0x3093;
  11679. t['nhookleft'] = 0x0272;
  11680. t['nhookretroflex'] = 0x0273;
  11681. t['nieunacirclekorean'] = 0x326F;
  11682. t['nieunaparenkorean'] = 0x320F;
  11683. t['nieuncieuckorean'] = 0x3135;
  11684. t['nieuncirclekorean'] = 0x3261;
  11685. t['nieunhieuhkorean'] = 0x3136;
  11686. t['nieunkorean'] = 0x3134;
  11687. t['nieunpansioskorean'] = 0x3168;
  11688. t['nieunparenkorean'] = 0x3201;
  11689. t['nieunsioskorean'] = 0x3167;
  11690. t['nieuntikeutkorean'] = 0x3166;
  11691. t['nihiragana'] = 0x306B;
  11692. t['nikatakana'] = 0x30CB;
  11693. t['nikatakanahalfwidth'] = 0xFF86;
  11694. t['nikhahitleftthai'] = 0xF899;
  11695. t['nikhahitthai'] = 0x0E4D;
  11696. t['nine'] = 0x0039;
  11697. t['ninearabic'] = 0x0669;
  11698. t['ninebengali'] = 0x09EF;
  11699. t['ninecircle'] = 0x2468;
  11700. t['ninecircleinversesansserif'] = 0x2792;
  11701. t['ninedeva'] = 0x096F;
  11702. t['ninegujarati'] = 0x0AEF;
  11703. t['ninegurmukhi'] = 0x0A6F;
  11704. t['ninehackarabic'] = 0x0669;
  11705. t['ninehangzhou'] = 0x3029;
  11706. t['nineideographicparen'] = 0x3228;
  11707. t['nineinferior'] = 0x2089;
  11708. t['ninemonospace'] = 0xFF19;
  11709. t['nineoldstyle'] = 0xF739;
  11710. t['nineparen'] = 0x247C;
  11711. t['nineperiod'] = 0x2490;
  11712. t['ninepersian'] = 0x06F9;
  11713. t['nineroman'] = 0x2178;
  11714. t['ninesuperior'] = 0x2079;
  11715. t['nineteencircle'] = 0x2472;
  11716. t['nineteenparen'] = 0x2486;
  11717. t['nineteenperiod'] = 0x249A;
  11718. t['ninethai'] = 0x0E59;
  11719. t['nj'] = 0x01CC;
  11720. t['njecyrillic'] = 0x045A;
  11721. t['nkatakana'] = 0x30F3;
  11722. t['nkatakanahalfwidth'] = 0xFF9D;
  11723. t['nlegrightlong'] = 0x019E;
  11724. t['nlinebelow'] = 0x1E49;
  11725. t['nmonospace'] = 0xFF4E;
  11726. t['nmsquare'] = 0x339A;
  11727. t['nnabengali'] = 0x09A3;
  11728. t['nnadeva'] = 0x0923;
  11729. t['nnagujarati'] = 0x0AA3;
  11730. t['nnagurmukhi'] = 0x0A23;
  11731. t['nnnadeva'] = 0x0929;
  11732. t['nohiragana'] = 0x306E;
  11733. t['nokatakana'] = 0x30CE;
  11734. t['nokatakanahalfwidth'] = 0xFF89;
  11735. t['nonbreakingspace'] = 0x00A0;
  11736. t['nonenthai'] = 0x0E13;
  11737. t['nonuthai'] = 0x0E19;
  11738. t['noonarabic'] = 0x0646;
  11739. t['noonfinalarabic'] = 0xFEE6;
  11740. t['noonghunnaarabic'] = 0x06BA;
  11741. t['noonghunnafinalarabic'] = 0xFB9F;
  11742. t['nooninitialarabic'] = 0xFEE7;
  11743. t['noonjeeminitialarabic'] = 0xFCD2;
  11744. t['noonjeemisolatedarabic'] = 0xFC4B;
  11745. t['noonmedialarabic'] = 0xFEE8;
  11746. t['noonmeeminitialarabic'] = 0xFCD5;
  11747. t['noonmeemisolatedarabic'] = 0xFC4E;
  11748. t['noonnoonfinalarabic'] = 0xFC8D;
  11749. t['notcontains'] = 0x220C;
  11750. t['notelement'] = 0x2209;
  11751. t['notelementof'] = 0x2209;
  11752. t['notequal'] = 0x2260;
  11753. t['notgreater'] = 0x226F;
  11754. t['notgreaternorequal'] = 0x2271;
  11755. t['notgreaternorless'] = 0x2279;
  11756. t['notidentical'] = 0x2262;
  11757. t['notless'] = 0x226E;
  11758. t['notlessnorequal'] = 0x2270;
  11759. t['notparallel'] = 0x2226;
  11760. t['notprecedes'] = 0x2280;
  11761. t['notsubset'] = 0x2284;
  11762. t['notsucceeds'] = 0x2281;
  11763. t['notsuperset'] = 0x2285;
  11764. t['nowarmenian'] = 0x0576;
  11765. t['nparen'] = 0x24A9;
  11766. t['nssquare'] = 0x33B1;
  11767. t['nsuperior'] = 0x207F;
  11768. t['ntilde'] = 0x00F1;
  11769. t['nu'] = 0x03BD;
  11770. t['nuhiragana'] = 0x306C;
  11771. t['nukatakana'] = 0x30CC;
  11772. t['nukatakanahalfwidth'] = 0xFF87;
  11773. t['nuktabengali'] = 0x09BC;
  11774. t['nuktadeva'] = 0x093C;
  11775. t['nuktagujarati'] = 0x0ABC;
  11776. t['nuktagurmukhi'] = 0x0A3C;
  11777. t['numbersign'] = 0x0023;
  11778. t['numbersignmonospace'] = 0xFF03;
  11779. t['numbersignsmall'] = 0xFE5F;
  11780. t['numeralsigngreek'] = 0x0374;
  11781. t['numeralsignlowergreek'] = 0x0375;
  11782. t['numero'] = 0x2116;
  11783. t['nun'] = 0x05E0;
  11784. t['nundagesh'] = 0xFB40;
  11785. t['nundageshhebrew'] = 0xFB40;
  11786. t['nunhebrew'] = 0x05E0;
  11787. t['nvsquare'] = 0x33B5;
  11788. t['nwsquare'] = 0x33BB;
  11789. t['nyabengali'] = 0x099E;
  11790. t['nyadeva'] = 0x091E;
  11791. t['nyagujarati'] = 0x0A9E;
  11792. t['nyagurmukhi'] = 0x0A1E;
  11793. t['o'] = 0x006F;
  11794. t['oacute'] = 0x00F3;
  11795. t['oangthai'] = 0x0E2D;
  11796. t['obarred'] = 0x0275;
  11797. t['obarredcyrillic'] = 0x04E9;
  11798. t['obarreddieresiscyrillic'] = 0x04EB;
  11799. t['obengali'] = 0x0993;
  11800. t['obopomofo'] = 0x311B;
  11801. t['obreve'] = 0x014F;
  11802. t['ocandradeva'] = 0x0911;
  11803. t['ocandragujarati'] = 0x0A91;
  11804. t['ocandravowelsigndeva'] = 0x0949;
  11805. t['ocandravowelsigngujarati'] = 0x0AC9;
  11806. t['ocaron'] = 0x01D2;
  11807. t['ocircle'] = 0x24DE;
  11808. t['ocircumflex'] = 0x00F4;
  11809. t['ocircumflexacute'] = 0x1ED1;
  11810. t['ocircumflexdotbelow'] = 0x1ED9;
  11811. t['ocircumflexgrave'] = 0x1ED3;
  11812. t['ocircumflexhookabove'] = 0x1ED5;
  11813. t['ocircumflextilde'] = 0x1ED7;
  11814. t['ocyrillic'] = 0x043E;
  11815. t['odblacute'] = 0x0151;
  11816. t['odblgrave'] = 0x020D;
  11817. t['odeva'] = 0x0913;
  11818. t['odieresis'] = 0x00F6;
  11819. t['odieresiscyrillic'] = 0x04E7;
  11820. t['odotbelow'] = 0x1ECD;
  11821. t['oe'] = 0x0153;
  11822. t['oekorean'] = 0x315A;
  11823. t['ogonek'] = 0x02DB;
  11824. t['ogonekcmb'] = 0x0328;
  11825. t['ograve'] = 0x00F2;
  11826. t['ogujarati'] = 0x0A93;
  11827. t['oharmenian'] = 0x0585;
  11828. t['ohiragana'] = 0x304A;
  11829. t['ohookabove'] = 0x1ECF;
  11830. t['ohorn'] = 0x01A1;
  11831. t['ohornacute'] = 0x1EDB;
  11832. t['ohorndotbelow'] = 0x1EE3;
  11833. t['ohorngrave'] = 0x1EDD;
  11834. t['ohornhookabove'] = 0x1EDF;
  11835. t['ohorntilde'] = 0x1EE1;
  11836. t['ohungarumlaut'] = 0x0151;
  11837. t['oi'] = 0x01A3;
  11838. t['oinvertedbreve'] = 0x020F;
  11839. t['okatakana'] = 0x30AA;
  11840. t['okatakanahalfwidth'] = 0xFF75;
  11841. t['okorean'] = 0x3157;
  11842. t['olehebrew'] = 0x05AB;
  11843. t['omacron'] = 0x014D;
  11844. t['omacronacute'] = 0x1E53;
  11845. t['omacrongrave'] = 0x1E51;
  11846. t['omdeva'] = 0x0950;
  11847. t['omega'] = 0x03C9;
  11848. t['omega1'] = 0x03D6;
  11849. t['omegacyrillic'] = 0x0461;
  11850. t['omegalatinclosed'] = 0x0277;
  11851. t['omegaroundcyrillic'] = 0x047B;
  11852. t['omegatitlocyrillic'] = 0x047D;
  11853. t['omegatonos'] = 0x03CE;
  11854. t['omgujarati'] = 0x0AD0;
  11855. t['omicron'] = 0x03BF;
  11856. t['omicrontonos'] = 0x03CC;
  11857. t['omonospace'] = 0xFF4F;
  11858. t['one'] = 0x0031;
  11859. t['onearabic'] = 0x0661;
  11860. t['onebengali'] = 0x09E7;
  11861. t['onecircle'] = 0x2460;
  11862. t['onecircleinversesansserif'] = 0x278A;
  11863. t['onedeva'] = 0x0967;
  11864. t['onedotenleader'] = 0x2024;
  11865. t['oneeighth'] = 0x215B;
  11866. t['onefitted'] = 0xF6DC;
  11867. t['onegujarati'] = 0x0AE7;
  11868. t['onegurmukhi'] = 0x0A67;
  11869. t['onehackarabic'] = 0x0661;
  11870. t['onehalf'] = 0x00BD;
  11871. t['onehangzhou'] = 0x3021;
  11872. t['oneideographicparen'] = 0x3220;
  11873. t['oneinferior'] = 0x2081;
  11874. t['onemonospace'] = 0xFF11;
  11875. t['onenumeratorbengali'] = 0x09F4;
  11876. t['oneoldstyle'] = 0xF731;
  11877. t['oneparen'] = 0x2474;
  11878. t['oneperiod'] = 0x2488;
  11879. t['onepersian'] = 0x06F1;
  11880. t['onequarter'] = 0x00BC;
  11881. t['oneroman'] = 0x2170;
  11882. t['onesuperior'] = 0x00B9;
  11883. t['onethai'] = 0x0E51;
  11884. t['onethird'] = 0x2153;
  11885. t['oogonek'] = 0x01EB;
  11886. t['oogonekmacron'] = 0x01ED;
  11887. t['oogurmukhi'] = 0x0A13;
  11888. t['oomatragurmukhi'] = 0x0A4B;
  11889. t['oopen'] = 0x0254;
  11890. t['oparen'] = 0x24AA;
  11891. t['openbullet'] = 0x25E6;
  11892. t['option'] = 0x2325;
  11893. t['ordfeminine'] = 0x00AA;
  11894. t['ordmasculine'] = 0x00BA;
  11895. t['orthogonal'] = 0x221F;
  11896. t['oshortdeva'] = 0x0912;
  11897. t['oshortvowelsigndeva'] = 0x094A;
  11898. t['oslash'] = 0x00F8;
  11899. t['oslashacute'] = 0x01FF;
  11900. t['osmallhiragana'] = 0x3049;
  11901. t['osmallkatakana'] = 0x30A9;
  11902. t['osmallkatakanahalfwidth'] = 0xFF6B;
  11903. t['ostrokeacute'] = 0x01FF;
  11904. t['osuperior'] = 0xF6F0;
  11905. t['otcyrillic'] = 0x047F;
  11906. t['otilde'] = 0x00F5;
  11907. t['otildeacute'] = 0x1E4D;
  11908. t['otildedieresis'] = 0x1E4F;
  11909. t['oubopomofo'] = 0x3121;
  11910. t['overline'] = 0x203E;
  11911. t['overlinecenterline'] = 0xFE4A;
  11912. t['overlinecmb'] = 0x0305;
  11913. t['overlinedashed'] = 0xFE49;
  11914. t['overlinedblwavy'] = 0xFE4C;
  11915. t['overlinewavy'] = 0xFE4B;
  11916. t['overscore'] = 0x00AF;
  11917. t['ovowelsignbengali'] = 0x09CB;
  11918. t['ovowelsigndeva'] = 0x094B;
  11919. t['ovowelsigngujarati'] = 0x0ACB;
  11920. t['p'] = 0x0070;
  11921. t['paampssquare'] = 0x3380;
  11922. t['paasentosquare'] = 0x332B;
  11923. t['pabengali'] = 0x09AA;
  11924. t['pacute'] = 0x1E55;
  11925. t['padeva'] = 0x092A;
  11926. t['pagedown'] = 0x21DF;
  11927. t['pageup'] = 0x21DE;
  11928. t['pagujarati'] = 0x0AAA;
  11929. t['pagurmukhi'] = 0x0A2A;
  11930. t['pahiragana'] = 0x3071;
  11931. t['paiyannoithai'] = 0x0E2F;
  11932. t['pakatakana'] = 0x30D1;
  11933. t['palatalizationcyrilliccmb'] = 0x0484;
  11934. t['palochkacyrillic'] = 0x04C0;
  11935. t['pansioskorean'] = 0x317F;
  11936. t['paragraph'] = 0x00B6;
  11937. t['parallel'] = 0x2225;
  11938. t['parenleft'] = 0x0028;
  11939. t['parenleftaltonearabic'] = 0xFD3E;
  11940. t['parenleftbt'] = 0xF8ED;
  11941. t['parenleftex'] = 0xF8EC;
  11942. t['parenleftinferior'] = 0x208D;
  11943. t['parenleftmonospace'] = 0xFF08;
  11944. t['parenleftsmall'] = 0xFE59;
  11945. t['parenleftsuperior'] = 0x207D;
  11946. t['parenlefttp'] = 0xF8EB;
  11947. t['parenleftvertical'] = 0xFE35;
  11948. t['parenright'] = 0x0029;
  11949. t['parenrightaltonearabic'] = 0xFD3F;
  11950. t['parenrightbt'] = 0xF8F8;
  11951. t['parenrightex'] = 0xF8F7;
  11952. t['parenrightinferior'] = 0x208E;
  11953. t['parenrightmonospace'] = 0xFF09;
  11954. t['parenrightsmall'] = 0xFE5A;
  11955. t['parenrightsuperior'] = 0x207E;
  11956. t['parenrighttp'] = 0xF8F6;
  11957. t['parenrightvertical'] = 0xFE36;
  11958. t['partialdiff'] = 0x2202;
  11959. t['paseqhebrew'] = 0x05C0;
  11960. t['pashtahebrew'] = 0x0599;
  11961. t['pasquare'] = 0x33A9;
  11962. t['patah'] = 0x05B7;
  11963. t['patah11'] = 0x05B7;
  11964. t['patah1d'] = 0x05B7;
  11965. t['patah2a'] = 0x05B7;
  11966. t['patahhebrew'] = 0x05B7;
  11967. t['patahnarrowhebrew'] = 0x05B7;
  11968. t['patahquarterhebrew'] = 0x05B7;
  11969. t['patahwidehebrew'] = 0x05B7;
  11970. t['pazerhebrew'] = 0x05A1;
  11971. t['pbopomofo'] = 0x3106;
  11972. t['pcircle'] = 0x24DF;
  11973. t['pdotaccent'] = 0x1E57;
  11974. t['pe'] = 0x05E4;
  11975. t['pecyrillic'] = 0x043F;
  11976. t['pedagesh'] = 0xFB44;
  11977. t['pedageshhebrew'] = 0xFB44;
  11978. t['peezisquare'] = 0x333B;
  11979. t['pefinaldageshhebrew'] = 0xFB43;
  11980. t['peharabic'] = 0x067E;
  11981. t['peharmenian'] = 0x057A;
  11982. t['pehebrew'] = 0x05E4;
  11983. t['pehfinalarabic'] = 0xFB57;
  11984. t['pehinitialarabic'] = 0xFB58;
  11985. t['pehiragana'] = 0x307A;
  11986. t['pehmedialarabic'] = 0xFB59;
  11987. t['pekatakana'] = 0x30DA;
  11988. t['pemiddlehookcyrillic'] = 0x04A7;
  11989. t['perafehebrew'] = 0xFB4E;
  11990. t['percent'] = 0x0025;
  11991. t['percentarabic'] = 0x066A;
  11992. t['percentmonospace'] = 0xFF05;
  11993. t['percentsmall'] = 0xFE6A;
  11994. t['period'] = 0x002E;
  11995. t['periodarmenian'] = 0x0589;
  11996. t['periodcentered'] = 0x00B7;
  11997. t['periodhalfwidth'] = 0xFF61;
  11998. t['periodinferior'] = 0xF6E7;
  11999. t['periodmonospace'] = 0xFF0E;
  12000. t['periodsmall'] = 0xFE52;
  12001. t['periodsuperior'] = 0xF6E8;
  12002. t['perispomenigreekcmb'] = 0x0342;
  12003. t['perpendicular'] = 0x22A5;
  12004. t['perthousand'] = 0x2030;
  12005. t['peseta'] = 0x20A7;
  12006. t['pfsquare'] = 0x338A;
  12007. t['phabengali'] = 0x09AB;
  12008. t['phadeva'] = 0x092B;
  12009. t['phagujarati'] = 0x0AAB;
  12010. t['phagurmukhi'] = 0x0A2B;
  12011. t['phi'] = 0x03C6;
  12012. t['phi1'] = 0x03D5;
  12013. t['phieuphacirclekorean'] = 0x327A;
  12014. t['phieuphaparenkorean'] = 0x321A;
  12015. t['phieuphcirclekorean'] = 0x326C;
  12016. t['phieuphkorean'] = 0x314D;
  12017. t['phieuphparenkorean'] = 0x320C;
  12018. t['philatin'] = 0x0278;
  12019. t['phinthuthai'] = 0x0E3A;
  12020. t['phisymbolgreek'] = 0x03D5;
  12021. t['phook'] = 0x01A5;
  12022. t['phophanthai'] = 0x0E1E;
  12023. t['phophungthai'] = 0x0E1C;
  12024. t['phosamphaothai'] = 0x0E20;
  12025. t['pi'] = 0x03C0;
  12026. t['pieupacirclekorean'] = 0x3273;
  12027. t['pieupaparenkorean'] = 0x3213;
  12028. t['pieupcieuckorean'] = 0x3176;
  12029. t['pieupcirclekorean'] = 0x3265;
  12030. t['pieupkiyeokkorean'] = 0x3172;
  12031. t['pieupkorean'] = 0x3142;
  12032. t['pieupparenkorean'] = 0x3205;
  12033. t['pieupsioskiyeokkorean'] = 0x3174;
  12034. t['pieupsioskorean'] = 0x3144;
  12035. t['pieupsiostikeutkorean'] = 0x3175;
  12036. t['pieupthieuthkorean'] = 0x3177;
  12037. t['pieuptikeutkorean'] = 0x3173;
  12038. t['pihiragana'] = 0x3074;
  12039. t['pikatakana'] = 0x30D4;
  12040. t['pisymbolgreek'] = 0x03D6;
  12041. t['piwrarmenian'] = 0x0583;
  12042. t['plus'] = 0x002B;
  12043. t['plusbelowcmb'] = 0x031F;
  12044. t['pluscircle'] = 0x2295;
  12045. t['plusminus'] = 0x00B1;
  12046. t['plusmod'] = 0x02D6;
  12047. t['plusmonospace'] = 0xFF0B;
  12048. t['plussmall'] = 0xFE62;
  12049. t['plussuperior'] = 0x207A;
  12050. t['pmonospace'] = 0xFF50;
  12051. t['pmsquare'] = 0x33D8;
  12052. t['pohiragana'] = 0x307D;
  12053. t['pointingindexdownwhite'] = 0x261F;
  12054. t['pointingindexleftwhite'] = 0x261C;
  12055. t['pointingindexrightwhite'] = 0x261E;
  12056. t['pointingindexupwhite'] = 0x261D;
  12057. t['pokatakana'] = 0x30DD;
  12058. t['poplathai'] = 0x0E1B;
  12059. t['postalmark'] = 0x3012;
  12060. t['postalmarkface'] = 0x3020;
  12061. t['pparen'] = 0x24AB;
  12062. t['precedes'] = 0x227A;
  12063. t['prescription'] = 0x211E;
  12064. t['primemod'] = 0x02B9;
  12065. t['primereversed'] = 0x2035;
  12066. t['product'] = 0x220F;
  12067. t['projective'] = 0x2305;
  12068. t['prolongedkana'] = 0x30FC;
  12069. t['propellor'] = 0x2318;
  12070. t['propersubset'] = 0x2282;
  12071. t['propersuperset'] = 0x2283;
  12072. t['proportion'] = 0x2237;
  12073. t['proportional'] = 0x221D;
  12074. t['psi'] = 0x03C8;
  12075. t['psicyrillic'] = 0x0471;
  12076. t['psilipneumatacyrilliccmb'] = 0x0486;
  12077. t['pssquare'] = 0x33B0;
  12078. t['puhiragana'] = 0x3077;
  12079. t['pukatakana'] = 0x30D7;
  12080. t['pvsquare'] = 0x33B4;
  12081. t['pwsquare'] = 0x33BA;
  12082. t['q'] = 0x0071;
  12083. t['qadeva'] = 0x0958;
  12084. t['qadmahebrew'] = 0x05A8;
  12085. t['qafarabic'] = 0x0642;
  12086. t['qaffinalarabic'] = 0xFED6;
  12087. t['qafinitialarabic'] = 0xFED7;
  12088. t['qafmedialarabic'] = 0xFED8;
  12089. t['qamats'] = 0x05B8;
  12090. t['qamats10'] = 0x05B8;
  12091. t['qamats1a'] = 0x05B8;
  12092. t['qamats1c'] = 0x05B8;
  12093. t['qamats27'] = 0x05B8;
  12094. t['qamats29'] = 0x05B8;
  12095. t['qamats33'] = 0x05B8;
  12096. t['qamatsde'] = 0x05B8;
  12097. t['qamatshebrew'] = 0x05B8;
  12098. t['qamatsnarrowhebrew'] = 0x05B8;
  12099. t['qamatsqatanhebrew'] = 0x05B8;
  12100. t['qamatsqatannarrowhebrew'] = 0x05B8;
  12101. t['qamatsqatanquarterhebrew'] = 0x05B8;
  12102. t['qamatsqatanwidehebrew'] = 0x05B8;
  12103. t['qamatsquarterhebrew'] = 0x05B8;
  12104. t['qamatswidehebrew'] = 0x05B8;
  12105. t['qarneyparahebrew'] = 0x059F;
  12106. t['qbopomofo'] = 0x3111;
  12107. t['qcircle'] = 0x24E0;
  12108. t['qhook'] = 0x02A0;
  12109. t['qmonospace'] = 0xFF51;
  12110. t['qof'] = 0x05E7;
  12111. t['qofdagesh'] = 0xFB47;
  12112. t['qofdageshhebrew'] = 0xFB47;
  12113. t['qofhebrew'] = 0x05E7;
  12114. t['qparen'] = 0x24AC;
  12115. t['quarternote'] = 0x2669;
  12116. t['qubuts'] = 0x05BB;
  12117. t['qubuts18'] = 0x05BB;
  12118. t['qubuts25'] = 0x05BB;
  12119. t['qubuts31'] = 0x05BB;
  12120. t['qubutshebrew'] = 0x05BB;
  12121. t['qubutsnarrowhebrew'] = 0x05BB;
  12122. t['qubutsquarterhebrew'] = 0x05BB;
  12123. t['qubutswidehebrew'] = 0x05BB;
  12124. t['question'] = 0x003F;
  12125. t['questionarabic'] = 0x061F;
  12126. t['questionarmenian'] = 0x055E;
  12127. t['questiondown'] = 0x00BF;
  12128. t['questiondownsmall'] = 0xF7BF;
  12129. t['questiongreek'] = 0x037E;
  12130. t['questionmonospace'] = 0xFF1F;
  12131. t['questionsmall'] = 0xF73F;
  12132. t['quotedbl'] = 0x0022;
  12133. t['quotedblbase'] = 0x201E;
  12134. t['quotedblleft'] = 0x201C;
  12135. t['quotedblmonospace'] = 0xFF02;
  12136. t['quotedblprime'] = 0x301E;
  12137. t['quotedblprimereversed'] = 0x301D;
  12138. t['quotedblright'] = 0x201D;
  12139. t['quoteleft'] = 0x2018;
  12140. t['quoteleftreversed'] = 0x201B;
  12141. t['quotereversed'] = 0x201B;
  12142. t['quoteright'] = 0x2019;
  12143. t['quoterightn'] = 0x0149;
  12144. t['quotesinglbase'] = 0x201A;
  12145. t['quotesingle'] = 0x0027;
  12146. t['quotesinglemonospace'] = 0xFF07;
  12147. t['r'] = 0x0072;
  12148. t['raarmenian'] = 0x057C;
  12149. t['rabengali'] = 0x09B0;
  12150. t['racute'] = 0x0155;
  12151. t['radeva'] = 0x0930;
  12152. t['radical'] = 0x221A;
  12153. t['radicalex'] = 0xF8E5;
  12154. t['radoverssquare'] = 0x33AE;
  12155. t['radoverssquaredsquare'] = 0x33AF;
  12156. t['radsquare'] = 0x33AD;
  12157. t['rafe'] = 0x05BF;
  12158. t['rafehebrew'] = 0x05BF;
  12159. t['ragujarati'] = 0x0AB0;
  12160. t['ragurmukhi'] = 0x0A30;
  12161. t['rahiragana'] = 0x3089;
  12162. t['rakatakana'] = 0x30E9;
  12163. t['rakatakanahalfwidth'] = 0xFF97;
  12164. t['ralowerdiagonalbengali'] = 0x09F1;
  12165. t['ramiddlediagonalbengali'] = 0x09F0;
  12166. t['ramshorn'] = 0x0264;
  12167. t['ratio'] = 0x2236;
  12168. t['rbopomofo'] = 0x3116;
  12169. t['rcaron'] = 0x0159;
  12170. t['rcedilla'] = 0x0157;
  12171. t['rcircle'] = 0x24E1;
  12172. t['rcommaaccent'] = 0x0157;
  12173. t['rdblgrave'] = 0x0211;
  12174. t['rdotaccent'] = 0x1E59;
  12175. t['rdotbelow'] = 0x1E5B;
  12176. t['rdotbelowmacron'] = 0x1E5D;
  12177. t['referencemark'] = 0x203B;
  12178. t['reflexsubset'] = 0x2286;
  12179. t['reflexsuperset'] = 0x2287;
  12180. t['registered'] = 0x00AE;
  12181. t['registersans'] = 0xF8E8;
  12182. t['registerserif'] = 0xF6DA;
  12183. t['reharabic'] = 0x0631;
  12184. t['reharmenian'] = 0x0580;
  12185. t['rehfinalarabic'] = 0xFEAE;
  12186. t['rehiragana'] = 0x308C;
  12187. t['rekatakana'] = 0x30EC;
  12188. t['rekatakanahalfwidth'] = 0xFF9A;
  12189. t['resh'] = 0x05E8;
  12190. t['reshdageshhebrew'] = 0xFB48;
  12191. t['reshhebrew'] = 0x05E8;
  12192. t['reversedtilde'] = 0x223D;
  12193. t['reviahebrew'] = 0x0597;
  12194. t['reviamugrashhebrew'] = 0x0597;
  12195. t['revlogicalnot'] = 0x2310;
  12196. t['rfishhook'] = 0x027E;
  12197. t['rfishhookreversed'] = 0x027F;
  12198. t['rhabengali'] = 0x09DD;
  12199. t['rhadeva'] = 0x095D;
  12200. t['rho'] = 0x03C1;
  12201. t['rhook'] = 0x027D;
  12202. t['rhookturned'] = 0x027B;
  12203. t['rhookturnedsuperior'] = 0x02B5;
  12204. t['rhosymbolgreek'] = 0x03F1;
  12205. t['rhotichookmod'] = 0x02DE;
  12206. t['rieulacirclekorean'] = 0x3271;
  12207. t['rieulaparenkorean'] = 0x3211;
  12208. t['rieulcirclekorean'] = 0x3263;
  12209. t['rieulhieuhkorean'] = 0x3140;
  12210. t['rieulkiyeokkorean'] = 0x313A;
  12211. t['rieulkiyeoksioskorean'] = 0x3169;
  12212. t['rieulkorean'] = 0x3139;
  12213. t['rieulmieumkorean'] = 0x313B;
  12214. t['rieulpansioskorean'] = 0x316C;
  12215. t['rieulparenkorean'] = 0x3203;
  12216. t['rieulphieuphkorean'] = 0x313F;
  12217. t['rieulpieupkorean'] = 0x313C;
  12218. t['rieulpieupsioskorean'] = 0x316B;
  12219. t['rieulsioskorean'] = 0x313D;
  12220. t['rieulthieuthkorean'] = 0x313E;
  12221. t['rieultikeutkorean'] = 0x316A;
  12222. t['rieulyeorinhieuhkorean'] = 0x316D;
  12223. t['rightangle'] = 0x221F;
  12224. t['righttackbelowcmb'] = 0x0319;
  12225. t['righttriangle'] = 0x22BF;
  12226. t['rihiragana'] = 0x308A;
  12227. t['rikatakana'] = 0x30EA;
  12228. t['rikatakanahalfwidth'] = 0xFF98;
  12229. t['ring'] = 0x02DA;
  12230. t['ringbelowcmb'] = 0x0325;
  12231. t['ringcmb'] = 0x030A;
  12232. t['ringhalfleft'] = 0x02BF;
  12233. t['ringhalfleftarmenian'] = 0x0559;
  12234. t['ringhalfleftbelowcmb'] = 0x031C;
  12235. t['ringhalfleftcentered'] = 0x02D3;
  12236. t['ringhalfright'] = 0x02BE;
  12237. t['ringhalfrightbelowcmb'] = 0x0339;
  12238. t['ringhalfrightcentered'] = 0x02D2;
  12239. t['rinvertedbreve'] = 0x0213;
  12240. t['rittorusquare'] = 0x3351;
  12241. t['rlinebelow'] = 0x1E5F;
  12242. t['rlongleg'] = 0x027C;
  12243. t['rlonglegturned'] = 0x027A;
  12244. t['rmonospace'] = 0xFF52;
  12245. t['rohiragana'] = 0x308D;
  12246. t['rokatakana'] = 0x30ED;
  12247. t['rokatakanahalfwidth'] = 0xFF9B;
  12248. t['roruathai'] = 0x0E23;
  12249. t['rparen'] = 0x24AD;
  12250. t['rrabengali'] = 0x09DC;
  12251. t['rradeva'] = 0x0931;
  12252. t['rragurmukhi'] = 0x0A5C;
  12253. t['rreharabic'] = 0x0691;
  12254. t['rrehfinalarabic'] = 0xFB8D;
  12255. t['rrvocalicbengali'] = 0x09E0;
  12256. t['rrvocalicdeva'] = 0x0960;
  12257. t['rrvocalicgujarati'] = 0x0AE0;
  12258. t['rrvocalicvowelsignbengali'] = 0x09C4;
  12259. t['rrvocalicvowelsigndeva'] = 0x0944;
  12260. t['rrvocalicvowelsigngujarati'] = 0x0AC4;
  12261. t['rsuperior'] = 0xF6F1;
  12262. t['rtblock'] = 0x2590;
  12263. t['rturned'] = 0x0279;
  12264. t['rturnedsuperior'] = 0x02B4;
  12265. t['ruhiragana'] = 0x308B;
  12266. t['rukatakana'] = 0x30EB;
  12267. t['rukatakanahalfwidth'] = 0xFF99;
  12268. t['rupeemarkbengali'] = 0x09F2;
  12269. t['rupeesignbengali'] = 0x09F3;
  12270. t['rupiah'] = 0xF6DD;
  12271. t['ruthai'] = 0x0E24;
  12272. t['rvocalicbengali'] = 0x098B;
  12273. t['rvocalicdeva'] = 0x090B;
  12274. t['rvocalicgujarati'] = 0x0A8B;
  12275. t['rvocalicvowelsignbengali'] = 0x09C3;
  12276. t['rvocalicvowelsigndeva'] = 0x0943;
  12277. t['rvocalicvowelsigngujarati'] = 0x0AC3;
  12278. t['s'] = 0x0073;
  12279. t['sabengali'] = 0x09B8;
  12280. t['sacute'] = 0x015B;
  12281. t['sacutedotaccent'] = 0x1E65;
  12282. t['sadarabic'] = 0x0635;
  12283. t['sadeva'] = 0x0938;
  12284. t['sadfinalarabic'] = 0xFEBA;
  12285. t['sadinitialarabic'] = 0xFEBB;
  12286. t['sadmedialarabic'] = 0xFEBC;
  12287. t['sagujarati'] = 0x0AB8;
  12288. t['sagurmukhi'] = 0x0A38;
  12289. t['sahiragana'] = 0x3055;
  12290. t['sakatakana'] = 0x30B5;
  12291. t['sakatakanahalfwidth'] = 0xFF7B;
  12292. t['sallallahoualayhewasallamarabic'] = 0xFDFA;
  12293. t['samekh'] = 0x05E1;
  12294. t['samekhdagesh'] = 0xFB41;
  12295. t['samekhdageshhebrew'] = 0xFB41;
  12296. t['samekhhebrew'] = 0x05E1;
  12297. t['saraaathai'] = 0x0E32;
  12298. t['saraaethai'] = 0x0E41;
  12299. t['saraaimaimalaithai'] = 0x0E44;
  12300. t['saraaimaimuanthai'] = 0x0E43;
  12301. t['saraamthai'] = 0x0E33;
  12302. t['saraathai'] = 0x0E30;
  12303. t['saraethai'] = 0x0E40;
  12304. t['saraiileftthai'] = 0xF886;
  12305. t['saraiithai'] = 0x0E35;
  12306. t['saraileftthai'] = 0xF885;
  12307. t['saraithai'] = 0x0E34;
  12308. t['saraothai'] = 0x0E42;
  12309. t['saraueeleftthai'] = 0xF888;
  12310. t['saraueethai'] = 0x0E37;
  12311. t['saraueleftthai'] = 0xF887;
  12312. t['sarauethai'] = 0x0E36;
  12313. t['sarauthai'] = 0x0E38;
  12314. t['sarauuthai'] = 0x0E39;
  12315. t['sbopomofo'] = 0x3119;
  12316. t['scaron'] = 0x0161;
  12317. t['scarondotaccent'] = 0x1E67;
  12318. t['scedilla'] = 0x015F;
  12319. t['schwa'] = 0x0259;
  12320. t['schwacyrillic'] = 0x04D9;
  12321. t['schwadieresiscyrillic'] = 0x04DB;
  12322. t['schwahook'] = 0x025A;
  12323. t['scircle'] = 0x24E2;
  12324. t['scircumflex'] = 0x015D;
  12325. t['scommaaccent'] = 0x0219;
  12326. t['sdotaccent'] = 0x1E61;
  12327. t['sdotbelow'] = 0x1E63;
  12328. t['sdotbelowdotaccent'] = 0x1E69;
  12329. t['seagullbelowcmb'] = 0x033C;
  12330. t['second'] = 0x2033;
  12331. t['secondtonechinese'] = 0x02CA;
  12332. t['section'] = 0x00A7;
  12333. t['seenarabic'] = 0x0633;
  12334. t['seenfinalarabic'] = 0xFEB2;
  12335. t['seeninitialarabic'] = 0xFEB3;
  12336. t['seenmedialarabic'] = 0xFEB4;
  12337. t['segol'] = 0x05B6;
  12338. t['segol13'] = 0x05B6;
  12339. t['segol1f'] = 0x05B6;
  12340. t['segol2c'] = 0x05B6;
  12341. t['segolhebrew'] = 0x05B6;
  12342. t['segolnarrowhebrew'] = 0x05B6;
  12343. t['segolquarterhebrew'] = 0x05B6;
  12344. t['segoltahebrew'] = 0x0592;
  12345. t['segolwidehebrew'] = 0x05B6;
  12346. t['seharmenian'] = 0x057D;
  12347. t['sehiragana'] = 0x305B;
  12348. t['sekatakana'] = 0x30BB;
  12349. t['sekatakanahalfwidth'] = 0xFF7E;
  12350. t['semicolon'] = 0x003B;
  12351. t['semicolonarabic'] = 0x061B;
  12352. t['semicolonmonospace'] = 0xFF1B;
  12353. t['semicolonsmall'] = 0xFE54;
  12354. t['semivoicedmarkkana'] = 0x309C;
  12355. t['semivoicedmarkkanahalfwidth'] = 0xFF9F;
  12356. t['sentisquare'] = 0x3322;
  12357. t['sentosquare'] = 0x3323;
  12358. t['seven'] = 0x0037;
  12359. t['sevenarabic'] = 0x0667;
  12360. t['sevenbengali'] = 0x09ED;
  12361. t['sevencircle'] = 0x2466;
  12362. t['sevencircleinversesansserif'] = 0x2790;
  12363. t['sevendeva'] = 0x096D;
  12364. t['seveneighths'] = 0x215E;
  12365. t['sevengujarati'] = 0x0AED;
  12366. t['sevengurmukhi'] = 0x0A6D;
  12367. t['sevenhackarabic'] = 0x0667;
  12368. t['sevenhangzhou'] = 0x3027;
  12369. t['sevenideographicparen'] = 0x3226;
  12370. t['seveninferior'] = 0x2087;
  12371. t['sevenmonospace'] = 0xFF17;
  12372. t['sevenoldstyle'] = 0xF737;
  12373. t['sevenparen'] = 0x247A;
  12374. t['sevenperiod'] = 0x248E;
  12375. t['sevenpersian'] = 0x06F7;
  12376. t['sevenroman'] = 0x2176;
  12377. t['sevensuperior'] = 0x2077;
  12378. t['seventeencircle'] = 0x2470;
  12379. t['seventeenparen'] = 0x2484;
  12380. t['seventeenperiod'] = 0x2498;
  12381. t['seventhai'] = 0x0E57;
  12382. t['sfthyphen'] = 0x00AD;
  12383. t['shaarmenian'] = 0x0577;
  12384. t['shabengali'] = 0x09B6;
  12385. t['shacyrillic'] = 0x0448;
  12386. t['shaddaarabic'] = 0x0651;
  12387. t['shaddadammaarabic'] = 0xFC61;
  12388. t['shaddadammatanarabic'] = 0xFC5E;
  12389. t['shaddafathaarabic'] = 0xFC60;
  12390. t['shaddakasraarabic'] = 0xFC62;
  12391. t['shaddakasratanarabic'] = 0xFC5F;
  12392. t['shade'] = 0x2592;
  12393. t['shadedark'] = 0x2593;
  12394. t['shadelight'] = 0x2591;
  12395. t['shademedium'] = 0x2592;
  12396. t['shadeva'] = 0x0936;
  12397. t['shagujarati'] = 0x0AB6;
  12398. t['shagurmukhi'] = 0x0A36;
  12399. t['shalshelethebrew'] = 0x0593;
  12400. t['shbopomofo'] = 0x3115;
  12401. t['shchacyrillic'] = 0x0449;
  12402. t['sheenarabic'] = 0x0634;
  12403. t['sheenfinalarabic'] = 0xFEB6;
  12404. t['sheeninitialarabic'] = 0xFEB7;
  12405. t['sheenmedialarabic'] = 0xFEB8;
  12406. t['sheicoptic'] = 0x03E3;
  12407. t['sheqel'] = 0x20AA;
  12408. t['sheqelhebrew'] = 0x20AA;
  12409. t['sheva'] = 0x05B0;
  12410. t['sheva115'] = 0x05B0;
  12411. t['sheva15'] = 0x05B0;
  12412. t['sheva22'] = 0x05B0;
  12413. t['sheva2e'] = 0x05B0;
  12414. t['shevahebrew'] = 0x05B0;
  12415. t['shevanarrowhebrew'] = 0x05B0;
  12416. t['shevaquarterhebrew'] = 0x05B0;
  12417. t['shevawidehebrew'] = 0x05B0;
  12418. t['shhacyrillic'] = 0x04BB;
  12419. t['shimacoptic'] = 0x03ED;
  12420. t['shin'] = 0x05E9;
  12421. t['shindagesh'] = 0xFB49;
  12422. t['shindageshhebrew'] = 0xFB49;
  12423. t['shindageshshindot'] = 0xFB2C;
  12424. t['shindageshshindothebrew'] = 0xFB2C;
  12425. t['shindageshsindot'] = 0xFB2D;
  12426. t['shindageshsindothebrew'] = 0xFB2D;
  12427. t['shindothebrew'] = 0x05C1;
  12428. t['shinhebrew'] = 0x05E9;
  12429. t['shinshindot'] = 0xFB2A;
  12430. t['shinshindothebrew'] = 0xFB2A;
  12431. t['shinsindot'] = 0xFB2B;
  12432. t['shinsindothebrew'] = 0xFB2B;
  12433. t['shook'] = 0x0282;
  12434. t['sigma'] = 0x03C3;
  12435. t['sigma1'] = 0x03C2;
  12436. t['sigmafinal'] = 0x03C2;
  12437. t['sigmalunatesymbolgreek'] = 0x03F2;
  12438. t['sihiragana'] = 0x3057;
  12439. t['sikatakana'] = 0x30B7;
  12440. t['sikatakanahalfwidth'] = 0xFF7C;
  12441. t['siluqhebrew'] = 0x05BD;
  12442. t['siluqlefthebrew'] = 0x05BD;
  12443. t['similar'] = 0x223C;
  12444. t['sindothebrew'] = 0x05C2;
  12445. t['siosacirclekorean'] = 0x3274;
  12446. t['siosaparenkorean'] = 0x3214;
  12447. t['sioscieuckorean'] = 0x317E;
  12448. t['sioscirclekorean'] = 0x3266;
  12449. t['sioskiyeokkorean'] = 0x317A;
  12450. t['sioskorean'] = 0x3145;
  12451. t['siosnieunkorean'] = 0x317B;
  12452. t['siosparenkorean'] = 0x3206;
  12453. t['siospieupkorean'] = 0x317D;
  12454. t['siostikeutkorean'] = 0x317C;
  12455. t['six'] = 0x0036;
  12456. t['sixarabic'] = 0x0666;
  12457. t['sixbengali'] = 0x09EC;
  12458. t['sixcircle'] = 0x2465;
  12459. t['sixcircleinversesansserif'] = 0x278F;
  12460. t['sixdeva'] = 0x096C;
  12461. t['sixgujarati'] = 0x0AEC;
  12462. t['sixgurmukhi'] = 0x0A6C;
  12463. t['sixhackarabic'] = 0x0666;
  12464. t['sixhangzhou'] = 0x3026;
  12465. t['sixideographicparen'] = 0x3225;
  12466. t['sixinferior'] = 0x2086;
  12467. t['sixmonospace'] = 0xFF16;
  12468. t['sixoldstyle'] = 0xF736;
  12469. t['sixparen'] = 0x2479;
  12470. t['sixperiod'] = 0x248D;
  12471. t['sixpersian'] = 0x06F6;
  12472. t['sixroman'] = 0x2175;
  12473. t['sixsuperior'] = 0x2076;
  12474. t['sixteencircle'] = 0x246F;
  12475. t['sixteencurrencydenominatorbengali'] = 0x09F9;
  12476. t['sixteenparen'] = 0x2483;
  12477. t['sixteenperiod'] = 0x2497;
  12478. t['sixthai'] = 0x0E56;
  12479. t['slash'] = 0x002F;
  12480. t['slashmonospace'] = 0xFF0F;
  12481. t['slong'] = 0x017F;
  12482. t['slongdotaccent'] = 0x1E9B;
  12483. t['smileface'] = 0x263A;
  12484. t['smonospace'] = 0xFF53;
  12485. t['sofpasuqhebrew'] = 0x05C3;
  12486. t['softhyphen'] = 0x00AD;
  12487. t['softsigncyrillic'] = 0x044C;
  12488. t['sohiragana'] = 0x305D;
  12489. t['sokatakana'] = 0x30BD;
  12490. t['sokatakanahalfwidth'] = 0xFF7F;
  12491. t['soliduslongoverlaycmb'] = 0x0338;
  12492. t['solidusshortoverlaycmb'] = 0x0337;
  12493. t['sorusithai'] = 0x0E29;
  12494. t['sosalathai'] = 0x0E28;
  12495. t['sosothai'] = 0x0E0B;
  12496. t['sosuathai'] = 0x0E2A;
  12497. t['space'] = 0x0020;
  12498. t['spacehackarabic'] = 0x0020;
  12499. t['spade'] = 0x2660;
  12500. t['spadesuitblack'] = 0x2660;
  12501. t['spadesuitwhite'] = 0x2664;
  12502. t['sparen'] = 0x24AE;
  12503. t['squarebelowcmb'] = 0x033B;
  12504. t['squarecc'] = 0x33C4;
  12505. t['squarecm'] = 0x339D;
  12506. t['squarediagonalcrosshatchfill'] = 0x25A9;
  12507. t['squarehorizontalfill'] = 0x25A4;
  12508. t['squarekg'] = 0x338F;
  12509. t['squarekm'] = 0x339E;
  12510. t['squarekmcapital'] = 0x33CE;
  12511. t['squareln'] = 0x33D1;
  12512. t['squarelog'] = 0x33D2;
  12513. t['squaremg'] = 0x338E;
  12514. t['squaremil'] = 0x33D5;
  12515. t['squaremm'] = 0x339C;
  12516. t['squaremsquared'] = 0x33A1;
  12517. t['squareorthogonalcrosshatchfill'] = 0x25A6;
  12518. t['squareupperlefttolowerrightfill'] = 0x25A7;
  12519. t['squareupperrighttolowerleftfill'] = 0x25A8;
  12520. t['squareverticalfill'] = 0x25A5;
  12521. t['squarewhitewithsmallblack'] = 0x25A3;
  12522. t['srsquare'] = 0x33DB;
  12523. t['ssabengali'] = 0x09B7;
  12524. t['ssadeva'] = 0x0937;
  12525. t['ssagujarati'] = 0x0AB7;
  12526. t['ssangcieuckorean'] = 0x3149;
  12527. t['ssanghieuhkorean'] = 0x3185;
  12528. t['ssangieungkorean'] = 0x3180;
  12529. t['ssangkiyeokkorean'] = 0x3132;
  12530. t['ssangnieunkorean'] = 0x3165;
  12531. t['ssangpieupkorean'] = 0x3143;
  12532. t['ssangsioskorean'] = 0x3146;
  12533. t['ssangtikeutkorean'] = 0x3138;
  12534. t['ssuperior'] = 0xF6F2;
  12535. t['sterling'] = 0x00A3;
  12536. t['sterlingmonospace'] = 0xFFE1;
  12537. t['strokelongoverlaycmb'] = 0x0336;
  12538. t['strokeshortoverlaycmb'] = 0x0335;
  12539. t['subset'] = 0x2282;
  12540. t['subsetnotequal'] = 0x228A;
  12541. t['subsetorequal'] = 0x2286;
  12542. t['succeeds'] = 0x227B;
  12543. t['suchthat'] = 0x220B;
  12544. t['suhiragana'] = 0x3059;
  12545. t['sukatakana'] = 0x30B9;
  12546. t['sukatakanahalfwidth'] = 0xFF7D;
  12547. t['sukunarabic'] = 0x0652;
  12548. t['summation'] = 0x2211;
  12549. t['sun'] = 0x263C;
  12550. t['superset'] = 0x2283;
  12551. t['supersetnotequal'] = 0x228B;
  12552. t['supersetorequal'] = 0x2287;
  12553. t['svsquare'] = 0x33DC;
  12554. t['syouwaerasquare'] = 0x337C;
  12555. t['t'] = 0x0074;
  12556. t['tabengali'] = 0x09A4;
  12557. t['tackdown'] = 0x22A4;
  12558. t['tackleft'] = 0x22A3;
  12559. t['tadeva'] = 0x0924;
  12560. t['tagujarati'] = 0x0AA4;
  12561. t['tagurmukhi'] = 0x0A24;
  12562. t['taharabic'] = 0x0637;
  12563. t['tahfinalarabic'] = 0xFEC2;
  12564. t['tahinitialarabic'] = 0xFEC3;
  12565. t['tahiragana'] = 0x305F;
  12566. t['tahmedialarabic'] = 0xFEC4;
  12567. t['taisyouerasquare'] = 0x337D;
  12568. t['takatakana'] = 0x30BF;
  12569. t['takatakanahalfwidth'] = 0xFF80;
  12570. t['tatweelarabic'] = 0x0640;
  12571. t['tau'] = 0x03C4;
  12572. t['tav'] = 0x05EA;
  12573. t['tavdages'] = 0xFB4A;
  12574. t['tavdagesh'] = 0xFB4A;
  12575. t['tavdageshhebrew'] = 0xFB4A;
  12576. t['tavhebrew'] = 0x05EA;
  12577. t['tbar'] = 0x0167;
  12578. t['tbopomofo'] = 0x310A;
  12579. t['tcaron'] = 0x0165;
  12580. t['tccurl'] = 0x02A8;
  12581. t['tcedilla'] = 0x0163;
  12582. t['tcheharabic'] = 0x0686;
  12583. t['tchehfinalarabic'] = 0xFB7B;
  12584. t['tchehinitialarabic'] = 0xFB7C;
  12585. t['tchehmedialarabic'] = 0xFB7D;
  12586. t['tcircle'] = 0x24E3;
  12587. t['tcircumflexbelow'] = 0x1E71;
  12588. t['tcommaaccent'] = 0x0163;
  12589. t['tdieresis'] = 0x1E97;
  12590. t['tdotaccent'] = 0x1E6B;
  12591. t['tdotbelow'] = 0x1E6D;
  12592. t['tecyrillic'] = 0x0442;
  12593. t['tedescendercyrillic'] = 0x04AD;
  12594. t['teharabic'] = 0x062A;
  12595. t['tehfinalarabic'] = 0xFE96;
  12596. t['tehhahinitialarabic'] = 0xFCA2;
  12597. t['tehhahisolatedarabic'] = 0xFC0C;
  12598. t['tehinitialarabic'] = 0xFE97;
  12599. t['tehiragana'] = 0x3066;
  12600. t['tehjeeminitialarabic'] = 0xFCA1;
  12601. t['tehjeemisolatedarabic'] = 0xFC0B;
  12602. t['tehmarbutaarabic'] = 0x0629;
  12603. t['tehmarbutafinalarabic'] = 0xFE94;
  12604. t['tehmedialarabic'] = 0xFE98;
  12605. t['tehmeeminitialarabic'] = 0xFCA4;
  12606. t['tehmeemisolatedarabic'] = 0xFC0E;
  12607. t['tehnoonfinalarabic'] = 0xFC73;
  12608. t['tekatakana'] = 0x30C6;
  12609. t['tekatakanahalfwidth'] = 0xFF83;
  12610. t['telephone'] = 0x2121;
  12611. t['telephoneblack'] = 0x260E;
  12612. t['telishagedolahebrew'] = 0x05A0;
  12613. t['telishaqetanahebrew'] = 0x05A9;
  12614. t['tencircle'] = 0x2469;
  12615. t['tenideographicparen'] = 0x3229;
  12616. t['tenparen'] = 0x247D;
  12617. t['tenperiod'] = 0x2491;
  12618. t['tenroman'] = 0x2179;
  12619. t['tesh'] = 0x02A7;
  12620. t['tet'] = 0x05D8;
  12621. t['tetdagesh'] = 0xFB38;
  12622. t['tetdageshhebrew'] = 0xFB38;
  12623. t['tethebrew'] = 0x05D8;
  12624. t['tetsecyrillic'] = 0x04B5;
  12625. t['tevirhebrew'] = 0x059B;
  12626. t['tevirlefthebrew'] = 0x059B;
  12627. t['thabengali'] = 0x09A5;
  12628. t['thadeva'] = 0x0925;
  12629. t['thagujarati'] = 0x0AA5;
  12630. t['thagurmukhi'] = 0x0A25;
  12631. t['thalarabic'] = 0x0630;
  12632. t['thalfinalarabic'] = 0xFEAC;
  12633. t['thanthakhatlowleftthai'] = 0xF898;
  12634. t['thanthakhatlowrightthai'] = 0xF897;
  12635. t['thanthakhatthai'] = 0x0E4C;
  12636. t['thanthakhatupperleftthai'] = 0xF896;
  12637. t['theharabic'] = 0x062B;
  12638. t['thehfinalarabic'] = 0xFE9A;
  12639. t['thehinitialarabic'] = 0xFE9B;
  12640. t['thehmedialarabic'] = 0xFE9C;
  12641. t['thereexists'] = 0x2203;
  12642. t['therefore'] = 0x2234;
  12643. t['theta'] = 0x03B8;
  12644. t['theta1'] = 0x03D1;
  12645. t['thetasymbolgreek'] = 0x03D1;
  12646. t['thieuthacirclekorean'] = 0x3279;
  12647. t['thieuthaparenkorean'] = 0x3219;
  12648. t['thieuthcirclekorean'] = 0x326B;
  12649. t['thieuthkorean'] = 0x314C;
  12650. t['thieuthparenkorean'] = 0x320B;
  12651. t['thirteencircle'] = 0x246C;
  12652. t['thirteenparen'] = 0x2480;
  12653. t['thirteenperiod'] = 0x2494;
  12654. t['thonangmonthothai'] = 0x0E11;
  12655. t['thook'] = 0x01AD;
  12656. t['thophuthaothai'] = 0x0E12;
  12657. t['thorn'] = 0x00FE;
  12658. t['thothahanthai'] = 0x0E17;
  12659. t['thothanthai'] = 0x0E10;
  12660. t['thothongthai'] = 0x0E18;
  12661. t['thothungthai'] = 0x0E16;
  12662. t['thousandcyrillic'] = 0x0482;
  12663. t['thousandsseparatorarabic'] = 0x066C;
  12664. t['thousandsseparatorpersian'] = 0x066C;
  12665. t['three'] = 0x0033;
  12666. t['threearabic'] = 0x0663;
  12667. t['threebengali'] = 0x09E9;
  12668. t['threecircle'] = 0x2462;
  12669. t['threecircleinversesansserif'] = 0x278C;
  12670. t['threedeva'] = 0x0969;
  12671. t['threeeighths'] = 0x215C;
  12672. t['threegujarati'] = 0x0AE9;
  12673. t['threegurmukhi'] = 0x0A69;
  12674. t['threehackarabic'] = 0x0663;
  12675. t['threehangzhou'] = 0x3023;
  12676. t['threeideographicparen'] = 0x3222;
  12677. t['threeinferior'] = 0x2083;
  12678. t['threemonospace'] = 0xFF13;
  12679. t['threenumeratorbengali'] = 0x09F6;
  12680. t['threeoldstyle'] = 0xF733;
  12681. t['threeparen'] = 0x2476;
  12682. t['threeperiod'] = 0x248A;
  12683. t['threepersian'] = 0x06F3;
  12684. t['threequarters'] = 0x00BE;
  12685. t['threequartersemdash'] = 0xF6DE;
  12686. t['threeroman'] = 0x2172;
  12687. t['threesuperior'] = 0x00B3;
  12688. t['threethai'] = 0x0E53;
  12689. t['thzsquare'] = 0x3394;
  12690. t['tihiragana'] = 0x3061;
  12691. t['tikatakana'] = 0x30C1;
  12692. t['tikatakanahalfwidth'] = 0xFF81;
  12693. t['tikeutacirclekorean'] = 0x3270;
  12694. t['tikeutaparenkorean'] = 0x3210;
  12695. t['tikeutcirclekorean'] = 0x3262;
  12696. t['tikeutkorean'] = 0x3137;
  12697. t['tikeutparenkorean'] = 0x3202;
  12698. t['tilde'] = 0x02DC;
  12699. t['tildebelowcmb'] = 0x0330;
  12700. t['tildecmb'] = 0x0303;
  12701. t['tildecomb'] = 0x0303;
  12702. t['tildedoublecmb'] = 0x0360;
  12703. t['tildeoperator'] = 0x223C;
  12704. t['tildeoverlaycmb'] = 0x0334;
  12705. t['tildeverticalcmb'] = 0x033E;
  12706. t['timescircle'] = 0x2297;
  12707. t['tipehahebrew'] = 0x0596;
  12708. t['tipehalefthebrew'] = 0x0596;
  12709. t['tippigurmukhi'] = 0x0A70;
  12710. t['titlocyrilliccmb'] = 0x0483;
  12711. t['tiwnarmenian'] = 0x057F;
  12712. t['tlinebelow'] = 0x1E6F;
  12713. t['tmonospace'] = 0xFF54;
  12714. t['toarmenian'] = 0x0569;
  12715. t['tohiragana'] = 0x3068;
  12716. t['tokatakana'] = 0x30C8;
  12717. t['tokatakanahalfwidth'] = 0xFF84;
  12718. t['tonebarextrahighmod'] = 0x02E5;
  12719. t['tonebarextralowmod'] = 0x02E9;
  12720. t['tonebarhighmod'] = 0x02E6;
  12721. t['tonebarlowmod'] = 0x02E8;
  12722. t['tonebarmidmod'] = 0x02E7;
  12723. t['tonefive'] = 0x01BD;
  12724. t['tonesix'] = 0x0185;
  12725. t['tonetwo'] = 0x01A8;
  12726. t['tonos'] = 0x0384;
  12727. t['tonsquare'] = 0x3327;
  12728. t['topatakthai'] = 0x0E0F;
  12729. t['tortoiseshellbracketleft'] = 0x3014;
  12730. t['tortoiseshellbracketleftsmall'] = 0xFE5D;
  12731. t['tortoiseshellbracketleftvertical'] = 0xFE39;
  12732. t['tortoiseshellbracketright'] = 0x3015;
  12733. t['tortoiseshellbracketrightsmall'] = 0xFE5E;
  12734. t['tortoiseshellbracketrightvertical'] = 0xFE3A;
  12735. t['totaothai'] = 0x0E15;
  12736. t['tpalatalhook'] = 0x01AB;
  12737. t['tparen'] = 0x24AF;
  12738. t['trademark'] = 0x2122;
  12739. t['trademarksans'] = 0xF8EA;
  12740. t['trademarkserif'] = 0xF6DB;
  12741. t['tretroflexhook'] = 0x0288;
  12742. t['triagdn'] = 0x25BC;
  12743. t['triaglf'] = 0x25C4;
  12744. t['triagrt'] = 0x25BA;
  12745. t['triagup'] = 0x25B2;
  12746. t['ts'] = 0x02A6;
  12747. t['tsadi'] = 0x05E6;
  12748. t['tsadidagesh'] = 0xFB46;
  12749. t['tsadidageshhebrew'] = 0xFB46;
  12750. t['tsadihebrew'] = 0x05E6;
  12751. t['tsecyrillic'] = 0x0446;
  12752. t['tsere'] = 0x05B5;
  12753. t['tsere12'] = 0x05B5;
  12754. t['tsere1e'] = 0x05B5;
  12755. t['tsere2b'] = 0x05B5;
  12756. t['tserehebrew'] = 0x05B5;
  12757. t['tserenarrowhebrew'] = 0x05B5;
  12758. t['tserequarterhebrew'] = 0x05B5;
  12759. t['tserewidehebrew'] = 0x05B5;
  12760. t['tshecyrillic'] = 0x045B;
  12761. t['tsuperior'] = 0xF6F3;
  12762. t['ttabengali'] = 0x099F;
  12763. t['ttadeva'] = 0x091F;
  12764. t['ttagujarati'] = 0x0A9F;
  12765. t['ttagurmukhi'] = 0x0A1F;
  12766. t['tteharabic'] = 0x0679;
  12767. t['ttehfinalarabic'] = 0xFB67;
  12768. t['ttehinitialarabic'] = 0xFB68;
  12769. t['ttehmedialarabic'] = 0xFB69;
  12770. t['tthabengali'] = 0x09A0;
  12771. t['tthadeva'] = 0x0920;
  12772. t['tthagujarati'] = 0x0AA0;
  12773. t['tthagurmukhi'] = 0x0A20;
  12774. t['tturned'] = 0x0287;
  12775. t['tuhiragana'] = 0x3064;
  12776. t['tukatakana'] = 0x30C4;
  12777. t['tukatakanahalfwidth'] = 0xFF82;
  12778. t['tusmallhiragana'] = 0x3063;
  12779. t['tusmallkatakana'] = 0x30C3;
  12780. t['tusmallkatakanahalfwidth'] = 0xFF6F;
  12781. t['twelvecircle'] = 0x246B;
  12782. t['twelveparen'] = 0x247F;
  12783. t['twelveperiod'] = 0x2493;
  12784. t['twelveroman'] = 0x217B;
  12785. t['twentycircle'] = 0x2473;
  12786. t['twentyhangzhou'] = 0x5344;
  12787. t['twentyparen'] = 0x2487;
  12788. t['twentyperiod'] = 0x249B;
  12789. t['two'] = 0x0032;
  12790. t['twoarabic'] = 0x0662;
  12791. t['twobengali'] = 0x09E8;
  12792. t['twocircle'] = 0x2461;
  12793. t['twocircleinversesansserif'] = 0x278B;
  12794. t['twodeva'] = 0x0968;
  12795. t['twodotenleader'] = 0x2025;
  12796. t['twodotleader'] = 0x2025;
  12797. t['twodotleadervertical'] = 0xFE30;
  12798. t['twogujarati'] = 0x0AE8;
  12799. t['twogurmukhi'] = 0x0A68;
  12800. t['twohackarabic'] = 0x0662;
  12801. t['twohangzhou'] = 0x3022;
  12802. t['twoideographicparen'] = 0x3221;
  12803. t['twoinferior'] = 0x2082;
  12804. t['twomonospace'] = 0xFF12;
  12805. t['twonumeratorbengali'] = 0x09F5;
  12806. t['twooldstyle'] = 0xF732;
  12807. t['twoparen'] = 0x2475;
  12808. t['twoperiod'] = 0x2489;
  12809. t['twopersian'] = 0x06F2;
  12810. t['tworoman'] = 0x2171;
  12811. t['twostroke'] = 0x01BB;
  12812. t['twosuperior'] = 0x00B2;
  12813. t['twothai'] = 0x0E52;
  12814. t['twothirds'] = 0x2154;
  12815. t['u'] = 0x0075;
  12816. t['uacute'] = 0x00FA;
  12817. t['ubar'] = 0x0289;
  12818. t['ubengali'] = 0x0989;
  12819. t['ubopomofo'] = 0x3128;
  12820. t['ubreve'] = 0x016D;
  12821. t['ucaron'] = 0x01D4;
  12822. t['ucircle'] = 0x24E4;
  12823. t['ucircumflex'] = 0x00FB;
  12824. t['ucircumflexbelow'] = 0x1E77;
  12825. t['ucyrillic'] = 0x0443;
  12826. t['udattadeva'] = 0x0951;
  12827. t['udblacute'] = 0x0171;
  12828. t['udblgrave'] = 0x0215;
  12829. t['udeva'] = 0x0909;
  12830. t['udieresis'] = 0x00FC;
  12831. t['udieresisacute'] = 0x01D8;
  12832. t['udieresisbelow'] = 0x1E73;
  12833. t['udieresiscaron'] = 0x01DA;
  12834. t['udieresiscyrillic'] = 0x04F1;
  12835. t['udieresisgrave'] = 0x01DC;
  12836. t['udieresismacron'] = 0x01D6;
  12837. t['udotbelow'] = 0x1EE5;
  12838. t['ugrave'] = 0x00F9;
  12839. t['ugujarati'] = 0x0A89;
  12840. t['ugurmukhi'] = 0x0A09;
  12841. t['uhiragana'] = 0x3046;
  12842. t['uhookabove'] = 0x1EE7;
  12843. t['uhorn'] = 0x01B0;
  12844. t['uhornacute'] = 0x1EE9;
  12845. t['uhorndotbelow'] = 0x1EF1;
  12846. t['uhorngrave'] = 0x1EEB;
  12847. t['uhornhookabove'] = 0x1EED;
  12848. t['uhorntilde'] = 0x1EEF;
  12849. t['uhungarumlaut'] = 0x0171;
  12850. t['uhungarumlautcyrillic'] = 0x04F3;
  12851. t['uinvertedbreve'] = 0x0217;
  12852. t['ukatakana'] = 0x30A6;
  12853. t['ukatakanahalfwidth'] = 0xFF73;
  12854. t['ukcyrillic'] = 0x0479;
  12855. t['ukorean'] = 0x315C;
  12856. t['umacron'] = 0x016B;
  12857. t['umacroncyrillic'] = 0x04EF;
  12858. t['umacrondieresis'] = 0x1E7B;
  12859. t['umatragurmukhi'] = 0x0A41;
  12860. t['umonospace'] = 0xFF55;
  12861. t['underscore'] = 0x005F;
  12862. t['underscoredbl'] = 0x2017;
  12863. t['underscoremonospace'] = 0xFF3F;
  12864. t['underscorevertical'] = 0xFE33;
  12865. t['underscorewavy'] = 0xFE4F;
  12866. t['union'] = 0x222A;
  12867. t['universal'] = 0x2200;
  12868. t['uogonek'] = 0x0173;
  12869. t['uparen'] = 0x24B0;
  12870. t['upblock'] = 0x2580;
  12871. t['upperdothebrew'] = 0x05C4;
  12872. t['upsilon'] = 0x03C5;
  12873. t['upsilondieresis'] = 0x03CB;
  12874. t['upsilondieresistonos'] = 0x03B0;
  12875. t['upsilonlatin'] = 0x028A;
  12876. t['upsilontonos'] = 0x03CD;
  12877. t['uptackbelowcmb'] = 0x031D;
  12878. t['uptackmod'] = 0x02D4;
  12879. t['uragurmukhi'] = 0x0A73;
  12880. t['uring'] = 0x016F;
  12881. t['ushortcyrillic'] = 0x045E;
  12882. t['usmallhiragana'] = 0x3045;
  12883. t['usmallkatakana'] = 0x30A5;
  12884. t['usmallkatakanahalfwidth'] = 0xFF69;
  12885. t['ustraightcyrillic'] = 0x04AF;
  12886. t['ustraightstrokecyrillic'] = 0x04B1;
  12887. t['utilde'] = 0x0169;
  12888. t['utildeacute'] = 0x1E79;
  12889. t['utildebelow'] = 0x1E75;
  12890. t['uubengali'] = 0x098A;
  12891. t['uudeva'] = 0x090A;
  12892. t['uugujarati'] = 0x0A8A;
  12893. t['uugurmukhi'] = 0x0A0A;
  12894. t['uumatragurmukhi'] = 0x0A42;
  12895. t['uuvowelsignbengali'] = 0x09C2;
  12896. t['uuvowelsigndeva'] = 0x0942;
  12897. t['uuvowelsigngujarati'] = 0x0AC2;
  12898. t['uvowelsignbengali'] = 0x09C1;
  12899. t['uvowelsigndeva'] = 0x0941;
  12900. t['uvowelsigngujarati'] = 0x0AC1;
  12901. t['v'] = 0x0076;
  12902. t['vadeva'] = 0x0935;
  12903. t['vagujarati'] = 0x0AB5;
  12904. t['vagurmukhi'] = 0x0A35;
  12905. t['vakatakana'] = 0x30F7;
  12906. t['vav'] = 0x05D5;
  12907. t['vavdagesh'] = 0xFB35;
  12908. t['vavdagesh65'] = 0xFB35;
  12909. t['vavdageshhebrew'] = 0xFB35;
  12910. t['vavhebrew'] = 0x05D5;
  12911. t['vavholam'] = 0xFB4B;
  12912. t['vavholamhebrew'] = 0xFB4B;
  12913. t['vavvavhebrew'] = 0x05F0;
  12914. t['vavyodhebrew'] = 0x05F1;
  12915. t['vcircle'] = 0x24E5;
  12916. t['vdotbelow'] = 0x1E7F;
  12917. t['vecyrillic'] = 0x0432;
  12918. t['veharabic'] = 0x06A4;
  12919. t['vehfinalarabic'] = 0xFB6B;
  12920. t['vehinitialarabic'] = 0xFB6C;
  12921. t['vehmedialarabic'] = 0xFB6D;
  12922. t['vekatakana'] = 0x30F9;
  12923. t['venus'] = 0x2640;
  12924. t['verticalbar'] = 0x007C;
  12925. t['verticallineabovecmb'] = 0x030D;
  12926. t['verticallinebelowcmb'] = 0x0329;
  12927. t['verticallinelowmod'] = 0x02CC;
  12928. t['verticallinemod'] = 0x02C8;
  12929. t['vewarmenian'] = 0x057E;
  12930. t['vhook'] = 0x028B;
  12931. t['vikatakana'] = 0x30F8;
  12932. t['viramabengali'] = 0x09CD;
  12933. t['viramadeva'] = 0x094D;
  12934. t['viramagujarati'] = 0x0ACD;
  12935. t['visargabengali'] = 0x0983;
  12936. t['visargadeva'] = 0x0903;
  12937. t['visargagujarati'] = 0x0A83;
  12938. t['vmonospace'] = 0xFF56;
  12939. t['voarmenian'] = 0x0578;
  12940. t['voicediterationhiragana'] = 0x309E;
  12941. t['voicediterationkatakana'] = 0x30FE;
  12942. t['voicedmarkkana'] = 0x309B;
  12943. t['voicedmarkkanahalfwidth'] = 0xFF9E;
  12944. t['vokatakana'] = 0x30FA;
  12945. t['vparen'] = 0x24B1;
  12946. t['vtilde'] = 0x1E7D;
  12947. t['vturned'] = 0x028C;
  12948. t['vuhiragana'] = 0x3094;
  12949. t['vukatakana'] = 0x30F4;
  12950. t['w'] = 0x0077;
  12951. t['wacute'] = 0x1E83;
  12952. t['waekorean'] = 0x3159;
  12953. t['wahiragana'] = 0x308F;
  12954. t['wakatakana'] = 0x30EF;
  12955. t['wakatakanahalfwidth'] = 0xFF9C;
  12956. t['wakorean'] = 0x3158;
  12957. t['wasmallhiragana'] = 0x308E;
  12958. t['wasmallkatakana'] = 0x30EE;
  12959. t['wattosquare'] = 0x3357;
  12960. t['wavedash'] = 0x301C;
  12961. t['wavyunderscorevertical'] = 0xFE34;
  12962. t['wawarabic'] = 0x0648;
  12963. t['wawfinalarabic'] = 0xFEEE;
  12964. t['wawhamzaabovearabic'] = 0x0624;
  12965. t['wawhamzaabovefinalarabic'] = 0xFE86;
  12966. t['wbsquare'] = 0x33DD;
  12967. t['wcircle'] = 0x24E6;
  12968. t['wcircumflex'] = 0x0175;
  12969. t['wdieresis'] = 0x1E85;
  12970. t['wdotaccent'] = 0x1E87;
  12971. t['wdotbelow'] = 0x1E89;
  12972. t['wehiragana'] = 0x3091;
  12973. t['weierstrass'] = 0x2118;
  12974. t['wekatakana'] = 0x30F1;
  12975. t['wekorean'] = 0x315E;
  12976. t['weokorean'] = 0x315D;
  12977. t['wgrave'] = 0x1E81;
  12978. t['whitebullet'] = 0x25E6;
  12979. t['whitecircle'] = 0x25CB;
  12980. t['whitecircleinverse'] = 0x25D9;
  12981. t['whitecornerbracketleft'] = 0x300E;
  12982. t['whitecornerbracketleftvertical'] = 0xFE43;
  12983. t['whitecornerbracketright'] = 0x300F;
  12984. t['whitecornerbracketrightvertical'] = 0xFE44;
  12985. t['whitediamond'] = 0x25C7;
  12986. t['whitediamondcontainingblacksmalldiamond'] = 0x25C8;
  12987. t['whitedownpointingsmalltriangle'] = 0x25BF;
  12988. t['whitedownpointingtriangle'] = 0x25BD;
  12989. t['whiteleftpointingsmalltriangle'] = 0x25C3;
  12990. t['whiteleftpointingtriangle'] = 0x25C1;
  12991. t['whitelenticularbracketleft'] = 0x3016;
  12992. t['whitelenticularbracketright'] = 0x3017;
  12993. t['whiterightpointingsmalltriangle'] = 0x25B9;
  12994. t['whiterightpointingtriangle'] = 0x25B7;
  12995. t['whitesmallsquare'] = 0x25AB;
  12996. t['whitesmilingface'] = 0x263A;
  12997. t['whitesquare'] = 0x25A1;
  12998. t['whitestar'] = 0x2606;
  12999. t['whitetelephone'] = 0x260F;
  13000. t['whitetortoiseshellbracketleft'] = 0x3018;
  13001. t['whitetortoiseshellbracketright'] = 0x3019;
  13002. t['whiteuppointingsmalltriangle'] = 0x25B5;
  13003. t['whiteuppointingtriangle'] = 0x25B3;
  13004. t['wihiragana'] = 0x3090;
  13005. t['wikatakana'] = 0x30F0;
  13006. t['wikorean'] = 0x315F;
  13007. t['wmonospace'] = 0xFF57;
  13008. t['wohiragana'] = 0x3092;
  13009. t['wokatakana'] = 0x30F2;
  13010. t['wokatakanahalfwidth'] = 0xFF66;
  13011. t['won'] = 0x20A9;
  13012. t['wonmonospace'] = 0xFFE6;
  13013. t['wowaenthai'] = 0x0E27;
  13014. t['wparen'] = 0x24B2;
  13015. t['wring'] = 0x1E98;
  13016. t['wsuperior'] = 0x02B7;
  13017. t['wturned'] = 0x028D;
  13018. t['wynn'] = 0x01BF;
  13019. t['x'] = 0x0078;
  13020. t['xabovecmb'] = 0x033D;
  13021. t['xbopomofo'] = 0x3112;
  13022. t['xcircle'] = 0x24E7;
  13023. t['xdieresis'] = 0x1E8D;
  13024. t['xdotaccent'] = 0x1E8B;
  13025. t['xeharmenian'] = 0x056D;
  13026. t['xi'] = 0x03BE;
  13027. t['xmonospace'] = 0xFF58;
  13028. t['xparen'] = 0x24B3;
  13029. t['xsuperior'] = 0x02E3;
  13030. t['y'] = 0x0079;
  13031. t['yaadosquare'] = 0x334E;
  13032. t['yabengali'] = 0x09AF;
  13033. t['yacute'] = 0x00FD;
  13034. t['yadeva'] = 0x092F;
  13035. t['yaekorean'] = 0x3152;
  13036. t['yagujarati'] = 0x0AAF;
  13037. t['yagurmukhi'] = 0x0A2F;
  13038. t['yahiragana'] = 0x3084;
  13039. t['yakatakana'] = 0x30E4;
  13040. t['yakatakanahalfwidth'] = 0xFF94;
  13041. t['yakorean'] = 0x3151;
  13042. t['yamakkanthai'] = 0x0E4E;
  13043. t['yasmallhiragana'] = 0x3083;
  13044. t['yasmallkatakana'] = 0x30E3;
  13045. t['yasmallkatakanahalfwidth'] = 0xFF6C;
  13046. t['yatcyrillic'] = 0x0463;
  13047. t['ycircle'] = 0x24E8;
  13048. t['ycircumflex'] = 0x0177;
  13049. t['ydieresis'] = 0x00FF;
  13050. t['ydotaccent'] = 0x1E8F;
  13051. t['ydotbelow'] = 0x1EF5;
  13052. t['yeharabic'] = 0x064A;
  13053. t['yehbarreearabic'] = 0x06D2;
  13054. t['yehbarreefinalarabic'] = 0xFBAF;
  13055. t['yehfinalarabic'] = 0xFEF2;
  13056. t['yehhamzaabovearabic'] = 0x0626;
  13057. t['yehhamzaabovefinalarabic'] = 0xFE8A;
  13058. t['yehhamzaaboveinitialarabic'] = 0xFE8B;
  13059. t['yehhamzaabovemedialarabic'] = 0xFE8C;
  13060. t['yehinitialarabic'] = 0xFEF3;
  13061. t['yehmedialarabic'] = 0xFEF4;
  13062. t['yehmeeminitialarabic'] = 0xFCDD;
  13063. t['yehmeemisolatedarabic'] = 0xFC58;
  13064. t['yehnoonfinalarabic'] = 0xFC94;
  13065. t['yehthreedotsbelowarabic'] = 0x06D1;
  13066. t['yekorean'] = 0x3156;
  13067. t['yen'] = 0x00A5;
  13068. t['yenmonospace'] = 0xFFE5;
  13069. t['yeokorean'] = 0x3155;
  13070. t['yeorinhieuhkorean'] = 0x3186;
  13071. t['yerahbenyomohebrew'] = 0x05AA;
  13072. t['yerahbenyomolefthebrew'] = 0x05AA;
  13073. t['yericyrillic'] = 0x044B;
  13074. t['yerudieresiscyrillic'] = 0x04F9;
  13075. t['yesieungkorean'] = 0x3181;
  13076. t['yesieungpansioskorean'] = 0x3183;
  13077. t['yesieungsioskorean'] = 0x3182;
  13078. t['yetivhebrew'] = 0x059A;
  13079. t['ygrave'] = 0x1EF3;
  13080. t['yhook'] = 0x01B4;
  13081. t['yhookabove'] = 0x1EF7;
  13082. t['yiarmenian'] = 0x0575;
  13083. t['yicyrillic'] = 0x0457;
  13084. t['yikorean'] = 0x3162;
  13085. t['yinyang'] = 0x262F;
  13086. t['yiwnarmenian'] = 0x0582;
  13087. t['ymonospace'] = 0xFF59;
  13088. t['yod'] = 0x05D9;
  13089. t['yoddagesh'] = 0xFB39;
  13090. t['yoddageshhebrew'] = 0xFB39;
  13091. t['yodhebrew'] = 0x05D9;
  13092. t['yodyodhebrew'] = 0x05F2;
  13093. t['yodyodpatahhebrew'] = 0xFB1F;
  13094. t['yohiragana'] = 0x3088;
  13095. t['yoikorean'] = 0x3189;
  13096. t['yokatakana'] = 0x30E8;
  13097. t['yokatakanahalfwidth'] = 0xFF96;
  13098. t['yokorean'] = 0x315B;
  13099. t['yosmallhiragana'] = 0x3087;
  13100. t['yosmallkatakana'] = 0x30E7;
  13101. t['yosmallkatakanahalfwidth'] = 0xFF6E;
  13102. t['yotgreek'] = 0x03F3;
  13103. t['yoyaekorean'] = 0x3188;
  13104. t['yoyakorean'] = 0x3187;
  13105. t['yoyakthai'] = 0x0E22;
  13106. t['yoyingthai'] = 0x0E0D;
  13107. t['yparen'] = 0x24B4;
  13108. t['ypogegrammeni'] = 0x037A;
  13109. t['ypogegrammenigreekcmb'] = 0x0345;
  13110. t['yr'] = 0x01A6;
  13111. t['yring'] = 0x1E99;
  13112. t['ysuperior'] = 0x02B8;
  13113. t['ytilde'] = 0x1EF9;
  13114. t['yturned'] = 0x028E;
  13115. t['yuhiragana'] = 0x3086;
  13116. t['yuikorean'] = 0x318C;
  13117. t['yukatakana'] = 0x30E6;
  13118. t['yukatakanahalfwidth'] = 0xFF95;
  13119. t['yukorean'] = 0x3160;
  13120. t['yusbigcyrillic'] = 0x046B;
  13121. t['yusbigiotifiedcyrillic'] = 0x046D;
  13122. t['yuslittlecyrillic'] = 0x0467;
  13123. t['yuslittleiotifiedcyrillic'] = 0x0469;
  13124. t['yusmallhiragana'] = 0x3085;
  13125. t['yusmallkatakana'] = 0x30E5;
  13126. t['yusmallkatakanahalfwidth'] = 0xFF6D;
  13127. t['yuyekorean'] = 0x318B;
  13128. t['yuyeokorean'] = 0x318A;
  13129. t['yyabengali'] = 0x09DF;
  13130. t['yyadeva'] = 0x095F;
  13131. t['z'] = 0x007A;
  13132. t['zaarmenian'] = 0x0566;
  13133. t['zacute'] = 0x017A;
  13134. t['zadeva'] = 0x095B;
  13135. t['zagurmukhi'] = 0x0A5B;
  13136. t['zaharabic'] = 0x0638;
  13137. t['zahfinalarabic'] = 0xFEC6;
  13138. t['zahinitialarabic'] = 0xFEC7;
  13139. t['zahiragana'] = 0x3056;
  13140. t['zahmedialarabic'] = 0xFEC8;
  13141. t['zainarabic'] = 0x0632;
  13142. t['zainfinalarabic'] = 0xFEB0;
  13143. t['zakatakana'] = 0x30B6;
  13144. t['zaqefgadolhebrew'] = 0x0595;
  13145. t['zaqefqatanhebrew'] = 0x0594;
  13146. t['zarqahebrew'] = 0x0598;
  13147. t['zayin'] = 0x05D6;
  13148. t['zayindagesh'] = 0xFB36;
  13149. t['zayindageshhebrew'] = 0xFB36;
  13150. t['zayinhebrew'] = 0x05D6;
  13151. t['zbopomofo'] = 0x3117;
  13152. t['zcaron'] = 0x017E;
  13153. t['zcircle'] = 0x24E9;
  13154. t['zcircumflex'] = 0x1E91;
  13155. t['zcurl'] = 0x0291;
  13156. t['zdot'] = 0x017C;
  13157. t['zdotaccent'] = 0x017C;
  13158. t['zdotbelow'] = 0x1E93;
  13159. t['zecyrillic'] = 0x0437;
  13160. t['zedescendercyrillic'] = 0x0499;
  13161. t['zedieresiscyrillic'] = 0x04DF;
  13162. t['zehiragana'] = 0x305C;
  13163. t['zekatakana'] = 0x30BC;
  13164. t['zero'] = 0x0030;
  13165. t['zeroarabic'] = 0x0660;
  13166. t['zerobengali'] = 0x09E6;
  13167. t['zerodeva'] = 0x0966;
  13168. t['zerogujarati'] = 0x0AE6;
  13169. t['zerogurmukhi'] = 0x0A66;
  13170. t['zerohackarabic'] = 0x0660;
  13171. t['zeroinferior'] = 0x2080;
  13172. t['zeromonospace'] = 0xFF10;
  13173. t['zerooldstyle'] = 0xF730;
  13174. t['zeropersian'] = 0x06F0;
  13175. t['zerosuperior'] = 0x2070;
  13176. t['zerothai'] = 0x0E50;
  13177. t['zerowidthjoiner'] = 0xFEFF;
  13178. t['zerowidthnonjoiner'] = 0x200C;
  13179. t['zerowidthspace'] = 0x200B;
  13180. t['zeta'] = 0x03B6;
  13181. t['zhbopomofo'] = 0x3113;
  13182. t['zhearmenian'] = 0x056A;
  13183. t['zhebrevecyrillic'] = 0x04C2;
  13184. t['zhecyrillic'] = 0x0436;
  13185. t['zhedescendercyrillic'] = 0x0497;
  13186. t['zhedieresiscyrillic'] = 0x04DD;
  13187. t['zihiragana'] = 0x3058;
  13188. t['zikatakana'] = 0x30B8;
  13189. t['zinorhebrew'] = 0x05AE;
  13190. t['zlinebelow'] = 0x1E95;
  13191. t['zmonospace'] = 0xFF5A;
  13192. t['zohiragana'] = 0x305E;
  13193. t['zokatakana'] = 0x30BE;
  13194. t['zparen'] = 0x24B5;
  13195. t['zretroflexhook'] = 0x0290;
  13196. t['zstroke'] = 0x01B6;
  13197. t['zuhiragana'] = 0x305A;
  13198. t['zukatakana'] = 0x30BA;
  13199. t['.notdef'] = 0x0000;
  13200. });
  13201. var getDingbatsGlyphsUnicode = getLookupTableFactory(function (t) {
  13202. t['space'] = 0x0020;
  13203. t['a1'] = 0x2701;
  13204. t['a2'] = 0x2702;
  13205. t['a202'] = 0x2703;
  13206. t['a3'] = 0x2704;
  13207. t['a4'] = 0x260E;
  13208. t['a5'] = 0x2706;
  13209. t['a119'] = 0x2707;
  13210. t['a118'] = 0x2708;
  13211. t['a117'] = 0x2709;
  13212. t['a11'] = 0x261B;
  13213. t['a12'] = 0x261E;
  13214. t['a13'] = 0x270C;
  13215. t['a14'] = 0x270D;
  13216. t['a15'] = 0x270E;
  13217. t['a16'] = 0x270F;
  13218. t['a105'] = 0x2710;
  13219. t['a17'] = 0x2711;
  13220. t['a18'] = 0x2712;
  13221. t['a19'] = 0x2713;
  13222. t['a20'] = 0x2714;
  13223. t['a21'] = 0x2715;
  13224. t['a22'] = 0x2716;
  13225. t['a23'] = 0x2717;
  13226. t['a24'] = 0x2718;
  13227. t['a25'] = 0x2719;
  13228. t['a26'] = 0x271A;
  13229. t['a27'] = 0x271B;
  13230. t['a28'] = 0x271C;
  13231. t['a6'] = 0x271D;
  13232. t['a7'] = 0x271E;
  13233. t['a8'] = 0x271F;
  13234. t['a9'] = 0x2720;
  13235. t['a10'] = 0x2721;
  13236. t['a29'] = 0x2722;
  13237. t['a30'] = 0x2723;
  13238. t['a31'] = 0x2724;
  13239. t['a32'] = 0x2725;
  13240. t['a33'] = 0x2726;
  13241. t['a34'] = 0x2727;
  13242. t['a35'] = 0x2605;
  13243. t['a36'] = 0x2729;
  13244. t['a37'] = 0x272A;
  13245. t['a38'] = 0x272B;
  13246. t['a39'] = 0x272C;
  13247. t['a40'] = 0x272D;
  13248. t['a41'] = 0x272E;
  13249. t['a42'] = 0x272F;
  13250. t['a43'] = 0x2730;
  13251. t['a44'] = 0x2731;
  13252. t['a45'] = 0x2732;
  13253. t['a46'] = 0x2733;
  13254. t['a47'] = 0x2734;
  13255. t['a48'] = 0x2735;
  13256. t['a49'] = 0x2736;
  13257. t['a50'] = 0x2737;
  13258. t['a51'] = 0x2738;
  13259. t['a52'] = 0x2739;
  13260. t['a53'] = 0x273A;
  13261. t['a54'] = 0x273B;
  13262. t['a55'] = 0x273C;
  13263. t['a56'] = 0x273D;
  13264. t['a57'] = 0x273E;
  13265. t['a58'] = 0x273F;
  13266. t['a59'] = 0x2740;
  13267. t['a60'] = 0x2741;
  13268. t['a61'] = 0x2742;
  13269. t['a62'] = 0x2743;
  13270. t['a63'] = 0x2744;
  13271. t['a64'] = 0x2745;
  13272. t['a65'] = 0x2746;
  13273. t['a66'] = 0x2747;
  13274. t['a67'] = 0x2748;
  13275. t['a68'] = 0x2749;
  13276. t['a69'] = 0x274A;
  13277. t['a70'] = 0x274B;
  13278. t['a71'] = 0x25CF;
  13279. t['a72'] = 0x274D;
  13280. t['a73'] = 0x25A0;
  13281. t['a74'] = 0x274F;
  13282. t['a203'] = 0x2750;
  13283. t['a75'] = 0x2751;
  13284. t['a204'] = 0x2752;
  13285. t['a76'] = 0x25B2;
  13286. t['a77'] = 0x25BC;
  13287. t['a78'] = 0x25C6;
  13288. t['a79'] = 0x2756;
  13289. t['a81'] = 0x25D7;
  13290. t['a82'] = 0x2758;
  13291. t['a83'] = 0x2759;
  13292. t['a84'] = 0x275A;
  13293. t['a97'] = 0x275B;
  13294. t['a98'] = 0x275C;
  13295. t['a99'] = 0x275D;
  13296. t['a100'] = 0x275E;
  13297. t['a101'] = 0x2761;
  13298. t['a102'] = 0x2762;
  13299. t['a103'] = 0x2763;
  13300. t['a104'] = 0x2764;
  13301. t['a106'] = 0x2765;
  13302. t['a107'] = 0x2766;
  13303. t['a108'] = 0x2767;
  13304. t['a112'] = 0x2663;
  13305. t['a111'] = 0x2666;
  13306. t['a110'] = 0x2665;
  13307. t['a109'] = 0x2660;
  13308. t['a120'] = 0x2460;
  13309. t['a121'] = 0x2461;
  13310. t['a122'] = 0x2462;
  13311. t['a123'] = 0x2463;
  13312. t['a124'] = 0x2464;
  13313. t['a125'] = 0x2465;
  13314. t['a126'] = 0x2466;
  13315. t['a127'] = 0x2467;
  13316. t['a128'] = 0x2468;
  13317. t['a129'] = 0x2469;
  13318. t['a130'] = 0x2776;
  13319. t['a131'] = 0x2777;
  13320. t['a132'] = 0x2778;
  13321. t['a133'] = 0x2779;
  13322. t['a134'] = 0x277A;
  13323. t['a135'] = 0x277B;
  13324. t['a136'] = 0x277C;
  13325. t['a137'] = 0x277D;
  13326. t['a138'] = 0x277E;
  13327. t['a139'] = 0x277F;
  13328. t['a140'] = 0x2780;
  13329. t['a141'] = 0x2781;
  13330. t['a142'] = 0x2782;
  13331. t['a143'] = 0x2783;
  13332. t['a144'] = 0x2784;
  13333. t['a145'] = 0x2785;
  13334. t['a146'] = 0x2786;
  13335. t['a147'] = 0x2787;
  13336. t['a148'] = 0x2788;
  13337. t['a149'] = 0x2789;
  13338. t['a150'] = 0x278A;
  13339. t['a151'] = 0x278B;
  13340. t['a152'] = 0x278C;
  13341. t['a153'] = 0x278D;
  13342. t['a154'] = 0x278E;
  13343. t['a155'] = 0x278F;
  13344. t['a156'] = 0x2790;
  13345. t['a157'] = 0x2791;
  13346. t['a158'] = 0x2792;
  13347. t['a159'] = 0x2793;
  13348. t['a160'] = 0x2794;
  13349. t['a161'] = 0x2192;
  13350. t['a163'] = 0x2194;
  13351. t['a164'] = 0x2195;
  13352. t['a196'] = 0x2798;
  13353. t['a165'] = 0x2799;
  13354. t['a192'] = 0x279A;
  13355. t['a166'] = 0x279B;
  13356. t['a167'] = 0x279C;
  13357. t['a168'] = 0x279D;
  13358. t['a169'] = 0x279E;
  13359. t['a170'] = 0x279F;
  13360. t['a171'] = 0x27A0;
  13361. t['a172'] = 0x27A1;
  13362. t['a173'] = 0x27A2;
  13363. t['a162'] = 0x27A3;
  13364. t['a174'] = 0x27A4;
  13365. t['a175'] = 0x27A5;
  13366. t['a176'] = 0x27A6;
  13367. t['a177'] = 0x27A7;
  13368. t['a178'] = 0x27A8;
  13369. t['a179'] = 0x27A9;
  13370. t['a193'] = 0x27AA;
  13371. t['a180'] = 0x27AB;
  13372. t['a199'] = 0x27AC;
  13373. t['a181'] = 0x27AD;
  13374. t['a200'] = 0x27AE;
  13375. t['a182'] = 0x27AF;
  13376. t['a201'] = 0x27B1;
  13377. t['a183'] = 0x27B2;
  13378. t['a184'] = 0x27B3;
  13379. t['a197'] = 0x27B4;
  13380. t['a185'] = 0x27B5;
  13381. t['a194'] = 0x27B6;
  13382. t['a198'] = 0x27B7;
  13383. t['a186'] = 0x27B8;
  13384. t['a195'] = 0x27B9;
  13385. t['a187'] = 0x27BA;
  13386. t['a188'] = 0x27BB;
  13387. t['a189'] = 0x27BC;
  13388. t['a190'] = 0x27BD;
  13389. t['a191'] = 0x27BE;
  13390. t['a89'] = 0x2768;
  13391. // 0xF8D7
  13392. t['a90'] = 0x2769;
  13393. // 0xF8D8
  13394. t['a93'] = 0x276A;
  13395. // 0xF8D9
  13396. t['a94'] = 0x276B;
  13397. // 0xF8DA
  13398. t['a91'] = 0x276C;
  13399. // 0xF8DB
  13400. t['a92'] = 0x276D;
  13401. // 0xF8DC
  13402. t['a205'] = 0x276E;
  13403. // 0xF8DD
  13404. t['a85'] = 0x276F;
  13405. // 0xF8DE
  13406. t['a206'] = 0x2770;
  13407. // 0xF8DF
  13408. t['a86'] = 0x2771;
  13409. // 0xF8E0
  13410. t['a87'] = 0x2772;
  13411. // 0xF8E1
  13412. t['a88'] = 0x2773;
  13413. // 0xF8E2
  13414. t['a95'] = 0x2774;
  13415. // 0xF8E3
  13416. t['a96'] = 0x2775;
  13417. // 0xF8E4
  13418. t['.notdef'] = 0x0000;
  13419. });
  13420. exports.getGlyphsUnicode = getGlyphsUnicode;
  13421. exports.getDingbatsGlyphsUnicode = getDingbatsGlyphsUnicode;
  13422. }));
  13423. (function (root, factory) {
  13424. factory(root.pdfjsCoreJbig2 = {}, root.pdfjsSharedUtil, root.pdfjsCoreArithmeticDecoder);
  13425. }(this, function (exports, sharedUtil, coreArithmeticDecoder) {
  13426. var error = sharedUtil.error;
  13427. var log2 = sharedUtil.log2;
  13428. var readInt8 = sharedUtil.readInt8;
  13429. var readUint16 = sharedUtil.readUint16;
  13430. var readUint32 = sharedUtil.readUint32;
  13431. var shadow = sharedUtil.shadow;
  13432. var ArithmeticDecoder = coreArithmeticDecoder.ArithmeticDecoder;
  13433. var Jbig2Image = function Jbig2ImageClosure() {
  13434. // Utility data structures
  13435. function ContextCache() {
  13436. }
  13437. ContextCache.prototype = {
  13438. getContexts: function (id) {
  13439. if (id in this) {
  13440. return this[id];
  13441. }
  13442. return this[id] = new Int8Array(1 << 16);
  13443. }
  13444. };
  13445. function DecodingContext(data, start, end) {
  13446. this.data = data;
  13447. this.start = start;
  13448. this.end = end;
  13449. }
  13450. DecodingContext.prototype = {
  13451. get decoder() {
  13452. var decoder = new ArithmeticDecoder(this.data, this.start, this.end);
  13453. return shadow(this, 'decoder', decoder);
  13454. },
  13455. get contextCache() {
  13456. var cache = new ContextCache();
  13457. return shadow(this, 'contextCache', cache);
  13458. }
  13459. };
  13460. // Annex A. Arithmetic Integer Decoding Procedure
  13461. // A.2 Procedure for decoding values
  13462. function decodeInteger(contextCache, procedure, decoder) {
  13463. var contexts = contextCache.getContexts(procedure);
  13464. var prev = 1;
  13465. function readBits(length) {
  13466. var v = 0;
  13467. for (var i = 0; i < length; i++) {
  13468. var bit = decoder.readBit(contexts, prev);
  13469. prev = prev < 256 ? prev << 1 | bit : (prev << 1 | bit) & 511 | 256;
  13470. v = v << 1 | bit;
  13471. }
  13472. return v >>> 0;
  13473. }
  13474. var sign = readBits(1);
  13475. 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);
  13476. return sign === 0 ? value : value > 0 ? -value : null;
  13477. }
  13478. // A.3 The IAID decoding procedure
  13479. function decodeIAID(contextCache, decoder, codeLength) {
  13480. var contexts = contextCache.getContexts('IAID');
  13481. var prev = 1;
  13482. for (var i = 0; i < codeLength; i++) {
  13483. var bit = decoder.readBit(contexts, prev);
  13484. prev = prev << 1 | bit;
  13485. }
  13486. if (codeLength < 31) {
  13487. return prev & (1 << codeLength) - 1;
  13488. }
  13489. return prev & 0x7FFFFFFF;
  13490. }
  13491. // 7.3 Segment types
  13492. var SegmentTypes = [
  13493. 'SymbolDictionary',
  13494. null,
  13495. null,
  13496. null,
  13497. 'IntermediateTextRegion',
  13498. null,
  13499. 'ImmediateTextRegion',
  13500. 'ImmediateLosslessTextRegion',
  13501. null,
  13502. null,
  13503. null,
  13504. null,
  13505. null,
  13506. null,
  13507. null,
  13508. null,
  13509. 'patternDictionary',
  13510. null,
  13511. null,
  13512. null,
  13513. 'IntermediateHalftoneRegion',
  13514. null,
  13515. 'ImmediateHalftoneRegion',
  13516. 'ImmediateLosslessHalftoneRegion',
  13517. null,
  13518. null,
  13519. null,
  13520. null,
  13521. null,
  13522. null,
  13523. null,
  13524. null,
  13525. null,
  13526. null,
  13527. null,
  13528. null,
  13529. 'IntermediateGenericRegion',
  13530. null,
  13531. 'ImmediateGenericRegion',
  13532. 'ImmediateLosslessGenericRegion',
  13533. 'IntermediateGenericRefinementRegion',
  13534. null,
  13535. 'ImmediateGenericRefinementRegion',
  13536. 'ImmediateLosslessGenericRefinementRegion',
  13537. null,
  13538. null,
  13539. null,
  13540. null,
  13541. 'PageInformation',
  13542. 'EndOfPage',
  13543. 'EndOfStripe',
  13544. 'EndOfFile',
  13545. 'Profiles',
  13546. 'Tables',
  13547. null,
  13548. null,
  13549. null,
  13550. null,
  13551. null,
  13552. null,
  13553. null,
  13554. null,
  13555. 'Extension'
  13556. ];
  13557. var CodingTemplates = [
  13558. [
  13559. {
  13560. x: -1,
  13561. y: -2
  13562. },
  13563. {
  13564. x: 0,
  13565. y: -2
  13566. },
  13567. {
  13568. x: 1,
  13569. y: -2
  13570. },
  13571. {
  13572. x: -2,
  13573. y: -1
  13574. },
  13575. {
  13576. x: -1,
  13577. y: -1
  13578. },
  13579. {
  13580. x: 0,
  13581. y: -1
  13582. },
  13583. {
  13584. x: 1,
  13585. y: -1
  13586. },
  13587. {
  13588. x: 2,
  13589. y: -1
  13590. },
  13591. {
  13592. x: -4,
  13593. y: 0
  13594. },
  13595. {
  13596. x: -3,
  13597. y: 0
  13598. },
  13599. {
  13600. x: -2,
  13601. y: 0
  13602. },
  13603. {
  13604. x: -1,
  13605. y: 0
  13606. }
  13607. ],
  13608. [
  13609. {
  13610. x: -1,
  13611. y: -2
  13612. },
  13613. {
  13614. x: 0,
  13615. y: -2
  13616. },
  13617. {
  13618. x: 1,
  13619. y: -2
  13620. },
  13621. {
  13622. x: 2,
  13623. y: -2
  13624. },
  13625. {
  13626. x: -2,
  13627. y: -1
  13628. },
  13629. {
  13630. x: -1,
  13631. y: -1
  13632. },
  13633. {
  13634. x: 0,
  13635. y: -1
  13636. },
  13637. {
  13638. x: 1,
  13639. y: -1
  13640. },
  13641. {
  13642. x: 2,
  13643. y: -1
  13644. },
  13645. {
  13646. x: -3,
  13647. y: 0
  13648. },
  13649. {
  13650. x: -2,
  13651. y: 0
  13652. },
  13653. {
  13654. x: -1,
  13655. y: 0
  13656. }
  13657. ],
  13658. [
  13659. {
  13660. x: -1,
  13661. y: -2
  13662. },
  13663. {
  13664. x: 0,
  13665. y: -2
  13666. },
  13667. {
  13668. x: 1,
  13669. y: -2
  13670. },
  13671. {
  13672. x: -2,
  13673. y: -1
  13674. },
  13675. {
  13676. x: -1,
  13677. y: -1
  13678. },
  13679. {
  13680. x: 0,
  13681. y: -1
  13682. },
  13683. {
  13684. x: 1,
  13685. y: -1
  13686. },
  13687. {
  13688. x: -2,
  13689. y: 0
  13690. },
  13691. {
  13692. x: -1,
  13693. y: 0
  13694. }
  13695. ],
  13696. [
  13697. {
  13698. x: -3,
  13699. y: -1
  13700. },
  13701. {
  13702. x: -2,
  13703. y: -1
  13704. },
  13705. {
  13706. x: -1,
  13707. y: -1
  13708. },
  13709. {
  13710. x: 0,
  13711. y: -1
  13712. },
  13713. {
  13714. x: 1,
  13715. y: -1
  13716. },
  13717. {
  13718. x: -4,
  13719. y: 0
  13720. },
  13721. {
  13722. x: -3,
  13723. y: 0
  13724. },
  13725. {
  13726. x: -2,
  13727. y: 0
  13728. },
  13729. {
  13730. x: -1,
  13731. y: 0
  13732. }
  13733. ]
  13734. ];
  13735. var RefinementTemplates = [
  13736. {
  13737. coding: [
  13738. {
  13739. x: 0,
  13740. y: -1
  13741. },
  13742. {
  13743. x: 1,
  13744. y: -1
  13745. },
  13746. {
  13747. x: -1,
  13748. y: 0
  13749. }
  13750. ],
  13751. reference: [
  13752. {
  13753. x: 0,
  13754. y: -1
  13755. },
  13756. {
  13757. x: 1,
  13758. y: -1
  13759. },
  13760. {
  13761. x: -1,
  13762. y: 0
  13763. },
  13764. {
  13765. x: 0,
  13766. y: 0
  13767. },
  13768. {
  13769. x: 1,
  13770. y: 0
  13771. },
  13772. {
  13773. x: -1,
  13774. y: 1
  13775. },
  13776. {
  13777. x: 0,
  13778. y: 1
  13779. },
  13780. {
  13781. x: 1,
  13782. y: 1
  13783. }
  13784. ]
  13785. },
  13786. {
  13787. coding: [
  13788. {
  13789. x: -1,
  13790. y: -1
  13791. },
  13792. {
  13793. x: 0,
  13794. y: -1
  13795. },
  13796. {
  13797. x: 1,
  13798. y: -1
  13799. },
  13800. {
  13801. x: -1,
  13802. y: 0
  13803. }
  13804. ],
  13805. reference: [
  13806. {
  13807. x: 0,
  13808. y: -1
  13809. },
  13810. {
  13811. x: -1,
  13812. y: 0
  13813. },
  13814. {
  13815. x: 0,
  13816. y: 0
  13817. },
  13818. {
  13819. x: 1,
  13820. y: 0
  13821. },
  13822. {
  13823. x: 0,
  13824. y: 1
  13825. },
  13826. {
  13827. x: 1,
  13828. y: 1
  13829. }
  13830. ]
  13831. }
  13832. ];
  13833. // See 6.2.5.7 Decoding the bitmap.
  13834. var ReusedContexts = [
  13835. 0x9B25,
  13836. // 10011 0110010 0101
  13837. 0x0795,
  13838. // 0011 110010 101
  13839. 0x00E5,
  13840. // 001 11001 01
  13841. 0x0195
  13842. ];
  13843. // 011001 0101
  13844. var RefinementReusedContexts = [
  13845. 0x0020,
  13846. // '000' + '0' (coding) + '00010000' + '0' (reference)
  13847. 0x0008
  13848. ];
  13849. // '0000' + '001000'
  13850. function decodeBitmapTemplate0(width, height, decodingContext) {
  13851. var decoder = decodingContext.decoder;
  13852. var contexts = decodingContext.contextCache.getContexts('GB');
  13853. var contextLabel, i, j, pixel, row, row1, row2, bitmap = [];
  13854. // ...ooooo....
  13855. // ..ooooooo... Context template for current pixel (X)
  13856. // .ooooX...... (concatenate values of 'o'-pixels to get contextLabel)
  13857. var OLD_PIXEL_MASK = 0x7BF7;
  13858. // 01111 0111111 0111
  13859. for (i = 0; i < height; i++) {
  13860. row = bitmap[i] = new Uint8Array(width);
  13861. row1 = i < 1 ? row : bitmap[i - 1];
  13862. row2 = i < 2 ? row : bitmap[i - 2];
  13863. // At the beginning of each row:
  13864. // Fill contextLabel with pixels that are above/right of (X)
  13865. contextLabel = row2[0] << 13 | row2[1] << 12 | row2[2] << 11 | row1[0] << 7 | row1[1] << 6 | row1[2] << 5 | row1[3] << 4;
  13866. for (j = 0; j < width; j++) {
  13867. row[j] = pixel = decoder.readBit(contexts, contextLabel);
  13868. // At each pixel: Clear contextLabel pixels that are shifted
  13869. // out of the context, then add new ones.
  13870. contextLabel = (contextLabel & OLD_PIXEL_MASK) << 1 | (j + 3 < width ? row2[j + 3] << 11 : 0) | (j + 4 < width ? row1[j + 4] << 4 : 0) | pixel;
  13871. }
  13872. }
  13873. return bitmap;
  13874. }
  13875. // 6.2 Generic Region Decoding Procedure
  13876. function decodeBitmap(mmr, width, height, templateIndex, prediction, skip, at, decodingContext) {
  13877. if (mmr) {
  13878. error('JBIG2 error: MMR encoding is not supported');
  13879. }
  13880. // Use optimized version for the most common case
  13881. 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) {
  13882. return decodeBitmapTemplate0(width, height, decodingContext);
  13883. }
  13884. var useskip = !!skip;
  13885. var template = CodingTemplates[templateIndex].concat(at);
  13886. // Sorting is non-standard, and it is not required. But sorting increases
  13887. // the number of template bits that can be reused from the previous
  13888. // contextLabel in the main loop.
  13889. template.sort(function (a, b) {
  13890. return a.y - b.y || a.x - b.x;
  13891. });
  13892. var templateLength = template.length;
  13893. var templateX = new Int8Array(templateLength);
  13894. var templateY = new Int8Array(templateLength);
  13895. var changingTemplateEntries = [];
  13896. var reuseMask = 0, minX = 0, maxX = 0, minY = 0;
  13897. var c, k;
  13898. for (k = 0; k < templateLength; k++) {
  13899. templateX[k] = template[k].x;
  13900. templateY[k] = template[k].y;
  13901. minX = Math.min(minX, template[k].x);
  13902. maxX = Math.max(maxX, template[k].x);
  13903. minY = Math.min(minY, template[k].y);
  13904. // Check if the template pixel appears in two consecutive context labels,
  13905. // so it can be reused. Otherwise, we add it to the list of changing
  13906. // template entries.
  13907. if (k < templateLength - 1 && template[k].y === template[k + 1].y && template[k].x === template[k + 1].x - 1) {
  13908. reuseMask |= 1 << templateLength - 1 - k;
  13909. } else {
  13910. changingTemplateEntries.push(k);
  13911. }
  13912. }
  13913. var changingEntriesLength = changingTemplateEntries.length;
  13914. var changingTemplateX = new Int8Array(changingEntriesLength);
  13915. var changingTemplateY = new Int8Array(changingEntriesLength);
  13916. var changingTemplateBit = new Uint16Array(changingEntriesLength);
  13917. for (c = 0; c < changingEntriesLength; c++) {
  13918. k = changingTemplateEntries[c];
  13919. changingTemplateX[c] = template[k].x;
  13920. changingTemplateY[c] = template[k].y;
  13921. changingTemplateBit[c] = 1 << templateLength - 1 - k;
  13922. }
  13923. // Get the safe bounding box edges from the width, height, minX, maxX, minY
  13924. var sbb_left = -minX;
  13925. var sbb_top = -minY;
  13926. var sbb_right = width - maxX;
  13927. var pseudoPixelContext = ReusedContexts[templateIndex];
  13928. var row = new Uint8Array(width);
  13929. var bitmap = [];
  13930. var decoder = decodingContext.decoder;
  13931. var contexts = decodingContext.contextCache.getContexts('GB');
  13932. var ltp = 0, j, i0, j0, contextLabel = 0, bit, shift;
  13933. for (var i = 0; i < height; i++) {
  13934. if (prediction) {
  13935. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  13936. ltp ^= sltp;
  13937. if (ltp) {
  13938. bitmap.push(row);
  13939. // duplicate previous row
  13940. continue;
  13941. }
  13942. }
  13943. row = new Uint8Array(row);
  13944. bitmap.push(row);
  13945. for (j = 0; j < width; j++) {
  13946. if (useskip && skip[i][j]) {
  13947. row[j] = 0;
  13948. continue;
  13949. }
  13950. // Are we in the middle of a scanline, so we can reuse contextLabel
  13951. // bits?
  13952. if (j >= sbb_left && j < sbb_right && i >= sbb_top) {
  13953. // If yes, we can just shift the bits that are reusable and only
  13954. // fetch the remaining ones.
  13955. contextLabel = contextLabel << 1 & reuseMask;
  13956. for (k = 0; k < changingEntriesLength; k++) {
  13957. i0 = i + changingTemplateY[k];
  13958. j0 = j + changingTemplateX[k];
  13959. bit = bitmap[i0][j0];
  13960. if (bit) {
  13961. bit = changingTemplateBit[k];
  13962. contextLabel |= bit;
  13963. }
  13964. }
  13965. } else {
  13966. // compute the contextLabel from scratch
  13967. contextLabel = 0;
  13968. shift = templateLength - 1;
  13969. for (k = 0; k < templateLength; k++, shift--) {
  13970. j0 = j + templateX[k];
  13971. if (j0 >= 0 && j0 < width) {
  13972. i0 = i + templateY[k];
  13973. if (i0 >= 0) {
  13974. bit = bitmap[i0][j0];
  13975. if (bit) {
  13976. contextLabel |= bit << shift;
  13977. }
  13978. }
  13979. }
  13980. }
  13981. }
  13982. var pixel = decoder.readBit(contexts, contextLabel);
  13983. row[j] = pixel;
  13984. }
  13985. }
  13986. return bitmap;
  13987. }
  13988. // 6.3.2 Generic Refinement Region Decoding Procedure
  13989. function decodeRefinement(width, height, templateIndex, referenceBitmap, offsetX, offsetY, prediction, at, decodingContext) {
  13990. var codingTemplate = RefinementTemplates[templateIndex].coding;
  13991. if (templateIndex === 0) {
  13992. codingTemplate = codingTemplate.concat([at[0]]);
  13993. }
  13994. var codingTemplateLength = codingTemplate.length;
  13995. var codingTemplateX = new Int32Array(codingTemplateLength);
  13996. var codingTemplateY = new Int32Array(codingTemplateLength);
  13997. var k;
  13998. for (k = 0; k < codingTemplateLength; k++) {
  13999. codingTemplateX[k] = codingTemplate[k].x;
  14000. codingTemplateY[k] = codingTemplate[k].y;
  14001. }
  14002. var referenceTemplate = RefinementTemplates[templateIndex].reference;
  14003. if (templateIndex === 0) {
  14004. referenceTemplate = referenceTemplate.concat([at[1]]);
  14005. }
  14006. var referenceTemplateLength = referenceTemplate.length;
  14007. var referenceTemplateX = new Int32Array(referenceTemplateLength);
  14008. var referenceTemplateY = new Int32Array(referenceTemplateLength);
  14009. for (k = 0; k < referenceTemplateLength; k++) {
  14010. referenceTemplateX[k] = referenceTemplate[k].x;
  14011. referenceTemplateY[k] = referenceTemplate[k].y;
  14012. }
  14013. var referenceWidth = referenceBitmap[0].length;
  14014. var referenceHeight = referenceBitmap.length;
  14015. var pseudoPixelContext = RefinementReusedContexts[templateIndex];
  14016. var bitmap = [];
  14017. var decoder = decodingContext.decoder;
  14018. var contexts = decodingContext.contextCache.getContexts('GR');
  14019. var ltp = 0;
  14020. for (var i = 0; i < height; i++) {
  14021. if (prediction) {
  14022. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  14023. ltp ^= sltp;
  14024. if (ltp) {
  14025. error('JBIG2 error: prediction is not supported');
  14026. }
  14027. }
  14028. var row = new Uint8Array(width);
  14029. bitmap.push(row);
  14030. for (var j = 0; j < width; j++) {
  14031. var i0, j0;
  14032. var contextLabel = 0;
  14033. for (k = 0; k < codingTemplateLength; k++) {
  14034. i0 = i + codingTemplateY[k];
  14035. j0 = j + codingTemplateX[k];
  14036. if (i0 < 0 || j0 < 0 || j0 >= width) {
  14037. contextLabel <<= 1;
  14038. } else
  14039. // out of bound pixel
  14040. {
  14041. contextLabel = contextLabel << 1 | bitmap[i0][j0];
  14042. }
  14043. }
  14044. for (k = 0; k < referenceTemplateLength; k++) {
  14045. i0 = i + referenceTemplateY[k] + offsetY;
  14046. j0 = j + referenceTemplateX[k] + offsetX;
  14047. if (i0 < 0 || i0 >= referenceHeight || j0 < 0 || j0 >= referenceWidth) {
  14048. contextLabel <<= 1;
  14049. } else
  14050. // out of bound pixel
  14051. {
  14052. contextLabel = contextLabel << 1 | referenceBitmap[i0][j0];
  14053. }
  14054. }
  14055. var pixel = decoder.readBit(contexts, contextLabel);
  14056. row[j] = pixel;
  14057. }
  14058. }
  14059. return bitmap;
  14060. }
  14061. // 6.5.5 Decoding the symbol dictionary
  14062. function decodeSymbolDictionary(huffman, refinement, symbols, numberOfNewSymbols, numberOfExportedSymbols, huffmanTables, templateIndex, at, refinementTemplateIndex, refinementAt, decodingContext) {
  14063. if (huffman) {
  14064. error('JBIG2 error: huffman is not supported');
  14065. }
  14066. var newSymbols = [];
  14067. var currentHeight = 0;
  14068. var symbolCodeLength = log2(symbols.length + numberOfNewSymbols);
  14069. var decoder = decodingContext.decoder;
  14070. var contextCache = decodingContext.contextCache;
  14071. while (newSymbols.length < numberOfNewSymbols) {
  14072. var deltaHeight = decodeInteger(contextCache, 'IADH', decoder);
  14073. // 6.5.6
  14074. currentHeight += deltaHeight;
  14075. var currentWidth = 0;
  14076. var totalWidth = 0;
  14077. while (true) {
  14078. var deltaWidth = decodeInteger(contextCache, 'IADW', decoder);
  14079. // 6.5.7
  14080. if (deltaWidth === null) {
  14081. break;
  14082. }
  14083. // OOB
  14084. currentWidth += deltaWidth;
  14085. totalWidth += currentWidth;
  14086. var bitmap;
  14087. if (refinement) {
  14088. // 6.5.8.2 Refinement/aggregate-coded symbol bitmap
  14089. var numberOfInstances = decodeInteger(contextCache, 'IAAI', decoder);
  14090. if (numberOfInstances > 1) {
  14091. bitmap = decodeTextRegion(huffman, refinement, currentWidth, currentHeight, 0, numberOfInstances, 1, //strip size
  14092. symbols.concat(newSymbols), symbolCodeLength, 0, //transposed
  14093. 0, //ds offset
  14094. 1, //top left 7.4.3.1.1
  14095. 0, //OR operator
  14096. huffmanTables, refinementTemplateIndex, refinementAt, decodingContext);
  14097. } else {
  14098. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  14099. var rdx = decodeInteger(contextCache, 'IARDX', decoder);
  14100. // 6.4.11.3
  14101. var rdy = decodeInteger(contextCache, 'IARDY', decoder);
  14102. // 6.4.11.4
  14103. var symbol = symbolId < symbols.length ? symbols[symbolId] : newSymbols[symbolId - symbols.length];
  14104. bitmap = decodeRefinement(currentWidth, currentHeight, refinementTemplateIndex, symbol, rdx, rdy, false, refinementAt, decodingContext);
  14105. }
  14106. } else {
  14107. // 6.5.8.1 Direct-coded symbol bitmap
  14108. bitmap = decodeBitmap(false, currentWidth, currentHeight, templateIndex, false, null, at, decodingContext);
  14109. }
  14110. newSymbols.push(bitmap);
  14111. }
  14112. }
  14113. // 6.5.10 Exported symbols
  14114. var exportedSymbols = [];
  14115. var flags = [], currentFlag = false;
  14116. var totalSymbolsLength = symbols.length + numberOfNewSymbols;
  14117. while (flags.length < totalSymbolsLength) {
  14118. var runLength = decodeInteger(contextCache, 'IAEX', decoder);
  14119. while (runLength--) {
  14120. flags.push(currentFlag);
  14121. }
  14122. currentFlag = !currentFlag;
  14123. }
  14124. for (var i = 0, ii = symbols.length; i < ii; i++) {
  14125. if (flags[i]) {
  14126. exportedSymbols.push(symbols[i]);
  14127. }
  14128. }
  14129. for (var j = 0; j < numberOfNewSymbols; i++, j++) {
  14130. if (flags[i]) {
  14131. exportedSymbols.push(newSymbols[j]);
  14132. }
  14133. }
  14134. return exportedSymbols;
  14135. }
  14136. function decodeTextRegion(huffman, refinement, width, height, defaultPixelValue, numberOfSymbolInstances, stripSize, inputSymbols, symbolCodeLength, transposed, dsOffset, referenceCorner, combinationOperator, huffmanTables, refinementTemplateIndex, refinementAt, decodingContext) {
  14137. if (huffman) {
  14138. error('JBIG2 error: huffman is not supported');
  14139. }
  14140. // Prepare bitmap
  14141. var bitmap = [];
  14142. var i, row;
  14143. for (i = 0; i < height; i++) {
  14144. row = new Uint8Array(width);
  14145. if (defaultPixelValue) {
  14146. for (var j = 0; j < width; j++) {
  14147. row[j] = defaultPixelValue;
  14148. }
  14149. }
  14150. bitmap.push(row);
  14151. }
  14152. var decoder = decodingContext.decoder;
  14153. var contextCache = decodingContext.contextCache;
  14154. var stripT = -decodeInteger(contextCache, 'IADT', decoder);
  14155. // 6.4.6
  14156. var firstS = 0;
  14157. i = 0;
  14158. while (i < numberOfSymbolInstances) {
  14159. var deltaT = decodeInteger(contextCache, 'IADT', decoder);
  14160. // 6.4.6
  14161. stripT += deltaT;
  14162. var deltaFirstS = decodeInteger(contextCache, 'IAFS', decoder);
  14163. // 6.4.7
  14164. firstS += deltaFirstS;
  14165. var currentS = firstS;
  14166. do {
  14167. var currentT = stripSize === 1 ? 0 : decodeInteger(contextCache, 'IAIT', decoder);
  14168. // 6.4.9
  14169. var t = stripSize * stripT + currentT;
  14170. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  14171. var applyRefinement = refinement && decodeInteger(contextCache, 'IARI', decoder);
  14172. var symbolBitmap = inputSymbols[symbolId];
  14173. var symbolWidth = symbolBitmap[0].length;
  14174. var symbolHeight = symbolBitmap.length;
  14175. if (applyRefinement) {
  14176. var rdw = decodeInteger(contextCache, 'IARDW', decoder);
  14177. // 6.4.11.1
  14178. var rdh = decodeInteger(contextCache, 'IARDH', decoder);
  14179. // 6.4.11.2
  14180. var rdx = decodeInteger(contextCache, 'IARDX', decoder);
  14181. // 6.4.11.3
  14182. var rdy = decodeInteger(contextCache, 'IARDY', decoder);
  14183. // 6.4.11.4
  14184. symbolWidth += rdw;
  14185. symbolHeight += rdh;
  14186. symbolBitmap = decodeRefinement(symbolWidth, symbolHeight, refinementTemplateIndex, symbolBitmap, (rdw >> 1) + rdx, (rdh >> 1) + rdy, false, refinementAt, decodingContext);
  14187. }
  14188. var offsetT = t - (referenceCorner & 1 ? 0 : symbolHeight);
  14189. var offsetS = currentS - (referenceCorner & 2 ? symbolWidth : 0);
  14190. var s2, t2, symbolRow;
  14191. if (transposed) {
  14192. // Place Symbol Bitmap from T1,S1
  14193. for (s2 = 0; s2 < symbolHeight; s2++) {
  14194. row = bitmap[offsetS + s2];
  14195. if (!row) {
  14196. continue;
  14197. }
  14198. symbolRow = symbolBitmap[s2];
  14199. // To ignore Parts of Symbol bitmap which goes
  14200. // outside bitmap region
  14201. var maxWidth = Math.min(width - offsetT, symbolWidth);
  14202. switch (combinationOperator) {
  14203. case 0:
  14204. // OR
  14205. for (t2 = 0; t2 < maxWidth; t2++) {
  14206. row[offsetT + t2] |= symbolRow[t2];
  14207. }
  14208. break;
  14209. case 2:
  14210. // XOR
  14211. for (t2 = 0; t2 < maxWidth; t2++) {
  14212. row[offsetT + t2] ^= symbolRow[t2];
  14213. }
  14214. break;
  14215. default:
  14216. error('JBIG2 error: operator ' + combinationOperator + ' is not supported');
  14217. }
  14218. }
  14219. currentS += symbolHeight - 1;
  14220. } else {
  14221. for (t2 = 0; t2 < symbolHeight; t2++) {
  14222. row = bitmap[offsetT + t2];
  14223. if (!row) {
  14224. continue;
  14225. }
  14226. symbolRow = symbolBitmap[t2];
  14227. switch (combinationOperator) {
  14228. case 0:
  14229. // OR
  14230. for (s2 = 0; s2 < symbolWidth; s2++) {
  14231. row[offsetS + s2] |= symbolRow[s2];
  14232. }
  14233. break;
  14234. case 2:
  14235. // XOR
  14236. for (s2 = 0; s2 < symbolWidth; s2++) {
  14237. row[offsetS + s2] ^= symbolRow[s2];
  14238. }
  14239. break;
  14240. default:
  14241. error('JBIG2 error: operator ' + combinationOperator + ' is not supported');
  14242. }
  14243. }
  14244. currentS += symbolWidth - 1;
  14245. }
  14246. i++;
  14247. var deltaS = decodeInteger(contextCache, 'IADS', decoder);
  14248. // 6.4.8
  14249. if (deltaS === null) {
  14250. break;
  14251. }
  14252. // OOB
  14253. currentS += deltaS + dsOffset;
  14254. } while (true);
  14255. }
  14256. return bitmap;
  14257. }
  14258. function readSegmentHeader(data, start) {
  14259. var segmentHeader = {};
  14260. segmentHeader.number = readUint32(data, start);
  14261. var flags = data[start + 4];
  14262. var segmentType = flags & 0x3F;
  14263. if (!SegmentTypes[segmentType]) {
  14264. error('JBIG2 error: invalid segment type: ' + segmentType);
  14265. }
  14266. segmentHeader.type = segmentType;
  14267. segmentHeader.typeName = SegmentTypes[segmentType];
  14268. segmentHeader.deferredNonRetain = !!(flags & 0x80);
  14269. var pageAssociationFieldSize = !!(flags & 0x40);
  14270. var referredFlags = data[start + 5];
  14271. var referredToCount = referredFlags >> 5 & 7;
  14272. var retainBits = [referredFlags & 31];
  14273. var position = start + 6;
  14274. if (referredFlags === 7) {
  14275. referredToCount = readUint32(data, position - 1) & 0x1FFFFFFF;
  14276. position += 3;
  14277. var bytes = referredToCount + 7 >> 3;
  14278. retainBits[0] = data[position++];
  14279. while (--bytes > 0) {
  14280. retainBits.push(data[position++]);
  14281. }
  14282. } else if (referredFlags === 5 || referredFlags === 6) {
  14283. error('JBIG2 error: invalid referred-to flags');
  14284. }
  14285. segmentHeader.retainBits = retainBits;
  14286. var referredToSegmentNumberSize = segmentHeader.number <= 256 ? 1 : segmentHeader.number <= 65536 ? 2 : 4;
  14287. var referredTo = [];
  14288. var i, ii;
  14289. for (i = 0; i < referredToCount; i++) {
  14290. var number = referredToSegmentNumberSize === 1 ? data[position] : referredToSegmentNumberSize === 2 ? readUint16(data, position) : readUint32(data, position);
  14291. referredTo.push(number);
  14292. position += referredToSegmentNumberSize;
  14293. }
  14294. segmentHeader.referredTo = referredTo;
  14295. if (!pageAssociationFieldSize) {
  14296. segmentHeader.pageAssociation = data[position++];
  14297. } else {
  14298. segmentHeader.pageAssociation = readUint32(data, position);
  14299. position += 4;
  14300. }
  14301. segmentHeader.length = readUint32(data, position);
  14302. position += 4;
  14303. if (segmentHeader.length === 0xFFFFFFFF) {
  14304. // 7.2.7 Segment data length, unknown segment length
  14305. if (segmentType === 38) {
  14306. // ImmediateGenericRegion
  14307. var genericRegionInfo = readRegionSegmentInformation(data, position);
  14308. var genericRegionSegmentFlags = data[position + RegionSegmentInformationFieldLength];
  14309. var genericRegionMmr = !!(genericRegionSegmentFlags & 1);
  14310. // searching for the segment end
  14311. var searchPatternLength = 6;
  14312. var searchPattern = new Uint8Array(searchPatternLength);
  14313. if (!genericRegionMmr) {
  14314. searchPattern[0] = 0xFF;
  14315. searchPattern[1] = 0xAC;
  14316. }
  14317. searchPattern[2] = genericRegionInfo.height >>> 24 & 0xFF;
  14318. searchPattern[3] = genericRegionInfo.height >> 16 & 0xFF;
  14319. searchPattern[4] = genericRegionInfo.height >> 8 & 0xFF;
  14320. searchPattern[5] = genericRegionInfo.height & 0xFF;
  14321. for (i = position, ii = data.length; i < ii; i++) {
  14322. var j = 0;
  14323. while (j < searchPatternLength && searchPattern[j] === data[i + j]) {
  14324. j++;
  14325. }
  14326. if (j === searchPatternLength) {
  14327. segmentHeader.length = i + searchPatternLength;
  14328. break;
  14329. }
  14330. }
  14331. if (segmentHeader.length === 0xFFFFFFFF) {
  14332. error('JBIG2 error: segment end was not found');
  14333. }
  14334. } else {
  14335. error('JBIG2 error: invalid unknown segment length');
  14336. }
  14337. }
  14338. segmentHeader.headerEnd = position;
  14339. return segmentHeader;
  14340. }
  14341. function readSegments(header, data, start, end) {
  14342. var segments = [];
  14343. var position = start;
  14344. while (position < end) {
  14345. var segmentHeader = readSegmentHeader(data, position);
  14346. position = segmentHeader.headerEnd;
  14347. var segment = {
  14348. header: segmentHeader,
  14349. data: data
  14350. };
  14351. if (!header.randomAccess) {
  14352. segment.start = position;
  14353. position += segmentHeader.length;
  14354. segment.end = position;
  14355. }
  14356. segments.push(segment);
  14357. if (segmentHeader.type === 51) {
  14358. break;
  14359. }
  14360. }
  14361. // end of file is found
  14362. if (header.randomAccess) {
  14363. for (var i = 0, ii = segments.length; i < ii; i++) {
  14364. segments[i].start = position;
  14365. position += segments[i].header.length;
  14366. segments[i].end = position;
  14367. }
  14368. }
  14369. return segments;
  14370. }
  14371. // 7.4.1 Region segment information field
  14372. function readRegionSegmentInformation(data, start) {
  14373. return {
  14374. width: readUint32(data, start),
  14375. height: readUint32(data, start + 4),
  14376. x: readUint32(data, start + 8),
  14377. y: readUint32(data, start + 12),
  14378. combinationOperator: data[start + 16] & 7
  14379. };
  14380. }
  14381. var RegionSegmentInformationFieldLength = 17;
  14382. function processSegment(segment, visitor) {
  14383. var header = segment.header;
  14384. var data = segment.data, position = segment.start, end = segment.end;
  14385. var args, at, i, atLength;
  14386. switch (header.type) {
  14387. case 0:
  14388. // SymbolDictionary
  14389. // 7.4.2 Symbol dictionary segment syntax
  14390. var dictionary = {};
  14391. var dictionaryFlags = readUint16(data, position);
  14392. // 7.4.2.1.1
  14393. dictionary.huffman = !!(dictionaryFlags & 1);
  14394. dictionary.refinement = !!(dictionaryFlags & 2);
  14395. dictionary.huffmanDHSelector = dictionaryFlags >> 2 & 3;
  14396. dictionary.huffmanDWSelector = dictionaryFlags >> 4 & 3;
  14397. dictionary.bitmapSizeSelector = dictionaryFlags >> 6 & 1;
  14398. dictionary.aggregationInstancesSelector = dictionaryFlags >> 7 & 1;
  14399. dictionary.bitmapCodingContextUsed = !!(dictionaryFlags & 256);
  14400. dictionary.bitmapCodingContextRetained = !!(dictionaryFlags & 512);
  14401. dictionary.template = dictionaryFlags >> 10 & 3;
  14402. dictionary.refinementTemplate = dictionaryFlags >> 12 & 1;
  14403. position += 2;
  14404. if (!dictionary.huffman) {
  14405. atLength = dictionary.template === 0 ? 4 : 1;
  14406. at = [];
  14407. for (i = 0; i < atLength; i++) {
  14408. at.push({
  14409. x: readInt8(data, position),
  14410. y: readInt8(data, position + 1)
  14411. });
  14412. position += 2;
  14413. }
  14414. dictionary.at = at;
  14415. }
  14416. if (dictionary.refinement && !dictionary.refinementTemplate) {
  14417. at = [];
  14418. for (i = 0; i < 2; i++) {
  14419. at.push({
  14420. x: readInt8(data, position),
  14421. y: readInt8(data, position + 1)
  14422. });
  14423. position += 2;
  14424. }
  14425. dictionary.refinementAt = at;
  14426. }
  14427. dictionary.numberOfExportedSymbols = readUint32(data, position);
  14428. position += 4;
  14429. dictionary.numberOfNewSymbols = readUint32(data, position);
  14430. position += 4;
  14431. args = [
  14432. dictionary,
  14433. header.number,
  14434. header.referredTo,
  14435. data,
  14436. position,
  14437. end
  14438. ];
  14439. break;
  14440. case 6:
  14441. // ImmediateTextRegion
  14442. case 7:
  14443. // ImmediateLosslessTextRegion
  14444. var textRegion = {};
  14445. textRegion.info = readRegionSegmentInformation(data, position);
  14446. position += RegionSegmentInformationFieldLength;
  14447. var textRegionSegmentFlags = readUint16(data, position);
  14448. position += 2;
  14449. textRegion.huffman = !!(textRegionSegmentFlags & 1);
  14450. textRegion.refinement = !!(textRegionSegmentFlags & 2);
  14451. textRegion.stripSize = 1 << (textRegionSegmentFlags >> 2 & 3);
  14452. textRegion.referenceCorner = textRegionSegmentFlags >> 4 & 3;
  14453. textRegion.transposed = !!(textRegionSegmentFlags & 64);
  14454. textRegion.combinationOperator = textRegionSegmentFlags >> 7 & 3;
  14455. textRegion.defaultPixelValue = textRegionSegmentFlags >> 9 & 1;
  14456. textRegion.dsOffset = textRegionSegmentFlags << 17 >> 27;
  14457. textRegion.refinementTemplate = textRegionSegmentFlags >> 15 & 1;
  14458. if (textRegion.huffman) {
  14459. var textRegionHuffmanFlags = readUint16(data, position);
  14460. position += 2;
  14461. textRegion.huffmanFS = textRegionHuffmanFlags & 3;
  14462. textRegion.huffmanDS = textRegionHuffmanFlags >> 2 & 3;
  14463. textRegion.huffmanDT = textRegionHuffmanFlags >> 4 & 3;
  14464. textRegion.huffmanRefinementDW = textRegionHuffmanFlags >> 6 & 3;
  14465. textRegion.huffmanRefinementDH = textRegionHuffmanFlags >> 8 & 3;
  14466. textRegion.huffmanRefinementDX = textRegionHuffmanFlags >> 10 & 3;
  14467. textRegion.huffmanRefinementDY = textRegionHuffmanFlags >> 12 & 3;
  14468. textRegion.huffmanRefinementSizeSelector = !!(textRegionHuffmanFlags & 14);
  14469. }
  14470. if (textRegion.refinement && !textRegion.refinementTemplate) {
  14471. at = [];
  14472. for (i = 0; i < 2; i++) {
  14473. at.push({
  14474. x: readInt8(data, position),
  14475. y: readInt8(data, position + 1)
  14476. });
  14477. position += 2;
  14478. }
  14479. textRegion.refinementAt = at;
  14480. }
  14481. textRegion.numberOfSymbolInstances = readUint32(data, position);
  14482. position += 4;
  14483. // TODO 7.4.3.1.7 Symbol ID Huffman table decoding
  14484. if (textRegion.huffman) {
  14485. error('JBIG2 error: huffman is not supported');
  14486. }
  14487. args = [
  14488. textRegion,
  14489. header.referredTo,
  14490. data,
  14491. position,
  14492. end
  14493. ];
  14494. break;
  14495. case 38:
  14496. // ImmediateGenericRegion
  14497. case 39:
  14498. // ImmediateLosslessGenericRegion
  14499. var genericRegion = {};
  14500. genericRegion.info = readRegionSegmentInformation(data, position);
  14501. position += RegionSegmentInformationFieldLength;
  14502. var genericRegionSegmentFlags = data[position++];
  14503. genericRegion.mmr = !!(genericRegionSegmentFlags & 1);
  14504. genericRegion.template = genericRegionSegmentFlags >> 1 & 3;
  14505. genericRegion.prediction = !!(genericRegionSegmentFlags & 8);
  14506. if (!genericRegion.mmr) {
  14507. atLength = genericRegion.template === 0 ? 4 : 1;
  14508. at = [];
  14509. for (i = 0; i < atLength; i++) {
  14510. at.push({
  14511. x: readInt8(data, position),
  14512. y: readInt8(data, position + 1)
  14513. });
  14514. position += 2;
  14515. }
  14516. genericRegion.at = at;
  14517. }
  14518. args = [
  14519. genericRegion,
  14520. data,
  14521. position,
  14522. end
  14523. ];
  14524. break;
  14525. case 48:
  14526. // PageInformation
  14527. var pageInfo = {
  14528. width: readUint32(data, position),
  14529. height: readUint32(data, position + 4),
  14530. resolutionX: readUint32(data, position + 8),
  14531. resolutionY: readUint32(data, position + 12)
  14532. };
  14533. if (pageInfo.height === 0xFFFFFFFF) {
  14534. delete pageInfo.height;
  14535. }
  14536. var pageSegmentFlags = data[position + 16];
  14537. var pageStripingInformation = readUint16(data, position + 17);
  14538. pageInfo.lossless = !!(pageSegmentFlags & 1);
  14539. pageInfo.refinement = !!(pageSegmentFlags & 2);
  14540. pageInfo.defaultPixelValue = pageSegmentFlags >> 2 & 1;
  14541. pageInfo.combinationOperator = pageSegmentFlags >> 3 & 3;
  14542. pageInfo.requiresBuffer = !!(pageSegmentFlags & 32);
  14543. pageInfo.combinationOperatorOverride = !!(pageSegmentFlags & 64);
  14544. args = [pageInfo];
  14545. break;
  14546. case 49:
  14547. // EndOfPage
  14548. break;
  14549. case 50:
  14550. // EndOfStripe
  14551. break;
  14552. case 51:
  14553. // EndOfFile
  14554. break;
  14555. case 62:
  14556. // 7.4.15 defines 2 extension types which
  14557. // are comments and can be ignored.
  14558. break;
  14559. default:
  14560. error('JBIG2 error: segment type ' + header.typeName + '(' + header.type + ') is not implemented');
  14561. }
  14562. var callbackName = 'on' + header.typeName;
  14563. if (callbackName in visitor) {
  14564. visitor[callbackName].apply(visitor, args);
  14565. }
  14566. }
  14567. function processSegments(segments, visitor) {
  14568. for (var i = 0, ii = segments.length; i < ii; i++) {
  14569. processSegment(segments[i], visitor);
  14570. }
  14571. }
  14572. function parseJbig2(data, start, end) {
  14573. var position = start;
  14574. 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) {
  14575. error('JBIG2 error: invalid header');
  14576. }
  14577. var header = {};
  14578. position += 8;
  14579. var flags = data[position++];
  14580. header.randomAccess = !(flags & 1);
  14581. if (!(flags & 2)) {
  14582. header.numberOfPages = readUint32(data, position);
  14583. position += 4;
  14584. }
  14585. var segments = readSegments(header, data, position, end);
  14586. error('Not implemented');
  14587. }
  14588. // processSegments(segments, new SimpleSegmentVisitor());
  14589. function parseJbig2Chunks(chunks) {
  14590. var visitor = new SimpleSegmentVisitor();
  14591. for (var i = 0, ii = chunks.length; i < ii; i++) {
  14592. var chunk = chunks[i];
  14593. var segments = readSegments({}, chunk.data, chunk.start, chunk.end);
  14594. processSegments(segments, visitor);
  14595. }
  14596. return visitor.buffer;
  14597. }
  14598. function SimpleSegmentVisitor() {
  14599. }
  14600. SimpleSegmentVisitor.prototype = {
  14601. onPageInformation: function SimpleSegmentVisitor_onPageInformation(info) {
  14602. this.currentPageInfo = info;
  14603. var rowSize = info.width + 7 >> 3;
  14604. var buffer = new Uint8Array(rowSize * info.height);
  14605. // The contents of ArrayBuffers are initialized to 0.
  14606. // Fill the buffer with 0xFF only if info.defaultPixelValue is set
  14607. if (info.defaultPixelValue) {
  14608. for (var i = 0, ii = buffer.length; i < ii; i++) {
  14609. buffer[i] = 0xFF;
  14610. }
  14611. }
  14612. this.buffer = buffer;
  14613. },
  14614. drawBitmap: function SimpleSegmentVisitor_drawBitmap(regionInfo, bitmap) {
  14615. var pageInfo = this.currentPageInfo;
  14616. var width = regionInfo.width, height = regionInfo.height;
  14617. var rowSize = pageInfo.width + 7 >> 3;
  14618. var combinationOperator = pageInfo.combinationOperatorOverride ? regionInfo.combinationOperator : pageInfo.combinationOperator;
  14619. var buffer = this.buffer;
  14620. var mask0 = 128 >> (regionInfo.x & 7);
  14621. var offset0 = regionInfo.y * rowSize + (regionInfo.x >> 3);
  14622. var i, j, mask, offset;
  14623. switch (combinationOperator) {
  14624. case 0:
  14625. // OR
  14626. for (i = 0; i < height; i++) {
  14627. mask = mask0;
  14628. offset = offset0;
  14629. for (j = 0; j < width; j++) {
  14630. if (bitmap[i][j]) {
  14631. buffer[offset] |= mask;
  14632. }
  14633. mask >>= 1;
  14634. if (!mask) {
  14635. mask = 128;
  14636. offset++;
  14637. }
  14638. }
  14639. offset0 += rowSize;
  14640. }
  14641. break;
  14642. case 2:
  14643. // XOR
  14644. for (i = 0; i < height; i++) {
  14645. mask = mask0;
  14646. offset = offset0;
  14647. for (j = 0; j < width; j++) {
  14648. if (bitmap[i][j]) {
  14649. buffer[offset] ^= mask;
  14650. }
  14651. mask >>= 1;
  14652. if (!mask) {
  14653. mask = 128;
  14654. offset++;
  14655. }
  14656. }
  14657. offset0 += rowSize;
  14658. }
  14659. break;
  14660. default:
  14661. error('JBIG2 error: operator ' + combinationOperator + ' is not supported');
  14662. }
  14663. },
  14664. onImmediateGenericRegion: function SimpleSegmentVisitor_onImmediateGenericRegion(region, data, start, end) {
  14665. var regionInfo = region.info;
  14666. var decodingContext = new DecodingContext(data, start, end);
  14667. var bitmap = decodeBitmap(region.mmr, regionInfo.width, regionInfo.height, region.template, region.prediction, null, region.at, decodingContext);
  14668. this.drawBitmap(regionInfo, bitmap);
  14669. },
  14670. onImmediateLosslessGenericRegion: function SimpleSegmentVisitor_onImmediateLosslessGenericRegion() {
  14671. this.onImmediateGenericRegion.apply(this, arguments);
  14672. },
  14673. onSymbolDictionary: function SimpleSegmentVisitor_onSymbolDictionary(dictionary, currentSegment, referredSegments, data, start, end) {
  14674. var huffmanTables;
  14675. if (dictionary.huffman) {
  14676. error('JBIG2 error: huffman is not supported');
  14677. }
  14678. // Combines exported symbols from all referred segments
  14679. var symbols = this.symbols;
  14680. if (!symbols) {
  14681. this.symbols = symbols = {};
  14682. }
  14683. var inputSymbols = [];
  14684. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  14685. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  14686. }
  14687. var decodingContext = new DecodingContext(data, start, end);
  14688. symbols[currentSegment] = decodeSymbolDictionary(dictionary.huffman, dictionary.refinement, inputSymbols, dictionary.numberOfNewSymbols, dictionary.numberOfExportedSymbols, huffmanTables, dictionary.template, dictionary.at, dictionary.refinementTemplate, dictionary.refinementAt, decodingContext);
  14689. },
  14690. onImmediateTextRegion: function SimpleSegmentVisitor_onImmediateTextRegion(region, referredSegments, data, start, end) {
  14691. var regionInfo = region.info;
  14692. var huffmanTables;
  14693. // Combines exported symbols from all referred segments
  14694. var symbols = this.symbols;
  14695. var inputSymbols = [];
  14696. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  14697. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  14698. }
  14699. var symbolCodeLength = log2(inputSymbols.length);
  14700. var decodingContext = new DecodingContext(data, start, end);
  14701. 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);
  14702. this.drawBitmap(regionInfo, bitmap);
  14703. },
  14704. onImmediateLosslessTextRegion: function SimpleSegmentVisitor_onImmediateLosslessTextRegion() {
  14705. this.onImmediateTextRegion.apply(this, arguments);
  14706. }
  14707. };
  14708. function Jbig2Image() {
  14709. }
  14710. Jbig2Image.prototype = {
  14711. parseChunks: function Jbig2Image_parseChunks(chunks) {
  14712. return parseJbig2Chunks(chunks);
  14713. }
  14714. };
  14715. return Jbig2Image;
  14716. }();
  14717. exports.Jbig2Image = Jbig2Image;
  14718. }));
  14719. (function (root, factory) {
  14720. factory(root.pdfjsCoreJpg = {}, root.pdfjsSharedUtil);
  14721. }(this, function (exports, sharedUtil) {
  14722. var error = sharedUtil.error;
  14723. /**
  14724. * This code was forked from https://github.com/notmasteryet/jpgjs.
  14725. * The original version was created by GitHub user notmasteryet.
  14726. *
  14727. * - The JPEG specification can be found in the ITU CCITT Recommendation T.81
  14728. * (www.w3.org/Graphics/JPEG/itu-t81.pdf)
  14729. * - The JFIF specification can be found in the JPEG File Interchange Format
  14730. * (www.w3.org/Graphics/JPEG/jfif3.pdf)
  14731. * - The Adobe Application-Specific JPEG markers in the
  14732. * Supporting the DCT Filters in PostScript Level 2, Technical Note #5116
  14733. * (partners.adobe.com/public/developer/en/ps/sdk/5116.DCT_Filter.pdf)
  14734. */
  14735. var JpegImage = function JpegImageClosure() {
  14736. var dctZigZag = new Uint8Array([
  14737. 0,
  14738. 1,
  14739. 8,
  14740. 16,
  14741. 9,
  14742. 2,
  14743. 3,
  14744. 10,
  14745. 17,
  14746. 24,
  14747. 32,
  14748. 25,
  14749. 18,
  14750. 11,
  14751. 4,
  14752. 5,
  14753. 12,
  14754. 19,
  14755. 26,
  14756. 33,
  14757. 40,
  14758. 48,
  14759. 41,
  14760. 34,
  14761. 27,
  14762. 20,
  14763. 13,
  14764. 6,
  14765. 7,
  14766. 14,
  14767. 21,
  14768. 28,
  14769. 35,
  14770. 42,
  14771. 49,
  14772. 56,
  14773. 57,
  14774. 50,
  14775. 43,
  14776. 36,
  14777. 29,
  14778. 22,
  14779. 15,
  14780. 23,
  14781. 30,
  14782. 37,
  14783. 44,
  14784. 51,
  14785. 58,
  14786. 59,
  14787. 52,
  14788. 45,
  14789. 38,
  14790. 31,
  14791. 39,
  14792. 46,
  14793. 53,
  14794. 60,
  14795. 61,
  14796. 54,
  14797. 47,
  14798. 55,
  14799. 62,
  14800. 63
  14801. ]);
  14802. var dctCos1 = 4017;
  14803. // cos(pi/16)
  14804. var dctSin1 = 799;
  14805. // sin(pi/16)
  14806. var dctCos3 = 3406;
  14807. // cos(3*pi/16)
  14808. var dctSin3 = 2276;
  14809. // sin(3*pi/16)
  14810. var dctCos6 = 1567;
  14811. // cos(6*pi/16)
  14812. var dctSin6 = 3784;
  14813. // sin(6*pi/16)
  14814. var dctSqrt2 = 5793;
  14815. // sqrt(2)
  14816. var dctSqrt1d2 = 2896;
  14817. // sqrt(2) / 2
  14818. function JpegImage() {
  14819. this.decodeTransform = null;
  14820. this.colorTransform = -1;
  14821. }
  14822. function buildHuffmanTable(codeLengths, values) {
  14823. var k = 0, code = [], i, j, length = 16;
  14824. while (length > 0 && !codeLengths[length - 1]) {
  14825. length--;
  14826. }
  14827. code.push({
  14828. children: [],
  14829. index: 0
  14830. });
  14831. var p = code[0], q;
  14832. for (i = 0; i < length; i++) {
  14833. for (j = 0; j < codeLengths[i]; j++) {
  14834. p = code.pop();
  14835. p.children[p.index] = values[k];
  14836. while (p.index > 0) {
  14837. p = code.pop();
  14838. }
  14839. p.index++;
  14840. code.push(p);
  14841. while (code.length <= i) {
  14842. code.push(q = {
  14843. children: [],
  14844. index: 0
  14845. });
  14846. p.children[p.index] = q.children;
  14847. p = q;
  14848. }
  14849. k++;
  14850. }
  14851. if (i + 1 < length) {
  14852. // p here points to last code
  14853. code.push(q = {
  14854. children: [],
  14855. index: 0
  14856. });
  14857. p.children[p.index] = q.children;
  14858. p = q;
  14859. }
  14860. }
  14861. return code[0].children;
  14862. }
  14863. function getBlockBufferOffset(component, row, col) {
  14864. return 64 * ((component.blocksPerLine + 1) * row + col);
  14865. }
  14866. function decodeScan(data, offset, frame, components, resetInterval, spectralStart, spectralEnd, successivePrev, successive) {
  14867. var mcusPerLine = frame.mcusPerLine;
  14868. var progressive = frame.progressive;
  14869. var startOffset = offset, bitsData = 0, bitsCount = 0;
  14870. function readBit() {
  14871. if (bitsCount > 0) {
  14872. bitsCount--;
  14873. return bitsData >> bitsCount & 1;
  14874. }
  14875. bitsData = data[offset++];
  14876. if (bitsData === 0xFF) {
  14877. var nextByte = data[offset++];
  14878. if (nextByte) {
  14879. error('JPEG error: unexpected marker ' + (bitsData << 8 | nextByte).toString(16));
  14880. }
  14881. }
  14882. // unstuff 0
  14883. bitsCount = 7;
  14884. return bitsData >>> 7;
  14885. }
  14886. function decodeHuffman(tree) {
  14887. var node = tree;
  14888. while (true) {
  14889. node = node[readBit()];
  14890. if (typeof node === 'number') {
  14891. return node;
  14892. }
  14893. if (typeof node !== 'object') {
  14894. error('JPEG error: invalid huffman sequence');
  14895. }
  14896. }
  14897. }
  14898. function receive(length) {
  14899. var n = 0;
  14900. while (length > 0) {
  14901. n = n << 1 | readBit();
  14902. length--;
  14903. }
  14904. return n;
  14905. }
  14906. function receiveAndExtend(length) {
  14907. if (length === 1) {
  14908. return readBit() === 1 ? 1 : -1;
  14909. }
  14910. var n = receive(length);
  14911. if (n >= 1 << length - 1) {
  14912. return n;
  14913. }
  14914. return n + (-1 << length) + 1;
  14915. }
  14916. function decodeBaseline(component, offset) {
  14917. var t = decodeHuffman(component.huffmanTableDC);
  14918. var diff = t === 0 ? 0 : receiveAndExtend(t);
  14919. component.blockData[offset] = component.pred += diff;
  14920. var k = 1;
  14921. while (k < 64) {
  14922. var rs = decodeHuffman(component.huffmanTableAC);
  14923. var s = rs & 15, r = rs >> 4;
  14924. if (s === 0) {
  14925. if (r < 15) {
  14926. break;
  14927. }
  14928. k += 16;
  14929. continue;
  14930. }
  14931. k += r;
  14932. var z = dctZigZag[k];
  14933. component.blockData[offset + z] = receiveAndExtend(s);
  14934. k++;
  14935. }
  14936. }
  14937. function decodeDCFirst(component, offset) {
  14938. var t = decodeHuffman(component.huffmanTableDC);
  14939. var diff = t === 0 ? 0 : receiveAndExtend(t) << successive;
  14940. component.blockData[offset] = component.pred += diff;
  14941. }
  14942. function decodeDCSuccessive(component, offset) {
  14943. component.blockData[offset] |= readBit() << successive;
  14944. }
  14945. var eobrun = 0;
  14946. function decodeACFirst(component, offset) {
  14947. if (eobrun > 0) {
  14948. eobrun--;
  14949. return;
  14950. }
  14951. var k = spectralStart, e = spectralEnd;
  14952. while (k <= e) {
  14953. var rs = decodeHuffman(component.huffmanTableAC);
  14954. var s = rs & 15, r = rs >> 4;
  14955. if (s === 0) {
  14956. if (r < 15) {
  14957. eobrun = receive(r) + (1 << r) - 1;
  14958. break;
  14959. }
  14960. k += 16;
  14961. continue;
  14962. }
  14963. k += r;
  14964. var z = dctZigZag[k];
  14965. component.blockData[offset + z] = receiveAndExtend(s) * (1 << successive);
  14966. k++;
  14967. }
  14968. }
  14969. var successiveACState = 0, successiveACNextValue;
  14970. function decodeACSuccessive(component, offset) {
  14971. var k = spectralStart;
  14972. var e = spectralEnd;
  14973. var r = 0;
  14974. var s;
  14975. var rs;
  14976. while (k <= e) {
  14977. var z = dctZigZag[k];
  14978. switch (successiveACState) {
  14979. case 0:
  14980. // initial state
  14981. rs = decodeHuffman(component.huffmanTableAC);
  14982. s = rs & 15;
  14983. r = rs >> 4;
  14984. if (s === 0) {
  14985. if (r < 15) {
  14986. eobrun = receive(r) + (1 << r);
  14987. successiveACState = 4;
  14988. } else {
  14989. r = 16;
  14990. successiveACState = 1;
  14991. }
  14992. } else {
  14993. if (s !== 1) {
  14994. error('JPEG error: invalid ACn encoding');
  14995. }
  14996. successiveACNextValue = receiveAndExtend(s);
  14997. successiveACState = r ? 2 : 3;
  14998. }
  14999. continue;
  15000. case 1:
  15001. // skipping r zero items
  15002. case 2:
  15003. if (component.blockData[offset + z]) {
  15004. component.blockData[offset + z] += readBit() << successive;
  15005. } else {
  15006. r--;
  15007. if (r === 0) {
  15008. successiveACState = successiveACState === 2 ? 3 : 0;
  15009. }
  15010. }
  15011. break;
  15012. case 3:
  15013. // set value for a zero item
  15014. if (component.blockData[offset + z]) {
  15015. component.blockData[offset + z] += readBit() << successive;
  15016. } else {
  15017. component.blockData[offset + z] = successiveACNextValue << successive;
  15018. successiveACState = 0;
  15019. }
  15020. break;
  15021. case 4:
  15022. // eob
  15023. if (component.blockData[offset + z]) {
  15024. component.blockData[offset + z] += readBit() << successive;
  15025. }
  15026. break;
  15027. }
  15028. k++;
  15029. }
  15030. if (successiveACState === 4) {
  15031. eobrun--;
  15032. if (eobrun === 0) {
  15033. successiveACState = 0;
  15034. }
  15035. }
  15036. }
  15037. function decodeMcu(component, decode, mcu, row, col) {
  15038. var mcuRow = mcu / mcusPerLine | 0;
  15039. var mcuCol = mcu % mcusPerLine;
  15040. var blockRow = mcuRow * component.v + row;
  15041. var blockCol = mcuCol * component.h + col;
  15042. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  15043. decode(component, offset);
  15044. }
  15045. function decodeBlock(component, decode, mcu) {
  15046. var blockRow = mcu / component.blocksPerLine | 0;
  15047. var blockCol = mcu % component.blocksPerLine;
  15048. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  15049. decode(component, offset);
  15050. }
  15051. var componentsLength = components.length;
  15052. var component, i, j, k, n;
  15053. var decodeFn;
  15054. if (progressive) {
  15055. if (spectralStart === 0) {
  15056. decodeFn = successivePrev === 0 ? decodeDCFirst : decodeDCSuccessive;
  15057. } else {
  15058. decodeFn = successivePrev === 0 ? decodeACFirst : decodeACSuccessive;
  15059. }
  15060. } else {
  15061. decodeFn = decodeBaseline;
  15062. }
  15063. var mcu = 0, marker;
  15064. var mcuExpected;
  15065. if (componentsLength === 1) {
  15066. mcuExpected = components[0].blocksPerLine * components[0].blocksPerColumn;
  15067. } else {
  15068. mcuExpected = mcusPerLine * frame.mcusPerColumn;
  15069. }
  15070. if (!resetInterval) {
  15071. resetInterval = mcuExpected;
  15072. }
  15073. var h, v;
  15074. while (mcu < mcuExpected) {
  15075. // reset interval stuff
  15076. for (i = 0; i < componentsLength; i++) {
  15077. components[i].pred = 0;
  15078. }
  15079. eobrun = 0;
  15080. if (componentsLength === 1) {
  15081. component = components[0];
  15082. for (n = 0; n < resetInterval; n++) {
  15083. decodeBlock(component, decodeFn, mcu);
  15084. mcu++;
  15085. }
  15086. } else {
  15087. for (n = 0; n < resetInterval; n++) {
  15088. for (i = 0; i < componentsLength; i++) {
  15089. component = components[i];
  15090. h = component.h;
  15091. v = component.v;
  15092. for (j = 0; j < v; j++) {
  15093. for (k = 0; k < h; k++) {
  15094. decodeMcu(component, decodeFn, mcu, j, k);
  15095. }
  15096. }
  15097. }
  15098. mcu++;
  15099. }
  15100. }
  15101. // find marker
  15102. bitsCount = 0;
  15103. marker = data[offset] << 8 | data[offset + 1];
  15104. // Some bad images seem to pad Scan blocks with zero bytes, skip past
  15105. // those to attempt to find a valid marker (fixes issue4090.pdf).
  15106. while (data[offset] === 0x00 && offset < data.length - 1) {
  15107. offset++;
  15108. marker = data[offset] << 8 | data[offset + 1];
  15109. }
  15110. if (marker <= 0xFF00) {
  15111. error('JPEG error: marker was not found');
  15112. }
  15113. if (marker >= 0xFFD0 && marker <= 0xFFD7) {
  15114. // RSTx
  15115. offset += 2;
  15116. } else {
  15117. break;
  15118. }
  15119. }
  15120. return offset - startOffset;
  15121. }
  15122. // A port of poppler's IDCT method which in turn is taken from:
  15123. // Christoph Loeffler, Adriaan Ligtenberg, George S. Moschytz,
  15124. // 'Practical Fast 1-D DCT Algorithms with 11 Multiplications',
  15125. // IEEE Intl. Conf. on Acoustics, Speech & Signal Processing, 1989,
  15126. // 988-991.
  15127. function quantizeAndInverse(component, blockBufferOffset, p) {
  15128. var qt = component.quantizationTable, blockData = component.blockData;
  15129. var v0, v1, v2, v3, v4, v5, v6, v7;
  15130. var p0, p1, p2, p3, p4, p5, p6, p7;
  15131. var t;
  15132. if (!qt) {
  15133. error('JPEG error: missing required Quantization Table.');
  15134. }
  15135. // inverse DCT on rows
  15136. for (var row = 0; row < 64; row += 8) {
  15137. // gather block data
  15138. p0 = blockData[blockBufferOffset + row];
  15139. p1 = blockData[blockBufferOffset + row + 1];
  15140. p2 = blockData[blockBufferOffset + row + 2];
  15141. p3 = blockData[blockBufferOffset + row + 3];
  15142. p4 = blockData[blockBufferOffset + row + 4];
  15143. p5 = blockData[blockBufferOffset + row + 5];
  15144. p6 = blockData[blockBufferOffset + row + 6];
  15145. p7 = blockData[blockBufferOffset + row + 7];
  15146. // dequant p0
  15147. p0 *= qt[row];
  15148. // check for all-zero AC coefficients
  15149. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  15150. t = dctSqrt2 * p0 + 512 >> 10;
  15151. p[row] = t;
  15152. p[row + 1] = t;
  15153. p[row + 2] = t;
  15154. p[row + 3] = t;
  15155. p[row + 4] = t;
  15156. p[row + 5] = t;
  15157. p[row + 6] = t;
  15158. p[row + 7] = t;
  15159. continue;
  15160. }
  15161. // dequant p1 ... p7
  15162. p1 *= qt[row + 1];
  15163. p2 *= qt[row + 2];
  15164. p3 *= qt[row + 3];
  15165. p4 *= qt[row + 4];
  15166. p5 *= qt[row + 5];
  15167. p6 *= qt[row + 6];
  15168. p7 *= qt[row + 7];
  15169. // stage 4
  15170. v0 = dctSqrt2 * p0 + 128 >> 8;
  15171. v1 = dctSqrt2 * p4 + 128 >> 8;
  15172. v2 = p2;
  15173. v3 = p6;
  15174. v4 = dctSqrt1d2 * (p1 - p7) + 128 >> 8;
  15175. v7 = dctSqrt1d2 * (p1 + p7) + 128 >> 8;
  15176. v5 = p3 << 4;
  15177. v6 = p5 << 4;
  15178. // stage 3
  15179. v0 = v0 + v1 + 1 >> 1;
  15180. v1 = v0 - v1;
  15181. t = v2 * dctSin6 + v3 * dctCos6 + 128 >> 8;
  15182. v2 = v2 * dctCos6 - v3 * dctSin6 + 128 >> 8;
  15183. v3 = t;
  15184. v4 = v4 + v6 + 1 >> 1;
  15185. v6 = v4 - v6;
  15186. v7 = v7 + v5 + 1 >> 1;
  15187. v5 = v7 - v5;
  15188. // stage 2
  15189. v0 = v0 + v3 + 1 >> 1;
  15190. v3 = v0 - v3;
  15191. v1 = v1 + v2 + 1 >> 1;
  15192. v2 = v1 - v2;
  15193. t = v4 * dctSin3 + v7 * dctCos3 + 2048 >> 12;
  15194. v4 = v4 * dctCos3 - v7 * dctSin3 + 2048 >> 12;
  15195. v7 = t;
  15196. t = v5 * dctSin1 + v6 * dctCos1 + 2048 >> 12;
  15197. v5 = v5 * dctCos1 - v6 * dctSin1 + 2048 >> 12;
  15198. v6 = t;
  15199. // stage 1
  15200. p[row] = v0 + v7;
  15201. p[row + 7] = v0 - v7;
  15202. p[row + 1] = v1 + v6;
  15203. p[row + 6] = v1 - v6;
  15204. p[row + 2] = v2 + v5;
  15205. p[row + 5] = v2 - v5;
  15206. p[row + 3] = v3 + v4;
  15207. p[row + 4] = v3 - v4;
  15208. }
  15209. // inverse DCT on columns
  15210. for (var col = 0; col < 8; ++col) {
  15211. p0 = p[col];
  15212. p1 = p[col + 8];
  15213. p2 = p[col + 16];
  15214. p3 = p[col + 24];
  15215. p4 = p[col + 32];
  15216. p5 = p[col + 40];
  15217. p6 = p[col + 48];
  15218. p7 = p[col + 56];
  15219. // check for all-zero AC coefficients
  15220. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  15221. t = dctSqrt2 * p0 + 8192 >> 14;
  15222. // convert to 8 bit
  15223. t = t < -2040 ? 0 : t >= 2024 ? 255 : t + 2056 >> 4;
  15224. blockData[blockBufferOffset + col] = t;
  15225. blockData[blockBufferOffset + col + 8] = t;
  15226. blockData[blockBufferOffset + col + 16] = t;
  15227. blockData[blockBufferOffset + col + 24] = t;
  15228. blockData[blockBufferOffset + col + 32] = t;
  15229. blockData[blockBufferOffset + col + 40] = t;
  15230. blockData[blockBufferOffset + col + 48] = t;
  15231. blockData[blockBufferOffset + col + 56] = t;
  15232. continue;
  15233. }
  15234. // stage 4
  15235. v0 = dctSqrt2 * p0 + 2048 >> 12;
  15236. v1 = dctSqrt2 * p4 + 2048 >> 12;
  15237. v2 = p2;
  15238. v3 = p6;
  15239. v4 = dctSqrt1d2 * (p1 - p7) + 2048 >> 12;
  15240. v7 = dctSqrt1d2 * (p1 + p7) + 2048 >> 12;
  15241. v5 = p3;
  15242. v6 = p5;
  15243. // stage 3
  15244. // Shift v0 by 128.5 << 5 here, so we don't need to shift p0...p7 when
  15245. // converting to UInt8 range later.
  15246. v0 = (v0 + v1 + 1 >> 1) + 4112;
  15247. v1 = v0 - v1;
  15248. t = v2 * dctSin6 + v3 * dctCos6 + 2048 >> 12;
  15249. v2 = v2 * dctCos6 - v3 * dctSin6 + 2048 >> 12;
  15250. v3 = t;
  15251. v4 = v4 + v6 + 1 >> 1;
  15252. v6 = v4 - v6;
  15253. v7 = v7 + v5 + 1 >> 1;
  15254. v5 = v7 - v5;
  15255. // stage 2
  15256. v0 = v0 + v3 + 1 >> 1;
  15257. v3 = v0 - v3;
  15258. v1 = v1 + v2 + 1 >> 1;
  15259. v2 = v1 - v2;
  15260. t = v4 * dctSin3 + v7 * dctCos3 + 2048 >> 12;
  15261. v4 = v4 * dctCos3 - v7 * dctSin3 + 2048 >> 12;
  15262. v7 = t;
  15263. t = v5 * dctSin1 + v6 * dctCos1 + 2048 >> 12;
  15264. v5 = v5 * dctCos1 - v6 * dctSin1 + 2048 >> 12;
  15265. v6 = t;
  15266. // stage 1
  15267. p0 = v0 + v7;
  15268. p7 = v0 - v7;
  15269. p1 = v1 + v6;
  15270. p6 = v1 - v6;
  15271. p2 = v2 + v5;
  15272. p5 = v2 - v5;
  15273. p3 = v3 + v4;
  15274. p4 = v3 - v4;
  15275. // convert to 8-bit integers
  15276. p0 = p0 < 16 ? 0 : p0 >= 4080 ? 255 : p0 >> 4;
  15277. p1 = p1 < 16 ? 0 : p1 >= 4080 ? 255 : p1 >> 4;
  15278. p2 = p2 < 16 ? 0 : p2 >= 4080 ? 255 : p2 >> 4;
  15279. p3 = p3 < 16 ? 0 : p3 >= 4080 ? 255 : p3 >> 4;
  15280. p4 = p4 < 16 ? 0 : p4 >= 4080 ? 255 : p4 >> 4;
  15281. p5 = p5 < 16 ? 0 : p5 >= 4080 ? 255 : p5 >> 4;
  15282. p6 = p6 < 16 ? 0 : p6 >= 4080 ? 255 : p6 >> 4;
  15283. p7 = p7 < 16 ? 0 : p7 >= 4080 ? 255 : p7 >> 4;
  15284. // store block data
  15285. blockData[blockBufferOffset + col] = p0;
  15286. blockData[blockBufferOffset + col + 8] = p1;
  15287. blockData[blockBufferOffset + col + 16] = p2;
  15288. blockData[blockBufferOffset + col + 24] = p3;
  15289. blockData[blockBufferOffset + col + 32] = p4;
  15290. blockData[blockBufferOffset + col + 40] = p5;
  15291. blockData[blockBufferOffset + col + 48] = p6;
  15292. blockData[blockBufferOffset + col + 56] = p7;
  15293. }
  15294. }
  15295. function buildComponentData(frame, component) {
  15296. var blocksPerLine = component.blocksPerLine;
  15297. var blocksPerColumn = component.blocksPerColumn;
  15298. var computationBuffer = new Int16Array(64);
  15299. for (var blockRow = 0; blockRow < blocksPerColumn; blockRow++) {
  15300. for (var blockCol = 0; blockCol < blocksPerLine; blockCol++) {
  15301. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  15302. quantizeAndInverse(component, offset, computationBuffer);
  15303. }
  15304. }
  15305. return component.blockData;
  15306. }
  15307. function clamp0to255(a) {
  15308. return a <= 0 ? 0 : a >= 255 ? 255 : a;
  15309. }
  15310. JpegImage.prototype = {
  15311. parse: function parse(data) {
  15312. function readUint16() {
  15313. var value = data[offset] << 8 | data[offset + 1];
  15314. offset += 2;
  15315. return value;
  15316. }
  15317. function readDataBlock() {
  15318. var length = readUint16();
  15319. var array = data.subarray(offset, offset + length - 2);
  15320. offset += array.length;
  15321. return array;
  15322. }
  15323. function prepareComponents(frame) {
  15324. var mcusPerLine = Math.ceil(frame.samplesPerLine / 8 / frame.maxH);
  15325. var mcusPerColumn = Math.ceil(frame.scanLines / 8 / frame.maxV);
  15326. for (var i = 0; i < frame.components.length; i++) {
  15327. component = frame.components[i];
  15328. var blocksPerLine = Math.ceil(Math.ceil(frame.samplesPerLine / 8) * component.h / frame.maxH);
  15329. var blocksPerColumn = Math.ceil(Math.ceil(frame.scanLines / 8) * component.v / frame.maxV);
  15330. var blocksPerLineForMcu = mcusPerLine * component.h;
  15331. var blocksPerColumnForMcu = mcusPerColumn * component.v;
  15332. var blocksBufferSize = 64 * blocksPerColumnForMcu * (blocksPerLineForMcu + 1);
  15333. component.blockData = new Int16Array(blocksBufferSize);
  15334. component.blocksPerLine = blocksPerLine;
  15335. component.blocksPerColumn = blocksPerColumn;
  15336. }
  15337. frame.mcusPerLine = mcusPerLine;
  15338. frame.mcusPerColumn = mcusPerColumn;
  15339. }
  15340. var offset = 0;
  15341. var jfif = null;
  15342. var adobe = null;
  15343. var frame, resetInterval;
  15344. var quantizationTables = [];
  15345. var huffmanTablesAC = [], huffmanTablesDC = [];
  15346. var fileMarker = readUint16();
  15347. if (fileMarker !== 0xFFD8) {
  15348. // SOI (Start of Image)
  15349. error('JPEG error: SOI not found');
  15350. }
  15351. fileMarker = readUint16();
  15352. while (fileMarker !== 0xFFD9) {
  15353. // EOI (End of image)
  15354. var i, j, l;
  15355. switch (fileMarker) {
  15356. case 0xFFE0:
  15357. // APP0 (Application Specific)
  15358. case 0xFFE1:
  15359. // APP1
  15360. case 0xFFE2:
  15361. // APP2
  15362. case 0xFFE3:
  15363. // APP3
  15364. case 0xFFE4:
  15365. // APP4
  15366. case 0xFFE5:
  15367. // APP5
  15368. case 0xFFE6:
  15369. // APP6
  15370. case 0xFFE7:
  15371. // APP7
  15372. case 0xFFE8:
  15373. // APP8
  15374. case 0xFFE9:
  15375. // APP9
  15376. case 0xFFEA:
  15377. // APP10
  15378. case 0xFFEB:
  15379. // APP11
  15380. case 0xFFEC:
  15381. // APP12
  15382. case 0xFFED:
  15383. // APP13
  15384. case 0xFFEE:
  15385. // APP14
  15386. case 0xFFEF:
  15387. // APP15
  15388. case 0xFFFE:
  15389. // COM (Comment)
  15390. var appData = readDataBlock();
  15391. if (fileMarker === 0xFFE0) {
  15392. if (appData[0] === 0x4A && appData[1] === 0x46 && appData[2] === 0x49 && appData[3] === 0x46 && appData[4] === 0) {
  15393. // 'JFIF\x00'
  15394. jfif = {
  15395. version: {
  15396. major: appData[5],
  15397. minor: appData[6]
  15398. },
  15399. densityUnits: appData[7],
  15400. xDensity: appData[8] << 8 | appData[9],
  15401. yDensity: appData[10] << 8 | appData[11],
  15402. thumbWidth: appData[12],
  15403. thumbHeight: appData[13],
  15404. thumbData: appData.subarray(14, 14 + 3 * appData[12] * appData[13])
  15405. };
  15406. }
  15407. }
  15408. // TODO APP1 - Exif
  15409. if (fileMarker === 0xFFEE) {
  15410. if (appData[0] === 0x41 && appData[1] === 0x64 && appData[2] === 0x6F && appData[3] === 0x62 && appData[4] === 0x65) {
  15411. // 'Adobe'
  15412. adobe = {
  15413. version: appData[5] << 8 | appData[6],
  15414. flags0: appData[7] << 8 | appData[8],
  15415. flags1: appData[9] << 8 | appData[10],
  15416. transformCode: appData[11]
  15417. };
  15418. }
  15419. }
  15420. break;
  15421. case 0xFFDB:
  15422. // DQT (Define Quantization Tables)
  15423. var quantizationTablesLength = readUint16();
  15424. var quantizationTablesEnd = quantizationTablesLength + offset - 2;
  15425. var z;
  15426. while (offset < quantizationTablesEnd) {
  15427. var quantizationTableSpec = data[offset++];
  15428. var tableData = new Uint16Array(64);
  15429. if (quantizationTableSpec >> 4 === 0) {
  15430. // 8 bit values
  15431. for (j = 0; j < 64; j++) {
  15432. z = dctZigZag[j];
  15433. tableData[z] = data[offset++];
  15434. }
  15435. } else if (quantizationTableSpec >> 4 === 1) {
  15436. //16 bit
  15437. for (j = 0; j < 64; j++) {
  15438. z = dctZigZag[j];
  15439. tableData[z] = readUint16();
  15440. }
  15441. } else {
  15442. error('JPEG error: DQT - invalid table spec');
  15443. }
  15444. quantizationTables[quantizationTableSpec & 15] = tableData;
  15445. }
  15446. break;
  15447. case 0xFFC0:
  15448. // SOF0 (Start of Frame, Baseline DCT)
  15449. case 0xFFC1:
  15450. // SOF1 (Start of Frame, Extended DCT)
  15451. case 0xFFC2:
  15452. // SOF2 (Start of Frame, Progressive DCT)
  15453. if (frame) {
  15454. error('JPEG error: Only single frame JPEGs supported');
  15455. }
  15456. readUint16();
  15457. // skip data length
  15458. frame = {};
  15459. frame.extended = fileMarker === 0xFFC1;
  15460. frame.progressive = fileMarker === 0xFFC2;
  15461. frame.precision = data[offset++];
  15462. frame.scanLines = readUint16();
  15463. frame.samplesPerLine = readUint16();
  15464. frame.components = [];
  15465. frame.componentIds = {};
  15466. var componentsCount = data[offset++], componentId;
  15467. var maxH = 0, maxV = 0;
  15468. for (i = 0; i < componentsCount; i++) {
  15469. componentId = data[offset];
  15470. var h = data[offset + 1] >> 4;
  15471. var v = data[offset + 1] & 15;
  15472. if (maxH < h) {
  15473. maxH = h;
  15474. }
  15475. if (maxV < v) {
  15476. maxV = v;
  15477. }
  15478. var qId = data[offset + 2];
  15479. l = frame.components.push({
  15480. h: h,
  15481. v: v,
  15482. quantizationId: qId,
  15483. quantizationTable: null
  15484. });
  15485. // See comment below.
  15486. frame.componentIds[componentId] = l - 1;
  15487. offset += 3;
  15488. }
  15489. frame.maxH = maxH;
  15490. frame.maxV = maxV;
  15491. prepareComponents(frame);
  15492. break;
  15493. case 0xFFC4:
  15494. // DHT (Define Huffman Tables)
  15495. var huffmanLength = readUint16();
  15496. for (i = 2; i < huffmanLength;) {
  15497. var huffmanTableSpec = data[offset++];
  15498. var codeLengths = new Uint8Array(16);
  15499. var codeLengthSum = 0;
  15500. for (j = 0; j < 16; j++, offset++) {
  15501. codeLengthSum += codeLengths[j] = data[offset];
  15502. }
  15503. var huffmanValues = new Uint8Array(codeLengthSum);
  15504. for (j = 0; j < codeLengthSum; j++, offset++) {
  15505. huffmanValues[j] = data[offset];
  15506. }
  15507. i += 17 + codeLengthSum;
  15508. (huffmanTableSpec >> 4 === 0 ? huffmanTablesDC : huffmanTablesAC)[huffmanTableSpec & 15] = buildHuffmanTable(codeLengths, huffmanValues);
  15509. }
  15510. break;
  15511. case 0xFFDD:
  15512. // DRI (Define Restart Interval)
  15513. readUint16();
  15514. // skip data length
  15515. resetInterval = readUint16();
  15516. break;
  15517. case 0xFFDA:
  15518. // SOS (Start of Scan)
  15519. var scanLength = readUint16();
  15520. var selectorsCount = data[offset++];
  15521. var components = [], component;
  15522. for (i = 0; i < selectorsCount; i++) {
  15523. var componentIndex = frame.componentIds[data[offset++]];
  15524. component = frame.components[componentIndex];
  15525. var tableSpec = data[offset++];
  15526. component.huffmanTableDC = huffmanTablesDC[tableSpec >> 4];
  15527. component.huffmanTableAC = huffmanTablesAC[tableSpec & 15];
  15528. components.push(component);
  15529. }
  15530. var spectralStart = data[offset++];
  15531. var spectralEnd = data[offset++];
  15532. var successiveApproximation = data[offset++];
  15533. var processed = decodeScan(data, offset, frame, components, resetInterval, spectralStart, spectralEnd, successiveApproximation >> 4, successiveApproximation & 15);
  15534. offset += processed;
  15535. break;
  15536. case 0xFFFF:
  15537. // Fill bytes
  15538. if (data[offset] !== 0xFF) {
  15539. // Avoid skipping a valid marker.
  15540. offset--;
  15541. }
  15542. break;
  15543. default:
  15544. if (data[offset - 3] === 0xFF && data[offset - 2] >= 0xC0 && data[offset - 2] <= 0xFE) {
  15545. // could be incorrect encoding -- last 0xFF byte of the previous
  15546. // block was eaten by the encoder
  15547. offset -= 3;
  15548. break;
  15549. }
  15550. error('JPEG error: unknown marker ' + fileMarker.toString(16));
  15551. }
  15552. fileMarker = readUint16();
  15553. }
  15554. this.width = frame.samplesPerLine;
  15555. this.height = frame.scanLines;
  15556. this.jfif = jfif;
  15557. this.adobe = adobe;
  15558. this.components = [];
  15559. for (i = 0; i < frame.components.length; i++) {
  15560. component = frame.components[i];
  15561. // Prevent errors when DQT markers are placed after SOF{n} markers,
  15562. // by assigning the `quantizationTable` entry after the entire image
  15563. // has been parsed (fixes issue7406.pdf).
  15564. var quantizationTable = quantizationTables[component.quantizationId];
  15565. if (quantizationTable) {
  15566. component.quantizationTable = quantizationTable;
  15567. }
  15568. this.components.push({
  15569. output: buildComponentData(frame, component),
  15570. scaleX: component.h / frame.maxH,
  15571. scaleY: component.v / frame.maxV,
  15572. blocksPerLine: component.blocksPerLine,
  15573. blocksPerColumn: component.blocksPerColumn
  15574. });
  15575. }
  15576. this.numComponents = this.components.length;
  15577. },
  15578. _getLinearizedBlockData: function getLinearizedBlockData(width, height) {
  15579. var scaleX = this.width / width, scaleY = this.height / height;
  15580. var component, componentScaleX, componentScaleY, blocksPerScanline;
  15581. var x, y, i, j, k;
  15582. var index;
  15583. var offset = 0;
  15584. var output;
  15585. var numComponents = this.components.length;
  15586. var dataLength = width * height * numComponents;
  15587. var data = new Uint8Array(dataLength);
  15588. var xScaleBlockOffset = new Uint32Array(width);
  15589. var mask3LSB = 0xfffffff8;
  15590. // used to clear the 3 LSBs
  15591. for (i = 0; i < numComponents; i++) {
  15592. component = this.components[i];
  15593. componentScaleX = component.scaleX * scaleX;
  15594. componentScaleY = component.scaleY * scaleY;
  15595. offset = i;
  15596. output = component.output;
  15597. blocksPerScanline = component.blocksPerLine + 1 << 3;
  15598. // precalculate the xScaleBlockOffset
  15599. for (x = 0; x < width; x++) {
  15600. j = 0 | x * componentScaleX;
  15601. xScaleBlockOffset[x] = (j & mask3LSB) << 3 | j & 7;
  15602. }
  15603. // linearize the blocks of the component
  15604. for (y = 0; y < height; y++) {
  15605. j = 0 | y * componentScaleY;
  15606. index = blocksPerScanline * (j & mask3LSB) | (j & 7) << 3;
  15607. for (x = 0; x < width; x++) {
  15608. data[offset] = output[index + xScaleBlockOffset[x]];
  15609. offset += numComponents;
  15610. }
  15611. }
  15612. }
  15613. // decodeTransform contains pairs of multiplier (-256..256) and additive
  15614. var transform = this.decodeTransform;
  15615. if (transform) {
  15616. for (i = 0; i < dataLength;) {
  15617. for (j = 0, k = 0; j < numComponents; j++, i++, k += 2) {
  15618. data[i] = (data[i] * transform[k] >> 8) + transform[k + 1];
  15619. }
  15620. }
  15621. }
  15622. return data;
  15623. },
  15624. _isColorConversionNeeded: function isColorConversionNeeded() {
  15625. if (this.adobe && this.adobe.transformCode) {
  15626. // The adobe transform marker overrides any previous setting
  15627. return true;
  15628. } else if (this.numComponents === 3) {
  15629. if (!this.adobe && this.colorTransform === 0) {
  15630. // If the Adobe transform marker is not present and the image
  15631. // dictionary has a 'ColorTransform' entry, explicitly set to `0`,
  15632. // then the colours should *not* be transformed.
  15633. return false;
  15634. }
  15635. return true;
  15636. } else {
  15637. // `this.numComponents !== 3`
  15638. if (!this.adobe && this.colorTransform === 1) {
  15639. // If the Adobe transform marker is not present and the image
  15640. // dictionary has a 'ColorTransform' entry, explicitly set to `1`,
  15641. // then the colours should be transformed.
  15642. return true;
  15643. }
  15644. return false;
  15645. }
  15646. },
  15647. _convertYccToRgb: function convertYccToRgb(data) {
  15648. var Y, Cb, Cr;
  15649. for (var i = 0, length = data.length; i < length; i += 3) {
  15650. Y = data[i];
  15651. Cb = data[i + 1];
  15652. Cr = data[i + 2];
  15653. data[i] = clamp0to255(Y - 179.456 + 1.402 * Cr);
  15654. data[i + 1] = clamp0to255(Y + 135.459 - 0.344 * Cb - 0.714 * Cr);
  15655. data[i + 2] = clamp0to255(Y - 226.816 + 1.772 * Cb);
  15656. }
  15657. return data;
  15658. },
  15659. _convertYcckToRgb: function convertYcckToRgb(data) {
  15660. var Y, Cb, Cr, k;
  15661. var offset = 0;
  15662. for (var i = 0, length = data.length; i < length; i += 4) {
  15663. Y = data[i];
  15664. Cb = data[i + 1];
  15665. Cr = data[i + 2];
  15666. k = data[i + 3];
  15667. 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);
  15668. 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);
  15669. 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);
  15670. data[offset++] = clamp0to255(r);
  15671. data[offset++] = clamp0to255(g);
  15672. data[offset++] = clamp0to255(b);
  15673. }
  15674. return data;
  15675. },
  15676. _convertYcckToCmyk: function convertYcckToCmyk(data) {
  15677. var Y, Cb, Cr;
  15678. for (var i = 0, length = data.length; i < length; i += 4) {
  15679. Y = data[i];
  15680. Cb = data[i + 1];
  15681. Cr = data[i + 2];
  15682. data[i] = clamp0to255(434.456 - Y - 1.402 * Cr);
  15683. data[i + 1] = clamp0to255(119.541 - Y + 0.344 * Cb + 0.714 * Cr);
  15684. data[i + 2] = clamp0to255(481.816 - Y - 1.772 * Cb);
  15685. }
  15686. // K in data[i + 3] is unchanged
  15687. return data;
  15688. },
  15689. _convertCmykToRgb: function convertCmykToRgb(data) {
  15690. var c, m, y, k;
  15691. var offset = 0;
  15692. var min = -255 * 255 * 255;
  15693. var scale = 1 / 255 / 255;
  15694. for (var i = 0, length = data.length; i < length; i += 4) {
  15695. c = data[i];
  15696. m = data[i + 1];
  15697. y = data[i + 2];
  15698. k = data[i + 3];
  15699. 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);
  15700. 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);
  15701. 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);
  15702. data[offset++] = r >= 0 ? 255 : r <= min ? 0 : 255 + r * scale | 0;
  15703. data[offset++] = g >= 0 ? 255 : g <= min ? 0 : 255 + g * scale | 0;
  15704. data[offset++] = b >= 0 ? 255 : b <= min ? 0 : 255 + b * scale | 0;
  15705. }
  15706. return data;
  15707. },
  15708. getData: function getData(width, height, forceRGBoutput) {
  15709. if (this.numComponents > 4) {
  15710. error('JPEG error: Unsupported color mode');
  15711. }
  15712. // type of data: Uint8Array(width * height * numComponents)
  15713. var data = this._getLinearizedBlockData(width, height);
  15714. if (this.numComponents === 1 && forceRGBoutput) {
  15715. var dataLength = data.length;
  15716. var rgbData = new Uint8Array(dataLength * 3);
  15717. var offset = 0;
  15718. for (var i = 0; i < dataLength; i++) {
  15719. var grayColor = data[i];
  15720. rgbData[offset++] = grayColor;
  15721. rgbData[offset++] = grayColor;
  15722. rgbData[offset++] = grayColor;
  15723. }
  15724. return rgbData;
  15725. } else if (this.numComponents === 3 && this._isColorConversionNeeded()) {
  15726. return this._convertYccToRgb(data);
  15727. } else if (this.numComponents === 4) {
  15728. if (this._isColorConversionNeeded()) {
  15729. if (forceRGBoutput) {
  15730. return this._convertYcckToRgb(data);
  15731. } else {
  15732. return this._convertYcckToCmyk(data);
  15733. }
  15734. } else if (forceRGBoutput) {
  15735. return this._convertCmykToRgb(data);
  15736. }
  15737. }
  15738. return data;
  15739. }
  15740. };
  15741. return JpegImage;
  15742. }();
  15743. exports.JpegImage = JpegImage;
  15744. }));
  15745. (function (root, factory) {
  15746. factory(root.pdfjsCoreJpx = {}, root.pdfjsSharedUtil, root.pdfjsCoreArithmeticDecoder);
  15747. }(this, function (exports, sharedUtil, coreArithmeticDecoder) {
  15748. var info = sharedUtil.info;
  15749. var warn = sharedUtil.warn;
  15750. var error = sharedUtil.error;
  15751. var log2 = sharedUtil.log2;
  15752. var readUint16 = sharedUtil.readUint16;
  15753. var readUint32 = sharedUtil.readUint32;
  15754. var ArithmeticDecoder = coreArithmeticDecoder.ArithmeticDecoder;
  15755. var JpxImage = function JpxImageClosure() {
  15756. // Table E.1
  15757. var SubbandsGainLog2 = {
  15758. 'LL': 0,
  15759. 'LH': 1,
  15760. 'HL': 1,
  15761. 'HH': 2
  15762. };
  15763. function JpxImage() {
  15764. this.failOnCorruptedImage = false;
  15765. }
  15766. JpxImage.prototype = {
  15767. parse: function JpxImage_parse(data) {
  15768. var head = readUint16(data, 0);
  15769. // No box header, immediate start of codestream (SOC)
  15770. if (head === 0xFF4F) {
  15771. this.parseCodestream(data, 0, data.length);
  15772. return;
  15773. }
  15774. var position = 0, length = data.length;
  15775. while (position < length) {
  15776. var headerSize = 8;
  15777. var lbox = readUint32(data, position);
  15778. var tbox = readUint32(data, position + 4);
  15779. position += headerSize;
  15780. if (lbox === 1) {
  15781. // XLBox: read UInt64 according to spec.
  15782. // JavaScript's int precision of 53 bit should be sufficient here.
  15783. lbox = readUint32(data, position) * 4294967296 + readUint32(data, position + 4);
  15784. position += 8;
  15785. headerSize += 8;
  15786. }
  15787. if (lbox === 0) {
  15788. lbox = length - position + headerSize;
  15789. }
  15790. if (lbox < headerSize) {
  15791. error('JPX Error: Invalid box field size');
  15792. }
  15793. var dataLength = lbox - headerSize;
  15794. var jumpDataLength = true;
  15795. switch (tbox) {
  15796. case 0x6A703268:
  15797. // 'jp2h'
  15798. jumpDataLength = false;
  15799. // parsing child boxes
  15800. break;
  15801. case 0x636F6C72:
  15802. // 'colr'
  15803. // Colorspaces are not used, the CS from the PDF is used.
  15804. var method = data[position];
  15805. if (method === 1) {
  15806. // enumerated colorspace
  15807. var colorspace = readUint32(data, position + 3);
  15808. switch (colorspace) {
  15809. case 16:
  15810. // this indicates a sRGB colorspace
  15811. case 17:
  15812. // this indicates a grayscale colorspace
  15813. case 18:
  15814. // this indicates a YUV colorspace
  15815. break;
  15816. default:
  15817. warn('Unknown colorspace ' + colorspace);
  15818. break;
  15819. }
  15820. } else if (method === 2) {
  15821. info('ICC profile not supported');
  15822. }
  15823. break;
  15824. case 0x6A703263:
  15825. // 'jp2c'
  15826. this.parseCodestream(data, position, position + dataLength);
  15827. break;
  15828. case 0x6A502020:
  15829. // 'jP\024\024'
  15830. if (0x0d0a870a !== readUint32(data, position)) {
  15831. warn('Invalid JP2 signature');
  15832. }
  15833. break;
  15834. // The following header types are valid but currently not used:
  15835. case 0x6A501A1A:
  15836. // 'jP\032\032'
  15837. case 0x66747970:
  15838. // 'ftyp'
  15839. case 0x72726571:
  15840. // 'rreq'
  15841. case 0x72657320:
  15842. // 'res '
  15843. case 0x69686472:
  15844. // 'ihdr'
  15845. break;
  15846. default:
  15847. var headerType = String.fromCharCode(tbox >> 24 & 0xFF, tbox >> 16 & 0xFF, tbox >> 8 & 0xFF, tbox & 0xFF);
  15848. warn('Unsupported header type ' + tbox + ' (' + headerType + ')');
  15849. break;
  15850. }
  15851. if (jumpDataLength) {
  15852. position += dataLength;
  15853. }
  15854. }
  15855. },
  15856. parseImageProperties: function JpxImage_parseImageProperties(stream) {
  15857. var newByte = stream.getByte();
  15858. while (newByte >= 0) {
  15859. var oldByte = newByte;
  15860. newByte = stream.getByte();
  15861. var code = oldByte << 8 | newByte;
  15862. // Image and tile size (SIZ)
  15863. if (code === 0xFF51) {
  15864. stream.skip(4);
  15865. var Xsiz = stream.getInt32() >>> 0;
  15866. // Byte 4
  15867. var Ysiz = stream.getInt32() >>> 0;
  15868. // Byte 8
  15869. var XOsiz = stream.getInt32() >>> 0;
  15870. // Byte 12
  15871. var YOsiz = stream.getInt32() >>> 0;
  15872. // Byte 16
  15873. stream.skip(16);
  15874. var Csiz = stream.getUint16();
  15875. // Byte 36
  15876. this.width = Xsiz - XOsiz;
  15877. this.height = Ysiz - YOsiz;
  15878. this.componentsCount = Csiz;
  15879. // Results are always returned as Uint8Arrays
  15880. this.bitsPerComponent = 8;
  15881. return;
  15882. }
  15883. }
  15884. error('JPX Error: No size marker found in JPX stream');
  15885. },
  15886. parseCodestream: function JpxImage_parseCodestream(data, start, end) {
  15887. var context = {};
  15888. var doNotRecover = false;
  15889. try {
  15890. var position = start;
  15891. while (position + 1 < end) {
  15892. var code = readUint16(data, position);
  15893. position += 2;
  15894. var length = 0, j, sqcd, spqcds, spqcdSize, scalarExpounded, tile;
  15895. switch (code) {
  15896. case 0xFF4F:
  15897. // Start of codestream (SOC)
  15898. context.mainHeader = true;
  15899. break;
  15900. case 0xFFD9:
  15901. // End of codestream (EOC)
  15902. break;
  15903. case 0xFF51:
  15904. // Image and tile size (SIZ)
  15905. length = readUint16(data, position);
  15906. var siz = {};
  15907. siz.Xsiz = readUint32(data, position + 4);
  15908. siz.Ysiz = readUint32(data, position + 8);
  15909. siz.XOsiz = readUint32(data, position + 12);
  15910. siz.YOsiz = readUint32(data, position + 16);
  15911. siz.XTsiz = readUint32(data, position + 20);
  15912. siz.YTsiz = readUint32(data, position + 24);
  15913. siz.XTOsiz = readUint32(data, position + 28);
  15914. siz.YTOsiz = readUint32(data, position + 32);
  15915. var componentsCount = readUint16(data, position + 36);
  15916. siz.Csiz = componentsCount;
  15917. var components = [];
  15918. j = position + 38;
  15919. for (var i = 0; i < componentsCount; i++) {
  15920. var component = {
  15921. precision: (data[j] & 0x7F) + 1,
  15922. isSigned: !!(data[j] & 0x80),
  15923. XRsiz: data[j + 1],
  15924. YRsiz: data[j + 1]
  15925. };
  15926. calculateComponentDimensions(component, siz);
  15927. components.push(component);
  15928. }
  15929. context.SIZ = siz;
  15930. context.components = components;
  15931. calculateTileGrids(context, components);
  15932. context.QCC = [];
  15933. context.COC = [];
  15934. break;
  15935. case 0xFF5C:
  15936. // Quantization default (QCD)
  15937. length = readUint16(data, position);
  15938. var qcd = {};
  15939. j = position + 2;
  15940. sqcd = data[j++];
  15941. switch (sqcd & 0x1F) {
  15942. case 0:
  15943. spqcdSize = 8;
  15944. scalarExpounded = true;
  15945. break;
  15946. case 1:
  15947. spqcdSize = 16;
  15948. scalarExpounded = false;
  15949. break;
  15950. case 2:
  15951. spqcdSize = 16;
  15952. scalarExpounded = true;
  15953. break;
  15954. default:
  15955. throw new Error('Invalid SQcd value ' + sqcd);
  15956. }
  15957. qcd.noQuantization = spqcdSize === 8;
  15958. qcd.scalarExpounded = scalarExpounded;
  15959. qcd.guardBits = sqcd >> 5;
  15960. spqcds = [];
  15961. while (j < length + position) {
  15962. var spqcd = {};
  15963. if (spqcdSize === 8) {
  15964. spqcd.epsilon = data[j++] >> 3;
  15965. spqcd.mu = 0;
  15966. } else {
  15967. spqcd.epsilon = data[j] >> 3;
  15968. spqcd.mu = (data[j] & 0x7) << 8 | data[j + 1];
  15969. j += 2;
  15970. }
  15971. spqcds.push(spqcd);
  15972. }
  15973. qcd.SPqcds = spqcds;
  15974. if (context.mainHeader) {
  15975. context.QCD = qcd;
  15976. } else {
  15977. context.currentTile.QCD = qcd;
  15978. context.currentTile.QCC = [];
  15979. }
  15980. break;
  15981. case 0xFF5D:
  15982. // Quantization component (QCC)
  15983. length = readUint16(data, position);
  15984. var qcc = {};
  15985. j = position + 2;
  15986. var cqcc;
  15987. if (context.SIZ.Csiz < 257) {
  15988. cqcc = data[j++];
  15989. } else {
  15990. cqcc = readUint16(data, j);
  15991. j += 2;
  15992. }
  15993. sqcd = data[j++];
  15994. switch (sqcd & 0x1F) {
  15995. case 0:
  15996. spqcdSize = 8;
  15997. scalarExpounded = true;
  15998. break;
  15999. case 1:
  16000. spqcdSize = 16;
  16001. scalarExpounded = false;
  16002. break;
  16003. case 2:
  16004. spqcdSize = 16;
  16005. scalarExpounded = true;
  16006. break;
  16007. default:
  16008. throw new Error('Invalid SQcd value ' + sqcd);
  16009. }
  16010. qcc.noQuantization = spqcdSize === 8;
  16011. qcc.scalarExpounded = scalarExpounded;
  16012. qcc.guardBits = sqcd >> 5;
  16013. spqcds = [];
  16014. while (j < length + position) {
  16015. spqcd = {};
  16016. if (spqcdSize === 8) {
  16017. spqcd.epsilon = data[j++] >> 3;
  16018. spqcd.mu = 0;
  16019. } else {
  16020. spqcd.epsilon = data[j] >> 3;
  16021. spqcd.mu = (data[j] & 0x7) << 8 | data[j + 1];
  16022. j += 2;
  16023. }
  16024. spqcds.push(spqcd);
  16025. }
  16026. qcc.SPqcds = spqcds;
  16027. if (context.mainHeader) {
  16028. context.QCC[cqcc] = qcc;
  16029. } else {
  16030. context.currentTile.QCC[cqcc] = qcc;
  16031. }
  16032. break;
  16033. case 0xFF52:
  16034. // Coding style default (COD)
  16035. length = readUint16(data, position);
  16036. var cod = {};
  16037. j = position + 2;
  16038. var scod = data[j++];
  16039. cod.entropyCoderWithCustomPrecincts = !!(scod & 1);
  16040. cod.sopMarkerUsed = !!(scod & 2);
  16041. cod.ephMarkerUsed = !!(scod & 4);
  16042. cod.progressionOrder = data[j++];
  16043. cod.layersCount = readUint16(data, j);
  16044. j += 2;
  16045. cod.multipleComponentTransform = data[j++];
  16046. cod.decompositionLevelsCount = data[j++];
  16047. cod.xcb = (data[j++] & 0xF) + 2;
  16048. cod.ycb = (data[j++] & 0xF) + 2;
  16049. var blockStyle = data[j++];
  16050. cod.selectiveArithmeticCodingBypass = !!(blockStyle & 1);
  16051. cod.resetContextProbabilities = !!(blockStyle & 2);
  16052. cod.terminationOnEachCodingPass = !!(blockStyle & 4);
  16053. cod.verticalyStripe = !!(blockStyle & 8);
  16054. cod.predictableTermination = !!(blockStyle & 16);
  16055. cod.segmentationSymbolUsed = !!(blockStyle & 32);
  16056. cod.reversibleTransformation = data[j++];
  16057. if (cod.entropyCoderWithCustomPrecincts) {
  16058. var precinctsSizes = [];
  16059. while (j < length + position) {
  16060. var precinctsSize = data[j++];
  16061. precinctsSizes.push({
  16062. PPx: precinctsSize & 0xF,
  16063. PPy: precinctsSize >> 4
  16064. });
  16065. }
  16066. cod.precinctsSizes = precinctsSizes;
  16067. }
  16068. var unsupported = [];
  16069. if (cod.selectiveArithmeticCodingBypass) {
  16070. unsupported.push('selectiveArithmeticCodingBypass');
  16071. }
  16072. if (cod.resetContextProbabilities) {
  16073. unsupported.push('resetContextProbabilities');
  16074. }
  16075. if (cod.terminationOnEachCodingPass) {
  16076. unsupported.push('terminationOnEachCodingPass');
  16077. }
  16078. if (cod.verticalyStripe) {
  16079. unsupported.push('verticalyStripe');
  16080. }
  16081. if (cod.predictableTermination) {
  16082. unsupported.push('predictableTermination');
  16083. }
  16084. if (unsupported.length > 0) {
  16085. doNotRecover = true;
  16086. throw new Error('Unsupported COD options (' + unsupported.join(', ') + ')');
  16087. }
  16088. if (context.mainHeader) {
  16089. context.COD = cod;
  16090. } else {
  16091. context.currentTile.COD = cod;
  16092. context.currentTile.COC = [];
  16093. }
  16094. break;
  16095. case 0xFF90:
  16096. // Start of tile-part (SOT)
  16097. length = readUint16(data, position);
  16098. tile = {};
  16099. tile.index = readUint16(data, position + 2);
  16100. tile.length = readUint32(data, position + 4);
  16101. tile.dataEnd = tile.length + position - 2;
  16102. tile.partIndex = data[position + 8];
  16103. tile.partsCount = data[position + 9];
  16104. context.mainHeader = false;
  16105. if (tile.partIndex === 0) {
  16106. // reset component specific settings
  16107. tile.COD = context.COD;
  16108. tile.COC = context.COC.slice(0);
  16109. // clone of the global COC
  16110. tile.QCD = context.QCD;
  16111. tile.QCC = context.QCC.slice(0);
  16112. }
  16113. // clone of the global COC
  16114. context.currentTile = tile;
  16115. break;
  16116. case 0xFF93:
  16117. // Start of data (SOD)
  16118. tile = context.currentTile;
  16119. if (tile.partIndex === 0) {
  16120. initializeTile(context, tile.index);
  16121. buildPackets(context);
  16122. }
  16123. // moving to the end of the data
  16124. length = tile.dataEnd - position;
  16125. parseTilePackets(context, data, position, length);
  16126. break;
  16127. case 0xFF55:
  16128. // Tile-part lengths, main header (TLM)
  16129. case 0xFF57:
  16130. // Packet length, main header (PLM)
  16131. case 0xFF58:
  16132. // Packet length, tile-part header (PLT)
  16133. case 0xFF64:
  16134. // Comment (COM)
  16135. length = readUint16(data, position);
  16136. // skipping content
  16137. break;
  16138. case 0xFF53:
  16139. // Coding style component (COC)
  16140. throw new Error('Codestream code 0xFF53 (COC) is ' + 'not implemented');
  16141. default:
  16142. throw new Error('Unknown codestream code: ' + code.toString(16));
  16143. }
  16144. position += length;
  16145. }
  16146. } catch (e) {
  16147. if (doNotRecover || this.failOnCorruptedImage) {
  16148. error('JPX Error: ' + e.message);
  16149. } else {
  16150. warn('JPX: Trying to recover from: ' + e.message);
  16151. }
  16152. }
  16153. this.tiles = transformComponents(context);
  16154. this.width = context.SIZ.Xsiz - context.SIZ.XOsiz;
  16155. this.height = context.SIZ.Ysiz - context.SIZ.YOsiz;
  16156. this.componentsCount = context.SIZ.Csiz;
  16157. }
  16158. };
  16159. function calculateComponentDimensions(component, siz) {
  16160. // Section B.2 Component mapping
  16161. component.x0 = Math.ceil(siz.XOsiz / component.XRsiz);
  16162. component.x1 = Math.ceil(siz.Xsiz / component.XRsiz);
  16163. component.y0 = Math.ceil(siz.YOsiz / component.YRsiz);
  16164. component.y1 = Math.ceil(siz.Ysiz / component.YRsiz);
  16165. component.width = component.x1 - component.x0;
  16166. component.height = component.y1 - component.y0;
  16167. }
  16168. function calculateTileGrids(context, components) {
  16169. var siz = context.SIZ;
  16170. // Section B.3 Division into tile and tile-components
  16171. var tile, tiles = [];
  16172. var numXtiles = Math.ceil((siz.Xsiz - siz.XTOsiz) / siz.XTsiz);
  16173. var numYtiles = Math.ceil((siz.Ysiz - siz.YTOsiz) / siz.YTsiz);
  16174. for (var q = 0; q < numYtiles; q++) {
  16175. for (var p = 0; p < numXtiles; p++) {
  16176. tile = {};
  16177. tile.tx0 = Math.max(siz.XTOsiz + p * siz.XTsiz, siz.XOsiz);
  16178. tile.ty0 = Math.max(siz.YTOsiz + q * siz.YTsiz, siz.YOsiz);
  16179. tile.tx1 = Math.min(siz.XTOsiz + (p + 1) * siz.XTsiz, siz.Xsiz);
  16180. tile.ty1 = Math.min(siz.YTOsiz + (q + 1) * siz.YTsiz, siz.Ysiz);
  16181. tile.width = tile.tx1 - tile.tx0;
  16182. tile.height = tile.ty1 - tile.ty0;
  16183. tile.components = [];
  16184. tiles.push(tile);
  16185. }
  16186. }
  16187. context.tiles = tiles;
  16188. var componentsCount = siz.Csiz;
  16189. for (var i = 0, ii = componentsCount; i < ii; i++) {
  16190. var component = components[i];
  16191. for (var j = 0, jj = tiles.length; j < jj; j++) {
  16192. var tileComponent = {};
  16193. tile = tiles[j];
  16194. tileComponent.tcx0 = Math.ceil(tile.tx0 / component.XRsiz);
  16195. tileComponent.tcy0 = Math.ceil(tile.ty0 / component.YRsiz);
  16196. tileComponent.tcx1 = Math.ceil(tile.tx1 / component.XRsiz);
  16197. tileComponent.tcy1 = Math.ceil(tile.ty1 / component.YRsiz);
  16198. tileComponent.width = tileComponent.tcx1 - tileComponent.tcx0;
  16199. tileComponent.height = tileComponent.tcy1 - tileComponent.tcy0;
  16200. tile.components[i] = tileComponent;
  16201. }
  16202. }
  16203. }
  16204. function getBlocksDimensions(context, component, r) {
  16205. var codOrCoc = component.codingStyleParameters;
  16206. var result = {};
  16207. if (!codOrCoc.entropyCoderWithCustomPrecincts) {
  16208. result.PPx = 15;
  16209. result.PPy = 15;
  16210. } else {
  16211. result.PPx = codOrCoc.precinctsSizes[r].PPx;
  16212. result.PPy = codOrCoc.precinctsSizes[r].PPy;
  16213. }
  16214. // calculate codeblock size as described in section B.7
  16215. result.xcb_ = r > 0 ? Math.min(codOrCoc.xcb, result.PPx - 1) : Math.min(codOrCoc.xcb, result.PPx);
  16216. result.ycb_ = r > 0 ? Math.min(codOrCoc.ycb, result.PPy - 1) : Math.min(codOrCoc.ycb, result.PPy);
  16217. return result;
  16218. }
  16219. function buildPrecincts(context, resolution, dimensions) {
  16220. // Section B.6 Division resolution to precincts
  16221. var precinctWidth = 1 << dimensions.PPx;
  16222. var precinctHeight = 1 << dimensions.PPy;
  16223. // Jasper introduces codeblock groups for mapping each subband codeblocks
  16224. // to precincts. Precinct partition divides a resolution according to width
  16225. // and height parameters. The subband that belongs to the resolution level
  16226. // has a different size than the level, unless it is the zero resolution.
  16227. // From Jasper documentation: jpeg2000.pdf, section K: Tier-2 coding:
  16228. // The precinct partitioning for a particular subband is derived from a
  16229. // partitioning of its parent LL band (i.e., the LL band at the next higher
  16230. // resolution level)... The LL band associated with each resolution level is
  16231. // divided into precincts... Each of the resulting precinct regions is then
  16232. // mapped into its child subbands (if any) at the next lower resolution
  16233. // level. This is accomplished by using the coordinate transformation
  16234. // (u, v) = (ceil(x/2), ceil(y/2)) where (x, y) and (u, v) are the
  16235. // coordinates of a point in the LL band and child subband, respectively.
  16236. var isZeroRes = resolution.resLevel === 0;
  16237. var precinctWidthInSubband = 1 << dimensions.PPx + (isZeroRes ? 0 : -1);
  16238. var precinctHeightInSubband = 1 << dimensions.PPy + (isZeroRes ? 0 : -1);
  16239. var numprecinctswide = resolution.trx1 > resolution.trx0 ? Math.ceil(resolution.trx1 / precinctWidth) - Math.floor(resolution.trx0 / precinctWidth) : 0;
  16240. var numprecinctshigh = resolution.try1 > resolution.try0 ? Math.ceil(resolution.try1 / precinctHeight) - Math.floor(resolution.try0 / precinctHeight) : 0;
  16241. var numprecincts = numprecinctswide * numprecinctshigh;
  16242. resolution.precinctParameters = {
  16243. precinctWidth: precinctWidth,
  16244. precinctHeight: precinctHeight,
  16245. numprecinctswide: numprecinctswide,
  16246. numprecinctshigh: numprecinctshigh,
  16247. numprecincts: numprecincts,
  16248. precinctWidthInSubband: precinctWidthInSubband,
  16249. precinctHeightInSubband: precinctHeightInSubband
  16250. };
  16251. }
  16252. function buildCodeblocks(context, subband, dimensions) {
  16253. // Section B.7 Division sub-band into code-blocks
  16254. var xcb_ = dimensions.xcb_;
  16255. var ycb_ = dimensions.ycb_;
  16256. var codeblockWidth = 1 << xcb_;
  16257. var codeblockHeight = 1 << ycb_;
  16258. var cbx0 = subband.tbx0 >> xcb_;
  16259. var cby0 = subband.tby0 >> ycb_;
  16260. var cbx1 = subband.tbx1 + codeblockWidth - 1 >> xcb_;
  16261. var cby1 = subband.tby1 + codeblockHeight - 1 >> ycb_;
  16262. var precinctParameters = subband.resolution.precinctParameters;
  16263. var codeblocks = [];
  16264. var precincts = [];
  16265. var i, j, codeblock, precinctNumber;
  16266. for (j = cby0; j < cby1; j++) {
  16267. for (i = cbx0; i < cbx1; i++) {
  16268. codeblock = {
  16269. cbx: i,
  16270. cby: j,
  16271. tbx0: codeblockWidth * i,
  16272. tby0: codeblockHeight * j,
  16273. tbx1: codeblockWidth * (i + 1),
  16274. tby1: codeblockHeight * (j + 1)
  16275. };
  16276. codeblock.tbx0_ = Math.max(subband.tbx0, codeblock.tbx0);
  16277. codeblock.tby0_ = Math.max(subband.tby0, codeblock.tby0);
  16278. codeblock.tbx1_ = Math.min(subband.tbx1, codeblock.tbx1);
  16279. codeblock.tby1_ = Math.min(subband.tby1, codeblock.tby1);
  16280. // Calculate precinct number for this codeblock, codeblock position
  16281. // should be relative to its subband, use actual dimension and position
  16282. // See comment about codeblock group width and height
  16283. var pi = Math.floor((codeblock.tbx0_ - subband.tbx0) / precinctParameters.precinctWidthInSubband);
  16284. var pj = Math.floor((codeblock.tby0_ - subband.tby0) / precinctParameters.precinctHeightInSubband);
  16285. precinctNumber = pi + pj * precinctParameters.numprecinctswide;
  16286. codeblock.precinctNumber = precinctNumber;
  16287. codeblock.subbandType = subband.type;
  16288. codeblock.Lblock = 3;
  16289. if (codeblock.tbx1_ <= codeblock.tbx0_ || codeblock.tby1_ <= codeblock.tby0_) {
  16290. continue;
  16291. }
  16292. codeblocks.push(codeblock);
  16293. // building precinct for the sub-band
  16294. var precinct = precincts[precinctNumber];
  16295. if (precinct !== undefined) {
  16296. if (i < precinct.cbxMin) {
  16297. precinct.cbxMin = i;
  16298. } else if (i > precinct.cbxMax) {
  16299. precinct.cbxMax = i;
  16300. }
  16301. if (j < precinct.cbyMin) {
  16302. precinct.cbxMin = j;
  16303. } else if (j > precinct.cbyMax) {
  16304. precinct.cbyMax = j;
  16305. }
  16306. } else {
  16307. precincts[precinctNumber] = precinct = {
  16308. cbxMin: i,
  16309. cbyMin: j,
  16310. cbxMax: i,
  16311. cbyMax: j
  16312. };
  16313. }
  16314. codeblock.precinct = precinct;
  16315. }
  16316. }
  16317. subband.codeblockParameters = {
  16318. codeblockWidth: xcb_,
  16319. codeblockHeight: ycb_,
  16320. numcodeblockwide: cbx1 - cbx0 + 1,
  16321. numcodeblockhigh: cby1 - cby0 + 1
  16322. };
  16323. subband.codeblocks = codeblocks;
  16324. subband.precincts = precincts;
  16325. }
  16326. function createPacket(resolution, precinctNumber, layerNumber) {
  16327. var precinctCodeblocks = [];
  16328. // Section B.10.8 Order of info in packet
  16329. var subbands = resolution.subbands;
  16330. // sub-bands already ordered in 'LL', 'HL', 'LH', and 'HH' sequence
  16331. for (var i = 0, ii = subbands.length; i < ii; i++) {
  16332. var subband = subbands[i];
  16333. var codeblocks = subband.codeblocks;
  16334. for (var j = 0, jj = codeblocks.length; j < jj; j++) {
  16335. var codeblock = codeblocks[j];
  16336. if (codeblock.precinctNumber !== precinctNumber) {
  16337. continue;
  16338. }
  16339. precinctCodeblocks.push(codeblock);
  16340. }
  16341. }
  16342. return {
  16343. layerNumber: layerNumber,
  16344. codeblocks: precinctCodeblocks
  16345. };
  16346. }
  16347. function LayerResolutionComponentPositionIterator(context) {
  16348. var siz = context.SIZ;
  16349. var tileIndex = context.currentTile.index;
  16350. var tile = context.tiles[tileIndex];
  16351. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  16352. var componentsCount = siz.Csiz;
  16353. var maxDecompositionLevelsCount = 0;
  16354. for (var q = 0; q < componentsCount; q++) {
  16355. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount, tile.components[q].codingStyleParameters.decompositionLevelsCount);
  16356. }
  16357. var l = 0, r = 0, i = 0, k = 0;
  16358. this.nextPacket = function JpxImage_nextPacket() {
  16359. // Section B.12.1.1 Layer-resolution-component-position
  16360. for (; l < layersCount; l++) {
  16361. for (; r <= maxDecompositionLevelsCount; r++) {
  16362. for (; i < componentsCount; i++) {
  16363. var component = tile.components[i];
  16364. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  16365. continue;
  16366. }
  16367. var resolution = component.resolutions[r];
  16368. var numprecincts = resolution.precinctParameters.numprecincts;
  16369. for (; k < numprecincts;) {
  16370. var packet = createPacket(resolution, k, l);
  16371. k++;
  16372. return packet;
  16373. }
  16374. k = 0;
  16375. }
  16376. i = 0;
  16377. }
  16378. r = 0;
  16379. }
  16380. error('JPX Error: Out of packets');
  16381. };
  16382. }
  16383. function ResolutionLayerComponentPositionIterator(context) {
  16384. var siz = context.SIZ;
  16385. var tileIndex = context.currentTile.index;
  16386. var tile = context.tiles[tileIndex];
  16387. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  16388. var componentsCount = siz.Csiz;
  16389. var maxDecompositionLevelsCount = 0;
  16390. for (var q = 0; q < componentsCount; q++) {
  16391. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount, tile.components[q].codingStyleParameters.decompositionLevelsCount);
  16392. }
  16393. var r = 0, l = 0, i = 0, k = 0;
  16394. this.nextPacket = function JpxImage_nextPacket() {
  16395. // Section B.12.1.2 Resolution-layer-component-position
  16396. for (; r <= maxDecompositionLevelsCount; r++) {
  16397. for (; l < layersCount; l++) {
  16398. for (; i < componentsCount; i++) {
  16399. var component = tile.components[i];
  16400. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  16401. continue;
  16402. }
  16403. var resolution = component.resolutions[r];
  16404. var numprecincts = resolution.precinctParameters.numprecincts;
  16405. for (; k < numprecincts;) {
  16406. var packet = createPacket(resolution, k, l);
  16407. k++;
  16408. return packet;
  16409. }
  16410. k = 0;
  16411. }
  16412. i = 0;
  16413. }
  16414. l = 0;
  16415. }
  16416. error('JPX Error: Out of packets');
  16417. };
  16418. }
  16419. function ResolutionPositionComponentLayerIterator(context) {
  16420. var siz = context.SIZ;
  16421. var tileIndex = context.currentTile.index;
  16422. var tile = context.tiles[tileIndex];
  16423. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  16424. var componentsCount = siz.Csiz;
  16425. var l, r, c, p;
  16426. var maxDecompositionLevelsCount = 0;
  16427. for (c = 0; c < componentsCount; c++) {
  16428. var component = tile.components[c];
  16429. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount, component.codingStyleParameters.decompositionLevelsCount);
  16430. }
  16431. var maxNumPrecinctsInLevel = new Int32Array(maxDecompositionLevelsCount + 1);
  16432. for (r = 0; r <= maxDecompositionLevelsCount; ++r) {
  16433. var maxNumPrecincts = 0;
  16434. for (c = 0; c < componentsCount; ++c) {
  16435. var resolutions = tile.components[c].resolutions;
  16436. if (r < resolutions.length) {
  16437. maxNumPrecincts = Math.max(maxNumPrecincts, resolutions[r].precinctParameters.numprecincts);
  16438. }
  16439. }
  16440. maxNumPrecinctsInLevel[r] = maxNumPrecincts;
  16441. }
  16442. l = 0;
  16443. r = 0;
  16444. c = 0;
  16445. p = 0;
  16446. this.nextPacket = function JpxImage_nextPacket() {
  16447. // Section B.12.1.3 Resolution-position-component-layer
  16448. for (; r <= maxDecompositionLevelsCount; r++) {
  16449. for (; p < maxNumPrecinctsInLevel[r]; p++) {
  16450. for (; c < componentsCount; c++) {
  16451. var component = tile.components[c];
  16452. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  16453. continue;
  16454. }
  16455. var resolution = component.resolutions[r];
  16456. var numprecincts = resolution.precinctParameters.numprecincts;
  16457. if (p >= numprecincts) {
  16458. continue;
  16459. }
  16460. for (; l < layersCount;) {
  16461. var packet = createPacket(resolution, p, l);
  16462. l++;
  16463. return packet;
  16464. }
  16465. l = 0;
  16466. }
  16467. c = 0;
  16468. }
  16469. p = 0;
  16470. }
  16471. error('JPX Error: Out of packets');
  16472. };
  16473. }
  16474. function PositionComponentResolutionLayerIterator(context) {
  16475. var siz = context.SIZ;
  16476. var tileIndex = context.currentTile.index;
  16477. var tile = context.tiles[tileIndex];
  16478. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  16479. var componentsCount = siz.Csiz;
  16480. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  16481. var precinctsIterationSizes = precinctsSizes;
  16482. var l = 0, r = 0, c = 0, px = 0, py = 0;
  16483. this.nextPacket = function JpxImage_nextPacket() {
  16484. // Section B.12.1.4 Position-component-resolution-layer
  16485. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  16486. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  16487. for (; c < componentsCount; c++) {
  16488. var component = tile.components[c];
  16489. var decompositionLevelsCount = component.codingStyleParameters.decompositionLevelsCount;
  16490. for (; r <= decompositionLevelsCount; r++) {
  16491. var resolution = component.resolutions[r];
  16492. var sizeInImageScale = precinctsSizes.components[c].resolutions[r];
  16493. var k = getPrecinctIndexIfExist(px, py, sizeInImageScale, precinctsIterationSizes, resolution);
  16494. if (k === null) {
  16495. continue;
  16496. }
  16497. for (; l < layersCount;) {
  16498. var packet = createPacket(resolution, k, l);
  16499. l++;
  16500. return packet;
  16501. }
  16502. l = 0;
  16503. }
  16504. r = 0;
  16505. }
  16506. c = 0;
  16507. }
  16508. px = 0;
  16509. }
  16510. error('JPX Error: Out of packets');
  16511. };
  16512. }
  16513. function ComponentPositionResolutionLayerIterator(context) {
  16514. var siz = context.SIZ;
  16515. var tileIndex = context.currentTile.index;
  16516. var tile = context.tiles[tileIndex];
  16517. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  16518. var componentsCount = siz.Csiz;
  16519. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  16520. var l = 0, r = 0, c = 0, px = 0, py = 0;
  16521. this.nextPacket = function JpxImage_nextPacket() {
  16522. // Section B.12.1.5 Component-position-resolution-layer
  16523. for (; c < componentsCount; ++c) {
  16524. var component = tile.components[c];
  16525. var precinctsIterationSizes = precinctsSizes.components[c];
  16526. var decompositionLevelsCount = component.codingStyleParameters.decompositionLevelsCount;
  16527. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  16528. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  16529. for (; r <= decompositionLevelsCount; r++) {
  16530. var resolution = component.resolutions[r];
  16531. var sizeInImageScale = precinctsIterationSizes.resolutions[r];
  16532. var k = getPrecinctIndexIfExist(px, py, sizeInImageScale, precinctsIterationSizes, resolution);
  16533. if (k === null) {
  16534. continue;
  16535. }
  16536. for (; l < layersCount;) {
  16537. var packet = createPacket(resolution, k, l);
  16538. l++;
  16539. return packet;
  16540. }
  16541. l = 0;
  16542. }
  16543. r = 0;
  16544. }
  16545. px = 0;
  16546. }
  16547. py = 0;
  16548. }
  16549. error('JPX Error: Out of packets');
  16550. };
  16551. }
  16552. function getPrecinctIndexIfExist(pxIndex, pyIndex, sizeInImageScale, precinctIterationSizes, resolution) {
  16553. var posX = pxIndex * precinctIterationSizes.minWidth;
  16554. var posY = pyIndex * precinctIterationSizes.minHeight;
  16555. if (posX % sizeInImageScale.width !== 0 || posY % sizeInImageScale.height !== 0) {
  16556. return null;
  16557. }
  16558. var startPrecinctRowIndex = posY / sizeInImageScale.width * resolution.precinctParameters.numprecinctswide;
  16559. return posX / sizeInImageScale.height + startPrecinctRowIndex;
  16560. }
  16561. function getPrecinctSizesInImageScale(tile) {
  16562. var componentsCount = tile.components.length;
  16563. var minWidth = Number.MAX_VALUE;
  16564. var minHeight = Number.MAX_VALUE;
  16565. var maxNumWide = 0;
  16566. var maxNumHigh = 0;
  16567. var sizePerComponent = new Array(componentsCount);
  16568. for (var c = 0; c < componentsCount; c++) {
  16569. var component = tile.components[c];
  16570. var decompositionLevelsCount = component.codingStyleParameters.decompositionLevelsCount;
  16571. var sizePerResolution = new Array(decompositionLevelsCount + 1);
  16572. var minWidthCurrentComponent = Number.MAX_VALUE;
  16573. var minHeightCurrentComponent = Number.MAX_VALUE;
  16574. var maxNumWideCurrentComponent = 0;
  16575. var maxNumHighCurrentComponent = 0;
  16576. var scale = 1;
  16577. for (var r = decompositionLevelsCount; r >= 0; --r) {
  16578. var resolution = component.resolutions[r];
  16579. var widthCurrentResolution = scale * resolution.precinctParameters.precinctWidth;
  16580. var heightCurrentResolution = scale * resolution.precinctParameters.precinctHeight;
  16581. minWidthCurrentComponent = Math.min(minWidthCurrentComponent, widthCurrentResolution);
  16582. minHeightCurrentComponent = Math.min(minHeightCurrentComponent, heightCurrentResolution);
  16583. maxNumWideCurrentComponent = Math.max(maxNumWideCurrentComponent, resolution.precinctParameters.numprecinctswide);
  16584. maxNumHighCurrentComponent = Math.max(maxNumHighCurrentComponent, resolution.precinctParameters.numprecinctshigh);
  16585. sizePerResolution[r] = {
  16586. width: widthCurrentResolution,
  16587. height: heightCurrentResolution
  16588. };
  16589. scale <<= 1;
  16590. }
  16591. minWidth = Math.min(minWidth, minWidthCurrentComponent);
  16592. minHeight = Math.min(minHeight, minHeightCurrentComponent);
  16593. maxNumWide = Math.max(maxNumWide, maxNumWideCurrentComponent);
  16594. maxNumHigh = Math.max(maxNumHigh, maxNumHighCurrentComponent);
  16595. sizePerComponent[c] = {
  16596. resolutions: sizePerResolution,
  16597. minWidth: minWidthCurrentComponent,
  16598. minHeight: minHeightCurrentComponent,
  16599. maxNumWide: maxNumWideCurrentComponent,
  16600. maxNumHigh: maxNumHighCurrentComponent
  16601. };
  16602. }
  16603. return {
  16604. components: sizePerComponent,
  16605. minWidth: minWidth,
  16606. minHeight: minHeight,
  16607. maxNumWide: maxNumWide,
  16608. maxNumHigh: maxNumHigh
  16609. };
  16610. }
  16611. function buildPackets(context) {
  16612. var siz = context.SIZ;
  16613. var tileIndex = context.currentTile.index;
  16614. var tile = context.tiles[tileIndex];
  16615. var componentsCount = siz.Csiz;
  16616. // Creating resolutions and sub-bands for each component
  16617. for (var c = 0; c < componentsCount; c++) {
  16618. var component = tile.components[c];
  16619. var decompositionLevelsCount = component.codingStyleParameters.decompositionLevelsCount;
  16620. // Section B.5 Resolution levels and sub-bands
  16621. var resolutions = [];
  16622. var subbands = [];
  16623. for (var r = 0; r <= decompositionLevelsCount; r++) {
  16624. var blocksDimensions = getBlocksDimensions(context, component, r);
  16625. var resolution = {};
  16626. var scale = 1 << decompositionLevelsCount - r;
  16627. resolution.trx0 = Math.ceil(component.tcx0 / scale);
  16628. resolution.try0 = Math.ceil(component.tcy0 / scale);
  16629. resolution.trx1 = Math.ceil(component.tcx1 / scale);
  16630. resolution.try1 = Math.ceil(component.tcy1 / scale);
  16631. resolution.resLevel = r;
  16632. buildPrecincts(context, resolution, blocksDimensions);
  16633. resolutions.push(resolution);
  16634. var subband;
  16635. if (r === 0) {
  16636. // one sub-band (LL) with last decomposition
  16637. subband = {};
  16638. subband.type = 'LL';
  16639. subband.tbx0 = Math.ceil(component.tcx0 / scale);
  16640. subband.tby0 = Math.ceil(component.tcy0 / scale);
  16641. subband.tbx1 = Math.ceil(component.tcx1 / scale);
  16642. subband.tby1 = Math.ceil(component.tcy1 / scale);
  16643. subband.resolution = resolution;
  16644. buildCodeblocks(context, subband, blocksDimensions);
  16645. subbands.push(subband);
  16646. resolution.subbands = [subband];
  16647. } else {
  16648. var bscale = 1 << decompositionLevelsCount - r + 1;
  16649. var resolutionSubbands = [];
  16650. // three sub-bands (HL, LH and HH) with rest of decompositions
  16651. subband = {};
  16652. subband.type = 'HL';
  16653. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  16654. subband.tby0 = Math.ceil(component.tcy0 / bscale);
  16655. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  16656. subband.tby1 = Math.ceil(component.tcy1 / bscale);
  16657. subband.resolution = resolution;
  16658. buildCodeblocks(context, subband, blocksDimensions);
  16659. subbands.push(subband);
  16660. resolutionSubbands.push(subband);
  16661. subband = {};
  16662. subband.type = 'LH';
  16663. subband.tbx0 = Math.ceil(component.tcx0 / bscale);
  16664. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  16665. subband.tbx1 = Math.ceil(component.tcx1 / bscale);
  16666. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  16667. subband.resolution = resolution;
  16668. buildCodeblocks(context, subband, blocksDimensions);
  16669. subbands.push(subband);
  16670. resolutionSubbands.push(subband);
  16671. subband = {};
  16672. subband.type = 'HH';
  16673. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  16674. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  16675. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  16676. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  16677. subband.resolution = resolution;
  16678. buildCodeblocks(context, subband, blocksDimensions);
  16679. subbands.push(subband);
  16680. resolutionSubbands.push(subband);
  16681. resolution.subbands = resolutionSubbands;
  16682. }
  16683. }
  16684. component.resolutions = resolutions;
  16685. component.subbands = subbands;
  16686. }
  16687. // Generate the packets sequence
  16688. var progressionOrder = tile.codingStyleDefaultParameters.progressionOrder;
  16689. switch (progressionOrder) {
  16690. case 0:
  16691. tile.packetsIterator = new LayerResolutionComponentPositionIterator(context);
  16692. break;
  16693. case 1:
  16694. tile.packetsIterator = new ResolutionLayerComponentPositionIterator(context);
  16695. break;
  16696. case 2:
  16697. tile.packetsIterator = new ResolutionPositionComponentLayerIterator(context);
  16698. break;
  16699. case 3:
  16700. tile.packetsIterator = new PositionComponentResolutionLayerIterator(context);
  16701. break;
  16702. case 4:
  16703. tile.packetsIterator = new ComponentPositionResolutionLayerIterator(context);
  16704. break;
  16705. default:
  16706. error('JPX Error: Unsupported progression order ' + progressionOrder);
  16707. }
  16708. }
  16709. function parseTilePackets(context, data, offset, dataLength) {
  16710. var position = 0;
  16711. var buffer, bufferSize = 0, skipNextBit = false;
  16712. function readBits(count) {
  16713. while (bufferSize < count) {
  16714. var b = data[offset + position];
  16715. position++;
  16716. if (skipNextBit) {
  16717. buffer = buffer << 7 | b;
  16718. bufferSize += 7;
  16719. skipNextBit = false;
  16720. } else {
  16721. buffer = buffer << 8 | b;
  16722. bufferSize += 8;
  16723. }
  16724. if (b === 0xFF) {
  16725. skipNextBit = true;
  16726. }
  16727. }
  16728. bufferSize -= count;
  16729. return buffer >>> bufferSize & (1 << count) - 1;
  16730. }
  16731. function skipMarkerIfEqual(value) {
  16732. if (data[offset + position - 1] === 0xFF && data[offset + position] === value) {
  16733. skipBytes(1);
  16734. return true;
  16735. } else if (data[offset + position] === 0xFF && data[offset + position + 1] === value) {
  16736. skipBytes(2);
  16737. return true;
  16738. }
  16739. return false;
  16740. }
  16741. function skipBytes(count) {
  16742. position += count;
  16743. }
  16744. function alignToByte() {
  16745. bufferSize = 0;
  16746. if (skipNextBit) {
  16747. position++;
  16748. skipNextBit = false;
  16749. }
  16750. }
  16751. function readCodingpasses() {
  16752. if (readBits(1) === 0) {
  16753. return 1;
  16754. }
  16755. if (readBits(1) === 0) {
  16756. return 2;
  16757. }
  16758. var value = readBits(2);
  16759. if (value < 3) {
  16760. return value + 3;
  16761. }
  16762. value = readBits(5);
  16763. if (value < 31) {
  16764. return value + 6;
  16765. }
  16766. value = readBits(7);
  16767. return value + 37;
  16768. }
  16769. var tileIndex = context.currentTile.index;
  16770. var tile = context.tiles[tileIndex];
  16771. var sopMarkerUsed = context.COD.sopMarkerUsed;
  16772. var ephMarkerUsed = context.COD.ephMarkerUsed;
  16773. var packetsIterator = tile.packetsIterator;
  16774. while (position < dataLength) {
  16775. alignToByte();
  16776. if (sopMarkerUsed && skipMarkerIfEqual(0x91)) {
  16777. // Skip also marker segment length and packet sequence ID
  16778. skipBytes(4);
  16779. }
  16780. var packet = packetsIterator.nextPacket();
  16781. if (!readBits(1)) {
  16782. continue;
  16783. }
  16784. var layerNumber = packet.layerNumber;
  16785. var queue = [], codeblock;
  16786. for (var i = 0, ii = packet.codeblocks.length; i < ii; i++) {
  16787. codeblock = packet.codeblocks[i];
  16788. var precinct = codeblock.precinct;
  16789. var codeblockColumn = codeblock.cbx - precinct.cbxMin;
  16790. var codeblockRow = codeblock.cby - precinct.cbyMin;
  16791. var codeblockIncluded = false;
  16792. var firstTimeInclusion = false;
  16793. var valueReady;
  16794. if (codeblock['included'] !== undefined) {
  16795. codeblockIncluded = !!readBits(1);
  16796. } else {
  16797. // reading inclusion tree
  16798. precinct = codeblock.precinct;
  16799. var inclusionTree, zeroBitPlanesTree;
  16800. if (precinct['inclusionTree'] !== undefined) {
  16801. inclusionTree = precinct.inclusionTree;
  16802. } else {
  16803. // building inclusion and zero bit-planes trees
  16804. var width = precinct.cbxMax - precinct.cbxMin + 1;
  16805. var height = precinct.cbyMax - precinct.cbyMin + 1;
  16806. inclusionTree = new InclusionTree(width, height, layerNumber);
  16807. zeroBitPlanesTree = new TagTree(width, height);
  16808. precinct.inclusionTree = inclusionTree;
  16809. precinct.zeroBitPlanesTree = zeroBitPlanesTree;
  16810. }
  16811. if (inclusionTree.reset(codeblockColumn, codeblockRow, layerNumber)) {
  16812. while (true) {
  16813. if (readBits(1)) {
  16814. valueReady = !inclusionTree.nextLevel();
  16815. if (valueReady) {
  16816. codeblock.included = true;
  16817. codeblockIncluded = firstTimeInclusion = true;
  16818. break;
  16819. }
  16820. } else {
  16821. inclusionTree.incrementValue(layerNumber);
  16822. break;
  16823. }
  16824. }
  16825. }
  16826. }
  16827. if (!codeblockIncluded) {
  16828. continue;
  16829. }
  16830. if (firstTimeInclusion) {
  16831. zeroBitPlanesTree = precinct.zeroBitPlanesTree;
  16832. zeroBitPlanesTree.reset(codeblockColumn, codeblockRow);
  16833. while (true) {
  16834. if (readBits(1)) {
  16835. valueReady = !zeroBitPlanesTree.nextLevel();
  16836. if (valueReady) {
  16837. break;
  16838. }
  16839. } else {
  16840. zeroBitPlanesTree.incrementValue();
  16841. }
  16842. }
  16843. codeblock.zeroBitPlanes = zeroBitPlanesTree.value;
  16844. }
  16845. var codingpasses = readCodingpasses();
  16846. while (readBits(1)) {
  16847. codeblock.Lblock++;
  16848. }
  16849. var codingpassesLog2 = log2(codingpasses);
  16850. // rounding down log2
  16851. var bits = (codingpasses < 1 << codingpassesLog2 ? codingpassesLog2 - 1 : codingpassesLog2) + codeblock.Lblock;
  16852. var codedDataLength = readBits(bits);
  16853. queue.push({
  16854. codeblock: codeblock,
  16855. codingpasses: codingpasses,
  16856. dataLength: codedDataLength
  16857. });
  16858. }
  16859. alignToByte();
  16860. if (ephMarkerUsed) {
  16861. skipMarkerIfEqual(0x92);
  16862. }
  16863. while (queue.length > 0) {
  16864. var packetItem = queue.shift();
  16865. codeblock = packetItem.codeblock;
  16866. if (codeblock['data'] === undefined) {
  16867. codeblock.data = [];
  16868. }
  16869. codeblock.data.push({
  16870. data: data,
  16871. start: offset + position,
  16872. end: offset + position + packetItem.dataLength,
  16873. codingpasses: packetItem.codingpasses
  16874. });
  16875. position += packetItem.dataLength;
  16876. }
  16877. }
  16878. return position;
  16879. }
  16880. function copyCoefficients(coefficients, levelWidth, levelHeight, subband, delta, mb, reversible, segmentationSymbolUsed) {
  16881. var x0 = subband.tbx0;
  16882. var y0 = subband.tby0;
  16883. var width = subband.tbx1 - subband.tbx0;
  16884. var codeblocks = subband.codeblocks;
  16885. var right = subband.type.charAt(0) === 'H' ? 1 : 0;
  16886. var bottom = subband.type.charAt(1) === 'H' ? levelWidth : 0;
  16887. for (var i = 0, ii = codeblocks.length; i < ii; ++i) {
  16888. var codeblock = codeblocks[i];
  16889. var blockWidth = codeblock.tbx1_ - codeblock.tbx0_;
  16890. var blockHeight = codeblock.tby1_ - codeblock.tby0_;
  16891. if (blockWidth === 0 || blockHeight === 0) {
  16892. continue;
  16893. }
  16894. if (codeblock['data'] === undefined) {
  16895. continue;
  16896. }
  16897. var bitModel, currentCodingpassType;
  16898. bitModel = new BitModel(blockWidth, blockHeight, codeblock.subbandType, codeblock.zeroBitPlanes, mb);
  16899. currentCodingpassType = 2;
  16900. // first bit plane starts from cleanup
  16901. // collect data
  16902. var data = codeblock.data, totalLength = 0, codingpasses = 0;
  16903. var j, jj, dataItem;
  16904. for (j = 0, jj = data.length; j < jj; j++) {
  16905. dataItem = data[j];
  16906. totalLength += dataItem.end - dataItem.start;
  16907. codingpasses += dataItem.codingpasses;
  16908. }
  16909. var encodedData = new Uint8Array(totalLength);
  16910. var position = 0;
  16911. for (j = 0, jj = data.length; j < jj; j++) {
  16912. dataItem = data[j];
  16913. var chunk = dataItem.data.subarray(dataItem.start, dataItem.end);
  16914. encodedData.set(chunk, position);
  16915. position += chunk.length;
  16916. }
  16917. // decoding the item
  16918. var decoder = new ArithmeticDecoder(encodedData, 0, totalLength);
  16919. bitModel.setDecoder(decoder);
  16920. for (j = 0; j < codingpasses; j++) {
  16921. switch (currentCodingpassType) {
  16922. case 0:
  16923. bitModel.runSignificancePropagationPass();
  16924. break;
  16925. case 1:
  16926. bitModel.runMagnitudeRefinementPass();
  16927. break;
  16928. case 2:
  16929. bitModel.runCleanupPass();
  16930. if (segmentationSymbolUsed) {
  16931. bitModel.checkSegmentationSymbol();
  16932. }
  16933. break;
  16934. }
  16935. currentCodingpassType = (currentCodingpassType + 1) % 3;
  16936. }
  16937. var offset = codeblock.tbx0_ - x0 + (codeblock.tby0_ - y0) * width;
  16938. var sign = bitModel.coefficentsSign;
  16939. var magnitude = bitModel.coefficentsMagnitude;
  16940. var bitsDecoded = bitModel.bitsDecoded;
  16941. var magnitudeCorrection = reversible ? 0 : 0.5;
  16942. var k, n, nb;
  16943. position = 0;
  16944. // Do the interleaving of Section F.3.3 here, so we do not need
  16945. // to copy later. LL level is not interleaved, just copied.
  16946. var interleave = subband.type !== 'LL';
  16947. for (j = 0; j < blockHeight; j++) {
  16948. var row = offset / width | 0;
  16949. // row in the non-interleaved subband
  16950. var levelOffset = 2 * row * (levelWidth - width) + right + bottom;
  16951. for (k = 0; k < blockWidth; k++) {
  16952. n = magnitude[position];
  16953. if (n !== 0) {
  16954. n = (n + magnitudeCorrection) * delta;
  16955. if (sign[position] !== 0) {
  16956. n = -n;
  16957. }
  16958. nb = bitsDecoded[position];
  16959. var pos = interleave ? levelOffset + (offset << 1) : offset;
  16960. if (reversible && nb >= mb) {
  16961. coefficients[pos] = n;
  16962. } else {
  16963. coefficients[pos] = n * (1 << mb - nb);
  16964. }
  16965. }
  16966. offset++;
  16967. position++;
  16968. }
  16969. offset += width - blockWidth;
  16970. }
  16971. }
  16972. }
  16973. function transformTile(context, tile, c) {
  16974. var component = tile.components[c];
  16975. var codingStyleParameters = component.codingStyleParameters;
  16976. var quantizationParameters = component.quantizationParameters;
  16977. var decompositionLevelsCount = codingStyleParameters.decompositionLevelsCount;
  16978. var spqcds = quantizationParameters.SPqcds;
  16979. var scalarExpounded = quantizationParameters.scalarExpounded;
  16980. var guardBits = quantizationParameters.guardBits;
  16981. var segmentationSymbolUsed = codingStyleParameters.segmentationSymbolUsed;
  16982. var precision = context.components[c].precision;
  16983. var reversible = codingStyleParameters.reversibleTransformation;
  16984. var transform = reversible ? new ReversibleTransform() : new IrreversibleTransform();
  16985. var subbandCoefficients = [];
  16986. var b = 0;
  16987. for (var i = 0; i <= decompositionLevelsCount; i++) {
  16988. var resolution = component.resolutions[i];
  16989. var width = resolution.trx1 - resolution.trx0;
  16990. var height = resolution.try1 - resolution.try0;
  16991. // Allocate space for the whole sublevel.
  16992. var coefficients = new Float32Array(width * height);
  16993. for (var j = 0, jj = resolution.subbands.length; j < jj; j++) {
  16994. var mu, epsilon;
  16995. if (!scalarExpounded) {
  16996. // formula E-5
  16997. mu = spqcds[0].mu;
  16998. epsilon = spqcds[0].epsilon + (i > 0 ? 1 - i : 0);
  16999. } else {
  17000. mu = spqcds[b].mu;
  17001. epsilon = spqcds[b].epsilon;
  17002. b++;
  17003. }
  17004. var subband = resolution.subbands[j];
  17005. var gainLog2 = SubbandsGainLog2[subband.type];
  17006. // calculate quantization coefficient (Section E.1.1.1)
  17007. var delta = reversible ? 1 : Math.pow(2, precision + gainLog2 - epsilon) * (1 + mu / 2048);
  17008. var mb = guardBits + epsilon - 1;
  17009. // In the first resolution level, copyCoefficients will fill the
  17010. // whole array with coefficients. In the succeeding passes,
  17011. // copyCoefficients will consecutively fill in the values that belong
  17012. // to the interleaved positions of the HL, LH, and HH coefficients.
  17013. // The LL coefficients will then be interleaved in Transform.iterate().
  17014. copyCoefficients(coefficients, width, height, subband, delta, mb, reversible, segmentationSymbolUsed);
  17015. }
  17016. subbandCoefficients.push({
  17017. width: width,
  17018. height: height,
  17019. items: coefficients
  17020. });
  17021. }
  17022. var result = transform.calculate(subbandCoefficients, component.tcx0, component.tcy0);
  17023. return {
  17024. left: component.tcx0,
  17025. top: component.tcy0,
  17026. width: result.width,
  17027. height: result.height,
  17028. items: result.items
  17029. };
  17030. }
  17031. function transformComponents(context) {
  17032. var siz = context.SIZ;
  17033. var components = context.components;
  17034. var componentsCount = siz.Csiz;
  17035. var resultImages = [];
  17036. for (var i = 0, ii = context.tiles.length; i < ii; i++) {
  17037. var tile = context.tiles[i];
  17038. var transformedTiles = [];
  17039. var c;
  17040. for (c = 0; c < componentsCount; c++) {
  17041. transformedTiles[c] = transformTile(context, tile, c);
  17042. }
  17043. var tile0 = transformedTiles[0];
  17044. var out = new Uint8Array(tile0.items.length * componentsCount);
  17045. var result = {
  17046. left: tile0.left,
  17047. top: tile0.top,
  17048. width: tile0.width,
  17049. height: tile0.height,
  17050. items: out
  17051. };
  17052. // Section G.2.2 Inverse multi component transform
  17053. var shift, offset, max, min, maxK;
  17054. var pos = 0, j, jj, y0, y1, y2, r, g, b, k, val;
  17055. if (tile.codingStyleDefaultParameters.multipleComponentTransform) {
  17056. var fourComponents = componentsCount === 4;
  17057. var y0items = transformedTiles[0].items;
  17058. var y1items = transformedTiles[1].items;
  17059. var y2items = transformedTiles[2].items;
  17060. var y3items = fourComponents ? transformedTiles[3].items : null;
  17061. // HACK: The multiple component transform formulas below assume that
  17062. // all components have the same precision. With this in mind, we
  17063. // compute shift and offset only once.
  17064. shift = components[0].precision - 8;
  17065. offset = (128 << shift) + 0.5;
  17066. max = 255 * (1 << shift);
  17067. maxK = max * 0.5;
  17068. min = -maxK;
  17069. var component0 = tile.components[0];
  17070. var alpha01 = componentsCount - 3;
  17071. jj = y0items.length;
  17072. if (!component0.codingStyleParameters.reversibleTransformation) {
  17073. // inverse irreversible multiple component transform
  17074. for (j = 0; j < jj; j++, pos += alpha01) {
  17075. y0 = y0items[j] + offset;
  17076. y1 = y1items[j];
  17077. y2 = y2items[j];
  17078. r = y0 + 1.402 * y2;
  17079. g = y0 - 0.34413 * y1 - 0.71414 * y2;
  17080. b = y0 + 1.772 * y1;
  17081. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  17082. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  17083. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  17084. }
  17085. } else {
  17086. // inverse reversible multiple component transform
  17087. for (j = 0; j < jj; j++, pos += alpha01) {
  17088. y0 = y0items[j] + offset;
  17089. y1 = y1items[j];
  17090. y2 = y2items[j];
  17091. g = y0 - (y2 + y1 >> 2);
  17092. r = g + y2;
  17093. b = g + y1;
  17094. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  17095. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  17096. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  17097. }
  17098. }
  17099. if (fourComponents) {
  17100. for (j = 0, pos = 3; j < jj; j++, pos += 4) {
  17101. k = y3items[j];
  17102. out[pos] = k <= min ? 0 : k >= maxK ? 255 : k + offset >> shift;
  17103. }
  17104. }
  17105. } else {
  17106. // no multi-component transform
  17107. for (c = 0; c < componentsCount; c++) {
  17108. var items = transformedTiles[c].items;
  17109. shift = components[c].precision - 8;
  17110. offset = (128 << shift) + 0.5;
  17111. max = 127.5 * (1 << shift);
  17112. min = -max;
  17113. for (pos = c, j = 0, jj = items.length; j < jj; j++) {
  17114. val = items[j];
  17115. out[pos] = val <= min ? 0 : val >= max ? 255 : val + offset >> shift;
  17116. pos += componentsCount;
  17117. }
  17118. }
  17119. }
  17120. resultImages.push(result);
  17121. }
  17122. return resultImages;
  17123. }
  17124. function initializeTile(context, tileIndex) {
  17125. var siz = context.SIZ;
  17126. var componentsCount = siz.Csiz;
  17127. var tile = context.tiles[tileIndex];
  17128. for (var c = 0; c < componentsCount; c++) {
  17129. var component = tile.components[c];
  17130. var qcdOrQcc = context.currentTile.QCC[c] !== undefined ? context.currentTile.QCC[c] : context.currentTile.QCD;
  17131. component.quantizationParameters = qcdOrQcc;
  17132. var codOrCoc = context.currentTile.COC[c] !== undefined ? context.currentTile.COC[c] : context.currentTile.COD;
  17133. component.codingStyleParameters = codOrCoc;
  17134. }
  17135. tile.codingStyleDefaultParameters = context.currentTile.COD;
  17136. }
  17137. // Section B.10.2 Tag trees
  17138. var TagTree = function TagTreeClosure() {
  17139. function TagTree(width, height) {
  17140. var levelsLength = log2(Math.max(width, height)) + 1;
  17141. this.levels = [];
  17142. for (var i = 0; i < levelsLength; i++) {
  17143. var level = {
  17144. width: width,
  17145. height: height,
  17146. items: []
  17147. };
  17148. this.levels.push(level);
  17149. width = Math.ceil(width / 2);
  17150. height = Math.ceil(height / 2);
  17151. }
  17152. }
  17153. TagTree.prototype = {
  17154. reset: function TagTree_reset(i, j) {
  17155. var currentLevel = 0, value = 0, level;
  17156. while (currentLevel < this.levels.length) {
  17157. level = this.levels[currentLevel];
  17158. var index = i + j * level.width;
  17159. if (level.items[index] !== undefined) {
  17160. value = level.items[index];
  17161. break;
  17162. }
  17163. level.index = index;
  17164. i >>= 1;
  17165. j >>= 1;
  17166. currentLevel++;
  17167. }
  17168. currentLevel--;
  17169. level = this.levels[currentLevel];
  17170. level.items[level.index] = value;
  17171. this.currentLevel = currentLevel;
  17172. delete this.value;
  17173. },
  17174. incrementValue: function TagTree_incrementValue() {
  17175. var level = this.levels[this.currentLevel];
  17176. level.items[level.index]++;
  17177. },
  17178. nextLevel: function TagTree_nextLevel() {
  17179. var currentLevel = this.currentLevel;
  17180. var level = this.levels[currentLevel];
  17181. var value = level.items[level.index];
  17182. currentLevel--;
  17183. if (currentLevel < 0) {
  17184. this.value = value;
  17185. return false;
  17186. }
  17187. this.currentLevel = currentLevel;
  17188. level = this.levels[currentLevel];
  17189. level.items[level.index] = value;
  17190. return true;
  17191. }
  17192. };
  17193. return TagTree;
  17194. }();
  17195. var InclusionTree = function InclusionTreeClosure() {
  17196. function InclusionTree(width, height, defaultValue) {
  17197. var levelsLength = log2(Math.max(width, height)) + 1;
  17198. this.levels = [];
  17199. for (var i = 0; i < levelsLength; i++) {
  17200. var items = new Uint8Array(width * height);
  17201. for (var j = 0, jj = items.length; j < jj; j++) {
  17202. items[j] = defaultValue;
  17203. }
  17204. var level = {
  17205. width: width,
  17206. height: height,
  17207. items: items
  17208. };
  17209. this.levels.push(level);
  17210. width = Math.ceil(width / 2);
  17211. height = Math.ceil(height / 2);
  17212. }
  17213. }
  17214. InclusionTree.prototype = {
  17215. reset: function InclusionTree_reset(i, j, stopValue) {
  17216. var currentLevel = 0;
  17217. while (currentLevel < this.levels.length) {
  17218. var level = this.levels[currentLevel];
  17219. var index = i + j * level.width;
  17220. level.index = index;
  17221. var value = level.items[index];
  17222. if (value === 0xFF) {
  17223. break;
  17224. }
  17225. if (value > stopValue) {
  17226. this.currentLevel = currentLevel;
  17227. // already know about this one, propagating the value to top levels
  17228. this.propagateValues();
  17229. return false;
  17230. }
  17231. i >>= 1;
  17232. j >>= 1;
  17233. currentLevel++;
  17234. }
  17235. this.currentLevel = currentLevel - 1;
  17236. return true;
  17237. },
  17238. incrementValue: function InclusionTree_incrementValue(stopValue) {
  17239. var level = this.levels[this.currentLevel];
  17240. level.items[level.index] = stopValue + 1;
  17241. this.propagateValues();
  17242. },
  17243. propagateValues: function InclusionTree_propagateValues() {
  17244. var levelIndex = this.currentLevel;
  17245. var level = this.levels[levelIndex];
  17246. var currentValue = level.items[level.index];
  17247. while (--levelIndex >= 0) {
  17248. level = this.levels[levelIndex];
  17249. level.items[level.index] = currentValue;
  17250. }
  17251. },
  17252. nextLevel: function InclusionTree_nextLevel() {
  17253. var currentLevel = this.currentLevel;
  17254. var level = this.levels[currentLevel];
  17255. var value = level.items[level.index];
  17256. level.items[level.index] = 0xFF;
  17257. currentLevel--;
  17258. if (currentLevel < 0) {
  17259. return false;
  17260. }
  17261. this.currentLevel = currentLevel;
  17262. level = this.levels[currentLevel];
  17263. level.items[level.index] = value;
  17264. return true;
  17265. }
  17266. };
  17267. return InclusionTree;
  17268. }();
  17269. // Section D. Coefficient bit modeling
  17270. var BitModel = function BitModelClosure() {
  17271. var UNIFORM_CONTEXT = 17;
  17272. var RUNLENGTH_CONTEXT = 18;
  17273. // Table D-1
  17274. // The index is binary presentation: 0dddvvhh, ddd - sum of Di (0..4),
  17275. // vv - sum of Vi (0..2), and hh - sum of Hi (0..2)
  17276. var LLAndLHContextsLabel = new Uint8Array([
  17277. 0,
  17278. 5,
  17279. 8,
  17280. 0,
  17281. 3,
  17282. 7,
  17283. 8,
  17284. 0,
  17285. 4,
  17286. 7,
  17287. 8,
  17288. 0,
  17289. 0,
  17290. 0,
  17291. 0,
  17292. 0,
  17293. 1,
  17294. 6,
  17295. 8,
  17296. 0,
  17297. 3,
  17298. 7,
  17299. 8,
  17300. 0,
  17301. 4,
  17302. 7,
  17303. 8,
  17304. 0,
  17305. 0,
  17306. 0,
  17307. 0,
  17308. 0,
  17309. 2,
  17310. 6,
  17311. 8,
  17312. 0,
  17313. 3,
  17314. 7,
  17315. 8,
  17316. 0,
  17317. 4,
  17318. 7,
  17319. 8,
  17320. 0,
  17321. 0,
  17322. 0,
  17323. 0,
  17324. 0,
  17325. 2,
  17326. 6,
  17327. 8,
  17328. 0,
  17329. 3,
  17330. 7,
  17331. 8,
  17332. 0,
  17333. 4,
  17334. 7,
  17335. 8,
  17336. 0,
  17337. 0,
  17338. 0,
  17339. 0,
  17340. 0,
  17341. 2,
  17342. 6,
  17343. 8,
  17344. 0,
  17345. 3,
  17346. 7,
  17347. 8,
  17348. 0,
  17349. 4,
  17350. 7,
  17351. 8
  17352. ]);
  17353. var HLContextLabel = new Uint8Array([
  17354. 0,
  17355. 3,
  17356. 4,
  17357. 0,
  17358. 5,
  17359. 7,
  17360. 7,
  17361. 0,
  17362. 8,
  17363. 8,
  17364. 8,
  17365. 0,
  17366. 0,
  17367. 0,
  17368. 0,
  17369. 0,
  17370. 1,
  17371. 3,
  17372. 4,
  17373. 0,
  17374. 6,
  17375. 7,
  17376. 7,
  17377. 0,
  17378. 8,
  17379. 8,
  17380. 8,
  17381. 0,
  17382. 0,
  17383. 0,
  17384. 0,
  17385. 0,
  17386. 2,
  17387. 3,
  17388. 4,
  17389. 0,
  17390. 6,
  17391. 7,
  17392. 7,
  17393. 0,
  17394. 8,
  17395. 8,
  17396. 8,
  17397. 0,
  17398. 0,
  17399. 0,
  17400. 0,
  17401. 0,
  17402. 2,
  17403. 3,
  17404. 4,
  17405. 0,
  17406. 6,
  17407. 7,
  17408. 7,
  17409. 0,
  17410. 8,
  17411. 8,
  17412. 8,
  17413. 0,
  17414. 0,
  17415. 0,
  17416. 0,
  17417. 0,
  17418. 2,
  17419. 3,
  17420. 4,
  17421. 0,
  17422. 6,
  17423. 7,
  17424. 7,
  17425. 0,
  17426. 8,
  17427. 8,
  17428. 8
  17429. ]);
  17430. var HHContextLabel = new Uint8Array([
  17431. 0,
  17432. 1,
  17433. 2,
  17434. 0,
  17435. 1,
  17436. 2,
  17437. 2,
  17438. 0,
  17439. 2,
  17440. 2,
  17441. 2,
  17442. 0,
  17443. 0,
  17444. 0,
  17445. 0,
  17446. 0,
  17447. 3,
  17448. 4,
  17449. 5,
  17450. 0,
  17451. 4,
  17452. 5,
  17453. 5,
  17454. 0,
  17455. 5,
  17456. 5,
  17457. 5,
  17458. 0,
  17459. 0,
  17460. 0,
  17461. 0,
  17462. 0,
  17463. 6,
  17464. 7,
  17465. 7,
  17466. 0,
  17467. 7,
  17468. 7,
  17469. 7,
  17470. 0,
  17471. 7,
  17472. 7,
  17473. 7,
  17474. 0,
  17475. 0,
  17476. 0,
  17477. 0,
  17478. 0,
  17479. 8,
  17480. 8,
  17481. 8,
  17482. 0,
  17483. 8,
  17484. 8,
  17485. 8,
  17486. 0,
  17487. 8,
  17488. 8,
  17489. 8,
  17490. 0,
  17491. 0,
  17492. 0,
  17493. 0,
  17494. 0,
  17495. 8,
  17496. 8,
  17497. 8,
  17498. 0,
  17499. 8,
  17500. 8,
  17501. 8,
  17502. 0,
  17503. 8,
  17504. 8,
  17505. 8
  17506. ]);
  17507. function BitModel(width, height, subband, zeroBitPlanes, mb) {
  17508. this.width = width;
  17509. this.height = height;
  17510. this.contextLabelTable = subband === 'HH' ? HHContextLabel : subband === 'HL' ? HLContextLabel : LLAndLHContextsLabel;
  17511. var coefficientCount = width * height;
  17512. // coefficients outside the encoding region treated as insignificant
  17513. // add border state cells for significanceState
  17514. this.neighborsSignificance = new Uint8Array(coefficientCount);
  17515. this.coefficentsSign = new Uint8Array(coefficientCount);
  17516. this.coefficentsMagnitude = mb > 14 ? new Uint32Array(coefficientCount) : mb > 6 ? new Uint16Array(coefficientCount) : new Uint8Array(coefficientCount);
  17517. this.processingFlags = new Uint8Array(coefficientCount);
  17518. var bitsDecoded = new Uint8Array(coefficientCount);
  17519. if (zeroBitPlanes !== 0) {
  17520. for (var i = 0; i < coefficientCount; i++) {
  17521. bitsDecoded[i] = zeroBitPlanes;
  17522. }
  17523. }
  17524. this.bitsDecoded = bitsDecoded;
  17525. this.reset();
  17526. }
  17527. BitModel.prototype = {
  17528. setDecoder: function BitModel_setDecoder(decoder) {
  17529. this.decoder = decoder;
  17530. },
  17531. reset: function BitModel_reset() {
  17532. // We have 17 contexts that are accessed via context labels,
  17533. // plus the uniform and runlength context.
  17534. this.contexts = new Int8Array(19);
  17535. // Contexts are packed into 1 byte:
  17536. // highest 7 bits carry the index, lowest bit carries mps
  17537. this.contexts[0] = 4 << 1 | 0;
  17538. this.contexts[UNIFORM_CONTEXT] = 46 << 1 | 0;
  17539. this.contexts[RUNLENGTH_CONTEXT] = 3 << 1 | 0;
  17540. },
  17541. setNeighborsSignificance: function BitModel_setNeighborsSignificance(row, column, index) {
  17542. var neighborsSignificance = this.neighborsSignificance;
  17543. var width = this.width, height = this.height;
  17544. var left = column > 0;
  17545. var right = column + 1 < width;
  17546. var i;
  17547. if (row > 0) {
  17548. i = index - width;
  17549. if (left) {
  17550. neighborsSignificance[i - 1] += 0x10;
  17551. }
  17552. if (right) {
  17553. neighborsSignificance[i + 1] += 0x10;
  17554. }
  17555. neighborsSignificance[i] += 0x04;
  17556. }
  17557. if (row + 1 < height) {
  17558. i = index + width;
  17559. if (left) {
  17560. neighborsSignificance[i - 1] += 0x10;
  17561. }
  17562. if (right) {
  17563. neighborsSignificance[i + 1] += 0x10;
  17564. }
  17565. neighborsSignificance[i] += 0x04;
  17566. }
  17567. if (left) {
  17568. neighborsSignificance[index - 1] += 0x01;
  17569. }
  17570. if (right) {
  17571. neighborsSignificance[index + 1] += 0x01;
  17572. }
  17573. neighborsSignificance[index] |= 0x80;
  17574. },
  17575. runSignificancePropagationPass: function BitModel_runSignificancePropagationPass() {
  17576. var decoder = this.decoder;
  17577. var width = this.width, height = this.height;
  17578. var coefficentsMagnitude = this.coefficentsMagnitude;
  17579. var coefficentsSign = this.coefficentsSign;
  17580. var neighborsSignificance = this.neighborsSignificance;
  17581. var processingFlags = this.processingFlags;
  17582. var contexts = this.contexts;
  17583. var labels = this.contextLabelTable;
  17584. var bitsDecoded = this.bitsDecoded;
  17585. var processedInverseMask = ~1;
  17586. var processedMask = 1;
  17587. var firstMagnitudeBitMask = 2;
  17588. for (var i0 = 0; i0 < height; i0 += 4) {
  17589. for (var j = 0; j < width; j++) {
  17590. var index = i0 * width + j;
  17591. for (var i1 = 0; i1 < 4; i1++, index += width) {
  17592. var i = i0 + i1;
  17593. if (i >= height) {
  17594. break;
  17595. }
  17596. // clear processed flag first
  17597. processingFlags[index] &= processedInverseMask;
  17598. if (coefficentsMagnitude[index] || !neighborsSignificance[index]) {
  17599. continue;
  17600. }
  17601. var contextLabel = labels[neighborsSignificance[index]];
  17602. var decision = decoder.readBit(contexts, contextLabel);
  17603. if (decision) {
  17604. var sign = this.decodeSignBit(i, j, index);
  17605. coefficentsSign[index] = sign;
  17606. coefficentsMagnitude[index] = 1;
  17607. this.setNeighborsSignificance(i, j, index);
  17608. processingFlags[index] |= firstMagnitudeBitMask;
  17609. }
  17610. bitsDecoded[index]++;
  17611. processingFlags[index] |= processedMask;
  17612. }
  17613. }
  17614. }
  17615. },
  17616. decodeSignBit: function BitModel_decodeSignBit(row, column, index) {
  17617. var width = this.width, height = this.height;
  17618. var coefficentsMagnitude = this.coefficentsMagnitude;
  17619. var coefficentsSign = this.coefficentsSign;
  17620. var contribution, sign0, sign1, significance1;
  17621. var contextLabel, decoded;
  17622. // calculate horizontal contribution
  17623. significance1 = column > 0 && coefficentsMagnitude[index - 1] !== 0;
  17624. if (column + 1 < width && coefficentsMagnitude[index + 1] !== 0) {
  17625. sign1 = coefficentsSign[index + 1];
  17626. if (significance1) {
  17627. sign0 = coefficentsSign[index - 1];
  17628. contribution = 1 - sign1 - sign0;
  17629. } else {
  17630. contribution = 1 - sign1 - sign1;
  17631. }
  17632. } else if (significance1) {
  17633. sign0 = coefficentsSign[index - 1];
  17634. contribution = 1 - sign0 - sign0;
  17635. } else {
  17636. contribution = 0;
  17637. }
  17638. var horizontalContribution = 3 * contribution;
  17639. // calculate vertical contribution and combine with the horizontal
  17640. significance1 = row > 0 && coefficentsMagnitude[index - width] !== 0;
  17641. if (row + 1 < height && coefficentsMagnitude[index + width] !== 0) {
  17642. sign1 = coefficentsSign[index + width];
  17643. if (significance1) {
  17644. sign0 = coefficentsSign[index - width];
  17645. contribution = 1 - sign1 - sign0 + horizontalContribution;
  17646. } else {
  17647. contribution = 1 - sign1 - sign1 + horizontalContribution;
  17648. }
  17649. } else if (significance1) {
  17650. sign0 = coefficentsSign[index - width];
  17651. contribution = 1 - sign0 - sign0 + horizontalContribution;
  17652. } else {
  17653. contribution = horizontalContribution;
  17654. }
  17655. if (contribution >= 0) {
  17656. contextLabel = 9 + contribution;
  17657. decoded = this.decoder.readBit(this.contexts, contextLabel);
  17658. } else {
  17659. contextLabel = 9 - contribution;
  17660. decoded = this.decoder.readBit(this.contexts, contextLabel) ^ 1;
  17661. }
  17662. return decoded;
  17663. },
  17664. runMagnitudeRefinementPass: function BitModel_runMagnitudeRefinementPass() {
  17665. var decoder = this.decoder;
  17666. var width = this.width, height = this.height;
  17667. var coefficentsMagnitude = this.coefficentsMagnitude;
  17668. var neighborsSignificance = this.neighborsSignificance;
  17669. var contexts = this.contexts;
  17670. var bitsDecoded = this.bitsDecoded;
  17671. var processingFlags = this.processingFlags;
  17672. var processedMask = 1;
  17673. var firstMagnitudeBitMask = 2;
  17674. var length = width * height;
  17675. var width4 = width * 4;
  17676. for (var index0 = 0, indexNext; index0 < length; index0 = indexNext) {
  17677. indexNext = Math.min(length, index0 + width4);
  17678. for (var j = 0; j < width; j++) {
  17679. for (var index = index0 + j; index < indexNext; index += width) {
  17680. // significant but not those that have just become
  17681. if (!coefficentsMagnitude[index] || (processingFlags[index] & processedMask) !== 0) {
  17682. continue;
  17683. }
  17684. var contextLabel = 16;
  17685. if ((processingFlags[index] & firstMagnitudeBitMask) !== 0) {
  17686. processingFlags[index] ^= firstMagnitudeBitMask;
  17687. // first refinement
  17688. var significance = neighborsSignificance[index] & 127;
  17689. contextLabel = significance === 0 ? 15 : 14;
  17690. }
  17691. var bit = decoder.readBit(contexts, contextLabel);
  17692. coefficentsMagnitude[index] = coefficentsMagnitude[index] << 1 | bit;
  17693. bitsDecoded[index]++;
  17694. processingFlags[index] |= processedMask;
  17695. }
  17696. }
  17697. }
  17698. },
  17699. runCleanupPass: function BitModel_runCleanupPass() {
  17700. var decoder = this.decoder;
  17701. var width = this.width, height = this.height;
  17702. var neighborsSignificance = this.neighborsSignificance;
  17703. var coefficentsMagnitude = this.coefficentsMagnitude;
  17704. var coefficentsSign = this.coefficentsSign;
  17705. var contexts = this.contexts;
  17706. var labels = this.contextLabelTable;
  17707. var bitsDecoded = this.bitsDecoded;
  17708. var processingFlags = this.processingFlags;
  17709. var processedMask = 1;
  17710. var firstMagnitudeBitMask = 2;
  17711. var oneRowDown = width;
  17712. var twoRowsDown = width * 2;
  17713. var threeRowsDown = width * 3;
  17714. var iNext;
  17715. for (var i0 = 0; i0 < height; i0 = iNext) {
  17716. iNext = Math.min(i0 + 4, height);
  17717. var indexBase = i0 * width;
  17718. var checkAllEmpty = i0 + 3 < height;
  17719. for (var j = 0; j < width; j++) {
  17720. var index0 = indexBase + j;
  17721. // using the property: labels[neighborsSignificance[index]] === 0
  17722. // when neighborsSignificance[index] === 0
  17723. 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;
  17724. var i1 = 0, index = index0;
  17725. var i = i0, sign;
  17726. if (allEmpty) {
  17727. var hasSignificantCoefficent = decoder.readBit(contexts, RUNLENGTH_CONTEXT);
  17728. if (!hasSignificantCoefficent) {
  17729. bitsDecoded[index0]++;
  17730. bitsDecoded[index0 + oneRowDown]++;
  17731. bitsDecoded[index0 + twoRowsDown]++;
  17732. bitsDecoded[index0 + threeRowsDown]++;
  17733. continue;
  17734. }
  17735. // next column
  17736. i1 = decoder.readBit(contexts, UNIFORM_CONTEXT) << 1 | decoder.readBit(contexts, UNIFORM_CONTEXT);
  17737. if (i1 !== 0) {
  17738. i = i0 + i1;
  17739. index += i1 * width;
  17740. }
  17741. sign = this.decodeSignBit(i, j, index);
  17742. coefficentsSign[index] = sign;
  17743. coefficentsMagnitude[index] = 1;
  17744. this.setNeighborsSignificance(i, j, index);
  17745. processingFlags[index] |= firstMagnitudeBitMask;
  17746. index = index0;
  17747. for (var i2 = i0; i2 <= i; i2++, index += width) {
  17748. bitsDecoded[index]++;
  17749. }
  17750. i1++;
  17751. }
  17752. for (i = i0 + i1; i < iNext; i++, index += width) {
  17753. if (coefficentsMagnitude[index] || (processingFlags[index] & processedMask) !== 0) {
  17754. continue;
  17755. }
  17756. var contextLabel = labels[neighborsSignificance[index]];
  17757. var decision = decoder.readBit(contexts, contextLabel);
  17758. if (decision === 1) {
  17759. sign = this.decodeSignBit(i, j, index);
  17760. coefficentsSign[index] = sign;
  17761. coefficentsMagnitude[index] = 1;
  17762. this.setNeighborsSignificance(i, j, index);
  17763. processingFlags[index] |= firstMagnitudeBitMask;
  17764. }
  17765. bitsDecoded[index]++;
  17766. }
  17767. }
  17768. }
  17769. },
  17770. checkSegmentationSymbol: function BitModel_checkSegmentationSymbol() {
  17771. var decoder = this.decoder;
  17772. var contexts = this.contexts;
  17773. 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);
  17774. if (symbol !== 0xA) {
  17775. error('JPX Error: Invalid segmentation symbol');
  17776. }
  17777. }
  17778. };
  17779. return BitModel;
  17780. }();
  17781. // Section F, Discrete wavelet transformation
  17782. var Transform = function TransformClosure() {
  17783. function Transform() {
  17784. }
  17785. Transform.prototype.calculate = function transformCalculate(subbands, u0, v0) {
  17786. var ll = subbands[0];
  17787. for (var i = 1, ii = subbands.length; i < ii; i++) {
  17788. ll = this.iterate(ll, subbands[i], u0, v0);
  17789. }
  17790. return ll;
  17791. };
  17792. Transform.prototype.extend = function extend(buffer, offset, size) {
  17793. // Section F.3.7 extending... using max extension of 4
  17794. var i1 = offset - 1, j1 = offset + 1;
  17795. var i2 = offset + size - 2, j2 = offset + size;
  17796. buffer[i1--] = buffer[j1++];
  17797. buffer[j2++] = buffer[i2--];
  17798. buffer[i1--] = buffer[j1++];
  17799. buffer[j2++] = buffer[i2--];
  17800. buffer[i1--] = buffer[j1++];
  17801. buffer[j2++] = buffer[i2--];
  17802. buffer[i1] = buffer[j1];
  17803. buffer[j2] = buffer[i2];
  17804. };
  17805. Transform.prototype.iterate = function Transform_iterate(ll, hl_lh_hh, u0, v0) {
  17806. var llWidth = ll.width, llHeight = ll.height, llItems = ll.items;
  17807. var width = hl_lh_hh.width;
  17808. var height = hl_lh_hh.height;
  17809. var items = hl_lh_hh.items;
  17810. var i, j, k, l, u, v;
  17811. // Interleave LL according to Section F.3.3
  17812. for (k = 0, i = 0; i < llHeight; i++) {
  17813. l = i * 2 * width;
  17814. for (j = 0; j < llWidth; j++, k++, l += 2) {
  17815. items[l] = llItems[k];
  17816. }
  17817. }
  17818. // The LL band is not needed anymore.
  17819. llItems = ll.items = null;
  17820. var bufferPadding = 4;
  17821. var rowBuffer = new Float32Array(width + 2 * bufferPadding);
  17822. // Section F.3.4 HOR_SR
  17823. if (width === 1) {
  17824. // if width = 1, when u0 even keep items as is, when odd divide by 2
  17825. if ((u0 & 1) !== 0) {
  17826. for (v = 0, k = 0; v < height; v++, k += width) {
  17827. items[k] *= 0.5;
  17828. }
  17829. }
  17830. } else {
  17831. for (v = 0, k = 0; v < height; v++, k += width) {
  17832. rowBuffer.set(items.subarray(k, k + width), bufferPadding);
  17833. this.extend(rowBuffer, bufferPadding, width);
  17834. this.filter(rowBuffer, bufferPadding, width);
  17835. items.set(rowBuffer.subarray(bufferPadding, bufferPadding + width), k);
  17836. }
  17837. }
  17838. // Accesses to the items array can take long, because it may not fit into
  17839. // CPU cache and has to be fetched from main memory. Since subsequent
  17840. // accesses to the items array are not local when reading columns, we
  17841. // have a cache miss every time. To reduce cache misses, get up to
  17842. // 'numBuffers' items at a time and store them into the individual
  17843. // buffers. The colBuffers should be small enough to fit into CPU cache.
  17844. var numBuffers = 16;
  17845. var colBuffers = [];
  17846. for (i = 0; i < numBuffers; i++) {
  17847. colBuffers.push(new Float32Array(height + 2 * bufferPadding));
  17848. }
  17849. var b, currentBuffer = 0;
  17850. ll = bufferPadding + height;
  17851. // Section F.3.5 VER_SR
  17852. if (height === 1) {
  17853. // if height = 1, when v0 even keep items as is, when odd divide by 2
  17854. if ((v0 & 1) !== 0) {
  17855. for (u = 0; u < width; u++) {
  17856. items[u] *= 0.5;
  17857. }
  17858. }
  17859. } else {
  17860. for (u = 0; u < width; u++) {
  17861. // if we ran out of buffers, copy several image columns at once
  17862. if (currentBuffer === 0) {
  17863. numBuffers = Math.min(width - u, numBuffers);
  17864. for (k = u, l = bufferPadding; l < ll; k += width, l++) {
  17865. for (b = 0; b < numBuffers; b++) {
  17866. colBuffers[b][l] = items[k + b];
  17867. }
  17868. }
  17869. currentBuffer = numBuffers;
  17870. }
  17871. currentBuffer--;
  17872. var buffer = colBuffers[currentBuffer];
  17873. this.extend(buffer, bufferPadding, height);
  17874. this.filter(buffer, bufferPadding, height);
  17875. // If this is last buffer in this group of buffers, flush all buffers.
  17876. if (currentBuffer === 0) {
  17877. k = u - numBuffers + 1;
  17878. for (l = bufferPadding; l < ll; k += width, l++) {
  17879. for (b = 0; b < numBuffers; b++) {
  17880. items[k + b] = colBuffers[b][l];
  17881. }
  17882. }
  17883. }
  17884. }
  17885. }
  17886. return {
  17887. width: width,
  17888. height: height,
  17889. items: items
  17890. };
  17891. };
  17892. return Transform;
  17893. }();
  17894. // Section 3.8.2 Irreversible 9-7 filter
  17895. var IrreversibleTransform = function IrreversibleTransformClosure() {
  17896. function IrreversibleTransform() {
  17897. Transform.call(this);
  17898. }
  17899. IrreversibleTransform.prototype = Object.create(Transform.prototype);
  17900. IrreversibleTransform.prototype.filter = function irreversibleTransformFilter(x, offset, length) {
  17901. var len = length >> 1;
  17902. offset = offset | 0;
  17903. var j, n, current, next;
  17904. var alpha = -1.586134342059924;
  17905. var beta = -0.052980118572961;
  17906. var gamma = 0.882911075530934;
  17907. var delta = 0.443506852043971;
  17908. var K = 1.230174104914001;
  17909. var K_ = 1 / K;
  17910. // step 1 is combined with step 3
  17911. // step 2
  17912. j = offset - 3;
  17913. for (n = len + 4; n--; j += 2) {
  17914. x[j] *= K_;
  17915. }
  17916. // step 1 & 3
  17917. j = offset - 2;
  17918. current = delta * x[j - 1];
  17919. for (n = len + 3; n--; j += 2) {
  17920. next = delta * x[j + 1];
  17921. x[j] = K * x[j] - current - next;
  17922. if (n--) {
  17923. j += 2;
  17924. current = delta * x[j + 1];
  17925. x[j] = K * x[j] - current - next;
  17926. } else {
  17927. break;
  17928. }
  17929. }
  17930. // step 4
  17931. j = offset - 1;
  17932. current = gamma * x[j - 1];
  17933. for (n = len + 2; n--; j += 2) {
  17934. next = gamma * x[j + 1];
  17935. x[j] -= current + next;
  17936. if (n--) {
  17937. j += 2;
  17938. current = gamma * x[j + 1];
  17939. x[j] -= current + next;
  17940. } else {
  17941. break;
  17942. }
  17943. }
  17944. // step 5
  17945. j = offset;
  17946. current = beta * x[j - 1];
  17947. for (n = len + 1; n--; j += 2) {
  17948. next = beta * x[j + 1];
  17949. x[j] -= current + next;
  17950. if (n--) {
  17951. j += 2;
  17952. current = beta * x[j + 1];
  17953. x[j] -= current + next;
  17954. } else {
  17955. break;
  17956. }
  17957. }
  17958. // step 6
  17959. if (len !== 0) {
  17960. j = offset + 1;
  17961. current = alpha * x[j - 1];
  17962. for (n = len; n--; j += 2) {
  17963. next = alpha * x[j + 1];
  17964. x[j] -= current + next;
  17965. if (n--) {
  17966. j += 2;
  17967. current = alpha * x[j + 1];
  17968. x[j] -= current + next;
  17969. } else {
  17970. break;
  17971. }
  17972. }
  17973. }
  17974. };
  17975. return IrreversibleTransform;
  17976. }();
  17977. // Section 3.8.1 Reversible 5-3 filter
  17978. var ReversibleTransform = function ReversibleTransformClosure() {
  17979. function ReversibleTransform() {
  17980. Transform.call(this);
  17981. }
  17982. ReversibleTransform.prototype = Object.create(Transform.prototype);
  17983. ReversibleTransform.prototype.filter = function reversibleTransformFilter(x, offset, length) {
  17984. var len = length >> 1;
  17985. offset = offset | 0;
  17986. var j, n;
  17987. for (j = offset, n = len + 1; n--; j += 2) {
  17988. x[j] -= x[j - 1] + x[j + 1] + 2 >> 2;
  17989. }
  17990. for (j = offset + 1, n = len; n--; j += 2) {
  17991. x[j] += x[j - 1] + x[j + 1] >> 1;
  17992. }
  17993. };
  17994. return ReversibleTransform;
  17995. }();
  17996. return JpxImage;
  17997. }();
  17998. exports.JpxImage = JpxImage;
  17999. }));
  18000. (function (root, factory) {
  18001. factory(root.pdfjsCoreMetrics = {}, root.pdfjsSharedUtil);
  18002. }(this, function (exports, sharedUtil) {
  18003. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  18004. // The Metrics object contains glyph widths (in glyph space units).
  18005. // As per PDF spec, for most fonts (Type 3 being an exception) a glyph
  18006. // space unit corresponds to 1/1000th of text space unit.
  18007. var getMetrics = getLookupTableFactory(function (t) {
  18008. t['Courier'] = 600;
  18009. t['Courier-Bold'] = 600;
  18010. t['Courier-BoldOblique'] = 600;
  18011. t['Courier-Oblique'] = 600;
  18012. t['Helvetica'] = getLookupTableFactory(function (t) {
  18013. t['space'] = 278;
  18014. t['exclam'] = 278;
  18015. t['quotedbl'] = 355;
  18016. t['numbersign'] = 556;
  18017. t['dollar'] = 556;
  18018. t['percent'] = 889;
  18019. t['ampersand'] = 667;
  18020. t['quoteright'] = 222;
  18021. t['parenleft'] = 333;
  18022. t['parenright'] = 333;
  18023. t['asterisk'] = 389;
  18024. t['plus'] = 584;
  18025. t['comma'] = 278;
  18026. t['hyphen'] = 333;
  18027. t['period'] = 278;
  18028. t['slash'] = 278;
  18029. t['zero'] = 556;
  18030. t['one'] = 556;
  18031. t['two'] = 556;
  18032. t['three'] = 556;
  18033. t['four'] = 556;
  18034. t['five'] = 556;
  18035. t['six'] = 556;
  18036. t['seven'] = 556;
  18037. t['eight'] = 556;
  18038. t['nine'] = 556;
  18039. t['colon'] = 278;
  18040. t['semicolon'] = 278;
  18041. t['less'] = 584;
  18042. t['equal'] = 584;
  18043. t['greater'] = 584;
  18044. t['question'] = 556;
  18045. t['at'] = 1015;
  18046. t['A'] = 667;
  18047. t['B'] = 667;
  18048. t['C'] = 722;
  18049. t['D'] = 722;
  18050. t['E'] = 667;
  18051. t['F'] = 611;
  18052. t['G'] = 778;
  18053. t['H'] = 722;
  18054. t['I'] = 278;
  18055. t['J'] = 500;
  18056. t['K'] = 667;
  18057. t['L'] = 556;
  18058. t['M'] = 833;
  18059. t['N'] = 722;
  18060. t['O'] = 778;
  18061. t['P'] = 667;
  18062. t['Q'] = 778;
  18063. t['R'] = 722;
  18064. t['S'] = 667;
  18065. t['T'] = 611;
  18066. t['U'] = 722;
  18067. t['V'] = 667;
  18068. t['W'] = 944;
  18069. t['X'] = 667;
  18070. t['Y'] = 667;
  18071. t['Z'] = 611;
  18072. t['bracketleft'] = 278;
  18073. t['backslash'] = 278;
  18074. t['bracketright'] = 278;
  18075. t['asciicircum'] = 469;
  18076. t['underscore'] = 556;
  18077. t['quoteleft'] = 222;
  18078. t['a'] = 556;
  18079. t['b'] = 556;
  18080. t['c'] = 500;
  18081. t['d'] = 556;
  18082. t['e'] = 556;
  18083. t['f'] = 278;
  18084. t['g'] = 556;
  18085. t['h'] = 556;
  18086. t['i'] = 222;
  18087. t['j'] = 222;
  18088. t['k'] = 500;
  18089. t['l'] = 222;
  18090. t['m'] = 833;
  18091. t['n'] = 556;
  18092. t['o'] = 556;
  18093. t['p'] = 556;
  18094. t['q'] = 556;
  18095. t['r'] = 333;
  18096. t['s'] = 500;
  18097. t['t'] = 278;
  18098. t['u'] = 556;
  18099. t['v'] = 500;
  18100. t['w'] = 722;
  18101. t['x'] = 500;
  18102. t['y'] = 500;
  18103. t['z'] = 500;
  18104. t['braceleft'] = 334;
  18105. t['bar'] = 260;
  18106. t['braceright'] = 334;
  18107. t['asciitilde'] = 584;
  18108. t['exclamdown'] = 333;
  18109. t['cent'] = 556;
  18110. t['sterling'] = 556;
  18111. t['fraction'] = 167;
  18112. t['yen'] = 556;
  18113. t['florin'] = 556;
  18114. t['section'] = 556;
  18115. t['currency'] = 556;
  18116. t['quotesingle'] = 191;
  18117. t['quotedblleft'] = 333;
  18118. t['guillemotleft'] = 556;
  18119. t['guilsinglleft'] = 333;
  18120. t['guilsinglright'] = 333;
  18121. t['fi'] = 500;
  18122. t['fl'] = 500;
  18123. t['endash'] = 556;
  18124. t['dagger'] = 556;
  18125. t['daggerdbl'] = 556;
  18126. t['periodcentered'] = 278;
  18127. t['paragraph'] = 537;
  18128. t['bullet'] = 350;
  18129. t['quotesinglbase'] = 222;
  18130. t['quotedblbase'] = 333;
  18131. t['quotedblright'] = 333;
  18132. t['guillemotright'] = 556;
  18133. t['ellipsis'] = 1000;
  18134. t['perthousand'] = 1000;
  18135. t['questiondown'] = 611;
  18136. t['grave'] = 333;
  18137. t['acute'] = 333;
  18138. t['circumflex'] = 333;
  18139. t['tilde'] = 333;
  18140. t['macron'] = 333;
  18141. t['breve'] = 333;
  18142. t['dotaccent'] = 333;
  18143. t['dieresis'] = 333;
  18144. t['ring'] = 333;
  18145. t['cedilla'] = 333;
  18146. t['hungarumlaut'] = 333;
  18147. t['ogonek'] = 333;
  18148. t['caron'] = 333;
  18149. t['emdash'] = 1000;
  18150. t['AE'] = 1000;
  18151. t['ordfeminine'] = 370;
  18152. t['Lslash'] = 556;
  18153. t['Oslash'] = 778;
  18154. t['OE'] = 1000;
  18155. t['ordmasculine'] = 365;
  18156. t['ae'] = 889;
  18157. t['dotlessi'] = 278;
  18158. t['lslash'] = 222;
  18159. t['oslash'] = 611;
  18160. t['oe'] = 944;
  18161. t['germandbls'] = 611;
  18162. t['Idieresis'] = 278;
  18163. t['eacute'] = 556;
  18164. t['abreve'] = 556;
  18165. t['uhungarumlaut'] = 556;
  18166. t['ecaron'] = 556;
  18167. t['Ydieresis'] = 667;
  18168. t['divide'] = 584;
  18169. t['Yacute'] = 667;
  18170. t['Acircumflex'] = 667;
  18171. t['aacute'] = 556;
  18172. t['Ucircumflex'] = 722;
  18173. t['yacute'] = 500;
  18174. t['scommaaccent'] = 500;
  18175. t['ecircumflex'] = 556;
  18176. t['Uring'] = 722;
  18177. t['Udieresis'] = 722;
  18178. t['aogonek'] = 556;
  18179. t['Uacute'] = 722;
  18180. t['uogonek'] = 556;
  18181. t['Edieresis'] = 667;
  18182. t['Dcroat'] = 722;
  18183. t['commaaccent'] = 250;
  18184. t['copyright'] = 737;
  18185. t['Emacron'] = 667;
  18186. t['ccaron'] = 500;
  18187. t['aring'] = 556;
  18188. t['Ncommaaccent'] = 722;
  18189. t['lacute'] = 222;
  18190. t['agrave'] = 556;
  18191. t['Tcommaaccent'] = 611;
  18192. t['Cacute'] = 722;
  18193. t['atilde'] = 556;
  18194. t['Edotaccent'] = 667;
  18195. t['scaron'] = 500;
  18196. t['scedilla'] = 500;
  18197. t['iacute'] = 278;
  18198. t['lozenge'] = 471;
  18199. t['Rcaron'] = 722;
  18200. t['Gcommaaccent'] = 778;
  18201. t['ucircumflex'] = 556;
  18202. t['acircumflex'] = 556;
  18203. t['Amacron'] = 667;
  18204. t['rcaron'] = 333;
  18205. t['ccedilla'] = 500;
  18206. t['Zdotaccent'] = 611;
  18207. t['Thorn'] = 667;
  18208. t['Omacron'] = 778;
  18209. t['Racute'] = 722;
  18210. t['Sacute'] = 667;
  18211. t['dcaron'] = 643;
  18212. t['Umacron'] = 722;
  18213. t['uring'] = 556;
  18214. t['threesuperior'] = 333;
  18215. t['Ograve'] = 778;
  18216. t['Agrave'] = 667;
  18217. t['Abreve'] = 667;
  18218. t['multiply'] = 584;
  18219. t['uacute'] = 556;
  18220. t['Tcaron'] = 611;
  18221. t['partialdiff'] = 476;
  18222. t['ydieresis'] = 500;
  18223. t['Nacute'] = 722;
  18224. t['icircumflex'] = 278;
  18225. t['Ecircumflex'] = 667;
  18226. t['adieresis'] = 556;
  18227. t['edieresis'] = 556;
  18228. t['cacute'] = 500;
  18229. t['nacute'] = 556;
  18230. t['umacron'] = 556;
  18231. t['Ncaron'] = 722;
  18232. t['Iacute'] = 278;
  18233. t['plusminus'] = 584;
  18234. t['brokenbar'] = 260;
  18235. t['registered'] = 737;
  18236. t['Gbreve'] = 778;
  18237. t['Idotaccent'] = 278;
  18238. t['summation'] = 600;
  18239. t['Egrave'] = 667;
  18240. t['racute'] = 333;
  18241. t['omacron'] = 556;
  18242. t['Zacute'] = 611;
  18243. t['Zcaron'] = 611;
  18244. t['greaterequal'] = 549;
  18245. t['Eth'] = 722;
  18246. t['Ccedilla'] = 722;
  18247. t['lcommaaccent'] = 222;
  18248. t['tcaron'] = 317;
  18249. t['eogonek'] = 556;
  18250. t['Uogonek'] = 722;
  18251. t['Aacute'] = 667;
  18252. t['Adieresis'] = 667;
  18253. t['egrave'] = 556;
  18254. t['zacute'] = 500;
  18255. t['iogonek'] = 222;
  18256. t['Oacute'] = 778;
  18257. t['oacute'] = 556;
  18258. t['amacron'] = 556;
  18259. t['sacute'] = 500;
  18260. t['idieresis'] = 278;
  18261. t['Ocircumflex'] = 778;
  18262. t['Ugrave'] = 722;
  18263. t['Delta'] = 612;
  18264. t['thorn'] = 556;
  18265. t['twosuperior'] = 333;
  18266. t['Odieresis'] = 778;
  18267. t['mu'] = 556;
  18268. t['igrave'] = 278;
  18269. t['ohungarumlaut'] = 556;
  18270. t['Eogonek'] = 667;
  18271. t['dcroat'] = 556;
  18272. t['threequarters'] = 834;
  18273. t['Scedilla'] = 667;
  18274. t['lcaron'] = 299;
  18275. t['Kcommaaccent'] = 667;
  18276. t['Lacute'] = 556;
  18277. t['trademark'] = 1000;
  18278. t['edotaccent'] = 556;
  18279. t['Igrave'] = 278;
  18280. t['Imacron'] = 278;
  18281. t['Lcaron'] = 556;
  18282. t['onehalf'] = 834;
  18283. t['lessequal'] = 549;
  18284. t['ocircumflex'] = 556;
  18285. t['ntilde'] = 556;
  18286. t['Uhungarumlaut'] = 722;
  18287. t['Eacute'] = 667;
  18288. t['emacron'] = 556;
  18289. t['gbreve'] = 556;
  18290. t['onequarter'] = 834;
  18291. t['Scaron'] = 667;
  18292. t['Scommaaccent'] = 667;
  18293. t['Ohungarumlaut'] = 778;
  18294. t['degree'] = 400;
  18295. t['ograve'] = 556;
  18296. t['Ccaron'] = 722;
  18297. t['ugrave'] = 556;
  18298. t['radical'] = 453;
  18299. t['Dcaron'] = 722;
  18300. t['rcommaaccent'] = 333;
  18301. t['Ntilde'] = 722;
  18302. t['otilde'] = 556;
  18303. t['Rcommaaccent'] = 722;
  18304. t['Lcommaaccent'] = 556;
  18305. t['Atilde'] = 667;
  18306. t['Aogonek'] = 667;
  18307. t['Aring'] = 667;
  18308. t['Otilde'] = 778;
  18309. t['zdotaccent'] = 500;
  18310. t['Ecaron'] = 667;
  18311. t['Iogonek'] = 278;
  18312. t['kcommaaccent'] = 500;
  18313. t['minus'] = 584;
  18314. t['Icircumflex'] = 278;
  18315. t['ncaron'] = 556;
  18316. t['tcommaaccent'] = 278;
  18317. t['logicalnot'] = 584;
  18318. t['odieresis'] = 556;
  18319. t['udieresis'] = 556;
  18320. t['notequal'] = 549;
  18321. t['gcommaaccent'] = 556;
  18322. t['eth'] = 556;
  18323. t['zcaron'] = 500;
  18324. t['ncommaaccent'] = 556;
  18325. t['onesuperior'] = 333;
  18326. t['imacron'] = 278;
  18327. t['Euro'] = 556;
  18328. });
  18329. t['Helvetica-Bold'] = getLookupTableFactory(function (t) {
  18330. t['space'] = 278;
  18331. t['exclam'] = 333;
  18332. t['quotedbl'] = 474;
  18333. t['numbersign'] = 556;
  18334. t['dollar'] = 556;
  18335. t['percent'] = 889;
  18336. t['ampersand'] = 722;
  18337. t['quoteright'] = 278;
  18338. t['parenleft'] = 333;
  18339. t['parenright'] = 333;
  18340. t['asterisk'] = 389;
  18341. t['plus'] = 584;
  18342. t['comma'] = 278;
  18343. t['hyphen'] = 333;
  18344. t['period'] = 278;
  18345. t['slash'] = 278;
  18346. t['zero'] = 556;
  18347. t['one'] = 556;
  18348. t['two'] = 556;
  18349. t['three'] = 556;
  18350. t['four'] = 556;
  18351. t['five'] = 556;
  18352. t['six'] = 556;
  18353. t['seven'] = 556;
  18354. t['eight'] = 556;
  18355. t['nine'] = 556;
  18356. t['colon'] = 333;
  18357. t['semicolon'] = 333;
  18358. t['less'] = 584;
  18359. t['equal'] = 584;
  18360. t['greater'] = 584;
  18361. t['question'] = 611;
  18362. t['at'] = 975;
  18363. t['A'] = 722;
  18364. t['B'] = 722;
  18365. t['C'] = 722;
  18366. t['D'] = 722;
  18367. t['E'] = 667;
  18368. t['F'] = 611;
  18369. t['G'] = 778;
  18370. t['H'] = 722;
  18371. t['I'] = 278;
  18372. t['J'] = 556;
  18373. t['K'] = 722;
  18374. t['L'] = 611;
  18375. t['M'] = 833;
  18376. t['N'] = 722;
  18377. t['O'] = 778;
  18378. t['P'] = 667;
  18379. t['Q'] = 778;
  18380. t['R'] = 722;
  18381. t['S'] = 667;
  18382. t['T'] = 611;
  18383. t['U'] = 722;
  18384. t['V'] = 667;
  18385. t['W'] = 944;
  18386. t['X'] = 667;
  18387. t['Y'] = 667;
  18388. t['Z'] = 611;
  18389. t['bracketleft'] = 333;
  18390. t['backslash'] = 278;
  18391. t['bracketright'] = 333;
  18392. t['asciicircum'] = 584;
  18393. t['underscore'] = 556;
  18394. t['quoteleft'] = 278;
  18395. t['a'] = 556;
  18396. t['b'] = 611;
  18397. t['c'] = 556;
  18398. t['d'] = 611;
  18399. t['e'] = 556;
  18400. t['f'] = 333;
  18401. t['g'] = 611;
  18402. t['h'] = 611;
  18403. t['i'] = 278;
  18404. t['j'] = 278;
  18405. t['k'] = 556;
  18406. t['l'] = 278;
  18407. t['m'] = 889;
  18408. t['n'] = 611;
  18409. t['o'] = 611;
  18410. t['p'] = 611;
  18411. t['q'] = 611;
  18412. t['r'] = 389;
  18413. t['s'] = 556;
  18414. t['t'] = 333;
  18415. t['u'] = 611;
  18416. t['v'] = 556;
  18417. t['w'] = 778;
  18418. t['x'] = 556;
  18419. t['y'] = 556;
  18420. t['z'] = 500;
  18421. t['braceleft'] = 389;
  18422. t['bar'] = 280;
  18423. t['braceright'] = 389;
  18424. t['asciitilde'] = 584;
  18425. t['exclamdown'] = 333;
  18426. t['cent'] = 556;
  18427. t['sterling'] = 556;
  18428. t['fraction'] = 167;
  18429. t['yen'] = 556;
  18430. t['florin'] = 556;
  18431. t['section'] = 556;
  18432. t['currency'] = 556;
  18433. t['quotesingle'] = 238;
  18434. t['quotedblleft'] = 500;
  18435. t['guillemotleft'] = 556;
  18436. t['guilsinglleft'] = 333;
  18437. t['guilsinglright'] = 333;
  18438. t['fi'] = 611;
  18439. t['fl'] = 611;
  18440. t['endash'] = 556;
  18441. t['dagger'] = 556;
  18442. t['daggerdbl'] = 556;
  18443. t['periodcentered'] = 278;
  18444. t['paragraph'] = 556;
  18445. t['bullet'] = 350;
  18446. t['quotesinglbase'] = 278;
  18447. t['quotedblbase'] = 500;
  18448. t['quotedblright'] = 500;
  18449. t['guillemotright'] = 556;
  18450. t['ellipsis'] = 1000;
  18451. t['perthousand'] = 1000;
  18452. t['questiondown'] = 611;
  18453. t['grave'] = 333;
  18454. t['acute'] = 333;
  18455. t['circumflex'] = 333;
  18456. t['tilde'] = 333;
  18457. t['macron'] = 333;
  18458. t['breve'] = 333;
  18459. t['dotaccent'] = 333;
  18460. t['dieresis'] = 333;
  18461. t['ring'] = 333;
  18462. t['cedilla'] = 333;
  18463. t['hungarumlaut'] = 333;
  18464. t['ogonek'] = 333;
  18465. t['caron'] = 333;
  18466. t['emdash'] = 1000;
  18467. t['AE'] = 1000;
  18468. t['ordfeminine'] = 370;
  18469. t['Lslash'] = 611;
  18470. t['Oslash'] = 778;
  18471. t['OE'] = 1000;
  18472. t['ordmasculine'] = 365;
  18473. t['ae'] = 889;
  18474. t['dotlessi'] = 278;
  18475. t['lslash'] = 278;
  18476. t['oslash'] = 611;
  18477. t['oe'] = 944;
  18478. t['germandbls'] = 611;
  18479. t['Idieresis'] = 278;
  18480. t['eacute'] = 556;
  18481. t['abreve'] = 556;
  18482. t['uhungarumlaut'] = 611;
  18483. t['ecaron'] = 556;
  18484. t['Ydieresis'] = 667;
  18485. t['divide'] = 584;
  18486. t['Yacute'] = 667;
  18487. t['Acircumflex'] = 722;
  18488. t['aacute'] = 556;
  18489. t['Ucircumflex'] = 722;
  18490. t['yacute'] = 556;
  18491. t['scommaaccent'] = 556;
  18492. t['ecircumflex'] = 556;
  18493. t['Uring'] = 722;
  18494. t['Udieresis'] = 722;
  18495. t['aogonek'] = 556;
  18496. t['Uacute'] = 722;
  18497. t['uogonek'] = 611;
  18498. t['Edieresis'] = 667;
  18499. t['Dcroat'] = 722;
  18500. t['commaaccent'] = 250;
  18501. t['copyright'] = 737;
  18502. t['Emacron'] = 667;
  18503. t['ccaron'] = 556;
  18504. t['aring'] = 556;
  18505. t['Ncommaaccent'] = 722;
  18506. t['lacute'] = 278;
  18507. t['agrave'] = 556;
  18508. t['Tcommaaccent'] = 611;
  18509. t['Cacute'] = 722;
  18510. t['atilde'] = 556;
  18511. t['Edotaccent'] = 667;
  18512. t['scaron'] = 556;
  18513. t['scedilla'] = 556;
  18514. t['iacute'] = 278;
  18515. t['lozenge'] = 494;
  18516. t['Rcaron'] = 722;
  18517. t['Gcommaaccent'] = 778;
  18518. t['ucircumflex'] = 611;
  18519. t['acircumflex'] = 556;
  18520. t['Amacron'] = 722;
  18521. t['rcaron'] = 389;
  18522. t['ccedilla'] = 556;
  18523. t['Zdotaccent'] = 611;
  18524. t['Thorn'] = 667;
  18525. t['Omacron'] = 778;
  18526. t['Racute'] = 722;
  18527. t['Sacute'] = 667;
  18528. t['dcaron'] = 743;
  18529. t['Umacron'] = 722;
  18530. t['uring'] = 611;
  18531. t['threesuperior'] = 333;
  18532. t['Ograve'] = 778;
  18533. t['Agrave'] = 722;
  18534. t['Abreve'] = 722;
  18535. t['multiply'] = 584;
  18536. t['uacute'] = 611;
  18537. t['Tcaron'] = 611;
  18538. t['partialdiff'] = 494;
  18539. t['ydieresis'] = 556;
  18540. t['Nacute'] = 722;
  18541. t['icircumflex'] = 278;
  18542. t['Ecircumflex'] = 667;
  18543. t['adieresis'] = 556;
  18544. t['edieresis'] = 556;
  18545. t['cacute'] = 556;
  18546. t['nacute'] = 611;
  18547. t['umacron'] = 611;
  18548. t['Ncaron'] = 722;
  18549. t['Iacute'] = 278;
  18550. t['plusminus'] = 584;
  18551. t['brokenbar'] = 280;
  18552. t['registered'] = 737;
  18553. t['Gbreve'] = 778;
  18554. t['Idotaccent'] = 278;
  18555. t['summation'] = 600;
  18556. t['Egrave'] = 667;
  18557. t['racute'] = 389;
  18558. t['omacron'] = 611;
  18559. t['Zacute'] = 611;
  18560. t['Zcaron'] = 611;
  18561. t['greaterequal'] = 549;
  18562. t['Eth'] = 722;
  18563. t['Ccedilla'] = 722;
  18564. t['lcommaaccent'] = 278;
  18565. t['tcaron'] = 389;
  18566. t['eogonek'] = 556;
  18567. t['Uogonek'] = 722;
  18568. t['Aacute'] = 722;
  18569. t['Adieresis'] = 722;
  18570. t['egrave'] = 556;
  18571. t['zacute'] = 500;
  18572. t['iogonek'] = 278;
  18573. t['Oacute'] = 778;
  18574. t['oacute'] = 611;
  18575. t['amacron'] = 556;
  18576. t['sacute'] = 556;
  18577. t['idieresis'] = 278;
  18578. t['Ocircumflex'] = 778;
  18579. t['Ugrave'] = 722;
  18580. t['Delta'] = 612;
  18581. t['thorn'] = 611;
  18582. t['twosuperior'] = 333;
  18583. t['Odieresis'] = 778;
  18584. t['mu'] = 611;
  18585. t['igrave'] = 278;
  18586. t['ohungarumlaut'] = 611;
  18587. t['Eogonek'] = 667;
  18588. t['dcroat'] = 611;
  18589. t['threequarters'] = 834;
  18590. t['Scedilla'] = 667;
  18591. t['lcaron'] = 400;
  18592. t['Kcommaaccent'] = 722;
  18593. t['Lacute'] = 611;
  18594. t['trademark'] = 1000;
  18595. t['edotaccent'] = 556;
  18596. t['Igrave'] = 278;
  18597. t['Imacron'] = 278;
  18598. t['Lcaron'] = 611;
  18599. t['onehalf'] = 834;
  18600. t['lessequal'] = 549;
  18601. t['ocircumflex'] = 611;
  18602. t['ntilde'] = 611;
  18603. t['Uhungarumlaut'] = 722;
  18604. t['Eacute'] = 667;
  18605. t['emacron'] = 556;
  18606. t['gbreve'] = 611;
  18607. t['onequarter'] = 834;
  18608. t['Scaron'] = 667;
  18609. t['Scommaaccent'] = 667;
  18610. t['Ohungarumlaut'] = 778;
  18611. t['degree'] = 400;
  18612. t['ograve'] = 611;
  18613. t['Ccaron'] = 722;
  18614. t['ugrave'] = 611;
  18615. t['radical'] = 549;
  18616. t['Dcaron'] = 722;
  18617. t['rcommaaccent'] = 389;
  18618. t['Ntilde'] = 722;
  18619. t['otilde'] = 611;
  18620. t['Rcommaaccent'] = 722;
  18621. t['Lcommaaccent'] = 611;
  18622. t['Atilde'] = 722;
  18623. t['Aogonek'] = 722;
  18624. t['Aring'] = 722;
  18625. t['Otilde'] = 778;
  18626. t['zdotaccent'] = 500;
  18627. t['Ecaron'] = 667;
  18628. t['Iogonek'] = 278;
  18629. t['kcommaaccent'] = 556;
  18630. t['minus'] = 584;
  18631. t['Icircumflex'] = 278;
  18632. t['ncaron'] = 611;
  18633. t['tcommaaccent'] = 333;
  18634. t['logicalnot'] = 584;
  18635. t['odieresis'] = 611;
  18636. t['udieresis'] = 611;
  18637. t['notequal'] = 549;
  18638. t['gcommaaccent'] = 611;
  18639. t['eth'] = 611;
  18640. t['zcaron'] = 500;
  18641. t['ncommaaccent'] = 611;
  18642. t['onesuperior'] = 333;
  18643. t['imacron'] = 278;
  18644. t['Euro'] = 556;
  18645. });
  18646. t['Helvetica-BoldOblique'] = getLookupTableFactory(function (t) {
  18647. t['space'] = 278;
  18648. t['exclam'] = 333;
  18649. t['quotedbl'] = 474;
  18650. t['numbersign'] = 556;
  18651. t['dollar'] = 556;
  18652. t['percent'] = 889;
  18653. t['ampersand'] = 722;
  18654. t['quoteright'] = 278;
  18655. t['parenleft'] = 333;
  18656. t['parenright'] = 333;
  18657. t['asterisk'] = 389;
  18658. t['plus'] = 584;
  18659. t['comma'] = 278;
  18660. t['hyphen'] = 333;
  18661. t['period'] = 278;
  18662. t['slash'] = 278;
  18663. t['zero'] = 556;
  18664. t['one'] = 556;
  18665. t['two'] = 556;
  18666. t['three'] = 556;
  18667. t['four'] = 556;
  18668. t['five'] = 556;
  18669. t['six'] = 556;
  18670. t['seven'] = 556;
  18671. t['eight'] = 556;
  18672. t['nine'] = 556;
  18673. t['colon'] = 333;
  18674. t['semicolon'] = 333;
  18675. t['less'] = 584;
  18676. t['equal'] = 584;
  18677. t['greater'] = 584;
  18678. t['question'] = 611;
  18679. t['at'] = 975;
  18680. t['A'] = 722;
  18681. t['B'] = 722;
  18682. t['C'] = 722;
  18683. t['D'] = 722;
  18684. t['E'] = 667;
  18685. t['F'] = 611;
  18686. t['G'] = 778;
  18687. t['H'] = 722;
  18688. t['I'] = 278;
  18689. t['J'] = 556;
  18690. t['K'] = 722;
  18691. t['L'] = 611;
  18692. t['M'] = 833;
  18693. t['N'] = 722;
  18694. t['O'] = 778;
  18695. t['P'] = 667;
  18696. t['Q'] = 778;
  18697. t['R'] = 722;
  18698. t['S'] = 667;
  18699. t['T'] = 611;
  18700. t['U'] = 722;
  18701. t['V'] = 667;
  18702. t['W'] = 944;
  18703. t['X'] = 667;
  18704. t['Y'] = 667;
  18705. t['Z'] = 611;
  18706. t['bracketleft'] = 333;
  18707. t['backslash'] = 278;
  18708. t['bracketright'] = 333;
  18709. t['asciicircum'] = 584;
  18710. t['underscore'] = 556;
  18711. t['quoteleft'] = 278;
  18712. t['a'] = 556;
  18713. t['b'] = 611;
  18714. t['c'] = 556;
  18715. t['d'] = 611;
  18716. t['e'] = 556;
  18717. t['f'] = 333;
  18718. t['g'] = 611;
  18719. t['h'] = 611;
  18720. t['i'] = 278;
  18721. t['j'] = 278;
  18722. t['k'] = 556;
  18723. t['l'] = 278;
  18724. t['m'] = 889;
  18725. t['n'] = 611;
  18726. t['o'] = 611;
  18727. t['p'] = 611;
  18728. t['q'] = 611;
  18729. t['r'] = 389;
  18730. t['s'] = 556;
  18731. t['t'] = 333;
  18732. t['u'] = 611;
  18733. t['v'] = 556;
  18734. t['w'] = 778;
  18735. t['x'] = 556;
  18736. t['y'] = 556;
  18737. t['z'] = 500;
  18738. t['braceleft'] = 389;
  18739. t['bar'] = 280;
  18740. t['braceright'] = 389;
  18741. t['asciitilde'] = 584;
  18742. t['exclamdown'] = 333;
  18743. t['cent'] = 556;
  18744. t['sterling'] = 556;
  18745. t['fraction'] = 167;
  18746. t['yen'] = 556;
  18747. t['florin'] = 556;
  18748. t['section'] = 556;
  18749. t['currency'] = 556;
  18750. t['quotesingle'] = 238;
  18751. t['quotedblleft'] = 500;
  18752. t['guillemotleft'] = 556;
  18753. t['guilsinglleft'] = 333;
  18754. t['guilsinglright'] = 333;
  18755. t['fi'] = 611;
  18756. t['fl'] = 611;
  18757. t['endash'] = 556;
  18758. t['dagger'] = 556;
  18759. t['daggerdbl'] = 556;
  18760. t['periodcentered'] = 278;
  18761. t['paragraph'] = 556;
  18762. t['bullet'] = 350;
  18763. t['quotesinglbase'] = 278;
  18764. t['quotedblbase'] = 500;
  18765. t['quotedblright'] = 500;
  18766. t['guillemotright'] = 556;
  18767. t['ellipsis'] = 1000;
  18768. t['perthousand'] = 1000;
  18769. t['questiondown'] = 611;
  18770. t['grave'] = 333;
  18771. t['acute'] = 333;
  18772. t['circumflex'] = 333;
  18773. t['tilde'] = 333;
  18774. t['macron'] = 333;
  18775. t['breve'] = 333;
  18776. t['dotaccent'] = 333;
  18777. t['dieresis'] = 333;
  18778. t['ring'] = 333;
  18779. t['cedilla'] = 333;
  18780. t['hungarumlaut'] = 333;
  18781. t['ogonek'] = 333;
  18782. t['caron'] = 333;
  18783. t['emdash'] = 1000;
  18784. t['AE'] = 1000;
  18785. t['ordfeminine'] = 370;
  18786. t['Lslash'] = 611;
  18787. t['Oslash'] = 778;
  18788. t['OE'] = 1000;
  18789. t['ordmasculine'] = 365;
  18790. t['ae'] = 889;
  18791. t['dotlessi'] = 278;
  18792. t['lslash'] = 278;
  18793. t['oslash'] = 611;
  18794. t['oe'] = 944;
  18795. t['germandbls'] = 611;
  18796. t['Idieresis'] = 278;
  18797. t['eacute'] = 556;
  18798. t['abreve'] = 556;
  18799. t['uhungarumlaut'] = 611;
  18800. t['ecaron'] = 556;
  18801. t['Ydieresis'] = 667;
  18802. t['divide'] = 584;
  18803. t['Yacute'] = 667;
  18804. t['Acircumflex'] = 722;
  18805. t['aacute'] = 556;
  18806. t['Ucircumflex'] = 722;
  18807. t['yacute'] = 556;
  18808. t['scommaaccent'] = 556;
  18809. t['ecircumflex'] = 556;
  18810. t['Uring'] = 722;
  18811. t['Udieresis'] = 722;
  18812. t['aogonek'] = 556;
  18813. t['Uacute'] = 722;
  18814. t['uogonek'] = 611;
  18815. t['Edieresis'] = 667;
  18816. t['Dcroat'] = 722;
  18817. t['commaaccent'] = 250;
  18818. t['copyright'] = 737;
  18819. t['Emacron'] = 667;
  18820. t['ccaron'] = 556;
  18821. t['aring'] = 556;
  18822. t['Ncommaaccent'] = 722;
  18823. t['lacute'] = 278;
  18824. t['agrave'] = 556;
  18825. t['Tcommaaccent'] = 611;
  18826. t['Cacute'] = 722;
  18827. t['atilde'] = 556;
  18828. t['Edotaccent'] = 667;
  18829. t['scaron'] = 556;
  18830. t['scedilla'] = 556;
  18831. t['iacute'] = 278;
  18832. t['lozenge'] = 494;
  18833. t['Rcaron'] = 722;
  18834. t['Gcommaaccent'] = 778;
  18835. t['ucircumflex'] = 611;
  18836. t['acircumflex'] = 556;
  18837. t['Amacron'] = 722;
  18838. t['rcaron'] = 389;
  18839. t['ccedilla'] = 556;
  18840. t['Zdotaccent'] = 611;
  18841. t['Thorn'] = 667;
  18842. t['Omacron'] = 778;
  18843. t['Racute'] = 722;
  18844. t['Sacute'] = 667;
  18845. t['dcaron'] = 743;
  18846. t['Umacron'] = 722;
  18847. t['uring'] = 611;
  18848. t['threesuperior'] = 333;
  18849. t['Ograve'] = 778;
  18850. t['Agrave'] = 722;
  18851. t['Abreve'] = 722;
  18852. t['multiply'] = 584;
  18853. t['uacute'] = 611;
  18854. t['Tcaron'] = 611;
  18855. t['partialdiff'] = 494;
  18856. t['ydieresis'] = 556;
  18857. t['Nacute'] = 722;
  18858. t['icircumflex'] = 278;
  18859. t['Ecircumflex'] = 667;
  18860. t['adieresis'] = 556;
  18861. t['edieresis'] = 556;
  18862. t['cacute'] = 556;
  18863. t['nacute'] = 611;
  18864. t['umacron'] = 611;
  18865. t['Ncaron'] = 722;
  18866. t['Iacute'] = 278;
  18867. t['plusminus'] = 584;
  18868. t['brokenbar'] = 280;
  18869. t['registered'] = 737;
  18870. t['Gbreve'] = 778;
  18871. t['Idotaccent'] = 278;
  18872. t['summation'] = 600;
  18873. t['Egrave'] = 667;
  18874. t['racute'] = 389;
  18875. t['omacron'] = 611;
  18876. t['Zacute'] = 611;
  18877. t['Zcaron'] = 611;
  18878. t['greaterequal'] = 549;
  18879. t['Eth'] = 722;
  18880. t['Ccedilla'] = 722;
  18881. t['lcommaaccent'] = 278;
  18882. t['tcaron'] = 389;
  18883. t['eogonek'] = 556;
  18884. t['Uogonek'] = 722;
  18885. t['Aacute'] = 722;
  18886. t['Adieresis'] = 722;
  18887. t['egrave'] = 556;
  18888. t['zacute'] = 500;
  18889. t['iogonek'] = 278;
  18890. t['Oacute'] = 778;
  18891. t['oacute'] = 611;
  18892. t['amacron'] = 556;
  18893. t['sacute'] = 556;
  18894. t['idieresis'] = 278;
  18895. t['Ocircumflex'] = 778;
  18896. t['Ugrave'] = 722;
  18897. t['Delta'] = 612;
  18898. t['thorn'] = 611;
  18899. t['twosuperior'] = 333;
  18900. t['Odieresis'] = 778;
  18901. t['mu'] = 611;
  18902. t['igrave'] = 278;
  18903. t['ohungarumlaut'] = 611;
  18904. t['Eogonek'] = 667;
  18905. t['dcroat'] = 611;
  18906. t['threequarters'] = 834;
  18907. t['Scedilla'] = 667;
  18908. t['lcaron'] = 400;
  18909. t['Kcommaaccent'] = 722;
  18910. t['Lacute'] = 611;
  18911. t['trademark'] = 1000;
  18912. t['edotaccent'] = 556;
  18913. t['Igrave'] = 278;
  18914. t['Imacron'] = 278;
  18915. t['Lcaron'] = 611;
  18916. t['onehalf'] = 834;
  18917. t['lessequal'] = 549;
  18918. t['ocircumflex'] = 611;
  18919. t['ntilde'] = 611;
  18920. t['Uhungarumlaut'] = 722;
  18921. t['Eacute'] = 667;
  18922. t['emacron'] = 556;
  18923. t['gbreve'] = 611;
  18924. t['onequarter'] = 834;
  18925. t['Scaron'] = 667;
  18926. t['Scommaaccent'] = 667;
  18927. t['Ohungarumlaut'] = 778;
  18928. t['degree'] = 400;
  18929. t['ograve'] = 611;
  18930. t['Ccaron'] = 722;
  18931. t['ugrave'] = 611;
  18932. t['radical'] = 549;
  18933. t['Dcaron'] = 722;
  18934. t['rcommaaccent'] = 389;
  18935. t['Ntilde'] = 722;
  18936. t['otilde'] = 611;
  18937. t['Rcommaaccent'] = 722;
  18938. t['Lcommaaccent'] = 611;
  18939. t['Atilde'] = 722;
  18940. t['Aogonek'] = 722;
  18941. t['Aring'] = 722;
  18942. t['Otilde'] = 778;
  18943. t['zdotaccent'] = 500;
  18944. t['Ecaron'] = 667;
  18945. t['Iogonek'] = 278;
  18946. t['kcommaaccent'] = 556;
  18947. t['minus'] = 584;
  18948. t['Icircumflex'] = 278;
  18949. t['ncaron'] = 611;
  18950. t['tcommaaccent'] = 333;
  18951. t['logicalnot'] = 584;
  18952. t['odieresis'] = 611;
  18953. t['udieresis'] = 611;
  18954. t['notequal'] = 549;
  18955. t['gcommaaccent'] = 611;
  18956. t['eth'] = 611;
  18957. t['zcaron'] = 500;
  18958. t['ncommaaccent'] = 611;
  18959. t['onesuperior'] = 333;
  18960. t['imacron'] = 278;
  18961. t['Euro'] = 556;
  18962. });
  18963. t['Helvetica-Oblique'] = getLookupTableFactory(function (t) {
  18964. t['space'] = 278;
  18965. t['exclam'] = 278;
  18966. t['quotedbl'] = 355;
  18967. t['numbersign'] = 556;
  18968. t['dollar'] = 556;
  18969. t['percent'] = 889;
  18970. t['ampersand'] = 667;
  18971. t['quoteright'] = 222;
  18972. t['parenleft'] = 333;
  18973. t['parenright'] = 333;
  18974. t['asterisk'] = 389;
  18975. t['plus'] = 584;
  18976. t['comma'] = 278;
  18977. t['hyphen'] = 333;
  18978. t['period'] = 278;
  18979. t['slash'] = 278;
  18980. t['zero'] = 556;
  18981. t['one'] = 556;
  18982. t['two'] = 556;
  18983. t['three'] = 556;
  18984. t['four'] = 556;
  18985. t['five'] = 556;
  18986. t['six'] = 556;
  18987. t['seven'] = 556;
  18988. t['eight'] = 556;
  18989. t['nine'] = 556;
  18990. t['colon'] = 278;
  18991. t['semicolon'] = 278;
  18992. t['less'] = 584;
  18993. t['equal'] = 584;
  18994. t['greater'] = 584;
  18995. t['question'] = 556;
  18996. t['at'] = 1015;
  18997. t['A'] = 667;
  18998. t['B'] = 667;
  18999. t['C'] = 722;
  19000. t['D'] = 722;
  19001. t['E'] = 667;
  19002. t['F'] = 611;
  19003. t['G'] = 778;
  19004. t['H'] = 722;
  19005. t['I'] = 278;
  19006. t['J'] = 500;
  19007. t['K'] = 667;
  19008. t['L'] = 556;
  19009. t['M'] = 833;
  19010. t['N'] = 722;
  19011. t['O'] = 778;
  19012. t['P'] = 667;
  19013. t['Q'] = 778;
  19014. t['R'] = 722;
  19015. t['S'] = 667;
  19016. t['T'] = 611;
  19017. t['U'] = 722;
  19018. t['V'] = 667;
  19019. t['W'] = 944;
  19020. t['X'] = 667;
  19021. t['Y'] = 667;
  19022. t['Z'] = 611;
  19023. t['bracketleft'] = 278;
  19024. t['backslash'] = 278;
  19025. t['bracketright'] = 278;
  19026. t['asciicircum'] = 469;
  19027. t['underscore'] = 556;
  19028. t['quoteleft'] = 222;
  19029. t['a'] = 556;
  19030. t['b'] = 556;
  19031. t['c'] = 500;
  19032. t['d'] = 556;
  19033. t['e'] = 556;
  19034. t['f'] = 278;
  19035. t['g'] = 556;
  19036. t['h'] = 556;
  19037. t['i'] = 222;
  19038. t['j'] = 222;
  19039. t['k'] = 500;
  19040. t['l'] = 222;
  19041. t['m'] = 833;
  19042. t['n'] = 556;
  19043. t['o'] = 556;
  19044. t['p'] = 556;
  19045. t['q'] = 556;
  19046. t['r'] = 333;
  19047. t['s'] = 500;
  19048. t['t'] = 278;
  19049. t['u'] = 556;
  19050. t['v'] = 500;
  19051. t['w'] = 722;
  19052. t['x'] = 500;
  19053. t['y'] = 500;
  19054. t['z'] = 500;
  19055. t['braceleft'] = 334;
  19056. t['bar'] = 260;
  19057. t['braceright'] = 334;
  19058. t['asciitilde'] = 584;
  19059. t['exclamdown'] = 333;
  19060. t['cent'] = 556;
  19061. t['sterling'] = 556;
  19062. t['fraction'] = 167;
  19063. t['yen'] = 556;
  19064. t['florin'] = 556;
  19065. t['section'] = 556;
  19066. t['currency'] = 556;
  19067. t['quotesingle'] = 191;
  19068. t['quotedblleft'] = 333;
  19069. t['guillemotleft'] = 556;
  19070. t['guilsinglleft'] = 333;
  19071. t['guilsinglright'] = 333;
  19072. t['fi'] = 500;
  19073. t['fl'] = 500;
  19074. t['endash'] = 556;
  19075. t['dagger'] = 556;
  19076. t['daggerdbl'] = 556;
  19077. t['periodcentered'] = 278;
  19078. t['paragraph'] = 537;
  19079. t['bullet'] = 350;
  19080. t['quotesinglbase'] = 222;
  19081. t['quotedblbase'] = 333;
  19082. t['quotedblright'] = 333;
  19083. t['guillemotright'] = 556;
  19084. t['ellipsis'] = 1000;
  19085. t['perthousand'] = 1000;
  19086. t['questiondown'] = 611;
  19087. t['grave'] = 333;
  19088. t['acute'] = 333;
  19089. t['circumflex'] = 333;
  19090. t['tilde'] = 333;
  19091. t['macron'] = 333;
  19092. t['breve'] = 333;
  19093. t['dotaccent'] = 333;
  19094. t['dieresis'] = 333;
  19095. t['ring'] = 333;
  19096. t['cedilla'] = 333;
  19097. t['hungarumlaut'] = 333;
  19098. t['ogonek'] = 333;
  19099. t['caron'] = 333;
  19100. t['emdash'] = 1000;
  19101. t['AE'] = 1000;
  19102. t['ordfeminine'] = 370;
  19103. t['Lslash'] = 556;
  19104. t['Oslash'] = 778;
  19105. t['OE'] = 1000;
  19106. t['ordmasculine'] = 365;
  19107. t['ae'] = 889;
  19108. t['dotlessi'] = 278;
  19109. t['lslash'] = 222;
  19110. t['oslash'] = 611;
  19111. t['oe'] = 944;
  19112. t['germandbls'] = 611;
  19113. t['Idieresis'] = 278;
  19114. t['eacute'] = 556;
  19115. t['abreve'] = 556;
  19116. t['uhungarumlaut'] = 556;
  19117. t['ecaron'] = 556;
  19118. t['Ydieresis'] = 667;
  19119. t['divide'] = 584;
  19120. t['Yacute'] = 667;
  19121. t['Acircumflex'] = 667;
  19122. t['aacute'] = 556;
  19123. t['Ucircumflex'] = 722;
  19124. t['yacute'] = 500;
  19125. t['scommaaccent'] = 500;
  19126. t['ecircumflex'] = 556;
  19127. t['Uring'] = 722;
  19128. t['Udieresis'] = 722;
  19129. t['aogonek'] = 556;
  19130. t['Uacute'] = 722;
  19131. t['uogonek'] = 556;
  19132. t['Edieresis'] = 667;
  19133. t['Dcroat'] = 722;
  19134. t['commaaccent'] = 250;
  19135. t['copyright'] = 737;
  19136. t['Emacron'] = 667;
  19137. t['ccaron'] = 500;
  19138. t['aring'] = 556;
  19139. t['Ncommaaccent'] = 722;
  19140. t['lacute'] = 222;
  19141. t['agrave'] = 556;
  19142. t['Tcommaaccent'] = 611;
  19143. t['Cacute'] = 722;
  19144. t['atilde'] = 556;
  19145. t['Edotaccent'] = 667;
  19146. t['scaron'] = 500;
  19147. t['scedilla'] = 500;
  19148. t['iacute'] = 278;
  19149. t['lozenge'] = 471;
  19150. t['Rcaron'] = 722;
  19151. t['Gcommaaccent'] = 778;
  19152. t['ucircumflex'] = 556;
  19153. t['acircumflex'] = 556;
  19154. t['Amacron'] = 667;
  19155. t['rcaron'] = 333;
  19156. t['ccedilla'] = 500;
  19157. t['Zdotaccent'] = 611;
  19158. t['Thorn'] = 667;
  19159. t['Omacron'] = 778;
  19160. t['Racute'] = 722;
  19161. t['Sacute'] = 667;
  19162. t['dcaron'] = 643;
  19163. t['Umacron'] = 722;
  19164. t['uring'] = 556;
  19165. t['threesuperior'] = 333;
  19166. t['Ograve'] = 778;
  19167. t['Agrave'] = 667;
  19168. t['Abreve'] = 667;
  19169. t['multiply'] = 584;
  19170. t['uacute'] = 556;
  19171. t['Tcaron'] = 611;
  19172. t['partialdiff'] = 476;
  19173. t['ydieresis'] = 500;
  19174. t['Nacute'] = 722;
  19175. t['icircumflex'] = 278;
  19176. t['Ecircumflex'] = 667;
  19177. t['adieresis'] = 556;
  19178. t['edieresis'] = 556;
  19179. t['cacute'] = 500;
  19180. t['nacute'] = 556;
  19181. t['umacron'] = 556;
  19182. t['Ncaron'] = 722;
  19183. t['Iacute'] = 278;
  19184. t['plusminus'] = 584;
  19185. t['brokenbar'] = 260;
  19186. t['registered'] = 737;
  19187. t['Gbreve'] = 778;
  19188. t['Idotaccent'] = 278;
  19189. t['summation'] = 600;
  19190. t['Egrave'] = 667;
  19191. t['racute'] = 333;
  19192. t['omacron'] = 556;
  19193. t['Zacute'] = 611;
  19194. t['Zcaron'] = 611;
  19195. t['greaterequal'] = 549;
  19196. t['Eth'] = 722;
  19197. t['Ccedilla'] = 722;
  19198. t['lcommaaccent'] = 222;
  19199. t['tcaron'] = 317;
  19200. t['eogonek'] = 556;
  19201. t['Uogonek'] = 722;
  19202. t['Aacute'] = 667;
  19203. t['Adieresis'] = 667;
  19204. t['egrave'] = 556;
  19205. t['zacute'] = 500;
  19206. t['iogonek'] = 222;
  19207. t['Oacute'] = 778;
  19208. t['oacute'] = 556;
  19209. t['amacron'] = 556;
  19210. t['sacute'] = 500;
  19211. t['idieresis'] = 278;
  19212. t['Ocircumflex'] = 778;
  19213. t['Ugrave'] = 722;
  19214. t['Delta'] = 612;
  19215. t['thorn'] = 556;
  19216. t['twosuperior'] = 333;
  19217. t['Odieresis'] = 778;
  19218. t['mu'] = 556;
  19219. t['igrave'] = 278;
  19220. t['ohungarumlaut'] = 556;
  19221. t['Eogonek'] = 667;
  19222. t['dcroat'] = 556;
  19223. t['threequarters'] = 834;
  19224. t['Scedilla'] = 667;
  19225. t['lcaron'] = 299;
  19226. t['Kcommaaccent'] = 667;
  19227. t['Lacute'] = 556;
  19228. t['trademark'] = 1000;
  19229. t['edotaccent'] = 556;
  19230. t['Igrave'] = 278;
  19231. t['Imacron'] = 278;
  19232. t['Lcaron'] = 556;
  19233. t['onehalf'] = 834;
  19234. t['lessequal'] = 549;
  19235. t['ocircumflex'] = 556;
  19236. t['ntilde'] = 556;
  19237. t['Uhungarumlaut'] = 722;
  19238. t['Eacute'] = 667;
  19239. t['emacron'] = 556;
  19240. t['gbreve'] = 556;
  19241. t['onequarter'] = 834;
  19242. t['Scaron'] = 667;
  19243. t['Scommaaccent'] = 667;
  19244. t['Ohungarumlaut'] = 778;
  19245. t['degree'] = 400;
  19246. t['ograve'] = 556;
  19247. t['Ccaron'] = 722;
  19248. t['ugrave'] = 556;
  19249. t['radical'] = 453;
  19250. t['Dcaron'] = 722;
  19251. t['rcommaaccent'] = 333;
  19252. t['Ntilde'] = 722;
  19253. t['otilde'] = 556;
  19254. t['Rcommaaccent'] = 722;
  19255. t['Lcommaaccent'] = 556;
  19256. t['Atilde'] = 667;
  19257. t['Aogonek'] = 667;
  19258. t['Aring'] = 667;
  19259. t['Otilde'] = 778;
  19260. t['zdotaccent'] = 500;
  19261. t['Ecaron'] = 667;
  19262. t['Iogonek'] = 278;
  19263. t['kcommaaccent'] = 500;
  19264. t['minus'] = 584;
  19265. t['Icircumflex'] = 278;
  19266. t['ncaron'] = 556;
  19267. t['tcommaaccent'] = 278;
  19268. t['logicalnot'] = 584;
  19269. t['odieresis'] = 556;
  19270. t['udieresis'] = 556;
  19271. t['notequal'] = 549;
  19272. t['gcommaaccent'] = 556;
  19273. t['eth'] = 556;
  19274. t['zcaron'] = 500;
  19275. t['ncommaaccent'] = 556;
  19276. t['onesuperior'] = 333;
  19277. t['imacron'] = 278;
  19278. t['Euro'] = 556;
  19279. });
  19280. t['Symbol'] = getLookupTableFactory(function (t) {
  19281. t['space'] = 250;
  19282. t['exclam'] = 333;
  19283. t['universal'] = 713;
  19284. t['numbersign'] = 500;
  19285. t['existential'] = 549;
  19286. t['percent'] = 833;
  19287. t['ampersand'] = 778;
  19288. t['suchthat'] = 439;
  19289. t['parenleft'] = 333;
  19290. t['parenright'] = 333;
  19291. t['asteriskmath'] = 500;
  19292. t['plus'] = 549;
  19293. t['comma'] = 250;
  19294. t['minus'] = 549;
  19295. t['period'] = 250;
  19296. t['slash'] = 278;
  19297. t['zero'] = 500;
  19298. t['one'] = 500;
  19299. t['two'] = 500;
  19300. t['three'] = 500;
  19301. t['four'] = 500;
  19302. t['five'] = 500;
  19303. t['six'] = 500;
  19304. t['seven'] = 500;
  19305. t['eight'] = 500;
  19306. t['nine'] = 500;
  19307. t['colon'] = 278;
  19308. t['semicolon'] = 278;
  19309. t['less'] = 549;
  19310. t['equal'] = 549;
  19311. t['greater'] = 549;
  19312. t['question'] = 444;
  19313. t['congruent'] = 549;
  19314. t['Alpha'] = 722;
  19315. t['Beta'] = 667;
  19316. t['Chi'] = 722;
  19317. t['Delta'] = 612;
  19318. t['Epsilon'] = 611;
  19319. t['Phi'] = 763;
  19320. t['Gamma'] = 603;
  19321. t['Eta'] = 722;
  19322. t['Iota'] = 333;
  19323. t['theta1'] = 631;
  19324. t['Kappa'] = 722;
  19325. t['Lambda'] = 686;
  19326. t['Mu'] = 889;
  19327. t['Nu'] = 722;
  19328. t['Omicron'] = 722;
  19329. t['Pi'] = 768;
  19330. t['Theta'] = 741;
  19331. t['Rho'] = 556;
  19332. t['Sigma'] = 592;
  19333. t['Tau'] = 611;
  19334. t['Upsilon'] = 690;
  19335. t['sigma1'] = 439;
  19336. t['Omega'] = 768;
  19337. t['Xi'] = 645;
  19338. t['Psi'] = 795;
  19339. t['Zeta'] = 611;
  19340. t['bracketleft'] = 333;
  19341. t['therefore'] = 863;
  19342. t['bracketright'] = 333;
  19343. t['perpendicular'] = 658;
  19344. t['underscore'] = 500;
  19345. t['radicalex'] = 500;
  19346. t['alpha'] = 631;
  19347. t['beta'] = 549;
  19348. t['chi'] = 549;
  19349. t['delta'] = 494;
  19350. t['epsilon'] = 439;
  19351. t['phi'] = 521;
  19352. t['gamma'] = 411;
  19353. t['eta'] = 603;
  19354. t['iota'] = 329;
  19355. t['phi1'] = 603;
  19356. t['kappa'] = 549;
  19357. t['lambda'] = 549;
  19358. t['mu'] = 576;
  19359. t['nu'] = 521;
  19360. t['omicron'] = 549;
  19361. t['pi'] = 549;
  19362. t['theta'] = 521;
  19363. t['rho'] = 549;
  19364. t['sigma'] = 603;
  19365. t['tau'] = 439;
  19366. t['upsilon'] = 576;
  19367. t['omega1'] = 713;
  19368. t['omega'] = 686;
  19369. t['xi'] = 493;
  19370. t['psi'] = 686;
  19371. t['zeta'] = 494;
  19372. t['braceleft'] = 480;
  19373. t['bar'] = 200;
  19374. t['braceright'] = 480;
  19375. t['similar'] = 549;
  19376. t['Euro'] = 750;
  19377. t['Upsilon1'] = 620;
  19378. t['minute'] = 247;
  19379. t['lessequal'] = 549;
  19380. t['fraction'] = 167;
  19381. t['infinity'] = 713;
  19382. t['florin'] = 500;
  19383. t['club'] = 753;
  19384. t['diamond'] = 753;
  19385. t['heart'] = 753;
  19386. t['spade'] = 753;
  19387. t['arrowboth'] = 1042;
  19388. t['arrowleft'] = 987;
  19389. t['arrowup'] = 603;
  19390. t['arrowright'] = 987;
  19391. t['arrowdown'] = 603;
  19392. t['degree'] = 400;
  19393. t['plusminus'] = 549;
  19394. t['second'] = 411;
  19395. t['greaterequal'] = 549;
  19396. t['multiply'] = 549;
  19397. t['proportional'] = 713;
  19398. t['partialdiff'] = 494;
  19399. t['bullet'] = 460;
  19400. t['divide'] = 549;
  19401. t['notequal'] = 549;
  19402. t['equivalence'] = 549;
  19403. t['approxequal'] = 549;
  19404. t['ellipsis'] = 1000;
  19405. t['arrowvertex'] = 603;
  19406. t['arrowhorizex'] = 1000;
  19407. t['carriagereturn'] = 658;
  19408. t['aleph'] = 823;
  19409. t['Ifraktur'] = 686;
  19410. t['Rfraktur'] = 795;
  19411. t['weierstrass'] = 987;
  19412. t['circlemultiply'] = 768;
  19413. t['circleplus'] = 768;
  19414. t['emptyset'] = 823;
  19415. t['intersection'] = 768;
  19416. t['union'] = 768;
  19417. t['propersuperset'] = 713;
  19418. t['reflexsuperset'] = 713;
  19419. t['notsubset'] = 713;
  19420. t['propersubset'] = 713;
  19421. t['reflexsubset'] = 713;
  19422. t['element'] = 713;
  19423. t['notelement'] = 713;
  19424. t['angle'] = 768;
  19425. t['gradient'] = 713;
  19426. t['registerserif'] = 790;
  19427. t['copyrightserif'] = 790;
  19428. t['trademarkserif'] = 890;
  19429. t['product'] = 823;
  19430. t['radical'] = 549;
  19431. t['dotmath'] = 250;
  19432. t['logicalnot'] = 713;
  19433. t['logicaland'] = 603;
  19434. t['logicalor'] = 603;
  19435. t['arrowdblboth'] = 1042;
  19436. t['arrowdblleft'] = 987;
  19437. t['arrowdblup'] = 603;
  19438. t['arrowdblright'] = 987;
  19439. t['arrowdbldown'] = 603;
  19440. t['lozenge'] = 494;
  19441. t['angleleft'] = 329;
  19442. t['registersans'] = 790;
  19443. t['copyrightsans'] = 790;
  19444. t['trademarksans'] = 786;
  19445. t['summation'] = 713;
  19446. t['parenlefttp'] = 384;
  19447. t['parenleftex'] = 384;
  19448. t['parenleftbt'] = 384;
  19449. t['bracketlefttp'] = 384;
  19450. t['bracketleftex'] = 384;
  19451. t['bracketleftbt'] = 384;
  19452. t['bracelefttp'] = 494;
  19453. t['braceleftmid'] = 494;
  19454. t['braceleftbt'] = 494;
  19455. t['braceex'] = 494;
  19456. t['angleright'] = 329;
  19457. t['integral'] = 274;
  19458. t['integraltp'] = 686;
  19459. t['integralex'] = 686;
  19460. t['integralbt'] = 686;
  19461. t['parenrighttp'] = 384;
  19462. t['parenrightex'] = 384;
  19463. t['parenrightbt'] = 384;
  19464. t['bracketrighttp'] = 384;
  19465. t['bracketrightex'] = 384;
  19466. t['bracketrightbt'] = 384;
  19467. t['bracerighttp'] = 494;
  19468. t['bracerightmid'] = 494;
  19469. t['bracerightbt'] = 494;
  19470. t['apple'] = 790;
  19471. });
  19472. t['Times-Roman'] = getLookupTableFactory(function (t) {
  19473. t['space'] = 250;
  19474. t['exclam'] = 333;
  19475. t['quotedbl'] = 408;
  19476. t['numbersign'] = 500;
  19477. t['dollar'] = 500;
  19478. t['percent'] = 833;
  19479. t['ampersand'] = 778;
  19480. t['quoteright'] = 333;
  19481. t['parenleft'] = 333;
  19482. t['parenright'] = 333;
  19483. t['asterisk'] = 500;
  19484. t['plus'] = 564;
  19485. t['comma'] = 250;
  19486. t['hyphen'] = 333;
  19487. t['period'] = 250;
  19488. t['slash'] = 278;
  19489. t['zero'] = 500;
  19490. t['one'] = 500;
  19491. t['two'] = 500;
  19492. t['three'] = 500;
  19493. t['four'] = 500;
  19494. t['five'] = 500;
  19495. t['six'] = 500;
  19496. t['seven'] = 500;
  19497. t['eight'] = 500;
  19498. t['nine'] = 500;
  19499. t['colon'] = 278;
  19500. t['semicolon'] = 278;
  19501. t['less'] = 564;
  19502. t['equal'] = 564;
  19503. t['greater'] = 564;
  19504. t['question'] = 444;
  19505. t['at'] = 921;
  19506. t['A'] = 722;
  19507. t['B'] = 667;
  19508. t['C'] = 667;
  19509. t['D'] = 722;
  19510. t['E'] = 611;
  19511. t['F'] = 556;
  19512. t['G'] = 722;
  19513. t['H'] = 722;
  19514. t['I'] = 333;
  19515. t['J'] = 389;
  19516. t['K'] = 722;
  19517. t['L'] = 611;
  19518. t['M'] = 889;
  19519. t['N'] = 722;
  19520. t['O'] = 722;
  19521. t['P'] = 556;
  19522. t['Q'] = 722;
  19523. t['R'] = 667;
  19524. t['S'] = 556;
  19525. t['T'] = 611;
  19526. t['U'] = 722;
  19527. t['V'] = 722;
  19528. t['W'] = 944;
  19529. t['X'] = 722;
  19530. t['Y'] = 722;
  19531. t['Z'] = 611;
  19532. t['bracketleft'] = 333;
  19533. t['backslash'] = 278;
  19534. t['bracketright'] = 333;
  19535. t['asciicircum'] = 469;
  19536. t['underscore'] = 500;
  19537. t['quoteleft'] = 333;
  19538. t['a'] = 444;
  19539. t['b'] = 500;
  19540. t['c'] = 444;
  19541. t['d'] = 500;
  19542. t['e'] = 444;
  19543. t['f'] = 333;
  19544. t['g'] = 500;
  19545. t['h'] = 500;
  19546. t['i'] = 278;
  19547. t['j'] = 278;
  19548. t['k'] = 500;
  19549. t['l'] = 278;
  19550. t['m'] = 778;
  19551. t['n'] = 500;
  19552. t['o'] = 500;
  19553. t['p'] = 500;
  19554. t['q'] = 500;
  19555. t['r'] = 333;
  19556. t['s'] = 389;
  19557. t['t'] = 278;
  19558. t['u'] = 500;
  19559. t['v'] = 500;
  19560. t['w'] = 722;
  19561. t['x'] = 500;
  19562. t['y'] = 500;
  19563. t['z'] = 444;
  19564. t['braceleft'] = 480;
  19565. t['bar'] = 200;
  19566. t['braceright'] = 480;
  19567. t['asciitilde'] = 541;
  19568. t['exclamdown'] = 333;
  19569. t['cent'] = 500;
  19570. t['sterling'] = 500;
  19571. t['fraction'] = 167;
  19572. t['yen'] = 500;
  19573. t['florin'] = 500;
  19574. t['section'] = 500;
  19575. t['currency'] = 500;
  19576. t['quotesingle'] = 180;
  19577. t['quotedblleft'] = 444;
  19578. t['guillemotleft'] = 500;
  19579. t['guilsinglleft'] = 333;
  19580. t['guilsinglright'] = 333;
  19581. t['fi'] = 556;
  19582. t['fl'] = 556;
  19583. t['endash'] = 500;
  19584. t['dagger'] = 500;
  19585. t['daggerdbl'] = 500;
  19586. t['periodcentered'] = 250;
  19587. t['paragraph'] = 453;
  19588. t['bullet'] = 350;
  19589. t['quotesinglbase'] = 333;
  19590. t['quotedblbase'] = 444;
  19591. t['quotedblright'] = 444;
  19592. t['guillemotright'] = 500;
  19593. t['ellipsis'] = 1000;
  19594. t['perthousand'] = 1000;
  19595. t['questiondown'] = 444;
  19596. t['grave'] = 333;
  19597. t['acute'] = 333;
  19598. t['circumflex'] = 333;
  19599. t['tilde'] = 333;
  19600. t['macron'] = 333;
  19601. t['breve'] = 333;
  19602. t['dotaccent'] = 333;
  19603. t['dieresis'] = 333;
  19604. t['ring'] = 333;
  19605. t['cedilla'] = 333;
  19606. t['hungarumlaut'] = 333;
  19607. t['ogonek'] = 333;
  19608. t['caron'] = 333;
  19609. t['emdash'] = 1000;
  19610. t['AE'] = 889;
  19611. t['ordfeminine'] = 276;
  19612. t['Lslash'] = 611;
  19613. t['Oslash'] = 722;
  19614. t['OE'] = 889;
  19615. t['ordmasculine'] = 310;
  19616. t['ae'] = 667;
  19617. t['dotlessi'] = 278;
  19618. t['lslash'] = 278;
  19619. t['oslash'] = 500;
  19620. t['oe'] = 722;
  19621. t['germandbls'] = 500;
  19622. t['Idieresis'] = 333;
  19623. t['eacute'] = 444;
  19624. t['abreve'] = 444;
  19625. t['uhungarumlaut'] = 500;
  19626. t['ecaron'] = 444;
  19627. t['Ydieresis'] = 722;
  19628. t['divide'] = 564;
  19629. t['Yacute'] = 722;
  19630. t['Acircumflex'] = 722;
  19631. t['aacute'] = 444;
  19632. t['Ucircumflex'] = 722;
  19633. t['yacute'] = 500;
  19634. t['scommaaccent'] = 389;
  19635. t['ecircumflex'] = 444;
  19636. t['Uring'] = 722;
  19637. t['Udieresis'] = 722;
  19638. t['aogonek'] = 444;
  19639. t['Uacute'] = 722;
  19640. t['uogonek'] = 500;
  19641. t['Edieresis'] = 611;
  19642. t['Dcroat'] = 722;
  19643. t['commaaccent'] = 250;
  19644. t['copyright'] = 760;
  19645. t['Emacron'] = 611;
  19646. t['ccaron'] = 444;
  19647. t['aring'] = 444;
  19648. t['Ncommaaccent'] = 722;
  19649. t['lacute'] = 278;
  19650. t['agrave'] = 444;
  19651. t['Tcommaaccent'] = 611;
  19652. t['Cacute'] = 667;
  19653. t['atilde'] = 444;
  19654. t['Edotaccent'] = 611;
  19655. t['scaron'] = 389;
  19656. t['scedilla'] = 389;
  19657. t['iacute'] = 278;
  19658. t['lozenge'] = 471;
  19659. t['Rcaron'] = 667;
  19660. t['Gcommaaccent'] = 722;
  19661. t['ucircumflex'] = 500;
  19662. t['acircumflex'] = 444;
  19663. t['Amacron'] = 722;
  19664. t['rcaron'] = 333;
  19665. t['ccedilla'] = 444;
  19666. t['Zdotaccent'] = 611;
  19667. t['Thorn'] = 556;
  19668. t['Omacron'] = 722;
  19669. t['Racute'] = 667;
  19670. t['Sacute'] = 556;
  19671. t['dcaron'] = 588;
  19672. t['Umacron'] = 722;
  19673. t['uring'] = 500;
  19674. t['threesuperior'] = 300;
  19675. t['Ograve'] = 722;
  19676. t['Agrave'] = 722;
  19677. t['Abreve'] = 722;
  19678. t['multiply'] = 564;
  19679. t['uacute'] = 500;
  19680. t['Tcaron'] = 611;
  19681. t['partialdiff'] = 476;
  19682. t['ydieresis'] = 500;
  19683. t['Nacute'] = 722;
  19684. t['icircumflex'] = 278;
  19685. t['Ecircumflex'] = 611;
  19686. t['adieresis'] = 444;
  19687. t['edieresis'] = 444;
  19688. t['cacute'] = 444;
  19689. t['nacute'] = 500;
  19690. t['umacron'] = 500;
  19691. t['Ncaron'] = 722;
  19692. t['Iacute'] = 333;
  19693. t['plusminus'] = 564;
  19694. t['brokenbar'] = 200;
  19695. t['registered'] = 760;
  19696. t['Gbreve'] = 722;
  19697. t['Idotaccent'] = 333;
  19698. t['summation'] = 600;
  19699. t['Egrave'] = 611;
  19700. t['racute'] = 333;
  19701. t['omacron'] = 500;
  19702. t['Zacute'] = 611;
  19703. t['Zcaron'] = 611;
  19704. t['greaterequal'] = 549;
  19705. t['Eth'] = 722;
  19706. t['Ccedilla'] = 667;
  19707. t['lcommaaccent'] = 278;
  19708. t['tcaron'] = 326;
  19709. t['eogonek'] = 444;
  19710. t['Uogonek'] = 722;
  19711. t['Aacute'] = 722;
  19712. t['Adieresis'] = 722;
  19713. t['egrave'] = 444;
  19714. t['zacute'] = 444;
  19715. t['iogonek'] = 278;
  19716. t['Oacute'] = 722;
  19717. t['oacute'] = 500;
  19718. t['amacron'] = 444;
  19719. t['sacute'] = 389;
  19720. t['idieresis'] = 278;
  19721. t['Ocircumflex'] = 722;
  19722. t['Ugrave'] = 722;
  19723. t['Delta'] = 612;
  19724. t['thorn'] = 500;
  19725. t['twosuperior'] = 300;
  19726. t['Odieresis'] = 722;
  19727. t['mu'] = 500;
  19728. t['igrave'] = 278;
  19729. t['ohungarumlaut'] = 500;
  19730. t['Eogonek'] = 611;
  19731. t['dcroat'] = 500;
  19732. t['threequarters'] = 750;
  19733. t['Scedilla'] = 556;
  19734. t['lcaron'] = 344;
  19735. t['Kcommaaccent'] = 722;
  19736. t['Lacute'] = 611;
  19737. t['trademark'] = 980;
  19738. t['edotaccent'] = 444;
  19739. t['Igrave'] = 333;
  19740. t['Imacron'] = 333;
  19741. t['Lcaron'] = 611;
  19742. t['onehalf'] = 750;
  19743. t['lessequal'] = 549;
  19744. t['ocircumflex'] = 500;
  19745. t['ntilde'] = 500;
  19746. t['Uhungarumlaut'] = 722;
  19747. t['Eacute'] = 611;
  19748. t['emacron'] = 444;
  19749. t['gbreve'] = 500;
  19750. t['onequarter'] = 750;
  19751. t['Scaron'] = 556;
  19752. t['Scommaaccent'] = 556;
  19753. t['Ohungarumlaut'] = 722;
  19754. t['degree'] = 400;
  19755. t['ograve'] = 500;
  19756. t['Ccaron'] = 667;
  19757. t['ugrave'] = 500;
  19758. t['radical'] = 453;
  19759. t['Dcaron'] = 722;
  19760. t['rcommaaccent'] = 333;
  19761. t['Ntilde'] = 722;
  19762. t['otilde'] = 500;
  19763. t['Rcommaaccent'] = 667;
  19764. t['Lcommaaccent'] = 611;
  19765. t['Atilde'] = 722;
  19766. t['Aogonek'] = 722;
  19767. t['Aring'] = 722;
  19768. t['Otilde'] = 722;
  19769. t['zdotaccent'] = 444;
  19770. t['Ecaron'] = 611;
  19771. t['Iogonek'] = 333;
  19772. t['kcommaaccent'] = 500;
  19773. t['minus'] = 564;
  19774. t['Icircumflex'] = 333;
  19775. t['ncaron'] = 500;
  19776. t['tcommaaccent'] = 278;
  19777. t['logicalnot'] = 564;
  19778. t['odieresis'] = 500;
  19779. t['udieresis'] = 500;
  19780. t['notequal'] = 549;
  19781. t['gcommaaccent'] = 500;
  19782. t['eth'] = 500;
  19783. t['zcaron'] = 444;
  19784. t['ncommaaccent'] = 500;
  19785. t['onesuperior'] = 300;
  19786. t['imacron'] = 278;
  19787. t['Euro'] = 500;
  19788. });
  19789. t['Times-Bold'] = getLookupTableFactory(function (t) {
  19790. t['space'] = 250;
  19791. t['exclam'] = 333;
  19792. t['quotedbl'] = 555;
  19793. t['numbersign'] = 500;
  19794. t['dollar'] = 500;
  19795. t['percent'] = 1000;
  19796. t['ampersand'] = 833;
  19797. t['quoteright'] = 333;
  19798. t['parenleft'] = 333;
  19799. t['parenright'] = 333;
  19800. t['asterisk'] = 500;
  19801. t['plus'] = 570;
  19802. t['comma'] = 250;
  19803. t['hyphen'] = 333;
  19804. t['period'] = 250;
  19805. t['slash'] = 278;
  19806. t['zero'] = 500;
  19807. t['one'] = 500;
  19808. t['two'] = 500;
  19809. t['three'] = 500;
  19810. t['four'] = 500;
  19811. t['five'] = 500;
  19812. t['six'] = 500;
  19813. t['seven'] = 500;
  19814. t['eight'] = 500;
  19815. t['nine'] = 500;
  19816. t['colon'] = 333;
  19817. t['semicolon'] = 333;
  19818. t['less'] = 570;
  19819. t['equal'] = 570;
  19820. t['greater'] = 570;
  19821. t['question'] = 500;
  19822. t['at'] = 930;
  19823. t['A'] = 722;
  19824. t['B'] = 667;
  19825. t['C'] = 722;
  19826. t['D'] = 722;
  19827. t['E'] = 667;
  19828. t['F'] = 611;
  19829. t['G'] = 778;
  19830. t['H'] = 778;
  19831. t['I'] = 389;
  19832. t['J'] = 500;
  19833. t['K'] = 778;
  19834. t['L'] = 667;
  19835. t['M'] = 944;
  19836. t['N'] = 722;
  19837. t['O'] = 778;
  19838. t['P'] = 611;
  19839. t['Q'] = 778;
  19840. t['R'] = 722;
  19841. t['S'] = 556;
  19842. t['T'] = 667;
  19843. t['U'] = 722;
  19844. t['V'] = 722;
  19845. t['W'] = 1000;
  19846. t['X'] = 722;
  19847. t['Y'] = 722;
  19848. t['Z'] = 667;
  19849. t['bracketleft'] = 333;
  19850. t['backslash'] = 278;
  19851. t['bracketright'] = 333;
  19852. t['asciicircum'] = 581;
  19853. t['underscore'] = 500;
  19854. t['quoteleft'] = 333;
  19855. t['a'] = 500;
  19856. t['b'] = 556;
  19857. t['c'] = 444;
  19858. t['d'] = 556;
  19859. t['e'] = 444;
  19860. t['f'] = 333;
  19861. t['g'] = 500;
  19862. t['h'] = 556;
  19863. t['i'] = 278;
  19864. t['j'] = 333;
  19865. t['k'] = 556;
  19866. t['l'] = 278;
  19867. t['m'] = 833;
  19868. t['n'] = 556;
  19869. t['o'] = 500;
  19870. t['p'] = 556;
  19871. t['q'] = 556;
  19872. t['r'] = 444;
  19873. t['s'] = 389;
  19874. t['t'] = 333;
  19875. t['u'] = 556;
  19876. t['v'] = 500;
  19877. t['w'] = 722;
  19878. t['x'] = 500;
  19879. t['y'] = 500;
  19880. t['z'] = 444;
  19881. t['braceleft'] = 394;
  19882. t['bar'] = 220;
  19883. t['braceright'] = 394;
  19884. t['asciitilde'] = 520;
  19885. t['exclamdown'] = 333;
  19886. t['cent'] = 500;
  19887. t['sterling'] = 500;
  19888. t['fraction'] = 167;
  19889. t['yen'] = 500;
  19890. t['florin'] = 500;
  19891. t['section'] = 500;
  19892. t['currency'] = 500;
  19893. t['quotesingle'] = 278;
  19894. t['quotedblleft'] = 500;
  19895. t['guillemotleft'] = 500;
  19896. t['guilsinglleft'] = 333;
  19897. t['guilsinglright'] = 333;
  19898. t['fi'] = 556;
  19899. t['fl'] = 556;
  19900. t['endash'] = 500;
  19901. t['dagger'] = 500;
  19902. t['daggerdbl'] = 500;
  19903. t['periodcentered'] = 250;
  19904. t['paragraph'] = 540;
  19905. t['bullet'] = 350;
  19906. t['quotesinglbase'] = 333;
  19907. t['quotedblbase'] = 500;
  19908. t['quotedblright'] = 500;
  19909. t['guillemotright'] = 500;
  19910. t['ellipsis'] = 1000;
  19911. t['perthousand'] = 1000;
  19912. t['questiondown'] = 500;
  19913. t['grave'] = 333;
  19914. t['acute'] = 333;
  19915. t['circumflex'] = 333;
  19916. t['tilde'] = 333;
  19917. t['macron'] = 333;
  19918. t['breve'] = 333;
  19919. t['dotaccent'] = 333;
  19920. t['dieresis'] = 333;
  19921. t['ring'] = 333;
  19922. t['cedilla'] = 333;
  19923. t['hungarumlaut'] = 333;
  19924. t['ogonek'] = 333;
  19925. t['caron'] = 333;
  19926. t['emdash'] = 1000;
  19927. t['AE'] = 1000;
  19928. t['ordfeminine'] = 300;
  19929. t['Lslash'] = 667;
  19930. t['Oslash'] = 778;
  19931. t['OE'] = 1000;
  19932. t['ordmasculine'] = 330;
  19933. t['ae'] = 722;
  19934. t['dotlessi'] = 278;
  19935. t['lslash'] = 278;
  19936. t['oslash'] = 500;
  19937. t['oe'] = 722;
  19938. t['germandbls'] = 556;
  19939. t['Idieresis'] = 389;
  19940. t['eacute'] = 444;
  19941. t['abreve'] = 500;
  19942. t['uhungarumlaut'] = 556;
  19943. t['ecaron'] = 444;
  19944. t['Ydieresis'] = 722;
  19945. t['divide'] = 570;
  19946. t['Yacute'] = 722;
  19947. t['Acircumflex'] = 722;
  19948. t['aacute'] = 500;
  19949. t['Ucircumflex'] = 722;
  19950. t['yacute'] = 500;
  19951. t['scommaaccent'] = 389;
  19952. t['ecircumflex'] = 444;
  19953. t['Uring'] = 722;
  19954. t['Udieresis'] = 722;
  19955. t['aogonek'] = 500;
  19956. t['Uacute'] = 722;
  19957. t['uogonek'] = 556;
  19958. t['Edieresis'] = 667;
  19959. t['Dcroat'] = 722;
  19960. t['commaaccent'] = 250;
  19961. t['copyright'] = 747;
  19962. t['Emacron'] = 667;
  19963. t['ccaron'] = 444;
  19964. t['aring'] = 500;
  19965. t['Ncommaaccent'] = 722;
  19966. t['lacute'] = 278;
  19967. t['agrave'] = 500;
  19968. t['Tcommaaccent'] = 667;
  19969. t['Cacute'] = 722;
  19970. t['atilde'] = 500;
  19971. t['Edotaccent'] = 667;
  19972. t['scaron'] = 389;
  19973. t['scedilla'] = 389;
  19974. t['iacute'] = 278;
  19975. t['lozenge'] = 494;
  19976. t['Rcaron'] = 722;
  19977. t['Gcommaaccent'] = 778;
  19978. t['ucircumflex'] = 556;
  19979. t['acircumflex'] = 500;
  19980. t['Amacron'] = 722;
  19981. t['rcaron'] = 444;
  19982. t['ccedilla'] = 444;
  19983. t['Zdotaccent'] = 667;
  19984. t['Thorn'] = 611;
  19985. t['Omacron'] = 778;
  19986. t['Racute'] = 722;
  19987. t['Sacute'] = 556;
  19988. t['dcaron'] = 672;
  19989. t['Umacron'] = 722;
  19990. t['uring'] = 556;
  19991. t['threesuperior'] = 300;
  19992. t['Ograve'] = 778;
  19993. t['Agrave'] = 722;
  19994. t['Abreve'] = 722;
  19995. t['multiply'] = 570;
  19996. t['uacute'] = 556;
  19997. t['Tcaron'] = 667;
  19998. t['partialdiff'] = 494;
  19999. t['ydieresis'] = 500;
  20000. t['Nacute'] = 722;
  20001. t['icircumflex'] = 278;
  20002. t['Ecircumflex'] = 667;
  20003. t['adieresis'] = 500;
  20004. t['edieresis'] = 444;
  20005. t['cacute'] = 444;
  20006. t['nacute'] = 556;
  20007. t['umacron'] = 556;
  20008. t['Ncaron'] = 722;
  20009. t['Iacute'] = 389;
  20010. t['plusminus'] = 570;
  20011. t['brokenbar'] = 220;
  20012. t['registered'] = 747;
  20013. t['Gbreve'] = 778;
  20014. t['Idotaccent'] = 389;
  20015. t['summation'] = 600;
  20016. t['Egrave'] = 667;
  20017. t['racute'] = 444;
  20018. t['omacron'] = 500;
  20019. t['Zacute'] = 667;
  20020. t['Zcaron'] = 667;
  20021. t['greaterequal'] = 549;
  20022. t['Eth'] = 722;
  20023. t['Ccedilla'] = 722;
  20024. t['lcommaaccent'] = 278;
  20025. t['tcaron'] = 416;
  20026. t['eogonek'] = 444;
  20027. t['Uogonek'] = 722;
  20028. t['Aacute'] = 722;
  20029. t['Adieresis'] = 722;
  20030. t['egrave'] = 444;
  20031. t['zacute'] = 444;
  20032. t['iogonek'] = 278;
  20033. t['Oacute'] = 778;
  20034. t['oacute'] = 500;
  20035. t['amacron'] = 500;
  20036. t['sacute'] = 389;
  20037. t['idieresis'] = 278;
  20038. t['Ocircumflex'] = 778;
  20039. t['Ugrave'] = 722;
  20040. t['Delta'] = 612;
  20041. t['thorn'] = 556;
  20042. t['twosuperior'] = 300;
  20043. t['Odieresis'] = 778;
  20044. t['mu'] = 556;
  20045. t['igrave'] = 278;
  20046. t['ohungarumlaut'] = 500;
  20047. t['Eogonek'] = 667;
  20048. t['dcroat'] = 556;
  20049. t['threequarters'] = 750;
  20050. t['Scedilla'] = 556;
  20051. t['lcaron'] = 394;
  20052. t['Kcommaaccent'] = 778;
  20053. t['Lacute'] = 667;
  20054. t['trademark'] = 1000;
  20055. t['edotaccent'] = 444;
  20056. t['Igrave'] = 389;
  20057. t['Imacron'] = 389;
  20058. t['Lcaron'] = 667;
  20059. t['onehalf'] = 750;
  20060. t['lessequal'] = 549;
  20061. t['ocircumflex'] = 500;
  20062. t['ntilde'] = 556;
  20063. t['Uhungarumlaut'] = 722;
  20064. t['Eacute'] = 667;
  20065. t['emacron'] = 444;
  20066. t['gbreve'] = 500;
  20067. t['onequarter'] = 750;
  20068. t['Scaron'] = 556;
  20069. t['Scommaaccent'] = 556;
  20070. t['Ohungarumlaut'] = 778;
  20071. t['degree'] = 400;
  20072. t['ograve'] = 500;
  20073. t['Ccaron'] = 722;
  20074. t['ugrave'] = 556;
  20075. t['radical'] = 549;
  20076. t['Dcaron'] = 722;
  20077. t['rcommaaccent'] = 444;
  20078. t['Ntilde'] = 722;
  20079. t['otilde'] = 500;
  20080. t['Rcommaaccent'] = 722;
  20081. t['Lcommaaccent'] = 667;
  20082. t['Atilde'] = 722;
  20083. t['Aogonek'] = 722;
  20084. t['Aring'] = 722;
  20085. t['Otilde'] = 778;
  20086. t['zdotaccent'] = 444;
  20087. t['Ecaron'] = 667;
  20088. t['Iogonek'] = 389;
  20089. t['kcommaaccent'] = 556;
  20090. t['minus'] = 570;
  20091. t['Icircumflex'] = 389;
  20092. t['ncaron'] = 556;
  20093. t['tcommaaccent'] = 333;
  20094. t['logicalnot'] = 570;
  20095. t['odieresis'] = 500;
  20096. t['udieresis'] = 556;
  20097. t['notequal'] = 549;
  20098. t['gcommaaccent'] = 500;
  20099. t['eth'] = 500;
  20100. t['zcaron'] = 444;
  20101. t['ncommaaccent'] = 556;
  20102. t['onesuperior'] = 300;
  20103. t['imacron'] = 278;
  20104. t['Euro'] = 500;
  20105. });
  20106. t['Times-BoldItalic'] = getLookupTableFactory(function (t) {
  20107. t['space'] = 250;
  20108. t['exclam'] = 389;
  20109. t['quotedbl'] = 555;
  20110. t['numbersign'] = 500;
  20111. t['dollar'] = 500;
  20112. t['percent'] = 833;
  20113. t['ampersand'] = 778;
  20114. t['quoteright'] = 333;
  20115. t['parenleft'] = 333;
  20116. t['parenright'] = 333;
  20117. t['asterisk'] = 500;
  20118. t['plus'] = 570;
  20119. t['comma'] = 250;
  20120. t['hyphen'] = 333;
  20121. t['period'] = 250;
  20122. t['slash'] = 278;
  20123. t['zero'] = 500;
  20124. t['one'] = 500;
  20125. t['two'] = 500;
  20126. t['three'] = 500;
  20127. t['four'] = 500;
  20128. t['five'] = 500;
  20129. t['six'] = 500;
  20130. t['seven'] = 500;
  20131. t['eight'] = 500;
  20132. t['nine'] = 500;
  20133. t['colon'] = 333;
  20134. t['semicolon'] = 333;
  20135. t['less'] = 570;
  20136. t['equal'] = 570;
  20137. t['greater'] = 570;
  20138. t['question'] = 500;
  20139. t['at'] = 832;
  20140. t['A'] = 667;
  20141. t['B'] = 667;
  20142. t['C'] = 667;
  20143. t['D'] = 722;
  20144. t['E'] = 667;
  20145. t['F'] = 667;
  20146. t['G'] = 722;
  20147. t['H'] = 778;
  20148. t['I'] = 389;
  20149. t['J'] = 500;
  20150. t['K'] = 667;
  20151. t['L'] = 611;
  20152. t['M'] = 889;
  20153. t['N'] = 722;
  20154. t['O'] = 722;
  20155. t['P'] = 611;
  20156. t['Q'] = 722;
  20157. t['R'] = 667;
  20158. t['S'] = 556;
  20159. t['T'] = 611;
  20160. t['U'] = 722;
  20161. t['V'] = 667;
  20162. t['W'] = 889;
  20163. t['X'] = 667;
  20164. t['Y'] = 611;
  20165. t['Z'] = 611;
  20166. t['bracketleft'] = 333;
  20167. t['backslash'] = 278;
  20168. t['bracketright'] = 333;
  20169. t['asciicircum'] = 570;
  20170. t['underscore'] = 500;
  20171. t['quoteleft'] = 333;
  20172. t['a'] = 500;
  20173. t['b'] = 500;
  20174. t['c'] = 444;
  20175. t['d'] = 500;
  20176. t['e'] = 444;
  20177. t['f'] = 333;
  20178. t['g'] = 500;
  20179. t['h'] = 556;
  20180. t['i'] = 278;
  20181. t['j'] = 278;
  20182. t['k'] = 500;
  20183. t['l'] = 278;
  20184. t['m'] = 778;
  20185. t['n'] = 556;
  20186. t['o'] = 500;
  20187. t['p'] = 500;
  20188. t['q'] = 500;
  20189. t['r'] = 389;
  20190. t['s'] = 389;
  20191. t['t'] = 278;
  20192. t['u'] = 556;
  20193. t['v'] = 444;
  20194. t['w'] = 667;
  20195. t['x'] = 500;
  20196. t['y'] = 444;
  20197. t['z'] = 389;
  20198. t['braceleft'] = 348;
  20199. t['bar'] = 220;
  20200. t['braceright'] = 348;
  20201. t['asciitilde'] = 570;
  20202. t['exclamdown'] = 389;
  20203. t['cent'] = 500;
  20204. t['sterling'] = 500;
  20205. t['fraction'] = 167;
  20206. t['yen'] = 500;
  20207. t['florin'] = 500;
  20208. t['section'] = 500;
  20209. t['currency'] = 500;
  20210. t['quotesingle'] = 278;
  20211. t['quotedblleft'] = 500;
  20212. t['guillemotleft'] = 500;
  20213. t['guilsinglleft'] = 333;
  20214. t['guilsinglright'] = 333;
  20215. t['fi'] = 556;
  20216. t['fl'] = 556;
  20217. t['endash'] = 500;
  20218. t['dagger'] = 500;
  20219. t['daggerdbl'] = 500;
  20220. t['periodcentered'] = 250;
  20221. t['paragraph'] = 500;
  20222. t['bullet'] = 350;
  20223. t['quotesinglbase'] = 333;
  20224. t['quotedblbase'] = 500;
  20225. t['quotedblright'] = 500;
  20226. t['guillemotright'] = 500;
  20227. t['ellipsis'] = 1000;
  20228. t['perthousand'] = 1000;
  20229. t['questiondown'] = 500;
  20230. t['grave'] = 333;
  20231. t['acute'] = 333;
  20232. t['circumflex'] = 333;
  20233. t['tilde'] = 333;
  20234. t['macron'] = 333;
  20235. t['breve'] = 333;
  20236. t['dotaccent'] = 333;
  20237. t['dieresis'] = 333;
  20238. t['ring'] = 333;
  20239. t['cedilla'] = 333;
  20240. t['hungarumlaut'] = 333;
  20241. t['ogonek'] = 333;
  20242. t['caron'] = 333;
  20243. t['emdash'] = 1000;
  20244. t['AE'] = 944;
  20245. t['ordfeminine'] = 266;
  20246. t['Lslash'] = 611;
  20247. t['Oslash'] = 722;
  20248. t['OE'] = 944;
  20249. t['ordmasculine'] = 300;
  20250. t['ae'] = 722;
  20251. t['dotlessi'] = 278;
  20252. t['lslash'] = 278;
  20253. t['oslash'] = 500;
  20254. t['oe'] = 722;
  20255. t['germandbls'] = 500;
  20256. t['Idieresis'] = 389;
  20257. t['eacute'] = 444;
  20258. t['abreve'] = 500;
  20259. t['uhungarumlaut'] = 556;
  20260. t['ecaron'] = 444;
  20261. t['Ydieresis'] = 611;
  20262. t['divide'] = 570;
  20263. t['Yacute'] = 611;
  20264. t['Acircumflex'] = 667;
  20265. t['aacute'] = 500;
  20266. t['Ucircumflex'] = 722;
  20267. t['yacute'] = 444;
  20268. t['scommaaccent'] = 389;
  20269. t['ecircumflex'] = 444;
  20270. t['Uring'] = 722;
  20271. t['Udieresis'] = 722;
  20272. t['aogonek'] = 500;
  20273. t['Uacute'] = 722;
  20274. t['uogonek'] = 556;
  20275. t['Edieresis'] = 667;
  20276. t['Dcroat'] = 722;
  20277. t['commaaccent'] = 250;
  20278. t['copyright'] = 747;
  20279. t['Emacron'] = 667;
  20280. t['ccaron'] = 444;
  20281. t['aring'] = 500;
  20282. t['Ncommaaccent'] = 722;
  20283. t['lacute'] = 278;
  20284. t['agrave'] = 500;
  20285. t['Tcommaaccent'] = 611;
  20286. t['Cacute'] = 667;
  20287. t['atilde'] = 500;
  20288. t['Edotaccent'] = 667;
  20289. t['scaron'] = 389;
  20290. t['scedilla'] = 389;
  20291. t['iacute'] = 278;
  20292. t['lozenge'] = 494;
  20293. t['Rcaron'] = 667;
  20294. t['Gcommaaccent'] = 722;
  20295. t['ucircumflex'] = 556;
  20296. t['acircumflex'] = 500;
  20297. t['Amacron'] = 667;
  20298. t['rcaron'] = 389;
  20299. t['ccedilla'] = 444;
  20300. t['Zdotaccent'] = 611;
  20301. t['Thorn'] = 611;
  20302. t['Omacron'] = 722;
  20303. t['Racute'] = 667;
  20304. t['Sacute'] = 556;
  20305. t['dcaron'] = 608;
  20306. t['Umacron'] = 722;
  20307. t['uring'] = 556;
  20308. t['threesuperior'] = 300;
  20309. t['Ograve'] = 722;
  20310. t['Agrave'] = 667;
  20311. t['Abreve'] = 667;
  20312. t['multiply'] = 570;
  20313. t['uacute'] = 556;
  20314. t['Tcaron'] = 611;
  20315. t['partialdiff'] = 494;
  20316. t['ydieresis'] = 444;
  20317. t['Nacute'] = 722;
  20318. t['icircumflex'] = 278;
  20319. t['Ecircumflex'] = 667;
  20320. t['adieresis'] = 500;
  20321. t['edieresis'] = 444;
  20322. t['cacute'] = 444;
  20323. t['nacute'] = 556;
  20324. t['umacron'] = 556;
  20325. t['Ncaron'] = 722;
  20326. t['Iacute'] = 389;
  20327. t['plusminus'] = 570;
  20328. t['brokenbar'] = 220;
  20329. t['registered'] = 747;
  20330. t['Gbreve'] = 722;
  20331. t['Idotaccent'] = 389;
  20332. t['summation'] = 600;
  20333. t['Egrave'] = 667;
  20334. t['racute'] = 389;
  20335. t['omacron'] = 500;
  20336. t['Zacute'] = 611;
  20337. t['Zcaron'] = 611;
  20338. t['greaterequal'] = 549;
  20339. t['Eth'] = 722;
  20340. t['Ccedilla'] = 667;
  20341. t['lcommaaccent'] = 278;
  20342. t['tcaron'] = 366;
  20343. t['eogonek'] = 444;
  20344. t['Uogonek'] = 722;
  20345. t['Aacute'] = 667;
  20346. t['Adieresis'] = 667;
  20347. t['egrave'] = 444;
  20348. t['zacute'] = 389;
  20349. t['iogonek'] = 278;
  20350. t['Oacute'] = 722;
  20351. t['oacute'] = 500;
  20352. t['amacron'] = 500;
  20353. t['sacute'] = 389;
  20354. t['idieresis'] = 278;
  20355. t['Ocircumflex'] = 722;
  20356. t['Ugrave'] = 722;
  20357. t['Delta'] = 612;
  20358. t['thorn'] = 500;
  20359. t['twosuperior'] = 300;
  20360. t['Odieresis'] = 722;
  20361. t['mu'] = 576;
  20362. t['igrave'] = 278;
  20363. t['ohungarumlaut'] = 500;
  20364. t['Eogonek'] = 667;
  20365. t['dcroat'] = 500;
  20366. t['threequarters'] = 750;
  20367. t['Scedilla'] = 556;
  20368. t['lcaron'] = 382;
  20369. t['Kcommaaccent'] = 667;
  20370. t['Lacute'] = 611;
  20371. t['trademark'] = 1000;
  20372. t['edotaccent'] = 444;
  20373. t['Igrave'] = 389;
  20374. t['Imacron'] = 389;
  20375. t['Lcaron'] = 611;
  20376. t['onehalf'] = 750;
  20377. t['lessequal'] = 549;
  20378. t['ocircumflex'] = 500;
  20379. t['ntilde'] = 556;
  20380. t['Uhungarumlaut'] = 722;
  20381. t['Eacute'] = 667;
  20382. t['emacron'] = 444;
  20383. t['gbreve'] = 500;
  20384. t['onequarter'] = 750;
  20385. t['Scaron'] = 556;
  20386. t['Scommaaccent'] = 556;
  20387. t['Ohungarumlaut'] = 722;
  20388. t['degree'] = 400;
  20389. t['ograve'] = 500;
  20390. t['Ccaron'] = 667;
  20391. t['ugrave'] = 556;
  20392. t['radical'] = 549;
  20393. t['Dcaron'] = 722;
  20394. t['rcommaaccent'] = 389;
  20395. t['Ntilde'] = 722;
  20396. t['otilde'] = 500;
  20397. t['Rcommaaccent'] = 667;
  20398. t['Lcommaaccent'] = 611;
  20399. t['Atilde'] = 667;
  20400. t['Aogonek'] = 667;
  20401. t['Aring'] = 667;
  20402. t['Otilde'] = 722;
  20403. t['zdotaccent'] = 389;
  20404. t['Ecaron'] = 667;
  20405. t['Iogonek'] = 389;
  20406. t['kcommaaccent'] = 500;
  20407. t['minus'] = 606;
  20408. t['Icircumflex'] = 389;
  20409. t['ncaron'] = 556;
  20410. t['tcommaaccent'] = 278;
  20411. t['logicalnot'] = 606;
  20412. t['odieresis'] = 500;
  20413. t['udieresis'] = 556;
  20414. t['notequal'] = 549;
  20415. t['gcommaaccent'] = 500;
  20416. t['eth'] = 500;
  20417. t['zcaron'] = 389;
  20418. t['ncommaaccent'] = 556;
  20419. t['onesuperior'] = 300;
  20420. t['imacron'] = 278;
  20421. t['Euro'] = 500;
  20422. });
  20423. t['Times-Italic'] = getLookupTableFactory(function (t) {
  20424. t['space'] = 250;
  20425. t['exclam'] = 333;
  20426. t['quotedbl'] = 420;
  20427. t['numbersign'] = 500;
  20428. t['dollar'] = 500;
  20429. t['percent'] = 833;
  20430. t['ampersand'] = 778;
  20431. t['quoteright'] = 333;
  20432. t['parenleft'] = 333;
  20433. t['parenright'] = 333;
  20434. t['asterisk'] = 500;
  20435. t['plus'] = 675;
  20436. t['comma'] = 250;
  20437. t['hyphen'] = 333;
  20438. t['period'] = 250;
  20439. t['slash'] = 278;
  20440. t['zero'] = 500;
  20441. t['one'] = 500;
  20442. t['two'] = 500;
  20443. t['three'] = 500;
  20444. t['four'] = 500;
  20445. t['five'] = 500;
  20446. t['six'] = 500;
  20447. t['seven'] = 500;
  20448. t['eight'] = 500;
  20449. t['nine'] = 500;
  20450. t['colon'] = 333;
  20451. t['semicolon'] = 333;
  20452. t['less'] = 675;
  20453. t['equal'] = 675;
  20454. t['greater'] = 675;
  20455. t['question'] = 500;
  20456. t['at'] = 920;
  20457. t['A'] = 611;
  20458. t['B'] = 611;
  20459. t['C'] = 667;
  20460. t['D'] = 722;
  20461. t['E'] = 611;
  20462. t['F'] = 611;
  20463. t['G'] = 722;
  20464. t['H'] = 722;
  20465. t['I'] = 333;
  20466. t['J'] = 444;
  20467. t['K'] = 667;
  20468. t['L'] = 556;
  20469. t['M'] = 833;
  20470. t['N'] = 667;
  20471. t['O'] = 722;
  20472. t['P'] = 611;
  20473. t['Q'] = 722;
  20474. t['R'] = 611;
  20475. t['S'] = 500;
  20476. t['T'] = 556;
  20477. t['U'] = 722;
  20478. t['V'] = 611;
  20479. t['W'] = 833;
  20480. t['X'] = 611;
  20481. t['Y'] = 556;
  20482. t['Z'] = 556;
  20483. t['bracketleft'] = 389;
  20484. t['backslash'] = 278;
  20485. t['bracketright'] = 389;
  20486. t['asciicircum'] = 422;
  20487. t['underscore'] = 500;
  20488. t['quoteleft'] = 333;
  20489. t['a'] = 500;
  20490. t['b'] = 500;
  20491. t['c'] = 444;
  20492. t['d'] = 500;
  20493. t['e'] = 444;
  20494. t['f'] = 278;
  20495. t['g'] = 500;
  20496. t['h'] = 500;
  20497. t['i'] = 278;
  20498. t['j'] = 278;
  20499. t['k'] = 444;
  20500. t['l'] = 278;
  20501. t['m'] = 722;
  20502. t['n'] = 500;
  20503. t['o'] = 500;
  20504. t['p'] = 500;
  20505. t['q'] = 500;
  20506. t['r'] = 389;
  20507. t['s'] = 389;
  20508. t['t'] = 278;
  20509. t['u'] = 500;
  20510. t['v'] = 444;
  20511. t['w'] = 667;
  20512. t['x'] = 444;
  20513. t['y'] = 444;
  20514. t['z'] = 389;
  20515. t['braceleft'] = 400;
  20516. t['bar'] = 275;
  20517. t['braceright'] = 400;
  20518. t['asciitilde'] = 541;
  20519. t['exclamdown'] = 389;
  20520. t['cent'] = 500;
  20521. t['sterling'] = 500;
  20522. t['fraction'] = 167;
  20523. t['yen'] = 500;
  20524. t['florin'] = 500;
  20525. t['section'] = 500;
  20526. t['currency'] = 500;
  20527. t['quotesingle'] = 214;
  20528. t['quotedblleft'] = 556;
  20529. t['guillemotleft'] = 500;
  20530. t['guilsinglleft'] = 333;
  20531. t['guilsinglright'] = 333;
  20532. t['fi'] = 500;
  20533. t['fl'] = 500;
  20534. t['endash'] = 500;
  20535. t['dagger'] = 500;
  20536. t['daggerdbl'] = 500;
  20537. t['periodcentered'] = 250;
  20538. t['paragraph'] = 523;
  20539. t['bullet'] = 350;
  20540. t['quotesinglbase'] = 333;
  20541. t['quotedblbase'] = 556;
  20542. t['quotedblright'] = 556;
  20543. t['guillemotright'] = 500;
  20544. t['ellipsis'] = 889;
  20545. t['perthousand'] = 1000;
  20546. t['questiondown'] = 500;
  20547. t['grave'] = 333;
  20548. t['acute'] = 333;
  20549. t['circumflex'] = 333;
  20550. t['tilde'] = 333;
  20551. t['macron'] = 333;
  20552. t['breve'] = 333;
  20553. t['dotaccent'] = 333;
  20554. t['dieresis'] = 333;
  20555. t['ring'] = 333;
  20556. t['cedilla'] = 333;
  20557. t['hungarumlaut'] = 333;
  20558. t['ogonek'] = 333;
  20559. t['caron'] = 333;
  20560. t['emdash'] = 889;
  20561. t['AE'] = 889;
  20562. t['ordfeminine'] = 276;
  20563. t['Lslash'] = 556;
  20564. t['Oslash'] = 722;
  20565. t['OE'] = 944;
  20566. t['ordmasculine'] = 310;
  20567. t['ae'] = 667;
  20568. t['dotlessi'] = 278;
  20569. t['lslash'] = 278;
  20570. t['oslash'] = 500;
  20571. t['oe'] = 667;
  20572. t['germandbls'] = 500;
  20573. t['Idieresis'] = 333;
  20574. t['eacute'] = 444;
  20575. t['abreve'] = 500;
  20576. t['uhungarumlaut'] = 500;
  20577. t['ecaron'] = 444;
  20578. t['Ydieresis'] = 556;
  20579. t['divide'] = 675;
  20580. t['Yacute'] = 556;
  20581. t['Acircumflex'] = 611;
  20582. t['aacute'] = 500;
  20583. t['Ucircumflex'] = 722;
  20584. t['yacute'] = 444;
  20585. t['scommaaccent'] = 389;
  20586. t['ecircumflex'] = 444;
  20587. t['Uring'] = 722;
  20588. t['Udieresis'] = 722;
  20589. t['aogonek'] = 500;
  20590. t['Uacute'] = 722;
  20591. t['uogonek'] = 500;
  20592. t['Edieresis'] = 611;
  20593. t['Dcroat'] = 722;
  20594. t['commaaccent'] = 250;
  20595. t['copyright'] = 760;
  20596. t['Emacron'] = 611;
  20597. t['ccaron'] = 444;
  20598. t['aring'] = 500;
  20599. t['Ncommaaccent'] = 667;
  20600. t['lacute'] = 278;
  20601. t['agrave'] = 500;
  20602. t['Tcommaaccent'] = 556;
  20603. t['Cacute'] = 667;
  20604. t['atilde'] = 500;
  20605. t['Edotaccent'] = 611;
  20606. t['scaron'] = 389;
  20607. t['scedilla'] = 389;
  20608. t['iacute'] = 278;
  20609. t['lozenge'] = 471;
  20610. t['Rcaron'] = 611;
  20611. t['Gcommaaccent'] = 722;
  20612. t['ucircumflex'] = 500;
  20613. t['acircumflex'] = 500;
  20614. t['Amacron'] = 611;
  20615. t['rcaron'] = 389;
  20616. t['ccedilla'] = 444;
  20617. t['Zdotaccent'] = 556;
  20618. t['Thorn'] = 611;
  20619. t['Omacron'] = 722;
  20620. t['Racute'] = 611;
  20621. t['Sacute'] = 500;
  20622. t['dcaron'] = 544;
  20623. t['Umacron'] = 722;
  20624. t['uring'] = 500;
  20625. t['threesuperior'] = 300;
  20626. t['Ograve'] = 722;
  20627. t['Agrave'] = 611;
  20628. t['Abreve'] = 611;
  20629. t['multiply'] = 675;
  20630. t['uacute'] = 500;
  20631. t['Tcaron'] = 556;
  20632. t['partialdiff'] = 476;
  20633. t['ydieresis'] = 444;
  20634. t['Nacute'] = 667;
  20635. t['icircumflex'] = 278;
  20636. t['Ecircumflex'] = 611;
  20637. t['adieresis'] = 500;
  20638. t['edieresis'] = 444;
  20639. t['cacute'] = 444;
  20640. t['nacute'] = 500;
  20641. t['umacron'] = 500;
  20642. t['Ncaron'] = 667;
  20643. t['Iacute'] = 333;
  20644. t['plusminus'] = 675;
  20645. t['brokenbar'] = 275;
  20646. t['registered'] = 760;
  20647. t['Gbreve'] = 722;
  20648. t['Idotaccent'] = 333;
  20649. t['summation'] = 600;
  20650. t['Egrave'] = 611;
  20651. t['racute'] = 389;
  20652. t['omacron'] = 500;
  20653. t['Zacute'] = 556;
  20654. t['Zcaron'] = 556;
  20655. t['greaterequal'] = 549;
  20656. t['Eth'] = 722;
  20657. t['Ccedilla'] = 667;
  20658. t['lcommaaccent'] = 278;
  20659. t['tcaron'] = 300;
  20660. t['eogonek'] = 444;
  20661. t['Uogonek'] = 722;
  20662. t['Aacute'] = 611;
  20663. t['Adieresis'] = 611;
  20664. t['egrave'] = 444;
  20665. t['zacute'] = 389;
  20666. t['iogonek'] = 278;
  20667. t['Oacute'] = 722;
  20668. t['oacute'] = 500;
  20669. t['amacron'] = 500;
  20670. t['sacute'] = 389;
  20671. t['idieresis'] = 278;
  20672. t['Ocircumflex'] = 722;
  20673. t['Ugrave'] = 722;
  20674. t['Delta'] = 612;
  20675. t['thorn'] = 500;
  20676. t['twosuperior'] = 300;
  20677. t['Odieresis'] = 722;
  20678. t['mu'] = 500;
  20679. t['igrave'] = 278;
  20680. t['ohungarumlaut'] = 500;
  20681. t['Eogonek'] = 611;
  20682. t['dcroat'] = 500;
  20683. t['threequarters'] = 750;
  20684. t['Scedilla'] = 500;
  20685. t['lcaron'] = 300;
  20686. t['Kcommaaccent'] = 667;
  20687. t['Lacute'] = 556;
  20688. t['trademark'] = 980;
  20689. t['edotaccent'] = 444;
  20690. t['Igrave'] = 333;
  20691. t['Imacron'] = 333;
  20692. t['Lcaron'] = 611;
  20693. t['onehalf'] = 750;
  20694. t['lessequal'] = 549;
  20695. t['ocircumflex'] = 500;
  20696. t['ntilde'] = 500;
  20697. t['Uhungarumlaut'] = 722;
  20698. t['Eacute'] = 611;
  20699. t['emacron'] = 444;
  20700. t['gbreve'] = 500;
  20701. t['onequarter'] = 750;
  20702. t['Scaron'] = 500;
  20703. t['Scommaaccent'] = 500;
  20704. t['Ohungarumlaut'] = 722;
  20705. t['degree'] = 400;
  20706. t['ograve'] = 500;
  20707. t['Ccaron'] = 667;
  20708. t['ugrave'] = 500;
  20709. t['radical'] = 453;
  20710. t['Dcaron'] = 722;
  20711. t['rcommaaccent'] = 389;
  20712. t['Ntilde'] = 667;
  20713. t['otilde'] = 500;
  20714. t['Rcommaaccent'] = 611;
  20715. t['Lcommaaccent'] = 556;
  20716. t['Atilde'] = 611;
  20717. t['Aogonek'] = 611;
  20718. t['Aring'] = 611;
  20719. t['Otilde'] = 722;
  20720. t['zdotaccent'] = 389;
  20721. t['Ecaron'] = 611;
  20722. t['Iogonek'] = 333;
  20723. t['kcommaaccent'] = 444;
  20724. t['minus'] = 675;
  20725. t['Icircumflex'] = 333;
  20726. t['ncaron'] = 500;
  20727. t['tcommaaccent'] = 278;
  20728. t['logicalnot'] = 675;
  20729. t['odieresis'] = 500;
  20730. t['udieresis'] = 500;
  20731. t['notequal'] = 549;
  20732. t['gcommaaccent'] = 500;
  20733. t['eth'] = 500;
  20734. t['zcaron'] = 389;
  20735. t['ncommaaccent'] = 500;
  20736. t['onesuperior'] = 300;
  20737. t['imacron'] = 278;
  20738. t['Euro'] = 500;
  20739. });
  20740. t['ZapfDingbats'] = getLookupTableFactory(function (t) {
  20741. t['space'] = 278;
  20742. t['a1'] = 974;
  20743. t['a2'] = 961;
  20744. t['a202'] = 974;
  20745. t['a3'] = 980;
  20746. t['a4'] = 719;
  20747. t['a5'] = 789;
  20748. t['a119'] = 790;
  20749. t['a118'] = 791;
  20750. t['a117'] = 690;
  20751. t['a11'] = 960;
  20752. t['a12'] = 939;
  20753. t['a13'] = 549;
  20754. t['a14'] = 855;
  20755. t['a15'] = 911;
  20756. t['a16'] = 933;
  20757. t['a105'] = 911;
  20758. t['a17'] = 945;
  20759. t['a18'] = 974;
  20760. t['a19'] = 755;
  20761. t['a20'] = 846;
  20762. t['a21'] = 762;
  20763. t['a22'] = 761;
  20764. t['a23'] = 571;
  20765. t['a24'] = 677;
  20766. t['a25'] = 763;
  20767. t['a26'] = 760;
  20768. t['a27'] = 759;
  20769. t['a28'] = 754;
  20770. t['a6'] = 494;
  20771. t['a7'] = 552;
  20772. t['a8'] = 537;
  20773. t['a9'] = 577;
  20774. t['a10'] = 692;
  20775. t['a29'] = 786;
  20776. t['a30'] = 788;
  20777. t['a31'] = 788;
  20778. t['a32'] = 790;
  20779. t['a33'] = 793;
  20780. t['a34'] = 794;
  20781. t['a35'] = 816;
  20782. t['a36'] = 823;
  20783. t['a37'] = 789;
  20784. t['a38'] = 841;
  20785. t['a39'] = 823;
  20786. t['a40'] = 833;
  20787. t['a41'] = 816;
  20788. t['a42'] = 831;
  20789. t['a43'] = 923;
  20790. t['a44'] = 744;
  20791. t['a45'] = 723;
  20792. t['a46'] = 749;
  20793. t['a47'] = 790;
  20794. t['a48'] = 792;
  20795. t['a49'] = 695;
  20796. t['a50'] = 776;
  20797. t['a51'] = 768;
  20798. t['a52'] = 792;
  20799. t['a53'] = 759;
  20800. t['a54'] = 707;
  20801. t['a55'] = 708;
  20802. t['a56'] = 682;
  20803. t['a57'] = 701;
  20804. t['a58'] = 826;
  20805. t['a59'] = 815;
  20806. t['a60'] = 789;
  20807. t['a61'] = 789;
  20808. t['a62'] = 707;
  20809. t['a63'] = 687;
  20810. t['a64'] = 696;
  20811. t['a65'] = 689;
  20812. t['a66'] = 786;
  20813. t['a67'] = 787;
  20814. t['a68'] = 713;
  20815. t['a69'] = 791;
  20816. t['a70'] = 785;
  20817. t['a71'] = 791;
  20818. t['a72'] = 873;
  20819. t['a73'] = 761;
  20820. t['a74'] = 762;
  20821. t['a203'] = 762;
  20822. t['a75'] = 759;
  20823. t['a204'] = 759;
  20824. t['a76'] = 892;
  20825. t['a77'] = 892;
  20826. t['a78'] = 788;
  20827. t['a79'] = 784;
  20828. t['a81'] = 438;
  20829. t['a82'] = 138;
  20830. t['a83'] = 277;
  20831. t['a84'] = 415;
  20832. t['a97'] = 392;
  20833. t['a98'] = 392;
  20834. t['a99'] = 668;
  20835. t['a100'] = 668;
  20836. t['a89'] = 390;
  20837. t['a90'] = 390;
  20838. t['a93'] = 317;
  20839. t['a94'] = 317;
  20840. t['a91'] = 276;
  20841. t['a92'] = 276;
  20842. t['a205'] = 509;
  20843. t['a85'] = 509;
  20844. t['a206'] = 410;
  20845. t['a86'] = 410;
  20846. t['a87'] = 234;
  20847. t['a88'] = 234;
  20848. t['a95'] = 334;
  20849. t['a96'] = 334;
  20850. t['a101'] = 732;
  20851. t['a102'] = 544;
  20852. t['a103'] = 544;
  20853. t['a104'] = 910;
  20854. t['a106'] = 667;
  20855. t['a107'] = 760;
  20856. t['a108'] = 760;
  20857. t['a112'] = 776;
  20858. t['a111'] = 595;
  20859. t['a110'] = 694;
  20860. t['a109'] = 626;
  20861. t['a120'] = 788;
  20862. t['a121'] = 788;
  20863. t['a122'] = 788;
  20864. t['a123'] = 788;
  20865. t['a124'] = 788;
  20866. t['a125'] = 788;
  20867. t['a126'] = 788;
  20868. t['a127'] = 788;
  20869. t['a128'] = 788;
  20870. t['a129'] = 788;
  20871. t['a130'] = 788;
  20872. t['a131'] = 788;
  20873. t['a132'] = 788;
  20874. t['a133'] = 788;
  20875. t['a134'] = 788;
  20876. t['a135'] = 788;
  20877. t['a136'] = 788;
  20878. t['a137'] = 788;
  20879. t['a138'] = 788;
  20880. t['a139'] = 788;
  20881. t['a140'] = 788;
  20882. t['a141'] = 788;
  20883. t['a142'] = 788;
  20884. t['a143'] = 788;
  20885. t['a144'] = 788;
  20886. t['a145'] = 788;
  20887. t['a146'] = 788;
  20888. t['a147'] = 788;
  20889. t['a148'] = 788;
  20890. t['a149'] = 788;
  20891. t['a150'] = 788;
  20892. t['a151'] = 788;
  20893. t['a152'] = 788;
  20894. t['a153'] = 788;
  20895. t['a154'] = 788;
  20896. t['a155'] = 788;
  20897. t['a156'] = 788;
  20898. t['a157'] = 788;
  20899. t['a158'] = 788;
  20900. t['a159'] = 788;
  20901. t['a160'] = 894;
  20902. t['a161'] = 838;
  20903. t['a163'] = 1016;
  20904. t['a164'] = 458;
  20905. t['a196'] = 748;
  20906. t['a165'] = 924;
  20907. t['a192'] = 748;
  20908. t['a166'] = 918;
  20909. t['a167'] = 927;
  20910. t['a168'] = 928;
  20911. t['a169'] = 928;
  20912. t['a170'] = 834;
  20913. t['a171'] = 873;
  20914. t['a172'] = 828;
  20915. t['a173'] = 924;
  20916. t['a162'] = 924;
  20917. t['a174'] = 917;
  20918. t['a175'] = 930;
  20919. t['a176'] = 931;
  20920. t['a177'] = 463;
  20921. t['a178'] = 883;
  20922. t['a179'] = 836;
  20923. t['a193'] = 836;
  20924. t['a180'] = 867;
  20925. t['a199'] = 867;
  20926. t['a181'] = 696;
  20927. t['a200'] = 696;
  20928. t['a182'] = 874;
  20929. t['a201'] = 874;
  20930. t['a183'] = 760;
  20931. t['a184'] = 946;
  20932. t['a197'] = 771;
  20933. t['a185'] = 865;
  20934. t['a194'] = 771;
  20935. t['a198'] = 888;
  20936. t['a186'] = 967;
  20937. t['a195'] = 888;
  20938. t['a187'] = 831;
  20939. t['a188'] = 873;
  20940. t['a189'] = 927;
  20941. t['a190'] = 970;
  20942. t['a191'] = 918;
  20943. });
  20944. });
  20945. exports.getMetrics = getMetrics;
  20946. }));
  20947. (function (root, factory) {
  20948. factory(root.pdfjsCoreMurmurHash3 = {}, root.pdfjsSharedUtil);
  20949. }(this, function (exports, sharedUtil) {
  20950. var Uint32ArrayView = sharedUtil.Uint32ArrayView;
  20951. var MurmurHash3_64 = function MurmurHash3_64Closure(seed) {
  20952. // Workaround for missing math precision in JS.
  20953. var MASK_HIGH = 0xffff0000;
  20954. var MASK_LOW = 0xffff;
  20955. function MurmurHash3_64(seed) {
  20956. var SEED = 0xc3d2e1f0;
  20957. this.h1 = seed ? seed & 0xffffffff : SEED;
  20958. this.h2 = seed ? seed & 0xffffffff : SEED;
  20959. }
  20960. var alwaysUseUint32ArrayView = false;
  20961. // old webkits have issues with non-aligned arrays
  20962. try {
  20963. new Uint32Array(new Uint8Array(5).buffer, 0, 1);
  20964. } catch (e) {
  20965. alwaysUseUint32ArrayView = true;
  20966. }
  20967. MurmurHash3_64.prototype = {
  20968. update: function MurmurHash3_64_update(input) {
  20969. var useUint32ArrayView = alwaysUseUint32ArrayView;
  20970. var i;
  20971. if (typeof input === 'string') {
  20972. var data = new Uint8Array(input.length * 2);
  20973. var length = 0;
  20974. for (i = 0; i < input.length; i++) {
  20975. var code = input.charCodeAt(i);
  20976. if (code <= 0xff) {
  20977. data[length++] = code;
  20978. } else {
  20979. data[length++] = code >>> 8;
  20980. data[length++] = code & 0xff;
  20981. }
  20982. }
  20983. } else if (input instanceof Uint8Array) {
  20984. data = input;
  20985. length = data.length;
  20986. } else if (typeof input === 'object' && 'length' in input) {
  20987. // processing regular arrays as well, e.g. for IE9
  20988. data = input;
  20989. length = data.length;
  20990. useUint32ArrayView = true;
  20991. } else {
  20992. throw new Error('Wrong data format in MurmurHash3_64_update. ' + 'Input must be a string or array.');
  20993. }
  20994. var blockCounts = length >> 2;
  20995. var tailLength = length - blockCounts * 4;
  20996. // we don't care about endianness here
  20997. var dataUint32 = useUint32ArrayView ? new Uint32ArrayView(data, blockCounts) : new Uint32Array(data.buffer, 0, blockCounts);
  20998. var k1 = 0;
  20999. var k2 = 0;
  21000. var h1 = this.h1;
  21001. var h2 = this.h2;
  21002. var C1 = 0xcc9e2d51;
  21003. var C2 = 0x1b873593;
  21004. var C1_LOW = C1 & MASK_LOW;
  21005. var C2_LOW = C2 & MASK_LOW;
  21006. for (i = 0; i < blockCounts; i++) {
  21007. if (i & 1) {
  21008. k1 = dataUint32[i];
  21009. k1 = k1 * C1 & MASK_HIGH | k1 * C1_LOW & MASK_LOW;
  21010. k1 = k1 << 15 | k1 >>> 17;
  21011. k1 = k1 * C2 & MASK_HIGH | k1 * C2_LOW & MASK_LOW;
  21012. h1 ^= k1;
  21013. h1 = h1 << 13 | h1 >>> 19;
  21014. h1 = h1 * 5 + 0xe6546b64;
  21015. } else {
  21016. k2 = dataUint32[i];
  21017. k2 = k2 * C1 & MASK_HIGH | k2 * C1_LOW & MASK_LOW;
  21018. k2 = k2 << 15 | k2 >>> 17;
  21019. k2 = k2 * C2 & MASK_HIGH | k2 * C2_LOW & MASK_LOW;
  21020. h2 ^= k2;
  21021. h2 = h2 << 13 | h2 >>> 19;
  21022. h2 = h2 * 5 + 0xe6546b64;
  21023. }
  21024. }
  21025. k1 = 0;
  21026. switch (tailLength) {
  21027. case 3:
  21028. k1 ^= data[blockCounts * 4 + 2] << 16;
  21029. case 2:
  21030. k1 ^= data[blockCounts * 4 + 1] << 8;
  21031. case 1:
  21032. k1 ^= data[blockCounts * 4];
  21033. k1 = k1 * C1 & MASK_HIGH | k1 * C1_LOW & MASK_LOW;
  21034. k1 = k1 << 15 | k1 >>> 17;
  21035. k1 = k1 * C2 & MASK_HIGH | k1 * C2_LOW & MASK_LOW;
  21036. if (blockCounts & 1) {
  21037. h1 ^= k1;
  21038. } else {
  21039. h2 ^= k1;
  21040. }
  21041. }
  21042. this.h1 = h1;
  21043. this.h2 = h2;
  21044. return this;
  21045. },
  21046. hexdigest: function MurmurHash3_64_hexdigest() {
  21047. var h1 = this.h1;
  21048. var h2 = this.h2;
  21049. h1 ^= h2 >>> 1;
  21050. h1 = h1 * 0xed558ccd & MASK_HIGH | h1 * 0x8ccd & MASK_LOW;
  21051. h2 = h2 * 0xff51afd7 & MASK_HIGH | ((h2 << 16 | h1 >>> 16) * 0xafd7ed55 & MASK_HIGH) >>> 16;
  21052. h1 ^= h2 >>> 1;
  21053. h1 = h1 * 0x1a85ec53 & MASK_HIGH | h1 * 0xec53 & MASK_LOW;
  21054. h2 = h2 * 0xc4ceb9fe & MASK_HIGH | ((h2 << 16 | h1 >>> 16) * 0xb9fe1a85 & MASK_HIGH) >>> 16;
  21055. h1 ^= h2 >>> 1;
  21056. for (var i = 0, arr = [
  21057. h1,
  21058. h2
  21059. ], str = ''; i < arr.length; i++) {
  21060. var hex = (arr[i] >>> 0).toString(16);
  21061. while (hex.length < 8) {
  21062. hex = '0' + hex;
  21063. }
  21064. str += hex;
  21065. }
  21066. return str;
  21067. }
  21068. };
  21069. return MurmurHash3_64;
  21070. }();
  21071. exports.MurmurHash3_64 = MurmurHash3_64;
  21072. }));
  21073. (function (root, factory) {
  21074. factory(root.pdfjsCorePrimitives = {}, root.pdfjsSharedUtil);
  21075. }(this, function (exports, sharedUtil) {
  21076. var isArray = sharedUtil.isArray;
  21077. var Name = function NameClosure() {
  21078. function Name(name) {
  21079. this.name = name;
  21080. }
  21081. Name.prototype = {};
  21082. var nameCache = Object.create(null);
  21083. Name.get = function Name_get(name) {
  21084. var nameValue = nameCache[name];
  21085. return nameValue ? nameValue : nameCache[name] = new Name(name);
  21086. };
  21087. return Name;
  21088. }();
  21089. var Cmd = function CmdClosure() {
  21090. function Cmd(cmd) {
  21091. this.cmd = cmd;
  21092. }
  21093. Cmd.prototype = {};
  21094. var cmdCache = Object.create(null);
  21095. Cmd.get = function Cmd_get(cmd) {
  21096. var cmdValue = cmdCache[cmd];
  21097. return cmdValue ? cmdValue : cmdCache[cmd] = new Cmd(cmd);
  21098. };
  21099. return Cmd;
  21100. }();
  21101. var Dict = function DictClosure() {
  21102. var nonSerializable = function nonSerializableClosure() {
  21103. return nonSerializable;
  21104. };
  21105. // creating closure on some variable
  21106. // xref is optional
  21107. function Dict(xref) {
  21108. // Map should only be used internally, use functions below to access.
  21109. this.map = Object.create(null);
  21110. this.xref = xref;
  21111. this.objId = null;
  21112. this.suppressEncryption = false;
  21113. this.__nonSerializable__ = nonSerializable;
  21114. }
  21115. // disable cloning of the Dict
  21116. Dict.prototype = {
  21117. assignXref: function Dict_assignXref(newXref) {
  21118. this.xref = newXref;
  21119. },
  21120. // automatically dereferences Ref objects
  21121. get: function Dict_get(key1, key2, key3) {
  21122. var value;
  21123. var xref = this.xref, suppressEncryption = this.suppressEncryption;
  21124. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map || typeof key2 === 'undefined') {
  21125. return xref ? xref.fetchIfRef(value, suppressEncryption) : value;
  21126. }
  21127. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map || typeof key3 === 'undefined') {
  21128. return xref ? xref.fetchIfRef(value, suppressEncryption) : value;
  21129. }
  21130. value = this.map[key3] || null;
  21131. return xref ? xref.fetchIfRef(value, suppressEncryption) : value;
  21132. },
  21133. // Same as get(), but returns a promise and uses fetchIfRefAsync().
  21134. getAsync: function Dict_getAsync(key1, key2, key3) {
  21135. var value;
  21136. var xref = this.xref, suppressEncryption = this.suppressEncryption;
  21137. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map || typeof key2 === 'undefined') {
  21138. if (xref) {
  21139. return xref.fetchIfRefAsync(value, suppressEncryption);
  21140. }
  21141. return Promise.resolve(value);
  21142. }
  21143. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map || typeof key3 === 'undefined') {
  21144. if (xref) {
  21145. return xref.fetchIfRefAsync(value, suppressEncryption);
  21146. }
  21147. return Promise.resolve(value);
  21148. }
  21149. value = this.map[key3] || null;
  21150. if (xref) {
  21151. return xref.fetchIfRefAsync(value, suppressEncryption);
  21152. }
  21153. return Promise.resolve(value);
  21154. },
  21155. // Same as get(), but dereferences all elements if the result is an Array.
  21156. getArray: function Dict_getArray(key1, key2, key3) {
  21157. var value = this.get(key1, key2, key3);
  21158. var xref = this.xref, suppressEncryption = this.suppressEncryption;
  21159. if (!isArray(value) || !xref) {
  21160. return value;
  21161. }
  21162. value = value.slice();
  21163. // Ensure that we don't modify the Dict data.
  21164. for (var i = 0, ii = value.length; i < ii; i++) {
  21165. if (!isRef(value[i])) {
  21166. continue;
  21167. }
  21168. value[i] = xref.fetch(value[i], suppressEncryption);
  21169. }
  21170. return value;
  21171. },
  21172. // no dereferencing
  21173. getRaw: function Dict_getRaw(key) {
  21174. return this.map[key];
  21175. },
  21176. getKeys: function Dict_getKeys() {
  21177. return Object.keys(this.map);
  21178. },
  21179. set: function Dict_set(key, value) {
  21180. this.map[key] = value;
  21181. },
  21182. has: function Dict_has(key) {
  21183. return key in this.map;
  21184. },
  21185. forEach: function Dict_forEach(callback) {
  21186. for (var key in this.map) {
  21187. callback(key, this.get(key));
  21188. }
  21189. }
  21190. };
  21191. Dict.empty = new Dict(null);
  21192. Dict.merge = function Dict_merge(xref, dictArray) {
  21193. var mergedDict = new Dict(xref);
  21194. for (var i = 0, ii = dictArray.length; i < ii; i++) {
  21195. var dict = dictArray[i];
  21196. if (!isDict(dict)) {
  21197. continue;
  21198. }
  21199. for (var keyName in dict.map) {
  21200. if (mergedDict.map[keyName]) {
  21201. continue;
  21202. }
  21203. mergedDict.map[keyName] = dict.map[keyName];
  21204. }
  21205. }
  21206. return mergedDict;
  21207. };
  21208. return Dict;
  21209. }();
  21210. var Ref = function RefClosure() {
  21211. function Ref(num, gen) {
  21212. this.num = num;
  21213. this.gen = gen;
  21214. }
  21215. Ref.prototype = {
  21216. toString: function Ref_toString() {
  21217. // This function is hot, so we make the string as compact as possible.
  21218. // |this.gen| is almost always zero, so we treat that case specially.
  21219. var str = this.num + 'R';
  21220. if (this.gen !== 0) {
  21221. str += this.gen;
  21222. }
  21223. return str;
  21224. }
  21225. };
  21226. return Ref;
  21227. }();
  21228. // The reference is identified by number and generation.
  21229. // This structure stores only one instance of the reference.
  21230. var RefSet = function RefSetClosure() {
  21231. function RefSet() {
  21232. this.dict = Object.create(null);
  21233. }
  21234. RefSet.prototype = {
  21235. has: function RefSet_has(ref) {
  21236. return ref.toString() in this.dict;
  21237. },
  21238. put: function RefSet_put(ref) {
  21239. this.dict[ref.toString()] = true;
  21240. },
  21241. remove: function RefSet_remove(ref) {
  21242. delete this.dict[ref.toString()];
  21243. }
  21244. };
  21245. return RefSet;
  21246. }();
  21247. var RefSetCache = function RefSetCacheClosure() {
  21248. function RefSetCache() {
  21249. this.dict = Object.create(null);
  21250. }
  21251. RefSetCache.prototype = {
  21252. get: function RefSetCache_get(ref) {
  21253. return this.dict[ref.toString()];
  21254. },
  21255. has: function RefSetCache_has(ref) {
  21256. return ref.toString() in this.dict;
  21257. },
  21258. put: function RefSetCache_put(ref, obj) {
  21259. this.dict[ref.toString()] = obj;
  21260. },
  21261. putAlias: function RefSetCache_putAlias(ref, aliasRef) {
  21262. this.dict[ref.toString()] = this.get(aliasRef);
  21263. },
  21264. forEach: function RefSetCache_forEach(fn, thisArg) {
  21265. for (var i in this.dict) {
  21266. fn.call(thisArg, this.dict[i]);
  21267. }
  21268. },
  21269. clear: function RefSetCache_clear() {
  21270. this.dict = Object.create(null);
  21271. }
  21272. };
  21273. return RefSetCache;
  21274. }();
  21275. function isName(v, name) {
  21276. return v instanceof Name && (name === undefined || v.name === name);
  21277. }
  21278. function isCmd(v, cmd) {
  21279. return v instanceof Cmd && (cmd === undefined || v.cmd === cmd);
  21280. }
  21281. function isDict(v, type) {
  21282. return v instanceof Dict && (type === undefined || isName(v.get('Type'), type));
  21283. }
  21284. function isRef(v) {
  21285. return v instanceof Ref;
  21286. }
  21287. function isRefsEqual(v1, v2) {
  21288. return v1.num === v2.num && v1.gen === v2.gen;
  21289. }
  21290. function isStream(v) {
  21291. return typeof v === 'object' && v !== null && v.getBytes !== undefined;
  21292. }
  21293. exports.Cmd = Cmd;
  21294. exports.Dict = Dict;
  21295. exports.Name = Name;
  21296. exports.Ref = Ref;
  21297. exports.RefSet = RefSet;
  21298. exports.RefSetCache = RefSetCache;
  21299. exports.isCmd = isCmd;
  21300. exports.isDict = isDict;
  21301. exports.isName = isName;
  21302. exports.isRef = isRef;
  21303. exports.isRefsEqual = isRefsEqual;
  21304. exports.isStream = isStream;
  21305. }));
  21306. (function (root, factory) {
  21307. factory(root.pdfjsCoreStandardFonts = {}, root.pdfjsSharedUtil);
  21308. }(this, function (exports, sharedUtil) {
  21309. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  21310. /**
  21311. * Hold a map of decoded fonts and of the standard fourteen Type1
  21312. * fonts and their acronyms.
  21313. */
  21314. var getStdFontMap = getLookupTableFactory(function (t) {
  21315. t['ArialNarrow'] = 'Helvetica';
  21316. t['ArialNarrow-Bold'] = 'Helvetica-Bold';
  21317. t['ArialNarrow-BoldItalic'] = 'Helvetica-BoldOblique';
  21318. t['ArialNarrow-Italic'] = 'Helvetica-Oblique';
  21319. t['ArialBlack'] = 'Helvetica';
  21320. t['ArialBlack-Bold'] = 'Helvetica-Bold';
  21321. t['ArialBlack-BoldItalic'] = 'Helvetica-BoldOblique';
  21322. t['ArialBlack-Italic'] = 'Helvetica-Oblique';
  21323. t['Arial'] = 'Helvetica';
  21324. t['Arial-Bold'] = 'Helvetica-Bold';
  21325. t['Arial-BoldItalic'] = 'Helvetica-BoldOblique';
  21326. t['Arial-Italic'] = 'Helvetica-Oblique';
  21327. t['Arial-BoldItalicMT'] = 'Helvetica-BoldOblique';
  21328. t['Arial-BoldMT'] = 'Helvetica-Bold';
  21329. t['Arial-ItalicMT'] = 'Helvetica-Oblique';
  21330. t['ArialMT'] = 'Helvetica';
  21331. t['Courier-Bold'] = 'Courier-Bold';
  21332. t['Courier-BoldItalic'] = 'Courier-BoldOblique';
  21333. t['Courier-Italic'] = 'Courier-Oblique';
  21334. t['CourierNew'] = 'Courier';
  21335. t['CourierNew-Bold'] = 'Courier-Bold';
  21336. t['CourierNew-BoldItalic'] = 'Courier-BoldOblique';
  21337. t['CourierNew-Italic'] = 'Courier-Oblique';
  21338. t['CourierNewPS-BoldItalicMT'] = 'Courier-BoldOblique';
  21339. t['CourierNewPS-BoldMT'] = 'Courier-Bold';
  21340. t['CourierNewPS-ItalicMT'] = 'Courier-Oblique';
  21341. t['CourierNewPSMT'] = 'Courier';
  21342. t['Helvetica'] = 'Helvetica';
  21343. t['Helvetica-Bold'] = 'Helvetica-Bold';
  21344. t['Helvetica-BoldItalic'] = 'Helvetica-BoldOblique';
  21345. t['Helvetica-BoldOblique'] = 'Helvetica-BoldOblique';
  21346. t['Helvetica-Italic'] = 'Helvetica-Oblique';
  21347. t['Helvetica-Oblique'] = 'Helvetica-Oblique';
  21348. t['Symbol-Bold'] = 'Symbol';
  21349. t['Symbol-BoldItalic'] = 'Symbol';
  21350. t['Symbol-Italic'] = 'Symbol';
  21351. t['TimesNewRoman'] = 'Times-Roman';
  21352. t['TimesNewRoman-Bold'] = 'Times-Bold';
  21353. t['TimesNewRoman-BoldItalic'] = 'Times-BoldItalic';
  21354. t['TimesNewRoman-Italic'] = 'Times-Italic';
  21355. t['TimesNewRomanPS'] = 'Times-Roman';
  21356. t['TimesNewRomanPS-Bold'] = 'Times-Bold';
  21357. t['TimesNewRomanPS-BoldItalic'] = 'Times-BoldItalic';
  21358. t['TimesNewRomanPS-BoldItalicMT'] = 'Times-BoldItalic';
  21359. t['TimesNewRomanPS-BoldMT'] = 'Times-Bold';
  21360. t['TimesNewRomanPS-Italic'] = 'Times-Italic';
  21361. t['TimesNewRomanPS-ItalicMT'] = 'Times-Italic';
  21362. t['TimesNewRomanPSMT'] = 'Times-Roman';
  21363. t['TimesNewRomanPSMT-Bold'] = 'Times-Bold';
  21364. t['TimesNewRomanPSMT-BoldItalic'] = 'Times-BoldItalic';
  21365. t['TimesNewRomanPSMT-Italic'] = 'Times-Italic';
  21366. });
  21367. /**
  21368. * Holds the map of the non-standard fonts that might be included as
  21369. * a standard fonts without glyph data.
  21370. */
  21371. var getNonStdFontMap = getLookupTableFactory(function (t) {
  21372. t['CenturyGothic'] = 'Helvetica';
  21373. t['CenturyGothic-Bold'] = 'Helvetica-Bold';
  21374. t['CenturyGothic-BoldItalic'] = 'Helvetica-BoldOblique';
  21375. t['CenturyGothic-Italic'] = 'Helvetica-Oblique';
  21376. t['ComicSansMS'] = 'Comic Sans MS';
  21377. t['ComicSansMS-Bold'] = 'Comic Sans MS-Bold';
  21378. t['ComicSansMS-BoldItalic'] = 'Comic Sans MS-BoldItalic';
  21379. t['ComicSansMS-Italic'] = 'Comic Sans MS-Italic';
  21380. t['LucidaConsole'] = 'Courier';
  21381. t['LucidaConsole-Bold'] = 'Courier-Bold';
  21382. t['LucidaConsole-BoldItalic'] = 'Courier-BoldOblique';
  21383. t['LucidaConsole-Italic'] = 'Courier-Oblique';
  21384. t['MS-Gothic'] = 'MS Gothic';
  21385. t['MS-Gothic-Bold'] = 'MS Gothic-Bold';
  21386. t['MS-Gothic-BoldItalic'] = 'MS Gothic-BoldItalic';
  21387. t['MS-Gothic-Italic'] = 'MS Gothic-Italic';
  21388. t['MS-Mincho'] = 'MS Mincho';
  21389. t['MS-Mincho-Bold'] = 'MS Mincho-Bold';
  21390. t['MS-Mincho-BoldItalic'] = 'MS Mincho-BoldItalic';
  21391. t['MS-Mincho-Italic'] = 'MS Mincho-Italic';
  21392. t['MS-PGothic'] = 'MS PGothic';
  21393. t['MS-PGothic-Bold'] = 'MS PGothic-Bold';
  21394. t['MS-PGothic-BoldItalic'] = 'MS PGothic-BoldItalic';
  21395. t['MS-PGothic-Italic'] = 'MS PGothic-Italic';
  21396. t['MS-PMincho'] = 'MS PMincho';
  21397. t['MS-PMincho-Bold'] = 'MS PMincho-Bold';
  21398. t['MS-PMincho-BoldItalic'] = 'MS PMincho-BoldItalic';
  21399. t['MS-PMincho-Italic'] = 'MS PMincho-Italic';
  21400. t['Wingdings'] = 'ZapfDingbats';
  21401. });
  21402. var getSerifFonts = getLookupTableFactory(function (t) {
  21403. t['Adobe Jenson'] = true;
  21404. t['Adobe Text'] = true;
  21405. t['Albertus'] = true;
  21406. t['Aldus'] = true;
  21407. t['Alexandria'] = true;
  21408. t['Algerian'] = true;
  21409. t['American Typewriter'] = true;
  21410. t['Antiqua'] = true;
  21411. t['Apex'] = true;
  21412. t['Arno'] = true;
  21413. t['Aster'] = true;
  21414. t['Aurora'] = true;
  21415. t['Baskerville'] = true;
  21416. t['Bell'] = true;
  21417. t['Bembo'] = true;
  21418. t['Bembo Schoolbook'] = true;
  21419. t['Benguiat'] = true;
  21420. t['Berkeley Old Style'] = true;
  21421. t['Bernhard Modern'] = true;
  21422. t['Berthold City'] = true;
  21423. t['Bodoni'] = true;
  21424. t['Bauer Bodoni'] = true;
  21425. t['Book Antiqua'] = true;
  21426. t['Bookman'] = true;
  21427. t['Bordeaux Roman'] = true;
  21428. t['Californian FB'] = true;
  21429. t['Calisto'] = true;
  21430. t['Calvert'] = true;
  21431. t['Capitals'] = true;
  21432. t['Cambria'] = true;
  21433. t['Cartier'] = true;
  21434. t['Caslon'] = true;
  21435. t['Catull'] = true;
  21436. t['Centaur'] = true;
  21437. t['Century Old Style'] = true;
  21438. t['Century Schoolbook'] = true;
  21439. t['Chaparral'] = true;
  21440. t['Charis SIL'] = true;
  21441. t['Cheltenham'] = true;
  21442. t['Cholla Slab'] = true;
  21443. t['Clarendon'] = true;
  21444. t['Clearface'] = true;
  21445. t['Cochin'] = true;
  21446. t['Colonna'] = true;
  21447. t['Computer Modern'] = true;
  21448. t['Concrete Roman'] = true;
  21449. t['Constantia'] = true;
  21450. t['Cooper Black'] = true;
  21451. t['Corona'] = true;
  21452. t['Ecotype'] = true;
  21453. t['Egyptienne'] = true;
  21454. t['Elephant'] = true;
  21455. t['Excelsior'] = true;
  21456. t['Fairfield'] = true;
  21457. t['FF Scala'] = true;
  21458. t['Folkard'] = true;
  21459. t['Footlight'] = true;
  21460. t['FreeSerif'] = true;
  21461. t['Friz Quadrata'] = true;
  21462. t['Garamond'] = true;
  21463. t['Gentium'] = true;
  21464. t['Georgia'] = true;
  21465. t['Gloucester'] = true;
  21466. t['Goudy Old Style'] = true;
  21467. t['Goudy Schoolbook'] = true;
  21468. t['Goudy Pro Font'] = true;
  21469. t['Granjon'] = true;
  21470. t['Guardian Egyptian'] = true;
  21471. t['Heather'] = true;
  21472. t['Hercules'] = true;
  21473. t['High Tower Text'] = true;
  21474. t['Hiroshige'] = true;
  21475. t['Hoefler Text'] = true;
  21476. t['Humana Serif'] = true;
  21477. t['Imprint'] = true;
  21478. t['Ionic No. 5'] = true;
  21479. t['Janson'] = true;
  21480. t['Joanna'] = true;
  21481. t['Korinna'] = true;
  21482. t['Lexicon'] = true;
  21483. t['Liberation Serif'] = true;
  21484. t['Linux Libertine'] = true;
  21485. t['Literaturnaya'] = true;
  21486. t['Lucida'] = true;
  21487. t['Lucida Bright'] = true;
  21488. t['Melior'] = true;
  21489. t['Memphis'] = true;
  21490. t['Miller'] = true;
  21491. t['Minion'] = true;
  21492. t['Modern'] = true;
  21493. t['Mona Lisa'] = true;
  21494. t['Mrs Eaves'] = true;
  21495. t['MS Serif'] = true;
  21496. t['Museo Slab'] = true;
  21497. t['New York'] = true;
  21498. t['Nimbus Roman'] = true;
  21499. t['NPS Rawlinson Roadway'] = true;
  21500. t['Palatino'] = true;
  21501. t['Perpetua'] = true;
  21502. t['Plantin'] = true;
  21503. t['Plantin Schoolbook'] = true;
  21504. t['Playbill'] = true;
  21505. t['Poor Richard'] = true;
  21506. t['Rawlinson Roadway'] = true;
  21507. t['Renault'] = true;
  21508. t['Requiem'] = true;
  21509. t['Rockwell'] = true;
  21510. t['Roman'] = true;
  21511. t['Rotis Serif'] = true;
  21512. t['Sabon'] = true;
  21513. t['Scala'] = true;
  21514. t['Seagull'] = true;
  21515. t['Sistina'] = true;
  21516. t['Souvenir'] = true;
  21517. t['STIX'] = true;
  21518. t['Stone Informal'] = true;
  21519. t['Stone Serif'] = true;
  21520. t['Sylfaen'] = true;
  21521. t['Times'] = true;
  21522. t['Trajan'] = true;
  21523. t['Trinité'] = true;
  21524. t['Trump Mediaeval'] = true;
  21525. t['Utopia'] = true;
  21526. t['Vale Type'] = true;
  21527. t['Bitstream Vera'] = true;
  21528. t['Vera Serif'] = true;
  21529. t['Versailles'] = true;
  21530. t['Wanted'] = true;
  21531. t['Weiss'] = true;
  21532. t['Wide Latin'] = true;
  21533. t['Windsor'] = true;
  21534. t['XITS'] = true;
  21535. });
  21536. var getSymbolsFonts = getLookupTableFactory(function (t) {
  21537. t['Dingbats'] = true;
  21538. t['Symbol'] = true;
  21539. t['ZapfDingbats'] = true;
  21540. });
  21541. // Glyph map for well-known standard fonts. Sometimes Ghostscript uses CID
  21542. // fonts, but does not embed the CID to GID mapping. The mapping is incomplete
  21543. // for all glyphs, but common for some set of the standard fonts.
  21544. var getGlyphMapForStandardFonts = getLookupTableFactory(function (t) {
  21545. t[2] = 10;
  21546. t[3] = 32;
  21547. t[4] = 33;
  21548. t[5] = 34;
  21549. t[6] = 35;
  21550. t[7] = 36;
  21551. t[8] = 37;
  21552. t[9] = 38;
  21553. t[10] = 39;
  21554. t[11] = 40;
  21555. t[12] = 41;
  21556. t[13] = 42;
  21557. t[14] = 43;
  21558. t[15] = 44;
  21559. t[16] = 45;
  21560. t[17] = 46;
  21561. t[18] = 47;
  21562. t[19] = 48;
  21563. t[20] = 49;
  21564. t[21] = 50;
  21565. t[22] = 51;
  21566. t[23] = 52;
  21567. t[24] = 53;
  21568. t[25] = 54;
  21569. t[26] = 55;
  21570. t[27] = 56;
  21571. t[28] = 57;
  21572. t[29] = 58;
  21573. t[30] = 894;
  21574. t[31] = 60;
  21575. t[32] = 61;
  21576. t[33] = 62;
  21577. t[34] = 63;
  21578. t[35] = 64;
  21579. t[36] = 65;
  21580. t[37] = 66;
  21581. t[38] = 67;
  21582. t[39] = 68;
  21583. t[40] = 69;
  21584. t[41] = 70;
  21585. t[42] = 71;
  21586. t[43] = 72;
  21587. t[44] = 73;
  21588. t[45] = 74;
  21589. t[46] = 75;
  21590. t[47] = 76;
  21591. t[48] = 77;
  21592. t[49] = 78;
  21593. t[50] = 79;
  21594. t[51] = 80;
  21595. t[52] = 81;
  21596. t[53] = 82;
  21597. t[54] = 83;
  21598. t[55] = 84;
  21599. t[56] = 85;
  21600. t[57] = 86;
  21601. t[58] = 87;
  21602. t[59] = 88;
  21603. t[60] = 89;
  21604. t[61] = 90;
  21605. t[62] = 91;
  21606. t[63] = 92;
  21607. t[64] = 93;
  21608. t[65] = 94;
  21609. t[66] = 95;
  21610. t[67] = 96;
  21611. t[68] = 97;
  21612. t[69] = 98;
  21613. t[70] = 99;
  21614. t[71] = 100;
  21615. t[72] = 101;
  21616. t[73] = 102;
  21617. t[74] = 103;
  21618. t[75] = 104;
  21619. t[76] = 105;
  21620. t[77] = 106;
  21621. t[78] = 107;
  21622. t[79] = 108;
  21623. t[80] = 109;
  21624. t[81] = 110;
  21625. t[82] = 111;
  21626. t[83] = 112;
  21627. t[84] = 113;
  21628. t[85] = 114;
  21629. t[86] = 115;
  21630. t[87] = 116;
  21631. t[88] = 117;
  21632. t[89] = 118;
  21633. t[90] = 119;
  21634. t[91] = 120;
  21635. t[92] = 121;
  21636. t[93] = 122;
  21637. t[94] = 123;
  21638. t[95] = 124;
  21639. t[96] = 125;
  21640. t[97] = 126;
  21641. t[98] = 196;
  21642. t[99] = 197;
  21643. t[100] = 199;
  21644. t[101] = 201;
  21645. t[102] = 209;
  21646. t[103] = 214;
  21647. t[104] = 220;
  21648. t[105] = 225;
  21649. t[106] = 224;
  21650. t[107] = 226;
  21651. t[108] = 228;
  21652. t[109] = 227;
  21653. t[110] = 229;
  21654. t[111] = 231;
  21655. t[112] = 233;
  21656. t[113] = 232;
  21657. t[114] = 234;
  21658. t[115] = 235;
  21659. t[116] = 237;
  21660. t[117] = 236;
  21661. t[118] = 238;
  21662. t[119] = 239;
  21663. t[120] = 241;
  21664. t[121] = 243;
  21665. t[122] = 242;
  21666. t[123] = 244;
  21667. t[124] = 246;
  21668. t[125] = 245;
  21669. t[126] = 250;
  21670. t[127] = 249;
  21671. t[128] = 251;
  21672. t[129] = 252;
  21673. t[130] = 8224;
  21674. t[131] = 176;
  21675. t[132] = 162;
  21676. t[133] = 163;
  21677. t[134] = 167;
  21678. t[135] = 8226;
  21679. t[136] = 182;
  21680. t[137] = 223;
  21681. t[138] = 174;
  21682. t[139] = 169;
  21683. t[140] = 8482;
  21684. t[141] = 180;
  21685. t[142] = 168;
  21686. t[143] = 8800;
  21687. t[144] = 198;
  21688. t[145] = 216;
  21689. t[146] = 8734;
  21690. t[147] = 177;
  21691. t[148] = 8804;
  21692. t[149] = 8805;
  21693. t[150] = 165;
  21694. t[151] = 181;
  21695. t[152] = 8706;
  21696. t[153] = 8721;
  21697. t[154] = 8719;
  21698. t[156] = 8747;
  21699. t[157] = 170;
  21700. t[158] = 186;
  21701. t[159] = 8486;
  21702. t[160] = 230;
  21703. t[161] = 248;
  21704. t[162] = 191;
  21705. t[163] = 161;
  21706. t[164] = 172;
  21707. t[165] = 8730;
  21708. t[166] = 402;
  21709. t[167] = 8776;
  21710. t[168] = 8710;
  21711. t[169] = 171;
  21712. t[170] = 187;
  21713. t[171] = 8230;
  21714. t[210] = 218;
  21715. t[223] = 711;
  21716. t[224] = 321;
  21717. t[225] = 322;
  21718. t[227] = 353;
  21719. t[229] = 382;
  21720. t[234] = 253;
  21721. t[252] = 263;
  21722. t[253] = 268;
  21723. t[254] = 269;
  21724. t[258] = 258;
  21725. t[260] = 260;
  21726. t[261] = 261;
  21727. t[265] = 280;
  21728. t[266] = 281;
  21729. t[268] = 283;
  21730. t[269] = 313;
  21731. t[275] = 323;
  21732. t[276] = 324;
  21733. t[278] = 328;
  21734. t[284] = 345;
  21735. t[285] = 346;
  21736. t[286] = 347;
  21737. t[292] = 367;
  21738. t[295] = 377;
  21739. t[296] = 378;
  21740. t[298] = 380;
  21741. t[305] = 963;
  21742. t[306] = 964;
  21743. t[307] = 966;
  21744. t[308] = 8215;
  21745. t[309] = 8252;
  21746. t[310] = 8319;
  21747. t[311] = 8359;
  21748. t[312] = 8592;
  21749. t[313] = 8593;
  21750. t[337] = 9552;
  21751. t[493] = 1039;
  21752. t[494] = 1040;
  21753. t[705] = 1524;
  21754. t[706] = 8362;
  21755. t[710] = 64288;
  21756. t[711] = 64298;
  21757. t[759] = 1617;
  21758. t[761] = 1776;
  21759. t[763] = 1778;
  21760. t[775] = 1652;
  21761. t[777] = 1764;
  21762. t[778] = 1780;
  21763. t[779] = 1781;
  21764. t[780] = 1782;
  21765. t[782] = 771;
  21766. t[783] = 64726;
  21767. t[786] = 8363;
  21768. t[788] = 8532;
  21769. t[790] = 768;
  21770. t[791] = 769;
  21771. t[792] = 768;
  21772. t[795] = 803;
  21773. t[797] = 64336;
  21774. t[798] = 64337;
  21775. t[799] = 64342;
  21776. t[800] = 64343;
  21777. t[801] = 64344;
  21778. t[802] = 64345;
  21779. t[803] = 64362;
  21780. t[804] = 64363;
  21781. t[805] = 64364;
  21782. t[2424] = 7821;
  21783. t[2425] = 7822;
  21784. t[2426] = 7823;
  21785. t[2427] = 7824;
  21786. t[2428] = 7825;
  21787. t[2429] = 7826;
  21788. t[2430] = 7827;
  21789. t[2433] = 7682;
  21790. t[2678] = 8045;
  21791. t[2679] = 8046;
  21792. t[2830] = 1552;
  21793. t[2838] = 686;
  21794. t[2840] = 751;
  21795. t[2842] = 753;
  21796. t[2843] = 754;
  21797. t[2844] = 755;
  21798. t[2846] = 757;
  21799. t[2856] = 767;
  21800. t[2857] = 848;
  21801. t[2858] = 849;
  21802. t[2862] = 853;
  21803. t[2863] = 854;
  21804. t[2864] = 855;
  21805. t[2865] = 861;
  21806. t[2866] = 862;
  21807. t[2906] = 7460;
  21808. t[2908] = 7462;
  21809. t[2909] = 7463;
  21810. t[2910] = 7464;
  21811. t[2912] = 7466;
  21812. t[2913] = 7467;
  21813. t[2914] = 7468;
  21814. t[2916] = 7470;
  21815. t[2917] = 7471;
  21816. t[2918] = 7472;
  21817. t[2920] = 7474;
  21818. t[2921] = 7475;
  21819. t[2922] = 7476;
  21820. t[2924] = 7478;
  21821. t[2925] = 7479;
  21822. t[2926] = 7480;
  21823. t[2928] = 7482;
  21824. t[2929] = 7483;
  21825. t[2930] = 7484;
  21826. t[2932] = 7486;
  21827. t[2933] = 7487;
  21828. t[2934] = 7488;
  21829. t[2936] = 7490;
  21830. t[2937] = 7491;
  21831. t[2938] = 7492;
  21832. t[2940] = 7494;
  21833. t[2941] = 7495;
  21834. t[2942] = 7496;
  21835. t[2944] = 7498;
  21836. t[2946] = 7500;
  21837. t[2948] = 7502;
  21838. t[2950] = 7504;
  21839. t[2951] = 7505;
  21840. t[2952] = 7506;
  21841. t[2954] = 7508;
  21842. t[2955] = 7509;
  21843. t[2956] = 7510;
  21844. t[2958] = 7512;
  21845. t[2959] = 7513;
  21846. t[2960] = 7514;
  21847. t[2962] = 7516;
  21848. t[2963] = 7517;
  21849. t[2964] = 7518;
  21850. t[2966] = 7520;
  21851. t[2967] = 7521;
  21852. t[2968] = 7522;
  21853. t[2970] = 7524;
  21854. t[2971] = 7525;
  21855. t[2972] = 7526;
  21856. t[2974] = 7528;
  21857. t[2975] = 7529;
  21858. t[2976] = 7530;
  21859. t[2978] = 1537;
  21860. t[2979] = 1538;
  21861. t[2980] = 1539;
  21862. t[2982] = 1549;
  21863. t[2983] = 1551;
  21864. t[2984] = 1552;
  21865. t[2986] = 1554;
  21866. t[2987] = 1555;
  21867. t[2988] = 1556;
  21868. t[2990] = 1623;
  21869. t[2991] = 1624;
  21870. t[2995] = 1775;
  21871. t[2999] = 1791;
  21872. t[3002] = 64290;
  21873. t[3003] = 64291;
  21874. t[3004] = 64292;
  21875. t[3006] = 64294;
  21876. t[3007] = 64295;
  21877. t[3008] = 64296;
  21878. t[3011] = 1900;
  21879. t[3014] = 8223;
  21880. t[3015] = 8244;
  21881. t[3017] = 7532;
  21882. t[3018] = 7533;
  21883. t[3019] = 7534;
  21884. t[3075] = 7590;
  21885. t[3076] = 7591;
  21886. t[3079] = 7594;
  21887. t[3080] = 7595;
  21888. t[3083] = 7598;
  21889. t[3084] = 7599;
  21890. t[3087] = 7602;
  21891. t[3088] = 7603;
  21892. t[3091] = 7606;
  21893. t[3092] = 7607;
  21894. t[3095] = 7610;
  21895. t[3096] = 7611;
  21896. t[3099] = 7614;
  21897. t[3100] = 7615;
  21898. t[3103] = 7618;
  21899. t[3104] = 7619;
  21900. t[3107] = 8337;
  21901. t[3108] = 8338;
  21902. t[3116] = 1884;
  21903. t[3119] = 1885;
  21904. t[3120] = 1885;
  21905. t[3123] = 1886;
  21906. t[3124] = 1886;
  21907. t[3127] = 1887;
  21908. t[3128] = 1887;
  21909. t[3131] = 1888;
  21910. t[3132] = 1888;
  21911. t[3135] = 1889;
  21912. t[3136] = 1889;
  21913. t[3139] = 1890;
  21914. t[3140] = 1890;
  21915. t[3143] = 1891;
  21916. t[3144] = 1891;
  21917. t[3147] = 1892;
  21918. t[3148] = 1892;
  21919. t[3153] = 580;
  21920. t[3154] = 581;
  21921. t[3157] = 584;
  21922. t[3158] = 585;
  21923. t[3161] = 588;
  21924. t[3162] = 589;
  21925. t[3165] = 891;
  21926. t[3166] = 892;
  21927. t[3169] = 1274;
  21928. t[3170] = 1275;
  21929. t[3173] = 1278;
  21930. t[3174] = 1279;
  21931. t[3181] = 7622;
  21932. t[3182] = 7623;
  21933. t[3282] = 11799;
  21934. t[3316] = 578;
  21935. t[3379] = 42785;
  21936. t[3393] = 1159;
  21937. t[3416] = 8377;
  21938. });
  21939. // The glyph map for ArialBlack differs slightly from the glyph map used for
  21940. // other well-known standard fonts. Hence we use this (incomplete) CID to GID
  21941. // mapping to adjust the glyph map for non-embedded ArialBlack fonts.
  21942. var getSupplementalGlyphMapForArialBlack = getLookupTableFactory(function (t) {
  21943. t[227] = 322;
  21944. t[264] = 261;
  21945. t[291] = 346;
  21946. });
  21947. exports.getStdFontMap = getStdFontMap;
  21948. exports.getNonStdFontMap = getNonStdFontMap;
  21949. exports.getSerifFonts = getSerifFonts;
  21950. exports.getSymbolsFonts = getSymbolsFonts;
  21951. exports.getGlyphMapForStandardFonts = getGlyphMapForStandardFonts;
  21952. exports.getSupplementalGlyphMapForArialBlack = getSupplementalGlyphMapForArialBlack;
  21953. }));
  21954. (function (root, factory) {
  21955. factory(root.pdfjsCoreUnicode = {}, root.pdfjsSharedUtil);
  21956. }(this, function (exports, sharedUtil) {
  21957. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  21958. // Some characters, e.g. copyrightserif, are mapped to the private use area
  21959. // and might not be displayed using standard fonts. Mapping/hacking well-known
  21960. // chars to the similar equivalents in the normal characters range.
  21961. var getSpecialPUASymbols = getLookupTableFactory(function (t) {
  21962. t[63721] = 0x00A9;
  21963. // copyrightsans (0xF8E9) => copyright
  21964. t[63193] = 0x00A9;
  21965. // copyrightserif (0xF6D9) => copyright
  21966. t[63720] = 0x00AE;
  21967. // registersans (0xF8E8) => registered
  21968. t[63194] = 0x00AE;
  21969. // registerserif (0xF6DA) => registered
  21970. t[63722] = 0x2122;
  21971. // trademarksans (0xF8EA) => trademark
  21972. t[63195] = 0x2122;
  21973. // trademarkserif (0xF6DB) => trademark
  21974. t[63729] = 0x23A7;
  21975. // bracelefttp (0xF8F1)
  21976. t[63730] = 0x23A8;
  21977. // braceleftmid (0xF8F2)
  21978. t[63731] = 0x23A9;
  21979. // braceleftbt (0xF8F3)
  21980. t[63740] = 0x23AB;
  21981. // bracerighttp (0xF8FC)
  21982. t[63741] = 0x23AC;
  21983. // bracerightmid (0xF8FD)
  21984. t[63742] = 0x23AD;
  21985. // bracerightbt (0xF8FE)
  21986. t[63726] = 0x23A1;
  21987. // bracketlefttp (0xF8EE)
  21988. t[63727] = 0x23A2;
  21989. // bracketleftex (0xF8EF)
  21990. t[63728] = 0x23A3;
  21991. // bracketleftbt (0xF8F0)
  21992. t[63737] = 0x23A4;
  21993. // bracketrighttp (0xF8F9)
  21994. t[63738] = 0x23A5;
  21995. // bracketrightex (0xF8FA)
  21996. t[63739] = 0x23A6;
  21997. // bracketrightbt (0xF8FB)
  21998. t[63723] = 0x239B;
  21999. // parenlefttp (0xF8EB)
  22000. t[63724] = 0x239C;
  22001. // parenleftex (0xF8EC)
  22002. t[63725] = 0x239D;
  22003. // parenleftbt (0xF8ED)
  22004. t[63734] = 0x239E;
  22005. // parenrighttp (0xF8F6)
  22006. t[63735] = 0x239F;
  22007. // parenrightex (0xF8F7)
  22008. t[63736] = 0x23A0;
  22009. });
  22010. // parenrightbt (0xF8F8)
  22011. function mapSpecialUnicodeValues(code) {
  22012. if (code >= 0xFFF0 && code <= 0xFFFF) {
  22013. // Specials unicode block.
  22014. return 0;
  22015. } else if (code >= 0xF600 && code <= 0xF8FF) {
  22016. return getSpecialPUASymbols()[code] || code;
  22017. }
  22018. return code;
  22019. }
  22020. function getUnicodeForGlyph(name, glyphsUnicodeMap) {
  22021. var unicode = glyphsUnicodeMap[name];
  22022. if (unicode !== undefined) {
  22023. return unicode;
  22024. }
  22025. if (!name) {
  22026. return -1;
  22027. }
  22028. // Try to recover valid Unicode values from 'uniXXXX'/'uXXXX{XX}' glyphs.
  22029. if (name[0] === 'u') {
  22030. var nameLen = name.length, hexStr;
  22031. if (nameLen === 7 && name[1] === 'n' && name[2] === 'i') {
  22032. // 'uniXXXX'
  22033. hexStr = name.substr(3);
  22034. } else if (nameLen >= 5 && nameLen <= 7) {
  22035. // 'uXXXX{XX}'
  22036. hexStr = name.substr(1);
  22037. } else {
  22038. return -1;
  22039. }
  22040. // Check for upper-case hexadecimal characters, to avoid false positives.
  22041. if (hexStr === hexStr.toUpperCase()) {
  22042. unicode = parseInt(hexStr, 16);
  22043. if (unicode >= 0) {
  22044. return unicode;
  22045. }
  22046. }
  22047. }
  22048. return -1;
  22049. }
  22050. var UnicodeRanges = [
  22051. {
  22052. 'begin': 0x0000,
  22053. 'end': 0x007F
  22054. },
  22055. // Basic Latin
  22056. {
  22057. 'begin': 0x0080,
  22058. 'end': 0x00FF
  22059. },
  22060. // Latin-1 Supplement
  22061. {
  22062. 'begin': 0x0100,
  22063. 'end': 0x017F
  22064. },
  22065. // Latin Extended-A
  22066. {
  22067. 'begin': 0x0180,
  22068. 'end': 0x024F
  22069. },
  22070. // Latin Extended-B
  22071. {
  22072. 'begin': 0x0250,
  22073. 'end': 0x02AF
  22074. },
  22075. // IPA Extensions
  22076. {
  22077. 'begin': 0x02B0,
  22078. 'end': 0x02FF
  22079. },
  22080. // Spacing Modifier Letters
  22081. {
  22082. 'begin': 0x0300,
  22083. 'end': 0x036F
  22084. },
  22085. // Combining Diacritical Marks
  22086. {
  22087. 'begin': 0x0370,
  22088. 'end': 0x03FF
  22089. },
  22090. // Greek and Coptic
  22091. {
  22092. 'begin': 0x2C80,
  22093. 'end': 0x2CFF
  22094. },
  22095. // Coptic
  22096. {
  22097. 'begin': 0x0400,
  22098. 'end': 0x04FF
  22099. },
  22100. // Cyrillic
  22101. {
  22102. 'begin': 0x0530,
  22103. 'end': 0x058F
  22104. },
  22105. // Armenian
  22106. {
  22107. 'begin': 0x0590,
  22108. 'end': 0x05FF
  22109. },
  22110. // Hebrew
  22111. {
  22112. 'begin': 0xA500,
  22113. 'end': 0xA63F
  22114. },
  22115. // Vai
  22116. {
  22117. 'begin': 0x0600,
  22118. 'end': 0x06FF
  22119. },
  22120. // Arabic
  22121. {
  22122. 'begin': 0x07C0,
  22123. 'end': 0x07FF
  22124. },
  22125. // NKo
  22126. {
  22127. 'begin': 0x0900,
  22128. 'end': 0x097F
  22129. },
  22130. // Devanagari
  22131. {
  22132. 'begin': 0x0980,
  22133. 'end': 0x09FF
  22134. },
  22135. // Bengali
  22136. {
  22137. 'begin': 0x0A00,
  22138. 'end': 0x0A7F
  22139. },
  22140. // Gurmukhi
  22141. {
  22142. 'begin': 0x0A80,
  22143. 'end': 0x0AFF
  22144. },
  22145. // Gujarati
  22146. {
  22147. 'begin': 0x0B00,
  22148. 'end': 0x0B7F
  22149. },
  22150. // Oriya
  22151. {
  22152. 'begin': 0x0B80,
  22153. 'end': 0x0BFF
  22154. },
  22155. // Tamil
  22156. {
  22157. 'begin': 0x0C00,
  22158. 'end': 0x0C7F
  22159. },
  22160. // Telugu
  22161. {
  22162. 'begin': 0x0C80,
  22163. 'end': 0x0CFF
  22164. },
  22165. // Kannada
  22166. {
  22167. 'begin': 0x0D00,
  22168. 'end': 0x0D7F
  22169. },
  22170. // Malayalam
  22171. {
  22172. 'begin': 0x0E00,
  22173. 'end': 0x0E7F
  22174. },
  22175. // Thai
  22176. {
  22177. 'begin': 0x0E80,
  22178. 'end': 0x0EFF
  22179. },
  22180. // Lao
  22181. {
  22182. 'begin': 0x10A0,
  22183. 'end': 0x10FF
  22184. },
  22185. // Georgian
  22186. {
  22187. 'begin': 0x1B00,
  22188. 'end': 0x1B7F
  22189. },
  22190. // Balinese
  22191. {
  22192. 'begin': 0x1100,
  22193. 'end': 0x11FF
  22194. },
  22195. // Hangul Jamo
  22196. {
  22197. 'begin': 0x1E00,
  22198. 'end': 0x1EFF
  22199. },
  22200. // Latin Extended Additional
  22201. {
  22202. 'begin': 0x1F00,
  22203. 'end': 0x1FFF
  22204. },
  22205. // Greek Extended
  22206. {
  22207. 'begin': 0x2000,
  22208. 'end': 0x206F
  22209. },
  22210. // General Punctuation
  22211. {
  22212. 'begin': 0x2070,
  22213. 'end': 0x209F
  22214. },
  22215. // Superscripts And Subscripts
  22216. {
  22217. 'begin': 0x20A0,
  22218. 'end': 0x20CF
  22219. },
  22220. // Currency Symbol
  22221. {
  22222. 'begin': 0x20D0,
  22223. 'end': 0x20FF
  22224. },
  22225. // Combining Diacritical Marks
  22226. {
  22227. 'begin': 0x2100,
  22228. 'end': 0x214F
  22229. },
  22230. // Letterlike Symbols
  22231. {
  22232. 'begin': 0x2150,
  22233. 'end': 0x218F
  22234. },
  22235. // Number Forms
  22236. {
  22237. 'begin': 0x2190,
  22238. 'end': 0x21FF
  22239. },
  22240. // Arrows
  22241. {
  22242. 'begin': 0x2200,
  22243. 'end': 0x22FF
  22244. },
  22245. // Mathematical Operators
  22246. {
  22247. 'begin': 0x2300,
  22248. 'end': 0x23FF
  22249. },
  22250. // Miscellaneous Technical
  22251. {
  22252. 'begin': 0x2400,
  22253. 'end': 0x243F
  22254. },
  22255. // Control Pictures
  22256. {
  22257. 'begin': 0x2440,
  22258. 'end': 0x245F
  22259. },
  22260. // Optical Character Recognition
  22261. {
  22262. 'begin': 0x2460,
  22263. 'end': 0x24FF
  22264. },
  22265. // Enclosed Alphanumerics
  22266. {
  22267. 'begin': 0x2500,
  22268. 'end': 0x257F
  22269. },
  22270. // Box Drawing
  22271. {
  22272. 'begin': 0x2580,
  22273. 'end': 0x259F
  22274. },
  22275. // Block Elements
  22276. {
  22277. 'begin': 0x25A0,
  22278. 'end': 0x25FF
  22279. },
  22280. // Geometric Shapes
  22281. {
  22282. 'begin': 0x2600,
  22283. 'end': 0x26FF
  22284. },
  22285. // Miscellaneous Symbols
  22286. {
  22287. 'begin': 0x2700,
  22288. 'end': 0x27BF
  22289. },
  22290. // Dingbats
  22291. {
  22292. 'begin': 0x3000,
  22293. 'end': 0x303F
  22294. },
  22295. // CJK Symbols And Punctuation
  22296. {
  22297. 'begin': 0x3040,
  22298. 'end': 0x309F
  22299. },
  22300. // Hiragana
  22301. {
  22302. 'begin': 0x30A0,
  22303. 'end': 0x30FF
  22304. },
  22305. // Katakana
  22306. {
  22307. 'begin': 0x3100,
  22308. 'end': 0x312F
  22309. },
  22310. // Bopomofo
  22311. {
  22312. 'begin': 0x3130,
  22313. 'end': 0x318F
  22314. },
  22315. // Hangul Compatibility Jamo
  22316. {
  22317. 'begin': 0xA840,
  22318. 'end': 0xA87F
  22319. },
  22320. // Phags-pa
  22321. {
  22322. 'begin': 0x3200,
  22323. 'end': 0x32FF
  22324. },
  22325. // Enclosed CJK Letters And Months
  22326. {
  22327. 'begin': 0x3300,
  22328. 'end': 0x33FF
  22329. },
  22330. // CJK Compatibility
  22331. {
  22332. 'begin': 0xAC00,
  22333. 'end': 0xD7AF
  22334. },
  22335. // Hangul Syllables
  22336. {
  22337. 'begin': 0xD800,
  22338. 'end': 0xDFFF
  22339. },
  22340. // Non-Plane 0 *
  22341. {
  22342. 'begin': 0x10900,
  22343. 'end': 0x1091F
  22344. },
  22345. // Phoenicia
  22346. {
  22347. 'begin': 0x4E00,
  22348. 'end': 0x9FFF
  22349. },
  22350. // CJK Unified Ideographs
  22351. {
  22352. 'begin': 0xE000,
  22353. 'end': 0xF8FF
  22354. },
  22355. // Private Use Area (plane 0)
  22356. {
  22357. 'begin': 0x31C0,
  22358. 'end': 0x31EF
  22359. },
  22360. // CJK Strokes
  22361. {
  22362. 'begin': 0xFB00,
  22363. 'end': 0xFB4F
  22364. },
  22365. // Alphabetic Presentation Forms
  22366. {
  22367. 'begin': 0xFB50,
  22368. 'end': 0xFDFF
  22369. },
  22370. // Arabic Presentation Forms-A
  22371. {
  22372. 'begin': 0xFE20,
  22373. 'end': 0xFE2F
  22374. },
  22375. // Combining Half Marks
  22376. {
  22377. 'begin': 0xFE10,
  22378. 'end': 0xFE1F
  22379. },
  22380. // Vertical Forms
  22381. {
  22382. 'begin': 0xFE50,
  22383. 'end': 0xFE6F
  22384. },
  22385. // Small Form Variants
  22386. {
  22387. 'begin': 0xFE70,
  22388. 'end': 0xFEFF
  22389. },
  22390. // Arabic Presentation Forms-B
  22391. {
  22392. 'begin': 0xFF00,
  22393. 'end': 0xFFEF
  22394. },
  22395. // Halfwidth And Fullwidth Forms
  22396. {
  22397. 'begin': 0xFFF0,
  22398. 'end': 0xFFFF
  22399. },
  22400. // Specials
  22401. {
  22402. 'begin': 0x0F00,
  22403. 'end': 0x0FFF
  22404. },
  22405. // Tibetan
  22406. {
  22407. 'begin': 0x0700,
  22408. 'end': 0x074F
  22409. },
  22410. // Syriac
  22411. {
  22412. 'begin': 0x0780,
  22413. 'end': 0x07BF
  22414. },
  22415. // Thaana
  22416. {
  22417. 'begin': 0x0D80,
  22418. 'end': 0x0DFF
  22419. },
  22420. // Sinhala
  22421. {
  22422. 'begin': 0x1000,
  22423. 'end': 0x109F
  22424. },
  22425. // Myanmar
  22426. {
  22427. 'begin': 0x1200,
  22428. 'end': 0x137F
  22429. },
  22430. // Ethiopic
  22431. {
  22432. 'begin': 0x13A0,
  22433. 'end': 0x13FF
  22434. },
  22435. // Cherokee
  22436. {
  22437. 'begin': 0x1400,
  22438. 'end': 0x167F
  22439. },
  22440. // Unified Canadian Aboriginal Syllabics
  22441. {
  22442. 'begin': 0x1680,
  22443. 'end': 0x169F
  22444. },
  22445. // Ogham
  22446. {
  22447. 'begin': 0x16A0,
  22448. 'end': 0x16FF
  22449. },
  22450. // Runic
  22451. {
  22452. 'begin': 0x1780,
  22453. 'end': 0x17FF
  22454. },
  22455. // Khmer
  22456. {
  22457. 'begin': 0x1800,
  22458. 'end': 0x18AF
  22459. },
  22460. // Mongolian
  22461. {
  22462. 'begin': 0x2800,
  22463. 'end': 0x28FF
  22464. },
  22465. // Braille Patterns
  22466. {
  22467. 'begin': 0xA000,
  22468. 'end': 0xA48F
  22469. },
  22470. // Yi Syllables
  22471. {
  22472. 'begin': 0x1700,
  22473. 'end': 0x171F
  22474. },
  22475. // Tagalog
  22476. {
  22477. 'begin': 0x10300,
  22478. 'end': 0x1032F
  22479. },
  22480. // Old Italic
  22481. {
  22482. 'begin': 0x10330,
  22483. 'end': 0x1034F
  22484. },
  22485. // Gothic
  22486. {
  22487. 'begin': 0x10400,
  22488. 'end': 0x1044F
  22489. },
  22490. // Deseret
  22491. {
  22492. 'begin': 0x1D000,
  22493. 'end': 0x1D0FF
  22494. },
  22495. // Byzantine Musical Symbols
  22496. {
  22497. 'begin': 0x1D400,
  22498. 'end': 0x1D7FF
  22499. },
  22500. // Mathematical Alphanumeric Symbols
  22501. {
  22502. 'begin': 0xFF000,
  22503. 'end': 0xFFFFD
  22504. },
  22505. // Private Use (plane 15)
  22506. {
  22507. 'begin': 0xFE00,
  22508. 'end': 0xFE0F
  22509. },
  22510. // Variation Selectors
  22511. {
  22512. 'begin': 0xE0000,
  22513. 'end': 0xE007F
  22514. },
  22515. // Tags
  22516. {
  22517. 'begin': 0x1900,
  22518. 'end': 0x194F
  22519. },
  22520. // Limbu
  22521. {
  22522. 'begin': 0x1950,
  22523. 'end': 0x197F
  22524. },
  22525. // Tai Le
  22526. {
  22527. 'begin': 0x1980,
  22528. 'end': 0x19DF
  22529. },
  22530. // New Tai Lue
  22531. {
  22532. 'begin': 0x1A00,
  22533. 'end': 0x1A1F
  22534. },
  22535. // Buginese
  22536. {
  22537. 'begin': 0x2C00,
  22538. 'end': 0x2C5F
  22539. },
  22540. // Glagolitic
  22541. {
  22542. 'begin': 0x2D30,
  22543. 'end': 0x2D7F
  22544. },
  22545. // Tifinagh
  22546. {
  22547. 'begin': 0x4DC0,
  22548. 'end': 0x4DFF
  22549. },
  22550. // Yijing Hexagram Symbols
  22551. {
  22552. 'begin': 0xA800,
  22553. 'end': 0xA82F
  22554. },
  22555. // Syloti Nagri
  22556. {
  22557. 'begin': 0x10000,
  22558. 'end': 0x1007F
  22559. },
  22560. // Linear B Syllabary
  22561. {
  22562. 'begin': 0x10140,
  22563. 'end': 0x1018F
  22564. },
  22565. // Ancient Greek Numbers
  22566. {
  22567. 'begin': 0x10380,
  22568. 'end': 0x1039F
  22569. },
  22570. // Ugaritic
  22571. {
  22572. 'begin': 0x103A0,
  22573. 'end': 0x103DF
  22574. },
  22575. // Old Persian
  22576. {
  22577. 'begin': 0x10450,
  22578. 'end': 0x1047F
  22579. },
  22580. // Shavian
  22581. {
  22582. 'begin': 0x10480,
  22583. 'end': 0x104AF
  22584. },
  22585. // Osmanya
  22586. {
  22587. 'begin': 0x10800,
  22588. 'end': 0x1083F
  22589. },
  22590. // Cypriot Syllabary
  22591. {
  22592. 'begin': 0x10A00,
  22593. 'end': 0x10A5F
  22594. },
  22595. // Kharoshthi
  22596. {
  22597. 'begin': 0x1D300,
  22598. 'end': 0x1D35F
  22599. },
  22600. // Tai Xuan Jing Symbols
  22601. {
  22602. 'begin': 0x12000,
  22603. 'end': 0x123FF
  22604. },
  22605. // Cuneiform
  22606. {
  22607. 'begin': 0x1D360,
  22608. 'end': 0x1D37F
  22609. },
  22610. // Counting Rod Numerals
  22611. {
  22612. 'begin': 0x1B80,
  22613. 'end': 0x1BBF
  22614. },
  22615. // Sundanese
  22616. {
  22617. 'begin': 0x1C00,
  22618. 'end': 0x1C4F
  22619. },
  22620. // Lepcha
  22621. {
  22622. 'begin': 0x1C50,
  22623. 'end': 0x1C7F
  22624. },
  22625. // Ol Chiki
  22626. {
  22627. 'begin': 0xA880,
  22628. 'end': 0xA8DF
  22629. },
  22630. // Saurashtra
  22631. {
  22632. 'begin': 0xA900,
  22633. 'end': 0xA92F
  22634. },
  22635. // Kayah Li
  22636. {
  22637. 'begin': 0xA930,
  22638. 'end': 0xA95F
  22639. },
  22640. // Rejang
  22641. {
  22642. 'begin': 0xAA00,
  22643. 'end': 0xAA5F
  22644. },
  22645. // Cham
  22646. {
  22647. 'begin': 0x10190,
  22648. 'end': 0x101CF
  22649. },
  22650. // Ancient Symbols
  22651. {
  22652. 'begin': 0x101D0,
  22653. 'end': 0x101FF
  22654. },
  22655. // Phaistos Disc
  22656. {
  22657. 'begin': 0x102A0,
  22658. 'end': 0x102DF
  22659. },
  22660. // Carian
  22661. {
  22662. 'begin': 0x1F030,
  22663. 'end': 0x1F09F
  22664. }
  22665. ];
  22666. // Domino Tiles
  22667. function getUnicodeRangeFor(value) {
  22668. for (var i = 0, ii = UnicodeRanges.length; i < ii; i++) {
  22669. var range = UnicodeRanges[i];
  22670. if (value >= range.begin && value < range.end) {
  22671. return i;
  22672. }
  22673. }
  22674. return -1;
  22675. }
  22676. function isRTLRangeFor(value) {
  22677. var range = UnicodeRanges[13];
  22678. if (value >= range.begin && value < range.end) {
  22679. return true;
  22680. }
  22681. range = UnicodeRanges[11];
  22682. if (value >= range.begin && value < range.end) {
  22683. return true;
  22684. }
  22685. return false;
  22686. }
  22687. // The normalization table is obtained by filtering the Unicode characters
  22688. // database with <compat> entries.
  22689. var getNormalizedUnicodes = getLookupTableFactory(function (t) {
  22690. t['\u00A8'] = '\u0020\u0308';
  22691. t['\u00AF'] = '\u0020\u0304';
  22692. t['\u00B4'] = '\u0020\u0301';
  22693. t['\u00B5'] = '\u03BC';
  22694. t['\u00B8'] = '\u0020\u0327';
  22695. t['\u0132'] = '\u0049\u004A';
  22696. t['\u0133'] = '\u0069\u006A';
  22697. t['\u013F'] = '\u004C\u00B7';
  22698. t['\u0140'] = '\u006C\u00B7';
  22699. t['\u0149'] = '\u02BC\u006E';
  22700. t['\u017F'] = '\u0073';
  22701. t['\u01C4'] = '\u0044\u017D';
  22702. t['\u01C5'] = '\u0044\u017E';
  22703. t['\u01C6'] = '\u0064\u017E';
  22704. t['\u01C7'] = '\u004C\u004A';
  22705. t['\u01C8'] = '\u004C\u006A';
  22706. t['\u01C9'] = '\u006C\u006A';
  22707. t['\u01CA'] = '\u004E\u004A';
  22708. t['\u01CB'] = '\u004E\u006A';
  22709. t['\u01CC'] = '\u006E\u006A';
  22710. t['\u01F1'] = '\u0044\u005A';
  22711. t['\u01F2'] = '\u0044\u007A';
  22712. t['\u01F3'] = '\u0064\u007A';
  22713. t['\u02D8'] = '\u0020\u0306';
  22714. t['\u02D9'] = '\u0020\u0307';
  22715. t['\u02DA'] = '\u0020\u030A';
  22716. t['\u02DB'] = '\u0020\u0328';
  22717. t['\u02DC'] = '\u0020\u0303';
  22718. t['\u02DD'] = '\u0020\u030B';
  22719. t['\u037A'] = '\u0020\u0345';
  22720. t['\u0384'] = '\u0020\u0301';
  22721. t['\u03D0'] = '\u03B2';
  22722. t['\u03D1'] = '\u03B8';
  22723. t['\u03D2'] = '\u03A5';
  22724. t['\u03D5'] = '\u03C6';
  22725. t['\u03D6'] = '\u03C0';
  22726. t['\u03F0'] = '\u03BA';
  22727. t['\u03F1'] = '\u03C1';
  22728. t['\u03F2'] = '\u03C2';
  22729. t['\u03F4'] = '\u0398';
  22730. t['\u03F5'] = '\u03B5';
  22731. t['\u03F9'] = '\u03A3';
  22732. t['\u0587'] = '\u0565\u0582';
  22733. t['\u0675'] = '\u0627\u0674';
  22734. t['\u0676'] = '\u0648\u0674';
  22735. t['\u0677'] = '\u06C7\u0674';
  22736. t['\u0678'] = '\u064A\u0674';
  22737. t['\u0E33'] = '\u0E4D\u0E32';
  22738. t['\u0EB3'] = '\u0ECD\u0EB2';
  22739. t['\u0EDC'] = '\u0EAB\u0E99';
  22740. t['\u0EDD'] = '\u0EAB\u0EA1';
  22741. t['\u0F77'] = '\u0FB2\u0F81';
  22742. t['\u0F79'] = '\u0FB3\u0F81';
  22743. t['\u1E9A'] = '\u0061\u02BE';
  22744. t['\u1FBD'] = '\u0020\u0313';
  22745. t['\u1FBF'] = '\u0020\u0313';
  22746. t['\u1FC0'] = '\u0020\u0342';
  22747. t['\u1FFE'] = '\u0020\u0314';
  22748. t['\u2002'] = '\u0020';
  22749. t['\u2003'] = '\u0020';
  22750. t['\u2004'] = '\u0020';
  22751. t['\u2005'] = '\u0020';
  22752. t['\u2006'] = '\u0020';
  22753. t['\u2008'] = '\u0020';
  22754. t['\u2009'] = '\u0020';
  22755. t['\u200A'] = '\u0020';
  22756. t['\u2017'] = '\u0020\u0333';
  22757. t['\u2024'] = '\u002E';
  22758. t['\u2025'] = '\u002E\u002E';
  22759. t['\u2026'] = '\u002E\u002E\u002E';
  22760. t['\u2033'] = '\u2032\u2032';
  22761. t['\u2034'] = '\u2032\u2032\u2032';
  22762. t['\u2036'] = '\u2035\u2035';
  22763. t['\u2037'] = '\u2035\u2035\u2035';
  22764. t['\u203C'] = '\u0021\u0021';
  22765. t['\u203E'] = '\u0020\u0305';
  22766. t['\u2047'] = '\u003F\u003F';
  22767. t['\u2048'] = '\u003F\u0021';
  22768. t['\u2049'] = '\u0021\u003F';
  22769. t['\u2057'] = '\u2032\u2032\u2032\u2032';
  22770. t['\u205F'] = '\u0020';
  22771. t['\u20A8'] = '\u0052\u0073';
  22772. t['\u2100'] = '\u0061\u002F\u0063';
  22773. t['\u2101'] = '\u0061\u002F\u0073';
  22774. t['\u2103'] = '\u00B0\u0043';
  22775. t['\u2105'] = '\u0063\u002F\u006F';
  22776. t['\u2106'] = '\u0063\u002F\u0075';
  22777. t['\u2107'] = '\u0190';
  22778. t['\u2109'] = '\u00B0\u0046';
  22779. t['\u2116'] = '\u004E\u006F';
  22780. t['\u2121'] = '\u0054\u0045\u004C';
  22781. t['\u2135'] = '\u05D0';
  22782. t['\u2136'] = '\u05D1';
  22783. t['\u2137'] = '\u05D2';
  22784. t['\u2138'] = '\u05D3';
  22785. t['\u213B'] = '\u0046\u0041\u0058';
  22786. t['\u2160'] = '\u0049';
  22787. t['\u2161'] = '\u0049\u0049';
  22788. t['\u2162'] = '\u0049\u0049\u0049';
  22789. t['\u2163'] = '\u0049\u0056';
  22790. t['\u2164'] = '\u0056';
  22791. t['\u2165'] = '\u0056\u0049';
  22792. t['\u2166'] = '\u0056\u0049\u0049';
  22793. t['\u2167'] = '\u0056\u0049\u0049\u0049';
  22794. t['\u2168'] = '\u0049\u0058';
  22795. t['\u2169'] = '\u0058';
  22796. t['\u216A'] = '\u0058\u0049';
  22797. t['\u216B'] = '\u0058\u0049\u0049';
  22798. t['\u216C'] = '\u004C';
  22799. t['\u216D'] = '\u0043';
  22800. t['\u216E'] = '\u0044';
  22801. t['\u216F'] = '\u004D';
  22802. t['\u2170'] = '\u0069';
  22803. t['\u2171'] = '\u0069\u0069';
  22804. t['\u2172'] = '\u0069\u0069\u0069';
  22805. t['\u2173'] = '\u0069\u0076';
  22806. t['\u2174'] = '\u0076';
  22807. t['\u2175'] = '\u0076\u0069';
  22808. t['\u2176'] = '\u0076\u0069\u0069';
  22809. t['\u2177'] = '\u0076\u0069\u0069\u0069';
  22810. t['\u2178'] = '\u0069\u0078';
  22811. t['\u2179'] = '\u0078';
  22812. t['\u217A'] = '\u0078\u0069';
  22813. t['\u217B'] = '\u0078\u0069\u0069';
  22814. t['\u217C'] = '\u006C';
  22815. t['\u217D'] = '\u0063';
  22816. t['\u217E'] = '\u0064';
  22817. t['\u217F'] = '\u006D';
  22818. t['\u222C'] = '\u222B\u222B';
  22819. t['\u222D'] = '\u222B\u222B\u222B';
  22820. t['\u222F'] = '\u222E\u222E';
  22821. t['\u2230'] = '\u222E\u222E\u222E';
  22822. t['\u2474'] = '\u0028\u0031\u0029';
  22823. t['\u2475'] = '\u0028\u0032\u0029';
  22824. t['\u2476'] = '\u0028\u0033\u0029';
  22825. t['\u2477'] = '\u0028\u0034\u0029';
  22826. t['\u2478'] = '\u0028\u0035\u0029';
  22827. t['\u2479'] = '\u0028\u0036\u0029';
  22828. t['\u247A'] = '\u0028\u0037\u0029';
  22829. t['\u247B'] = '\u0028\u0038\u0029';
  22830. t['\u247C'] = '\u0028\u0039\u0029';
  22831. t['\u247D'] = '\u0028\u0031\u0030\u0029';
  22832. t['\u247E'] = '\u0028\u0031\u0031\u0029';
  22833. t['\u247F'] = '\u0028\u0031\u0032\u0029';
  22834. t['\u2480'] = '\u0028\u0031\u0033\u0029';
  22835. t['\u2481'] = '\u0028\u0031\u0034\u0029';
  22836. t['\u2482'] = '\u0028\u0031\u0035\u0029';
  22837. t['\u2483'] = '\u0028\u0031\u0036\u0029';
  22838. t['\u2484'] = '\u0028\u0031\u0037\u0029';
  22839. t['\u2485'] = '\u0028\u0031\u0038\u0029';
  22840. t['\u2486'] = '\u0028\u0031\u0039\u0029';
  22841. t['\u2487'] = '\u0028\u0032\u0030\u0029';
  22842. t['\u2488'] = '\u0031\u002E';
  22843. t['\u2489'] = '\u0032\u002E';
  22844. t['\u248A'] = '\u0033\u002E';
  22845. t['\u248B'] = '\u0034\u002E';
  22846. t['\u248C'] = '\u0035\u002E';
  22847. t['\u248D'] = '\u0036\u002E';
  22848. t['\u248E'] = '\u0037\u002E';
  22849. t['\u248F'] = '\u0038\u002E';
  22850. t['\u2490'] = '\u0039\u002E';
  22851. t['\u2491'] = '\u0031\u0030\u002E';
  22852. t['\u2492'] = '\u0031\u0031\u002E';
  22853. t['\u2493'] = '\u0031\u0032\u002E';
  22854. t['\u2494'] = '\u0031\u0033\u002E';
  22855. t['\u2495'] = '\u0031\u0034\u002E';
  22856. t['\u2496'] = '\u0031\u0035\u002E';
  22857. t['\u2497'] = '\u0031\u0036\u002E';
  22858. t['\u2498'] = '\u0031\u0037\u002E';
  22859. t['\u2499'] = '\u0031\u0038\u002E';
  22860. t['\u249A'] = '\u0031\u0039\u002E';
  22861. t['\u249B'] = '\u0032\u0030\u002E';
  22862. t['\u249C'] = '\u0028\u0061\u0029';
  22863. t['\u249D'] = '\u0028\u0062\u0029';
  22864. t['\u249E'] = '\u0028\u0063\u0029';
  22865. t['\u249F'] = '\u0028\u0064\u0029';
  22866. t['\u24A0'] = '\u0028\u0065\u0029';
  22867. t['\u24A1'] = '\u0028\u0066\u0029';
  22868. t['\u24A2'] = '\u0028\u0067\u0029';
  22869. t['\u24A3'] = '\u0028\u0068\u0029';
  22870. t['\u24A4'] = '\u0028\u0069\u0029';
  22871. t['\u24A5'] = '\u0028\u006A\u0029';
  22872. t['\u24A6'] = '\u0028\u006B\u0029';
  22873. t['\u24A7'] = '\u0028\u006C\u0029';
  22874. t['\u24A8'] = '\u0028\u006D\u0029';
  22875. t['\u24A9'] = '\u0028\u006E\u0029';
  22876. t['\u24AA'] = '\u0028\u006F\u0029';
  22877. t['\u24AB'] = '\u0028\u0070\u0029';
  22878. t['\u24AC'] = '\u0028\u0071\u0029';
  22879. t['\u24AD'] = '\u0028\u0072\u0029';
  22880. t['\u24AE'] = '\u0028\u0073\u0029';
  22881. t['\u24AF'] = '\u0028\u0074\u0029';
  22882. t['\u24B0'] = '\u0028\u0075\u0029';
  22883. t['\u24B1'] = '\u0028\u0076\u0029';
  22884. t['\u24B2'] = '\u0028\u0077\u0029';
  22885. t['\u24B3'] = '\u0028\u0078\u0029';
  22886. t['\u24B4'] = '\u0028\u0079\u0029';
  22887. t['\u24B5'] = '\u0028\u007A\u0029';
  22888. t['\u2A0C'] = '\u222B\u222B\u222B\u222B';
  22889. t['\u2A74'] = '\u003A\u003A\u003D';
  22890. t['\u2A75'] = '\u003D\u003D';
  22891. t['\u2A76'] = '\u003D\u003D\u003D';
  22892. t['\u2E9F'] = '\u6BCD';
  22893. t['\u2EF3'] = '\u9F9F';
  22894. t['\u2F00'] = '\u4E00';
  22895. t['\u2F01'] = '\u4E28';
  22896. t['\u2F02'] = '\u4E36';
  22897. t['\u2F03'] = '\u4E3F';
  22898. t['\u2F04'] = '\u4E59';
  22899. t['\u2F05'] = '\u4E85';
  22900. t['\u2F06'] = '\u4E8C';
  22901. t['\u2F07'] = '\u4EA0';
  22902. t['\u2F08'] = '\u4EBA';
  22903. t['\u2F09'] = '\u513F';
  22904. t['\u2F0A'] = '\u5165';
  22905. t['\u2F0B'] = '\u516B';
  22906. t['\u2F0C'] = '\u5182';
  22907. t['\u2F0D'] = '\u5196';
  22908. t['\u2F0E'] = '\u51AB';
  22909. t['\u2F0F'] = '\u51E0';
  22910. t['\u2F10'] = '\u51F5';
  22911. t['\u2F11'] = '\u5200';
  22912. t['\u2F12'] = '\u529B';
  22913. t['\u2F13'] = '\u52F9';
  22914. t['\u2F14'] = '\u5315';
  22915. t['\u2F15'] = '\u531A';
  22916. t['\u2F16'] = '\u5338';
  22917. t['\u2F17'] = '\u5341';
  22918. t['\u2F18'] = '\u535C';
  22919. t['\u2F19'] = '\u5369';
  22920. t['\u2F1A'] = '\u5382';
  22921. t['\u2F1B'] = '\u53B6';
  22922. t['\u2F1C'] = '\u53C8';
  22923. t['\u2F1D'] = '\u53E3';
  22924. t['\u2F1E'] = '\u56D7';
  22925. t['\u2F1F'] = '\u571F';
  22926. t['\u2F20'] = '\u58EB';
  22927. t['\u2F21'] = '\u5902';
  22928. t['\u2F22'] = '\u590A';
  22929. t['\u2F23'] = '\u5915';
  22930. t['\u2F24'] = '\u5927';
  22931. t['\u2F25'] = '\u5973';
  22932. t['\u2F26'] = '\u5B50';
  22933. t['\u2F27'] = '\u5B80';
  22934. t['\u2F28'] = '\u5BF8';
  22935. t['\u2F29'] = '\u5C0F';
  22936. t['\u2F2A'] = '\u5C22';
  22937. t['\u2F2B'] = '\u5C38';
  22938. t['\u2F2C'] = '\u5C6E';
  22939. t['\u2F2D'] = '\u5C71';
  22940. t['\u2F2E'] = '\u5DDB';
  22941. t['\u2F2F'] = '\u5DE5';
  22942. t['\u2F30'] = '\u5DF1';
  22943. t['\u2F31'] = '\u5DFE';
  22944. t['\u2F32'] = '\u5E72';
  22945. t['\u2F33'] = '\u5E7A';
  22946. t['\u2F34'] = '\u5E7F';
  22947. t['\u2F35'] = '\u5EF4';
  22948. t['\u2F36'] = '\u5EFE';
  22949. t['\u2F37'] = '\u5F0B';
  22950. t['\u2F38'] = '\u5F13';
  22951. t['\u2F39'] = '\u5F50';
  22952. t['\u2F3A'] = '\u5F61';
  22953. t['\u2F3B'] = '\u5F73';
  22954. t['\u2F3C'] = '\u5FC3';
  22955. t['\u2F3D'] = '\u6208';
  22956. t['\u2F3E'] = '\u6236';
  22957. t['\u2F3F'] = '\u624B';
  22958. t['\u2F40'] = '\u652F';
  22959. t['\u2F41'] = '\u6534';
  22960. t['\u2F42'] = '\u6587';
  22961. t['\u2F43'] = '\u6597';
  22962. t['\u2F44'] = '\u65A4';
  22963. t['\u2F45'] = '\u65B9';
  22964. t['\u2F46'] = '\u65E0';
  22965. t['\u2F47'] = '\u65E5';
  22966. t['\u2F48'] = '\u66F0';
  22967. t['\u2F49'] = '\u6708';
  22968. t['\u2F4A'] = '\u6728';
  22969. t['\u2F4B'] = '\u6B20';
  22970. t['\u2F4C'] = '\u6B62';
  22971. t['\u2F4D'] = '\u6B79';
  22972. t['\u2F4E'] = '\u6BB3';
  22973. t['\u2F4F'] = '\u6BCB';
  22974. t['\u2F50'] = '\u6BD4';
  22975. t['\u2F51'] = '\u6BDB';
  22976. t['\u2F52'] = '\u6C0F';
  22977. t['\u2F53'] = '\u6C14';
  22978. t['\u2F54'] = '\u6C34';
  22979. t['\u2F55'] = '\u706B';
  22980. t['\u2F56'] = '\u722A';
  22981. t['\u2F57'] = '\u7236';
  22982. t['\u2F58'] = '\u723B';
  22983. t['\u2F59'] = '\u723F';
  22984. t['\u2F5A'] = '\u7247';
  22985. t['\u2F5B'] = '\u7259';
  22986. t['\u2F5C'] = '\u725B';
  22987. t['\u2F5D'] = '\u72AC';
  22988. t['\u2F5E'] = '\u7384';
  22989. t['\u2F5F'] = '\u7389';
  22990. t['\u2F60'] = '\u74DC';
  22991. t['\u2F61'] = '\u74E6';
  22992. t['\u2F62'] = '\u7518';
  22993. t['\u2F63'] = '\u751F';
  22994. t['\u2F64'] = '\u7528';
  22995. t['\u2F65'] = '\u7530';
  22996. t['\u2F66'] = '\u758B';
  22997. t['\u2F67'] = '\u7592';
  22998. t['\u2F68'] = '\u7676';
  22999. t['\u2F69'] = '\u767D';
  23000. t['\u2F6A'] = '\u76AE';
  23001. t['\u2F6B'] = '\u76BF';
  23002. t['\u2F6C'] = '\u76EE';
  23003. t['\u2F6D'] = '\u77DB';
  23004. t['\u2F6E'] = '\u77E2';
  23005. t['\u2F6F'] = '\u77F3';
  23006. t['\u2F70'] = '\u793A';
  23007. t['\u2F71'] = '\u79B8';
  23008. t['\u2F72'] = '\u79BE';
  23009. t['\u2F73'] = '\u7A74';
  23010. t['\u2F74'] = '\u7ACB';
  23011. t['\u2F75'] = '\u7AF9';
  23012. t['\u2F76'] = '\u7C73';
  23013. t['\u2F77'] = '\u7CF8';
  23014. t['\u2F78'] = '\u7F36';
  23015. t['\u2F79'] = '\u7F51';
  23016. t['\u2F7A'] = '\u7F8A';
  23017. t['\u2F7B'] = '\u7FBD';
  23018. t['\u2F7C'] = '\u8001';
  23019. t['\u2F7D'] = '\u800C';
  23020. t['\u2F7E'] = '\u8012';
  23021. t['\u2F7F'] = '\u8033';
  23022. t['\u2F80'] = '\u807F';
  23023. t['\u2F81'] = '\u8089';
  23024. t['\u2F82'] = '\u81E3';
  23025. t['\u2F83'] = '\u81EA';
  23026. t['\u2F84'] = '\u81F3';
  23027. t['\u2F85'] = '\u81FC';
  23028. t['\u2F86'] = '\u820C';
  23029. t['\u2F87'] = '\u821B';
  23030. t['\u2F88'] = '\u821F';
  23031. t['\u2F89'] = '\u826E';
  23032. t['\u2F8A'] = '\u8272';
  23033. t['\u2F8B'] = '\u8278';
  23034. t['\u2F8C'] = '\u864D';
  23035. t['\u2F8D'] = '\u866B';
  23036. t['\u2F8E'] = '\u8840';
  23037. t['\u2F8F'] = '\u884C';
  23038. t['\u2F90'] = '\u8863';
  23039. t['\u2F91'] = '\u897E';
  23040. t['\u2F92'] = '\u898B';
  23041. t['\u2F93'] = '\u89D2';
  23042. t['\u2F94'] = '\u8A00';
  23043. t['\u2F95'] = '\u8C37';
  23044. t['\u2F96'] = '\u8C46';
  23045. t['\u2F97'] = '\u8C55';
  23046. t['\u2F98'] = '\u8C78';
  23047. t['\u2F99'] = '\u8C9D';
  23048. t['\u2F9A'] = '\u8D64';
  23049. t['\u2F9B'] = '\u8D70';
  23050. t['\u2F9C'] = '\u8DB3';
  23051. t['\u2F9D'] = '\u8EAB';
  23052. t['\u2F9E'] = '\u8ECA';
  23053. t['\u2F9F'] = '\u8F9B';
  23054. t['\u2FA0'] = '\u8FB0';
  23055. t['\u2FA1'] = '\u8FB5';
  23056. t['\u2FA2'] = '\u9091';
  23057. t['\u2FA3'] = '\u9149';
  23058. t['\u2FA4'] = '\u91C6';
  23059. t['\u2FA5'] = '\u91CC';
  23060. t['\u2FA6'] = '\u91D1';
  23061. t['\u2FA7'] = '\u9577';
  23062. t['\u2FA8'] = '\u9580';
  23063. t['\u2FA9'] = '\u961C';
  23064. t['\u2FAA'] = '\u96B6';
  23065. t['\u2FAB'] = '\u96B9';
  23066. t['\u2FAC'] = '\u96E8';
  23067. t['\u2FAD'] = '\u9751';
  23068. t['\u2FAE'] = '\u975E';
  23069. t['\u2FAF'] = '\u9762';
  23070. t['\u2FB0'] = '\u9769';
  23071. t['\u2FB1'] = '\u97CB';
  23072. t['\u2FB2'] = '\u97ED';
  23073. t['\u2FB3'] = '\u97F3';
  23074. t['\u2FB4'] = '\u9801';
  23075. t['\u2FB5'] = '\u98A8';
  23076. t['\u2FB6'] = '\u98DB';
  23077. t['\u2FB7'] = '\u98DF';
  23078. t['\u2FB8'] = '\u9996';
  23079. t['\u2FB9'] = '\u9999';
  23080. t['\u2FBA'] = '\u99AC';
  23081. t['\u2FBB'] = '\u9AA8';
  23082. t['\u2FBC'] = '\u9AD8';
  23083. t['\u2FBD'] = '\u9ADF';
  23084. t['\u2FBE'] = '\u9B25';
  23085. t['\u2FBF'] = '\u9B2F';
  23086. t['\u2FC0'] = '\u9B32';
  23087. t['\u2FC1'] = '\u9B3C';
  23088. t['\u2FC2'] = '\u9B5A';
  23089. t['\u2FC3'] = '\u9CE5';
  23090. t['\u2FC4'] = '\u9E75';
  23091. t['\u2FC5'] = '\u9E7F';
  23092. t['\u2FC6'] = '\u9EA5';
  23093. t['\u2FC7'] = '\u9EBB';
  23094. t['\u2FC8'] = '\u9EC3';
  23095. t['\u2FC9'] = '\u9ECD';
  23096. t['\u2FCA'] = '\u9ED1';
  23097. t['\u2FCB'] = '\u9EF9';
  23098. t['\u2FCC'] = '\u9EFD';
  23099. t['\u2FCD'] = '\u9F0E';
  23100. t['\u2FCE'] = '\u9F13';
  23101. t['\u2FCF'] = '\u9F20';
  23102. t['\u2FD0'] = '\u9F3B';
  23103. t['\u2FD1'] = '\u9F4A';
  23104. t['\u2FD2'] = '\u9F52';
  23105. t['\u2FD3'] = '\u9F8D';
  23106. t['\u2FD4'] = '\u9F9C';
  23107. t['\u2FD5'] = '\u9FA0';
  23108. t['\u3036'] = '\u3012';
  23109. t['\u3038'] = '\u5341';
  23110. t['\u3039'] = '\u5344';
  23111. t['\u303A'] = '\u5345';
  23112. t['\u309B'] = '\u0020\u3099';
  23113. t['\u309C'] = '\u0020\u309A';
  23114. t['\u3131'] = '\u1100';
  23115. t['\u3132'] = '\u1101';
  23116. t['\u3133'] = '\u11AA';
  23117. t['\u3134'] = '\u1102';
  23118. t['\u3135'] = '\u11AC';
  23119. t['\u3136'] = '\u11AD';
  23120. t['\u3137'] = '\u1103';
  23121. t['\u3138'] = '\u1104';
  23122. t['\u3139'] = '\u1105';
  23123. t['\u313A'] = '\u11B0';
  23124. t['\u313B'] = '\u11B1';
  23125. t['\u313C'] = '\u11B2';
  23126. t['\u313D'] = '\u11B3';
  23127. t['\u313E'] = '\u11B4';
  23128. t['\u313F'] = '\u11B5';
  23129. t['\u3140'] = '\u111A';
  23130. t['\u3141'] = '\u1106';
  23131. t['\u3142'] = '\u1107';
  23132. t['\u3143'] = '\u1108';
  23133. t['\u3144'] = '\u1121';
  23134. t['\u3145'] = '\u1109';
  23135. t['\u3146'] = '\u110A';
  23136. t['\u3147'] = '\u110B';
  23137. t['\u3148'] = '\u110C';
  23138. t['\u3149'] = '\u110D';
  23139. t['\u314A'] = '\u110E';
  23140. t['\u314B'] = '\u110F';
  23141. t['\u314C'] = '\u1110';
  23142. t['\u314D'] = '\u1111';
  23143. t['\u314E'] = '\u1112';
  23144. t['\u314F'] = '\u1161';
  23145. t['\u3150'] = '\u1162';
  23146. t['\u3151'] = '\u1163';
  23147. t['\u3152'] = '\u1164';
  23148. t['\u3153'] = '\u1165';
  23149. t['\u3154'] = '\u1166';
  23150. t['\u3155'] = '\u1167';
  23151. t['\u3156'] = '\u1168';
  23152. t['\u3157'] = '\u1169';
  23153. t['\u3158'] = '\u116A';
  23154. t['\u3159'] = '\u116B';
  23155. t['\u315A'] = '\u116C';
  23156. t['\u315B'] = '\u116D';
  23157. t['\u315C'] = '\u116E';
  23158. t['\u315D'] = '\u116F';
  23159. t['\u315E'] = '\u1170';
  23160. t['\u315F'] = '\u1171';
  23161. t['\u3160'] = '\u1172';
  23162. t['\u3161'] = '\u1173';
  23163. t['\u3162'] = '\u1174';
  23164. t['\u3163'] = '\u1175';
  23165. t['\u3164'] = '\u1160';
  23166. t['\u3165'] = '\u1114';
  23167. t['\u3166'] = '\u1115';
  23168. t['\u3167'] = '\u11C7';
  23169. t['\u3168'] = '\u11C8';
  23170. t['\u3169'] = '\u11CC';
  23171. t['\u316A'] = '\u11CE';
  23172. t['\u316B'] = '\u11D3';
  23173. t['\u316C'] = '\u11D7';
  23174. t['\u316D'] = '\u11D9';
  23175. t['\u316E'] = '\u111C';
  23176. t['\u316F'] = '\u11DD';
  23177. t['\u3170'] = '\u11DF';
  23178. t['\u3171'] = '\u111D';
  23179. t['\u3172'] = '\u111E';
  23180. t['\u3173'] = '\u1120';
  23181. t['\u3174'] = '\u1122';
  23182. t['\u3175'] = '\u1123';
  23183. t['\u3176'] = '\u1127';
  23184. t['\u3177'] = '\u1129';
  23185. t['\u3178'] = '\u112B';
  23186. t['\u3179'] = '\u112C';
  23187. t['\u317A'] = '\u112D';
  23188. t['\u317B'] = '\u112E';
  23189. t['\u317C'] = '\u112F';
  23190. t['\u317D'] = '\u1132';
  23191. t['\u317E'] = '\u1136';
  23192. t['\u317F'] = '\u1140';
  23193. t['\u3180'] = '\u1147';
  23194. t['\u3181'] = '\u114C';
  23195. t['\u3182'] = '\u11F1';
  23196. t['\u3183'] = '\u11F2';
  23197. t['\u3184'] = '\u1157';
  23198. t['\u3185'] = '\u1158';
  23199. t['\u3186'] = '\u1159';
  23200. t['\u3187'] = '\u1184';
  23201. t['\u3188'] = '\u1185';
  23202. t['\u3189'] = '\u1188';
  23203. t['\u318A'] = '\u1191';
  23204. t['\u318B'] = '\u1192';
  23205. t['\u318C'] = '\u1194';
  23206. t['\u318D'] = '\u119E';
  23207. t['\u318E'] = '\u11A1';
  23208. t['\u3200'] = '\u0028\u1100\u0029';
  23209. t['\u3201'] = '\u0028\u1102\u0029';
  23210. t['\u3202'] = '\u0028\u1103\u0029';
  23211. t['\u3203'] = '\u0028\u1105\u0029';
  23212. t['\u3204'] = '\u0028\u1106\u0029';
  23213. t['\u3205'] = '\u0028\u1107\u0029';
  23214. t['\u3206'] = '\u0028\u1109\u0029';
  23215. t['\u3207'] = '\u0028\u110B\u0029';
  23216. t['\u3208'] = '\u0028\u110C\u0029';
  23217. t['\u3209'] = '\u0028\u110E\u0029';
  23218. t['\u320A'] = '\u0028\u110F\u0029';
  23219. t['\u320B'] = '\u0028\u1110\u0029';
  23220. t['\u320C'] = '\u0028\u1111\u0029';
  23221. t['\u320D'] = '\u0028\u1112\u0029';
  23222. t['\u320E'] = '\u0028\u1100\u1161\u0029';
  23223. t['\u320F'] = '\u0028\u1102\u1161\u0029';
  23224. t['\u3210'] = '\u0028\u1103\u1161\u0029';
  23225. t['\u3211'] = '\u0028\u1105\u1161\u0029';
  23226. t['\u3212'] = '\u0028\u1106\u1161\u0029';
  23227. t['\u3213'] = '\u0028\u1107\u1161\u0029';
  23228. t['\u3214'] = '\u0028\u1109\u1161\u0029';
  23229. t['\u3215'] = '\u0028\u110B\u1161\u0029';
  23230. t['\u3216'] = '\u0028\u110C\u1161\u0029';
  23231. t['\u3217'] = '\u0028\u110E\u1161\u0029';
  23232. t['\u3218'] = '\u0028\u110F\u1161\u0029';
  23233. t['\u3219'] = '\u0028\u1110\u1161\u0029';
  23234. t['\u321A'] = '\u0028\u1111\u1161\u0029';
  23235. t['\u321B'] = '\u0028\u1112\u1161\u0029';
  23236. t['\u321C'] = '\u0028\u110C\u116E\u0029';
  23237. t['\u321D'] = '\u0028\u110B\u1169\u110C\u1165\u11AB\u0029';
  23238. t['\u321E'] = '\u0028\u110B\u1169\u1112\u116E\u0029';
  23239. t['\u3220'] = '\u0028\u4E00\u0029';
  23240. t['\u3221'] = '\u0028\u4E8C\u0029';
  23241. t['\u3222'] = '\u0028\u4E09\u0029';
  23242. t['\u3223'] = '\u0028\u56DB\u0029';
  23243. t['\u3224'] = '\u0028\u4E94\u0029';
  23244. t['\u3225'] = '\u0028\u516D\u0029';
  23245. t['\u3226'] = '\u0028\u4E03\u0029';
  23246. t['\u3227'] = '\u0028\u516B\u0029';
  23247. t['\u3228'] = '\u0028\u4E5D\u0029';
  23248. t['\u3229'] = '\u0028\u5341\u0029';
  23249. t['\u322A'] = '\u0028\u6708\u0029';
  23250. t['\u322B'] = '\u0028\u706B\u0029';
  23251. t['\u322C'] = '\u0028\u6C34\u0029';
  23252. t['\u322D'] = '\u0028\u6728\u0029';
  23253. t['\u322E'] = '\u0028\u91D1\u0029';
  23254. t['\u322F'] = '\u0028\u571F\u0029';
  23255. t['\u3230'] = '\u0028\u65E5\u0029';
  23256. t['\u3231'] = '\u0028\u682A\u0029';
  23257. t['\u3232'] = '\u0028\u6709\u0029';
  23258. t['\u3233'] = '\u0028\u793E\u0029';
  23259. t['\u3234'] = '\u0028\u540D\u0029';
  23260. t['\u3235'] = '\u0028\u7279\u0029';
  23261. t['\u3236'] = '\u0028\u8CA1\u0029';
  23262. t['\u3237'] = '\u0028\u795D\u0029';
  23263. t['\u3238'] = '\u0028\u52B4\u0029';
  23264. t['\u3239'] = '\u0028\u4EE3\u0029';
  23265. t['\u323A'] = '\u0028\u547C\u0029';
  23266. t['\u323B'] = '\u0028\u5B66\u0029';
  23267. t['\u323C'] = '\u0028\u76E3\u0029';
  23268. t['\u323D'] = '\u0028\u4F01\u0029';
  23269. t['\u323E'] = '\u0028\u8CC7\u0029';
  23270. t['\u323F'] = '\u0028\u5354\u0029';
  23271. t['\u3240'] = '\u0028\u796D\u0029';
  23272. t['\u3241'] = '\u0028\u4F11\u0029';
  23273. t['\u3242'] = '\u0028\u81EA\u0029';
  23274. t['\u3243'] = '\u0028\u81F3\u0029';
  23275. t['\u32C0'] = '\u0031\u6708';
  23276. t['\u32C1'] = '\u0032\u6708';
  23277. t['\u32C2'] = '\u0033\u6708';
  23278. t['\u32C3'] = '\u0034\u6708';
  23279. t['\u32C4'] = '\u0035\u6708';
  23280. t['\u32C5'] = '\u0036\u6708';
  23281. t['\u32C6'] = '\u0037\u6708';
  23282. t['\u32C7'] = '\u0038\u6708';
  23283. t['\u32C8'] = '\u0039\u6708';
  23284. t['\u32C9'] = '\u0031\u0030\u6708';
  23285. t['\u32CA'] = '\u0031\u0031\u6708';
  23286. t['\u32CB'] = '\u0031\u0032\u6708';
  23287. t['\u3358'] = '\u0030\u70B9';
  23288. t['\u3359'] = '\u0031\u70B9';
  23289. t['\u335A'] = '\u0032\u70B9';
  23290. t['\u335B'] = '\u0033\u70B9';
  23291. t['\u335C'] = '\u0034\u70B9';
  23292. t['\u335D'] = '\u0035\u70B9';
  23293. t['\u335E'] = '\u0036\u70B9';
  23294. t['\u335F'] = '\u0037\u70B9';
  23295. t['\u3360'] = '\u0038\u70B9';
  23296. t['\u3361'] = '\u0039\u70B9';
  23297. t['\u3362'] = '\u0031\u0030\u70B9';
  23298. t['\u3363'] = '\u0031\u0031\u70B9';
  23299. t['\u3364'] = '\u0031\u0032\u70B9';
  23300. t['\u3365'] = '\u0031\u0033\u70B9';
  23301. t['\u3366'] = '\u0031\u0034\u70B9';
  23302. t['\u3367'] = '\u0031\u0035\u70B9';
  23303. t['\u3368'] = '\u0031\u0036\u70B9';
  23304. t['\u3369'] = '\u0031\u0037\u70B9';
  23305. t['\u336A'] = '\u0031\u0038\u70B9';
  23306. t['\u336B'] = '\u0031\u0039\u70B9';
  23307. t['\u336C'] = '\u0032\u0030\u70B9';
  23308. t['\u336D'] = '\u0032\u0031\u70B9';
  23309. t['\u336E'] = '\u0032\u0032\u70B9';
  23310. t['\u336F'] = '\u0032\u0033\u70B9';
  23311. t['\u3370'] = '\u0032\u0034\u70B9';
  23312. t['\u33E0'] = '\u0031\u65E5';
  23313. t['\u33E1'] = '\u0032\u65E5';
  23314. t['\u33E2'] = '\u0033\u65E5';
  23315. t['\u33E3'] = '\u0034\u65E5';
  23316. t['\u33E4'] = '\u0035\u65E5';
  23317. t['\u33E5'] = '\u0036\u65E5';
  23318. t['\u33E6'] = '\u0037\u65E5';
  23319. t['\u33E7'] = '\u0038\u65E5';
  23320. t['\u33E8'] = '\u0039\u65E5';
  23321. t['\u33E9'] = '\u0031\u0030\u65E5';
  23322. t['\u33EA'] = '\u0031\u0031\u65E5';
  23323. t['\u33EB'] = '\u0031\u0032\u65E5';
  23324. t['\u33EC'] = '\u0031\u0033\u65E5';
  23325. t['\u33ED'] = '\u0031\u0034\u65E5';
  23326. t['\u33EE'] = '\u0031\u0035\u65E5';
  23327. t['\u33EF'] = '\u0031\u0036\u65E5';
  23328. t['\u33F0'] = '\u0031\u0037\u65E5';
  23329. t['\u33F1'] = '\u0031\u0038\u65E5';
  23330. t['\u33F2'] = '\u0031\u0039\u65E5';
  23331. t['\u33F3'] = '\u0032\u0030\u65E5';
  23332. t['\u33F4'] = '\u0032\u0031\u65E5';
  23333. t['\u33F5'] = '\u0032\u0032\u65E5';
  23334. t['\u33F6'] = '\u0032\u0033\u65E5';
  23335. t['\u33F7'] = '\u0032\u0034\u65E5';
  23336. t['\u33F8'] = '\u0032\u0035\u65E5';
  23337. t['\u33F9'] = '\u0032\u0036\u65E5';
  23338. t['\u33FA'] = '\u0032\u0037\u65E5';
  23339. t['\u33FB'] = '\u0032\u0038\u65E5';
  23340. t['\u33FC'] = '\u0032\u0039\u65E5';
  23341. t['\u33FD'] = '\u0033\u0030\u65E5';
  23342. t['\u33FE'] = '\u0033\u0031\u65E5';
  23343. t['\uFB00'] = '\u0066\u0066';
  23344. t['\uFB01'] = '\u0066\u0069';
  23345. t['\uFB02'] = '\u0066\u006C';
  23346. t['\uFB03'] = '\u0066\u0066\u0069';
  23347. t['\uFB04'] = '\u0066\u0066\u006C';
  23348. t['\uFB05'] = '\u017F\u0074';
  23349. t['\uFB06'] = '\u0073\u0074';
  23350. t['\uFB13'] = '\u0574\u0576';
  23351. t['\uFB14'] = '\u0574\u0565';
  23352. t['\uFB15'] = '\u0574\u056B';
  23353. t['\uFB16'] = '\u057E\u0576';
  23354. t['\uFB17'] = '\u0574\u056D';
  23355. t['\uFB4F'] = '\u05D0\u05DC';
  23356. t['\uFB50'] = '\u0671';
  23357. t['\uFB51'] = '\u0671';
  23358. t['\uFB52'] = '\u067B';
  23359. t['\uFB53'] = '\u067B';
  23360. t['\uFB54'] = '\u067B';
  23361. t['\uFB55'] = '\u067B';
  23362. t['\uFB56'] = '\u067E';
  23363. t['\uFB57'] = '\u067E';
  23364. t['\uFB58'] = '\u067E';
  23365. t['\uFB59'] = '\u067E';
  23366. t['\uFB5A'] = '\u0680';
  23367. t['\uFB5B'] = '\u0680';
  23368. t['\uFB5C'] = '\u0680';
  23369. t['\uFB5D'] = '\u0680';
  23370. t['\uFB5E'] = '\u067A';
  23371. t['\uFB5F'] = '\u067A';
  23372. t['\uFB60'] = '\u067A';
  23373. t['\uFB61'] = '\u067A';
  23374. t['\uFB62'] = '\u067F';
  23375. t['\uFB63'] = '\u067F';
  23376. t['\uFB64'] = '\u067F';
  23377. t['\uFB65'] = '\u067F';
  23378. t['\uFB66'] = '\u0679';
  23379. t['\uFB67'] = '\u0679';
  23380. t['\uFB68'] = '\u0679';
  23381. t['\uFB69'] = '\u0679';
  23382. t['\uFB6A'] = '\u06A4';
  23383. t['\uFB6B'] = '\u06A4';
  23384. t['\uFB6C'] = '\u06A4';
  23385. t['\uFB6D'] = '\u06A4';
  23386. t['\uFB6E'] = '\u06A6';
  23387. t['\uFB6F'] = '\u06A6';
  23388. t['\uFB70'] = '\u06A6';
  23389. t['\uFB71'] = '\u06A6';
  23390. t['\uFB72'] = '\u0684';
  23391. t['\uFB73'] = '\u0684';
  23392. t['\uFB74'] = '\u0684';
  23393. t['\uFB75'] = '\u0684';
  23394. t['\uFB76'] = '\u0683';
  23395. t['\uFB77'] = '\u0683';
  23396. t['\uFB78'] = '\u0683';
  23397. t['\uFB79'] = '\u0683';
  23398. t['\uFB7A'] = '\u0686';
  23399. t['\uFB7B'] = '\u0686';
  23400. t['\uFB7C'] = '\u0686';
  23401. t['\uFB7D'] = '\u0686';
  23402. t['\uFB7E'] = '\u0687';
  23403. t['\uFB7F'] = '\u0687';
  23404. t['\uFB80'] = '\u0687';
  23405. t['\uFB81'] = '\u0687';
  23406. t['\uFB82'] = '\u068D';
  23407. t['\uFB83'] = '\u068D';
  23408. t['\uFB84'] = '\u068C';
  23409. t['\uFB85'] = '\u068C';
  23410. t['\uFB86'] = '\u068E';
  23411. t['\uFB87'] = '\u068E';
  23412. t['\uFB88'] = '\u0688';
  23413. t['\uFB89'] = '\u0688';
  23414. t['\uFB8A'] = '\u0698';
  23415. t['\uFB8B'] = '\u0698';
  23416. t['\uFB8C'] = '\u0691';
  23417. t['\uFB8D'] = '\u0691';
  23418. t['\uFB8E'] = '\u06A9';
  23419. t['\uFB8F'] = '\u06A9';
  23420. t['\uFB90'] = '\u06A9';
  23421. t['\uFB91'] = '\u06A9';
  23422. t['\uFB92'] = '\u06AF';
  23423. t['\uFB93'] = '\u06AF';
  23424. t['\uFB94'] = '\u06AF';
  23425. t['\uFB95'] = '\u06AF';
  23426. t['\uFB96'] = '\u06B3';
  23427. t['\uFB97'] = '\u06B3';
  23428. t['\uFB98'] = '\u06B3';
  23429. t['\uFB99'] = '\u06B3';
  23430. t['\uFB9A'] = '\u06B1';
  23431. t['\uFB9B'] = '\u06B1';
  23432. t['\uFB9C'] = '\u06B1';
  23433. t['\uFB9D'] = '\u06B1';
  23434. t['\uFB9E'] = '\u06BA';
  23435. t['\uFB9F'] = '\u06BA';
  23436. t['\uFBA0'] = '\u06BB';
  23437. t['\uFBA1'] = '\u06BB';
  23438. t['\uFBA2'] = '\u06BB';
  23439. t['\uFBA3'] = '\u06BB';
  23440. t['\uFBA4'] = '\u06C0';
  23441. t['\uFBA5'] = '\u06C0';
  23442. t['\uFBA6'] = '\u06C1';
  23443. t['\uFBA7'] = '\u06C1';
  23444. t['\uFBA8'] = '\u06C1';
  23445. t['\uFBA9'] = '\u06C1';
  23446. t['\uFBAA'] = '\u06BE';
  23447. t['\uFBAB'] = '\u06BE';
  23448. t['\uFBAC'] = '\u06BE';
  23449. t['\uFBAD'] = '\u06BE';
  23450. t['\uFBAE'] = '\u06D2';
  23451. t['\uFBAF'] = '\u06D2';
  23452. t['\uFBB0'] = '\u06D3';
  23453. t['\uFBB1'] = '\u06D3';
  23454. t['\uFBD3'] = '\u06AD';
  23455. t['\uFBD4'] = '\u06AD';
  23456. t['\uFBD5'] = '\u06AD';
  23457. t['\uFBD6'] = '\u06AD';
  23458. t['\uFBD7'] = '\u06C7';
  23459. t['\uFBD8'] = '\u06C7';
  23460. t['\uFBD9'] = '\u06C6';
  23461. t['\uFBDA'] = '\u06C6';
  23462. t['\uFBDB'] = '\u06C8';
  23463. t['\uFBDC'] = '\u06C8';
  23464. t['\uFBDD'] = '\u0677';
  23465. t['\uFBDE'] = '\u06CB';
  23466. t['\uFBDF'] = '\u06CB';
  23467. t['\uFBE0'] = '\u06C5';
  23468. t['\uFBE1'] = '\u06C5';
  23469. t['\uFBE2'] = '\u06C9';
  23470. t['\uFBE3'] = '\u06C9';
  23471. t['\uFBE4'] = '\u06D0';
  23472. t['\uFBE5'] = '\u06D0';
  23473. t['\uFBE6'] = '\u06D0';
  23474. t['\uFBE7'] = '\u06D0';
  23475. t['\uFBE8'] = '\u0649';
  23476. t['\uFBE9'] = '\u0649';
  23477. t['\uFBEA'] = '\u0626\u0627';
  23478. t['\uFBEB'] = '\u0626\u0627';
  23479. t['\uFBEC'] = '\u0626\u06D5';
  23480. t['\uFBED'] = '\u0626\u06D5';
  23481. t['\uFBEE'] = '\u0626\u0648';
  23482. t['\uFBEF'] = '\u0626\u0648';
  23483. t['\uFBF0'] = '\u0626\u06C7';
  23484. t['\uFBF1'] = '\u0626\u06C7';
  23485. t['\uFBF2'] = '\u0626\u06C6';
  23486. t['\uFBF3'] = '\u0626\u06C6';
  23487. t['\uFBF4'] = '\u0626\u06C8';
  23488. t['\uFBF5'] = '\u0626\u06C8';
  23489. t['\uFBF6'] = '\u0626\u06D0';
  23490. t['\uFBF7'] = '\u0626\u06D0';
  23491. t['\uFBF8'] = '\u0626\u06D0';
  23492. t['\uFBF9'] = '\u0626\u0649';
  23493. t['\uFBFA'] = '\u0626\u0649';
  23494. t['\uFBFB'] = '\u0626\u0649';
  23495. t['\uFBFC'] = '\u06CC';
  23496. t['\uFBFD'] = '\u06CC';
  23497. t['\uFBFE'] = '\u06CC';
  23498. t['\uFBFF'] = '\u06CC';
  23499. t['\uFC00'] = '\u0626\u062C';
  23500. t['\uFC01'] = '\u0626\u062D';
  23501. t['\uFC02'] = '\u0626\u0645';
  23502. t['\uFC03'] = '\u0626\u0649';
  23503. t['\uFC04'] = '\u0626\u064A';
  23504. t['\uFC05'] = '\u0628\u062C';
  23505. t['\uFC06'] = '\u0628\u062D';
  23506. t['\uFC07'] = '\u0628\u062E';
  23507. t['\uFC08'] = '\u0628\u0645';
  23508. t['\uFC09'] = '\u0628\u0649';
  23509. t['\uFC0A'] = '\u0628\u064A';
  23510. t['\uFC0B'] = '\u062A\u062C';
  23511. t['\uFC0C'] = '\u062A\u062D';
  23512. t['\uFC0D'] = '\u062A\u062E';
  23513. t['\uFC0E'] = '\u062A\u0645';
  23514. t['\uFC0F'] = '\u062A\u0649';
  23515. t['\uFC10'] = '\u062A\u064A';
  23516. t['\uFC11'] = '\u062B\u062C';
  23517. t['\uFC12'] = '\u062B\u0645';
  23518. t['\uFC13'] = '\u062B\u0649';
  23519. t['\uFC14'] = '\u062B\u064A';
  23520. t['\uFC15'] = '\u062C\u062D';
  23521. t['\uFC16'] = '\u062C\u0645';
  23522. t['\uFC17'] = '\u062D\u062C';
  23523. t['\uFC18'] = '\u062D\u0645';
  23524. t['\uFC19'] = '\u062E\u062C';
  23525. t['\uFC1A'] = '\u062E\u062D';
  23526. t['\uFC1B'] = '\u062E\u0645';
  23527. t['\uFC1C'] = '\u0633\u062C';
  23528. t['\uFC1D'] = '\u0633\u062D';
  23529. t['\uFC1E'] = '\u0633\u062E';
  23530. t['\uFC1F'] = '\u0633\u0645';
  23531. t['\uFC20'] = '\u0635\u062D';
  23532. t['\uFC21'] = '\u0635\u0645';
  23533. t['\uFC22'] = '\u0636\u062C';
  23534. t['\uFC23'] = '\u0636\u062D';
  23535. t['\uFC24'] = '\u0636\u062E';
  23536. t['\uFC25'] = '\u0636\u0645';
  23537. t['\uFC26'] = '\u0637\u062D';
  23538. t['\uFC27'] = '\u0637\u0645';
  23539. t['\uFC28'] = '\u0638\u0645';
  23540. t['\uFC29'] = '\u0639\u062C';
  23541. t['\uFC2A'] = '\u0639\u0645';
  23542. t['\uFC2B'] = '\u063A\u062C';
  23543. t['\uFC2C'] = '\u063A\u0645';
  23544. t['\uFC2D'] = '\u0641\u062C';
  23545. t['\uFC2E'] = '\u0641\u062D';
  23546. t['\uFC2F'] = '\u0641\u062E';
  23547. t['\uFC30'] = '\u0641\u0645';
  23548. t['\uFC31'] = '\u0641\u0649';
  23549. t['\uFC32'] = '\u0641\u064A';
  23550. t['\uFC33'] = '\u0642\u062D';
  23551. t['\uFC34'] = '\u0642\u0645';
  23552. t['\uFC35'] = '\u0642\u0649';
  23553. t['\uFC36'] = '\u0642\u064A';
  23554. t['\uFC37'] = '\u0643\u0627';
  23555. t['\uFC38'] = '\u0643\u062C';
  23556. t['\uFC39'] = '\u0643\u062D';
  23557. t['\uFC3A'] = '\u0643\u062E';
  23558. t['\uFC3B'] = '\u0643\u0644';
  23559. t['\uFC3C'] = '\u0643\u0645';
  23560. t['\uFC3D'] = '\u0643\u0649';
  23561. t['\uFC3E'] = '\u0643\u064A';
  23562. t['\uFC3F'] = '\u0644\u062C';
  23563. t['\uFC40'] = '\u0644\u062D';
  23564. t['\uFC41'] = '\u0644\u062E';
  23565. t['\uFC42'] = '\u0644\u0645';
  23566. t['\uFC43'] = '\u0644\u0649';
  23567. t['\uFC44'] = '\u0644\u064A';
  23568. t['\uFC45'] = '\u0645\u062C';
  23569. t['\uFC46'] = '\u0645\u062D';
  23570. t['\uFC47'] = '\u0645\u062E';
  23571. t['\uFC48'] = '\u0645\u0645';
  23572. t['\uFC49'] = '\u0645\u0649';
  23573. t['\uFC4A'] = '\u0645\u064A';
  23574. t['\uFC4B'] = '\u0646\u062C';
  23575. t['\uFC4C'] = '\u0646\u062D';
  23576. t['\uFC4D'] = '\u0646\u062E';
  23577. t['\uFC4E'] = '\u0646\u0645';
  23578. t['\uFC4F'] = '\u0646\u0649';
  23579. t['\uFC50'] = '\u0646\u064A';
  23580. t['\uFC51'] = '\u0647\u062C';
  23581. t['\uFC52'] = '\u0647\u0645';
  23582. t['\uFC53'] = '\u0647\u0649';
  23583. t['\uFC54'] = '\u0647\u064A';
  23584. t['\uFC55'] = '\u064A\u062C';
  23585. t['\uFC56'] = '\u064A\u062D';
  23586. t['\uFC57'] = '\u064A\u062E';
  23587. t['\uFC58'] = '\u064A\u0645';
  23588. t['\uFC59'] = '\u064A\u0649';
  23589. t['\uFC5A'] = '\u064A\u064A';
  23590. t['\uFC5B'] = '\u0630\u0670';
  23591. t['\uFC5C'] = '\u0631\u0670';
  23592. t['\uFC5D'] = '\u0649\u0670';
  23593. t['\uFC5E'] = '\u0020\u064C\u0651';
  23594. t['\uFC5F'] = '\u0020\u064D\u0651';
  23595. t['\uFC60'] = '\u0020\u064E\u0651';
  23596. t['\uFC61'] = '\u0020\u064F\u0651';
  23597. t['\uFC62'] = '\u0020\u0650\u0651';
  23598. t['\uFC63'] = '\u0020\u0651\u0670';
  23599. t['\uFC64'] = '\u0626\u0631';
  23600. t['\uFC65'] = '\u0626\u0632';
  23601. t['\uFC66'] = '\u0626\u0645';
  23602. t['\uFC67'] = '\u0626\u0646';
  23603. t['\uFC68'] = '\u0626\u0649';
  23604. t['\uFC69'] = '\u0626\u064A';
  23605. t['\uFC6A'] = '\u0628\u0631';
  23606. t['\uFC6B'] = '\u0628\u0632';
  23607. t['\uFC6C'] = '\u0628\u0645';
  23608. t['\uFC6D'] = '\u0628\u0646';
  23609. t['\uFC6E'] = '\u0628\u0649';
  23610. t['\uFC6F'] = '\u0628\u064A';
  23611. t['\uFC70'] = '\u062A\u0631';
  23612. t['\uFC71'] = '\u062A\u0632';
  23613. t['\uFC72'] = '\u062A\u0645';
  23614. t['\uFC73'] = '\u062A\u0646';
  23615. t['\uFC74'] = '\u062A\u0649';
  23616. t['\uFC75'] = '\u062A\u064A';
  23617. t['\uFC76'] = '\u062B\u0631';
  23618. t['\uFC77'] = '\u062B\u0632';
  23619. t['\uFC78'] = '\u062B\u0645';
  23620. t['\uFC79'] = '\u062B\u0646';
  23621. t['\uFC7A'] = '\u062B\u0649';
  23622. t['\uFC7B'] = '\u062B\u064A';
  23623. t['\uFC7C'] = '\u0641\u0649';
  23624. t['\uFC7D'] = '\u0641\u064A';
  23625. t['\uFC7E'] = '\u0642\u0649';
  23626. t['\uFC7F'] = '\u0642\u064A';
  23627. t['\uFC80'] = '\u0643\u0627';
  23628. t['\uFC81'] = '\u0643\u0644';
  23629. t['\uFC82'] = '\u0643\u0645';
  23630. t['\uFC83'] = '\u0643\u0649';
  23631. t['\uFC84'] = '\u0643\u064A';
  23632. t['\uFC85'] = '\u0644\u0645';
  23633. t['\uFC86'] = '\u0644\u0649';
  23634. t['\uFC87'] = '\u0644\u064A';
  23635. t['\uFC88'] = '\u0645\u0627';
  23636. t['\uFC89'] = '\u0645\u0645';
  23637. t['\uFC8A'] = '\u0646\u0631';
  23638. t['\uFC8B'] = '\u0646\u0632';
  23639. t['\uFC8C'] = '\u0646\u0645';
  23640. t['\uFC8D'] = '\u0646\u0646';
  23641. t['\uFC8E'] = '\u0646\u0649';
  23642. t['\uFC8F'] = '\u0646\u064A';
  23643. t['\uFC90'] = '\u0649\u0670';
  23644. t['\uFC91'] = '\u064A\u0631';
  23645. t['\uFC92'] = '\u064A\u0632';
  23646. t['\uFC93'] = '\u064A\u0645';
  23647. t['\uFC94'] = '\u064A\u0646';
  23648. t['\uFC95'] = '\u064A\u0649';
  23649. t['\uFC96'] = '\u064A\u064A';
  23650. t['\uFC97'] = '\u0626\u062C';
  23651. t['\uFC98'] = '\u0626\u062D';
  23652. t['\uFC99'] = '\u0626\u062E';
  23653. t['\uFC9A'] = '\u0626\u0645';
  23654. t['\uFC9B'] = '\u0626\u0647';
  23655. t['\uFC9C'] = '\u0628\u062C';
  23656. t['\uFC9D'] = '\u0628\u062D';
  23657. t['\uFC9E'] = '\u0628\u062E';
  23658. t['\uFC9F'] = '\u0628\u0645';
  23659. t['\uFCA0'] = '\u0628\u0647';
  23660. t['\uFCA1'] = '\u062A\u062C';
  23661. t['\uFCA2'] = '\u062A\u062D';
  23662. t['\uFCA3'] = '\u062A\u062E';
  23663. t['\uFCA4'] = '\u062A\u0645';
  23664. t['\uFCA5'] = '\u062A\u0647';
  23665. t['\uFCA6'] = '\u062B\u0645';
  23666. t['\uFCA7'] = '\u062C\u062D';
  23667. t['\uFCA8'] = '\u062C\u0645';
  23668. t['\uFCA9'] = '\u062D\u062C';
  23669. t['\uFCAA'] = '\u062D\u0645';
  23670. t['\uFCAB'] = '\u062E\u062C';
  23671. t['\uFCAC'] = '\u062E\u0645';
  23672. t['\uFCAD'] = '\u0633\u062C';
  23673. t['\uFCAE'] = '\u0633\u062D';
  23674. t['\uFCAF'] = '\u0633\u062E';
  23675. t['\uFCB0'] = '\u0633\u0645';
  23676. t['\uFCB1'] = '\u0635\u062D';
  23677. t['\uFCB2'] = '\u0635\u062E';
  23678. t['\uFCB3'] = '\u0635\u0645';
  23679. t['\uFCB4'] = '\u0636\u062C';
  23680. t['\uFCB5'] = '\u0636\u062D';
  23681. t['\uFCB6'] = '\u0636\u062E';
  23682. t['\uFCB7'] = '\u0636\u0645';
  23683. t['\uFCB8'] = '\u0637\u062D';
  23684. t['\uFCB9'] = '\u0638\u0645';
  23685. t['\uFCBA'] = '\u0639\u062C';
  23686. t['\uFCBB'] = '\u0639\u0645';
  23687. t['\uFCBC'] = '\u063A\u062C';
  23688. t['\uFCBD'] = '\u063A\u0645';
  23689. t['\uFCBE'] = '\u0641\u062C';
  23690. t['\uFCBF'] = '\u0641\u062D';
  23691. t['\uFCC0'] = '\u0641\u062E';
  23692. t['\uFCC1'] = '\u0641\u0645';
  23693. t['\uFCC2'] = '\u0642\u062D';
  23694. t['\uFCC3'] = '\u0642\u0645';
  23695. t['\uFCC4'] = '\u0643\u062C';
  23696. t['\uFCC5'] = '\u0643\u062D';
  23697. t['\uFCC6'] = '\u0643\u062E';
  23698. t['\uFCC7'] = '\u0643\u0644';
  23699. t['\uFCC8'] = '\u0643\u0645';
  23700. t['\uFCC9'] = '\u0644\u062C';
  23701. t['\uFCCA'] = '\u0644\u062D';
  23702. t['\uFCCB'] = '\u0644\u062E';
  23703. t['\uFCCC'] = '\u0644\u0645';
  23704. t['\uFCCD'] = '\u0644\u0647';
  23705. t['\uFCCE'] = '\u0645\u062C';
  23706. t['\uFCCF'] = '\u0645\u062D';
  23707. t['\uFCD0'] = '\u0645\u062E';
  23708. t['\uFCD1'] = '\u0645\u0645';
  23709. t['\uFCD2'] = '\u0646\u062C';
  23710. t['\uFCD3'] = '\u0646\u062D';
  23711. t['\uFCD4'] = '\u0646\u062E';
  23712. t['\uFCD5'] = '\u0646\u0645';
  23713. t['\uFCD6'] = '\u0646\u0647';
  23714. t['\uFCD7'] = '\u0647\u062C';
  23715. t['\uFCD8'] = '\u0647\u0645';
  23716. t['\uFCD9'] = '\u0647\u0670';
  23717. t['\uFCDA'] = '\u064A\u062C';
  23718. t['\uFCDB'] = '\u064A\u062D';
  23719. t['\uFCDC'] = '\u064A\u062E';
  23720. t['\uFCDD'] = '\u064A\u0645';
  23721. t['\uFCDE'] = '\u064A\u0647';
  23722. t['\uFCDF'] = '\u0626\u0645';
  23723. t['\uFCE0'] = '\u0626\u0647';
  23724. t['\uFCE1'] = '\u0628\u0645';
  23725. t['\uFCE2'] = '\u0628\u0647';
  23726. t['\uFCE3'] = '\u062A\u0645';
  23727. t['\uFCE4'] = '\u062A\u0647';
  23728. t['\uFCE5'] = '\u062B\u0645';
  23729. t['\uFCE6'] = '\u062B\u0647';
  23730. t['\uFCE7'] = '\u0633\u0645';
  23731. t['\uFCE8'] = '\u0633\u0647';
  23732. t['\uFCE9'] = '\u0634\u0645';
  23733. t['\uFCEA'] = '\u0634\u0647';
  23734. t['\uFCEB'] = '\u0643\u0644';
  23735. t['\uFCEC'] = '\u0643\u0645';
  23736. t['\uFCED'] = '\u0644\u0645';
  23737. t['\uFCEE'] = '\u0646\u0645';
  23738. t['\uFCEF'] = '\u0646\u0647';
  23739. t['\uFCF0'] = '\u064A\u0645';
  23740. t['\uFCF1'] = '\u064A\u0647';
  23741. t['\uFCF2'] = '\u0640\u064E\u0651';
  23742. t['\uFCF3'] = '\u0640\u064F\u0651';
  23743. t['\uFCF4'] = '\u0640\u0650\u0651';
  23744. t['\uFCF5'] = '\u0637\u0649';
  23745. t['\uFCF6'] = '\u0637\u064A';
  23746. t['\uFCF7'] = '\u0639\u0649';
  23747. t['\uFCF8'] = '\u0639\u064A';
  23748. t['\uFCF9'] = '\u063A\u0649';
  23749. t['\uFCFA'] = '\u063A\u064A';
  23750. t['\uFCFB'] = '\u0633\u0649';
  23751. t['\uFCFC'] = '\u0633\u064A';
  23752. t['\uFCFD'] = '\u0634\u0649';
  23753. t['\uFCFE'] = '\u0634\u064A';
  23754. t['\uFCFF'] = '\u062D\u0649';
  23755. t['\uFD00'] = '\u062D\u064A';
  23756. t['\uFD01'] = '\u062C\u0649';
  23757. t['\uFD02'] = '\u062C\u064A';
  23758. t['\uFD03'] = '\u062E\u0649';
  23759. t['\uFD04'] = '\u062E\u064A';
  23760. t['\uFD05'] = '\u0635\u0649';
  23761. t['\uFD06'] = '\u0635\u064A';
  23762. t['\uFD07'] = '\u0636\u0649';
  23763. t['\uFD08'] = '\u0636\u064A';
  23764. t['\uFD09'] = '\u0634\u062C';
  23765. t['\uFD0A'] = '\u0634\u062D';
  23766. t['\uFD0B'] = '\u0634\u062E';
  23767. t['\uFD0C'] = '\u0634\u0645';
  23768. t['\uFD0D'] = '\u0634\u0631';
  23769. t['\uFD0E'] = '\u0633\u0631';
  23770. t['\uFD0F'] = '\u0635\u0631';
  23771. t['\uFD10'] = '\u0636\u0631';
  23772. t['\uFD11'] = '\u0637\u0649';
  23773. t['\uFD12'] = '\u0637\u064A';
  23774. t['\uFD13'] = '\u0639\u0649';
  23775. t['\uFD14'] = '\u0639\u064A';
  23776. t['\uFD15'] = '\u063A\u0649';
  23777. t['\uFD16'] = '\u063A\u064A';
  23778. t['\uFD17'] = '\u0633\u0649';
  23779. t['\uFD18'] = '\u0633\u064A';
  23780. t['\uFD19'] = '\u0634\u0649';
  23781. t['\uFD1A'] = '\u0634\u064A';
  23782. t['\uFD1B'] = '\u062D\u0649';
  23783. t['\uFD1C'] = '\u062D\u064A';
  23784. t['\uFD1D'] = '\u062C\u0649';
  23785. t['\uFD1E'] = '\u062C\u064A';
  23786. t['\uFD1F'] = '\u062E\u0649';
  23787. t['\uFD20'] = '\u062E\u064A';
  23788. t['\uFD21'] = '\u0635\u0649';
  23789. t['\uFD22'] = '\u0635\u064A';
  23790. t['\uFD23'] = '\u0636\u0649';
  23791. t['\uFD24'] = '\u0636\u064A';
  23792. t['\uFD25'] = '\u0634\u062C';
  23793. t['\uFD26'] = '\u0634\u062D';
  23794. t['\uFD27'] = '\u0634\u062E';
  23795. t['\uFD28'] = '\u0634\u0645';
  23796. t['\uFD29'] = '\u0634\u0631';
  23797. t['\uFD2A'] = '\u0633\u0631';
  23798. t['\uFD2B'] = '\u0635\u0631';
  23799. t['\uFD2C'] = '\u0636\u0631';
  23800. t['\uFD2D'] = '\u0634\u062C';
  23801. t['\uFD2E'] = '\u0634\u062D';
  23802. t['\uFD2F'] = '\u0634\u062E';
  23803. t['\uFD30'] = '\u0634\u0645';
  23804. t['\uFD31'] = '\u0633\u0647';
  23805. t['\uFD32'] = '\u0634\u0647';
  23806. t['\uFD33'] = '\u0637\u0645';
  23807. t['\uFD34'] = '\u0633\u062C';
  23808. t['\uFD35'] = '\u0633\u062D';
  23809. t['\uFD36'] = '\u0633\u062E';
  23810. t['\uFD37'] = '\u0634\u062C';
  23811. t['\uFD38'] = '\u0634\u062D';
  23812. t['\uFD39'] = '\u0634\u062E';
  23813. t['\uFD3A'] = '\u0637\u0645';
  23814. t['\uFD3B'] = '\u0638\u0645';
  23815. t['\uFD3C'] = '\u0627\u064B';
  23816. t['\uFD3D'] = '\u0627\u064B';
  23817. t['\uFD50'] = '\u062A\u062C\u0645';
  23818. t['\uFD51'] = '\u062A\u062D\u062C';
  23819. t['\uFD52'] = '\u062A\u062D\u062C';
  23820. t['\uFD53'] = '\u062A\u062D\u0645';
  23821. t['\uFD54'] = '\u062A\u062E\u0645';
  23822. t['\uFD55'] = '\u062A\u0645\u062C';
  23823. t['\uFD56'] = '\u062A\u0645\u062D';
  23824. t['\uFD57'] = '\u062A\u0645\u062E';
  23825. t['\uFD58'] = '\u062C\u0645\u062D';
  23826. t['\uFD59'] = '\u062C\u0645\u062D';
  23827. t['\uFD5A'] = '\u062D\u0645\u064A';
  23828. t['\uFD5B'] = '\u062D\u0645\u0649';
  23829. t['\uFD5C'] = '\u0633\u062D\u062C';
  23830. t['\uFD5D'] = '\u0633\u062C\u062D';
  23831. t['\uFD5E'] = '\u0633\u062C\u0649';
  23832. t['\uFD5F'] = '\u0633\u0645\u062D';
  23833. t['\uFD60'] = '\u0633\u0645\u062D';
  23834. t['\uFD61'] = '\u0633\u0645\u062C';
  23835. t['\uFD62'] = '\u0633\u0645\u0645';
  23836. t['\uFD63'] = '\u0633\u0645\u0645';
  23837. t['\uFD64'] = '\u0635\u062D\u062D';
  23838. t['\uFD65'] = '\u0635\u062D\u062D';
  23839. t['\uFD66'] = '\u0635\u0645\u0645';
  23840. t['\uFD67'] = '\u0634\u062D\u0645';
  23841. t['\uFD68'] = '\u0634\u062D\u0645';
  23842. t['\uFD69'] = '\u0634\u062C\u064A';
  23843. t['\uFD6A'] = '\u0634\u0645\u062E';
  23844. t['\uFD6B'] = '\u0634\u0645\u062E';
  23845. t['\uFD6C'] = '\u0634\u0645\u0645';
  23846. t['\uFD6D'] = '\u0634\u0645\u0645';
  23847. t['\uFD6E'] = '\u0636\u062D\u0649';
  23848. t['\uFD6F'] = '\u0636\u062E\u0645';
  23849. t['\uFD70'] = '\u0636\u062E\u0645';
  23850. t['\uFD71'] = '\u0637\u0645\u062D';
  23851. t['\uFD72'] = '\u0637\u0645\u062D';
  23852. t['\uFD73'] = '\u0637\u0645\u0645';
  23853. t['\uFD74'] = '\u0637\u0645\u064A';
  23854. t['\uFD75'] = '\u0639\u062C\u0645';
  23855. t['\uFD76'] = '\u0639\u0645\u0645';
  23856. t['\uFD77'] = '\u0639\u0645\u0645';
  23857. t['\uFD78'] = '\u0639\u0645\u0649';
  23858. t['\uFD79'] = '\u063A\u0645\u0645';
  23859. t['\uFD7A'] = '\u063A\u0645\u064A';
  23860. t['\uFD7B'] = '\u063A\u0645\u0649';
  23861. t['\uFD7C'] = '\u0641\u062E\u0645';
  23862. t['\uFD7D'] = '\u0641\u062E\u0645';
  23863. t['\uFD7E'] = '\u0642\u0645\u062D';
  23864. t['\uFD7F'] = '\u0642\u0645\u0645';
  23865. t['\uFD80'] = '\u0644\u062D\u0645';
  23866. t['\uFD81'] = '\u0644\u062D\u064A';
  23867. t['\uFD82'] = '\u0644\u062D\u0649';
  23868. t['\uFD83'] = '\u0644\u062C\u062C';
  23869. t['\uFD84'] = '\u0644\u062C\u062C';
  23870. t['\uFD85'] = '\u0644\u062E\u0645';
  23871. t['\uFD86'] = '\u0644\u062E\u0645';
  23872. t['\uFD87'] = '\u0644\u0645\u062D';
  23873. t['\uFD88'] = '\u0644\u0645\u062D';
  23874. t['\uFD89'] = '\u0645\u062D\u062C';
  23875. t['\uFD8A'] = '\u0645\u062D\u0645';
  23876. t['\uFD8B'] = '\u0645\u062D\u064A';
  23877. t['\uFD8C'] = '\u0645\u062C\u062D';
  23878. t['\uFD8D'] = '\u0645\u062C\u0645';
  23879. t['\uFD8E'] = '\u0645\u062E\u062C';
  23880. t['\uFD8F'] = '\u0645\u062E\u0645';
  23881. t['\uFD92'] = '\u0645\u062C\u062E';
  23882. t['\uFD93'] = '\u0647\u0645\u062C';
  23883. t['\uFD94'] = '\u0647\u0645\u0645';
  23884. t['\uFD95'] = '\u0646\u062D\u0645';
  23885. t['\uFD96'] = '\u0646\u062D\u0649';
  23886. t['\uFD97'] = '\u0646\u062C\u0645';
  23887. t['\uFD98'] = '\u0646\u062C\u0645';
  23888. t['\uFD99'] = '\u0646\u062C\u0649';
  23889. t['\uFD9A'] = '\u0646\u0645\u064A';
  23890. t['\uFD9B'] = '\u0646\u0645\u0649';
  23891. t['\uFD9C'] = '\u064A\u0645\u0645';
  23892. t['\uFD9D'] = '\u064A\u0645\u0645';
  23893. t['\uFD9E'] = '\u0628\u062E\u064A';
  23894. t['\uFD9F'] = '\u062A\u062C\u064A';
  23895. t['\uFDA0'] = '\u062A\u062C\u0649';
  23896. t['\uFDA1'] = '\u062A\u062E\u064A';
  23897. t['\uFDA2'] = '\u062A\u062E\u0649';
  23898. t['\uFDA3'] = '\u062A\u0645\u064A';
  23899. t['\uFDA4'] = '\u062A\u0645\u0649';
  23900. t['\uFDA5'] = '\u062C\u0645\u064A';
  23901. t['\uFDA6'] = '\u062C\u062D\u0649';
  23902. t['\uFDA7'] = '\u062C\u0645\u0649';
  23903. t['\uFDA8'] = '\u0633\u062E\u0649';
  23904. t['\uFDA9'] = '\u0635\u062D\u064A';
  23905. t['\uFDAA'] = '\u0634\u062D\u064A';
  23906. t['\uFDAB'] = '\u0636\u062D\u064A';
  23907. t['\uFDAC'] = '\u0644\u062C\u064A';
  23908. t['\uFDAD'] = '\u0644\u0645\u064A';
  23909. t['\uFDAE'] = '\u064A\u062D\u064A';
  23910. t['\uFDAF'] = '\u064A\u062C\u064A';
  23911. t['\uFDB0'] = '\u064A\u0645\u064A';
  23912. t['\uFDB1'] = '\u0645\u0645\u064A';
  23913. t['\uFDB2'] = '\u0642\u0645\u064A';
  23914. t['\uFDB3'] = '\u0646\u062D\u064A';
  23915. t['\uFDB4'] = '\u0642\u0645\u062D';
  23916. t['\uFDB5'] = '\u0644\u062D\u0645';
  23917. t['\uFDB6'] = '\u0639\u0645\u064A';
  23918. t['\uFDB7'] = '\u0643\u0645\u064A';
  23919. t['\uFDB8'] = '\u0646\u062C\u062D';
  23920. t['\uFDB9'] = '\u0645\u062E\u064A';
  23921. t['\uFDBA'] = '\u0644\u062C\u0645';
  23922. t['\uFDBB'] = '\u0643\u0645\u0645';
  23923. t['\uFDBC'] = '\u0644\u062C\u0645';
  23924. t['\uFDBD'] = '\u0646\u062C\u062D';
  23925. t['\uFDBE'] = '\u062C\u062D\u064A';
  23926. t['\uFDBF'] = '\u062D\u062C\u064A';
  23927. t['\uFDC0'] = '\u0645\u062C\u064A';
  23928. t['\uFDC1'] = '\u0641\u0645\u064A';
  23929. t['\uFDC2'] = '\u0628\u062D\u064A';
  23930. t['\uFDC3'] = '\u0643\u0645\u0645';
  23931. t['\uFDC4'] = '\u0639\u062C\u0645';
  23932. t['\uFDC5'] = '\u0635\u0645\u0645';
  23933. t['\uFDC6'] = '\u0633\u062E\u064A';
  23934. t['\uFDC7'] = '\u0646\u062C\u064A';
  23935. t['\uFE49'] = '\u203E';
  23936. t['\uFE4A'] = '\u203E';
  23937. t['\uFE4B'] = '\u203E';
  23938. t['\uFE4C'] = '\u203E';
  23939. t['\uFE4D'] = '\u005F';
  23940. t['\uFE4E'] = '\u005F';
  23941. t['\uFE4F'] = '\u005F';
  23942. t['\uFE80'] = '\u0621';
  23943. t['\uFE81'] = '\u0622';
  23944. t['\uFE82'] = '\u0622';
  23945. t['\uFE83'] = '\u0623';
  23946. t['\uFE84'] = '\u0623';
  23947. t['\uFE85'] = '\u0624';
  23948. t['\uFE86'] = '\u0624';
  23949. t['\uFE87'] = '\u0625';
  23950. t['\uFE88'] = '\u0625';
  23951. t['\uFE89'] = '\u0626';
  23952. t['\uFE8A'] = '\u0626';
  23953. t['\uFE8B'] = '\u0626';
  23954. t['\uFE8C'] = '\u0626';
  23955. t['\uFE8D'] = '\u0627';
  23956. t['\uFE8E'] = '\u0627';
  23957. t['\uFE8F'] = '\u0628';
  23958. t['\uFE90'] = '\u0628';
  23959. t['\uFE91'] = '\u0628';
  23960. t['\uFE92'] = '\u0628';
  23961. t['\uFE93'] = '\u0629';
  23962. t['\uFE94'] = '\u0629';
  23963. t['\uFE95'] = '\u062A';
  23964. t['\uFE96'] = '\u062A';
  23965. t['\uFE97'] = '\u062A';
  23966. t['\uFE98'] = '\u062A';
  23967. t['\uFE99'] = '\u062B';
  23968. t['\uFE9A'] = '\u062B';
  23969. t['\uFE9B'] = '\u062B';
  23970. t['\uFE9C'] = '\u062B';
  23971. t['\uFE9D'] = '\u062C';
  23972. t['\uFE9E'] = '\u062C';
  23973. t['\uFE9F'] = '\u062C';
  23974. t['\uFEA0'] = '\u062C';
  23975. t['\uFEA1'] = '\u062D';
  23976. t['\uFEA2'] = '\u062D';
  23977. t['\uFEA3'] = '\u062D';
  23978. t['\uFEA4'] = '\u062D';
  23979. t['\uFEA5'] = '\u062E';
  23980. t['\uFEA6'] = '\u062E';
  23981. t['\uFEA7'] = '\u062E';
  23982. t['\uFEA8'] = '\u062E';
  23983. t['\uFEA9'] = '\u062F';
  23984. t['\uFEAA'] = '\u062F';
  23985. t['\uFEAB'] = '\u0630';
  23986. t['\uFEAC'] = '\u0630';
  23987. t['\uFEAD'] = '\u0631';
  23988. t['\uFEAE'] = '\u0631';
  23989. t['\uFEAF'] = '\u0632';
  23990. t['\uFEB0'] = '\u0632';
  23991. t['\uFEB1'] = '\u0633';
  23992. t['\uFEB2'] = '\u0633';
  23993. t['\uFEB3'] = '\u0633';
  23994. t['\uFEB4'] = '\u0633';
  23995. t['\uFEB5'] = '\u0634';
  23996. t['\uFEB6'] = '\u0634';
  23997. t['\uFEB7'] = '\u0634';
  23998. t['\uFEB8'] = '\u0634';
  23999. t['\uFEB9'] = '\u0635';
  24000. t['\uFEBA'] = '\u0635';
  24001. t['\uFEBB'] = '\u0635';
  24002. t['\uFEBC'] = '\u0635';
  24003. t['\uFEBD'] = '\u0636';
  24004. t['\uFEBE'] = '\u0636';
  24005. t['\uFEBF'] = '\u0636';
  24006. t['\uFEC0'] = '\u0636';
  24007. t['\uFEC1'] = '\u0637';
  24008. t['\uFEC2'] = '\u0637';
  24009. t['\uFEC3'] = '\u0637';
  24010. t['\uFEC4'] = '\u0637';
  24011. t['\uFEC5'] = '\u0638';
  24012. t['\uFEC6'] = '\u0638';
  24013. t['\uFEC7'] = '\u0638';
  24014. t['\uFEC8'] = '\u0638';
  24015. t['\uFEC9'] = '\u0639';
  24016. t['\uFECA'] = '\u0639';
  24017. t['\uFECB'] = '\u0639';
  24018. t['\uFECC'] = '\u0639';
  24019. t['\uFECD'] = '\u063A';
  24020. t['\uFECE'] = '\u063A';
  24021. t['\uFECF'] = '\u063A';
  24022. t['\uFED0'] = '\u063A';
  24023. t['\uFED1'] = '\u0641';
  24024. t['\uFED2'] = '\u0641';
  24025. t['\uFED3'] = '\u0641';
  24026. t['\uFED4'] = '\u0641';
  24027. t['\uFED5'] = '\u0642';
  24028. t['\uFED6'] = '\u0642';
  24029. t['\uFED7'] = '\u0642';
  24030. t['\uFED8'] = '\u0642';
  24031. t['\uFED9'] = '\u0643';
  24032. t['\uFEDA'] = '\u0643';
  24033. t['\uFEDB'] = '\u0643';
  24034. t['\uFEDC'] = '\u0643';
  24035. t['\uFEDD'] = '\u0644';
  24036. t['\uFEDE'] = '\u0644';
  24037. t['\uFEDF'] = '\u0644';
  24038. t['\uFEE0'] = '\u0644';
  24039. t['\uFEE1'] = '\u0645';
  24040. t['\uFEE2'] = '\u0645';
  24041. t['\uFEE3'] = '\u0645';
  24042. t['\uFEE4'] = '\u0645';
  24043. t['\uFEE5'] = '\u0646';
  24044. t['\uFEE6'] = '\u0646';
  24045. t['\uFEE7'] = '\u0646';
  24046. t['\uFEE8'] = '\u0646';
  24047. t['\uFEE9'] = '\u0647';
  24048. t['\uFEEA'] = '\u0647';
  24049. t['\uFEEB'] = '\u0647';
  24050. t['\uFEEC'] = '\u0647';
  24051. t['\uFEED'] = '\u0648';
  24052. t['\uFEEE'] = '\u0648';
  24053. t['\uFEEF'] = '\u0649';
  24054. t['\uFEF0'] = '\u0649';
  24055. t['\uFEF1'] = '\u064A';
  24056. t['\uFEF2'] = '\u064A';
  24057. t['\uFEF3'] = '\u064A';
  24058. t['\uFEF4'] = '\u064A';
  24059. t['\uFEF5'] = '\u0644\u0622';
  24060. t['\uFEF6'] = '\u0644\u0622';
  24061. t['\uFEF7'] = '\u0644\u0623';
  24062. t['\uFEF8'] = '\u0644\u0623';
  24063. t['\uFEF9'] = '\u0644\u0625';
  24064. t['\uFEFA'] = '\u0644\u0625';
  24065. t['\uFEFB'] = '\u0644\u0627';
  24066. t['\uFEFC'] = '\u0644\u0627';
  24067. });
  24068. function reverseIfRtl(chars) {
  24069. var charsLength = chars.length;
  24070. //reverse an arabic ligature
  24071. if (charsLength <= 1 || !isRTLRangeFor(chars.charCodeAt(0))) {
  24072. return chars;
  24073. }
  24074. var s = '';
  24075. for (var ii = charsLength - 1; ii >= 0; ii--) {
  24076. s += chars[ii];
  24077. }
  24078. return s;
  24079. }
  24080. exports.mapSpecialUnicodeValues = mapSpecialUnicodeValues;
  24081. exports.reverseIfRtl = reverseIfRtl;
  24082. exports.getUnicodeRangeFor = getUnicodeRangeFor;
  24083. exports.getNormalizedUnicodes = getNormalizedUnicodes;
  24084. exports.getUnicodeForGlyph = getUnicodeForGlyph;
  24085. }));
  24086. (function (root, factory) {
  24087. factory(root.pdfjsCoreStream = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCoreJbig2, root.pdfjsCoreJpg, root.pdfjsCoreJpx);
  24088. }(this, function (exports, sharedUtil, corePrimitives, coreJbig2, coreJpg, coreJpx) {
  24089. var Util = sharedUtil.Util;
  24090. var error = sharedUtil.error;
  24091. var info = sharedUtil.info;
  24092. var isInt = sharedUtil.isInt;
  24093. var isArray = sharedUtil.isArray;
  24094. var createObjectURL = sharedUtil.createObjectURL;
  24095. var shadow = sharedUtil.shadow;
  24096. var warn = sharedUtil.warn;
  24097. var isSpace = sharedUtil.isSpace;
  24098. var Dict = corePrimitives.Dict;
  24099. var isDict = corePrimitives.isDict;
  24100. var isStream = corePrimitives.isStream;
  24101. var Jbig2Image = coreJbig2.Jbig2Image;
  24102. var JpegImage = coreJpg.JpegImage;
  24103. var JpxImage = coreJpx.JpxImage;
  24104. var Stream = function StreamClosure() {
  24105. function Stream(arrayBuffer, start, length, dict) {
  24106. this.bytes = arrayBuffer instanceof Uint8Array ? arrayBuffer : new Uint8Array(arrayBuffer);
  24107. this.start = start || 0;
  24108. this.pos = this.start;
  24109. this.end = start + length || this.bytes.length;
  24110. this.dict = dict;
  24111. }
  24112. // required methods for a stream. if a particular stream does not
  24113. // implement these, an error should be thrown
  24114. Stream.prototype = {
  24115. get length() {
  24116. return this.end - this.start;
  24117. },
  24118. get isEmpty() {
  24119. return this.length === 0;
  24120. },
  24121. getByte: function Stream_getByte() {
  24122. if (this.pos >= this.end) {
  24123. return -1;
  24124. }
  24125. return this.bytes[this.pos++];
  24126. },
  24127. getUint16: function Stream_getUint16() {
  24128. var b0 = this.getByte();
  24129. var b1 = this.getByte();
  24130. if (b0 === -1 || b1 === -1) {
  24131. return -1;
  24132. }
  24133. return (b0 << 8) + b1;
  24134. },
  24135. getInt32: function Stream_getInt32() {
  24136. var b0 = this.getByte();
  24137. var b1 = this.getByte();
  24138. var b2 = this.getByte();
  24139. var b3 = this.getByte();
  24140. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  24141. },
  24142. // returns subarray of original buffer
  24143. // should only be read
  24144. getBytes: function Stream_getBytes(length) {
  24145. var bytes = this.bytes;
  24146. var pos = this.pos;
  24147. var strEnd = this.end;
  24148. if (!length) {
  24149. return bytes.subarray(pos, strEnd);
  24150. }
  24151. var end = pos + length;
  24152. if (end > strEnd) {
  24153. end = strEnd;
  24154. }
  24155. this.pos = end;
  24156. return bytes.subarray(pos, end);
  24157. },
  24158. peekByte: function Stream_peekByte() {
  24159. var peekedByte = this.getByte();
  24160. this.pos--;
  24161. return peekedByte;
  24162. },
  24163. peekBytes: function Stream_peekBytes(length) {
  24164. var bytes = this.getBytes(length);
  24165. this.pos -= bytes.length;
  24166. return bytes;
  24167. },
  24168. skip: function Stream_skip(n) {
  24169. if (!n) {
  24170. n = 1;
  24171. }
  24172. this.pos += n;
  24173. },
  24174. reset: function Stream_reset() {
  24175. this.pos = this.start;
  24176. },
  24177. moveStart: function Stream_moveStart() {
  24178. this.start = this.pos;
  24179. },
  24180. makeSubStream: function Stream_makeSubStream(start, length, dict) {
  24181. return new Stream(this.bytes.buffer, start, length, dict);
  24182. },
  24183. isStream: true
  24184. };
  24185. return Stream;
  24186. }();
  24187. var StringStream = function StringStreamClosure() {
  24188. function StringStream(str) {
  24189. var length = str.length;
  24190. var bytes = new Uint8Array(length);
  24191. for (var n = 0; n < length; ++n) {
  24192. bytes[n] = str.charCodeAt(n);
  24193. }
  24194. Stream.call(this, bytes);
  24195. }
  24196. StringStream.prototype = Stream.prototype;
  24197. return StringStream;
  24198. }();
  24199. // super class for the decoding streams
  24200. var DecodeStream = function DecodeStreamClosure() {
  24201. // Lots of DecodeStreams are created whose buffers are never used. For these
  24202. // we share a single empty buffer. This is (a) space-efficient and (b) avoids
  24203. // having special cases that would be required if we used |null| for an empty
  24204. // buffer.
  24205. var emptyBuffer = new Uint8Array(0);
  24206. function DecodeStream(maybeMinBufferLength) {
  24207. this.pos = 0;
  24208. this.bufferLength = 0;
  24209. this.eof = false;
  24210. this.buffer = emptyBuffer;
  24211. this.minBufferLength = 512;
  24212. if (maybeMinBufferLength) {
  24213. // Compute the first power of two that is as big as maybeMinBufferLength.
  24214. while (this.minBufferLength < maybeMinBufferLength) {
  24215. this.minBufferLength *= 2;
  24216. }
  24217. }
  24218. }
  24219. DecodeStream.prototype = {
  24220. get isEmpty() {
  24221. while (!this.eof && this.bufferLength === 0) {
  24222. this.readBlock();
  24223. }
  24224. return this.bufferLength === 0;
  24225. },
  24226. ensureBuffer: function DecodeStream_ensureBuffer(requested) {
  24227. var buffer = this.buffer;
  24228. if (requested <= buffer.byteLength) {
  24229. return buffer;
  24230. }
  24231. var size = this.minBufferLength;
  24232. while (size < requested) {
  24233. size *= 2;
  24234. }
  24235. var buffer2 = new Uint8Array(size);
  24236. buffer2.set(buffer);
  24237. return this.buffer = buffer2;
  24238. },
  24239. getByte: function DecodeStream_getByte() {
  24240. var pos = this.pos;
  24241. while (this.bufferLength <= pos) {
  24242. if (this.eof) {
  24243. return -1;
  24244. }
  24245. this.readBlock();
  24246. }
  24247. return this.buffer[this.pos++];
  24248. },
  24249. getUint16: function DecodeStream_getUint16() {
  24250. var b0 = this.getByte();
  24251. var b1 = this.getByte();
  24252. if (b0 === -1 || b1 === -1) {
  24253. return -1;
  24254. }
  24255. return (b0 << 8) + b1;
  24256. },
  24257. getInt32: function DecodeStream_getInt32() {
  24258. var b0 = this.getByte();
  24259. var b1 = this.getByte();
  24260. var b2 = this.getByte();
  24261. var b3 = this.getByte();
  24262. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  24263. },
  24264. getBytes: function DecodeStream_getBytes(length) {
  24265. var end, pos = this.pos;
  24266. if (length) {
  24267. this.ensureBuffer(pos + length);
  24268. end = pos + length;
  24269. while (!this.eof && this.bufferLength < end) {
  24270. this.readBlock();
  24271. }
  24272. var bufEnd = this.bufferLength;
  24273. if (end > bufEnd) {
  24274. end = bufEnd;
  24275. }
  24276. } else {
  24277. while (!this.eof) {
  24278. this.readBlock();
  24279. }
  24280. end = this.bufferLength;
  24281. }
  24282. this.pos = end;
  24283. return this.buffer.subarray(pos, end);
  24284. },
  24285. peekByte: function DecodeStream_peekByte() {
  24286. var peekedByte = this.getByte();
  24287. this.pos--;
  24288. return peekedByte;
  24289. },
  24290. peekBytes: function DecodeStream_peekBytes(length) {
  24291. var bytes = this.getBytes(length);
  24292. this.pos -= bytes.length;
  24293. return bytes;
  24294. },
  24295. makeSubStream: function DecodeStream_makeSubStream(start, length, dict) {
  24296. var end = start + length;
  24297. while (this.bufferLength <= end && !this.eof) {
  24298. this.readBlock();
  24299. }
  24300. return new Stream(this.buffer, start, length, dict);
  24301. },
  24302. skip: function DecodeStream_skip(n) {
  24303. if (!n) {
  24304. n = 1;
  24305. }
  24306. this.pos += n;
  24307. },
  24308. reset: function DecodeStream_reset() {
  24309. this.pos = 0;
  24310. },
  24311. getBaseStreams: function DecodeStream_getBaseStreams() {
  24312. if (this.str && this.str.getBaseStreams) {
  24313. return this.str.getBaseStreams();
  24314. }
  24315. return [];
  24316. }
  24317. };
  24318. return DecodeStream;
  24319. }();
  24320. var StreamsSequenceStream = function StreamsSequenceStreamClosure() {
  24321. function StreamsSequenceStream(streams) {
  24322. this.streams = streams;
  24323. DecodeStream.call(this, /* maybeLength = */
  24324. null);
  24325. }
  24326. StreamsSequenceStream.prototype = Object.create(DecodeStream.prototype);
  24327. StreamsSequenceStream.prototype.readBlock = function streamSequenceStreamReadBlock() {
  24328. var streams = this.streams;
  24329. if (streams.length === 0) {
  24330. this.eof = true;
  24331. return;
  24332. }
  24333. var stream = streams.shift();
  24334. var chunk = stream.getBytes();
  24335. var bufferLength = this.bufferLength;
  24336. var newLength = bufferLength + chunk.length;
  24337. var buffer = this.ensureBuffer(newLength);
  24338. buffer.set(chunk, bufferLength);
  24339. this.bufferLength = newLength;
  24340. };
  24341. StreamsSequenceStream.prototype.getBaseStreams = function StreamsSequenceStream_getBaseStreams() {
  24342. var baseStreams = [];
  24343. for (var i = 0, ii = this.streams.length; i < ii; i++) {
  24344. var stream = this.streams[i];
  24345. if (stream.getBaseStreams) {
  24346. Util.appendToArray(baseStreams, stream.getBaseStreams());
  24347. }
  24348. }
  24349. return baseStreams;
  24350. };
  24351. return StreamsSequenceStream;
  24352. }();
  24353. var FlateStream = function FlateStreamClosure() {
  24354. var codeLenCodeMap = new Int32Array([
  24355. 16,
  24356. 17,
  24357. 18,
  24358. 0,
  24359. 8,
  24360. 7,
  24361. 9,
  24362. 6,
  24363. 10,
  24364. 5,
  24365. 11,
  24366. 4,
  24367. 12,
  24368. 3,
  24369. 13,
  24370. 2,
  24371. 14,
  24372. 1,
  24373. 15
  24374. ]);
  24375. var lengthDecode = new Int32Array([
  24376. 0x00003,
  24377. 0x00004,
  24378. 0x00005,
  24379. 0x00006,
  24380. 0x00007,
  24381. 0x00008,
  24382. 0x00009,
  24383. 0x0000a,
  24384. 0x1000b,
  24385. 0x1000d,
  24386. 0x1000f,
  24387. 0x10011,
  24388. 0x20013,
  24389. 0x20017,
  24390. 0x2001b,
  24391. 0x2001f,
  24392. 0x30023,
  24393. 0x3002b,
  24394. 0x30033,
  24395. 0x3003b,
  24396. 0x40043,
  24397. 0x40053,
  24398. 0x40063,
  24399. 0x40073,
  24400. 0x50083,
  24401. 0x500a3,
  24402. 0x500c3,
  24403. 0x500e3,
  24404. 0x00102,
  24405. 0x00102,
  24406. 0x00102
  24407. ]);
  24408. var distDecode = new Int32Array([
  24409. 0x00001,
  24410. 0x00002,
  24411. 0x00003,
  24412. 0x00004,
  24413. 0x10005,
  24414. 0x10007,
  24415. 0x20009,
  24416. 0x2000d,
  24417. 0x30011,
  24418. 0x30019,
  24419. 0x40021,
  24420. 0x40031,
  24421. 0x50041,
  24422. 0x50061,
  24423. 0x60081,
  24424. 0x600c1,
  24425. 0x70101,
  24426. 0x70181,
  24427. 0x80201,
  24428. 0x80301,
  24429. 0x90401,
  24430. 0x90601,
  24431. 0xa0801,
  24432. 0xa0c01,
  24433. 0xb1001,
  24434. 0xb1801,
  24435. 0xc2001,
  24436. 0xc3001,
  24437. 0xd4001,
  24438. 0xd6001
  24439. ]);
  24440. var fixedLitCodeTab = [
  24441. new Int32Array([
  24442. 0x70100,
  24443. 0x80050,
  24444. 0x80010,
  24445. 0x80118,
  24446. 0x70110,
  24447. 0x80070,
  24448. 0x80030,
  24449. 0x900c0,
  24450. 0x70108,
  24451. 0x80060,
  24452. 0x80020,
  24453. 0x900a0,
  24454. 0x80000,
  24455. 0x80080,
  24456. 0x80040,
  24457. 0x900e0,
  24458. 0x70104,
  24459. 0x80058,
  24460. 0x80018,
  24461. 0x90090,
  24462. 0x70114,
  24463. 0x80078,
  24464. 0x80038,
  24465. 0x900d0,
  24466. 0x7010c,
  24467. 0x80068,
  24468. 0x80028,
  24469. 0x900b0,
  24470. 0x80008,
  24471. 0x80088,
  24472. 0x80048,
  24473. 0x900f0,
  24474. 0x70102,
  24475. 0x80054,
  24476. 0x80014,
  24477. 0x8011c,
  24478. 0x70112,
  24479. 0x80074,
  24480. 0x80034,
  24481. 0x900c8,
  24482. 0x7010a,
  24483. 0x80064,
  24484. 0x80024,
  24485. 0x900a8,
  24486. 0x80004,
  24487. 0x80084,
  24488. 0x80044,
  24489. 0x900e8,
  24490. 0x70106,
  24491. 0x8005c,
  24492. 0x8001c,
  24493. 0x90098,
  24494. 0x70116,
  24495. 0x8007c,
  24496. 0x8003c,
  24497. 0x900d8,
  24498. 0x7010e,
  24499. 0x8006c,
  24500. 0x8002c,
  24501. 0x900b8,
  24502. 0x8000c,
  24503. 0x8008c,
  24504. 0x8004c,
  24505. 0x900f8,
  24506. 0x70101,
  24507. 0x80052,
  24508. 0x80012,
  24509. 0x8011a,
  24510. 0x70111,
  24511. 0x80072,
  24512. 0x80032,
  24513. 0x900c4,
  24514. 0x70109,
  24515. 0x80062,
  24516. 0x80022,
  24517. 0x900a4,
  24518. 0x80002,
  24519. 0x80082,
  24520. 0x80042,
  24521. 0x900e4,
  24522. 0x70105,
  24523. 0x8005a,
  24524. 0x8001a,
  24525. 0x90094,
  24526. 0x70115,
  24527. 0x8007a,
  24528. 0x8003a,
  24529. 0x900d4,
  24530. 0x7010d,
  24531. 0x8006a,
  24532. 0x8002a,
  24533. 0x900b4,
  24534. 0x8000a,
  24535. 0x8008a,
  24536. 0x8004a,
  24537. 0x900f4,
  24538. 0x70103,
  24539. 0x80056,
  24540. 0x80016,
  24541. 0x8011e,
  24542. 0x70113,
  24543. 0x80076,
  24544. 0x80036,
  24545. 0x900cc,
  24546. 0x7010b,
  24547. 0x80066,
  24548. 0x80026,
  24549. 0x900ac,
  24550. 0x80006,
  24551. 0x80086,
  24552. 0x80046,
  24553. 0x900ec,
  24554. 0x70107,
  24555. 0x8005e,
  24556. 0x8001e,
  24557. 0x9009c,
  24558. 0x70117,
  24559. 0x8007e,
  24560. 0x8003e,
  24561. 0x900dc,
  24562. 0x7010f,
  24563. 0x8006e,
  24564. 0x8002e,
  24565. 0x900bc,
  24566. 0x8000e,
  24567. 0x8008e,
  24568. 0x8004e,
  24569. 0x900fc,
  24570. 0x70100,
  24571. 0x80051,
  24572. 0x80011,
  24573. 0x80119,
  24574. 0x70110,
  24575. 0x80071,
  24576. 0x80031,
  24577. 0x900c2,
  24578. 0x70108,
  24579. 0x80061,
  24580. 0x80021,
  24581. 0x900a2,
  24582. 0x80001,
  24583. 0x80081,
  24584. 0x80041,
  24585. 0x900e2,
  24586. 0x70104,
  24587. 0x80059,
  24588. 0x80019,
  24589. 0x90092,
  24590. 0x70114,
  24591. 0x80079,
  24592. 0x80039,
  24593. 0x900d2,
  24594. 0x7010c,
  24595. 0x80069,
  24596. 0x80029,
  24597. 0x900b2,
  24598. 0x80009,
  24599. 0x80089,
  24600. 0x80049,
  24601. 0x900f2,
  24602. 0x70102,
  24603. 0x80055,
  24604. 0x80015,
  24605. 0x8011d,
  24606. 0x70112,
  24607. 0x80075,
  24608. 0x80035,
  24609. 0x900ca,
  24610. 0x7010a,
  24611. 0x80065,
  24612. 0x80025,
  24613. 0x900aa,
  24614. 0x80005,
  24615. 0x80085,
  24616. 0x80045,
  24617. 0x900ea,
  24618. 0x70106,
  24619. 0x8005d,
  24620. 0x8001d,
  24621. 0x9009a,
  24622. 0x70116,
  24623. 0x8007d,
  24624. 0x8003d,
  24625. 0x900da,
  24626. 0x7010e,
  24627. 0x8006d,
  24628. 0x8002d,
  24629. 0x900ba,
  24630. 0x8000d,
  24631. 0x8008d,
  24632. 0x8004d,
  24633. 0x900fa,
  24634. 0x70101,
  24635. 0x80053,
  24636. 0x80013,
  24637. 0x8011b,
  24638. 0x70111,
  24639. 0x80073,
  24640. 0x80033,
  24641. 0x900c6,
  24642. 0x70109,
  24643. 0x80063,
  24644. 0x80023,
  24645. 0x900a6,
  24646. 0x80003,
  24647. 0x80083,
  24648. 0x80043,
  24649. 0x900e6,
  24650. 0x70105,
  24651. 0x8005b,
  24652. 0x8001b,
  24653. 0x90096,
  24654. 0x70115,
  24655. 0x8007b,
  24656. 0x8003b,
  24657. 0x900d6,
  24658. 0x7010d,
  24659. 0x8006b,
  24660. 0x8002b,
  24661. 0x900b6,
  24662. 0x8000b,
  24663. 0x8008b,
  24664. 0x8004b,
  24665. 0x900f6,
  24666. 0x70103,
  24667. 0x80057,
  24668. 0x80017,
  24669. 0x8011f,
  24670. 0x70113,
  24671. 0x80077,
  24672. 0x80037,
  24673. 0x900ce,
  24674. 0x7010b,
  24675. 0x80067,
  24676. 0x80027,
  24677. 0x900ae,
  24678. 0x80007,
  24679. 0x80087,
  24680. 0x80047,
  24681. 0x900ee,
  24682. 0x70107,
  24683. 0x8005f,
  24684. 0x8001f,
  24685. 0x9009e,
  24686. 0x70117,
  24687. 0x8007f,
  24688. 0x8003f,
  24689. 0x900de,
  24690. 0x7010f,
  24691. 0x8006f,
  24692. 0x8002f,
  24693. 0x900be,
  24694. 0x8000f,
  24695. 0x8008f,
  24696. 0x8004f,
  24697. 0x900fe,
  24698. 0x70100,
  24699. 0x80050,
  24700. 0x80010,
  24701. 0x80118,
  24702. 0x70110,
  24703. 0x80070,
  24704. 0x80030,
  24705. 0x900c1,
  24706. 0x70108,
  24707. 0x80060,
  24708. 0x80020,
  24709. 0x900a1,
  24710. 0x80000,
  24711. 0x80080,
  24712. 0x80040,
  24713. 0x900e1,
  24714. 0x70104,
  24715. 0x80058,
  24716. 0x80018,
  24717. 0x90091,
  24718. 0x70114,
  24719. 0x80078,
  24720. 0x80038,
  24721. 0x900d1,
  24722. 0x7010c,
  24723. 0x80068,
  24724. 0x80028,
  24725. 0x900b1,
  24726. 0x80008,
  24727. 0x80088,
  24728. 0x80048,
  24729. 0x900f1,
  24730. 0x70102,
  24731. 0x80054,
  24732. 0x80014,
  24733. 0x8011c,
  24734. 0x70112,
  24735. 0x80074,
  24736. 0x80034,
  24737. 0x900c9,
  24738. 0x7010a,
  24739. 0x80064,
  24740. 0x80024,
  24741. 0x900a9,
  24742. 0x80004,
  24743. 0x80084,
  24744. 0x80044,
  24745. 0x900e9,
  24746. 0x70106,
  24747. 0x8005c,
  24748. 0x8001c,
  24749. 0x90099,
  24750. 0x70116,
  24751. 0x8007c,
  24752. 0x8003c,
  24753. 0x900d9,
  24754. 0x7010e,
  24755. 0x8006c,
  24756. 0x8002c,
  24757. 0x900b9,
  24758. 0x8000c,
  24759. 0x8008c,
  24760. 0x8004c,
  24761. 0x900f9,
  24762. 0x70101,
  24763. 0x80052,
  24764. 0x80012,
  24765. 0x8011a,
  24766. 0x70111,
  24767. 0x80072,
  24768. 0x80032,
  24769. 0x900c5,
  24770. 0x70109,
  24771. 0x80062,
  24772. 0x80022,
  24773. 0x900a5,
  24774. 0x80002,
  24775. 0x80082,
  24776. 0x80042,
  24777. 0x900e5,
  24778. 0x70105,
  24779. 0x8005a,
  24780. 0x8001a,
  24781. 0x90095,
  24782. 0x70115,
  24783. 0x8007a,
  24784. 0x8003a,
  24785. 0x900d5,
  24786. 0x7010d,
  24787. 0x8006a,
  24788. 0x8002a,
  24789. 0x900b5,
  24790. 0x8000a,
  24791. 0x8008a,
  24792. 0x8004a,
  24793. 0x900f5,
  24794. 0x70103,
  24795. 0x80056,
  24796. 0x80016,
  24797. 0x8011e,
  24798. 0x70113,
  24799. 0x80076,
  24800. 0x80036,
  24801. 0x900cd,
  24802. 0x7010b,
  24803. 0x80066,
  24804. 0x80026,
  24805. 0x900ad,
  24806. 0x80006,
  24807. 0x80086,
  24808. 0x80046,
  24809. 0x900ed,
  24810. 0x70107,
  24811. 0x8005e,
  24812. 0x8001e,
  24813. 0x9009d,
  24814. 0x70117,
  24815. 0x8007e,
  24816. 0x8003e,
  24817. 0x900dd,
  24818. 0x7010f,
  24819. 0x8006e,
  24820. 0x8002e,
  24821. 0x900bd,
  24822. 0x8000e,
  24823. 0x8008e,
  24824. 0x8004e,
  24825. 0x900fd,
  24826. 0x70100,
  24827. 0x80051,
  24828. 0x80011,
  24829. 0x80119,
  24830. 0x70110,
  24831. 0x80071,
  24832. 0x80031,
  24833. 0x900c3,
  24834. 0x70108,
  24835. 0x80061,
  24836. 0x80021,
  24837. 0x900a3,
  24838. 0x80001,
  24839. 0x80081,
  24840. 0x80041,
  24841. 0x900e3,
  24842. 0x70104,
  24843. 0x80059,
  24844. 0x80019,
  24845. 0x90093,
  24846. 0x70114,
  24847. 0x80079,
  24848. 0x80039,
  24849. 0x900d3,
  24850. 0x7010c,
  24851. 0x80069,
  24852. 0x80029,
  24853. 0x900b3,
  24854. 0x80009,
  24855. 0x80089,
  24856. 0x80049,
  24857. 0x900f3,
  24858. 0x70102,
  24859. 0x80055,
  24860. 0x80015,
  24861. 0x8011d,
  24862. 0x70112,
  24863. 0x80075,
  24864. 0x80035,
  24865. 0x900cb,
  24866. 0x7010a,
  24867. 0x80065,
  24868. 0x80025,
  24869. 0x900ab,
  24870. 0x80005,
  24871. 0x80085,
  24872. 0x80045,
  24873. 0x900eb,
  24874. 0x70106,
  24875. 0x8005d,
  24876. 0x8001d,
  24877. 0x9009b,
  24878. 0x70116,
  24879. 0x8007d,
  24880. 0x8003d,
  24881. 0x900db,
  24882. 0x7010e,
  24883. 0x8006d,
  24884. 0x8002d,
  24885. 0x900bb,
  24886. 0x8000d,
  24887. 0x8008d,
  24888. 0x8004d,
  24889. 0x900fb,
  24890. 0x70101,
  24891. 0x80053,
  24892. 0x80013,
  24893. 0x8011b,
  24894. 0x70111,
  24895. 0x80073,
  24896. 0x80033,
  24897. 0x900c7,
  24898. 0x70109,
  24899. 0x80063,
  24900. 0x80023,
  24901. 0x900a7,
  24902. 0x80003,
  24903. 0x80083,
  24904. 0x80043,
  24905. 0x900e7,
  24906. 0x70105,
  24907. 0x8005b,
  24908. 0x8001b,
  24909. 0x90097,
  24910. 0x70115,
  24911. 0x8007b,
  24912. 0x8003b,
  24913. 0x900d7,
  24914. 0x7010d,
  24915. 0x8006b,
  24916. 0x8002b,
  24917. 0x900b7,
  24918. 0x8000b,
  24919. 0x8008b,
  24920. 0x8004b,
  24921. 0x900f7,
  24922. 0x70103,
  24923. 0x80057,
  24924. 0x80017,
  24925. 0x8011f,
  24926. 0x70113,
  24927. 0x80077,
  24928. 0x80037,
  24929. 0x900cf,
  24930. 0x7010b,
  24931. 0x80067,
  24932. 0x80027,
  24933. 0x900af,
  24934. 0x80007,
  24935. 0x80087,
  24936. 0x80047,
  24937. 0x900ef,
  24938. 0x70107,
  24939. 0x8005f,
  24940. 0x8001f,
  24941. 0x9009f,
  24942. 0x70117,
  24943. 0x8007f,
  24944. 0x8003f,
  24945. 0x900df,
  24946. 0x7010f,
  24947. 0x8006f,
  24948. 0x8002f,
  24949. 0x900bf,
  24950. 0x8000f,
  24951. 0x8008f,
  24952. 0x8004f,
  24953. 0x900ff
  24954. ]),
  24955. 9
  24956. ];
  24957. var fixedDistCodeTab = [
  24958. new Int32Array([
  24959. 0x50000,
  24960. 0x50010,
  24961. 0x50008,
  24962. 0x50018,
  24963. 0x50004,
  24964. 0x50014,
  24965. 0x5000c,
  24966. 0x5001c,
  24967. 0x50002,
  24968. 0x50012,
  24969. 0x5000a,
  24970. 0x5001a,
  24971. 0x50006,
  24972. 0x50016,
  24973. 0x5000e,
  24974. 0x00000,
  24975. 0x50001,
  24976. 0x50011,
  24977. 0x50009,
  24978. 0x50019,
  24979. 0x50005,
  24980. 0x50015,
  24981. 0x5000d,
  24982. 0x5001d,
  24983. 0x50003,
  24984. 0x50013,
  24985. 0x5000b,
  24986. 0x5001b,
  24987. 0x50007,
  24988. 0x50017,
  24989. 0x5000f,
  24990. 0x00000
  24991. ]),
  24992. 5
  24993. ];
  24994. function FlateStream(str, maybeLength) {
  24995. this.str = str;
  24996. this.dict = str.dict;
  24997. var cmf = str.getByte();
  24998. var flg = str.getByte();
  24999. if (cmf === -1 || flg === -1) {
  25000. error('Invalid header in flate stream: ' + cmf + ', ' + flg);
  25001. }
  25002. if ((cmf & 0x0f) !== 0x08) {
  25003. error('Unknown compression method in flate stream: ' + cmf + ', ' + flg);
  25004. }
  25005. if (((cmf << 8) + flg) % 31 !== 0) {
  25006. error('Bad FCHECK in flate stream: ' + cmf + ', ' + flg);
  25007. }
  25008. if (flg & 0x20) {
  25009. error('FDICT bit set in flate stream: ' + cmf + ', ' + flg);
  25010. }
  25011. this.codeSize = 0;
  25012. this.codeBuf = 0;
  25013. DecodeStream.call(this, maybeLength);
  25014. }
  25015. FlateStream.prototype = Object.create(DecodeStream.prototype);
  25016. FlateStream.prototype.getBits = function FlateStream_getBits(bits) {
  25017. var str = this.str;
  25018. var codeSize = this.codeSize;
  25019. var codeBuf = this.codeBuf;
  25020. var b;
  25021. while (codeSize < bits) {
  25022. if ((b = str.getByte()) === -1) {
  25023. error('Bad encoding in flate stream');
  25024. }
  25025. codeBuf |= b << codeSize;
  25026. codeSize += 8;
  25027. }
  25028. b = codeBuf & (1 << bits) - 1;
  25029. this.codeBuf = codeBuf >> bits;
  25030. this.codeSize = codeSize -= bits;
  25031. return b;
  25032. };
  25033. FlateStream.prototype.getCode = function FlateStream_getCode(table) {
  25034. var str = this.str;
  25035. var codes = table[0];
  25036. var maxLen = table[1];
  25037. var codeSize = this.codeSize;
  25038. var codeBuf = this.codeBuf;
  25039. var b;
  25040. while (codeSize < maxLen) {
  25041. if ((b = str.getByte()) === -1) {
  25042. // premature end of stream. code might however still be valid.
  25043. // codeSize < codeLen check below guards against incomplete codeVal.
  25044. break;
  25045. }
  25046. codeBuf |= b << codeSize;
  25047. codeSize += 8;
  25048. }
  25049. var code = codes[codeBuf & (1 << maxLen) - 1];
  25050. var codeLen = code >> 16;
  25051. var codeVal = code & 0xffff;
  25052. if (codeLen < 1 || codeSize < codeLen) {
  25053. error('Bad encoding in flate stream');
  25054. }
  25055. this.codeBuf = codeBuf >> codeLen;
  25056. this.codeSize = codeSize - codeLen;
  25057. return codeVal;
  25058. };
  25059. FlateStream.prototype.generateHuffmanTable = function flateStreamGenerateHuffmanTable(lengths) {
  25060. var n = lengths.length;
  25061. // find max code length
  25062. var maxLen = 0;
  25063. var i;
  25064. for (i = 0; i < n; ++i) {
  25065. if (lengths[i] > maxLen) {
  25066. maxLen = lengths[i];
  25067. }
  25068. }
  25069. // build the table
  25070. var size = 1 << maxLen;
  25071. var codes = new Int32Array(size);
  25072. for (var len = 1, code = 0, skip = 2; len <= maxLen; ++len, code <<= 1, skip <<= 1) {
  25073. for (var val = 0; val < n; ++val) {
  25074. if (lengths[val] === len) {
  25075. // bit-reverse the code
  25076. var code2 = 0;
  25077. var t = code;
  25078. for (i = 0; i < len; ++i) {
  25079. code2 = code2 << 1 | t & 1;
  25080. t >>= 1;
  25081. }
  25082. // fill the table entries
  25083. for (i = code2; i < size; i += skip) {
  25084. codes[i] = len << 16 | val;
  25085. }
  25086. ++code;
  25087. }
  25088. }
  25089. }
  25090. return [
  25091. codes,
  25092. maxLen
  25093. ];
  25094. };
  25095. FlateStream.prototype.readBlock = function FlateStream_readBlock() {
  25096. var buffer, len;
  25097. var str = this.str;
  25098. // read block header
  25099. var hdr = this.getBits(3);
  25100. if (hdr & 1) {
  25101. this.eof = true;
  25102. }
  25103. hdr >>= 1;
  25104. if (hdr === 0) {
  25105. // uncompressed block
  25106. var b;
  25107. if ((b = str.getByte()) === -1) {
  25108. error('Bad block header in flate stream');
  25109. }
  25110. var blockLen = b;
  25111. if ((b = str.getByte()) === -1) {
  25112. error('Bad block header in flate stream');
  25113. }
  25114. blockLen |= b << 8;
  25115. if ((b = str.getByte()) === -1) {
  25116. error('Bad block header in flate stream');
  25117. }
  25118. var check = b;
  25119. if ((b = str.getByte()) === -1) {
  25120. error('Bad block header in flate stream');
  25121. }
  25122. check |= b << 8;
  25123. if (check !== (~blockLen & 0xffff) && (blockLen !== 0 || check !== 0)) {
  25124. // Ignoring error for bad "empty" block (see issue 1277)
  25125. error('Bad uncompressed block length in flate stream');
  25126. }
  25127. this.codeBuf = 0;
  25128. this.codeSize = 0;
  25129. var bufferLength = this.bufferLength;
  25130. buffer = this.ensureBuffer(bufferLength + blockLen);
  25131. var end = bufferLength + blockLen;
  25132. this.bufferLength = end;
  25133. if (blockLen === 0) {
  25134. if (str.peekByte() === -1) {
  25135. this.eof = true;
  25136. }
  25137. } else {
  25138. for (var n = bufferLength; n < end; ++n) {
  25139. if ((b = str.getByte()) === -1) {
  25140. this.eof = true;
  25141. break;
  25142. }
  25143. buffer[n] = b;
  25144. }
  25145. }
  25146. return;
  25147. }
  25148. var litCodeTable;
  25149. var distCodeTable;
  25150. if (hdr === 1) {
  25151. // compressed block, fixed codes
  25152. litCodeTable = fixedLitCodeTab;
  25153. distCodeTable = fixedDistCodeTab;
  25154. } else if (hdr === 2) {
  25155. // compressed block, dynamic codes
  25156. var numLitCodes = this.getBits(5) + 257;
  25157. var numDistCodes = this.getBits(5) + 1;
  25158. var numCodeLenCodes = this.getBits(4) + 4;
  25159. // build the code lengths code table
  25160. var codeLenCodeLengths = new Uint8Array(codeLenCodeMap.length);
  25161. var i;
  25162. for (i = 0; i < numCodeLenCodes; ++i) {
  25163. codeLenCodeLengths[codeLenCodeMap[i]] = this.getBits(3);
  25164. }
  25165. var codeLenCodeTab = this.generateHuffmanTable(codeLenCodeLengths);
  25166. // build the literal and distance code tables
  25167. len = 0;
  25168. i = 0;
  25169. var codes = numLitCodes + numDistCodes;
  25170. var codeLengths = new Uint8Array(codes);
  25171. var bitsLength, bitsOffset, what;
  25172. while (i < codes) {
  25173. var code = this.getCode(codeLenCodeTab);
  25174. if (code === 16) {
  25175. bitsLength = 2;
  25176. bitsOffset = 3;
  25177. what = len;
  25178. } else if (code === 17) {
  25179. bitsLength = 3;
  25180. bitsOffset = 3;
  25181. what = len = 0;
  25182. } else if (code === 18) {
  25183. bitsLength = 7;
  25184. bitsOffset = 11;
  25185. what = len = 0;
  25186. } else {
  25187. codeLengths[i++] = len = code;
  25188. continue;
  25189. }
  25190. var repeatLength = this.getBits(bitsLength) + bitsOffset;
  25191. while (repeatLength-- > 0) {
  25192. codeLengths[i++] = what;
  25193. }
  25194. }
  25195. litCodeTable = this.generateHuffmanTable(codeLengths.subarray(0, numLitCodes));
  25196. distCodeTable = this.generateHuffmanTable(codeLengths.subarray(numLitCodes, codes));
  25197. } else {
  25198. error('Unknown block type in flate stream');
  25199. }
  25200. buffer = this.buffer;
  25201. var limit = buffer ? buffer.length : 0;
  25202. var pos = this.bufferLength;
  25203. while (true) {
  25204. var code1 = this.getCode(litCodeTable);
  25205. if (code1 < 256) {
  25206. if (pos + 1 >= limit) {
  25207. buffer = this.ensureBuffer(pos + 1);
  25208. limit = buffer.length;
  25209. }
  25210. buffer[pos++] = code1;
  25211. continue;
  25212. }
  25213. if (code1 === 256) {
  25214. this.bufferLength = pos;
  25215. return;
  25216. }
  25217. code1 -= 257;
  25218. code1 = lengthDecode[code1];
  25219. var code2 = code1 >> 16;
  25220. if (code2 > 0) {
  25221. code2 = this.getBits(code2);
  25222. }
  25223. len = (code1 & 0xffff) + code2;
  25224. code1 = this.getCode(distCodeTable);
  25225. code1 = distDecode[code1];
  25226. code2 = code1 >> 16;
  25227. if (code2 > 0) {
  25228. code2 = this.getBits(code2);
  25229. }
  25230. var dist = (code1 & 0xffff) + code2;
  25231. if (pos + len >= limit) {
  25232. buffer = this.ensureBuffer(pos + len);
  25233. limit = buffer.length;
  25234. }
  25235. for (var k = 0; k < len; ++k, ++pos) {
  25236. buffer[pos] = buffer[pos - dist];
  25237. }
  25238. }
  25239. };
  25240. return FlateStream;
  25241. }();
  25242. var PredictorStream = function PredictorStreamClosure() {
  25243. function PredictorStream(str, maybeLength, params) {
  25244. if (!isDict(params)) {
  25245. return str;
  25246. }
  25247. // no prediction
  25248. var predictor = this.predictor = params.get('Predictor') || 1;
  25249. if (predictor <= 1) {
  25250. return str;
  25251. }
  25252. // no prediction
  25253. if (predictor !== 2 && (predictor < 10 || predictor > 15)) {
  25254. error('Unsupported predictor: ' + predictor);
  25255. }
  25256. if (predictor === 2) {
  25257. this.readBlock = this.readBlockTiff;
  25258. } else {
  25259. this.readBlock = this.readBlockPng;
  25260. }
  25261. this.str = str;
  25262. this.dict = str.dict;
  25263. var colors = this.colors = params.get('Colors') || 1;
  25264. var bits = this.bits = params.get('BitsPerComponent') || 8;
  25265. var columns = this.columns = params.get('Columns') || 1;
  25266. this.pixBytes = colors * bits + 7 >> 3;
  25267. this.rowBytes = columns * colors * bits + 7 >> 3;
  25268. DecodeStream.call(this, maybeLength);
  25269. return this;
  25270. }
  25271. PredictorStream.prototype = Object.create(DecodeStream.prototype);
  25272. PredictorStream.prototype.readBlockTiff = function predictorStreamReadBlockTiff() {
  25273. var rowBytes = this.rowBytes;
  25274. var bufferLength = this.bufferLength;
  25275. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  25276. var bits = this.bits;
  25277. var colors = this.colors;
  25278. var rawBytes = this.str.getBytes(rowBytes);
  25279. this.eof = !rawBytes.length;
  25280. if (this.eof) {
  25281. return;
  25282. }
  25283. var inbuf = 0, outbuf = 0;
  25284. var inbits = 0, outbits = 0;
  25285. var pos = bufferLength;
  25286. var i;
  25287. if (bits === 1) {
  25288. for (i = 0; i < rowBytes; ++i) {
  25289. var c = rawBytes[i];
  25290. inbuf = inbuf << 8 | c;
  25291. // bitwise addition is exclusive or
  25292. // first shift inbuf and then add
  25293. buffer[pos++] = (c ^ inbuf >> colors) & 0xFF;
  25294. // truncate inbuf (assumes colors < 16)
  25295. inbuf &= 0xFFFF;
  25296. }
  25297. } else if (bits === 8) {
  25298. for (i = 0; i < colors; ++i) {
  25299. buffer[pos++] = rawBytes[i];
  25300. }
  25301. for (; i < rowBytes; ++i) {
  25302. buffer[pos] = buffer[pos - colors] + rawBytes[i];
  25303. pos++;
  25304. }
  25305. } else {
  25306. var compArray = new Uint8Array(colors + 1);
  25307. var bitMask = (1 << bits) - 1;
  25308. var j = 0, k = bufferLength;
  25309. var columns = this.columns;
  25310. for (i = 0; i < columns; ++i) {
  25311. for (var kk = 0; kk < colors; ++kk) {
  25312. if (inbits < bits) {
  25313. inbuf = inbuf << 8 | rawBytes[j++] & 0xFF;
  25314. inbits += 8;
  25315. }
  25316. compArray[kk] = compArray[kk] + (inbuf >> inbits - bits) & bitMask;
  25317. inbits -= bits;
  25318. outbuf = outbuf << bits | compArray[kk];
  25319. outbits += bits;
  25320. if (outbits >= 8) {
  25321. buffer[k++] = outbuf >> outbits - 8 & 0xFF;
  25322. outbits -= 8;
  25323. }
  25324. }
  25325. }
  25326. if (outbits > 0) {
  25327. buffer[k++] = (outbuf << 8 - outbits) + (inbuf & (1 << 8 - outbits) - 1);
  25328. }
  25329. }
  25330. this.bufferLength += rowBytes;
  25331. };
  25332. PredictorStream.prototype.readBlockPng = function predictorStreamReadBlockPng() {
  25333. var rowBytes = this.rowBytes;
  25334. var pixBytes = this.pixBytes;
  25335. var predictor = this.str.getByte();
  25336. var rawBytes = this.str.getBytes(rowBytes);
  25337. this.eof = !rawBytes.length;
  25338. if (this.eof) {
  25339. return;
  25340. }
  25341. var bufferLength = this.bufferLength;
  25342. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  25343. var prevRow = buffer.subarray(bufferLength - rowBytes, bufferLength);
  25344. if (prevRow.length === 0) {
  25345. prevRow = new Uint8Array(rowBytes);
  25346. }
  25347. var i, j = bufferLength, up, c;
  25348. switch (predictor) {
  25349. case 0:
  25350. for (i = 0; i < rowBytes; ++i) {
  25351. buffer[j++] = rawBytes[i];
  25352. }
  25353. break;
  25354. case 1:
  25355. for (i = 0; i < pixBytes; ++i) {
  25356. buffer[j++] = rawBytes[i];
  25357. }
  25358. for (; i < rowBytes; ++i) {
  25359. buffer[j] = buffer[j - pixBytes] + rawBytes[i] & 0xFF;
  25360. j++;
  25361. }
  25362. break;
  25363. case 2:
  25364. for (i = 0; i < rowBytes; ++i) {
  25365. buffer[j++] = prevRow[i] + rawBytes[i] & 0xFF;
  25366. }
  25367. break;
  25368. case 3:
  25369. for (i = 0; i < pixBytes; ++i) {
  25370. buffer[j++] = (prevRow[i] >> 1) + rawBytes[i];
  25371. }
  25372. for (; i < rowBytes; ++i) {
  25373. buffer[j] = (prevRow[i] + buffer[j - pixBytes] >> 1) + rawBytes[i] & 0xFF;
  25374. j++;
  25375. }
  25376. break;
  25377. case 4:
  25378. // we need to save the up left pixels values. the simplest way
  25379. // is to create a new buffer
  25380. for (i = 0; i < pixBytes; ++i) {
  25381. up = prevRow[i];
  25382. c = rawBytes[i];
  25383. buffer[j++] = up + c;
  25384. }
  25385. for (; i < rowBytes; ++i) {
  25386. up = prevRow[i];
  25387. var upLeft = prevRow[i - pixBytes];
  25388. var left = buffer[j - pixBytes];
  25389. var p = left + up - upLeft;
  25390. var pa = p - left;
  25391. if (pa < 0) {
  25392. pa = -pa;
  25393. }
  25394. var pb = p - up;
  25395. if (pb < 0) {
  25396. pb = -pb;
  25397. }
  25398. var pc = p - upLeft;
  25399. if (pc < 0) {
  25400. pc = -pc;
  25401. }
  25402. c = rawBytes[i];
  25403. if (pa <= pb && pa <= pc) {
  25404. buffer[j++] = left + c;
  25405. } else if (pb <= pc) {
  25406. buffer[j++] = up + c;
  25407. } else {
  25408. buffer[j++] = upLeft + c;
  25409. }
  25410. }
  25411. break;
  25412. default:
  25413. error('Unsupported predictor: ' + predictor);
  25414. }
  25415. this.bufferLength += rowBytes;
  25416. };
  25417. return PredictorStream;
  25418. }();
  25419. /**
  25420. * Depending on the type of JPEG a JpegStream is handled in different ways. For
  25421. * JPEG's that are supported natively such as DeviceGray and DeviceRGB the image
  25422. * data is stored and then loaded by the browser. For unsupported JPEG's we use
  25423. * a library to decode these images and the stream behaves like all the other
  25424. * DecodeStreams.
  25425. */
  25426. var JpegStream = function JpegStreamClosure() {
  25427. function JpegStream(stream, maybeLength, dict, params) {
  25428. // Some images may contain 'junk' before the SOI (start-of-image) marker.
  25429. // Note: this seems to mainly affect inline images.
  25430. var ch;
  25431. while ((ch = stream.getByte()) !== -1) {
  25432. if (ch === 0xFF) {
  25433. // Find the first byte of the SOI marker (0xFFD8).
  25434. stream.skip(-1);
  25435. // Reset the stream position to the SOI.
  25436. break;
  25437. }
  25438. }
  25439. this.stream = stream;
  25440. this.maybeLength = maybeLength;
  25441. this.dict = dict;
  25442. this.params = params;
  25443. DecodeStream.call(this, maybeLength);
  25444. }
  25445. JpegStream.prototype = Object.create(DecodeStream.prototype);
  25446. Object.defineProperty(JpegStream.prototype, 'bytes', {
  25447. get: function JpegStream_bytes() {
  25448. // If this.maybeLength is null, we'll get the entire stream.
  25449. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  25450. },
  25451. configurable: true
  25452. });
  25453. JpegStream.prototype.ensureBuffer = function JpegStream_ensureBuffer(req) {
  25454. if (this.bufferLength) {
  25455. return;
  25456. }
  25457. var jpegImage = new JpegImage();
  25458. // Checking if values need to be transformed before conversion.
  25459. var decodeArr = this.dict.getArray('Decode', 'D');
  25460. if (this.forceRGB && isArray(decodeArr)) {
  25461. var bitsPerComponent = this.dict.get('BitsPerComponent') || 8;
  25462. var decodeArrLength = decodeArr.length;
  25463. var transform = new Int32Array(decodeArrLength);
  25464. var transformNeeded = false;
  25465. var maxValue = (1 << bitsPerComponent) - 1;
  25466. for (var i = 0; i < decodeArrLength; i += 2) {
  25467. transform[i] = (decodeArr[i + 1] - decodeArr[i]) * 256 | 0;
  25468. transform[i + 1] = decodeArr[i] * maxValue | 0;
  25469. if (transform[i] !== 256 || transform[i + 1] !== 0) {
  25470. transformNeeded = true;
  25471. }
  25472. }
  25473. if (transformNeeded) {
  25474. jpegImage.decodeTransform = transform;
  25475. }
  25476. }
  25477. // Fetching the 'ColorTransform' entry, if it exists.
  25478. if (isDict(this.params)) {
  25479. var colorTransform = this.params.get('ColorTransform');
  25480. if (isInt(colorTransform)) {
  25481. jpegImage.colorTransform = colorTransform;
  25482. }
  25483. }
  25484. jpegImage.parse(this.bytes);
  25485. var data = jpegImage.getData(this.drawWidth, this.drawHeight, this.forceRGB);
  25486. this.buffer = data;
  25487. this.bufferLength = data.length;
  25488. this.eof = true;
  25489. };
  25490. JpegStream.prototype.getBytes = function JpegStream_getBytes(length) {
  25491. this.ensureBuffer();
  25492. return this.buffer;
  25493. };
  25494. JpegStream.prototype.getIR = function JpegStream_getIR(forceDataSchema) {
  25495. return createObjectURL(this.bytes, 'image/jpeg', forceDataSchema);
  25496. };
  25497. return JpegStream;
  25498. }();
  25499. /**
  25500. * For JPEG 2000's we use a library to decode these images and
  25501. * the stream behaves like all the other DecodeStreams.
  25502. */
  25503. var JpxStream = function JpxStreamClosure() {
  25504. function JpxStream(stream, maybeLength, dict, params) {
  25505. this.stream = stream;
  25506. this.maybeLength = maybeLength;
  25507. this.dict = dict;
  25508. this.params = params;
  25509. DecodeStream.call(this, maybeLength);
  25510. }
  25511. JpxStream.prototype = Object.create(DecodeStream.prototype);
  25512. Object.defineProperty(JpxStream.prototype, 'bytes', {
  25513. get: function JpxStream_bytes() {
  25514. // If this.maybeLength is null, we'll get the entire stream.
  25515. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  25516. },
  25517. configurable: true
  25518. });
  25519. JpxStream.prototype.ensureBuffer = function JpxStream_ensureBuffer(req) {
  25520. if (this.bufferLength) {
  25521. return;
  25522. }
  25523. var jpxImage = new JpxImage();
  25524. jpxImage.parse(this.bytes);
  25525. var width = jpxImage.width;
  25526. var height = jpxImage.height;
  25527. var componentsCount = jpxImage.componentsCount;
  25528. var tileCount = jpxImage.tiles.length;
  25529. if (tileCount === 1) {
  25530. this.buffer = jpxImage.tiles[0].items;
  25531. } else {
  25532. var data = new Uint8Array(width * height * componentsCount);
  25533. for (var k = 0; k < tileCount; k++) {
  25534. var tileComponents = jpxImage.tiles[k];
  25535. var tileWidth = tileComponents.width;
  25536. var tileHeight = tileComponents.height;
  25537. var tileLeft = tileComponents.left;
  25538. var tileTop = tileComponents.top;
  25539. var src = tileComponents.items;
  25540. var srcPosition = 0;
  25541. var dataPosition = (width * tileTop + tileLeft) * componentsCount;
  25542. var imgRowSize = width * componentsCount;
  25543. var tileRowSize = tileWidth * componentsCount;
  25544. for (var j = 0; j < tileHeight; j++) {
  25545. var rowBytes = src.subarray(srcPosition, srcPosition + tileRowSize);
  25546. data.set(rowBytes, dataPosition);
  25547. srcPosition += tileRowSize;
  25548. dataPosition += imgRowSize;
  25549. }
  25550. }
  25551. this.buffer = data;
  25552. }
  25553. this.bufferLength = this.buffer.length;
  25554. this.eof = true;
  25555. };
  25556. return JpxStream;
  25557. }();
  25558. /**
  25559. * For JBIG2's we use a library to decode these images and
  25560. * the stream behaves like all the other DecodeStreams.
  25561. */
  25562. var Jbig2Stream = function Jbig2StreamClosure() {
  25563. function Jbig2Stream(stream, maybeLength, dict, params) {
  25564. this.stream = stream;
  25565. this.maybeLength = maybeLength;
  25566. this.dict = dict;
  25567. this.params = params;
  25568. DecodeStream.call(this, maybeLength);
  25569. }
  25570. Jbig2Stream.prototype = Object.create(DecodeStream.prototype);
  25571. Object.defineProperty(Jbig2Stream.prototype, 'bytes', {
  25572. get: function Jbig2Stream_bytes() {
  25573. // If this.maybeLength is null, we'll get the entire stream.
  25574. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  25575. },
  25576. configurable: true
  25577. });
  25578. Jbig2Stream.prototype.ensureBuffer = function Jbig2Stream_ensureBuffer(req) {
  25579. if (this.bufferLength) {
  25580. return;
  25581. }
  25582. var jbig2Image = new Jbig2Image();
  25583. var chunks = [];
  25584. if (isDict(this.params)) {
  25585. var globalsStream = this.params.get('JBIG2Globals');
  25586. if (isStream(globalsStream)) {
  25587. var globals = globalsStream.getBytes();
  25588. chunks.push({
  25589. data: globals,
  25590. start: 0,
  25591. end: globals.length
  25592. });
  25593. }
  25594. }
  25595. chunks.push({
  25596. data: this.bytes,
  25597. start: 0,
  25598. end: this.bytes.length
  25599. });
  25600. var data = jbig2Image.parseChunks(chunks);
  25601. var dataLength = data.length;
  25602. // JBIG2 had black as 1 and white as 0, inverting the colors
  25603. for (var i = 0; i < dataLength; i++) {
  25604. data[i] ^= 0xFF;
  25605. }
  25606. this.buffer = data;
  25607. this.bufferLength = dataLength;
  25608. this.eof = true;
  25609. };
  25610. return Jbig2Stream;
  25611. }();
  25612. var DecryptStream = function DecryptStreamClosure() {
  25613. function DecryptStream(str, maybeLength, decrypt) {
  25614. this.str = str;
  25615. this.dict = str.dict;
  25616. this.decrypt = decrypt;
  25617. this.nextChunk = null;
  25618. this.initialized = false;
  25619. DecodeStream.call(this, maybeLength);
  25620. }
  25621. var chunkSize = 512;
  25622. DecryptStream.prototype = Object.create(DecodeStream.prototype);
  25623. DecryptStream.prototype.readBlock = function DecryptStream_readBlock() {
  25624. var chunk;
  25625. if (this.initialized) {
  25626. chunk = this.nextChunk;
  25627. } else {
  25628. chunk = this.str.getBytes(chunkSize);
  25629. this.initialized = true;
  25630. }
  25631. if (!chunk || chunk.length === 0) {
  25632. this.eof = true;
  25633. return;
  25634. }
  25635. this.nextChunk = this.str.getBytes(chunkSize);
  25636. var hasMoreData = this.nextChunk && this.nextChunk.length > 0;
  25637. var decrypt = this.decrypt;
  25638. chunk = decrypt(chunk, !hasMoreData);
  25639. var bufferLength = this.bufferLength;
  25640. var i, n = chunk.length;
  25641. var buffer = this.ensureBuffer(bufferLength + n);
  25642. for (i = 0; i < n; i++) {
  25643. buffer[bufferLength++] = chunk[i];
  25644. }
  25645. this.bufferLength = bufferLength;
  25646. };
  25647. return DecryptStream;
  25648. }();
  25649. var Ascii85Stream = function Ascii85StreamClosure() {
  25650. function Ascii85Stream(str, maybeLength) {
  25651. this.str = str;
  25652. this.dict = str.dict;
  25653. this.input = new Uint8Array(5);
  25654. // Most streams increase in size when decoded, but Ascii85 streams
  25655. // typically shrink by ~20%.
  25656. if (maybeLength) {
  25657. maybeLength = 0.8 * maybeLength;
  25658. }
  25659. DecodeStream.call(this, maybeLength);
  25660. }
  25661. Ascii85Stream.prototype = Object.create(DecodeStream.prototype);
  25662. Ascii85Stream.prototype.readBlock = function Ascii85Stream_readBlock() {
  25663. var TILDA_CHAR = 0x7E;
  25664. // '~'
  25665. var Z_LOWER_CHAR = 0x7A;
  25666. // 'z'
  25667. var EOF = -1;
  25668. var str = this.str;
  25669. var c = str.getByte();
  25670. while (isSpace(c)) {
  25671. c = str.getByte();
  25672. }
  25673. if (c === EOF || c === TILDA_CHAR) {
  25674. this.eof = true;
  25675. return;
  25676. }
  25677. var bufferLength = this.bufferLength, buffer;
  25678. var i;
  25679. // special code for z
  25680. if (c === Z_LOWER_CHAR) {
  25681. buffer = this.ensureBuffer(bufferLength + 4);
  25682. for (i = 0; i < 4; ++i) {
  25683. buffer[bufferLength + i] = 0;
  25684. }
  25685. this.bufferLength += 4;
  25686. } else {
  25687. var input = this.input;
  25688. input[0] = c;
  25689. for (i = 1; i < 5; ++i) {
  25690. c = str.getByte();
  25691. while (isSpace(c)) {
  25692. c = str.getByte();
  25693. }
  25694. input[i] = c;
  25695. if (c === EOF || c === TILDA_CHAR) {
  25696. break;
  25697. }
  25698. }
  25699. buffer = this.ensureBuffer(bufferLength + i - 1);
  25700. this.bufferLength += i - 1;
  25701. // partial ending;
  25702. if (i < 5) {
  25703. for (; i < 5; ++i) {
  25704. input[i] = 0x21 + 84;
  25705. }
  25706. this.eof = true;
  25707. }
  25708. var t = 0;
  25709. for (i = 0; i < 5; ++i) {
  25710. t = t * 85 + (input[i] - 0x21);
  25711. }
  25712. for (i = 3; i >= 0; --i) {
  25713. buffer[bufferLength + i] = t & 0xFF;
  25714. t >>= 8;
  25715. }
  25716. }
  25717. };
  25718. return Ascii85Stream;
  25719. }();
  25720. var AsciiHexStream = function AsciiHexStreamClosure() {
  25721. function AsciiHexStream(str, maybeLength) {
  25722. this.str = str;
  25723. this.dict = str.dict;
  25724. this.firstDigit = -1;
  25725. // Most streams increase in size when decoded, but AsciiHex streams shrink
  25726. // by 50%.
  25727. if (maybeLength) {
  25728. maybeLength = 0.5 * maybeLength;
  25729. }
  25730. DecodeStream.call(this, maybeLength);
  25731. }
  25732. AsciiHexStream.prototype = Object.create(DecodeStream.prototype);
  25733. AsciiHexStream.prototype.readBlock = function AsciiHexStream_readBlock() {
  25734. var UPSTREAM_BLOCK_SIZE = 8000;
  25735. var bytes = this.str.getBytes(UPSTREAM_BLOCK_SIZE);
  25736. if (!bytes.length) {
  25737. this.eof = true;
  25738. return;
  25739. }
  25740. var maxDecodeLength = bytes.length + 1 >> 1;
  25741. var buffer = this.ensureBuffer(this.bufferLength + maxDecodeLength);
  25742. var bufferLength = this.bufferLength;
  25743. var firstDigit = this.firstDigit;
  25744. for (var i = 0, ii = bytes.length; i < ii; i++) {
  25745. var ch = bytes[i], digit;
  25746. if (ch >= 0x30 && ch <= 0x39) {
  25747. // '0'-'9'
  25748. digit = ch & 0x0F;
  25749. } else if (ch >= 0x41 && ch <= 0x46 || ch >= 0x61 && ch <= 0x66) {
  25750. // 'A'-'Z', 'a'-'z'
  25751. digit = (ch & 0x0F) + 9;
  25752. } else if (ch === 0x3E) {
  25753. // '>'
  25754. this.eof = true;
  25755. break;
  25756. } else {
  25757. // probably whitespace
  25758. continue;
  25759. }
  25760. // ignoring
  25761. if (firstDigit < 0) {
  25762. firstDigit = digit;
  25763. } else {
  25764. buffer[bufferLength++] = firstDigit << 4 | digit;
  25765. firstDigit = -1;
  25766. }
  25767. }
  25768. if (firstDigit >= 0 && this.eof) {
  25769. // incomplete byte
  25770. buffer[bufferLength++] = firstDigit << 4;
  25771. firstDigit = -1;
  25772. }
  25773. this.firstDigit = firstDigit;
  25774. this.bufferLength = bufferLength;
  25775. };
  25776. return AsciiHexStream;
  25777. }();
  25778. var RunLengthStream = function RunLengthStreamClosure() {
  25779. function RunLengthStream(str, maybeLength) {
  25780. this.str = str;
  25781. this.dict = str.dict;
  25782. DecodeStream.call(this, maybeLength);
  25783. }
  25784. RunLengthStream.prototype = Object.create(DecodeStream.prototype);
  25785. RunLengthStream.prototype.readBlock = function RunLengthStream_readBlock() {
  25786. // The repeatHeader has following format. The first byte defines type of run
  25787. // and amount of bytes to repeat/copy: n = 0 through 127 - copy next n bytes
  25788. // (in addition to the second byte from the header), n = 129 through 255 -
  25789. // duplicate the second byte from the header (257 - n) times, n = 128 - end.
  25790. var repeatHeader = this.str.getBytes(2);
  25791. if (!repeatHeader || repeatHeader.length < 2 || repeatHeader[0] === 128) {
  25792. this.eof = true;
  25793. return;
  25794. }
  25795. var buffer;
  25796. var bufferLength = this.bufferLength;
  25797. var n = repeatHeader[0];
  25798. if (n < 128) {
  25799. // copy n bytes
  25800. buffer = this.ensureBuffer(bufferLength + n + 1);
  25801. buffer[bufferLength++] = repeatHeader[1];
  25802. if (n > 0) {
  25803. var source = this.str.getBytes(n);
  25804. buffer.set(source, bufferLength);
  25805. bufferLength += n;
  25806. }
  25807. } else {
  25808. n = 257 - n;
  25809. var b = repeatHeader[1];
  25810. buffer = this.ensureBuffer(bufferLength + n + 1);
  25811. for (var i = 0; i < n; i++) {
  25812. buffer[bufferLength++] = b;
  25813. }
  25814. }
  25815. this.bufferLength = bufferLength;
  25816. };
  25817. return RunLengthStream;
  25818. }();
  25819. var CCITTFaxStream = function CCITTFaxStreamClosure() {
  25820. var ccittEOL = -2;
  25821. var ccittEOF = -1;
  25822. var twoDimPass = 0;
  25823. var twoDimHoriz = 1;
  25824. var twoDimVert0 = 2;
  25825. var twoDimVertR1 = 3;
  25826. var twoDimVertL1 = 4;
  25827. var twoDimVertR2 = 5;
  25828. var twoDimVertL2 = 6;
  25829. var twoDimVertR3 = 7;
  25830. var twoDimVertL3 = 8;
  25831. var twoDimTable = [
  25832. [
  25833. -1,
  25834. -1
  25835. ],
  25836. [
  25837. -1,
  25838. -1
  25839. ],
  25840. // 000000x
  25841. [
  25842. 7,
  25843. twoDimVertL3
  25844. ],
  25845. // 0000010
  25846. [
  25847. 7,
  25848. twoDimVertR3
  25849. ],
  25850. // 0000011
  25851. [
  25852. 6,
  25853. twoDimVertL2
  25854. ],
  25855. [
  25856. 6,
  25857. twoDimVertL2
  25858. ],
  25859. // 000010x
  25860. [
  25861. 6,
  25862. twoDimVertR2
  25863. ],
  25864. [
  25865. 6,
  25866. twoDimVertR2
  25867. ],
  25868. // 000011x
  25869. [
  25870. 4,
  25871. twoDimPass
  25872. ],
  25873. [
  25874. 4,
  25875. twoDimPass
  25876. ],
  25877. // 0001xxx
  25878. [
  25879. 4,
  25880. twoDimPass
  25881. ],
  25882. [
  25883. 4,
  25884. twoDimPass
  25885. ],
  25886. [
  25887. 4,
  25888. twoDimPass
  25889. ],
  25890. [
  25891. 4,
  25892. twoDimPass
  25893. ],
  25894. [
  25895. 4,
  25896. twoDimPass
  25897. ],
  25898. [
  25899. 4,
  25900. twoDimPass
  25901. ],
  25902. [
  25903. 3,
  25904. twoDimHoriz
  25905. ],
  25906. [
  25907. 3,
  25908. twoDimHoriz
  25909. ],
  25910. // 001xxxx
  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. twoDimHoriz
  25958. ],
  25959. [
  25960. 3,
  25961. twoDimHoriz
  25962. ],
  25963. [
  25964. 3,
  25965. twoDimHoriz
  25966. ],
  25967. [
  25968. 3,
  25969. twoDimVertL1
  25970. ],
  25971. [
  25972. 3,
  25973. twoDimVertL1
  25974. ],
  25975. // 010xxxx
  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. twoDimVertL1
  26023. ],
  26024. [
  26025. 3,
  26026. twoDimVertL1
  26027. ],
  26028. [
  26029. 3,
  26030. twoDimVertL1
  26031. ],
  26032. [
  26033. 3,
  26034. twoDimVertR1
  26035. ],
  26036. [
  26037. 3,
  26038. twoDimVertR1
  26039. ],
  26040. // 011xxxx
  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. 3,
  26087. twoDimVertR1
  26088. ],
  26089. [
  26090. 3,
  26091. twoDimVertR1
  26092. ],
  26093. [
  26094. 3,
  26095. twoDimVertR1
  26096. ],
  26097. [
  26098. 1,
  26099. twoDimVert0
  26100. ],
  26101. [
  26102. 1,
  26103. twoDimVert0
  26104. ],
  26105. // 1xxxxxx
  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. 1,
  26344. twoDimVert0
  26345. ],
  26346. [
  26347. 1,
  26348. twoDimVert0
  26349. ],
  26350. [
  26351. 1,
  26352. twoDimVert0
  26353. ]
  26354. ];
  26355. var whiteTable1 = [
  26356. [
  26357. -1,
  26358. -1
  26359. ],
  26360. // 00000
  26361. [
  26362. 12,
  26363. ccittEOL
  26364. ],
  26365. // 00001
  26366. [
  26367. -1,
  26368. -1
  26369. ],
  26370. [
  26371. -1,
  26372. -1
  26373. ],
  26374. // 0001x
  26375. [
  26376. -1,
  26377. -1
  26378. ],
  26379. [
  26380. -1,
  26381. -1
  26382. ],
  26383. [
  26384. -1,
  26385. -1
  26386. ],
  26387. [
  26388. -1,
  26389. -1
  26390. ],
  26391. // 001xx
  26392. [
  26393. -1,
  26394. -1
  26395. ],
  26396. [
  26397. -1,
  26398. -1
  26399. ],
  26400. [
  26401. -1,
  26402. -1
  26403. ],
  26404. [
  26405. -1,
  26406. -1
  26407. ],
  26408. // 010xx
  26409. [
  26410. -1,
  26411. -1
  26412. ],
  26413. [
  26414. -1,
  26415. -1
  26416. ],
  26417. [
  26418. -1,
  26419. -1
  26420. ],
  26421. [
  26422. -1,
  26423. -1
  26424. ],
  26425. // 011xx
  26426. [
  26427. 11,
  26428. 1792
  26429. ],
  26430. [
  26431. 11,
  26432. 1792
  26433. ],
  26434. // 1000x
  26435. [
  26436. 12,
  26437. 1984
  26438. ],
  26439. // 10010
  26440. [
  26441. 12,
  26442. 2048
  26443. ],
  26444. // 10011
  26445. [
  26446. 12,
  26447. 2112
  26448. ],
  26449. // 10100
  26450. [
  26451. 12,
  26452. 2176
  26453. ],
  26454. // 10101
  26455. [
  26456. 12,
  26457. 2240
  26458. ],
  26459. // 10110
  26460. [
  26461. 12,
  26462. 2304
  26463. ],
  26464. // 10111
  26465. [
  26466. 11,
  26467. 1856
  26468. ],
  26469. [
  26470. 11,
  26471. 1856
  26472. ],
  26473. // 1100x
  26474. [
  26475. 11,
  26476. 1920
  26477. ],
  26478. [
  26479. 11,
  26480. 1920
  26481. ],
  26482. // 1101x
  26483. [
  26484. 12,
  26485. 2368
  26486. ],
  26487. // 11100
  26488. [
  26489. 12,
  26490. 2432
  26491. ],
  26492. // 11101
  26493. [
  26494. 12,
  26495. 2496
  26496. ],
  26497. // 11110
  26498. [
  26499. 12,
  26500. 2560
  26501. ]
  26502. ];
  26503. // 11111
  26504. var whiteTable2 = [
  26505. [
  26506. -1,
  26507. -1
  26508. ],
  26509. [
  26510. -1,
  26511. -1
  26512. ],
  26513. [
  26514. -1,
  26515. -1
  26516. ],
  26517. [
  26518. -1,
  26519. -1
  26520. ],
  26521. // 0000000xx
  26522. [
  26523. 8,
  26524. 29
  26525. ],
  26526. [
  26527. 8,
  26528. 29
  26529. ],
  26530. // 00000010x
  26531. [
  26532. 8,
  26533. 30
  26534. ],
  26535. [
  26536. 8,
  26537. 30
  26538. ],
  26539. // 00000011x
  26540. [
  26541. 8,
  26542. 45
  26543. ],
  26544. [
  26545. 8,
  26546. 45
  26547. ],
  26548. // 00000100x
  26549. [
  26550. 8,
  26551. 46
  26552. ],
  26553. [
  26554. 8,
  26555. 46
  26556. ],
  26557. // 00000101x
  26558. [
  26559. 7,
  26560. 22
  26561. ],
  26562. [
  26563. 7,
  26564. 22
  26565. ],
  26566. [
  26567. 7,
  26568. 22
  26569. ],
  26570. [
  26571. 7,
  26572. 22
  26573. ],
  26574. // 0000011xx
  26575. [
  26576. 7,
  26577. 23
  26578. ],
  26579. [
  26580. 7,
  26581. 23
  26582. ],
  26583. [
  26584. 7,
  26585. 23
  26586. ],
  26587. [
  26588. 7,
  26589. 23
  26590. ],
  26591. // 0000100xx
  26592. [
  26593. 8,
  26594. 47
  26595. ],
  26596. [
  26597. 8,
  26598. 47
  26599. ],
  26600. // 00001010x
  26601. [
  26602. 8,
  26603. 48
  26604. ],
  26605. [
  26606. 8,
  26607. 48
  26608. ],
  26609. // 00001011x
  26610. [
  26611. 6,
  26612. 13
  26613. ],
  26614. [
  26615. 6,
  26616. 13
  26617. ],
  26618. [
  26619. 6,
  26620. 13
  26621. ],
  26622. [
  26623. 6,
  26624. 13
  26625. ],
  26626. // 000011xxx
  26627. [
  26628. 6,
  26629. 13
  26630. ],
  26631. [
  26632. 6,
  26633. 13
  26634. ],
  26635. [
  26636. 6,
  26637. 13
  26638. ],
  26639. [
  26640. 6,
  26641. 13
  26642. ],
  26643. [
  26644. 7,
  26645. 20
  26646. ],
  26647. [
  26648. 7,
  26649. 20
  26650. ],
  26651. [
  26652. 7,
  26653. 20
  26654. ],
  26655. [
  26656. 7,
  26657. 20
  26658. ],
  26659. // 0001000xx
  26660. [
  26661. 8,
  26662. 33
  26663. ],
  26664. [
  26665. 8,
  26666. 33
  26667. ],
  26668. // 00010010x
  26669. [
  26670. 8,
  26671. 34
  26672. ],
  26673. [
  26674. 8,
  26675. 34
  26676. ],
  26677. // 00010011x
  26678. [
  26679. 8,
  26680. 35
  26681. ],
  26682. [
  26683. 8,
  26684. 35
  26685. ],
  26686. // 00010100x
  26687. [
  26688. 8,
  26689. 36
  26690. ],
  26691. [
  26692. 8,
  26693. 36
  26694. ],
  26695. // 00010101x
  26696. [
  26697. 8,
  26698. 37
  26699. ],
  26700. [
  26701. 8,
  26702. 37
  26703. ],
  26704. // 00010110x
  26705. [
  26706. 8,
  26707. 38
  26708. ],
  26709. [
  26710. 8,
  26711. 38
  26712. ],
  26713. // 00010111x
  26714. [
  26715. 7,
  26716. 19
  26717. ],
  26718. [
  26719. 7,
  26720. 19
  26721. ],
  26722. [
  26723. 7,
  26724. 19
  26725. ],
  26726. [
  26727. 7,
  26728. 19
  26729. ],
  26730. // 0001100xx
  26731. [
  26732. 8,
  26733. 31
  26734. ],
  26735. [
  26736. 8,
  26737. 31
  26738. ],
  26739. // 00011010x
  26740. [
  26741. 8,
  26742. 32
  26743. ],
  26744. [
  26745. 8,
  26746. 32
  26747. ],
  26748. // 00011011x
  26749. [
  26750. 6,
  26751. 1
  26752. ],
  26753. [
  26754. 6,
  26755. 1
  26756. ],
  26757. [
  26758. 6,
  26759. 1
  26760. ],
  26761. [
  26762. 6,
  26763. 1
  26764. ],
  26765. // 000111xxx
  26766. [
  26767. 6,
  26768. 1
  26769. ],
  26770. [
  26771. 6,
  26772. 1
  26773. ],
  26774. [
  26775. 6,
  26776. 1
  26777. ],
  26778. [
  26779. 6,
  26780. 1
  26781. ],
  26782. [
  26783. 6,
  26784. 12
  26785. ],
  26786. [
  26787. 6,
  26788. 12
  26789. ],
  26790. [
  26791. 6,
  26792. 12
  26793. ],
  26794. [
  26795. 6,
  26796. 12
  26797. ],
  26798. // 001000xxx
  26799. [
  26800. 6,
  26801. 12
  26802. ],
  26803. [
  26804. 6,
  26805. 12
  26806. ],
  26807. [
  26808. 6,
  26809. 12
  26810. ],
  26811. [
  26812. 6,
  26813. 12
  26814. ],
  26815. [
  26816. 8,
  26817. 53
  26818. ],
  26819. [
  26820. 8,
  26821. 53
  26822. ],
  26823. // 00100100x
  26824. [
  26825. 8,
  26826. 54
  26827. ],
  26828. [
  26829. 8,
  26830. 54
  26831. ],
  26832. // 00100101x
  26833. [
  26834. 7,
  26835. 26
  26836. ],
  26837. [
  26838. 7,
  26839. 26
  26840. ],
  26841. [
  26842. 7,
  26843. 26
  26844. ],
  26845. [
  26846. 7,
  26847. 26
  26848. ],
  26849. // 0010011xx
  26850. [
  26851. 8,
  26852. 39
  26853. ],
  26854. [
  26855. 8,
  26856. 39
  26857. ],
  26858. // 00101000x
  26859. [
  26860. 8,
  26861. 40
  26862. ],
  26863. [
  26864. 8,
  26865. 40
  26866. ],
  26867. // 00101001x
  26868. [
  26869. 8,
  26870. 41
  26871. ],
  26872. [
  26873. 8,
  26874. 41
  26875. ],
  26876. // 00101010x
  26877. [
  26878. 8,
  26879. 42
  26880. ],
  26881. [
  26882. 8,
  26883. 42
  26884. ],
  26885. // 00101011x
  26886. [
  26887. 8,
  26888. 43
  26889. ],
  26890. [
  26891. 8,
  26892. 43
  26893. ],
  26894. // 00101100x
  26895. [
  26896. 8,
  26897. 44
  26898. ],
  26899. [
  26900. 8,
  26901. 44
  26902. ],
  26903. // 00101101x
  26904. [
  26905. 7,
  26906. 21
  26907. ],
  26908. [
  26909. 7,
  26910. 21
  26911. ],
  26912. [
  26913. 7,
  26914. 21
  26915. ],
  26916. [
  26917. 7,
  26918. 21
  26919. ],
  26920. // 0010111xx
  26921. [
  26922. 7,
  26923. 28
  26924. ],
  26925. [
  26926. 7,
  26927. 28
  26928. ],
  26929. [
  26930. 7,
  26931. 28
  26932. ],
  26933. [
  26934. 7,
  26935. 28
  26936. ],
  26937. // 0011000xx
  26938. [
  26939. 8,
  26940. 61
  26941. ],
  26942. [
  26943. 8,
  26944. 61
  26945. ],
  26946. // 00110010x
  26947. [
  26948. 8,
  26949. 62
  26950. ],
  26951. [
  26952. 8,
  26953. 62
  26954. ],
  26955. // 00110011x
  26956. [
  26957. 8,
  26958. 63
  26959. ],
  26960. [
  26961. 8,
  26962. 63
  26963. ],
  26964. // 00110100x
  26965. [
  26966. 8,
  26967. 0
  26968. ],
  26969. [
  26970. 8,
  26971. 0
  26972. ],
  26973. // 00110101x
  26974. [
  26975. 8,
  26976. 320
  26977. ],
  26978. [
  26979. 8,
  26980. 320
  26981. ],
  26982. // 00110110x
  26983. [
  26984. 8,
  26985. 384
  26986. ],
  26987. [
  26988. 8,
  26989. 384
  26990. ],
  26991. // 00110111x
  26992. [
  26993. 5,
  26994. 10
  26995. ],
  26996. [
  26997. 5,
  26998. 10
  26999. ],
  27000. [
  27001. 5,
  27002. 10
  27003. ],
  27004. [
  27005. 5,
  27006. 10
  27007. ],
  27008. // 00111xxxx
  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. 10
  27048. ],
  27049. [
  27050. 5,
  27051. 10
  27052. ],
  27053. [
  27054. 5,
  27055. 10
  27056. ],
  27057. [
  27058. 5,
  27059. 11
  27060. ],
  27061. [
  27062. 5,
  27063. 11
  27064. ],
  27065. [
  27066. 5,
  27067. 11
  27068. ],
  27069. [
  27070. 5,
  27071. 11
  27072. ],
  27073. // 01000xxxx
  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. 5,
  27112. 11
  27113. ],
  27114. [
  27115. 5,
  27116. 11
  27117. ],
  27118. [
  27119. 5,
  27120. 11
  27121. ],
  27122. [
  27123. 7,
  27124. 27
  27125. ],
  27126. [
  27127. 7,
  27128. 27
  27129. ],
  27130. [
  27131. 7,
  27132. 27
  27133. ],
  27134. [
  27135. 7,
  27136. 27
  27137. ],
  27138. // 0100100xx
  27139. [
  27140. 8,
  27141. 59
  27142. ],
  27143. [
  27144. 8,
  27145. 59
  27146. ],
  27147. // 01001010x
  27148. [
  27149. 8,
  27150. 60
  27151. ],
  27152. [
  27153. 8,
  27154. 60
  27155. ],
  27156. // 01001011x
  27157. [
  27158. 9,
  27159. 1472
  27160. ],
  27161. // 010011000
  27162. [
  27163. 9,
  27164. 1536
  27165. ],
  27166. // 010011001
  27167. [
  27168. 9,
  27169. 1600
  27170. ],
  27171. // 010011010
  27172. [
  27173. 9,
  27174. 1728
  27175. ],
  27176. // 010011011
  27177. [
  27178. 7,
  27179. 18
  27180. ],
  27181. [
  27182. 7,
  27183. 18
  27184. ],
  27185. [
  27186. 7,
  27187. 18
  27188. ],
  27189. [
  27190. 7,
  27191. 18
  27192. ],
  27193. // 0100111xx
  27194. [
  27195. 7,
  27196. 24
  27197. ],
  27198. [
  27199. 7,
  27200. 24
  27201. ],
  27202. [
  27203. 7,
  27204. 24
  27205. ],
  27206. [
  27207. 7,
  27208. 24
  27209. ],
  27210. // 0101000xx
  27211. [
  27212. 8,
  27213. 49
  27214. ],
  27215. [
  27216. 8,
  27217. 49
  27218. ],
  27219. // 01010010x
  27220. [
  27221. 8,
  27222. 50
  27223. ],
  27224. [
  27225. 8,
  27226. 50
  27227. ],
  27228. // 01010011x
  27229. [
  27230. 8,
  27231. 51
  27232. ],
  27233. [
  27234. 8,
  27235. 51
  27236. ],
  27237. // 01010100x
  27238. [
  27239. 8,
  27240. 52
  27241. ],
  27242. [
  27243. 8,
  27244. 52
  27245. ],
  27246. // 01010101x
  27247. [
  27248. 7,
  27249. 25
  27250. ],
  27251. [
  27252. 7,
  27253. 25
  27254. ],
  27255. [
  27256. 7,
  27257. 25
  27258. ],
  27259. [
  27260. 7,
  27261. 25
  27262. ],
  27263. // 0101011xx
  27264. [
  27265. 8,
  27266. 55
  27267. ],
  27268. [
  27269. 8,
  27270. 55
  27271. ],
  27272. // 01011000x
  27273. [
  27274. 8,
  27275. 56
  27276. ],
  27277. [
  27278. 8,
  27279. 56
  27280. ],
  27281. // 01011001x
  27282. [
  27283. 8,
  27284. 57
  27285. ],
  27286. [
  27287. 8,
  27288. 57
  27289. ],
  27290. // 01011010x
  27291. [
  27292. 8,
  27293. 58
  27294. ],
  27295. [
  27296. 8,
  27297. 58
  27298. ],
  27299. // 01011011x
  27300. [
  27301. 6,
  27302. 192
  27303. ],
  27304. [
  27305. 6,
  27306. 192
  27307. ],
  27308. [
  27309. 6,
  27310. 192
  27311. ],
  27312. [
  27313. 6,
  27314. 192
  27315. ],
  27316. // 010111xxx
  27317. [
  27318. 6,
  27319. 192
  27320. ],
  27321. [
  27322. 6,
  27323. 192
  27324. ],
  27325. [
  27326. 6,
  27327. 192
  27328. ],
  27329. [
  27330. 6,
  27331. 192
  27332. ],
  27333. [
  27334. 6,
  27335. 1664
  27336. ],
  27337. [
  27338. 6,
  27339. 1664
  27340. ],
  27341. [
  27342. 6,
  27343. 1664
  27344. ],
  27345. [
  27346. 6,
  27347. 1664
  27348. ],
  27349. // 011000xxx
  27350. [
  27351. 6,
  27352. 1664
  27353. ],
  27354. [
  27355. 6,
  27356. 1664
  27357. ],
  27358. [
  27359. 6,
  27360. 1664
  27361. ],
  27362. [
  27363. 6,
  27364. 1664
  27365. ],
  27366. [
  27367. 8,
  27368. 448
  27369. ],
  27370. [
  27371. 8,
  27372. 448
  27373. ],
  27374. // 01100100x
  27375. [
  27376. 8,
  27377. 512
  27378. ],
  27379. [
  27380. 8,
  27381. 512
  27382. ],
  27383. // 01100101x
  27384. [
  27385. 9,
  27386. 704
  27387. ],
  27388. // 011001100
  27389. [
  27390. 9,
  27391. 768
  27392. ],
  27393. // 011001101
  27394. [
  27395. 8,
  27396. 640
  27397. ],
  27398. [
  27399. 8,
  27400. 640
  27401. ],
  27402. // 01100111x
  27403. [
  27404. 8,
  27405. 576
  27406. ],
  27407. [
  27408. 8,
  27409. 576
  27410. ],
  27411. // 01101000x
  27412. [
  27413. 9,
  27414. 832
  27415. ],
  27416. // 011010010
  27417. [
  27418. 9,
  27419. 896
  27420. ],
  27421. // 011010011
  27422. [
  27423. 9,
  27424. 960
  27425. ],
  27426. // 011010100
  27427. [
  27428. 9,
  27429. 1024
  27430. ],
  27431. // 011010101
  27432. [
  27433. 9,
  27434. 1088
  27435. ],
  27436. // 011010110
  27437. [
  27438. 9,
  27439. 1152
  27440. ],
  27441. // 011010111
  27442. [
  27443. 9,
  27444. 1216
  27445. ],
  27446. // 011011000
  27447. [
  27448. 9,
  27449. 1280
  27450. ],
  27451. // 011011001
  27452. [
  27453. 9,
  27454. 1344
  27455. ],
  27456. // 011011010
  27457. [
  27458. 9,
  27459. 1408
  27460. ],
  27461. // 011011011
  27462. [
  27463. 7,
  27464. 256
  27465. ],
  27466. [
  27467. 7,
  27468. 256
  27469. ],
  27470. [
  27471. 7,
  27472. 256
  27473. ],
  27474. [
  27475. 7,
  27476. 256
  27477. ],
  27478. // 0110111xx
  27479. [
  27480. 4,
  27481. 2
  27482. ],
  27483. [
  27484. 4,
  27485. 2
  27486. ],
  27487. [
  27488. 4,
  27489. 2
  27490. ],
  27491. [
  27492. 4,
  27493. 2
  27494. ],
  27495. // 0111xxxxx
  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. 2
  27599. ],
  27600. [
  27601. 4,
  27602. 2
  27603. ],
  27604. [
  27605. 4,
  27606. 2
  27607. ],
  27608. [
  27609. 4,
  27610. 3
  27611. ],
  27612. [
  27613. 4,
  27614. 3
  27615. ],
  27616. [
  27617. 4,
  27618. 3
  27619. ],
  27620. [
  27621. 4,
  27622. 3
  27623. ],
  27624. // 1000xxxxx
  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. 4,
  27727. 3
  27728. ],
  27729. [
  27730. 4,
  27731. 3
  27732. ],
  27733. [
  27734. 4,
  27735. 3
  27736. ],
  27737. [
  27738. 5,
  27739. 128
  27740. ],
  27741. [
  27742. 5,
  27743. 128
  27744. ],
  27745. [
  27746. 5,
  27747. 128
  27748. ],
  27749. [
  27750. 5,
  27751. 128
  27752. ],
  27753. // 10010xxxx
  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. 128
  27793. ],
  27794. [
  27795. 5,
  27796. 128
  27797. ],
  27798. [
  27799. 5,
  27800. 128
  27801. ],
  27802. [
  27803. 5,
  27804. 8
  27805. ],
  27806. [
  27807. 5,
  27808. 8
  27809. ],
  27810. [
  27811. 5,
  27812. 8
  27813. ],
  27814. [
  27815. 5,
  27816. 8
  27817. ],
  27818. // 10011xxxx
  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. 8
  27858. ],
  27859. [
  27860. 5,
  27861. 8
  27862. ],
  27863. [
  27864. 5,
  27865. 8
  27866. ],
  27867. [
  27868. 5,
  27869. 9
  27870. ],
  27871. [
  27872. 5,
  27873. 9
  27874. ],
  27875. [
  27876. 5,
  27877. 9
  27878. ],
  27879. [
  27880. 5,
  27881. 9
  27882. ],
  27883. // 10100xxxx
  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. 5,
  27922. 9
  27923. ],
  27924. [
  27925. 5,
  27926. 9
  27927. ],
  27928. [
  27929. 5,
  27930. 9
  27931. ],
  27932. [
  27933. 6,
  27934. 16
  27935. ],
  27936. [
  27937. 6,
  27938. 16
  27939. ],
  27940. [
  27941. 6,
  27942. 16
  27943. ],
  27944. [
  27945. 6,
  27946. 16
  27947. ],
  27948. // 101010xxx
  27949. [
  27950. 6,
  27951. 16
  27952. ],
  27953. [
  27954. 6,
  27955. 16
  27956. ],
  27957. [
  27958. 6,
  27959. 16
  27960. ],
  27961. [
  27962. 6,
  27963. 16
  27964. ],
  27965. [
  27966. 6,
  27967. 17
  27968. ],
  27969. [
  27970. 6,
  27971. 17
  27972. ],
  27973. [
  27974. 6,
  27975. 17
  27976. ],
  27977. [
  27978. 6,
  27979. 17
  27980. ],
  27981. // 101011xxx
  27982. [
  27983. 6,
  27984. 17
  27985. ],
  27986. [
  27987. 6,
  27988. 17
  27989. ],
  27990. [
  27991. 6,
  27992. 17
  27993. ],
  27994. [
  27995. 6,
  27996. 17
  27997. ],
  27998. [
  27999. 4,
  28000. 4
  28001. ],
  28002. [
  28003. 4,
  28004. 4
  28005. ],
  28006. [
  28007. 4,
  28008. 4
  28009. ],
  28010. [
  28011. 4,
  28012. 4
  28013. ],
  28014. // 1011xxxxx
  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. 4
  28118. ],
  28119. [
  28120. 4,
  28121. 4
  28122. ],
  28123. [
  28124. 4,
  28125. 4
  28126. ],
  28127. [
  28128. 4,
  28129. 5
  28130. ],
  28131. [
  28132. 4,
  28133. 5
  28134. ],
  28135. [
  28136. 4,
  28137. 5
  28138. ],
  28139. [
  28140. 4,
  28141. 5
  28142. ],
  28143. // 1100xxxxx
  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. 4,
  28246. 5
  28247. ],
  28248. [
  28249. 4,
  28250. 5
  28251. ],
  28252. [
  28253. 4,
  28254. 5
  28255. ],
  28256. [
  28257. 6,
  28258. 14
  28259. ],
  28260. [
  28261. 6,
  28262. 14
  28263. ],
  28264. [
  28265. 6,
  28266. 14
  28267. ],
  28268. [
  28269. 6,
  28270. 14
  28271. ],
  28272. // 110100xxx
  28273. [
  28274. 6,
  28275. 14
  28276. ],
  28277. [
  28278. 6,
  28279. 14
  28280. ],
  28281. [
  28282. 6,
  28283. 14
  28284. ],
  28285. [
  28286. 6,
  28287. 14
  28288. ],
  28289. [
  28290. 6,
  28291. 15
  28292. ],
  28293. [
  28294. 6,
  28295. 15
  28296. ],
  28297. [
  28298. 6,
  28299. 15
  28300. ],
  28301. [
  28302. 6,
  28303. 15
  28304. ],
  28305. // 110101xxx
  28306. [
  28307. 6,
  28308. 15
  28309. ],
  28310. [
  28311. 6,
  28312. 15
  28313. ],
  28314. [
  28315. 6,
  28316. 15
  28317. ],
  28318. [
  28319. 6,
  28320. 15
  28321. ],
  28322. [
  28323. 5,
  28324. 64
  28325. ],
  28326. [
  28327. 5,
  28328. 64
  28329. ],
  28330. [
  28331. 5,
  28332. 64
  28333. ],
  28334. [
  28335. 5,
  28336. 64
  28337. ],
  28338. // 11011xxxx
  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. 5,
  28377. 64
  28378. ],
  28379. [
  28380. 5,
  28381. 64
  28382. ],
  28383. [
  28384. 5,
  28385. 64
  28386. ],
  28387. [
  28388. 4,
  28389. 6
  28390. ],
  28391. [
  28392. 4,
  28393. 6
  28394. ],
  28395. [
  28396. 4,
  28397. 6
  28398. ],
  28399. [
  28400. 4,
  28401. 6
  28402. ],
  28403. // 1110xxxxx
  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. 6
  28507. ],
  28508. [
  28509. 4,
  28510. 6
  28511. ],
  28512. [
  28513. 4,
  28514. 6
  28515. ],
  28516. [
  28517. 4,
  28518. 7
  28519. ],
  28520. [
  28521. 4,
  28522. 7
  28523. ],
  28524. [
  28525. 4,
  28526. 7
  28527. ],
  28528. [
  28529. 4,
  28530. 7
  28531. ],
  28532. // 1111xxxxx
  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. 4,
  28635. 7
  28636. ],
  28637. [
  28638. 4,
  28639. 7
  28640. ],
  28641. [
  28642. 4,
  28643. 7
  28644. ]
  28645. ];
  28646. var blackTable1 = [
  28647. [
  28648. -1,
  28649. -1
  28650. ],
  28651. [
  28652. -1,
  28653. -1
  28654. ],
  28655. // 000000000000x
  28656. [
  28657. 12,
  28658. ccittEOL
  28659. ],
  28660. [
  28661. 12,
  28662. ccittEOL
  28663. ],
  28664. // 000000000001x
  28665. [
  28666. -1,
  28667. -1
  28668. ],
  28669. [
  28670. -1,
  28671. -1
  28672. ],
  28673. [
  28674. -1,
  28675. -1
  28676. ],
  28677. [
  28678. -1,
  28679. -1
  28680. ],
  28681. // 00000000001xx
  28682. [
  28683. -1,
  28684. -1
  28685. ],
  28686. [
  28687. -1,
  28688. -1
  28689. ],
  28690. [
  28691. -1,
  28692. -1
  28693. ],
  28694. [
  28695. -1,
  28696. -1
  28697. ],
  28698. // 00000000010xx
  28699. [
  28700. -1,
  28701. -1
  28702. ],
  28703. [
  28704. -1,
  28705. -1
  28706. ],
  28707. [
  28708. -1,
  28709. -1
  28710. ],
  28711. [
  28712. -1,
  28713. -1
  28714. ],
  28715. // 00000000011xx
  28716. [
  28717. -1,
  28718. -1
  28719. ],
  28720. [
  28721. -1,
  28722. -1
  28723. ],
  28724. [
  28725. -1,
  28726. -1
  28727. ],
  28728. [
  28729. -1,
  28730. -1
  28731. ],
  28732. // 00000000100xx
  28733. [
  28734. -1,
  28735. -1
  28736. ],
  28737. [
  28738. -1,
  28739. -1
  28740. ],
  28741. [
  28742. -1,
  28743. -1
  28744. ],
  28745. [
  28746. -1,
  28747. -1
  28748. ],
  28749. // 00000000101xx
  28750. [
  28751. -1,
  28752. -1
  28753. ],
  28754. [
  28755. -1,
  28756. -1
  28757. ],
  28758. [
  28759. -1,
  28760. -1
  28761. ],
  28762. [
  28763. -1,
  28764. -1
  28765. ],
  28766. // 00000000110xx
  28767. [
  28768. -1,
  28769. -1
  28770. ],
  28771. [
  28772. -1,
  28773. -1
  28774. ],
  28775. [
  28776. -1,
  28777. -1
  28778. ],
  28779. [
  28780. -1,
  28781. -1
  28782. ],
  28783. // 00000000111xx
  28784. [
  28785. 11,
  28786. 1792
  28787. ],
  28788. [
  28789. 11,
  28790. 1792
  28791. ],
  28792. [
  28793. 11,
  28794. 1792
  28795. ],
  28796. [
  28797. 11,
  28798. 1792
  28799. ],
  28800. // 00000001000xx
  28801. [
  28802. 12,
  28803. 1984
  28804. ],
  28805. [
  28806. 12,
  28807. 1984
  28808. ],
  28809. // 000000010010x
  28810. [
  28811. 12,
  28812. 2048
  28813. ],
  28814. [
  28815. 12,
  28816. 2048
  28817. ],
  28818. // 000000010011x
  28819. [
  28820. 12,
  28821. 2112
  28822. ],
  28823. [
  28824. 12,
  28825. 2112
  28826. ],
  28827. // 000000010100x
  28828. [
  28829. 12,
  28830. 2176
  28831. ],
  28832. [
  28833. 12,
  28834. 2176
  28835. ],
  28836. // 000000010101x
  28837. [
  28838. 12,
  28839. 2240
  28840. ],
  28841. [
  28842. 12,
  28843. 2240
  28844. ],
  28845. // 000000010110x
  28846. [
  28847. 12,
  28848. 2304
  28849. ],
  28850. [
  28851. 12,
  28852. 2304
  28853. ],
  28854. // 000000010111x
  28855. [
  28856. 11,
  28857. 1856
  28858. ],
  28859. [
  28860. 11,
  28861. 1856
  28862. ],
  28863. [
  28864. 11,
  28865. 1856
  28866. ],
  28867. [
  28868. 11,
  28869. 1856
  28870. ],
  28871. // 00000001100xx
  28872. [
  28873. 11,
  28874. 1920
  28875. ],
  28876. [
  28877. 11,
  28878. 1920
  28879. ],
  28880. [
  28881. 11,
  28882. 1920
  28883. ],
  28884. [
  28885. 11,
  28886. 1920
  28887. ],
  28888. // 00000001101xx
  28889. [
  28890. 12,
  28891. 2368
  28892. ],
  28893. [
  28894. 12,
  28895. 2368
  28896. ],
  28897. // 000000011100x
  28898. [
  28899. 12,
  28900. 2432
  28901. ],
  28902. [
  28903. 12,
  28904. 2432
  28905. ],
  28906. // 000000011101x
  28907. [
  28908. 12,
  28909. 2496
  28910. ],
  28911. [
  28912. 12,
  28913. 2496
  28914. ],
  28915. // 000000011110x
  28916. [
  28917. 12,
  28918. 2560
  28919. ],
  28920. [
  28921. 12,
  28922. 2560
  28923. ],
  28924. // 000000011111x
  28925. [
  28926. 10,
  28927. 18
  28928. ],
  28929. [
  28930. 10,
  28931. 18
  28932. ],
  28933. [
  28934. 10,
  28935. 18
  28936. ],
  28937. [
  28938. 10,
  28939. 18
  28940. ],
  28941. // 0000001000xxx
  28942. [
  28943. 10,
  28944. 18
  28945. ],
  28946. [
  28947. 10,
  28948. 18
  28949. ],
  28950. [
  28951. 10,
  28952. 18
  28953. ],
  28954. [
  28955. 10,
  28956. 18
  28957. ],
  28958. [
  28959. 12,
  28960. 52
  28961. ],
  28962. [
  28963. 12,
  28964. 52
  28965. ],
  28966. // 000000100100x
  28967. [
  28968. 13,
  28969. 640
  28970. ],
  28971. // 0000001001010
  28972. [
  28973. 13,
  28974. 704
  28975. ],
  28976. // 0000001001011
  28977. [
  28978. 13,
  28979. 768
  28980. ],
  28981. // 0000001001100
  28982. [
  28983. 13,
  28984. 832
  28985. ],
  28986. // 0000001001101
  28987. [
  28988. 12,
  28989. 55
  28990. ],
  28991. [
  28992. 12,
  28993. 55
  28994. ],
  28995. // 000000100111x
  28996. [
  28997. 12,
  28998. 56
  28999. ],
  29000. [
  29001. 12,
  29002. 56
  29003. ],
  29004. // 000000101000x
  29005. [
  29006. 13,
  29007. 1280
  29008. ],
  29009. // 0000001010010
  29010. [
  29011. 13,
  29012. 1344
  29013. ],
  29014. // 0000001010011
  29015. [
  29016. 13,
  29017. 1408
  29018. ],
  29019. // 0000001010100
  29020. [
  29021. 13,
  29022. 1472
  29023. ],
  29024. // 0000001010101
  29025. [
  29026. 12,
  29027. 59
  29028. ],
  29029. [
  29030. 12,
  29031. 59
  29032. ],
  29033. // 000000101011x
  29034. [
  29035. 12,
  29036. 60
  29037. ],
  29038. [
  29039. 12,
  29040. 60
  29041. ],
  29042. // 000000101100x
  29043. [
  29044. 13,
  29045. 1536
  29046. ],
  29047. // 0000001011010
  29048. [
  29049. 13,
  29050. 1600
  29051. ],
  29052. // 0000001011011
  29053. [
  29054. 11,
  29055. 24
  29056. ],
  29057. [
  29058. 11,
  29059. 24
  29060. ],
  29061. [
  29062. 11,
  29063. 24
  29064. ],
  29065. [
  29066. 11,
  29067. 24
  29068. ],
  29069. // 00000010111xx
  29070. [
  29071. 11,
  29072. 25
  29073. ],
  29074. [
  29075. 11,
  29076. 25
  29077. ],
  29078. [
  29079. 11,
  29080. 25
  29081. ],
  29082. [
  29083. 11,
  29084. 25
  29085. ],
  29086. // 00000011000xx
  29087. [
  29088. 13,
  29089. 1664
  29090. ],
  29091. // 0000001100100
  29092. [
  29093. 13,
  29094. 1728
  29095. ],
  29096. // 0000001100101
  29097. [
  29098. 12,
  29099. 320
  29100. ],
  29101. [
  29102. 12,
  29103. 320
  29104. ],
  29105. // 000000110011x
  29106. [
  29107. 12,
  29108. 384
  29109. ],
  29110. [
  29111. 12,
  29112. 384
  29113. ],
  29114. // 000000110100x
  29115. [
  29116. 12,
  29117. 448
  29118. ],
  29119. [
  29120. 12,
  29121. 448
  29122. ],
  29123. // 000000110101x
  29124. [
  29125. 13,
  29126. 512
  29127. ],
  29128. // 0000001101100
  29129. [
  29130. 13,
  29131. 576
  29132. ],
  29133. // 0000001101101
  29134. [
  29135. 12,
  29136. 53
  29137. ],
  29138. [
  29139. 12,
  29140. 53
  29141. ],
  29142. // 000000110111x
  29143. [
  29144. 12,
  29145. 54
  29146. ],
  29147. [
  29148. 12,
  29149. 54
  29150. ],
  29151. // 000000111000x
  29152. [
  29153. 13,
  29154. 896
  29155. ],
  29156. // 0000001110010
  29157. [
  29158. 13,
  29159. 960
  29160. ],
  29161. // 0000001110011
  29162. [
  29163. 13,
  29164. 1024
  29165. ],
  29166. // 0000001110100
  29167. [
  29168. 13,
  29169. 1088
  29170. ],
  29171. // 0000001110101
  29172. [
  29173. 13,
  29174. 1152
  29175. ],
  29176. // 0000001110110
  29177. [
  29178. 13,
  29179. 1216
  29180. ],
  29181. // 0000001110111
  29182. [
  29183. 10,
  29184. 64
  29185. ],
  29186. [
  29187. 10,
  29188. 64
  29189. ],
  29190. [
  29191. 10,
  29192. 64
  29193. ],
  29194. [
  29195. 10,
  29196. 64
  29197. ],
  29198. // 0000001111xxx
  29199. [
  29200. 10,
  29201. 64
  29202. ],
  29203. [
  29204. 10,
  29205. 64
  29206. ],
  29207. [
  29208. 10,
  29209. 64
  29210. ],
  29211. [
  29212. 10,
  29213. 64
  29214. ]
  29215. ];
  29216. var blackTable2 = [
  29217. [
  29218. 8,
  29219. 13
  29220. ],
  29221. [
  29222. 8,
  29223. 13
  29224. ],
  29225. [
  29226. 8,
  29227. 13
  29228. ],
  29229. [
  29230. 8,
  29231. 13
  29232. ],
  29233. // 00000100xxxx
  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. 8,
  29272. 13
  29273. ],
  29274. [
  29275. 8,
  29276. 13
  29277. ],
  29278. [
  29279. 8,
  29280. 13
  29281. ],
  29282. [
  29283. 11,
  29284. 23
  29285. ],
  29286. [
  29287. 11,
  29288. 23
  29289. ],
  29290. // 00000101000x
  29291. [
  29292. 12,
  29293. 50
  29294. ],
  29295. // 000001010010
  29296. [
  29297. 12,
  29298. 51
  29299. ],
  29300. // 000001010011
  29301. [
  29302. 12,
  29303. 44
  29304. ],
  29305. // 000001010100
  29306. [
  29307. 12,
  29308. 45
  29309. ],
  29310. // 000001010101
  29311. [
  29312. 12,
  29313. 46
  29314. ],
  29315. // 000001010110
  29316. [
  29317. 12,
  29318. 47
  29319. ],
  29320. // 000001010111
  29321. [
  29322. 12,
  29323. 57
  29324. ],
  29325. // 000001011000
  29326. [
  29327. 12,
  29328. 58
  29329. ],
  29330. // 000001011001
  29331. [
  29332. 12,
  29333. 61
  29334. ],
  29335. // 000001011010
  29336. [
  29337. 12,
  29338. 256
  29339. ],
  29340. // 000001011011
  29341. [
  29342. 10,
  29343. 16
  29344. ],
  29345. [
  29346. 10,
  29347. 16
  29348. ],
  29349. [
  29350. 10,
  29351. 16
  29352. ],
  29353. [
  29354. 10,
  29355. 16
  29356. ],
  29357. // 0000010111xx
  29358. [
  29359. 10,
  29360. 17
  29361. ],
  29362. [
  29363. 10,
  29364. 17
  29365. ],
  29366. [
  29367. 10,
  29368. 17
  29369. ],
  29370. [
  29371. 10,
  29372. 17
  29373. ],
  29374. // 0000011000xx
  29375. [
  29376. 12,
  29377. 48
  29378. ],
  29379. // 000001100100
  29380. [
  29381. 12,
  29382. 49
  29383. ],
  29384. // 000001100101
  29385. [
  29386. 12,
  29387. 62
  29388. ],
  29389. // 000001100110
  29390. [
  29391. 12,
  29392. 63
  29393. ],
  29394. // 000001100111
  29395. [
  29396. 12,
  29397. 30
  29398. ],
  29399. // 000001101000
  29400. [
  29401. 12,
  29402. 31
  29403. ],
  29404. // 000001101001
  29405. [
  29406. 12,
  29407. 32
  29408. ],
  29409. // 000001101010
  29410. [
  29411. 12,
  29412. 33
  29413. ],
  29414. // 000001101011
  29415. [
  29416. 12,
  29417. 40
  29418. ],
  29419. // 000001101100
  29420. [
  29421. 12,
  29422. 41
  29423. ],
  29424. // 000001101101
  29425. [
  29426. 11,
  29427. 22
  29428. ],
  29429. [
  29430. 11,
  29431. 22
  29432. ],
  29433. // 00000110111x
  29434. [
  29435. 8,
  29436. 14
  29437. ],
  29438. [
  29439. 8,
  29440. 14
  29441. ],
  29442. [
  29443. 8,
  29444. 14
  29445. ],
  29446. [
  29447. 8,
  29448. 14
  29449. ],
  29450. // 00000111xxxx
  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. 8,
  29489. 14
  29490. ],
  29491. [
  29492. 8,
  29493. 14
  29494. ],
  29495. [
  29496. 8,
  29497. 14
  29498. ],
  29499. [
  29500. 7,
  29501. 10
  29502. ],
  29503. [
  29504. 7,
  29505. 10
  29506. ],
  29507. [
  29508. 7,
  29509. 10
  29510. ],
  29511. [
  29512. 7,
  29513. 10
  29514. ],
  29515. // 0000100xxxxx
  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. 10
  29619. ],
  29620. [
  29621. 7,
  29622. 10
  29623. ],
  29624. [
  29625. 7,
  29626. 10
  29627. ],
  29628. [
  29629. 7,
  29630. 11
  29631. ],
  29632. [
  29633. 7,
  29634. 11
  29635. ],
  29636. [
  29637. 7,
  29638. 11
  29639. ],
  29640. [
  29641. 7,
  29642. 11
  29643. ],
  29644. // 0000101xxxxx
  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. 7,
  29747. 11
  29748. ],
  29749. [
  29750. 7,
  29751. 11
  29752. ],
  29753. [
  29754. 7,
  29755. 11
  29756. ],
  29757. [
  29758. 9,
  29759. 15
  29760. ],
  29761. [
  29762. 9,
  29763. 15
  29764. ],
  29765. [
  29766. 9,
  29767. 15
  29768. ],
  29769. [
  29770. 9,
  29771. 15
  29772. ],
  29773. // 000011000xxx
  29774. [
  29775. 9,
  29776. 15
  29777. ],
  29778. [
  29779. 9,
  29780. 15
  29781. ],
  29782. [
  29783. 9,
  29784. 15
  29785. ],
  29786. [
  29787. 9,
  29788. 15
  29789. ],
  29790. [
  29791. 12,
  29792. 128
  29793. ],
  29794. // 000011001000
  29795. [
  29796. 12,
  29797. 192
  29798. ],
  29799. // 000011001001
  29800. [
  29801. 12,
  29802. 26
  29803. ],
  29804. // 000011001010
  29805. [
  29806. 12,
  29807. 27
  29808. ],
  29809. // 000011001011
  29810. [
  29811. 12,
  29812. 28
  29813. ],
  29814. // 000011001100
  29815. [
  29816. 12,
  29817. 29
  29818. ],
  29819. // 000011001101
  29820. [
  29821. 11,
  29822. 19
  29823. ],
  29824. [
  29825. 11,
  29826. 19
  29827. ],
  29828. // 00001100111x
  29829. [
  29830. 11,
  29831. 20
  29832. ],
  29833. [
  29834. 11,
  29835. 20
  29836. ],
  29837. // 00001101000x
  29838. [
  29839. 12,
  29840. 34
  29841. ],
  29842. // 000011010010
  29843. [
  29844. 12,
  29845. 35
  29846. ],
  29847. // 000011010011
  29848. [
  29849. 12,
  29850. 36
  29851. ],
  29852. // 000011010100
  29853. [
  29854. 12,
  29855. 37
  29856. ],
  29857. // 000011010101
  29858. [
  29859. 12,
  29860. 38
  29861. ],
  29862. // 000011010110
  29863. [
  29864. 12,
  29865. 39
  29866. ],
  29867. // 000011010111
  29868. [
  29869. 11,
  29870. 21
  29871. ],
  29872. [
  29873. 11,
  29874. 21
  29875. ],
  29876. // 00001101100x
  29877. [
  29878. 12,
  29879. 42
  29880. ],
  29881. // 000011011010
  29882. [
  29883. 12,
  29884. 43
  29885. ],
  29886. // 000011011011
  29887. [
  29888. 10,
  29889. 0
  29890. ],
  29891. [
  29892. 10,
  29893. 0
  29894. ],
  29895. [
  29896. 10,
  29897. 0
  29898. ],
  29899. [
  29900. 10,
  29901. 0
  29902. ],
  29903. // 0000110111xx
  29904. [
  29905. 7,
  29906. 12
  29907. ],
  29908. [
  29909. 7,
  29910. 12
  29911. ],
  29912. [
  29913. 7,
  29914. 12
  29915. ],
  29916. [
  29917. 7,
  29918. 12
  29919. ],
  29920. // 0000111xxxxx
  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. 7,
  30023. 12
  30024. ],
  30025. [
  30026. 7,
  30027. 12
  30028. ],
  30029. [
  30030. 7,
  30031. 12
  30032. ]
  30033. ];
  30034. var blackTable3 = [
  30035. [
  30036. -1,
  30037. -1
  30038. ],
  30039. [
  30040. -1,
  30041. -1
  30042. ],
  30043. [
  30044. -1,
  30045. -1
  30046. ],
  30047. [
  30048. -1,
  30049. -1
  30050. ],
  30051. // 0000xx
  30052. [
  30053. 6,
  30054. 9
  30055. ],
  30056. // 000100
  30057. [
  30058. 6,
  30059. 8
  30060. ],
  30061. // 000101
  30062. [
  30063. 5,
  30064. 7
  30065. ],
  30066. [
  30067. 5,
  30068. 7
  30069. ],
  30070. // 00011x
  30071. [
  30072. 4,
  30073. 6
  30074. ],
  30075. [
  30076. 4,
  30077. 6
  30078. ],
  30079. [
  30080. 4,
  30081. 6
  30082. ],
  30083. [
  30084. 4,
  30085. 6
  30086. ],
  30087. // 0010xx
  30088. [
  30089. 4,
  30090. 5
  30091. ],
  30092. [
  30093. 4,
  30094. 5
  30095. ],
  30096. [
  30097. 4,
  30098. 5
  30099. ],
  30100. [
  30101. 4,
  30102. 5
  30103. ],
  30104. // 0011xx
  30105. [
  30106. 3,
  30107. 1
  30108. ],
  30109. [
  30110. 3,
  30111. 1
  30112. ],
  30113. [
  30114. 3,
  30115. 1
  30116. ],
  30117. [
  30118. 3,
  30119. 1
  30120. ],
  30121. // 010xxx
  30122. [
  30123. 3,
  30124. 1
  30125. ],
  30126. [
  30127. 3,
  30128. 1
  30129. ],
  30130. [
  30131. 3,
  30132. 1
  30133. ],
  30134. [
  30135. 3,
  30136. 1
  30137. ],
  30138. [
  30139. 3,
  30140. 4
  30141. ],
  30142. [
  30143. 3,
  30144. 4
  30145. ],
  30146. [
  30147. 3,
  30148. 4
  30149. ],
  30150. [
  30151. 3,
  30152. 4
  30153. ],
  30154. // 011xxx
  30155. [
  30156. 3,
  30157. 4
  30158. ],
  30159. [
  30160. 3,
  30161. 4
  30162. ],
  30163. [
  30164. 3,
  30165. 4
  30166. ],
  30167. [
  30168. 3,
  30169. 4
  30170. ],
  30171. [
  30172. 2,
  30173. 3
  30174. ],
  30175. [
  30176. 2,
  30177. 3
  30178. ],
  30179. [
  30180. 2,
  30181. 3
  30182. ],
  30183. [
  30184. 2,
  30185. 3
  30186. ],
  30187. // 10xxxx
  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. 3
  30227. ],
  30228. [
  30229. 2,
  30230. 3
  30231. ],
  30232. [
  30233. 2,
  30234. 3
  30235. ],
  30236. [
  30237. 2,
  30238. 2
  30239. ],
  30240. [
  30241. 2,
  30242. 2
  30243. ],
  30244. [
  30245. 2,
  30246. 2
  30247. ],
  30248. [
  30249. 2,
  30250. 2
  30251. ],
  30252. // 11xxxx
  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. 2,
  30291. 2
  30292. ],
  30293. [
  30294. 2,
  30295. 2
  30296. ],
  30297. [
  30298. 2,
  30299. 2
  30300. ]
  30301. ];
  30302. function CCITTFaxStream(str, maybeLength, params) {
  30303. this.str = str;
  30304. this.dict = str.dict;
  30305. params = params || Dict.empty;
  30306. this.encoding = params.get('K') || 0;
  30307. this.eoline = params.get('EndOfLine') || false;
  30308. this.byteAlign = params.get('EncodedByteAlign') || false;
  30309. this.columns = params.get('Columns') || 1728;
  30310. this.rows = params.get('Rows') || 0;
  30311. var eoblock = params.get('EndOfBlock');
  30312. if (eoblock === null || eoblock === undefined) {
  30313. eoblock = true;
  30314. }
  30315. this.eoblock = eoblock;
  30316. this.black = params.get('BlackIs1') || false;
  30317. this.codingLine = new Uint32Array(this.columns + 1);
  30318. this.refLine = new Uint32Array(this.columns + 2);
  30319. this.codingLine[0] = this.columns;
  30320. this.codingPos = 0;
  30321. this.row = 0;
  30322. this.nextLine2D = this.encoding < 0;
  30323. this.inputBits = 0;
  30324. this.inputBuf = 0;
  30325. this.outputBits = 0;
  30326. var code1;
  30327. while ((code1 = this.lookBits(12)) === 0) {
  30328. this.eatBits(1);
  30329. }
  30330. if (code1 === 1) {
  30331. this.eatBits(12);
  30332. }
  30333. if (this.encoding > 0) {
  30334. this.nextLine2D = !this.lookBits(1);
  30335. this.eatBits(1);
  30336. }
  30337. DecodeStream.call(this, maybeLength);
  30338. }
  30339. CCITTFaxStream.prototype = Object.create(DecodeStream.prototype);
  30340. CCITTFaxStream.prototype.readBlock = function CCITTFaxStream_readBlock() {
  30341. while (!this.eof) {
  30342. var c = this.lookChar();
  30343. this.ensureBuffer(this.bufferLength + 1);
  30344. this.buffer[this.bufferLength++] = c;
  30345. }
  30346. };
  30347. CCITTFaxStream.prototype.addPixels = function ccittFaxStreamAddPixels(a1, blackPixels) {
  30348. var codingLine = this.codingLine;
  30349. var codingPos = this.codingPos;
  30350. if (a1 > codingLine[codingPos]) {
  30351. if (a1 > this.columns) {
  30352. info('row is wrong length');
  30353. this.err = true;
  30354. a1 = this.columns;
  30355. }
  30356. if (codingPos & 1 ^ blackPixels) {
  30357. ++codingPos;
  30358. }
  30359. codingLine[codingPos] = a1;
  30360. }
  30361. this.codingPos = codingPos;
  30362. };
  30363. CCITTFaxStream.prototype.addPixelsNeg = function ccittFaxStreamAddPixelsNeg(a1, blackPixels) {
  30364. var codingLine = this.codingLine;
  30365. var codingPos = this.codingPos;
  30366. if (a1 > codingLine[codingPos]) {
  30367. if (a1 > this.columns) {
  30368. info('row is wrong length');
  30369. this.err = true;
  30370. a1 = this.columns;
  30371. }
  30372. if (codingPos & 1 ^ blackPixels) {
  30373. ++codingPos;
  30374. }
  30375. codingLine[codingPos] = a1;
  30376. } else if (a1 < codingLine[codingPos]) {
  30377. if (a1 < 0) {
  30378. info('invalid code');
  30379. this.err = true;
  30380. a1 = 0;
  30381. }
  30382. while (codingPos > 0 && a1 < codingLine[codingPos - 1]) {
  30383. --codingPos;
  30384. }
  30385. codingLine[codingPos] = a1;
  30386. }
  30387. this.codingPos = codingPos;
  30388. };
  30389. CCITTFaxStream.prototype.lookChar = function CCITTFaxStream_lookChar() {
  30390. var refLine = this.refLine;
  30391. var codingLine = this.codingLine;
  30392. var columns = this.columns;
  30393. var refPos, blackPixels, bits, i;
  30394. if (this.outputBits === 0) {
  30395. if (this.eof) {
  30396. return null;
  30397. }
  30398. this.err = false;
  30399. var code1, code2, code3;
  30400. if (this.nextLine2D) {
  30401. for (i = 0; codingLine[i] < columns; ++i) {
  30402. refLine[i] = codingLine[i];
  30403. }
  30404. refLine[i++] = columns;
  30405. refLine[i] = columns;
  30406. codingLine[0] = 0;
  30407. this.codingPos = 0;
  30408. refPos = 0;
  30409. blackPixels = 0;
  30410. while (codingLine[this.codingPos] < columns) {
  30411. code1 = this.getTwoDimCode();
  30412. switch (code1) {
  30413. case twoDimPass:
  30414. this.addPixels(refLine[refPos + 1], blackPixels);
  30415. if (refLine[refPos + 1] < columns) {
  30416. refPos += 2;
  30417. }
  30418. break;
  30419. case twoDimHoriz:
  30420. code1 = code2 = 0;
  30421. if (blackPixels) {
  30422. do {
  30423. code1 += code3 = this.getBlackCode();
  30424. } while (code3 >= 64);
  30425. do {
  30426. code2 += code3 = this.getWhiteCode();
  30427. } while (code3 >= 64);
  30428. } else {
  30429. do {
  30430. code1 += code3 = this.getWhiteCode();
  30431. } while (code3 >= 64);
  30432. do {
  30433. code2 += code3 = this.getBlackCode();
  30434. } while (code3 >= 64);
  30435. }
  30436. this.addPixels(codingLine[this.codingPos] + code1, blackPixels);
  30437. if (codingLine[this.codingPos] < columns) {
  30438. this.addPixels(codingLine[this.codingPos] + code2, blackPixels ^ 1);
  30439. }
  30440. while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
  30441. refPos += 2;
  30442. }
  30443. break;
  30444. case twoDimVertR3:
  30445. this.addPixels(refLine[refPos] + 3, blackPixels);
  30446. blackPixels ^= 1;
  30447. if (codingLine[this.codingPos] < columns) {
  30448. ++refPos;
  30449. while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
  30450. refPos += 2;
  30451. }
  30452. }
  30453. break;
  30454. case twoDimVertR2:
  30455. this.addPixels(refLine[refPos] + 2, blackPixels);
  30456. blackPixels ^= 1;
  30457. if (codingLine[this.codingPos] < columns) {
  30458. ++refPos;
  30459. while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
  30460. refPos += 2;
  30461. }
  30462. }
  30463. break;
  30464. case twoDimVertR1:
  30465. this.addPixels(refLine[refPos] + 1, blackPixels);
  30466. blackPixels ^= 1;
  30467. if (codingLine[this.codingPos] < columns) {
  30468. ++refPos;
  30469. while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
  30470. refPos += 2;
  30471. }
  30472. }
  30473. break;
  30474. case twoDimVert0:
  30475. this.addPixels(refLine[refPos], blackPixels);
  30476. blackPixels ^= 1;
  30477. if (codingLine[this.codingPos] < columns) {
  30478. ++refPos;
  30479. while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
  30480. refPos += 2;
  30481. }
  30482. }
  30483. break;
  30484. case twoDimVertL3:
  30485. this.addPixelsNeg(refLine[refPos] - 3, blackPixels);
  30486. blackPixels ^= 1;
  30487. if (codingLine[this.codingPos] < columns) {
  30488. if (refPos > 0) {
  30489. --refPos;
  30490. } else {
  30491. ++refPos;
  30492. }
  30493. while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
  30494. refPos += 2;
  30495. }
  30496. }
  30497. break;
  30498. case twoDimVertL2:
  30499. this.addPixelsNeg(refLine[refPos] - 2, blackPixels);
  30500. blackPixels ^= 1;
  30501. if (codingLine[this.codingPos] < columns) {
  30502. if (refPos > 0) {
  30503. --refPos;
  30504. } else {
  30505. ++refPos;
  30506. }
  30507. while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
  30508. refPos += 2;
  30509. }
  30510. }
  30511. break;
  30512. case twoDimVertL1:
  30513. this.addPixelsNeg(refLine[refPos] - 1, blackPixels);
  30514. blackPixels ^= 1;
  30515. if (codingLine[this.codingPos] < columns) {
  30516. if (refPos > 0) {
  30517. --refPos;
  30518. } else {
  30519. ++refPos;
  30520. }
  30521. while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
  30522. refPos += 2;
  30523. }
  30524. }
  30525. break;
  30526. case ccittEOF:
  30527. this.addPixels(columns, 0);
  30528. this.eof = true;
  30529. break;
  30530. default:
  30531. info('bad 2d code');
  30532. this.addPixels(columns, 0);
  30533. this.err = true;
  30534. }
  30535. }
  30536. } else {
  30537. codingLine[0] = 0;
  30538. this.codingPos = 0;
  30539. blackPixels = 0;
  30540. while (codingLine[this.codingPos] < columns) {
  30541. code1 = 0;
  30542. if (blackPixels) {
  30543. do {
  30544. code1 += code3 = this.getBlackCode();
  30545. } while (code3 >= 64);
  30546. } else {
  30547. do {
  30548. code1 += code3 = this.getWhiteCode();
  30549. } while (code3 >= 64);
  30550. }
  30551. this.addPixels(codingLine[this.codingPos] + code1, blackPixels);
  30552. blackPixels ^= 1;
  30553. }
  30554. }
  30555. var gotEOL = false;
  30556. if (this.byteAlign) {
  30557. this.inputBits &= ~7;
  30558. }
  30559. if (!this.eoblock && this.row === this.rows - 1) {
  30560. this.eof = true;
  30561. } else {
  30562. code1 = this.lookBits(12);
  30563. if (this.eoline) {
  30564. while (code1 !== ccittEOF && code1 !== 1) {
  30565. this.eatBits(1);
  30566. code1 = this.lookBits(12);
  30567. }
  30568. } else {
  30569. while (code1 === 0) {
  30570. this.eatBits(1);
  30571. code1 = this.lookBits(12);
  30572. }
  30573. }
  30574. if (code1 === 1) {
  30575. this.eatBits(12);
  30576. gotEOL = true;
  30577. } else if (code1 === ccittEOF) {
  30578. this.eof = true;
  30579. }
  30580. }
  30581. if (!this.eof && this.encoding > 0) {
  30582. this.nextLine2D = !this.lookBits(1);
  30583. this.eatBits(1);
  30584. }
  30585. if (this.eoblock && gotEOL && this.byteAlign) {
  30586. code1 = this.lookBits(12);
  30587. if (code1 === 1) {
  30588. this.eatBits(12);
  30589. if (this.encoding > 0) {
  30590. this.lookBits(1);
  30591. this.eatBits(1);
  30592. }
  30593. if (this.encoding >= 0) {
  30594. for (i = 0; i < 4; ++i) {
  30595. code1 = this.lookBits(12);
  30596. if (code1 !== 1) {
  30597. info('bad rtc code: ' + code1);
  30598. }
  30599. this.eatBits(12);
  30600. if (this.encoding > 0) {
  30601. this.lookBits(1);
  30602. this.eatBits(1);
  30603. }
  30604. }
  30605. }
  30606. this.eof = true;
  30607. }
  30608. } else if (this.err && this.eoline) {
  30609. while (true) {
  30610. code1 = this.lookBits(13);
  30611. if (code1 === ccittEOF) {
  30612. this.eof = true;
  30613. return null;
  30614. }
  30615. if (code1 >> 1 === 1) {
  30616. break;
  30617. }
  30618. this.eatBits(1);
  30619. }
  30620. this.eatBits(12);
  30621. if (this.encoding > 0) {
  30622. this.eatBits(1);
  30623. this.nextLine2D = !(code1 & 1);
  30624. }
  30625. }
  30626. if (codingLine[0] > 0) {
  30627. this.outputBits = codingLine[this.codingPos = 0];
  30628. } else {
  30629. this.outputBits = codingLine[this.codingPos = 1];
  30630. }
  30631. this.row++;
  30632. }
  30633. var c;
  30634. if (this.outputBits >= 8) {
  30635. c = this.codingPos & 1 ? 0 : 0xFF;
  30636. this.outputBits -= 8;
  30637. if (this.outputBits === 0 && codingLine[this.codingPos] < columns) {
  30638. this.codingPos++;
  30639. this.outputBits = codingLine[this.codingPos] - codingLine[this.codingPos - 1];
  30640. }
  30641. } else {
  30642. bits = 8;
  30643. c = 0;
  30644. do {
  30645. if (this.outputBits > bits) {
  30646. c <<= bits;
  30647. if (!(this.codingPos & 1)) {
  30648. c |= 0xFF >> 8 - bits;
  30649. }
  30650. this.outputBits -= bits;
  30651. bits = 0;
  30652. } else {
  30653. c <<= this.outputBits;
  30654. if (!(this.codingPos & 1)) {
  30655. c |= 0xFF >> 8 - this.outputBits;
  30656. }
  30657. bits -= this.outputBits;
  30658. this.outputBits = 0;
  30659. if (codingLine[this.codingPos] < columns) {
  30660. this.codingPos++;
  30661. this.outputBits = codingLine[this.codingPos] - codingLine[this.codingPos - 1];
  30662. } else if (bits > 0) {
  30663. c <<= bits;
  30664. bits = 0;
  30665. }
  30666. }
  30667. } while (bits);
  30668. }
  30669. if (this.black) {
  30670. c ^= 0xFF;
  30671. }
  30672. return c;
  30673. };
  30674. // This functions returns the code found from the table.
  30675. // The start and end parameters set the boundaries for searching the table.
  30676. // The limit parameter is optional. Function returns an array with three
  30677. // values. The first array element indicates whether a valid code is being
  30678. // returned. The second array element is the actual code. The third array
  30679. // element indicates whether EOF was reached.
  30680. CCITTFaxStream.prototype.findTableCode = function ccittFaxStreamFindTableCode(start, end, table, limit) {
  30681. var limitValue = limit || 0;
  30682. for (var i = start; i <= end; ++i) {
  30683. var code = this.lookBits(i);
  30684. if (code === ccittEOF) {
  30685. return [
  30686. true,
  30687. 1,
  30688. false
  30689. ];
  30690. }
  30691. if (i < end) {
  30692. code <<= end - i;
  30693. }
  30694. if (!limitValue || code >= limitValue) {
  30695. var p = table[code - limitValue];
  30696. if (p[0] === i) {
  30697. this.eatBits(i);
  30698. return [
  30699. true,
  30700. p[1],
  30701. true
  30702. ];
  30703. }
  30704. }
  30705. }
  30706. return [
  30707. false,
  30708. 0,
  30709. false
  30710. ];
  30711. };
  30712. CCITTFaxStream.prototype.getTwoDimCode = function ccittFaxStreamGetTwoDimCode() {
  30713. var code = 0;
  30714. var p;
  30715. if (this.eoblock) {
  30716. code = this.lookBits(7);
  30717. p = twoDimTable[code];
  30718. if (p && p[0] > 0) {
  30719. this.eatBits(p[0]);
  30720. return p[1];
  30721. }
  30722. } else {
  30723. var result = this.findTableCode(1, 7, twoDimTable);
  30724. if (result[0] && result[2]) {
  30725. return result[1];
  30726. }
  30727. }
  30728. info('Bad two dim code');
  30729. return ccittEOF;
  30730. };
  30731. CCITTFaxStream.prototype.getWhiteCode = function ccittFaxStreamGetWhiteCode() {
  30732. var code = 0;
  30733. var p;
  30734. if (this.eoblock) {
  30735. code = this.lookBits(12);
  30736. if (code === ccittEOF) {
  30737. return 1;
  30738. }
  30739. if (code >> 5 === 0) {
  30740. p = whiteTable1[code];
  30741. } else {
  30742. p = whiteTable2[code >> 3];
  30743. }
  30744. if (p[0] > 0) {
  30745. this.eatBits(p[0]);
  30746. return p[1];
  30747. }
  30748. } else {
  30749. var result = this.findTableCode(1, 9, whiteTable2);
  30750. if (result[0]) {
  30751. return result[1];
  30752. }
  30753. result = this.findTableCode(11, 12, whiteTable1);
  30754. if (result[0]) {
  30755. return result[1];
  30756. }
  30757. }
  30758. info('bad white code');
  30759. this.eatBits(1);
  30760. return 1;
  30761. };
  30762. CCITTFaxStream.prototype.getBlackCode = function ccittFaxStreamGetBlackCode() {
  30763. var code, p;
  30764. if (this.eoblock) {
  30765. code = this.lookBits(13);
  30766. if (code === ccittEOF) {
  30767. return 1;
  30768. }
  30769. if (code >> 7 === 0) {
  30770. p = blackTable1[code];
  30771. } else if (code >> 9 === 0 && code >> 7 !== 0) {
  30772. p = blackTable2[(code >> 1) - 64];
  30773. } else {
  30774. p = blackTable3[code >> 7];
  30775. }
  30776. if (p[0] > 0) {
  30777. this.eatBits(p[0]);
  30778. return p[1];
  30779. }
  30780. } else {
  30781. var result = this.findTableCode(2, 6, blackTable3);
  30782. if (result[0]) {
  30783. return result[1];
  30784. }
  30785. result = this.findTableCode(7, 12, blackTable2, 64);
  30786. if (result[0]) {
  30787. return result[1];
  30788. }
  30789. result = this.findTableCode(10, 13, blackTable1);
  30790. if (result[0]) {
  30791. return result[1];
  30792. }
  30793. }
  30794. info('bad black code');
  30795. this.eatBits(1);
  30796. return 1;
  30797. };
  30798. CCITTFaxStream.prototype.lookBits = function CCITTFaxStream_lookBits(n) {
  30799. var c;
  30800. while (this.inputBits < n) {
  30801. if ((c = this.str.getByte()) === -1) {
  30802. if (this.inputBits === 0) {
  30803. return ccittEOF;
  30804. }
  30805. return this.inputBuf << n - this.inputBits & 0xFFFF >> 16 - n;
  30806. }
  30807. this.inputBuf = this.inputBuf << 8 | c;
  30808. this.inputBits += 8;
  30809. }
  30810. return this.inputBuf >> this.inputBits - n & 0xFFFF >> 16 - n;
  30811. };
  30812. CCITTFaxStream.prototype.eatBits = function CCITTFaxStream_eatBits(n) {
  30813. if ((this.inputBits -= n) < 0) {
  30814. this.inputBits = 0;
  30815. }
  30816. };
  30817. return CCITTFaxStream;
  30818. }();
  30819. var LZWStream = function LZWStreamClosure() {
  30820. function LZWStream(str, maybeLength, earlyChange) {
  30821. this.str = str;
  30822. this.dict = str.dict;
  30823. this.cachedData = 0;
  30824. this.bitsCached = 0;
  30825. var maxLzwDictionarySize = 4096;
  30826. var lzwState = {
  30827. earlyChange: earlyChange,
  30828. codeLength: 9,
  30829. nextCode: 258,
  30830. dictionaryValues: new Uint8Array(maxLzwDictionarySize),
  30831. dictionaryLengths: new Uint16Array(maxLzwDictionarySize),
  30832. dictionaryPrevCodes: new Uint16Array(maxLzwDictionarySize),
  30833. currentSequence: new Uint8Array(maxLzwDictionarySize),
  30834. currentSequenceLength: 0
  30835. };
  30836. for (var i = 0; i < 256; ++i) {
  30837. lzwState.dictionaryValues[i] = i;
  30838. lzwState.dictionaryLengths[i] = 1;
  30839. }
  30840. this.lzwState = lzwState;
  30841. DecodeStream.call(this, maybeLength);
  30842. }
  30843. LZWStream.prototype = Object.create(DecodeStream.prototype);
  30844. LZWStream.prototype.readBits = function LZWStream_readBits(n) {
  30845. var bitsCached = this.bitsCached;
  30846. var cachedData = this.cachedData;
  30847. while (bitsCached < n) {
  30848. var c = this.str.getByte();
  30849. if (c === -1) {
  30850. this.eof = true;
  30851. return null;
  30852. }
  30853. cachedData = cachedData << 8 | c;
  30854. bitsCached += 8;
  30855. }
  30856. this.bitsCached = bitsCached -= n;
  30857. this.cachedData = cachedData;
  30858. this.lastCode = null;
  30859. return cachedData >>> bitsCached & (1 << n) - 1;
  30860. };
  30861. LZWStream.prototype.readBlock = function LZWStream_readBlock() {
  30862. var blockSize = 512;
  30863. var estimatedDecodedSize = blockSize * 2, decodedSizeDelta = blockSize;
  30864. var i, j, q;
  30865. var lzwState = this.lzwState;
  30866. if (!lzwState) {
  30867. return;
  30868. }
  30869. // eof was found
  30870. var earlyChange = lzwState.earlyChange;
  30871. var nextCode = lzwState.nextCode;
  30872. var dictionaryValues = lzwState.dictionaryValues;
  30873. var dictionaryLengths = lzwState.dictionaryLengths;
  30874. var dictionaryPrevCodes = lzwState.dictionaryPrevCodes;
  30875. var codeLength = lzwState.codeLength;
  30876. var prevCode = lzwState.prevCode;
  30877. var currentSequence = lzwState.currentSequence;
  30878. var currentSequenceLength = lzwState.currentSequenceLength;
  30879. var decodedLength = 0;
  30880. var currentBufferLength = this.bufferLength;
  30881. var buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  30882. for (i = 0; i < blockSize; i++) {
  30883. var code = this.readBits(codeLength);
  30884. var hasPrev = currentSequenceLength > 0;
  30885. if (code < 256) {
  30886. currentSequence[0] = code;
  30887. currentSequenceLength = 1;
  30888. } else if (code >= 258) {
  30889. if (code < nextCode) {
  30890. currentSequenceLength = dictionaryLengths[code];
  30891. for (j = currentSequenceLength - 1, q = code; j >= 0; j--) {
  30892. currentSequence[j] = dictionaryValues[q];
  30893. q = dictionaryPrevCodes[q];
  30894. }
  30895. } else {
  30896. currentSequence[currentSequenceLength++] = currentSequence[0];
  30897. }
  30898. } else if (code === 256) {
  30899. codeLength = 9;
  30900. nextCode = 258;
  30901. currentSequenceLength = 0;
  30902. continue;
  30903. } else {
  30904. this.eof = true;
  30905. delete this.lzwState;
  30906. break;
  30907. }
  30908. if (hasPrev) {
  30909. dictionaryPrevCodes[nextCode] = prevCode;
  30910. dictionaryLengths[nextCode] = dictionaryLengths[prevCode] + 1;
  30911. dictionaryValues[nextCode] = currentSequence[0];
  30912. nextCode++;
  30913. codeLength = nextCode + earlyChange & nextCode + earlyChange - 1 ? codeLength : Math.min(Math.log(nextCode + earlyChange) / 0.6931471805599453 + 1, 12) | 0;
  30914. }
  30915. prevCode = code;
  30916. decodedLength += currentSequenceLength;
  30917. if (estimatedDecodedSize < decodedLength) {
  30918. do {
  30919. estimatedDecodedSize += decodedSizeDelta;
  30920. } while (estimatedDecodedSize < decodedLength);
  30921. buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  30922. }
  30923. for (j = 0; j < currentSequenceLength; j++) {
  30924. buffer[currentBufferLength++] = currentSequence[j];
  30925. }
  30926. }
  30927. lzwState.nextCode = nextCode;
  30928. lzwState.codeLength = codeLength;
  30929. lzwState.prevCode = prevCode;
  30930. lzwState.currentSequenceLength = currentSequenceLength;
  30931. this.bufferLength = currentBufferLength;
  30932. };
  30933. return LZWStream;
  30934. }();
  30935. var NullStream = function NullStreamClosure() {
  30936. function NullStream() {
  30937. Stream.call(this, new Uint8Array(0));
  30938. }
  30939. NullStream.prototype = Stream.prototype;
  30940. return NullStream;
  30941. }();
  30942. exports.Ascii85Stream = Ascii85Stream;
  30943. exports.AsciiHexStream = AsciiHexStream;
  30944. exports.CCITTFaxStream = CCITTFaxStream;
  30945. exports.DecryptStream = DecryptStream;
  30946. exports.DecodeStream = DecodeStream;
  30947. exports.FlateStream = FlateStream;
  30948. exports.Jbig2Stream = Jbig2Stream;
  30949. exports.JpegStream = JpegStream;
  30950. exports.JpxStream = JpxStream;
  30951. exports.NullStream = NullStream;
  30952. exports.PredictorStream = PredictorStream;
  30953. exports.RunLengthStream = RunLengthStream;
  30954. exports.Stream = Stream;
  30955. exports.StreamsSequenceStream = StreamsSequenceStream;
  30956. exports.StringStream = StringStream;
  30957. exports.LZWStream = LZWStream;
  30958. }));
  30959. (function (root, factory) {
  30960. factory(root.pdfjsCoreCrypto = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCoreStream);
  30961. }(this, function (exports, sharedUtil, corePrimitives, coreStream) {
  30962. var PasswordException = sharedUtil.PasswordException;
  30963. var PasswordResponses = sharedUtil.PasswordResponses;
  30964. var bytesToString = sharedUtil.bytesToString;
  30965. var warn = sharedUtil.warn;
  30966. var error = sharedUtil.error;
  30967. var assert = sharedUtil.assert;
  30968. var isInt = sharedUtil.isInt;
  30969. var stringToBytes = sharedUtil.stringToBytes;
  30970. var utf8StringToString = sharedUtil.utf8StringToString;
  30971. var Name = corePrimitives.Name;
  30972. var isName = corePrimitives.isName;
  30973. var isDict = corePrimitives.isDict;
  30974. var DecryptStream = coreStream.DecryptStream;
  30975. var ARCFourCipher = function ARCFourCipherClosure() {
  30976. function ARCFourCipher(key) {
  30977. this.a = 0;
  30978. this.b = 0;
  30979. var s = new Uint8Array(256);
  30980. var i, j = 0, tmp, keyLength = key.length;
  30981. for (i = 0; i < 256; ++i) {
  30982. s[i] = i;
  30983. }
  30984. for (i = 0; i < 256; ++i) {
  30985. tmp = s[i];
  30986. j = j + tmp + key[i % keyLength] & 0xFF;
  30987. s[i] = s[j];
  30988. s[j] = tmp;
  30989. }
  30990. this.s = s;
  30991. }
  30992. ARCFourCipher.prototype = {
  30993. encryptBlock: function ARCFourCipher_encryptBlock(data) {
  30994. var i, n = data.length, tmp, tmp2;
  30995. var a = this.a, b = this.b, s = this.s;
  30996. var output = new Uint8Array(n);
  30997. for (i = 0; i < n; ++i) {
  30998. a = a + 1 & 0xFF;
  30999. tmp = s[a];
  31000. b = b + tmp & 0xFF;
  31001. tmp2 = s[b];
  31002. s[a] = tmp2;
  31003. s[b] = tmp;
  31004. output[i] = data[i] ^ s[tmp + tmp2 & 0xFF];
  31005. }
  31006. this.a = a;
  31007. this.b = b;
  31008. return output;
  31009. }
  31010. };
  31011. ARCFourCipher.prototype.decryptBlock = ARCFourCipher.prototype.encryptBlock;
  31012. return ARCFourCipher;
  31013. }();
  31014. var calculateMD5 = function calculateMD5Closure() {
  31015. var r = new Uint8Array([
  31016. 7,
  31017. 12,
  31018. 17,
  31019. 22,
  31020. 7,
  31021. 12,
  31022. 17,
  31023. 22,
  31024. 7,
  31025. 12,
  31026. 17,
  31027. 22,
  31028. 7,
  31029. 12,
  31030. 17,
  31031. 22,
  31032. 5,
  31033. 9,
  31034. 14,
  31035. 20,
  31036. 5,
  31037. 9,
  31038. 14,
  31039. 20,
  31040. 5,
  31041. 9,
  31042. 14,
  31043. 20,
  31044. 5,
  31045. 9,
  31046. 14,
  31047. 20,
  31048. 4,
  31049. 11,
  31050. 16,
  31051. 23,
  31052. 4,
  31053. 11,
  31054. 16,
  31055. 23,
  31056. 4,
  31057. 11,
  31058. 16,
  31059. 23,
  31060. 4,
  31061. 11,
  31062. 16,
  31063. 23,
  31064. 6,
  31065. 10,
  31066. 15,
  31067. 21,
  31068. 6,
  31069. 10,
  31070. 15,
  31071. 21,
  31072. 6,
  31073. 10,
  31074. 15,
  31075. 21,
  31076. 6,
  31077. 10,
  31078. 15,
  31079. 21
  31080. ]);
  31081. var k = new Int32Array([
  31082. -680876936,
  31083. -389564586,
  31084. 606105819,
  31085. -1044525330,
  31086. -176418897,
  31087. 1200080426,
  31088. -1473231341,
  31089. -45705983,
  31090. 1770035416,
  31091. -1958414417,
  31092. -42063,
  31093. -1990404162,
  31094. 1804603682,
  31095. -40341101,
  31096. -1502002290,
  31097. 1236535329,
  31098. -165796510,
  31099. -1069501632,
  31100. 643717713,
  31101. -373897302,
  31102. -701558691,
  31103. 38016083,
  31104. -660478335,
  31105. -405537848,
  31106. 568446438,
  31107. -1019803690,
  31108. -187363961,
  31109. 1163531501,
  31110. -1444681467,
  31111. -51403784,
  31112. 1735328473,
  31113. -1926607734,
  31114. -378558,
  31115. -2022574463,
  31116. 1839030562,
  31117. -35309556,
  31118. -1530992060,
  31119. 1272893353,
  31120. -155497632,
  31121. -1094730640,
  31122. 681279174,
  31123. -358537222,
  31124. -722521979,
  31125. 76029189,
  31126. -640364487,
  31127. -421815835,
  31128. 530742520,
  31129. -995338651,
  31130. -198630844,
  31131. 1126891415,
  31132. -1416354905,
  31133. -57434055,
  31134. 1700485571,
  31135. -1894986606,
  31136. -1051523,
  31137. -2054922799,
  31138. 1873313359,
  31139. -30611744,
  31140. -1560198380,
  31141. 1309151649,
  31142. -145523070,
  31143. -1120210379,
  31144. 718787259,
  31145. -343485551
  31146. ]);
  31147. function hash(data, offset, length) {
  31148. var h0 = 1732584193, h1 = -271733879, h2 = -1732584194, h3 = 271733878;
  31149. // pre-processing
  31150. var paddedLength = length + 72 & ~63;
  31151. // data + 9 extra bytes
  31152. var padded = new Uint8Array(paddedLength);
  31153. var i, j, n;
  31154. for (i = 0; i < length; ++i) {
  31155. padded[i] = data[offset++];
  31156. }
  31157. padded[i++] = 0x80;
  31158. n = paddedLength - 8;
  31159. while (i < n) {
  31160. padded[i++] = 0;
  31161. }
  31162. padded[i++] = length << 3 & 0xFF;
  31163. padded[i++] = length >> 5 & 0xFF;
  31164. padded[i++] = length >> 13 & 0xFF;
  31165. padded[i++] = length >> 21 & 0xFF;
  31166. padded[i++] = length >>> 29 & 0xFF;
  31167. padded[i++] = 0;
  31168. padded[i++] = 0;
  31169. padded[i++] = 0;
  31170. var w = new Int32Array(16);
  31171. for (i = 0; i < paddedLength;) {
  31172. for (j = 0; j < 16; ++j, i += 4) {
  31173. w[j] = padded[i] | padded[i + 1] << 8 | padded[i + 2] << 16 | padded[i + 3] << 24;
  31174. }
  31175. var a = h0, b = h1, c = h2, d = h3, f, g;
  31176. for (j = 0; j < 64; ++j) {
  31177. if (j < 16) {
  31178. f = b & c | ~b & d;
  31179. g = j;
  31180. } else if (j < 32) {
  31181. f = d & b | ~d & c;
  31182. g = 5 * j + 1 & 15;
  31183. } else if (j < 48) {
  31184. f = b ^ c ^ d;
  31185. g = 3 * j + 5 & 15;
  31186. } else {
  31187. f = c ^ (b | ~d);
  31188. g = 7 * j & 15;
  31189. }
  31190. var tmp = d, rotateArg = a + f + k[j] + w[g] | 0, rotate = r[j];
  31191. d = c;
  31192. c = b;
  31193. b = b + (rotateArg << rotate | rotateArg >>> 32 - rotate) | 0;
  31194. a = tmp;
  31195. }
  31196. h0 = h0 + a | 0;
  31197. h1 = h1 + b | 0;
  31198. h2 = h2 + c | 0;
  31199. h3 = h3 + d | 0;
  31200. }
  31201. return new Uint8Array([
  31202. h0 & 0xFF,
  31203. h0 >> 8 & 0xFF,
  31204. h0 >> 16 & 0xFF,
  31205. h0 >>> 24 & 0xFF,
  31206. h1 & 0xFF,
  31207. h1 >> 8 & 0xFF,
  31208. h1 >> 16 & 0xFF,
  31209. h1 >>> 24 & 0xFF,
  31210. h2 & 0xFF,
  31211. h2 >> 8 & 0xFF,
  31212. h2 >> 16 & 0xFF,
  31213. h2 >>> 24 & 0xFF,
  31214. h3 & 0xFF,
  31215. h3 >> 8 & 0xFF,
  31216. h3 >> 16 & 0xFF,
  31217. h3 >>> 24 & 0xFF
  31218. ]);
  31219. }
  31220. return hash;
  31221. }();
  31222. var Word64 = function Word64Closure() {
  31223. function Word64(highInteger, lowInteger) {
  31224. this.high = highInteger | 0;
  31225. this.low = lowInteger | 0;
  31226. }
  31227. Word64.prototype = {
  31228. and: function Word64_and(word) {
  31229. this.high &= word.high;
  31230. this.low &= word.low;
  31231. },
  31232. xor: function Word64_xor(word) {
  31233. this.high ^= word.high;
  31234. this.low ^= word.low;
  31235. },
  31236. or: function Word64_or(word) {
  31237. this.high |= word.high;
  31238. this.low |= word.low;
  31239. },
  31240. shiftRight: function Word64_shiftRight(places) {
  31241. if (places >= 32) {
  31242. this.low = this.high >>> places - 32 | 0;
  31243. this.high = 0;
  31244. } else {
  31245. this.low = this.low >>> places | this.high << 32 - places;
  31246. this.high = this.high >>> places | 0;
  31247. }
  31248. },
  31249. shiftLeft: function Word64_shiftLeft(places) {
  31250. if (places >= 32) {
  31251. this.high = this.low << places - 32;
  31252. this.low = 0;
  31253. } else {
  31254. this.high = this.high << places | this.low >>> 32 - places;
  31255. this.low = this.low << places;
  31256. }
  31257. },
  31258. rotateRight: function Word64_rotateRight(places) {
  31259. var low, high;
  31260. if (places & 32) {
  31261. high = this.low;
  31262. low = this.high;
  31263. } else {
  31264. low = this.low;
  31265. high = this.high;
  31266. }
  31267. places &= 31;
  31268. this.low = low >>> places | high << 32 - places;
  31269. this.high = high >>> places | low << 32 - places;
  31270. },
  31271. not: function Word64_not() {
  31272. this.high = ~this.high;
  31273. this.low = ~this.low;
  31274. },
  31275. add: function Word64_add(word) {
  31276. var lowAdd = (this.low >>> 0) + (word.low >>> 0);
  31277. var highAdd = (this.high >>> 0) + (word.high >>> 0);
  31278. if (lowAdd > 0xFFFFFFFF) {
  31279. highAdd += 1;
  31280. }
  31281. this.low = lowAdd | 0;
  31282. this.high = highAdd | 0;
  31283. },
  31284. copyTo: function Word64_copyTo(bytes, offset) {
  31285. bytes[offset] = this.high >>> 24 & 0xFF;
  31286. bytes[offset + 1] = this.high >> 16 & 0xFF;
  31287. bytes[offset + 2] = this.high >> 8 & 0xFF;
  31288. bytes[offset + 3] = this.high & 0xFF;
  31289. bytes[offset + 4] = this.low >>> 24 & 0xFF;
  31290. bytes[offset + 5] = this.low >> 16 & 0xFF;
  31291. bytes[offset + 6] = this.low >> 8 & 0xFF;
  31292. bytes[offset + 7] = this.low & 0xFF;
  31293. },
  31294. assign: function Word64_assign(word) {
  31295. this.high = word.high;
  31296. this.low = word.low;
  31297. }
  31298. };
  31299. return Word64;
  31300. }();
  31301. var calculateSHA256 = function calculateSHA256Closure() {
  31302. function rotr(x, n) {
  31303. return x >>> n | x << 32 - n;
  31304. }
  31305. function ch(x, y, z) {
  31306. return x & y ^ ~x & z;
  31307. }
  31308. function maj(x, y, z) {
  31309. return x & y ^ x & z ^ y & z;
  31310. }
  31311. function sigma(x) {
  31312. return rotr(x, 2) ^ rotr(x, 13) ^ rotr(x, 22);
  31313. }
  31314. function sigmaPrime(x) {
  31315. return rotr(x, 6) ^ rotr(x, 11) ^ rotr(x, 25);
  31316. }
  31317. function littleSigma(x) {
  31318. return rotr(x, 7) ^ rotr(x, 18) ^ x >>> 3;
  31319. }
  31320. function littleSigmaPrime(x) {
  31321. return rotr(x, 17) ^ rotr(x, 19) ^ x >>> 10;
  31322. }
  31323. var k = [
  31324. 0x428a2f98,
  31325. 0x71374491,
  31326. 0xb5c0fbcf,
  31327. 0xe9b5dba5,
  31328. 0x3956c25b,
  31329. 0x59f111f1,
  31330. 0x923f82a4,
  31331. 0xab1c5ed5,
  31332. 0xd807aa98,
  31333. 0x12835b01,
  31334. 0x243185be,
  31335. 0x550c7dc3,
  31336. 0x72be5d74,
  31337. 0x80deb1fe,
  31338. 0x9bdc06a7,
  31339. 0xc19bf174,
  31340. 0xe49b69c1,
  31341. 0xefbe4786,
  31342. 0x0fc19dc6,
  31343. 0x240ca1cc,
  31344. 0x2de92c6f,
  31345. 0x4a7484aa,
  31346. 0x5cb0a9dc,
  31347. 0x76f988da,
  31348. 0x983e5152,
  31349. 0xa831c66d,
  31350. 0xb00327c8,
  31351. 0xbf597fc7,
  31352. 0xc6e00bf3,
  31353. 0xd5a79147,
  31354. 0x06ca6351,
  31355. 0x14292967,
  31356. 0x27b70a85,
  31357. 0x2e1b2138,
  31358. 0x4d2c6dfc,
  31359. 0x53380d13,
  31360. 0x650a7354,
  31361. 0x766a0abb,
  31362. 0x81c2c92e,
  31363. 0x92722c85,
  31364. 0xa2bfe8a1,
  31365. 0xa81a664b,
  31366. 0xc24b8b70,
  31367. 0xc76c51a3,
  31368. 0xd192e819,
  31369. 0xd6990624,
  31370. 0xf40e3585,
  31371. 0x106aa070,
  31372. 0x19a4c116,
  31373. 0x1e376c08,
  31374. 0x2748774c,
  31375. 0x34b0bcb5,
  31376. 0x391c0cb3,
  31377. 0x4ed8aa4a,
  31378. 0x5b9cca4f,
  31379. 0x682e6ff3,
  31380. 0x748f82ee,
  31381. 0x78a5636f,
  31382. 0x84c87814,
  31383. 0x8cc70208,
  31384. 0x90befffa,
  31385. 0xa4506ceb,
  31386. 0xbef9a3f7,
  31387. 0xc67178f2
  31388. ];
  31389. function hash(data, offset, length) {
  31390. // initial hash values
  31391. var h0 = 0x6a09e667, h1 = 0xbb67ae85, h2 = 0x3c6ef372, h3 = 0xa54ff53a, h4 = 0x510e527f, h5 = 0x9b05688c, h6 = 0x1f83d9ab, h7 = 0x5be0cd19;
  31392. // pre-processing
  31393. var paddedLength = Math.ceil((length + 9) / 64) * 64;
  31394. var padded = new Uint8Array(paddedLength);
  31395. var i, j, n;
  31396. for (i = 0; i < length; ++i) {
  31397. padded[i] = data[offset++];
  31398. }
  31399. padded[i++] = 0x80;
  31400. n = paddedLength - 8;
  31401. while (i < n) {
  31402. padded[i++] = 0;
  31403. }
  31404. padded[i++] = 0;
  31405. padded[i++] = 0;
  31406. padded[i++] = 0;
  31407. padded[i++] = length >>> 29 & 0xFF;
  31408. padded[i++] = length >> 21 & 0xFF;
  31409. padded[i++] = length >> 13 & 0xFF;
  31410. padded[i++] = length >> 5 & 0xFF;
  31411. padded[i++] = length << 3 & 0xFF;
  31412. var w = new Uint32Array(64);
  31413. // for each 512 bit block
  31414. for (i = 0; i < paddedLength;) {
  31415. for (j = 0; j < 16; ++j) {
  31416. w[j] = padded[i] << 24 | padded[i + 1] << 16 | padded[i + 2] << 8 | padded[i + 3];
  31417. i += 4;
  31418. }
  31419. for (j = 16; j < 64; ++j) {
  31420. w[j] = littleSigmaPrime(w[j - 2]) + w[j - 7] + littleSigma(w[j - 15]) + w[j - 16] | 0;
  31421. }
  31422. var a = h0, b = h1, c = h2, d = h3, e = h4, f = h5, g = h6, h = h7, t1, t2;
  31423. for (j = 0; j < 64; ++j) {
  31424. t1 = h + sigmaPrime(e) + ch(e, f, g) + k[j] + w[j];
  31425. t2 = sigma(a) + maj(a, b, c);
  31426. h = g;
  31427. g = f;
  31428. f = e;
  31429. e = d + t1 | 0;
  31430. d = c;
  31431. c = b;
  31432. b = a;
  31433. a = t1 + t2 | 0;
  31434. }
  31435. h0 = h0 + a | 0;
  31436. h1 = h1 + b | 0;
  31437. h2 = h2 + c | 0;
  31438. h3 = h3 + d | 0;
  31439. h4 = h4 + e | 0;
  31440. h5 = h5 + f | 0;
  31441. h6 = h6 + g | 0;
  31442. h7 = h7 + h | 0;
  31443. }
  31444. return new Uint8Array([
  31445. h0 >> 24 & 0xFF,
  31446. h0 >> 16 & 0xFF,
  31447. h0 >> 8 & 0xFF,
  31448. h0 & 0xFF,
  31449. h1 >> 24 & 0xFF,
  31450. h1 >> 16 & 0xFF,
  31451. h1 >> 8 & 0xFF,
  31452. h1 & 0xFF,
  31453. h2 >> 24 & 0xFF,
  31454. h2 >> 16 & 0xFF,
  31455. h2 >> 8 & 0xFF,
  31456. h2 & 0xFF,
  31457. h3 >> 24 & 0xFF,
  31458. h3 >> 16 & 0xFF,
  31459. h3 >> 8 & 0xFF,
  31460. h3 & 0xFF,
  31461. h4 >> 24 & 0xFF,
  31462. h4 >> 16 & 0xFF,
  31463. h4 >> 8 & 0xFF,
  31464. h4 & 0xFF,
  31465. h5 >> 24 & 0xFF,
  31466. h5 >> 16 & 0xFF,
  31467. h5 >> 8 & 0xFF,
  31468. h5 & 0xFF,
  31469. h6 >> 24 & 0xFF,
  31470. h6 >> 16 & 0xFF,
  31471. h6 >> 8 & 0xFF,
  31472. h6 & 0xFF,
  31473. h7 >> 24 & 0xFF,
  31474. h7 >> 16 & 0xFF,
  31475. h7 >> 8 & 0xFF,
  31476. h7 & 0xFF
  31477. ]);
  31478. }
  31479. return hash;
  31480. }();
  31481. var calculateSHA512 = function calculateSHA512Closure() {
  31482. function ch(result, x, y, z, tmp) {
  31483. result.assign(x);
  31484. result.and(y);
  31485. tmp.assign(x);
  31486. tmp.not();
  31487. tmp.and(z);
  31488. result.xor(tmp);
  31489. }
  31490. function maj(result, x, y, z, tmp) {
  31491. result.assign(x);
  31492. result.and(y);
  31493. tmp.assign(x);
  31494. tmp.and(z);
  31495. result.xor(tmp);
  31496. tmp.assign(y);
  31497. tmp.and(z);
  31498. result.xor(tmp);
  31499. }
  31500. function sigma(result, x, tmp) {
  31501. result.assign(x);
  31502. result.rotateRight(28);
  31503. tmp.assign(x);
  31504. tmp.rotateRight(34);
  31505. result.xor(tmp);
  31506. tmp.assign(x);
  31507. tmp.rotateRight(39);
  31508. result.xor(tmp);
  31509. }
  31510. function sigmaPrime(result, x, tmp) {
  31511. result.assign(x);
  31512. result.rotateRight(14);
  31513. tmp.assign(x);
  31514. tmp.rotateRight(18);
  31515. result.xor(tmp);
  31516. tmp.assign(x);
  31517. tmp.rotateRight(41);
  31518. result.xor(tmp);
  31519. }
  31520. function littleSigma(result, x, tmp) {
  31521. result.assign(x);
  31522. result.rotateRight(1);
  31523. tmp.assign(x);
  31524. tmp.rotateRight(8);
  31525. result.xor(tmp);
  31526. tmp.assign(x);
  31527. tmp.shiftRight(7);
  31528. result.xor(tmp);
  31529. }
  31530. function littleSigmaPrime(result, x, tmp) {
  31531. result.assign(x);
  31532. result.rotateRight(19);
  31533. tmp.assign(x);
  31534. tmp.rotateRight(61);
  31535. result.xor(tmp);
  31536. tmp.assign(x);
  31537. tmp.shiftRight(6);
  31538. result.xor(tmp);
  31539. }
  31540. var k = [
  31541. new Word64(0x428a2f98, 0xd728ae22),
  31542. new Word64(0x71374491, 0x23ef65cd),
  31543. new Word64(0xb5c0fbcf, 0xec4d3b2f),
  31544. new Word64(0xe9b5dba5, 0x8189dbbc),
  31545. new Word64(0x3956c25b, 0xf348b538),
  31546. new Word64(0x59f111f1, 0xb605d019),
  31547. new Word64(0x923f82a4, 0xaf194f9b),
  31548. new Word64(0xab1c5ed5, 0xda6d8118),
  31549. new Word64(0xd807aa98, 0xa3030242),
  31550. new Word64(0x12835b01, 0x45706fbe),
  31551. new Word64(0x243185be, 0x4ee4b28c),
  31552. new Word64(0x550c7dc3, 0xd5ffb4e2),
  31553. new Word64(0x72be5d74, 0xf27b896f),
  31554. new Word64(0x80deb1fe, 0x3b1696b1),
  31555. new Word64(0x9bdc06a7, 0x25c71235),
  31556. new Word64(0xc19bf174, 0xcf692694),
  31557. new Word64(0xe49b69c1, 0x9ef14ad2),
  31558. new Word64(0xefbe4786, 0x384f25e3),
  31559. new Word64(0x0fc19dc6, 0x8b8cd5b5),
  31560. new Word64(0x240ca1cc, 0x77ac9c65),
  31561. new Word64(0x2de92c6f, 0x592b0275),
  31562. new Word64(0x4a7484aa, 0x6ea6e483),
  31563. new Word64(0x5cb0a9dc, 0xbd41fbd4),
  31564. new Word64(0x76f988da, 0x831153b5),
  31565. new Word64(0x983e5152, 0xee66dfab),
  31566. new Word64(0xa831c66d, 0x2db43210),
  31567. new Word64(0xb00327c8, 0x98fb213f),
  31568. new Word64(0xbf597fc7, 0xbeef0ee4),
  31569. new Word64(0xc6e00bf3, 0x3da88fc2),
  31570. new Word64(0xd5a79147, 0x930aa725),
  31571. new Word64(0x06ca6351, 0xe003826f),
  31572. new Word64(0x14292967, 0x0a0e6e70),
  31573. new Word64(0x27b70a85, 0x46d22ffc),
  31574. new Word64(0x2e1b2138, 0x5c26c926),
  31575. new Word64(0x4d2c6dfc, 0x5ac42aed),
  31576. new Word64(0x53380d13, 0x9d95b3df),
  31577. new Word64(0x650a7354, 0x8baf63de),
  31578. new Word64(0x766a0abb, 0x3c77b2a8),
  31579. new Word64(0x81c2c92e, 0x47edaee6),
  31580. new Word64(0x92722c85, 0x1482353b),
  31581. new Word64(0xa2bfe8a1, 0x4cf10364),
  31582. new Word64(0xa81a664b, 0xbc423001),
  31583. new Word64(0xc24b8b70, 0xd0f89791),
  31584. new Word64(0xc76c51a3, 0x0654be30),
  31585. new Word64(0xd192e819, 0xd6ef5218),
  31586. new Word64(0xd6990624, 0x5565a910),
  31587. new Word64(0xf40e3585, 0x5771202a),
  31588. new Word64(0x106aa070, 0x32bbd1b8),
  31589. new Word64(0x19a4c116, 0xb8d2d0c8),
  31590. new Word64(0x1e376c08, 0x5141ab53),
  31591. new Word64(0x2748774c, 0xdf8eeb99),
  31592. new Word64(0x34b0bcb5, 0xe19b48a8),
  31593. new Word64(0x391c0cb3, 0xc5c95a63),
  31594. new Word64(0x4ed8aa4a, 0xe3418acb),
  31595. new Word64(0x5b9cca4f, 0x7763e373),
  31596. new Word64(0x682e6ff3, 0xd6b2b8a3),
  31597. new Word64(0x748f82ee, 0x5defb2fc),
  31598. new Word64(0x78a5636f, 0x43172f60),
  31599. new Word64(0x84c87814, 0xa1f0ab72),
  31600. new Word64(0x8cc70208, 0x1a6439ec),
  31601. new Word64(0x90befffa, 0x23631e28),
  31602. new Word64(0xa4506ceb, 0xde82bde9),
  31603. new Word64(0xbef9a3f7, 0xb2c67915),
  31604. new Word64(0xc67178f2, 0xe372532b),
  31605. new Word64(0xca273ece, 0xea26619c),
  31606. new Word64(0xd186b8c7, 0x21c0c207),
  31607. new Word64(0xeada7dd6, 0xcde0eb1e),
  31608. new Word64(0xf57d4f7f, 0xee6ed178),
  31609. new Word64(0x06f067aa, 0x72176fba),
  31610. new Word64(0x0a637dc5, 0xa2c898a6),
  31611. new Word64(0x113f9804, 0xbef90dae),
  31612. new Word64(0x1b710b35, 0x131c471b),
  31613. new Word64(0x28db77f5, 0x23047d84),
  31614. new Word64(0x32caab7b, 0x40c72493),
  31615. new Word64(0x3c9ebe0a, 0x15c9bebc),
  31616. new Word64(0x431d67c4, 0x9c100d4c),
  31617. new Word64(0x4cc5d4be, 0xcb3e42b6),
  31618. new Word64(0x597f299c, 0xfc657e2a),
  31619. new Word64(0x5fcb6fab, 0x3ad6faec),
  31620. new Word64(0x6c44198c, 0x4a475817)
  31621. ];
  31622. function hash(data, offset, length, mode384) {
  31623. mode384 = !!mode384;
  31624. // initial hash values
  31625. var h0, h1, h2, h3, h4, h5, h6, h7;
  31626. if (!mode384) {
  31627. h0 = new Word64(0x6a09e667, 0xf3bcc908);
  31628. h1 = new Word64(0xbb67ae85, 0x84caa73b);
  31629. h2 = new Word64(0x3c6ef372, 0xfe94f82b);
  31630. h3 = new Word64(0xa54ff53a, 0x5f1d36f1);
  31631. h4 = new Word64(0x510e527f, 0xade682d1);
  31632. h5 = new Word64(0x9b05688c, 0x2b3e6c1f);
  31633. h6 = new Word64(0x1f83d9ab, 0xfb41bd6b);
  31634. h7 = new Word64(0x5be0cd19, 0x137e2179);
  31635. } else {
  31636. // SHA384 is exactly the same
  31637. // except with different starting values and a trimmed result
  31638. h0 = new Word64(0xcbbb9d5d, 0xc1059ed8);
  31639. h1 = new Word64(0x629a292a, 0x367cd507);
  31640. h2 = new Word64(0x9159015a, 0x3070dd17);
  31641. h3 = new Word64(0x152fecd8, 0xf70e5939);
  31642. h4 = new Word64(0x67332667, 0xffc00b31);
  31643. h5 = new Word64(0x8eb44a87, 0x68581511);
  31644. h6 = new Word64(0xdb0c2e0d, 0x64f98fa7);
  31645. h7 = new Word64(0x47b5481d, 0xbefa4fa4);
  31646. }
  31647. // pre-processing
  31648. var paddedLength = Math.ceil((length + 17) / 128) * 128;
  31649. var padded = new Uint8Array(paddedLength);
  31650. var i, j, n;
  31651. for (i = 0; i < length; ++i) {
  31652. padded[i] = data[offset++];
  31653. }
  31654. padded[i++] = 0x80;
  31655. n = paddedLength - 16;
  31656. while (i < n) {
  31657. padded[i++] = 0;
  31658. }
  31659. padded[i++] = 0;
  31660. padded[i++] = 0;
  31661. padded[i++] = 0;
  31662. padded[i++] = 0;
  31663. padded[i++] = 0;
  31664. padded[i++] = 0;
  31665. padded[i++] = 0;
  31666. padded[i++] = 0;
  31667. padded[i++] = 0;
  31668. padded[i++] = 0;
  31669. padded[i++] = 0;
  31670. padded[i++] = length >>> 29 & 0xFF;
  31671. padded[i++] = length >> 21 & 0xFF;
  31672. padded[i++] = length >> 13 & 0xFF;
  31673. padded[i++] = length >> 5 & 0xFF;
  31674. padded[i++] = length << 3 & 0xFF;
  31675. var w = new Array(80);
  31676. for (i = 0; i < 80; i++) {
  31677. w[i] = new Word64(0, 0);
  31678. }
  31679. var a = new Word64(0, 0), b = new Word64(0, 0), c = new Word64(0, 0);
  31680. var d = new Word64(0, 0), e = new Word64(0, 0), f = new Word64(0, 0);
  31681. var g = new Word64(0, 0), h = new Word64(0, 0);
  31682. var t1 = new Word64(0, 0), t2 = new Word64(0, 0);
  31683. var tmp1 = new Word64(0, 0), tmp2 = new Word64(0, 0), tmp3;
  31684. // for each 1024 bit block
  31685. for (i = 0; i < paddedLength;) {
  31686. for (j = 0; j < 16; ++j) {
  31687. w[j].high = padded[i] << 24 | padded[i + 1] << 16 | padded[i + 2] << 8 | padded[i + 3];
  31688. w[j].low = padded[i + 4] << 24 | padded[i + 5] << 16 | padded[i + 6] << 8 | padded[i + 7];
  31689. i += 8;
  31690. }
  31691. for (j = 16; j < 80; ++j) {
  31692. tmp3 = w[j];
  31693. littleSigmaPrime(tmp3, w[j - 2], tmp2);
  31694. tmp3.add(w[j - 7]);
  31695. littleSigma(tmp1, w[j - 15], tmp2);
  31696. tmp3.add(tmp1);
  31697. tmp3.add(w[j - 16]);
  31698. }
  31699. a.assign(h0);
  31700. b.assign(h1);
  31701. c.assign(h2);
  31702. d.assign(h3);
  31703. e.assign(h4);
  31704. f.assign(h5);
  31705. g.assign(h6);
  31706. h.assign(h7);
  31707. for (j = 0; j < 80; ++j) {
  31708. t1.assign(h);
  31709. sigmaPrime(tmp1, e, tmp2);
  31710. t1.add(tmp1);
  31711. ch(tmp1, e, f, g, tmp2);
  31712. t1.add(tmp1);
  31713. t1.add(k[j]);
  31714. t1.add(w[j]);
  31715. sigma(t2, a, tmp2);
  31716. maj(tmp1, a, b, c, tmp2);
  31717. t2.add(tmp1);
  31718. tmp3 = h;
  31719. h = g;
  31720. g = f;
  31721. f = e;
  31722. d.add(t1);
  31723. e = d;
  31724. d = c;
  31725. c = b;
  31726. b = a;
  31727. tmp3.assign(t1);
  31728. tmp3.add(t2);
  31729. a = tmp3;
  31730. }
  31731. h0.add(a);
  31732. h1.add(b);
  31733. h2.add(c);
  31734. h3.add(d);
  31735. h4.add(e);
  31736. h5.add(f);
  31737. h6.add(g);
  31738. h7.add(h);
  31739. }
  31740. var result;
  31741. if (!mode384) {
  31742. result = new Uint8Array(64);
  31743. h0.copyTo(result, 0);
  31744. h1.copyTo(result, 8);
  31745. h2.copyTo(result, 16);
  31746. h3.copyTo(result, 24);
  31747. h4.copyTo(result, 32);
  31748. h5.copyTo(result, 40);
  31749. h6.copyTo(result, 48);
  31750. h7.copyTo(result, 56);
  31751. } else {
  31752. result = new Uint8Array(48);
  31753. h0.copyTo(result, 0);
  31754. h1.copyTo(result, 8);
  31755. h2.copyTo(result, 16);
  31756. h3.copyTo(result, 24);
  31757. h4.copyTo(result, 32);
  31758. h5.copyTo(result, 40);
  31759. }
  31760. return result;
  31761. }
  31762. return hash;
  31763. }();
  31764. var calculateSHA384 = function calculateSHA384Closure() {
  31765. function hash(data, offset, length) {
  31766. return calculateSHA512(data, offset, length, true);
  31767. }
  31768. return hash;
  31769. }();
  31770. var NullCipher = function NullCipherClosure() {
  31771. function NullCipher() {
  31772. }
  31773. NullCipher.prototype = {
  31774. decryptBlock: function NullCipher_decryptBlock(data) {
  31775. return data;
  31776. }
  31777. };
  31778. return NullCipher;
  31779. }();
  31780. var AES128Cipher = function AES128CipherClosure() {
  31781. var rcon = new Uint8Array([
  31782. 0x8d,
  31783. 0x01,
  31784. 0x02,
  31785. 0x04,
  31786. 0x08,
  31787. 0x10,
  31788. 0x20,
  31789. 0x40,
  31790. 0x80,
  31791. 0x1b,
  31792. 0x36,
  31793. 0x6c,
  31794. 0xd8,
  31795. 0xab,
  31796. 0x4d,
  31797. 0x9a,
  31798. 0x2f,
  31799. 0x5e,
  31800. 0xbc,
  31801. 0x63,
  31802. 0xc6,
  31803. 0x97,
  31804. 0x35,
  31805. 0x6a,
  31806. 0xd4,
  31807. 0xb3,
  31808. 0x7d,
  31809. 0xfa,
  31810. 0xef,
  31811. 0xc5,
  31812. 0x91,
  31813. 0x39,
  31814. 0x72,
  31815. 0xe4,
  31816. 0xd3,
  31817. 0xbd,
  31818. 0x61,
  31819. 0xc2,
  31820. 0x9f,
  31821. 0x25,
  31822. 0x4a,
  31823. 0x94,
  31824. 0x33,
  31825. 0x66,
  31826. 0xcc,
  31827. 0x83,
  31828. 0x1d,
  31829. 0x3a,
  31830. 0x74,
  31831. 0xe8,
  31832. 0xcb,
  31833. 0x8d,
  31834. 0x01,
  31835. 0x02,
  31836. 0x04,
  31837. 0x08,
  31838. 0x10,
  31839. 0x20,
  31840. 0x40,
  31841. 0x80,
  31842. 0x1b,
  31843. 0x36,
  31844. 0x6c,
  31845. 0xd8,
  31846. 0xab,
  31847. 0x4d,
  31848. 0x9a,
  31849. 0x2f,
  31850. 0x5e,
  31851. 0xbc,
  31852. 0x63,
  31853. 0xc6,
  31854. 0x97,
  31855. 0x35,
  31856. 0x6a,
  31857. 0xd4,
  31858. 0xb3,
  31859. 0x7d,
  31860. 0xfa,
  31861. 0xef,
  31862. 0xc5,
  31863. 0x91,
  31864. 0x39,
  31865. 0x72,
  31866. 0xe4,
  31867. 0xd3,
  31868. 0xbd,
  31869. 0x61,
  31870. 0xc2,
  31871. 0x9f,
  31872. 0x25,
  31873. 0x4a,
  31874. 0x94,
  31875. 0x33,
  31876. 0x66,
  31877. 0xcc,
  31878. 0x83,
  31879. 0x1d,
  31880. 0x3a,
  31881. 0x74,
  31882. 0xe8,
  31883. 0xcb,
  31884. 0x8d,
  31885. 0x01,
  31886. 0x02,
  31887. 0x04,
  31888. 0x08,
  31889. 0x10,
  31890. 0x20,
  31891. 0x40,
  31892. 0x80,
  31893. 0x1b,
  31894. 0x36,
  31895. 0x6c,
  31896. 0xd8,
  31897. 0xab,
  31898. 0x4d,
  31899. 0x9a,
  31900. 0x2f,
  31901. 0x5e,
  31902. 0xbc,
  31903. 0x63,
  31904. 0xc6,
  31905. 0x97,
  31906. 0x35,
  31907. 0x6a,
  31908. 0xd4,
  31909. 0xb3,
  31910. 0x7d,
  31911. 0xfa,
  31912. 0xef,
  31913. 0xc5,
  31914. 0x91,
  31915. 0x39,
  31916. 0x72,
  31917. 0xe4,
  31918. 0xd3,
  31919. 0xbd,
  31920. 0x61,
  31921. 0xc2,
  31922. 0x9f,
  31923. 0x25,
  31924. 0x4a,
  31925. 0x94,
  31926. 0x33,
  31927. 0x66,
  31928. 0xcc,
  31929. 0x83,
  31930. 0x1d,
  31931. 0x3a,
  31932. 0x74,
  31933. 0xe8,
  31934. 0xcb,
  31935. 0x8d,
  31936. 0x01,
  31937. 0x02,
  31938. 0x04,
  31939. 0x08,
  31940. 0x10,
  31941. 0x20,
  31942. 0x40,
  31943. 0x80,
  31944. 0x1b,
  31945. 0x36,
  31946. 0x6c,
  31947. 0xd8,
  31948. 0xab,
  31949. 0x4d,
  31950. 0x9a,
  31951. 0x2f,
  31952. 0x5e,
  31953. 0xbc,
  31954. 0x63,
  31955. 0xc6,
  31956. 0x97,
  31957. 0x35,
  31958. 0x6a,
  31959. 0xd4,
  31960. 0xb3,
  31961. 0x7d,
  31962. 0xfa,
  31963. 0xef,
  31964. 0xc5,
  31965. 0x91,
  31966. 0x39,
  31967. 0x72,
  31968. 0xe4,
  31969. 0xd3,
  31970. 0xbd,
  31971. 0x61,
  31972. 0xc2,
  31973. 0x9f,
  31974. 0x25,
  31975. 0x4a,
  31976. 0x94,
  31977. 0x33,
  31978. 0x66,
  31979. 0xcc,
  31980. 0x83,
  31981. 0x1d,
  31982. 0x3a,
  31983. 0x74,
  31984. 0xe8,
  31985. 0xcb,
  31986. 0x8d,
  31987. 0x01,
  31988. 0x02,
  31989. 0x04,
  31990. 0x08,
  31991. 0x10,
  31992. 0x20,
  31993. 0x40,
  31994. 0x80,
  31995. 0x1b,
  31996. 0x36,
  31997. 0x6c,
  31998. 0xd8,
  31999. 0xab,
  32000. 0x4d,
  32001. 0x9a,
  32002. 0x2f,
  32003. 0x5e,
  32004. 0xbc,
  32005. 0x63,
  32006. 0xc6,
  32007. 0x97,
  32008. 0x35,
  32009. 0x6a,
  32010. 0xd4,
  32011. 0xb3,
  32012. 0x7d,
  32013. 0xfa,
  32014. 0xef,
  32015. 0xc5,
  32016. 0x91,
  32017. 0x39,
  32018. 0x72,
  32019. 0xe4,
  32020. 0xd3,
  32021. 0xbd,
  32022. 0x61,
  32023. 0xc2,
  32024. 0x9f,
  32025. 0x25,
  32026. 0x4a,
  32027. 0x94,
  32028. 0x33,
  32029. 0x66,
  32030. 0xcc,
  32031. 0x83,
  32032. 0x1d,
  32033. 0x3a,
  32034. 0x74,
  32035. 0xe8,
  32036. 0xcb,
  32037. 0x8d
  32038. ]);
  32039. var s = new Uint8Array([
  32040. 0x63,
  32041. 0x7c,
  32042. 0x77,
  32043. 0x7b,
  32044. 0xf2,
  32045. 0x6b,
  32046. 0x6f,
  32047. 0xc5,
  32048. 0x30,
  32049. 0x01,
  32050. 0x67,
  32051. 0x2b,
  32052. 0xfe,
  32053. 0xd7,
  32054. 0xab,
  32055. 0x76,
  32056. 0xca,
  32057. 0x82,
  32058. 0xc9,
  32059. 0x7d,
  32060. 0xfa,
  32061. 0x59,
  32062. 0x47,
  32063. 0xf0,
  32064. 0xad,
  32065. 0xd4,
  32066. 0xa2,
  32067. 0xaf,
  32068. 0x9c,
  32069. 0xa4,
  32070. 0x72,
  32071. 0xc0,
  32072. 0xb7,
  32073. 0xfd,
  32074. 0x93,
  32075. 0x26,
  32076. 0x36,
  32077. 0x3f,
  32078. 0xf7,
  32079. 0xcc,
  32080. 0x34,
  32081. 0xa5,
  32082. 0xe5,
  32083. 0xf1,
  32084. 0x71,
  32085. 0xd8,
  32086. 0x31,
  32087. 0x15,
  32088. 0x04,
  32089. 0xc7,
  32090. 0x23,
  32091. 0xc3,
  32092. 0x18,
  32093. 0x96,
  32094. 0x05,
  32095. 0x9a,
  32096. 0x07,
  32097. 0x12,
  32098. 0x80,
  32099. 0xe2,
  32100. 0xeb,
  32101. 0x27,
  32102. 0xb2,
  32103. 0x75,
  32104. 0x09,
  32105. 0x83,
  32106. 0x2c,
  32107. 0x1a,
  32108. 0x1b,
  32109. 0x6e,
  32110. 0x5a,
  32111. 0xa0,
  32112. 0x52,
  32113. 0x3b,
  32114. 0xd6,
  32115. 0xb3,
  32116. 0x29,
  32117. 0xe3,
  32118. 0x2f,
  32119. 0x84,
  32120. 0x53,
  32121. 0xd1,
  32122. 0x00,
  32123. 0xed,
  32124. 0x20,
  32125. 0xfc,
  32126. 0xb1,
  32127. 0x5b,
  32128. 0x6a,
  32129. 0xcb,
  32130. 0xbe,
  32131. 0x39,
  32132. 0x4a,
  32133. 0x4c,
  32134. 0x58,
  32135. 0xcf,
  32136. 0xd0,
  32137. 0xef,
  32138. 0xaa,
  32139. 0xfb,
  32140. 0x43,
  32141. 0x4d,
  32142. 0x33,
  32143. 0x85,
  32144. 0x45,
  32145. 0xf9,
  32146. 0x02,
  32147. 0x7f,
  32148. 0x50,
  32149. 0x3c,
  32150. 0x9f,
  32151. 0xa8,
  32152. 0x51,
  32153. 0xa3,
  32154. 0x40,
  32155. 0x8f,
  32156. 0x92,
  32157. 0x9d,
  32158. 0x38,
  32159. 0xf5,
  32160. 0xbc,
  32161. 0xb6,
  32162. 0xda,
  32163. 0x21,
  32164. 0x10,
  32165. 0xff,
  32166. 0xf3,
  32167. 0xd2,
  32168. 0xcd,
  32169. 0x0c,
  32170. 0x13,
  32171. 0xec,
  32172. 0x5f,
  32173. 0x97,
  32174. 0x44,
  32175. 0x17,
  32176. 0xc4,
  32177. 0xa7,
  32178. 0x7e,
  32179. 0x3d,
  32180. 0x64,
  32181. 0x5d,
  32182. 0x19,
  32183. 0x73,
  32184. 0x60,
  32185. 0x81,
  32186. 0x4f,
  32187. 0xdc,
  32188. 0x22,
  32189. 0x2a,
  32190. 0x90,
  32191. 0x88,
  32192. 0x46,
  32193. 0xee,
  32194. 0xb8,
  32195. 0x14,
  32196. 0xde,
  32197. 0x5e,
  32198. 0x0b,
  32199. 0xdb,
  32200. 0xe0,
  32201. 0x32,
  32202. 0x3a,
  32203. 0x0a,
  32204. 0x49,
  32205. 0x06,
  32206. 0x24,
  32207. 0x5c,
  32208. 0xc2,
  32209. 0xd3,
  32210. 0xac,
  32211. 0x62,
  32212. 0x91,
  32213. 0x95,
  32214. 0xe4,
  32215. 0x79,
  32216. 0xe7,
  32217. 0xc8,
  32218. 0x37,
  32219. 0x6d,
  32220. 0x8d,
  32221. 0xd5,
  32222. 0x4e,
  32223. 0xa9,
  32224. 0x6c,
  32225. 0x56,
  32226. 0xf4,
  32227. 0xea,
  32228. 0x65,
  32229. 0x7a,
  32230. 0xae,
  32231. 0x08,
  32232. 0xba,
  32233. 0x78,
  32234. 0x25,
  32235. 0x2e,
  32236. 0x1c,
  32237. 0xa6,
  32238. 0xb4,
  32239. 0xc6,
  32240. 0xe8,
  32241. 0xdd,
  32242. 0x74,
  32243. 0x1f,
  32244. 0x4b,
  32245. 0xbd,
  32246. 0x8b,
  32247. 0x8a,
  32248. 0x70,
  32249. 0x3e,
  32250. 0xb5,
  32251. 0x66,
  32252. 0x48,
  32253. 0x03,
  32254. 0xf6,
  32255. 0x0e,
  32256. 0x61,
  32257. 0x35,
  32258. 0x57,
  32259. 0xb9,
  32260. 0x86,
  32261. 0xc1,
  32262. 0x1d,
  32263. 0x9e,
  32264. 0xe1,
  32265. 0xf8,
  32266. 0x98,
  32267. 0x11,
  32268. 0x69,
  32269. 0xd9,
  32270. 0x8e,
  32271. 0x94,
  32272. 0x9b,
  32273. 0x1e,
  32274. 0x87,
  32275. 0xe9,
  32276. 0xce,
  32277. 0x55,
  32278. 0x28,
  32279. 0xdf,
  32280. 0x8c,
  32281. 0xa1,
  32282. 0x89,
  32283. 0x0d,
  32284. 0xbf,
  32285. 0xe6,
  32286. 0x42,
  32287. 0x68,
  32288. 0x41,
  32289. 0x99,
  32290. 0x2d,
  32291. 0x0f,
  32292. 0xb0,
  32293. 0x54,
  32294. 0xbb,
  32295. 0x16
  32296. ]);
  32297. var inv_s = new Uint8Array([
  32298. 0x52,
  32299. 0x09,
  32300. 0x6a,
  32301. 0xd5,
  32302. 0x30,
  32303. 0x36,
  32304. 0xa5,
  32305. 0x38,
  32306. 0xbf,
  32307. 0x40,
  32308. 0xa3,
  32309. 0x9e,
  32310. 0x81,
  32311. 0xf3,
  32312. 0xd7,
  32313. 0xfb,
  32314. 0x7c,
  32315. 0xe3,
  32316. 0x39,
  32317. 0x82,
  32318. 0x9b,
  32319. 0x2f,
  32320. 0xff,
  32321. 0x87,
  32322. 0x34,
  32323. 0x8e,
  32324. 0x43,
  32325. 0x44,
  32326. 0xc4,
  32327. 0xde,
  32328. 0xe9,
  32329. 0xcb,
  32330. 0x54,
  32331. 0x7b,
  32332. 0x94,
  32333. 0x32,
  32334. 0xa6,
  32335. 0xc2,
  32336. 0x23,
  32337. 0x3d,
  32338. 0xee,
  32339. 0x4c,
  32340. 0x95,
  32341. 0x0b,
  32342. 0x42,
  32343. 0xfa,
  32344. 0xc3,
  32345. 0x4e,
  32346. 0x08,
  32347. 0x2e,
  32348. 0xa1,
  32349. 0x66,
  32350. 0x28,
  32351. 0xd9,
  32352. 0x24,
  32353. 0xb2,
  32354. 0x76,
  32355. 0x5b,
  32356. 0xa2,
  32357. 0x49,
  32358. 0x6d,
  32359. 0x8b,
  32360. 0xd1,
  32361. 0x25,
  32362. 0x72,
  32363. 0xf8,
  32364. 0xf6,
  32365. 0x64,
  32366. 0x86,
  32367. 0x68,
  32368. 0x98,
  32369. 0x16,
  32370. 0xd4,
  32371. 0xa4,
  32372. 0x5c,
  32373. 0xcc,
  32374. 0x5d,
  32375. 0x65,
  32376. 0xb6,
  32377. 0x92,
  32378. 0x6c,
  32379. 0x70,
  32380. 0x48,
  32381. 0x50,
  32382. 0xfd,
  32383. 0xed,
  32384. 0xb9,
  32385. 0xda,
  32386. 0x5e,
  32387. 0x15,
  32388. 0x46,
  32389. 0x57,
  32390. 0xa7,
  32391. 0x8d,
  32392. 0x9d,
  32393. 0x84,
  32394. 0x90,
  32395. 0xd8,
  32396. 0xab,
  32397. 0x00,
  32398. 0x8c,
  32399. 0xbc,
  32400. 0xd3,
  32401. 0x0a,
  32402. 0xf7,
  32403. 0xe4,
  32404. 0x58,
  32405. 0x05,
  32406. 0xb8,
  32407. 0xb3,
  32408. 0x45,
  32409. 0x06,
  32410. 0xd0,
  32411. 0x2c,
  32412. 0x1e,
  32413. 0x8f,
  32414. 0xca,
  32415. 0x3f,
  32416. 0x0f,
  32417. 0x02,
  32418. 0xc1,
  32419. 0xaf,
  32420. 0xbd,
  32421. 0x03,
  32422. 0x01,
  32423. 0x13,
  32424. 0x8a,
  32425. 0x6b,
  32426. 0x3a,
  32427. 0x91,
  32428. 0x11,
  32429. 0x41,
  32430. 0x4f,
  32431. 0x67,
  32432. 0xdc,
  32433. 0xea,
  32434. 0x97,
  32435. 0xf2,
  32436. 0xcf,
  32437. 0xce,
  32438. 0xf0,
  32439. 0xb4,
  32440. 0xe6,
  32441. 0x73,
  32442. 0x96,
  32443. 0xac,
  32444. 0x74,
  32445. 0x22,
  32446. 0xe7,
  32447. 0xad,
  32448. 0x35,
  32449. 0x85,
  32450. 0xe2,
  32451. 0xf9,
  32452. 0x37,
  32453. 0xe8,
  32454. 0x1c,
  32455. 0x75,
  32456. 0xdf,
  32457. 0x6e,
  32458. 0x47,
  32459. 0xf1,
  32460. 0x1a,
  32461. 0x71,
  32462. 0x1d,
  32463. 0x29,
  32464. 0xc5,
  32465. 0x89,
  32466. 0x6f,
  32467. 0xb7,
  32468. 0x62,
  32469. 0x0e,
  32470. 0xaa,
  32471. 0x18,
  32472. 0xbe,
  32473. 0x1b,
  32474. 0xfc,
  32475. 0x56,
  32476. 0x3e,
  32477. 0x4b,
  32478. 0xc6,
  32479. 0xd2,
  32480. 0x79,
  32481. 0x20,
  32482. 0x9a,
  32483. 0xdb,
  32484. 0xc0,
  32485. 0xfe,
  32486. 0x78,
  32487. 0xcd,
  32488. 0x5a,
  32489. 0xf4,
  32490. 0x1f,
  32491. 0xdd,
  32492. 0xa8,
  32493. 0x33,
  32494. 0x88,
  32495. 0x07,
  32496. 0xc7,
  32497. 0x31,
  32498. 0xb1,
  32499. 0x12,
  32500. 0x10,
  32501. 0x59,
  32502. 0x27,
  32503. 0x80,
  32504. 0xec,
  32505. 0x5f,
  32506. 0x60,
  32507. 0x51,
  32508. 0x7f,
  32509. 0xa9,
  32510. 0x19,
  32511. 0xb5,
  32512. 0x4a,
  32513. 0x0d,
  32514. 0x2d,
  32515. 0xe5,
  32516. 0x7a,
  32517. 0x9f,
  32518. 0x93,
  32519. 0xc9,
  32520. 0x9c,
  32521. 0xef,
  32522. 0xa0,
  32523. 0xe0,
  32524. 0x3b,
  32525. 0x4d,
  32526. 0xae,
  32527. 0x2a,
  32528. 0xf5,
  32529. 0xb0,
  32530. 0xc8,
  32531. 0xeb,
  32532. 0xbb,
  32533. 0x3c,
  32534. 0x83,
  32535. 0x53,
  32536. 0x99,
  32537. 0x61,
  32538. 0x17,
  32539. 0x2b,
  32540. 0x04,
  32541. 0x7e,
  32542. 0xba,
  32543. 0x77,
  32544. 0xd6,
  32545. 0x26,
  32546. 0xe1,
  32547. 0x69,
  32548. 0x14,
  32549. 0x63,
  32550. 0x55,
  32551. 0x21,
  32552. 0x0c,
  32553. 0x7d
  32554. ]);
  32555. var mixCol = new Uint8Array(256);
  32556. for (var i = 0; i < 256; i++) {
  32557. if (i < 128) {
  32558. mixCol[i] = i << 1;
  32559. } else {
  32560. mixCol[i] = i << 1 ^ 0x1b;
  32561. }
  32562. }
  32563. var mix = new Uint32Array([
  32564. 0x00000000,
  32565. 0x0e090d0b,
  32566. 0x1c121a16,
  32567. 0x121b171d,
  32568. 0x3824342c,
  32569. 0x362d3927,
  32570. 0x24362e3a,
  32571. 0x2a3f2331,
  32572. 0x70486858,
  32573. 0x7e416553,
  32574. 0x6c5a724e,
  32575. 0x62537f45,
  32576. 0x486c5c74,
  32577. 0x4665517f,
  32578. 0x547e4662,
  32579. 0x5a774b69,
  32580. 0xe090d0b0,
  32581. 0xee99ddbb,
  32582. 0xfc82caa6,
  32583. 0xf28bc7ad,
  32584. 0xd8b4e49c,
  32585. 0xd6bde997,
  32586. 0xc4a6fe8a,
  32587. 0xcaaff381,
  32588. 0x90d8b8e8,
  32589. 0x9ed1b5e3,
  32590. 0x8ccaa2fe,
  32591. 0x82c3aff5,
  32592. 0xa8fc8cc4,
  32593. 0xa6f581cf,
  32594. 0xb4ee96d2,
  32595. 0xbae79bd9,
  32596. 0xdb3bbb7b,
  32597. 0xd532b670,
  32598. 0xc729a16d,
  32599. 0xc920ac66,
  32600. 0xe31f8f57,
  32601. 0xed16825c,
  32602. 0xff0d9541,
  32603. 0xf104984a,
  32604. 0xab73d323,
  32605. 0xa57ade28,
  32606. 0xb761c935,
  32607. 0xb968c43e,
  32608. 0x9357e70f,
  32609. 0x9d5eea04,
  32610. 0x8f45fd19,
  32611. 0x814cf012,
  32612. 0x3bab6bcb,
  32613. 0x35a266c0,
  32614. 0x27b971dd,
  32615. 0x29b07cd6,
  32616. 0x038f5fe7,
  32617. 0x0d8652ec,
  32618. 0x1f9d45f1,
  32619. 0x119448fa,
  32620. 0x4be30393,
  32621. 0x45ea0e98,
  32622. 0x57f11985,
  32623. 0x59f8148e,
  32624. 0x73c737bf,
  32625. 0x7dce3ab4,
  32626. 0x6fd52da9,
  32627. 0x61dc20a2,
  32628. 0xad766df6,
  32629. 0xa37f60fd,
  32630. 0xb16477e0,
  32631. 0xbf6d7aeb,
  32632. 0x955259da,
  32633. 0x9b5b54d1,
  32634. 0x894043cc,
  32635. 0x87494ec7,
  32636. 0xdd3e05ae,
  32637. 0xd33708a5,
  32638. 0xc12c1fb8,
  32639. 0xcf2512b3,
  32640. 0xe51a3182,
  32641. 0xeb133c89,
  32642. 0xf9082b94,
  32643. 0xf701269f,
  32644. 0x4de6bd46,
  32645. 0x43efb04d,
  32646. 0x51f4a750,
  32647. 0x5ffdaa5b,
  32648. 0x75c2896a,
  32649. 0x7bcb8461,
  32650. 0x69d0937c,
  32651. 0x67d99e77,
  32652. 0x3daed51e,
  32653. 0x33a7d815,
  32654. 0x21bccf08,
  32655. 0x2fb5c203,
  32656. 0x058ae132,
  32657. 0x0b83ec39,
  32658. 0x1998fb24,
  32659. 0x1791f62f,
  32660. 0x764dd68d,
  32661. 0x7844db86,
  32662. 0x6a5fcc9b,
  32663. 0x6456c190,
  32664. 0x4e69e2a1,
  32665. 0x4060efaa,
  32666. 0x527bf8b7,
  32667. 0x5c72f5bc,
  32668. 0x0605bed5,
  32669. 0x080cb3de,
  32670. 0x1a17a4c3,
  32671. 0x141ea9c8,
  32672. 0x3e218af9,
  32673. 0x302887f2,
  32674. 0x223390ef,
  32675. 0x2c3a9de4,
  32676. 0x96dd063d,
  32677. 0x98d40b36,
  32678. 0x8acf1c2b,
  32679. 0x84c61120,
  32680. 0xaef93211,
  32681. 0xa0f03f1a,
  32682. 0xb2eb2807,
  32683. 0xbce2250c,
  32684. 0xe6956e65,
  32685. 0xe89c636e,
  32686. 0xfa877473,
  32687. 0xf48e7978,
  32688. 0xdeb15a49,
  32689. 0xd0b85742,
  32690. 0xc2a3405f,
  32691. 0xccaa4d54,
  32692. 0x41ecdaf7,
  32693. 0x4fe5d7fc,
  32694. 0x5dfec0e1,
  32695. 0x53f7cdea,
  32696. 0x79c8eedb,
  32697. 0x77c1e3d0,
  32698. 0x65daf4cd,
  32699. 0x6bd3f9c6,
  32700. 0x31a4b2af,
  32701. 0x3fadbfa4,
  32702. 0x2db6a8b9,
  32703. 0x23bfa5b2,
  32704. 0x09808683,
  32705. 0x07898b88,
  32706. 0x15929c95,
  32707. 0x1b9b919e,
  32708. 0xa17c0a47,
  32709. 0xaf75074c,
  32710. 0xbd6e1051,
  32711. 0xb3671d5a,
  32712. 0x99583e6b,
  32713. 0x97513360,
  32714. 0x854a247d,
  32715. 0x8b432976,
  32716. 0xd134621f,
  32717. 0xdf3d6f14,
  32718. 0xcd267809,
  32719. 0xc32f7502,
  32720. 0xe9105633,
  32721. 0xe7195b38,
  32722. 0xf5024c25,
  32723. 0xfb0b412e,
  32724. 0x9ad7618c,
  32725. 0x94de6c87,
  32726. 0x86c57b9a,
  32727. 0x88cc7691,
  32728. 0xa2f355a0,
  32729. 0xacfa58ab,
  32730. 0xbee14fb6,
  32731. 0xb0e842bd,
  32732. 0xea9f09d4,
  32733. 0xe49604df,
  32734. 0xf68d13c2,
  32735. 0xf8841ec9,
  32736. 0xd2bb3df8,
  32737. 0xdcb230f3,
  32738. 0xcea927ee,
  32739. 0xc0a02ae5,
  32740. 0x7a47b13c,
  32741. 0x744ebc37,
  32742. 0x6655ab2a,
  32743. 0x685ca621,
  32744. 0x42638510,
  32745. 0x4c6a881b,
  32746. 0x5e719f06,
  32747. 0x5078920d,
  32748. 0x0a0fd964,
  32749. 0x0406d46f,
  32750. 0x161dc372,
  32751. 0x1814ce79,
  32752. 0x322bed48,
  32753. 0x3c22e043,
  32754. 0x2e39f75e,
  32755. 0x2030fa55,
  32756. 0xec9ab701,
  32757. 0xe293ba0a,
  32758. 0xf088ad17,
  32759. 0xfe81a01c,
  32760. 0xd4be832d,
  32761. 0xdab78e26,
  32762. 0xc8ac993b,
  32763. 0xc6a59430,
  32764. 0x9cd2df59,
  32765. 0x92dbd252,
  32766. 0x80c0c54f,
  32767. 0x8ec9c844,
  32768. 0xa4f6eb75,
  32769. 0xaaffe67e,
  32770. 0xb8e4f163,
  32771. 0xb6edfc68,
  32772. 0x0c0a67b1,
  32773. 0x02036aba,
  32774. 0x10187da7,
  32775. 0x1e1170ac,
  32776. 0x342e539d,
  32777. 0x3a275e96,
  32778. 0x283c498b,
  32779. 0x26354480,
  32780. 0x7c420fe9,
  32781. 0x724b02e2,
  32782. 0x605015ff,
  32783. 0x6e5918f4,
  32784. 0x44663bc5,
  32785. 0x4a6f36ce,
  32786. 0x587421d3,
  32787. 0x567d2cd8,
  32788. 0x37a10c7a,
  32789. 0x39a80171,
  32790. 0x2bb3166c,
  32791. 0x25ba1b67,
  32792. 0x0f853856,
  32793. 0x018c355d,
  32794. 0x13972240,
  32795. 0x1d9e2f4b,
  32796. 0x47e96422,
  32797. 0x49e06929,
  32798. 0x5bfb7e34,
  32799. 0x55f2733f,
  32800. 0x7fcd500e,
  32801. 0x71c45d05,
  32802. 0x63df4a18,
  32803. 0x6dd64713,
  32804. 0xd731dcca,
  32805. 0xd938d1c1,
  32806. 0xcb23c6dc,
  32807. 0xc52acbd7,
  32808. 0xef15e8e6,
  32809. 0xe11ce5ed,
  32810. 0xf307f2f0,
  32811. 0xfd0efffb,
  32812. 0xa779b492,
  32813. 0xa970b999,
  32814. 0xbb6bae84,
  32815. 0xb562a38f,
  32816. 0x9f5d80be,
  32817. 0x91548db5,
  32818. 0x834f9aa8,
  32819. 0x8d4697a3
  32820. ]);
  32821. function expandKey128(cipherKey) {
  32822. var b = 176, result = new Uint8Array(b);
  32823. result.set(cipherKey);
  32824. for (var j = 16, i = 1; j < b; ++i) {
  32825. // RotWord
  32826. var t1 = result[j - 3], t2 = result[j - 2], t3 = result[j - 1], t4 = result[j - 4];
  32827. // SubWord
  32828. t1 = s[t1];
  32829. t2 = s[t2];
  32830. t3 = s[t3];
  32831. t4 = s[t4];
  32832. // Rcon
  32833. t1 = t1 ^ rcon[i];
  32834. for (var n = 0; n < 4; ++n) {
  32835. result[j] = t1 ^= result[j - 16];
  32836. j++;
  32837. result[j] = t2 ^= result[j - 16];
  32838. j++;
  32839. result[j] = t3 ^= result[j - 16];
  32840. j++;
  32841. result[j] = t4 ^= result[j - 16];
  32842. j++;
  32843. }
  32844. }
  32845. return result;
  32846. }
  32847. function decrypt128(input, key) {
  32848. var state = new Uint8Array(16);
  32849. state.set(input);
  32850. var i, j, k;
  32851. var t, u, v;
  32852. // AddRoundKey
  32853. for (j = 0, k = 160; j < 16; ++j, ++k) {
  32854. state[j] ^= key[k];
  32855. }
  32856. for (i = 9; i >= 1; --i) {
  32857. // InvShiftRows
  32858. t = state[13];
  32859. state[13] = state[9];
  32860. state[9] = state[5];
  32861. state[5] = state[1];
  32862. state[1] = t;
  32863. t = state[14];
  32864. u = state[10];
  32865. state[14] = state[6];
  32866. state[10] = state[2];
  32867. state[6] = t;
  32868. state[2] = u;
  32869. t = state[15];
  32870. u = state[11];
  32871. v = state[7];
  32872. state[15] = state[3];
  32873. state[11] = t;
  32874. state[7] = u;
  32875. state[3] = v;
  32876. // InvSubBytes
  32877. for (j = 0; j < 16; ++j) {
  32878. state[j] = inv_s[state[j]];
  32879. }
  32880. // AddRoundKey
  32881. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  32882. state[j] ^= key[k];
  32883. }
  32884. // InvMixColumns
  32885. for (j = 0; j < 16; j += 4) {
  32886. var s0 = mix[state[j]], s1 = mix[state[j + 1]], s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  32887. t = s0 ^ s1 >>> 8 ^ s1 << 24 ^ s2 >>> 16 ^ s2 << 16 ^ s3 >>> 24 ^ s3 << 8;
  32888. state[j] = t >>> 24 & 0xFF;
  32889. state[j + 1] = t >> 16 & 0xFF;
  32890. state[j + 2] = t >> 8 & 0xFF;
  32891. state[j + 3] = t & 0xFF;
  32892. }
  32893. }
  32894. // InvShiftRows
  32895. t = state[13];
  32896. state[13] = state[9];
  32897. state[9] = state[5];
  32898. state[5] = state[1];
  32899. state[1] = t;
  32900. t = state[14];
  32901. u = state[10];
  32902. state[14] = state[6];
  32903. state[10] = state[2];
  32904. state[6] = t;
  32905. state[2] = u;
  32906. t = state[15];
  32907. u = state[11];
  32908. v = state[7];
  32909. state[15] = state[3];
  32910. state[11] = t;
  32911. state[7] = u;
  32912. state[3] = v;
  32913. for (j = 0; j < 16; ++j) {
  32914. // InvSubBytes
  32915. state[j] = inv_s[state[j]];
  32916. // AddRoundKey
  32917. state[j] ^= key[j];
  32918. }
  32919. return state;
  32920. }
  32921. function encrypt128(input, key) {
  32922. var t, u, v, k;
  32923. var state = new Uint8Array(16);
  32924. state.set(input);
  32925. for (j = 0; j < 16; ++j) {
  32926. // AddRoundKey
  32927. state[j] ^= key[j];
  32928. }
  32929. for (i = 1; i < 10; i++) {
  32930. //SubBytes
  32931. for (j = 0; j < 16; ++j) {
  32932. state[j] = s[state[j]];
  32933. }
  32934. //ShiftRows
  32935. v = state[1];
  32936. state[1] = state[5];
  32937. state[5] = state[9];
  32938. state[9] = state[13];
  32939. state[13] = v;
  32940. v = state[2];
  32941. u = state[6];
  32942. state[2] = state[10];
  32943. state[6] = state[14];
  32944. state[10] = v;
  32945. state[14] = u;
  32946. v = state[3];
  32947. u = state[7];
  32948. t = state[11];
  32949. state[3] = state[15];
  32950. state[7] = v;
  32951. state[11] = u;
  32952. state[15] = t;
  32953. //MixColumns
  32954. for (var j = 0; j < 16; j += 4) {
  32955. var s0 = state[j + 0], s1 = state[j + 1];
  32956. var s2 = state[j + 2], s3 = state[j + 3];
  32957. t = s0 ^ s1 ^ s2 ^ s3;
  32958. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  32959. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  32960. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  32961. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  32962. }
  32963. //AddRoundKey
  32964. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  32965. state[j] ^= key[k];
  32966. }
  32967. }
  32968. //SubBytes
  32969. for (j = 0; j < 16; ++j) {
  32970. state[j] = s[state[j]];
  32971. }
  32972. //ShiftRows
  32973. v = state[1];
  32974. state[1] = state[5];
  32975. state[5] = state[9];
  32976. state[9] = state[13];
  32977. state[13] = v;
  32978. v = state[2];
  32979. u = state[6];
  32980. state[2] = state[10];
  32981. state[6] = state[14];
  32982. state[10] = v;
  32983. state[14] = u;
  32984. v = state[3];
  32985. u = state[7];
  32986. t = state[11];
  32987. state[3] = state[15];
  32988. state[7] = v;
  32989. state[11] = u;
  32990. state[15] = t;
  32991. //AddRoundKey
  32992. for (j = 0, k = 160; j < 16; ++j, ++k) {
  32993. state[j] ^= key[k];
  32994. }
  32995. return state;
  32996. }
  32997. function AES128Cipher(key) {
  32998. this.key = expandKey128(key);
  32999. this.buffer = new Uint8Array(16);
  33000. this.bufferPosition = 0;
  33001. }
  33002. function decryptBlock2(data, finalize) {
  33003. var i, j, ii, sourceLength = data.length, buffer = this.buffer, bufferLength = this.bufferPosition, result = [], iv = this.iv;
  33004. for (i = 0; i < sourceLength; ++i) {
  33005. buffer[bufferLength] = data[i];
  33006. ++bufferLength;
  33007. if (bufferLength < 16) {
  33008. continue;
  33009. }
  33010. // buffer is full, decrypting
  33011. var plain = decrypt128(buffer, this.key);
  33012. // xor-ing the IV vector to get plain text
  33013. for (j = 0; j < 16; ++j) {
  33014. plain[j] ^= iv[j];
  33015. }
  33016. iv = buffer;
  33017. result.push(plain);
  33018. buffer = new Uint8Array(16);
  33019. bufferLength = 0;
  33020. }
  33021. // saving incomplete buffer
  33022. this.buffer = buffer;
  33023. this.bufferLength = bufferLength;
  33024. this.iv = iv;
  33025. if (result.length === 0) {
  33026. return new Uint8Array([]);
  33027. }
  33028. // combining plain text blocks into one
  33029. var outputLength = 16 * result.length;
  33030. if (finalize) {
  33031. // undo a padding that is described in RFC 2898
  33032. var lastBlock = result[result.length - 1];
  33033. var psLen = lastBlock[15];
  33034. if (psLen <= 16) {
  33035. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  33036. if (lastBlock[i] !== psLen) {
  33037. // Invalid padding, assume that the block has no padding.
  33038. psLen = 0;
  33039. break;
  33040. }
  33041. }
  33042. outputLength -= psLen;
  33043. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  33044. }
  33045. }
  33046. var output = new Uint8Array(outputLength);
  33047. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  33048. output.set(result[i], j);
  33049. }
  33050. return output;
  33051. }
  33052. AES128Cipher.prototype = {
  33053. decryptBlock: function AES128Cipher_decryptBlock(data, finalize) {
  33054. var i, sourceLength = data.length;
  33055. var buffer = this.buffer, bufferLength = this.bufferPosition;
  33056. // waiting for IV values -- they are at the start of the stream
  33057. for (i = 0; bufferLength < 16 && i < sourceLength; ++i, ++bufferLength) {
  33058. buffer[bufferLength] = data[i];
  33059. }
  33060. if (bufferLength < 16) {
  33061. // need more data
  33062. this.bufferLength = bufferLength;
  33063. return new Uint8Array([]);
  33064. }
  33065. this.iv = buffer;
  33066. this.buffer = new Uint8Array(16);
  33067. this.bufferLength = 0;
  33068. // starting decryption
  33069. this.decryptBlock = decryptBlock2;
  33070. return this.decryptBlock(data.subarray(16), finalize);
  33071. },
  33072. encrypt: function AES128Cipher_encrypt(data, iv) {
  33073. var i, j, ii, sourceLength = data.length, buffer = this.buffer, bufferLength = this.bufferPosition, result = [];
  33074. if (!iv) {
  33075. iv = new Uint8Array(16);
  33076. }
  33077. for (i = 0; i < sourceLength; ++i) {
  33078. buffer[bufferLength] = data[i];
  33079. ++bufferLength;
  33080. if (bufferLength < 16) {
  33081. continue;
  33082. }
  33083. for (j = 0; j < 16; ++j) {
  33084. buffer[j] ^= iv[j];
  33085. }
  33086. // buffer is full, encrypting
  33087. var cipher = encrypt128(buffer, this.key);
  33088. iv = cipher;
  33089. result.push(cipher);
  33090. buffer = new Uint8Array(16);
  33091. bufferLength = 0;
  33092. }
  33093. // saving incomplete buffer
  33094. this.buffer = buffer;
  33095. this.bufferLength = bufferLength;
  33096. this.iv = iv;
  33097. if (result.length === 0) {
  33098. return new Uint8Array([]);
  33099. }
  33100. // combining plain text blocks into one
  33101. var outputLength = 16 * result.length;
  33102. var output = new Uint8Array(outputLength);
  33103. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  33104. output.set(result[i], j);
  33105. }
  33106. return output;
  33107. }
  33108. };
  33109. return AES128Cipher;
  33110. }();
  33111. var AES256Cipher = function AES256CipherClosure() {
  33112. var rcon = new Uint8Array([
  33113. 0x8d,
  33114. 0x01,
  33115. 0x02,
  33116. 0x04,
  33117. 0x08,
  33118. 0x10,
  33119. 0x20,
  33120. 0x40,
  33121. 0x80,
  33122. 0x1b,
  33123. 0x36,
  33124. 0x6c,
  33125. 0xd8,
  33126. 0xab,
  33127. 0x4d,
  33128. 0x9a,
  33129. 0x2f,
  33130. 0x5e,
  33131. 0xbc,
  33132. 0x63,
  33133. 0xc6,
  33134. 0x97,
  33135. 0x35,
  33136. 0x6a,
  33137. 0xd4,
  33138. 0xb3,
  33139. 0x7d,
  33140. 0xfa,
  33141. 0xef,
  33142. 0xc5,
  33143. 0x91,
  33144. 0x39,
  33145. 0x72,
  33146. 0xe4,
  33147. 0xd3,
  33148. 0xbd,
  33149. 0x61,
  33150. 0xc2,
  33151. 0x9f,
  33152. 0x25,
  33153. 0x4a,
  33154. 0x94,
  33155. 0x33,
  33156. 0x66,
  33157. 0xcc,
  33158. 0x83,
  33159. 0x1d,
  33160. 0x3a,
  33161. 0x74,
  33162. 0xe8,
  33163. 0xcb,
  33164. 0x8d,
  33165. 0x01,
  33166. 0x02,
  33167. 0x04,
  33168. 0x08,
  33169. 0x10,
  33170. 0x20,
  33171. 0x40,
  33172. 0x80,
  33173. 0x1b,
  33174. 0x36,
  33175. 0x6c,
  33176. 0xd8,
  33177. 0xab,
  33178. 0x4d,
  33179. 0x9a,
  33180. 0x2f,
  33181. 0x5e,
  33182. 0xbc,
  33183. 0x63,
  33184. 0xc6,
  33185. 0x97,
  33186. 0x35,
  33187. 0x6a,
  33188. 0xd4,
  33189. 0xb3,
  33190. 0x7d,
  33191. 0xfa,
  33192. 0xef,
  33193. 0xc5,
  33194. 0x91,
  33195. 0x39,
  33196. 0x72,
  33197. 0xe4,
  33198. 0xd3,
  33199. 0xbd,
  33200. 0x61,
  33201. 0xc2,
  33202. 0x9f,
  33203. 0x25,
  33204. 0x4a,
  33205. 0x94,
  33206. 0x33,
  33207. 0x66,
  33208. 0xcc,
  33209. 0x83,
  33210. 0x1d,
  33211. 0x3a,
  33212. 0x74,
  33213. 0xe8,
  33214. 0xcb,
  33215. 0x8d,
  33216. 0x01,
  33217. 0x02,
  33218. 0x04,
  33219. 0x08,
  33220. 0x10,
  33221. 0x20,
  33222. 0x40,
  33223. 0x80,
  33224. 0x1b,
  33225. 0x36,
  33226. 0x6c,
  33227. 0xd8,
  33228. 0xab,
  33229. 0x4d,
  33230. 0x9a,
  33231. 0x2f,
  33232. 0x5e,
  33233. 0xbc,
  33234. 0x63,
  33235. 0xc6,
  33236. 0x97,
  33237. 0x35,
  33238. 0x6a,
  33239. 0xd4,
  33240. 0xb3,
  33241. 0x7d,
  33242. 0xfa,
  33243. 0xef,
  33244. 0xc5,
  33245. 0x91,
  33246. 0x39,
  33247. 0x72,
  33248. 0xe4,
  33249. 0xd3,
  33250. 0xbd,
  33251. 0x61,
  33252. 0xc2,
  33253. 0x9f,
  33254. 0x25,
  33255. 0x4a,
  33256. 0x94,
  33257. 0x33,
  33258. 0x66,
  33259. 0xcc,
  33260. 0x83,
  33261. 0x1d,
  33262. 0x3a,
  33263. 0x74,
  33264. 0xe8,
  33265. 0xcb,
  33266. 0x8d,
  33267. 0x01,
  33268. 0x02,
  33269. 0x04,
  33270. 0x08,
  33271. 0x10,
  33272. 0x20,
  33273. 0x40,
  33274. 0x80,
  33275. 0x1b,
  33276. 0x36,
  33277. 0x6c,
  33278. 0xd8,
  33279. 0xab,
  33280. 0x4d,
  33281. 0x9a,
  33282. 0x2f,
  33283. 0x5e,
  33284. 0xbc,
  33285. 0x63,
  33286. 0xc6,
  33287. 0x97,
  33288. 0x35,
  33289. 0x6a,
  33290. 0xd4,
  33291. 0xb3,
  33292. 0x7d,
  33293. 0xfa,
  33294. 0xef,
  33295. 0xc5,
  33296. 0x91,
  33297. 0x39,
  33298. 0x72,
  33299. 0xe4,
  33300. 0xd3,
  33301. 0xbd,
  33302. 0x61,
  33303. 0xc2,
  33304. 0x9f,
  33305. 0x25,
  33306. 0x4a,
  33307. 0x94,
  33308. 0x33,
  33309. 0x66,
  33310. 0xcc,
  33311. 0x83,
  33312. 0x1d,
  33313. 0x3a,
  33314. 0x74,
  33315. 0xe8,
  33316. 0xcb,
  33317. 0x8d,
  33318. 0x01,
  33319. 0x02,
  33320. 0x04,
  33321. 0x08,
  33322. 0x10,
  33323. 0x20,
  33324. 0x40,
  33325. 0x80,
  33326. 0x1b,
  33327. 0x36,
  33328. 0x6c,
  33329. 0xd8,
  33330. 0xab,
  33331. 0x4d,
  33332. 0x9a,
  33333. 0x2f,
  33334. 0x5e,
  33335. 0xbc,
  33336. 0x63,
  33337. 0xc6,
  33338. 0x97,
  33339. 0x35,
  33340. 0x6a,
  33341. 0xd4,
  33342. 0xb3,
  33343. 0x7d,
  33344. 0xfa,
  33345. 0xef,
  33346. 0xc5,
  33347. 0x91,
  33348. 0x39,
  33349. 0x72,
  33350. 0xe4,
  33351. 0xd3,
  33352. 0xbd,
  33353. 0x61,
  33354. 0xc2,
  33355. 0x9f,
  33356. 0x25,
  33357. 0x4a,
  33358. 0x94,
  33359. 0x33,
  33360. 0x66,
  33361. 0xcc,
  33362. 0x83,
  33363. 0x1d,
  33364. 0x3a,
  33365. 0x74,
  33366. 0xe8,
  33367. 0xcb,
  33368. 0x8d
  33369. ]);
  33370. var s = new Uint8Array([
  33371. 0x63,
  33372. 0x7c,
  33373. 0x77,
  33374. 0x7b,
  33375. 0xf2,
  33376. 0x6b,
  33377. 0x6f,
  33378. 0xc5,
  33379. 0x30,
  33380. 0x01,
  33381. 0x67,
  33382. 0x2b,
  33383. 0xfe,
  33384. 0xd7,
  33385. 0xab,
  33386. 0x76,
  33387. 0xca,
  33388. 0x82,
  33389. 0xc9,
  33390. 0x7d,
  33391. 0xfa,
  33392. 0x59,
  33393. 0x47,
  33394. 0xf0,
  33395. 0xad,
  33396. 0xd4,
  33397. 0xa2,
  33398. 0xaf,
  33399. 0x9c,
  33400. 0xa4,
  33401. 0x72,
  33402. 0xc0,
  33403. 0xb7,
  33404. 0xfd,
  33405. 0x93,
  33406. 0x26,
  33407. 0x36,
  33408. 0x3f,
  33409. 0xf7,
  33410. 0xcc,
  33411. 0x34,
  33412. 0xa5,
  33413. 0xe5,
  33414. 0xf1,
  33415. 0x71,
  33416. 0xd8,
  33417. 0x31,
  33418. 0x15,
  33419. 0x04,
  33420. 0xc7,
  33421. 0x23,
  33422. 0xc3,
  33423. 0x18,
  33424. 0x96,
  33425. 0x05,
  33426. 0x9a,
  33427. 0x07,
  33428. 0x12,
  33429. 0x80,
  33430. 0xe2,
  33431. 0xeb,
  33432. 0x27,
  33433. 0xb2,
  33434. 0x75,
  33435. 0x09,
  33436. 0x83,
  33437. 0x2c,
  33438. 0x1a,
  33439. 0x1b,
  33440. 0x6e,
  33441. 0x5a,
  33442. 0xa0,
  33443. 0x52,
  33444. 0x3b,
  33445. 0xd6,
  33446. 0xb3,
  33447. 0x29,
  33448. 0xe3,
  33449. 0x2f,
  33450. 0x84,
  33451. 0x53,
  33452. 0xd1,
  33453. 0x00,
  33454. 0xed,
  33455. 0x20,
  33456. 0xfc,
  33457. 0xb1,
  33458. 0x5b,
  33459. 0x6a,
  33460. 0xcb,
  33461. 0xbe,
  33462. 0x39,
  33463. 0x4a,
  33464. 0x4c,
  33465. 0x58,
  33466. 0xcf,
  33467. 0xd0,
  33468. 0xef,
  33469. 0xaa,
  33470. 0xfb,
  33471. 0x43,
  33472. 0x4d,
  33473. 0x33,
  33474. 0x85,
  33475. 0x45,
  33476. 0xf9,
  33477. 0x02,
  33478. 0x7f,
  33479. 0x50,
  33480. 0x3c,
  33481. 0x9f,
  33482. 0xa8,
  33483. 0x51,
  33484. 0xa3,
  33485. 0x40,
  33486. 0x8f,
  33487. 0x92,
  33488. 0x9d,
  33489. 0x38,
  33490. 0xf5,
  33491. 0xbc,
  33492. 0xb6,
  33493. 0xda,
  33494. 0x21,
  33495. 0x10,
  33496. 0xff,
  33497. 0xf3,
  33498. 0xd2,
  33499. 0xcd,
  33500. 0x0c,
  33501. 0x13,
  33502. 0xec,
  33503. 0x5f,
  33504. 0x97,
  33505. 0x44,
  33506. 0x17,
  33507. 0xc4,
  33508. 0xa7,
  33509. 0x7e,
  33510. 0x3d,
  33511. 0x64,
  33512. 0x5d,
  33513. 0x19,
  33514. 0x73,
  33515. 0x60,
  33516. 0x81,
  33517. 0x4f,
  33518. 0xdc,
  33519. 0x22,
  33520. 0x2a,
  33521. 0x90,
  33522. 0x88,
  33523. 0x46,
  33524. 0xee,
  33525. 0xb8,
  33526. 0x14,
  33527. 0xde,
  33528. 0x5e,
  33529. 0x0b,
  33530. 0xdb,
  33531. 0xe0,
  33532. 0x32,
  33533. 0x3a,
  33534. 0x0a,
  33535. 0x49,
  33536. 0x06,
  33537. 0x24,
  33538. 0x5c,
  33539. 0xc2,
  33540. 0xd3,
  33541. 0xac,
  33542. 0x62,
  33543. 0x91,
  33544. 0x95,
  33545. 0xe4,
  33546. 0x79,
  33547. 0xe7,
  33548. 0xc8,
  33549. 0x37,
  33550. 0x6d,
  33551. 0x8d,
  33552. 0xd5,
  33553. 0x4e,
  33554. 0xa9,
  33555. 0x6c,
  33556. 0x56,
  33557. 0xf4,
  33558. 0xea,
  33559. 0x65,
  33560. 0x7a,
  33561. 0xae,
  33562. 0x08,
  33563. 0xba,
  33564. 0x78,
  33565. 0x25,
  33566. 0x2e,
  33567. 0x1c,
  33568. 0xa6,
  33569. 0xb4,
  33570. 0xc6,
  33571. 0xe8,
  33572. 0xdd,
  33573. 0x74,
  33574. 0x1f,
  33575. 0x4b,
  33576. 0xbd,
  33577. 0x8b,
  33578. 0x8a,
  33579. 0x70,
  33580. 0x3e,
  33581. 0xb5,
  33582. 0x66,
  33583. 0x48,
  33584. 0x03,
  33585. 0xf6,
  33586. 0x0e,
  33587. 0x61,
  33588. 0x35,
  33589. 0x57,
  33590. 0xb9,
  33591. 0x86,
  33592. 0xc1,
  33593. 0x1d,
  33594. 0x9e,
  33595. 0xe1,
  33596. 0xf8,
  33597. 0x98,
  33598. 0x11,
  33599. 0x69,
  33600. 0xd9,
  33601. 0x8e,
  33602. 0x94,
  33603. 0x9b,
  33604. 0x1e,
  33605. 0x87,
  33606. 0xe9,
  33607. 0xce,
  33608. 0x55,
  33609. 0x28,
  33610. 0xdf,
  33611. 0x8c,
  33612. 0xa1,
  33613. 0x89,
  33614. 0x0d,
  33615. 0xbf,
  33616. 0xe6,
  33617. 0x42,
  33618. 0x68,
  33619. 0x41,
  33620. 0x99,
  33621. 0x2d,
  33622. 0x0f,
  33623. 0xb0,
  33624. 0x54,
  33625. 0xbb,
  33626. 0x16
  33627. ]);
  33628. var inv_s = new Uint8Array([
  33629. 0x52,
  33630. 0x09,
  33631. 0x6a,
  33632. 0xd5,
  33633. 0x30,
  33634. 0x36,
  33635. 0xa5,
  33636. 0x38,
  33637. 0xbf,
  33638. 0x40,
  33639. 0xa3,
  33640. 0x9e,
  33641. 0x81,
  33642. 0xf3,
  33643. 0xd7,
  33644. 0xfb,
  33645. 0x7c,
  33646. 0xe3,
  33647. 0x39,
  33648. 0x82,
  33649. 0x9b,
  33650. 0x2f,
  33651. 0xff,
  33652. 0x87,
  33653. 0x34,
  33654. 0x8e,
  33655. 0x43,
  33656. 0x44,
  33657. 0xc4,
  33658. 0xde,
  33659. 0xe9,
  33660. 0xcb,
  33661. 0x54,
  33662. 0x7b,
  33663. 0x94,
  33664. 0x32,
  33665. 0xa6,
  33666. 0xc2,
  33667. 0x23,
  33668. 0x3d,
  33669. 0xee,
  33670. 0x4c,
  33671. 0x95,
  33672. 0x0b,
  33673. 0x42,
  33674. 0xfa,
  33675. 0xc3,
  33676. 0x4e,
  33677. 0x08,
  33678. 0x2e,
  33679. 0xa1,
  33680. 0x66,
  33681. 0x28,
  33682. 0xd9,
  33683. 0x24,
  33684. 0xb2,
  33685. 0x76,
  33686. 0x5b,
  33687. 0xa2,
  33688. 0x49,
  33689. 0x6d,
  33690. 0x8b,
  33691. 0xd1,
  33692. 0x25,
  33693. 0x72,
  33694. 0xf8,
  33695. 0xf6,
  33696. 0x64,
  33697. 0x86,
  33698. 0x68,
  33699. 0x98,
  33700. 0x16,
  33701. 0xd4,
  33702. 0xa4,
  33703. 0x5c,
  33704. 0xcc,
  33705. 0x5d,
  33706. 0x65,
  33707. 0xb6,
  33708. 0x92,
  33709. 0x6c,
  33710. 0x70,
  33711. 0x48,
  33712. 0x50,
  33713. 0xfd,
  33714. 0xed,
  33715. 0xb9,
  33716. 0xda,
  33717. 0x5e,
  33718. 0x15,
  33719. 0x46,
  33720. 0x57,
  33721. 0xa7,
  33722. 0x8d,
  33723. 0x9d,
  33724. 0x84,
  33725. 0x90,
  33726. 0xd8,
  33727. 0xab,
  33728. 0x00,
  33729. 0x8c,
  33730. 0xbc,
  33731. 0xd3,
  33732. 0x0a,
  33733. 0xf7,
  33734. 0xe4,
  33735. 0x58,
  33736. 0x05,
  33737. 0xb8,
  33738. 0xb3,
  33739. 0x45,
  33740. 0x06,
  33741. 0xd0,
  33742. 0x2c,
  33743. 0x1e,
  33744. 0x8f,
  33745. 0xca,
  33746. 0x3f,
  33747. 0x0f,
  33748. 0x02,
  33749. 0xc1,
  33750. 0xaf,
  33751. 0xbd,
  33752. 0x03,
  33753. 0x01,
  33754. 0x13,
  33755. 0x8a,
  33756. 0x6b,
  33757. 0x3a,
  33758. 0x91,
  33759. 0x11,
  33760. 0x41,
  33761. 0x4f,
  33762. 0x67,
  33763. 0xdc,
  33764. 0xea,
  33765. 0x97,
  33766. 0xf2,
  33767. 0xcf,
  33768. 0xce,
  33769. 0xf0,
  33770. 0xb4,
  33771. 0xe6,
  33772. 0x73,
  33773. 0x96,
  33774. 0xac,
  33775. 0x74,
  33776. 0x22,
  33777. 0xe7,
  33778. 0xad,
  33779. 0x35,
  33780. 0x85,
  33781. 0xe2,
  33782. 0xf9,
  33783. 0x37,
  33784. 0xe8,
  33785. 0x1c,
  33786. 0x75,
  33787. 0xdf,
  33788. 0x6e,
  33789. 0x47,
  33790. 0xf1,
  33791. 0x1a,
  33792. 0x71,
  33793. 0x1d,
  33794. 0x29,
  33795. 0xc5,
  33796. 0x89,
  33797. 0x6f,
  33798. 0xb7,
  33799. 0x62,
  33800. 0x0e,
  33801. 0xaa,
  33802. 0x18,
  33803. 0xbe,
  33804. 0x1b,
  33805. 0xfc,
  33806. 0x56,
  33807. 0x3e,
  33808. 0x4b,
  33809. 0xc6,
  33810. 0xd2,
  33811. 0x79,
  33812. 0x20,
  33813. 0x9a,
  33814. 0xdb,
  33815. 0xc0,
  33816. 0xfe,
  33817. 0x78,
  33818. 0xcd,
  33819. 0x5a,
  33820. 0xf4,
  33821. 0x1f,
  33822. 0xdd,
  33823. 0xa8,
  33824. 0x33,
  33825. 0x88,
  33826. 0x07,
  33827. 0xc7,
  33828. 0x31,
  33829. 0xb1,
  33830. 0x12,
  33831. 0x10,
  33832. 0x59,
  33833. 0x27,
  33834. 0x80,
  33835. 0xec,
  33836. 0x5f,
  33837. 0x60,
  33838. 0x51,
  33839. 0x7f,
  33840. 0xa9,
  33841. 0x19,
  33842. 0xb5,
  33843. 0x4a,
  33844. 0x0d,
  33845. 0x2d,
  33846. 0xe5,
  33847. 0x7a,
  33848. 0x9f,
  33849. 0x93,
  33850. 0xc9,
  33851. 0x9c,
  33852. 0xef,
  33853. 0xa0,
  33854. 0xe0,
  33855. 0x3b,
  33856. 0x4d,
  33857. 0xae,
  33858. 0x2a,
  33859. 0xf5,
  33860. 0xb0,
  33861. 0xc8,
  33862. 0xeb,
  33863. 0xbb,
  33864. 0x3c,
  33865. 0x83,
  33866. 0x53,
  33867. 0x99,
  33868. 0x61,
  33869. 0x17,
  33870. 0x2b,
  33871. 0x04,
  33872. 0x7e,
  33873. 0xba,
  33874. 0x77,
  33875. 0xd6,
  33876. 0x26,
  33877. 0xe1,
  33878. 0x69,
  33879. 0x14,
  33880. 0x63,
  33881. 0x55,
  33882. 0x21,
  33883. 0x0c,
  33884. 0x7d
  33885. ]);
  33886. var mixCol = new Uint8Array(256);
  33887. for (var i = 0; i < 256; i++) {
  33888. if (i < 128) {
  33889. mixCol[i] = i << 1;
  33890. } else {
  33891. mixCol[i] = i << 1 ^ 0x1b;
  33892. }
  33893. }
  33894. var mix = new Uint32Array([
  33895. 0x00000000,
  33896. 0x0e090d0b,
  33897. 0x1c121a16,
  33898. 0x121b171d,
  33899. 0x3824342c,
  33900. 0x362d3927,
  33901. 0x24362e3a,
  33902. 0x2a3f2331,
  33903. 0x70486858,
  33904. 0x7e416553,
  33905. 0x6c5a724e,
  33906. 0x62537f45,
  33907. 0x486c5c74,
  33908. 0x4665517f,
  33909. 0x547e4662,
  33910. 0x5a774b69,
  33911. 0xe090d0b0,
  33912. 0xee99ddbb,
  33913. 0xfc82caa6,
  33914. 0xf28bc7ad,
  33915. 0xd8b4e49c,
  33916. 0xd6bde997,
  33917. 0xc4a6fe8a,
  33918. 0xcaaff381,
  33919. 0x90d8b8e8,
  33920. 0x9ed1b5e3,
  33921. 0x8ccaa2fe,
  33922. 0x82c3aff5,
  33923. 0xa8fc8cc4,
  33924. 0xa6f581cf,
  33925. 0xb4ee96d2,
  33926. 0xbae79bd9,
  33927. 0xdb3bbb7b,
  33928. 0xd532b670,
  33929. 0xc729a16d,
  33930. 0xc920ac66,
  33931. 0xe31f8f57,
  33932. 0xed16825c,
  33933. 0xff0d9541,
  33934. 0xf104984a,
  33935. 0xab73d323,
  33936. 0xa57ade28,
  33937. 0xb761c935,
  33938. 0xb968c43e,
  33939. 0x9357e70f,
  33940. 0x9d5eea04,
  33941. 0x8f45fd19,
  33942. 0x814cf012,
  33943. 0x3bab6bcb,
  33944. 0x35a266c0,
  33945. 0x27b971dd,
  33946. 0x29b07cd6,
  33947. 0x038f5fe7,
  33948. 0x0d8652ec,
  33949. 0x1f9d45f1,
  33950. 0x119448fa,
  33951. 0x4be30393,
  33952. 0x45ea0e98,
  33953. 0x57f11985,
  33954. 0x59f8148e,
  33955. 0x73c737bf,
  33956. 0x7dce3ab4,
  33957. 0x6fd52da9,
  33958. 0x61dc20a2,
  33959. 0xad766df6,
  33960. 0xa37f60fd,
  33961. 0xb16477e0,
  33962. 0xbf6d7aeb,
  33963. 0x955259da,
  33964. 0x9b5b54d1,
  33965. 0x894043cc,
  33966. 0x87494ec7,
  33967. 0xdd3e05ae,
  33968. 0xd33708a5,
  33969. 0xc12c1fb8,
  33970. 0xcf2512b3,
  33971. 0xe51a3182,
  33972. 0xeb133c89,
  33973. 0xf9082b94,
  33974. 0xf701269f,
  33975. 0x4de6bd46,
  33976. 0x43efb04d,
  33977. 0x51f4a750,
  33978. 0x5ffdaa5b,
  33979. 0x75c2896a,
  33980. 0x7bcb8461,
  33981. 0x69d0937c,
  33982. 0x67d99e77,
  33983. 0x3daed51e,
  33984. 0x33a7d815,
  33985. 0x21bccf08,
  33986. 0x2fb5c203,
  33987. 0x058ae132,
  33988. 0x0b83ec39,
  33989. 0x1998fb24,
  33990. 0x1791f62f,
  33991. 0x764dd68d,
  33992. 0x7844db86,
  33993. 0x6a5fcc9b,
  33994. 0x6456c190,
  33995. 0x4e69e2a1,
  33996. 0x4060efaa,
  33997. 0x527bf8b7,
  33998. 0x5c72f5bc,
  33999. 0x0605bed5,
  34000. 0x080cb3de,
  34001. 0x1a17a4c3,
  34002. 0x141ea9c8,
  34003. 0x3e218af9,
  34004. 0x302887f2,
  34005. 0x223390ef,
  34006. 0x2c3a9de4,
  34007. 0x96dd063d,
  34008. 0x98d40b36,
  34009. 0x8acf1c2b,
  34010. 0x84c61120,
  34011. 0xaef93211,
  34012. 0xa0f03f1a,
  34013. 0xb2eb2807,
  34014. 0xbce2250c,
  34015. 0xe6956e65,
  34016. 0xe89c636e,
  34017. 0xfa877473,
  34018. 0xf48e7978,
  34019. 0xdeb15a49,
  34020. 0xd0b85742,
  34021. 0xc2a3405f,
  34022. 0xccaa4d54,
  34023. 0x41ecdaf7,
  34024. 0x4fe5d7fc,
  34025. 0x5dfec0e1,
  34026. 0x53f7cdea,
  34027. 0x79c8eedb,
  34028. 0x77c1e3d0,
  34029. 0x65daf4cd,
  34030. 0x6bd3f9c6,
  34031. 0x31a4b2af,
  34032. 0x3fadbfa4,
  34033. 0x2db6a8b9,
  34034. 0x23bfa5b2,
  34035. 0x09808683,
  34036. 0x07898b88,
  34037. 0x15929c95,
  34038. 0x1b9b919e,
  34039. 0xa17c0a47,
  34040. 0xaf75074c,
  34041. 0xbd6e1051,
  34042. 0xb3671d5a,
  34043. 0x99583e6b,
  34044. 0x97513360,
  34045. 0x854a247d,
  34046. 0x8b432976,
  34047. 0xd134621f,
  34048. 0xdf3d6f14,
  34049. 0xcd267809,
  34050. 0xc32f7502,
  34051. 0xe9105633,
  34052. 0xe7195b38,
  34053. 0xf5024c25,
  34054. 0xfb0b412e,
  34055. 0x9ad7618c,
  34056. 0x94de6c87,
  34057. 0x86c57b9a,
  34058. 0x88cc7691,
  34059. 0xa2f355a0,
  34060. 0xacfa58ab,
  34061. 0xbee14fb6,
  34062. 0xb0e842bd,
  34063. 0xea9f09d4,
  34064. 0xe49604df,
  34065. 0xf68d13c2,
  34066. 0xf8841ec9,
  34067. 0xd2bb3df8,
  34068. 0xdcb230f3,
  34069. 0xcea927ee,
  34070. 0xc0a02ae5,
  34071. 0x7a47b13c,
  34072. 0x744ebc37,
  34073. 0x6655ab2a,
  34074. 0x685ca621,
  34075. 0x42638510,
  34076. 0x4c6a881b,
  34077. 0x5e719f06,
  34078. 0x5078920d,
  34079. 0x0a0fd964,
  34080. 0x0406d46f,
  34081. 0x161dc372,
  34082. 0x1814ce79,
  34083. 0x322bed48,
  34084. 0x3c22e043,
  34085. 0x2e39f75e,
  34086. 0x2030fa55,
  34087. 0xec9ab701,
  34088. 0xe293ba0a,
  34089. 0xf088ad17,
  34090. 0xfe81a01c,
  34091. 0xd4be832d,
  34092. 0xdab78e26,
  34093. 0xc8ac993b,
  34094. 0xc6a59430,
  34095. 0x9cd2df59,
  34096. 0x92dbd252,
  34097. 0x80c0c54f,
  34098. 0x8ec9c844,
  34099. 0xa4f6eb75,
  34100. 0xaaffe67e,
  34101. 0xb8e4f163,
  34102. 0xb6edfc68,
  34103. 0x0c0a67b1,
  34104. 0x02036aba,
  34105. 0x10187da7,
  34106. 0x1e1170ac,
  34107. 0x342e539d,
  34108. 0x3a275e96,
  34109. 0x283c498b,
  34110. 0x26354480,
  34111. 0x7c420fe9,
  34112. 0x724b02e2,
  34113. 0x605015ff,
  34114. 0x6e5918f4,
  34115. 0x44663bc5,
  34116. 0x4a6f36ce,
  34117. 0x587421d3,
  34118. 0x567d2cd8,
  34119. 0x37a10c7a,
  34120. 0x39a80171,
  34121. 0x2bb3166c,
  34122. 0x25ba1b67,
  34123. 0x0f853856,
  34124. 0x018c355d,
  34125. 0x13972240,
  34126. 0x1d9e2f4b,
  34127. 0x47e96422,
  34128. 0x49e06929,
  34129. 0x5bfb7e34,
  34130. 0x55f2733f,
  34131. 0x7fcd500e,
  34132. 0x71c45d05,
  34133. 0x63df4a18,
  34134. 0x6dd64713,
  34135. 0xd731dcca,
  34136. 0xd938d1c1,
  34137. 0xcb23c6dc,
  34138. 0xc52acbd7,
  34139. 0xef15e8e6,
  34140. 0xe11ce5ed,
  34141. 0xf307f2f0,
  34142. 0xfd0efffb,
  34143. 0xa779b492,
  34144. 0xa970b999,
  34145. 0xbb6bae84,
  34146. 0xb562a38f,
  34147. 0x9f5d80be,
  34148. 0x91548db5,
  34149. 0x834f9aa8,
  34150. 0x8d4697a3
  34151. ]);
  34152. function expandKey256(cipherKey) {
  34153. var b = 240, result = new Uint8Array(b);
  34154. var r = 1;
  34155. result.set(cipherKey);
  34156. for (var j = 32, i = 1; j < b; ++i) {
  34157. if (j % 32 === 16) {
  34158. t1 = s[t1];
  34159. t2 = s[t2];
  34160. t3 = s[t3];
  34161. t4 = s[t4];
  34162. } else if (j % 32 === 0) {
  34163. // RotWord
  34164. var t1 = result[j - 3], t2 = result[j - 2], t3 = result[j - 1], t4 = result[j - 4];
  34165. // SubWord
  34166. t1 = s[t1];
  34167. t2 = s[t2];
  34168. t3 = s[t3];
  34169. t4 = s[t4];
  34170. // Rcon
  34171. t1 = t1 ^ r;
  34172. if ((r <<= 1) >= 256) {
  34173. r = (r ^ 0x1b) & 0xFF;
  34174. }
  34175. }
  34176. for (var n = 0; n < 4; ++n) {
  34177. result[j] = t1 ^= result[j - 32];
  34178. j++;
  34179. result[j] = t2 ^= result[j - 32];
  34180. j++;
  34181. result[j] = t3 ^= result[j - 32];
  34182. j++;
  34183. result[j] = t4 ^= result[j - 32];
  34184. j++;
  34185. }
  34186. }
  34187. return result;
  34188. }
  34189. function decrypt256(input, key) {
  34190. var state = new Uint8Array(16);
  34191. state.set(input);
  34192. var i, j, k;
  34193. var t, u, v;
  34194. // AddRoundKey
  34195. for (j = 0, k = 224; j < 16; ++j, ++k) {
  34196. state[j] ^= key[k];
  34197. }
  34198. for (i = 13; i >= 1; --i) {
  34199. // InvShiftRows
  34200. t = state[13];
  34201. state[13] = state[9];
  34202. state[9] = state[5];
  34203. state[5] = state[1];
  34204. state[1] = t;
  34205. t = state[14];
  34206. u = state[10];
  34207. state[14] = state[6];
  34208. state[10] = state[2];
  34209. state[6] = t;
  34210. state[2] = u;
  34211. t = state[15];
  34212. u = state[11];
  34213. v = state[7];
  34214. state[15] = state[3];
  34215. state[11] = t;
  34216. state[7] = u;
  34217. state[3] = v;
  34218. // InvSubBytes
  34219. for (j = 0; j < 16; ++j) {
  34220. state[j] = inv_s[state[j]];
  34221. }
  34222. // AddRoundKey
  34223. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  34224. state[j] ^= key[k];
  34225. }
  34226. // InvMixColumns
  34227. for (j = 0; j < 16; j += 4) {
  34228. var s0 = mix[state[j]], s1 = mix[state[j + 1]], s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  34229. t = s0 ^ s1 >>> 8 ^ s1 << 24 ^ s2 >>> 16 ^ s2 << 16 ^ s3 >>> 24 ^ s3 << 8;
  34230. state[j] = t >>> 24 & 0xFF;
  34231. state[j + 1] = t >> 16 & 0xFF;
  34232. state[j + 2] = t >> 8 & 0xFF;
  34233. state[j + 3] = t & 0xFF;
  34234. }
  34235. }
  34236. // InvShiftRows
  34237. t = state[13];
  34238. state[13] = state[9];
  34239. state[9] = state[5];
  34240. state[5] = state[1];
  34241. state[1] = t;
  34242. t = state[14];
  34243. u = state[10];
  34244. state[14] = state[6];
  34245. state[10] = state[2];
  34246. state[6] = t;
  34247. state[2] = u;
  34248. t = state[15];
  34249. u = state[11];
  34250. v = state[7];
  34251. state[15] = state[3];
  34252. state[11] = t;
  34253. state[7] = u;
  34254. state[3] = v;
  34255. for (j = 0; j < 16; ++j) {
  34256. // InvSubBytes
  34257. state[j] = inv_s[state[j]];
  34258. // AddRoundKey
  34259. state[j] ^= key[j];
  34260. }
  34261. return state;
  34262. }
  34263. function encrypt256(input, key) {
  34264. var t, u, v, k;
  34265. var state = new Uint8Array(16);
  34266. state.set(input);
  34267. for (j = 0; j < 16; ++j) {
  34268. // AddRoundKey
  34269. state[j] ^= key[j];
  34270. }
  34271. for (i = 1; i < 14; i++) {
  34272. //SubBytes
  34273. for (j = 0; j < 16; ++j) {
  34274. state[j] = s[state[j]];
  34275. }
  34276. //ShiftRows
  34277. v = state[1];
  34278. state[1] = state[5];
  34279. state[5] = state[9];
  34280. state[9] = state[13];
  34281. state[13] = v;
  34282. v = state[2];
  34283. u = state[6];
  34284. state[2] = state[10];
  34285. state[6] = state[14];
  34286. state[10] = v;
  34287. state[14] = u;
  34288. v = state[3];
  34289. u = state[7];
  34290. t = state[11];
  34291. state[3] = state[15];
  34292. state[7] = v;
  34293. state[11] = u;
  34294. state[15] = t;
  34295. //MixColumns
  34296. for (var j = 0; j < 16; j += 4) {
  34297. var s0 = state[j + 0], s1 = state[j + 1];
  34298. var s2 = state[j + 2], s3 = state[j + 3];
  34299. t = s0 ^ s1 ^ s2 ^ s3;
  34300. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  34301. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  34302. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  34303. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  34304. }
  34305. //AddRoundKey
  34306. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  34307. state[j] ^= key[k];
  34308. }
  34309. }
  34310. //SubBytes
  34311. for (j = 0; j < 16; ++j) {
  34312. state[j] = s[state[j]];
  34313. }
  34314. //ShiftRows
  34315. v = state[1];
  34316. state[1] = state[5];
  34317. state[5] = state[9];
  34318. state[9] = state[13];
  34319. state[13] = v;
  34320. v = state[2];
  34321. u = state[6];
  34322. state[2] = state[10];
  34323. state[6] = state[14];
  34324. state[10] = v;
  34325. state[14] = u;
  34326. v = state[3];
  34327. u = state[7];
  34328. t = state[11];
  34329. state[3] = state[15];
  34330. state[7] = v;
  34331. state[11] = u;
  34332. state[15] = t;
  34333. //AddRoundKey
  34334. for (j = 0, k = 224; j < 16; ++j, ++k) {
  34335. state[j] ^= key[k];
  34336. }
  34337. return state;
  34338. }
  34339. function AES256Cipher(key) {
  34340. this.key = expandKey256(key);
  34341. this.buffer = new Uint8Array(16);
  34342. this.bufferPosition = 0;
  34343. }
  34344. function decryptBlock2(data, finalize) {
  34345. var i, j, ii, sourceLength = data.length, buffer = this.buffer, bufferLength = this.bufferPosition, result = [], iv = this.iv;
  34346. for (i = 0; i < sourceLength; ++i) {
  34347. buffer[bufferLength] = data[i];
  34348. ++bufferLength;
  34349. if (bufferLength < 16) {
  34350. continue;
  34351. }
  34352. // buffer is full, decrypting
  34353. var plain = decrypt256(buffer, this.key);
  34354. // xor-ing the IV vector to get plain text
  34355. for (j = 0; j < 16; ++j) {
  34356. plain[j] ^= iv[j];
  34357. }
  34358. iv = buffer;
  34359. result.push(plain);
  34360. buffer = new Uint8Array(16);
  34361. bufferLength = 0;
  34362. }
  34363. // saving incomplete buffer
  34364. this.buffer = buffer;
  34365. this.bufferLength = bufferLength;
  34366. this.iv = iv;
  34367. if (result.length === 0) {
  34368. return new Uint8Array([]);
  34369. }
  34370. // combining plain text blocks into one
  34371. var outputLength = 16 * result.length;
  34372. if (finalize) {
  34373. // undo a padding that is described in RFC 2898
  34374. var lastBlock = result[result.length - 1];
  34375. var psLen = lastBlock[15];
  34376. if (psLen <= 16) {
  34377. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  34378. if (lastBlock[i] !== psLen) {
  34379. // Invalid padding, assume that the block has no padding.
  34380. psLen = 0;
  34381. break;
  34382. }
  34383. }
  34384. outputLength -= psLen;
  34385. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  34386. }
  34387. }
  34388. var output = new Uint8Array(outputLength);
  34389. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  34390. output.set(result[i], j);
  34391. }
  34392. return output;
  34393. }
  34394. AES256Cipher.prototype = {
  34395. decryptBlock: function AES256Cipher_decryptBlock(data, finalize, iv) {
  34396. var i, sourceLength = data.length;
  34397. var buffer = this.buffer, bufferLength = this.bufferPosition;
  34398. // if not supplied an IV wait for IV values
  34399. // they are at the start of the stream
  34400. if (iv) {
  34401. this.iv = iv;
  34402. } else {
  34403. for (i = 0; bufferLength < 16 && i < sourceLength; ++i, ++bufferLength) {
  34404. buffer[bufferLength] = data[i];
  34405. }
  34406. if (bufferLength < 16) {
  34407. //need more data
  34408. this.bufferLength = bufferLength;
  34409. return new Uint8Array([]);
  34410. }
  34411. this.iv = buffer;
  34412. data = data.subarray(16);
  34413. }
  34414. this.buffer = new Uint8Array(16);
  34415. this.bufferLength = 0;
  34416. // starting decryption
  34417. this.decryptBlock = decryptBlock2;
  34418. return this.decryptBlock(data, finalize);
  34419. },
  34420. encrypt: function AES256Cipher_encrypt(data, iv) {
  34421. var i, j, ii, sourceLength = data.length, buffer = this.buffer, bufferLength = this.bufferPosition, result = [];
  34422. if (!iv) {
  34423. iv = new Uint8Array(16);
  34424. }
  34425. for (i = 0; i < sourceLength; ++i) {
  34426. buffer[bufferLength] = data[i];
  34427. ++bufferLength;
  34428. if (bufferLength < 16) {
  34429. continue;
  34430. }
  34431. for (j = 0; j < 16; ++j) {
  34432. buffer[j] ^= iv[j];
  34433. }
  34434. // buffer is full, encrypting
  34435. var cipher = encrypt256(buffer, this.key);
  34436. this.iv = cipher;
  34437. result.push(cipher);
  34438. buffer = new Uint8Array(16);
  34439. bufferLength = 0;
  34440. }
  34441. // saving incomplete buffer
  34442. this.buffer = buffer;
  34443. this.bufferLength = bufferLength;
  34444. this.iv = iv;
  34445. if (result.length === 0) {
  34446. return new Uint8Array([]);
  34447. }
  34448. // combining plain text blocks into one
  34449. var outputLength = 16 * result.length;
  34450. var output = new Uint8Array(outputLength);
  34451. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  34452. output.set(result[i], j);
  34453. }
  34454. return output;
  34455. }
  34456. };
  34457. return AES256Cipher;
  34458. }();
  34459. var PDF17 = function PDF17Closure() {
  34460. function compareByteArrays(array1, array2) {
  34461. if (array1.length !== array2.length) {
  34462. return false;
  34463. }
  34464. for (var i = 0; i < array1.length; i++) {
  34465. if (array1[i] !== array2[i]) {
  34466. return false;
  34467. }
  34468. }
  34469. return true;
  34470. }
  34471. function PDF17() {
  34472. }
  34473. PDF17.prototype = {
  34474. checkOwnerPassword: function PDF17_checkOwnerPassword(password, ownerValidationSalt, userBytes, ownerPassword) {
  34475. var hashData = new Uint8Array(password.length + 56);
  34476. hashData.set(password, 0);
  34477. hashData.set(ownerValidationSalt, password.length);
  34478. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  34479. var result = calculateSHA256(hashData, 0, hashData.length);
  34480. return compareByteArrays(result, ownerPassword);
  34481. },
  34482. checkUserPassword: function PDF17_checkUserPassword(password, userValidationSalt, userPassword) {
  34483. var hashData = new Uint8Array(password.length + 8);
  34484. hashData.set(password, 0);
  34485. hashData.set(userValidationSalt, password.length);
  34486. var result = calculateSHA256(hashData, 0, hashData.length);
  34487. return compareByteArrays(result, userPassword);
  34488. },
  34489. getOwnerKey: function PDF17_getOwnerKey(password, ownerKeySalt, userBytes, ownerEncryption) {
  34490. var hashData = new Uint8Array(password.length + 56);
  34491. hashData.set(password, 0);
  34492. hashData.set(ownerKeySalt, password.length);
  34493. hashData.set(userBytes, password.length + ownerKeySalt.length);
  34494. var key = calculateSHA256(hashData, 0, hashData.length);
  34495. var cipher = new AES256Cipher(key);
  34496. return cipher.decryptBlock(ownerEncryption, false, new Uint8Array(16));
  34497. },
  34498. getUserKey: function PDF17_getUserKey(password, userKeySalt, userEncryption) {
  34499. var hashData = new Uint8Array(password.length + 8);
  34500. hashData.set(password, 0);
  34501. hashData.set(userKeySalt, password.length);
  34502. //key is the decryption key for the UE string
  34503. var key = calculateSHA256(hashData, 0, hashData.length);
  34504. var cipher = new AES256Cipher(key);
  34505. return cipher.decryptBlock(userEncryption, false, new Uint8Array(16));
  34506. }
  34507. };
  34508. return PDF17;
  34509. }();
  34510. var PDF20 = function PDF20Closure() {
  34511. function concatArrays(array1, array2) {
  34512. var t = new Uint8Array(array1.length + array2.length);
  34513. t.set(array1, 0);
  34514. t.set(array2, array1.length);
  34515. return t;
  34516. }
  34517. function calculatePDF20Hash(password, input, userBytes) {
  34518. //This refers to Algorithm 2.B as defined in ISO 32000-2
  34519. var k = calculateSHA256(input, 0, input.length).subarray(0, 32);
  34520. var e = [0];
  34521. var i = 0;
  34522. while (i < 64 || e[e.length - 1] > i - 32) {
  34523. var arrayLength = password.length + k.length + userBytes.length;
  34524. var k1 = new Uint8Array(arrayLength * 64);
  34525. var array = concatArrays(password, k);
  34526. array = concatArrays(array, userBytes);
  34527. for (var j = 0, pos = 0; j < 64; j++, pos += arrayLength) {
  34528. k1.set(array, pos);
  34529. }
  34530. //AES128 CBC NO PADDING with
  34531. //first 16 bytes of k as the key and the second 16 as the iv.
  34532. var cipher = new AES128Cipher(k.subarray(0, 16));
  34533. e = cipher.encrypt(k1, k.subarray(16, 32));
  34534. //Now we have to take the first 16 bytes of an unsigned
  34535. //big endian integer... and compute the remainder
  34536. //modulo 3.... That is a fairly large number and
  34537. //JavaScript isn't going to handle that well...
  34538. //So we're using a trick that allows us to perform
  34539. //modulo math byte by byte
  34540. var remainder = 0;
  34541. for (var z = 0; z < 16; z++) {
  34542. remainder *= 256 % 3;
  34543. remainder %= 3;
  34544. remainder += (e[z] >>> 0) % 3;
  34545. remainder %= 3;
  34546. }
  34547. if (remainder === 0) {
  34548. k = calculateSHA256(e, 0, e.length);
  34549. } else if (remainder === 1) {
  34550. k = calculateSHA384(e, 0, e.length);
  34551. } else if (remainder === 2) {
  34552. k = calculateSHA512(e, 0, e.length);
  34553. }
  34554. i++;
  34555. }
  34556. return k.subarray(0, 32);
  34557. }
  34558. function PDF20() {
  34559. }
  34560. function compareByteArrays(array1, array2) {
  34561. if (array1.length !== array2.length) {
  34562. return false;
  34563. }
  34564. for (var i = 0; i < array1.length; i++) {
  34565. if (array1[i] !== array2[i]) {
  34566. return false;
  34567. }
  34568. }
  34569. return true;
  34570. }
  34571. PDF20.prototype = {
  34572. hash: function PDF20_hash(password, concatBytes, userBytes) {
  34573. return calculatePDF20Hash(password, concatBytes, userBytes);
  34574. },
  34575. checkOwnerPassword: function PDF20_checkOwnerPassword(password, ownerValidationSalt, userBytes, ownerPassword) {
  34576. var hashData = new Uint8Array(password.length + 56);
  34577. hashData.set(password, 0);
  34578. hashData.set(ownerValidationSalt, password.length);
  34579. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  34580. var result = calculatePDF20Hash(password, hashData, userBytes);
  34581. return compareByteArrays(result, ownerPassword);
  34582. },
  34583. checkUserPassword: function PDF20_checkUserPassword(password, userValidationSalt, userPassword) {
  34584. var hashData = new Uint8Array(password.length + 8);
  34585. hashData.set(password, 0);
  34586. hashData.set(userValidationSalt, password.length);
  34587. var result = calculatePDF20Hash(password, hashData, []);
  34588. return compareByteArrays(result, userPassword);
  34589. },
  34590. getOwnerKey: function PDF20_getOwnerKey(password, ownerKeySalt, userBytes, ownerEncryption) {
  34591. var hashData = new Uint8Array(password.length + 56);
  34592. hashData.set(password, 0);
  34593. hashData.set(ownerKeySalt, password.length);
  34594. hashData.set(userBytes, password.length + ownerKeySalt.length);
  34595. var key = calculatePDF20Hash(password, hashData, userBytes);
  34596. var cipher = new AES256Cipher(key);
  34597. return cipher.decryptBlock(ownerEncryption, false, new Uint8Array(16));
  34598. },
  34599. getUserKey: function PDF20_getUserKey(password, userKeySalt, userEncryption) {
  34600. var hashData = new Uint8Array(password.length + 8);
  34601. hashData.set(password, 0);
  34602. hashData.set(userKeySalt, password.length);
  34603. //key is the decryption key for the UE string
  34604. var key = calculatePDF20Hash(password, hashData, []);
  34605. var cipher = new AES256Cipher(key);
  34606. return cipher.decryptBlock(userEncryption, false, new Uint8Array(16));
  34607. }
  34608. };
  34609. return PDF20;
  34610. }();
  34611. var CipherTransform = function CipherTransformClosure() {
  34612. function CipherTransform(stringCipherConstructor, streamCipherConstructor) {
  34613. this.stringCipherConstructor = stringCipherConstructor;
  34614. this.streamCipherConstructor = streamCipherConstructor;
  34615. }
  34616. CipherTransform.prototype = {
  34617. createStream: function CipherTransform_createStream(stream, length) {
  34618. var cipher = new this.streamCipherConstructor();
  34619. return new DecryptStream(stream, length, function cipherTransformDecryptStream(data, finalize) {
  34620. return cipher.decryptBlock(data, finalize);
  34621. });
  34622. },
  34623. decryptString: function CipherTransform_decryptString(s) {
  34624. var cipher = new this.stringCipherConstructor();
  34625. var data = stringToBytes(s);
  34626. data = cipher.decryptBlock(data, true);
  34627. return bytesToString(data);
  34628. }
  34629. };
  34630. return CipherTransform;
  34631. }();
  34632. var CipherTransformFactory = function CipherTransformFactoryClosure() {
  34633. var defaultPasswordBytes = new Uint8Array([
  34634. 0x28,
  34635. 0xBF,
  34636. 0x4E,
  34637. 0x5E,
  34638. 0x4E,
  34639. 0x75,
  34640. 0x8A,
  34641. 0x41,
  34642. 0x64,
  34643. 0x00,
  34644. 0x4E,
  34645. 0x56,
  34646. 0xFF,
  34647. 0xFA,
  34648. 0x01,
  34649. 0x08,
  34650. 0x2E,
  34651. 0x2E,
  34652. 0x00,
  34653. 0xB6,
  34654. 0xD0,
  34655. 0x68,
  34656. 0x3E,
  34657. 0x80,
  34658. 0x2F,
  34659. 0x0C,
  34660. 0xA9,
  34661. 0xFE,
  34662. 0x64,
  34663. 0x53,
  34664. 0x69,
  34665. 0x7A
  34666. ]);
  34667. function createEncryptionKey20(revision, password, ownerPassword, ownerValidationSalt, ownerKeySalt, uBytes, userPassword, userValidationSalt, userKeySalt, ownerEncryption, userEncryption, perms) {
  34668. if (password) {
  34669. var passwordLength = Math.min(127, password.length);
  34670. password = password.subarray(0, passwordLength);
  34671. } else {
  34672. password = [];
  34673. }
  34674. var pdfAlgorithm;
  34675. if (revision === 6) {
  34676. pdfAlgorithm = new PDF20();
  34677. } else {
  34678. pdfAlgorithm = new PDF17();
  34679. }
  34680. if (pdfAlgorithm.checkUserPassword(password, userValidationSalt, userPassword)) {
  34681. return pdfAlgorithm.getUserKey(password, userKeySalt, userEncryption);
  34682. } else if (password.length && pdfAlgorithm.checkOwnerPassword(password, ownerValidationSalt, uBytes, ownerPassword)) {
  34683. return pdfAlgorithm.getOwnerKey(password, ownerKeySalt, uBytes, ownerEncryption);
  34684. }
  34685. return null;
  34686. }
  34687. function prepareKeyData(fileId, password, ownerPassword, userPassword, flags, revision, keyLength, encryptMetadata) {
  34688. var hashDataSize = 40 + ownerPassword.length + fileId.length;
  34689. var hashData = new Uint8Array(hashDataSize), i = 0, j, n;
  34690. if (password) {
  34691. n = Math.min(32, password.length);
  34692. for (; i < n; ++i) {
  34693. hashData[i] = password[i];
  34694. }
  34695. }
  34696. j = 0;
  34697. while (i < 32) {
  34698. hashData[i++] = defaultPasswordBytes[j++];
  34699. }
  34700. // as now the padded password in the hashData[0..i]
  34701. for (j = 0, n = ownerPassword.length; j < n; ++j) {
  34702. hashData[i++] = ownerPassword[j];
  34703. }
  34704. hashData[i++] = flags & 0xFF;
  34705. hashData[i++] = flags >> 8 & 0xFF;
  34706. hashData[i++] = flags >> 16 & 0xFF;
  34707. hashData[i++] = flags >>> 24 & 0xFF;
  34708. for (j = 0, n = fileId.length; j < n; ++j) {
  34709. hashData[i++] = fileId[j];
  34710. }
  34711. if (revision >= 4 && !encryptMetadata) {
  34712. hashData[i++] = 0xFF;
  34713. hashData[i++] = 0xFF;
  34714. hashData[i++] = 0xFF;
  34715. hashData[i++] = 0xFF;
  34716. }
  34717. var hash = calculateMD5(hashData, 0, i);
  34718. var keyLengthInBytes = keyLength >> 3;
  34719. if (revision >= 3) {
  34720. for (j = 0; j < 50; ++j) {
  34721. hash = calculateMD5(hash, 0, keyLengthInBytes);
  34722. }
  34723. }
  34724. var encryptionKey = hash.subarray(0, keyLengthInBytes);
  34725. var cipher, checkData;
  34726. if (revision >= 3) {
  34727. for (i = 0; i < 32; ++i) {
  34728. hashData[i] = defaultPasswordBytes[i];
  34729. }
  34730. for (j = 0, n = fileId.length; j < n; ++j) {
  34731. hashData[i++] = fileId[j];
  34732. }
  34733. cipher = new ARCFourCipher(encryptionKey);
  34734. checkData = cipher.encryptBlock(calculateMD5(hashData, 0, i));
  34735. n = encryptionKey.length;
  34736. var derivedKey = new Uint8Array(n), k;
  34737. for (j = 1; j <= 19; ++j) {
  34738. for (k = 0; k < n; ++k) {
  34739. derivedKey[k] = encryptionKey[k] ^ j;
  34740. }
  34741. cipher = new ARCFourCipher(derivedKey);
  34742. checkData = cipher.encryptBlock(checkData);
  34743. }
  34744. for (j = 0, n = checkData.length; j < n; ++j) {
  34745. if (userPassword[j] !== checkData[j]) {
  34746. return null;
  34747. }
  34748. }
  34749. } else {
  34750. cipher = new ARCFourCipher(encryptionKey);
  34751. checkData = cipher.encryptBlock(defaultPasswordBytes);
  34752. for (j = 0, n = checkData.length; j < n; ++j) {
  34753. if (userPassword[j] !== checkData[j]) {
  34754. return null;
  34755. }
  34756. }
  34757. }
  34758. return encryptionKey;
  34759. }
  34760. function decodeUserPassword(password, ownerPassword, revision, keyLength) {
  34761. var hashData = new Uint8Array(32), i = 0, j, n;
  34762. n = Math.min(32, password.length);
  34763. for (; i < n; ++i) {
  34764. hashData[i] = password[i];
  34765. }
  34766. j = 0;
  34767. while (i < 32) {
  34768. hashData[i++] = defaultPasswordBytes[j++];
  34769. }
  34770. var hash = calculateMD5(hashData, 0, i);
  34771. var keyLengthInBytes = keyLength >> 3;
  34772. if (revision >= 3) {
  34773. for (j = 0; j < 50; ++j) {
  34774. hash = calculateMD5(hash, 0, hash.length);
  34775. }
  34776. }
  34777. var cipher, userPassword;
  34778. if (revision >= 3) {
  34779. userPassword = ownerPassword;
  34780. var derivedKey = new Uint8Array(keyLengthInBytes), k;
  34781. for (j = 19; j >= 0; j--) {
  34782. for (k = 0; k < keyLengthInBytes; ++k) {
  34783. derivedKey[k] = hash[k] ^ j;
  34784. }
  34785. cipher = new ARCFourCipher(derivedKey);
  34786. userPassword = cipher.encryptBlock(userPassword);
  34787. }
  34788. } else {
  34789. cipher = new ARCFourCipher(hash.subarray(0, keyLengthInBytes));
  34790. userPassword = cipher.encryptBlock(ownerPassword);
  34791. }
  34792. return userPassword;
  34793. }
  34794. var identityName = Name.get('Identity');
  34795. function CipherTransformFactory(dict, fileId, password) {
  34796. var filter = dict.get('Filter');
  34797. if (!isName(filter, 'Standard')) {
  34798. error('unknown encryption method');
  34799. }
  34800. this.dict = dict;
  34801. var algorithm = dict.get('V');
  34802. if (!isInt(algorithm) || algorithm !== 1 && algorithm !== 2 && algorithm !== 4 && algorithm !== 5) {
  34803. error('unsupported encryption algorithm');
  34804. }
  34805. this.algorithm = algorithm;
  34806. var keyLength = dict.get('Length');
  34807. if (!keyLength) {
  34808. // Spec asks to rely on encryption dictionary's Length entry, however
  34809. // some PDFs don't have it. Trying to recover.
  34810. if (algorithm <= 3) {
  34811. // For 1 and 2 it's fixed to 40-bit, for 3 40-bit is a minimal value.
  34812. keyLength = 40;
  34813. } else {
  34814. // Trying to find default handler -- it usually has Length.
  34815. var cfDict = dict.get('CF');
  34816. var streamCryptoName = dict.get('StmF');
  34817. if (isDict(cfDict) && isName(streamCryptoName)) {
  34818. cfDict.suppressEncryption = true;
  34819. // See comment below.
  34820. var handlerDict = cfDict.get(streamCryptoName.name);
  34821. keyLength = handlerDict && handlerDict.get('Length') || 128;
  34822. if (keyLength < 40) {
  34823. // Sometimes it's incorrect value of bits, generators specify bytes.
  34824. keyLength <<= 3;
  34825. }
  34826. }
  34827. }
  34828. }
  34829. if (!isInt(keyLength) || keyLength < 40 || keyLength % 8 !== 0) {
  34830. error('invalid key length');
  34831. }
  34832. // prepare keys
  34833. var ownerPassword = stringToBytes(dict.get('O')).subarray(0, 32);
  34834. var userPassword = stringToBytes(dict.get('U')).subarray(0, 32);
  34835. var flags = dict.get('P');
  34836. var revision = dict.get('R');
  34837. // meaningful when V is 4 or 5
  34838. var encryptMetadata = (algorithm === 4 || algorithm === 5) && dict.get('EncryptMetadata') !== false;
  34839. this.encryptMetadata = encryptMetadata;
  34840. var fileIdBytes = stringToBytes(fileId);
  34841. var passwordBytes;
  34842. if (password) {
  34843. if (revision === 6) {
  34844. try {
  34845. password = utf8StringToString(password);
  34846. } catch (ex) {
  34847. warn('CipherTransformFactory: ' + 'Unable to convert UTF8 encoded password.');
  34848. }
  34849. }
  34850. passwordBytes = stringToBytes(password);
  34851. }
  34852. var encryptionKey;
  34853. if (algorithm !== 5) {
  34854. encryptionKey = prepareKeyData(fileIdBytes, passwordBytes, ownerPassword, userPassword, flags, revision, keyLength, encryptMetadata);
  34855. } else {
  34856. var ownerValidationSalt = stringToBytes(dict.get('O')).subarray(32, 40);
  34857. var ownerKeySalt = stringToBytes(dict.get('O')).subarray(40, 48);
  34858. var uBytes = stringToBytes(dict.get('U')).subarray(0, 48);
  34859. var userValidationSalt = stringToBytes(dict.get('U')).subarray(32, 40);
  34860. var userKeySalt = stringToBytes(dict.get('U')).subarray(40, 48);
  34861. var ownerEncryption = stringToBytes(dict.get('OE'));
  34862. var userEncryption = stringToBytes(dict.get('UE'));
  34863. var perms = stringToBytes(dict.get('Perms'));
  34864. encryptionKey = createEncryptionKey20(revision, passwordBytes, ownerPassword, ownerValidationSalt, ownerKeySalt, uBytes, userPassword, userValidationSalt, userKeySalt, ownerEncryption, userEncryption, perms);
  34865. }
  34866. if (!encryptionKey && !password) {
  34867. throw new PasswordException('No password given', PasswordResponses.NEED_PASSWORD);
  34868. } else if (!encryptionKey && password) {
  34869. // Attempting use the password as an owner password
  34870. var decodedPassword = decodeUserPassword(passwordBytes, ownerPassword, revision, keyLength);
  34871. encryptionKey = prepareKeyData(fileIdBytes, decodedPassword, ownerPassword, userPassword, flags, revision, keyLength, encryptMetadata);
  34872. }
  34873. if (!encryptionKey) {
  34874. throw new PasswordException('Incorrect Password', PasswordResponses.INCORRECT_PASSWORD);
  34875. }
  34876. this.encryptionKey = encryptionKey;
  34877. if (algorithm >= 4) {
  34878. var cf = dict.get('CF');
  34879. if (isDict(cf)) {
  34880. // The 'CF' dictionary itself should not be encrypted, and by setting
  34881. // `suppressEncryption` we can prevent an infinite loop inside of
  34882. // `XRef_fetchUncompressed` if the dictionary contains indirect objects
  34883. // (fixes issue7665.pdf).
  34884. cf.suppressEncryption = true;
  34885. }
  34886. this.cf = cf;
  34887. this.stmf = dict.get('StmF') || identityName;
  34888. this.strf = dict.get('StrF') || identityName;
  34889. this.eff = dict.get('EFF') || this.stmf;
  34890. }
  34891. }
  34892. function buildObjectKey(num, gen, encryptionKey, isAes) {
  34893. var key = new Uint8Array(encryptionKey.length + 9), i, n;
  34894. for (i = 0, n = encryptionKey.length; i < n; ++i) {
  34895. key[i] = encryptionKey[i];
  34896. }
  34897. key[i++] = num & 0xFF;
  34898. key[i++] = num >> 8 & 0xFF;
  34899. key[i++] = num >> 16 & 0xFF;
  34900. key[i++] = gen & 0xFF;
  34901. key[i++] = gen >> 8 & 0xFF;
  34902. if (isAes) {
  34903. key[i++] = 0x73;
  34904. key[i++] = 0x41;
  34905. key[i++] = 0x6C;
  34906. key[i++] = 0x54;
  34907. }
  34908. var hash = calculateMD5(key, 0, i);
  34909. return hash.subarray(0, Math.min(encryptionKey.length + 5, 16));
  34910. }
  34911. function buildCipherConstructor(cf, name, num, gen, key) {
  34912. assert(isName(name), 'Invalid crypt filter name.');
  34913. var cryptFilter = cf.get(name.name);
  34914. var cfm;
  34915. if (cryptFilter !== null && cryptFilter !== undefined) {
  34916. cfm = cryptFilter.get('CFM');
  34917. }
  34918. if (!cfm || cfm.name === 'None') {
  34919. return function cipherTransformFactoryBuildCipherConstructorNone() {
  34920. return new NullCipher();
  34921. };
  34922. }
  34923. if ('V2' === cfm.name) {
  34924. return function cipherTransformFactoryBuildCipherConstructorV2() {
  34925. return new ARCFourCipher(buildObjectKey(num, gen, key, false));
  34926. };
  34927. }
  34928. if ('AESV2' === cfm.name) {
  34929. return function cipherTransformFactoryBuildCipherConstructorAESV2() {
  34930. return new AES128Cipher(buildObjectKey(num, gen, key, true));
  34931. };
  34932. }
  34933. if ('AESV3' === cfm.name) {
  34934. return function cipherTransformFactoryBuildCipherConstructorAESV3() {
  34935. return new AES256Cipher(key);
  34936. };
  34937. }
  34938. error('Unknown crypto method');
  34939. }
  34940. CipherTransformFactory.prototype = {
  34941. createCipherTransform: function CipherTransformFactory_createCipherTransform(num, gen) {
  34942. if (this.algorithm === 4 || this.algorithm === 5) {
  34943. return new CipherTransform(buildCipherConstructor(this.cf, this.stmf, num, gen, this.encryptionKey), buildCipherConstructor(this.cf, this.strf, num, gen, this.encryptionKey));
  34944. }
  34945. // algorithms 1 and 2
  34946. var key = buildObjectKey(num, gen, this.encryptionKey, false);
  34947. var cipherConstructor = function buildCipherCipherConstructor() {
  34948. return new ARCFourCipher(key);
  34949. };
  34950. return new CipherTransform(cipherConstructor, cipherConstructor);
  34951. }
  34952. };
  34953. return CipherTransformFactory;
  34954. }();
  34955. exports.AES128Cipher = AES128Cipher;
  34956. exports.AES256Cipher = AES256Cipher;
  34957. exports.ARCFourCipher = ARCFourCipher;
  34958. exports.CipherTransformFactory = CipherTransformFactory;
  34959. exports.PDF17 = PDF17;
  34960. exports.PDF20 = PDF20;
  34961. exports.calculateMD5 = calculateMD5;
  34962. exports.calculateSHA256 = calculateSHA256;
  34963. exports.calculateSHA384 = calculateSHA384;
  34964. exports.calculateSHA512 = calculateSHA512;
  34965. }));
  34966. (function (root, factory) {
  34967. factory(root.pdfjsCoreFontRenderer = {}, root.pdfjsSharedUtil, root.pdfjsCoreStream, root.pdfjsCoreGlyphList, root.pdfjsCoreEncodings, root.pdfjsCoreCFFParser);
  34968. }(this, function (exports, sharedUtil, coreStream, coreGlyphList, coreEncodings, coreCFFParser) {
  34969. var Util = sharedUtil.Util;
  34970. var bytesToString = sharedUtil.bytesToString;
  34971. var error = sharedUtil.error;
  34972. var Stream = coreStream.Stream;
  34973. var getGlyphsUnicode = coreGlyphList.getGlyphsUnicode;
  34974. var StandardEncoding = coreEncodings.StandardEncoding;
  34975. var CFFParser = coreCFFParser.CFFParser;
  34976. var FontRendererFactory = function FontRendererFactoryClosure() {
  34977. function getLong(data, offset) {
  34978. return data[offset] << 24 | data[offset + 1] << 16 | data[offset + 2] << 8 | data[offset + 3];
  34979. }
  34980. function getUshort(data, offset) {
  34981. return data[offset] << 8 | data[offset + 1];
  34982. }
  34983. function parseCmap(data, start, end) {
  34984. var offset = getUshort(data, start + 2) === 1 ? getLong(data, start + 8) : getLong(data, start + 16);
  34985. var format = getUshort(data, start + offset);
  34986. var length, ranges, p, i;
  34987. if (format === 4) {
  34988. length = getUshort(data, start + offset + 2);
  34989. var segCount = getUshort(data, start + offset + 6) >> 1;
  34990. p = start + offset + 14;
  34991. ranges = [];
  34992. for (i = 0; i < segCount; i++, p += 2) {
  34993. ranges[i] = { end: getUshort(data, p) };
  34994. }
  34995. p += 2;
  34996. for (i = 0; i < segCount; i++, p += 2) {
  34997. ranges[i].start = getUshort(data, p);
  34998. }
  34999. for (i = 0; i < segCount; i++, p += 2) {
  35000. ranges[i].idDelta = getUshort(data, p);
  35001. }
  35002. for (i = 0; i < segCount; i++, p += 2) {
  35003. var idOffset = getUshort(data, p);
  35004. if (idOffset === 0) {
  35005. continue;
  35006. }
  35007. ranges[i].ids = [];
  35008. for (var j = 0, jj = ranges[i].end - ranges[i].start + 1; j < jj; j++) {
  35009. ranges[i].ids[j] = getUshort(data, p + idOffset);
  35010. idOffset += 2;
  35011. }
  35012. }
  35013. return ranges;
  35014. } else if (format === 12) {
  35015. length = getLong(data, start + offset + 4);
  35016. var groups = getLong(data, start + offset + 12);
  35017. p = start + offset + 16;
  35018. ranges = [];
  35019. for (i = 0; i < groups; i++) {
  35020. ranges.push({
  35021. start: getLong(data, p),
  35022. end: getLong(data, p + 4),
  35023. idDelta: getLong(data, p + 8) - getLong(data, p)
  35024. });
  35025. p += 12;
  35026. }
  35027. return ranges;
  35028. }
  35029. error('not supported cmap: ' + format);
  35030. }
  35031. function parseCff(data, start, end, seacAnalysisEnabled) {
  35032. var properties = {};
  35033. var parser = new CFFParser(new Stream(data, start, end - start), properties, seacAnalysisEnabled);
  35034. var cff = parser.parse();
  35035. return {
  35036. glyphs: cff.charStrings.objects,
  35037. subrs: cff.topDict.privateDict && cff.topDict.privateDict.subrsIndex && cff.topDict.privateDict.subrsIndex.objects,
  35038. gsubrs: cff.globalSubrIndex && cff.globalSubrIndex.objects
  35039. };
  35040. }
  35041. function parseGlyfTable(glyf, loca, isGlyphLocationsLong) {
  35042. var itemSize, itemDecode;
  35043. if (isGlyphLocationsLong) {
  35044. itemSize = 4;
  35045. itemDecode = function fontItemDecodeLong(data, offset) {
  35046. return data[offset] << 24 | data[offset + 1] << 16 | data[offset + 2] << 8 | data[offset + 3];
  35047. };
  35048. } else {
  35049. itemSize = 2;
  35050. itemDecode = function fontItemDecode(data, offset) {
  35051. return data[offset] << 9 | data[offset + 1] << 1;
  35052. };
  35053. }
  35054. var glyphs = [];
  35055. var startOffset = itemDecode(loca, 0);
  35056. for (var j = itemSize; j < loca.length; j += itemSize) {
  35057. var endOffset = itemDecode(loca, j);
  35058. glyphs.push(glyf.subarray(startOffset, endOffset));
  35059. startOffset = endOffset;
  35060. }
  35061. return glyphs;
  35062. }
  35063. function lookupCmap(ranges, unicode) {
  35064. var code = unicode.charCodeAt(0), gid = 0;
  35065. var l = 0, r = ranges.length - 1;
  35066. while (l < r) {
  35067. var c = l + r + 1 >> 1;
  35068. if (code < ranges[c].start) {
  35069. r = c - 1;
  35070. } else {
  35071. l = c;
  35072. }
  35073. }
  35074. if (ranges[l].start <= code && code <= ranges[l].end) {
  35075. gid = ranges[l].idDelta + (ranges[l].ids ? ranges[l].ids[code - ranges[l].start] : code) & 0xFFFF;
  35076. }
  35077. return {
  35078. charCode: code,
  35079. glyphId: gid
  35080. };
  35081. }
  35082. function compileGlyf(code, cmds, font) {
  35083. function moveTo(x, y) {
  35084. cmds.push({
  35085. cmd: 'moveTo',
  35086. args: [
  35087. x,
  35088. y
  35089. ]
  35090. });
  35091. }
  35092. function lineTo(x, y) {
  35093. cmds.push({
  35094. cmd: 'lineTo',
  35095. args: [
  35096. x,
  35097. y
  35098. ]
  35099. });
  35100. }
  35101. function quadraticCurveTo(xa, ya, x, y) {
  35102. cmds.push({
  35103. cmd: 'quadraticCurveTo',
  35104. args: [
  35105. xa,
  35106. ya,
  35107. x,
  35108. y
  35109. ]
  35110. });
  35111. }
  35112. var i = 0;
  35113. var numberOfContours = (code[i] << 24 | code[i + 1] << 16) >> 16;
  35114. var flags;
  35115. var x = 0, y = 0;
  35116. i += 10;
  35117. if (numberOfContours < 0) {
  35118. // composite glyph
  35119. do {
  35120. flags = code[i] << 8 | code[i + 1];
  35121. var glyphIndex = code[i + 2] << 8 | code[i + 3];
  35122. i += 4;
  35123. var arg1, arg2;
  35124. if (flags & 0x01) {
  35125. arg1 = (code[i] << 24 | code[i + 1] << 16) >> 16;
  35126. arg2 = (code[i + 2] << 24 | code[i + 3] << 16) >> 16;
  35127. i += 4;
  35128. } else {
  35129. arg1 = code[i++];
  35130. arg2 = code[i++];
  35131. }
  35132. if (flags & 0x02) {
  35133. x = arg1;
  35134. y = arg2;
  35135. } else {
  35136. x = 0;
  35137. y = 0;
  35138. }
  35139. // TODO "they are points" ?
  35140. var scaleX = 1, scaleY = 1, scale01 = 0, scale10 = 0;
  35141. if (flags & 0x08) {
  35142. scaleX = scaleY = (code[i] << 24 | code[i + 1] << 16) / 1073741824;
  35143. i += 2;
  35144. } else if (flags & 0x40) {
  35145. scaleX = (code[i] << 24 | code[i + 1] << 16) / 1073741824;
  35146. scaleY = (code[i + 2] << 24 | code[i + 3] << 16) / 1073741824;
  35147. i += 4;
  35148. } else if (flags & 0x80) {
  35149. scaleX = (code[i] << 24 | code[i + 1] << 16) / 1073741824;
  35150. scale01 = (code[i + 2] << 24 | code[i + 3] << 16) / 1073741824;
  35151. scale10 = (code[i + 4] << 24 | code[i + 5] << 16) / 1073741824;
  35152. scaleY = (code[i + 6] << 24 | code[i + 7] << 16) / 1073741824;
  35153. i += 8;
  35154. }
  35155. var subglyph = font.glyphs[glyphIndex];
  35156. if (subglyph) {
  35157. cmds.push({ cmd: 'save' });
  35158. cmds.push({
  35159. cmd: 'transform',
  35160. args: [
  35161. scaleX,
  35162. scale01,
  35163. scale10,
  35164. scaleY,
  35165. x,
  35166. y
  35167. ]
  35168. });
  35169. compileGlyf(subglyph, cmds, font);
  35170. cmds.push({ cmd: 'restore' });
  35171. }
  35172. } while (flags & 0x20);
  35173. } else {
  35174. // simple glyph
  35175. var endPtsOfContours = [];
  35176. var j, jj;
  35177. for (j = 0; j < numberOfContours; j++) {
  35178. endPtsOfContours.push(code[i] << 8 | code[i + 1]);
  35179. i += 2;
  35180. }
  35181. var instructionLength = code[i] << 8 | code[i + 1];
  35182. i += 2 + instructionLength;
  35183. // skipping the instructions
  35184. var numberOfPoints = endPtsOfContours[endPtsOfContours.length - 1] + 1;
  35185. var points = [];
  35186. while (points.length < numberOfPoints) {
  35187. flags = code[i++];
  35188. var repeat = 1;
  35189. if (flags & 0x08) {
  35190. repeat += code[i++];
  35191. }
  35192. while (repeat-- > 0) {
  35193. points.push({ flags: flags });
  35194. }
  35195. }
  35196. for (j = 0; j < numberOfPoints; j++) {
  35197. switch (points[j].flags & 0x12) {
  35198. case 0x00:
  35199. x += (code[i] << 24 | code[i + 1] << 16) >> 16;
  35200. i += 2;
  35201. break;
  35202. case 0x02:
  35203. x -= code[i++];
  35204. break;
  35205. case 0x12:
  35206. x += code[i++];
  35207. break;
  35208. }
  35209. points[j].x = x;
  35210. }
  35211. for (j = 0; j < numberOfPoints; j++) {
  35212. switch (points[j].flags & 0x24) {
  35213. case 0x00:
  35214. y += (code[i] << 24 | code[i + 1] << 16) >> 16;
  35215. i += 2;
  35216. break;
  35217. case 0x04:
  35218. y -= code[i++];
  35219. break;
  35220. case 0x24:
  35221. y += code[i++];
  35222. break;
  35223. }
  35224. points[j].y = y;
  35225. }
  35226. var startPoint = 0;
  35227. for (i = 0; i < numberOfContours; i++) {
  35228. var endPoint = endPtsOfContours[i];
  35229. // contours might have implicit points, which is located in the middle
  35230. // between two neighboring off-curve points
  35231. var contour = points.slice(startPoint, endPoint + 1);
  35232. if (contour[0].flags & 1) {
  35233. contour.push(contour[0]);
  35234. } else // using start point at the contour end
  35235. if (contour[contour.length - 1].flags & 1) {
  35236. // first is off-curve point, trying to use one from the end
  35237. contour.unshift(contour[contour.length - 1]);
  35238. } else {
  35239. // start and end are off-curve points, creating implicit one
  35240. var p = {
  35241. flags: 1,
  35242. x: (contour[0].x + contour[contour.length - 1].x) / 2,
  35243. y: (contour[0].y + contour[contour.length - 1].y) / 2
  35244. };
  35245. contour.unshift(p);
  35246. contour.push(p);
  35247. }
  35248. moveTo(contour[0].x, contour[0].y);
  35249. for (j = 1, jj = contour.length; j < jj; j++) {
  35250. if (contour[j].flags & 1) {
  35251. lineTo(contour[j].x, contour[j].y);
  35252. } else if (contour[j + 1].flags & 1) {
  35253. quadraticCurveTo(contour[j].x, contour[j].y, contour[j + 1].x, contour[j + 1].y);
  35254. j++;
  35255. } else {
  35256. quadraticCurveTo(contour[j].x, contour[j].y, (contour[j].x + contour[j + 1].x) / 2, (contour[j].y + contour[j + 1].y) / 2);
  35257. }
  35258. }
  35259. startPoint = endPoint + 1;
  35260. }
  35261. }
  35262. }
  35263. function compileCharString(code, cmds, font) {
  35264. var stack = [];
  35265. var x = 0, y = 0;
  35266. var stems = 0;
  35267. function moveTo(x, y) {
  35268. cmds.push({
  35269. cmd: 'moveTo',
  35270. args: [
  35271. x,
  35272. y
  35273. ]
  35274. });
  35275. }
  35276. function lineTo(x, y) {
  35277. cmds.push({
  35278. cmd: 'lineTo',
  35279. args: [
  35280. x,
  35281. y
  35282. ]
  35283. });
  35284. }
  35285. function bezierCurveTo(x1, y1, x2, y2, x, y) {
  35286. cmds.push({
  35287. cmd: 'bezierCurveTo',
  35288. args: [
  35289. x1,
  35290. y1,
  35291. x2,
  35292. y2,
  35293. x,
  35294. y
  35295. ]
  35296. });
  35297. }
  35298. function parse(code) {
  35299. var i = 0;
  35300. while (i < code.length) {
  35301. var stackClean = false;
  35302. var v = code[i++];
  35303. var xa, xb, ya, yb, y1, y2, y3, n, subrCode;
  35304. switch (v) {
  35305. case 1:
  35306. // hstem
  35307. stems += stack.length >> 1;
  35308. stackClean = true;
  35309. break;
  35310. case 3:
  35311. // vstem
  35312. stems += stack.length >> 1;
  35313. stackClean = true;
  35314. break;
  35315. case 4:
  35316. // vmoveto
  35317. y += stack.pop();
  35318. moveTo(x, y);
  35319. stackClean = true;
  35320. break;
  35321. case 5:
  35322. // rlineto
  35323. while (stack.length > 0) {
  35324. x += stack.shift();
  35325. y += stack.shift();
  35326. lineTo(x, y);
  35327. }
  35328. break;
  35329. case 6:
  35330. // hlineto
  35331. while (stack.length > 0) {
  35332. x += stack.shift();
  35333. lineTo(x, y);
  35334. if (stack.length === 0) {
  35335. break;
  35336. }
  35337. y += stack.shift();
  35338. lineTo(x, y);
  35339. }
  35340. break;
  35341. case 7:
  35342. // vlineto
  35343. while (stack.length > 0) {
  35344. y += stack.shift();
  35345. lineTo(x, y);
  35346. if (stack.length === 0) {
  35347. break;
  35348. }
  35349. x += stack.shift();
  35350. lineTo(x, y);
  35351. }
  35352. break;
  35353. case 8:
  35354. // rrcurveto
  35355. while (stack.length > 0) {
  35356. xa = x + stack.shift();
  35357. ya = y + stack.shift();
  35358. xb = xa + stack.shift();
  35359. yb = ya + stack.shift();
  35360. x = xb + stack.shift();
  35361. y = yb + stack.shift();
  35362. bezierCurveTo(xa, ya, xb, yb, x, y);
  35363. }
  35364. break;
  35365. case 10:
  35366. // callsubr
  35367. n = stack.pop() + font.subrsBias;
  35368. subrCode = font.subrs[n];
  35369. if (subrCode) {
  35370. parse(subrCode);
  35371. }
  35372. break;
  35373. case 11:
  35374. // return
  35375. return;
  35376. case 12:
  35377. v = code[i++];
  35378. switch (v) {
  35379. case 34:
  35380. // flex
  35381. xa = x + stack.shift();
  35382. xb = xa + stack.shift();
  35383. y1 = y + stack.shift();
  35384. x = xb + stack.shift();
  35385. bezierCurveTo(xa, y, xb, y1, x, y1);
  35386. xa = x + stack.shift();
  35387. xb = xa + stack.shift();
  35388. x = xb + stack.shift();
  35389. bezierCurveTo(xa, y1, xb, y, x, y);
  35390. break;
  35391. case 35:
  35392. // flex
  35393. xa = x + stack.shift();
  35394. ya = y + stack.shift();
  35395. xb = xa + stack.shift();
  35396. yb = ya + stack.shift();
  35397. x = xb + stack.shift();
  35398. y = yb + stack.shift();
  35399. bezierCurveTo(xa, ya, xb, yb, x, y);
  35400. xa = x + stack.shift();
  35401. ya = y + stack.shift();
  35402. xb = xa + stack.shift();
  35403. yb = ya + stack.shift();
  35404. x = xb + stack.shift();
  35405. y = yb + stack.shift();
  35406. bezierCurveTo(xa, ya, xb, yb, x, y);
  35407. stack.pop();
  35408. // fd
  35409. break;
  35410. case 36:
  35411. // hflex1
  35412. xa = x + stack.shift();
  35413. y1 = y + stack.shift();
  35414. xb = xa + stack.shift();
  35415. y2 = y1 + stack.shift();
  35416. x = xb + stack.shift();
  35417. bezierCurveTo(xa, y1, xb, y2, x, y2);
  35418. xa = x + stack.shift();
  35419. xb = xa + stack.shift();
  35420. y3 = y2 + stack.shift();
  35421. x = xb + stack.shift();
  35422. bezierCurveTo(xa, y2, xb, y3, x, y);
  35423. break;
  35424. case 37:
  35425. // flex1
  35426. var x0 = x, y0 = y;
  35427. xa = x + stack.shift();
  35428. ya = y + stack.shift();
  35429. xb = xa + stack.shift();
  35430. yb = ya + stack.shift();
  35431. x = xb + stack.shift();
  35432. y = yb + stack.shift();
  35433. bezierCurveTo(xa, ya, xb, yb, x, y);
  35434. xa = x + stack.shift();
  35435. ya = y + stack.shift();
  35436. xb = xa + stack.shift();
  35437. yb = ya + stack.shift();
  35438. x = xb;
  35439. y = yb;
  35440. if (Math.abs(x - x0) > Math.abs(y - y0)) {
  35441. x += stack.shift();
  35442. } else {
  35443. y += stack.shift();
  35444. }
  35445. bezierCurveTo(xa, ya, xb, yb, x, y);
  35446. break;
  35447. default:
  35448. error('unknown operator: 12 ' + v);
  35449. }
  35450. break;
  35451. case 14:
  35452. // endchar
  35453. if (stack.length >= 4) {
  35454. var achar = stack.pop();
  35455. var bchar = stack.pop();
  35456. y = stack.pop();
  35457. x = stack.pop();
  35458. cmds.push({ cmd: 'save' });
  35459. cmds.push({
  35460. cmd: 'translate',
  35461. args: [
  35462. x,
  35463. y
  35464. ]
  35465. });
  35466. var cmap = lookupCmap(font.cmap, String.fromCharCode(font.glyphNameMap[StandardEncoding[achar]]));
  35467. compileCharString(font.glyphs[cmap.glyphId], cmds, font);
  35468. cmds.push({ cmd: 'restore' });
  35469. cmap = lookupCmap(font.cmap, String.fromCharCode(font.glyphNameMap[StandardEncoding[bchar]]));
  35470. compileCharString(font.glyphs[cmap.glyphId], cmds, font);
  35471. }
  35472. return;
  35473. case 18:
  35474. // hstemhm
  35475. stems += stack.length >> 1;
  35476. stackClean = true;
  35477. break;
  35478. case 19:
  35479. // hintmask
  35480. stems += stack.length >> 1;
  35481. i += stems + 7 >> 3;
  35482. stackClean = true;
  35483. break;
  35484. case 20:
  35485. // cntrmask
  35486. stems += stack.length >> 1;
  35487. i += stems + 7 >> 3;
  35488. stackClean = true;
  35489. break;
  35490. case 21:
  35491. // rmoveto
  35492. y += stack.pop();
  35493. x += stack.pop();
  35494. moveTo(x, y);
  35495. stackClean = true;
  35496. break;
  35497. case 22:
  35498. // hmoveto
  35499. x += stack.pop();
  35500. moveTo(x, y);
  35501. stackClean = true;
  35502. break;
  35503. case 23:
  35504. // vstemhm
  35505. stems += stack.length >> 1;
  35506. stackClean = true;
  35507. break;
  35508. case 24:
  35509. // rcurveline
  35510. while (stack.length > 2) {
  35511. xa = x + stack.shift();
  35512. ya = y + stack.shift();
  35513. xb = xa + stack.shift();
  35514. yb = ya + stack.shift();
  35515. x = xb + stack.shift();
  35516. y = yb + stack.shift();
  35517. bezierCurveTo(xa, ya, xb, yb, x, y);
  35518. }
  35519. x += stack.shift();
  35520. y += stack.shift();
  35521. lineTo(x, y);
  35522. break;
  35523. case 25:
  35524. // rlinecurve
  35525. while (stack.length > 6) {
  35526. x += stack.shift();
  35527. y += stack.shift();
  35528. lineTo(x, y);
  35529. }
  35530. xa = x + stack.shift();
  35531. ya = y + stack.shift();
  35532. xb = xa + stack.shift();
  35533. yb = ya + stack.shift();
  35534. x = xb + stack.shift();
  35535. y = yb + stack.shift();
  35536. bezierCurveTo(xa, ya, xb, yb, x, y);
  35537. break;
  35538. case 26:
  35539. // vvcurveto
  35540. if (stack.length % 2) {
  35541. x += stack.shift();
  35542. }
  35543. while (stack.length > 0) {
  35544. xa = x;
  35545. ya = y + stack.shift();
  35546. xb = xa + stack.shift();
  35547. yb = ya + stack.shift();
  35548. x = xb;
  35549. y = yb + stack.shift();
  35550. bezierCurveTo(xa, ya, xb, yb, x, y);
  35551. }
  35552. break;
  35553. case 27:
  35554. // hhcurveto
  35555. if (stack.length % 2) {
  35556. y += stack.shift();
  35557. }
  35558. while (stack.length > 0) {
  35559. xa = x + stack.shift();
  35560. ya = y;
  35561. xb = xa + stack.shift();
  35562. yb = ya + stack.shift();
  35563. x = xb + stack.shift();
  35564. y = yb;
  35565. bezierCurveTo(xa, ya, xb, yb, x, y);
  35566. }
  35567. break;
  35568. case 28:
  35569. stack.push((code[i] << 24 | code[i + 1] << 16) >> 16);
  35570. i += 2;
  35571. break;
  35572. case 29:
  35573. // callgsubr
  35574. n = stack.pop() + font.gsubrsBias;
  35575. subrCode = font.gsubrs[n];
  35576. if (subrCode) {
  35577. parse(subrCode);
  35578. }
  35579. break;
  35580. case 30:
  35581. // vhcurveto
  35582. while (stack.length > 0) {
  35583. xa = x;
  35584. ya = y + stack.shift();
  35585. xb = xa + stack.shift();
  35586. yb = ya + stack.shift();
  35587. x = xb + stack.shift();
  35588. y = yb + (stack.length === 1 ? stack.shift() : 0);
  35589. bezierCurveTo(xa, ya, xb, yb, x, y);
  35590. if (stack.length === 0) {
  35591. break;
  35592. }
  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. }
  35601. break;
  35602. case 31:
  35603. // hvcurveto
  35604. while (stack.length > 0) {
  35605. xa = x + stack.shift();
  35606. ya = y;
  35607. xb = xa + stack.shift();
  35608. yb = ya + stack.shift();
  35609. y = yb + stack.shift();
  35610. x = xb + (stack.length === 1 ? stack.shift() : 0);
  35611. bezierCurveTo(xa, ya, xb, yb, x, y);
  35612. if (stack.length === 0) {
  35613. break;
  35614. }
  35615. xa = x;
  35616. ya = y + stack.shift();
  35617. xb = xa + stack.shift();
  35618. yb = ya + stack.shift();
  35619. x = xb + stack.shift();
  35620. y = yb + (stack.length === 1 ? stack.shift() : 0);
  35621. bezierCurveTo(xa, ya, xb, yb, x, y);
  35622. }
  35623. break;
  35624. default:
  35625. if (v < 32) {
  35626. error('unknown operator: ' + v);
  35627. }
  35628. if (v < 247) {
  35629. stack.push(v - 139);
  35630. } else if (v < 251) {
  35631. stack.push((v - 247) * 256 + code[i++] + 108);
  35632. } else if (v < 255) {
  35633. stack.push(-(v - 251) * 256 - code[i++] - 108);
  35634. } else {
  35635. stack.push((code[i] << 24 | code[i + 1] << 16 | code[i + 2] << 8 | code[i + 3]) / 65536);
  35636. i += 4;
  35637. }
  35638. break;
  35639. }
  35640. if (stackClean) {
  35641. stack.length = 0;
  35642. }
  35643. }
  35644. }
  35645. parse(code);
  35646. }
  35647. var noop = '';
  35648. function CompiledFont(fontMatrix) {
  35649. this.compiledGlyphs = Object.create(null);
  35650. this.compiledCharCodeToGlyphId = Object.create(null);
  35651. this.fontMatrix = fontMatrix;
  35652. }
  35653. CompiledFont.prototype = {
  35654. getPathJs: function (unicode) {
  35655. var cmap = lookupCmap(this.cmap, unicode);
  35656. var fn = this.compiledGlyphs[cmap.glyphId];
  35657. if (!fn) {
  35658. fn = this.compileGlyph(this.glyphs[cmap.glyphId]);
  35659. this.compiledGlyphs[cmap.glyphId] = fn;
  35660. }
  35661. if (this.compiledCharCodeToGlyphId[cmap.charCode] === undefined) {
  35662. this.compiledCharCodeToGlyphId[cmap.charCode] = cmap.glyphId;
  35663. }
  35664. return fn;
  35665. },
  35666. compileGlyph: function (code) {
  35667. if (!code || code.length === 0 || code[0] === 14) {
  35668. return noop;
  35669. }
  35670. var cmds = [];
  35671. cmds.push({ cmd: 'save' });
  35672. cmds.push({
  35673. cmd: 'transform',
  35674. args: this.fontMatrix.slice()
  35675. });
  35676. cmds.push({
  35677. cmd: 'scale',
  35678. args: [
  35679. 'size',
  35680. '-size'
  35681. ]
  35682. });
  35683. this.compileGlyphImpl(code, cmds);
  35684. cmds.push({ cmd: 'restore' });
  35685. return cmds;
  35686. },
  35687. compileGlyphImpl: function () {
  35688. error('Children classes should implement this.');
  35689. },
  35690. hasBuiltPath: function (unicode) {
  35691. var cmap = lookupCmap(this.cmap, unicode);
  35692. return this.compiledGlyphs[cmap.glyphId] !== undefined && this.compiledCharCodeToGlyphId[cmap.charCode] !== undefined;
  35693. }
  35694. };
  35695. function TrueTypeCompiled(glyphs, cmap, fontMatrix) {
  35696. fontMatrix = fontMatrix || [
  35697. 0.000488,
  35698. 0,
  35699. 0,
  35700. 0.000488,
  35701. 0,
  35702. 0
  35703. ];
  35704. CompiledFont.call(this, fontMatrix);
  35705. this.glyphs = glyphs;
  35706. this.cmap = cmap;
  35707. }
  35708. Util.inherit(TrueTypeCompiled, CompiledFont, {
  35709. compileGlyphImpl: function (code, cmds) {
  35710. compileGlyf(code, cmds, this);
  35711. }
  35712. });
  35713. function Type2Compiled(cffInfo, cmap, fontMatrix, glyphNameMap) {
  35714. fontMatrix = fontMatrix || [
  35715. 0.001,
  35716. 0,
  35717. 0,
  35718. 0.001,
  35719. 0,
  35720. 0
  35721. ];
  35722. CompiledFont.call(this, fontMatrix);
  35723. this.glyphs = cffInfo.glyphs;
  35724. this.gsubrs = cffInfo.gsubrs || [];
  35725. this.subrs = cffInfo.subrs || [];
  35726. this.cmap = cmap;
  35727. this.glyphNameMap = glyphNameMap || getGlyphsUnicode();
  35728. this.gsubrsBias = this.gsubrs.length < 1240 ? 107 : this.gsubrs.length < 33900 ? 1131 : 32768;
  35729. this.subrsBias = this.subrs.length < 1240 ? 107 : this.subrs.length < 33900 ? 1131 : 32768;
  35730. }
  35731. Util.inherit(Type2Compiled, CompiledFont, {
  35732. compileGlyphImpl: function (code, cmds) {
  35733. compileCharString(code, cmds, this);
  35734. }
  35735. });
  35736. return {
  35737. create: function FontRendererFactory_create(font, seacAnalysisEnabled) {
  35738. var data = new Uint8Array(font.data);
  35739. var cmap, glyf, loca, cff, indexToLocFormat, unitsPerEm;
  35740. var numTables = getUshort(data, 4);
  35741. for (var i = 0, p = 12; i < numTables; i++, p += 16) {
  35742. var tag = bytesToString(data.subarray(p, p + 4));
  35743. var offset = getLong(data, p + 8);
  35744. var length = getLong(data, p + 12);
  35745. switch (tag) {
  35746. case 'cmap':
  35747. cmap = parseCmap(data, offset, offset + length);
  35748. break;
  35749. case 'glyf':
  35750. glyf = data.subarray(offset, offset + length);
  35751. break;
  35752. case 'loca':
  35753. loca = data.subarray(offset, offset + length);
  35754. break;
  35755. case 'head':
  35756. unitsPerEm = getUshort(data, offset + 18);
  35757. indexToLocFormat = getUshort(data, offset + 50);
  35758. break;
  35759. case 'CFF ':
  35760. cff = parseCff(data, offset, offset + length, seacAnalysisEnabled);
  35761. break;
  35762. }
  35763. }
  35764. if (glyf) {
  35765. var fontMatrix = !unitsPerEm ? font.fontMatrix : [
  35766. 1 / unitsPerEm,
  35767. 0,
  35768. 0,
  35769. 1 / unitsPerEm,
  35770. 0,
  35771. 0
  35772. ];
  35773. return new TrueTypeCompiled(parseGlyfTable(glyf, loca, indexToLocFormat), cmap, fontMatrix);
  35774. } else {
  35775. return new Type2Compiled(cff, cmap, font.fontMatrix, font.glyphNameMap);
  35776. }
  35777. }
  35778. };
  35779. }();
  35780. exports.FontRendererFactory = FontRendererFactory;
  35781. }));
  35782. (function (root, factory) {
  35783. factory(root.pdfjsCoreParser = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCoreStream);
  35784. }(this, function (exports, sharedUtil, corePrimitives, coreStream) {
  35785. var MissingDataException = sharedUtil.MissingDataException;
  35786. var StreamType = sharedUtil.StreamType;
  35787. var assert = sharedUtil.assert;
  35788. var error = sharedUtil.error;
  35789. var info = sharedUtil.info;
  35790. var isArray = sharedUtil.isArray;
  35791. var isInt = sharedUtil.isInt;
  35792. var isNum = sharedUtil.isNum;
  35793. var isString = sharedUtil.isString;
  35794. var warn = sharedUtil.warn;
  35795. var Cmd = corePrimitives.Cmd;
  35796. var Dict = corePrimitives.Dict;
  35797. var Name = corePrimitives.Name;
  35798. var Ref = corePrimitives.Ref;
  35799. var isCmd = corePrimitives.isCmd;
  35800. var isDict = corePrimitives.isDict;
  35801. var isName = corePrimitives.isName;
  35802. var Ascii85Stream = coreStream.Ascii85Stream;
  35803. var AsciiHexStream = coreStream.AsciiHexStream;
  35804. var CCITTFaxStream = coreStream.CCITTFaxStream;
  35805. var FlateStream = coreStream.FlateStream;
  35806. var Jbig2Stream = coreStream.Jbig2Stream;
  35807. var JpegStream = coreStream.JpegStream;
  35808. var JpxStream = coreStream.JpxStream;
  35809. var LZWStream = coreStream.LZWStream;
  35810. var NullStream = coreStream.NullStream;
  35811. var PredictorStream = coreStream.PredictorStream;
  35812. var RunLengthStream = coreStream.RunLengthStream;
  35813. var EOF = {};
  35814. function isEOF(v) {
  35815. return v === EOF;
  35816. }
  35817. var MAX_LENGTH_TO_CACHE = 1000;
  35818. var Parser = function ParserClosure() {
  35819. function Parser(lexer, allowStreams, xref, recoveryMode) {
  35820. this.lexer = lexer;
  35821. this.allowStreams = allowStreams;
  35822. this.xref = xref;
  35823. this.recoveryMode = recoveryMode || false;
  35824. this.imageCache = Object.create(null);
  35825. this.refill();
  35826. }
  35827. Parser.prototype = {
  35828. refill: function Parser_refill() {
  35829. this.buf1 = this.lexer.getObj();
  35830. this.buf2 = this.lexer.getObj();
  35831. },
  35832. shift: function Parser_shift() {
  35833. if (isCmd(this.buf2, 'ID')) {
  35834. this.buf1 = this.buf2;
  35835. this.buf2 = null;
  35836. } else {
  35837. this.buf1 = this.buf2;
  35838. this.buf2 = this.lexer.getObj();
  35839. }
  35840. },
  35841. tryShift: function Parser_tryShift() {
  35842. try {
  35843. this.shift();
  35844. return true;
  35845. } catch (e) {
  35846. if (e instanceof MissingDataException) {
  35847. throw e;
  35848. }
  35849. // Upon failure, the caller should reset this.lexer.pos to a known good
  35850. // state and call this.shift() twice to reset the buffers.
  35851. return false;
  35852. }
  35853. },
  35854. getObj: function Parser_getObj(cipherTransform) {
  35855. var buf1 = this.buf1;
  35856. this.shift();
  35857. if (buf1 instanceof Cmd) {
  35858. switch (buf1.cmd) {
  35859. case 'BI':
  35860. // inline image
  35861. return this.makeInlineImage(cipherTransform);
  35862. case '[':
  35863. // array
  35864. var array = [];
  35865. while (!isCmd(this.buf1, ']') && !isEOF(this.buf1)) {
  35866. array.push(this.getObj(cipherTransform));
  35867. }
  35868. if (isEOF(this.buf1)) {
  35869. if (!this.recoveryMode) {
  35870. error('End of file inside array');
  35871. }
  35872. return array;
  35873. }
  35874. this.shift();
  35875. return array;
  35876. case '<<':
  35877. // dictionary or stream
  35878. var dict = new Dict(this.xref);
  35879. while (!isCmd(this.buf1, '>>') && !isEOF(this.buf1)) {
  35880. if (!isName(this.buf1)) {
  35881. info('Malformed dictionary: key must be a name object');
  35882. this.shift();
  35883. continue;
  35884. }
  35885. var key = this.buf1.name;
  35886. this.shift();
  35887. if (isEOF(this.buf1)) {
  35888. break;
  35889. }
  35890. dict.set(key, this.getObj(cipherTransform));
  35891. }
  35892. if (isEOF(this.buf1)) {
  35893. if (!this.recoveryMode) {
  35894. error('End of file inside dictionary');
  35895. }
  35896. return dict;
  35897. }
  35898. // Stream objects are not allowed inside content streams or
  35899. // object streams.
  35900. if (isCmd(this.buf2, 'stream')) {
  35901. return this.allowStreams ? this.makeStream(dict, cipherTransform) : dict;
  35902. }
  35903. this.shift();
  35904. return dict;
  35905. default:
  35906. // simple object
  35907. return buf1;
  35908. }
  35909. }
  35910. if (isInt(buf1)) {
  35911. // indirect reference or integer
  35912. var num = buf1;
  35913. if (isInt(this.buf1) && isCmd(this.buf2, 'R')) {
  35914. var ref = new Ref(num, this.buf1);
  35915. this.shift();
  35916. this.shift();
  35917. return ref;
  35918. }
  35919. return num;
  35920. }
  35921. if (isString(buf1)) {
  35922. // string
  35923. var str = buf1;
  35924. if (cipherTransform) {
  35925. str = cipherTransform.decryptString(str);
  35926. }
  35927. return str;
  35928. }
  35929. // simple object
  35930. return buf1;
  35931. },
  35932. /**
  35933. * Find the end of the stream by searching for the /EI\s/.
  35934. * @returns {number} The inline stream length.
  35935. */
  35936. findDefaultInlineStreamEnd: function Parser_findDefaultInlineStreamEnd(stream) {
  35937. var E = 0x45, I = 0x49, SPACE = 0x20, LF = 0xA, CR = 0xD;
  35938. var startPos = stream.pos, state = 0, ch, i, n, followingBytes;
  35939. while ((ch = stream.getByte()) !== -1) {
  35940. if (state === 0) {
  35941. state = ch === E ? 1 : 0;
  35942. } else if (state === 1) {
  35943. state = ch === I ? 2 : 0;
  35944. } else {
  35945. assert(state === 2);
  35946. if (ch === SPACE || ch === LF || ch === CR) {
  35947. // Let's check the next five bytes are ASCII... just be sure.
  35948. n = 5;
  35949. followingBytes = stream.peekBytes(n);
  35950. for (i = 0; i < n; i++) {
  35951. ch = followingBytes[i];
  35952. if (ch !== LF && ch !== CR && (ch < SPACE || ch > 0x7F)) {
  35953. // Not a LF, CR, SPACE or any visible ASCII character, i.e.
  35954. // it's binary stuff. Resetting the state.
  35955. state = 0;
  35956. break;
  35957. }
  35958. }
  35959. if (state === 2) {
  35960. break;
  35961. }
  35962. } else
  35963. // Finished!
  35964. {
  35965. state = 0;
  35966. }
  35967. }
  35968. }
  35969. return stream.pos - 4 - startPos;
  35970. },
  35971. /**
  35972. * Find the EOI (end-of-image) marker 0xFFD9 of the stream.
  35973. * @returns {number} The inline stream length.
  35974. */
  35975. findDCTDecodeInlineStreamEnd: function Parser_findDCTDecodeInlineStreamEnd(stream) {
  35976. var startPos = stream.pos, foundEOI = false, b, markerLength, length;
  35977. while ((b = stream.getByte()) !== -1) {
  35978. if (b !== 0xFF) {
  35979. // Not a valid marker.
  35980. continue;
  35981. }
  35982. switch (stream.getByte()) {
  35983. case 0x00:
  35984. // Byte stuffing.
  35985. // 0xFF00 appears to be a very common byte sequence in JPEG images.
  35986. break;
  35987. case 0xFF:
  35988. // Fill byte.
  35989. // Avoid skipping a valid marker, resetting the stream position.
  35990. stream.skip(-1);
  35991. break;
  35992. case 0xD9:
  35993. // EOI
  35994. foundEOI = true;
  35995. break;
  35996. case 0xC0:
  35997. // SOF0
  35998. case 0xC1:
  35999. // SOF1
  36000. case 0xC2:
  36001. // SOF2
  36002. case 0xC3:
  36003. // SOF3
  36004. case 0xC5:
  36005. // SOF5
  36006. case 0xC6:
  36007. // SOF6
  36008. case 0xC7:
  36009. // SOF7
  36010. case 0xC9:
  36011. // SOF9
  36012. case 0xCA:
  36013. // SOF10
  36014. case 0xCB:
  36015. // SOF11
  36016. case 0xCD:
  36017. // SOF13
  36018. case 0xCE:
  36019. // SOF14
  36020. case 0xCF:
  36021. // SOF15
  36022. case 0xC4:
  36023. // DHT
  36024. case 0xCC:
  36025. // DAC
  36026. case 0xDA:
  36027. // SOS
  36028. case 0xDB:
  36029. // DQT
  36030. case 0xDC:
  36031. // DNL
  36032. case 0xDD:
  36033. // DRI
  36034. case 0xDE:
  36035. // DHP
  36036. case 0xDF:
  36037. // EXP
  36038. case 0xE0:
  36039. // APP0
  36040. case 0xE1:
  36041. // APP1
  36042. case 0xE2:
  36043. // APP2
  36044. case 0xE3:
  36045. // APP3
  36046. case 0xE4:
  36047. // APP4
  36048. case 0xE5:
  36049. // APP5
  36050. case 0xE6:
  36051. // APP6
  36052. case 0xE7:
  36053. // APP7
  36054. case 0xE8:
  36055. // APP8
  36056. case 0xE9:
  36057. // APP9
  36058. case 0xEA:
  36059. // APP10
  36060. case 0xEB:
  36061. // APP11
  36062. case 0xEC:
  36063. // APP12
  36064. case 0xED:
  36065. // APP13
  36066. case 0xEE:
  36067. // APP14
  36068. case 0xEF:
  36069. // APP15
  36070. case 0xFE:
  36071. // COM
  36072. // The marker should be followed by the length of the segment.
  36073. markerLength = stream.getUint16();
  36074. if (markerLength > 2) {
  36075. // |markerLength| contains the byte length of the marker segment,
  36076. // including its own length (2 bytes) and excluding the marker.
  36077. stream.skip(markerLength - 2);
  36078. } else
  36079. // Jump to the next marker.
  36080. {
  36081. // The marker length is invalid, resetting the stream position.
  36082. stream.skip(-2);
  36083. }
  36084. break;
  36085. }
  36086. if (foundEOI) {
  36087. break;
  36088. }
  36089. }
  36090. length = stream.pos - startPos;
  36091. if (b === -1) {
  36092. warn('Inline DCTDecode image stream: ' + 'EOI marker not found, searching for /EI/ instead.');
  36093. stream.skip(-length);
  36094. // Reset the stream position.
  36095. return this.findDefaultInlineStreamEnd(stream);
  36096. }
  36097. this.inlineStreamSkipEI(stream);
  36098. return length;
  36099. },
  36100. /**
  36101. * Find the EOD (end-of-data) marker '~>' (i.e. TILDE + GT) of the stream.
  36102. * @returns {number} The inline stream length.
  36103. */
  36104. findASCII85DecodeInlineStreamEnd: function Parser_findASCII85DecodeInlineStreamEnd(stream) {
  36105. var TILDE = 0x7E, GT = 0x3E;
  36106. var startPos = stream.pos, ch, length;
  36107. while ((ch = stream.getByte()) !== -1) {
  36108. if (ch === TILDE && stream.peekByte() === GT) {
  36109. stream.skip();
  36110. break;
  36111. }
  36112. }
  36113. length = stream.pos - startPos;
  36114. if (ch === -1) {
  36115. warn('Inline ASCII85Decode image stream: ' + 'EOD marker not found, searching for /EI/ instead.');
  36116. stream.skip(-length);
  36117. // Reset the stream position.
  36118. return this.findDefaultInlineStreamEnd(stream);
  36119. }
  36120. this.inlineStreamSkipEI(stream);
  36121. return length;
  36122. },
  36123. /**
  36124. * Find the EOD (end-of-data) marker '>' (i.e. GT) of the stream.
  36125. * @returns {number} The inline stream length.
  36126. */
  36127. findASCIIHexDecodeInlineStreamEnd: function Parser_findASCIIHexDecodeInlineStreamEnd(stream) {
  36128. var GT = 0x3E;
  36129. var startPos = stream.pos, ch, length;
  36130. while ((ch = stream.getByte()) !== -1) {
  36131. if (ch === GT) {
  36132. break;
  36133. }
  36134. }
  36135. length = stream.pos - startPos;
  36136. if (ch === -1) {
  36137. warn('Inline ASCIIHexDecode image stream: ' + 'EOD marker not found, searching for /EI/ instead.');
  36138. stream.skip(-length);
  36139. // Reset the stream position.
  36140. return this.findDefaultInlineStreamEnd(stream);
  36141. }
  36142. this.inlineStreamSkipEI(stream);
  36143. return length;
  36144. },
  36145. /**
  36146. * Skip over the /EI/ for streams where we search for an EOD marker.
  36147. */
  36148. inlineStreamSkipEI: function Parser_inlineStreamSkipEI(stream) {
  36149. var E = 0x45, I = 0x49;
  36150. var state = 0, ch;
  36151. while ((ch = stream.getByte()) !== -1) {
  36152. if (state === 0) {
  36153. state = ch === E ? 1 : 0;
  36154. } else if (state === 1) {
  36155. state = ch === I ? 2 : 0;
  36156. } else if (state === 2) {
  36157. break;
  36158. }
  36159. }
  36160. },
  36161. makeInlineImage: function Parser_makeInlineImage(cipherTransform) {
  36162. var lexer = this.lexer;
  36163. var stream = lexer.stream;
  36164. // Parse dictionary.
  36165. var dict = new Dict(this.xref);
  36166. while (!isCmd(this.buf1, 'ID') && !isEOF(this.buf1)) {
  36167. if (!isName(this.buf1)) {
  36168. error('Dictionary key must be a name object');
  36169. }
  36170. var key = this.buf1.name;
  36171. this.shift();
  36172. if (isEOF(this.buf1)) {
  36173. break;
  36174. }
  36175. dict.set(key, this.getObj(cipherTransform));
  36176. }
  36177. // Extract the name of the first (i.e. the current) image filter.
  36178. var filter = dict.get('Filter', 'F'), filterName;
  36179. if (isName(filter)) {
  36180. filterName = filter.name;
  36181. } else if (isArray(filter) && isName(filter[0])) {
  36182. filterName = filter[0].name;
  36183. }
  36184. // Parse image stream.
  36185. var startPos = stream.pos, length, i, ii;
  36186. if (filterName === 'DCTDecode' || filterName === 'DCT') {
  36187. length = this.findDCTDecodeInlineStreamEnd(stream);
  36188. } else if (filterName === 'ASCII85Decide' || filterName === 'A85') {
  36189. length = this.findASCII85DecodeInlineStreamEnd(stream);
  36190. } else if (filterName === 'ASCIIHexDecode' || filterName === 'AHx') {
  36191. length = this.findASCIIHexDecodeInlineStreamEnd(stream);
  36192. } else {
  36193. length = this.findDefaultInlineStreamEnd(stream);
  36194. }
  36195. var imageStream = stream.makeSubStream(startPos, length, dict);
  36196. // Cache all images below the MAX_LENGTH_TO_CACHE threshold by their
  36197. // adler32 checksum.
  36198. var adler32;
  36199. if (length < MAX_LENGTH_TO_CACHE) {
  36200. var imageBytes = imageStream.getBytes();
  36201. imageStream.reset();
  36202. var a = 1;
  36203. var b = 0;
  36204. for (i = 0, ii = imageBytes.length; i < ii; ++i) {
  36205. // No modulo required in the loop if imageBytes.length < 5552.
  36206. a += imageBytes[i] & 0xff;
  36207. b += a;
  36208. }
  36209. adler32 = b % 65521 << 16 | a % 65521;
  36210. if (this.imageCache.adler32 === adler32) {
  36211. this.buf2 = Cmd.get('EI');
  36212. this.shift();
  36213. this.imageCache[adler32].reset();
  36214. return this.imageCache[adler32];
  36215. }
  36216. }
  36217. if (cipherTransform) {
  36218. imageStream = cipherTransform.createStream(imageStream, length);
  36219. }
  36220. imageStream = this.filter(imageStream, dict, length);
  36221. imageStream.dict = dict;
  36222. if (adler32 !== undefined) {
  36223. imageStream.cacheKey = 'inline_' + length + '_' + adler32;
  36224. this.imageCache[adler32] = imageStream;
  36225. }
  36226. this.buf2 = Cmd.get('EI');
  36227. this.shift();
  36228. return imageStream;
  36229. },
  36230. makeStream: function Parser_makeStream(dict, cipherTransform) {
  36231. var lexer = this.lexer;
  36232. var stream = lexer.stream;
  36233. // get stream start position
  36234. lexer.skipToNextLine();
  36235. var pos = stream.pos - 1;
  36236. // get length
  36237. var length = dict.get('Length');
  36238. if (!isInt(length)) {
  36239. info('Bad ' + length + ' attribute in stream');
  36240. length = 0;
  36241. }
  36242. // skip over the stream data
  36243. stream.pos = pos + length;
  36244. lexer.nextChar();
  36245. // Shift '>>' and check whether the new object marks the end of the stream
  36246. if (this.tryShift() && isCmd(this.buf2, 'endstream')) {
  36247. this.shift();
  36248. } else
  36249. // 'stream'
  36250. {
  36251. // bad stream length, scanning for endstream
  36252. stream.pos = pos;
  36253. var SCAN_BLOCK_SIZE = 2048;
  36254. var ENDSTREAM_SIGNATURE_LENGTH = 9;
  36255. var ENDSTREAM_SIGNATURE = [
  36256. 0x65,
  36257. 0x6E,
  36258. 0x64,
  36259. 0x73,
  36260. 0x74,
  36261. 0x72,
  36262. 0x65,
  36263. 0x61,
  36264. 0x6D
  36265. ];
  36266. var skipped = 0, found = false, i, j;
  36267. while (stream.pos < stream.end) {
  36268. var scanBytes = stream.peekBytes(SCAN_BLOCK_SIZE);
  36269. var scanLength = scanBytes.length - ENDSTREAM_SIGNATURE_LENGTH;
  36270. if (scanLength <= 0) {
  36271. break;
  36272. }
  36273. found = false;
  36274. i = 0;
  36275. while (i < scanLength) {
  36276. j = 0;
  36277. while (j < ENDSTREAM_SIGNATURE_LENGTH && scanBytes[i + j] === ENDSTREAM_SIGNATURE[j]) {
  36278. j++;
  36279. }
  36280. if (j >= ENDSTREAM_SIGNATURE_LENGTH) {
  36281. found = true;
  36282. break;
  36283. }
  36284. i++;
  36285. }
  36286. if (found) {
  36287. skipped += i;
  36288. stream.pos += i;
  36289. break;
  36290. }
  36291. skipped += scanLength;
  36292. stream.pos += scanLength;
  36293. }
  36294. if (!found) {
  36295. error('Missing endstream');
  36296. }
  36297. length = skipped;
  36298. lexer.nextChar();
  36299. this.shift();
  36300. this.shift();
  36301. }
  36302. this.shift();
  36303. // 'endstream'
  36304. stream = stream.makeSubStream(pos, length, dict);
  36305. if (cipherTransform) {
  36306. stream = cipherTransform.createStream(stream, length);
  36307. }
  36308. stream = this.filter(stream, dict, length);
  36309. stream.dict = dict;
  36310. return stream;
  36311. },
  36312. filter: function Parser_filter(stream, dict, length) {
  36313. var filter = dict.get('Filter', 'F');
  36314. var params = dict.get('DecodeParms', 'DP');
  36315. if (isName(filter)) {
  36316. if (isArray(params)) {
  36317. params = params[0];
  36318. }
  36319. return this.makeFilter(stream, filter.name, length, params);
  36320. }
  36321. var maybeLength = length;
  36322. if (isArray(filter)) {
  36323. var filterArray = filter;
  36324. var paramsArray = params;
  36325. for (var i = 0, ii = filterArray.length; i < ii; ++i) {
  36326. filter = filterArray[i];
  36327. if (!isName(filter)) {
  36328. error('Bad filter name: ' + filter);
  36329. }
  36330. params = null;
  36331. if (isArray(paramsArray) && i in paramsArray) {
  36332. params = paramsArray[i];
  36333. }
  36334. stream = this.makeFilter(stream, filter.name, maybeLength, params);
  36335. // after the first stream the length variable is invalid
  36336. maybeLength = null;
  36337. }
  36338. }
  36339. return stream;
  36340. },
  36341. makeFilter: function Parser_makeFilter(stream, name, maybeLength, params) {
  36342. // Since the 'Length' entry in the stream dictionary can be completely
  36343. // wrong, e.g. zero for non-empty streams, only skip parsing the stream
  36344. // when we can be absolutely certain that it actually is empty.
  36345. if (maybeLength === 0) {
  36346. warn('Empty "' + name + '" stream.');
  36347. return new NullStream(stream);
  36348. }
  36349. try {
  36350. if (params && this.xref) {
  36351. params = this.xref.fetchIfRef(params);
  36352. }
  36353. var xrefStreamStats = this.xref.stats.streamTypes;
  36354. if (name === 'FlateDecode' || name === 'Fl') {
  36355. xrefStreamStats[StreamType.FLATE] = true;
  36356. if (params) {
  36357. return new PredictorStream(new FlateStream(stream, maybeLength), maybeLength, params);
  36358. }
  36359. return new FlateStream(stream, maybeLength);
  36360. }
  36361. if (name === 'LZWDecode' || name === 'LZW') {
  36362. xrefStreamStats[StreamType.LZW] = true;
  36363. var earlyChange = 1;
  36364. if (params) {
  36365. if (params.has('EarlyChange')) {
  36366. earlyChange = params.get('EarlyChange');
  36367. }
  36368. return new PredictorStream(new LZWStream(stream, maybeLength, earlyChange), maybeLength, params);
  36369. }
  36370. return new LZWStream(stream, maybeLength, earlyChange);
  36371. }
  36372. if (name === 'DCTDecode' || name === 'DCT') {
  36373. xrefStreamStats[StreamType.DCT] = true;
  36374. return new JpegStream(stream, maybeLength, stream.dict, params);
  36375. }
  36376. if (name === 'JPXDecode' || name === 'JPX') {
  36377. xrefStreamStats[StreamType.JPX] = true;
  36378. return new JpxStream(stream, maybeLength, stream.dict, params);
  36379. }
  36380. if (name === 'ASCII85Decode' || name === 'A85') {
  36381. xrefStreamStats[StreamType.A85] = true;
  36382. return new Ascii85Stream(stream, maybeLength);
  36383. }
  36384. if (name === 'ASCIIHexDecode' || name === 'AHx') {
  36385. xrefStreamStats[StreamType.AHX] = true;
  36386. return new AsciiHexStream(stream, maybeLength);
  36387. }
  36388. if (name === 'CCITTFaxDecode' || name === 'CCF') {
  36389. xrefStreamStats[StreamType.CCF] = true;
  36390. return new CCITTFaxStream(stream, maybeLength, params);
  36391. }
  36392. if (name === 'RunLengthDecode' || name === 'RL') {
  36393. xrefStreamStats[StreamType.RL] = true;
  36394. return new RunLengthStream(stream, maybeLength);
  36395. }
  36396. if (name === 'JBIG2Decode') {
  36397. xrefStreamStats[StreamType.JBIG] = true;
  36398. return new Jbig2Stream(stream, maybeLength, stream.dict, params);
  36399. }
  36400. warn('filter "' + name + '" not supported yet');
  36401. return stream;
  36402. } catch (ex) {
  36403. if (ex instanceof MissingDataException) {
  36404. throw ex;
  36405. }
  36406. warn('Invalid stream: \"' + ex + '\"');
  36407. return new NullStream(stream);
  36408. }
  36409. }
  36410. };
  36411. return Parser;
  36412. }();
  36413. var Lexer = function LexerClosure() {
  36414. function Lexer(stream, knownCommands) {
  36415. this.stream = stream;
  36416. this.nextChar();
  36417. // While lexing, we build up many strings one char at a time. Using += for
  36418. // this can result in lots of garbage strings. It's better to build an
  36419. // array of single-char strings and then join() them together at the end.
  36420. // And reusing a single array (i.e. |this.strBuf|) over and over for this
  36421. // purpose uses less memory than using a new array for each string.
  36422. this.strBuf = [];
  36423. // The PDFs might have "glued" commands with other commands, operands or
  36424. // literals, e.g. "q1". The knownCommands is a dictionary of the valid
  36425. // commands and their prefixes. The prefixes are built the following way:
  36426. // if there a command that is a prefix of the other valid command or
  36427. // literal (e.g. 'f' and 'false') the following prefixes must be included,
  36428. // 'fa', 'fal', 'fals'. The prefixes are not needed, if the command has no
  36429. // other commands or literals as a prefix. The knowCommands is optional.
  36430. this.knownCommands = knownCommands;
  36431. }
  36432. // A '1' in this array means the character is white space. A '1' or
  36433. // '2' means the character ends a name or command.
  36434. var specialChars = [
  36435. 1,
  36436. 0,
  36437. 0,
  36438. 0,
  36439. 0,
  36440. 0,
  36441. 0,
  36442. 0,
  36443. 0,
  36444. 1,
  36445. 1,
  36446. 0,
  36447. 1,
  36448. 1,
  36449. 0,
  36450. 0,
  36451. // 0x
  36452. 0,
  36453. 0,
  36454. 0,
  36455. 0,
  36456. 0,
  36457. 0,
  36458. 0,
  36459. 0,
  36460. 0,
  36461. 0,
  36462. 0,
  36463. 0,
  36464. 0,
  36465. 0,
  36466. 0,
  36467. 0,
  36468. // 1x
  36469. 1,
  36470. 0,
  36471. 0,
  36472. 0,
  36473. 0,
  36474. 2,
  36475. 0,
  36476. 0,
  36477. 2,
  36478. 2,
  36479. 0,
  36480. 0,
  36481. 0,
  36482. 0,
  36483. 0,
  36484. 2,
  36485. // 2x
  36486. 0,
  36487. 0,
  36488. 0,
  36489. 0,
  36490. 0,
  36491. 0,
  36492. 0,
  36493. 0,
  36494. 0,
  36495. 0,
  36496. 0,
  36497. 0,
  36498. 2,
  36499. 0,
  36500. 2,
  36501. 0,
  36502. // 3x
  36503. 0,
  36504. 0,
  36505. 0,
  36506. 0,
  36507. 0,
  36508. 0,
  36509. 0,
  36510. 0,
  36511. 0,
  36512. 0,
  36513. 0,
  36514. 0,
  36515. 0,
  36516. 0,
  36517. 0,
  36518. 0,
  36519. // 4x
  36520. 0,
  36521. 0,
  36522. 0,
  36523. 0,
  36524. 0,
  36525. 0,
  36526. 0,
  36527. 0,
  36528. 0,
  36529. 0,
  36530. 0,
  36531. 2,
  36532. 0,
  36533. 2,
  36534. 0,
  36535. 0,
  36536. // 5x
  36537. 0,
  36538. 0,
  36539. 0,
  36540. 0,
  36541. 0,
  36542. 0,
  36543. 0,
  36544. 0,
  36545. 0,
  36546. 0,
  36547. 0,
  36548. 0,
  36549. 0,
  36550. 0,
  36551. 0,
  36552. 0,
  36553. // 6x
  36554. 0,
  36555. 0,
  36556. 0,
  36557. 0,
  36558. 0,
  36559. 0,
  36560. 0,
  36561. 0,
  36562. 0,
  36563. 0,
  36564. 0,
  36565. 2,
  36566. 0,
  36567. 2,
  36568. 0,
  36569. 0,
  36570. // 7x
  36571. 0,
  36572. 0,
  36573. 0,
  36574. 0,
  36575. 0,
  36576. 0,
  36577. 0,
  36578. 0,
  36579. 0,
  36580. 0,
  36581. 0,
  36582. 0,
  36583. 0,
  36584. 0,
  36585. 0,
  36586. 0,
  36587. // 8x
  36588. 0,
  36589. 0,
  36590. 0,
  36591. 0,
  36592. 0,
  36593. 0,
  36594. 0,
  36595. 0,
  36596. 0,
  36597. 0,
  36598. 0,
  36599. 0,
  36600. 0,
  36601. 0,
  36602. 0,
  36603. 0,
  36604. // 9x
  36605. 0,
  36606. 0,
  36607. 0,
  36608. 0,
  36609. 0,
  36610. 0,
  36611. 0,
  36612. 0,
  36613. 0,
  36614. 0,
  36615. 0,
  36616. 0,
  36617. 0,
  36618. 0,
  36619. 0,
  36620. 0,
  36621. // ax
  36622. 0,
  36623. 0,
  36624. 0,
  36625. 0,
  36626. 0,
  36627. 0,
  36628. 0,
  36629. 0,
  36630. 0,
  36631. 0,
  36632. 0,
  36633. 0,
  36634. 0,
  36635. 0,
  36636. 0,
  36637. 0,
  36638. // bx
  36639. 0,
  36640. 0,
  36641. 0,
  36642. 0,
  36643. 0,
  36644. 0,
  36645. 0,
  36646. 0,
  36647. 0,
  36648. 0,
  36649. 0,
  36650. 0,
  36651. 0,
  36652. 0,
  36653. 0,
  36654. 0,
  36655. // cx
  36656. 0,
  36657. 0,
  36658. 0,
  36659. 0,
  36660. 0,
  36661. 0,
  36662. 0,
  36663. 0,
  36664. 0,
  36665. 0,
  36666. 0,
  36667. 0,
  36668. 0,
  36669. 0,
  36670. 0,
  36671. 0,
  36672. // dx
  36673. 0,
  36674. 0,
  36675. 0,
  36676. 0,
  36677. 0,
  36678. 0,
  36679. 0,
  36680. 0,
  36681. 0,
  36682. 0,
  36683. 0,
  36684. 0,
  36685. 0,
  36686. 0,
  36687. 0,
  36688. 0,
  36689. // ex
  36690. 0,
  36691. 0,
  36692. 0,
  36693. 0,
  36694. 0,
  36695. 0,
  36696. 0,
  36697. 0,
  36698. 0,
  36699. 0,
  36700. 0,
  36701. 0,
  36702. 0,
  36703. 0,
  36704. 0,
  36705. 0
  36706. ];
  36707. // fx
  36708. function toHexDigit(ch) {
  36709. if (ch >= 0x30 && ch <= 0x39) {
  36710. // '0'-'9'
  36711. return ch & 0x0F;
  36712. }
  36713. if (ch >= 0x41 && ch <= 0x46 || ch >= 0x61 && ch <= 0x66) {
  36714. // 'A'-'F', 'a'-'f'
  36715. return (ch & 0x0F) + 9;
  36716. }
  36717. return -1;
  36718. }
  36719. Lexer.prototype = {
  36720. nextChar: function Lexer_nextChar() {
  36721. return this.currentChar = this.stream.getByte();
  36722. },
  36723. peekChar: function Lexer_peekChar() {
  36724. return this.stream.peekByte();
  36725. },
  36726. getNumber: function Lexer_getNumber() {
  36727. var ch = this.currentChar;
  36728. var eNotation = false;
  36729. var divideBy = 0;
  36730. // different from 0 if it's a floating point value
  36731. var sign = 1;
  36732. if (ch === 0x2D) {
  36733. // '-'
  36734. sign = -1;
  36735. ch = this.nextChar();
  36736. if (ch === 0x2D) {
  36737. // '-'
  36738. // Ignore double negative (this is consistent with Adobe Reader).
  36739. ch = this.nextChar();
  36740. }
  36741. } else if (ch === 0x2B) {
  36742. // '+'
  36743. ch = this.nextChar();
  36744. }
  36745. if (ch === 0x2E) {
  36746. // '.'
  36747. divideBy = 10;
  36748. ch = this.nextChar();
  36749. }
  36750. if (ch < 0x30 || ch > 0x39) {
  36751. // '0' - '9'
  36752. error('Invalid number: ' + String.fromCharCode(ch));
  36753. return 0;
  36754. }
  36755. var baseValue = ch - 0x30;
  36756. // '0'
  36757. var powerValue = 0;
  36758. var powerValueSign = 1;
  36759. while ((ch = this.nextChar()) >= 0) {
  36760. if (0x30 <= ch && ch <= 0x39) {
  36761. // '0' - '9'
  36762. var currentDigit = ch - 0x30;
  36763. // '0'
  36764. if (eNotation) {
  36765. // We are after an 'e' or 'E'
  36766. powerValue = powerValue * 10 + currentDigit;
  36767. } else {
  36768. if (divideBy !== 0) {
  36769. // We are after a point
  36770. divideBy *= 10;
  36771. }
  36772. baseValue = baseValue * 10 + currentDigit;
  36773. }
  36774. } else if (ch === 0x2E) {
  36775. // '.'
  36776. if (divideBy === 0) {
  36777. divideBy = 1;
  36778. } else {
  36779. // A number can have only one '.'
  36780. break;
  36781. }
  36782. } else if (ch === 0x2D) {
  36783. // '-'
  36784. // ignore minus signs in the middle of numbers to match
  36785. // Adobe's behavior
  36786. warn('Badly formatted number');
  36787. } else if (ch === 0x45 || ch === 0x65) {
  36788. // 'E', 'e'
  36789. // 'E' can be either a scientific notation or the beginning of a new
  36790. // operator
  36791. ch = this.peekChar();
  36792. if (ch === 0x2B || ch === 0x2D) {
  36793. // '+', '-'
  36794. powerValueSign = ch === 0x2D ? -1 : 1;
  36795. this.nextChar();
  36796. } else // Consume the sign character
  36797. if (ch < 0x30 || ch > 0x39) {
  36798. // '0' - '9'
  36799. // The 'E' must be the beginning of a new operator
  36800. break;
  36801. }
  36802. eNotation = true;
  36803. } else {
  36804. // the last character doesn't belong to us
  36805. break;
  36806. }
  36807. }
  36808. if (divideBy !== 0) {
  36809. baseValue /= divideBy;
  36810. }
  36811. if (eNotation) {
  36812. baseValue *= Math.pow(10, powerValueSign * powerValue);
  36813. }
  36814. return sign * baseValue;
  36815. },
  36816. getString: function Lexer_getString() {
  36817. var numParen = 1;
  36818. var done = false;
  36819. var strBuf = this.strBuf;
  36820. strBuf.length = 0;
  36821. var ch = this.nextChar();
  36822. while (true) {
  36823. var charBuffered = false;
  36824. switch (ch | 0) {
  36825. case -1:
  36826. warn('Unterminated string');
  36827. done = true;
  36828. break;
  36829. case 0x28:
  36830. // '('
  36831. ++numParen;
  36832. strBuf.push('(');
  36833. break;
  36834. case 0x29:
  36835. // ')'
  36836. if (--numParen === 0) {
  36837. this.nextChar();
  36838. // consume strings ')'
  36839. done = true;
  36840. } else {
  36841. strBuf.push(')');
  36842. }
  36843. break;
  36844. case 0x5C:
  36845. // '\\'
  36846. ch = this.nextChar();
  36847. switch (ch) {
  36848. case -1:
  36849. warn('Unterminated string');
  36850. done = true;
  36851. break;
  36852. case 0x6E:
  36853. // 'n'
  36854. strBuf.push('\n');
  36855. break;
  36856. case 0x72:
  36857. // 'r'
  36858. strBuf.push('\r');
  36859. break;
  36860. case 0x74:
  36861. // 't'
  36862. strBuf.push('\t');
  36863. break;
  36864. case 0x62:
  36865. // 'b'
  36866. strBuf.push('\b');
  36867. break;
  36868. case 0x66:
  36869. // 'f'
  36870. strBuf.push('\f');
  36871. break;
  36872. case 0x5C:
  36873. // '\'
  36874. case 0x28:
  36875. // '('
  36876. case 0x29:
  36877. // ')'
  36878. strBuf.push(String.fromCharCode(ch));
  36879. break;
  36880. case 0x30:
  36881. case 0x31:
  36882. case 0x32:
  36883. case 0x33:
  36884. // '0'-'3'
  36885. case 0x34:
  36886. case 0x35:
  36887. case 0x36:
  36888. case 0x37:
  36889. // '4'-'7'
  36890. var x = ch & 0x0F;
  36891. ch = this.nextChar();
  36892. charBuffered = true;
  36893. if (ch >= 0x30 && ch <= 0x37) {
  36894. // '0'-'7'
  36895. x = (x << 3) + (ch & 0x0F);
  36896. ch = this.nextChar();
  36897. if (ch >= 0x30 && ch <= 0x37) {
  36898. // '0'-'7'
  36899. charBuffered = false;
  36900. x = (x << 3) + (ch & 0x0F);
  36901. }
  36902. }
  36903. strBuf.push(String.fromCharCode(x));
  36904. break;
  36905. case 0x0D:
  36906. // CR
  36907. if (this.peekChar() === 0x0A) {
  36908. // LF
  36909. this.nextChar();
  36910. }
  36911. break;
  36912. case 0x0A:
  36913. // LF
  36914. break;
  36915. default:
  36916. strBuf.push(String.fromCharCode(ch));
  36917. break;
  36918. }
  36919. break;
  36920. default:
  36921. strBuf.push(String.fromCharCode(ch));
  36922. break;
  36923. }
  36924. if (done) {
  36925. break;
  36926. }
  36927. if (!charBuffered) {
  36928. ch = this.nextChar();
  36929. }
  36930. }
  36931. return strBuf.join('');
  36932. },
  36933. getName: function Lexer_getName() {
  36934. var ch, previousCh;
  36935. var strBuf = this.strBuf;
  36936. strBuf.length = 0;
  36937. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  36938. if (ch === 0x23) {
  36939. // '#'
  36940. ch = this.nextChar();
  36941. if (specialChars[ch]) {
  36942. warn('Lexer_getName: ' + 'NUMBER SIGN (#) should be followed by a hexadecimal number.');
  36943. strBuf.push('#');
  36944. break;
  36945. }
  36946. var x = toHexDigit(ch);
  36947. if (x !== -1) {
  36948. previousCh = ch;
  36949. ch = this.nextChar();
  36950. var x2 = toHexDigit(ch);
  36951. if (x2 === -1) {
  36952. warn('Lexer_getName: Illegal digit (' + String.fromCharCode(ch) + ') in hexadecimal number.');
  36953. strBuf.push('#', String.fromCharCode(previousCh));
  36954. if (specialChars[ch]) {
  36955. break;
  36956. }
  36957. strBuf.push(String.fromCharCode(ch));
  36958. continue;
  36959. }
  36960. strBuf.push(String.fromCharCode(x << 4 | x2));
  36961. } else {
  36962. strBuf.push('#', String.fromCharCode(ch));
  36963. }
  36964. } else {
  36965. strBuf.push(String.fromCharCode(ch));
  36966. }
  36967. }
  36968. if (strBuf.length > 127) {
  36969. warn('name token is longer than allowed by the spec: ' + strBuf.length);
  36970. }
  36971. return Name.get(strBuf.join(''));
  36972. },
  36973. getHexString: function Lexer_getHexString() {
  36974. var strBuf = this.strBuf;
  36975. strBuf.length = 0;
  36976. var ch = this.currentChar;
  36977. var isFirstHex = true;
  36978. var firstDigit;
  36979. var secondDigit;
  36980. while (true) {
  36981. if (ch < 0) {
  36982. warn('Unterminated hex string');
  36983. break;
  36984. } else if (ch === 0x3E) {
  36985. // '>'
  36986. this.nextChar();
  36987. break;
  36988. } else if (specialChars[ch] === 1) {
  36989. ch = this.nextChar();
  36990. continue;
  36991. } else {
  36992. if (isFirstHex) {
  36993. firstDigit = toHexDigit(ch);
  36994. if (firstDigit === -1) {
  36995. warn('Ignoring invalid character "' + ch + '" in hex string');
  36996. ch = this.nextChar();
  36997. continue;
  36998. }
  36999. } else {
  37000. secondDigit = toHexDigit(ch);
  37001. if (secondDigit === -1) {
  37002. warn('Ignoring invalid character "' + ch + '" in hex string');
  37003. ch = this.nextChar();
  37004. continue;
  37005. }
  37006. strBuf.push(String.fromCharCode(firstDigit << 4 | secondDigit));
  37007. }
  37008. isFirstHex = !isFirstHex;
  37009. ch = this.nextChar();
  37010. }
  37011. }
  37012. return strBuf.join('');
  37013. },
  37014. getObj: function Lexer_getObj() {
  37015. // skip whitespace and comments
  37016. var comment = false;
  37017. var ch = this.currentChar;
  37018. while (true) {
  37019. if (ch < 0) {
  37020. return EOF;
  37021. }
  37022. if (comment) {
  37023. if (ch === 0x0A || ch === 0x0D) {
  37024. // LF, CR
  37025. comment = false;
  37026. }
  37027. } else if (ch === 0x25) {
  37028. // '%'
  37029. comment = true;
  37030. } else if (specialChars[ch] !== 1) {
  37031. break;
  37032. }
  37033. ch = this.nextChar();
  37034. }
  37035. // start reading token
  37036. switch (ch | 0) {
  37037. case 0x30:
  37038. case 0x31:
  37039. case 0x32:
  37040. case 0x33:
  37041. case 0x34:
  37042. // '0'-'4'
  37043. case 0x35:
  37044. case 0x36:
  37045. case 0x37:
  37046. case 0x38:
  37047. case 0x39:
  37048. // '5'-'9'
  37049. case 0x2B:
  37050. case 0x2D:
  37051. case 0x2E:
  37052. // '+', '-', '.'
  37053. return this.getNumber();
  37054. case 0x28:
  37055. // '('
  37056. return this.getString();
  37057. case 0x2F:
  37058. // '/'
  37059. return this.getName();
  37060. // array punctuation
  37061. case 0x5B:
  37062. // '['
  37063. this.nextChar();
  37064. return Cmd.get('[');
  37065. case 0x5D:
  37066. // ']'
  37067. this.nextChar();
  37068. return Cmd.get(']');
  37069. // hex string or dict punctuation
  37070. case 0x3C:
  37071. // '<'
  37072. ch = this.nextChar();
  37073. if (ch === 0x3C) {
  37074. // dict punctuation
  37075. this.nextChar();
  37076. return Cmd.get('<<');
  37077. }
  37078. return this.getHexString();
  37079. // dict punctuation
  37080. case 0x3E:
  37081. // '>'
  37082. ch = this.nextChar();
  37083. if (ch === 0x3E) {
  37084. this.nextChar();
  37085. return Cmd.get('>>');
  37086. }
  37087. return Cmd.get('>');
  37088. case 0x7B:
  37089. // '{'
  37090. this.nextChar();
  37091. return Cmd.get('{');
  37092. case 0x7D:
  37093. // '}'
  37094. this.nextChar();
  37095. return Cmd.get('}');
  37096. case 0x29:
  37097. // ')'
  37098. error('Illegal character: ' + ch);
  37099. break;
  37100. }
  37101. // command
  37102. var str = String.fromCharCode(ch);
  37103. var knownCommands = this.knownCommands;
  37104. var knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  37105. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  37106. // stop if known command is found and next character does not make
  37107. // the str a command
  37108. var possibleCommand = str + String.fromCharCode(ch);
  37109. if (knownCommandFound && knownCommands[possibleCommand] === undefined) {
  37110. break;
  37111. }
  37112. if (str.length === 128) {
  37113. error('Command token too long: ' + str.length);
  37114. }
  37115. str = possibleCommand;
  37116. knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  37117. }
  37118. if (str === 'true') {
  37119. return true;
  37120. }
  37121. if (str === 'false') {
  37122. return false;
  37123. }
  37124. if (str === 'null') {
  37125. return null;
  37126. }
  37127. return Cmd.get(str);
  37128. },
  37129. skipToNextLine: function Lexer_skipToNextLine() {
  37130. var ch = this.currentChar;
  37131. while (ch >= 0) {
  37132. if (ch === 0x0D) {
  37133. // CR
  37134. ch = this.nextChar();
  37135. if (ch === 0x0A) {
  37136. // LF
  37137. this.nextChar();
  37138. }
  37139. break;
  37140. } else if (ch === 0x0A) {
  37141. // LF
  37142. this.nextChar();
  37143. break;
  37144. }
  37145. ch = this.nextChar();
  37146. }
  37147. }
  37148. };
  37149. return Lexer;
  37150. }();
  37151. var Linearization = {
  37152. create: function LinearizationCreate(stream) {
  37153. function getInt(name, allowZeroValue) {
  37154. var obj = linDict.get(name);
  37155. if (isInt(obj) && (allowZeroValue ? obj >= 0 : obj > 0)) {
  37156. return obj;
  37157. }
  37158. throw new Error('The "' + name + '" parameter in the linearization ' + 'dictionary is invalid.');
  37159. }
  37160. function getHints() {
  37161. var hints = linDict.get('H'), hintsLength, item;
  37162. if (isArray(hints) && ((hintsLength = hints.length) === 2 || hintsLength === 4)) {
  37163. for (var index = 0; index < hintsLength; index++) {
  37164. if (!(isInt(item = hints[index]) && item > 0)) {
  37165. throw new Error('Hint (' + index + ') in the linearization dictionary is invalid.');
  37166. }
  37167. }
  37168. return hints;
  37169. }
  37170. throw new Error('Hint array in the linearization dictionary is invalid.');
  37171. }
  37172. var parser = new Parser(new Lexer(stream), false, null);
  37173. var obj1 = parser.getObj();
  37174. var obj2 = parser.getObj();
  37175. var obj3 = parser.getObj();
  37176. var linDict = parser.getObj();
  37177. var obj, length;
  37178. if (!(isInt(obj1) && isInt(obj2) && isCmd(obj3, 'obj') && isDict(linDict) && isNum(obj = linDict.get('Linearized')) && obj > 0)) {
  37179. return null;
  37180. } else // No valid linearization dictionary found.
  37181. if ((length = getInt('L')) !== stream.length) {
  37182. throw new Error('The "L" parameter in the linearization dictionary ' + 'does not equal the stream length.');
  37183. }
  37184. return {
  37185. length: length,
  37186. hints: getHints(),
  37187. objectNumberFirst: getInt('O'),
  37188. endFirst: getInt('E'),
  37189. numPages: getInt('N'),
  37190. mainXRefEntriesOffset: getInt('T'),
  37191. pageFirst: linDict.has('P') ? getInt('P', true) : 0
  37192. };
  37193. }
  37194. };
  37195. exports.EOF = EOF;
  37196. exports.Lexer = Lexer;
  37197. exports.Linearization = Linearization;
  37198. exports.Parser = Parser;
  37199. exports.isEOF = isEOF;
  37200. }));
  37201. (function (root, factory) {
  37202. factory(root.pdfjsCoreType1Parser = {}, root.pdfjsSharedUtil, root.pdfjsCoreStream, root.pdfjsCoreEncodings);
  37203. }(this, function (exports, sharedUtil, coreStream, coreEncodings) {
  37204. var warn = sharedUtil.warn;
  37205. var isSpace = sharedUtil.isSpace;
  37206. var Stream = coreStream.Stream;
  37207. var getEncoding = coreEncodings.getEncoding;
  37208. // Hinting is currently disabled due to unknown problems on windows
  37209. // in tracemonkey and various other pdfs with type1 fonts.
  37210. var HINTING_ENABLED = false;
  37211. /*
  37212. * CharStrings are encoded following the the CharString Encoding sequence
  37213. * describe in Chapter 6 of the "Adobe Type1 Font Format" specification.
  37214. * The value in a byte indicates a command, a number, or subsequent bytes
  37215. * that are to be interpreted in a special way.
  37216. *
  37217. * CharString Number Encoding:
  37218. * A CharString byte containing the values from 32 through 255 inclusive
  37219. * indicate an integer. These values are decoded in four ranges.
  37220. *
  37221. * 1. A CharString byte containing a value, v, between 32 and 246 inclusive,
  37222. * indicate the integer v - 139. Thus, the integer values from -107 through
  37223. * 107 inclusive may be encoded in single byte.
  37224. *
  37225. * 2. A CharString byte containing a value, v, between 247 and 250 inclusive,
  37226. * indicates an integer involving the next byte, w, according to the formula:
  37227. * [(v - 247) x 256] + w + 108
  37228. *
  37229. * 3. A CharString byte containing a value, v, between 251 and 254 inclusive,
  37230. * indicates an integer involving the next byte, w, according to the formula:
  37231. * -[(v - 251) * 256] - w - 108
  37232. *
  37233. * 4. A CharString containing the value 255 indicates that the next 4 bytes
  37234. * are a two complement signed integer. The first of these bytes contains the
  37235. * highest order bits, the second byte contains the next higher order bits
  37236. * and the fourth byte contain the lowest order bits.
  37237. *
  37238. *
  37239. * CharString Command Encoding:
  37240. * CharStrings commands are encoded in 1 or 2 bytes.
  37241. *
  37242. * Single byte commands are encoded in 1 byte that contains a value between
  37243. * 0 and 31 inclusive.
  37244. * If a command byte contains the value 12, then the value in the next byte
  37245. * indicates a command. This "escape" mechanism allows many extra commands
  37246. * to be encoded and this encoding technique helps to minimize the length of
  37247. * the charStrings.
  37248. */
  37249. var Type1CharString = function Type1CharStringClosure() {
  37250. var COMMAND_MAP = {
  37251. 'hstem': [1],
  37252. 'vstem': [3],
  37253. 'vmoveto': [4],
  37254. 'rlineto': [5],
  37255. 'hlineto': [6],
  37256. 'vlineto': [7],
  37257. 'rrcurveto': [8],
  37258. 'callsubr': [10],
  37259. 'flex': [
  37260. 12,
  37261. 35
  37262. ],
  37263. 'drop': [
  37264. 12,
  37265. 18
  37266. ],
  37267. 'endchar': [14],
  37268. 'rmoveto': [21],
  37269. 'hmoveto': [22],
  37270. 'vhcurveto': [30],
  37271. 'hvcurveto': [31]
  37272. };
  37273. function Type1CharString() {
  37274. this.width = 0;
  37275. this.lsb = 0;
  37276. this.flexing = false;
  37277. this.output = [];
  37278. this.stack = [];
  37279. }
  37280. Type1CharString.prototype = {
  37281. convert: function Type1CharString_convert(encoded, subrs, seacAnalysisEnabled) {
  37282. var count = encoded.length;
  37283. var error = false;
  37284. var wx, sbx, subrNumber;
  37285. for (var i = 0; i < count; i++) {
  37286. var value = encoded[i];
  37287. if (value < 32) {
  37288. if (value === 12) {
  37289. value = (value << 8) + encoded[++i];
  37290. }
  37291. switch (value) {
  37292. case 1:
  37293. // hstem
  37294. if (!HINTING_ENABLED) {
  37295. this.stack = [];
  37296. break;
  37297. }
  37298. error = this.executeCommand(2, COMMAND_MAP.hstem);
  37299. break;
  37300. case 3:
  37301. // vstem
  37302. if (!HINTING_ENABLED) {
  37303. this.stack = [];
  37304. break;
  37305. }
  37306. error = this.executeCommand(2, COMMAND_MAP.vstem);
  37307. break;
  37308. case 4:
  37309. // vmoveto
  37310. if (this.flexing) {
  37311. if (this.stack.length < 1) {
  37312. error = true;
  37313. break;
  37314. }
  37315. // Add the dx for flex and but also swap the values so they are
  37316. // the right order.
  37317. var dy = this.stack.pop();
  37318. this.stack.push(0, dy);
  37319. break;
  37320. }
  37321. error = this.executeCommand(1, COMMAND_MAP.vmoveto);
  37322. break;
  37323. case 5:
  37324. // rlineto
  37325. error = this.executeCommand(2, COMMAND_MAP.rlineto);
  37326. break;
  37327. case 6:
  37328. // hlineto
  37329. error = this.executeCommand(1, COMMAND_MAP.hlineto);
  37330. break;
  37331. case 7:
  37332. // vlineto
  37333. error = this.executeCommand(1, COMMAND_MAP.vlineto);
  37334. break;
  37335. case 8:
  37336. // rrcurveto
  37337. error = this.executeCommand(6, COMMAND_MAP.rrcurveto);
  37338. break;
  37339. case 9:
  37340. // closepath
  37341. // closepath is a Type1 command that does not take argument and is
  37342. // useless in Type2 and it can simply be ignored.
  37343. this.stack = [];
  37344. break;
  37345. case 10:
  37346. // callsubr
  37347. if (this.stack.length < 1) {
  37348. error = true;
  37349. break;
  37350. }
  37351. subrNumber = this.stack.pop();
  37352. error = this.convert(subrs[subrNumber], subrs, seacAnalysisEnabled);
  37353. break;
  37354. case 11:
  37355. // return
  37356. return error;
  37357. case 13:
  37358. // hsbw
  37359. if (this.stack.length < 2) {
  37360. error = true;
  37361. break;
  37362. }
  37363. // To convert to type2 we have to move the width value to the
  37364. // first part of the charstring and then use hmoveto with lsb.
  37365. wx = this.stack.pop();
  37366. sbx = this.stack.pop();
  37367. this.lsb = sbx;
  37368. this.width = wx;
  37369. this.stack.push(wx, sbx);
  37370. error = this.executeCommand(2, COMMAND_MAP.hmoveto);
  37371. break;
  37372. case 14:
  37373. // endchar
  37374. this.output.push(COMMAND_MAP.endchar[0]);
  37375. break;
  37376. case 21:
  37377. // rmoveto
  37378. if (this.flexing) {
  37379. break;
  37380. }
  37381. error = this.executeCommand(2, COMMAND_MAP.rmoveto);
  37382. break;
  37383. case 22:
  37384. // hmoveto
  37385. if (this.flexing) {
  37386. // Add the dy for flex.
  37387. this.stack.push(0);
  37388. break;
  37389. }
  37390. error = this.executeCommand(1, COMMAND_MAP.hmoveto);
  37391. break;
  37392. case 30:
  37393. // vhcurveto
  37394. error = this.executeCommand(4, COMMAND_MAP.vhcurveto);
  37395. break;
  37396. case 31:
  37397. // hvcurveto
  37398. error = this.executeCommand(4, COMMAND_MAP.hvcurveto);
  37399. break;
  37400. case (12 << 8) + 0:
  37401. // dotsection
  37402. // dotsection is a Type1 command to specify some hinting feature
  37403. // for dots that do not take a parameter and it can safely be
  37404. // ignored for Type2.
  37405. this.stack = [];
  37406. break;
  37407. case (12 << 8) + 1:
  37408. // vstem3
  37409. if (!HINTING_ENABLED) {
  37410. this.stack = [];
  37411. break;
  37412. }
  37413. // [vh]stem3 are Type1 only and Type2 supports [vh]stem with
  37414. // multiple parameters, so instead of returning [vh]stem3 take a
  37415. // shortcut and return [vhstem] instead.
  37416. error = this.executeCommand(2, COMMAND_MAP.vstem);
  37417. break;
  37418. case (12 << 8) + 2:
  37419. // hstem3
  37420. if (!HINTING_ENABLED) {
  37421. this.stack = [];
  37422. break;
  37423. }
  37424. // See vstem3.
  37425. error = this.executeCommand(2, COMMAND_MAP.hstem);
  37426. break;
  37427. case (12 << 8) + 6:
  37428. // seac
  37429. // seac is like type 2's special endchar but it doesn't use the
  37430. // first argument asb, so remove it.
  37431. if (seacAnalysisEnabled) {
  37432. this.seac = this.stack.splice(-4, 4);
  37433. error = this.executeCommand(0, COMMAND_MAP.endchar);
  37434. } else {
  37435. error = this.executeCommand(4, COMMAND_MAP.endchar);
  37436. }
  37437. break;
  37438. case (12 << 8) + 7:
  37439. // sbw
  37440. if (this.stack.length < 4) {
  37441. error = true;
  37442. break;
  37443. }
  37444. // To convert to type2 we have to move the width value to the
  37445. // first part of the charstring and then use rmoveto with
  37446. // (dx, dy). The height argument will not be used for vmtx and
  37447. // vhea tables reconstruction -- ignoring it.
  37448. var wy = this.stack.pop();
  37449. wx = this.stack.pop();
  37450. var sby = this.stack.pop();
  37451. sbx = this.stack.pop();
  37452. this.lsb = sbx;
  37453. this.width = wx;
  37454. this.stack.push(wx, sbx, sby);
  37455. error = this.executeCommand(3, COMMAND_MAP.rmoveto);
  37456. break;
  37457. case (12 << 8) + 12:
  37458. // div
  37459. if (this.stack.length < 2) {
  37460. error = true;
  37461. break;
  37462. }
  37463. var num2 = this.stack.pop();
  37464. var num1 = this.stack.pop();
  37465. this.stack.push(num1 / num2);
  37466. break;
  37467. case (12 << 8) + 16:
  37468. // callothersubr
  37469. if (this.stack.length < 2) {
  37470. error = true;
  37471. break;
  37472. }
  37473. subrNumber = this.stack.pop();
  37474. var numArgs = this.stack.pop();
  37475. if (subrNumber === 0 && numArgs === 3) {
  37476. var flexArgs = this.stack.splice(this.stack.length - 17, 17);
  37477. this.stack.push(flexArgs[2] + flexArgs[0], // bcp1x + rpx
  37478. flexArgs[3] + flexArgs[1], // bcp1y + rpy
  37479. flexArgs[4], // bcp2x
  37480. flexArgs[5], // bcp2y
  37481. flexArgs[6], // p2x
  37482. flexArgs[7], // p2y
  37483. flexArgs[8], // bcp3x
  37484. flexArgs[9], // bcp3y
  37485. flexArgs[10], // bcp4x
  37486. flexArgs[11], // bcp4y
  37487. flexArgs[12], // p3x
  37488. flexArgs[13], // p3y
  37489. flexArgs[14]);
  37490. // flexDepth
  37491. // 15 = finalx unused by flex
  37492. // 16 = finaly unused by flex
  37493. error = this.executeCommand(13, COMMAND_MAP.flex, true);
  37494. this.flexing = false;
  37495. this.stack.push(flexArgs[15], flexArgs[16]);
  37496. } else if (subrNumber === 1 && numArgs === 0) {
  37497. this.flexing = true;
  37498. }
  37499. break;
  37500. case (12 << 8) + 17:
  37501. // pop
  37502. // Ignore this since it is only used with othersubr.
  37503. break;
  37504. case (12 << 8) + 33:
  37505. // setcurrentpoint
  37506. // Ignore for now.
  37507. this.stack = [];
  37508. break;
  37509. default:
  37510. warn('Unknown type 1 charstring command of "' + value + '"');
  37511. break;
  37512. }
  37513. if (error) {
  37514. break;
  37515. }
  37516. continue;
  37517. } else if (value <= 246) {
  37518. value = value - 139;
  37519. } else if (value <= 250) {
  37520. value = (value - 247) * 256 + encoded[++i] + 108;
  37521. } else if (value <= 254) {
  37522. value = -((value - 251) * 256) - encoded[++i] - 108;
  37523. } else {
  37524. value = (encoded[++i] & 0xff) << 24 | (encoded[++i] & 0xff) << 16 | (encoded[++i] & 0xff) << 8 | (encoded[++i] & 0xff) << 0;
  37525. }
  37526. this.stack.push(value);
  37527. }
  37528. return error;
  37529. },
  37530. executeCommand: function (howManyArgs, command, keepStack) {
  37531. var stackLength = this.stack.length;
  37532. if (howManyArgs > stackLength) {
  37533. return true;
  37534. }
  37535. var start = stackLength - howManyArgs;
  37536. for (var i = start; i < stackLength; i++) {
  37537. var value = this.stack[i];
  37538. if (value === (value | 0)) {
  37539. // int
  37540. this.output.push(28, value >> 8 & 0xff, value & 0xff);
  37541. } else {
  37542. // fixed point
  37543. value = 65536 * value | 0;
  37544. this.output.push(255, value >> 24 & 0xFF, value >> 16 & 0xFF, value >> 8 & 0xFF, value & 0xFF);
  37545. }
  37546. }
  37547. this.output.push.apply(this.output, command);
  37548. if (keepStack) {
  37549. this.stack.splice(start, howManyArgs);
  37550. } else {
  37551. this.stack.length = 0;
  37552. }
  37553. return false;
  37554. }
  37555. };
  37556. return Type1CharString;
  37557. }();
  37558. /*
  37559. * Type1Parser encapsulate the needed code for parsing a Type1 font
  37560. * program. Some of its logic depends on the Type2 charstrings
  37561. * structure.
  37562. * Note: this doesn't really parse the font since that would require evaluation
  37563. * of PostScript, but it is possible in most cases to extract what we need
  37564. * without a full parse.
  37565. */
  37566. var Type1Parser = function Type1ParserClosure() {
  37567. /*
  37568. * Decrypt a Sequence of Ciphertext Bytes to Produce the Original Sequence
  37569. * of Plaintext Bytes. The function took a key as a parameter which can be
  37570. * for decrypting the eexec block of for decoding charStrings.
  37571. */
  37572. var EEXEC_ENCRYPT_KEY = 55665;
  37573. var CHAR_STRS_ENCRYPT_KEY = 4330;
  37574. function isHexDigit(code) {
  37575. return code >= 48 && code <= 57 || // '0'-'9'
  37576. code >= 65 && code <= 70 || // 'A'-'F'
  37577. code >= 97 && code <= 102;
  37578. }
  37579. // 'a'-'f'
  37580. function decrypt(data, key, discardNumber) {
  37581. if (discardNumber >= data.length) {
  37582. return new Uint8Array(0);
  37583. }
  37584. var r = key | 0, c1 = 52845, c2 = 22719, i, j;
  37585. for (i = 0; i < discardNumber; i++) {
  37586. r = (data[i] + r) * c1 + c2 & (1 << 16) - 1;
  37587. }
  37588. var count = data.length - discardNumber;
  37589. var decrypted = new Uint8Array(count);
  37590. for (i = discardNumber, j = 0; j < count; i++, j++) {
  37591. var value = data[i];
  37592. decrypted[j] = value ^ r >> 8;
  37593. r = (value + r) * c1 + c2 & (1 << 16) - 1;
  37594. }
  37595. return decrypted;
  37596. }
  37597. function decryptAscii(data, key, discardNumber) {
  37598. var r = key | 0, c1 = 52845, c2 = 22719;
  37599. var count = data.length, maybeLength = count >>> 1;
  37600. var decrypted = new Uint8Array(maybeLength);
  37601. var i, j;
  37602. for (i = 0, j = 0; i < count; i++) {
  37603. var digit1 = data[i];
  37604. if (!isHexDigit(digit1)) {
  37605. continue;
  37606. }
  37607. i++;
  37608. var digit2;
  37609. while (i < count && !isHexDigit(digit2 = data[i])) {
  37610. i++;
  37611. }
  37612. if (i < count) {
  37613. var value = parseInt(String.fromCharCode(digit1, digit2), 16);
  37614. decrypted[j++] = value ^ r >> 8;
  37615. r = (value + r) * c1 + c2 & (1 << 16) - 1;
  37616. }
  37617. }
  37618. return Array.prototype.slice.call(decrypted, discardNumber, j);
  37619. }
  37620. function isSpecial(c) {
  37621. return c === 0x2F || // '/'
  37622. c === 0x5B || c === 0x5D || // '[', ']'
  37623. c === 0x7B || c === 0x7D || // '{', '}'
  37624. c === 0x28 || c === 0x29;
  37625. }
  37626. // '(', ')'
  37627. function Type1Parser(stream, encrypted, seacAnalysisEnabled) {
  37628. if (encrypted) {
  37629. var data = stream.getBytes();
  37630. var isBinary = !(isHexDigit(data[0]) && isHexDigit(data[1]) && isHexDigit(data[2]) && isHexDigit(data[3]));
  37631. stream = new Stream(isBinary ? decrypt(data, EEXEC_ENCRYPT_KEY, 4) : decryptAscii(data, EEXEC_ENCRYPT_KEY, 4));
  37632. }
  37633. this.seacAnalysisEnabled = !!seacAnalysisEnabled;
  37634. this.stream = stream;
  37635. this.nextChar();
  37636. }
  37637. Type1Parser.prototype = {
  37638. readNumberArray: function Type1Parser_readNumberArray() {
  37639. this.getToken();
  37640. // read '[' or '{' (arrays can start with either)
  37641. var array = [];
  37642. while (true) {
  37643. var token = this.getToken();
  37644. if (token === null || token === ']' || token === '}') {
  37645. break;
  37646. }
  37647. array.push(parseFloat(token || 0));
  37648. }
  37649. return array;
  37650. },
  37651. readNumber: function Type1Parser_readNumber() {
  37652. var token = this.getToken();
  37653. return parseFloat(token || 0);
  37654. },
  37655. readInt: function Type1Parser_readInt() {
  37656. // Use '| 0' to prevent setting a double into length such as the double
  37657. // does not flow into the loop variable.
  37658. var token = this.getToken();
  37659. return parseInt(token || 0, 10) | 0;
  37660. },
  37661. readBoolean: function Type1Parser_readBoolean() {
  37662. var token = this.getToken();
  37663. // Use 1 and 0 since that's what type2 charstrings use.
  37664. return token === 'true' ? 1 : 0;
  37665. },
  37666. nextChar: function Type1_nextChar() {
  37667. return this.currentChar = this.stream.getByte();
  37668. },
  37669. getToken: function Type1Parser_getToken() {
  37670. // Eat whitespace and comments.
  37671. var comment = false;
  37672. var ch = this.currentChar;
  37673. while (true) {
  37674. if (ch === -1) {
  37675. return null;
  37676. }
  37677. if (comment) {
  37678. if (ch === 0x0A || ch === 0x0D) {
  37679. comment = false;
  37680. }
  37681. } else if (ch === 0x25) {
  37682. // '%'
  37683. comment = true;
  37684. } else if (!isSpace(ch)) {
  37685. break;
  37686. }
  37687. ch = this.nextChar();
  37688. }
  37689. if (isSpecial(ch)) {
  37690. this.nextChar();
  37691. return String.fromCharCode(ch);
  37692. }
  37693. var token = '';
  37694. do {
  37695. token += String.fromCharCode(ch);
  37696. ch = this.nextChar();
  37697. } while (ch >= 0 && !isSpace(ch) && !isSpecial(ch));
  37698. return token;
  37699. },
  37700. /*
  37701. * Returns an object containing a Subrs array and a CharStrings
  37702. * array extracted from and eexec encrypted block of data
  37703. */
  37704. extractFontProgram: function Type1Parser_extractFontProgram() {
  37705. var stream = this.stream;
  37706. var subrs = [], charstrings = [];
  37707. var privateData = Object.create(null);
  37708. privateData['lenIV'] = 4;
  37709. var program = {
  37710. subrs: [],
  37711. charstrings: [],
  37712. properties: { 'privateData': privateData }
  37713. };
  37714. var token, length, data, lenIV, encoded;
  37715. while ((token = this.getToken()) !== null) {
  37716. if (token !== '/') {
  37717. continue;
  37718. }
  37719. token = this.getToken();
  37720. switch (token) {
  37721. case 'CharStrings':
  37722. // The number immediately following CharStrings must be greater or
  37723. // equal to the number of CharStrings.
  37724. this.getToken();
  37725. this.getToken();
  37726. // read in 'dict'
  37727. this.getToken();
  37728. // read in 'dup'
  37729. this.getToken();
  37730. // read in 'begin'
  37731. while (true) {
  37732. token = this.getToken();
  37733. if (token === null || token === 'end') {
  37734. break;
  37735. }
  37736. if (token !== '/') {
  37737. continue;
  37738. }
  37739. var glyph = this.getToken();
  37740. length = this.readInt();
  37741. this.getToken();
  37742. // read in 'RD' or '-|'
  37743. data = stream.makeSubStream(stream.pos, length);
  37744. lenIV = program.properties.privateData['lenIV'];
  37745. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  37746. // Skip past the required space and binary data.
  37747. stream.skip(length);
  37748. this.nextChar();
  37749. token = this.getToken();
  37750. // read in 'ND' or '|-'
  37751. if (token === 'noaccess') {
  37752. this.getToken();
  37753. }
  37754. // read in 'def'
  37755. charstrings.push({
  37756. glyph: glyph,
  37757. encoded: encoded
  37758. });
  37759. }
  37760. break;
  37761. case 'Subrs':
  37762. var num = this.readInt();
  37763. this.getToken();
  37764. // read in 'array'
  37765. while ((token = this.getToken()) === 'dup') {
  37766. var index = this.readInt();
  37767. length = this.readInt();
  37768. this.getToken();
  37769. // read in 'RD' or '-|'
  37770. data = stream.makeSubStream(stream.pos, length);
  37771. lenIV = program.properties.privateData['lenIV'];
  37772. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  37773. // Skip past the required space and binary data.
  37774. stream.skip(length);
  37775. this.nextChar();
  37776. token = this.getToken();
  37777. // read in 'NP' or '|'
  37778. if (token === 'noaccess') {
  37779. this.getToken();
  37780. }
  37781. // read in 'put'
  37782. subrs[index] = encoded;
  37783. }
  37784. break;
  37785. case 'BlueValues':
  37786. case 'OtherBlues':
  37787. case 'FamilyBlues':
  37788. case 'FamilyOtherBlues':
  37789. var blueArray = this.readNumberArray();
  37790. // *Blue* values may contain invalid data: disables reading of
  37791. // those values when hinting is disabled.
  37792. if (blueArray.length > 0 && blueArray.length % 2 === 0 && HINTING_ENABLED) {
  37793. program.properties.privateData[token] = blueArray;
  37794. }
  37795. break;
  37796. case 'StemSnapH':
  37797. case 'StemSnapV':
  37798. program.properties.privateData[token] = this.readNumberArray();
  37799. break;
  37800. case 'StdHW':
  37801. case 'StdVW':
  37802. program.properties.privateData[token] = this.readNumberArray()[0];
  37803. break;
  37804. case 'BlueShift':
  37805. case 'lenIV':
  37806. case 'BlueFuzz':
  37807. case 'BlueScale':
  37808. case 'LanguageGroup':
  37809. case 'ExpansionFactor':
  37810. program.properties.privateData[token] = this.readNumber();
  37811. break;
  37812. case 'ForceBold':
  37813. program.properties.privateData[token] = this.readBoolean();
  37814. break;
  37815. }
  37816. }
  37817. for (var i = 0; i < charstrings.length; i++) {
  37818. glyph = charstrings[i].glyph;
  37819. encoded = charstrings[i].encoded;
  37820. var charString = new Type1CharString();
  37821. var error = charString.convert(encoded, subrs, this.seacAnalysisEnabled);
  37822. var output = charString.output;
  37823. if (error) {
  37824. // It seems when FreeType encounters an error while evaluating a glyph
  37825. // that it completely ignores the glyph so we'll mimic that behaviour
  37826. // here and put an endchar to make the validator happy.
  37827. output = [14];
  37828. }
  37829. program.charstrings.push({
  37830. glyphName: glyph,
  37831. charstring: output,
  37832. width: charString.width,
  37833. lsb: charString.lsb,
  37834. seac: charString.seac
  37835. });
  37836. }
  37837. return program;
  37838. },
  37839. extractFontHeader: function Type1Parser_extractFontHeader(properties) {
  37840. var token;
  37841. while ((token = this.getToken()) !== null) {
  37842. if (token !== '/') {
  37843. continue;
  37844. }
  37845. token = this.getToken();
  37846. switch (token) {
  37847. case 'FontMatrix':
  37848. var matrix = this.readNumberArray();
  37849. properties.fontMatrix = matrix;
  37850. break;
  37851. case 'Encoding':
  37852. var encodingArg = this.getToken();
  37853. var encoding;
  37854. if (!/^\d+$/.test(encodingArg)) {
  37855. // encoding name is specified
  37856. encoding = getEncoding(encodingArg);
  37857. } else {
  37858. encoding = [];
  37859. var size = parseInt(encodingArg, 10) | 0;
  37860. this.getToken();
  37861. // read in 'array'
  37862. for (var j = 0; j < size; j++) {
  37863. token = this.getToken();
  37864. // skipping till first dup or def (e.g. ignoring for statement)
  37865. while (token !== 'dup' && token !== 'def') {
  37866. token = this.getToken();
  37867. if (token === null) {
  37868. return;
  37869. }
  37870. }
  37871. // invalid header
  37872. if (token === 'def') {
  37873. break;
  37874. }
  37875. // read all array data
  37876. var index = this.readInt();
  37877. this.getToken();
  37878. // read in '/'
  37879. var glyph = this.getToken();
  37880. encoding[index] = glyph;
  37881. this.getToken();
  37882. }
  37883. }
  37884. // read the in 'put'
  37885. properties.builtInEncoding = encoding;
  37886. break;
  37887. case 'FontBBox':
  37888. var fontBBox = this.readNumberArray();
  37889. // adjusting ascent/descent
  37890. properties.ascent = fontBBox[3];
  37891. properties.descent = fontBBox[1];
  37892. properties.ascentScaled = true;
  37893. break;
  37894. }
  37895. }
  37896. }
  37897. };
  37898. return Type1Parser;
  37899. }();
  37900. exports.Type1Parser = Type1Parser;
  37901. }));
  37902. (function (root, factory) {
  37903. factory(root.pdfjsCoreCMap = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreParser);
  37904. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreParser) {
  37905. var Util = sharedUtil.Util;
  37906. var assert = sharedUtil.assert;
  37907. var warn = sharedUtil.warn;
  37908. var error = sharedUtil.error;
  37909. var isInt = sharedUtil.isInt;
  37910. var isString = sharedUtil.isString;
  37911. var MissingDataException = sharedUtil.MissingDataException;
  37912. var isName = corePrimitives.isName;
  37913. var isCmd = corePrimitives.isCmd;
  37914. var isStream = corePrimitives.isStream;
  37915. var StringStream = coreStream.StringStream;
  37916. var Lexer = coreParser.Lexer;
  37917. var isEOF = coreParser.isEOF;
  37918. var BUILT_IN_CMAPS = [
  37919. // << Start unicode maps.
  37920. 'Adobe-GB1-UCS2',
  37921. 'Adobe-CNS1-UCS2',
  37922. 'Adobe-Japan1-UCS2',
  37923. 'Adobe-Korea1-UCS2',
  37924. // >> End unicode maps.
  37925. '78-EUC-H',
  37926. '78-EUC-V',
  37927. '78-H',
  37928. '78-RKSJ-H',
  37929. '78-RKSJ-V',
  37930. '78-V',
  37931. '78ms-RKSJ-H',
  37932. '78ms-RKSJ-V',
  37933. '83pv-RKSJ-H',
  37934. '90ms-RKSJ-H',
  37935. '90ms-RKSJ-V',
  37936. '90msp-RKSJ-H',
  37937. '90msp-RKSJ-V',
  37938. '90pv-RKSJ-H',
  37939. '90pv-RKSJ-V',
  37940. 'Add-H',
  37941. 'Add-RKSJ-H',
  37942. 'Add-RKSJ-V',
  37943. 'Add-V',
  37944. 'Adobe-CNS1-0',
  37945. 'Adobe-CNS1-1',
  37946. 'Adobe-CNS1-2',
  37947. 'Adobe-CNS1-3',
  37948. 'Adobe-CNS1-4',
  37949. 'Adobe-CNS1-5',
  37950. 'Adobe-CNS1-6',
  37951. 'Adobe-GB1-0',
  37952. 'Adobe-GB1-1',
  37953. 'Adobe-GB1-2',
  37954. 'Adobe-GB1-3',
  37955. 'Adobe-GB1-4',
  37956. 'Adobe-GB1-5',
  37957. 'Adobe-Japan1-0',
  37958. 'Adobe-Japan1-1',
  37959. 'Adobe-Japan1-2',
  37960. 'Adobe-Japan1-3',
  37961. 'Adobe-Japan1-4',
  37962. 'Adobe-Japan1-5',
  37963. 'Adobe-Japan1-6',
  37964. 'Adobe-Korea1-0',
  37965. 'Adobe-Korea1-1',
  37966. 'Adobe-Korea1-2',
  37967. 'B5-H',
  37968. 'B5-V',
  37969. 'B5pc-H',
  37970. 'B5pc-V',
  37971. 'CNS-EUC-H',
  37972. 'CNS-EUC-V',
  37973. 'CNS1-H',
  37974. 'CNS1-V',
  37975. 'CNS2-H',
  37976. 'CNS2-V',
  37977. 'ETHK-B5-H',
  37978. 'ETHK-B5-V',
  37979. 'ETen-B5-H',
  37980. 'ETen-B5-V',
  37981. 'ETenms-B5-H',
  37982. 'ETenms-B5-V',
  37983. 'EUC-H',
  37984. 'EUC-V',
  37985. 'Ext-H',
  37986. 'Ext-RKSJ-H',
  37987. 'Ext-RKSJ-V',
  37988. 'Ext-V',
  37989. 'GB-EUC-H',
  37990. 'GB-EUC-V',
  37991. 'GB-H',
  37992. 'GB-V',
  37993. 'GBK-EUC-H',
  37994. 'GBK-EUC-V',
  37995. 'GBK2K-H',
  37996. 'GBK2K-V',
  37997. 'GBKp-EUC-H',
  37998. 'GBKp-EUC-V',
  37999. 'GBT-EUC-H',
  38000. 'GBT-EUC-V',
  38001. 'GBT-H',
  38002. 'GBT-V',
  38003. 'GBTpc-EUC-H',
  38004. 'GBTpc-EUC-V',
  38005. 'GBpc-EUC-H',
  38006. 'GBpc-EUC-V',
  38007. 'H',
  38008. 'HKdla-B5-H',
  38009. 'HKdla-B5-V',
  38010. 'HKdlb-B5-H',
  38011. 'HKdlb-B5-V',
  38012. 'HKgccs-B5-H',
  38013. 'HKgccs-B5-V',
  38014. 'HKm314-B5-H',
  38015. 'HKm314-B5-V',
  38016. 'HKm471-B5-H',
  38017. 'HKm471-B5-V',
  38018. 'HKscs-B5-H',
  38019. 'HKscs-B5-V',
  38020. 'Hankaku',
  38021. 'Hiragana',
  38022. 'KSC-EUC-H',
  38023. 'KSC-EUC-V',
  38024. 'KSC-H',
  38025. 'KSC-Johab-H',
  38026. 'KSC-Johab-V',
  38027. 'KSC-V',
  38028. 'KSCms-UHC-H',
  38029. 'KSCms-UHC-HW-H',
  38030. 'KSCms-UHC-HW-V',
  38031. 'KSCms-UHC-V',
  38032. 'KSCpc-EUC-H',
  38033. 'KSCpc-EUC-V',
  38034. 'Katakana',
  38035. 'NWP-H',
  38036. 'NWP-V',
  38037. 'RKSJ-H',
  38038. 'RKSJ-V',
  38039. 'Roman',
  38040. 'UniCNS-UCS2-H',
  38041. 'UniCNS-UCS2-V',
  38042. 'UniCNS-UTF16-H',
  38043. 'UniCNS-UTF16-V',
  38044. 'UniCNS-UTF32-H',
  38045. 'UniCNS-UTF32-V',
  38046. 'UniCNS-UTF8-H',
  38047. 'UniCNS-UTF8-V',
  38048. 'UniGB-UCS2-H',
  38049. 'UniGB-UCS2-V',
  38050. 'UniGB-UTF16-H',
  38051. 'UniGB-UTF16-V',
  38052. 'UniGB-UTF32-H',
  38053. 'UniGB-UTF32-V',
  38054. 'UniGB-UTF8-H',
  38055. 'UniGB-UTF8-V',
  38056. 'UniJIS-UCS2-H',
  38057. 'UniJIS-UCS2-HW-H',
  38058. 'UniJIS-UCS2-HW-V',
  38059. 'UniJIS-UCS2-V',
  38060. 'UniJIS-UTF16-H',
  38061. 'UniJIS-UTF16-V',
  38062. 'UniJIS-UTF32-H',
  38063. 'UniJIS-UTF32-V',
  38064. 'UniJIS-UTF8-H',
  38065. 'UniJIS-UTF8-V',
  38066. 'UniJIS2004-UTF16-H',
  38067. 'UniJIS2004-UTF16-V',
  38068. 'UniJIS2004-UTF32-H',
  38069. 'UniJIS2004-UTF32-V',
  38070. 'UniJIS2004-UTF8-H',
  38071. 'UniJIS2004-UTF8-V',
  38072. 'UniJISPro-UCS2-HW-V',
  38073. 'UniJISPro-UCS2-V',
  38074. 'UniJISPro-UTF8-V',
  38075. 'UniJISX0213-UTF32-H',
  38076. 'UniJISX0213-UTF32-V',
  38077. 'UniJISX02132004-UTF32-H',
  38078. 'UniJISX02132004-UTF32-V',
  38079. 'UniKS-UCS2-H',
  38080. 'UniKS-UCS2-V',
  38081. 'UniKS-UTF16-H',
  38082. 'UniKS-UTF16-V',
  38083. 'UniKS-UTF32-H',
  38084. 'UniKS-UTF32-V',
  38085. 'UniKS-UTF8-H',
  38086. 'UniKS-UTF8-V',
  38087. 'V',
  38088. 'WP-Symbol'
  38089. ];
  38090. // CMap, not to be confused with TrueType's cmap.
  38091. var CMap = function CMapClosure() {
  38092. function CMap(builtInCMap) {
  38093. // Codespace ranges are stored as follows:
  38094. // [[1BytePairs], [2BytePairs], [3BytePairs], [4BytePairs]]
  38095. // where nBytePairs are ranges e.g. [low1, high1, low2, high2, ...]
  38096. this.codespaceRanges = [
  38097. [],
  38098. [],
  38099. [],
  38100. []
  38101. ];
  38102. this.numCodespaceRanges = 0;
  38103. // Map entries have one of two forms.
  38104. // - cid chars are 16-bit unsigned integers, stored as integers.
  38105. // - bf chars are variable-length byte sequences, stored as strings, with
  38106. // one byte per character.
  38107. this._map = [];
  38108. this.name = '';
  38109. this.vertical = false;
  38110. this.useCMap = null;
  38111. this.builtInCMap = builtInCMap;
  38112. }
  38113. CMap.prototype = {
  38114. addCodespaceRange: function (n, low, high) {
  38115. this.codespaceRanges[n - 1].push(low, high);
  38116. this.numCodespaceRanges++;
  38117. },
  38118. mapCidRange: function (low, high, dstLow) {
  38119. while (low <= high) {
  38120. this._map[low++] = dstLow++;
  38121. }
  38122. },
  38123. mapBfRange: function (low, high, dstLow) {
  38124. var lastByte = dstLow.length - 1;
  38125. while (low <= high) {
  38126. this._map[low++] = dstLow;
  38127. // Only the last byte has to be incremented.
  38128. dstLow = dstLow.substr(0, lastByte) + String.fromCharCode(dstLow.charCodeAt(lastByte) + 1);
  38129. }
  38130. },
  38131. mapBfRangeToArray: function (low, high, array) {
  38132. var i = 0, ii = array.length;
  38133. while (low <= high && i < ii) {
  38134. this._map[low] = array[i++];
  38135. ++low;
  38136. }
  38137. },
  38138. // This is used for both bf and cid chars.
  38139. mapOne: function (src, dst) {
  38140. this._map[src] = dst;
  38141. },
  38142. lookup: function (code) {
  38143. return this._map[code];
  38144. },
  38145. contains: function (code) {
  38146. return this._map[code] !== undefined;
  38147. },
  38148. forEach: function (callback) {
  38149. // Most maps have fewer than 65536 entries, and for those we use normal
  38150. // array iteration. But really sparse tables are possible -- e.g. with
  38151. // indices in the *billions*. For such tables we use for..in, which isn't
  38152. // ideal because it stringifies the indices for all present elements, but
  38153. // it does avoid iterating over every undefined entry.
  38154. var map = this._map;
  38155. var length = map.length;
  38156. var i;
  38157. if (length <= 0x10000) {
  38158. for (i = 0; i < length; i++) {
  38159. if (map[i] !== undefined) {
  38160. callback(i, map[i]);
  38161. }
  38162. }
  38163. } else {
  38164. for (i in this._map) {
  38165. callback(i, map[i]);
  38166. }
  38167. }
  38168. },
  38169. charCodeOf: function (value) {
  38170. return this._map.indexOf(value);
  38171. },
  38172. getMap: function () {
  38173. return this._map;
  38174. },
  38175. readCharCode: function (str, offset, out) {
  38176. var c = 0;
  38177. var codespaceRanges = this.codespaceRanges;
  38178. var codespaceRangesLen = this.codespaceRanges.length;
  38179. // 9.7.6.2 CMap Mapping
  38180. // The code length is at most 4.
  38181. for (var n = 0; n < codespaceRangesLen; n++) {
  38182. c = (c << 8 | str.charCodeAt(offset + n)) >>> 0;
  38183. // Check each codespace range to see if it falls within.
  38184. var codespaceRange = codespaceRanges[n];
  38185. for (var k = 0, kk = codespaceRange.length; k < kk;) {
  38186. var low = codespaceRange[k++];
  38187. var high = codespaceRange[k++];
  38188. if (c >= low && c <= high) {
  38189. out.charcode = c;
  38190. out.length = n + 1;
  38191. return;
  38192. }
  38193. }
  38194. }
  38195. out.charcode = 0;
  38196. out.length = 1;
  38197. },
  38198. get length() {
  38199. return this._map.length;
  38200. },
  38201. get isIdentityCMap() {
  38202. if (!(this.name === 'Identity-H' || this.name === 'Identity-V')) {
  38203. return false;
  38204. }
  38205. if (this._map.length !== 0x10000) {
  38206. return false;
  38207. }
  38208. for (var i = 0; i < 0x10000; i++) {
  38209. if (this._map[i] !== i) {
  38210. return false;
  38211. }
  38212. }
  38213. return true;
  38214. }
  38215. };
  38216. return CMap;
  38217. }();
  38218. // A special case of CMap, where the _map array implicitly has a length of
  38219. // 65536 and each element is equal to its index.
  38220. var IdentityCMap = function IdentityCMapClosure() {
  38221. function IdentityCMap(vertical, n) {
  38222. CMap.call(this);
  38223. this.vertical = vertical;
  38224. this.addCodespaceRange(n, 0, 0xffff);
  38225. }
  38226. Util.inherit(IdentityCMap, CMap, {});
  38227. IdentityCMap.prototype = {
  38228. addCodespaceRange: CMap.prototype.addCodespaceRange,
  38229. mapCidRange: function (low, high, dstLow) {
  38230. error('should not call mapCidRange');
  38231. },
  38232. mapBfRange: function (low, high, dstLow) {
  38233. error('should not call mapBfRange');
  38234. },
  38235. mapBfRangeToArray: function (low, high, array) {
  38236. error('should not call mapBfRangeToArray');
  38237. },
  38238. mapOne: function (src, dst) {
  38239. error('should not call mapCidOne');
  38240. },
  38241. lookup: function (code) {
  38242. return isInt(code) && code <= 0xffff ? code : undefined;
  38243. },
  38244. contains: function (code) {
  38245. return isInt(code) && code <= 0xffff;
  38246. },
  38247. forEach: function (callback) {
  38248. for (var i = 0; i <= 0xffff; i++) {
  38249. callback(i, i);
  38250. }
  38251. },
  38252. charCodeOf: function (value) {
  38253. return isInt(value) && value <= 0xffff ? value : -1;
  38254. },
  38255. getMap: function () {
  38256. // Sometimes identity maps must be instantiated, but it's rare.
  38257. var map = new Array(0x10000);
  38258. for (var i = 0; i <= 0xffff; i++) {
  38259. map[i] = i;
  38260. }
  38261. return map;
  38262. },
  38263. readCharCode: CMap.prototype.readCharCode,
  38264. get length() {
  38265. return 0x10000;
  38266. },
  38267. get isIdentityCMap() {
  38268. error('should not access .isIdentityCMap');
  38269. }
  38270. };
  38271. return IdentityCMap;
  38272. }();
  38273. var BinaryCMapReader = function BinaryCMapReaderClosure() {
  38274. function fetchBinaryData(url) {
  38275. return new Promise(function (resolve, reject) {
  38276. var request = new XMLHttpRequest();
  38277. request.open('GET', url, true);
  38278. request.responseType = 'arraybuffer';
  38279. request.onreadystatechange = function () {
  38280. if (request.readyState === XMLHttpRequest.DONE) {
  38281. if (!request.response || request.status !== 200 && request.status !== 0) {
  38282. reject(new Error('Unable to get binary cMap at: ' + url));
  38283. } else {
  38284. resolve(new Uint8Array(request.response));
  38285. }
  38286. }
  38287. };
  38288. request.send(null);
  38289. });
  38290. }
  38291. function hexToInt(a, size) {
  38292. var n = 0;
  38293. for (var i = 0; i <= size; i++) {
  38294. n = n << 8 | a[i];
  38295. }
  38296. return n >>> 0;
  38297. }
  38298. function hexToStr(a, size) {
  38299. // This code is hot. Special-case some common values to avoid creating an
  38300. // object with subarray().
  38301. if (size === 1) {
  38302. return String.fromCharCode(a[0], a[1]);
  38303. }
  38304. if (size === 3) {
  38305. return String.fromCharCode(a[0], a[1], a[2], a[3]);
  38306. }
  38307. return String.fromCharCode.apply(null, a.subarray(0, size + 1));
  38308. }
  38309. function addHex(a, b, size) {
  38310. var c = 0;
  38311. for (var i = size; i >= 0; i--) {
  38312. c += a[i] + b[i];
  38313. a[i] = c & 255;
  38314. c >>= 8;
  38315. }
  38316. }
  38317. function incHex(a, size) {
  38318. var c = 1;
  38319. for (var i = size; i >= 0 && c > 0; i--) {
  38320. c += a[i];
  38321. a[i] = c & 255;
  38322. c >>= 8;
  38323. }
  38324. }
  38325. var MAX_NUM_SIZE = 16;
  38326. var MAX_ENCODED_NUM_SIZE = 19;
  38327. // ceil(MAX_NUM_SIZE * 7 / 8)
  38328. function BinaryCMapStream(data) {
  38329. this.buffer = data;
  38330. this.pos = 0;
  38331. this.end = data.length;
  38332. this.tmpBuf = new Uint8Array(MAX_ENCODED_NUM_SIZE);
  38333. }
  38334. BinaryCMapStream.prototype = {
  38335. readByte: function () {
  38336. if (this.pos >= this.end) {
  38337. return -1;
  38338. }
  38339. return this.buffer[this.pos++];
  38340. },
  38341. readNumber: function () {
  38342. var n = 0;
  38343. var last;
  38344. do {
  38345. var b = this.readByte();
  38346. if (b < 0) {
  38347. error('unexpected EOF in bcmap');
  38348. }
  38349. last = !(b & 0x80);
  38350. n = n << 7 | b & 0x7F;
  38351. } while (!last);
  38352. return n;
  38353. },
  38354. readSigned: function () {
  38355. var n = this.readNumber();
  38356. return n & 1 ? ~(n >>> 1) : n >>> 1;
  38357. },
  38358. readHex: function (num, size) {
  38359. num.set(this.buffer.subarray(this.pos, this.pos + size + 1));
  38360. this.pos += size + 1;
  38361. },
  38362. readHexNumber: function (num, size) {
  38363. var last;
  38364. var stack = this.tmpBuf, sp = 0;
  38365. do {
  38366. var b = this.readByte();
  38367. if (b < 0) {
  38368. error('unexpected EOF in bcmap');
  38369. }
  38370. last = !(b & 0x80);
  38371. stack[sp++] = b & 0x7F;
  38372. } while (!last);
  38373. var i = size, buffer = 0, bufferSize = 0;
  38374. while (i >= 0) {
  38375. while (bufferSize < 8 && stack.length > 0) {
  38376. buffer = stack[--sp] << bufferSize | buffer;
  38377. bufferSize += 7;
  38378. }
  38379. num[i] = buffer & 255;
  38380. i--;
  38381. buffer >>= 8;
  38382. bufferSize -= 8;
  38383. }
  38384. },
  38385. readHexSigned: function (num, size) {
  38386. this.readHexNumber(num, size);
  38387. var sign = num[size] & 1 ? 255 : 0;
  38388. var c = 0;
  38389. for (var i = 0; i <= size; i++) {
  38390. c = (c & 1) << 8 | num[i];
  38391. num[i] = c >> 1 ^ sign;
  38392. }
  38393. },
  38394. readString: function () {
  38395. var len = this.readNumber();
  38396. var s = '';
  38397. for (var i = 0; i < len; i++) {
  38398. s += String.fromCharCode(this.readNumber());
  38399. }
  38400. return s;
  38401. }
  38402. };
  38403. function processBinaryCMap(url, cMap, extend) {
  38404. return fetchBinaryData(url).then(function (data) {
  38405. var stream = new BinaryCMapStream(data);
  38406. var header = stream.readByte();
  38407. cMap.vertical = !!(header & 1);
  38408. var useCMap = null;
  38409. var start = new Uint8Array(MAX_NUM_SIZE);
  38410. var end = new Uint8Array(MAX_NUM_SIZE);
  38411. var char = new Uint8Array(MAX_NUM_SIZE);
  38412. var charCode = new Uint8Array(MAX_NUM_SIZE);
  38413. var tmp = new Uint8Array(MAX_NUM_SIZE);
  38414. var code;
  38415. var b;
  38416. while ((b = stream.readByte()) >= 0) {
  38417. var type = b >> 5;
  38418. if (type === 7) {
  38419. // metadata, e.g. comment or usecmap
  38420. switch (b & 0x1F) {
  38421. case 0:
  38422. stream.readString();
  38423. // skipping comment
  38424. break;
  38425. case 1:
  38426. useCMap = stream.readString();
  38427. break;
  38428. }
  38429. continue;
  38430. }
  38431. var sequence = !!(b & 0x10);
  38432. var dataSize = b & 15;
  38433. assert(dataSize + 1 <= MAX_NUM_SIZE);
  38434. var ucs2DataSize = 1;
  38435. var subitemsCount = stream.readNumber();
  38436. var i;
  38437. switch (type) {
  38438. case 0:
  38439. // codespacerange
  38440. stream.readHex(start, dataSize);
  38441. stream.readHexNumber(end, dataSize);
  38442. addHex(end, start, dataSize);
  38443. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize), hexToInt(end, dataSize));
  38444. for (i = 1; i < subitemsCount; i++) {
  38445. incHex(end, dataSize);
  38446. stream.readHexNumber(start, dataSize);
  38447. addHex(start, end, dataSize);
  38448. stream.readHexNumber(end, dataSize);
  38449. addHex(end, start, dataSize);
  38450. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize), hexToInt(end, dataSize));
  38451. }
  38452. break;
  38453. case 1:
  38454. // notdefrange
  38455. stream.readHex(start, dataSize);
  38456. stream.readHexNumber(end, dataSize);
  38457. addHex(end, start, dataSize);
  38458. code = stream.readNumber();
  38459. // undefined range, skipping
  38460. for (i = 1; i < subitemsCount; i++) {
  38461. incHex(end, dataSize);
  38462. stream.readHexNumber(start, dataSize);
  38463. addHex(start, end, dataSize);
  38464. stream.readHexNumber(end, dataSize);
  38465. addHex(end, start, dataSize);
  38466. code = stream.readNumber();
  38467. }
  38468. // nop
  38469. break;
  38470. case 2:
  38471. // cidchar
  38472. stream.readHex(char, dataSize);
  38473. code = stream.readNumber();
  38474. cMap.mapOne(hexToInt(char, dataSize), code);
  38475. for (i = 1; i < subitemsCount; i++) {
  38476. incHex(char, dataSize);
  38477. if (!sequence) {
  38478. stream.readHexNumber(tmp, dataSize);
  38479. addHex(char, tmp, dataSize);
  38480. }
  38481. code = stream.readSigned() + (code + 1);
  38482. cMap.mapOne(hexToInt(char, dataSize), code);
  38483. }
  38484. break;
  38485. case 3:
  38486. // cidrange
  38487. stream.readHex(start, dataSize);
  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. for (i = 1; i < subitemsCount; i++) {
  38493. incHex(end, dataSize);
  38494. if (!sequence) {
  38495. stream.readHexNumber(start, dataSize);
  38496. addHex(start, end, dataSize);
  38497. } else {
  38498. start.set(end);
  38499. }
  38500. stream.readHexNumber(end, dataSize);
  38501. addHex(end, start, dataSize);
  38502. code = stream.readNumber();
  38503. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize), code);
  38504. }
  38505. break;
  38506. case 4:
  38507. // bfchar
  38508. stream.readHex(char, ucs2DataSize);
  38509. stream.readHex(charCode, dataSize);
  38510. cMap.mapOne(hexToInt(char, ucs2DataSize), hexToStr(charCode, dataSize));
  38511. for (i = 1; i < subitemsCount; i++) {
  38512. incHex(char, ucs2DataSize);
  38513. if (!sequence) {
  38514. stream.readHexNumber(tmp, ucs2DataSize);
  38515. addHex(char, tmp, ucs2DataSize);
  38516. }
  38517. incHex(charCode, dataSize);
  38518. stream.readHexSigned(tmp, dataSize);
  38519. addHex(charCode, tmp, dataSize);
  38520. cMap.mapOne(hexToInt(char, ucs2DataSize), hexToStr(charCode, dataSize));
  38521. }
  38522. break;
  38523. case 5:
  38524. // bfrange
  38525. stream.readHex(start, ucs2DataSize);
  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. for (i = 1; i < subitemsCount; i++) {
  38531. incHex(end, ucs2DataSize);
  38532. if (!sequence) {
  38533. stream.readHexNumber(start, ucs2DataSize);
  38534. addHex(start, end, ucs2DataSize);
  38535. } else {
  38536. start.set(end);
  38537. }
  38538. stream.readHexNumber(end, ucs2DataSize);
  38539. addHex(end, start, ucs2DataSize);
  38540. stream.readHex(charCode, dataSize);
  38541. cMap.mapBfRange(hexToInt(start, ucs2DataSize), hexToInt(end, ucs2DataSize), hexToStr(charCode, dataSize));
  38542. }
  38543. break;
  38544. default:
  38545. error('Unknown type: ' + type);
  38546. break;
  38547. }
  38548. }
  38549. if (useCMap) {
  38550. return extend(useCMap);
  38551. }
  38552. return cMap;
  38553. });
  38554. }
  38555. function BinaryCMapReader() {
  38556. }
  38557. BinaryCMapReader.prototype = { read: processBinaryCMap };
  38558. return BinaryCMapReader;
  38559. }();
  38560. var CMapFactory = function CMapFactoryClosure() {
  38561. function strToInt(str) {
  38562. var a = 0;
  38563. for (var i = 0; i < str.length; i++) {
  38564. a = a << 8 | str.charCodeAt(i);
  38565. }
  38566. return a >>> 0;
  38567. }
  38568. function expectString(obj) {
  38569. if (!isString(obj)) {
  38570. error('Malformed CMap: expected string.');
  38571. }
  38572. }
  38573. function expectInt(obj) {
  38574. if (!isInt(obj)) {
  38575. error('Malformed CMap: expected int.');
  38576. }
  38577. }
  38578. function parseBfChar(cMap, lexer) {
  38579. while (true) {
  38580. var obj = lexer.getObj();
  38581. if (isEOF(obj)) {
  38582. break;
  38583. }
  38584. if (isCmd(obj, 'endbfchar')) {
  38585. return;
  38586. }
  38587. expectString(obj);
  38588. var src = strToInt(obj);
  38589. obj = lexer.getObj();
  38590. // TODO are /dstName used?
  38591. expectString(obj);
  38592. var dst = obj;
  38593. cMap.mapOne(src, dst);
  38594. }
  38595. }
  38596. function parseBfRange(cMap, lexer) {
  38597. while (true) {
  38598. var obj = lexer.getObj();
  38599. if (isEOF(obj)) {
  38600. break;
  38601. }
  38602. if (isCmd(obj, 'endbfrange')) {
  38603. return;
  38604. }
  38605. expectString(obj);
  38606. var low = strToInt(obj);
  38607. obj = lexer.getObj();
  38608. expectString(obj);
  38609. var high = strToInt(obj);
  38610. obj = lexer.getObj();
  38611. if (isInt(obj) || isString(obj)) {
  38612. var dstLow = isInt(obj) ? String.fromCharCode(obj) : obj;
  38613. cMap.mapBfRange(low, high, dstLow);
  38614. } else if (isCmd(obj, '[')) {
  38615. obj = lexer.getObj();
  38616. var array = [];
  38617. while (!isCmd(obj, ']') && !isEOF(obj)) {
  38618. array.push(obj);
  38619. obj = lexer.getObj();
  38620. }
  38621. cMap.mapBfRangeToArray(low, high, array);
  38622. } else {
  38623. break;
  38624. }
  38625. }
  38626. error('Invalid bf range.');
  38627. }
  38628. function parseCidChar(cMap, lexer) {
  38629. while (true) {
  38630. var obj = lexer.getObj();
  38631. if (isEOF(obj)) {
  38632. break;
  38633. }
  38634. if (isCmd(obj, 'endcidchar')) {
  38635. return;
  38636. }
  38637. expectString(obj);
  38638. var src = strToInt(obj);
  38639. obj = lexer.getObj();
  38640. expectInt(obj);
  38641. var dst = obj;
  38642. cMap.mapOne(src, dst);
  38643. }
  38644. }
  38645. function parseCidRange(cMap, lexer) {
  38646. while (true) {
  38647. var obj = lexer.getObj();
  38648. if (isEOF(obj)) {
  38649. break;
  38650. }
  38651. if (isCmd(obj, 'endcidrange')) {
  38652. return;
  38653. }
  38654. expectString(obj);
  38655. var low = strToInt(obj);
  38656. obj = lexer.getObj();
  38657. expectString(obj);
  38658. var high = strToInt(obj);
  38659. obj = lexer.getObj();
  38660. expectInt(obj);
  38661. var dstLow = obj;
  38662. cMap.mapCidRange(low, high, dstLow);
  38663. }
  38664. }
  38665. function parseCodespaceRange(cMap, lexer) {
  38666. while (true) {
  38667. var obj = lexer.getObj();
  38668. if (isEOF(obj)) {
  38669. break;
  38670. }
  38671. if (isCmd(obj, 'endcodespacerange')) {
  38672. return;
  38673. }
  38674. if (!isString(obj)) {
  38675. break;
  38676. }
  38677. var low = strToInt(obj);
  38678. obj = lexer.getObj();
  38679. if (!isString(obj)) {
  38680. break;
  38681. }
  38682. var high = strToInt(obj);
  38683. cMap.addCodespaceRange(obj.length, low, high);
  38684. }
  38685. error('Invalid codespace range.');
  38686. }
  38687. function parseWMode(cMap, lexer) {
  38688. var obj = lexer.getObj();
  38689. if (isInt(obj)) {
  38690. cMap.vertical = !!obj;
  38691. }
  38692. }
  38693. function parseCMapName(cMap, lexer) {
  38694. var obj = lexer.getObj();
  38695. if (isName(obj) && isString(obj.name)) {
  38696. cMap.name = obj.name;
  38697. }
  38698. }
  38699. function parseCMap(cMap, lexer, builtInCMapParams, useCMap) {
  38700. var previous;
  38701. var embededUseCMap;
  38702. objLoop:
  38703. while (true) {
  38704. try {
  38705. var obj = lexer.getObj();
  38706. if (isEOF(obj)) {
  38707. break;
  38708. } else if (isName(obj)) {
  38709. if (obj.name === 'WMode') {
  38710. parseWMode(cMap, lexer);
  38711. } else if (obj.name === 'CMapName') {
  38712. parseCMapName(cMap, lexer);
  38713. }
  38714. previous = obj;
  38715. } else if (isCmd(obj)) {
  38716. switch (obj.cmd) {
  38717. case 'endcmap':
  38718. break objLoop;
  38719. case 'usecmap':
  38720. if (isName(previous)) {
  38721. embededUseCMap = previous.name;
  38722. }
  38723. break;
  38724. case 'begincodespacerange':
  38725. parseCodespaceRange(cMap, lexer);
  38726. break;
  38727. case 'beginbfchar':
  38728. parseBfChar(cMap, lexer);
  38729. break;
  38730. case 'begincidchar':
  38731. parseCidChar(cMap, lexer);
  38732. break;
  38733. case 'beginbfrange':
  38734. parseBfRange(cMap, lexer);
  38735. break;
  38736. case 'begincidrange':
  38737. parseCidRange(cMap, lexer);
  38738. break;
  38739. }
  38740. }
  38741. } catch (ex) {
  38742. if (ex instanceof MissingDataException) {
  38743. throw ex;
  38744. }
  38745. warn('Invalid cMap data: ' + ex);
  38746. continue;
  38747. }
  38748. }
  38749. if (!useCMap && embededUseCMap) {
  38750. // Load the usecmap definition from the file only if there wasn't one
  38751. // specified.
  38752. useCMap = embededUseCMap;
  38753. }
  38754. if (useCMap) {
  38755. return extendCMap(cMap, builtInCMapParams, useCMap);
  38756. }
  38757. return Promise.resolve(cMap);
  38758. }
  38759. function extendCMap(cMap, builtInCMapParams, useCMap) {
  38760. return createBuiltInCMap(useCMap, builtInCMapParams).then(function (newCMap) {
  38761. cMap.useCMap = newCMap;
  38762. // If there aren't any code space ranges defined clone all the parent ones
  38763. // into this cMap.
  38764. if (cMap.numCodespaceRanges === 0) {
  38765. var useCodespaceRanges = cMap.useCMap.codespaceRanges;
  38766. for (var i = 0; i < useCodespaceRanges.length; i++) {
  38767. cMap.codespaceRanges[i] = useCodespaceRanges[i].slice();
  38768. }
  38769. cMap.numCodespaceRanges = cMap.useCMap.numCodespaceRanges;
  38770. }
  38771. // Merge the map into the current one, making sure not to override
  38772. // any previously defined entries.
  38773. cMap.useCMap.forEach(function (key, value) {
  38774. if (!cMap.contains(key)) {
  38775. cMap.mapOne(key, cMap.useCMap.lookup(key));
  38776. }
  38777. });
  38778. return cMap;
  38779. });
  38780. }
  38781. function parseBinaryCMap(name, builtInCMapParams) {
  38782. var url = builtInCMapParams.url + name + '.bcmap';
  38783. var cMap = new CMap(true);
  38784. return new BinaryCMapReader().read(url, cMap, function (useCMap) {
  38785. return extendCMap(cMap, builtInCMapParams, useCMap);
  38786. });
  38787. }
  38788. function createBuiltInCMap(name, builtInCMapParams) {
  38789. if (name === 'Identity-H') {
  38790. return Promise.resolve(new IdentityCMap(false, 2));
  38791. } else if (name === 'Identity-V') {
  38792. return Promise.resolve(new IdentityCMap(true, 2));
  38793. }
  38794. if (BUILT_IN_CMAPS.indexOf(name) === -1) {
  38795. return Promise.reject(new Error('Unknown cMap name: ' + name));
  38796. }
  38797. assert(builtInCMapParams, 'built-in cMap parameters are not provided');
  38798. if (builtInCMapParams.packed) {
  38799. return parseBinaryCMap(name, builtInCMapParams);
  38800. }
  38801. return new Promise(function (resolve, reject) {
  38802. var url = builtInCMapParams.url + name;
  38803. var request = new XMLHttpRequest();
  38804. request.onreadystatechange = function () {
  38805. if (request.readyState === XMLHttpRequest.DONE) {
  38806. if (request.status === 200 || request.status === 0) {
  38807. var cMap = new CMap(true);
  38808. var lexer = new Lexer(new StringStream(request.responseText));
  38809. parseCMap(cMap, lexer, builtInCMapParams, null).then(function (parsedCMap) {
  38810. resolve(parsedCMap);
  38811. });
  38812. } else {
  38813. reject(new Error('Unable to get cMap at: ' + url));
  38814. }
  38815. }
  38816. };
  38817. request.open('GET', url, true);
  38818. request.send(null);
  38819. });
  38820. }
  38821. return {
  38822. create: function (encoding, builtInCMapParams, useCMap) {
  38823. if (isName(encoding)) {
  38824. return createBuiltInCMap(encoding.name, builtInCMapParams);
  38825. } else if (isStream(encoding)) {
  38826. var cMap = new CMap();
  38827. var lexer = new Lexer(encoding);
  38828. return parseCMap(cMap, lexer, builtInCMapParams, useCMap).then(function (parsedCMap) {
  38829. if (parsedCMap.isIdentityCMap) {
  38830. return createBuiltInCMap(parsedCMap.name, builtInCMapParams);
  38831. }
  38832. return parsedCMap;
  38833. });
  38834. }
  38835. return Promise.reject(new Error('Encoding required.'));
  38836. }
  38837. };
  38838. }();
  38839. exports.CMap = CMap;
  38840. exports.CMapFactory = CMapFactory;
  38841. exports.IdentityCMap = IdentityCMap;
  38842. }));
  38843. (function (root, factory) {
  38844. factory(root.pdfjsCoreFonts = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreGlyphList, root.pdfjsCoreFontRenderer, root.pdfjsCoreEncodings, root.pdfjsCoreStandardFonts, root.pdfjsCoreUnicode, root.pdfjsCoreType1Parser, root.pdfjsCoreCFFParser);
  38845. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreGlyphList, coreFontRenderer, coreEncodings, coreStandardFonts, coreUnicode, coreType1Parser, coreCFFParser) {
  38846. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  38847. var FontType = sharedUtil.FontType;
  38848. var assert = sharedUtil.assert;
  38849. var bytesToString = sharedUtil.bytesToString;
  38850. var error = sharedUtil.error;
  38851. var info = sharedUtil.info;
  38852. var isArray = sharedUtil.isArray;
  38853. var isInt = sharedUtil.isInt;
  38854. var isNum = sharedUtil.isNum;
  38855. var readUint32 = sharedUtil.readUint32;
  38856. var shadow = sharedUtil.shadow;
  38857. var string32 = sharedUtil.string32;
  38858. var warn = sharedUtil.warn;
  38859. var MissingDataException = sharedUtil.MissingDataException;
  38860. var isSpace = sharedUtil.isSpace;
  38861. var Stream = coreStream.Stream;
  38862. var getGlyphsUnicode = coreGlyphList.getGlyphsUnicode;
  38863. var getDingbatsGlyphsUnicode = coreGlyphList.getDingbatsGlyphsUnicode;
  38864. var FontRendererFactory = coreFontRenderer.FontRendererFactory;
  38865. var StandardEncoding = coreEncodings.StandardEncoding;
  38866. var MacRomanEncoding = coreEncodings.MacRomanEncoding;
  38867. var SymbolSetEncoding = coreEncodings.SymbolSetEncoding;
  38868. var ZapfDingbatsEncoding = coreEncodings.ZapfDingbatsEncoding;
  38869. var getEncoding = coreEncodings.getEncoding;
  38870. var getStdFontMap = coreStandardFonts.getStdFontMap;
  38871. var getNonStdFontMap = coreStandardFonts.getNonStdFontMap;
  38872. var getGlyphMapForStandardFonts = coreStandardFonts.getGlyphMapForStandardFonts;
  38873. var getSupplementalGlyphMapForArialBlack = coreStandardFonts.getSupplementalGlyphMapForArialBlack;
  38874. var getUnicodeRangeFor = coreUnicode.getUnicodeRangeFor;
  38875. var mapSpecialUnicodeValues = coreUnicode.mapSpecialUnicodeValues;
  38876. var getUnicodeForGlyph = coreUnicode.getUnicodeForGlyph;
  38877. var Type1Parser = coreType1Parser.Type1Parser;
  38878. var CFFStandardStrings = coreCFFParser.CFFStandardStrings;
  38879. var CFFParser = coreCFFParser.CFFParser;
  38880. var CFFCompiler = coreCFFParser.CFFCompiler;
  38881. var CFF = coreCFFParser.CFF;
  38882. var CFFHeader = coreCFFParser.CFFHeader;
  38883. var CFFTopDict = coreCFFParser.CFFTopDict;
  38884. var CFFPrivateDict = coreCFFParser.CFFPrivateDict;
  38885. var CFFStrings = coreCFFParser.CFFStrings;
  38886. var CFFIndex = coreCFFParser.CFFIndex;
  38887. var CFFCharset = coreCFFParser.CFFCharset;
  38888. // Unicode Private Use Area
  38889. var PRIVATE_USE_OFFSET_START = 0xE000;
  38890. var PRIVATE_USE_OFFSET_END = 0xF8FF;
  38891. var SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = false;
  38892. // PDF Glyph Space Units are one Thousandth of a TextSpace Unit
  38893. // except for Type 3 fonts
  38894. var PDF_GLYPH_SPACE_UNITS = 1000;
  38895. // Accented charactars are not displayed properly on Windows, using this flag
  38896. // to control analysis of seac charstrings.
  38897. var SEAC_ANALYSIS_ENABLED = false;
  38898. var FontFlags = {
  38899. FixedPitch: 1,
  38900. Serif: 2,
  38901. Symbolic: 4,
  38902. Script: 8,
  38903. Nonsymbolic: 32,
  38904. Italic: 64,
  38905. AllCap: 65536,
  38906. SmallCap: 131072,
  38907. ForceBold: 262144
  38908. };
  38909. var MacStandardGlyphOrdering = [
  38910. '.notdef',
  38911. '.null',
  38912. 'nonmarkingreturn',
  38913. 'space',
  38914. 'exclam',
  38915. 'quotedbl',
  38916. 'numbersign',
  38917. 'dollar',
  38918. 'percent',
  38919. 'ampersand',
  38920. 'quotesingle',
  38921. 'parenleft',
  38922. 'parenright',
  38923. 'asterisk',
  38924. 'plus',
  38925. 'comma',
  38926. 'hyphen',
  38927. 'period',
  38928. 'slash',
  38929. 'zero',
  38930. 'one',
  38931. 'two',
  38932. 'three',
  38933. 'four',
  38934. 'five',
  38935. 'six',
  38936. 'seven',
  38937. 'eight',
  38938. 'nine',
  38939. 'colon',
  38940. 'semicolon',
  38941. 'less',
  38942. 'equal',
  38943. 'greater',
  38944. 'question',
  38945. 'at',
  38946. 'A',
  38947. 'B',
  38948. 'C',
  38949. 'D',
  38950. 'E',
  38951. 'F',
  38952. 'G',
  38953. 'H',
  38954. 'I',
  38955. 'J',
  38956. 'K',
  38957. 'L',
  38958. 'M',
  38959. 'N',
  38960. 'O',
  38961. 'P',
  38962. 'Q',
  38963. 'R',
  38964. 'S',
  38965. 'T',
  38966. 'U',
  38967. 'V',
  38968. 'W',
  38969. 'X',
  38970. 'Y',
  38971. 'Z',
  38972. 'bracketleft',
  38973. 'backslash',
  38974. 'bracketright',
  38975. 'asciicircum',
  38976. 'underscore',
  38977. 'grave',
  38978. 'a',
  38979. 'b',
  38980. 'c',
  38981. 'd',
  38982. 'e',
  38983. 'f',
  38984. 'g',
  38985. 'h',
  38986. 'i',
  38987. 'j',
  38988. 'k',
  38989. 'l',
  38990. 'm',
  38991. 'n',
  38992. 'o',
  38993. 'p',
  38994. 'q',
  38995. 'r',
  38996. 's',
  38997. 't',
  38998. 'u',
  38999. 'v',
  39000. 'w',
  39001. 'x',
  39002. 'y',
  39003. 'z',
  39004. 'braceleft',
  39005. 'bar',
  39006. 'braceright',
  39007. 'asciitilde',
  39008. 'Adieresis',
  39009. 'Aring',
  39010. 'Ccedilla',
  39011. 'Eacute',
  39012. 'Ntilde',
  39013. 'Odieresis',
  39014. 'Udieresis',
  39015. 'aacute',
  39016. 'agrave',
  39017. 'acircumflex',
  39018. 'adieresis',
  39019. 'atilde',
  39020. 'aring',
  39021. 'ccedilla',
  39022. 'eacute',
  39023. 'egrave',
  39024. 'ecircumflex',
  39025. 'edieresis',
  39026. 'iacute',
  39027. 'igrave',
  39028. 'icircumflex',
  39029. 'idieresis',
  39030. 'ntilde',
  39031. 'oacute',
  39032. 'ograve',
  39033. 'ocircumflex',
  39034. 'odieresis',
  39035. 'otilde',
  39036. 'uacute',
  39037. 'ugrave',
  39038. 'ucircumflex',
  39039. 'udieresis',
  39040. 'dagger',
  39041. 'degree',
  39042. 'cent',
  39043. 'sterling',
  39044. 'section',
  39045. 'bullet',
  39046. 'paragraph',
  39047. 'germandbls',
  39048. 'registered',
  39049. 'copyright',
  39050. 'trademark',
  39051. 'acute',
  39052. 'dieresis',
  39053. 'notequal',
  39054. 'AE',
  39055. 'Oslash',
  39056. 'infinity',
  39057. 'plusminus',
  39058. 'lessequal',
  39059. 'greaterequal',
  39060. 'yen',
  39061. 'mu',
  39062. 'partialdiff',
  39063. 'summation',
  39064. 'product',
  39065. 'pi',
  39066. 'integral',
  39067. 'ordfeminine',
  39068. 'ordmasculine',
  39069. 'Omega',
  39070. 'ae',
  39071. 'oslash',
  39072. 'questiondown',
  39073. 'exclamdown',
  39074. 'logicalnot',
  39075. 'radical',
  39076. 'florin',
  39077. 'approxequal',
  39078. 'Delta',
  39079. 'guillemotleft',
  39080. 'guillemotright',
  39081. 'ellipsis',
  39082. 'nonbreakingspace',
  39083. 'Agrave',
  39084. 'Atilde',
  39085. 'Otilde',
  39086. 'OE',
  39087. 'oe',
  39088. 'endash',
  39089. 'emdash',
  39090. 'quotedblleft',
  39091. 'quotedblright',
  39092. 'quoteleft',
  39093. 'quoteright',
  39094. 'divide',
  39095. 'lozenge',
  39096. 'ydieresis',
  39097. 'Ydieresis',
  39098. 'fraction',
  39099. 'currency',
  39100. 'guilsinglleft',
  39101. 'guilsinglright',
  39102. 'fi',
  39103. 'fl',
  39104. 'daggerdbl',
  39105. 'periodcentered',
  39106. 'quotesinglbase',
  39107. 'quotedblbase',
  39108. 'perthousand',
  39109. 'Acircumflex',
  39110. 'Ecircumflex',
  39111. 'Aacute',
  39112. 'Edieresis',
  39113. 'Egrave',
  39114. 'Iacute',
  39115. 'Icircumflex',
  39116. 'Idieresis',
  39117. 'Igrave',
  39118. 'Oacute',
  39119. 'Ocircumflex',
  39120. 'apple',
  39121. 'Ograve',
  39122. 'Uacute',
  39123. 'Ucircumflex',
  39124. 'Ugrave',
  39125. 'dotlessi',
  39126. 'circumflex',
  39127. 'tilde',
  39128. 'macron',
  39129. 'breve',
  39130. 'dotaccent',
  39131. 'ring',
  39132. 'cedilla',
  39133. 'hungarumlaut',
  39134. 'ogonek',
  39135. 'caron',
  39136. 'Lslash',
  39137. 'lslash',
  39138. 'Scaron',
  39139. 'scaron',
  39140. 'Zcaron',
  39141. 'zcaron',
  39142. 'brokenbar',
  39143. 'Eth',
  39144. 'eth',
  39145. 'Yacute',
  39146. 'yacute',
  39147. 'Thorn',
  39148. 'thorn',
  39149. 'minus',
  39150. 'multiply',
  39151. 'onesuperior',
  39152. 'twosuperior',
  39153. 'threesuperior',
  39154. 'onehalf',
  39155. 'onequarter',
  39156. 'threequarters',
  39157. 'franc',
  39158. 'Gbreve',
  39159. 'gbreve',
  39160. 'Idotaccent',
  39161. 'Scedilla',
  39162. 'scedilla',
  39163. 'Cacute',
  39164. 'cacute',
  39165. 'Ccaron',
  39166. 'ccaron',
  39167. 'dcroat'
  39168. ];
  39169. function adjustWidths(properties) {
  39170. if (!properties.fontMatrix) {
  39171. return;
  39172. }
  39173. if (properties.fontMatrix[0] === FONT_IDENTITY_MATRIX[0]) {
  39174. return;
  39175. }
  39176. // adjusting width to fontMatrix scale
  39177. var scale = 0.001 / properties.fontMatrix[0];
  39178. var glyphsWidths = properties.widths;
  39179. for (var glyph in glyphsWidths) {
  39180. glyphsWidths[glyph] *= scale;
  39181. }
  39182. properties.defaultWidth *= scale;
  39183. }
  39184. function adjustToUnicode(properties, builtInEncoding) {
  39185. if (properties.hasIncludedToUnicodeMap) {
  39186. return;
  39187. }
  39188. // The font dictionary has a `ToUnicode` entry.
  39189. if (properties.hasEncoding) {
  39190. return;
  39191. }
  39192. // The font dictionary has an `Encoding` entry.
  39193. if (builtInEncoding === properties.defaultEncoding) {
  39194. return;
  39195. }
  39196. // No point in trying to adjust `toUnicode` if the encodings match.
  39197. if (properties.toUnicode instanceof IdentityToUnicodeMap) {
  39198. return;
  39199. }
  39200. var toUnicode = [], glyphsUnicodeMap = getGlyphsUnicode();
  39201. for (var charCode in builtInEncoding) {
  39202. var glyphName = builtInEncoding[charCode];
  39203. var unicode = getUnicodeForGlyph(glyphName, glyphsUnicodeMap);
  39204. if (unicode !== -1) {
  39205. toUnicode[charCode] = String.fromCharCode(unicode);
  39206. }
  39207. }
  39208. properties.toUnicode.amend(toUnicode);
  39209. }
  39210. function getFontType(type, subtype) {
  39211. switch (type) {
  39212. case 'Type1':
  39213. return subtype === 'Type1C' ? FontType.TYPE1C : FontType.TYPE1;
  39214. case 'CIDFontType0':
  39215. return subtype === 'CIDFontType0C' ? FontType.CIDFONTTYPE0C : FontType.CIDFONTTYPE0;
  39216. case 'OpenType':
  39217. return FontType.OPENTYPE;
  39218. case 'TrueType':
  39219. return FontType.TRUETYPE;
  39220. case 'CIDFontType2':
  39221. return FontType.CIDFONTTYPE2;
  39222. case 'MMType1':
  39223. return FontType.MMTYPE1;
  39224. case 'Type0':
  39225. return FontType.TYPE0;
  39226. default:
  39227. return FontType.UNKNOWN;
  39228. }
  39229. }
  39230. // Some bad PDF generators, e.g. Scribus PDF, include glyph names
  39231. // in a 'uniXXXX' format -- attempting to recover proper ones.
  39232. function recoverGlyphName(name, glyphsUnicodeMap) {
  39233. if (glyphsUnicodeMap[name] !== undefined) {
  39234. return name;
  39235. }
  39236. // The glyph name is non-standard, trying to recover.
  39237. var unicode = getUnicodeForGlyph(name, glyphsUnicodeMap);
  39238. if (unicode !== -1) {
  39239. for (var key in glyphsUnicodeMap) {
  39240. if (glyphsUnicodeMap[key] === unicode) {
  39241. return key;
  39242. }
  39243. }
  39244. }
  39245. info('Unable to recover a standard glyph name for: ' + name);
  39246. return name;
  39247. }
  39248. var Glyph = function GlyphClosure() {
  39249. function Glyph(fontChar, unicode, accent, width, vmetric, operatorListId, isSpace, isInFont) {
  39250. this.fontChar = fontChar;
  39251. this.unicode = unicode;
  39252. this.accent = accent;
  39253. this.width = width;
  39254. this.vmetric = vmetric;
  39255. this.operatorListId = operatorListId;
  39256. this.isSpace = isSpace;
  39257. this.isInFont = isInFont;
  39258. }
  39259. Glyph.prototype.matchesForCache = function (fontChar, unicode, accent, width, vmetric, operatorListId, isSpace, isInFont) {
  39260. 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;
  39261. };
  39262. return Glyph;
  39263. }();
  39264. var ToUnicodeMap = function ToUnicodeMapClosure() {
  39265. function ToUnicodeMap(cmap) {
  39266. // The elements of this._map can be integers or strings, depending on how
  39267. // |cmap| was created.
  39268. this._map = cmap;
  39269. }
  39270. ToUnicodeMap.prototype = {
  39271. get length() {
  39272. return this._map.length;
  39273. },
  39274. forEach: function (callback) {
  39275. for (var charCode in this._map) {
  39276. callback(charCode, this._map[charCode].charCodeAt(0));
  39277. }
  39278. },
  39279. has: function (i) {
  39280. return this._map[i] !== undefined;
  39281. },
  39282. get: function (i) {
  39283. return this._map[i];
  39284. },
  39285. charCodeOf: function (v) {
  39286. return this._map.indexOf(v);
  39287. },
  39288. amend: function (map) {
  39289. for (var charCode in map) {
  39290. this._map[charCode] = map[charCode];
  39291. }
  39292. }
  39293. };
  39294. return ToUnicodeMap;
  39295. }();
  39296. var IdentityToUnicodeMap = function IdentityToUnicodeMapClosure() {
  39297. function IdentityToUnicodeMap(firstChar, lastChar) {
  39298. this.firstChar = firstChar;
  39299. this.lastChar = lastChar;
  39300. }
  39301. IdentityToUnicodeMap.prototype = {
  39302. get length() {
  39303. return this.lastChar + 1 - this.firstChar;
  39304. },
  39305. forEach: function (callback) {
  39306. for (var i = this.firstChar, ii = this.lastChar; i <= ii; i++) {
  39307. callback(i, i);
  39308. }
  39309. },
  39310. has: function (i) {
  39311. return this.firstChar <= i && i <= this.lastChar;
  39312. },
  39313. get: function (i) {
  39314. if (this.firstChar <= i && i <= this.lastChar) {
  39315. return String.fromCharCode(i);
  39316. }
  39317. return undefined;
  39318. },
  39319. charCodeOf: function (v) {
  39320. return isInt(v) && v >= this.firstChar && v <= this.lastChar ? v : -1;
  39321. },
  39322. amend: function (map) {
  39323. error('Should not call amend()');
  39324. }
  39325. };
  39326. return IdentityToUnicodeMap;
  39327. }();
  39328. var OpenTypeFileBuilder = function OpenTypeFileBuilderClosure() {
  39329. function writeInt16(dest, offset, num) {
  39330. dest[offset] = num >> 8 & 0xFF;
  39331. dest[offset + 1] = num & 0xFF;
  39332. }
  39333. function writeInt32(dest, offset, num) {
  39334. dest[offset] = num >> 24 & 0xFF;
  39335. dest[offset + 1] = num >> 16 & 0xFF;
  39336. dest[offset + 2] = num >> 8 & 0xFF;
  39337. dest[offset + 3] = num & 0xFF;
  39338. }
  39339. function writeData(dest, offset, data) {
  39340. var i, ii;
  39341. if (data instanceof Uint8Array) {
  39342. dest.set(data, offset);
  39343. } else if (typeof data === 'string') {
  39344. for (i = 0, ii = data.length; i < ii; i++) {
  39345. dest[offset++] = data.charCodeAt(i) & 0xFF;
  39346. }
  39347. } else {
  39348. // treating everything else as array
  39349. for (i = 0, ii = data.length; i < ii; i++) {
  39350. dest[offset++] = data[i] & 0xFF;
  39351. }
  39352. }
  39353. }
  39354. function OpenTypeFileBuilder(sfnt) {
  39355. this.sfnt = sfnt;
  39356. this.tables = Object.create(null);
  39357. }
  39358. OpenTypeFileBuilder.getSearchParams = function OpenTypeFileBuilder_getSearchParams(entriesCount, entrySize) {
  39359. var maxPower2 = 1, log2 = 0;
  39360. while ((maxPower2 ^ entriesCount) > maxPower2) {
  39361. maxPower2 <<= 1;
  39362. log2++;
  39363. }
  39364. var searchRange = maxPower2 * entrySize;
  39365. return {
  39366. range: searchRange,
  39367. entry: log2,
  39368. rangeShift: entrySize * entriesCount - searchRange
  39369. };
  39370. };
  39371. var OTF_HEADER_SIZE = 12;
  39372. var OTF_TABLE_ENTRY_SIZE = 16;
  39373. OpenTypeFileBuilder.prototype = {
  39374. toArray: function OpenTypeFileBuilder_toArray() {
  39375. var sfnt = this.sfnt;
  39376. // Tables needs to be written by ascendant alphabetic order
  39377. var tables = this.tables;
  39378. var tablesNames = Object.keys(tables);
  39379. tablesNames.sort();
  39380. var numTables = tablesNames.length;
  39381. var i, j, jj, table, tableName;
  39382. // layout the tables data
  39383. var offset = OTF_HEADER_SIZE + numTables * OTF_TABLE_ENTRY_SIZE;
  39384. var tableOffsets = [offset];
  39385. for (i = 0; i < numTables; i++) {
  39386. table = tables[tablesNames[i]];
  39387. var paddedLength = (table.length + 3 & ~3) >>> 0;
  39388. offset += paddedLength;
  39389. tableOffsets.push(offset);
  39390. }
  39391. var file = new Uint8Array(offset);
  39392. // write the table data first (mostly for checksum)
  39393. for (i = 0; i < numTables; i++) {
  39394. table = tables[tablesNames[i]];
  39395. writeData(file, tableOffsets[i], table);
  39396. }
  39397. // sfnt version (4 bytes)
  39398. if (sfnt === 'true') {
  39399. // Windows hates the Mac TrueType sfnt version number
  39400. sfnt = string32(0x00010000);
  39401. }
  39402. file[0] = sfnt.charCodeAt(0) & 0xFF;
  39403. file[1] = sfnt.charCodeAt(1) & 0xFF;
  39404. file[2] = sfnt.charCodeAt(2) & 0xFF;
  39405. file[3] = sfnt.charCodeAt(3) & 0xFF;
  39406. // numTables (2 bytes)
  39407. writeInt16(file, 4, numTables);
  39408. var searchParams = OpenTypeFileBuilder.getSearchParams(numTables, 16);
  39409. // searchRange (2 bytes)
  39410. writeInt16(file, 6, searchParams.range);
  39411. // entrySelector (2 bytes)
  39412. writeInt16(file, 8, searchParams.entry);
  39413. // rangeShift (2 bytes)
  39414. writeInt16(file, 10, searchParams.rangeShift);
  39415. offset = OTF_HEADER_SIZE;
  39416. // writing table entries
  39417. for (i = 0; i < numTables; i++) {
  39418. tableName = tablesNames[i];
  39419. file[offset] = tableName.charCodeAt(0) & 0xFF;
  39420. file[offset + 1] = tableName.charCodeAt(1) & 0xFF;
  39421. file[offset + 2] = tableName.charCodeAt(2) & 0xFF;
  39422. file[offset + 3] = tableName.charCodeAt(3) & 0xFF;
  39423. // checksum
  39424. var checksum = 0;
  39425. for (j = tableOffsets[i], jj = tableOffsets[i + 1]; j < jj; j += 4) {
  39426. var quad = readUint32(file, j);
  39427. checksum = checksum + quad >>> 0;
  39428. }
  39429. writeInt32(file, offset + 4, checksum);
  39430. // offset
  39431. writeInt32(file, offset + 8, tableOffsets[i]);
  39432. // length
  39433. writeInt32(file, offset + 12, tables[tableName].length);
  39434. offset += OTF_TABLE_ENTRY_SIZE;
  39435. }
  39436. return file;
  39437. },
  39438. addTable: function OpenTypeFileBuilder_addTable(tag, data) {
  39439. if (tag in this.tables) {
  39440. throw new Error('Table ' + tag + ' already exists');
  39441. }
  39442. this.tables[tag] = data;
  39443. }
  39444. };
  39445. return OpenTypeFileBuilder;
  39446. }();
  39447. // Problematic Unicode characters in the fonts that needs to be moved to avoid
  39448. // issues when they are painted on the canvas, e.g. complex-script shaping or
  39449. // control/whitespace characters. The ranges are listed in pairs: the first item
  39450. // is a code of the first problematic code, the second one is the next
  39451. // non-problematic code. The ranges must be in sorted order.
  39452. var ProblematicCharRanges = new Int32Array([
  39453. // Control characters.
  39454. 0x0000,
  39455. 0x0020,
  39456. 0x007F,
  39457. 0x00A1,
  39458. 0x00AD,
  39459. 0x00AE,
  39460. // Chars that is used in complex-script shaping.
  39461. 0x0600,
  39462. 0x0780,
  39463. 0x08A0,
  39464. 0x10A0,
  39465. 0x1780,
  39466. 0x1800,
  39467. 0x1C00,
  39468. 0x1C50,
  39469. // General punctuation chars.
  39470. 0x2000,
  39471. 0x2010,
  39472. 0x2011,
  39473. 0x2012,
  39474. 0x2028,
  39475. 0x2030,
  39476. 0x205F,
  39477. 0x2070,
  39478. 0x25CC,
  39479. 0x25CD,
  39480. 0x3000,
  39481. 0x3001,
  39482. // Chars that is used in complex-script shaping.
  39483. 0xAA60,
  39484. 0xAA80,
  39485. // Specials Unicode block.
  39486. 0xFFF0,
  39487. 0x10000
  39488. ]);
  39489. /**
  39490. * 'Font' is the class the outside world should use, it encapsulate all the font
  39491. * decoding logics whatever type it is (assuming the font type is supported).
  39492. *
  39493. * For example to read a Type1 font and to attach it to the document:
  39494. * var type1Font = new Font("MyFontName", binaryFile, propertiesObject);
  39495. * type1Font.bind();
  39496. */
  39497. var Font = function FontClosure() {
  39498. function Font(name, file, properties) {
  39499. var charCode, glyphName, unicode;
  39500. this.name = name;
  39501. this.loadedName = properties.loadedName;
  39502. this.isType3Font = properties.isType3Font;
  39503. this.sizes = [];
  39504. this.missingFile = false;
  39505. this.glyphCache = Object.create(null);
  39506. var names = name.split('+');
  39507. names = names.length > 1 ? names[1] : names[0];
  39508. names = names.split(/[-,_]/g)[0];
  39509. this.isSerifFont = !!(properties.flags & FontFlags.Serif);
  39510. this.isSymbolicFont = !!(properties.flags & FontFlags.Symbolic);
  39511. this.isMonospace = !!(properties.flags & FontFlags.FixedPitch);
  39512. var type = properties.type;
  39513. var subtype = properties.subtype;
  39514. this.type = type;
  39515. this.fallbackName = this.isMonospace ? 'monospace' : this.isSerifFont ? 'serif' : 'sans-serif';
  39516. this.differences = properties.differences;
  39517. this.widths = properties.widths;
  39518. this.defaultWidth = properties.defaultWidth;
  39519. this.composite = properties.composite;
  39520. this.wideChars = properties.wideChars;
  39521. this.cMap = properties.cMap;
  39522. this.ascent = properties.ascent / PDF_GLYPH_SPACE_UNITS;
  39523. this.descent = properties.descent / PDF_GLYPH_SPACE_UNITS;
  39524. this.fontMatrix = properties.fontMatrix;
  39525. this.bbox = properties.bbox;
  39526. this.toUnicode = properties.toUnicode;
  39527. this.toFontChar = [];
  39528. if (properties.type === 'Type3') {
  39529. for (charCode = 0; charCode < 256; charCode++) {
  39530. this.toFontChar[charCode] = this.differences[charCode] || properties.defaultEncoding[charCode];
  39531. }
  39532. this.fontType = FontType.TYPE3;
  39533. return;
  39534. }
  39535. this.cidEncoding = properties.cidEncoding;
  39536. this.vertical = properties.vertical;
  39537. if (this.vertical) {
  39538. this.vmetrics = properties.vmetrics;
  39539. this.defaultVMetrics = properties.defaultVMetrics;
  39540. }
  39541. var glyphsUnicodeMap;
  39542. if (!file || file.isEmpty) {
  39543. if (file) {
  39544. // Some bad PDF generators will include empty font files,
  39545. // attempting to recover by assuming that no file exists.
  39546. warn('Font file is empty in "' + name + '" (' + this.loadedName + ')');
  39547. }
  39548. this.missingFile = true;
  39549. // The file data is not specified. Trying to fix the font name
  39550. // to be used with the canvas.font.
  39551. var fontName = name.replace(/[,_]/g, '-');
  39552. var stdFontMap = getStdFontMap(), nonStdFontMap = getNonStdFontMap();
  39553. var isStandardFont = !!stdFontMap[fontName] || !!(nonStdFontMap[fontName] && stdFontMap[nonStdFontMap[fontName]]);
  39554. fontName = stdFontMap[fontName] || nonStdFontMap[fontName] || fontName;
  39555. this.bold = fontName.search(/bold/gi) !== -1;
  39556. this.italic = fontName.search(/oblique/gi) !== -1 || fontName.search(/italic/gi) !== -1;
  39557. // Use 'name' instead of 'fontName' here because the original
  39558. // name ArialBlack for example will be replaced by Helvetica.
  39559. this.black = name.search(/Black/g) !== -1;
  39560. // if at least one width is present, remeasure all chars when exists
  39561. this.remeasure = Object.keys(this.widths).length > 0;
  39562. if (isStandardFont && type === 'CIDFontType2' && properties.cidEncoding.indexOf('Identity-') === 0) {
  39563. var GlyphMapForStandardFonts = getGlyphMapForStandardFonts();
  39564. // Standard fonts might be embedded as CID font without glyph mapping.
  39565. // Building one based on GlyphMapForStandardFonts.
  39566. var map = [];
  39567. for (charCode in GlyphMapForStandardFonts) {
  39568. map[+charCode] = GlyphMapForStandardFonts[charCode];
  39569. }
  39570. if (/ArialBlack/i.test(name)) {
  39571. var SupplementalGlyphMapForArialBlack = getSupplementalGlyphMapForArialBlack();
  39572. for (charCode in SupplementalGlyphMapForArialBlack) {
  39573. map[+charCode] = SupplementalGlyphMapForArialBlack[charCode];
  39574. }
  39575. }
  39576. var isIdentityUnicode = this.toUnicode instanceof IdentityToUnicodeMap;
  39577. if (!isIdentityUnicode) {
  39578. this.toUnicode.forEach(function (charCode, unicodeCharCode) {
  39579. map[+charCode] = unicodeCharCode;
  39580. });
  39581. }
  39582. this.toFontChar = map;
  39583. this.toUnicode = new ToUnicodeMap(map);
  39584. } else if (/Symbol/i.test(fontName)) {
  39585. this.toFontChar = buildToFontChar(SymbolSetEncoding, getGlyphsUnicode(), properties.differences);
  39586. } else if (/Dingbats/i.test(fontName)) {
  39587. if (/Wingdings/i.test(name)) {
  39588. warn('Non-embedded Wingdings font, falling back to ZapfDingbats.');
  39589. }
  39590. this.toFontChar = buildToFontChar(ZapfDingbatsEncoding, getDingbatsGlyphsUnicode(), properties.differences);
  39591. } else if (isStandardFont) {
  39592. this.toFontChar = buildToFontChar(properties.defaultEncoding, getGlyphsUnicode(), properties.differences);
  39593. } else {
  39594. glyphsUnicodeMap = getGlyphsUnicode();
  39595. this.toUnicode.forEach(function (charCode, unicodeCharCode) {
  39596. if (!this.composite) {
  39597. glyphName = properties.differences[charCode] || properties.defaultEncoding[charCode];
  39598. unicode = getUnicodeForGlyph(glyphName, glyphsUnicodeMap);
  39599. if (unicode !== -1) {
  39600. unicodeCharCode = unicode;
  39601. }
  39602. }
  39603. this.toFontChar[charCode] = unicodeCharCode;
  39604. }.bind(this));
  39605. }
  39606. this.loadedName = fontName.split('-')[0];
  39607. this.loading = false;
  39608. this.fontType = getFontType(type, subtype);
  39609. return;
  39610. }
  39611. // Some fonts might use wrong font types for Type1C or CIDFontType0C
  39612. if (subtype === 'Type1C') {
  39613. if (type !== 'Type1' && type !== 'MMType1') {
  39614. // Some TrueType fonts by mistake claim Type1C
  39615. if (isTrueTypeFile(file)) {
  39616. subtype = 'TrueType';
  39617. } else {
  39618. type = 'Type1';
  39619. }
  39620. } else if (isOpenTypeFile(file)) {
  39621. // Sometimes the type/subtype can be a complete lie (see issue7598.pdf).
  39622. type = subtype = 'OpenType';
  39623. }
  39624. }
  39625. if (subtype === 'CIDFontType0C' && type !== 'CIDFontType0') {
  39626. type = 'CIDFontType0';
  39627. }
  39628. if (subtype === 'OpenType') {
  39629. type = 'OpenType';
  39630. }
  39631. // Some CIDFontType0C fonts by mistake claim CIDFontType0.
  39632. if (type === 'CIDFontType0') {
  39633. if (isType1File(file)) {
  39634. subtype = 'CIDFontType0';
  39635. } else if (isOpenTypeFile(file)) {
  39636. // Sometimes the type/subtype can be a complete lie (see issue6782.pdf).
  39637. type = subtype = 'OpenType';
  39638. } else {
  39639. subtype = 'CIDFontType0C';
  39640. }
  39641. }
  39642. var data;
  39643. switch (type) {
  39644. case 'MMType1':
  39645. info('MMType1 font (' + name + '), falling back to Type1.');
  39646. case 'Type1':
  39647. case 'CIDFontType0':
  39648. this.mimetype = 'font/opentype';
  39649. var cff = subtype === 'Type1C' || subtype === 'CIDFontType0C' ? new CFFFont(file, properties) : new Type1Font(name, file, properties);
  39650. adjustWidths(properties);
  39651. // Wrap the CFF data inside an OTF font file
  39652. data = this.convert(name, cff, properties);
  39653. break;
  39654. case 'OpenType':
  39655. case 'TrueType':
  39656. case 'CIDFontType2':
  39657. this.mimetype = 'font/opentype';
  39658. // Repair the TrueType file. It is can be damaged in the point of
  39659. // view of the sanitizer
  39660. data = this.checkAndRepair(name, file, properties);
  39661. if (this.isOpenType) {
  39662. adjustWidths(properties);
  39663. type = 'OpenType';
  39664. }
  39665. break;
  39666. default:
  39667. error('Font ' + type + ' is not supported');
  39668. break;
  39669. }
  39670. this.data = data;
  39671. this.fontType = getFontType(type, subtype);
  39672. // Transfer some properties again that could change during font conversion
  39673. this.fontMatrix = properties.fontMatrix;
  39674. this.widths = properties.widths;
  39675. this.defaultWidth = properties.defaultWidth;
  39676. this.toUnicode = properties.toUnicode;
  39677. this.encoding = properties.baseEncoding;
  39678. this.seacMap = properties.seacMap;
  39679. this.loading = true;
  39680. }
  39681. Font.getFontID = function () {
  39682. var ID = 1;
  39683. return function Font_getFontID() {
  39684. return String(ID++);
  39685. };
  39686. }();
  39687. function int16(b0, b1) {
  39688. return (b0 << 8) + b1;
  39689. }
  39690. function signedInt16(b0, b1) {
  39691. var value = (b0 << 8) + b1;
  39692. return value & 1 << 15 ? value - 0x10000 : value;
  39693. }
  39694. function int32(b0, b1, b2, b3) {
  39695. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  39696. }
  39697. function string16(value) {
  39698. return String.fromCharCode(value >> 8 & 0xff, value & 0xff);
  39699. }
  39700. function safeString16(value) {
  39701. // clamp value to the 16-bit int range
  39702. value = value > 0x7FFF ? 0x7FFF : value < -0x8000 ? -0x8000 : value;
  39703. return String.fromCharCode(value >> 8 & 0xff, value & 0xff);
  39704. }
  39705. function isTrueTypeFile(file) {
  39706. var header = file.peekBytes(4);
  39707. return readUint32(header, 0) === 0x00010000;
  39708. }
  39709. function isOpenTypeFile(file) {
  39710. var header = file.peekBytes(4);
  39711. return bytesToString(header) === 'OTTO';
  39712. }
  39713. function isType1File(file) {
  39714. var header = file.peekBytes(2);
  39715. // All Type1 font programs must begin with the comment '%!' (0x25 + 0x21).
  39716. if (header[0] === 0x25 && header[1] === 0x21) {
  39717. return true;
  39718. }
  39719. // ... obviously some fonts violate that part of the specification,
  39720. // please refer to the comment in |Type1Font| below.
  39721. if (header[0] === 0x80 && header[1] === 0x01) {
  39722. // pfb file header.
  39723. return true;
  39724. }
  39725. return false;
  39726. }
  39727. function buildToFontChar(encoding, glyphsUnicodeMap, differences) {
  39728. var toFontChar = [], unicode;
  39729. for (var i = 0, ii = encoding.length; i < ii; i++) {
  39730. unicode = getUnicodeForGlyph(encoding[i], glyphsUnicodeMap);
  39731. if (unicode !== -1) {
  39732. toFontChar[i] = unicode;
  39733. }
  39734. }
  39735. for (var charCode in differences) {
  39736. unicode = getUnicodeForGlyph(differences[charCode], glyphsUnicodeMap);
  39737. if (unicode !== -1) {
  39738. toFontChar[+charCode] = unicode;
  39739. }
  39740. }
  39741. return toFontChar;
  39742. }
  39743. /**
  39744. * Helper function for |adjustMapping|.
  39745. * @return {boolean}
  39746. */
  39747. function isProblematicUnicodeLocation(code) {
  39748. // Using binary search to find a range start.
  39749. var i = 0, j = ProblematicCharRanges.length - 1;
  39750. while (i < j) {
  39751. var c = i + j + 1 >> 1;
  39752. if (code < ProblematicCharRanges[c]) {
  39753. j = c - 1;
  39754. } else {
  39755. i = c;
  39756. }
  39757. }
  39758. // Even index means code in problematic range.
  39759. return !(i & 1);
  39760. }
  39761. /**
  39762. * Rebuilds the char code to glyph ID map by trying to replace the char codes
  39763. * with their unicode value. It also moves char codes that are in known
  39764. * problematic locations.
  39765. * @return {Object} Two properties:
  39766. * 'toFontChar' - maps original char codes(the value that will be read
  39767. * from commands such as show text) to the char codes that will be used in the
  39768. * font that we build
  39769. * 'charCodeToGlyphId' - maps the new font char codes to glyph ids
  39770. */
  39771. function adjustMapping(charCodeToGlyphId, properties) {
  39772. var toUnicode = properties.toUnicode;
  39773. var isSymbolic = !!(properties.flags & FontFlags.Symbolic);
  39774. var isIdentityUnicode = properties.toUnicode instanceof IdentityToUnicodeMap;
  39775. var newMap = Object.create(null);
  39776. var toFontChar = [];
  39777. var usedFontCharCodes = [];
  39778. var nextAvailableFontCharCode = PRIVATE_USE_OFFSET_START;
  39779. for (var originalCharCode in charCodeToGlyphId) {
  39780. originalCharCode |= 0;
  39781. var glyphId = charCodeToGlyphId[originalCharCode];
  39782. var fontCharCode = originalCharCode;
  39783. // First try to map the value to a unicode position if a non identity map
  39784. // was created.
  39785. if (!isIdentityUnicode && toUnicode.has(originalCharCode)) {
  39786. var unicode = toUnicode.get(fontCharCode);
  39787. // TODO: Try to map ligatures to the correct spot.
  39788. if (unicode.length === 1) {
  39789. fontCharCode = unicode.charCodeAt(0);
  39790. }
  39791. }
  39792. // Try to move control characters, special characters and already mapped
  39793. // characters to the private use area since they will not be drawn by
  39794. // canvas if left in their current position. Also, move characters if the
  39795. // font was symbolic and there is only an identity unicode map since the
  39796. // characters probably aren't in the correct position (fixes an issue
  39797. // with firefox and thuluthfont).
  39798. if ((usedFontCharCodes[fontCharCode] !== undefined || isProblematicUnicodeLocation(fontCharCode) || isSymbolic && isIdentityUnicode) && nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END) {
  39799. // Room left.
  39800. // Loop to try and find a free spot in the private use area.
  39801. do {
  39802. fontCharCode = nextAvailableFontCharCode++;
  39803. if (SKIP_PRIVATE_USE_RANGE_F000_TO_F01F && fontCharCode === 0xF000) {
  39804. fontCharCode = 0xF020;
  39805. nextAvailableFontCharCode = fontCharCode + 1;
  39806. }
  39807. } while (usedFontCharCodes[fontCharCode] !== undefined && nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END);
  39808. }
  39809. newMap[fontCharCode] = glyphId;
  39810. toFontChar[originalCharCode] = fontCharCode;
  39811. usedFontCharCodes[fontCharCode] = true;
  39812. }
  39813. return {
  39814. toFontChar: toFontChar,
  39815. charCodeToGlyphId: newMap,
  39816. nextAvailableFontCharCode: nextAvailableFontCharCode
  39817. };
  39818. }
  39819. function getRanges(glyphs, numGlyphs) {
  39820. // Array.sort() sorts by characters, not numerically, so convert to an
  39821. // array of characters.
  39822. var codes = [];
  39823. for (var charCode in glyphs) {
  39824. // Remove an invalid glyph ID mappings to make OTS happy.
  39825. if (glyphs[charCode] >= numGlyphs) {
  39826. continue;
  39827. }
  39828. codes.push({
  39829. fontCharCode: charCode | 0,
  39830. glyphId: glyphs[charCode]
  39831. });
  39832. }
  39833. codes.sort(function fontGetRangesSort(a, b) {
  39834. return a.fontCharCode - b.fontCharCode;
  39835. });
  39836. // Split the sorted codes into ranges.
  39837. var ranges = [];
  39838. var length = codes.length;
  39839. for (var n = 0; n < length;) {
  39840. var start = codes[n].fontCharCode;
  39841. var codeIndices = [codes[n].glyphId];
  39842. ++n;
  39843. var end = start;
  39844. while (n < length && end + 1 === codes[n].fontCharCode) {
  39845. codeIndices.push(codes[n].glyphId);
  39846. ++end;
  39847. ++n;
  39848. if (end === 0xFFFF) {
  39849. break;
  39850. }
  39851. }
  39852. ranges.push([
  39853. start,
  39854. end,
  39855. codeIndices
  39856. ]);
  39857. }
  39858. return ranges;
  39859. }
  39860. function createCmapTable(glyphs, numGlyphs) {
  39861. var ranges = getRanges(glyphs, numGlyphs);
  39862. var numTables = ranges[ranges.length - 1][1] > 0xFFFF ? 2 : 1;
  39863. var cmap = '\x00\x00' + // version
  39864. string16(numTables) + // numTables
  39865. '\x00\x03' + // platformID
  39866. '\x00\x01' + // encodingID
  39867. string32(4 + numTables * 8);
  39868. // start of the table record
  39869. var i, ii, j, jj;
  39870. for (i = ranges.length - 1; i >= 0; --i) {
  39871. if (ranges[i][0] <= 0xFFFF) {
  39872. break;
  39873. }
  39874. }
  39875. var bmpLength = i + 1;
  39876. if (ranges[i][0] < 0xFFFF && ranges[i][1] === 0xFFFF) {
  39877. ranges[i][1] = 0xFFFE;
  39878. }
  39879. var trailingRangesCount = ranges[i][1] < 0xFFFF ? 1 : 0;
  39880. var segCount = bmpLength + trailingRangesCount;
  39881. var searchParams = OpenTypeFileBuilder.getSearchParams(segCount, 2);
  39882. // Fill up the 4 parallel arrays describing the segments.
  39883. var startCount = '';
  39884. var endCount = '';
  39885. var idDeltas = '';
  39886. var idRangeOffsets = '';
  39887. var glyphsIds = '';
  39888. var bias = 0;
  39889. var range, start, end, codes;
  39890. for (i = 0, ii = bmpLength; i < ii; i++) {
  39891. range = ranges[i];
  39892. start = range[0];
  39893. end = range[1];
  39894. startCount += string16(start);
  39895. endCount += string16(end);
  39896. codes = range[2];
  39897. var contiguous = true;
  39898. for (j = 1, jj = codes.length; j < jj; ++j) {
  39899. if (codes[j] !== codes[j - 1] + 1) {
  39900. contiguous = false;
  39901. break;
  39902. }
  39903. }
  39904. if (!contiguous) {
  39905. var offset = (segCount - i) * 2 + bias * 2;
  39906. bias += end - start + 1;
  39907. idDeltas += string16(0);
  39908. idRangeOffsets += string16(offset);
  39909. for (j = 0, jj = codes.length; j < jj; ++j) {
  39910. glyphsIds += string16(codes[j]);
  39911. }
  39912. } else {
  39913. var startCode = codes[0];
  39914. idDeltas += string16(startCode - start & 0xFFFF);
  39915. idRangeOffsets += string16(0);
  39916. }
  39917. }
  39918. if (trailingRangesCount > 0) {
  39919. endCount += '\xFF\xFF';
  39920. startCount += '\xFF\xFF';
  39921. idDeltas += '\x00\x01';
  39922. idRangeOffsets += '\x00\x00';
  39923. }
  39924. var format314 = '\x00\x00' + // language
  39925. string16(2 * segCount) + string16(searchParams.range) + string16(searchParams.entry) + string16(searchParams.rangeShift) + endCount + '\x00\x00' + startCount + idDeltas + idRangeOffsets + glyphsIds;
  39926. var format31012 = '';
  39927. var header31012 = '';
  39928. if (numTables > 1) {
  39929. cmap += '\x00\x03' + // platformID
  39930. '\x00\x0A' + // encodingID
  39931. string32(4 + numTables * 8 + 4 + format314.length);
  39932. // start of the table record
  39933. format31012 = '';
  39934. for (i = 0, ii = ranges.length; i < ii; i++) {
  39935. range = ranges[i];
  39936. start = range[0];
  39937. codes = range[2];
  39938. var code = codes[0];
  39939. for (j = 1, jj = codes.length; j < jj; ++j) {
  39940. if (codes[j] !== codes[j - 1] + 1) {
  39941. end = range[0] + j - 1;
  39942. format31012 += string32(start) + // startCharCode
  39943. string32(end) + // endCharCode
  39944. string32(code);
  39945. // startGlyphID
  39946. start = end + 1;
  39947. code = codes[j];
  39948. }
  39949. }
  39950. format31012 += string32(start) + // startCharCode
  39951. string32(range[1]) + // endCharCode
  39952. string32(code);
  39953. }
  39954. // startGlyphID
  39955. header31012 = '\x00\x0C' + // format
  39956. '\x00\x00' + // reserved
  39957. string32(format31012.length + 16) + // length
  39958. '\x00\x00\x00\x00' + // language
  39959. string32(format31012.length / 12);
  39960. }
  39961. // nGroups
  39962. return cmap + '\x00\x04' + // format
  39963. string16(format314.length + 4) + // length
  39964. format314 + header31012 + format31012;
  39965. }
  39966. function validateOS2Table(os2) {
  39967. var stream = new Stream(os2.data);
  39968. var version = stream.getUint16();
  39969. // TODO verify all OS/2 tables fields, but currently we validate only those
  39970. // that give us issues
  39971. stream.getBytes(60);
  39972. // skipping type, misc sizes, panose, unicode ranges
  39973. var selection = stream.getUint16();
  39974. if (version < 4 && selection & 0x0300) {
  39975. return false;
  39976. }
  39977. var firstChar = stream.getUint16();
  39978. var lastChar = stream.getUint16();
  39979. if (firstChar > lastChar) {
  39980. return false;
  39981. }
  39982. stream.getBytes(6);
  39983. // skipping sTypoAscender/Descender/LineGap
  39984. var usWinAscent = stream.getUint16();
  39985. if (usWinAscent === 0) {
  39986. // makes font unreadable by windows
  39987. return false;
  39988. }
  39989. // OS/2 appears to be valid, resetting some fields
  39990. os2.data[8] = os2.data[9] = 0;
  39991. // IE rejects fonts if fsType != 0
  39992. return true;
  39993. }
  39994. function createOS2Table(properties, charstrings, override) {
  39995. override = override || {
  39996. unitsPerEm: 0,
  39997. yMax: 0,
  39998. yMin: 0,
  39999. ascent: 0,
  40000. descent: 0
  40001. };
  40002. var ulUnicodeRange1 = 0;
  40003. var ulUnicodeRange2 = 0;
  40004. var ulUnicodeRange3 = 0;
  40005. var ulUnicodeRange4 = 0;
  40006. var firstCharIndex = null;
  40007. var lastCharIndex = 0;
  40008. if (charstrings) {
  40009. for (var code in charstrings) {
  40010. code |= 0;
  40011. if (firstCharIndex > code || !firstCharIndex) {
  40012. firstCharIndex = code;
  40013. }
  40014. if (lastCharIndex < code) {
  40015. lastCharIndex = code;
  40016. }
  40017. var position = getUnicodeRangeFor(code);
  40018. if (position < 32) {
  40019. ulUnicodeRange1 |= 1 << position;
  40020. } else if (position < 64) {
  40021. ulUnicodeRange2 |= 1 << position - 32;
  40022. } else if (position < 96) {
  40023. ulUnicodeRange3 |= 1 << position - 64;
  40024. } else if (position < 123) {
  40025. ulUnicodeRange4 |= 1 << position - 96;
  40026. } else {
  40027. error('Unicode ranges Bits > 123 are reserved for internal usage');
  40028. }
  40029. }
  40030. } else {
  40031. // TODO
  40032. firstCharIndex = 0;
  40033. lastCharIndex = 255;
  40034. }
  40035. var bbox = properties.bbox || [
  40036. 0,
  40037. 0,
  40038. 0,
  40039. 0
  40040. ];
  40041. var unitsPerEm = override.unitsPerEm || 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0];
  40042. // if the font units differ to the PDF glyph space units
  40043. // then scale up the values
  40044. var scale = properties.ascentScaled ? 1.0 : unitsPerEm / PDF_GLYPH_SPACE_UNITS;
  40045. var typoAscent = override.ascent || Math.round(scale * (properties.ascent || bbox[3]));
  40046. var typoDescent = override.descent || Math.round(scale * (properties.descent || bbox[1]));
  40047. if (typoDescent > 0 && properties.descent > 0 && bbox[1] < 0) {
  40048. typoDescent = -typoDescent;
  40049. }
  40050. // fixing incorrect descent
  40051. var winAscent = override.yMax || typoAscent;
  40052. var winDescent = -override.yMin || -typoDescent;
  40053. return '\x00\x03' + // version
  40054. '\x02\x24' + // xAvgCharWidth
  40055. '\x01\xF4' + // usWeightClass
  40056. '\x00\x05' + // usWidthClass
  40057. '\x00\x00' + // fstype (0 to let the font loads via font-face on IE)
  40058. '\x02\x8A' + // ySubscriptXSize
  40059. '\x02\xBB' + // ySubscriptYSize
  40060. '\x00\x00' + // ySubscriptXOffset
  40061. '\x00\x8C' + // ySubscriptYOffset
  40062. '\x02\x8A' + // ySuperScriptXSize
  40063. '\x02\xBB' + // ySuperScriptYSize
  40064. '\x00\x00' + // ySuperScriptXOffset
  40065. '\x01\xDF' + // ySuperScriptYOffset
  40066. '\x00\x31' + // yStrikeOutSize
  40067. '\x01\x02' + // yStrikeOutPosition
  40068. '\x00\x00' + // sFamilyClass
  40069. '\x00\x00\x06' + String.fromCharCode(properties.fixedPitch ? 0x09 : 0x00) + '\x00\x00\x00\x00\x00\x00' + // Panose
  40070. string32(ulUnicodeRange1) + // ulUnicodeRange1 (Bits 0-31)
  40071. string32(ulUnicodeRange2) + // ulUnicodeRange2 (Bits 32-63)
  40072. string32(ulUnicodeRange3) + // ulUnicodeRange3 (Bits 64-95)
  40073. string32(ulUnicodeRange4) + // ulUnicodeRange4 (Bits 96-127)
  40074. '\x2A\x32\x31\x2A' + // achVendID
  40075. string16(properties.italicAngle ? 1 : 0) + // fsSelection
  40076. string16(firstCharIndex || properties.firstChar) + // usFirstCharIndex
  40077. string16(lastCharIndex || properties.lastChar) + // usLastCharIndex
  40078. string16(typoAscent) + // sTypoAscender
  40079. string16(typoDescent) + // sTypoDescender
  40080. '\x00\x64' + // sTypoLineGap (7%-10% of the unitsPerEM value)
  40081. string16(winAscent) + // usWinAscent
  40082. string16(winDescent) + // usWinDescent
  40083. '\x00\x00\x00\x00' + // ulCodePageRange1 (Bits 0-31)
  40084. '\x00\x00\x00\x00' + // ulCodePageRange2 (Bits 32-63)
  40085. string16(properties.xHeight) + // sxHeight
  40086. string16(properties.capHeight) + // sCapHeight
  40087. string16(0) + // usDefaultChar
  40088. string16(firstCharIndex || properties.firstChar) + // usBreakChar
  40089. '\x00\x03';
  40090. }
  40091. // usMaxContext
  40092. function createPostTable(properties) {
  40093. var angle = Math.floor(properties.italicAngle * Math.pow(2, 16));
  40094. return '\x00\x03\x00\x00' + // Version number
  40095. string32(angle) + // italicAngle
  40096. '\x00\x00' + // underlinePosition
  40097. '\x00\x00' + // underlineThickness
  40098. string32(properties.fixedPitch) + // isFixedPitch
  40099. '\x00\x00\x00\x00' + // minMemType42
  40100. '\x00\x00\x00\x00' + // maxMemType42
  40101. '\x00\x00\x00\x00' + // minMemType1
  40102. '\x00\x00\x00\x00';
  40103. }
  40104. // maxMemType1
  40105. function createNameTable(name, proto) {
  40106. if (!proto) {
  40107. proto = [
  40108. [],
  40109. []
  40110. ];
  40111. }
  40112. // no strings and unicode strings
  40113. var strings = [
  40114. proto[0][0] || 'Original licence',
  40115. // 0.Copyright
  40116. proto[0][1] || name,
  40117. // 1.Font family
  40118. proto[0][2] || 'Unknown',
  40119. // 2.Font subfamily (font weight)
  40120. proto[0][3] || 'uniqueID',
  40121. // 3.Unique ID
  40122. proto[0][4] || name,
  40123. // 4.Full font name
  40124. proto[0][5] || 'Version 0.11',
  40125. // 5.Version
  40126. proto[0][6] || '',
  40127. // 6.Postscript name
  40128. proto[0][7] || 'Unknown',
  40129. // 7.Trademark
  40130. proto[0][8] || 'Unknown',
  40131. // 8.Manufacturer
  40132. proto[0][9] || 'Unknown'
  40133. ];
  40134. // 9.Designer
  40135. // Mac want 1-byte per character strings while Windows want
  40136. // 2-bytes per character, so duplicate the names table
  40137. var stringsUnicode = [];
  40138. var i, ii, j, jj, str;
  40139. for (i = 0, ii = strings.length; i < ii; i++) {
  40140. str = proto[1][i] || strings[i];
  40141. var strBufUnicode = [];
  40142. for (j = 0, jj = str.length; j < jj; j++) {
  40143. strBufUnicode.push(string16(str.charCodeAt(j)));
  40144. }
  40145. stringsUnicode.push(strBufUnicode.join(''));
  40146. }
  40147. var names = [
  40148. strings,
  40149. stringsUnicode
  40150. ];
  40151. var platforms = [
  40152. '\x00\x01',
  40153. '\x00\x03'
  40154. ];
  40155. var encodings = [
  40156. '\x00\x00',
  40157. '\x00\x01'
  40158. ];
  40159. var languages = [
  40160. '\x00\x00',
  40161. '\x04\x09'
  40162. ];
  40163. var namesRecordCount = strings.length * platforms.length;
  40164. var nameTable = '\x00\x00' + // format
  40165. string16(namesRecordCount) + // Number of names Record
  40166. string16(namesRecordCount * 12 + 6);
  40167. // Storage
  40168. // Build the name records field
  40169. var strOffset = 0;
  40170. for (i = 0, ii = platforms.length; i < ii; i++) {
  40171. var strs = names[i];
  40172. for (j = 0, jj = strs.length; j < jj; j++) {
  40173. str = strs[j];
  40174. var nameRecord = platforms[i] + // platform ID
  40175. encodings[i] + // encoding ID
  40176. languages[i] + // language ID
  40177. string16(j) + // name ID
  40178. string16(str.length) + string16(strOffset);
  40179. nameTable += nameRecord;
  40180. strOffset += str.length;
  40181. }
  40182. }
  40183. nameTable += strings.join('') + stringsUnicode.join('');
  40184. return nameTable;
  40185. }
  40186. Font.prototype = {
  40187. name: null,
  40188. font: null,
  40189. mimetype: null,
  40190. encoding: null,
  40191. get renderer() {
  40192. var renderer = FontRendererFactory.create(this, SEAC_ANALYSIS_ENABLED);
  40193. return shadow(this, 'renderer', renderer);
  40194. },
  40195. exportData: function Font_exportData() {
  40196. // TODO remove enumerating of the properties, e.g. hardcode exact names.
  40197. var data = {};
  40198. for (var i in this) {
  40199. if (this.hasOwnProperty(i)) {
  40200. data[i] = this[i];
  40201. }
  40202. }
  40203. return data;
  40204. },
  40205. checkAndRepair: function Font_checkAndRepair(name, font, properties) {
  40206. function readTableEntry(file) {
  40207. var tag = bytesToString(file.getBytes(4));
  40208. var checksum = file.getInt32() >>> 0;
  40209. var offset = file.getInt32() >>> 0;
  40210. var length = file.getInt32() >>> 0;
  40211. // Read the table associated data
  40212. var previousPosition = file.pos;
  40213. file.pos = file.start ? file.start : 0;
  40214. file.skip(offset);
  40215. var data = file.getBytes(length);
  40216. file.pos = previousPosition;
  40217. if (tag === 'head') {
  40218. // clearing checksum adjustment
  40219. data[8] = data[9] = data[10] = data[11] = 0;
  40220. data[17] |= 0x20;
  40221. }
  40222. //Set font optimized for cleartype flag
  40223. return {
  40224. tag: tag,
  40225. checksum: checksum,
  40226. length: length,
  40227. offset: offset,
  40228. data: data
  40229. };
  40230. }
  40231. function readOpenTypeHeader(ttf) {
  40232. return {
  40233. version: bytesToString(ttf.getBytes(4)),
  40234. numTables: ttf.getUint16(),
  40235. searchRange: ttf.getUint16(),
  40236. entrySelector: ttf.getUint16(),
  40237. rangeShift: ttf.getUint16()
  40238. };
  40239. }
  40240. /**
  40241. * Read the appropriate subtable from the cmap according to 9.6.6.4 from
  40242. * PDF spec
  40243. */
  40244. function readCmapTable(cmap, font, isSymbolicFont, hasEncoding) {
  40245. if (!cmap) {
  40246. warn('No cmap table available.');
  40247. return {
  40248. platformId: -1,
  40249. encodingId: -1,
  40250. mappings: [],
  40251. hasShortCmap: false
  40252. };
  40253. }
  40254. var segment;
  40255. var start = (font.start ? font.start : 0) + cmap.offset;
  40256. font.pos = start;
  40257. var version = font.getUint16();
  40258. var numTables = font.getUint16();
  40259. var potentialTable;
  40260. var canBreak = false;
  40261. // There's an order of preference in terms of which cmap subtable to
  40262. // use:
  40263. // - non-symbolic fonts the preference is a 3,1 table then a 1,0 table
  40264. // - symbolic fonts the preference is a 3,0 table then a 1,0 table
  40265. // The following takes advantage of the fact that the tables are sorted
  40266. // to work.
  40267. for (var i = 0; i < numTables; i++) {
  40268. var platformId = font.getUint16();
  40269. var encodingId = font.getUint16();
  40270. var offset = font.getInt32() >>> 0;
  40271. var useTable = false;
  40272. if (platformId === 0 && encodingId === 0) {
  40273. useTable = true;
  40274. } else // Continue the loop since there still may be a higher priority
  40275. // table.
  40276. if (platformId === 1 && encodingId === 0) {
  40277. useTable = true;
  40278. } else // Continue the loop since there still may be a higher priority
  40279. // table.
  40280. if (platformId === 3 && encodingId === 1 && (!isSymbolicFont && hasEncoding || !potentialTable)) {
  40281. useTable = true;
  40282. if (!isSymbolicFont) {
  40283. canBreak = true;
  40284. }
  40285. } else if (isSymbolicFont && platformId === 3 && encodingId === 0) {
  40286. useTable = true;
  40287. canBreak = true;
  40288. }
  40289. if (useTable) {
  40290. potentialTable = {
  40291. platformId: platformId,
  40292. encodingId: encodingId,
  40293. offset: offset
  40294. };
  40295. }
  40296. if (canBreak) {
  40297. break;
  40298. }
  40299. }
  40300. if (potentialTable) {
  40301. font.pos = start + potentialTable.offset;
  40302. }
  40303. if (!potentialTable || font.peekByte() === -1) {
  40304. warn('Could not find a preferred cmap table.');
  40305. return {
  40306. platformId: -1,
  40307. encodingId: -1,
  40308. mappings: [],
  40309. hasShortCmap: false
  40310. };
  40311. }
  40312. var format = font.getUint16();
  40313. var length = font.getUint16();
  40314. var language = font.getUint16();
  40315. var hasShortCmap = false;
  40316. var mappings = [];
  40317. var j, glyphId;
  40318. // TODO(mack): refactor this cmap subtable reading logic out
  40319. if (format === 0) {
  40320. for (j = 0; j < 256; j++) {
  40321. var index = font.getByte();
  40322. if (!index) {
  40323. continue;
  40324. }
  40325. mappings.push({
  40326. charCode: j,
  40327. glyphId: index
  40328. });
  40329. }
  40330. hasShortCmap = true;
  40331. } else if (format === 4) {
  40332. // re-creating the table in format 4 since the encoding
  40333. // might be changed
  40334. var segCount = font.getUint16() >> 1;
  40335. font.getBytes(6);
  40336. // skipping range fields
  40337. var segIndex, segments = [];
  40338. for (segIndex = 0; segIndex < segCount; segIndex++) {
  40339. segments.push({ end: font.getUint16() });
  40340. }
  40341. font.getUint16();
  40342. for (segIndex = 0; segIndex < segCount; segIndex++) {
  40343. segments[segIndex].start = font.getUint16();
  40344. }
  40345. for (segIndex = 0; segIndex < segCount; segIndex++) {
  40346. segments[segIndex].delta = font.getUint16();
  40347. }
  40348. var offsetsCount = 0;
  40349. for (segIndex = 0; segIndex < segCount; segIndex++) {
  40350. segment = segments[segIndex];
  40351. var rangeOffset = font.getUint16();
  40352. if (!rangeOffset) {
  40353. segment.offsetIndex = -1;
  40354. continue;
  40355. }
  40356. var offsetIndex = (rangeOffset >> 1) - (segCount - segIndex);
  40357. segment.offsetIndex = offsetIndex;
  40358. offsetsCount = Math.max(offsetsCount, offsetIndex + segment.end - segment.start + 1);
  40359. }
  40360. var offsets = [];
  40361. for (j = 0; j < offsetsCount; j++) {
  40362. offsets.push(font.getUint16());
  40363. }
  40364. for (segIndex = 0; segIndex < segCount; segIndex++) {
  40365. segment = segments[segIndex];
  40366. start = segment.start;
  40367. var end = segment.end;
  40368. var delta = segment.delta;
  40369. offsetIndex = segment.offsetIndex;
  40370. for (j = start; j <= end; j++) {
  40371. if (j === 0xFFFF) {
  40372. continue;
  40373. }
  40374. glyphId = offsetIndex < 0 ? j : offsets[offsetIndex + j - start];
  40375. glyphId = glyphId + delta & 0xFFFF;
  40376. if (glyphId === 0) {
  40377. continue;
  40378. }
  40379. mappings.push({
  40380. charCode: j,
  40381. glyphId: glyphId
  40382. });
  40383. }
  40384. }
  40385. } else if (format === 6) {
  40386. // Format 6 is a 2-bytes dense mapping, which means the font data
  40387. // lives glue together even if they are pretty far in the unicode
  40388. // table. (This looks weird, so I can have missed something), this
  40389. // works on Linux but seems to fails on Mac so let's rewrite the
  40390. // cmap table to a 3-1-4 style
  40391. var firstCode = font.getUint16();
  40392. var entryCount = font.getUint16();
  40393. for (j = 0; j < entryCount; j++) {
  40394. glyphId = font.getUint16();
  40395. var charCode = firstCode + j;
  40396. mappings.push({
  40397. charCode: charCode,
  40398. glyphId: glyphId
  40399. });
  40400. }
  40401. } else {
  40402. warn('cmap table has unsupported format: ' + format);
  40403. return {
  40404. platformId: -1,
  40405. encodingId: -1,
  40406. mappings: [],
  40407. hasShortCmap: false
  40408. };
  40409. }
  40410. // removing duplicate entries
  40411. mappings.sort(function (a, b) {
  40412. return a.charCode - b.charCode;
  40413. });
  40414. for (i = 1; i < mappings.length; i++) {
  40415. if (mappings[i - 1].charCode === mappings[i].charCode) {
  40416. mappings.splice(i, 1);
  40417. i--;
  40418. }
  40419. }
  40420. return {
  40421. platformId: potentialTable.platformId,
  40422. encodingId: potentialTable.encodingId,
  40423. mappings: mappings,
  40424. hasShortCmap: hasShortCmap
  40425. };
  40426. }
  40427. function sanitizeMetrics(font, header, metrics, numGlyphs) {
  40428. if (!header) {
  40429. if (metrics) {
  40430. metrics.data = null;
  40431. }
  40432. return;
  40433. }
  40434. font.pos = (font.start ? font.start : 0) + header.offset;
  40435. font.pos += header.length - 2;
  40436. var numOfMetrics = font.getUint16();
  40437. if (numOfMetrics > numGlyphs) {
  40438. info('The numOfMetrics (' + numOfMetrics + ') should not be ' + 'greater than the numGlyphs (' + numGlyphs + ')');
  40439. // Reduce numOfMetrics if it is greater than numGlyphs
  40440. numOfMetrics = numGlyphs;
  40441. header.data[34] = (numOfMetrics & 0xff00) >> 8;
  40442. header.data[35] = numOfMetrics & 0x00ff;
  40443. }
  40444. var numOfSidebearings = numGlyphs - numOfMetrics;
  40445. var numMissing = numOfSidebearings - (metrics.length - numOfMetrics * 4 >> 1);
  40446. if (numMissing > 0) {
  40447. // For each missing glyph, we set both the width and lsb to 0 (zero).
  40448. // Since we need to add two properties for each glyph, this explains
  40449. // the use of |numMissing * 2| when initializing the typed array.
  40450. var entries = new Uint8Array(metrics.length + numMissing * 2);
  40451. entries.set(metrics.data);
  40452. metrics.data = entries;
  40453. }
  40454. }
  40455. function sanitizeGlyph(source, sourceStart, sourceEnd, dest, destStart, hintsValid) {
  40456. if (sourceEnd - sourceStart <= 12) {
  40457. // glyph with data less than 12 is invalid one
  40458. return 0;
  40459. }
  40460. var glyf = source.subarray(sourceStart, sourceEnd);
  40461. var contoursCount = glyf[0] << 8 | glyf[1];
  40462. if (contoursCount & 0x8000) {
  40463. // complex glyph, writing as is
  40464. dest.set(glyf, destStart);
  40465. return glyf.length;
  40466. }
  40467. var i, j = 10, flagsCount = 0;
  40468. for (i = 0; i < contoursCount; i++) {
  40469. var endPoint = glyf[j] << 8 | glyf[j + 1];
  40470. flagsCount = endPoint + 1;
  40471. j += 2;
  40472. }
  40473. // skipping instructions
  40474. var instructionsStart = j;
  40475. var instructionsLength = glyf[j] << 8 | glyf[j + 1];
  40476. j += 2 + instructionsLength;
  40477. var instructionsEnd = j;
  40478. // validating flags
  40479. var coordinatesLength = 0;
  40480. for (i = 0; i < flagsCount; i++) {
  40481. var flag = glyf[j++];
  40482. if (flag & 0xC0) {
  40483. // reserved flags must be zero, cleaning up
  40484. glyf[j - 1] = flag & 0x3F;
  40485. }
  40486. var xyLength = (flag & 2 ? 1 : flag & 16 ? 0 : 2) + (flag & 4 ? 1 : flag & 32 ? 0 : 2);
  40487. coordinatesLength += xyLength;
  40488. if (flag & 8) {
  40489. var repeat = glyf[j++];
  40490. i += repeat;
  40491. coordinatesLength += repeat * xyLength;
  40492. }
  40493. }
  40494. // glyph without coordinates will be rejected
  40495. if (coordinatesLength === 0) {
  40496. return 0;
  40497. }
  40498. var glyphDataLength = j + coordinatesLength;
  40499. if (glyphDataLength > glyf.length) {
  40500. // not enough data for coordinates
  40501. return 0;
  40502. }
  40503. if (!hintsValid && instructionsLength > 0) {
  40504. dest.set(glyf.subarray(0, instructionsStart), destStart);
  40505. dest.set([
  40506. 0,
  40507. 0
  40508. ], destStart + instructionsStart);
  40509. dest.set(glyf.subarray(instructionsEnd, glyphDataLength), destStart + instructionsStart + 2);
  40510. glyphDataLength -= instructionsLength;
  40511. if (glyf.length - glyphDataLength > 3) {
  40512. glyphDataLength = glyphDataLength + 3 & ~3;
  40513. }
  40514. return glyphDataLength;
  40515. }
  40516. if (glyf.length - glyphDataLength > 3) {
  40517. // truncating and aligning to 4 bytes the long glyph data
  40518. glyphDataLength = glyphDataLength + 3 & ~3;
  40519. dest.set(glyf.subarray(0, glyphDataLength), destStart);
  40520. return glyphDataLength;
  40521. }
  40522. // glyph data is fine
  40523. dest.set(glyf, destStart);
  40524. return glyf.length;
  40525. }
  40526. function sanitizeHead(head, numGlyphs, locaLength) {
  40527. var data = head.data;
  40528. // Validate version:
  40529. // Should always be 0x00010000
  40530. var version = int32(data[0], data[1], data[2], data[3]);
  40531. if (version >> 16 !== 1) {
  40532. info('Attempting to fix invalid version in head table: ' + version);
  40533. data[0] = 0;
  40534. data[1] = 1;
  40535. data[2] = 0;
  40536. data[3] = 0;
  40537. }
  40538. var indexToLocFormat = int16(data[50], data[51]);
  40539. if (indexToLocFormat < 0 || indexToLocFormat > 1) {
  40540. info('Attempting to fix invalid indexToLocFormat in head table: ' + indexToLocFormat);
  40541. // The value of indexToLocFormat should be 0 if the loca table
  40542. // consists of short offsets, and should be 1 if the loca table
  40543. // consists of long offsets.
  40544. //
  40545. // The number of entries in the loca table should be numGlyphs + 1.
  40546. //
  40547. // Using this information, we can work backwards to deduce if the
  40548. // size of each offset in the loca table, and thus figure out the
  40549. // appropriate value for indexToLocFormat.
  40550. var numGlyphsPlusOne = numGlyphs + 1;
  40551. if (locaLength === numGlyphsPlusOne << 1) {
  40552. // 0x0000 indicates the loca table consists of short offsets
  40553. data[50] = 0;
  40554. data[51] = 0;
  40555. } else if (locaLength === numGlyphsPlusOne << 2) {
  40556. // 0x0001 indicates the loca table consists of long offsets
  40557. data[50] = 0;
  40558. data[51] = 1;
  40559. } else {
  40560. warn('Could not fix indexToLocFormat: ' + indexToLocFormat);
  40561. }
  40562. }
  40563. }
  40564. function sanitizeGlyphLocations(loca, glyf, numGlyphs, isGlyphLocationsLong, hintsValid, dupFirstEntry) {
  40565. var itemSize, itemDecode, itemEncode;
  40566. if (isGlyphLocationsLong) {
  40567. itemSize = 4;
  40568. itemDecode = function fontItemDecodeLong(data, offset) {
  40569. return data[offset] << 24 | data[offset + 1] << 16 | data[offset + 2] << 8 | data[offset + 3];
  40570. };
  40571. itemEncode = function fontItemEncodeLong(data, offset, value) {
  40572. data[offset] = value >>> 24 & 0xFF;
  40573. data[offset + 1] = value >> 16 & 0xFF;
  40574. data[offset + 2] = value >> 8 & 0xFF;
  40575. data[offset + 3] = value & 0xFF;
  40576. };
  40577. } else {
  40578. itemSize = 2;
  40579. itemDecode = function fontItemDecode(data, offset) {
  40580. return data[offset] << 9 | data[offset + 1] << 1;
  40581. };
  40582. itemEncode = function fontItemEncode(data, offset, value) {
  40583. data[offset] = value >> 9 & 0xFF;
  40584. data[offset + 1] = value >> 1 & 0xFF;
  40585. };
  40586. }
  40587. var locaData = loca.data;
  40588. var locaDataSize = itemSize * (1 + numGlyphs);
  40589. // is loca.data too short or long?
  40590. if (locaData.length !== locaDataSize) {
  40591. locaData = new Uint8Array(locaDataSize);
  40592. locaData.set(loca.data.subarray(0, locaDataSize));
  40593. loca.data = locaData;
  40594. }
  40595. // removing the invalid glyphs
  40596. var oldGlyfData = glyf.data;
  40597. var oldGlyfDataLength = oldGlyfData.length;
  40598. var newGlyfData = new Uint8Array(oldGlyfDataLength);
  40599. var startOffset = itemDecode(locaData, 0);
  40600. var writeOffset = 0;
  40601. var missingGlyphData = Object.create(null);
  40602. itemEncode(locaData, 0, writeOffset);
  40603. var i, j;
  40604. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  40605. var endOffset = itemDecode(locaData, j);
  40606. if (endOffset > oldGlyfDataLength && (oldGlyfDataLength + 3 & ~3) === endOffset) {
  40607. // Aspose breaks fonts by aligning the glyphs to the qword, but not
  40608. // the glyf table size, which makes last glyph out of range.
  40609. endOffset = oldGlyfDataLength;
  40610. }
  40611. if (endOffset > oldGlyfDataLength) {
  40612. // glyph end offset points outside glyf data, rejecting the glyph
  40613. itemEncode(locaData, j, writeOffset);
  40614. startOffset = endOffset;
  40615. continue;
  40616. }
  40617. if (startOffset === endOffset) {
  40618. missingGlyphData[i] = true;
  40619. }
  40620. var newLength = sanitizeGlyph(oldGlyfData, startOffset, endOffset, newGlyfData, writeOffset, hintsValid);
  40621. writeOffset += newLength;
  40622. itemEncode(locaData, j, writeOffset);
  40623. startOffset = endOffset;
  40624. }
  40625. if (writeOffset === 0) {
  40626. // glyf table cannot be empty -- redoing the glyf and loca tables
  40627. // to have single glyph with one point
  40628. var simpleGlyph = new Uint8Array([
  40629. 0,
  40630. 1,
  40631. 0,
  40632. 0,
  40633. 0,
  40634. 0,
  40635. 0,
  40636. 0,
  40637. 0,
  40638. 0,
  40639. 0,
  40640. 0,
  40641. 0,
  40642. 0,
  40643. 49,
  40644. 0
  40645. ]);
  40646. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  40647. itemEncode(locaData, j, simpleGlyph.length);
  40648. }
  40649. glyf.data = simpleGlyph;
  40650. return missingGlyphData;
  40651. }
  40652. if (dupFirstEntry) {
  40653. var firstEntryLength = itemDecode(locaData, itemSize);
  40654. if (newGlyfData.length > firstEntryLength + writeOffset) {
  40655. glyf.data = newGlyfData.subarray(0, firstEntryLength + writeOffset);
  40656. } else {
  40657. glyf.data = new Uint8Array(firstEntryLength + writeOffset);
  40658. glyf.data.set(newGlyfData.subarray(0, writeOffset));
  40659. }
  40660. glyf.data.set(newGlyfData.subarray(0, firstEntryLength), writeOffset);
  40661. itemEncode(loca.data, locaData.length - itemSize, writeOffset + firstEntryLength);
  40662. } else {
  40663. glyf.data = newGlyfData.subarray(0, writeOffset);
  40664. }
  40665. return missingGlyphData;
  40666. }
  40667. function readPostScriptTable(post, properties, maxpNumGlyphs) {
  40668. var start = (font.start ? font.start : 0) + post.offset;
  40669. font.pos = start;
  40670. var length = post.length, end = start + length;
  40671. var version = font.getInt32();
  40672. // skip rest to the tables
  40673. font.getBytes(28);
  40674. var glyphNames;
  40675. var valid = true;
  40676. var i;
  40677. switch (version) {
  40678. case 0x00010000:
  40679. glyphNames = MacStandardGlyphOrdering;
  40680. break;
  40681. case 0x00020000:
  40682. var numGlyphs = font.getUint16();
  40683. if (numGlyphs !== maxpNumGlyphs) {
  40684. valid = false;
  40685. break;
  40686. }
  40687. var glyphNameIndexes = [];
  40688. for (i = 0; i < numGlyphs; ++i) {
  40689. var index = font.getUint16();
  40690. if (index >= 32768) {
  40691. valid = false;
  40692. break;
  40693. }
  40694. glyphNameIndexes.push(index);
  40695. }
  40696. if (!valid) {
  40697. break;
  40698. }
  40699. var customNames = [];
  40700. var strBuf = [];
  40701. while (font.pos < end) {
  40702. var stringLength = font.getByte();
  40703. strBuf.length = stringLength;
  40704. for (i = 0; i < stringLength; ++i) {
  40705. strBuf[i] = String.fromCharCode(font.getByte());
  40706. }
  40707. customNames.push(strBuf.join(''));
  40708. }
  40709. glyphNames = [];
  40710. for (i = 0; i < numGlyphs; ++i) {
  40711. var j = glyphNameIndexes[i];
  40712. if (j < 258) {
  40713. glyphNames.push(MacStandardGlyphOrdering[j]);
  40714. continue;
  40715. }
  40716. glyphNames.push(customNames[j - 258]);
  40717. }
  40718. break;
  40719. case 0x00030000:
  40720. break;
  40721. default:
  40722. warn('Unknown/unsupported post table version ' + version);
  40723. valid = false;
  40724. if (properties.defaultEncoding) {
  40725. glyphNames = properties.defaultEncoding;
  40726. }
  40727. break;
  40728. }
  40729. properties.glyphNames = glyphNames;
  40730. return valid;
  40731. }
  40732. function readNameTable(nameTable) {
  40733. var start = (font.start ? font.start : 0) + nameTable.offset;
  40734. font.pos = start;
  40735. var names = [
  40736. [],
  40737. []
  40738. ];
  40739. var length = nameTable.length, end = start + length;
  40740. var format = font.getUint16();
  40741. var FORMAT_0_HEADER_LENGTH = 6;
  40742. if (format !== 0 || length < FORMAT_0_HEADER_LENGTH) {
  40743. // unsupported name table format or table "too" small
  40744. return names;
  40745. }
  40746. var numRecords = font.getUint16();
  40747. var stringsStart = font.getUint16();
  40748. var records = [];
  40749. var NAME_RECORD_LENGTH = 12;
  40750. var i, ii;
  40751. for (i = 0; i < numRecords && font.pos + NAME_RECORD_LENGTH <= end; i++) {
  40752. var r = {
  40753. platform: font.getUint16(),
  40754. encoding: font.getUint16(),
  40755. language: font.getUint16(),
  40756. name: font.getUint16(),
  40757. length: font.getUint16(),
  40758. offset: font.getUint16()
  40759. };
  40760. // using only Macintosh and Windows platform/encoding names
  40761. if (r.platform === 1 && r.encoding === 0 && r.language === 0 || r.platform === 3 && r.encoding === 1 && r.language === 0x409) {
  40762. records.push(r);
  40763. }
  40764. }
  40765. for (i = 0, ii = records.length; i < ii; i++) {
  40766. var record = records[i];
  40767. if (record.length <= 0) {
  40768. continue;
  40769. }
  40770. // Nothing to process, ignoring.
  40771. var pos = start + stringsStart + record.offset;
  40772. if (pos + record.length > end) {
  40773. continue;
  40774. }
  40775. // outside of name table, ignoring
  40776. font.pos = pos;
  40777. var nameIndex = record.name;
  40778. if (record.encoding) {
  40779. // unicode
  40780. var str = '';
  40781. for (var j = 0, jj = record.length; j < jj; j += 2) {
  40782. str += String.fromCharCode(font.getUint16());
  40783. }
  40784. names[1][nameIndex] = str;
  40785. } else {
  40786. names[0][nameIndex] = bytesToString(font.getBytes(record.length));
  40787. }
  40788. }
  40789. return names;
  40790. }
  40791. var TTOpsStackDeltas = [
  40792. 0,
  40793. 0,
  40794. 0,
  40795. 0,
  40796. 0,
  40797. 0,
  40798. 0,
  40799. 0,
  40800. -2,
  40801. -2,
  40802. -2,
  40803. -2,
  40804. 0,
  40805. 0,
  40806. -2,
  40807. -5,
  40808. -1,
  40809. -1,
  40810. -1,
  40811. -1,
  40812. -1,
  40813. -1,
  40814. -1,
  40815. -1,
  40816. 0,
  40817. 0,
  40818. -1,
  40819. 0,
  40820. -1,
  40821. -1,
  40822. -1,
  40823. -1,
  40824. 1,
  40825. -1,
  40826. -999,
  40827. 0,
  40828. 1,
  40829. 0,
  40830. -1,
  40831. -2,
  40832. 0,
  40833. -1,
  40834. -2,
  40835. -1,
  40836. -1,
  40837. 0,
  40838. -1,
  40839. -1,
  40840. 0,
  40841. 0,
  40842. -999,
  40843. -999,
  40844. -1,
  40845. -1,
  40846. -1,
  40847. -1,
  40848. -2,
  40849. -999,
  40850. -2,
  40851. -2,
  40852. -999,
  40853. 0,
  40854. -2,
  40855. -2,
  40856. 0,
  40857. 0,
  40858. -2,
  40859. 0,
  40860. -2,
  40861. 0,
  40862. 0,
  40863. 0,
  40864. -2,
  40865. -1,
  40866. -1,
  40867. 1,
  40868. 1,
  40869. 0,
  40870. 0,
  40871. -1,
  40872. -1,
  40873. -1,
  40874. -1,
  40875. -1,
  40876. -1,
  40877. -1,
  40878. 0,
  40879. 0,
  40880. -1,
  40881. 0,
  40882. -1,
  40883. -1,
  40884. 0,
  40885. -999,
  40886. -1,
  40887. -1,
  40888. -1,
  40889. -1,
  40890. -1,
  40891. -1,
  40892. 0,
  40893. 0,
  40894. 0,
  40895. 0,
  40896. 0,
  40897. 0,
  40898. 0,
  40899. 0,
  40900. 0,
  40901. 0,
  40902. 0,
  40903. 0,
  40904. -2,
  40905. -999,
  40906. -999,
  40907. -999,
  40908. -999,
  40909. -999,
  40910. -1,
  40911. -1,
  40912. -2,
  40913. -2,
  40914. 0,
  40915. 0,
  40916. 0,
  40917. 0,
  40918. -1,
  40919. -1,
  40920. -999,
  40921. -2,
  40922. -2,
  40923. 0,
  40924. 0,
  40925. -1,
  40926. -2,
  40927. -2,
  40928. 0,
  40929. 0,
  40930. 0,
  40931. -1,
  40932. -1,
  40933. -1,
  40934. -2
  40935. ];
  40936. // 0xC0-DF == -1 and 0xE0-FF == -2
  40937. function sanitizeTTProgram(table, ttContext) {
  40938. var data = table.data;
  40939. var i = 0, j, n, b, funcId, pc, lastEndf = 0, lastDeff = 0;
  40940. var stack = [];
  40941. var callstack = [];
  40942. var functionsCalled = [];
  40943. var tooComplexToFollowFunctions = ttContext.tooComplexToFollowFunctions;
  40944. var inFDEF = false, ifLevel = 0, inELSE = 0;
  40945. for (var ii = data.length; i < ii;) {
  40946. var op = data[i++];
  40947. // The TrueType instruction set docs can be found at
  40948. // https://developer.apple.com/fonts/TTRefMan/RM05/Chap5.html
  40949. if (op === 0x40) {
  40950. // NPUSHB - pushes n bytes
  40951. n = data[i++];
  40952. if (inFDEF || inELSE) {
  40953. i += n;
  40954. } else {
  40955. for (j = 0; j < n; j++) {
  40956. stack.push(data[i++]);
  40957. }
  40958. }
  40959. } else if (op === 0x41) {
  40960. // NPUSHW - pushes n words
  40961. n = data[i++];
  40962. if (inFDEF || inELSE) {
  40963. i += n * 2;
  40964. } else {
  40965. for (j = 0; j < n; j++) {
  40966. b = data[i++];
  40967. stack.push(b << 8 | data[i++]);
  40968. }
  40969. }
  40970. } else if ((op & 0xF8) === 0xB0) {
  40971. // PUSHB - pushes bytes
  40972. n = op - 0xB0 + 1;
  40973. if (inFDEF || inELSE) {
  40974. i += n;
  40975. } else {
  40976. for (j = 0; j < n; j++) {
  40977. stack.push(data[i++]);
  40978. }
  40979. }
  40980. } else if ((op & 0xF8) === 0xB8) {
  40981. // PUSHW - pushes words
  40982. n = op - 0xB8 + 1;
  40983. if (inFDEF || inELSE) {
  40984. i += n * 2;
  40985. } else {
  40986. for (j = 0; j < n; j++) {
  40987. b = data[i++];
  40988. stack.push(b << 8 | data[i++]);
  40989. }
  40990. }
  40991. } else if (op === 0x2B && !tooComplexToFollowFunctions) {
  40992. // CALL
  40993. if (!inFDEF && !inELSE) {
  40994. // collecting inforamtion about which functions are used
  40995. funcId = stack[stack.length - 1];
  40996. ttContext.functionsUsed[funcId] = true;
  40997. if (funcId in ttContext.functionsStackDeltas) {
  40998. stack.length += ttContext.functionsStackDeltas[funcId];
  40999. } else if (funcId in ttContext.functionsDefined && functionsCalled.indexOf(funcId) < 0) {
  41000. callstack.push({
  41001. data: data,
  41002. i: i,
  41003. stackTop: stack.length - 1
  41004. });
  41005. functionsCalled.push(funcId);
  41006. pc = ttContext.functionsDefined[funcId];
  41007. if (!pc) {
  41008. warn('TT: CALL non-existent function');
  41009. ttContext.hintsValid = false;
  41010. return;
  41011. }
  41012. data = pc.data;
  41013. i = pc.i;
  41014. }
  41015. }
  41016. } else if (op === 0x2C && !tooComplexToFollowFunctions) {
  41017. // FDEF
  41018. if (inFDEF || inELSE) {
  41019. warn('TT: nested FDEFs not allowed');
  41020. tooComplexToFollowFunctions = true;
  41021. }
  41022. inFDEF = true;
  41023. // collecting inforamtion about which functions are defined
  41024. lastDeff = i;
  41025. funcId = stack.pop();
  41026. ttContext.functionsDefined[funcId] = {
  41027. data: data,
  41028. i: i
  41029. };
  41030. } else if (op === 0x2D) {
  41031. // ENDF - end of function
  41032. if (inFDEF) {
  41033. inFDEF = false;
  41034. lastEndf = i;
  41035. } else {
  41036. pc = callstack.pop();
  41037. if (!pc) {
  41038. warn('TT: ENDF bad stack');
  41039. ttContext.hintsValid = false;
  41040. return;
  41041. }
  41042. funcId = functionsCalled.pop();
  41043. data = pc.data;
  41044. i = pc.i;
  41045. ttContext.functionsStackDeltas[funcId] = stack.length - pc.stackTop;
  41046. }
  41047. } else if (op === 0x89) {
  41048. // IDEF - instruction definition
  41049. if (inFDEF || inELSE) {
  41050. warn('TT: nested IDEFs not allowed');
  41051. tooComplexToFollowFunctions = true;
  41052. }
  41053. inFDEF = true;
  41054. // recording it as a function to track ENDF
  41055. lastDeff = i;
  41056. } else if (op === 0x58) {
  41057. // IF
  41058. ++ifLevel;
  41059. } else if (op === 0x1B) {
  41060. // ELSE
  41061. inELSE = ifLevel;
  41062. } else if (op === 0x59) {
  41063. // EIF
  41064. if (inELSE === ifLevel) {
  41065. inELSE = 0;
  41066. }
  41067. --ifLevel;
  41068. } else if (op === 0x1C) {
  41069. // JMPR
  41070. if (!inFDEF && !inELSE) {
  41071. var offset = stack[stack.length - 1];
  41072. // only jumping forward to prevent infinite loop
  41073. if (offset > 0) {
  41074. i += offset - 1;
  41075. }
  41076. }
  41077. }
  41078. // Adjusting stack not extactly, but just enough to get function id
  41079. if (!inFDEF && !inELSE) {
  41080. var stackDelta = op <= 0x8E ? TTOpsStackDeltas[op] : op >= 0xC0 && op <= 0xDF ? -1 : op >= 0xE0 ? -2 : 0;
  41081. if (op >= 0x71 && op <= 0x75) {
  41082. n = stack.pop();
  41083. if (n === n) {
  41084. stackDelta = -n * 2;
  41085. }
  41086. }
  41087. while (stackDelta < 0 && stack.length > 0) {
  41088. stack.pop();
  41089. stackDelta++;
  41090. }
  41091. while (stackDelta > 0) {
  41092. stack.push(NaN);
  41093. // pushing any number into stack
  41094. stackDelta--;
  41095. }
  41096. }
  41097. }
  41098. ttContext.tooComplexToFollowFunctions = tooComplexToFollowFunctions;
  41099. var content = [data];
  41100. if (i > data.length) {
  41101. content.push(new Uint8Array(i - data.length));
  41102. }
  41103. if (lastDeff > lastEndf) {
  41104. warn('TT: complementing a missing function tail');
  41105. // new function definition started, but not finished
  41106. // complete function by [CLEAR, ENDF]
  41107. content.push(new Uint8Array([
  41108. 0x22,
  41109. 0x2D
  41110. ]));
  41111. }
  41112. foldTTTable(table, content);
  41113. }
  41114. function checkInvalidFunctions(ttContext, maxFunctionDefs) {
  41115. if (ttContext.tooComplexToFollowFunctions) {
  41116. return;
  41117. }
  41118. if (ttContext.functionsDefined.length > maxFunctionDefs) {
  41119. warn('TT: more functions defined than expected');
  41120. ttContext.hintsValid = false;
  41121. return;
  41122. }
  41123. for (var j = 0, jj = ttContext.functionsUsed.length; j < jj; j++) {
  41124. if (j > maxFunctionDefs) {
  41125. warn('TT: invalid function id: ' + j);
  41126. ttContext.hintsValid = false;
  41127. return;
  41128. }
  41129. if (ttContext.functionsUsed[j] && !ttContext.functionsDefined[j]) {
  41130. warn('TT: undefined function: ' + j);
  41131. ttContext.hintsValid = false;
  41132. return;
  41133. }
  41134. }
  41135. }
  41136. function foldTTTable(table, content) {
  41137. if (content.length > 1) {
  41138. // concatenating the content items
  41139. var newLength = 0;
  41140. var j, jj;
  41141. for (j = 0, jj = content.length; j < jj; j++) {
  41142. newLength += content[j].length;
  41143. }
  41144. newLength = newLength + 3 & ~3;
  41145. var result = new Uint8Array(newLength);
  41146. var pos = 0;
  41147. for (j = 0, jj = content.length; j < jj; j++) {
  41148. result.set(content[j], pos);
  41149. pos += content[j].length;
  41150. }
  41151. table.data = result;
  41152. table.length = newLength;
  41153. }
  41154. }
  41155. function sanitizeTTPrograms(fpgm, prep, cvt, maxFunctionDefs) {
  41156. var ttContext = {
  41157. functionsDefined: [],
  41158. functionsUsed: [],
  41159. functionsStackDeltas: [],
  41160. tooComplexToFollowFunctions: false,
  41161. hintsValid: true
  41162. };
  41163. if (fpgm) {
  41164. sanitizeTTProgram(fpgm, ttContext);
  41165. }
  41166. if (prep) {
  41167. sanitizeTTProgram(prep, ttContext);
  41168. }
  41169. if (fpgm) {
  41170. checkInvalidFunctions(ttContext, maxFunctionDefs);
  41171. }
  41172. if (cvt && cvt.length & 1) {
  41173. var cvtData = new Uint8Array(cvt.length + 1);
  41174. cvtData.set(cvt.data);
  41175. cvt.data = cvtData;
  41176. }
  41177. return ttContext.hintsValid;
  41178. }
  41179. // The following steps modify the original font data, making copy
  41180. font = new Stream(new Uint8Array(font.getBytes()));
  41181. var VALID_TABLES = [
  41182. 'OS/2',
  41183. 'cmap',
  41184. 'head',
  41185. 'hhea',
  41186. 'hmtx',
  41187. 'maxp',
  41188. 'name',
  41189. 'post',
  41190. 'loca',
  41191. 'glyf',
  41192. 'fpgm',
  41193. 'prep',
  41194. 'cvt ',
  41195. 'CFF '
  41196. ];
  41197. var header = readOpenTypeHeader(font);
  41198. var numTables = header.numTables;
  41199. var cff, cffFile;
  41200. var tables = Object.create(null);
  41201. tables['OS/2'] = null;
  41202. tables['cmap'] = null;
  41203. tables['head'] = null;
  41204. tables['hhea'] = null;
  41205. tables['hmtx'] = null;
  41206. tables['maxp'] = null;
  41207. tables['name'] = null;
  41208. tables['post'] = null;
  41209. var table;
  41210. for (var i = 0; i < numTables; i++) {
  41211. table = readTableEntry(font);
  41212. if (VALID_TABLES.indexOf(table.tag) < 0) {
  41213. continue;
  41214. }
  41215. // skipping table if it's not a required or optional table
  41216. if (table.length === 0) {
  41217. continue;
  41218. }
  41219. // skipping empty tables
  41220. tables[table.tag] = table;
  41221. }
  41222. var isTrueType = !tables['CFF '];
  41223. if (!isTrueType) {
  41224. // OpenType font
  41225. if (header.version === 'OTTO' && properties.type !== 'CIDFontType2' || !tables['head'] || !tables['hhea'] || !tables['maxp'] || !tables['post']) {
  41226. // no major tables: throwing everything at CFFFont
  41227. cffFile = new Stream(tables['CFF '].data);
  41228. cff = new CFFFont(cffFile, properties);
  41229. adjustWidths(properties);
  41230. return this.convert(name, cff, properties);
  41231. }
  41232. delete tables['glyf'];
  41233. delete tables['loca'];
  41234. delete tables['fpgm'];
  41235. delete tables['prep'];
  41236. delete tables['cvt '];
  41237. this.isOpenType = true;
  41238. } else {
  41239. if (!tables['loca']) {
  41240. error('Required "loca" table is not found');
  41241. }
  41242. if (!tables['glyf']) {
  41243. warn('Required "glyf" table is not found -- trying to recover.');
  41244. // Note: We use `sanitizeGlyphLocations` to add dummy glyf data below.
  41245. tables['glyf'] = {
  41246. tag: 'glyf',
  41247. data: new Uint8Array(0)
  41248. };
  41249. }
  41250. this.isOpenType = false;
  41251. }
  41252. if (!tables['maxp']) {
  41253. error('Required "maxp" table is not found');
  41254. }
  41255. font.pos = (font.start || 0) + tables['maxp'].offset;
  41256. var version = font.getInt32();
  41257. var numGlyphs = font.getUint16();
  41258. var maxFunctionDefs = 0;
  41259. if (version >= 0x00010000 && tables['maxp'].length >= 22) {
  41260. // maxZones can be invalid
  41261. font.pos += 8;
  41262. var maxZones = font.getUint16();
  41263. if (maxZones > 2) {
  41264. // reset to 2 if font has invalid maxZones
  41265. tables['maxp'].data[14] = 0;
  41266. tables['maxp'].data[15] = 2;
  41267. }
  41268. font.pos += 4;
  41269. maxFunctionDefs = font.getUint16();
  41270. }
  41271. var dupFirstEntry = false;
  41272. if (properties.type === 'CIDFontType2' && properties.toUnicode && properties.toUnicode.get(0) > '\u0000') {
  41273. // oracle's defect (see 3427), duplicating first entry
  41274. dupFirstEntry = true;
  41275. numGlyphs++;
  41276. tables['maxp'].data[4] = numGlyphs >> 8;
  41277. tables['maxp'].data[5] = numGlyphs & 255;
  41278. }
  41279. var hintsValid = sanitizeTTPrograms(tables['fpgm'], tables['prep'], tables['cvt '], maxFunctionDefs);
  41280. if (!hintsValid) {
  41281. delete tables['fpgm'];
  41282. delete tables['prep'];
  41283. delete tables['cvt '];
  41284. }
  41285. // Ensure the hmtx table contains the advance width and
  41286. // sidebearings information for numGlyphs in the maxp table
  41287. sanitizeMetrics(font, tables['hhea'], tables['hmtx'], numGlyphs);
  41288. if (!tables['head']) {
  41289. error('Required "head" table is not found');
  41290. }
  41291. sanitizeHead(tables['head'], numGlyphs, isTrueType ? tables['loca'].length : 0);
  41292. var missingGlyphs = Object.create(null);
  41293. if (isTrueType) {
  41294. var isGlyphLocationsLong = int16(tables['head'].data[50], tables['head'].data[51]);
  41295. missingGlyphs = sanitizeGlyphLocations(tables['loca'], tables['glyf'], numGlyphs, isGlyphLocationsLong, hintsValid, dupFirstEntry);
  41296. }
  41297. if (!tables['hhea']) {
  41298. error('Required "hhea" table is not found');
  41299. }
  41300. // Sanitizer reduces the glyph advanceWidth to the maxAdvanceWidth
  41301. // Sometimes it's 0. That needs to be fixed
  41302. if (tables['hhea'].data[10] === 0 && tables['hhea'].data[11] === 0) {
  41303. tables['hhea'].data[10] = 0xFF;
  41304. tables['hhea'].data[11] = 0xFF;
  41305. }
  41306. // Extract some more font properties from the OpenType head and
  41307. // hhea tables; yMin and descent value are always negative.
  41308. var metricsOverride = {
  41309. unitsPerEm: int16(tables['head'].data[18], tables['head'].data[19]),
  41310. yMax: int16(tables['head'].data[42], tables['head'].data[43]),
  41311. yMin: signedInt16(tables['head'].data[38], tables['head'].data[39]),
  41312. ascent: int16(tables['hhea'].data[4], tables['hhea'].data[5]),
  41313. descent: signedInt16(tables['hhea'].data[6], tables['hhea'].data[7])
  41314. };
  41315. // PDF FontDescriptor metrics lie -- using data from actual font.
  41316. this.ascent = metricsOverride.ascent / metricsOverride.unitsPerEm;
  41317. this.descent = metricsOverride.descent / metricsOverride.unitsPerEm;
  41318. // The 'post' table has glyphs names.
  41319. if (tables['post']) {
  41320. var valid = readPostScriptTable(tables['post'], properties, numGlyphs);
  41321. if (!valid) {
  41322. tables['post'] = null;
  41323. }
  41324. }
  41325. var charCodeToGlyphId = [], charCode;
  41326. var toUnicode = properties.toUnicode, widths = properties.widths;
  41327. var skipToUnicode = toUnicode instanceof IdentityToUnicodeMap || toUnicode.length === 0x10000;
  41328. // Helper function to try to skip mapping of empty glyphs.
  41329. // Note: In some cases, just relying on the glyph data doesn't work,
  41330. // hence we also use a few heuristics to fix various PDF files.
  41331. function hasGlyph(glyphId, charCode, widthCode) {
  41332. if (!missingGlyphs[glyphId]) {
  41333. return true;
  41334. }
  41335. if (!skipToUnicode && charCode >= 0 && toUnicode.has(charCode)) {
  41336. return true;
  41337. }
  41338. if (widths && widthCode >= 0 && isNum(widths[widthCode])) {
  41339. return true;
  41340. }
  41341. return false;
  41342. }
  41343. if (properties.type === 'CIDFontType2') {
  41344. var cidToGidMap = properties.cidToGidMap || [];
  41345. var isCidToGidMapEmpty = cidToGidMap.length === 0;
  41346. properties.cMap.forEach(function (charCode, cid) {
  41347. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  41348. var glyphId = -1;
  41349. if (isCidToGidMapEmpty) {
  41350. glyphId = cid;
  41351. } else if (cidToGidMap[cid] !== undefined) {
  41352. glyphId = cidToGidMap[cid];
  41353. }
  41354. if (glyphId >= 0 && glyphId < numGlyphs && hasGlyph(glyphId, charCode, cid)) {
  41355. charCodeToGlyphId[charCode] = glyphId;
  41356. }
  41357. });
  41358. if (dupFirstEntry && (isCidToGidMapEmpty || !charCodeToGlyphId[0])) {
  41359. // We don't duplicate the first entry in the `charCodeToGlyphId` map
  41360. // if the font has a `CIDToGIDMap` which has already mapped the first
  41361. // entry to a non-zero `glyphId` (fixes issue7544.pdf).
  41362. charCodeToGlyphId[0] = numGlyphs - 1;
  41363. }
  41364. } else {
  41365. // Most of the following logic in this code branch is based on the
  41366. // 9.6.6.4 of the PDF spec.
  41367. var cmapTable = readCmapTable(tables['cmap'], font, this.isSymbolicFont, properties.hasEncoding);
  41368. var cmapPlatformId = cmapTable.platformId;
  41369. var cmapEncodingId = cmapTable.encodingId;
  41370. var cmapMappings = cmapTable.mappings;
  41371. var cmapMappingsLength = cmapMappings.length;
  41372. // The spec seems to imply that if the font is symbolic the encoding
  41373. // should be ignored, this doesn't appear to work for 'preistabelle.pdf'
  41374. // where the the font is symbolic and it has an encoding.
  41375. if (properties.hasEncoding && (cmapPlatformId === 3 && cmapEncodingId === 1 || cmapPlatformId === 1 && cmapEncodingId === 0) || cmapPlatformId === -1 && cmapEncodingId === -1 && // Temporary hack
  41376. !!getEncoding(properties.baseEncodingName)) {
  41377. // Temporary hack
  41378. // When no preferred cmap table was found and |baseEncodingName| is
  41379. // one of the predefined encodings, we seem to obtain a better
  41380. // |charCodeToGlyphId| map from the code below (fixes bug 1057544).
  41381. // TODO: Note that this is a hack which should be removed as soon as
  41382. // we have proper support for more exotic cmap tables.
  41383. var baseEncoding = [];
  41384. if (properties.baseEncodingName === 'MacRomanEncoding' || properties.baseEncodingName === 'WinAnsiEncoding') {
  41385. baseEncoding = getEncoding(properties.baseEncodingName);
  41386. }
  41387. var glyphsUnicodeMap = getGlyphsUnicode();
  41388. for (charCode = 0; charCode < 256; charCode++) {
  41389. var glyphName, standardGlyphName;
  41390. if (this.differences && charCode in this.differences) {
  41391. glyphName = this.differences[charCode];
  41392. } else if (charCode in baseEncoding && baseEncoding[charCode] !== '') {
  41393. glyphName = baseEncoding[charCode];
  41394. } else {
  41395. glyphName = StandardEncoding[charCode];
  41396. }
  41397. if (!glyphName) {
  41398. continue;
  41399. }
  41400. // Ensure that non-standard glyph names are resolved to valid ones.
  41401. standardGlyphName = recoverGlyphName(glyphName, glyphsUnicodeMap);
  41402. var unicodeOrCharCode, isUnicode = false;
  41403. if (cmapPlatformId === 3 && cmapEncodingId === 1) {
  41404. unicodeOrCharCode = glyphsUnicodeMap[standardGlyphName];
  41405. isUnicode = true;
  41406. } else if (cmapPlatformId === 1 && cmapEncodingId === 0) {
  41407. // TODO: the encoding needs to be updated with mac os table.
  41408. unicodeOrCharCode = MacRomanEncoding.indexOf(standardGlyphName);
  41409. }
  41410. var found = false;
  41411. for (i = 0; i < cmapMappingsLength; ++i) {
  41412. if (cmapMappings[i].charCode !== unicodeOrCharCode) {
  41413. continue;
  41414. }
  41415. var code = isUnicode ? charCode : unicodeOrCharCode;
  41416. if (hasGlyph(cmapMappings[i].glyphId, code, -1)) {
  41417. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  41418. found = true;
  41419. break;
  41420. }
  41421. }
  41422. if (!found && properties.glyphNames) {
  41423. // Try to map using the post table.
  41424. var glyphId = properties.glyphNames.indexOf(glyphName);
  41425. // The post table ought to use the same kind of glyph names as the
  41426. // `differences` array, but check the standard ones as a fallback.
  41427. if (glyphId === -1 && standardGlyphName !== glyphName) {
  41428. glyphId = properties.glyphNames.indexOf(standardGlyphName);
  41429. }
  41430. if (glyphId > 0 && hasGlyph(glyphId, -1, -1)) {
  41431. charCodeToGlyphId[charCode] = glyphId;
  41432. found = true;
  41433. }
  41434. }
  41435. if (!found) {
  41436. charCodeToGlyphId[charCode] = 0;
  41437. }
  41438. }
  41439. } else // notdef
  41440. if (cmapPlatformId === 0 && cmapEncodingId === 0) {
  41441. // Default Unicode semantics, use the charcodes as is.
  41442. for (i = 0; i < cmapMappingsLength; ++i) {
  41443. charCodeToGlyphId[cmapMappings[i].charCode] = cmapMappings[i].glyphId;
  41444. }
  41445. } else {
  41446. // For (3, 0) cmap tables:
  41447. // The charcode key being stored in charCodeToGlyphId is the lower
  41448. // byte of the two-byte charcodes of the cmap table since according to
  41449. // the spec: 'each byte from the string shall be prepended with the
  41450. // high byte of the range [of charcodes in the cmap table], to form
  41451. // a two-byte character, which shall be used to select the
  41452. // associated glyph description from the subtable'.
  41453. //
  41454. // For (1, 0) cmap tables:
  41455. // 'single bytes from the string shall be used to look up the
  41456. // associated glyph descriptions from the subtable'. This means
  41457. // charcodes in the cmap will be single bytes, so no-op since
  41458. // glyph.charCode & 0xFF === glyph.charCode
  41459. for (i = 0; i < cmapMappingsLength; ++i) {
  41460. charCode = cmapMappings[i].charCode & 0xFF;
  41461. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  41462. }
  41463. }
  41464. }
  41465. if (charCodeToGlyphId.length === 0) {
  41466. // defines at least one glyph
  41467. charCodeToGlyphId[0] = 0;
  41468. }
  41469. // Converting glyphs and ids into font's cmap table
  41470. var newMapping = adjustMapping(charCodeToGlyphId, properties);
  41471. this.toFontChar = newMapping.toFontChar;
  41472. tables['cmap'] = {
  41473. tag: 'cmap',
  41474. data: createCmapTable(newMapping.charCodeToGlyphId, numGlyphs)
  41475. };
  41476. if (!tables['OS/2'] || !validateOS2Table(tables['OS/2'])) {
  41477. tables['OS/2'] = {
  41478. tag: 'OS/2',
  41479. data: createOS2Table(properties, newMapping.charCodeToGlyphId, metricsOverride)
  41480. };
  41481. }
  41482. // Rewrite the 'post' table if needed
  41483. if (!tables['post']) {
  41484. tables['post'] = {
  41485. tag: 'post',
  41486. data: createPostTable(properties)
  41487. };
  41488. }
  41489. if (!isTrueType) {
  41490. try {
  41491. // Trying to repair CFF file
  41492. cffFile = new Stream(tables['CFF '].data);
  41493. var parser = new CFFParser(cffFile, properties, SEAC_ANALYSIS_ENABLED);
  41494. cff = parser.parse();
  41495. var compiler = new CFFCompiler(cff);
  41496. tables['CFF '].data = compiler.compile();
  41497. } catch (e) {
  41498. warn('Failed to compile font ' + properties.loadedName);
  41499. }
  41500. }
  41501. // Re-creating 'name' table
  41502. if (!tables['name']) {
  41503. tables['name'] = {
  41504. tag: 'name',
  41505. data: createNameTable(this.name)
  41506. };
  41507. } else {
  41508. // ... using existing 'name' table as prototype
  41509. var namePrototype = readNameTable(tables['name']);
  41510. tables['name'].data = createNameTable(name, namePrototype);
  41511. }
  41512. var builder = new OpenTypeFileBuilder(header.version);
  41513. for (var tableTag in tables) {
  41514. builder.addTable(tableTag, tables[tableTag].data);
  41515. }
  41516. return builder.toArray();
  41517. },
  41518. convert: function Font_convert(fontName, font, properties) {
  41519. // TODO: Check the charstring widths to determine this.
  41520. properties.fixedPitch = false;
  41521. if (properties.builtInEncoding) {
  41522. // For Type1 fonts that do not include either `ToUnicode` or `Encoding`
  41523. // data, attempt to use the `builtInEncoding` to improve text selection.
  41524. adjustToUnicode(properties, properties.builtInEncoding);
  41525. }
  41526. var mapping = font.getGlyphMapping(properties);
  41527. var newMapping = adjustMapping(mapping, properties);
  41528. this.toFontChar = newMapping.toFontChar;
  41529. var numGlyphs = font.numGlyphs;
  41530. function getCharCodes(charCodeToGlyphId, glyphId) {
  41531. var charCodes = null;
  41532. for (var charCode in charCodeToGlyphId) {
  41533. if (glyphId === charCodeToGlyphId[charCode]) {
  41534. if (!charCodes) {
  41535. charCodes = [];
  41536. }
  41537. charCodes.push(charCode | 0);
  41538. }
  41539. }
  41540. return charCodes;
  41541. }
  41542. function createCharCode(charCodeToGlyphId, glyphId) {
  41543. for (var charCode in charCodeToGlyphId) {
  41544. if (glyphId === charCodeToGlyphId[charCode]) {
  41545. return charCode | 0;
  41546. }
  41547. }
  41548. newMapping.charCodeToGlyphId[newMapping.nextAvailableFontCharCode] = glyphId;
  41549. return newMapping.nextAvailableFontCharCode++;
  41550. }
  41551. var seacs = font.seacs;
  41552. if (SEAC_ANALYSIS_ENABLED && seacs && seacs.length) {
  41553. var matrix = properties.fontMatrix || FONT_IDENTITY_MATRIX;
  41554. var charset = font.getCharset();
  41555. var seacMap = Object.create(null);
  41556. for (var glyphId in seacs) {
  41557. glyphId |= 0;
  41558. var seac = seacs[glyphId];
  41559. var baseGlyphName = StandardEncoding[seac[2]];
  41560. var accentGlyphName = StandardEncoding[seac[3]];
  41561. var baseGlyphId = charset.indexOf(baseGlyphName);
  41562. var accentGlyphId = charset.indexOf(accentGlyphName);
  41563. if (baseGlyphId < 0 || accentGlyphId < 0) {
  41564. continue;
  41565. }
  41566. var accentOffset = {
  41567. x: seac[0] * matrix[0] + seac[1] * matrix[2] + matrix[4],
  41568. y: seac[0] * matrix[1] + seac[1] * matrix[3] + matrix[5]
  41569. };
  41570. var charCodes = getCharCodes(mapping, glyphId);
  41571. if (!charCodes) {
  41572. // There's no point in mapping it if the char code was never mapped
  41573. // to begin with.
  41574. continue;
  41575. }
  41576. for (var i = 0, ii = charCodes.length; i < ii; i++) {
  41577. var charCode = charCodes[i];
  41578. // Find a fontCharCode that maps to the base and accent glyphs.
  41579. // If one doesn't exists, create it.
  41580. var charCodeToGlyphId = newMapping.charCodeToGlyphId;
  41581. var baseFontCharCode = createCharCode(charCodeToGlyphId, baseGlyphId);
  41582. var accentFontCharCode = createCharCode(charCodeToGlyphId, accentGlyphId);
  41583. seacMap[charCode] = {
  41584. baseFontCharCode: baseFontCharCode,
  41585. accentFontCharCode: accentFontCharCode,
  41586. accentOffset: accentOffset
  41587. };
  41588. }
  41589. }
  41590. properties.seacMap = seacMap;
  41591. }
  41592. var unitsPerEm = 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0];
  41593. var builder = new OpenTypeFileBuilder('\x4F\x54\x54\x4F');
  41594. // PostScript Font Program
  41595. builder.addTable('CFF ', font.data);
  41596. // OS/2 and Windows Specific metrics
  41597. builder.addTable('OS/2', createOS2Table(properties, newMapping.charCodeToGlyphId));
  41598. // Character to glyphs mapping
  41599. builder.addTable('cmap', createCmapTable(newMapping.charCodeToGlyphId, numGlyphs));
  41600. // Font header
  41601. builder.addTable('head', '\x00\x01\x00\x00' + // Version number
  41602. '\x00\x00\x10\x00' + // fontRevision
  41603. '\x00\x00\x00\x00' + // checksumAdjustement
  41604. '\x5F\x0F\x3C\xF5' + // magicNumber
  41605. '\x00\x00' + // Flags
  41606. safeString16(unitsPerEm) + // unitsPerEM
  41607. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // creation date
  41608. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // modifification date
  41609. '\x00\x00' + // xMin
  41610. safeString16(properties.descent) + // yMin
  41611. '\x0F\xFF' + // xMax
  41612. safeString16(properties.ascent) + // yMax
  41613. string16(properties.italicAngle ? 2 : 0) + // macStyle
  41614. '\x00\x11' + // lowestRecPPEM
  41615. '\x00\x00' + // fontDirectionHint
  41616. '\x00\x00' + // indexToLocFormat
  41617. '\x00\x00');
  41618. // glyphDataFormat
  41619. // Horizontal header
  41620. builder.addTable('hhea', '\x00\x01\x00\x00' + // Version number
  41621. safeString16(properties.ascent) + // Typographic Ascent
  41622. safeString16(properties.descent) + // Typographic Descent
  41623. '\x00\x00' + // Line Gap
  41624. '\xFF\xFF' + // advanceWidthMax
  41625. '\x00\x00' + // minLeftSidebearing
  41626. '\x00\x00' + // minRightSidebearing
  41627. '\x00\x00' + // xMaxExtent
  41628. safeString16(properties.capHeight) + // caretSlopeRise
  41629. safeString16(Math.tan(properties.italicAngle) * properties.xHeight) + // caretSlopeRun
  41630. '\x00\x00' + // caretOffset
  41631. '\x00\x00' + // -reserved-
  41632. '\x00\x00' + // -reserved-
  41633. '\x00\x00' + // -reserved-
  41634. '\x00\x00' + // -reserved-
  41635. '\x00\x00' + // metricDataFormat
  41636. string16(numGlyphs));
  41637. // Number of HMetrics
  41638. // Horizontal metrics
  41639. builder.addTable('hmtx', function fontFieldsHmtx() {
  41640. var charstrings = font.charstrings;
  41641. var cffWidths = font.cff ? font.cff.widths : null;
  41642. var hmtx = '\x00\x00\x00\x00';
  41643. // Fake .notdef
  41644. for (var i = 1, ii = numGlyphs; i < ii; i++) {
  41645. var width = 0;
  41646. if (charstrings) {
  41647. var charstring = charstrings[i - 1];
  41648. width = 'width' in charstring ? charstring.width : 0;
  41649. } else if (cffWidths) {
  41650. width = Math.ceil(cffWidths[i] || 0);
  41651. }
  41652. hmtx += string16(width) + string16(0);
  41653. }
  41654. return hmtx;
  41655. }());
  41656. // Maximum profile
  41657. builder.addTable('maxp', '\x00\x00\x50\x00' + // Version number
  41658. string16(numGlyphs));
  41659. // Num of glyphs
  41660. // Naming tables
  41661. builder.addTable('name', createNameTable(fontName));
  41662. // PostScript information
  41663. builder.addTable('post', createPostTable(properties));
  41664. return builder.toArray();
  41665. },
  41666. get spaceWidth() {
  41667. if ('_shadowWidth' in this) {
  41668. return this._shadowWidth;
  41669. }
  41670. // trying to estimate space character width
  41671. var possibleSpaceReplacements = [
  41672. 'space',
  41673. 'minus',
  41674. 'one',
  41675. 'i',
  41676. 'I'
  41677. ];
  41678. var width;
  41679. for (var i = 0, ii = possibleSpaceReplacements.length; i < ii; i++) {
  41680. var glyphName = possibleSpaceReplacements[i];
  41681. // if possible, getting width by glyph name
  41682. if (glyphName in this.widths) {
  41683. width = this.widths[glyphName];
  41684. break;
  41685. }
  41686. var glyphsUnicodeMap = getGlyphsUnicode();
  41687. var glyphUnicode = glyphsUnicodeMap[glyphName];
  41688. // finding the charcode via unicodeToCID map
  41689. var charcode = 0;
  41690. if (this.composite) {
  41691. if (this.cMap.contains(glyphUnicode)) {
  41692. charcode = this.cMap.lookup(glyphUnicode);
  41693. }
  41694. }
  41695. // ... via toUnicode map
  41696. if (!charcode && this.toUnicode) {
  41697. charcode = this.toUnicode.charCodeOf(glyphUnicode);
  41698. }
  41699. // setting it to unicode if negative or undefined
  41700. if (charcode <= 0) {
  41701. charcode = glyphUnicode;
  41702. }
  41703. // trying to get width via charcode
  41704. width = this.widths[charcode];
  41705. if (width) {
  41706. break;
  41707. }
  41708. }
  41709. // the non-zero width found
  41710. width = width || this.defaultWidth;
  41711. // Do not shadow the property here. See discussion:
  41712. // https://github.com/mozilla/pdf.js/pull/2127#discussion_r1662280
  41713. this._shadowWidth = width;
  41714. return width;
  41715. },
  41716. charToGlyph: function Font_charToGlyph(charcode, isSpace) {
  41717. var fontCharCode, width, operatorListId;
  41718. var widthCode = charcode;
  41719. if (this.cMap && this.cMap.contains(charcode)) {
  41720. widthCode = this.cMap.lookup(charcode);
  41721. }
  41722. width = this.widths[widthCode];
  41723. width = isNum(width) ? width : this.defaultWidth;
  41724. var vmetric = this.vmetrics && this.vmetrics[widthCode];
  41725. var unicode = this.toUnicode.get(charcode) || charcode;
  41726. if (typeof unicode === 'number') {
  41727. unicode = String.fromCharCode(unicode);
  41728. }
  41729. var isInFont = charcode in this.toFontChar;
  41730. // First try the toFontChar map, if it's not there then try falling
  41731. // back to the char code.
  41732. fontCharCode = this.toFontChar[charcode] || charcode;
  41733. if (this.missingFile) {
  41734. fontCharCode = mapSpecialUnicodeValues(fontCharCode);
  41735. }
  41736. if (this.isType3Font) {
  41737. // Font char code in this case is actually a glyph name.
  41738. operatorListId = fontCharCode;
  41739. }
  41740. var accent = null;
  41741. if (this.seacMap && this.seacMap[charcode]) {
  41742. isInFont = true;
  41743. var seac = this.seacMap[charcode];
  41744. fontCharCode = seac.baseFontCharCode;
  41745. accent = {
  41746. fontChar: String.fromCharCode(seac.accentFontCharCode),
  41747. offset: seac.accentOffset
  41748. };
  41749. }
  41750. var fontChar = String.fromCharCode(fontCharCode);
  41751. var glyph = this.glyphCache[charcode];
  41752. if (!glyph || !glyph.matchesForCache(fontChar, unicode, accent, width, vmetric, operatorListId, isSpace, isInFont)) {
  41753. glyph = new Glyph(fontChar, unicode, accent, width, vmetric, operatorListId, isSpace, isInFont);
  41754. this.glyphCache[charcode] = glyph;
  41755. }
  41756. return glyph;
  41757. },
  41758. charsToGlyphs: function Font_charsToGlyphs(chars) {
  41759. var charsCache = this.charsCache;
  41760. var glyphs, glyph, charcode;
  41761. // if we translated this string before, just grab it from the cache
  41762. if (charsCache) {
  41763. glyphs = charsCache[chars];
  41764. if (glyphs) {
  41765. return glyphs;
  41766. }
  41767. }
  41768. // lazily create the translation cache
  41769. if (!charsCache) {
  41770. charsCache = this.charsCache = Object.create(null);
  41771. }
  41772. glyphs = [];
  41773. var charsCacheKey = chars;
  41774. var i = 0, ii;
  41775. if (this.cMap) {
  41776. // composite fonts have multi-byte strings convert the string from
  41777. // single-byte to multi-byte
  41778. var c = Object.create(null);
  41779. while (i < chars.length) {
  41780. this.cMap.readCharCode(chars, i, c);
  41781. charcode = c.charcode;
  41782. var length = c.length;
  41783. i += length;
  41784. // Space is char with code 0x20 and length 1 in multiple-byte codes.
  41785. var isSpace = length === 1 && chars.charCodeAt(i - 1) === 0x20;
  41786. glyph = this.charToGlyph(charcode, isSpace);
  41787. glyphs.push(glyph);
  41788. }
  41789. } else {
  41790. for (i = 0, ii = chars.length; i < ii; ++i) {
  41791. charcode = chars.charCodeAt(i);
  41792. glyph = this.charToGlyph(charcode, charcode === 0x20);
  41793. glyphs.push(glyph);
  41794. }
  41795. }
  41796. // Enter the translated string into the cache
  41797. return charsCache[charsCacheKey] = glyphs;
  41798. }
  41799. };
  41800. return Font;
  41801. }();
  41802. var ErrorFont = function ErrorFontClosure() {
  41803. function ErrorFont(error) {
  41804. this.error = error;
  41805. this.loadedName = 'g_font_error';
  41806. this.loading = false;
  41807. }
  41808. ErrorFont.prototype = {
  41809. charsToGlyphs: function ErrorFont_charsToGlyphs() {
  41810. return [];
  41811. },
  41812. exportData: function ErrorFont_exportData() {
  41813. return { error: this.error };
  41814. }
  41815. };
  41816. return ErrorFont;
  41817. }();
  41818. /**
  41819. * Shared logic for building a char code to glyph id mapping for Type1 and
  41820. * simple CFF fonts. See section 9.6.6.2 of the spec.
  41821. * @param {Object} properties Font properties object.
  41822. * @param {Object} builtInEncoding The encoding contained within the actual font
  41823. * data.
  41824. * @param {Array} glyphNames Array of glyph names where the index is the
  41825. * glyph ID.
  41826. * @returns {Object} A char code to glyph ID map.
  41827. */
  41828. function type1FontGlyphMapping(properties, builtInEncoding, glyphNames) {
  41829. var charCodeToGlyphId = Object.create(null);
  41830. var glyphId, charCode, baseEncoding;
  41831. if (properties.baseEncodingName) {
  41832. // If a valid base encoding name was used, the mapping is initialized with
  41833. // that.
  41834. baseEncoding = getEncoding(properties.baseEncodingName);
  41835. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  41836. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  41837. if (glyphId >= 0) {
  41838. charCodeToGlyphId[charCode] = glyphId;
  41839. } else {
  41840. charCodeToGlyphId[charCode] = 0;
  41841. }
  41842. }
  41843. } else // notdef
  41844. if (!!(properties.flags & FontFlags.Symbolic)) {
  41845. // For a symbolic font the encoding should be the fonts built-in
  41846. // encoding.
  41847. for (charCode in builtInEncoding) {
  41848. charCodeToGlyphId[charCode] = builtInEncoding[charCode];
  41849. }
  41850. } else {
  41851. // For non-symbolic fonts that don't have a base encoding the standard
  41852. // encoding should be used.
  41853. baseEncoding = StandardEncoding;
  41854. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  41855. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  41856. if (glyphId >= 0) {
  41857. charCodeToGlyphId[charCode] = glyphId;
  41858. } else {
  41859. charCodeToGlyphId[charCode] = 0;
  41860. }
  41861. }
  41862. }
  41863. // notdef
  41864. // Lastly, merge in the differences.
  41865. var differences = properties.differences, glyphsUnicodeMap;
  41866. if (differences) {
  41867. for (charCode in differences) {
  41868. var glyphName = differences[charCode];
  41869. glyphId = glyphNames.indexOf(glyphName);
  41870. if (glyphId === -1) {
  41871. if (!glyphsUnicodeMap) {
  41872. glyphsUnicodeMap = getGlyphsUnicode();
  41873. }
  41874. var standardGlyphName = recoverGlyphName(glyphName, glyphsUnicodeMap);
  41875. if (standardGlyphName !== glyphName) {
  41876. glyphId = glyphNames.indexOf(standardGlyphName);
  41877. }
  41878. }
  41879. if (glyphId >= 0) {
  41880. charCodeToGlyphId[charCode] = glyphId;
  41881. } else {
  41882. charCodeToGlyphId[charCode] = 0;
  41883. }
  41884. }
  41885. }
  41886. // notdef
  41887. return charCodeToGlyphId;
  41888. }
  41889. // Type1Font is also a CIDFontType0.
  41890. var Type1Font = function Type1FontClosure() {
  41891. function findBlock(streamBytes, signature, startIndex) {
  41892. var streamBytesLength = streamBytes.length;
  41893. var signatureLength = signature.length;
  41894. var scanLength = streamBytesLength - signatureLength;
  41895. var i = startIndex, j, found = false;
  41896. while (i < scanLength) {
  41897. j = 0;
  41898. while (j < signatureLength && streamBytes[i + j] === signature[j]) {
  41899. j++;
  41900. }
  41901. if (j >= signatureLength) {
  41902. // `signature` found, skip over whitespace.
  41903. i += j;
  41904. while (i < streamBytesLength && isSpace(streamBytes[i])) {
  41905. i++;
  41906. }
  41907. found = true;
  41908. break;
  41909. }
  41910. i++;
  41911. }
  41912. return {
  41913. found: found,
  41914. length: i
  41915. };
  41916. }
  41917. function getHeaderBlock(stream, suggestedLength) {
  41918. var EEXEC_SIGNATURE = [
  41919. 0x65,
  41920. 0x65,
  41921. 0x78,
  41922. 0x65,
  41923. 0x63
  41924. ];
  41925. var streamStartPos = stream.pos;
  41926. // Save the initial stream position.
  41927. var headerBytes, headerBytesLength, block;
  41928. try {
  41929. headerBytes = stream.getBytes(suggestedLength);
  41930. headerBytesLength = headerBytes.length;
  41931. } catch (ex) {
  41932. if (ex instanceof MissingDataException) {
  41933. throw ex;
  41934. }
  41935. }
  41936. // Ignore errors if the `suggestedLength` is huge enough that a Uint8Array
  41937. // cannot hold the result of `getBytes`, and fallback to simply checking
  41938. // the entire stream (fixes issue3928.pdf).
  41939. if (headerBytesLength === suggestedLength) {
  41940. // Most of the time `suggestedLength` is correct, so to speed things up we
  41941. // initially only check the last few bytes to see if the header was found.
  41942. // Otherwise we (potentially) check the entire stream to prevent errors in
  41943. // `Type1Parser` (fixes issue5686.pdf).
  41944. block = findBlock(headerBytes, EEXEC_SIGNATURE, suggestedLength - 2 * EEXEC_SIGNATURE.length);
  41945. if (block.found && block.length === suggestedLength) {
  41946. return {
  41947. stream: new Stream(headerBytes),
  41948. length: suggestedLength
  41949. };
  41950. }
  41951. }
  41952. warn('Invalid "Length1" property in Type1 font -- trying to recover.');
  41953. stream.pos = streamStartPos;
  41954. // Reset the stream position.
  41955. var SCAN_BLOCK_LENGTH = 2048;
  41956. var actualLength;
  41957. while (true) {
  41958. var scanBytes = stream.peekBytes(SCAN_BLOCK_LENGTH);
  41959. block = findBlock(scanBytes, EEXEC_SIGNATURE, 0);
  41960. if (block.length === 0) {
  41961. break;
  41962. }
  41963. stream.pos += block.length;
  41964. // Update the stream position.
  41965. if (block.found) {
  41966. actualLength = stream.pos - streamStartPos;
  41967. break;
  41968. }
  41969. }
  41970. stream.pos = streamStartPos;
  41971. // Reset the stream position.
  41972. if (actualLength) {
  41973. return {
  41974. stream: new Stream(stream.getBytes(actualLength)),
  41975. length: actualLength
  41976. };
  41977. }
  41978. warn('Unable to recover "Length1" property in Type1 font -- using as is.');
  41979. return {
  41980. stream: new Stream(stream.getBytes(suggestedLength)),
  41981. length: suggestedLength
  41982. };
  41983. }
  41984. function getEexecBlock(stream, suggestedLength) {
  41985. // We should ideally parse the eexec block to ensure that `suggestedLength`
  41986. // is correct, so we don't truncate the block data if it's too small.
  41987. // However, this would also require checking if the fixed-content portion
  41988. // exists (using the 'Length3' property), and ensuring that it's valid.
  41989. //
  41990. // Given that `suggestedLength` almost always is correct, all the validation
  41991. // would require a great deal of unnecessary parsing for most fonts.
  41992. // To save time, we always fetch the entire stream instead, which also avoid
  41993. // issues if `suggestedLength` is huge (see comment in `getHeaderBlock`).
  41994. //
  41995. // NOTE: This means that the function can include the fixed-content portion
  41996. // in the returned eexec block. In practice this does *not* seem to matter,
  41997. // since `Type1Parser_extractFontProgram` will skip over any non-commands.
  41998. var eexecBytes = stream.getBytes();
  41999. return {
  42000. stream: new Stream(eexecBytes),
  42001. length: eexecBytes.length
  42002. };
  42003. }
  42004. function Type1Font(name, file, properties) {
  42005. // Some bad generators embed pfb file as is, we have to strip 6-byte header.
  42006. // Also, length1 and length2 might be off by 6 bytes as well.
  42007. // http://www.math.ubc.ca/~cass/piscript/type1.pdf
  42008. var PFB_HEADER_SIZE = 6;
  42009. var headerBlockLength = properties.length1;
  42010. var eexecBlockLength = properties.length2;
  42011. var pfbHeader = file.peekBytes(PFB_HEADER_SIZE);
  42012. var pfbHeaderPresent = pfbHeader[0] === 0x80 && pfbHeader[1] === 0x01;
  42013. if (pfbHeaderPresent) {
  42014. file.skip(PFB_HEADER_SIZE);
  42015. headerBlockLength = pfbHeader[5] << 24 | pfbHeader[4] << 16 | pfbHeader[3] << 8 | pfbHeader[2];
  42016. }
  42017. // Get the data block containing glyphs and subrs information
  42018. var headerBlock = getHeaderBlock(file, headerBlockLength);
  42019. headerBlockLength = headerBlock.length;
  42020. var headerBlockParser = new Type1Parser(headerBlock.stream, false, SEAC_ANALYSIS_ENABLED);
  42021. headerBlockParser.extractFontHeader(properties);
  42022. if (pfbHeaderPresent) {
  42023. pfbHeader = file.getBytes(PFB_HEADER_SIZE);
  42024. eexecBlockLength = pfbHeader[5] << 24 | pfbHeader[4] << 16 | pfbHeader[3] << 8 | pfbHeader[2];
  42025. }
  42026. // Decrypt the data blocks and retrieve it's content
  42027. var eexecBlock = getEexecBlock(file, eexecBlockLength);
  42028. eexecBlockLength = eexecBlock.length;
  42029. var eexecBlockParser = new Type1Parser(eexecBlock.stream, true, SEAC_ANALYSIS_ENABLED);
  42030. var data = eexecBlockParser.extractFontProgram();
  42031. for (var info in data.properties) {
  42032. properties[info] = data.properties[info];
  42033. }
  42034. var charstrings = data.charstrings;
  42035. var type2Charstrings = this.getType2Charstrings(charstrings);
  42036. var subrs = this.getType2Subrs(data.subrs);
  42037. this.charstrings = charstrings;
  42038. this.data = this.wrap(name, type2Charstrings, this.charstrings, subrs, properties);
  42039. this.seacs = this.getSeacs(data.charstrings);
  42040. }
  42041. Type1Font.prototype = {
  42042. get numGlyphs() {
  42043. return this.charstrings.length + 1;
  42044. },
  42045. getCharset: function Type1Font_getCharset() {
  42046. var charset = ['.notdef'];
  42047. var charstrings = this.charstrings;
  42048. for (var glyphId = 0; glyphId < charstrings.length; glyphId++) {
  42049. charset.push(charstrings[glyphId].glyphName);
  42050. }
  42051. return charset;
  42052. },
  42053. getGlyphMapping: function Type1Font_getGlyphMapping(properties) {
  42054. var charstrings = this.charstrings;
  42055. var glyphNames = ['.notdef'], glyphId;
  42056. for (glyphId = 0; glyphId < charstrings.length; glyphId++) {
  42057. glyphNames.push(charstrings[glyphId].glyphName);
  42058. }
  42059. var encoding = properties.builtInEncoding;
  42060. if (encoding) {
  42061. var builtInEncoding = Object.create(null);
  42062. for (var charCode in encoding) {
  42063. glyphId = glyphNames.indexOf(encoding[charCode]);
  42064. if (glyphId >= 0) {
  42065. builtInEncoding[charCode] = glyphId;
  42066. }
  42067. }
  42068. }
  42069. return type1FontGlyphMapping(properties, builtInEncoding, glyphNames);
  42070. },
  42071. getSeacs: function Type1Font_getSeacs(charstrings) {
  42072. var i, ii;
  42073. var seacMap = [];
  42074. for (i = 0, ii = charstrings.length; i < ii; i++) {
  42075. var charstring = charstrings[i];
  42076. if (charstring.seac) {
  42077. // Offset by 1 for .notdef
  42078. seacMap[i + 1] = charstring.seac;
  42079. }
  42080. }
  42081. return seacMap;
  42082. },
  42083. getType2Charstrings: function Type1Font_getType2Charstrings(type1Charstrings) {
  42084. var type2Charstrings = [];
  42085. for (var i = 0, ii = type1Charstrings.length; i < ii; i++) {
  42086. type2Charstrings.push(type1Charstrings[i].charstring);
  42087. }
  42088. return type2Charstrings;
  42089. },
  42090. getType2Subrs: function Type1Font_getType2Subrs(type1Subrs) {
  42091. var bias = 0;
  42092. var count = type1Subrs.length;
  42093. if (count < 1133) {
  42094. bias = 107;
  42095. } else if (count < 33769) {
  42096. bias = 1131;
  42097. } else {
  42098. bias = 32768;
  42099. }
  42100. // Add a bunch of empty subrs to deal with the Type2 bias
  42101. var type2Subrs = [];
  42102. var i;
  42103. for (i = 0; i < bias; i++) {
  42104. type2Subrs.push([0x0B]);
  42105. }
  42106. for (i = 0; i < count; i++) {
  42107. type2Subrs.push(type1Subrs[i]);
  42108. }
  42109. return type2Subrs;
  42110. },
  42111. wrap: function Type1Font_wrap(name, glyphs, charstrings, subrs, properties) {
  42112. var cff = new CFF();
  42113. cff.header = new CFFHeader(1, 0, 4, 4);
  42114. cff.names = [name];
  42115. var topDict = new CFFTopDict();
  42116. // CFF strings IDs 0...390 are predefined names, so refering
  42117. // to entries in our own String INDEX starts at SID 391.
  42118. topDict.setByName('version', 391);
  42119. topDict.setByName('Notice', 392);
  42120. topDict.setByName('FullName', 393);
  42121. topDict.setByName('FamilyName', 394);
  42122. topDict.setByName('Weight', 395);
  42123. topDict.setByName('Encoding', null);
  42124. // placeholder
  42125. topDict.setByName('FontMatrix', properties.fontMatrix);
  42126. topDict.setByName('FontBBox', properties.bbox);
  42127. topDict.setByName('charset', null);
  42128. // placeholder
  42129. topDict.setByName('CharStrings', null);
  42130. // placeholder
  42131. topDict.setByName('Private', null);
  42132. // placeholder
  42133. cff.topDict = topDict;
  42134. var strings = new CFFStrings();
  42135. strings.add('Version 0.11');
  42136. // Version
  42137. strings.add('See original notice');
  42138. // Notice
  42139. strings.add(name);
  42140. // FullName
  42141. strings.add(name);
  42142. // FamilyName
  42143. strings.add('Medium');
  42144. // Weight
  42145. cff.strings = strings;
  42146. cff.globalSubrIndex = new CFFIndex();
  42147. var count = glyphs.length;
  42148. var charsetArray = [0];
  42149. var i, ii;
  42150. for (i = 0; i < count; i++) {
  42151. var index = CFFStandardStrings.indexOf(charstrings[i].glyphName);
  42152. // TODO: Insert the string and correctly map it. Previously it was
  42153. // thought mapping names that aren't in the standard strings to .notdef
  42154. // was fine, however in issue818 when mapping them all to .notdef the
  42155. // adieresis glyph no longer worked.
  42156. if (index === -1) {
  42157. index = 0;
  42158. }
  42159. charsetArray.push(index >> 8 & 0xff, index & 0xff);
  42160. }
  42161. cff.charset = new CFFCharset(false, 0, [], charsetArray);
  42162. var charStringsIndex = new CFFIndex();
  42163. charStringsIndex.add([
  42164. 0x8B,
  42165. 0x0E
  42166. ]);
  42167. // .notdef
  42168. for (i = 0; i < count; i++) {
  42169. var glyph = glyphs[i];
  42170. // If the CharString outline is empty, replace it with .notdef to
  42171. // prevent OTS from rejecting the font (fixes bug1252420.pdf).
  42172. if (glyph.length === 0) {
  42173. charStringsIndex.add([
  42174. 0x8B,
  42175. 0x0E
  42176. ]);
  42177. // .notdef
  42178. continue;
  42179. }
  42180. charStringsIndex.add(glyph);
  42181. }
  42182. cff.charStrings = charStringsIndex;
  42183. var privateDict = new CFFPrivateDict();
  42184. privateDict.setByName('Subrs', null);
  42185. // placeholder
  42186. var fields = [
  42187. 'BlueValues',
  42188. 'OtherBlues',
  42189. 'FamilyBlues',
  42190. 'FamilyOtherBlues',
  42191. 'StemSnapH',
  42192. 'StemSnapV',
  42193. 'BlueShift',
  42194. 'BlueFuzz',
  42195. 'BlueScale',
  42196. 'LanguageGroup',
  42197. 'ExpansionFactor',
  42198. 'ForceBold',
  42199. 'StdHW',
  42200. 'StdVW'
  42201. ];
  42202. for (i = 0, ii = fields.length; i < ii; i++) {
  42203. var field = fields[i];
  42204. if (!(field in properties.privateData)) {
  42205. continue;
  42206. }
  42207. var value = properties.privateData[field];
  42208. if (isArray(value)) {
  42209. // All of the private dictionary array data in CFF must be stored as
  42210. // "delta-encoded" numbers.
  42211. for (var j = value.length - 1; j > 0; j--) {
  42212. value[j] -= value[j - 1];
  42213. }
  42214. }
  42215. // ... difference from previous value
  42216. privateDict.setByName(field, value);
  42217. }
  42218. cff.topDict.privateDict = privateDict;
  42219. var subrIndex = new CFFIndex();
  42220. for (i = 0, ii = subrs.length; i < ii; i++) {
  42221. subrIndex.add(subrs[i]);
  42222. }
  42223. privateDict.subrsIndex = subrIndex;
  42224. var compiler = new CFFCompiler(cff);
  42225. return compiler.compile();
  42226. }
  42227. };
  42228. return Type1Font;
  42229. }();
  42230. var CFFFont = function CFFFontClosure() {
  42231. function CFFFont(file, properties) {
  42232. this.properties = properties;
  42233. var parser = new CFFParser(file, properties, SEAC_ANALYSIS_ENABLED);
  42234. this.cff = parser.parse();
  42235. var compiler = new CFFCompiler(this.cff);
  42236. this.seacs = this.cff.seacs;
  42237. try {
  42238. this.data = compiler.compile();
  42239. } catch (e) {
  42240. warn('Failed to compile font ' + properties.loadedName);
  42241. // There may have just been an issue with the compiler, set the data
  42242. // anyway and hope the font loaded.
  42243. this.data = file;
  42244. }
  42245. }
  42246. CFFFont.prototype = {
  42247. get numGlyphs() {
  42248. return this.cff.charStrings.count;
  42249. },
  42250. getCharset: function CFFFont_getCharset() {
  42251. return this.cff.charset.charset;
  42252. },
  42253. getGlyphMapping: function CFFFont_getGlyphMapping() {
  42254. var cff = this.cff;
  42255. var properties = this.properties;
  42256. var charsets = cff.charset.charset;
  42257. var charCodeToGlyphId;
  42258. var glyphId;
  42259. if (properties.composite) {
  42260. charCodeToGlyphId = Object.create(null);
  42261. if (cff.isCIDFont) {
  42262. // If the font is actually a CID font then we should use the charset
  42263. // to map CIDs to GIDs.
  42264. for (glyphId = 0; glyphId < charsets.length; glyphId++) {
  42265. var cid = charsets[glyphId];
  42266. var charCode = properties.cMap.charCodeOf(cid);
  42267. charCodeToGlyphId[charCode] = glyphId;
  42268. }
  42269. } else {
  42270. // If it is NOT actually a CID font then CIDs should be mapped
  42271. // directly to GIDs.
  42272. for (glyphId = 0; glyphId < cff.charStrings.count; glyphId++) {
  42273. charCodeToGlyphId[glyphId] = glyphId;
  42274. }
  42275. }
  42276. return charCodeToGlyphId;
  42277. }
  42278. var encoding = cff.encoding ? cff.encoding.encoding : null;
  42279. charCodeToGlyphId = type1FontGlyphMapping(properties, encoding, charsets);
  42280. return charCodeToGlyphId;
  42281. }
  42282. };
  42283. return CFFFont;
  42284. }();
  42285. // Workaround for seac on Windows.
  42286. (function checkSeacSupport() {
  42287. if (typeof navigator !== 'undefined' && /Windows/.test(navigator.userAgent)) {
  42288. SEAC_ANALYSIS_ENABLED = true;
  42289. }
  42290. }());
  42291. // Workaround for Private Use Area characters in Chrome on Windows
  42292. // http://code.google.com/p/chromium/issues/detail?id=122465
  42293. // https://github.com/mozilla/pdf.js/issues/1689
  42294. (function checkChromeWindows() {
  42295. if (typeof navigator !== 'undefined' && /Windows.*Chrome/.test(navigator.userAgent)) {
  42296. SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = true;
  42297. }
  42298. }());
  42299. exports.ErrorFont = ErrorFont;
  42300. exports.Font = Font;
  42301. exports.FontFlags = FontFlags;
  42302. exports.IdentityToUnicodeMap = IdentityToUnicodeMap;
  42303. exports.ToUnicodeMap = ToUnicodeMap;
  42304. exports.getFontType = getFontType;
  42305. }));
  42306. (function (root, factory) {
  42307. factory(root.pdfjsCorePsParser = {}, root.pdfjsSharedUtil, root.pdfjsCoreParser);
  42308. }(this, function (exports, sharedUtil, coreParser) {
  42309. var error = sharedUtil.error;
  42310. var isSpace = sharedUtil.isSpace;
  42311. var EOF = coreParser.EOF;
  42312. var PostScriptParser = function PostScriptParserClosure() {
  42313. function PostScriptParser(lexer) {
  42314. this.lexer = lexer;
  42315. this.operators = [];
  42316. this.token = null;
  42317. this.prev = null;
  42318. }
  42319. PostScriptParser.prototype = {
  42320. nextToken: function PostScriptParser_nextToken() {
  42321. this.prev = this.token;
  42322. this.token = this.lexer.getToken();
  42323. },
  42324. accept: function PostScriptParser_accept(type) {
  42325. if (this.token.type === type) {
  42326. this.nextToken();
  42327. return true;
  42328. }
  42329. return false;
  42330. },
  42331. expect: function PostScriptParser_expect(type) {
  42332. if (this.accept(type)) {
  42333. return true;
  42334. }
  42335. error('Unexpected symbol: found ' + this.token.type + ' expected ' + type + '.');
  42336. },
  42337. parse: function PostScriptParser_parse() {
  42338. this.nextToken();
  42339. this.expect(PostScriptTokenTypes.LBRACE);
  42340. this.parseBlock();
  42341. this.expect(PostScriptTokenTypes.RBRACE);
  42342. return this.operators;
  42343. },
  42344. parseBlock: function PostScriptParser_parseBlock() {
  42345. while (true) {
  42346. if (this.accept(PostScriptTokenTypes.NUMBER)) {
  42347. this.operators.push(this.prev.value);
  42348. } else if (this.accept(PostScriptTokenTypes.OPERATOR)) {
  42349. this.operators.push(this.prev.value);
  42350. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  42351. this.parseCondition();
  42352. } else {
  42353. return;
  42354. }
  42355. }
  42356. },
  42357. parseCondition: function PostScriptParser_parseCondition() {
  42358. // Add two place holders that will be updated later
  42359. var conditionLocation = this.operators.length;
  42360. this.operators.push(null, null);
  42361. this.parseBlock();
  42362. this.expect(PostScriptTokenTypes.RBRACE);
  42363. if (this.accept(PostScriptTokenTypes.IF)) {
  42364. // The true block is right after the 'if' so it just falls through on
  42365. // true else it jumps and skips the true block.
  42366. this.operators[conditionLocation] = this.operators.length;
  42367. this.operators[conditionLocation + 1] = 'jz';
  42368. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  42369. var jumpLocation = this.operators.length;
  42370. this.operators.push(null, null);
  42371. var endOfTrue = this.operators.length;
  42372. this.parseBlock();
  42373. this.expect(PostScriptTokenTypes.RBRACE);
  42374. this.expect(PostScriptTokenTypes.IFELSE);
  42375. // The jump is added at the end of the true block to skip the false
  42376. // block.
  42377. this.operators[jumpLocation] = this.operators.length;
  42378. this.operators[jumpLocation + 1] = 'j';
  42379. this.operators[conditionLocation] = endOfTrue;
  42380. this.operators[conditionLocation + 1] = 'jz';
  42381. } else {
  42382. error('PS Function: error parsing conditional.');
  42383. }
  42384. }
  42385. };
  42386. return PostScriptParser;
  42387. }();
  42388. var PostScriptTokenTypes = {
  42389. LBRACE: 0,
  42390. RBRACE: 1,
  42391. NUMBER: 2,
  42392. OPERATOR: 3,
  42393. IF: 4,
  42394. IFELSE: 5
  42395. };
  42396. var PostScriptToken = function PostScriptTokenClosure() {
  42397. function PostScriptToken(type, value) {
  42398. this.type = type;
  42399. this.value = value;
  42400. }
  42401. var opCache = Object.create(null);
  42402. PostScriptToken.getOperator = function PostScriptToken_getOperator(op) {
  42403. var opValue = opCache[op];
  42404. if (opValue) {
  42405. return opValue;
  42406. }
  42407. return opCache[op] = new PostScriptToken(PostScriptTokenTypes.OPERATOR, op);
  42408. };
  42409. PostScriptToken.LBRACE = new PostScriptToken(PostScriptTokenTypes.LBRACE, '{');
  42410. PostScriptToken.RBRACE = new PostScriptToken(PostScriptTokenTypes.RBRACE, '}');
  42411. PostScriptToken.IF = new PostScriptToken(PostScriptTokenTypes.IF, 'IF');
  42412. PostScriptToken.IFELSE = new PostScriptToken(PostScriptTokenTypes.IFELSE, 'IFELSE');
  42413. return PostScriptToken;
  42414. }();
  42415. var PostScriptLexer = function PostScriptLexerClosure() {
  42416. function PostScriptLexer(stream) {
  42417. this.stream = stream;
  42418. this.nextChar();
  42419. this.strBuf = [];
  42420. }
  42421. PostScriptLexer.prototype = {
  42422. nextChar: function PostScriptLexer_nextChar() {
  42423. return this.currentChar = this.stream.getByte();
  42424. },
  42425. getToken: function PostScriptLexer_getToken() {
  42426. var comment = false;
  42427. var ch = this.currentChar;
  42428. // skip comments
  42429. while (true) {
  42430. if (ch < 0) {
  42431. return EOF;
  42432. }
  42433. if (comment) {
  42434. if (ch === 0x0A || ch === 0x0D) {
  42435. comment = false;
  42436. }
  42437. } else if (ch === 0x25) {
  42438. // '%'
  42439. comment = true;
  42440. } else if (!isSpace(ch)) {
  42441. break;
  42442. }
  42443. ch = this.nextChar();
  42444. }
  42445. switch (ch | 0) {
  42446. case 0x30:
  42447. case 0x31:
  42448. case 0x32:
  42449. case 0x33:
  42450. case 0x34:
  42451. // '0'-'4'
  42452. case 0x35:
  42453. case 0x36:
  42454. case 0x37:
  42455. case 0x38:
  42456. case 0x39:
  42457. // '5'-'9'
  42458. case 0x2B:
  42459. case 0x2D:
  42460. case 0x2E:
  42461. // '+', '-', '.'
  42462. return new PostScriptToken(PostScriptTokenTypes.NUMBER, this.getNumber());
  42463. case 0x7B:
  42464. // '{'
  42465. this.nextChar();
  42466. return PostScriptToken.LBRACE;
  42467. case 0x7D:
  42468. // '}'
  42469. this.nextChar();
  42470. return PostScriptToken.RBRACE;
  42471. }
  42472. // operator
  42473. var strBuf = this.strBuf;
  42474. strBuf.length = 0;
  42475. strBuf[0] = String.fromCharCode(ch);
  42476. while ((ch = this.nextChar()) >= 0 && // and 'A'-'Z', 'a'-'z'
  42477. (ch >= 0x41 && ch <= 0x5A || ch >= 0x61 && ch <= 0x7A)) {
  42478. strBuf.push(String.fromCharCode(ch));
  42479. }
  42480. var str = strBuf.join('');
  42481. switch (str.toLowerCase()) {
  42482. case 'if':
  42483. return PostScriptToken.IF;
  42484. case 'ifelse':
  42485. return PostScriptToken.IFELSE;
  42486. default:
  42487. return PostScriptToken.getOperator(str);
  42488. }
  42489. },
  42490. getNumber: function PostScriptLexer_getNumber() {
  42491. var ch = this.currentChar;
  42492. var strBuf = this.strBuf;
  42493. strBuf.length = 0;
  42494. strBuf[0] = String.fromCharCode(ch);
  42495. while ((ch = this.nextChar()) >= 0) {
  42496. if (ch >= 0x30 && ch <= 0x39 || // '0'-'9'
  42497. ch === 0x2D || ch === 0x2E) {
  42498. // '-', '.'
  42499. strBuf.push(String.fromCharCode(ch));
  42500. } else {
  42501. break;
  42502. }
  42503. }
  42504. var value = parseFloat(strBuf.join(''));
  42505. if (isNaN(value)) {
  42506. error('Invalid floating point number: ' + value);
  42507. }
  42508. return value;
  42509. }
  42510. };
  42511. return PostScriptLexer;
  42512. }();
  42513. exports.PostScriptLexer = PostScriptLexer;
  42514. exports.PostScriptParser = PostScriptParser;
  42515. }));
  42516. (function (root, factory) {
  42517. factory(root.pdfjsCoreFunction = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCorePsParser);
  42518. }(this, function (exports, sharedUtil, corePrimitives, corePsParser) {
  42519. var error = sharedUtil.error;
  42520. var info = sharedUtil.info;
  42521. var isArray = sharedUtil.isArray;
  42522. var isBool = sharedUtil.isBool;
  42523. var isDict = corePrimitives.isDict;
  42524. var isStream = corePrimitives.isStream;
  42525. var PostScriptLexer = corePsParser.PostScriptLexer;
  42526. var PostScriptParser = corePsParser.PostScriptParser;
  42527. var PDFFunction = function PDFFunctionClosure() {
  42528. var CONSTRUCT_SAMPLED = 0;
  42529. var CONSTRUCT_INTERPOLATED = 2;
  42530. var CONSTRUCT_STICHED = 3;
  42531. var CONSTRUCT_POSTSCRIPT = 4;
  42532. return {
  42533. getSampleArray: function PDFFunction_getSampleArray(size, outputSize, bps, str) {
  42534. var i, ii;
  42535. var length = 1;
  42536. for (i = 0, ii = size.length; i < ii; i++) {
  42537. length *= size[i];
  42538. }
  42539. length *= outputSize;
  42540. var array = new Array(length);
  42541. var codeSize = 0;
  42542. var codeBuf = 0;
  42543. // 32 is a valid bps so shifting won't work
  42544. var sampleMul = 1.0 / (Math.pow(2.0, bps) - 1);
  42545. var strBytes = str.getBytes((length * bps + 7) / 8);
  42546. var strIdx = 0;
  42547. for (i = 0; i < length; i++) {
  42548. while (codeSize < bps) {
  42549. codeBuf <<= 8;
  42550. codeBuf |= strBytes[strIdx++];
  42551. codeSize += 8;
  42552. }
  42553. codeSize -= bps;
  42554. array[i] = (codeBuf >> codeSize) * sampleMul;
  42555. codeBuf &= (1 << codeSize) - 1;
  42556. }
  42557. return array;
  42558. },
  42559. getIR: function PDFFunction_getIR(xref, fn) {
  42560. var dict = fn.dict;
  42561. if (!dict) {
  42562. dict = fn;
  42563. }
  42564. var types = [
  42565. this.constructSampled,
  42566. null,
  42567. this.constructInterpolated,
  42568. this.constructStiched,
  42569. this.constructPostScript
  42570. ];
  42571. var typeNum = dict.get('FunctionType');
  42572. var typeFn = types[typeNum];
  42573. if (!typeFn) {
  42574. error('Unknown type of function');
  42575. }
  42576. return typeFn.call(this, fn, dict, xref);
  42577. },
  42578. fromIR: function PDFFunction_fromIR(IR) {
  42579. var type = IR[0];
  42580. switch (type) {
  42581. case CONSTRUCT_SAMPLED:
  42582. return this.constructSampledFromIR(IR);
  42583. case CONSTRUCT_INTERPOLATED:
  42584. return this.constructInterpolatedFromIR(IR);
  42585. case CONSTRUCT_STICHED:
  42586. return this.constructStichedFromIR(IR);
  42587. //case CONSTRUCT_POSTSCRIPT:
  42588. default:
  42589. return this.constructPostScriptFromIR(IR);
  42590. }
  42591. },
  42592. parse: function PDFFunction_parse(xref, fn) {
  42593. var IR = this.getIR(xref, fn);
  42594. return this.fromIR(IR);
  42595. },
  42596. parseArray: function PDFFunction_parseArray(xref, fnObj) {
  42597. if (!isArray(fnObj)) {
  42598. // not an array -- parsing as regular function
  42599. return this.parse(xref, fnObj);
  42600. }
  42601. var fnArray = [];
  42602. for (var j = 0, jj = fnObj.length; j < jj; j++) {
  42603. var obj = xref.fetchIfRef(fnObj[j]);
  42604. fnArray.push(PDFFunction.parse(xref, obj));
  42605. }
  42606. return function (src, srcOffset, dest, destOffset) {
  42607. for (var i = 0, ii = fnArray.length; i < ii; i++) {
  42608. fnArray[i](src, srcOffset, dest, destOffset + i);
  42609. }
  42610. };
  42611. },
  42612. constructSampled: function PDFFunction_constructSampled(str, dict) {
  42613. function toMultiArray(arr) {
  42614. var inputLength = arr.length;
  42615. var out = [];
  42616. var index = 0;
  42617. for (var i = 0; i < inputLength; i += 2) {
  42618. out[index] = [
  42619. arr[i],
  42620. arr[i + 1]
  42621. ];
  42622. ++index;
  42623. }
  42624. return out;
  42625. }
  42626. var domain = dict.getArray('Domain');
  42627. var range = dict.getArray('Range');
  42628. if (!domain || !range) {
  42629. error('No domain or range');
  42630. }
  42631. var inputSize = domain.length / 2;
  42632. var outputSize = range.length / 2;
  42633. domain = toMultiArray(domain);
  42634. range = toMultiArray(range);
  42635. var size = dict.get('Size');
  42636. var bps = dict.get('BitsPerSample');
  42637. var order = dict.get('Order') || 1;
  42638. if (order !== 1) {
  42639. // No description how cubic spline interpolation works in PDF32000:2008
  42640. // As in poppler, ignoring order, linear interpolation may work as good
  42641. info('No support for cubic spline interpolation: ' + order);
  42642. }
  42643. var encode = dict.getArray('Encode');
  42644. if (!encode) {
  42645. encode = [];
  42646. for (var i = 0; i < inputSize; ++i) {
  42647. encode.push(0);
  42648. encode.push(size[i] - 1);
  42649. }
  42650. }
  42651. encode = toMultiArray(encode);
  42652. var decode = dict.getArray('Decode');
  42653. if (!decode) {
  42654. decode = range;
  42655. } else {
  42656. decode = toMultiArray(decode);
  42657. }
  42658. var samples = this.getSampleArray(size, outputSize, bps, str);
  42659. return [
  42660. CONSTRUCT_SAMPLED,
  42661. inputSize,
  42662. domain,
  42663. encode,
  42664. decode,
  42665. samples,
  42666. size,
  42667. outputSize,
  42668. Math.pow(2, bps) - 1,
  42669. range
  42670. ];
  42671. },
  42672. constructSampledFromIR: function PDFFunction_constructSampledFromIR(IR) {
  42673. // See chapter 3, page 109 of the PDF reference
  42674. function interpolate(x, xmin, xmax, ymin, ymax) {
  42675. return ymin + (x - xmin) * ((ymax - ymin) / (xmax - xmin));
  42676. }
  42677. return function constructSampledFromIRResult(src, srcOffset, dest, destOffset) {
  42678. // See chapter 3, page 110 of the PDF reference.
  42679. var m = IR[1];
  42680. var domain = IR[2];
  42681. var encode = IR[3];
  42682. var decode = IR[4];
  42683. var samples = IR[5];
  42684. var size = IR[6];
  42685. var n = IR[7];
  42686. //var mask = IR[8];
  42687. var range = IR[9];
  42688. // Building the cube vertices: its part and sample index
  42689. // http://rjwagner49.com/Mathematics/Interpolation.pdf
  42690. var cubeVertices = 1 << m;
  42691. var cubeN = new Float64Array(cubeVertices);
  42692. var cubeVertex = new Uint32Array(cubeVertices);
  42693. var i, j;
  42694. for (j = 0; j < cubeVertices; j++) {
  42695. cubeN[j] = 1;
  42696. }
  42697. var k = n, pos = 1;
  42698. // Map x_i to y_j for 0 <= i < m using the sampled function.
  42699. for (i = 0; i < m; ++i) {
  42700. // x_i' = min(max(x_i, Domain_2i), Domain_2i+1)
  42701. var domain_2i = domain[i][0];
  42702. var domain_2i_1 = domain[i][1];
  42703. var xi = Math.min(Math.max(src[srcOffset + i], domain_2i), domain_2i_1);
  42704. // e_i = Interpolate(x_i', Domain_2i, Domain_2i+1,
  42705. // Encode_2i, Encode_2i+1)
  42706. var e = interpolate(xi, domain_2i, domain_2i_1, encode[i][0], encode[i][1]);
  42707. // e_i' = min(max(e_i, 0), Size_i - 1)
  42708. var size_i = size[i];
  42709. e = Math.min(Math.max(e, 0), size_i - 1);
  42710. // Adjusting the cube: N and vertex sample index
  42711. var e0 = e < size_i - 1 ? Math.floor(e) : e - 1;
  42712. // e1 = e0 + 1;
  42713. var n0 = e0 + 1 - e;
  42714. // (e1 - e) / (e1 - e0);
  42715. var n1 = e - e0;
  42716. // (e - e0) / (e1 - e0);
  42717. var offset0 = e0 * k;
  42718. var offset1 = offset0 + k;
  42719. // e1 * k
  42720. for (j = 0; j < cubeVertices; j++) {
  42721. if (j & pos) {
  42722. cubeN[j] *= n1;
  42723. cubeVertex[j] += offset1;
  42724. } else {
  42725. cubeN[j] *= n0;
  42726. cubeVertex[j] += offset0;
  42727. }
  42728. }
  42729. k *= size_i;
  42730. pos <<= 1;
  42731. }
  42732. for (j = 0; j < n; ++j) {
  42733. // Sum all cube vertices' samples portions
  42734. var rj = 0;
  42735. for (i = 0; i < cubeVertices; i++) {
  42736. rj += samples[cubeVertex[i] + j] * cubeN[i];
  42737. }
  42738. // r_j' = Interpolate(r_j, 0, 2^BitsPerSample - 1,
  42739. // Decode_2j, Decode_2j+1)
  42740. rj = interpolate(rj, 0, 1, decode[j][0], decode[j][1]);
  42741. // y_j = min(max(r_j, range_2j), range_2j+1)
  42742. dest[destOffset + j] = Math.min(Math.max(rj, range[j][0]), range[j][1]);
  42743. }
  42744. };
  42745. },
  42746. constructInterpolated: function PDFFunction_constructInterpolated(str, dict) {
  42747. var c0 = dict.getArray('C0') || [0];
  42748. var c1 = dict.getArray('C1') || [1];
  42749. var n = dict.get('N');
  42750. if (!isArray(c0) || !isArray(c1)) {
  42751. error('Illegal dictionary for interpolated function');
  42752. }
  42753. var length = c0.length;
  42754. var diff = [];
  42755. for (var i = 0; i < length; ++i) {
  42756. diff.push(c1[i] - c0[i]);
  42757. }
  42758. return [
  42759. CONSTRUCT_INTERPOLATED,
  42760. c0,
  42761. diff,
  42762. n
  42763. ];
  42764. },
  42765. constructInterpolatedFromIR: function PDFFunction_constructInterpolatedFromIR(IR) {
  42766. var c0 = IR[1];
  42767. var diff = IR[2];
  42768. var n = IR[3];
  42769. var length = diff.length;
  42770. return function constructInterpolatedFromIRResult(src, srcOffset, dest, destOffset) {
  42771. var x = n === 1 ? src[srcOffset] : Math.pow(src[srcOffset], n);
  42772. for (var j = 0; j < length; ++j) {
  42773. dest[destOffset + j] = c0[j] + x * diff[j];
  42774. }
  42775. };
  42776. },
  42777. constructStiched: function PDFFunction_constructStiched(fn, dict, xref) {
  42778. var domain = dict.getArray('Domain');
  42779. if (!domain) {
  42780. error('No domain');
  42781. }
  42782. var inputSize = domain.length / 2;
  42783. if (inputSize !== 1) {
  42784. error('Bad domain for stiched function');
  42785. }
  42786. var fnRefs = dict.get('Functions');
  42787. var fns = [];
  42788. for (var i = 0, ii = fnRefs.length; i < ii; ++i) {
  42789. fns.push(PDFFunction.getIR(xref, xref.fetchIfRef(fnRefs[i])));
  42790. }
  42791. var bounds = dict.getArray('Bounds');
  42792. var encode = dict.getArray('Encode');
  42793. return [
  42794. CONSTRUCT_STICHED,
  42795. domain,
  42796. bounds,
  42797. encode,
  42798. fns
  42799. ];
  42800. },
  42801. constructStichedFromIR: function PDFFunction_constructStichedFromIR(IR) {
  42802. var domain = IR[1];
  42803. var bounds = IR[2];
  42804. var encode = IR[3];
  42805. var fnsIR = IR[4];
  42806. var fns = [];
  42807. var tmpBuf = new Float32Array(1);
  42808. for (var i = 0, ii = fnsIR.length; i < ii; i++) {
  42809. fns.push(PDFFunction.fromIR(fnsIR[i]));
  42810. }
  42811. return function constructStichedFromIRResult(src, srcOffset, dest, destOffset) {
  42812. var clip = function constructStichedFromIRClip(v, min, max) {
  42813. if (v > max) {
  42814. v = max;
  42815. } else if (v < min) {
  42816. v = min;
  42817. }
  42818. return v;
  42819. };
  42820. // clip to domain
  42821. var v = clip(src[srcOffset], domain[0], domain[1]);
  42822. // calculate which bound the value is in
  42823. for (var i = 0, ii = bounds.length; i < ii; ++i) {
  42824. if (v < bounds[i]) {
  42825. break;
  42826. }
  42827. }
  42828. // encode value into domain of function
  42829. var dmin = domain[0];
  42830. if (i > 0) {
  42831. dmin = bounds[i - 1];
  42832. }
  42833. var dmax = domain[1];
  42834. if (i < bounds.length) {
  42835. dmax = bounds[i];
  42836. }
  42837. var rmin = encode[2 * i];
  42838. var rmax = encode[2 * i + 1];
  42839. // Prevent the value from becoming NaN as a result
  42840. // of division by zero (fixes issue6113.pdf).
  42841. tmpBuf[0] = dmin === dmax ? rmin : rmin + (v - dmin) * (rmax - rmin) / (dmax - dmin);
  42842. // call the appropriate function
  42843. fns[i](tmpBuf, 0, dest, destOffset);
  42844. };
  42845. },
  42846. constructPostScript: function PDFFunction_constructPostScript(fn, dict, xref) {
  42847. var domain = dict.getArray('Domain');
  42848. var range = dict.getArray('Range');
  42849. if (!domain) {
  42850. error('No domain.');
  42851. }
  42852. if (!range) {
  42853. error('No range.');
  42854. }
  42855. var lexer = new PostScriptLexer(fn);
  42856. var parser = new PostScriptParser(lexer);
  42857. var code = parser.parse();
  42858. return [
  42859. CONSTRUCT_POSTSCRIPT,
  42860. domain,
  42861. range,
  42862. code
  42863. ];
  42864. },
  42865. constructPostScriptFromIR: function PDFFunction_constructPostScriptFromIR(IR) {
  42866. var domain = IR[1];
  42867. var range = IR[2];
  42868. var code = IR[3];
  42869. var compiled = new PostScriptCompiler().compile(code, domain, range);
  42870. if (compiled) {
  42871. // Compiled function consists of simple expressions such as addition,
  42872. // subtraction, Math.max, and also contains 'var' and 'return'
  42873. // statements. See the generation in the PostScriptCompiler below.
  42874. return new Function('src', 'srcOffset', 'dest', 'destOffset', compiled);
  42875. }
  42876. info('Unable to compile PS function');
  42877. var numOutputs = range.length >> 1;
  42878. var numInputs = domain.length >> 1;
  42879. var evaluator = new PostScriptEvaluator(code);
  42880. // Cache the values for a big speed up, the cache size is limited though
  42881. // since the number of possible values can be huge from a PS function.
  42882. var cache = Object.create(null);
  42883. // The MAX_CACHE_SIZE is set to ~4x the maximum number of distinct values
  42884. // seen in our tests.
  42885. var MAX_CACHE_SIZE = 2048 * 4;
  42886. var cache_available = MAX_CACHE_SIZE;
  42887. var tmpBuf = new Float32Array(numInputs);
  42888. return function constructPostScriptFromIRResult(src, srcOffset, dest, destOffset) {
  42889. var i, value;
  42890. var key = '';
  42891. var input = tmpBuf;
  42892. for (i = 0; i < numInputs; i++) {
  42893. value = src[srcOffset + i];
  42894. input[i] = value;
  42895. key += value + '_';
  42896. }
  42897. var cachedValue = cache[key];
  42898. if (cachedValue !== undefined) {
  42899. dest.set(cachedValue, destOffset);
  42900. return;
  42901. }
  42902. var output = new Float32Array(numOutputs);
  42903. var stack = evaluator.execute(input);
  42904. var stackIndex = stack.length - numOutputs;
  42905. for (i = 0; i < numOutputs; i++) {
  42906. value = stack[stackIndex + i];
  42907. var bound = range[i * 2];
  42908. if (value < bound) {
  42909. value = bound;
  42910. } else {
  42911. bound = range[i * 2 + 1];
  42912. if (value > bound) {
  42913. value = bound;
  42914. }
  42915. }
  42916. output[i] = value;
  42917. }
  42918. if (cache_available > 0) {
  42919. cache_available--;
  42920. cache[key] = output;
  42921. }
  42922. dest.set(output, destOffset);
  42923. };
  42924. }
  42925. };
  42926. }();
  42927. function isPDFFunction(v) {
  42928. var fnDict;
  42929. if (typeof v !== 'object') {
  42930. return false;
  42931. } else if (isDict(v)) {
  42932. fnDict = v;
  42933. } else if (isStream(v)) {
  42934. fnDict = v.dict;
  42935. } else {
  42936. return false;
  42937. }
  42938. return fnDict.has('FunctionType');
  42939. }
  42940. var PostScriptStack = function PostScriptStackClosure() {
  42941. var MAX_STACK_SIZE = 100;
  42942. function PostScriptStack(initialStack) {
  42943. this.stack = !initialStack ? [] : Array.prototype.slice.call(initialStack, 0);
  42944. }
  42945. PostScriptStack.prototype = {
  42946. push: function PostScriptStack_push(value) {
  42947. if (this.stack.length >= MAX_STACK_SIZE) {
  42948. error('PostScript function stack overflow.');
  42949. }
  42950. this.stack.push(value);
  42951. },
  42952. pop: function PostScriptStack_pop() {
  42953. if (this.stack.length <= 0) {
  42954. error('PostScript function stack underflow.');
  42955. }
  42956. return this.stack.pop();
  42957. },
  42958. copy: function PostScriptStack_copy(n) {
  42959. if (this.stack.length + n >= MAX_STACK_SIZE) {
  42960. error('PostScript function stack overflow.');
  42961. }
  42962. var stack = this.stack;
  42963. for (var i = stack.length - n, j = n - 1; j >= 0; j--, i++) {
  42964. stack.push(stack[i]);
  42965. }
  42966. },
  42967. index: function PostScriptStack_index(n) {
  42968. this.push(this.stack[this.stack.length - n - 1]);
  42969. },
  42970. // rotate the last n stack elements p times
  42971. roll: function PostScriptStack_roll(n, p) {
  42972. var stack = this.stack;
  42973. var l = stack.length - n;
  42974. var r = stack.length - 1, c = l + (p - Math.floor(p / n) * n), i, j, t;
  42975. for (i = l, j = r; i < j; i++, j--) {
  42976. t = stack[i];
  42977. stack[i] = stack[j];
  42978. stack[j] = t;
  42979. }
  42980. for (i = l, j = c - 1; i < j; i++, j--) {
  42981. t = stack[i];
  42982. stack[i] = stack[j];
  42983. stack[j] = t;
  42984. }
  42985. for (i = c, j = r; i < j; i++, j--) {
  42986. t = stack[i];
  42987. stack[i] = stack[j];
  42988. stack[j] = t;
  42989. }
  42990. }
  42991. };
  42992. return PostScriptStack;
  42993. }();
  42994. var PostScriptEvaluator = function PostScriptEvaluatorClosure() {
  42995. function PostScriptEvaluator(operators) {
  42996. this.operators = operators;
  42997. }
  42998. PostScriptEvaluator.prototype = {
  42999. execute: function PostScriptEvaluator_execute(initialStack) {
  43000. var stack = new PostScriptStack(initialStack);
  43001. var counter = 0;
  43002. var operators = this.operators;
  43003. var length = operators.length;
  43004. var operator, a, b;
  43005. while (counter < length) {
  43006. operator = operators[counter++];
  43007. if (typeof operator === 'number') {
  43008. // Operator is really an operand and should be pushed to the stack.
  43009. stack.push(operator);
  43010. continue;
  43011. }
  43012. switch (operator) {
  43013. // non standard ps operators
  43014. case 'jz':
  43015. // jump if false
  43016. b = stack.pop();
  43017. a = stack.pop();
  43018. if (!a) {
  43019. counter = b;
  43020. }
  43021. break;
  43022. case 'j':
  43023. // jump
  43024. a = stack.pop();
  43025. counter = a;
  43026. break;
  43027. // all ps operators in alphabetical order (excluding if/ifelse)
  43028. case 'abs':
  43029. a = stack.pop();
  43030. stack.push(Math.abs(a));
  43031. break;
  43032. case 'add':
  43033. b = stack.pop();
  43034. a = stack.pop();
  43035. stack.push(a + b);
  43036. break;
  43037. case 'and':
  43038. b = stack.pop();
  43039. a = stack.pop();
  43040. if (isBool(a) && isBool(b)) {
  43041. stack.push(a && b);
  43042. } else {
  43043. stack.push(a & b);
  43044. }
  43045. break;
  43046. case 'atan':
  43047. a = stack.pop();
  43048. stack.push(Math.atan(a));
  43049. break;
  43050. case 'bitshift':
  43051. b = stack.pop();
  43052. a = stack.pop();
  43053. if (a > 0) {
  43054. stack.push(a << b);
  43055. } else {
  43056. stack.push(a >> b);
  43057. }
  43058. break;
  43059. case 'ceiling':
  43060. a = stack.pop();
  43061. stack.push(Math.ceil(a));
  43062. break;
  43063. case 'copy':
  43064. a = stack.pop();
  43065. stack.copy(a);
  43066. break;
  43067. case 'cos':
  43068. a = stack.pop();
  43069. stack.push(Math.cos(a));
  43070. break;
  43071. case 'cvi':
  43072. a = stack.pop() | 0;
  43073. stack.push(a);
  43074. break;
  43075. case 'cvr':
  43076. // noop
  43077. break;
  43078. case 'div':
  43079. b = stack.pop();
  43080. a = stack.pop();
  43081. stack.push(a / b);
  43082. break;
  43083. case 'dup':
  43084. stack.copy(1);
  43085. break;
  43086. case 'eq':
  43087. b = stack.pop();
  43088. a = stack.pop();
  43089. stack.push(a === b);
  43090. break;
  43091. case 'exch':
  43092. stack.roll(2, 1);
  43093. break;
  43094. case 'exp':
  43095. b = stack.pop();
  43096. a = stack.pop();
  43097. stack.push(Math.pow(a, b));
  43098. break;
  43099. case 'false':
  43100. stack.push(false);
  43101. break;
  43102. case 'floor':
  43103. a = stack.pop();
  43104. stack.push(Math.floor(a));
  43105. break;
  43106. case 'ge':
  43107. b = stack.pop();
  43108. a = stack.pop();
  43109. stack.push(a >= b);
  43110. break;
  43111. case 'gt':
  43112. b = stack.pop();
  43113. a = stack.pop();
  43114. stack.push(a > b);
  43115. break;
  43116. case 'idiv':
  43117. b = stack.pop();
  43118. a = stack.pop();
  43119. stack.push(a / b | 0);
  43120. break;
  43121. case 'index':
  43122. a = stack.pop();
  43123. stack.index(a);
  43124. break;
  43125. case 'le':
  43126. b = stack.pop();
  43127. a = stack.pop();
  43128. stack.push(a <= b);
  43129. break;
  43130. case 'ln':
  43131. a = stack.pop();
  43132. stack.push(Math.log(a));
  43133. break;
  43134. case 'log':
  43135. a = stack.pop();
  43136. stack.push(Math.log(a) / Math.LN10);
  43137. break;
  43138. case 'lt':
  43139. b = stack.pop();
  43140. a = stack.pop();
  43141. stack.push(a < b);
  43142. break;
  43143. case 'mod':
  43144. b = stack.pop();
  43145. a = stack.pop();
  43146. stack.push(a % b);
  43147. break;
  43148. case 'mul':
  43149. b = stack.pop();
  43150. a = stack.pop();
  43151. stack.push(a * b);
  43152. break;
  43153. case 'ne':
  43154. b = stack.pop();
  43155. a = stack.pop();
  43156. stack.push(a !== b);
  43157. break;
  43158. case 'neg':
  43159. a = stack.pop();
  43160. stack.push(-a);
  43161. break;
  43162. case 'not':
  43163. a = stack.pop();
  43164. if (isBool(a)) {
  43165. stack.push(!a);
  43166. } else {
  43167. stack.push(~a);
  43168. }
  43169. break;
  43170. case 'or':
  43171. b = stack.pop();
  43172. a = stack.pop();
  43173. if (isBool(a) && isBool(b)) {
  43174. stack.push(a || b);
  43175. } else {
  43176. stack.push(a | b);
  43177. }
  43178. break;
  43179. case 'pop':
  43180. stack.pop();
  43181. break;
  43182. case 'roll':
  43183. b = stack.pop();
  43184. a = stack.pop();
  43185. stack.roll(a, b);
  43186. break;
  43187. case 'round':
  43188. a = stack.pop();
  43189. stack.push(Math.round(a));
  43190. break;
  43191. case 'sin':
  43192. a = stack.pop();
  43193. stack.push(Math.sin(a));
  43194. break;
  43195. case 'sqrt':
  43196. a = stack.pop();
  43197. stack.push(Math.sqrt(a));
  43198. break;
  43199. case 'sub':
  43200. b = stack.pop();
  43201. a = stack.pop();
  43202. stack.push(a - b);
  43203. break;
  43204. case 'true':
  43205. stack.push(true);
  43206. break;
  43207. case 'truncate':
  43208. a = stack.pop();
  43209. a = a < 0 ? Math.ceil(a) : Math.floor(a);
  43210. stack.push(a);
  43211. break;
  43212. case 'xor':
  43213. b = stack.pop();
  43214. a = stack.pop();
  43215. if (isBool(a) && isBool(b)) {
  43216. stack.push(a !== b);
  43217. } else {
  43218. stack.push(a ^ b);
  43219. }
  43220. break;
  43221. default:
  43222. error('Unknown operator ' + operator);
  43223. break;
  43224. }
  43225. }
  43226. return stack.stack;
  43227. }
  43228. };
  43229. return PostScriptEvaluator;
  43230. }();
  43231. // Most of the PDFs functions consist of simple operations such as:
  43232. // roll, exch, sub, cvr, pop, index, dup, mul, if, gt, add.
  43233. //
  43234. // We can compile most of such programs, and at the same moment, we can
  43235. // optimize some expressions using basic math properties. Keeping track of
  43236. // min/max values will allow us to avoid extra Math.min/Math.max calls.
  43237. var PostScriptCompiler = function PostScriptCompilerClosure() {
  43238. function AstNode(type) {
  43239. this.type = type;
  43240. }
  43241. AstNode.prototype.visit = function (visitor) {
  43242. throw new Error('abstract method');
  43243. };
  43244. function AstArgument(index, min, max) {
  43245. AstNode.call(this, 'args');
  43246. this.index = index;
  43247. this.min = min;
  43248. this.max = max;
  43249. }
  43250. AstArgument.prototype = Object.create(AstNode.prototype);
  43251. AstArgument.prototype.visit = function (visitor) {
  43252. visitor.visitArgument(this);
  43253. };
  43254. function AstLiteral(number) {
  43255. AstNode.call(this, 'literal');
  43256. this.number = number;
  43257. this.min = number;
  43258. this.max = number;
  43259. }
  43260. AstLiteral.prototype = Object.create(AstNode.prototype);
  43261. AstLiteral.prototype.visit = function (visitor) {
  43262. visitor.visitLiteral(this);
  43263. };
  43264. function AstBinaryOperation(op, arg1, arg2, min, max) {
  43265. AstNode.call(this, 'binary');
  43266. this.op = op;
  43267. this.arg1 = arg1;
  43268. this.arg2 = arg2;
  43269. this.min = min;
  43270. this.max = max;
  43271. }
  43272. AstBinaryOperation.prototype = Object.create(AstNode.prototype);
  43273. AstBinaryOperation.prototype.visit = function (visitor) {
  43274. visitor.visitBinaryOperation(this);
  43275. };
  43276. function AstMin(arg, max) {
  43277. AstNode.call(this, 'max');
  43278. this.arg = arg;
  43279. this.min = arg.min;
  43280. this.max = max;
  43281. }
  43282. AstMin.prototype = Object.create(AstNode.prototype);
  43283. AstMin.prototype.visit = function (visitor) {
  43284. visitor.visitMin(this);
  43285. };
  43286. function AstVariable(index, min, max) {
  43287. AstNode.call(this, 'var');
  43288. this.index = index;
  43289. this.min = min;
  43290. this.max = max;
  43291. }
  43292. AstVariable.prototype = Object.create(AstNode.prototype);
  43293. AstVariable.prototype.visit = function (visitor) {
  43294. visitor.visitVariable(this);
  43295. };
  43296. function AstVariableDefinition(variable, arg) {
  43297. AstNode.call(this, 'definition');
  43298. this.variable = variable;
  43299. this.arg = arg;
  43300. }
  43301. AstVariableDefinition.prototype = Object.create(AstNode.prototype);
  43302. AstVariableDefinition.prototype.visit = function (visitor) {
  43303. visitor.visitVariableDefinition(this);
  43304. };
  43305. function ExpressionBuilderVisitor() {
  43306. this.parts = [];
  43307. }
  43308. ExpressionBuilderVisitor.prototype = {
  43309. visitArgument: function (arg) {
  43310. this.parts.push('Math.max(', arg.min, ', Math.min(', arg.max, ', src[srcOffset + ', arg.index, ']))');
  43311. },
  43312. visitVariable: function (variable) {
  43313. this.parts.push('v', variable.index);
  43314. },
  43315. visitLiteral: function (literal) {
  43316. this.parts.push(literal.number);
  43317. },
  43318. visitBinaryOperation: function (operation) {
  43319. this.parts.push('(');
  43320. operation.arg1.visit(this);
  43321. this.parts.push(' ', operation.op, ' ');
  43322. operation.arg2.visit(this);
  43323. this.parts.push(')');
  43324. },
  43325. visitVariableDefinition: function (definition) {
  43326. this.parts.push('var ');
  43327. definition.variable.visit(this);
  43328. this.parts.push(' = ');
  43329. definition.arg.visit(this);
  43330. this.parts.push(';');
  43331. },
  43332. visitMin: function (max) {
  43333. this.parts.push('Math.min(');
  43334. max.arg.visit(this);
  43335. this.parts.push(', ', max.max, ')');
  43336. },
  43337. toString: function () {
  43338. return this.parts.join('');
  43339. }
  43340. };
  43341. function buildAddOperation(num1, num2) {
  43342. if (num2.type === 'literal' && num2.number === 0) {
  43343. // optimization: second operand is 0
  43344. return num1;
  43345. }
  43346. if (num1.type === 'literal' && num1.number === 0) {
  43347. // optimization: first operand is 0
  43348. return num2;
  43349. }
  43350. if (num2.type === 'literal' && num1.type === 'literal') {
  43351. // optimization: operands operand are literals
  43352. return new AstLiteral(num1.number + num2.number);
  43353. }
  43354. return new AstBinaryOperation('+', num1, num2, num1.min + num2.min, num1.max + num2.max);
  43355. }
  43356. function buildMulOperation(num1, num2) {
  43357. if (num2.type === 'literal') {
  43358. // optimization: second operands is a literal...
  43359. if (num2.number === 0) {
  43360. return new AstLiteral(0);
  43361. } else // and it's 0
  43362. if (num2.number === 1) {
  43363. return num1;
  43364. } else // and it's 1
  43365. if (num1.type === 'literal') {
  43366. // ... and first operands is a literal too
  43367. return new AstLiteral(num1.number * num2.number);
  43368. }
  43369. }
  43370. if (num1.type === 'literal') {
  43371. // optimization: first operands is a literal...
  43372. if (num1.number === 0) {
  43373. return new AstLiteral(0);
  43374. } else // and it's 0
  43375. if (num1.number === 1) {
  43376. return num2;
  43377. }
  43378. }
  43379. // and it's 1
  43380. var min = Math.min(num1.min * num2.min, num1.min * num2.max, num1.max * num2.min, num1.max * num2.max);
  43381. var max = Math.max(num1.min * num2.min, num1.min * num2.max, num1.max * num2.min, num1.max * num2.max);
  43382. return new AstBinaryOperation('*', num1, num2, min, max);
  43383. }
  43384. function buildSubOperation(num1, num2) {
  43385. if (num2.type === 'literal') {
  43386. // optimization: second operands is a literal...
  43387. if (num2.number === 0) {
  43388. return num1;
  43389. } else // ... and it's 0
  43390. if (num1.type === 'literal') {
  43391. // ... and first operands is a literal too
  43392. return new AstLiteral(num1.number - num2.number);
  43393. }
  43394. }
  43395. if (num2.type === 'binary' && num2.op === '-' && num1.type === 'literal' && num1.number === 1 && num2.arg1.type === 'literal' && num2.arg1.number === 1) {
  43396. // optimization for case: 1 - (1 - x)
  43397. return num2.arg2;
  43398. }
  43399. return new AstBinaryOperation('-', num1, num2, num1.min - num2.max, num1.max - num2.min);
  43400. }
  43401. function buildMinOperation(num1, max) {
  43402. if (num1.min >= max) {
  43403. // optimization: num1 min value is not less than required max
  43404. return new AstLiteral(max);
  43405. } else // just returning max
  43406. if (num1.max <= max) {
  43407. // optimization: num1 max value is not greater than required max
  43408. return num1;
  43409. }
  43410. // just returning an argument
  43411. return new AstMin(num1, max);
  43412. }
  43413. function PostScriptCompiler() {
  43414. }
  43415. PostScriptCompiler.prototype = {
  43416. compile: function PostScriptCompiler_compile(code, domain, range) {
  43417. var stack = [];
  43418. var i, ii;
  43419. var instructions = [];
  43420. var inputSize = domain.length >> 1, outputSize = range.length >> 1;
  43421. var lastRegister = 0;
  43422. var n, j;
  43423. var num1, num2, ast1, ast2, tmpVar, item;
  43424. for (i = 0; i < inputSize; i++) {
  43425. stack.push(new AstArgument(i, domain[i * 2], domain[i * 2 + 1]));
  43426. }
  43427. for (i = 0, ii = code.length; i < ii; i++) {
  43428. item = code[i];
  43429. if (typeof item === 'number') {
  43430. stack.push(new AstLiteral(item));
  43431. continue;
  43432. }
  43433. switch (item) {
  43434. case 'add':
  43435. if (stack.length < 2) {
  43436. return null;
  43437. }
  43438. num2 = stack.pop();
  43439. num1 = stack.pop();
  43440. stack.push(buildAddOperation(num1, num2));
  43441. break;
  43442. case 'cvr':
  43443. if (stack.length < 1) {
  43444. return null;
  43445. }
  43446. break;
  43447. case 'mul':
  43448. if (stack.length < 2) {
  43449. return null;
  43450. }
  43451. num2 = stack.pop();
  43452. num1 = stack.pop();
  43453. stack.push(buildMulOperation(num1, num2));
  43454. break;
  43455. case 'sub':
  43456. if (stack.length < 2) {
  43457. return null;
  43458. }
  43459. num2 = stack.pop();
  43460. num1 = stack.pop();
  43461. stack.push(buildSubOperation(num1, num2));
  43462. break;
  43463. case 'exch':
  43464. if (stack.length < 2) {
  43465. return null;
  43466. }
  43467. ast1 = stack.pop();
  43468. ast2 = stack.pop();
  43469. stack.push(ast1, ast2);
  43470. break;
  43471. case 'pop':
  43472. if (stack.length < 1) {
  43473. return null;
  43474. }
  43475. stack.pop();
  43476. break;
  43477. case 'index':
  43478. if (stack.length < 1) {
  43479. return null;
  43480. }
  43481. num1 = stack.pop();
  43482. if (num1.type !== 'literal') {
  43483. return null;
  43484. }
  43485. n = num1.number;
  43486. if (n < 0 || (n | 0) !== n || stack.length < n) {
  43487. return null;
  43488. }
  43489. ast1 = stack[stack.length - n - 1];
  43490. if (ast1.type === 'literal' || ast1.type === 'var') {
  43491. stack.push(ast1);
  43492. break;
  43493. }
  43494. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  43495. stack[stack.length - n - 1] = tmpVar;
  43496. stack.push(tmpVar);
  43497. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  43498. break;
  43499. case 'dup':
  43500. if (stack.length < 1) {
  43501. return null;
  43502. }
  43503. 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]) {
  43504. // special case of the commands sequence for the min operation
  43505. num1 = stack.pop();
  43506. stack.push(buildMinOperation(num1, code[i + 1]));
  43507. i += 6;
  43508. break;
  43509. }
  43510. ast1 = stack[stack.length - 1];
  43511. if (ast1.type === 'literal' || ast1.type === 'var') {
  43512. // we don't have to save into intermediate variable a literal or
  43513. // variable.
  43514. stack.push(ast1);
  43515. break;
  43516. }
  43517. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  43518. stack[stack.length - 1] = tmpVar;
  43519. stack.push(tmpVar);
  43520. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  43521. break;
  43522. case 'roll':
  43523. if (stack.length < 2) {
  43524. return null;
  43525. }
  43526. num2 = stack.pop();
  43527. num1 = stack.pop();
  43528. if (num2.type !== 'literal' || num1.type !== 'literal') {
  43529. // both roll operands must be numbers
  43530. return null;
  43531. }
  43532. j = num2.number;
  43533. n = num1.number;
  43534. if (n <= 0 || (n | 0) !== n || (j | 0) !== j || stack.length < n) {
  43535. // ... and integers
  43536. return null;
  43537. }
  43538. j = (j % n + n) % n;
  43539. if (j === 0) {
  43540. break;
  43541. }
  43542. // just skipping -- there are nothing to rotate
  43543. Array.prototype.push.apply(stack, stack.splice(stack.length - n, n - j));
  43544. break;
  43545. default:
  43546. return null;
  43547. }
  43548. }
  43549. // unsupported operator
  43550. if (stack.length !== outputSize) {
  43551. return null;
  43552. }
  43553. var result = [];
  43554. instructions.forEach(function (instruction) {
  43555. var statementBuilder = new ExpressionBuilderVisitor();
  43556. instruction.visit(statementBuilder);
  43557. result.push(statementBuilder.toString());
  43558. });
  43559. stack.forEach(function (expr, i) {
  43560. var statementBuilder = new ExpressionBuilderVisitor();
  43561. expr.visit(statementBuilder);
  43562. var min = range[i * 2], max = range[i * 2 + 1];
  43563. var out = [statementBuilder.toString()];
  43564. if (min > expr.min) {
  43565. out.unshift('Math.max(', min, ', ');
  43566. out.push(')');
  43567. }
  43568. if (max < expr.max) {
  43569. out.unshift('Math.min(', max, ', ');
  43570. out.push(')');
  43571. }
  43572. out.unshift('dest[destOffset + ', i, '] = ');
  43573. out.push(';');
  43574. result.push(out.join(''));
  43575. });
  43576. return result.join('\n');
  43577. }
  43578. };
  43579. return PostScriptCompiler;
  43580. }();
  43581. exports.isPDFFunction = isPDFFunction;
  43582. exports.PDFFunction = PDFFunction;
  43583. exports.PostScriptEvaluator = PostScriptEvaluator;
  43584. exports.PostScriptCompiler = PostScriptCompiler;
  43585. }));
  43586. (function (root, factory) {
  43587. factory(root.pdfjsCoreColorSpace = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCoreFunction);
  43588. }(this, function (exports, sharedUtil, corePrimitives, coreFunction) {
  43589. var error = sharedUtil.error;
  43590. var info = sharedUtil.info;
  43591. var isArray = sharedUtil.isArray;
  43592. var isString = sharedUtil.isString;
  43593. var shadow = sharedUtil.shadow;
  43594. var warn = sharedUtil.warn;
  43595. var isDict = corePrimitives.isDict;
  43596. var isName = corePrimitives.isName;
  43597. var isStream = corePrimitives.isStream;
  43598. var PDFFunction = coreFunction.PDFFunction;
  43599. var ColorSpace = function ColorSpaceClosure() {
  43600. /**
  43601. * Resizes an RGB image with 3 components.
  43602. * @param {TypedArray} src - The source buffer.
  43603. * @param {Number} bpc - Number of bits per component.
  43604. * @param {Number} w1 - Original width.
  43605. * @param {Number} h1 - Original height.
  43606. * @param {Number} w2 - New width.
  43607. * @param {Number} h2 - New height.
  43608. * @param {Number} alpha01 - Size reserved for the alpha channel.
  43609. * @param {TypedArray} dest - The destination buffer.
  43610. */
  43611. function resizeRgbImage(src, bpc, w1, h1, w2, h2, alpha01, dest) {
  43612. var COMPONENTS = 3;
  43613. alpha01 = alpha01 !== 1 ? 0 : alpha01;
  43614. var xRatio = w1 / w2;
  43615. var yRatio = h1 / h2;
  43616. var i, j, py, newIndex = 0, oldIndex;
  43617. var xScaled = new Uint16Array(w2);
  43618. var w1Scanline = w1 * COMPONENTS;
  43619. for (i = 0; i < w2; i++) {
  43620. xScaled[i] = Math.floor(i * xRatio) * COMPONENTS;
  43621. }
  43622. for (i = 0; i < h2; i++) {
  43623. py = Math.floor(i * yRatio) * w1Scanline;
  43624. for (j = 0; j < w2; j++) {
  43625. oldIndex = py + xScaled[j];
  43626. dest[newIndex++] = src[oldIndex++];
  43627. dest[newIndex++] = src[oldIndex++];
  43628. dest[newIndex++] = src[oldIndex++];
  43629. newIndex += alpha01;
  43630. }
  43631. }
  43632. }
  43633. // Constructor should define this.numComps, this.defaultColor, this.name
  43634. function ColorSpace() {
  43635. error('should not call ColorSpace constructor');
  43636. }
  43637. ColorSpace.prototype = {
  43638. /**
  43639. * Converts the color value to the RGB color. The color components are
  43640. * located in the src array starting from the srcOffset. Returns the array
  43641. * of the rgb components, each value ranging from [0,255].
  43642. */
  43643. getRgb: function ColorSpace_getRgb(src, srcOffset) {
  43644. var rgb = new Uint8Array(3);
  43645. this.getRgbItem(src, srcOffset, rgb, 0);
  43646. return rgb;
  43647. },
  43648. /**
  43649. * Converts the color value to the RGB color, similar to the getRgb method.
  43650. * The result placed into the dest array starting from the destOffset.
  43651. */
  43652. getRgbItem: function ColorSpace_getRgbItem(src, srcOffset, dest, destOffset) {
  43653. error('Should not call ColorSpace.getRgbItem');
  43654. },
  43655. /**
  43656. * Converts the specified number of the color values to the RGB colors.
  43657. * The colors are located in the src array starting from the srcOffset.
  43658. * The result is placed into the dest array starting from the destOffset.
  43659. * The src array items shall be in [0,2^bits) range, the dest array items
  43660. * will be in [0,255] range. alpha01 indicates how many alpha components
  43661. * there are in the dest array; it will be either 0 (RGB array) or 1 (RGBA
  43662. * array).
  43663. */
  43664. getRgbBuffer: function ColorSpace_getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
  43665. error('Should not call ColorSpace.getRgbBuffer');
  43666. },
  43667. /**
  43668. * Determines the number of bytes required to store the result of the
  43669. * conversion done by the getRgbBuffer method. As in getRgbBuffer,
  43670. * |alpha01| is either 0 (RGB output) or 1 (RGBA output).
  43671. */
  43672. getOutputLength: function ColorSpace_getOutputLength(inputLength, alpha01) {
  43673. error('Should not call ColorSpace.getOutputLength');
  43674. },
  43675. /**
  43676. * Returns true if source data will be equal the result/output data.
  43677. */
  43678. isPassthrough: function ColorSpace_isPassthrough(bits) {
  43679. return false;
  43680. },
  43681. /**
  43682. * Fills in the RGB colors in the destination buffer. alpha01 indicates
  43683. * how many alpha components there are in the dest array; it will be either
  43684. * 0 (RGB array) or 1 (RGBA array).
  43685. */
  43686. fillRgb: function ColorSpace_fillRgb(dest, originalWidth, originalHeight, width, height, actualHeight, bpc, comps, alpha01) {
  43687. var count = originalWidth * originalHeight;
  43688. var rgbBuf = null;
  43689. var numComponentColors = 1 << bpc;
  43690. var needsResizing = originalHeight !== height || originalWidth !== width;
  43691. var i, ii;
  43692. if (this.isPassthrough(bpc)) {
  43693. rgbBuf = comps;
  43694. } else if (this.numComps === 1 && count > numComponentColors && this.name !== 'DeviceGray' && this.name !== 'DeviceRGB') {
  43695. // Optimization: create a color map when there is just one component and
  43696. // we are converting more colors than the size of the color map. We
  43697. // don't build the map if the colorspace is gray or rgb since those
  43698. // methods are faster than building a map. This mainly offers big speed
  43699. // ups for indexed and alternate colorspaces.
  43700. //
  43701. // TODO it may be worth while to cache the color map. While running
  43702. // testing I never hit a cache so I will leave that out for now (perhaps
  43703. // we are reparsing colorspaces too much?).
  43704. var allColors = bpc <= 8 ? new Uint8Array(numComponentColors) : new Uint16Array(numComponentColors);
  43705. var key;
  43706. for (i = 0; i < numComponentColors; i++) {
  43707. allColors[i] = i;
  43708. }
  43709. var colorMap = new Uint8Array(numComponentColors * 3);
  43710. this.getRgbBuffer(allColors, 0, numComponentColors, colorMap, 0, bpc, /* alpha01 = */
  43711. 0);
  43712. var destPos, rgbPos;
  43713. if (!needsResizing) {
  43714. // Fill in the RGB values directly into |dest|.
  43715. destPos = 0;
  43716. for (i = 0; i < count; ++i) {
  43717. key = comps[i] * 3;
  43718. dest[destPos++] = colorMap[key];
  43719. dest[destPos++] = colorMap[key + 1];
  43720. dest[destPos++] = colorMap[key + 2];
  43721. destPos += alpha01;
  43722. }
  43723. } else {
  43724. rgbBuf = new Uint8Array(count * 3);
  43725. rgbPos = 0;
  43726. for (i = 0; i < count; ++i) {
  43727. key = comps[i] * 3;
  43728. rgbBuf[rgbPos++] = colorMap[key];
  43729. rgbBuf[rgbPos++] = colorMap[key + 1];
  43730. rgbBuf[rgbPos++] = colorMap[key + 2];
  43731. }
  43732. }
  43733. } else {
  43734. if (!needsResizing) {
  43735. // Fill in the RGB values directly into |dest|.
  43736. this.getRgbBuffer(comps, 0, width * actualHeight, dest, 0, bpc, alpha01);
  43737. } else {
  43738. rgbBuf = new Uint8Array(count * 3);
  43739. this.getRgbBuffer(comps, 0, count, rgbBuf, 0, bpc, /* alpha01 = */
  43740. 0);
  43741. }
  43742. }
  43743. if (rgbBuf) {
  43744. if (needsResizing) {
  43745. resizeRgbImage(rgbBuf, bpc, originalWidth, originalHeight, width, height, alpha01, dest);
  43746. } else {
  43747. rgbPos = 0;
  43748. destPos = 0;
  43749. for (i = 0, ii = width * actualHeight; i < ii; i++) {
  43750. dest[destPos++] = rgbBuf[rgbPos++];
  43751. dest[destPos++] = rgbBuf[rgbPos++];
  43752. dest[destPos++] = rgbBuf[rgbPos++];
  43753. destPos += alpha01;
  43754. }
  43755. }
  43756. }
  43757. },
  43758. /**
  43759. * True if the colorspace has components in the default range of [0, 1].
  43760. * This should be true for all colorspaces except for lab color spaces
  43761. * which are [0,100], [-128, 127], [-128, 127].
  43762. */
  43763. usesZeroToOneRange: true
  43764. };
  43765. ColorSpace.parse = function ColorSpace_parse(cs, xref, res) {
  43766. var IR = ColorSpace.parseToIR(cs, xref, res);
  43767. if (IR instanceof AlternateCS) {
  43768. return IR;
  43769. }
  43770. return ColorSpace.fromIR(IR);
  43771. };
  43772. ColorSpace.fromIR = function ColorSpace_fromIR(IR) {
  43773. var name = isArray(IR) ? IR[0] : IR;
  43774. var whitePoint, blackPoint, gamma;
  43775. switch (name) {
  43776. case 'DeviceGrayCS':
  43777. return this.singletons.gray;
  43778. case 'DeviceRgbCS':
  43779. return this.singletons.rgb;
  43780. case 'DeviceCmykCS':
  43781. return this.singletons.cmyk;
  43782. case 'CalGrayCS':
  43783. whitePoint = IR[1];
  43784. blackPoint = IR[2];
  43785. gamma = IR[3];
  43786. return new CalGrayCS(whitePoint, blackPoint, gamma);
  43787. case 'CalRGBCS':
  43788. whitePoint = IR[1];
  43789. blackPoint = IR[2];
  43790. gamma = IR[3];
  43791. var matrix = IR[4];
  43792. return new CalRGBCS(whitePoint, blackPoint, gamma, matrix);
  43793. case 'PatternCS':
  43794. var basePatternCS = IR[1];
  43795. if (basePatternCS) {
  43796. basePatternCS = ColorSpace.fromIR(basePatternCS);
  43797. }
  43798. return new PatternCS(basePatternCS);
  43799. case 'IndexedCS':
  43800. var baseIndexedCS = IR[1];
  43801. var hiVal = IR[2];
  43802. var lookup = IR[3];
  43803. return new IndexedCS(ColorSpace.fromIR(baseIndexedCS), hiVal, lookup);
  43804. case 'AlternateCS':
  43805. var numComps = IR[1];
  43806. var alt = IR[2];
  43807. var tintFnIR = IR[3];
  43808. return new AlternateCS(numComps, ColorSpace.fromIR(alt), PDFFunction.fromIR(tintFnIR));
  43809. case 'LabCS':
  43810. whitePoint = IR[1];
  43811. blackPoint = IR[2];
  43812. var range = IR[3];
  43813. return new LabCS(whitePoint, blackPoint, range);
  43814. default:
  43815. error('Unknown name ' + name);
  43816. }
  43817. return null;
  43818. };
  43819. ColorSpace.parseToIR = function ColorSpace_parseToIR(cs, xref, res) {
  43820. if (isName(cs)) {
  43821. var colorSpaces = res.get('ColorSpace');
  43822. if (isDict(colorSpaces)) {
  43823. var refcs = colorSpaces.get(cs.name);
  43824. if (refcs) {
  43825. cs = refcs;
  43826. }
  43827. }
  43828. }
  43829. cs = xref.fetchIfRef(cs);
  43830. var mode;
  43831. if (isName(cs)) {
  43832. mode = cs.name;
  43833. this.mode = mode;
  43834. switch (mode) {
  43835. case 'DeviceGray':
  43836. case 'G':
  43837. return 'DeviceGrayCS';
  43838. case 'DeviceRGB':
  43839. case 'RGB':
  43840. return 'DeviceRgbCS';
  43841. case 'DeviceCMYK':
  43842. case 'CMYK':
  43843. return 'DeviceCmykCS';
  43844. case 'Pattern':
  43845. return [
  43846. 'PatternCS',
  43847. null
  43848. ];
  43849. default:
  43850. error('unrecognized colorspace ' + mode);
  43851. }
  43852. } else if (isArray(cs)) {
  43853. mode = xref.fetchIfRef(cs[0]).name;
  43854. this.mode = mode;
  43855. var numComps, params, alt, whitePoint, blackPoint, gamma;
  43856. switch (mode) {
  43857. case 'DeviceGray':
  43858. case 'G':
  43859. return 'DeviceGrayCS';
  43860. case 'DeviceRGB':
  43861. case 'RGB':
  43862. return 'DeviceRgbCS';
  43863. case 'DeviceCMYK':
  43864. case 'CMYK':
  43865. return 'DeviceCmykCS';
  43866. case 'CalGray':
  43867. params = xref.fetchIfRef(cs[1]);
  43868. whitePoint = params.getArray('WhitePoint');
  43869. blackPoint = params.getArray('BlackPoint');
  43870. gamma = params.get('Gamma');
  43871. return [
  43872. 'CalGrayCS',
  43873. whitePoint,
  43874. blackPoint,
  43875. gamma
  43876. ];
  43877. case 'CalRGB':
  43878. params = xref.fetchIfRef(cs[1]);
  43879. whitePoint = params.getArray('WhitePoint');
  43880. blackPoint = params.getArray('BlackPoint');
  43881. gamma = params.getArray('Gamma');
  43882. var matrix = params.getArray('Matrix');
  43883. return [
  43884. 'CalRGBCS',
  43885. whitePoint,
  43886. blackPoint,
  43887. gamma,
  43888. matrix
  43889. ];
  43890. case 'ICCBased':
  43891. var stream = xref.fetchIfRef(cs[1]);
  43892. var dict = stream.dict;
  43893. numComps = dict.get('N');
  43894. alt = dict.get('Alternate');
  43895. if (alt) {
  43896. var altIR = ColorSpace.parseToIR(alt, xref, res);
  43897. // Parse the /Alternate CS to ensure that the number of components
  43898. // are correct, and also (indirectly) that it is not a PatternCS.
  43899. var altCS = ColorSpace.fromIR(altIR);
  43900. if (altCS.numComps === numComps) {
  43901. return altIR;
  43902. }
  43903. warn('ICCBased color space: Ignoring incorrect /Alternate entry.');
  43904. }
  43905. if (numComps === 1) {
  43906. return 'DeviceGrayCS';
  43907. } else if (numComps === 3) {
  43908. return 'DeviceRgbCS';
  43909. } else if (numComps === 4) {
  43910. return 'DeviceCmykCS';
  43911. }
  43912. break;
  43913. case 'Pattern':
  43914. var basePatternCS = cs[1] || null;
  43915. if (basePatternCS) {
  43916. basePatternCS = ColorSpace.parseToIR(basePatternCS, xref, res);
  43917. }
  43918. return [
  43919. 'PatternCS',
  43920. basePatternCS
  43921. ];
  43922. case 'Indexed':
  43923. case 'I':
  43924. var baseIndexedCS = ColorSpace.parseToIR(cs[1], xref, res);
  43925. var hiVal = xref.fetchIfRef(cs[2]) + 1;
  43926. var lookup = xref.fetchIfRef(cs[3]);
  43927. if (isStream(lookup)) {
  43928. lookup = lookup.getBytes();
  43929. }
  43930. return [
  43931. 'IndexedCS',
  43932. baseIndexedCS,
  43933. hiVal,
  43934. lookup
  43935. ];
  43936. case 'Separation':
  43937. case 'DeviceN':
  43938. var name = xref.fetchIfRef(cs[1]);
  43939. numComps = 1;
  43940. if (isName(name)) {
  43941. numComps = 1;
  43942. } else if (isArray(name)) {
  43943. numComps = name.length;
  43944. }
  43945. alt = ColorSpace.parseToIR(cs[2], xref, res);
  43946. var tintFnIR = PDFFunction.getIR(xref, xref.fetchIfRef(cs[3]));
  43947. return [
  43948. 'AlternateCS',
  43949. numComps,
  43950. alt,
  43951. tintFnIR
  43952. ];
  43953. case 'Lab':
  43954. params = xref.fetchIfRef(cs[1]);
  43955. whitePoint = params.getArray('WhitePoint');
  43956. blackPoint = params.getArray('BlackPoint');
  43957. var range = params.getArray('Range');
  43958. return [
  43959. 'LabCS',
  43960. whitePoint,
  43961. blackPoint,
  43962. range
  43963. ];
  43964. default:
  43965. error('unimplemented color space object "' + mode + '"');
  43966. }
  43967. } else {
  43968. error('unrecognized color space object: "' + cs + '"');
  43969. }
  43970. return null;
  43971. };
  43972. /**
  43973. * Checks if a decode map matches the default decode map for a color space.
  43974. * This handles the general decode maps where there are two values per
  43975. * component. e.g. [0, 1, 0, 1, 0, 1] for a RGB color.
  43976. * This does not handle Lab, Indexed, or Pattern decode maps since they are
  43977. * slightly different.
  43978. * @param {Array} decode Decode map (usually from an image).
  43979. * @param {Number} n Number of components the color space has.
  43980. */
  43981. ColorSpace.isDefaultDecode = function ColorSpace_isDefaultDecode(decode, n) {
  43982. if (!isArray(decode)) {
  43983. return true;
  43984. }
  43985. if (n * 2 !== decode.length) {
  43986. warn('The decode map is not the correct length');
  43987. return true;
  43988. }
  43989. for (var i = 0, ii = decode.length; i < ii; i += 2) {
  43990. if (decode[i] !== 0 || decode[i + 1] !== 1) {
  43991. return false;
  43992. }
  43993. }
  43994. return true;
  43995. };
  43996. ColorSpace.singletons = {
  43997. get gray() {
  43998. return shadow(this, 'gray', new DeviceGrayCS());
  43999. },
  44000. get rgb() {
  44001. return shadow(this, 'rgb', new DeviceRgbCS());
  44002. },
  44003. get cmyk() {
  44004. return shadow(this, 'cmyk', new DeviceCmykCS());
  44005. }
  44006. };
  44007. return ColorSpace;
  44008. }();
  44009. /**
  44010. * Alternate color space handles both Separation and DeviceN color spaces. A
  44011. * Separation color space is actually just a DeviceN with one color component.
  44012. * Both color spaces use a tinting function to convert colors to a base color
  44013. * space.
  44014. */
  44015. var AlternateCS = function AlternateCSClosure() {
  44016. function AlternateCS(numComps, base, tintFn) {
  44017. this.name = 'Alternate';
  44018. this.numComps = numComps;
  44019. this.defaultColor = new Float32Array(numComps);
  44020. for (var i = 0; i < numComps; ++i) {
  44021. this.defaultColor[i] = 1;
  44022. }
  44023. this.base = base;
  44024. this.tintFn = tintFn;
  44025. this.tmpBuf = new Float32Array(base.numComps);
  44026. }
  44027. AlternateCS.prototype = {
  44028. getRgb: ColorSpace.prototype.getRgb,
  44029. getRgbItem: function AlternateCS_getRgbItem(src, srcOffset, dest, destOffset) {
  44030. var tmpBuf = this.tmpBuf;
  44031. this.tintFn(src, srcOffset, tmpBuf, 0);
  44032. this.base.getRgbItem(tmpBuf, 0, dest, destOffset);
  44033. },
  44034. getRgbBuffer: function AlternateCS_getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
  44035. var tintFn = this.tintFn;
  44036. var base = this.base;
  44037. var scale = 1 / ((1 << bits) - 1);
  44038. var baseNumComps = base.numComps;
  44039. var usesZeroToOneRange = base.usesZeroToOneRange;
  44040. var isPassthrough = (base.isPassthrough(8) || !usesZeroToOneRange) && alpha01 === 0;
  44041. var pos = isPassthrough ? destOffset : 0;
  44042. var baseBuf = isPassthrough ? dest : new Uint8Array(baseNumComps * count);
  44043. var numComps = this.numComps;
  44044. var scaled = new Float32Array(numComps);
  44045. var tinted = new Float32Array(baseNumComps);
  44046. var i, j;
  44047. if (usesZeroToOneRange) {
  44048. for (i = 0; i < count; i++) {
  44049. for (j = 0; j < numComps; j++) {
  44050. scaled[j] = src[srcOffset++] * scale;
  44051. }
  44052. tintFn(scaled, 0, tinted, 0);
  44053. for (j = 0; j < baseNumComps; j++) {
  44054. baseBuf[pos++] = tinted[j] * 255;
  44055. }
  44056. }
  44057. } else {
  44058. for (i = 0; i < count; i++) {
  44059. for (j = 0; j < numComps; j++) {
  44060. scaled[j] = src[srcOffset++] * scale;
  44061. }
  44062. tintFn(scaled, 0, tinted, 0);
  44063. base.getRgbItem(tinted, 0, baseBuf, pos);
  44064. pos += baseNumComps;
  44065. }
  44066. }
  44067. if (!isPassthrough) {
  44068. base.getRgbBuffer(baseBuf, 0, count, dest, destOffset, 8, alpha01);
  44069. }
  44070. },
  44071. getOutputLength: function AlternateCS_getOutputLength(inputLength, alpha01) {
  44072. return this.base.getOutputLength(inputLength * this.base.numComps / this.numComps, alpha01);
  44073. },
  44074. isPassthrough: ColorSpace.prototype.isPassthrough,
  44075. fillRgb: ColorSpace.prototype.fillRgb,
  44076. isDefaultDecode: function AlternateCS_isDefaultDecode(decodeMap) {
  44077. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  44078. },
  44079. usesZeroToOneRange: true
  44080. };
  44081. return AlternateCS;
  44082. }();
  44083. var PatternCS = function PatternCSClosure() {
  44084. function PatternCS(baseCS) {
  44085. this.name = 'Pattern';
  44086. this.base = baseCS;
  44087. }
  44088. PatternCS.prototype = {};
  44089. return PatternCS;
  44090. }();
  44091. var IndexedCS = function IndexedCSClosure() {
  44092. function IndexedCS(base, highVal, lookup) {
  44093. this.name = 'Indexed';
  44094. this.numComps = 1;
  44095. this.defaultColor = new Uint8Array([0]);
  44096. this.base = base;
  44097. this.highVal = highVal;
  44098. var baseNumComps = base.numComps;
  44099. var length = baseNumComps * highVal;
  44100. var lookupArray;
  44101. if (isStream(lookup)) {
  44102. lookupArray = new Uint8Array(length);
  44103. var bytes = lookup.getBytes(length);
  44104. lookupArray.set(bytes);
  44105. } else if (isString(lookup)) {
  44106. lookupArray = new Uint8Array(length);
  44107. for (var i = 0; i < length; ++i) {
  44108. lookupArray[i] = lookup.charCodeAt(i);
  44109. }
  44110. } else if (lookup instanceof Uint8Array || lookup instanceof Array) {
  44111. lookupArray = lookup;
  44112. } else {
  44113. error('Unrecognized lookup table: ' + lookup);
  44114. }
  44115. this.lookup = lookupArray;
  44116. }
  44117. IndexedCS.prototype = {
  44118. getRgb: ColorSpace.prototype.getRgb,
  44119. getRgbItem: function IndexedCS_getRgbItem(src, srcOffset, dest, destOffset) {
  44120. var numComps = this.base.numComps;
  44121. var start = src[srcOffset] * numComps;
  44122. this.base.getRgbItem(this.lookup, start, dest, destOffset);
  44123. },
  44124. getRgbBuffer: function IndexedCS_getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
  44125. var base = this.base;
  44126. var numComps = base.numComps;
  44127. var outputDelta = base.getOutputLength(numComps, alpha01);
  44128. var lookup = this.lookup;
  44129. for (var i = 0; i < count; ++i) {
  44130. var lookupPos = src[srcOffset++] * numComps;
  44131. base.getRgbBuffer(lookup, lookupPos, 1, dest, destOffset, 8, alpha01);
  44132. destOffset += outputDelta;
  44133. }
  44134. },
  44135. getOutputLength: function IndexedCS_getOutputLength(inputLength, alpha01) {
  44136. return this.base.getOutputLength(inputLength * this.base.numComps, alpha01);
  44137. },
  44138. isPassthrough: ColorSpace.prototype.isPassthrough,
  44139. fillRgb: ColorSpace.prototype.fillRgb,
  44140. isDefaultDecode: function IndexedCS_isDefaultDecode(decodeMap) {
  44141. // indexed color maps shouldn't be changed
  44142. return true;
  44143. },
  44144. usesZeroToOneRange: true
  44145. };
  44146. return IndexedCS;
  44147. }();
  44148. var DeviceGrayCS = function DeviceGrayCSClosure() {
  44149. function DeviceGrayCS() {
  44150. this.name = 'DeviceGray';
  44151. this.numComps = 1;
  44152. this.defaultColor = new Float32Array([0]);
  44153. }
  44154. DeviceGrayCS.prototype = {
  44155. getRgb: ColorSpace.prototype.getRgb,
  44156. getRgbItem: function DeviceGrayCS_getRgbItem(src, srcOffset, dest, destOffset) {
  44157. var c = src[srcOffset] * 255 | 0;
  44158. c = c < 0 ? 0 : c > 255 ? 255 : c;
  44159. dest[destOffset] = dest[destOffset + 1] = dest[destOffset + 2] = c;
  44160. },
  44161. getRgbBuffer: function DeviceGrayCS_getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
  44162. var scale = 255 / ((1 << bits) - 1);
  44163. var j = srcOffset, q = destOffset;
  44164. for (var i = 0; i < count; ++i) {
  44165. var c = scale * src[j++] | 0;
  44166. dest[q++] = c;
  44167. dest[q++] = c;
  44168. dest[q++] = c;
  44169. q += alpha01;
  44170. }
  44171. },
  44172. getOutputLength: function DeviceGrayCS_getOutputLength(inputLength, alpha01) {
  44173. return inputLength * (3 + alpha01);
  44174. },
  44175. isPassthrough: ColorSpace.prototype.isPassthrough,
  44176. fillRgb: ColorSpace.prototype.fillRgb,
  44177. isDefaultDecode: function DeviceGrayCS_isDefaultDecode(decodeMap) {
  44178. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  44179. },
  44180. usesZeroToOneRange: true
  44181. };
  44182. return DeviceGrayCS;
  44183. }();
  44184. var DeviceRgbCS = function DeviceRgbCSClosure() {
  44185. function DeviceRgbCS() {
  44186. this.name = 'DeviceRGB';
  44187. this.numComps = 3;
  44188. this.defaultColor = new Float32Array([
  44189. 0,
  44190. 0,
  44191. 0
  44192. ]);
  44193. }
  44194. DeviceRgbCS.prototype = {
  44195. getRgb: ColorSpace.prototype.getRgb,
  44196. getRgbItem: function DeviceRgbCS_getRgbItem(src, srcOffset, dest, destOffset) {
  44197. var r = src[srcOffset] * 255 | 0;
  44198. var g = src[srcOffset + 1] * 255 | 0;
  44199. var b = src[srcOffset + 2] * 255 | 0;
  44200. dest[destOffset] = r < 0 ? 0 : r > 255 ? 255 : r;
  44201. dest[destOffset + 1] = g < 0 ? 0 : g > 255 ? 255 : g;
  44202. dest[destOffset + 2] = b < 0 ? 0 : b > 255 ? 255 : b;
  44203. },
  44204. getRgbBuffer: function DeviceRgbCS_getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
  44205. if (bits === 8 && alpha01 === 0) {
  44206. dest.set(src.subarray(srcOffset, srcOffset + count * 3), destOffset);
  44207. return;
  44208. }
  44209. var scale = 255 / ((1 << bits) - 1);
  44210. var j = srcOffset, q = destOffset;
  44211. for (var i = 0; i < count; ++i) {
  44212. dest[q++] = scale * src[j++] | 0;
  44213. dest[q++] = scale * src[j++] | 0;
  44214. dest[q++] = scale * src[j++] | 0;
  44215. q += alpha01;
  44216. }
  44217. },
  44218. getOutputLength: function DeviceRgbCS_getOutputLength(inputLength, alpha01) {
  44219. return inputLength * (3 + alpha01) / 3 | 0;
  44220. },
  44221. isPassthrough: function DeviceRgbCS_isPassthrough(bits) {
  44222. return bits === 8;
  44223. },
  44224. fillRgb: ColorSpace.prototype.fillRgb,
  44225. isDefaultDecode: function DeviceRgbCS_isDefaultDecode(decodeMap) {
  44226. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  44227. },
  44228. usesZeroToOneRange: true
  44229. };
  44230. return DeviceRgbCS;
  44231. }();
  44232. var DeviceCmykCS = function DeviceCmykCSClosure() {
  44233. // The coefficients below was found using numerical analysis: the method of
  44234. // steepest descent for the sum((f_i - color_value_i)^2) for r/g/b colors,
  44235. // where color_value is the tabular value from the table of sampled RGB colors
  44236. // from CMYK US Web Coated (SWOP) colorspace, and f_i is the corresponding
  44237. // CMYK color conversion using the estimation below:
  44238. // f(A, B,.. N) = Acc+Bcm+Ccy+Dck+c+Fmm+Gmy+Hmk+Im+Jyy+Kyk+Ly+Mkk+Nk+255
  44239. function convertToRgb(src, srcOffset, srcScale, dest, destOffset) {
  44240. var c = src[srcOffset + 0] * srcScale;
  44241. var m = src[srcOffset + 1] * srcScale;
  44242. var y = src[srcOffset + 2] * srcScale;
  44243. var k = src[srcOffset + 3] * srcScale;
  44244. 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;
  44245. 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;
  44246. 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;
  44247. dest[destOffset] = r > 255 ? 255 : r < 0 ? 0 : r;
  44248. dest[destOffset + 1] = g > 255 ? 255 : g < 0 ? 0 : g;
  44249. dest[destOffset + 2] = b > 255 ? 255 : b < 0 ? 0 : b;
  44250. }
  44251. function DeviceCmykCS() {
  44252. this.name = 'DeviceCMYK';
  44253. this.numComps = 4;
  44254. this.defaultColor = new Float32Array([
  44255. 0,
  44256. 0,
  44257. 0,
  44258. 1
  44259. ]);
  44260. }
  44261. DeviceCmykCS.prototype = {
  44262. getRgb: ColorSpace.prototype.getRgb,
  44263. getRgbItem: function DeviceCmykCS_getRgbItem(src, srcOffset, dest, destOffset) {
  44264. convertToRgb(src, srcOffset, 1, dest, destOffset);
  44265. },
  44266. getRgbBuffer: function DeviceCmykCS_getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
  44267. var scale = 1 / ((1 << bits) - 1);
  44268. for (var i = 0; i < count; i++) {
  44269. convertToRgb(src, srcOffset, scale, dest, destOffset);
  44270. srcOffset += 4;
  44271. destOffset += 3 + alpha01;
  44272. }
  44273. },
  44274. getOutputLength: function DeviceCmykCS_getOutputLength(inputLength, alpha01) {
  44275. return inputLength / 4 * (3 + alpha01) | 0;
  44276. },
  44277. isPassthrough: ColorSpace.prototype.isPassthrough,
  44278. fillRgb: ColorSpace.prototype.fillRgb,
  44279. isDefaultDecode: function DeviceCmykCS_isDefaultDecode(decodeMap) {
  44280. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  44281. },
  44282. usesZeroToOneRange: true
  44283. };
  44284. return DeviceCmykCS;
  44285. }();
  44286. //
  44287. // CalGrayCS: Based on "PDF Reference, Sixth Ed", p.245
  44288. //
  44289. var CalGrayCS = function CalGrayCSClosure() {
  44290. function CalGrayCS(whitePoint, blackPoint, gamma) {
  44291. this.name = 'CalGray';
  44292. this.numComps = 1;
  44293. this.defaultColor = new Float32Array([0]);
  44294. if (!whitePoint) {
  44295. error('WhitePoint missing - required for color space CalGray');
  44296. }
  44297. blackPoint = blackPoint || [
  44298. 0,
  44299. 0,
  44300. 0
  44301. ];
  44302. gamma = gamma || 1;
  44303. // Translate arguments to spec variables.
  44304. this.XW = whitePoint[0];
  44305. this.YW = whitePoint[1];
  44306. this.ZW = whitePoint[2];
  44307. this.XB = blackPoint[0];
  44308. this.YB = blackPoint[1];
  44309. this.ZB = blackPoint[2];
  44310. this.G = gamma;
  44311. // Validate variables as per spec.
  44312. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  44313. error('Invalid WhitePoint components for ' + this.name + ', no fallback available');
  44314. }
  44315. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  44316. info('Invalid BlackPoint for ' + this.name + ', falling back to default');
  44317. this.XB = this.YB = this.ZB = 0;
  44318. }
  44319. if (this.XB !== 0 || this.YB !== 0 || this.ZB !== 0) {
  44320. warn(this.name + ', BlackPoint: XB: ' + this.XB + ', YB: ' + this.YB + ', ZB: ' + this.ZB + ', only default values are supported.');
  44321. }
  44322. if (this.G < 1) {
  44323. info('Invalid Gamma: ' + this.G + ' for ' + this.name + ', falling back to default');
  44324. this.G = 1;
  44325. }
  44326. }
  44327. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  44328. // A represents a gray component of a calibrated gray space.
  44329. // A <---> AG in the spec
  44330. var A = src[srcOffset] * scale;
  44331. var AG = Math.pow(A, cs.G);
  44332. // Computes L as per spec. ( = cs.YW * AG )
  44333. // Except if other than default BlackPoint values are used.
  44334. var L = cs.YW * AG;
  44335. // http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html, Ch 4.
  44336. // Convert values to rgb range [0, 255].
  44337. var val = Math.max(295.8 * Math.pow(L, 0.333333333333333333) - 40.8, 0) | 0;
  44338. dest[destOffset] = val;
  44339. dest[destOffset + 1] = val;
  44340. dest[destOffset + 2] = val;
  44341. }
  44342. CalGrayCS.prototype = {
  44343. getRgb: ColorSpace.prototype.getRgb,
  44344. getRgbItem: function CalGrayCS_getRgbItem(src, srcOffset, dest, destOffset) {
  44345. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  44346. },
  44347. getRgbBuffer: function CalGrayCS_getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
  44348. var scale = 1 / ((1 << bits) - 1);
  44349. for (var i = 0; i < count; ++i) {
  44350. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  44351. srcOffset += 1;
  44352. destOffset += 3 + alpha01;
  44353. }
  44354. },
  44355. getOutputLength: function CalGrayCS_getOutputLength(inputLength, alpha01) {
  44356. return inputLength * (3 + alpha01);
  44357. },
  44358. isPassthrough: ColorSpace.prototype.isPassthrough,
  44359. fillRgb: ColorSpace.prototype.fillRgb,
  44360. isDefaultDecode: function CalGrayCS_isDefaultDecode(decodeMap) {
  44361. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  44362. },
  44363. usesZeroToOneRange: true
  44364. };
  44365. return CalGrayCS;
  44366. }();
  44367. //
  44368. // CalRGBCS: Based on "PDF Reference, Sixth Ed", p.247
  44369. //
  44370. var CalRGBCS = function CalRGBCSClosure() {
  44371. // See http://www.brucelindbloom.com/index.html?Eqn_ChromAdapt.html for these
  44372. // matrices.
  44373. var BRADFORD_SCALE_MATRIX = new Float32Array([
  44374. 0.8951,
  44375. 0.2664,
  44376. -0.1614,
  44377. -0.7502,
  44378. 1.7135,
  44379. 0.0367,
  44380. 0.0389,
  44381. -0.0685,
  44382. 1.0296
  44383. ]);
  44384. var BRADFORD_SCALE_INVERSE_MATRIX = new Float32Array([
  44385. 0.9869929,
  44386. -0.1470543,
  44387. 0.1599627,
  44388. 0.4323053,
  44389. 0.5183603,
  44390. 0.0492912,
  44391. -0.0085287,
  44392. 0.0400428,
  44393. 0.9684867
  44394. ]);
  44395. // See http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html.
  44396. var SRGB_D65_XYZ_TO_RGB_MATRIX = new Float32Array([
  44397. 3.2404542,
  44398. -1.5371385,
  44399. -0.4985314,
  44400. -0.9692660,
  44401. 1.8760108,
  44402. 0.0415560,
  44403. 0.0556434,
  44404. -0.2040259,
  44405. 1.0572252
  44406. ]);
  44407. var FLAT_WHITEPOINT_MATRIX = new Float32Array([
  44408. 1,
  44409. 1,
  44410. 1
  44411. ]);
  44412. var tempNormalizeMatrix = new Float32Array(3);
  44413. var tempConvertMatrix1 = new Float32Array(3);
  44414. var tempConvertMatrix2 = new Float32Array(3);
  44415. var DECODE_L_CONSTANT = Math.pow((8 + 16) / 116, 3) / 8.0;
  44416. function CalRGBCS(whitePoint, blackPoint, gamma, matrix) {
  44417. this.name = 'CalRGB';
  44418. this.numComps = 3;
  44419. this.defaultColor = new Float32Array(3);
  44420. if (!whitePoint) {
  44421. error('WhitePoint missing - required for color space CalRGB');
  44422. }
  44423. blackPoint = blackPoint || new Float32Array(3);
  44424. gamma = gamma || new Float32Array([
  44425. 1,
  44426. 1,
  44427. 1
  44428. ]);
  44429. matrix = matrix || new Float32Array([
  44430. 1,
  44431. 0,
  44432. 0,
  44433. 0,
  44434. 1,
  44435. 0,
  44436. 0,
  44437. 0,
  44438. 1
  44439. ]);
  44440. // Translate arguments to spec variables.
  44441. var XW = whitePoint[0];
  44442. var YW = whitePoint[1];
  44443. var ZW = whitePoint[2];
  44444. this.whitePoint = whitePoint;
  44445. var XB = blackPoint[0];
  44446. var YB = blackPoint[1];
  44447. var ZB = blackPoint[2];
  44448. this.blackPoint = blackPoint;
  44449. this.GR = gamma[0];
  44450. this.GG = gamma[1];
  44451. this.GB = gamma[2];
  44452. this.MXA = matrix[0];
  44453. this.MYA = matrix[1];
  44454. this.MZA = matrix[2];
  44455. this.MXB = matrix[3];
  44456. this.MYB = matrix[4];
  44457. this.MZB = matrix[5];
  44458. this.MXC = matrix[6];
  44459. this.MYC = matrix[7];
  44460. this.MZC = matrix[8];
  44461. // Validate variables as per spec.
  44462. if (XW < 0 || ZW < 0 || YW !== 1) {
  44463. error('Invalid WhitePoint components for ' + this.name + ', no fallback available');
  44464. }
  44465. if (XB < 0 || YB < 0 || ZB < 0) {
  44466. info('Invalid BlackPoint for ' + this.name + ' [' + XB + ', ' + YB + ', ' + ZB + '], falling back to default');
  44467. this.blackPoint = new Float32Array(3);
  44468. }
  44469. if (this.GR < 0 || this.GG < 0 || this.GB < 0) {
  44470. info('Invalid Gamma [' + this.GR + ', ' + this.GG + ', ' + this.GB + '] for ' + this.name + ', falling back to default');
  44471. this.GR = this.GG = this.GB = 1;
  44472. }
  44473. 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) {
  44474. 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');
  44475. this.MXA = this.MYB = this.MZC = 1;
  44476. this.MXB = this.MYA = this.MZA = this.MXC = this.MYC = this.MZB = 0;
  44477. }
  44478. }
  44479. function matrixProduct(a, b, result) {
  44480. result[0] = a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
  44481. result[1] = a[3] * b[0] + a[4] * b[1] + a[5] * b[2];
  44482. result[2] = a[6] * b[0] + a[7] * b[1] + a[8] * b[2];
  44483. }
  44484. function convertToFlat(sourceWhitePoint, LMS, result) {
  44485. result[0] = LMS[0] * 1 / sourceWhitePoint[0];
  44486. result[1] = LMS[1] * 1 / sourceWhitePoint[1];
  44487. result[2] = LMS[2] * 1 / sourceWhitePoint[2];
  44488. }
  44489. function convertToD65(sourceWhitePoint, LMS, result) {
  44490. var D65X = 0.95047;
  44491. var D65Y = 1;
  44492. var D65Z = 1.08883;
  44493. result[0] = LMS[0] * D65X / sourceWhitePoint[0];
  44494. result[1] = LMS[1] * D65Y / sourceWhitePoint[1];
  44495. result[2] = LMS[2] * D65Z / sourceWhitePoint[2];
  44496. }
  44497. function sRGBTransferFunction(color) {
  44498. // See http://en.wikipedia.org/wiki/SRGB.
  44499. if (color <= 0.0031308) {
  44500. return adjustToRange(0, 1, 12.92 * color);
  44501. }
  44502. return adjustToRange(0, 1, (1 + 0.055) * Math.pow(color, 1 / 2.4) - 0.055);
  44503. }
  44504. function adjustToRange(min, max, value) {
  44505. return Math.max(min, Math.min(max, value));
  44506. }
  44507. function decodeL(L) {
  44508. if (L < 0) {
  44509. return -decodeL(-L);
  44510. }
  44511. if (L > 8.0) {
  44512. return Math.pow((L + 16) / 116, 3);
  44513. }
  44514. return L * DECODE_L_CONSTANT;
  44515. }
  44516. function compensateBlackPoint(sourceBlackPoint, XYZ_Flat, result) {
  44517. // In case the blackPoint is already the default blackPoint then there is
  44518. // no need to do compensation.
  44519. if (sourceBlackPoint[0] === 0 && sourceBlackPoint[1] === 0 && sourceBlackPoint[2] === 0) {
  44520. result[0] = XYZ_Flat[0];
  44521. result[1] = XYZ_Flat[1];
  44522. result[2] = XYZ_Flat[2];
  44523. return;
  44524. }
  44525. // For the blackPoint calculation details, please see
  44526. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  44527. // AdobeBPC.pdf.
  44528. // The destination blackPoint is the default blackPoint [0, 0, 0].
  44529. var zeroDecodeL = decodeL(0);
  44530. var X_DST = zeroDecodeL;
  44531. var X_SRC = decodeL(sourceBlackPoint[0]);
  44532. var Y_DST = zeroDecodeL;
  44533. var Y_SRC = decodeL(sourceBlackPoint[1]);
  44534. var Z_DST = zeroDecodeL;
  44535. var Z_SRC = decodeL(sourceBlackPoint[2]);
  44536. var X_Scale = (1 - X_DST) / (1 - X_SRC);
  44537. var X_Offset = 1 - X_Scale;
  44538. var Y_Scale = (1 - Y_DST) / (1 - Y_SRC);
  44539. var Y_Offset = 1 - Y_Scale;
  44540. var Z_Scale = (1 - Z_DST) / (1 - Z_SRC);
  44541. var Z_Offset = 1 - Z_Scale;
  44542. result[0] = XYZ_Flat[0] * X_Scale + X_Offset;
  44543. result[1] = XYZ_Flat[1] * Y_Scale + Y_Offset;
  44544. result[2] = XYZ_Flat[2] * Z_Scale + Z_Offset;
  44545. }
  44546. function normalizeWhitePointToFlat(sourceWhitePoint, XYZ_In, result) {
  44547. // In case the whitePoint is already flat then there is no need to do
  44548. // normalization.
  44549. if (sourceWhitePoint[0] === 1 && sourceWhitePoint[2] === 1) {
  44550. result[0] = XYZ_In[0];
  44551. result[1] = XYZ_In[1];
  44552. result[2] = XYZ_In[2];
  44553. return;
  44554. }
  44555. var LMS = result;
  44556. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  44557. var LMS_Flat = tempNormalizeMatrix;
  44558. convertToFlat(sourceWhitePoint, LMS, LMS_Flat);
  44559. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_Flat, result);
  44560. }
  44561. function normalizeWhitePointToD65(sourceWhitePoint, XYZ_In, result) {
  44562. var LMS = result;
  44563. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  44564. var LMS_D65 = tempNormalizeMatrix;
  44565. convertToD65(sourceWhitePoint, LMS, LMS_D65);
  44566. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_D65, result);
  44567. }
  44568. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  44569. // A, B and C represent a red, green and blue components of a calibrated
  44570. // rgb space.
  44571. var A = adjustToRange(0, 1, src[srcOffset] * scale);
  44572. var B = adjustToRange(0, 1, src[srcOffset + 1] * scale);
  44573. var C = adjustToRange(0, 1, src[srcOffset + 2] * scale);
  44574. // A <---> AGR in the spec
  44575. // B <---> BGG in the spec
  44576. // C <---> CGB in the spec
  44577. var AGR = Math.pow(A, cs.GR);
  44578. var BGG = Math.pow(B, cs.GG);
  44579. var CGB = Math.pow(C, cs.GB);
  44580. // Computes intermediate variables L, M, N as per spec.
  44581. // To decode X, Y, Z values map L, M, N directly to them.
  44582. var X = cs.MXA * AGR + cs.MXB * BGG + cs.MXC * CGB;
  44583. var Y = cs.MYA * AGR + cs.MYB * BGG + cs.MYC * CGB;
  44584. var Z = cs.MZA * AGR + cs.MZB * BGG + cs.MZC * CGB;
  44585. // The following calculations are based on this document:
  44586. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  44587. // AdobeBPC.pdf.
  44588. var XYZ = tempConvertMatrix1;
  44589. XYZ[0] = X;
  44590. XYZ[1] = Y;
  44591. XYZ[2] = Z;
  44592. var XYZ_Flat = tempConvertMatrix2;
  44593. normalizeWhitePointToFlat(cs.whitePoint, XYZ, XYZ_Flat);
  44594. var XYZ_Black = tempConvertMatrix1;
  44595. compensateBlackPoint(cs.blackPoint, XYZ_Flat, XYZ_Black);
  44596. var XYZ_D65 = tempConvertMatrix2;
  44597. normalizeWhitePointToD65(FLAT_WHITEPOINT_MATRIX, XYZ_Black, XYZ_D65);
  44598. var SRGB = tempConvertMatrix1;
  44599. matrixProduct(SRGB_D65_XYZ_TO_RGB_MATRIX, XYZ_D65, SRGB);
  44600. var sR = sRGBTransferFunction(SRGB[0]);
  44601. var sG = sRGBTransferFunction(SRGB[1]);
  44602. var sB = sRGBTransferFunction(SRGB[2]);
  44603. // Convert the values to rgb range [0, 255].
  44604. dest[destOffset] = Math.round(sR * 255);
  44605. dest[destOffset + 1] = Math.round(sG * 255);
  44606. dest[destOffset + 2] = Math.round(sB * 255);
  44607. }
  44608. CalRGBCS.prototype = {
  44609. getRgb: function CalRGBCS_getRgb(src, srcOffset) {
  44610. var rgb = new Uint8Array(3);
  44611. this.getRgbItem(src, srcOffset, rgb, 0);
  44612. return rgb;
  44613. },
  44614. getRgbItem: function CalRGBCS_getRgbItem(src, srcOffset, dest, destOffset) {
  44615. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  44616. },
  44617. getRgbBuffer: function CalRGBCS_getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
  44618. var scale = 1 / ((1 << bits) - 1);
  44619. for (var i = 0; i < count; ++i) {
  44620. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  44621. srcOffset += 3;
  44622. destOffset += 3 + alpha01;
  44623. }
  44624. },
  44625. getOutputLength: function CalRGBCS_getOutputLength(inputLength, alpha01) {
  44626. return inputLength * (3 + alpha01) / 3 | 0;
  44627. },
  44628. isPassthrough: ColorSpace.prototype.isPassthrough,
  44629. fillRgb: ColorSpace.prototype.fillRgb,
  44630. isDefaultDecode: function CalRGBCS_isDefaultDecode(decodeMap) {
  44631. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  44632. },
  44633. usesZeroToOneRange: true
  44634. };
  44635. return CalRGBCS;
  44636. }();
  44637. //
  44638. // LabCS: Based on "PDF Reference, Sixth Ed", p.250
  44639. //
  44640. var LabCS = function LabCSClosure() {
  44641. function LabCS(whitePoint, blackPoint, range) {
  44642. this.name = 'Lab';
  44643. this.numComps = 3;
  44644. this.defaultColor = new Float32Array([
  44645. 0,
  44646. 0,
  44647. 0
  44648. ]);
  44649. if (!whitePoint) {
  44650. error('WhitePoint missing - required for color space Lab');
  44651. }
  44652. blackPoint = blackPoint || [
  44653. 0,
  44654. 0,
  44655. 0
  44656. ];
  44657. range = range || [
  44658. -100,
  44659. 100,
  44660. -100,
  44661. 100
  44662. ];
  44663. // Translate args to spec variables
  44664. this.XW = whitePoint[0];
  44665. this.YW = whitePoint[1];
  44666. this.ZW = whitePoint[2];
  44667. this.amin = range[0];
  44668. this.amax = range[1];
  44669. this.bmin = range[2];
  44670. this.bmax = range[3];
  44671. // These are here just for completeness - the spec doesn't offer any
  44672. // formulas that use BlackPoint in Lab
  44673. this.XB = blackPoint[0];
  44674. this.YB = blackPoint[1];
  44675. this.ZB = blackPoint[2];
  44676. // Validate vars as per spec
  44677. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  44678. error('Invalid WhitePoint components, no fallback available');
  44679. }
  44680. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  44681. info('Invalid BlackPoint, falling back to default');
  44682. this.XB = this.YB = this.ZB = 0;
  44683. }
  44684. if (this.amin > this.amax || this.bmin > this.bmax) {
  44685. info('Invalid Range, falling back to defaults');
  44686. this.amin = -100;
  44687. this.amax = 100;
  44688. this.bmin = -100;
  44689. this.bmax = 100;
  44690. }
  44691. }
  44692. // Function g(x) from spec
  44693. function fn_g(x) {
  44694. if (x >= 6 / 29) {
  44695. return x * x * x;
  44696. } else {
  44697. return 108 / 841 * (x - 4 / 29);
  44698. }
  44699. }
  44700. function decode(value, high1, low2, high2) {
  44701. return low2 + value * (high2 - low2) / high1;
  44702. }
  44703. // If decoding is needed maxVal should be 2^bits per component - 1.
  44704. function convertToRgb(cs, src, srcOffset, maxVal, dest, destOffset) {
  44705. // XXX: Lab input is in the range of [0, 100], [amin, amax], [bmin, bmax]
  44706. // not the usual [0, 1]. If a command like setFillColor is used the src
  44707. // values will already be within the correct range. However, if we are
  44708. // converting an image we have to map the values to the correct range given
  44709. // above.
  44710. // Ls,as,bs <---> L*,a*,b* in the spec
  44711. var Ls = src[srcOffset];
  44712. var as = src[srcOffset + 1];
  44713. var bs = src[srcOffset + 2];
  44714. if (maxVal !== false) {
  44715. Ls = decode(Ls, maxVal, 0, 100);
  44716. as = decode(as, maxVal, cs.amin, cs.amax);
  44717. bs = decode(bs, maxVal, cs.bmin, cs.bmax);
  44718. }
  44719. // Adjust limits of 'as' and 'bs'
  44720. as = as > cs.amax ? cs.amax : as < cs.amin ? cs.amin : as;
  44721. bs = bs > cs.bmax ? cs.bmax : bs < cs.bmin ? cs.bmin : bs;
  44722. // Computes intermediate variables X,Y,Z as per spec
  44723. var M = (Ls + 16) / 116;
  44724. var L = M + as / 500;
  44725. var N = M - bs / 200;
  44726. var X = cs.XW * fn_g(L);
  44727. var Y = cs.YW * fn_g(M);
  44728. var Z = cs.ZW * fn_g(N);
  44729. var r, g, b;
  44730. // Using different conversions for D50 and D65 white points,
  44731. // per http://www.color.org/srgb.pdf
  44732. if (cs.ZW < 1) {
  44733. // Assuming D50 (X=0.9642, Y=1.00, Z=0.8249)
  44734. r = X * 3.1339 + Y * -1.6170 + Z * -0.4906;
  44735. g = X * -0.9785 + Y * 1.9160 + Z * 0.0333;
  44736. b = X * 0.0720 + Y * -0.2290 + Z * 1.4057;
  44737. } else {
  44738. // Assuming D65 (X=0.9505, Y=1.00, Z=1.0888)
  44739. r = X * 3.2406 + Y * -1.5372 + Z * -0.4986;
  44740. g = X * -0.9689 + Y * 1.8758 + Z * 0.0415;
  44741. b = X * 0.0557 + Y * -0.2040 + Z * 1.0570;
  44742. }
  44743. // clamp color values to [0,1] range then convert to [0,255] range.
  44744. dest[destOffset] = r <= 0 ? 0 : r >= 1 ? 255 : Math.sqrt(r) * 255 | 0;
  44745. dest[destOffset + 1] = g <= 0 ? 0 : g >= 1 ? 255 : Math.sqrt(g) * 255 | 0;
  44746. dest[destOffset + 2] = b <= 0 ? 0 : b >= 1 ? 255 : Math.sqrt(b) * 255 | 0;
  44747. }
  44748. LabCS.prototype = {
  44749. getRgb: ColorSpace.prototype.getRgb,
  44750. getRgbItem: function LabCS_getRgbItem(src, srcOffset, dest, destOffset) {
  44751. convertToRgb(this, src, srcOffset, false, dest, destOffset);
  44752. },
  44753. getRgbBuffer: function LabCS_getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
  44754. var maxVal = (1 << bits) - 1;
  44755. for (var i = 0; i < count; i++) {
  44756. convertToRgb(this, src, srcOffset, maxVal, dest, destOffset);
  44757. srcOffset += 3;
  44758. destOffset += 3 + alpha01;
  44759. }
  44760. },
  44761. getOutputLength: function LabCS_getOutputLength(inputLength, alpha01) {
  44762. return inputLength * (3 + alpha01) / 3 | 0;
  44763. },
  44764. isPassthrough: ColorSpace.prototype.isPassthrough,
  44765. fillRgb: ColorSpace.prototype.fillRgb,
  44766. isDefaultDecode: function LabCS_isDefaultDecode(decodeMap) {
  44767. // XXX: Decoding is handled with the lab conversion because of the strange
  44768. // ranges that are used.
  44769. return true;
  44770. },
  44771. usesZeroToOneRange: false
  44772. };
  44773. return LabCS;
  44774. }();
  44775. exports.ColorSpace = ColorSpace;
  44776. }));
  44777. (function (root, factory) {
  44778. factory(root.pdfjsCoreImage = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCoreColorSpace, root.pdfjsCoreStream, root.pdfjsCoreJpx);
  44779. }(this, function (exports, sharedUtil, corePrimitives, coreColorSpace, coreStream, coreJpx) {
  44780. var ImageKind = sharedUtil.ImageKind;
  44781. var assert = sharedUtil.assert;
  44782. var error = sharedUtil.error;
  44783. var info = sharedUtil.info;
  44784. var isArray = sharedUtil.isArray;
  44785. var warn = sharedUtil.warn;
  44786. var Name = corePrimitives.Name;
  44787. var isStream = corePrimitives.isStream;
  44788. var ColorSpace = coreColorSpace.ColorSpace;
  44789. var DecodeStream = coreStream.DecodeStream;
  44790. var JpegStream = coreStream.JpegStream;
  44791. var JpxImage = coreJpx.JpxImage;
  44792. var PDFImage = function PDFImageClosure() {
  44793. /**
  44794. * Decodes the image using native decoder if possible. Resolves the promise
  44795. * when the image data is ready.
  44796. */
  44797. function handleImageData(image, nativeDecoder) {
  44798. if (nativeDecoder && nativeDecoder.canDecode(image)) {
  44799. return nativeDecoder.decode(image);
  44800. } else {
  44801. return Promise.resolve(image);
  44802. }
  44803. }
  44804. /**
  44805. * Decode and clamp a value. The formula is different from the spec because we
  44806. * don't decode to float range [0,1], we decode it in the [0,max] range.
  44807. */
  44808. function decodeAndClamp(value, addend, coefficient, max) {
  44809. value = addend + value * coefficient;
  44810. // Clamp the value to the range
  44811. return value < 0 ? 0 : value > max ? max : value;
  44812. }
  44813. /**
  44814. * Resizes an image mask with 1 component.
  44815. * @param {TypedArray} src - The source buffer.
  44816. * @param {Number} bpc - Number of bits per component.
  44817. * @param {Number} w1 - Original width.
  44818. * @param {Number} h1 - Original height.
  44819. * @param {Number} w2 - New width.
  44820. * @param {Number} h2 - New height.
  44821. * @returns {TypedArray} The resized image mask buffer.
  44822. */
  44823. function resizeImageMask(src, bpc, w1, h1, w2, h2) {
  44824. var length = w2 * h2;
  44825. var dest = bpc <= 8 ? new Uint8Array(length) : bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length);
  44826. var xRatio = w1 / w2;
  44827. var yRatio = h1 / h2;
  44828. var i, j, py, newIndex = 0, oldIndex;
  44829. var xScaled = new Uint16Array(w2);
  44830. var w1Scanline = w1;
  44831. for (i = 0; i < w2; i++) {
  44832. xScaled[i] = Math.floor(i * xRatio);
  44833. }
  44834. for (i = 0; i < h2; i++) {
  44835. py = Math.floor(i * yRatio) * w1Scanline;
  44836. for (j = 0; j < w2; j++) {
  44837. oldIndex = py + xScaled[j];
  44838. dest[newIndex++] = src[oldIndex];
  44839. }
  44840. }
  44841. return dest;
  44842. }
  44843. function PDFImage(xref, res, image, inline, smask, mask, isMask) {
  44844. this.image = image;
  44845. var dict = image.dict;
  44846. if (dict.has('Filter')) {
  44847. var filter = dict.get('Filter').name;
  44848. if (filter === 'JPXDecode') {
  44849. var jpxImage = new JpxImage();
  44850. jpxImage.parseImageProperties(image.stream);
  44851. image.stream.reset();
  44852. image.bitsPerComponent = jpxImage.bitsPerComponent;
  44853. image.numComps = jpxImage.componentsCount;
  44854. } else if (filter === 'JBIG2Decode') {
  44855. image.bitsPerComponent = 1;
  44856. image.numComps = 1;
  44857. }
  44858. }
  44859. // TODO cache rendered images?
  44860. this.width = dict.get('Width', 'W');
  44861. this.height = dict.get('Height', 'H');
  44862. if (this.width < 1 || this.height < 1) {
  44863. error('Invalid image width: ' + this.width + ' or height: ' + this.height);
  44864. }
  44865. this.interpolate = dict.get('Interpolate', 'I') || false;
  44866. this.imageMask = dict.get('ImageMask', 'IM') || false;
  44867. this.matte = dict.get('Matte') || false;
  44868. var bitsPerComponent = image.bitsPerComponent;
  44869. if (!bitsPerComponent) {
  44870. bitsPerComponent = dict.get('BitsPerComponent', 'BPC');
  44871. if (!bitsPerComponent) {
  44872. if (this.imageMask) {
  44873. bitsPerComponent = 1;
  44874. } else {
  44875. error('Bits per component missing in image: ' + this.imageMask);
  44876. }
  44877. }
  44878. }
  44879. this.bpc = bitsPerComponent;
  44880. if (!this.imageMask) {
  44881. var colorSpace = dict.get('ColorSpace', 'CS');
  44882. if (!colorSpace) {
  44883. info('JPX images (which do not require color spaces)');
  44884. switch (image.numComps) {
  44885. case 1:
  44886. colorSpace = Name.get('DeviceGray');
  44887. break;
  44888. case 3:
  44889. colorSpace = Name.get('DeviceRGB');
  44890. break;
  44891. case 4:
  44892. colorSpace = Name.get('DeviceCMYK');
  44893. break;
  44894. default:
  44895. error('JPX images with ' + this.numComps + ' color components not supported.');
  44896. }
  44897. }
  44898. this.colorSpace = ColorSpace.parse(colorSpace, xref, res);
  44899. this.numComps = this.colorSpace.numComps;
  44900. }
  44901. this.decode = dict.getArray('Decode', 'D');
  44902. this.needsDecode = false;
  44903. if (this.decode && (this.colorSpace && !this.colorSpace.isDefaultDecode(this.decode) || isMask && !ColorSpace.isDefaultDecode(this.decode, 1))) {
  44904. this.needsDecode = true;
  44905. // Do some preprocessing to avoid more math.
  44906. var max = (1 << bitsPerComponent) - 1;
  44907. this.decodeCoefficients = [];
  44908. this.decodeAddends = [];
  44909. for (var i = 0, j = 0; i < this.decode.length; i += 2, ++j) {
  44910. var dmin = this.decode[i];
  44911. var dmax = this.decode[i + 1];
  44912. this.decodeCoefficients[j] = dmax - dmin;
  44913. this.decodeAddends[j] = max * dmin;
  44914. }
  44915. }
  44916. if (smask) {
  44917. this.smask = new PDFImage(xref, res, smask, false);
  44918. } else if (mask) {
  44919. if (isStream(mask)) {
  44920. var maskDict = mask.dict, imageMask = maskDict.get('ImageMask', 'IM');
  44921. if (!imageMask) {
  44922. warn('Ignoring /Mask in image without /ImageMask.');
  44923. } else {
  44924. this.mask = new PDFImage(xref, res, mask, false, null, null, true);
  44925. }
  44926. } else {
  44927. // Color key mask (just an array).
  44928. this.mask = mask;
  44929. }
  44930. }
  44931. }
  44932. /**
  44933. * Handles processing of image data and returns the Promise that is resolved
  44934. * with a PDFImage when the image is ready to be used.
  44935. */
  44936. PDFImage.buildImage = function PDFImage_buildImage(handler, xref, res, image, inline, nativeDecoder) {
  44937. var imagePromise = handleImageData(image, nativeDecoder);
  44938. var smaskPromise;
  44939. var maskPromise;
  44940. var smask = image.dict.get('SMask');
  44941. var mask = image.dict.get('Mask');
  44942. if (smask) {
  44943. smaskPromise = handleImageData(smask, nativeDecoder);
  44944. maskPromise = Promise.resolve(null);
  44945. } else {
  44946. smaskPromise = Promise.resolve(null);
  44947. if (mask) {
  44948. if (isStream(mask)) {
  44949. maskPromise = handleImageData(mask, nativeDecoder);
  44950. } else if (isArray(mask)) {
  44951. maskPromise = Promise.resolve(mask);
  44952. } else {
  44953. warn('Unsupported mask format.');
  44954. maskPromise = Promise.resolve(null);
  44955. }
  44956. } else {
  44957. maskPromise = Promise.resolve(null);
  44958. }
  44959. }
  44960. return Promise.all([
  44961. imagePromise,
  44962. smaskPromise,
  44963. maskPromise
  44964. ]).then(function (results) {
  44965. var imageData = results[0];
  44966. var smaskData = results[1];
  44967. var maskData = results[2];
  44968. return new PDFImage(xref, res, imageData, inline, smaskData, maskData);
  44969. });
  44970. };
  44971. PDFImage.createMask = function PDFImage_createMask(imgArray, width, height, imageIsFromDecodeStream, inverseDecode) {
  44972. // |imgArray| might not contain full data for every pixel of the mask, so
  44973. // we need to distinguish between |computedLength| and |actualLength|.
  44974. // In particular, if inverseDecode is true, then the array we return must
  44975. // have a length of |computedLength|.
  44976. var computedLength = (width + 7 >> 3) * height;
  44977. var actualLength = imgArray.byteLength;
  44978. var haveFullData = computedLength === actualLength;
  44979. var data, i;
  44980. if (imageIsFromDecodeStream && (!inverseDecode || haveFullData)) {
  44981. // imgArray came from a DecodeStream and its data is in an appropriate
  44982. // form, so we can just transfer it.
  44983. data = imgArray;
  44984. } else if (!inverseDecode) {
  44985. data = new Uint8Array(actualLength);
  44986. data.set(imgArray);
  44987. } else {
  44988. data = new Uint8Array(computedLength);
  44989. data.set(imgArray);
  44990. for (i = actualLength; i < computedLength; i++) {
  44991. data[i] = 0xff;
  44992. }
  44993. }
  44994. // If necessary, invert the original mask data (but not any extra we might
  44995. // have added above). It's safe to modify the array -- whether it's the
  44996. // original or a copy, we're about to transfer it anyway, so nothing else
  44997. // in this thread can be relying on its contents.
  44998. if (inverseDecode) {
  44999. for (i = 0; i < actualLength; i++) {
  45000. data[i] = ~data[i];
  45001. }
  45002. }
  45003. return {
  45004. data: data,
  45005. width: width,
  45006. height: height
  45007. };
  45008. };
  45009. PDFImage.prototype = {
  45010. get drawWidth() {
  45011. return Math.max(this.width, this.smask && this.smask.width || 0, this.mask && this.mask.width || 0);
  45012. },
  45013. get drawHeight() {
  45014. return Math.max(this.height, this.smask && this.smask.height || 0, this.mask && this.mask.height || 0);
  45015. },
  45016. decodeBuffer: function PDFImage_decodeBuffer(buffer) {
  45017. var bpc = this.bpc;
  45018. var numComps = this.numComps;
  45019. var decodeAddends = this.decodeAddends;
  45020. var decodeCoefficients = this.decodeCoefficients;
  45021. var max = (1 << bpc) - 1;
  45022. var i, ii;
  45023. if (bpc === 1) {
  45024. // If the buffer needed decode that means it just needs to be inverted.
  45025. for (i = 0, ii = buffer.length; i < ii; i++) {
  45026. buffer[i] = +!buffer[i];
  45027. }
  45028. return;
  45029. }
  45030. var index = 0;
  45031. for (i = 0, ii = this.width * this.height; i < ii; i++) {
  45032. for (var j = 0; j < numComps; j++) {
  45033. buffer[index] = decodeAndClamp(buffer[index], decodeAddends[j], decodeCoefficients[j], max);
  45034. index++;
  45035. }
  45036. }
  45037. },
  45038. getComponents: function PDFImage_getComponents(buffer) {
  45039. var bpc = this.bpc;
  45040. // This image doesn't require any extra work.
  45041. if (bpc === 8) {
  45042. return buffer;
  45043. }
  45044. var width = this.width;
  45045. var height = this.height;
  45046. var numComps = this.numComps;
  45047. var length = width * height * numComps;
  45048. var bufferPos = 0;
  45049. var output = bpc <= 8 ? new Uint8Array(length) : bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length);
  45050. var rowComps = width * numComps;
  45051. var max = (1 << bpc) - 1;
  45052. var i = 0, ii, buf;
  45053. if (bpc === 1) {
  45054. // Optimization for reading 1 bpc images.
  45055. var mask, loop1End, loop2End;
  45056. for (var j = 0; j < height; j++) {
  45057. loop1End = i + (rowComps & ~7);
  45058. loop2End = i + rowComps;
  45059. // unroll loop for all full bytes
  45060. while (i < loop1End) {
  45061. buf = buffer[bufferPos++];
  45062. output[i] = buf >> 7 & 1;
  45063. output[i + 1] = buf >> 6 & 1;
  45064. output[i + 2] = buf >> 5 & 1;
  45065. output[i + 3] = buf >> 4 & 1;
  45066. output[i + 4] = buf >> 3 & 1;
  45067. output[i + 5] = buf >> 2 & 1;
  45068. output[i + 6] = buf >> 1 & 1;
  45069. output[i + 7] = buf & 1;
  45070. i += 8;
  45071. }
  45072. // handle remaining bits
  45073. if (i < loop2End) {
  45074. buf = buffer[bufferPos++];
  45075. mask = 128;
  45076. while (i < loop2End) {
  45077. output[i++] = +!!(buf & mask);
  45078. mask >>= 1;
  45079. }
  45080. }
  45081. }
  45082. } else {
  45083. // The general case that handles all other bpc values.
  45084. var bits = 0;
  45085. buf = 0;
  45086. for (i = 0, ii = length; i < ii; ++i) {
  45087. if (i % rowComps === 0) {
  45088. buf = 0;
  45089. bits = 0;
  45090. }
  45091. while (bits < bpc) {
  45092. buf = buf << 8 | buffer[bufferPos++];
  45093. bits += 8;
  45094. }
  45095. var remainingBits = bits - bpc;
  45096. var value = buf >> remainingBits;
  45097. output[i] = value < 0 ? 0 : value > max ? max : value;
  45098. buf = buf & (1 << remainingBits) - 1;
  45099. bits = remainingBits;
  45100. }
  45101. }
  45102. return output;
  45103. },
  45104. fillOpacity: function PDFImage_fillOpacity(rgbaBuf, width, height, actualHeight, image) {
  45105. var smask = this.smask;
  45106. var mask = this.mask;
  45107. var alphaBuf, sw, sh, i, ii, j;
  45108. if (smask) {
  45109. sw = smask.width;
  45110. sh = smask.height;
  45111. alphaBuf = new Uint8Array(sw * sh);
  45112. smask.fillGrayBuffer(alphaBuf);
  45113. if (sw !== width || sh !== height) {
  45114. alphaBuf = resizeImageMask(alphaBuf, smask.bpc, sw, sh, width, height);
  45115. }
  45116. } else if (mask) {
  45117. if (mask instanceof PDFImage) {
  45118. sw = mask.width;
  45119. sh = mask.height;
  45120. alphaBuf = new Uint8Array(sw * sh);
  45121. mask.numComps = 1;
  45122. mask.fillGrayBuffer(alphaBuf);
  45123. // Need to invert values in rgbaBuf
  45124. for (i = 0, ii = sw * sh; i < ii; ++i) {
  45125. alphaBuf[i] = 255 - alphaBuf[i];
  45126. }
  45127. if (sw !== width || sh !== height) {
  45128. alphaBuf = resizeImageMask(alphaBuf, mask.bpc, sw, sh, width, height);
  45129. }
  45130. } else if (isArray(mask)) {
  45131. // Color key mask: if any of the components are outside the range
  45132. // then they should be painted.
  45133. alphaBuf = new Uint8Array(width * height);
  45134. var numComps = this.numComps;
  45135. for (i = 0, ii = width * height; i < ii; ++i) {
  45136. var opacity = 0;
  45137. var imageOffset = i * numComps;
  45138. for (j = 0; j < numComps; ++j) {
  45139. var color = image[imageOffset + j];
  45140. var maskOffset = j * 2;
  45141. if (color < mask[maskOffset] || color > mask[maskOffset + 1]) {
  45142. opacity = 255;
  45143. break;
  45144. }
  45145. }
  45146. alphaBuf[i] = opacity;
  45147. }
  45148. } else {
  45149. error('Unknown mask format.');
  45150. }
  45151. }
  45152. if (alphaBuf) {
  45153. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  45154. rgbaBuf[j] = alphaBuf[i];
  45155. }
  45156. } else {
  45157. // No mask.
  45158. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  45159. rgbaBuf[j] = 255;
  45160. }
  45161. }
  45162. },
  45163. undoPreblend: function PDFImage_undoPreblend(buffer, width, height) {
  45164. var matte = this.smask && this.smask.matte;
  45165. if (!matte) {
  45166. return;
  45167. }
  45168. var matteRgb = this.colorSpace.getRgb(matte, 0);
  45169. var matteR = matteRgb[0];
  45170. var matteG = matteRgb[1];
  45171. var matteB = matteRgb[2];
  45172. var length = width * height * 4;
  45173. var r, g, b;
  45174. for (var i = 0; i < length; i += 4) {
  45175. var alpha = buffer[i + 3];
  45176. if (alpha === 0) {
  45177. // according formula we have to get Infinity in all components
  45178. // making it white (typical paper color) should be okay
  45179. buffer[i] = 255;
  45180. buffer[i + 1] = 255;
  45181. buffer[i + 2] = 255;
  45182. continue;
  45183. }
  45184. var k = 255 / alpha;
  45185. r = (buffer[i] - matteR) * k + matteR;
  45186. g = (buffer[i + 1] - matteG) * k + matteG;
  45187. b = (buffer[i + 2] - matteB) * k + matteB;
  45188. buffer[i] = r <= 0 ? 0 : r >= 255 ? 255 : r | 0;
  45189. buffer[i + 1] = g <= 0 ? 0 : g >= 255 ? 255 : g | 0;
  45190. buffer[i + 2] = b <= 0 ? 0 : b >= 255 ? 255 : b | 0;
  45191. }
  45192. },
  45193. createImageData: function PDFImage_createImageData(forceRGBA) {
  45194. var drawWidth = this.drawWidth;
  45195. var drawHeight = this.drawHeight;
  45196. var imgData = {
  45197. // other fields are filled in below
  45198. width: drawWidth,
  45199. height: drawHeight
  45200. };
  45201. var numComps = this.numComps;
  45202. var originalWidth = this.width;
  45203. var originalHeight = this.height;
  45204. var bpc = this.bpc;
  45205. // Rows start at byte boundary.
  45206. var rowBytes = originalWidth * numComps * bpc + 7 >> 3;
  45207. var imgArray;
  45208. if (!forceRGBA) {
  45209. // If it is a 1-bit-per-pixel grayscale (i.e. black-and-white) image
  45210. // without any complications, we pass a same-sized copy to the main
  45211. // thread rather than expanding by 32x to RGBA form. This saves *lots*
  45212. // of memory for many scanned documents. It's also much faster.
  45213. //
  45214. // Similarly, if it is a 24-bit-per pixel RGB image without any
  45215. // complications, we avoid expanding by 1.333x to RGBA form.
  45216. var kind;
  45217. if (this.colorSpace.name === 'DeviceGray' && bpc === 1) {
  45218. kind = ImageKind.GRAYSCALE_1BPP;
  45219. } else if (this.colorSpace.name === 'DeviceRGB' && bpc === 8 && !this.needsDecode) {
  45220. kind = ImageKind.RGB_24BPP;
  45221. }
  45222. if (kind && !this.smask && !this.mask && drawWidth === originalWidth && drawHeight === originalHeight) {
  45223. imgData.kind = kind;
  45224. imgArray = this.getImageBytes(originalHeight * rowBytes);
  45225. // If imgArray came from a DecodeStream, we're safe to transfer it
  45226. // (and thus detach its underlying buffer) because it will constitute
  45227. // the entire DecodeStream's data. But if it came from a Stream, we
  45228. // need to copy it because it'll only be a portion of the Stream's
  45229. // data, and the rest will be read later on.
  45230. if (this.image instanceof DecodeStream) {
  45231. imgData.data = imgArray;
  45232. } else {
  45233. var newArray = new Uint8Array(imgArray.length);
  45234. newArray.set(imgArray);
  45235. imgData.data = newArray;
  45236. }
  45237. if (this.needsDecode) {
  45238. // Invert the buffer (which must be grayscale if we reached here).
  45239. assert(kind === ImageKind.GRAYSCALE_1BPP);
  45240. var buffer = imgData.data;
  45241. for (var i = 0, ii = buffer.length; i < ii; i++) {
  45242. buffer[i] ^= 0xff;
  45243. }
  45244. }
  45245. return imgData;
  45246. }
  45247. if (this.image instanceof JpegStream && !this.smask && !this.mask && (this.colorSpace.name === 'DeviceGray' || this.colorSpace.name === 'DeviceRGB' || this.colorSpace.name === 'DeviceCMYK')) {
  45248. imgData.kind = ImageKind.RGB_24BPP;
  45249. imgData.data = this.getImageBytes(originalHeight * rowBytes, drawWidth, drawHeight, true);
  45250. return imgData;
  45251. }
  45252. }
  45253. imgArray = this.getImageBytes(originalHeight * rowBytes);
  45254. // imgArray can be incomplete (e.g. after CCITT fax encoding).
  45255. var actualHeight = 0 | imgArray.length / rowBytes * drawHeight / originalHeight;
  45256. var comps = this.getComponents(imgArray);
  45257. // If opacity data is present, use RGBA_32BPP form. Otherwise, use the
  45258. // more compact RGB_24BPP form if allowable.
  45259. var alpha01, maybeUndoPreblend;
  45260. if (!forceRGBA && !this.smask && !this.mask) {
  45261. imgData.kind = ImageKind.RGB_24BPP;
  45262. imgData.data = new Uint8Array(drawWidth * drawHeight * 3);
  45263. alpha01 = 0;
  45264. maybeUndoPreblend = false;
  45265. } else {
  45266. imgData.kind = ImageKind.RGBA_32BPP;
  45267. imgData.data = new Uint8Array(drawWidth * drawHeight * 4);
  45268. alpha01 = 1;
  45269. maybeUndoPreblend = true;
  45270. // Color key masking (opacity) must be performed before decoding.
  45271. this.fillOpacity(imgData.data, drawWidth, drawHeight, actualHeight, comps);
  45272. }
  45273. if (this.needsDecode) {
  45274. this.decodeBuffer(comps);
  45275. }
  45276. this.colorSpace.fillRgb(imgData.data, originalWidth, originalHeight, drawWidth, drawHeight, actualHeight, bpc, comps, alpha01);
  45277. if (maybeUndoPreblend) {
  45278. this.undoPreblend(imgData.data, drawWidth, actualHeight);
  45279. }
  45280. return imgData;
  45281. },
  45282. fillGrayBuffer: function PDFImage_fillGrayBuffer(buffer) {
  45283. var numComps = this.numComps;
  45284. if (numComps !== 1) {
  45285. error('Reading gray scale from a color image: ' + numComps);
  45286. }
  45287. var width = this.width;
  45288. var height = this.height;
  45289. var bpc = this.bpc;
  45290. // rows start at byte boundary
  45291. var rowBytes = width * numComps * bpc + 7 >> 3;
  45292. var imgArray = this.getImageBytes(height * rowBytes);
  45293. var comps = this.getComponents(imgArray);
  45294. var i, length;
  45295. if (bpc === 1) {
  45296. // inline decoding (= inversion) for 1 bpc images
  45297. length = width * height;
  45298. if (this.needsDecode) {
  45299. // invert and scale to {0, 255}
  45300. for (i = 0; i < length; ++i) {
  45301. buffer[i] = comps[i] - 1 & 255;
  45302. }
  45303. } else {
  45304. // scale to {0, 255}
  45305. for (i = 0; i < length; ++i) {
  45306. buffer[i] = -comps[i] & 255;
  45307. }
  45308. }
  45309. return;
  45310. }
  45311. if (this.needsDecode) {
  45312. this.decodeBuffer(comps);
  45313. }
  45314. length = width * height;
  45315. // we aren't using a colorspace so we need to scale the value
  45316. var scale = 255 / ((1 << bpc) - 1);
  45317. for (i = 0; i < length; ++i) {
  45318. buffer[i] = scale * comps[i] | 0;
  45319. }
  45320. },
  45321. getImageBytes: function PDFImage_getImageBytes(length, drawWidth, drawHeight, forceRGB) {
  45322. this.image.reset();
  45323. this.image.drawWidth = drawWidth || this.width;
  45324. this.image.drawHeight = drawHeight || this.height;
  45325. this.image.forceRGB = !!forceRGB;
  45326. return this.image.getBytes(length);
  45327. }
  45328. };
  45329. return PDFImage;
  45330. }();
  45331. exports.PDFImage = PDFImage;
  45332. }));
  45333. (function (root, factory) {
  45334. factory(root.pdfjsCoreObj = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCoreCrypto, root.pdfjsCoreParser, root.pdfjsCoreChunkedStream, root.pdfjsCoreColorSpace);
  45335. }(this, function (exports, sharedUtil, corePrimitives, coreCrypto, coreParser, coreChunkedStream, coreColorSpace) {
  45336. var InvalidPDFException = sharedUtil.InvalidPDFException;
  45337. var MissingDataException = sharedUtil.MissingDataException;
  45338. var XRefParseException = sharedUtil.XRefParseException;
  45339. var assert = sharedUtil.assert;
  45340. var bytesToString = sharedUtil.bytesToString;
  45341. var createPromiseCapability = sharedUtil.createPromiseCapability;
  45342. var error = sharedUtil.error;
  45343. var info = sharedUtil.info;
  45344. var isArray = sharedUtil.isArray;
  45345. var isBool = sharedUtil.isBool;
  45346. var isInt = sharedUtil.isInt;
  45347. var isString = sharedUtil.isString;
  45348. var shadow = sharedUtil.shadow;
  45349. var stringToPDFString = sharedUtil.stringToPDFString;
  45350. var stringToUTF8String = sharedUtil.stringToUTF8String;
  45351. var warn = sharedUtil.warn;
  45352. var createValidAbsoluteUrl = sharedUtil.createValidAbsoluteUrl;
  45353. var Util = sharedUtil.Util;
  45354. var Ref = corePrimitives.Ref;
  45355. var RefSet = corePrimitives.RefSet;
  45356. var RefSetCache = corePrimitives.RefSetCache;
  45357. var isName = corePrimitives.isName;
  45358. var isCmd = corePrimitives.isCmd;
  45359. var isDict = corePrimitives.isDict;
  45360. var isRef = corePrimitives.isRef;
  45361. var isRefsEqual = corePrimitives.isRefsEqual;
  45362. var isStream = corePrimitives.isStream;
  45363. var CipherTransformFactory = coreCrypto.CipherTransformFactory;
  45364. var Lexer = coreParser.Lexer;
  45365. var Parser = coreParser.Parser;
  45366. var ChunkedStream = coreChunkedStream.ChunkedStream;
  45367. var ColorSpace = coreColorSpace.ColorSpace;
  45368. var Catalog = function CatalogClosure() {
  45369. function Catalog(pdfManager, xref, pageFactory) {
  45370. this.pdfManager = pdfManager;
  45371. this.xref = xref;
  45372. this.catDict = xref.getCatalogObj();
  45373. this.fontCache = new RefSetCache();
  45374. assert(isDict(this.catDict), 'catalog object is not a dictionary');
  45375. // TODO refactor to move getPage() to the PDFDocument.
  45376. this.pageFactory = pageFactory;
  45377. this.pagePromises = [];
  45378. }
  45379. Catalog.prototype = {
  45380. get metadata() {
  45381. var streamRef = this.catDict.getRaw('Metadata');
  45382. if (!isRef(streamRef)) {
  45383. return shadow(this, 'metadata', null);
  45384. }
  45385. var encryptMetadata = !this.xref.encrypt ? false : this.xref.encrypt.encryptMetadata;
  45386. var stream = this.xref.fetch(streamRef, !encryptMetadata);
  45387. var metadata;
  45388. if (stream && isDict(stream.dict)) {
  45389. var type = stream.dict.get('Type');
  45390. var subtype = stream.dict.get('Subtype');
  45391. if (isName(type, 'Metadata') && isName(subtype, 'XML')) {
  45392. // XXX: This should examine the charset the XML document defines,
  45393. // however since there are currently no real means to decode
  45394. // arbitrary charsets, let's just hope that the author of the PDF
  45395. // was reasonable enough to stick with the XML default charset,
  45396. // which is UTF-8.
  45397. try {
  45398. metadata = stringToUTF8String(bytesToString(stream.getBytes()));
  45399. } catch (e) {
  45400. info('Skipping invalid metadata.');
  45401. }
  45402. }
  45403. }
  45404. return shadow(this, 'metadata', metadata);
  45405. },
  45406. get toplevelPagesDict() {
  45407. var pagesObj = this.catDict.get('Pages');
  45408. assert(isDict(pagesObj), 'invalid top-level pages dictionary');
  45409. // shadow the prototype getter
  45410. return shadow(this, 'toplevelPagesDict', pagesObj);
  45411. },
  45412. get documentOutline() {
  45413. var obj = null;
  45414. try {
  45415. obj = this.readDocumentOutline();
  45416. } catch (ex) {
  45417. if (ex instanceof MissingDataException) {
  45418. throw ex;
  45419. }
  45420. warn('Unable to read document outline');
  45421. }
  45422. return shadow(this, 'documentOutline', obj);
  45423. },
  45424. readDocumentOutline: function Catalog_readDocumentOutline() {
  45425. var obj = this.catDict.get('Outlines');
  45426. if (!isDict(obj)) {
  45427. return null;
  45428. }
  45429. obj = obj.getRaw('First');
  45430. if (!isRef(obj)) {
  45431. return null;
  45432. }
  45433. var root = { items: [] };
  45434. var queue = [{
  45435. obj: obj,
  45436. parent: root
  45437. }];
  45438. // To avoid recursion, keep track of the already processed items.
  45439. var processed = new RefSet();
  45440. processed.put(obj);
  45441. var xref = this.xref, blackColor = new Uint8Array(3);
  45442. while (queue.length > 0) {
  45443. var i = queue.shift();
  45444. var outlineDict = xref.fetchIfRef(i.obj);
  45445. if (outlineDict === null) {
  45446. continue;
  45447. }
  45448. assert(outlineDict.has('Title'), 'Invalid outline item');
  45449. var data = {
  45450. url: null,
  45451. dest: null
  45452. };
  45453. Catalog.parseDestDictionary({
  45454. destDict: outlineDict,
  45455. resultObj: data,
  45456. docBaseUrl: this.pdfManager.docBaseUrl
  45457. });
  45458. var title = outlineDict.get('Title');
  45459. var flags = outlineDict.get('F') || 0;
  45460. var color = outlineDict.getArray('C'), rgbColor = blackColor;
  45461. // We only need to parse the color when it's valid, and non-default.
  45462. if (isArray(color) && color.length === 3 && (color[0] !== 0 || color[1] !== 0 || color[2] !== 0)) {
  45463. rgbColor = ColorSpace.singletons.rgb.getRgb(color, 0);
  45464. }
  45465. var outlineItem = {
  45466. dest: data.dest,
  45467. url: data.url,
  45468. newWindow: data.newWindow,
  45469. title: stringToPDFString(title),
  45470. color: rgbColor,
  45471. count: outlineDict.get('Count'),
  45472. bold: !!(flags & 2),
  45473. italic: !!(flags & 1),
  45474. items: []
  45475. };
  45476. i.parent.items.push(outlineItem);
  45477. obj = outlineDict.getRaw('First');
  45478. if (isRef(obj) && !processed.has(obj)) {
  45479. queue.push({
  45480. obj: obj,
  45481. parent: outlineItem
  45482. });
  45483. processed.put(obj);
  45484. }
  45485. obj = outlineDict.getRaw('Next');
  45486. if (isRef(obj) && !processed.has(obj)) {
  45487. queue.push({
  45488. obj: obj,
  45489. parent: i.parent
  45490. });
  45491. processed.put(obj);
  45492. }
  45493. }
  45494. return root.items.length > 0 ? root.items : null;
  45495. },
  45496. get numPages() {
  45497. var obj = this.toplevelPagesDict.get('Count');
  45498. assert(isInt(obj), 'page count in top level pages object is not an integer');
  45499. // shadow the prototype getter
  45500. return shadow(this, 'num', obj);
  45501. },
  45502. get destinations() {
  45503. function fetchDestination(dest) {
  45504. return isDict(dest) ? dest.get('D') : dest;
  45505. }
  45506. var xref = this.xref;
  45507. var dests = {}, nameTreeRef, nameDictionaryRef;
  45508. var obj = this.catDict.get('Names');
  45509. if (obj && obj.has('Dests')) {
  45510. nameTreeRef = obj.getRaw('Dests');
  45511. } else if (this.catDict.has('Dests')) {
  45512. nameDictionaryRef = this.catDict.get('Dests');
  45513. }
  45514. if (nameDictionaryRef) {
  45515. // reading simple destination dictionary
  45516. obj = nameDictionaryRef;
  45517. obj.forEach(function catalogForEach(key, value) {
  45518. if (!value) {
  45519. return;
  45520. }
  45521. dests[key] = fetchDestination(value);
  45522. });
  45523. }
  45524. if (nameTreeRef) {
  45525. var nameTree = new NameTree(nameTreeRef, xref);
  45526. var names = nameTree.getAll();
  45527. for (var name in names) {
  45528. dests[name] = fetchDestination(names[name]);
  45529. }
  45530. }
  45531. return shadow(this, 'destinations', dests);
  45532. },
  45533. getDestination: function Catalog_getDestination(destinationId) {
  45534. function fetchDestination(dest) {
  45535. return isDict(dest) ? dest.get('D') : dest;
  45536. }
  45537. var xref = this.xref;
  45538. var dest = null, nameTreeRef, nameDictionaryRef;
  45539. var obj = this.catDict.get('Names');
  45540. if (obj && obj.has('Dests')) {
  45541. nameTreeRef = obj.getRaw('Dests');
  45542. } else if (this.catDict.has('Dests')) {
  45543. nameDictionaryRef = this.catDict.get('Dests');
  45544. }
  45545. if (nameDictionaryRef) {
  45546. // Simple destination dictionary.
  45547. var value = nameDictionaryRef.get(destinationId);
  45548. if (value) {
  45549. dest = fetchDestination(value);
  45550. }
  45551. }
  45552. if (nameTreeRef) {
  45553. var nameTree = new NameTree(nameTreeRef, xref);
  45554. dest = fetchDestination(nameTree.get(destinationId));
  45555. }
  45556. return dest;
  45557. },
  45558. get pageLabels() {
  45559. var obj = null;
  45560. try {
  45561. obj = this.readPageLabels();
  45562. } catch (ex) {
  45563. if (ex instanceof MissingDataException) {
  45564. throw ex;
  45565. }
  45566. warn('Unable to read page labels.');
  45567. }
  45568. return shadow(this, 'pageLabels', obj);
  45569. },
  45570. readPageLabels: function Catalog_readPageLabels() {
  45571. var obj = this.catDict.getRaw('PageLabels');
  45572. if (!obj) {
  45573. return null;
  45574. }
  45575. var pageLabels = new Array(this.numPages);
  45576. var style = null;
  45577. var prefix = '';
  45578. var start = 1;
  45579. var numberTree = new NumberTree(obj, this.xref);
  45580. var nums = numberTree.getAll();
  45581. var currentLabel = '', currentIndex = 1;
  45582. for (var i = 0, ii = this.numPages; i < ii; i++) {
  45583. if (i in nums) {
  45584. var labelDict = nums[i];
  45585. assert(isDict(labelDict), 'The PageLabel is not a dictionary.');
  45586. var type = labelDict.get('Type');
  45587. assert(!type || isName(type, 'PageLabel'), 'Invalid type in PageLabel dictionary.');
  45588. var s = labelDict.get('S');
  45589. assert(!s || isName(s), 'Invalid style in PageLabel dictionary.');
  45590. style = s ? s.name : null;
  45591. prefix = labelDict.get('P') || '';
  45592. assert(isString(prefix), 'Invalid prefix in PageLabel dictionary.');
  45593. start = labelDict.get('St') || 1;
  45594. assert(isInt(start), 'Invalid start in PageLabel dictionary.');
  45595. currentIndex = start;
  45596. }
  45597. switch (style) {
  45598. case 'D':
  45599. currentLabel = currentIndex;
  45600. break;
  45601. case 'R':
  45602. case 'r':
  45603. currentLabel = Util.toRoman(currentIndex, style === 'r');
  45604. break;
  45605. case 'A':
  45606. case 'a':
  45607. var LIMIT = 26;
  45608. // Use only the characters A--Z, or a--z.
  45609. var A_UPPER_CASE = 0x41, A_LOWER_CASE = 0x61;
  45610. var baseCharCode = style === 'a' ? A_LOWER_CASE : A_UPPER_CASE;
  45611. var letterIndex = currentIndex - 1;
  45612. var character = String.fromCharCode(baseCharCode + letterIndex % LIMIT);
  45613. var charBuf = [];
  45614. for (var j = 0, jj = letterIndex / LIMIT | 0; j <= jj; j++) {
  45615. charBuf.push(character);
  45616. }
  45617. currentLabel = charBuf.join('');
  45618. break;
  45619. default:
  45620. assert(!style, 'Invalid style "' + style + '" in PageLabel dictionary.');
  45621. }
  45622. pageLabels[i] = prefix + currentLabel;
  45623. currentLabel = '';
  45624. currentIndex++;
  45625. }
  45626. return pageLabels;
  45627. },
  45628. get attachments() {
  45629. var xref = this.xref;
  45630. var attachments = null, nameTreeRef;
  45631. var obj = this.catDict.get('Names');
  45632. if (obj) {
  45633. nameTreeRef = obj.getRaw('EmbeddedFiles');
  45634. }
  45635. if (nameTreeRef) {
  45636. var nameTree = new NameTree(nameTreeRef, xref);
  45637. var names = nameTree.getAll();
  45638. for (var name in names) {
  45639. var fs = new FileSpec(names[name], xref);
  45640. if (!attachments) {
  45641. attachments = Object.create(null);
  45642. }
  45643. attachments[stringToPDFString(name)] = fs.serializable;
  45644. }
  45645. }
  45646. return shadow(this, 'attachments', attachments);
  45647. },
  45648. get javaScript() {
  45649. var xref = this.xref;
  45650. var obj = this.catDict.get('Names');
  45651. var javaScript = [];
  45652. function appendIfJavaScriptDict(jsDict) {
  45653. var type = jsDict.get('S');
  45654. if (!isName(type, 'JavaScript')) {
  45655. return;
  45656. }
  45657. var js = jsDict.get('JS');
  45658. if (isStream(js)) {
  45659. js = bytesToString(js.getBytes());
  45660. } else if (!isString(js)) {
  45661. return;
  45662. }
  45663. javaScript.push(stringToPDFString(js));
  45664. }
  45665. if (obj && obj.has('JavaScript')) {
  45666. var nameTree = new NameTree(obj.getRaw('JavaScript'), xref);
  45667. var names = nameTree.getAll();
  45668. for (var name in names) {
  45669. // We don't really use the JavaScript right now. This code is
  45670. // defensive so we don't cause errors on document load.
  45671. var jsDict = names[name];
  45672. if (isDict(jsDict)) {
  45673. appendIfJavaScriptDict(jsDict);
  45674. }
  45675. }
  45676. }
  45677. // Append OpenAction actions to javaScript array
  45678. var openactionDict = this.catDict.get('OpenAction');
  45679. if (isDict(openactionDict, 'Action')) {
  45680. var actionType = openactionDict.get('S');
  45681. if (isName(actionType, 'Named')) {
  45682. // The named Print action is not a part of the PDF 1.7 specification,
  45683. // but is supported by many PDF readers/writers (including Adobe's).
  45684. var action = openactionDict.get('N');
  45685. if (isName(action, 'Print')) {
  45686. javaScript.push('print({});');
  45687. }
  45688. } else {
  45689. appendIfJavaScriptDict(openactionDict);
  45690. }
  45691. }
  45692. return shadow(this, 'javaScript', javaScript);
  45693. },
  45694. cleanup: function Catalog_cleanup() {
  45695. var promises = [];
  45696. this.fontCache.forEach(function (promise) {
  45697. promises.push(promise);
  45698. });
  45699. return Promise.all(promises).then(function (translatedFonts) {
  45700. for (var i = 0, ii = translatedFonts.length; i < ii; i++) {
  45701. var font = translatedFonts[i].dict;
  45702. delete font.translated;
  45703. }
  45704. this.fontCache.clear();
  45705. }.bind(this));
  45706. },
  45707. getPage: function Catalog_getPage(pageIndex) {
  45708. if (!(pageIndex in this.pagePromises)) {
  45709. this.pagePromises[pageIndex] = this.getPageDict(pageIndex).then(function (a) {
  45710. var dict = a[0];
  45711. var ref = a[1];
  45712. return this.pageFactory.createPage(pageIndex, dict, ref, this.fontCache);
  45713. }.bind(this));
  45714. }
  45715. return this.pagePromises[pageIndex];
  45716. },
  45717. getPageDict: function Catalog_getPageDict(pageIndex) {
  45718. var capability = createPromiseCapability();
  45719. var nodesToVisit = [this.catDict.getRaw('Pages')];
  45720. var currentPageIndex = 0;
  45721. var xref = this.xref;
  45722. var checkAllKids = false;
  45723. function next() {
  45724. while (nodesToVisit.length) {
  45725. var currentNode = nodesToVisit.pop();
  45726. if (isRef(currentNode)) {
  45727. xref.fetchAsync(currentNode).then(function (obj) {
  45728. if (isDict(obj, 'Page') || isDict(obj) && !obj.has('Kids')) {
  45729. if (pageIndex === currentPageIndex) {
  45730. capability.resolve([
  45731. obj,
  45732. currentNode
  45733. ]);
  45734. } else {
  45735. currentPageIndex++;
  45736. next();
  45737. }
  45738. return;
  45739. }
  45740. nodesToVisit.push(obj);
  45741. next();
  45742. }, capability.reject);
  45743. return;
  45744. }
  45745. // Must be a child page dictionary.
  45746. assert(isDict(currentNode), 'page dictionary kid reference points to wrong type of object');
  45747. var count = currentNode.get('Count');
  45748. // If the current node doesn't have any children, avoid getting stuck
  45749. // in an empty node further down in the tree (see issue5644.pdf).
  45750. if (count === 0) {
  45751. checkAllKids = true;
  45752. }
  45753. // Skip nodes where the page can't be.
  45754. if (currentPageIndex + count <= pageIndex) {
  45755. currentPageIndex += count;
  45756. continue;
  45757. }
  45758. var kids = currentNode.get('Kids');
  45759. assert(isArray(kids), 'page dictionary kids object is not an array');
  45760. if (!checkAllKids && count === kids.length) {
  45761. // Nodes that don't have the page have been skipped and this is the
  45762. // bottom of the tree which means the page requested must be a
  45763. // descendant of this pages node. Ideally we would just resolve the
  45764. // promise with the page ref here, but there is the case where more
  45765. // pages nodes could link to single a page (see issue 3666 pdf). To
  45766. // handle this push it back on the queue so if it is a pages node it
  45767. // will be descended into.
  45768. nodesToVisit = [kids[pageIndex - currentPageIndex]];
  45769. currentPageIndex = pageIndex;
  45770. continue;
  45771. } else {
  45772. for (var last = kids.length - 1; last >= 0; last--) {
  45773. nodesToVisit.push(kids[last]);
  45774. }
  45775. }
  45776. }
  45777. capability.reject('Page index ' + pageIndex + ' not found.');
  45778. }
  45779. next();
  45780. return capability.promise;
  45781. },
  45782. getPageIndex: function Catalog_getPageIndex(pageRef) {
  45783. // The page tree nodes have the count of all the leaves below them. To get
  45784. // how many pages are before we just have to walk up the tree and keep
  45785. // adding the count of siblings to the left of the node.
  45786. var xref = this.xref;
  45787. function pagesBeforeRef(kidRef) {
  45788. var total = 0;
  45789. var parentRef;
  45790. return xref.fetchAsync(kidRef).then(function (node) {
  45791. if (isRefsEqual(kidRef, pageRef) && !isDict(node, 'Page') && !(isDict(node) && !node.has('Type') && node.has('Contents'))) {
  45792. throw new Error('The reference does not point to a /Page Dict.');
  45793. }
  45794. if (!node) {
  45795. return null;
  45796. }
  45797. assert(isDict(node), 'node must be a Dict.');
  45798. parentRef = node.getRaw('Parent');
  45799. return node.getAsync('Parent');
  45800. }).then(function (parent) {
  45801. if (!parent) {
  45802. return null;
  45803. }
  45804. assert(isDict(parent), 'parent must be a Dict.');
  45805. return parent.getAsync('Kids');
  45806. }).then(function (kids) {
  45807. if (!kids) {
  45808. return null;
  45809. }
  45810. var kidPromises = [];
  45811. var found = false;
  45812. for (var i = 0; i < kids.length; i++) {
  45813. var kid = kids[i];
  45814. assert(isRef(kid), 'kid must be a Ref.');
  45815. if (kid.num === kidRef.num) {
  45816. found = true;
  45817. break;
  45818. }
  45819. kidPromises.push(xref.fetchAsync(kid).then(function (kid) {
  45820. if (kid.has('Count')) {
  45821. var count = kid.get('Count');
  45822. total += count;
  45823. } else {
  45824. // page leaf node
  45825. total++;
  45826. }
  45827. }));
  45828. }
  45829. if (!found) {
  45830. error('kid ref not found in parents kids');
  45831. }
  45832. return Promise.all(kidPromises).then(function () {
  45833. return [
  45834. total,
  45835. parentRef
  45836. ];
  45837. });
  45838. });
  45839. }
  45840. var total = 0;
  45841. function next(ref) {
  45842. return pagesBeforeRef(ref).then(function (args) {
  45843. if (!args) {
  45844. return total;
  45845. }
  45846. var count = args[0];
  45847. var parentRef = args[1];
  45848. total += count;
  45849. return next(parentRef);
  45850. });
  45851. }
  45852. return next(pageRef);
  45853. }
  45854. };
  45855. /**
  45856. * Helper function used to parse the contents of destination dictionaries.
  45857. * @param {Dict} destDict - The dictionary containing the destination.
  45858. * @param {Object} resultObj - The object where the parsed destination
  45859. * properties will be placed.
  45860. * @param {string} docBaseUrl - (optional) The document base URL that is used
  45861. * when attempting to recover valid absolute URLs from relative ones.
  45862. */
  45863. Catalog.parseDestDictionary = function Catalog_parseDestDictionary(params) {
  45864. // Lets URLs beginning with 'www.' default to using the 'http://' protocol.
  45865. function addDefaultProtocolToUrl(url) {
  45866. if (url.indexOf('www.') === 0) {
  45867. return 'http://' + url;
  45868. }
  45869. return url;
  45870. }
  45871. // According to ISO 32000-1:2008, section 12.6.4.7, URIs should be encoded
  45872. // in 7-bit ASCII. Some bad PDFs use UTF-8 encoding, see Bugzilla 1122280.
  45873. function tryConvertUrlEncoding(url) {
  45874. try {
  45875. return stringToUTF8String(url);
  45876. } catch (e) {
  45877. return url;
  45878. }
  45879. }
  45880. var destDict = params.destDict;
  45881. if (!isDict(destDict)) {
  45882. warn('Catalog_parseDestDictionary: "destDict" must be a dictionary.');
  45883. return;
  45884. }
  45885. var resultObj = params.resultObj;
  45886. if (typeof resultObj !== 'object') {
  45887. warn('Catalog_parseDestDictionary: "resultObj" must be an object.');
  45888. return;
  45889. }
  45890. var docBaseUrl = params.docBaseUrl || null;
  45891. var action = destDict.get('A'), url, dest;
  45892. if (isDict(action)) {
  45893. var linkType = action.get('S').name;
  45894. switch (linkType) {
  45895. case 'URI':
  45896. url = action.get('URI');
  45897. if (isName(url)) {
  45898. // Some bad PDFs do not put parentheses around relative URLs.
  45899. url = '/' + url.name;
  45900. } else if (isString(url)) {
  45901. url = addDefaultProtocolToUrl(url);
  45902. }
  45903. // TODO: pdf spec mentions urls can be relative to a Base
  45904. // entry in the dictionary.
  45905. break;
  45906. case 'GoTo':
  45907. dest = action.get('D');
  45908. break;
  45909. case 'GoToR':
  45910. var urlDict = action.get('F');
  45911. if (isDict(urlDict)) {
  45912. // We assume that we found a FileSpec dictionary
  45913. // and fetch the URL without checking any further.
  45914. url = urlDict.get('F') || null;
  45915. } else if (isString(urlDict)) {
  45916. url = urlDict;
  45917. }
  45918. // NOTE: the destination is relative to the *remote* document.
  45919. var remoteDest = action.get('D');
  45920. if (remoteDest) {
  45921. if (isName(remoteDest)) {
  45922. remoteDest = remoteDest.name;
  45923. }
  45924. if (isString(url)) {
  45925. var baseUrl = url.split('#')[0];
  45926. if (isString(remoteDest)) {
  45927. // In practice, a named destination may contain only a number.
  45928. // If that happens, use the '#nameddest=' form to avoid the link
  45929. // redirecting to a page, instead of the correct destination.
  45930. url = baseUrl + '#' + (/^\d+$/.test(remoteDest) ? 'nameddest=' : '') + remoteDest;
  45931. } else if (isArray(remoteDest)) {
  45932. url = baseUrl + '#' + JSON.stringify(remoteDest);
  45933. }
  45934. }
  45935. }
  45936. // The 'NewWindow' property, equal to `LinkTarget.BLANK`.
  45937. var newWindow = action.get('NewWindow');
  45938. if (isBool(newWindow)) {
  45939. resultObj.newWindow = newWindow;
  45940. }
  45941. break;
  45942. case 'Named':
  45943. var namedAction = action.get('N');
  45944. if (isName(namedAction)) {
  45945. resultObj.action = namedAction.name;
  45946. }
  45947. break;
  45948. default:
  45949. warn('Catalog_parseDestDictionary: Unrecognized link type "' + linkType + '".');
  45950. break;
  45951. }
  45952. } else if (destDict.has('Dest')) {
  45953. // Simple destination link.
  45954. dest = destDict.get('Dest');
  45955. }
  45956. if (isString(url)) {
  45957. url = tryConvertUrlEncoding(url);
  45958. var absoluteUrl = createValidAbsoluteUrl(url, docBaseUrl);
  45959. if (absoluteUrl) {
  45960. resultObj.url = absoluteUrl.href;
  45961. }
  45962. resultObj.unsafeUrl = url;
  45963. }
  45964. if (dest) {
  45965. if (isName(dest)) {
  45966. dest = dest.name;
  45967. }
  45968. if (isString(dest) || isArray(dest)) {
  45969. resultObj.dest = dest;
  45970. }
  45971. }
  45972. };
  45973. return Catalog;
  45974. }();
  45975. var XRef = function XRefClosure() {
  45976. function XRef(stream, password) {
  45977. this.stream = stream;
  45978. this.entries = [];
  45979. this.xrefstms = Object.create(null);
  45980. // prepare the XRef cache
  45981. this.cache = [];
  45982. this.password = password;
  45983. this.stats = {
  45984. streamTypes: [],
  45985. fontTypes: []
  45986. };
  45987. }
  45988. XRef.prototype = {
  45989. setStartXRef: function XRef_setStartXRef(startXRef) {
  45990. // Store the starting positions of xref tables as we process them
  45991. // so we can recover from missing data errors
  45992. this.startXRefQueue = [startXRef];
  45993. },
  45994. parse: function XRef_parse(recoveryMode) {
  45995. var trailerDict;
  45996. if (!recoveryMode) {
  45997. trailerDict = this.readXRef();
  45998. } else {
  45999. warn('Indexing all PDF objects');
  46000. trailerDict = this.indexObjects();
  46001. }
  46002. trailerDict.assignXref(this);
  46003. this.trailer = trailerDict;
  46004. var encrypt = trailerDict.get('Encrypt');
  46005. if (encrypt) {
  46006. var ids = trailerDict.get('ID');
  46007. var fileId = ids && ids.length ? ids[0] : '';
  46008. // The 'Encrypt' dictionary itself should not be encrypted, and by
  46009. // setting `suppressEncryption` we can prevent an infinite loop inside
  46010. // of `XRef_fetchUncompressed` if the dictionary contains indirect
  46011. // objects (fixes issue7665.pdf).
  46012. encrypt.suppressEncryption = true;
  46013. this.encrypt = new CipherTransformFactory(encrypt, fileId, this.password);
  46014. }
  46015. // get the root dictionary (catalog) object
  46016. if (!(this.root = trailerDict.get('Root'))) {
  46017. error('Invalid root reference');
  46018. }
  46019. },
  46020. processXRefTable: function XRef_processXRefTable(parser) {
  46021. if (!('tableState' in this)) {
  46022. // Stores state of the table as we process it so we can resume
  46023. // from middle of table in case of missing data error
  46024. this.tableState = {
  46025. entryNum: 0,
  46026. streamPos: parser.lexer.stream.pos,
  46027. parserBuf1: parser.buf1,
  46028. parserBuf2: parser.buf2
  46029. };
  46030. }
  46031. var obj = this.readXRefTable(parser);
  46032. // Sanity check
  46033. if (!isCmd(obj, 'trailer')) {
  46034. error('Invalid XRef table: could not find trailer dictionary');
  46035. }
  46036. // Read trailer dictionary, e.g.
  46037. // trailer
  46038. // << /Size 22
  46039. // /Root 20R
  46040. // /Info 10R
  46041. // /ID [ <81b14aafa313db63dbd6f981e49f94f4> ]
  46042. // >>
  46043. // The parser goes through the entire stream << ... >> and provides
  46044. // a getter interface for the key-value table
  46045. var dict = parser.getObj();
  46046. // The pdflib PDF generator can generate a nested trailer dictionary
  46047. if (!isDict(dict) && dict.dict) {
  46048. dict = dict.dict;
  46049. }
  46050. if (!isDict(dict)) {
  46051. error('Invalid XRef table: could not parse trailer dictionary');
  46052. }
  46053. delete this.tableState;
  46054. return dict;
  46055. },
  46056. readXRefTable: function XRef_readXRefTable(parser) {
  46057. // Example of cross-reference table:
  46058. // xref
  46059. // 0 1 <-- subsection header (first obj #, obj count)
  46060. // 0000000000 65535 f <-- actual object (offset, generation #, f/n)
  46061. // 23 2 <-- subsection header ... and so on ...
  46062. // 0000025518 00002 n
  46063. // 0000025635 00000 n
  46064. // trailer
  46065. // ...
  46066. var stream = parser.lexer.stream;
  46067. var tableState = this.tableState;
  46068. stream.pos = tableState.streamPos;
  46069. parser.buf1 = tableState.parserBuf1;
  46070. parser.buf2 = tableState.parserBuf2;
  46071. // Outer loop is over subsection headers
  46072. var obj;
  46073. while (true) {
  46074. if (!('firstEntryNum' in tableState) || !('entryCount' in tableState)) {
  46075. if (isCmd(obj = parser.getObj(), 'trailer')) {
  46076. break;
  46077. }
  46078. tableState.firstEntryNum = obj;
  46079. tableState.entryCount = parser.getObj();
  46080. }
  46081. var first = tableState.firstEntryNum;
  46082. var count = tableState.entryCount;
  46083. if (!isInt(first) || !isInt(count)) {
  46084. error('Invalid XRef table: wrong types in subsection header');
  46085. }
  46086. // Inner loop is over objects themselves
  46087. for (var i = tableState.entryNum; i < count; i++) {
  46088. tableState.streamPos = stream.pos;
  46089. tableState.entryNum = i;
  46090. tableState.parserBuf1 = parser.buf1;
  46091. tableState.parserBuf2 = parser.buf2;
  46092. var entry = {};
  46093. entry.offset = parser.getObj();
  46094. entry.gen = parser.getObj();
  46095. var type = parser.getObj();
  46096. if (isCmd(type, 'f')) {
  46097. entry.free = true;
  46098. } else if (isCmd(type, 'n')) {
  46099. entry.uncompressed = true;
  46100. }
  46101. // Validate entry obj
  46102. if (!isInt(entry.offset) || !isInt(entry.gen) || !(entry.free || entry.uncompressed)) {
  46103. error('Invalid entry in XRef subsection: ' + first + ', ' + count);
  46104. }
  46105. // The first xref table entry, i.e. obj 0, should be free. Attempting
  46106. // to adjust an incorrect first obj # (fixes issue 3248 and 7229).
  46107. if (i === 0 && entry.free && first === 1) {
  46108. first = 0;
  46109. }
  46110. if (!this.entries[i + first]) {
  46111. this.entries[i + first] = entry;
  46112. }
  46113. }
  46114. tableState.entryNum = 0;
  46115. tableState.streamPos = stream.pos;
  46116. tableState.parserBuf1 = parser.buf1;
  46117. tableState.parserBuf2 = parser.buf2;
  46118. delete tableState.firstEntryNum;
  46119. delete tableState.entryCount;
  46120. }
  46121. // Sanity check: as per spec, first object must be free
  46122. if (this.entries[0] && !this.entries[0].free) {
  46123. error('Invalid XRef table: unexpected first object');
  46124. }
  46125. return obj;
  46126. },
  46127. processXRefStream: function XRef_processXRefStream(stream) {
  46128. if (!('streamState' in this)) {
  46129. // Stores state of the stream as we process it so we can resume
  46130. // from middle of stream in case of missing data error
  46131. var streamParameters = stream.dict;
  46132. var byteWidths = streamParameters.get('W');
  46133. var range = streamParameters.get('Index');
  46134. if (!range) {
  46135. range = [
  46136. 0,
  46137. streamParameters.get('Size')
  46138. ];
  46139. }
  46140. this.streamState = {
  46141. entryRanges: range,
  46142. byteWidths: byteWidths,
  46143. entryNum: 0,
  46144. streamPos: stream.pos
  46145. };
  46146. }
  46147. this.readXRefStream(stream);
  46148. delete this.streamState;
  46149. return stream.dict;
  46150. },
  46151. readXRefStream: function XRef_readXRefStream(stream) {
  46152. var i, j;
  46153. var streamState = this.streamState;
  46154. stream.pos = streamState.streamPos;
  46155. var byteWidths = streamState.byteWidths;
  46156. var typeFieldWidth = byteWidths[0];
  46157. var offsetFieldWidth = byteWidths[1];
  46158. var generationFieldWidth = byteWidths[2];
  46159. var entryRanges = streamState.entryRanges;
  46160. while (entryRanges.length > 0) {
  46161. var first = entryRanges[0];
  46162. var n = entryRanges[1];
  46163. if (!isInt(first) || !isInt(n)) {
  46164. error('Invalid XRef range fields: ' + first + ', ' + n);
  46165. }
  46166. if (!isInt(typeFieldWidth) || !isInt(offsetFieldWidth) || !isInt(generationFieldWidth)) {
  46167. error('Invalid XRef entry fields length: ' + first + ', ' + n);
  46168. }
  46169. for (i = streamState.entryNum; i < n; ++i) {
  46170. streamState.entryNum = i;
  46171. streamState.streamPos = stream.pos;
  46172. var type = 0, offset = 0, generation = 0;
  46173. for (j = 0; j < typeFieldWidth; ++j) {
  46174. type = type << 8 | stream.getByte();
  46175. }
  46176. // if type field is absent, its default value is 1
  46177. if (typeFieldWidth === 0) {
  46178. type = 1;
  46179. }
  46180. for (j = 0; j < offsetFieldWidth; ++j) {
  46181. offset = offset << 8 | stream.getByte();
  46182. }
  46183. for (j = 0; j < generationFieldWidth; ++j) {
  46184. generation = generation << 8 | stream.getByte();
  46185. }
  46186. var entry = {};
  46187. entry.offset = offset;
  46188. entry.gen = generation;
  46189. switch (type) {
  46190. case 0:
  46191. entry.free = true;
  46192. break;
  46193. case 1:
  46194. entry.uncompressed = true;
  46195. break;
  46196. case 2:
  46197. break;
  46198. default:
  46199. error('Invalid XRef entry type: ' + type);
  46200. }
  46201. if (!this.entries[first + i]) {
  46202. this.entries[first + i] = entry;
  46203. }
  46204. }
  46205. streamState.entryNum = 0;
  46206. streamState.streamPos = stream.pos;
  46207. entryRanges.splice(0, 2);
  46208. }
  46209. },
  46210. indexObjects: function XRef_indexObjects() {
  46211. // Simple scan through the PDF content to find objects,
  46212. // trailers and XRef streams.
  46213. var TAB = 0x9, LF = 0xA, CR = 0xD, SPACE = 0x20;
  46214. var PERCENT = 0x25, LT = 0x3C;
  46215. function readToken(data, offset) {
  46216. var token = '', ch = data[offset];
  46217. while (ch !== LF && ch !== CR && ch !== LT) {
  46218. if (++offset >= data.length) {
  46219. break;
  46220. }
  46221. token += String.fromCharCode(ch);
  46222. ch = data[offset];
  46223. }
  46224. return token;
  46225. }
  46226. function skipUntil(data, offset, what) {
  46227. var length = what.length, dataLength = data.length;
  46228. var skipped = 0;
  46229. // finding byte sequence
  46230. while (offset < dataLength) {
  46231. var i = 0;
  46232. while (i < length && data[offset + i] === what[i]) {
  46233. ++i;
  46234. }
  46235. if (i >= length) {
  46236. break;
  46237. }
  46238. // sequence found
  46239. offset++;
  46240. skipped++;
  46241. }
  46242. return skipped;
  46243. }
  46244. var objRegExp = /^(\d+)\s+(\d+)\s+obj\b/;
  46245. var trailerBytes = new Uint8Array([
  46246. 116,
  46247. 114,
  46248. 97,
  46249. 105,
  46250. 108,
  46251. 101,
  46252. 114
  46253. ]);
  46254. var startxrefBytes = new Uint8Array([
  46255. 115,
  46256. 116,
  46257. 97,
  46258. 114,
  46259. 116,
  46260. 120,
  46261. 114,
  46262. 101,
  46263. 102
  46264. ]);
  46265. var endobjBytes = new Uint8Array([
  46266. 101,
  46267. 110,
  46268. 100,
  46269. 111,
  46270. 98,
  46271. 106
  46272. ]);
  46273. var xrefBytes = new Uint8Array([
  46274. 47,
  46275. 88,
  46276. 82,
  46277. 101,
  46278. 102
  46279. ]);
  46280. // Clear out any existing entries, since they may be bogus.
  46281. this.entries.length = 0;
  46282. var stream = this.stream;
  46283. stream.pos = 0;
  46284. var buffer = stream.getBytes();
  46285. var position = stream.start, length = buffer.length;
  46286. var trailers = [], xrefStms = [];
  46287. while (position < length) {
  46288. var ch = buffer[position];
  46289. if (ch === TAB || ch === LF || ch === CR || ch === SPACE) {
  46290. ++position;
  46291. continue;
  46292. }
  46293. if (ch === PERCENT) {
  46294. // %-comment
  46295. do {
  46296. ++position;
  46297. if (position >= length) {
  46298. break;
  46299. }
  46300. ch = buffer[position];
  46301. } while (ch !== LF && ch !== CR);
  46302. continue;
  46303. }
  46304. var token = readToken(buffer, position);
  46305. var m;
  46306. if (token.indexOf('xref') === 0 && (token.length === 4 || /\s/.test(token[4]))) {
  46307. position += skipUntil(buffer, position, trailerBytes);
  46308. trailers.push(position);
  46309. position += skipUntil(buffer, position, startxrefBytes);
  46310. } else if (m = objRegExp.exec(token)) {
  46311. if (typeof this.entries[m[1]] === 'undefined') {
  46312. this.entries[m[1]] = {
  46313. offset: position - stream.start,
  46314. gen: m[2] | 0,
  46315. uncompressed: true
  46316. };
  46317. }
  46318. var contentLength = skipUntil(buffer, position, endobjBytes) + 7;
  46319. var content = buffer.subarray(position, position + contentLength);
  46320. // checking XRef stream suspect
  46321. // (it shall have '/XRef' and next char is not a letter)
  46322. var xrefTagOffset = skipUntil(content, 0, xrefBytes);
  46323. if (xrefTagOffset < contentLength && content[xrefTagOffset + 5] < 64) {
  46324. xrefStms.push(position - stream.start);
  46325. this.xrefstms[position - stream.start] = 1;
  46326. }
  46327. // Avoid recursion
  46328. position += contentLength;
  46329. } else if (token.indexOf('trailer') === 0 && (token.length === 7 || /\s/.test(token[7]))) {
  46330. trailers.push(position);
  46331. position += skipUntil(buffer, position, startxrefBytes);
  46332. } else {
  46333. position += token.length + 1;
  46334. }
  46335. }
  46336. // reading XRef streams
  46337. var i, ii;
  46338. for (i = 0, ii = xrefStms.length; i < ii; ++i) {
  46339. this.startXRefQueue.push(xrefStms[i]);
  46340. this.readXRef(/* recoveryMode */
  46341. true);
  46342. }
  46343. // finding main trailer
  46344. var dict;
  46345. for (i = 0, ii = trailers.length; i < ii; ++i) {
  46346. stream.pos = trailers[i];
  46347. var parser = new Parser(new Lexer(stream), /* allowStreams = */
  46348. true, /* xref = */
  46349. this, /* recoveryMode = */
  46350. true);
  46351. var obj = parser.getObj();
  46352. if (!isCmd(obj, 'trailer')) {
  46353. continue;
  46354. }
  46355. // read the trailer dictionary
  46356. dict = parser.getObj();
  46357. if (!isDict(dict)) {
  46358. continue;
  46359. }
  46360. // taking the first one with 'ID'
  46361. if (dict.has('ID')) {
  46362. return dict;
  46363. }
  46364. }
  46365. // no tailer with 'ID', taking last one (if exists)
  46366. if (dict) {
  46367. return dict;
  46368. }
  46369. // nothing helps
  46370. // calling error() would reject worker with an UnknownErrorException.
  46371. throw new InvalidPDFException('Invalid PDF structure');
  46372. },
  46373. readXRef: function XRef_readXRef(recoveryMode) {
  46374. var stream = this.stream;
  46375. try {
  46376. while (this.startXRefQueue.length) {
  46377. var startXRef = this.startXRefQueue[0];
  46378. stream.pos = startXRef + stream.start;
  46379. var parser = new Parser(new Lexer(stream), true, this);
  46380. var obj = parser.getObj();
  46381. var dict;
  46382. // Get dictionary
  46383. if (isCmd(obj, 'xref')) {
  46384. // Parse end-of-file XRef
  46385. dict = this.processXRefTable(parser);
  46386. if (!this.topDict) {
  46387. this.topDict = dict;
  46388. }
  46389. // Recursively get other XRefs 'XRefStm', if any
  46390. obj = dict.get('XRefStm');
  46391. if (isInt(obj)) {
  46392. var pos = obj;
  46393. // ignore previously loaded xref streams
  46394. // (possible infinite recursion)
  46395. if (!(pos in this.xrefstms)) {
  46396. this.xrefstms[pos] = 1;
  46397. this.startXRefQueue.push(pos);
  46398. }
  46399. }
  46400. } else if (isInt(obj)) {
  46401. // Parse in-stream XRef
  46402. if (!isInt(parser.getObj()) || !isCmd(parser.getObj(), 'obj') || !isStream(obj = parser.getObj())) {
  46403. error('Invalid XRef stream');
  46404. }
  46405. dict = this.processXRefStream(obj);
  46406. if (!this.topDict) {
  46407. this.topDict = dict;
  46408. }
  46409. if (!dict) {
  46410. error('Failed to read XRef stream');
  46411. }
  46412. } else {
  46413. error('Invalid XRef stream header');
  46414. }
  46415. // Recursively get previous dictionary, if any
  46416. obj = dict.get('Prev');
  46417. if (isInt(obj)) {
  46418. this.startXRefQueue.push(obj);
  46419. } else if (isRef(obj)) {
  46420. // The spec says Prev must not be a reference, i.e. "/Prev NNN"
  46421. // This is a fallback for non-compliant PDFs, i.e. "/Prev NNN 0 R"
  46422. this.startXRefQueue.push(obj.num);
  46423. }
  46424. this.startXRefQueue.shift();
  46425. }
  46426. return this.topDict;
  46427. } catch (e) {
  46428. if (e instanceof MissingDataException) {
  46429. throw e;
  46430. }
  46431. info('(while reading XRef): ' + e);
  46432. }
  46433. if (recoveryMode) {
  46434. return;
  46435. }
  46436. throw new XRefParseException();
  46437. },
  46438. getEntry: function XRef_getEntry(i) {
  46439. var xrefEntry = this.entries[i];
  46440. if (xrefEntry && !xrefEntry.free && xrefEntry.offset) {
  46441. return xrefEntry;
  46442. }
  46443. return null;
  46444. },
  46445. fetchIfRef: function XRef_fetchIfRef(obj, suppressEncryption) {
  46446. if (!isRef(obj)) {
  46447. return obj;
  46448. }
  46449. return this.fetch(obj, suppressEncryption);
  46450. },
  46451. fetch: function XRef_fetch(ref, suppressEncryption) {
  46452. assert(isRef(ref), 'ref object is not a reference');
  46453. var num = ref.num;
  46454. if (num in this.cache) {
  46455. var cacheEntry = this.cache[num];
  46456. return cacheEntry;
  46457. }
  46458. var xrefEntry = this.getEntry(num);
  46459. // the referenced entry can be free
  46460. if (xrefEntry === null) {
  46461. return this.cache[num] = null;
  46462. }
  46463. if (xrefEntry.uncompressed) {
  46464. xrefEntry = this.fetchUncompressed(ref, xrefEntry, suppressEncryption);
  46465. } else {
  46466. xrefEntry = this.fetchCompressed(xrefEntry, suppressEncryption);
  46467. }
  46468. if (isDict(xrefEntry)) {
  46469. xrefEntry.objId = ref.toString();
  46470. } else if (isStream(xrefEntry)) {
  46471. xrefEntry.dict.objId = ref.toString();
  46472. }
  46473. return xrefEntry;
  46474. },
  46475. fetchUncompressed: function XRef_fetchUncompressed(ref, xrefEntry, suppressEncryption) {
  46476. var gen = ref.gen;
  46477. var num = ref.num;
  46478. if (xrefEntry.gen !== gen) {
  46479. error('inconsistent generation in XRef');
  46480. }
  46481. var stream = this.stream.makeSubStream(xrefEntry.offset + this.stream.start);
  46482. var parser = new Parser(new Lexer(stream), true, this);
  46483. var obj1 = parser.getObj();
  46484. var obj2 = parser.getObj();
  46485. var obj3 = parser.getObj();
  46486. if (!isInt(obj1) || parseInt(obj1, 10) !== num || !isInt(obj2) || parseInt(obj2, 10) !== gen || !isCmd(obj3)) {
  46487. error('bad XRef entry');
  46488. }
  46489. if (!isCmd(obj3, 'obj')) {
  46490. // some bad PDFs use "obj1234" and really mean 1234
  46491. if (obj3.cmd.indexOf('obj') === 0) {
  46492. num = parseInt(obj3.cmd.substring(3), 10);
  46493. if (!isNaN(num)) {
  46494. return num;
  46495. }
  46496. }
  46497. error('bad XRef entry');
  46498. }
  46499. if (this.encrypt && !suppressEncryption) {
  46500. xrefEntry = parser.getObj(this.encrypt.createCipherTransform(num, gen));
  46501. } else {
  46502. xrefEntry = parser.getObj();
  46503. }
  46504. if (!isStream(xrefEntry)) {
  46505. this.cache[num] = xrefEntry;
  46506. }
  46507. return xrefEntry;
  46508. },
  46509. fetchCompressed: function XRef_fetchCompressed(xrefEntry, suppressEncryption) {
  46510. var tableOffset = xrefEntry.offset;
  46511. var stream = this.fetch(new Ref(tableOffset, 0));
  46512. if (!isStream(stream)) {
  46513. error('bad ObjStm stream');
  46514. }
  46515. var first = stream.dict.get('First');
  46516. var n = stream.dict.get('N');
  46517. if (!isInt(first) || !isInt(n)) {
  46518. error('invalid first and n parameters for ObjStm stream');
  46519. }
  46520. var parser = new Parser(new Lexer(stream), false, this);
  46521. parser.allowStreams = true;
  46522. var i, entries = [], num, nums = [];
  46523. // read the object numbers to populate cache
  46524. for (i = 0; i < n; ++i) {
  46525. num = parser.getObj();
  46526. if (!isInt(num)) {
  46527. error('invalid object number in the ObjStm stream: ' + num);
  46528. }
  46529. nums.push(num);
  46530. var offset = parser.getObj();
  46531. if (!isInt(offset)) {
  46532. error('invalid object offset in the ObjStm stream: ' + offset);
  46533. }
  46534. }
  46535. // read stream objects for cache
  46536. for (i = 0; i < n; ++i) {
  46537. entries.push(parser.getObj());
  46538. // The ObjStm should not contain 'endobj'. If it's present, skip over it
  46539. // to support corrupt PDFs (fixes issue 5241, bug 898610, bug 1037816).
  46540. if (isCmd(parser.buf1, 'endobj')) {
  46541. parser.shift();
  46542. }
  46543. num = nums[i];
  46544. var entry = this.entries[num];
  46545. if (entry && entry.offset === tableOffset && entry.gen === i) {
  46546. this.cache[num] = entries[i];
  46547. }
  46548. }
  46549. xrefEntry = entries[xrefEntry.gen];
  46550. if (xrefEntry === undefined) {
  46551. error('bad XRef entry for compressed object');
  46552. }
  46553. return xrefEntry;
  46554. },
  46555. fetchIfRefAsync: function XRef_fetchIfRefAsync(obj, suppressEncryption) {
  46556. if (!isRef(obj)) {
  46557. return Promise.resolve(obj);
  46558. }
  46559. return this.fetchAsync(obj, suppressEncryption);
  46560. },
  46561. fetchAsync: function XRef_fetchAsync(ref, suppressEncryption) {
  46562. var streamManager = this.stream.manager;
  46563. var xref = this;
  46564. return new Promise(function tryFetch(resolve, reject) {
  46565. try {
  46566. resolve(xref.fetch(ref, suppressEncryption));
  46567. } catch (e) {
  46568. if (e instanceof MissingDataException) {
  46569. streamManager.requestRange(e.begin, e.end).then(function () {
  46570. tryFetch(resolve, reject);
  46571. }, reject);
  46572. return;
  46573. }
  46574. reject(e);
  46575. }
  46576. });
  46577. },
  46578. getCatalogObj: function XRef_getCatalogObj() {
  46579. return this.root;
  46580. }
  46581. };
  46582. return XRef;
  46583. }();
  46584. /**
  46585. * A NameTree/NumberTree is like a Dict but has some advantageous properties,
  46586. * see the specification (7.9.6 and 7.9.7) for additional details.
  46587. * TODO: implement all the Dict functions and make this more efficient.
  46588. */
  46589. var NameOrNumberTree = function NameOrNumberTreeClosure() {
  46590. function NameOrNumberTree(root, xref) {
  46591. throw new Error('Cannot initialize NameOrNumberTree.');
  46592. }
  46593. NameOrNumberTree.prototype = {
  46594. getAll: function NameOrNumberTree_getAll() {
  46595. var dict = Object.create(null);
  46596. if (!this.root) {
  46597. return dict;
  46598. }
  46599. var xref = this.xref;
  46600. // Reading Name/Number tree.
  46601. var processed = new RefSet();
  46602. processed.put(this.root);
  46603. var queue = [this.root];
  46604. while (queue.length > 0) {
  46605. var i, n;
  46606. var obj = xref.fetchIfRef(queue.shift());
  46607. if (!isDict(obj)) {
  46608. continue;
  46609. }
  46610. if (obj.has('Kids')) {
  46611. var kids = obj.get('Kids');
  46612. for (i = 0, n = kids.length; i < n; i++) {
  46613. var kid = kids[i];
  46614. assert(!processed.has(kid), 'Duplicate entry in "' + this._type + '" tree.');
  46615. queue.push(kid);
  46616. processed.put(kid);
  46617. }
  46618. continue;
  46619. }
  46620. var entries = obj.get(this._type);
  46621. if (isArray(entries)) {
  46622. for (i = 0, n = entries.length; i < n; i += 2) {
  46623. dict[xref.fetchIfRef(entries[i])] = xref.fetchIfRef(entries[i + 1]);
  46624. }
  46625. }
  46626. }
  46627. return dict;
  46628. },
  46629. get: function NameOrNumberTree_get(key) {
  46630. if (!this.root) {
  46631. return null;
  46632. }
  46633. var xref = this.xref;
  46634. var kidsOrEntries = xref.fetchIfRef(this.root);
  46635. var loopCount = 0;
  46636. var MAX_LEVELS = 10;
  46637. var l, r, m;
  46638. // Perform a binary search to quickly find the entry that
  46639. // contains the key we are looking for.
  46640. while (kidsOrEntries.has('Kids')) {
  46641. if (++loopCount > MAX_LEVELS) {
  46642. warn('Search depth limit reached for "' + this._type + '" tree.');
  46643. return null;
  46644. }
  46645. var kids = kidsOrEntries.get('Kids');
  46646. if (!isArray(kids)) {
  46647. return null;
  46648. }
  46649. l = 0;
  46650. r = kids.length - 1;
  46651. while (l <= r) {
  46652. m = l + r >> 1;
  46653. var kid = xref.fetchIfRef(kids[m]);
  46654. var limits = kid.get('Limits');
  46655. if (key < xref.fetchIfRef(limits[0])) {
  46656. r = m - 1;
  46657. } else if (key > xref.fetchIfRef(limits[1])) {
  46658. l = m + 1;
  46659. } else {
  46660. kidsOrEntries = xref.fetchIfRef(kids[m]);
  46661. break;
  46662. }
  46663. }
  46664. if (l > r) {
  46665. return null;
  46666. }
  46667. }
  46668. // If we get here, then we have found the right entry. Now go through the
  46669. // entries in the dictionary until we find the key we're looking for.
  46670. var entries = kidsOrEntries.get(this._type);
  46671. if (isArray(entries)) {
  46672. // Perform a binary search to reduce the lookup time.
  46673. l = 0;
  46674. r = entries.length - 2;
  46675. while (l <= r) {
  46676. // Check only even indices (0, 2, 4, ...) because the
  46677. // odd indices contain the actual data.
  46678. m = l + r & ~1;
  46679. var currentKey = xref.fetchIfRef(entries[m]);
  46680. if (key < currentKey) {
  46681. r = m - 2;
  46682. } else if (key > currentKey) {
  46683. l = m + 2;
  46684. } else {
  46685. return xref.fetchIfRef(entries[m + 1]);
  46686. }
  46687. }
  46688. }
  46689. return null;
  46690. }
  46691. };
  46692. return NameOrNumberTree;
  46693. }();
  46694. var NameTree = function NameTreeClosure() {
  46695. function NameTree(root, xref) {
  46696. this.root = root;
  46697. this.xref = xref;
  46698. this._type = 'Names';
  46699. }
  46700. Util.inherit(NameTree, NameOrNumberTree, {});
  46701. return NameTree;
  46702. }();
  46703. var NumberTree = function NumberTreeClosure() {
  46704. function NumberTree(root, xref) {
  46705. this.root = root;
  46706. this.xref = xref;
  46707. this._type = 'Nums';
  46708. }
  46709. Util.inherit(NumberTree, NameOrNumberTree, {});
  46710. return NumberTree;
  46711. }();
  46712. /**
  46713. * "A PDF file can refer to the contents of another file by using a File
  46714. * Specification (PDF 1.1)", see the spec (7.11) for more details.
  46715. * NOTE: Only embedded files are supported (as part of the attachments support)
  46716. * TODO: support the 'URL' file system (with caching if !/V), portable
  46717. * collections attributes and related files (/RF)
  46718. */
  46719. var FileSpec = function FileSpecClosure() {
  46720. function FileSpec(root, xref) {
  46721. if (!root || !isDict(root)) {
  46722. return;
  46723. }
  46724. this.xref = xref;
  46725. this.root = root;
  46726. if (root.has('FS')) {
  46727. this.fs = root.get('FS');
  46728. }
  46729. this.description = root.has('Desc') ? stringToPDFString(root.get('Desc')) : '';
  46730. if (root.has('RF')) {
  46731. warn('Related file specifications are not supported');
  46732. }
  46733. this.contentAvailable = true;
  46734. if (!root.has('EF')) {
  46735. this.contentAvailable = false;
  46736. warn('Non-embedded file specifications are not supported');
  46737. }
  46738. }
  46739. function pickPlatformItem(dict) {
  46740. // Look for the filename in this order:
  46741. // UF, F, Unix, Mac, DOS
  46742. if (dict.has('UF')) {
  46743. return dict.get('UF');
  46744. } else if (dict.has('F')) {
  46745. return dict.get('F');
  46746. } else if (dict.has('Unix')) {
  46747. return dict.get('Unix');
  46748. } else if (dict.has('Mac')) {
  46749. return dict.get('Mac');
  46750. } else if (dict.has('DOS')) {
  46751. return dict.get('DOS');
  46752. } else {
  46753. return null;
  46754. }
  46755. }
  46756. FileSpec.prototype = {
  46757. get filename() {
  46758. if (!this._filename && this.root) {
  46759. var filename = pickPlatformItem(this.root) || 'unnamed';
  46760. this._filename = stringToPDFString(filename).replace(/\\\\/g, '\\').replace(/\\\//g, '/').replace(/\\/g, '/');
  46761. }
  46762. return this._filename;
  46763. },
  46764. get content() {
  46765. if (!this.contentAvailable) {
  46766. return null;
  46767. }
  46768. if (!this.contentRef && this.root) {
  46769. this.contentRef = pickPlatformItem(this.root.get('EF'));
  46770. }
  46771. var content = null;
  46772. if (this.contentRef) {
  46773. var xref = this.xref;
  46774. var fileObj = xref.fetchIfRef(this.contentRef);
  46775. if (fileObj && isStream(fileObj)) {
  46776. content = fileObj.getBytes();
  46777. } else {
  46778. warn('Embedded file specification points to non-existing/invalid ' + 'content');
  46779. }
  46780. } else {
  46781. warn('Embedded file specification does not have a content');
  46782. }
  46783. return content;
  46784. },
  46785. get serializable() {
  46786. return {
  46787. filename: this.filename,
  46788. content: this.content
  46789. };
  46790. }
  46791. };
  46792. return FileSpec;
  46793. }();
  46794. /**
  46795. * A helper for loading missing data in object graphs. It traverses the graph
  46796. * depth first and queues up any objects that have missing data. Once it has
  46797. * has traversed as many objects that are available it attempts to bundle the
  46798. * missing data requests and then resume from the nodes that weren't ready.
  46799. *
  46800. * NOTE: It provides protection from circular references by keeping track of
  46801. * of loaded references. However, you must be careful not to load any graphs
  46802. * that have references to the catalog or other pages since that will cause the
  46803. * entire PDF document object graph to be traversed.
  46804. */
  46805. var ObjectLoader = function () {
  46806. function mayHaveChildren(value) {
  46807. return isRef(value) || isDict(value) || isArray(value) || isStream(value);
  46808. }
  46809. function addChildren(node, nodesToVisit) {
  46810. var value;
  46811. if (isDict(node) || isStream(node)) {
  46812. var map;
  46813. if (isDict(node)) {
  46814. map = node.map;
  46815. } else {
  46816. map = node.dict.map;
  46817. }
  46818. for (var key in map) {
  46819. value = map[key];
  46820. if (mayHaveChildren(value)) {
  46821. nodesToVisit.push(value);
  46822. }
  46823. }
  46824. } else if (isArray(node)) {
  46825. for (var i = 0, ii = node.length; i < ii; i++) {
  46826. value = node[i];
  46827. if (mayHaveChildren(value)) {
  46828. nodesToVisit.push(value);
  46829. }
  46830. }
  46831. }
  46832. }
  46833. function ObjectLoader(obj, keys, xref) {
  46834. this.obj = obj;
  46835. this.keys = keys;
  46836. this.xref = xref;
  46837. this.refSet = null;
  46838. this.capability = null;
  46839. }
  46840. ObjectLoader.prototype = {
  46841. load: function ObjectLoader_load() {
  46842. var keys = this.keys;
  46843. this.capability = createPromiseCapability();
  46844. // Don't walk the graph if all the data is already loaded.
  46845. if (!(this.xref.stream instanceof ChunkedStream) || this.xref.stream.getMissingChunks().length === 0) {
  46846. this.capability.resolve();
  46847. return this.capability.promise;
  46848. }
  46849. this.refSet = new RefSet();
  46850. // Setup the initial nodes to visit.
  46851. var nodesToVisit = [];
  46852. for (var i = 0; i < keys.length; i++) {
  46853. nodesToVisit.push(this.obj[keys[i]]);
  46854. }
  46855. this._walk(nodesToVisit);
  46856. return this.capability.promise;
  46857. },
  46858. _walk: function ObjectLoader_walk(nodesToVisit) {
  46859. var nodesToRevisit = [];
  46860. var pendingRequests = [];
  46861. // DFS walk of the object graph.
  46862. while (nodesToVisit.length) {
  46863. var currentNode = nodesToVisit.pop();
  46864. // Only references or chunked streams can cause missing data exceptions.
  46865. if (isRef(currentNode)) {
  46866. // Skip nodes that have already been visited.
  46867. if (this.refSet.has(currentNode)) {
  46868. continue;
  46869. }
  46870. try {
  46871. var ref = currentNode;
  46872. this.refSet.put(ref);
  46873. currentNode = this.xref.fetch(currentNode);
  46874. } catch (e) {
  46875. if (!(e instanceof MissingDataException)) {
  46876. throw e;
  46877. }
  46878. nodesToRevisit.push(currentNode);
  46879. pendingRequests.push({
  46880. begin: e.begin,
  46881. end: e.end
  46882. });
  46883. }
  46884. }
  46885. if (currentNode && currentNode.getBaseStreams) {
  46886. var baseStreams = currentNode.getBaseStreams();
  46887. var foundMissingData = false;
  46888. for (var i = 0; i < baseStreams.length; i++) {
  46889. var stream = baseStreams[i];
  46890. if (stream.getMissingChunks && stream.getMissingChunks().length) {
  46891. foundMissingData = true;
  46892. pendingRequests.push({
  46893. begin: stream.start,
  46894. end: stream.end
  46895. });
  46896. }
  46897. }
  46898. if (foundMissingData) {
  46899. nodesToRevisit.push(currentNode);
  46900. }
  46901. }
  46902. addChildren(currentNode, nodesToVisit);
  46903. }
  46904. if (pendingRequests.length) {
  46905. this.xref.stream.manager.requestRanges(pendingRequests).then(function pendingRequestCallback() {
  46906. nodesToVisit = nodesToRevisit;
  46907. for (var i = 0; i < nodesToRevisit.length; i++) {
  46908. var node = nodesToRevisit[i];
  46909. // Remove any reference nodes from the currrent refset so they
  46910. // aren't skipped when we revist them.
  46911. if (isRef(node)) {
  46912. this.refSet.remove(node);
  46913. }
  46914. }
  46915. this._walk(nodesToVisit);
  46916. }.bind(this), this.capability.reject);
  46917. return;
  46918. }
  46919. // Everything is loaded.
  46920. this.refSet = null;
  46921. this.capability.resolve();
  46922. }
  46923. };
  46924. return ObjectLoader;
  46925. }();
  46926. exports.Catalog = Catalog;
  46927. exports.ObjectLoader = ObjectLoader;
  46928. exports.XRef = XRef;
  46929. exports.FileSpec = FileSpec;
  46930. }));
  46931. (function (root, factory) {
  46932. factory(root.pdfjsCorePattern = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCoreFunction, root.pdfjsCoreColorSpace);
  46933. }(this, function (exports, sharedUtil, corePrimitives, coreFunction, coreColorSpace) {
  46934. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  46935. var MissingDataException = sharedUtil.MissingDataException;
  46936. var Util = sharedUtil.Util;
  46937. var assert = sharedUtil.assert;
  46938. var error = sharedUtil.error;
  46939. var info = sharedUtil.info;
  46940. var warn = sharedUtil.warn;
  46941. var isStream = corePrimitives.isStream;
  46942. var PDFFunction = coreFunction.PDFFunction;
  46943. var ColorSpace = coreColorSpace.ColorSpace;
  46944. var ShadingType = {
  46945. FUNCTION_BASED: 1,
  46946. AXIAL: 2,
  46947. RADIAL: 3,
  46948. FREE_FORM_MESH: 4,
  46949. LATTICE_FORM_MESH: 5,
  46950. COONS_PATCH_MESH: 6,
  46951. TENSOR_PATCH_MESH: 7
  46952. };
  46953. var Pattern = function PatternClosure() {
  46954. // Constructor should define this.getPattern
  46955. function Pattern() {
  46956. error('should not call Pattern constructor');
  46957. }
  46958. Pattern.prototype = {
  46959. // Input: current Canvas context
  46960. // Output: the appropriate fillStyle or strokeStyle
  46961. getPattern: function Pattern_getPattern(ctx) {
  46962. error('Should not call Pattern.getStyle: ' + ctx);
  46963. }
  46964. };
  46965. Pattern.parseShading = function Pattern_parseShading(shading, matrix, xref, res, handler) {
  46966. var dict = isStream(shading) ? shading.dict : shading;
  46967. var type = dict.get('ShadingType');
  46968. try {
  46969. switch (type) {
  46970. case ShadingType.AXIAL:
  46971. case ShadingType.RADIAL:
  46972. // Both radial and axial shadings are handled by RadialAxial shading.
  46973. return new Shadings.RadialAxial(dict, matrix, xref, res);
  46974. case ShadingType.FREE_FORM_MESH:
  46975. case ShadingType.LATTICE_FORM_MESH:
  46976. case ShadingType.COONS_PATCH_MESH:
  46977. case ShadingType.TENSOR_PATCH_MESH:
  46978. return new Shadings.Mesh(shading, matrix, xref, res);
  46979. default:
  46980. throw new Error('Unsupported ShadingType: ' + type);
  46981. }
  46982. } catch (ex) {
  46983. if (ex instanceof MissingDataException) {
  46984. throw ex;
  46985. }
  46986. handler.send('UnsupportedFeature', { featureId: UNSUPPORTED_FEATURES.shadingPattern });
  46987. warn(ex);
  46988. return new Shadings.Dummy();
  46989. }
  46990. };
  46991. return Pattern;
  46992. }();
  46993. var Shadings = {};
  46994. // A small number to offset the first/last color stops so we can insert ones to
  46995. // support extend. Number.MIN_VALUE is too small and breaks the extend.
  46996. Shadings.SMALL_NUMBER = 1e-6;
  46997. // Radial and axial shading have very similar implementations
  46998. // If needed, the implementations can be broken into two classes
  46999. Shadings.RadialAxial = function RadialAxialClosure() {
  47000. function RadialAxial(dict, matrix, xref, res) {
  47001. this.matrix = matrix;
  47002. this.coordsArr = dict.getArray('Coords');
  47003. this.shadingType = dict.get('ShadingType');
  47004. this.type = 'Pattern';
  47005. var cs = dict.get('ColorSpace', 'CS');
  47006. cs = ColorSpace.parse(cs, xref, res);
  47007. this.cs = cs;
  47008. var t0 = 0.0, t1 = 1.0;
  47009. if (dict.has('Domain')) {
  47010. var domainArr = dict.getArray('Domain');
  47011. t0 = domainArr[0];
  47012. t1 = domainArr[1];
  47013. }
  47014. var extendStart = false, extendEnd = false;
  47015. if (dict.has('Extend')) {
  47016. var extendArr = dict.getArray('Extend');
  47017. extendStart = extendArr[0];
  47018. extendEnd = extendArr[1];
  47019. }
  47020. if (this.shadingType === ShadingType.RADIAL && (!extendStart || !extendEnd)) {
  47021. // Radial gradient only currently works if either circle is fully within
  47022. // the other circle.
  47023. var x1 = this.coordsArr[0];
  47024. var y1 = this.coordsArr[1];
  47025. var r1 = this.coordsArr[2];
  47026. var x2 = this.coordsArr[3];
  47027. var y2 = this.coordsArr[4];
  47028. var r2 = this.coordsArr[5];
  47029. var distance = Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
  47030. if (r1 <= r2 + distance && r2 <= r1 + distance) {
  47031. warn('Unsupported radial gradient.');
  47032. }
  47033. }
  47034. this.extendStart = extendStart;
  47035. this.extendEnd = extendEnd;
  47036. var fnObj = dict.get('Function');
  47037. var fn = PDFFunction.parseArray(xref, fnObj);
  47038. // 10 samples seems good enough for now, but probably won't work
  47039. // if there are sharp color changes. Ideally, we would implement
  47040. // the spec faithfully and add lossless optimizations.
  47041. var diff = t1 - t0;
  47042. var step = diff / 10;
  47043. var colorStops = this.colorStops = [];
  47044. // Protect against bad domains so we don't end up in an infinte loop below.
  47045. if (t0 >= t1 || step <= 0) {
  47046. // Acrobat doesn't seem to handle these cases so we'll ignore for
  47047. // now.
  47048. info('Bad shading domain.');
  47049. return;
  47050. }
  47051. var color = new Float32Array(cs.numComps), ratio = new Float32Array(1);
  47052. var rgbColor;
  47053. for (var i = t0; i <= t1; i += step) {
  47054. ratio[0] = i;
  47055. fn(ratio, 0, color, 0);
  47056. rgbColor = cs.getRgb(color, 0);
  47057. var cssColor = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  47058. colorStops.push([
  47059. (i - t0) / diff,
  47060. cssColor
  47061. ]);
  47062. }
  47063. var background = 'transparent';
  47064. if (dict.has('Background')) {
  47065. rgbColor = cs.getRgb(dict.get('Background'), 0);
  47066. background = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  47067. }
  47068. if (!extendStart) {
  47069. // Insert a color stop at the front and offset the first real color stop
  47070. // so it doesn't conflict with the one we insert.
  47071. colorStops.unshift([
  47072. 0,
  47073. background
  47074. ]);
  47075. colorStops[1][0] += Shadings.SMALL_NUMBER;
  47076. }
  47077. if (!extendEnd) {
  47078. // Same idea as above in extendStart but for the end.
  47079. colorStops[colorStops.length - 1][0] -= Shadings.SMALL_NUMBER;
  47080. colorStops.push([
  47081. 1,
  47082. background
  47083. ]);
  47084. }
  47085. this.colorStops = colorStops;
  47086. }
  47087. RadialAxial.prototype = {
  47088. getIR: function RadialAxial_getIR() {
  47089. var coordsArr = this.coordsArr;
  47090. var shadingType = this.shadingType;
  47091. var type, p0, p1, r0, r1;
  47092. if (shadingType === ShadingType.AXIAL) {
  47093. p0 = [
  47094. coordsArr[0],
  47095. coordsArr[1]
  47096. ];
  47097. p1 = [
  47098. coordsArr[2],
  47099. coordsArr[3]
  47100. ];
  47101. r0 = null;
  47102. r1 = null;
  47103. type = 'axial';
  47104. } else if (shadingType === ShadingType.RADIAL) {
  47105. p0 = [
  47106. coordsArr[0],
  47107. coordsArr[1]
  47108. ];
  47109. p1 = [
  47110. coordsArr[3],
  47111. coordsArr[4]
  47112. ];
  47113. r0 = coordsArr[2];
  47114. r1 = coordsArr[5];
  47115. type = 'radial';
  47116. } else {
  47117. error('getPattern type unknown: ' + shadingType);
  47118. }
  47119. var matrix = this.matrix;
  47120. if (matrix) {
  47121. p0 = Util.applyTransform(p0, matrix);
  47122. p1 = Util.applyTransform(p1, matrix);
  47123. if (shadingType === ShadingType.RADIAL) {
  47124. var scale = Util.singularValueDecompose2dScale(matrix);
  47125. r0 *= scale[0];
  47126. r1 *= scale[1];
  47127. }
  47128. }
  47129. return [
  47130. 'RadialAxial',
  47131. type,
  47132. this.colorStops,
  47133. p0,
  47134. p1,
  47135. r0,
  47136. r1
  47137. ];
  47138. }
  47139. };
  47140. return RadialAxial;
  47141. }();
  47142. // All mesh shading. For now, they will be presented as set of the triangles
  47143. // to be drawn on the canvas and rgb color for each vertex.
  47144. Shadings.Mesh = function MeshClosure() {
  47145. function MeshStreamReader(stream, context) {
  47146. this.stream = stream;
  47147. this.context = context;
  47148. this.buffer = 0;
  47149. this.bufferLength = 0;
  47150. var numComps = context.numComps;
  47151. this.tmpCompsBuf = new Float32Array(numComps);
  47152. var csNumComps = context.colorSpace.numComps;
  47153. this.tmpCsCompsBuf = context.colorFn ? new Float32Array(csNumComps) : this.tmpCompsBuf;
  47154. }
  47155. MeshStreamReader.prototype = {
  47156. get hasData() {
  47157. if (this.stream.end) {
  47158. return this.stream.pos < this.stream.end;
  47159. }
  47160. if (this.bufferLength > 0) {
  47161. return true;
  47162. }
  47163. var nextByte = this.stream.getByte();
  47164. if (nextByte < 0) {
  47165. return false;
  47166. }
  47167. this.buffer = nextByte;
  47168. this.bufferLength = 8;
  47169. return true;
  47170. },
  47171. readBits: function MeshStreamReader_readBits(n) {
  47172. var buffer = this.buffer;
  47173. var bufferLength = this.bufferLength;
  47174. if (n === 32) {
  47175. if (bufferLength === 0) {
  47176. return (this.stream.getByte() << 24 | this.stream.getByte() << 16 | this.stream.getByte() << 8 | this.stream.getByte()) >>> 0;
  47177. }
  47178. buffer = buffer << 24 | this.stream.getByte() << 16 | this.stream.getByte() << 8 | this.stream.getByte();
  47179. var nextByte = this.stream.getByte();
  47180. this.buffer = nextByte & (1 << bufferLength) - 1;
  47181. return (buffer << 8 - bufferLength | (nextByte & 0xFF) >> bufferLength) >>> 0;
  47182. }
  47183. if (n === 8 && bufferLength === 0) {
  47184. return this.stream.getByte();
  47185. }
  47186. while (bufferLength < n) {
  47187. buffer = buffer << 8 | this.stream.getByte();
  47188. bufferLength += 8;
  47189. }
  47190. bufferLength -= n;
  47191. this.bufferLength = bufferLength;
  47192. this.buffer = buffer & (1 << bufferLength) - 1;
  47193. return buffer >> bufferLength;
  47194. },
  47195. align: function MeshStreamReader_align() {
  47196. this.buffer = 0;
  47197. this.bufferLength = 0;
  47198. },
  47199. readFlag: function MeshStreamReader_readFlag() {
  47200. return this.readBits(this.context.bitsPerFlag);
  47201. },
  47202. readCoordinate: function MeshStreamReader_readCoordinate() {
  47203. var bitsPerCoordinate = this.context.bitsPerCoordinate;
  47204. var xi = this.readBits(bitsPerCoordinate);
  47205. var yi = this.readBits(bitsPerCoordinate);
  47206. var decode = this.context.decode;
  47207. var scale = bitsPerCoordinate < 32 ? 1 / ((1 << bitsPerCoordinate) - 1) : 2.3283064365386963e-10;
  47208. // 2 ^ -32
  47209. return [
  47210. xi * scale * (decode[1] - decode[0]) + decode[0],
  47211. yi * scale * (decode[3] - decode[2]) + decode[2]
  47212. ];
  47213. },
  47214. readComponents: function MeshStreamReader_readComponents() {
  47215. var numComps = this.context.numComps;
  47216. var bitsPerComponent = this.context.bitsPerComponent;
  47217. var scale = bitsPerComponent < 32 ? 1 / ((1 << bitsPerComponent) - 1) : 2.3283064365386963e-10;
  47218. // 2 ^ -32
  47219. var decode = this.context.decode;
  47220. var components = this.tmpCompsBuf;
  47221. for (var i = 0, j = 4; i < numComps; i++, j += 2) {
  47222. var ci = this.readBits(bitsPerComponent);
  47223. components[i] = ci * scale * (decode[j + 1] - decode[j]) + decode[j];
  47224. }
  47225. var color = this.tmpCsCompsBuf;
  47226. if (this.context.colorFn) {
  47227. this.context.colorFn(components, 0, color, 0);
  47228. }
  47229. return this.context.colorSpace.getRgb(color, 0);
  47230. }
  47231. };
  47232. function decodeType4Shading(mesh, reader) {
  47233. var coords = mesh.coords;
  47234. var colors = mesh.colors;
  47235. var operators = [];
  47236. var ps = [];
  47237. // not maintaining cs since that will match ps
  47238. var verticesLeft = 0;
  47239. // assuming we have all data to start a new triangle
  47240. while (reader.hasData) {
  47241. var f = reader.readFlag();
  47242. var coord = reader.readCoordinate();
  47243. var color = reader.readComponents();
  47244. if (verticesLeft === 0) {
  47245. // ignoring flags if we started a triangle
  47246. assert(0 <= f && f <= 2, 'Unknown type4 flag');
  47247. switch (f) {
  47248. case 0:
  47249. verticesLeft = 3;
  47250. break;
  47251. case 1:
  47252. ps.push(ps[ps.length - 2], ps[ps.length - 1]);
  47253. verticesLeft = 1;
  47254. break;
  47255. case 2:
  47256. ps.push(ps[ps.length - 3], ps[ps.length - 1]);
  47257. verticesLeft = 1;
  47258. break;
  47259. }
  47260. operators.push(f);
  47261. }
  47262. ps.push(coords.length);
  47263. coords.push(coord);
  47264. colors.push(color);
  47265. verticesLeft--;
  47266. reader.align();
  47267. }
  47268. mesh.figures.push({
  47269. type: 'triangles',
  47270. coords: new Int32Array(ps),
  47271. colors: new Int32Array(ps)
  47272. });
  47273. }
  47274. function decodeType5Shading(mesh, reader, verticesPerRow) {
  47275. var coords = mesh.coords;
  47276. var colors = mesh.colors;
  47277. var ps = [];
  47278. // not maintaining cs since that will match ps
  47279. while (reader.hasData) {
  47280. var coord = reader.readCoordinate();
  47281. var color = reader.readComponents();
  47282. ps.push(coords.length);
  47283. coords.push(coord);
  47284. colors.push(color);
  47285. }
  47286. mesh.figures.push({
  47287. type: 'lattice',
  47288. coords: new Int32Array(ps),
  47289. colors: new Int32Array(ps),
  47290. verticesPerRow: verticesPerRow
  47291. });
  47292. }
  47293. var MIN_SPLIT_PATCH_CHUNKS_AMOUNT = 3;
  47294. var MAX_SPLIT_PATCH_CHUNKS_AMOUNT = 20;
  47295. var TRIANGLE_DENSITY = 20;
  47296. // count of triangles per entire mesh bounds
  47297. var getB = function getBClosure() {
  47298. function buildB(count) {
  47299. var lut = [];
  47300. for (var i = 0; i <= count; i++) {
  47301. var t = i / count, t_ = 1 - t;
  47302. lut.push(new Float32Array([
  47303. t_ * t_ * t_,
  47304. 3 * t * t_ * t_,
  47305. 3 * t * t * t_,
  47306. t * t * t
  47307. ]));
  47308. }
  47309. return lut;
  47310. }
  47311. var cache = [];
  47312. return function getB(count) {
  47313. if (!cache[count]) {
  47314. cache[count] = buildB(count);
  47315. }
  47316. return cache[count];
  47317. };
  47318. }();
  47319. function buildFigureFromPatch(mesh, index) {
  47320. var figure = mesh.figures[index];
  47321. assert(figure.type === 'patch', 'Unexpected patch mesh figure');
  47322. var coords = mesh.coords, colors = mesh.colors;
  47323. var pi = figure.coords;
  47324. var ci = figure.colors;
  47325. var figureMinX = Math.min(coords[pi[0]][0], coords[pi[3]][0], coords[pi[12]][0], coords[pi[15]][0]);
  47326. var figureMinY = Math.min(coords[pi[0]][1], coords[pi[3]][1], coords[pi[12]][1], coords[pi[15]][1]);
  47327. var figureMaxX = Math.max(coords[pi[0]][0], coords[pi[3]][0], coords[pi[12]][0], coords[pi[15]][0]);
  47328. var figureMaxY = Math.max(coords[pi[0]][1], coords[pi[3]][1], coords[pi[12]][1], coords[pi[15]][1]);
  47329. var splitXBy = Math.ceil((figureMaxX - figureMinX) * TRIANGLE_DENSITY / (mesh.bounds[2] - mesh.bounds[0]));
  47330. splitXBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT, Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitXBy));
  47331. var splitYBy = Math.ceil((figureMaxY - figureMinY) * TRIANGLE_DENSITY / (mesh.bounds[3] - mesh.bounds[1]));
  47332. splitYBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT, Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitYBy));
  47333. var verticesPerRow = splitXBy + 1;
  47334. var figureCoords = new Int32Array((splitYBy + 1) * verticesPerRow);
  47335. var figureColors = new Int32Array((splitYBy + 1) * verticesPerRow);
  47336. var k = 0;
  47337. var cl = new Uint8Array(3), cr = new Uint8Array(3);
  47338. var c0 = colors[ci[0]], c1 = colors[ci[1]], c2 = colors[ci[2]], c3 = colors[ci[3]];
  47339. var bRow = getB(splitYBy), bCol = getB(splitXBy);
  47340. for (var row = 0; row <= splitYBy; row++) {
  47341. cl[0] = (c0[0] * (splitYBy - row) + c2[0] * row) / splitYBy | 0;
  47342. cl[1] = (c0[1] * (splitYBy - row) + c2[1] * row) / splitYBy | 0;
  47343. cl[2] = (c0[2] * (splitYBy - row) + c2[2] * row) / splitYBy | 0;
  47344. cr[0] = (c1[0] * (splitYBy - row) + c3[0] * row) / splitYBy | 0;
  47345. cr[1] = (c1[1] * (splitYBy - row) + c3[1] * row) / splitYBy | 0;
  47346. cr[2] = (c1[2] * (splitYBy - row) + c3[2] * row) / splitYBy | 0;
  47347. for (var col = 0; col <= splitXBy; col++, k++) {
  47348. if ((row === 0 || row === splitYBy) && (col === 0 || col === splitXBy)) {
  47349. continue;
  47350. }
  47351. var x = 0, y = 0;
  47352. var q = 0;
  47353. for (var i = 0; i <= 3; i++) {
  47354. for (var j = 0; j <= 3; j++, q++) {
  47355. var m = bRow[row][i] * bCol[col][j];
  47356. x += coords[pi[q]][0] * m;
  47357. y += coords[pi[q]][1] * m;
  47358. }
  47359. }
  47360. figureCoords[k] = coords.length;
  47361. coords.push([
  47362. x,
  47363. y
  47364. ]);
  47365. figureColors[k] = colors.length;
  47366. var newColor = new Uint8Array(3);
  47367. newColor[0] = (cl[0] * (splitXBy - col) + cr[0] * col) / splitXBy | 0;
  47368. newColor[1] = (cl[1] * (splitXBy - col) + cr[1] * col) / splitXBy | 0;
  47369. newColor[2] = (cl[2] * (splitXBy - col) + cr[2] * col) / splitXBy | 0;
  47370. colors.push(newColor);
  47371. }
  47372. }
  47373. figureCoords[0] = pi[0];
  47374. figureColors[0] = ci[0];
  47375. figureCoords[splitXBy] = pi[3];
  47376. figureColors[splitXBy] = ci[1];
  47377. figureCoords[verticesPerRow * splitYBy] = pi[12];
  47378. figureColors[verticesPerRow * splitYBy] = ci[2];
  47379. figureCoords[verticesPerRow * splitYBy + splitXBy] = pi[15];
  47380. figureColors[verticesPerRow * splitYBy + splitXBy] = ci[3];
  47381. mesh.figures[index] = {
  47382. type: 'lattice',
  47383. coords: figureCoords,
  47384. colors: figureColors,
  47385. verticesPerRow: verticesPerRow
  47386. };
  47387. }
  47388. function decodeType6Shading(mesh, reader) {
  47389. // A special case of Type 7. The p11, p12, p21, p22 automatically filled
  47390. var coords = mesh.coords;
  47391. var colors = mesh.colors;
  47392. var ps = new Int32Array(16);
  47393. // p00, p10, ..., p30, p01, ..., p33
  47394. var cs = new Int32Array(4);
  47395. // c00, c30, c03, c33
  47396. while (reader.hasData) {
  47397. var f = reader.readFlag();
  47398. assert(0 <= f && f <= 3, 'Unknown type6 flag');
  47399. var i, ii;
  47400. var pi = coords.length;
  47401. for (i = 0, ii = f !== 0 ? 8 : 12; i < ii; i++) {
  47402. coords.push(reader.readCoordinate());
  47403. }
  47404. var ci = colors.length;
  47405. for (i = 0, ii = f !== 0 ? 2 : 4; i < ii; i++) {
  47406. colors.push(reader.readComponents());
  47407. }
  47408. var tmp1, tmp2, tmp3, tmp4;
  47409. switch (f) {
  47410. case 0:
  47411. ps[12] = pi + 3;
  47412. ps[13] = pi + 4;
  47413. ps[14] = pi + 5;
  47414. ps[15] = pi + 6;
  47415. ps[8] = pi + 2;
  47416. /* values for 5, 6, 9, 10 are */
  47417. ps[11] = pi + 7;
  47418. ps[4] = pi + 1;
  47419. /* calculated below */
  47420. ps[7] = pi + 8;
  47421. ps[0] = pi;
  47422. ps[1] = pi + 11;
  47423. ps[2] = pi + 10;
  47424. ps[3] = pi + 9;
  47425. cs[2] = ci + 1;
  47426. cs[3] = ci + 2;
  47427. cs[0] = ci;
  47428. cs[1] = ci + 3;
  47429. break;
  47430. case 1:
  47431. tmp1 = ps[12];
  47432. tmp2 = ps[13];
  47433. tmp3 = ps[14];
  47434. tmp4 = ps[15];
  47435. ps[12] = tmp4;
  47436. ps[13] = pi + 0;
  47437. ps[14] = pi + 1;
  47438. ps[15] = pi + 2;
  47439. ps[8] = tmp3;
  47440. /* values for 5, 6, 9, 10 are */
  47441. ps[11] = pi + 3;
  47442. ps[4] = tmp2;
  47443. /* calculated below */
  47444. ps[7] = pi + 4;
  47445. ps[0] = tmp1;
  47446. ps[1] = pi + 7;
  47447. ps[2] = pi + 6;
  47448. ps[3] = pi + 5;
  47449. tmp1 = cs[2];
  47450. tmp2 = cs[3];
  47451. cs[2] = tmp2;
  47452. cs[3] = ci;
  47453. cs[0] = tmp1;
  47454. cs[1] = ci + 1;
  47455. break;
  47456. case 2:
  47457. tmp1 = ps[15];
  47458. tmp2 = ps[11];
  47459. ps[12] = ps[3];
  47460. ps[13] = pi + 0;
  47461. ps[14] = pi + 1;
  47462. ps[15] = pi + 2;
  47463. ps[8] = ps[7];
  47464. /* values for 5, 6, 9, 10 are */
  47465. ps[11] = pi + 3;
  47466. ps[4] = tmp2;
  47467. /* calculated below */
  47468. ps[7] = pi + 4;
  47469. ps[0] = tmp1;
  47470. ps[1] = pi + 7;
  47471. ps[2] = pi + 6;
  47472. ps[3] = pi + 5;
  47473. tmp1 = cs[3];
  47474. cs[2] = cs[1];
  47475. cs[3] = ci;
  47476. cs[0] = tmp1;
  47477. cs[1] = ci + 1;
  47478. break;
  47479. case 3:
  47480. ps[12] = ps[0];
  47481. ps[13] = pi + 0;
  47482. ps[14] = pi + 1;
  47483. ps[15] = pi + 2;
  47484. ps[8] = ps[1];
  47485. /* values for 5, 6, 9, 10 are */
  47486. ps[11] = pi + 3;
  47487. ps[4] = ps[2];
  47488. /* calculated below */
  47489. ps[7] = pi + 4;
  47490. ps[0] = ps[3];
  47491. ps[1] = pi + 7;
  47492. ps[2] = pi + 6;
  47493. ps[3] = pi + 5;
  47494. cs[2] = cs[0];
  47495. cs[3] = ci;
  47496. cs[0] = cs[1];
  47497. cs[1] = ci + 1;
  47498. break;
  47499. }
  47500. // set p11, p12, p21, p22
  47501. ps[5] = coords.length;
  47502. coords.push([
  47503. (-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,
  47504. (-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
  47505. ]);
  47506. ps[6] = coords.length;
  47507. coords.push([
  47508. (-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,
  47509. (-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
  47510. ]);
  47511. ps[9] = coords.length;
  47512. coords.push([
  47513. (-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,
  47514. (-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
  47515. ]);
  47516. ps[10] = coords.length;
  47517. coords.push([
  47518. (-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,
  47519. (-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
  47520. ]);
  47521. mesh.figures.push({
  47522. type: 'patch',
  47523. coords: new Int32Array(ps),
  47524. // making copies of ps and cs
  47525. colors: new Int32Array(cs)
  47526. });
  47527. }
  47528. }
  47529. function decodeType7Shading(mesh, reader) {
  47530. var coords = mesh.coords;
  47531. var colors = mesh.colors;
  47532. var ps = new Int32Array(16);
  47533. // p00, p10, ..., p30, p01, ..., p33
  47534. var cs = new Int32Array(4);
  47535. // c00, c30, c03, c33
  47536. while (reader.hasData) {
  47537. var f = reader.readFlag();
  47538. assert(0 <= f && f <= 3, 'Unknown type7 flag');
  47539. var i, ii;
  47540. var pi = coords.length;
  47541. for (i = 0, ii = f !== 0 ? 12 : 16; i < ii; i++) {
  47542. coords.push(reader.readCoordinate());
  47543. }
  47544. var ci = colors.length;
  47545. for (i = 0, ii = f !== 0 ? 2 : 4; i < ii; i++) {
  47546. colors.push(reader.readComponents());
  47547. }
  47548. var tmp1, tmp2, tmp3, tmp4;
  47549. switch (f) {
  47550. case 0:
  47551. ps[12] = pi + 3;
  47552. ps[13] = pi + 4;
  47553. ps[14] = pi + 5;
  47554. ps[15] = pi + 6;
  47555. ps[8] = pi + 2;
  47556. ps[9] = pi + 13;
  47557. ps[10] = pi + 14;
  47558. ps[11] = pi + 7;
  47559. ps[4] = pi + 1;
  47560. ps[5] = pi + 12;
  47561. ps[6] = pi + 15;
  47562. ps[7] = pi + 8;
  47563. ps[0] = pi;
  47564. ps[1] = pi + 11;
  47565. ps[2] = pi + 10;
  47566. ps[3] = pi + 9;
  47567. cs[2] = ci + 1;
  47568. cs[3] = ci + 2;
  47569. cs[0] = ci;
  47570. cs[1] = ci + 3;
  47571. break;
  47572. case 1:
  47573. tmp1 = ps[12];
  47574. tmp2 = ps[13];
  47575. tmp3 = ps[14];
  47576. tmp4 = ps[15];
  47577. ps[12] = tmp4;
  47578. ps[13] = pi + 0;
  47579. ps[14] = pi + 1;
  47580. ps[15] = pi + 2;
  47581. ps[8] = tmp3;
  47582. ps[9] = pi + 9;
  47583. ps[10] = pi + 10;
  47584. ps[11] = pi + 3;
  47585. ps[4] = tmp2;
  47586. ps[5] = pi + 8;
  47587. ps[6] = pi + 11;
  47588. ps[7] = pi + 4;
  47589. ps[0] = tmp1;
  47590. ps[1] = pi + 7;
  47591. ps[2] = pi + 6;
  47592. ps[3] = pi + 5;
  47593. tmp1 = cs[2];
  47594. tmp2 = cs[3];
  47595. cs[2] = tmp2;
  47596. cs[3] = ci;
  47597. cs[0] = tmp1;
  47598. cs[1] = ci + 1;
  47599. break;
  47600. case 2:
  47601. tmp1 = ps[15];
  47602. tmp2 = ps[11];
  47603. ps[12] = ps[3];
  47604. ps[13] = pi + 0;
  47605. ps[14] = pi + 1;
  47606. ps[15] = pi + 2;
  47607. ps[8] = ps[7];
  47608. ps[9] = pi + 9;
  47609. ps[10] = pi + 10;
  47610. ps[11] = pi + 3;
  47611. ps[4] = tmp2;
  47612. ps[5] = pi + 8;
  47613. ps[6] = pi + 11;
  47614. ps[7] = pi + 4;
  47615. ps[0] = tmp1;
  47616. ps[1] = pi + 7;
  47617. ps[2] = pi + 6;
  47618. ps[3] = pi + 5;
  47619. tmp1 = cs[3];
  47620. cs[2] = cs[1];
  47621. cs[3] = ci;
  47622. cs[0] = tmp1;
  47623. cs[1] = ci + 1;
  47624. break;
  47625. case 3:
  47626. ps[12] = ps[0];
  47627. ps[13] = pi + 0;
  47628. ps[14] = pi + 1;
  47629. ps[15] = pi + 2;
  47630. ps[8] = ps[1];
  47631. ps[9] = pi + 9;
  47632. ps[10] = pi + 10;
  47633. ps[11] = pi + 3;
  47634. ps[4] = ps[2];
  47635. ps[5] = pi + 8;
  47636. ps[6] = pi + 11;
  47637. ps[7] = pi + 4;
  47638. ps[0] = ps[3];
  47639. ps[1] = pi + 7;
  47640. ps[2] = pi + 6;
  47641. ps[3] = pi + 5;
  47642. cs[2] = cs[0];
  47643. cs[3] = ci;
  47644. cs[0] = cs[1];
  47645. cs[1] = ci + 1;
  47646. break;
  47647. }
  47648. mesh.figures.push({
  47649. type: 'patch',
  47650. coords: new Int32Array(ps),
  47651. // making copies of ps and cs
  47652. colors: new Int32Array(cs)
  47653. });
  47654. }
  47655. }
  47656. function updateBounds(mesh) {
  47657. var minX = mesh.coords[0][0], minY = mesh.coords[0][1], maxX = minX, maxY = minY;
  47658. for (var i = 1, ii = mesh.coords.length; i < ii; i++) {
  47659. var x = mesh.coords[i][0], y = mesh.coords[i][1];
  47660. minX = minX > x ? x : minX;
  47661. minY = minY > y ? y : minY;
  47662. maxX = maxX < x ? x : maxX;
  47663. maxY = maxY < y ? y : maxY;
  47664. }
  47665. mesh.bounds = [
  47666. minX,
  47667. minY,
  47668. maxX,
  47669. maxY
  47670. ];
  47671. }
  47672. function packData(mesh) {
  47673. var i, ii, j, jj;
  47674. var coords = mesh.coords;
  47675. var coordsPacked = new Float32Array(coords.length * 2);
  47676. for (i = 0, j = 0, ii = coords.length; i < ii; i++) {
  47677. var xy = coords[i];
  47678. coordsPacked[j++] = xy[0];
  47679. coordsPacked[j++] = xy[1];
  47680. }
  47681. mesh.coords = coordsPacked;
  47682. var colors = mesh.colors;
  47683. var colorsPacked = new Uint8Array(colors.length * 3);
  47684. for (i = 0, j = 0, ii = colors.length; i < ii; i++) {
  47685. var c = colors[i];
  47686. colorsPacked[j++] = c[0];
  47687. colorsPacked[j++] = c[1];
  47688. colorsPacked[j++] = c[2];
  47689. }
  47690. mesh.colors = colorsPacked;
  47691. var figures = mesh.figures;
  47692. for (i = 0, ii = figures.length; i < ii; i++) {
  47693. var figure = figures[i], ps = figure.coords, cs = figure.colors;
  47694. for (j = 0, jj = ps.length; j < jj; j++) {
  47695. ps[j] *= 2;
  47696. cs[j] *= 3;
  47697. }
  47698. }
  47699. }
  47700. function Mesh(stream, matrix, xref, res) {
  47701. assert(isStream(stream), 'Mesh data is not a stream');
  47702. var dict = stream.dict;
  47703. this.matrix = matrix;
  47704. this.shadingType = dict.get('ShadingType');
  47705. this.type = 'Pattern';
  47706. this.bbox = dict.getArray('BBox');
  47707. var cs = dict.get('ColorSpace', 'CS');
  47708. cs = ColorSpace.parse(cs, xref, res);
  47709. this.cs = cs;
  47710. this.background = dict.has('Background') ? cs.getRgb(dict.get('Background'), 0) : null;
  47711. var fnObj = dict.get('Function');
  47712. var fn = fnObj ? PDFFunction.parseArray(xref, fnObj) : null;
  47713. this.coords = [];
  47714. this.colors = [];
  47715. this.figures = [];
  47716. var decodeContext = {
  47717. bitsPerCoordinate: dict.get('BitsPerCoordinate'),
  47718. bitsPerComponent: dict.get('BitsPerComponent'),
  47719. bitsPerFlag: dict.get('BitsPerFlag'),
  47720. decode: dict.getArray('Decode'),
  47721. colorFn: fn,
  47722. colorSpace: cs,
  47723. numComps: fn ? 1 : cs.numComps
  47724. };
  47725. var reader = new MeshStreamReader(stream, decodeContext);
  47726. var patchMesh = false;
  47727. switch (this.shadingType) {
  47728. case ShadingType.FREE_FORM_MESH:
  47729. decodeType4Shading(this, reader);
  47730. break;
  47731. case ShadingType.LATTICE_FORM_MESH:
  47732. var verticesPerRow = dict.get('VerticesPerRow') | 0;
  47733. assert(verticesPerRow >= 2, 'Invalid VerticesPerRow');
  47734. decodeType5Shading(this, reader, verticesPerRow);
  47735. break;
  47736. case ShadingType.COONS_PATCH_MESH:
  47737. decodeType6Shading(this, reader);
  47738. patchMesh = true;
  47739. break;
  47740. case ShadingType.TENSOR_PATCH_MESH:
  47741. decodeType7Shading(this, reader);
  47742. patchMesh = true;
  47743. break;
  47744. default:
  47745. error('Unsupported mesh type.');
  47746. break;
  47747. }
  47748. if (patchMesh) {
  47749. // dirty bounds calculation for determining, how dense shall be triangles
  47750. updateBounds(this);
  47751. for (var i = 0, ii = this.figures.length; i < ii; i++) {
  47752. buildFigureFromPatch(this, i);
  47753. }
  47754. }
  47755. // calculate bounds
  47756. updateBounds(this);
  47757. packData(this);
  47758. }
  47759. Mesh.prototype = {
  47760. getIR: function Mesh_getIR() {
  47761. return [
  47762. 'Mesh',
  47763. this.shadingType,
  47764. this.coords,
  47765. this.colors,
  47766. this.figures,
  47767. this.bounds,
  47768. this.matrix,
  47769. this.bbox,
  47770. this.background
  47771. ];
  47772. }
  47773. };
  47774. return Mesh;
  47775. }();
  47776. Shadings.Dummy = function DummyClosure() {
  47777. function Dummy() {
  47778. this.type = 'Pattern';
  47779. }
  47780. Dummy.prototype = {
  47781. getIR: function Dummy_getIR() {
  47782. return ['Dummy'];
  47783. }
  47784. };
  47785. return Dummy;
  47786. }();
  47787. function getTilingPatternIR(operatorList, dict, args) {
  47788. var matrix = dict.getArray('Matrix');
  47789. var bbox = dict.getArray('BBox');
  47790. var xstep = dict.get('XStep');
  47791. var ystep = dict.get('YStep');
  47792. var paintType = dict.get('PaintType');
  47793. var tilingType = dict.get('TilingType');
  47794. return [
  47795. 'TilingPattern',
  47796. args,
  47797. operatorList,
  47798. matrix,
  47799. bbox,
  47800. xstep,
  47801. ystep,
  47802. paintType,
  47803. tilingType
  47804. ];
  47805. }
  47806. exports.Pattern = Pattern;
  47807. exports.getTilingPatternIR = getTilingPatternIR;
  47808. }));
  47809. (function (root, factory) {
  47810. 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);
  47811. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreParser, coreImage, coreColorSpace, coreMurmurHash3, coreFonts, coreFunction, corePattern, coreCMap, coreMetrics, coreBidi, coreEncodings, coreStandardFonts, coreUnicode, coreGlyphList) {
  47812. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  47813. var IDENTITY_MATRIX = sharedUtil.IDENTITY_MATRIX;
  47814. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  47815. var ImageKind = sharedUtil.ImageKind;
  47816. var OPS = sharedUtil.OPS;
  47817. var TextRenderingMode = sharedUtil.TextRenderingMode;
  47818. var Util = sharedUtil.Util;
  47819. var assert = sharedUtil.assert;
  47820. var createPromiseCapability = sharedUtil.createPromiseCapability;
  47821. var error = sharedUtil.error;
  47822. var info = sharedUtil.info;
  47823. var isArray = sharedUtil.isArray;
  47824. var isNum = sharedUtil.isNum;
  47825. var isString = sharedUtil.isString;
  47826. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  47827. var warn = sharedUtil.warn;
  47828. var Dict = corePrimitives.Dict;
  47829. var Name = corePrimitives.Name;
  47830. var isCmd = corePrimitives.isCmd;
  47831. var isDict = corePrimitives.isDict;
  47832. var isName = corePrimitives.isName;
  47833. var isRef = corePrimitives.isRef;
  47834. var isStream = corePrimitives.isStream;
  47835. var DecodeStream = coreStream.DecodeStream;
  47836. var JpegStream = coreStream.JpegStream;
  47837. var Stream = coreStream.Stream;
  47838. var Lexer = coreParser.Lexer;
  47839. var Parser = coreParser.Parser;
  47840. var isEOF = coreParser.isEOF;
  47841. var PDFImage = coreImage.PDFImage;
  47842. var ColorSpace = coreColorSpace.ColorSpace;
  47843. var MurmurHash3_64 = coreMurmurHash3.MurmurHash3_64;
  47844. var ErrorFont = coreFonts.ErrorFont;
  47845. var FontFlags = coreFonts.FontFlags;
  47846. var Font = coreFonts.Font;
  47847. var IdentityToUnicodeMap = coreFonts.IdentityToUnicodeMap;
  47848. var ToUnicodeMap = coreFonts.ToUnicodeMap;
  47849. var getFontType = coreFonts.getFontType;
  47850. var isPDFFunction = coreFunction.isPDFFunction;
  47851. var PDFFunction = coreFunction.PDFFunction;
  47852. var Pattern = corePattern.Pattern;
  47853. var getTilingPatternIR = corePattern.getTilingPatternIR;
  47854. var CMapFactory = coreCMap.CMapFactory;
  47855. var IdentityCMap = coreCMap.IdentityCMap;
  47856. var getMetrics = coreMetrics.getMetrics;
  47857. var bidi = coreBidi.bidi;
  47858. var WinAnsiEncoding = coreEncodings.WinAnsiEncoding;
  47859. var StandardEncoding = coreEncodings.StandardEncoding;
  47860. var MacRomanEncoding = coreEncodings.MacRomanEncoding;
  47861. var SymbolSetEncoding = coreEncodings.SymbolSetEncoding;
  47862. var ZapfDingbatsEncoding = coreEncodings.ZapfDingbatsEncoding;
  47863. var getEncoding = coreEncodings.getEncoding;
  47864. var getStdFontMap = coreStandardFonts.getStdFontMap;
  47865. var getSerifFonts = coreStandardFonts.getSerifFonts;
  47866. var getSymbolsFonts = coreStandardFonts.getSymbolsFonts;
  47867. var getNormalizedUnicodes = coreUnicode.getNormalizedUnicodes;
  47868. var reverseIfRtl = coreUnicode.reverseIfRtl;
  47869. var getUnicodeForGlyph = coreUnicode.getUnicodeForGlyph;
  47870. var getGlyphsUnicode = coreGlyphList.getGlyphsUnicode;
  47871. var PartialEvaluator = function PartialEvaluatorClosure() {
  47872. var DefaultPartialEvaluatorOptions = {
  47873. forceDataSchema: false,
  47874. maxImageSize: -1,
  47875. disableFontFace: false,
  47876. cMapOptions: {
  47877. url: null,
  47878. packed: false
  47879. }
  47880. };
  47881. function NativeImageDecoder(xref, resources, handler, forceDataSchema) {
  47882. this.xref = xref;
  47883. this.resources = resources;
  47884. this.handler = handler;
  47885. this.forceDataSchema = forceDataSchema;
  47886. }
  47887. NativeImageDecoder.prototype = {
  47888. canDecode: function (image) {
  47889. return image instanceof JpegStream && NativeImageDecoder.isDecodable(image, this.xref, this.resources);
  47890. },
  47891. decode: function (image) {
  47892. // For natively supported JPEGs send them to the main thread for decoding.
  47893. var dict = image.dict;
  47894. var colorSpace = dict.get('ColorSpace', 'CS');
  47895. colorSpace = ColorSpace.parse(colorSpace, this.xref, this.resources);
  47896. var numComps = colorSpace.numComps;
  47897. var decodePromise = this.handler.sendWithPromise('JpegDecode', [
  47898. image.getIR(this.forceDataSchema),
  47899. numComps
  47900. ]);
  47901. return decodePromise.then(function (message) {
  47902. var data = message.data;
  47903. return new Stream(data, 0, data.length, image.dict);
  47904. });
  47905. }
  47906. };
  47907. /**
  47908. * Checks if the image can be decoded and displayed by the browser without any
  47909. * further processing such as color space conversions.
  47910. */
  47911. NativeImageDecoder.isSupported = function NativeImageDecoder_isSupported(image, xref, res) {
  47912. var dict = image.dict;
  47913. if (dict.has('DecodeParms') || dict.has('DP')) {
  47914. return false;
  47915. }
  47916. var cs = ColorSpace.parse(dict.get('ColorSpace', 'CS'), xref, res);
  47917. return (cs.name === 'DeviceGray' || cs.name === 'DeviceRGB') && cs.isDefaultDecode(dict.getArray('Decode', 'D'));
  47918. };
  47919. /**
  47920. * Checks if the image can be decoded by the browser.
  47921. */
  47922. NativeImageDecoder.isDecodable = function NativeImageDecoder_isDecodable(image, xref, res) {
  47923. var dict = image.dict;
  47924. if (dict.has('DecodeParms') || dict.has('DP')) {
  47925. return false;
  47926. }
  47927. var cs = ColorSpace.parse(dict.get('ColorSpace', 'CS'), xref, res);
  47928. return (cs.numComps === 1 || cs.numComps === 3) && cs.isDefaultDecode(dict.getArray('Decode', 'D'));
  47929. };
  47930. function PartialEvaluator(pdfManager, xref, handler, pageIndex, uniquePrefix, idCounters, fontCache, options) {
  47931. this.pdfManager = pdfManager;
  47932. this.xref = xref;
  47933. this.handler = handler;
  47934. this.pageIndex = pageIndex;
  47935. this.uniquePrefix = uniquePrefix;
  47936. this.idCounters = idCounters;
  47937. this.fontCache = fontCache;
  47938. this.options = options || DefaultPartialEvaluatorOptions;
  47939. }
  47940. // Trying to minimize Date.now() usage and check every 100 time
  47941. var TIME_SLOT_DURATION_MS = 20;
  47942. var CHECK_TIME_EVERY = 100;
  47943. function TimeSlotManager() {
  47944. this.reset();
  47945. }
  47946. TimeSlotManager.prototype = {
  47947. check: function TimeSlotManager_check() {
  47948. if (++this.checked < CHECK_TIME_EVERY) {
  47949. return false;
  47950. }
  47951. this.checked = 0;
  47952. return this.endTime <= Date.now();
  47953. },
  47954. reset: function TimeSlotManager_reset() {
  47955. this.endTime = Date.now() + TIME_SLOT_DURATION_MS;
  47956. this.checked = 0;
  47957. }
  47958. };
  47959. var deferred = Promise.resolve();
  47960. var TILING_PATTERN = 1, SHADING_PATTERN = 2;
  47961. PartialEvaluator.prototype = {
  47962. hasBlendModes: function PartialEvaluator_hasBlendModes(resources) {
  47963. if (!isDict(resources)) {
  47964. return false;
  47965. }
  47966. var processed = Object.create(null);
  47967. if (resources.objId) {
  47968. processed[resources.objId] = true;
  47969. }
  47970. var nodes = [resources], xref = this.xref;
  47971. while (nodes.length) {
  47972. var key, i, ii;
  47973. var node = nodes.shift();
  47974. // First check the current resources for blend modes.
  47975. var graphicStates = node.get('ExtGState');
  47976. if (isDict(graphicStates)) {
  47977. var graphicStatesKeys = graphicStates.getKeys();
  47978. for (i = 0, ii = graphicStatesKeys.length; i < ii; i++) {
  47979. key = graphicStatesKeys[i];
  47980. var graphicState = graphicStates.get(key);
  47981. var bm = graphicState.get('BM');
  47982. if (isName(bm) && bm.name !== 'Normal') {
  47983. return true;
  47984. }
  47985. }
  47986. }
  47987. // Descend into the XObjects to look for more resources and blend modes.
  47988. var xObjects = node.get('XObject');
  47989. if (!isDict(xObjects)) {
  47990. continue;
  47991. }
  47992. var xObjectsKeys = xObjects.getKeys();
  47993. for (i = 0, ii = xObjectsKeys.length; i < ii; i++) {
  47994. key = xObjectsKeys[i];
  47995. var xObject = xObjects.getRaw(key);
  47996. if (isRef(xObject)) {
  47997. if (processed[xObject.toString()]) {
  47998. // The XObject has already been processed, and by avoiding a
  47999. // redundant `xref.fetch` we can *significantly* reduce the load
  48000. // time for badly generated PDF files (fixes issue6961.pdf).
  48001. continue;
  48002. }
  48003. xObject = xref.fetch(xObject);
  48004. }
  48005. if (!isStream(xObject)) {
  48006. continue;
  48007. }
  48008. if (xObject.dict.objId) {
  48009. if (processed[xObject.dict.objId]) {
  48010. // stream has objId and is processed already
  48011. continue;
  48012. }
  48013. processed[xObject.dict.objId] = true;
  48014. }
  48015. var xResources = xObject.dict.get('Resources');
  48016. // Checking objId to detect an infinite loop.
  48017. if (isDict(xResources) && (!xResources.objId || !processed[xResources.objId])) {
  48018. nodes.push(xResources);
  48019. if (xResources.objId) {
  48020. processed[xResources.objId] = true;
  48021. }
  48022. }
  48023. }
  48024. }
  48025. return false;
  48026. },
  48027. buildFormXObject: function PartialEvaluator_buildFormXObject(resources, xobj, smask, operatorList, task, initialState) {
  48028. var matrix = xobj.dict.getArray('Matrix');
  48029. var bbox = xobj.dict.getArray('BBox');
  48030. var group = xobj.dict.get('Group');
  48031. if (group) {
  48032. var groupOptions = {
  48033. matrix: matrix,
  48034. bbox: bbox,
  48035. smask: smask,
  48036. isolated: false,
  48037. knockout: false
  48038. };
  48039. var groupSubtype = group.get('S');
  48040. var colorSpace;
  48041. if (isName(groupSubtype, 'Transparency')) {
  48042. groupOptions.isolated = group.get('I') || false;
  48043. groupOptions.knockout = group.get('K') || false;
  48044. colorSpace = group.has('CS') ? ColorSpace.parse(group.get('CS'), this.xref, resources) : null;
  48045. }
  48046. if (smask && smask.backdrop) {
  48047. colorSpace = colorSpace || ColorSpace.singletons.rgb;
  48048. smask.backdrop = colorSpace.getRgb(smask.backdrop, 0);
  48049. }
  48050. operatorList.addOp(OPS.beginGroup, [groupOptions]);
  48051. }
  48052. operatorList.addOp(OPS.paintFormXObjectBegin, [
  48053. matrix,
  48054. bbox
  48055. ]);
  48056. return this.getOperatorList(xobj, task, xobj.dict.get('Resources') || resources, operatorList, initialState).then(function () {
  48057. operatorList.addOp(OPS.paintFormXObjectEnd, []);
  48058. if (group) {
  48059. operatorList.addOp(OPS.endGroup, [groupOptions]);
  48060. }
  48061. });
  48062. },
  48063. buildPaintImageXObject: function PartialEvaluator_buildPaintImageXObject(resources, image, inline, operatorList, cacheKey, imageCache) {
  48064. var self = this;
  48065. var dict = image.dict;
  48066. var w = dict.get('Width', 'W');
  48067. var h = dict.get('Height', 'H');
  48068. if (!(w && isNum(w)) || !(h && isNum(h))) {
  48069. warn('Image dimensions are missing, or not numbers.');
  48070. return;
  48071. }
  48072. var maxImageSize = this.options.maxImageSize;
  48073. if (maxImageSize !== -1 && w * h > maxImageSize) {
  48074. warn('Image exceeded maximum allowed size and was removed.');
  48075. return;
  48076. }
  48077. var imageMask = dict.get('ImageMask', 'IM') || false;
  48078. var imgData, args;
  48079. if (imageMask) {
  48080. // This depends on a tmpCanvas being filled with the
  48081. // current fillStyle, such that processing the pixel
  48082. // data can't be done here. Instead of creating a
  48083. // complete PDFImage, only read the information needed
  48084. // for later.
  48085. var width = dict.get('Width', 'W');
  48086. var height = dict.get('Height', 'H');
  48087. var bitStrideLength = width + 7 >> 3;
  48088. var imgArray = image.getBytes(bitStrideLength * height);
  48089. var decode = dict.getArray('Decode', 'D');
  48090. var inverseDecode = !!decode && decode[0] > 0;
  48091. imgData = PDFImage.createMask(imgArray, width, height, image instanceof DecodeStream, inverseDecode);
  48092. imgData.cached = true;
  48093. args = [imgData];
  48094. operatorList.addOp(OPS.paintImageMaskXObject, args);
  48095. if (cacheKey) {
  48096. imageCache[cacheKey] = {
  48097. fn: OPS.paintImageMaskXObject,
  48098. args: args
  48099. };
  48100. }
  48101. return;
  48102. }
  48103. var softMask = dict.get('SMask', 'SM') || false;
  48104. var mask = dict.get('Mask') || false;
  48105. var SMALL_IMAGE_DIMENSIONS = 200;
  48106. // Inlining small images into the queue as RGB data
  48107. if (inline && !softMask && !mask && !(image instanceof JpegStream) && w + h < SMALL_IMAGE_DIMENSIONS) {
  48108. var imageObj = new PDFImage(this.xref, resources, image, inline, null, null);
  48109. // We force the use of RGBA_32BPP images here, because we can't handle
  48110. // any other kind.
  48111. imgData = imageObj.createImageData(/* forceRGBA = */
  48112. true);
  48113. operatorList.addOp(OPS.paintInlineImageXObject, [imgData]);
  48114. return;
  48115. }
  48116. // If there is no imageMask, create the PDFImage and a lot
  48117. // of image processing can be done here.
  48118. var uniquePrefix = this.uniquePrefix || '';
  48119. var objId = 'img_' + uniquePrefix + ++this.idCounters.obj;
  48120. operatorList.addDependency(objId);
  48121. args = [
  48122. objId,
  48123. w,
  48124. h
  48125. ];
  48126. if (!softMask && !mask && image instanceof JpegStream && NativeImageDecoder.isSupported(image, this.xref, resources)) {
  48127. // These JPEGs don't need any more processing so we can just send it.
  48128. operatorList.addOp(OPS.paintJpegXObject, args);
  48129. this.handler.send('obj', [
  48130. objId,
  48131. this.pageIndex,
  48132. 'JpegStream',
  48133. image.getIR(this.options.forceDataSchema)
  48134. ]);
  48135. return;
  48136. }
  48137. // Creates native image decoder only if a JPEG image or mask is present.
  48138. var nativeImageDecoder = null;
  48139. if (image instanceof JpegStream || mask instanceof JpegStream || softMask instanceof JpegStream) {
  48140. nativeImageDecoder = new NativeImageDecoder(self.xref, resources, self.handler, self.options.forceDataSchema);
  48141. }
  48142. PDFImage.buildImage(self.handler, self.xref, resources, image, inline, nativeImageDecoder).then(function (imageObj) {
  48143. var imgData = imageObj.createImageData(/* forceRGBA = */
  48144. false);
  48145. self.handler.send('obj', [
  48146. objId,
  48147. self.pageIndex,
  48148. 'Image',
  48149. imgData
  48150. ], [imgData.data.buffer]);
  48151. }).then(undefined, function (reason) {
  48152. warn('Unable to decode image: ' + reason);
  48153. self.handler.send('obj', [
  48154. objId,
  48155. self.pageIndex,
  48156. 'Image',
  48157. null
  48158. ]);
  48159. });
  48160. operatorList.addOp(OPS.paintImageXObject, args);
  48161. if (cacheKey) {
  48162. imageCache[cacheKey] = {
  48163. fn: OPS.paintImageXObject,
  48164. args: args
  48165. };
  48166. }
  48167. },
  48168. handleSMask: function PartialEvaluator_handleSmask(smask, resources, operatorList, task, stateManager) {
  48169. var smaskContent = smask.get('G');
  48170. var smaskOptions = {
  48171. subtype: smask.get('S').name,
  48172. backdrop: smask.get('BC')
  48173. };
  48174. // The SMask might have a alpha/luminosity value transfer function --
  48175. // we will build a map of integer values in range 0..255 to be fast.
  48176. var transferObj = smask.get('TR');
  48177. if (isPDFFunction(transferObj)) {
  48178. var transferFn = PDFFunction.parse(this.xref, transferObj);
  48179. var transferMap = new Uint8Array(256);
  48180. var tmp = new Float32Array(1);
  48181. for (var i = 0; i < 256; i++) {
  48182. tmp[0] = i / 255;
  48183. transferFn(tmp, 0, tmp, 0);
  48184. transferMap[i] = tmp[0] * 255 | 0;
  48185. }
  48186. smaskOptions.transferMap = transferMap;
  48187. }
  48188. return this.buildFormXObject(resources, smaskContent, smaskOptions, operatorList, task, stateManager.state.clone());
  48189. },
  48190. handleTilingType: function PartialEvaluator_handleTilingType(fn, args, resources, pattern, patternDict, operatorList, task) {
  48191. // Create an IR of the pattern code.
  48192. var tilingOpList = new OperatorList();
  48193. // Merge the available resources, to prevent issues when the patternDict
  48194. // is missing some /Resources entries (fixes issue6541.pdf).
  48195. var resourcesArray = [
  48196. patternDict.get('Resources'),
  48197. resources
  48198. ];
  48199. var patternResources = Dict.merge(this.xref, resourcesArray);
  48200. return this.getOperatorList(pattern, task, patternResources, tilingOpList).then(function () {
  48201. // Add the dependencies to the parent operator list so they are
  48202. // resolved before sub operator list is executed synchronously.
  48203. operatorList.addDependencies(tilingOpList.dependencies);
  48204. operatorList.addOp(fn, getTilingPatternIR({
  48205. fnArray: tilingOpList.fnArray,
  48206. argsArray: tilingOpList.argsArray
  48207. }, patternDict, args));
  48208. });
  48209. },
  48210. handleSetFont: function PartialEvaluator_handleSetFont(resources, fontArgs, fontRef, operatorList, task, state) {
  48211. // TODO(mack): Not needed?
  48212. var fontName;
  48213. if (fontArgs) {
  48214. fontArgs = fontArgs.slice();
  48215. fontName = fontArgs[0].name;
  48216. }
  48217. var self = this;
  48218. return this.loadFont(fontName, fontRef, this.xref, resources).then(function (translated) {
  48219. if (!translated.font.isType3Font) {
  48220. return translated;
  48221. }
  48222. return translated.loadType3Data(self, resources, operatorList, task).then(function () {
  48223. return translated;
  48224. }, function (reason) {
  48225. // Error in the font data -- sending unsupported feature notification.
  48226. self.handler.send('UnsupportedFeature', { featureId: UNSUPPORTED_FEATURES.font });
  48227. return new TranslatedFont('g_font_error', new ErrorFont('Type3 font load error: ' + reason), translated.font);
  48228. });
  48229. }).then(function (translated) {
  48230. state.font = translated.font;
  48231. translated.send(self.handler);
  48232. return translated.loadedName;
  48233. });
  48234. },
  48235. handleText: function PartialEvaluator_handleText(chars, state) {
  48236. var font = state.font;
  48237. var glyphs = font.charsToGlyphs(chars);
  48238. var isAddToPathSet = !!(state.textRenderingMode & TextRenderingMode.ADD_TO_PATH_FLAG);
  48239. if (font.data && (isAddToPathSet || this.options.disableFontFace)) {
  48240. var buildPath = function (fontChar) {
  48241. if (!font.renderer.hasBuiltPath(fontChar)) {
  48242. var path = font.renderer.getPathJs(fontChar);
  48243. this.handler.send('commonobj', [
  48244. font.loadedName + '_path_' + fontChar,
  48245. 'FontPath',
  48246. path
  48247. ]);
  48248. }
  48249. }.bind(this);
  48250. for (var i = 0, ii = glyphs.length; i < ii; i++) {
  48251. var glyph = glyphs[i];
  48252. buildPath(glyph.fontChar);
  48253. // If the glyph has an accent we need to build a path for its
  48254. // fontChar too, otherwise CanvasGraphics_paintChar will fail.
  48255. var accent = glyph.accent;
  48256. if (accent && accent.fontChar) {
  48257. buildPath(accent.fontChar);
  48258. }
  48259. }
  48260. }
  48261. return glyphs;
  48262. },
  48263. setGState: function PartialEvaluator_setGState(resources, gState, operatorList, task, xref, stateManager) {
  48264. // This array holds the converted/processed state data.
  48265. var gStateObj = [];
  48266. var gStateKeys = gState.getKeys();
  48267. var self = this;
  48268. var promise = Promise.resolve();
  48269. for (var i = 0, ii = gStateKeys.length; i < ii; i++) {
  48270. var key = gStateKeys[i];
  48271. var value = gState.get(key);
  48272. switch (key) {
  48273. case 'Type':
  48274. break;
  48275. case 'LW':
  48276. case 'LC':
  48277. case 'LJ':
  48278. case 'ML':
  48279. case 'D':
  48280. case 'RI':
  48281. case 'FL':
  48282. case 'CA':
  48283. case 'ca':
  48284. gStateObj.push([
  48285. key,
  48286. value
  48287. ]);
  48288. break;
  48289. case 'Font':
  48290. promise = promise.then(function () {
  48291. return self.handleSetFont(resources, null, value[0], operatorList, task, stateManager.state).then(function (loadedName) {
  48292. operatorList.addDependency(loadedName);
  48293. gStateObj.push([
  48294. key,
  48295. [
  48296. loadedName,
  48297. value[1]
  48298. ]
  48299. ]);
  48300. });
  48301. });
  48302. break;
  48303. case 'BM':
  48304. gStateObj.push([
  48305. key,
  48306. value
  48307. ]);
  48308. break;
  48309. case 'SMask':
  48310. if (isName(value, 'None')) {
  48311. gStateObj.push([
  48312. key,
  48313. false
  48314. ]);
  48315. break;
  48316. }
  48317. if (isDict(value)) {
  48318. promise = promise.then(function (dict) {
  48319. return self.handleSMask(dict, resources, operatorList, task, stateManager);
  48320. }.bind(this, value));
  48321. gStateObj.push([
  48322. key,
  48323. true
  48324. ]);
  48325. } else {
  48326. warn('Unsupported SMask type');
  48327. }
  48328. break;
  48329. // Only generate info log messages for the following since
  48330. // they are unlikely to have a big impact on the rendering.
  48331. case 'OP':
  48332. case 'op':
  48333. case 'OPM':
  48334. case 'BG':
  48335. case 'BG2':
  48336. case 'UCR':
  48337. case 'UCR2':
  48338. case 'TR':
  48339. case 'TR2':
  48340. case 'HT':
  48341. case 'SM':
  48342. case 'SA':
  48343. case 'AIS':
  48344. case 'TK':
  48345. // TODO implement these operators.
  48346. info('graphic state operator ' + key);
  48347. break;
  48348. default:
  48349. info('Unknown graphic state operator ' + key);
  48350. break;
  48351. }
  48352. }
  48353. return promise.then(function () {
  48354. if (gStateObj.length > 0) {
  48355. operatorList.addOp(OPS.setGState, [gStateObj]);
  48356. }
  48357. });
  48358. },
  48359. loadFont: function PartialEvaluator_loadFont(fontName, font, xref, resources) {
  48360. function errorFont() {
  48361. return Promise.resolve(new TranslatedFont('g_font_error', new ErrorFont('Font ' + fontName + ' is not available'), font));
  48362. }
  48363. var fontRef;
  48364. if (font) {
  48365. // Loading by ref.
  48366. assert(isRef(font));
  48367. fontRef = font;
  48368. } else {
  48369. // Loading by name.
  48370. var fontRes = resources.get('Font');
  48371. if (fontRes) {
  48372. fontRef = fontRes.getRaw(fontName);
  48373. } else {
  48374. warn('fontRes not available');
  48375. return errorFont();
  48376. }
  48377. }
  48378. if (!fontRef) {
  48379. warn('fontRef not available');
  48380. return errorFont();
  48381. }
  48382. if (this.fontCache.has(fontRef)) {
  48383. return this.fontCache.get(fontRef);
  48384. }
  48385. font = xref.fetchIfRef(fontRef);
  48386. if (!isDict(font)) {
  48387. return errorFont();
  48388. }
  48389. // We are holding `font.translated` references just for `fontRef`s that
  48390. // are not actually `Ref`s, but rather `Dict`s. See explanation below.
  48391. if (font.translated) {
  48392. return font.translated;
  48393. }
  48394. var fontCapability = createPromiseCapability();
  48395. var preEvaluatedFont = this.preEvaluateFont(font, xref);
  48396. var descriptor = preEvaluatedFont.descriptor;
  48397. var fontRefIsRef = isRef(fontRef), fontID;
  48398. if (fontRefIsRef) {
  48399. fontID = fontRef.toString();
  48400. }
  48401. if (isDict(descriptor)) {
  48402. if (!descriptor.fontAliases) {
  48403. descriptor.fontAliases = Object.create(null);
  48404. }
  48405. var fontAliases = descriptor.fontAliases;
  48406. var hash = preEvaluatedFont.hash;
  48407. if (fontAliases[hash]) {
  48408. var aliasFontRef = fontAliases[hash].aliasRef;
  48409. if (fontRefIsRef && aliasFontRef && this.fontCache.has(aliasFontRef)) {
  48410. this.fontCache.putAlias(fontRef, aliasFontRef);
  48411. return this.fontCache.get(fontRef);
  48412. }
  48413. } else {
  48414. fontAliases[hash] = { fontID: Font.getFontID() };
  48415. }
  48416. if (fontRefIsRef) {
  48417. fontAliases[hash].aliasRef = fontRef;
  48418. }
  48419. fontID = fontAliases[hash].fontID;
  48420. }
  48421. // Workaround for bad PDF generators that reference fonts incorrectly,
  48422. // where `fontRef` is a `Dict` rather than a `Ref` (fixes bug946506.pdf).
  48423. // In this case we should not put the font into `this.fontCache` (which is
  48424. // a `RefSetCache`), since it's not meaningful to use a `Dict` as a key.
  48425. //
  48426. // However, if we don't cache the font it's not possible to remove it
  48427. // when `cleanup` is triggered from the API, which causes issues on
  48428. // subsequent rendering operations (see issue7403.pdf).
  48429. // A simple workaround would be to just not hold `font.translated`
  48430. // references in this case, but this would force us to unnecessarily load
  48431. // the same fonts over and over.
  48432. //
  48433. // Instead, we cheat a bit by attempting to use a modified `fontID` as a
  48434. // key in `this.fontCache`, to allow the font to be cached.
  48435. // NOTE: This works because `RefSetCache` calls `toString()` on provided
  48436. // keys. Also, since `fontRef` is used when getting cached fonts,
  48437. // we'll not accidentally match fonts cached with the `fontID`.
  48438. if (fontRefIsRef) {
  48439. this.fontCache.put(fontRef, fontCapability.promise);
  48440. } else {
  48441. if (!fontID) {
  48442. fontID = (this.uniquePrefix || 'F_') + ++this.idCounters.obj;
  48443. }
  48444. this.fontCache.put('id_' + fontID, fontCapability.promise);
  48445. }
  48446. assert(fontID, 'The "fontID" must be defined.');
  48447. // Keep track of each font we translated so the caller can
  48448. // load them asynchronously before calling display on a page.
  48449. font.loadedName = 'g_' + this.pdfManager.docId + '_f' + fontID;
  48450. font.translated = fontCapability.promise;
  48451. // TODO move promises into translate font
  48452. var translatedPromise;
  48453. try {
  48454. translatedPromise = this.translateFont(preEvaluatedFont, xref);
  48455. } catch (e) {
  48456. translatedPromise = Promise.reject(e);
  48457. }
  48458. var self = this;
  48459. translatedPromise.then(function (translatedFont) {
  48460. if (translatedFont.fontType !== undefined) {
  48461. var xrefFontStats = xref.stats.fontTypes;
  48462. xrefFontStats[translatedFont.fontType] = true;
  48463. }
  48464. fontCapability.resolve(new TranslatedFont(font.loadedName, translatedFont, font));
  48465. }, function (reason) {
  48466. // TODO fontCapability.reject?
  48467. // Error in the font data -- sending unsupported feature notification.
  48468. self.handler.send('UnsupportedFeature', { featureId: UNSUPPORTED_FEATURES.font });
  48469. try {
  48470. // error, but it's still nice to have font type reported
  48471. var descriptor = preEvaluatedFont.descriptor;
  48472. var fontFile3 = descriptor && descriptor.get('FontFile3');
  48473. var subtype = fontFile3 && fontFile3.get('Subtype');
  48474. var fontType = getFontType(preEvaluatedFont.type, subtype && subtype.name);
  48475. var xrefFontStats = xref.stats.fontTypes;
  48476. xrefFontStats[fontType] = true;
  48477. } catch (ex) {
  48478. }
  48479. fontCapability.resolve(new TranslatedFont(font.loadedName, new ErrorFont(reason instanceof Error ? reason.message : reason), font));
  48480. });
  48481. return fontCapability.promise;
  48482. },
  48483. buildPath: function PartialEvaluator_buildPath(operatorList, fn, args) {
  48484. var lastIndex = operatorList.length - 1;
  48485. if (!args) {
  48486. args = [];
  48487. }
  48488. if (lastIndex < 0 || operatorList.fnArray[lastIndex] !== OPS.constructPath) {
  48489. operatorList.addOp(OPS.constructPath, [
  48490. [fn],
  48491. args
  48492. ]);
  48493. } else {
  48494. var opArgs = operatorList.argsArray[lastIndex];
  48495. opArgs[0].push(fn);
  48496. Array.prototype.push.apply(opArgs[1], args);
  48497. }
  48498. },
  48499. handleColorN: function PartialEvaluator_handleColorN(operatorList, fn, args, cs, patterns, resources, task, xref) {
  48500. // compile tiling patterns
  48501. var patternName = args[args.length - 1];
  48502. // SCN/scn applies patterns along with normal colors
  48503. var pattern;
  48504. if (isName(patternName) && (pattern = patterns.get(patternName.name))) {
  48505. var dict = isStream(pattern) ? pattern.dict : pattern;
  48506. var typeNum = dict.get('PatternType');
  48507. if (typeNum === TILING_PATTERN) {
  48508. var color = cs.base ? cs.base.getRgb(args, 0) : null;
  48509. return this.handleTilingType(fn, color, resources, pattern, dict, operatorList, task);
  48510. } else if (typeNum === SHADING_PATTERN) {
  48511. var shading = dict.get('Shading');
  48512. var matrix = dict.getArray('Matrix');
  48513. pattern = Pattern.parseShading(shading, matrix, xref, resources, this.handler);
  48514. operatorList.addOp(fn, pattern.getIR());
  48515. return Promise.resolve();
  48516. } else {
  48517. return Promise.reject('Unknown PatternType: ' + typeNum);
  48518. }
  48519. }
  48520. // TODO shall we fail here?
  48521. operatorList.addOp(fn, args);
  48522. return Promise.resolve();
  48523. },
  48524. getOperatorList: function PartialEvaluator_getOperatorList(stream, task, resources, operatorList, initialState) {
  48525. var self = this;
  48526. var xref = this.xref;
  48527. var imageCache = Object.create(null);
  48528. assert(operatorList);
  48529. resources = resources || Dict.empty;
  48530. var xobjs = resources.get('XObject') || Dict.empty;
  48531. var patterns = resources.get('Pattern') || Dict.empty;
  48532. var stateManager = new StateManager(initialState || new EvalState());
  48533. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  48534. var timeSlotManager = new TimeSlotManager();
  48535. return new Promise(function promiseBody(resolve, reject) {
  48536. var next = function (promise) {
  48537. promise.then(function () {
  48538. try {
  48539. promiseBody(resolve, reject);
  48540. } catch (ex) {
  48541. reject(ex);
  48542. }
  48543. }, reject);
  48544. };
  48545. task.ensureNotTerminated();
  48546. timeSlotManager.reset();
  48547. var stop, operation = {}, i, ii, cs;
  48548. while (!(stop = timeSlotManager.check())) {
  48549. // The arguments parsed by read() are used beyond this loop, so we
  48550. // cannot reuse the same array on each iteration. Therefore we pass
  48551. // in |null| as the initial value (see the comment on
  48552. // EvaluatorPreprocessor_read() for why).
  48553. operation.args = null;
  48554. if (!preprocessor.read(operation)) {
  48555. break;
  48556. }
  48557. var args = operation.args;
  48558. var fn = operation.fn;
  48559. switch (fn | 0) {
  48560. case OPS.paintXObject:
  48561. if (args[0].code) {
  48562. break;
  48563. }
  48564. // eagerly compile XForm objects
  48565. var name = args[0].name;
  48566. if (!name) {
  48567. warn('XObject must be referred to by name.');
  48568. continue;
  48569. }
  48570. if (imageCache[name] !== undefined) {
  48571. operatorList.addOp(imageCache[name].fn, imageCache[name].args);
  48572. args = null;
  48573. continue;
  48574. }
  48575. var xobj = xobjs.get(name);
  48576. if (xobj) {
  48577. assert(isStream(xobj), 'XObject should be a stream');
  48578. var type = xobj.dict.get('Subtype');
  48579. assert(isName(type), 'XObject should have a Name subtype');
  48580. if (type.name === 'Form') {
  48581. stateManager.save();
  48582. next(self.buildFormXObject(resources, xobj, null, operatorList, task, stateManager.state.clone()).then(function () {
  48583. stateManager.restore();
  48584. }));
  48585. return;
  48586. } else if (type.name === 'Image') {
  48587. self.buildPaintImageXObject(resources, xobj, false, operatorList, name, imageCache);
  48588. args = null;
  48589. continue;
  48590. } else if (type.name === 'PS') {
  48591. // PostScript XObjects are unused when viewing documents.
  48592. // See section 4.7.1 of Adobe's PDF reference.
  48593. info('Ignored XObject subtype PS');
  48594. continue;
  48595. } else {
  48596. error('Unhandled XObject subtype ' + type.name);
  48597. }
  48598. }
  48599. break;
  48600. case OPS.setFont:
  48601. var fontSize = args[1];
  48602. // eagerly collect all fonts
  48603. next(self.handleSetFont(resources, args, null, operatorList, task, stateManager.state).then(function (loadedName) {
  48604. operatorList.addDependency(loadedName);
  48605. operatorList.addOp(OPS.setFont, [
  48606. loadedName,
  48607. fontSize
  48608. ]);
  48609. }));
  48610. return;
  48611. case OPS.endInlineImage:
  48612. var cacheKey = args[0].cacheKey;
  48613. if (cacheKey) {
  48614. var cacheEntry = imageCache[cacheKey];
  48615. if (cacheEntry !== undefined) {
  48616. operatorList.addOp(cacheEntry.fn, cacheEntry.args);
  48617. args = null;
  48618. continue;
  48619. }
  48620. }
  48621. self.buildPaintImageXObject(resources, args[0], true, operatorList, cacheKey, imageCache);
  48622. args = null;
  48623. continue;
  48624. case OPS.showText:
  48625. args[0] = self.handleText(args[0], stateManager.state);
  48626. break;
  48627. case OPS.showSpacedText:
  48628. var arr = args[0];
  48629. var combinedGlyphs = [];
  48630. var arrLength = arr.length;
  48631. var state = stateManager.state;
  48632. for (i = 0; i < arrLength; ++i) {
  48633. var arrItem = arr[i];
  48634. if (isString(arrItem)) {
  48635. Array.prototype.push.apply(combinedGlyphs, self.handleText(arrItem, state));
  48636. } else if (isNum(arrItem)) {
  48637. combinedGlyphs.push(arrItem);
  48638. }
  48639. }
  48640. args[0] = combinedGlyphs;
  48641. fn = OPS.showText;
  48642. break;
  48643. case OPS.nextLineShowText:
  48644. operatorList.addOp(OPS.nextLine);
  48645. args[0] = self.handleText(args[0], stateManager.state);
  48646. fn = OPS.showText;
  48647. break;
  48648. case OPS.nextLineSetSpacingShowText:
  48649. operatorList.addOp(OPS.nextLine);
  48650. operatorList.addOp(OPS.setWordSpacing, [args.shift()]);
  48651. operatorList.addOp(OPS.setCharSpacing, [args.shift()]);
  48652. args[0] = self.handleText(args[0], stateManager.state);
  48653. fn = OPS.showText;
  48654. break;
  48655. case OPS.setTextRenderingMode:
  48656. stateManager.state.textRenderingMode = args[0];
  48657. break;
  48658. case OPS.setFillColorSpace:
  48659. stateManager.state.fillColorSpace = ColorSpace.parse(args[0], xref, resources);
  48660. continue;
  48661. case OPS.setStrokeColorSpace:
  48662. stateManager.state.strokeColorSpace = ColorSpace.parse(args[0], xref, resources);
  48663. continue;
  48664. case OPS.setFillColor:
  48665. cs = stateManager.state.fillColorSpace;
  48666. args = cs.getRgb(args, 0);
  48667. fn = OPS.setFillRGBColor;
  48668. break;
  48669. case OPS.setStrokeColor:
  48670. cs = stateManager.state.strokeColorSpace;
  48671. args = cs.getRgb(args, 0);
  48672. fn = OPS.setStrokeRGBColor;
  48673. break;
  48674. case OPS.setFillGray:
  48675. stateManager.state.fillColorSpace = ColorSpace.singletons.gray;
  48676. args = ColorSpace.singletons.gray.getRgb(args, 0);
  48677. fn = OPS.setFillRGBColor;
  48678. break;
  48679. case OPS.setStrokeGray:
  48680. stateManager.state.strokeColorSpace = ColorSpace.singletons.gray;
  48681. args = ColorSpace.singletons.gray.getRgb(args, 0);
  48682. fn = OPS.setStrokeRGBColor;
  48683. break;
  48684. case OPS.setFillCMYKColor:
  48685. stateManager.state.fillColorSpace = ColorSpace.singletons.cmyk;
  48686. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  48687. fn = OPS.setFillRGBColor;
  48688. break;
  48689. case OPS.setStrokeCMYKColor:
  48690. stateManager.state.strokeColorSpace = ColorSpace.singletons.cmyk;
  48691. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  48692. fn = OPS.setStrokeRGBColor;
  48693. break;
  48694. case OPS.setFillRGBColor:
  48695. stateManager.state.fillColorSpace = ColorSpace.singletons.rgb;
  48696. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  48697. break;
  48698. case OPS.setStrokeRGBColor:
  48699. stateManager.state.strokeColorSpace = ColorSpace.singletons.rgb;
  48700. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  48701. break;
  48702. case OPS.setFillColorN:
  48703. cs = stateManager.state.fillColorSpace;
  48704. if (cs.name === 'Pattern') {
  48705. next(self.handleColorN(operatorList, OPS.setFillColorN, args, cs, patterns, resources, task, xref));
  48706. return;
  48707. }
  48708. args = cs.getRgb(args, 0);
  48709. fn = OPS.setFillRGBColor;
  48710. break;
  48711. case OPS.setStrokeColorN:
  48712. cs = stateManager.state.strokeColorSpace;
  48713. if (cs.name === 'Pattern') {
  48714. next(self.handleColorN(operatorList, OPS.setStrokeColorN, args, cs, patterns, resources, task, xref));
  48715. return;
  48716. }
  48717. args = cs.getRgb(args, 0);
  48718. fn = OPS.setStrokeRGBColor;
  48719. break;
  48720. case OPS.shadingFill:
  48721. var shadingRes = resources.get('Shading');
  48722. if (!shadingRes) {
  48723. error('No shading resource found');
  48724. }
  48725. var shading = shadingRes.get(args[0].name);
  48726. if (!shading) {
  48727. error('No shading object found');
  48728. }
  48729. var shadingFill = Pattern.parseShading(shading, null, xref, resources, self.handler);
  48730. var patternIR = shadingFill.getIR();
  48731. args = [patternIR];
  48732. fn = OPS.shadingFill;
  48733. break;
  48734. case OPS.setGState:
  48735. var dictName = args[0];
  48736. var extGState = resources.get('ExtGState');
  48737. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  48738. break;
  48739. }
  48740. var gState = extGState.get(dictName.name);
  48741. next(self.setGState(resources, gState, operatorList, task, xref, stateManager));
  48742. return;
  48743. case OPS.moveTo:
  48744. case OPS.lineTo:
  48745. case OPS.curveTo:
  48746. case OPS.curveTo2:
  48747. case OPS.curveTo3:
  48748. case OPS.closePath:
  48749. self.buildPath(operatorList, fn, args);
  48750. continue;
  48751. case OPS.rectangle:
  48752. self.buildPath(operatorList, fn, args);
  48753. continue;
  48754. case OPS.markPoint:
  48755. case OPS.markPointProps:
  48756. case OPS.beginMarkedContent:
  48757. case OPS.beginMarkedContentProps:
  48758. case OPS.endMarkedContent:
  48759. case OPS.beginCompat:
  48760. case OPS.endCompat:
  48761. // Ignore operators where the corresponding handlers are known to
  48762. // be no-op in CanvasGraphics (display/canvas.js). This prevents
  48763. // serialization errors and is also a bit more efficient.
  48764. // We could also try to serialize all objects in a general way,
  48765. // e.g. as done in https://github.com/mozilla/pdf.js/pull/6266,
  48766. // but doing so is meaningless without knowing the semantics.
  48767. continue;
  48768. default:
  48769. // Note: Ignore the operator if it has `Dict` arguments, since
  48770. // those are non-serializable, otherwise postMessage will throw
  48771. // "An object could not be cloned.".
  48772. if (args !== null) {
  48773. for (i = 0, ii = args.length; i < ii; i++) {
  48774. if (args[i] instanceof Dict) {
  48775. break;
  48776. }
  48777. }
  48778. if (i < ii) {
  48779. warn('getOperatorList - ignoring operator: ' + fn);
  48780. continue;
  48781. }
  48782. }
  48783. }
  48784. operatorList.addOp(fn, args);
  48785. }
  48786. if (stop) {
  48787. next(deferred);
  48788. return;
  48789. }
  48790. // Some PDFs don't close all restores inside object/form.
  48791. // Closing those for them.
  48792. for (i = 0, ii = preprocessor.savedStatesDepth; i < ii; i++) {
  48793. operatorList.addOp(OPS.restore, []);
  48794. }
  48795. resolve();
  48796. });
  48797. },
  48798. getTextContent: function PartialEvaluator_getTextContent(stream, task, resources, stateManager, normalizeWhitespace, combineTextItems) {
  48799. stateManager = stateManager || new StateManager(new TextState());
  48800. var WhitespaceRegexp = /\s/g;
  48801. var textContent = {
  48802. items: [],
  48803. styles: Object.create(null)
  48804. };
  48805. var textContentItem = {
  48806. initialized: false,
  48807. str: [],
  48808. width: 0,
  48809. height: 0,
  48810. vertical: false,
  48811. lastAdvanceWidth: 0,
  48812. lastAdvanceHeight: 0,
  48813. textAdvanceScale: 0,
  48814. spaceWidth: 0,
  48815. fakeSpaceMin: Infinity,
  48816. fakeMultiSpaceMin: Infinity,
  48817. fakeMultiSpaceMax: -0,
  48818. textRunBreakAllowed: false,
  48819. transform: null,
  48820. fontName: null
  48821. };
  48822. var SPACE_FACTOR = 0.3;
  48823. var MULTI_SPACE_FACTOR = 1.5;
  48824. var MULTI_SPACE_FACTOR_MAX = 4;
  48825. var self = this;
  48826. var xref = this.xref;
  48827. resources = xref.fetchIfRef(resources) || Dict.empty;
  48828. // The xobj is parsed iff it's needed, e.g. if there is a `DO` cmd.
  48829. var xobjs = null;
  48830. var xobjsCache = Object.create(null);
  48831. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  48832. var textState;
  48833. function ensureTextContentItem() {
  48834. if (textContentItem.initialized) {
  48835. return textContentItem;
  48836. }
  48837. var font = textState.font;
  48838. if (!(font.loadedName in textContent.styles)) {
  48839. textContent.styles[font.loadedName] = {
  48840. fontFamily: font.fallbackName,
  48841. ascent: font.ascent,
  48842. descent: font.descent,
  48843. vertical: font.vertical
  48844. };
  48845. }
  48846. textContentItem.fontName = font.loadedName;
  48847. // 9.4.4 Text Space Details
  48848. var tsm = [
  48849. textState.fontSize * textState.textHScale,
  48850. 0,
  48851. 0,
  48852. textState.fontSize,
  48853. 0,
  48854. textState.textRise
  48855. ];
  48856. if (font.isType3Font && textState.fontMatrix !== FONT_IDENTITY_MATRIX && textState.fontSize === 1) {
  48857. var glyphHeight = font.bbox[3] - font.bbox[1];
  48858. if (glyphHeight > 0) {
  48859. glyphHeight = glyphHeight * textState.fontMatrix[3];
  48860. tsm[3] *= glyphHeight;
  48861. }
  48862. }
  48863. var trm = Util.transform(textState.ctm, Util.transform(textState.textMatrix, tsm));
  48864. textContentItem.transform = trm;
  48865. if (!font.vertical) {
  48866. textContentItem.width = 0;
  48867. textContentItem.height = Math.sqrt(trm[2] * trm[2] + trm[3] * trm[3]);
  48868. textContentItem.vertical = false;
  48869. } else {
  48870. textContentItem.width = Math.sqrt(trm[0] * trm[0] + trm[1] * trm[1]);
  48871. textContentItem.height = 0;
  48872. textContentItem.vertical = true;
  48873. }
  48874. var a = textState.textLineMatrix[0];
  48875. var b = textState.textLineMatrix[1];
  48876. var scaleLineX = Math.sqrt(a * a + b * b);
  48877. a = textState.ctm[0];
  48878. b = textState.ctm[1];
  48879. var scaleCtmX = Math.sqrt(a * a + b * b);
  48880. textContentItem.textAdvanceScale = scaleCtmX * scaleLineX;
  48881. textContentItem.lastAdvanceWidth = 0;
  48882. textContentItem.lastAdvanceHeight = 0;
  48883. var spaceWidth = font.spaceWidth / 1000 * textState.fontSize;
  48884. if (spaceWidth) {
  48885. textContentItem.spaceWidth = spaceWidth;
  48886. textContentItem.fakeSpaceMin = spaceWidth * SPACE_FACTOR;
  48887. textContentItem.fakeMultiSpaceMin = spaceWidth * MULTI_SPACE_FACTOR;
  48888. textContentItem.fakeMultiSpaceMax = spaceWidth * MULTI_SPACE_FACTOR_MAX;
  48889. // It's okay for monospace fonts to fake as much space as needed.
  48890. textContentItem.textRunBreakAllowed = !font.isMonospace;
  48891. } else {
  48892. textContentItem.spaceWidth = 0;
  48893. textContentItem.fakeSpaceMin = Infinity;
  48894. textContentItem.fakeMultiSpaceMin = Infinity;
  48895. textContentItem.fakeMultiSpaceMax = 0;
  48896. textContentItem.textRunBreakAllowed = false;
  48897. }
  48898. textContentItem.initialized = true;
  48899. return textContentItem;
  48900. }
  48901. function replaceWhitespace(str) {
  48902. // Replaces all whitespaces with standard spaces (0x20), to avoid
  48903. // alignment issues between the textLayer and the canvas if the text
  48904. // contains e.g. tabs (fixes issue6612.pdf).
  48905. var i = 0, ii = str.length, code;
  48906. while (i < ii && (code = str.charCodeAt(i)) >= 0x20 && code <= 0x7F) {
  48907. i++;
  48908. }
  48909. return i < ii ? str.replace(WhitespaceRegexp, ' ') : str;
  48910. }
  48911. function runBidiTransform(textChunk) {
  48912. var str = textChunk.str.join('');
  48913. var bidiResult = bidi(str, -1, textChunk.vertical);
  48914. return {
  48915. str: normalizeWhitespace ? replaceWhitespace(bidiResult.str) : bidiResult.str,
  48916. dir: bidiResult.dir,
  48917. width: textChunk.width,
  48918. height: textChunk.height,
  48919. transform: textChunk.transform,
  48920. fontName: textChunk.fontName
  48921. };
  48922. }
  48923. function handleSetFont(fontName, fontRef) {
  48924. return self.loadFont(fontName, fontRef, xref, resources).then(function (translated) {
  48925. textState.font = translated.font;
  48926. textState.fontMatrix = translated.font.fontMatrix || FONT_IDENTITY_MATRIX;
  48927. });
  48928. }
  48929. function buildTextContentItem(chars) {
  48930. var font = textState.font;
  48931. var textChunk = ensureTextContentItem();
  48932. var width = 0;
  48933. var height = 0;
  48934. var glyphs = font.charsToGlyphs(chars);
  48935. var defaultVMetrics = font.defaultVMetrics;
  48936. for (var i = 0; i < glyphs.length; i++) {
  48937. var glyph = glyphs[i];
  48938. var vMetricX = null;
  48939. var vMetricY = null;
  48940. var glyphWidth = null;
  48941. if (font.vertical) {
  48942. if (glyph.vmetric) {
  48943. glyphWidth = glyph.vmetric[0];
  48944. vMetricX = glyph.vmetric[1];
  48945. vMetricY = glyph.vmetric[2];
  48946. } else {
  48947. glyphWidth = glyph.width;
  48948. vMetricX = glyph.width * 0.5;
  48949. vMetricY = defaultVMetrics[2];
  48950. }
  48951. } else {
  48952. glyphWidth = glyph.width;
  48953. }
  48954. var glyphUnicode = glyph.unicode;
  48955. var NormalizedUnicodes = getNormalizedUnicodes();
  48956. if (NormalizedUnicodes[glyphUnicode] !== undefined) {
  48957. glyphUnicode = NormalizedUnicodes[glyphUnicode];
  48958. }
  48959. glyphUnicode = reverseIfRtl(glyphUnicode);
  48960. // The following will calculate the x and y of the individual glyphs.
  48961. // if (font.vertical) {
  48962. // tsm[4] -= vMetricX * Math.abs(textState.fontSize) *
  48963. // textState.fontMatrix[0];
  48964. // tsm[5] -= vMetricY * textState.fontSize *
  48965. // textState.fontMatrix[0];
  48966. // }
  48967. // var trm = Util.transform(textState.textMatrix, tsm);
  48968. // var pt = Util.applyTransform([trm[4], trm[5]], textState.ctm);
  48969. // var x = pt[0];
  48970. // var y = pt[1];
  48971. var charSpacing = textState.charSpacing;
  48972. if (glyph.isSpace) {
  48973. var wordSpacing = textState.wordSpacing;
  48974. charSpacing += wordSpacing;
  48975. if (wordSpacing > 0) {
  48976. addFakeSpaces(wordSpacing, textChunk.str);
  48977. }
  48978. }
  48979. var tx = 0;
  48980. var ty = 0;
  48981. if (!font.vertical) {
  48982. var w0 = glyphWidth * textState.fontMatrix[0];
  48983. tx = (w0 * textState.fontSize + charSpacing) * textState.textHScale;
  48984. width += tx;
  48985. } else {
  48986. var w1 = glyphWidth * textState.fontMatrix[0];
  48987. ty = w1 * textState.fontSize + charSpacing;
  48988. height += ty;
  48989. }
  48990. textState.translateTextMatrix(tx, ty);
  48991. textChunk.str.push(glyphUnicode);
  48992. }
  48993. if (!font.vertical) {
  48994. textChunk.lastAdvanceWidth = width;
  48995. textChunk.width += width * textChunk.textAdvanceScale;
  48996. } else {
  48997. textChunk.lastAdvanceHeight = height;
  48998. textChunk.height += Math.abs(height * textChunk.textAdvanceScale);
  48999. }
  49000. return textChunk;
  49001. }
  49002. function addFakeSpaces(width, strBuf) {
  49003. if (width < textContentItem.fakeSpaceMin) {
  49004. return;
  49005. }
  49006. if (width < textContentItem.fakeMultiSpaceMin) {
  49007. strBuf.push(' ');
  49008. return;
  49009. }
  49010. var fakeSpaces = Math.round(width / textContentItem.spaceWidth);
  49011. while (fakeSpaces-- > 0) {
  49012. strBuf.push(' ');
  49013. }
  49014. }
  49015. function flushTextContentItem() {
  49016. if (!textContentItem.initialized) {
  49017. return;
  49018. }
  49019. textContent.items.push(runBidiTransform(textContentItem));
  49020. textContentItem.initialized = false;
  49021. textContentItem.str.length = 0;
  49022. }
  49023. var timeSlotManager = new TimeSlotManager();
  49024. return new Promise(function promiseBody(resolve, reject) {
  49025. var next = function (promise) {
  49026. promise.then(function () {
  49027. try {
  49028. promiseBody(resolve, reject);
  49029. } catch (ex) {
  49030. reject(ex);
  49031. }
  49032. }, reject);
  49033. };
  49034. task.ensureNotTerminated();
  49035. timeSlotManager.reset();
  49036. var stop, operation = {}, args = [];
  49037. while (!(stop = timeSlotManager.check())) {
  49038. // The arguments parsed by read() are not used beyond this loop, so
  49039. // we can reuse the same array on every iteration, thus avoiding
  49040. // unnecessary allocations.
  49041. args.length = 0;
  49042. operation.args = args;
  49043. if (!preprocessor.read(operation)) {
  49044. break;
  49045. }
  49046. textState = stateManager.state;
  49047. var fn = operation.fn;
  49048. args = operation.args;
  49049. var advance, diff;
  49050. switch (fn | 0) {
  49051. case OPS.setFont:
  49052. // Optimization to ignore multiple identical Tf commands.
  49053. var fontNameArg = args[0].name, fontSizeArg = args[1];
  49054. if (textState.font && fontNameArg === textState.fontName && fontSizeArg === textState.fontSize) {
  49055. break;
  49056. }
  49057. flushTextContentItem();
  49058. textState.fontName = fontNameArg;
  49059. textState.fontSize = fontSizeArg;
  49060. next(handleSetFont(fontNameArg, null));
  49061. return;
  49062. case OPS.setTextRise:
  49063. flushTextContentItem();
  49064. textState.textRise = args[0];
  49065. break;
  49066. case OPS.setHScale:
  49067. flushTextContentItem();
  49068. textState.textHScale = args[0] / 100;
  49069. break;
  49070. case OPS.setLeading:
  49071. flushTextContentItem();
  49072. textState.leading = args[0];
  49073. break;
  49074. case OPS.moveText:
  49075. // Optimization to treat same line movement as advance
  49076. var isSameTextLine = !textState.font ? false : (textState.font.vertical ? args[0] : args[1]) === 0;
  49077. advance = args[0] - args[1];
  49078. if (combineTextItems && isSameTextLine && textContentItem.initialized && advance > 0 && advance <= textContentItem.fakeMultiSpaceMax) {
  49079. textState.translateTextLineMatrix(args[0], args[1]);
  49080. textContentItem.width += args[0] - textContentItem.lastAdvanceWidth;
  49081. textContentItem.height += args[1] - textContentItem.lastAdvanceHeight;
  49082. diff = args[0] - textContentItem.lastAdvanceWidth - (args[1] - textContentItem.lastAdvanceHeight);
  49083. addFakeSpaces(diff, textContentItem.str);
  49084. break;
  49085. }
  49086. flushTextContentItem();
  49087. textState.translateTextLineMatrix(args[0], args[1]);
  49088. textState.textMatrix = textState.textLineMatrix.slice();
  49089. break;
  49090. case OPS.setLeadingMoveText:
  49091. flushTextContentItem();
  49092. textState.leading = -args[1];
  49093. textState.translateTextLineMatrix(args[0], args[1]);
  49094. textState.textMatrix = textState.textLineMatrix.slice();
  49095. break;
  49096. case OPS.nextLine:
  49097. flushTextContentItem();
  49098. textState.carriageReturn();
  49099. break;
  49100. case OPS.setTextMatrix:
  49101. // Optimization to treat same line movement as advance.
  49102. advance = textState.calcTextLineMatrixAdvance(args[0], args[1], args[2], args[3], args[4], args[5]);
  49103. if (combineTextItems && advance !== null && textContentItem.initialized && advance.value > 0 && advance.value <= textContentItem.fakeMultiSpaceMax) {
  49104. textState.translateTextLineMatrix(advance.width, advance.height);
  49105. textContentItem.width += advance.width - textContentItem.lastAdvanceWidth;
  49106. textContentItem.height += advance.height - textContentItem.lastAdvanceHeight;
  49107. diff = advance.width - textContentItem.lastAdvanceWidth - (advance.height - textContentItem.lastAdvanceHeight);
  49108. addFakeSpaces(diff, textContentItem.str);
  49109. break;
  49110. }
  49111. flushTextContentItem();
  49112. textState.setTextMatrix(args[0], args[1], args[2], args[3], args[4], args[5]);
  49113. textState.setTextLineMatrix(args[0], args[1], args[2], args[3], args[4], args[5]);
  49114. break;
  49115. case OPS.setCharSpacing:
  49116. textState.charSpacing = args[0];
  49117. break;
  49118. case OPS.setWordSpacing:
  49119. textState.wordSpacing = args[0];
  49120. break;
  49121. case OPS.beginText:
  49122. flushTextContentItem();
  49123. textState.textMatrix = IDENTITY_MATRIX.slice();
  49124. textState.textLineMatrix = IDENTITY_MATRIX.slice();
  49125. break;
  49126. case OPS.showSpacedText:
  49127. var items = args[0];
  49128. var offset;
  49129. for (var j = 0, jj = items.length; j < jj; j++) {
  49130. if (typeof items[j] === 'string') {
  49131. buildTextContentItem(items[j]);
  49132. } else if (isNum(items[j])) {
  49133. ensureTextContentItem();
  49134. // PDF Specification 5.3.2 states:
  49135. // The number is expressed in thousandths of a unit of text
  49136. // space.
  49137. // This amount is subtracted from the current horizontal or
  49138. // vertical coordinate, depending on the writing mode.
  49139. // In the default coordinate system, a positive adjustment
  49140. // has the effect of moving the next glyph painted either to
  49141. // the left or down by the given amount.
  49142. advance = items[j] * textState.fontSize / 1000;
  49143. var breakTextRun = false;
  49144. if (textState.font.vertical) {
  49145. offset = advance * (textState.textHScale * textState.textMatrix[2] + textState.textMatrix[3]);
  49146. textState.translateTextMatrix(0, advance);
  49147. breakTextRun = textContentItem.textRunBreakAllowed && advance > textContentItem.fakeMultiSpaceMax;
  49148. if (!breakTextRun) {
  49149. // Value needs to be added to height to paint down.
  49150. textContentItem.height += offset;
  49151. }
  49152. } else {
  49153. advance = -advance;
  49154. offset = advance * (textState.textHScale * textState.textMatrix[0] + textState.textMatrix[1]);
  49155. textState.translateTextMatrix(advance, 0);
  49156. breakTextRun = textContentItem.textRunBreakAllowed && advance > textContentItem.fakeMultiSpaceMax;
  49157. if (!breakTextRun) {
  49158. // Value needs to be subtracted from width to paint left.
  49159. textContentItem.width += offset;
  49160. }
  49161. }
  49162. if (breakTextRun) {
  49163. flushTextContentItem();
  49164. } else if (advance > 0) {
  49165. addFakeSpaces(advance, textContentItem.str);
  49166. }
  49167. }
  49168. }
  49169. break;
  49170. case OPS.showText:
  49171. buildTextContentItem(args[0]);
  49172. break;
  49173. case OPS.nextLineShowText:
  49174. flushTextContentItem();
  49175. textState.carriageReturn();
  49176. buildTextContentItem(args[0]);
  49177. break;
  49178. case OPS.nextLineSetSpacingShowText:
  49179. flushTextContentItem();
  49180. textState.wordSpacing = args[0];
  49181. textState.charSpacing = args[1];
  49182. textState.carriageReturn();
  49183. buildTextContentItem(args[2]);
  49184. break;
  49185. case OPS.paintXObject:
  49186. flushTextContentItem();
  49187. if (args[0].code) {
  49188. break;
  49189. }
  49190. if (!xobjs) {
  49191. xobjs = resources.get('XObject') || Dict.empty;
  49192. }
  49193. var name = args[0].name;
  49194. if (xobjsCache.key === name) {
  49195. if (xobjsCache.texts) {
  49196. Util.appendToArray(textContent.items, xobjsCache.texts.items);
  49197. Util.extendObj(textContent.styles, xobjsCache.texts.styles);
  49198. }
  49199. break;
  49200. }
  49201. var xobj = xobjs.get(name);
  49202. if (!xobj) {
  49203. break;
  49204. }
  49205. assert(isStream(xobj), 'XObject should be a stream');
  49206. var type = xobj.dict.get('Subtype');
  49207. assert(isName(type), 'XObject should have a Name subtype');
  49208. if ('Form' !== type.name) {
  49209. xobjsCache.key = name;
  49210. xobjsCache.texts = null;
  49211. break;
  49212. }
  49213. stateManager.save();
  49214. var matrix = xobj.dict.getArray('Matrix');
  49215. if (isArray(matrix) && matrix.length === 6) {
  49216. stateManager.transform(matrix);
  49217. }
  49218. next(self.getTextContent(xobj, task, xobj.dict.get('Resources') || resources, stateManager, normalizeWhitespace, combineTextItems).then(function (formTextContent) {
  49219. Util.appendToArray(textContent.items, formTextContent.items);
  49220. Util.extendObj(textContent.styles, formTextContent.styles);
  49221. stateManager.restore();
  49222. xobjsCache.key = name;
  49223. xobjsCache.texts = formTextContent;
  49224. }));
  49225. return;
  49226. case OPS.setGState:
  49227. flushTextContentItem();
  49228. var dictName = args[0];
  49229. var extGState = resources.get('ExtGState');
  49230. if (!isDict(extGState) || !isName(dictName)) {
  49231. break;
  49232. }
  49233. var gState = extGState.get(dictName.name);
  49234. if (!isDict(gState)) {
  49235. break;
  49236. }
  49237. var gStateFont = gState.get('Font');
  49238. if (gStateFont) {
  49239. textState.fontName = null;
  49240. textState.fontSize = gStateFont[1];
  49241. next(handleSetFont(null, gStateFont[0]));
  49242. return;
  49243. }
  49244. break;
  49245. }
  49246. }
  49247. // switch
  49248. // while
  49249. if (stop) {
  49250. next(deferred);
  49251. return;
  49252. }
  49253. flushTextContentItem();
  49254. resolve(textContent);
  49255. });
  49256. },
  49257. extractDataStructures: function PartialEvaluator_extractDataStructures(dict, baseDict, xref, properties) {
  49258. // 9.10.2
  49259. var toUnicode = dict.get('ToUnicode') || baseDict.get('ToUnicode');
  49260. var toUnicodePromise = toUnicode ? this.readToUnicode(toUnicode) : Promise.resolve(undefined);
  49261. if (properties.composite) {
  49262. // CIDSystemInfo helps to match CID to glyphs
  49263. var cidSystemInfo = dict.get('CIDSystemInfo');
  49264. if (isDict(cidSystemInfo)) {
  49265. properties.cidSystemInfo = {
  49266. registry: cidSystemInfo.get('Registry'),
  49267. ordering: cidSystemInfo.get('Ordering'),
  49268. supplement: cidSystemInfo.get('Supplement')
  49269. };
  49270. }
  49271. var cidToGidMap = dict.get('CIDToGIDMap');
  49272. if (isStream(cidToGidMap)) {
  49273. properties.cidToGidMap = this.readCidToGidMap(cidToGidMap);
  49274. }
  49275. }
  49276. // Based on 9.6.6 of the spec the encoding can come from multiple places
  49277. // and depends on the font type. The base encoding and differences are
  49278. // read here, but the encoding that is actually used is chosen during
  49279. // glyph mapping in the font.
  49280. // TODO: Loading the built in encoding in the font would allow the
  49281. // differences to be merged in here not require us to hold on to it.
  49282. var differences = [];
  49283. var baseEncodingName = null;
  49284. var encoding;
  49285. if (dict.has('Encoding')) {
  49286. encoding = dict.get('Encoding');
  49287. if (isDict(encoding)) {
  49288. baseEncodingName = encoding.get('BaseEncoding');
  49289. baseEncodingName = isName(baseEncodingName) ? baseEncodingName.name : null;
  49290. // Load the differences between the base and original
  49291. if (encoding.has('Differences')) {
  49292. var diffEncoding = encoding.get('Differences');
  49293. var index = 0;
  49294. for (var j = 0, jj = diffEncoding.length; j < jj; j++) {
  49295. var data = xref.fetchIfRef(diffEncoding[j]);
  49296. if (isNum(data)) {
  49297. index = data;
  49298. } else if (isName(data)) {
  49299. differences[index++] = data.name;
  49300. } else {
  49301. error('Invalid entry in \'Differences\' array: ' + data);
  49302. }
  49303. }
  49304. }
  49305. } else if (isName(encoding)) {
  49306. baseEncodingName = encoding.name;
  49307. } else {
  49308. error('Encoding is not a Name nor a Dict');
  49309. }
  49310. // According to table 114 if the encoding is a named encoding it must be
  49311. // one of these predefined encodings.
  49312. if (baseEncodingName !== 'MacRomanEncoding' && baseEncodingName !== 'MacExpertEncoding' && baseEncodingName !== 'WinAnsiEncoding') {
  49313. baseEncodingName = null;
  49314. }
  49315. }
  49316. if (baseEncodingName) {
  49317. properties.defaultEncoding = getEncoding(baseEncodingName).slice();
  49318. } else {
  49319. encoding = properties.type === 'TrueType' ? WinAnsiEncoding : StandardEncoding;
  49320. // The Symbolic attribute can be misused for regular fonts
  49321. // Heuristic: we have to check if the font is a standard one also
  49322. if (!!(properties.flags & FontFlags.Symbolic)) {
  49323. encoding = MacRomanEncoding;
  49324. if (!properties.file) {
  49325. if (/Symbol/i.test(properties.name)) {
  49326. encoding = SymbolSetEncoding;
  49327. } else if (/Dingbats/i.test(properties.name)) {
  49328. encoding = ZapfDingbatsEncoding;
  49329. }
  49330. }
  49331. }
  49332. properties.defaultEncoding = encoding;
  49333. }
  49334. properties.differences = differences;
  49335. properties.baseEncodingName = baseEncodingName;
  49336. properties.hasEncoding = !!baseEncodingName || differences.length > 0;
  49337. properties.dict = dict;
  49338. return toUnicodePromise.then(function (toUnicode) {
  49339. properties.toUnicode = toUnicode;
  49340. return this.buildToUnicode(properties);
  49341. }.bind(this)).then(function (toUnicode) {
  49342. properties.toUnicode = toUnicode;
  49343. return properties;
  49344. });
  49345. },
  49346. /**
  49347. * Builds a char code to unicode map based on section 9.10 of the spec.
  49348. * @param {Object} properties Font properties object.
  49349. * @return {Promise} A Promise that is resolved with a
  49350. * {ToUnicodeMap|IdentityToUnicodeMap} object.
  49351. */
  49352. buildToUnicode: function PartialEvaluator_buildToUnicode(properties) {
  49353. properties.hasIncludedToUnicodeMap = !!properties.toUnicode && properties.toUnicode.length > 0;
  49354. // Section 9.10.2 Mapping Character Codes to Unicode Values
  49355. if (properties.hasIncludedToUnicodeMap) {
  49356. return Promise.resolve(properties.toUnicode);
  49357. }
  49358. // According to the spec if the font is a simple font we should only map
  49359. // to unicode if the base encoding is MacRoman, MacExpert, or WinAnsi or
  49360. // the differences array only contains adobe standard or symbol set names,
  49361. // in pratice it seems better to always try to create a toUnicode
  49362. // map based of the default encoding.
  49363. var toUnicode, charcode, glyphName;
  49364. if (!properties.composite)
  49365. /* is simple font */
  49366. {
  49367. toUnicode = [];
  49368. var encoding = properties.defaultEncoding.slice();
  49369. var baseEncodingName = properties.baseEncodingName;
  49370. // Merge in the differences array.
  49371. var differences = properties.differences;
  49372. for (charcode in differences) {
  49373. glyphName = differences[charcode];
  49374. if (glyphName === '.notdef') {
  49375. // Skip .notdef to prevent rendering errors, e.g. boxes appearing
  49376. // where there should be spaces (fixes issue5256.pdf).
  49377. continue;
  49378. }
  49379. encoding[charcode] = glyphName;
  49380. }
  49381. var glyphsUnicodeMap = getGlyphsUnicode();
  49382. for (charcode in encoding) {
  49383. // a) Map the character code to a character name.
  49384. glyphName = encoding[charcode];
  49385. // b) Look up the character name in the Adobe Glyph List (see the
  49386. // Bibliography) to obtain the corresponding Unicode value.
  49387. if (glyphName === '') {
  49388. continue;
  49389. } else if (glyphsUnicodeMap[glyphName] === undefined) {
  49390. // (undocumented) c) Few heuristics to recognize unknown glyphs
  49391. // NOTE: Adobe Reader does not do this step, but OSX Preview does
  49392. var code = 0;
  49393. switch (glyphName[0]) {
  49394. case 'G':
  49395. // Gxx glyph
  49396. if (glyphName.length === 3) {
  49397. code = parseInt(glyphName.substr(1), 16);
  49398. }
  49399. break;
  49400. case 'g':
  49401. // g00xx glyph
  49402. if (glyphName.length === 5) {
  49403. code = parseInt(glyphName.substr(1), 16);
  49404. }
  49405. break;
  49406. case 'C':
  49407. // Cddd glyph
  49408. case 'c':
  49409. // cddd glyph
  49410. if (glyphName.length >= 3) {
  49411. code = +glyphName.substr(1);
  49412. }
  49413. break;
  49414. default:
  49415. // 'uniXXXX'/'uXXXX{XX}' glyphs
  49416. var unicode = getUnicodeForGlyph(glyphName, glyphsUnicodeMap);
  49417. if (unicode !== -1) {
  49418. code = unicode;
  49419. }
  49420. }
  49421. if (code) {
  49422. // If |baseEncodingName| is one the predefined encodings,
  49423. // and |code| equals |charcode|, using the glyph defined in the
  49424. // baseEncoding seems to yield a better |toUnicode| mapping
  49425. // (fixes issue 5070).
  49426. if (baseEncodingName && code === +charcode) {
  49427. var baseEncoding = getEncoding(baseEncodingName);
  49428. if (baseEncoding && (glyphName = baseEncoding[charcode])) {
  49429. toUnicode[charcode] = String.fromCharCode(glyphsUnicodeMap[glyphName]);
  49430. continue;
  49431. }
  49432. }
  49433. toUnicode[charcode] = String.fromCharCode(code);
  49434. }
  49435. continue;
  49436. }
  49437. toUnicode[charcode] = String.fromCharCode(glyphsUnicodeMap[glyphName]);
  49438. }
  49439. return Promise.resolve(new ToUnicodeMap(toUnicode));
  49440. }
  49441. // If the font is a composite font that uses one of the predefined CMaps
  49442. // listed in Table 118 (except Identity–H and Identity–V) or whose
  49443. // descendant CIDFont uses the Adobe-GB1, Adobe-CNS1, Adobe-Japan1, or
  49444. // Adobe-Korea1 character collection:
  49445. 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'))) {
  49446. // Then:
  49447. // a) Map the character code to a character identifier (CID) according
  49448. // to the font’s CMap.
  49449. // b) Obtain the registry and ordering of the character collection used
  49450. // by the font’s CMap (for example, Adobe and Japan1) from its
  49451. // CIDSystemInfo dictionary.
  49452. var registry = properties.cidSystemInfo.registry;
  49453. var ordering = properties.cidSystemInfo.ordering;
  49454. // c) Construct a second CMap name by concatenating the registry and
  49455. // ordering obtained in step (b) in the format registry–ordering–UCS2
  49456. // (for example, Adobe–Japan1–UCS2).
  49457. var ucs2CMapName = Name.get(registry + '-' + ordering + '-UCS2');
  49458. // d) Obtain the CMap with the name constructed in step (c) (available
  49459. // from the ASN Web site; see the Bibliography).
  49460. return CMapFactory.create(ucs2CMapName, this.options.cMapOptions, null).then(function (ucs2CMap) {
  49461. var cMap = properties.cMap;
  49462. toUnicode = [];
  49463. cMap.forEach(function (charcode, cid) {
  49464. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  49465. // e) Map the CID obtained in step (a) according to the CMap
  49466. // obtained in step (d), producing a Unicode value.
  49467. var ucs2 = ucs2CMap.lookup(cid);
  49468. if (ucs2) {
  49469. toUnicode[charcode] = String.fromCharCode((ucs2.charCodeAt(0) << 8) + ucs2.charCodeAt(1));
  49470. }
  49471. });
  49472. return new ToUnicodeMap(toUnicode);
  49473. });
  49474. }
  49475. // The viewer's choice, just use an identity map.
  49476. return Promise.resolve(new IdentityToUnicodeMap(properties.firstChar, properties.lastChar));
  49477. },
  49478. readToUnicode: function PartialEvaluator_readToUnicode(toUnicode) {
  49479. var cmapObj = toUnicode;
  49480. if (isName(cmapObj)) {
  49481. return CMapFactory.create(cmapObj, this.options.cMapOptions, null).then(function (cmap) {
  49482. if (cmap instanceof IdentityCMap) {
  49483. return new IdentityToUnicodeMap(0, 0xFFFF);
  49484. }
  49485. return new ToUnicodeMap(cmap.getMap());
  49486. });
  49487. } else if (isStream(cmapObj)) {
  49488. return CMapFactory.create(cmapObj, this.options.cMapOptions, null).then(function (cmap) {
  49489. if (cmap instanceof IdentityCMap) {
  49490. return new IdentityToUnicodeMap(0, 0xFFFF);
  49491. }
  49492. var map = new Array(cmap.length);
  49493. // Convert UTF-16BE
  49494. // NOTE: cmap can be a sparse array, so use forEach instead of for(;;)
  49495. // to iterate over all keys.
  49496. cmap.forEach(function (charCode, token) {
  49497. var str = [];
  49498. for (var k = 0; k < token.length; k += 2) {
  49499. var w1 = token.charCodeAt(k) << 8 | token.charCodeAt(k + 1);
  49500. if ((w1 & 0xF800) !== 0xD800) {
  49501. // w1 < 0xD800 || w1 > 0xDFFF
  49502. str.push(w1);
  49503. continue;
  49504. }
  49505. k += 2;
  49506. var w2 = token.charCodeAt(k) << 8 | token.charCodeAt(k + 1);
  49507. str.push(((w1 & 0x3ff) << 10) + (w2 & 0x3ff) + 0x10000);
  49508. }
  49509. map[charCode] = String.fromCharCode.apply(String, str);
  49510. });
  49511. return new ToUnicodeMap(map);
  49512. });
  49513. }
  49514. return Promise.resolve(null);
  49515. },
  49516. readCidToGidMap: function PartialEvaluator_readCidToGidMap(cidToGidStream) {
  49517. // Extract the encoding from the CIDToGIDMap
  49518. var glyphsData = cidToGidStream.getBytes();
  49519. // Set encoding 0 to later verify the font has an encoding
  49520. var result = [];
  49521. for (var j = 0, jj = glyphsData.length; j < jj; j++) {
  49522. var glyphID = glyphsData[j++] << 8 | glyphsData[j];
  49523. if (glyphID === 0) {
  49524. continue;
  49525. }
  49526. var code = j >> 1;
  49527. result[code] = glyphID;
  49528. }
  49529. return result;
  49530. },
  49531. extractWidths: function PartialEvaluator_extractWidths(dict, xref, descriptor, properties) {
  49532. var glyphsWidths = [];
  49533. var defaultWidth = 0;
  49534. var glyphsVMetrics = [];
  49535. var defaultVMetrics;
  49536. var i, ii, j, jj, start, code, widths;
  49537. if (properties.composite) {
  49538. defaultWidth = dict.get('DW') || 1000;
  49539. widths = dict.get('W');
  49540. if (widths) {
  49541. for (i = 0, ii = widths.length; i < ii; i++) {
  49542. start = widths[i++];
  49543. code = xref.fetchIfRef(widths[i]);
  49544. if (isArray(code)) {
  49545. for (j = 0, jj = code.length; j < jj; j++) {
  49546. glyphsWidths[start++] = code[j];
  49547. }
  49548. } else {
  49549. var width = widths[++i];
  49550. for (j = start; j <= code; j++) {
  49551. glyphsWidths[j] = width;
  49552. }
  49553. }
  49554. }
  49555. }
  49556. if (properties.vertical) {
  49557. var vmetrics = dict.get('DW2') || [
  49558. 880,
  49559. -1000
  49560. ];
  49561. defaultVMetrics = [
  49562. vmetrics[1],
  49563. defaultWidth * 0.5,
  49564. vmetrics[0]
  49565. ];
  49566. vmetrics = dict.get('W2');
  49567. if (vmetrics) {
  49568. for (i = 0, ii = vmetrics.length; i < ii; i++) {
  49569. start = vmetrics[i++];
  49570. code = xref.fetchIfRef(vmetrics[i]);
  49571. if (isArray(code)) {
  49572. for (j = 0, jj = code.length; j < jj; j++) {
  49573. glyphsVMetrics[start++] = [
  49574. code[j++],
  49575. code[j++],
  49576. code[j]
  49577. ];
  49578. }
  49579. } else {
  49580. var vmetric = [
  49581. vmetrics[++i],
  49582. vmetrics[++i],
  49583. vmetrics[++i]
  49584. ];
  49585. for (j = start; j <= code; j++) {
  49586. glyphsVMetrics[j] = vmetric;
  49587. }
  49588. }
  49589. }
  49590. }
  49591. }
  49592. } else {
  49593. var firstChar = properties.firstChar;
  49594. widths = dict.get('Widths');
  49595. if (widths) {
  49596. j = firstChar;
  49597. for (i = 0, ii = widths.length; i < ii; i++) {
  49598. glyphsWidths[j++] = widths[i];
  49599. }
  49600. defaultWidth = parseFloat(descriptor.get('MissingWidth')) || 0;
  49601. } else {
  49602. // Trying get the BaseFont metrics (see comment above).
  49603. var baseFontName = dict.get('BaseFont');
  49604. if (isName(baseFontName)) {
  49605. var metrics = this.getBaseFontMetrics(baseFontName.name);
  49606. glyphsWidths = this.buildCharCodeToWidth(metrics.widths, properties);
  49607. defaultWidth = metrics.defaultWidth;
  49608. }
  49609. }
  49610. }
  49611. // Heuristic: detection of monospace font by checking all non-zero widths
  49612. var isMonospace = true;
  49613. var firstWidth = defaultWidth;
  49614. for (var glyph in glyphsWidths) {
  49615. var glyphWidth = glyphsWidths[glyph];
  49616. if (!glyphWidth) {
  49617. continue;
  49618. }
  49619. if (!firstWidth) {
  49620. firstWidth = glyphWidth;
  49621. continue;
  49622. }
  49623. if (firstWidth !== glyphWidth) {
  49624. isMonospace = false;
  49625. break;
  49626. }
  49627. }
  49628. if (isMonospace) {
  49629. properties.flags |= FontFlags.FixedPitch;
  49630. }
  49631. properties.defaultWidth = defaultWidth;
  49632. properties.widths = glyphsWidths;
  49633. properties.defaultVMetrics = defaultVMetrics;
  49634. properties.vmetrics = glyphsVMetrics;
  49635. },
  49636. isSerifFont: function PartialEvaluator_isSerifFont(baseFontName) {
  49637. // Simulating descriptor flags attribute
  49638. var fontNameWoStyle = baseFontName.split('-')[0];
  49639. return fontNameWoStyle in getSerifFonts() || fontNameWoStyle.search(/serif/gi) !== -1;
  49640. },
  49641. getBaseFontMetrics: function PartialEvaluator_getBaseFontMetrics(name) {
  49642. var defaultWidth = 0;
  49643. var widths = [];
  49644. var monospace = false;
  49645. var stdFontMap = getStdFontMap();
  49646. var lookupName = stdFontMap[name] || name;
  49647. var Metrics = getMetrics();
  49648. if (!(lookupName in Metrics)) {
  49649. // Use default fonts for looking up font metrics if the passed
  49650. // font is not a base font
  49651. if (this.isSerifFont(name)) {
  49652. lookupName = 'Times-Roman';
  49653. } else {
  49654. lookupName = 'Helvetica';
  49655. }
  49656. }
  49657. var glyphWidths = Metrics[lookupName];
  49658. if (isNum(glyphWidths)) {
  49659. defaultWidth = glyphWidths;
  49660. monospace = true;
  49661. } else {
  49662. widths = glyphWidths();
  49663. }
  49664. // expand lazy widths array
  49665. return {
  49666. defaultWidth: defaultWidth,
  49667. monospace: monospace,
  49668. widths: widths
  49669. };
  49670. },
  49671. buildCharCodeToWidth: function PartialEvaluator_bulildCharCodeToWidth(widthsByGlyphName, properties) {
  49672. var widths = Object.create(null);
  49673. var differences = properties.differences;
  49674. var encoding = properties.defaultEncoding;
  49675. for (var charCode = 0; charCode < 256; charCode++) {
  49676. if (charCode in differences && widthsByGlyphName[differences[charCode]]) {
  49677. widths[charCode] = widthsByGlyphName[differences[charCode]];
  49678. continue;
  49679. }
  49680. if (charCode in encoding && widthsByGlyphName[encoding[charCode]]) {
  49681. widths[charCode] = widthsByGlyphName[encoding[charCode]];
  49682. continue;
  49683. }
  49684. }
  49685. return widths;
  49686. },
  49687. preEvaluateFont: function PartialEvaluator_preEvaluateFont(dict, xref) {
  49688. var baseDict = dict;
  49689. var type = dict.get('Subtype');
  49690. assert(isName(type), 'invalid font Subtype');
  49691. var composite = false;
  49692. var uint8array;
  49693. if (type.name === 'Type0') {
  49694. // If font is a composite
  49695. // - get the descendant font
  49696. // - set the type according to the descendant font
  49697. // - get the FontDescriptor from the descendant font
  49698. var df = dict.get('DescendantFonts');
  49699. if (!df) {
  49700. error('Descendant fonts are not specified');
  49701. }
  49702. dict = isArray(df) ? xref.fetchIfRef(df[0]) : df;
  49703. type = dict.get('Subtype');
  49704. assert(isName(type), 'invalid font Subtype');
  49705. composite = true;
  49706. }
  49707. var descriptor = dict.get('FontDescriptor');
  49708. if (descriptor) {
  49709. var hash = new MurmurHash3_64();
  49710. var encoding = baseDict.getRaw('Encoding');
  49711. if (isName(encoding)) {
  49712. hash.update(encoding.name);
  49713. } else if (isRef(encoding)) {
  49714. hash.update(encoding.toString());
  49715. } else if (isDict(encoding)) {
  49716. var keys = encoding.getKeys();
  49717. for (var i = 0, ii = keys.length; i < ii; i++) {
  49718. var entry = encoding.getRaw(keys[i]);
  49719. if (isName(entry)) {
  49720. hash.update(entry.name);
  49721. } else if (isRef(entry)) {
  49722. hash.update(entry.toString());
  49723. } else if (isArray(entry)) {
  49724. // 'Differences' entry.
  49725. // Ideally we should check the contents of the array, but to avoid
  49726. // parsing it here and then again in |extractDataStructures|,
  49727. // we only use the array length for now (fixes bug1157493.pdf).
  49728. hash.update(entry.length.toString());
  49729. }
  49730. }
  49731. }
  49732. var toUnicode = dict.get('ToUnicode') || baseDict.get('ToUnicode');
  49733. if (isStream(toUnicode)) {
  49734. var stream = toUnicode.str || toUnicode;
  49735. uint8array = stream.buffer ? new Uint8Array(stream.buffer.buffer, 0, stream.bufferLength) : new Uint8Array(stream.bytes.buffer, stream.start, stream.end - stream.start);
  49736. hash.update(uint8array);
  49737. } else if (isName(toUnicode)) {
  49738. hash.update(toUnicode.name);
  49739. }
  49740. var widths = dict.get('Widths') || baseDict.get('Widths');
  49741. if (widths) {
  49742. uint8array = new Uint8Array(new Uint32Array(widths).buffer);
  49743. hash.update(uint8array);
  49744. }
  49745. }
  49746. return {
  49747. descriptor: descriptor,
  49748. dict: dict,
  49749. baseDict: baseDict,
  49750. composite: composite,
  49751. type: type.name,
  49752. hash: hash ? hash.hexdigest() : ''
  49753. };
  49754. },
  49755. translateFont: function PartialEvaluator_translateFont(preEvaluatedFont, xref) {
  49756. var baseDict = preEvaluatedFont.baseDict;
  49757. var dict = preEvaluatedFont.dict;
  49758. var composite = preEvaluatedFont.composite;
  49759. var descriptor = preEvaluatedFont.descriptor;
  49760. var type = preEvaluatedFont.type;
  49761. var maxCharIndex = composite ? 0xFFFF : 0xFF;
  49762. var cMapOptions = this.options.cMapOptions;
  49763. var properties;
  49764. if (!descriptor) {
  49765. if (type === 'Type3') {
  49766. // FontDescriptor is only required for Type3 fonts when the document
  49767. // is a tagged pdf. Create a barbebones one to get by.
  49768. descriptor = new Dict(null);
  49769. descriptor.set('FontName', Name.get(type));
  49770. descriptor.set('FontBBox', dict.getArray('FontBBox'));
  49771. } else {
  49772. // Before PDF 1.5 if the font was one of the base 14 fonts, having a
  49773. // FontDescriptor was not required.
  49774. // This case is here for compatibility.
  49775. var baseFontName = dict.get('BaseFont');
  49776. if (!isName(baseFontName)) {
  49777. error('Base font is not specified');
  49778. }
  49779. // Using base font name as a font name.
  49780. baseFontName = baseFontName.name.replace(/[,_]/g, '-');
  49781. var metrics = this.getBaseFontMetrics(baseFontName);
  49782. // Simulating descriptor flags attribute
  49783. var fontNameWoStyle = baseFontName.split('-')[0];
  49784. var flags = (this.isSerifFont(fontNameWoStyle) ? FontFlags.Serif : 0) | (metrics.monospace ? FontFlags.FixedPitch : 0) | (getSymbolsFonts()[fontNameWoStyle] ? FontFlags.Symbolic : FontFlags.Nonsymbolic);
  49785. properties = {
  49786. type: type,
  49787. name: baseFontName,
  49788. widths: metrics.widths,
  49789. defaultWidth: metrics.defaultWidth,
  49790. flags: flags,
  49791. firstChar: 0,
  49792. lastChar: maxCharIndex
  49793. };
  49794. return this.extractDataStructures(dict, dict, xref, properties).then(function (properties) {
  49795. properties.widths = this.buildCharCodeToWidth(metrics.widths, properties);
  49796. return new Font(baseFontName, null, properties);
  49797. }.bind(this));
  49798. }
  49799. }
  49800. // According to the spec if 'FontDescriptor' is declared, 'FirstChar',
  49801. // 'LastChar' and 'Widths' should exist too, but some PDF encoders seem
  49802. // to ignore this rule when a variant of a standard font is used.
  49803. // TODO Fill the width array depending on which of the base font this is
  49804. // a variant.
  49805. var firstChar = dict.get('FirstChar') || 0;
  49806. var lastChar = dict.get('LastChar') || maxCharIndex;
  49807. var fontName = descriptor.get('FontName');
  49808. var baseFont = dict.get('BaseFont');
  49809. // Some bad PDFs have a string as the font name.
  49810. if (isString(fontName)) {
  49811. fontName = Name.get(fontName);
  49812. }
  49813. if (isString(baseFont)) {
  49814. baseFont = Name.get(baseFont);
  49815. }
  49816. if (type !== 'Type3') {
  49817. var fontNameStr = fontName && fontName.name;
  49818. var baseFontStr = baseFont && baseFont.name;
  49819. if (fontNameStr !== baseFontStr) {
  49820. info('The FontDescriptor\'s FontName is "' + fontNameStr + '" but should be the same as the Font\'s BaseFont "' + baseFontStr + '"');
  49821. // Workaround for cases where e.g. fontNameStr = 'Arial' and
  49822. // baseFontStr = 'Arial,Bold' (needed when no font file is embedded).
  49823. if (fontNameStr && baseFontStr && baseFontStr.indexOf(fontNameStr) === 0) {
  49824. fontName = baseFont;
  49825. }
  49826. }
  49827. }
  49828. fontName = fontName || baseFont;
  49829. assert(isName(fontName), 'invalid font name');
  49830. var fontFile = descriptor.get('FontFile', 'FontFile2', 'FontFile3');
  49831. if (fontFile) {
  49832. if (fontFile.dict) {
  49833. var subtype = fontFile.dict.get('Subtype');
  49834. if (subtype) {
  49835. subtype = subtype.name;
  49836. }
  49837. var length1 = fontFile.dict.get('Length1');
  49838. var length2 = fontFile.dict.get('Length2');
  49839. var length3 = fontFile.dict.get('Length3');
  49840. }
  49841. }
  49842. properties = {
  49843. type: type,
  49844. name: fontName.name,
  49845. subtype: subtype,
  49846. file: fontFile,
  49847. length1: length1,
  49848. length2: length2,
  49849. length3: length3,
  49850. loadedName: baseDict.loadedName,
  49851. composite: composite,
  49852. wideChars: composite,
  49853. fixedPitch: false,
  49854. fontMatrix: dict.getArray('FontMatrix') || FONT_IDENTITY_MATRIX,
  49855. firstChar: firstChar || 0,
  49856. lastChar: lastChar || maxCharIndex,
  49857. bbox: descriptor.getArray('FontBBox'),
  49858. ascent: descriptor.get('Ascent'),
  49859. descent: descriptor.get('Descent'),
  49860. xHeight: descriptor.get('XHeight'),
  49861. capHeight: descriptor.get('CapHeight'),
  49862. flags: descriptor.get('Flags'),
  49863. italicAngle: descriptor.get('ItalicAngle'),
  49864. coded: false
  49865. };
  49866. var cMapPromise;
  49867. if (composite) {
  49868. var cidEncoding = baseDict.get('Encoding');
  49869. if (isName(cidEncoding)) {
  49870. properties.cidEncoding = cidEncoding.name;
  49871. }
  49872. cMapPromise = CMapFactory.create(cidEncoding, cMapOptions, null).then(function (cMap) {
  49873. properties.cMap = cMap;
  49874. properties.vertical = properties.cMap.vertical;
  49875. });
  49876. } else {
  49877. cMapPromise = Promise.resolve(undefined);
  49878. }
  49879. return cMapPromise.then(function () {
  49880. return this.extractDataStructures(dict, baseDict, xref, properties);
  49881. }.bind(this)).then(function (properties) {
  49882. this.extractWidths(dict, xref, descriptor, properties);
  49883. if (type === 'Type3') {
  49884. properties.isType3Font = true;
  49885. }
  49886. return new Font(fontName.name, fontFile, properties);
  49887. }.bind(this));
  49888. }
  49889. };
  49890. return PartialEvaluator;
  49891. }();
  49892. var TranslatedFont = function TranslatedFontClosure() {
  49893. function TranslatedFont(loadedName, font, dict) {
  49894. this.loadedName = loadedName;
  49895. this.font = font;
  49896. this.dict = dict;
  49897. this.type3Loaded = null;
  49898. this.sent = false;
  49899. }
  49900. TranslatedFont.prototype = {
  49901. send: function (handler) {
  49902. if (this.sent) {
  49903. return;
  49904. }
  49905. var fontData = this.font.exportData();
  49906. handler.send('commonobj', [
  49907. this.loadedName,
  49908. 'Font',
  49909. fontData
  49910. ]);
  49911. this.sent = true;
  49912. },
  49913. loadType3Data: function (evaluator, resources, parentOperatorList, task) {
  49914. assert(this.font.isType3Font);
  49915. if (this.type3Loaded) {
  49916. return this.type3Loaded;
  49917. }
  49918. var translatedFont = this.font;
  49919. var loadCharProcsPromise = Promise.resolve();
  49920. var charProcs = this.dict.get('CharProcs');
  49921. var fontResources = this.dict.get('Resources') || resources;
  49922. var charProcKeys = charProcs.getKeys();
  49923. var charProcOperatorList = Object.create(null);
  49924. for (var i = 0, n = charProcKeys.length; i < n; ++i) {
  49925. loadCharProcsPromise = loadCharProcsPromise.then(function (key) {
  49926. var glyphStream = charProcs.get(key);
  49927. var operatorList = new OperatorList();
  49928. return evaluator.getOperatorList(glyphStream, task, fontResources, operatorList).then(function () {
  49929. charProcOperatorList[key] = operatorList.getIR();
  49930. // Add the dependencies to the parent operator list so they are
  49931. // resolved before sub operator list is executed synchronously.
  49932. parentOperatorList.addDependencies(operatorList.dependencies);
  49933. }, function (reason) {
  49934. warn('Type3 font resource \"' + key + '\" is not available');
  49935. var operatorList = new OperatorList();
  49936. charProcOperatorList[key] = operatorList.getIR();
  49937. });
  49938. }.bind(this, charProcKeys[i]));
  49939. }
  49940. this.type3Loaded = loadCharProcsPromise.then(function () {
  49941. translatedFont.charProcOperatorList = charProcOperatorList;
  49942. });
  49943. return this.type3Loaded;
  49944. }
  49945. };
  49946. return TranslatedFont;
  49947. }();
  49948. var OperatorList = function OperatorListClosure() {
  49949. var CHUNK_SIZE = 1000;
  49950. var CHUNK_SIZE_ABOUT = CHUNK_SIZE - 5;
  49951. // close to chunk size
  49952. function getTransfers(queue) {
  49953. var transfers = [];
  49954. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  49955. for (var i = 0, ii = queue.length; i < ii; i++) {
  49956. switch (fnArray[i]) {
  49957. case OPS.paintInlineImageXObject:
  49958. case OPS.paintInlineImageXObjectGroup:
  49959. case OPS.paintImageMaskXObject:
  49960. var arg = argsArray[i][0];
  49961. // first param in imgData
  49962. if (!arg.cached) {
  49963. transfers.push(arg.data.buffer);
  49964. }
  49965. break;
  49966. }
  49967. }
  49968. return transfers;
  49969. }
  49970. function OperatorList(intent, messageHandler, pageIndex) {
  49971. this.messageHandler = messageHandler;
  49972. this.fnArray = [];
  49973. this.argsArray = [];
  49974. this.dependencies = Object.create(null);
  49975. this._totalLength = 0;
  49976. this.pageIndex = pageIndex;
  49977. this.intent = intent;
  49978. }
  49979. OperatorList.prototype = {
  49980. get length() {
  49981. return this.argsArray.length;
  49982. },
  49983. /**
  49984. * @returns {number} The total length of the entire operator list,
  49985. * since `this.length === 0` after flushing.
  49986. */
  49987. get totalLength() {
  49988. return this._totalLength + this.length;
  49989. },
  49990. addOp: function (fn, args) {
  49991. this.fnArray.push(fn);
  49992. this.argsArray.push(args);
  49993. if (this.messageHandler) {
  49994. if (this.fnArray.length >= CHUNK_SIZE) {
  49995. this.flush();
  49996. } else if (this.fnArray.length >= CHUNK_SIZE_ABOUT && (fn === OPS.restore || fn === OPS.endText)) {
  49997. // heuristic to flush on boundary of restore or endText
  49998. this.flush();
  49999. }
  50000. }
  50001. },
  50002. addDependency: function (dependency) {
  50003. if (dependency in this.dependencies) {
  50004. return;
  50005. }
  50006. this.dependencies[dependency] = true;
  50007. this.addOp(OPS.dependency, [dependency]);
  50008. },
  50009. addDependencies: function (dependencies) {
  50010. for (var key in dependencies) {
  50011. this.addDependency(key);
  50012. }
  50013. },
  50014. addOpList: function (opList) {
  50015. Util.extendObj(this.dependencies, opList.dependencies);
  50016. for (var i = 0, ii = opList.length; i < ii; i++) {
  50017. this.addOp(opList.fnArray[i], opList.argsArray[i]);
  50018. }
  50019. },
  50020. getIR: function () {
  50021. return {
  50022. fnArray: this.fnArray,
  50023. argsArray: this.argsArray,
  50024. length: this.length
  50025. };
  50026. },
  50027. flush: function (lastChunk) {
  50028. if (this.intent !== 'oplist') {
  50029. new QueueOptimizer().optimize(this);
  50030. }
  50031. var transfers = getTransfers(this);
  50032. var length = this.length;
  50033. this._totalLength += length;
  50034. this.messageHandler.send('RenderPageChunk', {
  50035. operatorList: {
  50036. fnArray: this.fnArray,
  50037. argsArray: this.argsArray,
  50038. lastChunk: lastChunk,
  50039. length: length
  50040. },
  50041. pageIndex: this.pageIndex,
  50042. intent: this.intent
  50043. }, transfers);
  50044. this.dependencies = Object.create(null);
  50045. this.fnArray.length = 0;
  50046. this.argsArray.length = 0;
  50047. }
  50048. };
  50049. return OperatorList;
  50050. }();
  50051. var StateManager = function StateManagerClosure() {
  50052. function StateManager(initialState) {
  50053. this.state = initialState;
  50054. this.stateStack = [];
  50055. }
  50056. StateManager.prototype = {
  50057. save: function () {
  50058. var old = this.state;
  50059. this.stateStack.push(this.state);
  50060. this.state = old.clone();
  50061. },
  50062. restore: function () {
  50063. var prev = this.stateStack.pop();
  50064. if (prev) {
  50065. this.state = prev;
  50066. }
  50067. },
  50068. transform: function (args) {
  50069. this.state.ctm = Util.transform(this.state.ctm, args);
  50070. }
  50071. };
  50072. return StateManager;
  50073. }();
  50074. var TextState = function TextStateClosure() {
  50075. function TextState() {
  50076. this.ctm = new Float32Array(IDENTITY_MATRIX);
  50077. this.fontName = null;
  50078. this.fontSize = 0;
  50079. this.font = null;
  50080. this.fontMatrix = FONT_IDENTITY_MATRIX;
  50081. this.textMatrix = IDENTITY_MATRIX.slice();
  50082. this.textLineMatrix = IDENTITY_MATRIX.slice();
  50083. this.charSpacing = 0;
  50084. this.wordSpacing = 0;
  50085. this.leading = 0;
  50086. this.textHScale = 1;
  50087. this.textRise = 0;
  50088. }
  50089. TextState.prototype = {
  50090. setTextMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  50091. var m = this.textMatrix;
  50092. m[0] = a;
  50093. m[1] = b;
  50094. m[2] = c;
  50095. m[3] = d;
  50096. m[4] = e;
  50097. m[5] = f;
  50098. },
  50099. setTextLineMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  50100. var m = this.textLineMatrix;
  50101. m[0] = a;
  50102. m[1] = b;
  50103. m[2] = c;
  50104. m[3] = d;
  50105. m[4] = e;
  50106. m[5] = f;
  50107. },
  50108. translateTextMatrix: function TextState_translateTextMatrix(x, y) {
  50109. var m = this.textMatrix;
  50110. m[4] = m[0] * x + m[2] * y + m[4];
  50111. m[5] = m[1] * x + m[3] * y + m[5];
  50112. },
  50113. translateTextLineMatrix: function TextState_translateTextMatrix(x, y) {
  50114. var m = this.textLineMatrix;
  50115. m[4] = m[0] * x + m[2] * y + m[4];
  50116. m[5] = m[1] * x + m[3] * y + m[5];
  50117. },
  50118. calcTextLineMatrixAdvance: function TextState_calcTextLineMatrixAdvance(a, b, c, d, e, f) {
  50119. var font = this.font;
  50120. if (!font) {
  50121. return null;
  50122. }
  50123. var m = this.textLineMatrix;
  50124. if (!(a === m[0] && b === m[1] && c === m[2] && d === m[3])) {
  50125. return null;
  50126. }
  50127. var txDiff = e - m[4], tyDiff = f - m[5];
  50128. if (font.vertical && txDiff !== 0 || !font.vertical && tyDiff !== 0) {
  50129. return null;
  50130. }
  50131. var tx, ty, denominator = a * d - b * c;
  50132. if (font.vertical) {
  50133. tx = -tyDiff * c / denominator;
  50134. ty = tyDiff * a / denominator;
  50135. } else {
  50136. tx = txDiff * d / denominator;
  50137. ty = -txDiff * b / denominator;
  50138. }
  50139. return {
  50140. width: tx,
  50141. height: ty,
  50142. value: font.vertical ? ty : tx
  50143. };
  50144. },
  50145. calcRenderMatrix: function TextState_calcRendeMatrix(ctm) {
  50146. // 9.4.4 Text Space Details
  50147. var tsm = [
  50148. this.fontSize * this.textHScale,
  50149. 0,
  50150. 0,
  50151. this.fontSize,
  50152. 0,
  50153. this.textRise
  50154. ];
  50155. return Util.transform(ctm, Util.transform(this.textMatrix, tsm));
  50156. },
  50157. carriageReturn: function TextState_carriageReturn() {
  50158. this.translateTextLineMatrix(0, -this.leading);
  50159. this.textMatrix = this.textLineMatrix.slice();
  50160. },
  50161. clone: function TextState_clone() {
  50162. var clone = Object.create(this);
  50163. clone.textMatrix = this.textMatrix.slice();
  50164. clone.textLineMatrix = this.textLineMatrix.slice();
  50165. clone.fontMatrix = this.fontMatrix.slice();
  50166. return clone;
  50167. }
  50168. };
  50169. return TextState;
  50170. }();
  50171. var EvalState = function EvalStateClosure() {
  50172. function EvalState() {
  50173. this.ctm = new Float32Array(IDENTITY_MATRIX);
  50174. this.font = null;
  50175. this.textRenderingMode = TextRenderingMode.FILL;
  50176. this.fillColorSpace = ColorSpace.singletons.gray;
  50177. this.strokeColorSpace = ColorSpace.singletons.gray;
  50178. }
  50179. EvalState.prototype = {
  50180. clone: function CanvasExtraState_clone() {
  50181. return Object.create(this);
  50182. }
  50183. };
  50184. return EvalState;
  50185. }();
  50186. var EvaluatorPreprocessor = function EvaluatorPreprocessorClosure() {
  50187. // Specifies properties for each command
  50188. //
  50189. // If variableArgs === true: [0, `numArgs`] expected
  50190. // If variableArgs === false: exactly `numArgs` expected
  50191. var getOPMap = getLookupTableFactory(function (t) {
  50192. // Graphic state
  50193. t['w'] = {
  50194. id: OPS.setLineWidth,
  50195. numArgs: 1,
  50196. variableArgs: false
  50197. };
  50198. t['J'] = {
  50199. id: OPS.setLineCap,
  50200. numArgs: 1,
  50201. variableArgs: false
  50202. };
  50203. t['j'] = {
  50204. id: OPS.setLineJoin,
  50205. numArgs: 1,
  50206. variableArgs: false
  50207. };
  50208. t['M'] = {
  50209. id: OPS.setMiterLimit,
  50210. numArgs: 1,
  50211. variableArgs: false
  50212. };
  50213. t['d'] = {
  50214. id: OPS.setDash,
  50215. numArgs: 2,
  50216. variableArgs: false
  50217. };
  50218. t['ri'] = {
  50219. id: OPS.setRenderingIntent,
  50220. numArgs: 1,
  50221. variableArgs: false
  50222. };
  50223. t['i'] = {
  50224. id: OPS.setFlatness,
  50225. numArgs: 1,
  50226. variableArgs: false
  50227. };
  50228. t['gs'] = {
  50229. id: OPS.setGState,
  50230. numArgs: 1,
  50231. variableArgs: false
  50232. };
  50233. t['q'] = {
  50234. id: OPS.save,
  50235. numArgs: 0,
  50236. variableArgs: false
  50237. };
  50238. t['Q'] = {
  50239. id: OPS.restore,
  50240. numArgs: 0,
  50241. variableArgs: false
  50242. };
  50243. t['cm'] = {
  50244. id: OPS.transform,
  50245. numArgs: 6,
  50246. variableArgs: false
  50247. };
  50248. // Path
  50249. t['m'] = {
  50250. id: OPS.moveTo,
  50251. numArgs: 2,
  50252. variableArgs: false
  50253. };
  50254. t['l'] = {
  50255. id: OPS.lineTo,
  50256. numArgs: 2,
  50257. variableArgs: false
  50258. };
  50259. t['c'] = {
  50260. id: OPS.curveTo,
  50261. numArgs: 6,
  50262. variableArgs: false
  50263. };
  50264. t['v'] = {
  50265. id: OPS.curveTo2,
  50266. numArgs: 4,
  50267. variableArgs: false
  50268. };
  50269. t['y'] = {
  50270. id: OPS.curveTo3,
  50271. numArgs: 4,
  50272. variableArgs: false
  50273. };
  50274. t['h'] = {
  50275. id: OPS.closePath,
  50276. numArgs: 0,
  50277. variableArgs: false
  50278. };
  50279. t['re'] = {
  50280. id: OPS.rectangle,
  50281. numArgs: 4,
  50282. variableArgs: false
  50283. };
  50284. t['S'] = {
  50285. id: OPS.stroke,
  50286. numArgs: 0,
  50287. variableArgs: false
  50288. };
  50289. t['s'] = {
  50290. id: OPS.closeStroke,
  50291. numArgs: 0,
  50292. variableArgs: false
  50293. };
  50294. t['f'] = {
  50295. id: OPS.fill,
  50296. numArgs: 0,
  50297. variableArgs: false
  50298. };
  50299. t['F'] = {
  50300. id: OPS.fill,
  50301. numArgs: 0,
  50302. variableArgs: false
  50303. };
  50304. t['f*'] = {
  50305. id: OPS.eoFill,
  50306. numArgs: 0,
  50307. variableArgs: false
  50308. };
  50309. t['B'] = {
  50310. id: OPS.fillStroke,
  50311. numArgs: 0,
  50312. variableArgs: false
  50313. };
  50314. t['B*'] = {
  50315. id: OPS.eoFillStroke,
  50316. numArgs: 0,
  50317. variableArgs: false
  50318. };
  50319. t['b'] = {
  50320. id: OPS.closeFillStroke,
  50321. numArgs: 0,
  50322. variableArgs: false
  50323. };
  50324. t['b*'] = {
  50325. id: OPS.closeEOFillStroke,
  50326. numArgs: 0,
  50327. variableArgs: false
  50328. };
  50329. t['n'] = {
  50330. id: OPS.endPath,
  50331. numArgs: 0,
  50332. variableArgs: false
  50333. };
  50334. // Clipping
  50335. t['W'] = {
  50336. id: OPS.clip,
  50337. numArgs: 0,
  50338. variableArgs: false
  50339. };
  50340. t['W*'] = {
  50341. id: OPS.eoClip,
  50342. numArgs: 0,
  50343. variableArgs: false
  50344. };
  50345. // Text
  50346. t['BT'] = {
  50347. id: OPS.beginText,
  50348. numArgs: 0,
  50349. variableArgs: false
  50350. };
  50351. t['ET'] = {
  50352. id: OPS.endText,
  50353. numArgs: 0,
  50354. variableArgs: false
  50355. };
  50356. t['Tc'] = {
  50357. id: OPS.setCharSpacing,
  50358. numArgs: 1,
  50359. variableArgs: false
  50360. };
  50361. t['Tw'] = {
  50362. id: OPS.setWordSpacing,
  50363. numArgs: 1,
  50364. variableArgs: false
  50365. };
  50366. t['Tz'] = {
  50367. id: OPS.setHScale,
  50368. numArgs: 1,
  50369. variableArgs: false
  50370. };
  50371. t['TL'] = {
  50372. id: OPS.setLeading,
  50373. numArgs: 1,
  50374. variableArgs: false
  50375. };
  50376. t['Tf'] = {
  50377. id: OPS.setFont,
  50378. numArgs: 2,
  50379. variableArgs: false
  50380. };
  50381. t['Tr'] = {
  50382. id: OPS.setTextRenderingMode,
  50383. numArgs: 1,
  50384. variableArgs: false
  50385. };
  50386. t['Ts'] = {
  50387. id: OPS.setTextRise,
  50388. numArgs: 1,
  50389. variableArgs: false
  50390. };
  50391. t['Td'] = {
  50392. id: OPS.moveText,
  50393. numArgs: 2,
  50394. variableArgs: false
  50395. };
  50396. t['TD'] = {
  50397. id: OPS.setLeadingMoveText,
  50398. numArgs: 2,
  50399. variableArgs: false
  50400. };
  50401. t['Tm'] = {
  50402. id: OPS.setTextMatrix,
  50403. numArgs: 6,
  50404. variableArgs: false
  50405. };
  50406. t['T*'] = {
  50407. id: OPS.nextLine,
  50408. numArgs: 0,
  50409. variableArgs: false
  50410. };
  50411. t['Tj'] = {
  50412. id: OPS.showText,
  50413. numArgs: 1,
  50414. variableArgs: false
  50415. };
  50416. t['TJ'] = {
  50417. id: OPS.showSpacedText,
  50418. numArgs: 1,
  50419. variableArgs: false
  50420. };
  50421. t['\''] = {
  50422. id: OPS.nextLineShowText,
  50423. numArgs: 1,
  50424. variableArgs: false
  50425. };
  50426. t['"'] = {
  50427. id: OPS.nextLineSetSpacingShowText,
  50428. numArgs: 3,
  50429. variableArgs: false
  50430. };
  50431. // Type3 fonts
  50432. t['d0'] = {
  50433. id: OPS.setCharWidth,
  50434. numArgs: 2,
  50435. variableArgs: false
  50436. };
  50437. t['d1'] = {
  50438. id: OPS.setCharWidthAndBounds,
  50439. numArgs: 6,
  50440. variableArgs: false
  50441. };
  50442. // Color
  50443. t['CS'] = {
  50444. id: OPS.setStrokeColorSpace,
  50445. numArgs: 1,
  50446. variableArgs: false
  50447. };
  50448. t['cs'] = {
  50449. id: OPS.setFillColorSpace,
  50450. numArgs: 1,
  50451. variableArgs: false
  50452. };
  50453. t['SC'] = {
  50454. id: OPS.setStrokeColor,
  50455. numArgs: 4,
  50456. variableArgs: true
  50457. };
  50458. t['SCN'] = {
  50459. id: OPS.setStrokeColorN,
  50460. numArgs: 33,
  50461. variableArgs: true
  50462. };
  50463. t['sc'] = {
  50464. id: OPS.setFillColor,
  50465. numArgs: 4,
  50466. variableArgs: true
  50467. };
  50468. t['scn'] = {
  50469. id: OPS.setFillColorN,
  50470. numArgs: 33,
  50471. variableArgs: true
  50472. };
  50473. t['G'] = {
  50474. id: OPS.setStrokeGray,
  50475. numArgs: 1,
  50476. variableArgs: false
  50477. };
  50478. t['g'] = {
  50479. id: OPS.setFillGray,
  50480. numArgs: 1,
  50481. variableArgs: false
  50482. };
  50483. t['RG'] = {
  50484. id: OPS.setStrokeRGBColor,
  50485. numArgs: 3,
  50486. variableArgs: false
  50487. };
  50488. t['rg'] = {
  50489. id: OPS.setFillRGBColor,
  50490. numArgs: 3,
  50491. variableArgs: false
  50492. };
  50493. t['K'] = {
  50494. id: OPS.setStrokeCMYKColor,
  50495. numArgs: 4,
  50496. variableArgs: false
  50497. };
  50498. t['k'] = {
  50499. id: OPS.setFillCMYKColor,
  50500. numArgs: 4,
  50501. variableArgs: false
  50502. };
  50503. // Shading
  50504. t['sh'] = {
  50505. id: OPS.shadingFill,
  50506. numArgs: 1,
  50507. variableArgs: false
  50508. };
  50509. // Images
  50510. t['BI'] = {
  50511. id: OPS.beginInlineImage,
  50512. numArgs: 0,
  50513. variableArgs: false
  50514. };
  50515. t['ID'] = {
  50516. id: OPS.beginImageData,
  50517. numArgs: 0,
  50518. variableArgs: false
  50519. };
  50520. t['EI'] = {
  50521. id: OPS.endInlineImage,
  50522. numArgs: 1,
  50523. variableArgs: false
  50524. };
  50525. // XObjects
  50526. t['Do'] = {
  50527. id: OPS.paintXObject,
  50528. numArgs: 1,
  50529. variableArgs: false
  50530. };
  50531. t['MP'] = {
  50532. id: OPS.markPoint,
  50533. numArgs: 1,
  50534. variableArgs: false
  50535. };
  50536. t['DP'] = {
  50537. id: OPS.markPointProps,
  50538. numArgs: 2,
  50539. variableArgs: false
  50540. };
  50541. t['BMC'] = {
  50542. id: OPS.beginMarkedContent,
  50543. numArgs: 1,
  50544. variableArgs: false
  50545. };
  50546. t['BDC'] = {
  50547. id: OPS.beginMarkedContentProps,
  50548. numArgs: 2,
  50549. variableArgs: false
  50550. };
  50551. t['EMC'] = {
  50552. id: OPS.endMarkedContent,
  50553. numArgs: 0,
  50554. variableArgs: false
  50555. };
  50556. // Compatibility
  50557. t['BX'] = {
  50558. id: OPS.beginCompat,
  50559. numArgs: 0,
  50560. variableArgs: false
  50561. };
  50562. t['EX'] = {
  50563. id: OPS.endCompat,
  50564. numArgs: 0,
  50565. variableArgs: false
  50566. };
  50567. // (reserved partial commands for the lexer)
  50568. t['BM'] = null;
  50569. t['BD'] = null;
  50570. t['true'] = null;
  50571. t['fa'] = null;
  50572. t['fal'] = null;
  50573. t['fals'] = null;
  50574. t['false'] = null;
  50575. t['nu'] = null;
  50576. t['nul'] = null;
  50577. t['null'] = null;
  50578. });
  50579. function EvaluatorPreprocessor(stream, xref, stateManager) {
  50580. this.opMap = getOPMap();
  50581. // TODO(mduan): pass array of knownCommands rather than this.opMap
  50582. // dictionary
  50583. this.parser = new Parser(new Lexer(stream, this.opMap), false, xref);
  50584. this.stateManager = stateManager;
  50585. this.nonProcessedArgs = [];
  50586. }
  50587. EvaluatorPreprocessor.prototype = {
  50588. get savedStatesDepth() {
  50589. return this.stateManager.stateStack.length;
  50590. },
  50591. // |operation| is an object with two fields:
  50592. //
  50593. // - |fn| is an out param.
  50594. //
  50595. // - |args| is an inout param. On entry, it should have one of two values.
  50596. //
  50597. // - An empty array. This indicates that the caller is providing the
  50598. // array in which the args will be stored in. The caller should use
  50599. // this value if it can reuse a single array for each call to read().
  50600. //
  50601. // - |null|. This indicates that the caller needs this function to create
  50602. // the array in which any args are stored in. If there are zero args,
  50603. // this function will leave |operation.args| as |null| (thus avoiding
  50604. // allocations that would occur if we used an empty array to represent
  50605. // zero arguments). Otherwise, it will replace |null| with a new array
  50606. // containing the arguments. The caller should use this value if it
  50607. // cannot reuse an array for each call to read().
  50608. //
  50609. // These two modes are present because this function is very hot and so
  50610. // avoiding allocations where possible is worthwhile.
  50611. //
  50612. read: function EvaluatorPreprocessor_read(operation) {
  50613. var args = operation.args;
  50614. while (true) {
  50615. var obj = this.parser.getObj();
  50616. if (isCmd(obj)) {
  50617. var cmd = obj.cmd;
  50618. // Check that the command is valid
  50619. var opSpec = this.opMap[cmd];
  50620. if (!opSpec) {
  50621. warn('Unknown command "' + cmd + '"');
  50622. continue;
  50623. }
  50624. var fn = opSpec.id;
  50625. var numArgs = opSpec.numArgs;
  50626. var argsLength = args !== null ? args.length : 0;
  50627. if (!opSpec.variableArgs) {
  50628. // Postscript commands can be nested, e.g. /F2 /GS2 gs 5.711 Tf
  50629. if (argsLength !== numArgs) {
  50630. var nonProcessedArgs = this.nonProcessedArgs;
  50631. while (argsLength > numArgs) {
  50632. nonProcessedArgs.push(args.shift());
  50633. argsLength--;
  50634. }
  50635. while (argsLength < numArgs && nonProcessedArgs.length !== 0) {
  50636. if (!args) {
  50637. args = [];
  50638. }
  50639. args.unshift(nonProcessedArgs.pop());
  50640. argsLength++;
  50641. }
  50642. }
  50643. if (argsLength < numArgs) {
  50644. // If we receive too few args, it's not possible to possible
  50645. // to execute the command, so skip the command
  50646. info('Command ' + fn + ': because expected ' + numArgs + ' args, but received ' + argsLength + ' args; skipping');
  50647. args = null;
  50648. continue;
  50649. }
  50650. } else if (argsLength > numArgs) {
  50651. info('Command ' + fn + ': expected [0,' + numArgs + '] args, but received ' + argsLength + ' args');
  50652. }
  50653. // TODO figure out how to type-check vararg functions
  50654. this.preprocessCommand(fn, args);
  50655. operation.fn = fn;
  50656. operation.args = args;
  50657. return true;
  50658. } else {
  50659. if (isEOF(obj)) {
  50660. return false;
  50661. }
  50662. // no more commands
  50663. // argument
  50664. if (obj !== null) {
  50665. if (!args) {
  50666. args = [];
  50667. }
  50668. args.push(obj);
  50669. assert(args.length <= 33, 'Too many arguments');
  50670. }
  50671. }
  50672. }
  50673. },
  50674. preprocessCommand: function EvaluatorPreprocessor_preprocessCommand(fn, args) {
  50675. switch (fn | 0) {
  50676. case OPS.save:
  50677. this.stateManager.save();
  50678. break;
  50679. case OPS.restore:
  50680. this.stateManager.restore();
  50681. break;
  50682. case OPS.transform:
  50683. this.stateManager.transform(args);
  50684. break;
  50685. }
  50686. }
  50687. };
  50688. return EvaluatorPreprocessor;
  50689. }();
  50690. var QueueOptimizer = function QueueOptimizerClosure() {
  50691. function addState(parentState, pattern, fn) {
  50692. var state = parentState;
  50693. for (var i = 0, ii = pattern.length - 1; i < ii; i++) {
  50694. var item = pattern[i];
  50695. state = state[item] || (state[item] = []);
  50696. }
  50697. state[pattern[pattern.length - 1]] = fn;
  50698. }
  50699. function handlePaintSolidColorImageMask(iFirstSave, count, fnArray, argsArray) {
  50700. // Handles special case of mainly LaTeX documents which use image masks to
  50701. // draw lines with the current fill style.
  50702. // 'count' groups of (save, transform, paintImageMaskXObject, restore)+
  50703. // have been found at iFirstSave.
  50704. var iFirstPIMXO = iFirstSave + 2;
  50705. for (var i = 0; i < count; i++) {
  50706. var arg = argsArray[iFirstPIMXO + 4 * i];
  50707. var imageMask = arg.length === 1 && arg[0];
  50708. if (imageMask && imageMask.width === 1 && imageMask.height === 1 && (!imageMask.data.length || imageMask.data.length === 1 && imageMask.data[0] === 0)) {
  50709. fnArray[iFirstPIMXO + 4 * i] = OPS.paintSolidColorImageMask;
  50710. continue;
  50711. }
  50712. break;
  50713. }
  50714. return count - i;
  50715. }
  50716. var InitialState = [];
  50717. // This replaces (save, transform, paintInlineImageXObject, restore)+
  50718. // sequences with one |paintInlineImageXObjectGroup| operation.
  50719. addState(InitialState, [
  50720. OPS.save,
  50721. OPS.transform,
  50722. OPS.paintInlineImageXObject,
  50723. OPS.restore
  50724. ], function foundInlineImageGroup(context) {
  50725. var MIN_IMAGES_IN_INLINE_IMAGES_BLOCK = 10;
  50726. var MAX_IMAGES_IN_INLINE_IMAGES_BLOCK = 200;
  50727. var MAX_WIDTH = 1000;
  50728. var IMAGE_PADDING = 1;
  50729. var fnArray = context.fnArray, argsArray = context.argsArray;
  50730. var curr = context.iCurr;
  50731. var iFirstSave = curr - 3;
  50732. var iFirstTransform = curr - 2;
  50733. var iFirstPIIXO = curr - 1;
  50734. // Look for the quartets.
  50735. var i = iFirstSave + 4;
  50736. var ii = fnArray.length;
  50737. while (i + 3 < ii) {
  50738. if (fnArray[i] !== OPS.save || fnArray[i + 1] !== OPS.transform || fnArray[i + 2] !== OPS.paintInlineImageXObject || fnArray[i + 3] !== OPS.restore) {
  50739. break;
  50740. }
  50741. // ops don't match
  50742. i += 4;
  50743. }
  50744. // At this point, i is the index of the first op past the last valid
  50745. // quartet.
  50746. var count = Math.min((i - iFirstSave) / 4, MAX_IMAGES_IN_INLINE_IMAGES_BLOCK);
  50747. if (count < MIN_IMAGES_IN_INLINE_IMAGES_BLOCK) {
  50748. return i;
  50749. }
  50750. // assuming that heights of those image is too small (~1 pixel)
  50751. // packing as much as possible by lines
  50752. var maxX = 0;
  50753. var map = [], maxLineHeight = 0;
  50754. var currentX = IMAGE_PADDING, currentY = IMAGE_PADDING;
  50755. var q;
  50756. for (q = 0; q < count; q++) {
  50757. var transform = argsArray[iFirstTransform + (q << 2)];
  50758. var img = argsArray[iFirstPIIXO + (q << 2)][0];
  50759. if (currentX + img.width > MAX_WIDTH) {
  50760. // starting new line
  50761. maxX = Math.max(maxX, currentX);
  50762. currentY += maxLineHeight + 2 * IMAGE_PADDING;
  50763. currentX = 0;
  50764. maxLineHeight = 0;
  50765. }
  50766. map.push({
  50767. transform: transform,
  50768. x: currentX,
  50769. y: currentY,
  50770. w: img.width,
  50771. h: img.height
  50772. });
  50773. currentX += img.width + 2 * IMAGE_PADDING;
  50774. maxLineHeight = Math.max(maxLineHeight, img.height);
  50775. }
  50776. var imgWidth = Math.max(maxX, currentX) + IMAGE_PADDING;
  50777. var imgHeight = currentY + maxLineHeight + IMAGE_PADDING;
  50778. var imgData = new Uint8Array(imgWidth * imgHeight * 4);
  50779. var imgRowSize = imgWidth << 2;
  50780. for (q = 0; q < count; q++) {
  50781. var data = argsArray[iFirstPIIXO + (q << 2)][0].data;
  50782. // Copy image by lines and extends pixels into padding.
  50783. var rowSize = map[q].w << 2;
  50784. var dataOffset = 0;
  50785. var offset = map[q].x + map[q].y * imgWidth << 2;
  50786. imgData.set(data.subarray(0, rowSize), offset - imgRowSize);
  50787. for (var k = 0, kk = map[q].h; k < kk; k++) {
  50788. imgData.set(data.subarray(dataOffset, dataOffset + rowSize), offset);
  50789. dataOffset += rowSize;
  50790. offset += imgRowSize;
  50791. }
  50792. imgData.set(data.subarray(dataOffset - rowSize, dataOffset), offset);
  50793. while (offset >= 0) {
  50794. data[offset - 4] = data[offset];
  50795. data[offset - 3] = data[offset + 1];
  50796. data[offset - 2] = data[offset + 2];
  50797. data[offset - 1] = data[offset + 3];
  50798. data[offset + rowSize] = data[offset + rowSize - 4];
  50799. data[offset + rowSize + 1] = data[offset + rowSize - 3];
  50800. data[offset + rowSize + 2] = data[offset + rowSize - 2];
  50801. data[offset + rowSize + 3] = data[offset + rowSize - 1];
  50802. offset -= imgRowSize;
  50803. }
  50804. }
  50805. // Replace queue items.
  50806. fnArray.splice(iFirstSave, count * 4, OPS.paintInlineImageXObjectGroup);
  50807. argsArray.splice(iFirstSave, count * 4, [
  50808. {
  50809. width: imgWidth,
  50810. height: imgHeight,
  50811. kind: ImageKind.RGBA_32BPP,
  50812. data: imgData
  50813. },
  50814. map
  50815. ]);
  50816. return iFirstSave + 1;
  50817. });
  50818. // This replaces (save, transform, paintImageMaskXObject, restore)+
  50819. // sequences with one |paintImageMaskXObjectGroup| or one
  50820. // |paintImageMaskXObjectRepeat| operation.
  50821. addState(InitialState, [
  50822. OPS.save,
  50823. OPS.transform,
  50824. OPS.paintImageMaskXObject,
  50825. OPS.restore
  50826. ], function foundImageMaskGroup(context) {
  50827. var MIN_IMAGES_IN_MASKS_BLOCK = 10;
  50828. var MAX_IMAGES_IN_MASKS_BLOCK = 100;
  50829. var MAX_SAME_IMAGES_IN_MASKS_BLOCK = 1000;
  50830. var fnArray = context.fnArray, argsArray = context.argsArray;
  50831. var curr = context.iCurr;
  50832. var iFirstSave = curr - 3;
  50833. var iFirstTransform = curr - 2;
  50834. var iFirstPIMXO = curr - 1;
  50835. // Look for the quartets.
  50836. var i = iFirstSave + 4;
  50837. var ii = fnArray.length;
  50838. while (i + 3 < ii) {
  50839. if (fnArray[i] !== OPS.save || fnArray[i + 1] !== OPS.transform || fnArray[i + 2] !== OPS.paintImageMaskXObject || fnArray[i + 3] !== OPS.restore) {
  50840. break;
  50841. }
  50842. // ops don't match
  50843. i += 4;
  50844. }
  50845. // At this point, i is the index of the first op past the last valid
  50846. // quartet.
  50847. var count = (i - iFirstSave) / 4;
  50848. count = handlePaintSolidColorImageMask(iFirstSave, count, fnArray, argsArray);
  50849. if (count < MIN_IMAGES_IN_MASKS_BLOCK) {
  50850. return i;
  50851. }
  50852. var q;
  50853. var isSameImage = false;
  50854. var iTransform, transformArgs;
  50855. var firstPIMXOArg0 = argsArray[iFirstPIMXO][0];
  50856. if (argsArray[iFirstTransform][1] === 0 && argsArray[iFirstTransform][2] === 0) {
  50857. isSameImage = true;
  50858. var firstTransformArg0 = argsArray[iFirstTransform][0];
  50859. var firstTransformArg3 = argsArray[iFirstTransform][3];
  50860. iTransform = iFirstTransform + 4;
  50861. var iPIMXO = iFirstPIMXO + 4;
  50862. for (q = 1; q < count; q++, iTransform += 4, iPIMXO += 4) {
  50863. transformArgs = argsArray[iTransform];
  50864. if (argsArray[iPIMXO][0] !== firstPIMXOArg0 || transformArgs[0] !== firstTransformArg0 || transformArgs[1] !== 0 || transformArgs[2] !== 0 || transformArgs[3] !== firstTransformArg3) {
  50865. if (q < MIN_IMAGES_IN_MASKS_BLOCK) {
  50866. isSameImage = false;
  50867. } else {
  50868. count = q;
  50869. }
  50870. break;
  50871. }
  50872. }
  50873. }
  50874. // different image or transform
  50875. if (isSameImage) {
  50876. count = Math.min(count, MAX_SAME_IMAGES_IN_MASKS_BLOCK);
  50877. var positions = new Float32Array(count * 2);
  50878. iTransform = iFirstTransform;
  50879. for (q = 0; q < count; q++, iTransform += 4) {
  50880. transformArgs = argsArray[iTransform];
  50881. positions[q << 1] = transformArgs[4];
  50882. positions[(q << 1) + 1] = transformArgs[5];
  50883. }
  50884. // Replace queue items.
  50885. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectRepeat);
  50886. argsArray.splice(iFirstSave, count * 4, [
  50887. firstPIMXOArg0,
  50888. firstTransformArg0,
  50889. firstTransformArg3,
  50890. positions
  50891. ]);
  50892. } else {
  50893. count = Math.min(count, MAX_IMAGES_IN_MASKS_BLOCK);
  50894. var images = [];
  50895. for (q = 0; q < count; q++) {
  50896. transformArgs = argsArray[iFirstTransform + (q << 2)];
  50897. var maskParams = argsArray[iFirstPIMXO + (q << 2)][0];
  50898. images.push({
  50899. data: maskParams.data,
  50900. width: maskParams.width,
  50901. height: maskParams.height,
  50902. transform: transformArgs
  50903. });
  50904. }
  50905. // Replace queue items.
  50906. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectGroup);
  50907. argsArray.splice(iFirstSave, count * 4, [images]);
  50908. }
  50909. return iFirstSave + 1;
  50910. });
  50911. // This replaces (save, transform, paintImageXObject, restore)+ sequences
  50912. // with one paintImageXObjectRepeat operation, if the |transform| and
  50913. // |paintImageXObjectRepeat| ops are appropriate.
  50914. addState(InitialState, [
  50915. OPS.save,
  50916. OPS.transform,
  50917. OPS.paintImageXObject,
  50918. OPS.restore
  50919. ], function (context) {
  50920. var MIN_IMAGES_IN_BLOCK = 3;
  50921. var MAX_IMAGES_IN_BLOCK = 1000;
  50922. var fnArray = context.fnArray, argsArray = context.argsArray;
  50923. var curr = context.iCurr;
  50924. var iFirstSave = curr - 3;
  50925. var iFirstTransform = curr - 2;
  50926. var iFirstPIXO = curr - 1;
  50927. var iFirstRestore = curr;
  50928. if (argsArray[iFirstTransform][1] !== 0 || argsArray[iFirstTransform][2] !== 0) {
  50929. return iFirstRestore + 1;
  50930. }
  50931. // transform has the wrong form
  50932. // Look for the quartets.
  50933. var firstPIXOArg0 = argsArray[iFirstPIXO][0];
  50934. var firstTransformArg0 = argsArray[iFirstTransform][0];
  50935. var firstTransformArg3 = argsArray[iFirstTransform][3];
  50936. var i = iFirstSave + 4;
  50937. var ii = fnArray.length;
  50938. while (i + 3 < ii) {
  50939. if (fnArray[i] !== OPS.save || fnArray[i + 1] !== OPS.transform || fnArray[i + 2] !== OPS.paintImageXObject || fnArray[i + 3] !== OPS.restore) {
  50940. break;
  50941. }
  50942. // ops don't match
  50943. if (argsArray[i + 1][0] !== firstTransformArg0 || argsArray[i + 1][1] !== 0 || argsArray[i + 1][2] !== 0 || argsArray[i + 1][3] !== firstTransformArg3) {
  50944. break;
  50945. }
  50946. // transforms don't match
  50947. if (argsArray[i + 2][0] !== firstPIXOArg0) {
  50948. break;
  50949. }
  50950. // images don't match
  50951. i += 4;
  50952. }
  50953. // At this point, i is the index of the first op past the last valid
  50954. // quartet.
  50955. var count = Math.min((i - iFirstSave) / 4, MAX_IMAGES_IN_BLOCK);
  50956. if (count < MIN_IMAGES_IN_BLOCK) {
  50957. return i;
  50958. }
  50959. // Extract the (x,y) positions from all of the matching transforms.
  50960. var positions = new Float32Array(count * 2);
  50961. var iTransform = iFirstTransform;
  50962. for (var q = 0; q < count; q++, iTransform += 4) {
  50963. var transformArgs = argsArray[iTransform];
  50964. positions[q << 1] = transformArgs[4];
  50965. positions[(q << 1) + 1] = transformArgs[5];
  50966. }
  50967. // Replace queue items.
  50968. var args = [
  50969. firstPIXOArg0,
  50970. firstTransformArg0,
  50971. firstTransformArg3,
  50972. positions
  50973. ];
  50974. fnArray.splice(iFirstSave, count * 4, OPS.paintImageXObjectRepeat);
  50975. argsArray.splice(iFirstSave, count * 4, args);
  50976. return iFirstSave + 1;
  50977. });
  50978. // This replaces (beginText, setFont, setTextMatrix, showText, endText)+
  50979. // sequences with (beginText, setFont, (setTextMatrix, showText)+, endText)+
  50980. // sequences, if the font for each one is the same.
  50981. addState(InitialState, [
  50982. OPS.beginText,
  50983. OPS.setFont,
  50984. OPS.setTextMatrix,
  50985. OPS.showText,
  50986. OPS.endText
  50987. ], function (context) {
  50988. var MIN_CHARS_IN_BLOCK = 3;
  50989. var MAX_CHARS_IN_BLOCK = 1000;
  50990. var fnArray = context.fnArray, argsArray = context.argsArray;
  50991. var curr = context.iCurr;
  50992. var iFirstBeginText = curr - 4;
  50993. var iFirstSetFont = curr - 3;
  50994. var iFirstSetTextMatrix = curr - 2;
  50995. var iFirstShowText = curr - 1;
  50996. var iFirstEndText = curr;
  50997. // Look for the quintets.
  50998. var firstSetFontArg0 = argsArray[iFirstSetFont][0];
  50999. var firstSetFontArg1 = argsArray[iFirstSetFont][1];
  51000. var i = iFirstBeginText + 5;
  51001. var ii = fnArray.length;
  51002. while (i + 4 < ii) {
  51003. 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) {
  51004. break;
  51005. }
  51006. // ops don't match
  51007. if (argsArray[i + 1][0] !== firstSetFontArg0 || argsArray[i + 1][1] !== firstSetFontArg1) {
  51008. break;
  51009. }
  51010. // fonts don't match
  51011. i += 5;
  51012. }
  51013. // At this point, i is the index of the first op past the last valid
  51014. // quintet.
  51015. var count = Math.min((i - iFirstBeginText) / 5, MAX_CHARS_IN_BLOCK);
  51016. if (count < MIN_CHARS_IN_BLOCK) {
  51017. return i;
  51018. }
  51019. // If the preceding quintet is (<something>, setFont, setTextMatrix,
  51020. // showText, endText), include that as well. (E.g. <something> might be
  51021. // |dependency|.)
  51022. var iFirst = iFirstBeginText;
  51023. 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) {
  51024. count++;
  51025. iFirst -= 5;
  51026. }
  51027. // Remove (endText, beginText, setFont) trios.
  51028. var iEndText = iFirst + 4;
  51029. for (var q = 1; q < count; q++) {
  51030. fnArray.splice(iEndText, 3);
  51031. argsArray.splice(iEndText, 3);
  51032. iEndText += 2;
  51033. }
  51034. return iEndText + 1;
  51035. });
  51036. function QueueOptimizer() {
  51037. }
  51038. QueueOptimizer.prototype = {
  51039. optimize: function QueueOptimizer_optimize(queue) {
  51040. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  51041. var context = {
  51042. iCurr: 0,
  51043. fnArray: fnArray,
  51044. argsArray: argsArray
  51045. };
  51046. var state;
  51047. var i = 0, ii = fnArray.length;
  51048. while (i < ii) {
  51049. state = (state || InitialState)[fnArray[i]];
  51050. if (typeof state === 'function') {
  51051. // we found some handler
  51052. context.iCurr = i;
  51053. // state() returns the index of the first non-matching op (if we
  51054. // didn't match) or the first op past the modified ops (if we did
  51055. // match and replace).
  51056. i = state(context);
  51057. state = undefined;
  51058. // reset the state machine
  51059. ii = context.fnArray.length;
  51060. } else {
  51061. i++;
  51062. }
  51063. }
  51064. }
  51065. };
  51066. return QueueOptimizer;
  51067. }();
  51068. exports.OperatorList = OperatorList;
  51069. exports.PartialEvaluator = PartialEvaluator;
  51070. }));
  51071. (function (root, factory) {
  51072. factory(root.pdfjsCoreAnnotation = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreColorSpace, root.pdfjsCoreObj, root.pdfjsCoreEvaluator);
  51073. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreColorSpace, coreObj, coreEvaluator) {
  51074. var AnnotationBorderStyleType = sharedUtil.AnnotationBorderStyleType;
  51075. var AnnotationFieldFlag = sharedUtil.AnnotationFieldFlag;
  51076. var AnnotationFlag = sharedUtil.AnnotationFlag;
  51077. var AnnotationType = sharedUtil.AnnotationType;
  51078. var OPS = sharedUtil.OPS;
  51079. var Util = sharedUtil.Util;
  51080. var isString = sharedUtil.isString;
  51081. var isArray = sharedUtil.isArray;
  51082. var isInt = sharedUtil.isInt;
  51083. var stringToBytes = sharedUtil.stringToBytes;
  51084. var stringToPDFString = sharedUtil.stringToPDFString;
  51085. var warn = sharedUtil.warn;
  51086. var Dict = corePrimitives.Dict;
  51087. var isDict = corePrimitives.isDict;
  51088. var isName = corePrimitives.isName;
  51089. var isRef = corePrimitives.isRef;
  51090. var Stream = coreStream.Stream;
  51091. var ColorSpace = coreColorSpace.ColorSpace;
  51092. var Catalog = coreObj.Catalog;
  51093. var ObjectLoader = coreObj.ObjectLoader;
  51094. var FileSpec = coreObj.FileSpec;
  51095. var OperatorList = coreEvaluator.OperatorList;
  51096. /**
  51097. * @class
  51098. * @alias AnnotationFactory
  51099. */
  51100. function AnnotationFactory() {
  51101. }
  51102. AnnotationFactory.prototype = /** @lends AnnotationFactory.prototype */
  51103. {
  51104. /**
  51105. * @param {XRef} xref
  51106. * @param {Object} ref
  51107. * @param {PDFManager} pdfManager
  51108. * @param {string} uniquePrefix
  51109. * @param {Object} idCounters
  51110. * @returns {Annotation}
  51111. */
  51112. create: function AnnotationFactory_create(xref, ref, pdfManager, uniquePrefix, idCounters) {
  51113. var dict = xref.fetchIfRef(ref);
  51114. if (!isDict(dict)) {
  51115. return;
  51116. }
  51117. var id = isRef(ref) ? ref.toString() : 'annot_' + (uniquePrefix || '') + ++idCounters.obj;
  51118. // Determine the annotation's subtype.
  51119. var subtype = dict.get('Subtype');
  51120. subtype = isName(subtype) ? subtype.name : null;
  51121. // Return the right annotation object based on the subtype and field type.
  51122. var parameters = {
  51123. xref: xref,
  51124. dict: dict,
  51125. ref: isRef(ref) ? ref : null,
  51126. subtype: subtype,
  51127. id: id,
  51128. pdfManager: pdfManager
  51129. };
  51130. switch (subtype) {
  51131. case 'Link':
  51132. return new LinkAnnotation(parameters);
  51133. case 'Text':
  51134. return new TextAnnotation(parameters);
  51135. case 'Widget':
  51136. var fieldType = Util.getInheritableProperty(dict, 'FT');
  51137. fieldType = isName(fieldType) ? fieldType.name : null;
  51138. switch (fieldType) {
  51139. case 'Tx':
  51140. return new TextWidgetAnnotation(parameters);
  51141. case 'Ch':
  51142. return new ChoiceWidgetAnnotation(parameters);
  51143. }
  51144. warn('Unimplemented widget field type "' + fieldType + '", ' + 'falling back to base field type.');
  51145. return new WidgetAnnotation(parameters);
  51146. case 'Popup':
  51147. return new PopupAnnotation(parameters);
  51148. case 'Highlight':
  51149. return new HighlightAnnotation(parameters);
  51150. case 'Underline':
  51151. return new UnderlineAnnotation(parameters);
  51152. case 'Squiggly':
  51153. return new SquigglyAnnotation(parameters);
  51154. case 'StrikeOut':
  51155. return new StrikeOutAnnotation(parameters);
  51156. case 'FileAttachment':
  51157. return new FileAttachmentAnnotation(parameters);
  51158. default:
  51159. if (!subtype) {
  51160. warn('Annotation is missing the required /Subtype.');
  51161. } else {
  51162. warn('Unimplemented annotation type "' + subtype + '", ' + 'falling back to base annotation.');
  51163. }
  51164. return new Annotation(parameters);
  51165. }
  51166. }
  51167. };
  51168. var Annotation = function AnnotationClosure() {
  51169. // 12.5.5: Algorithm: Appearance streams
  51170. function getTransformMatrix(rect, bbox, matrix) {
  51171. var bounds = Util.getAxialAlignedBoundingBox(bbox, matrix);
  51172. var minX = bounds[0];
  51173. var minY = bounds[1];
  51174. var maxX = bounds[2];
  51175. var maxY = bounds[3];
  51176. if (minX === maxX || minY === maxY) {
  51177. // From real-life file, bbox was [0, 0, 0, 0]. In this case,
  51178. // just apply the transform for rect
  51179. return [
  51180. 1,
  51181. 0,
  51182. 0,
  51183. 1,
  51184. rect[0],
  51185. rect[1]
  51186. ];
  51187. }
  51188. var xRatio = (rect[2] - rect[0]) / (maxX - minX);
  51189. var yRatio = (rect[3] - rect[1]) / (maxY - minY);
  51190. return [
  51191. xRatio,
  51192. 0,
  51193. 0,
  51194. yRatio,
  51195. rect[0] - minX * xRatio,
  51196. rect[1] - minY * yRatio
  51197. ];
  51198. }
  51199. function getDefaultAppearance(dict) {
  51200. var appearanceState = dict.get('AP');
  51201. if (!isDict(appearanceState)) {
  51202. return;
  51203. }
  51204. var appearance;
  51205. var appearances = appearanceState.get('N');
  51206. if (isDict(appearances)) {
  51207. var as = dict.get('AS');
  51208. if (as && appearances.has(as.name)) {
  51209. appearance = appearances.get(as.name);
  51210. }
  51211. } else {
  51212. appearance = appearances;
  51213. }
  51214. return appearance;
  51215. }
  51216. function Annotation(params) {
  51217. var dict = params.dict;
  51218. this.setFlags(dict.get('F'));
  51219. this.setRectangle(dict.getArray('Rect'));
  51220. this.setColor(dict.getArray('C'));
  51221. this.setBorderStyle(dict);
  51222. this.appearance = getDefaultAppearance(dict);
  51223. // Expose public properties using a data object.
  51224. this.data = {};
  51225. this.data.id = params.id;
  51226. this.data.subtype = params.subtype;
  51227. this.data.annotationFlags = this.flags;
  51228. this.data.rect = this.rectangle;
  51229. this.data.color = this.color;
  51230. this.data.borderStyle = this.borderStyle;
  51231. this.data.hasAppearance = !!this.appearance;
  51232. }
  51233. Annotation.prototype = {
  51234. /**
  51235. * @private
  51236. */
  51237. _hasFlag: function Annotation_hasFlag(flags, flag) {
  51238. return !!(flags & flag);
  51239. },
  51240. /**
  51241. * @private
  51242. */
  51243. _isViewable: function Annotation_isViewable(flags) {
  51244. return !this._hasFlag(flags, AnnotationFlag.INVISIBLE) && !this._hasFlag(flags, AnnotationFlag.HIDDEN) && !this._hasFlag(flags, AnnotationFlag.NOVIEW);
  51245. },
  51246. /**
  51247. * @private
  51248. */
  51249. _isPrintable: function AnnotationFlag_isPrintable(flags) {
  51250. return this._hasFlag(flags, AnnotationFlag.PRINT) && !this._hasFlag(flags, AnnotationFlag.INVISIBLE) && !this._hasFlag(flags, AnnotationFlag.HIDDEN);
  51251. },
  51252. /**
  51253. * @return {boolean}
  51254. */
  51255. get viewable() {
  51256. if (this.flags === 0) {
  51257. return true;
  51258. }
  51259. return this._isViewable(this.flags);
  51260. },
  51261. /**
  51262. * @return {boolean}
  51263. */
  51264. get printable() {
  51265. if (this.flags === 0) {
  51266. return false;
  51267. }
  51268. return this._isPrintable(this.flags);
  51269. },
  51270. /**
  51271. * Set the flags.
  51272. *
  51273. * @public
  51274. * @memberof Annotation
  51275. * @param {number} flags - Unsigned 32-bit integer specifying annotation
  51276. * characteristics
  51277. * @see {@link shared/util.js}
  51278. */
  51279. setFlags: function Annotation_setFlags(flags) {
  51280. this.flags = isInt(flags) && flags > 0 ? flags : 0;
  51281. },
  51282. /**
  51283. * Check if a provided flag is set.
  51284. *
  51285. * @public
  51286. * @memberof Annotation
  51287. * @param {number} flag - Hexadecimal representation for an annotation
  51288. * characteristic
  51289. * @return {boolean}
  51290. * @see {@link shared/util.js}
  51291. */
  51292. hasFlag: function Annotation_hasFlag(flag) {
  51293. return this._hasFlag(this.flags, flag);
  51294. },
  51295. /**
  51296. * Set the rectangle.
  51297. *
  51298. * @public
  51299. * @memberof Annotation
  51300. * @param {Array} rectangle - The rectangle array with exactly four entries
  51301. */
  51302. setRectangle: function Annotation_setRectangle(rectangle) {
  51303. if (isArray(rectangle) && rectangle.length === 4) {
  51304. this.rectangle = Util.normalizeRect(rectangle);
  51305. } else {
  51306. this.rectangle = [
  51307. 0,
  51308. 0,
  51309. 0,
  51310. 0
  51311. ];
  51312. }
  51313. },
  51314. /**
  51315. * Set the color and take care of color space conversion.
  51316. *
  51317. * @public
  51318. * @memberof Annotation
  51319. * @param {Array} color - The color array containing either 0
  51320. * (transparent), 1 (grayscale), 3 (RGB) or
  51321. * 4 (CMYK) elements
  51322. */
  51323. setColor: function Annotation_setColor(color) {
  51324. var rgbColor = new Uint8Array(3);
  51325. // Black in RGB color space (default)
  51326. if (!isArray(color)) {
  51327. this.color = rgbColor;
  51328. return;
  51329. }
  51330. switch (color.length) {
  51331. case 0:
  51332. // Transparent, which we indicate with a null value
  51333. this.color = null;
  51334. break;
  51335. case 1:
  51336. // Convert grayscale to RGB
  51337. ColorSpace.singletons.gray.getRgbItem(color, 0, rgbColor, 0);
  51338. this.color = rgbColor;
  51339. break;
  51340. case 3:
  51341. // Convert RGB percentages to RGB
  51342. ColorSpace.singletons.rgb.getRgbItem(color, 0, rgbColor, 0);
  51343. this.color = rgbColor;
  51344. break;
  51345. case 4:
  51346. // Convert CMYK to RGB
  51347. ColorSpace.singletons.cmyk.getRgbItem(color, 0, rgbColor, 0);
  51348. this.color = rgbColor;
  51349. break;
  51350. default:
  51351. this.color = rgbColor;
  51352. break;
  51353. }
  51354. },
  51355. /**
  51356. * Set the border style (as AnnotationBorderStyle object).
  51357. *
  51358. * @public
  51359. * @memberof Annotation
  51360. * @param {Dict} borderStyle - The border style dictionary
  51361. */
  51362. setBorderStyle: function Annotation_setBorderStyle(borderStyle) {
  51363. this.borderStyle = new AnnotationBorderStyle();
  51364. if (!isDict(borderStyle)) {
  51365. return;
  51366. }
  51367. if (borderStyle.has('BS')) {
  51368. var dict = borderStyle.get('BS');
  51369. var dictType = dict.get('Type');
  51370. if (!dictType || isName(dictType, 'Border')) {
  51371. this.borderStyle.setWidth(dict.get('W'));
  51372. this.borderStyle.setStyle(dict.get('S'));
  51373. this.borderStyle.setDashArray(dict.getArray('D'));
  51374. }
  51375. } else if (borderStyle.has('Border')) {
  51376. var array = borderStyle.getArray('Border');
  51377. if (isArray(array) && array.length >= 3) {
  51378. this.borderStyle.setHorizontalCornerRadius(array[0]);
  51379. this.borderStyle.setVerticalCornerRadius(array[1]);
  51380. this.borderStyle.setWidth(array[2]);
  51381. if (array.length === 4) {
  51382. // Dash array available
  51383. this.borderStyle.setDashArray(array[3]);
  51384. }
  51385. }
  51386. } else {
  51387. // There are no border entries in the dictionary. According to the
  51388. // specification, we should draw a solid border of width 1 in that
  51389. // case, but Adobe Reader did not implement that part of the
  51390. // specification and instead draws no border at all, so we do the same.
  51391. // See also https://github.com/mozilla/pdf.js/issues/6179.
  51392. this.borderStyle.setWidth(0);
  51393. }
  51394. },
  51395. /**
  51396. * Prepare the annotation for working with a popup in the display layer.
  51397. *
  51398. * @private
  51399. * @memberof Annotation
  51400. * @param {Dict} dict - The annotation's data dictionary
  51401. */
  51402. _preparePopup: function Annotation_preparePopup(dict) {
  51403. if (!dict.has('C')) {
  51404. // Fall back to the default background color.
  51405. this.data.color = null;
  51406. }
  51407. this.data.hasPopup = dict.has('Popup');
  51408. this.data.title = stringToPDFString(dict.get('T') || '');
  51409. this.data.contents = stringToPDFString(dict.get('Contents') || '');
  51410. },
  51411. loadResources: function Annotation_loadResources(keys) {
  51412. return new Promise(function (resolve, reject) {
  51413. this.appearance.dict.getAsync('Resources').then(function (resources) {
  51414. if (!resources) {
  51415. resolve();
  51416. return;
  51417. }
  51418. var objectLoader = new ObjectLoader(resources.map, keys, resources.xref);
  51419. objectLoader.load().then(function () {
  51420. resolve(resources);
  51421. }, reject);
  51422. }, reject);
  51423. }.bind(this));
  51424. },
  51425. getOperatorList: function Annotation_getOperatorList(evaluator, task, renderForms) {
  51426. if (!this.appearance) {
  51427. return Promise.resolve(new OperatorList());
  51428. }
  51429. var data = this.data;
  51430. var appearanceDict = this.appearance.dict;
  51431. var resourcesPromise = this.loadResources([
  51432. 'ExtGState',
  51433. 'ColorSpace',
  51434. 'Pattern',
  51435. 'Shading',
  51436. 'XObject',
  51437. 'Font'
  51438. ]);
  51439. // ProcSet
  51440. // Properties
  51441. var bbox = appearanceDict.getArray('BBox') || [
  51442. 0,
  51443. 0,
  51444. 1,
  51445. 1
  51446. ];
  51447. var matrix = appearanceDict.getArray('Matrix') || [
  51448. 1,
  51449. 0,
  51450. 0,
  51451. 1,
  51452. 0,
  51453. 0
  51454. ];
  51455. var transform = getTransformMatrix(data.rect, bbox, matrix);
  51456. var self = this;
  51457. return resourcesPromise.then(function (resources) {
  51458. var opList = new OperatorList();
  51459. opList.addOp(OPS.beginAnnotation, [
  51460. data.rect,
  51461. transform,
  51462. matrix
  51463. ]);
  51464. return evaluator.getOperatorList(self.appearance, task, resources, opList).then(function () {
  51465. opList.addOp(OPS.endAnnotation, []);
  51466. self.appearance.reset();
  51467. return opList;
  51468. });
  51469. });
  51470. }
  51471. };
  51472. Annotation.appendToOperatorList = function Annotation_appendToOperatorList(annotations, opList, partialEvaluator, task, intent, renderForms) {
  51473. var annotationPromises = [];
  51474. for (var i = 0, n = annotations.length; i < n; ++i) {
  51475. if (intent === 'display' && annotations[i].viewable || intent === 'print' && annotations[i].printable) {
  51476. annotationPromises.push(annotations[i].getOperatorList(partialEvaluator, task, renderForms));
  51477. }
  51478. }
  51479. return Promise.all(annotationPromises).then(function (operatorLists) {
  51480. opList.addOp(OPS.beginAnnotations, []);
  51481. for (var i = 0, n = operatorLists.length; i < n; ++i) {
  51482. opList.addOpList(operatorLists[i]);
  51483. }
  51484. opList.addOp(OPS.endAnnotations, []);
  51485. });
  51486. };
  51487. return Annotation;
  51488. }();
  51489. /**
  51490. * Contains all data regarding an annotation's border style.
  51491. *
  51492. * @class
  51493. */
  51494. var AnnotationBorderStyle = function AnnotationBorderStyleClosure() {
  51495. /**
  51496. * @constructor
  51497. * @private
  51498. */
  51499. function AnnotationBorderStyle() {
  51500. this.width = 1;
  51501. this.style = AnnotationBorderStyleType.SOLID;
  51502. this.dashArray = [3];
  51503. this.horizontalCornerRadius = 0;
  51504. this.verticalCornerRadius = 0;
  51505. }
  51506. AnnotationBorderStyle.prototype = {
  51507. /**
  51508. * Set the width.
  51509. *
  51510. * @public
  51511. * @memberof AnnotationBorderStyle
  51512. * @param {integer} width - The width
  51513. */
  51514. setWidth: function AnnotationBorderStyle_setWidth(width) {
  51515. if (width === (width | 0)) {
  51516. this.width = width;
  51517. }
  51518. },
  51519. /**
  51520. * Set the style.
  51521. *
  51522. * @public
  51523. * @memberof AnnotationBorderStyle
  51524. * @param {Object} style - The style object
  51525. * @see {@link shared/util.js}
  51526. */
  51527. setStyle: function AnnotationBorderStyle_setStyle(style) {
  51528. if (!style) {
  51529. return;
  51530. }
  51531. switch (style.name) {
  51532. case 'S':
  51533. this.style = AnnotationBorderStyleType.SOLID;
  51534. break;
  51535. case 'D':
  51536. this.style = AnnotationBorderStyleType.DASHED;
  51537. break;
  51538. case 'B':
  51539. this.style = AnnotationBorderStyleType.BEVELED;
  51540. break;
  51541. case 'I':
  51542. this.style = AnnotationBorderStyleType.INSET;
  51543. break;
  51544. case 'U':
  51545. this.style = AnnotationBorderStyleType.UNDERLINE;
  51546. break;
  51547. default:
  51548. break;
  51549. }
  51550. },
  51551. /**
  51552. * Set the dash array.
  51553. *
  51554. * @public
  51555. * @memberof AnnotationBorderStyle
  51556. * @param {Array} dashArray - The dash array with at least one element
  51557. */
  51558. setDashArray: function AnnotationBorderStyle_setDashArray(dashArray) {
  51559. // We validate the dash array, but we do not use it because CSS does not
  51560. // allow us to change spacing of dashes. For more information, visit
  51561. // http://www.w3.org/TR/css3-background/#the-border-style.
  51562. if (isArray(dashArray) && dashArray.length > 0) {
  51563. // According to the PDF specification: the elements in a dashArray
  51564. // shall be numbers that are nonnegative and not all equal to zero.
  51565. var isValid = true;
  51566. var allZeros = true;
  51567. for (var i = 0, len = dashArray.length; i < len; i++) {
  51568. var element = dashArray[i];
  51569. var validNumber = +element >= 0;
  51570. if (!validNumber) {
  51571. isValid = false;
  51572. break;
  51573. } else if (element > 0) {
  51574. allZeros = false;
  51575. }
  51576. }
  51577. if (isValid && !allZeros) {
  51578. this.dashArray = dashArray;
  51579. } else {
  51580. this.width = 0;
  51581. }
  51582. } else // Adobe behavior when the array is invalid.
  51583. if (dashArray) {
  51584. this.width = 0;
  51585. }
  51586. },
  51587. // Adobe behavior when the array is invalid.
  51588. /**
  51589. * Set the horizontal corner radius (from a Border dictionary).
  51590. *
  51591. * @public
  51592. * @memberof AnnotationBorderStyle
  51593. * @param {integer} radius - The horizontal corner radius
  51594. */
  51595. setHorizontalCornerRadius: function AnnotationBorderStyle_setHorizontalCornerRadius(radius) {
  51596. if (radius === (radius | 0)) {
  51597. this.horizontalCornerRadius = radius;
  51598. }
  51599. },
  51600. /**
  51601. * Set the vertical corner radius (from a Border dictionary).
  51602. *
  51603. * @public
  51604. * @memberof AnnotationBorderStyle
  51605. * @param {integer} radius - The vertical corner radius
  51606. */
  51607. setVerticalCornerRadius: function AnnotationBorderStyle_setVerticalCornerRadius(radius) {
  51608. if (radius === (radius | 0)) {
  51609. this.verticalCornerRadius = radius;
  51610. }
  51611. }
  51612. };
  51613. return AnnotationBorderStyle;
  51614. }();
  51615. var WidgetAnnotation = function WidgetAnnotationClosure() {
  51616. function WidgetAnnotation(params) {
  51617. Annotation.call(this, params);
  51618. var dict = params.dict;
  51619. var data = this.data;
  51620. data.annotationType = AnnotationType.WIDGET;
  51621. data.fieldValue = Util.getInheritableProperty(dict, 'V', /* getArray = */
  51622. true);
  51623. data.alternativeText = stringToPDFString(dict.get('TU') || '');
  51624. data.defaultAppearance = Util.getInheritableProperty(dict, 'DA') || '';
  51625. var fieldType = Util.getInheritableProperty(dict, 'FT');
  51626. data.fieldType = isName(fieldType) ? fieldType.name : null;
  51627. this.fieldResources = Util.getInheritableProperty(dict, 'DR') || Dict.empty;
  51628. data.fieldFlags = Util.getInheritableProperty(dict, 'Ff');
  51629. if (!isInt(data.fieldFlags) || data.fieldFlags < 0) {
  51630. data.fieldFlags = 0;
  51631. }
  51632. data.readOnly = this.hasFieldFlag(AnnotationFieldFlag.READONLY);
  51633. // Hide signatures because we cannot validate them.
  51634. if (data.fieldType === 'Sig') {
  51635. this.setFlags(AnnotationFlag.HIDDEN);
  51636. }
  51637. // Building the full field name by collecting the field and
  51638. // its ancestors 'T' data and joining them using '.'.
  51639. var fieldName = [];
  51640. var namedItem = dict;
  51641. var ref = params.ref;
  51642. while (namedItem) {
  51643. var parent = namedItem.get('Parent');
  51644. var parentRef = namedItem.getRaw('Parent');
  51645. var name = namedItem.get('T');
  51646. if (name) {
  51647. fieldName.unshift(stringToPDFString(name));
  51648. } else if (parent && ref) {
  51649. // The field name is absent, that means more than one field
  51650. // with the same name may exist. Replacing the empty name
  51651. // with the '`' plus index in the parent's 'Kids' array.
  51652. // This is not in the PDF spec but necessary to id the
  51653. // the input controls.
  51654. var kids = parent.get('Kids');
  51655. var j, jj;
  51656. for (j = 0, jj = kids.length; j < jj; j++) {
  51657. var kidRef = kids[j];
  51658. if (kidRef.num === ref.num && kidRef.gen === ref.gen) {
  51659. break;
  51660. }
  51661. }
  51662. fieldName.unshift('`' + j);
  51663. }
  51664. namedItem = parent;
  51665. ref = parentRef;
  51666. }
  51667. data.fullName = fieldName.join('.');
  51668. }
  51669. Util.inherit(WidgetAnnotation, Annotation, {
  51670. /**
  51671. * Check if a provided field flag is set.
  51672. *
  51673. * @public
  51674. * @memberof WidgetAnnotation
  51675. * @param {number} flag - Hexadecimal representation for an annotation
  51676. * field characteristic
  51677. * @return {boolean}
  51678. * @see {@link shared/util.js}
  51679. */
  51680. hasFieldFlag: function WidgetAnnotation_hasFieldFlag(flag) {
  51681. return !!(this.data.fieldFlags & flag);
  51682. }
  51683. });
  51684. return WidgetAnnotation;
  51685. }();
  51686. var TextWidgetAnnotation = function TextWidgetAnnotationClosure() {
  51687. function TextWidgetAnnotation(params) {
  51688. WidgetAnnotation.call(this, params);
  51689. // The field value is always a string.
  51690. this.data.fieldValue = stringToPDFString(this.data.fieldValue || '');
  51691. // Determine the alignment of text in the field.
  51692. var alignment = Util.getInheritableProperty(params.dict, 'Q');
  51693. if (!isInt(alignment) || alignment < 0 || alignment > 2) {
  51694. alignment = null;
  51695. }
  51696. this.data.textAlignment = alignment;
  51697. // Determine the maximum length of text in the field.
  51698. var maximumLength = Util.getInheritableProperty(params.dict, 'MaxLen');
  51699. if (!isInt(maximumLength) || maximumLength < 0) {
  51700. maximumLength = null;
  51701. }
  51702. this.data.maxLen = maximumLength;
  51703. // Process field flags for the display layer.
  51704. this.data.multiLine = this.hasFieldFlag(AnnotationFieldFlag.MULTILINE);
  51705. this.data.comb = this.hasFieldFlag(AnnotationFieldFlag.COMB) && !this.hasFieldFlag(AnnotationFieldFlag.MULTILINE) && !this.hasFieldFlag(AnnotationFieldFlag.PASSWORD) && !this.hasFieldFlag(AnnotationFieldFlag.FILESELECT) && this.data.maxLen !== null;
  51706. }
  51707. Util.inherit(TextWidgetAnnotation, WidgetAnnotation, {
  51708. getOperatorList: function TextWidgetAnnotation_getOperatorList(evaluator, task, renderForms) {
  51709. var operatorList = new OperatorList();
  51710. // Do not render form elements on the canvas when interactive forms are
  51711. // enabled. The display layer is responsible for rendering them instead.
  51712. if (renderForms) {
  51713. return Promise.resolve(operatorList);
  51714. }
  51715. if (this.appearance) {
  51716. return Annotation.prototype.getOperatorList.call(this, evaluator, task, renderForms);
  51717. }
  51718. // Even if there is an appearance stream, ignore it. This is the
  51719. // behaviour used by Adobe Reader.
  51720. if (!this.data.defaultAppearance) {
  51721. return Promise.resolve(operatorList);
  51722. }
  51723. var stream = new Stream(stringToBytes(this.data.defaultAppearance));
  51724. return evaluator.getOperatorList(stream, task, this.fieldResources, operatorList).then(function () {
  51725. return operatorList;
  51726. });
  51727. }
  51728. });
  51729. return TextWidgetAnnotation;
  51730. }();
  51731. var ChoiceWidgetAnnotation = function ChoiceWidgetAnnotationClosure() {
  51732. function ChoiceWidgetAnnotation(params) {
  51733. WidgetAnnotation.call(this, params);
  51734. // Determine the options. The options array may consist of strings or
  51735. // arrays. If the array consists of arrays, then the first element of
  51736. // each array is the export value and the second element of each array is
  51737. // the display value. If the array consists of strings, then these
  51738. // represent both the export and display value. In this case, we convert
  51739. // it to an array of arrays as well for convenience in the display layer.
  51740. this.data.options = [];
  51741. var options = params.dict.getArray('Opt');
  51742. if (isArray(options)) {
  51743. for (var i = 0, ii = options.length; i < ii; i++) {
  51744. var option = options[i];
  51745. this.data.options[i] = {
  51746. exportValue: isArray(option) ? option[0] : option,
  51747. displayValue: isArray(option) ? option[1] : option
  51748. };
  51749. }
  51750. }
  51751. // Determine the field value. In this case, it may be a string or an
  51752. // array of strings. For convenience in the display layer, convert the
  51753. // string to an array of one string as well.
  51754. if (!isArray(this.data.fieldValue)) {
  51755. this.data.fieldValue = [this.data.fieldValue];
  51756. }
  51757. // Process field flags for the display layer.
  51758. this.data.combo = this.hasFieldFlag(AnnotationFieldFlag.COMBO);
  51759. this.data.multiSelect = this.hasFieldFlag(AnnotationFieldFlag.MULTISELECT);
  51760. }
  51761. Util.inherit(ChoiceWidgetAnnotation, WidgetAnnotation, {
  51762. getOperatorList: function ChoiceWidgetAnnotation_getOperatorList(evaluator, task, renderForms) {
  51763. var operatorList = new OperatorList();
  51764. // Do not render form elements on the canvas when interactive forms are
  51765. // enabled. The display layer is responsible for rendering them instead.
  51766. if (renderForms) {
  51767. return Promise.resolve(operatorList);
  51768. }
  51769. return Annotation.prototype.getOperatorList.call(this, evaluator, task, renderForms);
  51770. }
  51771. });
  51772. return ChoiceWidgetAnnotation;
  51773. }();
  51774. var TextAnnotation = function TextAnnotationClosure() {
  51775. var DEFAULT_ICON_SIZE = 22;
  51776. // px
  51777. function TextAnnotation(parameters) {
  51778. Annotation.call(this, parameters);
  51779. this.data.annotationType = AnnotationType.TEXT;
  51780. if (this.data.hasAppearance) {
  51781. this.data.name = 'NoIcon';
  51782. } else {
  51783. this.data.rect[1] = this.data.rect[3] - DEFAULT_ICON_SIZE;
  51784. this.data.rect[2] = this.data.rect[0] + DEFAULT_ICON_SIZE;
  51785. this.data.name = parameters.dict.has('Name') ? parameters.dict.get('Name').name : 'Note';
  51786. }
  51787. this._preparePopup(parameters.dict);
  51788. }
  51789. Util.inherit(TextAnnotation, Annotation, {});
  51790. return TextAnnotation;
  51791. }();
  51792. var LinkAnnotation = function LinkAnnotationClosure() {
  51793. function LinkAnnotation(params) {
  51794. Annotation.call(this, params);
  51795. var data = this.data;
  51796. data.annotationType = AnnotationType.LINK;
  51797. Catalog.parseDestDictionary({
  51798. destDict: params.dict,
  51799. resultObj: data,
  51800. docBaseUrl: params.pdfManager.docBaseUrl
  51801. });
  51802. }
  51803. Util.inherit(LinkAnnotation, Annotation, {});
  51804. return LinkAnnotation;
  51805. }();
  51806. var PopupAnnotation = function PopupAnnotationClosure() {
  51807. function PopupAnnotation(parameters) {
  51808. Annotation.call(this, parameters);
  51809. this.data.annotationType = AnnotationType.POPUP;
  51810. var dict = parameters.dict;
  51811. var parentItem = dict.get('Parent');
  51812. if (!parentItem) {
  51813. warn('Popup annotation has a missing or invalid parent annotation.');
  51814. return;
  51815. }
  51816. this.data.parentId = dict.getRaw('Parent').toString();
  51817. this.data.title = stringToPDFString(parentItem.get('T') || '');
  51818. this.data.contents = stringToPDFString(parentItem.get('Contents') || '');
  51819. if (!parentItem.has('C')) {
  51820. // Fall back to the default background color.
  51821. this.data.color = null;
  51822. } else {
  51823. this.setColor(parentItem.getArray('C'));
  51824. this.data.color = this.color;
  51825. }
  51826. // If the Popup annotation is not viewable, but the parent annotation is,
  51827. // that is most likely a bug. Fallback to inherit the flags from the parent
  51828. // annotation (this is consistent with the behaviour in Adobe Reader).
  51829. if (!this.viewable) {
  51830. var parentFlags = parentItem.get('F');
  51831. if (this._isViewable(parentFlags)) {
  51832. this.setFlags(parentFlags);
  51833. }
  51834. }
  51835. }
  51836. Util.inherit(PopupAnnotation, Annotation, {});
  51837. return PopupAnnotation;
  51838. }();
  51839. var HighlightAnnotation = function HighlightAnnotationClosure() {
  51840. function HighlightAnnotation(parameters) {
  51841. Annotation.call(this, parameters);
  51842. this.data.annotationType = AnnotationType.HIGHLIGHT;
  51843. this._preparePopup(parameters.dict);
  51844. // PDF viewers completely ignore any border styles.
  51845. this.data.borderStyle.setWidth(0);
  51846. }
  51847. Util.inherit(HighlightAnnotation, Annotation, {});
  51848. return HighlightAnnotation;
  51849. }();
  51850. var UnderlineAnnotation = function UnderlineAnnotationClosure() {
  51851. function UnderlineAnnotation(parameters) {
  51852. Annotation.call(this, parameters);
  51853. this.data.annotationType = AnnotationType.UNDERLINE;
  51854. this._preparePopup(parameters.dict);
  51855. // PDF viewers completely ignore any border styles.
  51856. this.data.borderStyle.setWidth(0);
  51857. }
  51858. Util.inherit(UnderlineAnnotation, Annotation, {});
  51859. return UnderlineAnnotation;
  51860. }();
  51861. var SquigglyAnnotation = function SquigglyAnnotationClosure() {
  51862. function SquigglyAnnotation(parameters) {
  51863. Annotation.call(this, parameters);
  51864. this.data.annotationType = AnnotationType.SQUIGGLY;
  51865. this._preparePopup(parameters.dict);
  51866. // PDF viewers completely ignore any border styles.
  51867. this.data.borderStyle.setWidth(0);
  51868. }
  51869. Util.inherit(SquigglyAnnotation, Annotation, {});
  51870. return SquigglyAnnotation;
  51871. }();
  51872. var StrikeOutAnnotation = function StrikeOutAnnotationClosure() {
  51873. function StrikeOutAnnotation(parameters) {
  51874. Annotation.call(this, parameters);
  51875. this.data.annotationType = AnnotationType.STRIKEOUT;
  51876. this._preparePopup(parameters.dict);
  51877. // PDF viewers completely ignore any border styles.
  51878. this.data.borderStyle.setWidth(0);
  51879. }
  51880. Util.inherit(StrikeOutAnnotation, Annotation, {});
  51881. return StrikeOutAnnotation;
  51882. }();
  51883. var FileAttachmentAnnotation = function FileAttachmentAnnotationClosure() {
  51884. function FileAttachmentAnnotation(parameters) {
  51885. Annotation.call(this, parameters);
  51886. var file = new FileSpec(parameters.dict.get('FS'), parameters.xref);
  51887. this.data.annotationType = AnnotationType.FILEATTACHMENT;
  51888. this.data.file = file.serializable;
  51889. this._preparePopup(parameters.dict);
  51890. }
  51891. Util.inherit(FileAttachmentAnnotation, Annotation, {});
  51892. return FileAttachmentAnnotation;
  51893. }();
  51894. exports.Annotation = Annotation;
  51895. exports.AnnotationBorderStyle = AnnotationBorderStyle;
  51896. exports.AnnotationFactory = AnnotationFactory;
  51897. }));
  51898. (function (root, factory) {
  51899. factory(root.pdfjsCoreDocument = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreObj, root.pdfjsCoreParser, root.pdfjsCoreCrypto, root.pdfjsCoreEvaluator, root.pdfjsCoreAnnotation);
  51900. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreObj, coreParser, coreCrypto, coreEvaluator, coreAnnotation) {
  51901. var MissingDataException = sharedUtil.MissingDataException;
  51902. var Util = sharedUtil.Util;
  51903. var assert = sharedUtil.assert;
  51904. var error = sharedUtil.error;
  51905. var info = sharedUtil.info;
  51906. var isArray = sharedUtil.isArray;
  51907. var isArrayBuffer = sharedUtil.isArrayBuffer;
  51908. var isString = sharedUtil.isString;
  51909. var shadow = sharedUtil.shadow;
  51910. var stringToBytes = sharedUtil.stringToBytes;
  51911. var stringToPDFString = sharedUtil.stringToPDFString;
  51912. var warn = sharedUtil.warn;
  51913. var isSpace = sharedUtil.isSpace;
  51914. var Dict = corePrimitives.Dict;
  51915. var isDict = corePrimitives.isDict;
  51916. var isName = corePrimitives.isName;
  51917. var isStream = corePrimitives.isStream;
  51918. var NullStream = coreStream.NullStream;
  51919. var Stream = coreStream.Stream;
  51920. var StreamsSequenceStream = coreStream.StreamsSequenceStream;
  51921. var Catalog = coreObj.Catalog;
  51922. var ObjectLoader = coreObj.ObjectLoader;
  51923. var XRef = coreObj.XRef;
  51924. var Linearization = coreParser.Linearization;
  51925. var calculateMD5 = coreCrypto.calculateMD5;
  51926. var OperatorList = coreEvaluator.OperatorList;
  51927. var PartialEvaluator = coreEvaluator.PartialEvaluator;
  51928. var Annotation = coreAnnotation.Annotation;
  51929. var AnnotationFactory = coreAnnotation.AnnotationFactory;
  51930. var Page = function PageClosure() {
  51931. var LETTER_SIZE_MEDIABOX = [
  51932. 0,
  51933. 0,
  51934. 612,
  51935. 792
  51936. ];
  51937. function Page(pdfManager, xref, pageIndex, pageDict, ref, fontCache) {
  51938. this.pdfManager = pdfManager;
  51939. this.pageIndex = pageIndex;
  51940. this.pageDict = pageDict;
  51941. this.xref = xref;
  51942. this.ref = ref;
  51943. this.fontCache = fontCache;
  51944. this.uniquePrefix = 'p' + this.pageIndex + '_';
  51945. this.idCounters = { obj: 0 };
  51946. this.evaluatorOptions = pdfManager.evaluatorOptions;
  51947. this.resourcesPromise = null;
  51948. }
  51949. Page.prototype = {
  51950. getPageProp: function Page_getPageProp(key) {
  51951. return this.pageDict.get(key);
  51952. },
  51953. getInheritedPageProp: function Page_getInheritedPageProp(key) {
  51954. var dict = this.pageDict, valueArray = null, loopCount = 0;
  51955. var MAX_LOOP_COUNT = 100;
  51956. // Always walk up the entire parent chain, to be able to find
  51957. // e.g. \Resources placed on multiple levels of the tree.
  51958. while (dict) {
  51959. var value = dict.get(key);
  51960. if (value) {
  51961. if (!valueArray) {
  51962. valueArray = [];
  51963. }
  51964. valueArray.push(value);
  51965. }
  51966. if (++loopCount > MAX_LOOP_COUNT) {
  51967. warn('Page_getInheritedPageProp: maximum loop count exceeded.');
  51968. break;
  51969. }
  51970. dict = dict.get('Parent');
  51971. }
  51972. if (!valueArray) {
  51973. return Dict.empty;
  51974. }
  51975. if (valueArray.length === 1 || !isDict(valueArray[0]) || loopCount > MAX_LOOP_COUNT) {
  51976. return valueArray[0];
  51977. }
  51978. return Dict.merge(this.xref, valueArray);
  51979. },
  51980. get content() {
  51981. return this.getPageProp('Contents');
  51982. },
  51983. get resources() {
  51984. // For robustness: The spec states that a \Resources entry has to be
  51985. // present, but can be empty. Some document omit it still, in this case
  51986. // we return an empty dictionary.
  51987. return shadow(this, 'resources', this.getInheritedPageProp('Resources'));
  51988. },
  51989. get mediaBox() {
  51990. var obj = this.getInheritedPageProp('MediaBox');
  51991. // Reset invalid media box to letter size.
  51992. if (!isArray(obj) || obj.length !== 4) {
  51993. obj = LETTER_SIZE_MEDIABOX;
  51994. }
  51995. return shadow(this, 'mediaBox', obj);
  51996. },
  51997. get view() {
  51998. var mediaBox = this.mediaBox;
  51999. var cropBox = this.getInheritedPageProp('CropBox');
  52000. if (!isArray(cropBox) || cropBox.length !== 4) {
  52001. return shadow(this, 'view', mediaBox);
  52002. }
  52003. // From the spec, 6th ed., p.963:
  52004. // "The crop, bleed, trim, and art boxes should not ordinarily
  52005. // extend beyond the boundaries of the media box. If they do, they are
  52006. // effectively reduced to their intersection with the media box."
  52007. cropBox = Util.intersect(cropBox, mediaBox);
  52008. if (!cropBox) {
  52009. return shadow(this, 'view', mediaBox);
  52010. }
  52011. return shadow(this, 'view', cropBox);
  52012. },
  52013. get rotate() {
  52014. var rotate = this.getInheritedPageProp('Rotate') || 0;
  52015. // Normalize rotation so it's a multiple of 90 and between 0 and 270
  52016. if (rotate % 90 !== 0) {
  52017. rotate = 0;
  52018. } else if (rotate >= 360) {
  52019. rotate = rotate % 360;
  52020. } else if (rotate < 0) {
  52021. // The spec doesn't cover negatives, assume its counterclockwise
  52022. // rotation. The following is the other implementation of modulo.
  52023. rotate = (rotate % 360 + 360) % 360;
  52024. }
  52025. return shadow(this, 'rotate', rotate);
  52026. },
  52027. getContentStream: function Page_getContentStream() {
  52028. var content = this.content;
  52029. var stream;
  52030. if (isArray(content)) {
  52031. // fetching items
  52032. var xref = this.xref;
  52033. var i, n = content.length;
  52034. var streams = [];
  52035. for (i = 0; i < n; ++i) {
  52036. streams.push(xref.fetchIfRef(content[i]));
  52037. }
  52038. stream = new StreamsSequenceStream(streams);
  52039. } else if (isStream(content)) {
  52040. stream = content;
  52041. } else {
  52042. // replacing non-existent page content with empty one
  52043. stream = new NullStream();
  52044. }
  52045. return stream;
  52046. },
  52047. loadResources: function Page_loadResources(keys) {
  52048. if (!this.resourcesPromise) {
  52049. // TODO: add async getInheritedPageProp and remove this.
  52050. this.resourcesPromise = this.pdfManager.ensure(this, 'resources');
  52051. }
  52052. return this.resourcesPromise.then(function resourceSuccess() {
  52053. var objectLoader = new ObjectLoader(this.resources.map, keys, this.xref);
  52054. return objectLoader.load();
  52055. }.bind(this));
  52056. },
  52057. getOperatorList: function Page_getOperatorList(handler, task, intent, renderInteractiveForms) {
  52058. var self = this;
  52059. var pdfManager = this.pdfManager;
  52060. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream', []);
  52061. var resourcesPromise = this.loadResources([
  52062. 'ExtGState',
  52063. 'ColorSpace',
  52064. 'Pattern',
  52065. 'Shading',
  52066. 'XObject',
  52067. 'Font'
  52068. ]);
  52069. // ProcSet
  52070. // Properties
  52071. var partialEvaluator = new PartialEvaluator(pdfManager, this.xref, handler, this.pageIndex, this.uniquePrefix, this.idCounters, this.fontCache, this.evaluatorOptions);
  52072. var dataPromises = Promise.all([
  52073. contentStreamPromise,
  52074. resourcesPromise
  52075. ]);
  52076. var pageListPromise = dataPromises.then(function (data) {
  52077. var contentStream = data[0];
  52078. var opList = new OperatorList(intent, handler, self.pageIndex);
  52079. handler.send('StartRenderPage', {
  52080. transparency: partialEvaluator.hasBlendModes(self.resources),
  52081. pageIndex: self.pageIndex,
  52082. intent: intent
  52083. });
  52084. return partialEvaluator.getOperatorList(contentStream, task, self.resources, opList).then(function () {
  52085. return opList;
  52086. });
  52087. });
  52088. var annotationsPromise = pdfManager.ensure(this, 'annotations');
  52089. return Promise.all([
  52090. pageListPromise,
  52091. annotationsPromise
  52092. ]).then(function (datas) {
  52093. var pageOpList = datas[0];
  52094. var annotations = datas[1];
  52095. if (annotations.length === 0) {
  52096. pageOpList.flush(true);
  52097. return pageOpList;
  52098. }
  52099. var annotationsReadyPromise = Annotation.appendToOperatorList(annotations, pageOpList, partialEvaluator, task, intent, renderInteractiveForms);
  52100. return annotationsReadyPromise.then(function () {
  52101. pageOpList.flush(true);
  52102. return pageOpList;
  52103. });
  52104. });
  52105. },
  52106. extractTextContent: function Page_extractTextContent(task, normalizeWhitespace, combineTextItems) {
  52107. var handler = {
  52108. on: function nullHandlerOn() {
  52109. },
  52110. send: function nullHandlerSend() {
  52111. }
  52112. };
  52113. var self = this;
  52114. var pdfManager = this.pdfManager;
  52115. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream', []);
  52116. var resourcesPromise = this.loadResources([
  52117. 'ExtGState',
  52118. 'XObject',
  52119. 'Font'
  52120. ]);
  52121. var dataPromises = Promise.all([
  52122. contentStreamPromise,
  52123. resourcesPromise
  52124. ]);
  52125. return dataPromises.then(function (data) {
  52126. var contentStream = data[0];
  52127. var partialEvaluator = new PartialEvaluator(pdfManager, self.xref, handler, self.pageIndex, self.uniquePrefix, self.idCounters, self.fontCache, self.evaluatorOptions);
  52128. return partialEvaluator.getTextContent(contentStream, task, self.resources, /* stateManager = */
  52129. null, normalizeWhitespace, combineTextItems);
  52130. });
  52131. },
  52132. getAnnotationsData: function Page_getAnnotationsData(intent) {
  52133. var annotations = this.annotations;
  52134. var annotationsData = [];
  52135. for (var i = 0, n = annotations.length; i < n; ++i) {
  52136. if (intent) {
  52137. if (!(intent === 'display' && annotations[i].viewable) && !(intent === 'print' && annotations[i].printable)) {
  52138. continue;
  52139. }
  52140. }
  52141. annotationsData.push(annotations[i].data);
  52142. }
  52143. return annotationsData;
  52144. },
  52145. get annotations() {
  52146. var annotations = [];
  52147. var annotationRefs = this.getInheritedPageProp('Annots') || [];
  52148. var annotationFactory = new AnnotationFactory();
  52149. for (var i = 0, n = annotationRefs.length; i < n; ++i) {
  52150. var annotationRef = annotationRefs[i];
  52151. var annotation = annotationFactory.create(this.xref, annotationRef, this.pdfManager, this.uniquePrefix, this.idCounters);
  52152. if (annotation) {
  52153. annotations.push(annotation);
  52154. }
  52155. }
  52156. return shadow(this, 'annotations', annotations);
  52157. }
  52158. };
  52159. return Page;
  52160. }();
  52161. /**
  52162. * The `PDFDocument` holds all the data of the PDF file. Compared to the
  52163. * `PDFDoc`, this one doesn't have any job management code.
  52164. * Right now there exists one PDFDocument on the main thread + one object
  52165. * for each worker. If there is no worker support enabled, there are two
  52166. * `PDFDocument` objects on the main thread created.
  52167. */
  52168. var PDFDocument = function PDFDocumentClosure() {
  52169. var FINGERPRINT_FIRST_BYTES = 1024;
  52170. var EMPTY_FINGERPRINT = '\x00\x00\x00\x00\x00\x00\x00' + '\x00\x00\x00\x00\x00\x00\x00\x00\x00';
  52171. function PDFDocument(pdfManager, arg, password) {
  52172. if (isStream(arg)) {
  52173. init.call(this, pdfManager, arg, password);
  52174. } else if (isArrayBuffer(arg)) {
  52175. init.call(this, pdfManager, new Stream(arg), password);
  52176. } else {
  52177. error('PDFDocument: Unknown argument type');
  52178. }
  52179. }
  52180. function init(pdfManager, stream, password) {
  52181. assert(stream.length > 0, 'stream must have data');
  52182. this.pdfManager = pdfManager;
  52183. this.stream = stream;
  52184. var xref = new XRef(this.stream, password, pdfManager);
  52185. this.xref = xref;
  52186. }
  52187. function find(stream, needle, limit, backwards) {
  52188. var pos = stream.pos;
  52189. var end = stream.end;
  52190. var strBuf = [];
  52191. if (pos + limit > end) {
  52192. limit = end - pos;
  52193. }
  52194. for (var n = 0; n < limit; ++n) {
  52195. strBuf.push(String.fromCharCode(stream.getByte()));
  52196. }
  52197. var str = strBuf.join('');
  52198. stream.pos = pos;
  52199. var index = backwards ? str.lastIndexOf(needle) : str.indexOf(needle);
  52200. if (index === -1) {
  52201. return false;
  52202. }
  52203. /* not found */
  52204. stream.pos += index;
  52205. return true;
  52206. }
  52207. /* found */
  52208. var DocumentInfoValidators = {
  52209. get entries() {
  52210. // Lazily build this since all the validation functions below are not
  52211. // defined until after this file loads.
  52212. return shadow(this, 'entries', {
  52213. Title: isString,
  52214. Author: isString,
  52215. Subject: isString,
  52216. Keywords: isString,
  52217. Creator: isString,
  52218. Producer: isString,
  52219. CreationDate: isString,
  52220. ModDate: isString,
  52221. Trapped: isName
  52222. });
  52223. }
  52224. };
  52225. PDFDocument.prototype = {
  52226. parse: function PDFDocument_parse(recoveryMode) {
  52227. this.setup(recoveryMode);
  52228. var version = this.catalog.catDict.get('Version');
  52229. if (isName(version)) {
  52230. this.pdfFormatVersion = version.name;
  52231. }
  52232. try {
  52233. // checking if AcroForm is present
  52234. this.acroForm = this.catalog.catDict.get('AcroForm');
  52235. if (this.acroForm) {
  52236. this.xfa = this.acroForm.get('XFA');
  52237. var fields = this.acroForm.get('Fields');
  52238. if ((!fields || !isArray(fields) || fields.length === 0) && !this.xfa) {
  52239. // no fields and no XFA -- not a form (?)
  52240. this.acroForm = null;
  52241. }
  52242. }
  52243. } catch (ex) {
  52244. info('Something wrong with AcroForm entry');
  52245. this.acroForm = null;
  52246. }
  52247. },
  52248. get linearization() {
  52249. var linearization = null;
  52250. if (this.stream.length) {
  52251. try {
  52252. linearization = Linearization.create(this.stream);
  52253. } catch (err) {
  52254. if (err instanceof MissingDataException) {
  52255. throw err;
  52256. }
  52257. info(err);
  52258. }
  52259. }
  52260. // shadow the prototype getter with a data property
  52261. return shadow(this, 'linearization', linearization);
  52262. },
  52263. get startXRef() {
  52264. var stream = this.stream;
  52265. var startXRef = 0;
  52266. var linearization = this.linearization;
  52267. if (linearization) {
  52268. // Find end of first obj.
  52269. stream.reset();
  52270. if (find(stream, 'endobj', 1024)) {
  52271. startXRef = stream.pos + 6;
  52272. }
  52273. } else {
  52274. // Find startxref by jumping backward from the end of the file.
  52275. var step = 1024;
  52276. var found = false, pos = stream.end;
  52277. while (!found && pos > 0) {
  52278. pos -= step - 'startxref'.length;
  52279. if (pos < 0) {
  52280. pos = 0;
  52281. }
  52282. stream.pos = pos;
  52283. found = find(stream, 'startxref', step, true);
  52284. }
  52285. if (found) {
  52286. stream.skip(9);
  52287. var ch;
  52288. do {
  52289. ch = stream.getByte();
  52290. } while (isSpace(ch));
  52291. var str = '';
  52292. while (ch >= 0x20 && ch <= 0x39) {
  52293. // < '9'
  52294. str += String.fromCharCode(ch);
  52295. ch = stream.getByte();
  52296. }
  52297. startXRef = parseInt(str, 10);
  52298. if (isNaN(startXRef)) {
  52299. startXRef = 0;
  52300. }
  52301. }
  52302. }
  52303. // shadow the prototype getter with a data property
  52304. return shadow(this, 'startXRef', startXRef);
  52305. },
  52306. get mainXRefEntriesOffset() {
  52307. var mainXRefEntriesOffset = 0;
  52308. var linearization = this.linearization;
  52309. if (linearization) {
  52310. mainXRefEntriesOffset = linearization.mainXRefEntriesOffset;
  52311. }
  52312. // shadow the prototype getter with a data property
  52313. return shadow(this, 'mainXRefEntriesOffset', mainXRefEntriesOffset);
  52314. },
  52315. // Find the header, remove leading garbage and setup the stream
  52316. // starting from the header.
  52317. checkHeader: function PDFDocument_checkHeader() {
  52318. var stream = this.stream;
  52319. stream.reset();
  52320. if (find(stream, '%PDF-', 1024)) {
  52321. // Found the header, trim off any garbage before it.
  52322. stream.moveStart();
  52323. // Reading file format version
  52324. var MAX_VERSION_LENGTH = 12;
  52325. var version = '', ch;
  52326. while ((ch = stream.getByte()) > 0x20) {
  52327. // SPACE
  52328. if (version.length >= MAX_VERSION_LENGTH) {
  52329. break;
  52330. }
  52331. version += String.fromCharCode(ch);
  52332. }
  52333. if (!this.pdfFormatVersion) {
  52334. // removing "%PDF-"-prefix
  52335. this.pdfFormatVersion = version.substring(5);
  52336. }
  52337. return;
  52338. }
  52339. },
  52340. // May not be a PDF file, continue anyway.
  52341. parseStartXRef: function PDFDocument_parseStartXRef() {
  52342. var startXRef = this.startXRef;
  52343. this.xref.setStartXRef(startXRef);
  52344. },
  52345. setup: function PDFDocument_setup(recoveryMode) {
  52346. this.xref.parse(recoveryMode);
  52347. var self = this;
  52348. var pageFactory = {
  52349. createPage: function (pageIndex, dict, ref, fontCache) {
  52350. return new Page(self.pdfManager, self.xref, pageIndex, dict, ref, fontCache);
  52351. }
  52352. };
  52353. this.catalog = new Catalog(this.pdfManager, this.xref, pageFactory);
  52354. },
  52355. get numPages() {
  52356. var linearization = this.linearization;
  52357. var num = linearization ? linearization.numPages : this.catalog.numPages;
  52358. // shadow the prototype getter
  52359. return shadow(this, 'numPages', num);
  52360. },
  52361. get documentInfo() {
  52362. var docInfo = {
  52363. PDFFormatVersion: this.pdfFormatVersion,
  52364. IsAcroFormPresent: !!this.acroForm,
  52365. IsXFAPresent: !!this.xfa
  52366. };
  52367. var infoDict;
  52368. try {
  52369. infoDict = this.xref.trailer.get('Info');
  52370. } catch (err) {
  52371. info('The document information dictionary is invalid.');
  52372. }
  52373. if (infoDict) {
  52374. var validEntries = DocumentInfoValidators.entries;
  52375. // Only fill the document info with valid entries from the spec.
  52376. for (var key in validEntries) {
  52377. if (infoDict.has(key)) {
  52378. var value = infoDict.get(key);
  52379. // Make sure the value conforms to the spec.
  52380. if (validEntries[key](value)) {
  52381. docInfo[key] = typeof value !== 'string' ? value : stringToPDFString(value);
  52382. } else {
  52383. info('Bad value in document info for "' + key + '"');
  52384. }
  52385. }
  52386. }
  52387. }
  52388. return shadow(this, 'documentInfo', docInfo);
  52389. },
  52390. get fingerprint() {
  52391. var xref = this.xref, hash, fileID = '';
  52392. var idArray = xref.trailer.get('ID');
  52393. if (idArray && isArray(idArray) && idArray[0] && isString(idArray[0]) && idArray[0] !== EMPTY_FINGERPRINT) {
  52394. hash = stringToBytes(idArray[0]);
  52395. } else {
  52396. if (this.stream.ensureRange) {
  52397. this.stream.ensureRange(0, Math.min(FINGERPRINT_FIRST_BYTES, this.stream.end));
  52398. }
  52399. hash = calculateMD5(this.stream.bytes.subarray(0, FINGERPRINT_FIRST_BYTES), 0, FINGERPRINT_FIRST_BYTES);
  52400. }
  52401. for (var i = 0, n = hash.length; i < n; i++) {
  52402. var hex = hash[i].toString(16);
  52403. fileID += hex.length === 1 ? '0' + hex : hex;
  52404. }
  52405. return shadow(this, 'fingerprint', fileID);
  52406. },
  52407. getPage: function PDFDocument_getPage(pageIndex) {
  52408. return this.catalog.getPage(pageIndex);
  52409. },
  52410. cleanup: function PDFDocument_cleanup() {
  52411. return this.catalog.cleanup();
  52412. }
  52413. };
  52414. return PDFDocument;
  52415. }();
  52416. exports.Page = Page;
  52417. exports.PDFDocument = PDFDocument;
  52418. }));
  52419. (function (root, factory) {
  52420. factory(root.pdfjsCorePdfManager = {}, root.pdfjsSharedUtil, root.pdfjsCoreStream, root.pdfjsCoreChunkedStream, root.pdfjsCoreDocument);
  52421. }(this, function (exports, sharedUtil, coreStream, coreChunkedStream, coreDocument) {
  52422. var warn = sharedUtil.warn;
  52423. var createValidAbsoluteUrl = sharedUtil.createValidAbsoluteUrl;
  52424. var shadow = sharedUtil.shadow;
  52425. var NotImplementedException = sharedUtil.NotImplementedException;
  52426. var MissingDataException = sharedUtil.MissingDataException;
  52427. var createPromiseCapability = sharedUtil.createPromiseCapability;
  52428. var Util = sharedUtil.Util;
  52429. var Stream = coreStream.Stream;
  52430. var ChunkedStreamManager = coreChunkedStream.ChunkedStreamManager;
  52431. var PDFDocument = coreDocument.PDFDocument;
  52432. var BasePdfManager = function BasePdfManagerClosure() {
  52433. function BasePdfManager() {
  52434. throw new Error('Cannot initialize BaseManagerManager');
  52435. }
  52436. BasePdfManager.prototype = {
  52437. get docId() {
  52438. return this._docId;
  52439. },
  52440. get docBaseUrl() {
  52441. var docBaseUrl = null;
  52442. if (this._docBaseUrl) {
  52443. var absoluteUrl = createValidAbsoluteUrl(this._docBaseUrl);
  52444. if (absoluteUrl) {
  52445. docBaseUrl = absoluteUrl.href;
  52446. } else {
  52447. warn('Invalid absolute docBaseUrl: "' + this._docBaseUrl + '".');
  52448. }
  52449. }
  52450. return shadow(this, 'docBaseUrl', docBaseUrl);
  52451. },
  52452. onLoadedStream: function BasePdfManager_onLoadedStream() {
  52453. throw new NotImplementedException();
  52454. },
  52455. ensureDoc: function BasePdfManager_ensureDoc(prop, args) {
  52456. return this.ensure(this.pdfDocument, prop, args);
  52457. },
  52458. ensureXRef: function BasePdfManager_ensureXRef(prop, args) {
  52459. return this.ensure(this.pdfDocument.xref, prop, args);
  52460. },
  52461. ensureCatalog: function BasePdfManager_ensureCatalog(prop, args) {
  52462. return this.ensure(this.pdfDocument.catalog, prop, args);
  52463. },
  52464. getPage: function BasePdfManager_getPage(pageIndex) {
  52465. return this.pdfDocument.getPage(pageIndex);
  52466. },
  52467. cleanup: function BasePdfManager_cleanup() {
  52468. return this.pdfDocument.cleanup();
  52469. },
  52470. ensure: function BasePdfManager_ensure(obj, prop, args) {
  52471. return new NotImplementedException();
  52472. },
  52473. requestRange: function BasePdfManager_requestRange(begin, end) {
  52474. return new NotImplementedException();
  52475. },
  52476. requestLoadedStream: function BasePdfManager_requestLoadedStream() {
  52477. return new NotImplementedException();
  52478. },
  52479. sendProgressiveData: function BasePdfManager_sendProgressiveData(chunk) {
  52480. return new NotImplementedException();
  52481. },
  52482. updatePassword: function BasePdfManager_updatePassword(password) {
  52483. this.pdfDocument.xref.password = this.password = password;
  52484. if (this._passwordChangedCapability) {
  52485. this._passwordChangedCapability.resolve();
  52486. }
  52487. },
  52488. passwordChanged: function BasePdfManager_passwordChanged() {
  52489. this._passwordChangedCapability = createPromiseCapability();
  52490. return this._passwordChangedCapability.promise;
  52491. },
  52492. terminate: function BasePdfManager_terminate() {
  52493. return new NotImplementedException();
  52494. }
  52495. };
  52496. return BasePdfManager;
  52497. }();
  52498. var LocalPdfManager = function LocalPdfManagerClosure() {
  52499. function LocalPdfManager(docId, data, password, evaluatorOptions, docBaseUrl) {
  52500. this._docId = docId;
  52501. this._docBaseUrl = docBaseUrl;
  52502. this.evaluatorOptions = evaluatorOptions;
  52503. var stream = new Stream(data);
  52504. this.pdfDocument = new PDFDocument(this, stream, password);
  52505. this._loadedStreamCapability = createPromiseCapability();
  52506. this._loadedStreamCapability.resolve(stream);
  52507. }
  52508. Util.inherit(LocalPdfManager, BasePdfManager, {
  52509. ensure: function LocalPdfManager_ensure(obj, prop, args) {
  52510. return new Promise(function (resolve, reject) {
  52511. try {
  52512. var value = obj[prop];
  52513. var result;
  52514. if (typeof value === 'function') {
  52515. result = value.apply(obj, args);
  52516. } else {
  52517. result = value;
  52518. }
  52519. resolve(result);
  52520. } catch (e) {
  52521. reject(e);
  52522. }
  52523. });
  52524. },
  52525. requestRange: function LocalPdfManager_requestRange(begin, end) {
  52526. return Promise.resolve();
  52527. },
  52528. requestLoadedStream: function LocalPdfManager_requestLoadedStream() {
  52529. return;
  52530. },
  52531. onLoadedStream: function LocalPdfManager_onLoadedStream() {
  52532. return this._loadedStreamCapability.promise;
  52533. },
  52534. terminate: function LocalPdfManager_terminate() {
  52535. return;
  52536. }
  52537. });
  52538. return LocalPdfManager;
  52539. }();
  52540. var NetworkPdfManager = function NetworkPdfManagerClosure() {
  52541. function NetworkPdfManager(docId, pdfNetworkStream, args, evaluatorOptions, docBaseUrl) {
  52542. this._docId = docId;
  52543. this._docBaseUrl = docBaseUrl;
  52544. this.msgHandler = args.msgHandler;
  52545. this.evaluatorOptions = evaluatorOptions;
  52546. var params = {
  52547. msgHandler: args.msgHandler,
  52548. url: args.url,
  52549. length: args.length,
  52550. disableAutoFetch: args.disableAutoFetch,
  52551. rangeChunkSize: args.rangeChunkSize
  52552. };
  52553. this.streamManager = new ChunkedStreamManager(pdfNetworkStream, params);
  52554. this.pdfDocument = new PDFDocument(this, this.streamManager.getStream(), args.password);
  52555. }
  52556. Util.inherit(NetworkPdfManager, BasePdfManager, {
  52557. ensure: function NetworkPdfManager_ensure(obj, prop, args) {
  52558. var pdfManager = this;
  52559. return new Promise(function (resolve, reject) {
  52560. function ensureHelper() {
  52561. try {
  52562. var result;
  52563. var value = obj[prop];
  52564. if (typeof value === 'function') {
  52565. result = value.apply(obj, args);
  52566. } else {
  52567. result = value;
  52568. }
  52569. resolve(result);
  52570. } catch (e) {
  52571. if (!(e instanceof MissingDataException)) {
  52572. reject(e);
  52573. return;
  52574. }
  52575. pdfManager.streamManager.requestRange(e.begin, e.end).then(ensureHelper, reject);
  52576. }
  52577. }
  52578. ensureHelper();
  52579. });
  52580. },
  52581. requestRange: function NetworkPdfManager_requestRange(begin, end) {
  52582. return this.streamManager.requestRange(begin, end);
  52583. },
  52584. requestLoadedStream: function NetworkPdfManager_requestLoadedStream() {
  52585. this.streamManager.requestAllChunks();
  52586. },
  52587. sendProgressiveData: function NetworkPdfManager_sendProgressiveData(chunk) {
  52588. this.streamManager.onReceiveData({ chunk: chunk });
  52589. },
  52590. onLoadedStream: function NetworkPdfManager_onLoadedStream() {
  52591. return this.streamManager.onLoadedStream();
  52592. },
  52593. terminate: function NetworkPdfManager_terminate() {
  52594. this.streamManager.abort();
  52595. }
  52596. });
  52597. return NetworkPdfManager;
  52598. }();
  52599. exports.LocalPdfManager = LocalPdfManager;
  52600. exports.NetworkPdfManager = NetworkPdfManager;
  52601. }));
  52602. (function (root, factory) {
  52603. factory(root.pdfjsCoreWorker = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCorePdfManager);
  52604. }(this, function (exports, sharedUtil, corePrimitives, corePdfManager) {
  52605. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  52606. var InvalidPDFException = sharedUtil.InvalidPDFException;
  52607. var MessageHandler = sharedUtil.MessageHandler;
  52608. var MissingPDFException = sharedUtil.MissingPDFException;
  52609. var UnexpectedResponseException = sharedUtil.UnexpectedResponseException;
  52610. var PasswordException = sharedUtil.PasswordException;
  52611. var PasswordResponses = sharedUtil.PasswordResponses;
  52612. var UnknownErrorException = sharedUtil.UnknownErrorException;
  52613. var XRefParseException = sharedUtil.XRefParseException;
  52614. var arrayByteLength = sharedUtil.arrayByteLength;
  52615. var arraysToBytes = sharedUtil.arraysToBytes;
  52616. var assert = sharedUtil.assert;
  52617. var createPromiseCapability = sharedUtil.createPromiseCapability;
  52618. var error = sharedUtil.error;
  52619. var info = sharedUtil.info;
  52620. var warn = sharedUtil.warn;
  52621. var setVerbosityLevel = sharedUtil.setVerbosityLevel;
  52622. var Ref = corePrimitives.Ref;
  52623. var LocalPdfManager = corePdfManager.LocalPdfManager;
  52624. var NetworkPdfManager = corePdfManager.NetworkPdfManager;
  52625. var globalScope = sharedUtil.globalScope;
  52626. var WorkerTask = function WorkerTaskClosure() {
  52627. function WorkerTask(name) {
  52628. this.name = name;
  52629. this.terminated = false;
  52630. this._capability = createPromiseCapability();
  52631. }
  52632. WorkerTask.prototype = {
  52633. get finished() {
  52634. return this._capability.promise;
  52635. },
  52636. finish: function () {
  52637. this._capability.resolve();
  52638. },
  52639. terminate: function () {
  52640. this.terminated = true;
  52641. },
  52642. ensureNotTerminated: function () {
  52643. if (this.terminated) {
  52644. throw new Error('Worker task was terminated');
  52645. }
  52646. }
  52647. };
  52648. return WorkerTask;
  52649. }();
  52650. /** @implements {IPDFStream} */
  52651. var PDFWorkerStream = function PDFWorkerStreamClosure() {
  52652. function PDFWorkerStream(params, msgHandler) {
  52653. this._queuedChunks = [];
  52654. var initialData = params.initialData;
  52655. if (initialData && initialData.length > 0) {
  52656. this._queuedChunks.push(initialData);
  52657. }
  52658. this._msgHandler = msgHandler;
  52659. this._isRangeSupported = !params.disableRange;
  52660. this._isStreamingSupported = !params.disableStream;
  52661. this._contentLength = params.length;
  52662. this._fullRequestReader = null;
  52663. this._rangeReaders = [];
  52664. msgHandler.on('OnDataRange', this._onReceiveData.bind(this));
  52665. msgHandler.on('OnDataProgress', this._onProgress.bind(this));
  52666. }
  52667. PDFWorkerStream.prototype = {
  52668. _onReceiveData: function PDFWorkerStream_onReceiveData(args) {
  52669. if (args.begin === undefined) {
  52670. if (this._fullRequestReader) {
  52671. this._fullRequestReader._enqueue(args.chunk);
  52672. } else {
  52673. this._queuedChunks.push(args.chunk);
  52674. }
  52675. } else {
  52676. var found = this._rangeReaders.some(function (rangeReader) {
  52677. if (rangeReader._begin !== args.begin) {
  52678. return false;
  52679. }
  52680. rangeReader._enqueue(args.chunk);
  52681. return true;
  52682. });
  52683. assert(found);
  52684. }
  52685. },
  52686. _onProgress: function PDFWorkerStream_onProgress(evt) {
  52687. if (this._rangeReaders.length > 0) {
  52688. // Reporting to first range reader.
  52689. var firstReader = this._rangeReaders[0];
  52690. if (firstReader.onProgress) {
  52691. firstReader.onProgress({ loaded: evt.loaded });
  52692. }
  52693. }
  52694. },
  52695. _removeRangeReader: function PDFWorkerStream_removeRangeReader(reader) {
  52696. var i = this._rangeReaders.indexOf(reader);
  52697. if (i >= 0) {
  52698. this._rangeReaders.splice(i, 1);
  52699. }
  52700. },
  52701. getFullReader: function PDFWorkerStream_getFullReader() {
  52702. assert(!this._fullRequestReader);
  52703. var queuedChunks = this._queuedChunks;
  52704. this._queuedChunks = null;
  52705. return new PDFWorkerStreamReader(this, queuedChunks);
  52706. },
  52707. getRangeReader: function PDFWorkerStream_getRangeReader(begin, end) {
  52708. var reader = new PDFWorkerStreamRangeReader(this, begin, end);
  52709. this._msgHandler.send('RequestDataRange', {
  52710. begin: begin,
  52711. end: end
  52712. });
  52713. this._rangeReaders.push(reader);
  52714. return reader;
  52715. },
  52716. cancelAllRequests: function PDFWorkerStream_cancelAllRequests(reason) {
  52717. if (this._fullRequestReader) {
  52718. this._fullRequestReader.cancel(reason);
  52719. }
  52720. var readers = this._rangeReaders.slice(0);
  52721. readers.forEach(function (rangeReader) {
  52722. rangeReader.cancel(reason);
  52723. });
  52724. }
  52725. };
  52726. /** @implements {IPDFStreamReader} */
  52727. function PDFWorkerStreamReader(stream, queuedChunks) {
  52728. this._stream = stream;
  52729. this._done = false;
  52730. this._queuedChunks = queuedChunks || [];
  52731. this._requests = [];
  52732. this._headersReady = Promise.resolve();
  52733. stream._fullRequestReader = this;
  52734. this.onProgress = null;
  52735. }
  52736. // not used
  52737. PDFWorkerStreamReader.prototype = {
  52738. _enqueue: function PDFWorkerStreamReader_enqueue(chunk) {
  52739. if (this._done) {
  52740. return;
  52741. }
  52742. // ignore new data
  52743. if (this._requests.length > 0) {
  52744. var requestCapability = this._requests.shift();
  52745. requestCapability.resolve({
  52746. value: chunk,
  52747. done: false
  52748. });
  52749. return;
  52750. }
  52751. this._queuedChunks.push(chunk);
  52752. },
  52753. get headersReady() {
  52754. return this._headersReady;
  52755. },
  52756. get isRangeSupported() {
  52757. return this._stream._isRangeSupported;
  52758. },
  52759. get isStreamingSupported() {
  52760. return this._stream._isStreamingSupported;
  52761. },
  52762. get contentLength() {
  52763. return this._stream._contentLength;
  52764. },
  52765. read: function PDFWorkerStreamReader_read() {
  52766. if (this._queuedChunks.length > 0) {
  52767. var chunk = this._queuedChunks.shift();
  52768. return Promise.resolve({
  52769. value: chunk,
  52770. done: false
  52771. });
  52772. }
  52773. if (this._done) {
  52774. return Promise.resolve({
  52775. value: undefined,
  52776. done: true
  52777. });
  52778. }
  52779. var requestCapability = createPromiseCapability();
  52780. this._requests.push(requestCapability);
  52781. return requestCapability.promise;
  52782. },
  52783. cancel: function PDFWorkerStreamReader_cancel(reason) {
  52784. this._done = true;
  52785. this._requests.forEach(function (requestCapability) {
  52786. requestCapability.resolve({
  52787. value: undefined,
  52788. done: true
  52789. });
  52790. });
  52791. this._requests = [];
  52792. }
  52793. };
  52794. /** @implements {IPDFStreamRangeReader} */
  52795. function PDFWorkerStreamRangeReader(stream, begin, end) {
  52796. this._stream = stream;
  52797. this._begin = begin;
  52798. this._end = end;
  52799. this._queuedChunk = null;
  52800. this._requests = [];
  52801. this._done = false;
  52802. this.onProgress = null;
  52803. }
  52804. PDFWorkerStreamRangeReader.prototype = {
  52805. _enqueue: function PDFWorkerStreamRangeReader_enqueue(chunk) {
  52806. if (this._done) {
  52807. return;
  52808. }
  52809. // ignore new data
  52810. if (this._requests.length === 0) {
  52811. this._queuedChunk = chunk;
  52812. } else {
  52813. var requestsCapability = this._requests.shift();
  52814. requestsCapability.resolve({
  52815. value: chunk,
  52816. done: false
  52817. });
  52818. this._requests.forEach(function (requestCapability) {
  52819. requestCapability.resolve({
  52820. value: undefined,
  52821. done: true
  52822. });
  52823. });
  52824. this._requests = [];
  52825. }
  52826. this._done = true;
  52827. this._stream._removeRangeReader(this);
  52828. },
  52829. get isStreamingSupported() {
  52830. return false;
  52831. },
  52832. read: function PDFWorkerStreamRangeReader_read() {
  52833. if (this._queuedChunk) {
  52834. return Promise.resolve({
  52835. value: this._queuedChunk,
  52836. done: false
  52837. });
  52838. }
  52839. if (this._done) {
  52840. return Promise.resolve({
  52841. value: undefined,
  52842. done: true
  52843. });
  52844. }
  52845. var requestCapability = createPromiseCapability();
  52846. this._requests.push(requestCapability);
  52847. return requestCapability.promise;
  52848. },
  52849. cancel: function PDFWorkerStreamRangeReader_cancel(reason) {
  52850. this._done = true;
  52851. this._requests.forEach(function (requestCapability) {
  52852. requestCapability.resolve({
  52853. value: undefined,
  52854. done: true
  52855. });
  52856. });
  52857. this._requests = [];
  52858. this._stream._removeRangeReader(this);
  52859. }
  52860. };
  52861. return PDFWorkerStream;
  52862. }();
  52863. /** @type IPDFStream */
  52864. var PDFNetworkStream;
  52865. /**
  52866. * Sets PDFNetworkStream class to be used as alternative PDF data transport.
  52867. * @param {IPDFStream} cls - the PDF data transport.
  52868. */
  52869. function setPDFNetworkStreamClass(cls) {
  52870. PDFNetworkStream = cls;
  52871. }
  52872. var WorkerMessageHandler = {
  52873. setup: function wphSetup(handler, port) {
  52874. var testMessageProcessed = false;
  52875. handler.on('test', function wphSetupTest(data) {
  52876. if (testMessageProcessed) {
  52877. return;
  52878. }
  52879. // we already processed 'test' message once
  52880. testMessageProcessed = true;
  52881. // check if Uint8Array can be sent to worker
  52882. if (!(data instanceof Uint8Array)) {
  52883. handler.send('test', 'main', false);
  52884. return;
  52885. }
  52886. // making sure postMessage transfers are working
  52887. var supportTransfers = data[0] === 255;
  52888. handler.postMessageTransfers = supportTransfers;
  52889. // check if the response property is supported by xhr
  52890. var xhr = new XMLHttpRequest();
  52891. var responseExists = 'response' in xhr;
  52892. // check if the property is actually implemented
  52893. try {
  52894. var dummy = xhr.responseType;
  52895. } catch (e) {
  52896. responseExists = false;
  52897. }
  52898. if (!responseExists) {
  52899. handler.send('test', false);
  52900. return;
  52901. }
  52902. handler.send('test', {
  52903. supportTypedArray: true,
  52904. supportTransfers: supportTransfers
  52905. });
  52906. });
  52907. handler.on('configure', function wphConfigure(data) {
  52908. setVerbosityLevel(data.verbosity);
  52909. });
  52910. handler.on('GetDocRequest', function wphSetupDoc(data) {
  52911. return WorkerMessageHandler.createDocumentHandler(data, port);
  52912. });
  52913. },
  52914. createDocumentHandler: function wphCreateDocumentHandler(docParams, port) {
  52915. // This context is actually holds references on pdfManager and handler,
  52916. // until the latter is destroyed.
  52917. var pdfManager;
  52918. var terminated = false;
  52919. var cancelXHRs = null;
  52920. var WorkerTasks = [];
  52921. var docId = docParams.docId;
  52922. var docBaseUrl = docParams.docBaseUrl;
  52923. var workerHandlerName = docParams.docId + '_worker';
  52924. var handler = new MessageHandler(workerHandlerName, docId, port);
  52925. // Ensure that postMessage transfers are correctly enabled/disabled,
  52926. // to prevent "DataCloneError" in older versions of IE (see issue 6957).
  52927. handler.postMessageTransfers = docParams.postMessageTransfers;
  52928. function ensureNotTerminated() {
  52929. if (terminated) {
  52930. throw new Error('Worker was terminated');
  52931. }
  52932. }
  52933. function startWorkerTask(task) {
  52934. WorkerTasks.push(task);
  52935. }
  52936. function finishWorkerTask(task) {
  52937. task.finish();
  52938. var i = WorkerTasks.indexOf(task);
  52939. WorkerTasks.splice(i, 1);
  52940. }
  52941. function loadDocument(recoveryMode) {
  52942. var loadDocumentCapability = createPromiseCapability();
  52943. var parseSuccess = function parseSuccess() {
  52944. var numPagesPromise = pdfManager.ensureDoc('numPages');
  52945. var fingerprintPromise = pdfManager.ensureDoc('fingerprint');
  52946. var encryptedPromise = pdfManager.ensureXRef('encrypt');
  52947. Promise.all([
  52948. numPagesPromise,
  52949. fingerprintPromise,
  52950. encryptedPromise
  52951. ]).then(function onDocReady(results) {
  52952. var doc = {
  52953. numPages: results[0],
  52954. fingerprint: results[1],
  52955. encrypted: !!results[2]
  52956. };
  52957. loadDocumentCapability.resolve(doc);
  52958. }, parseFailure);
  52959. };
  52960. var parseFailure = function parseFailure(e) {
  52961. loadDocumentCapability.reject(e);
  52962. };
  52963. pdfManager.ensureDoc('checkHeader', []).then(function () {
  52964. pdfManager.ensureDoc('parseStartXRef', []).then(function () {
  52965. pdfManager.ensureDoc('parse', [recoveryMode]).then(parseSuccess, parseFailure);
  52966. }, parseFailure);
  52967. }, parseFailure);
  52968. return loadDocumentCapability.promise;
  52969. }
  52970. function getPdfManager(data, evaluatorOptions) {
  52971. var pdfManagerCapability = createPromiseCapability();
  52972. var pdfManager;
  52973. var source = data.source;
  52974. if (source.data) {
  52975. try {
  52976. pdfManager = new LocalPdfManager(docId, source.data, source.password, evaluatorOptions, docBaseUrl);
  52977. pdfManagerCapability.resolve(pdfManager);
  52978. } catch (ex) {
  52979. pdfManagerCapability.reject(ex);
  52980. }
  52981. return pdfManagerCapability.promise;
  52982. }
  52983. var pdfStream;
  52984. try {
  52985. if (source.chunkedViewerLoading) {
  52986. pdfStream = new PDFWorkerStream(source, handler);
  52987. } else {
  52988. assert(PDFNetworkStream, 'pdfjs/core/network module is not loaded');
  52989. pdfStream = new PDFNetworkStream(data);
  52990. }
  52991. } catch (ex) {
  52992. pdfManagerCapability.reject(ex);
  52993. return pdfManagerCapability.promise;
  52994. }
  52995. var fullRequest = pdfStream.getFullReader();
  52996. fullRequest.headersReady.then(function () {
  52997. if (!fullRequest.isStreamingSupported || !fullRequest.isRangeSupported) {
  52998. // If stream or range are disabled, it's our only way to report
  52999. // loading progress.
  53000. fullRequest.onProgress = function (evt) {
  53001. handler.send('DocProgress', {
  53002. loaded: evt.loaded,
  53003. total: evt.total
  53004. });
  53005. };
  53006. }
  53007. if (!fullRequest.isRangeSupported) {
  53008. return;
  53009. }
  53010. // We don't need auto-fetch when streaming is enabled.
  53011. var disableAutoFetch = source.disableAutoFetch || fullRequest.isStreamingSupported;
  53012. pdfManager = new NetworkPdfManager(docId, pdfStream, {
  53013. msgHandler: handler,
  53014. url: source.url,
  53015. password: source.password,
  53016. length: fullRequest.contentLength,
  53017. disableAutoFetch: disableAutoFetch,
  53018. rangeChunkSize: source.rangeChunkSize
  53019. }, evaluatorOptions, docBaseUrl);
  53020. pdfManagerCapability.resolve(pdfManager);
  53021. cancelXHRs = null;
  53022. }).catch(function (reason) {
  53023. pdfManagerCapability.reject(reason);
  53024. cancelXHRs = null;
  53025. });
  53026. var cachedChunks = [], loaded = 0;
  53027. var flushChunks = function () {
  53028. var pdfFile = arraysToBytes(cachedChunks);
  53029. if (source.length && pdfFile.length !== source.length) {
  53030. warn('reported HTTP length is different from actual');
  53031. }
  53032. // the data is array, instantiating directly from it
  53033. try {
  53034. pdfManager = new LocalPdfManager(docId, pdfFile, source.password, evaluatorOptions, docBaseUrl);
  53035. pdfManagerCapability.resolve(pdfManager);
  53036. } catch (ex) {
  53037. pdfManagerCapability.reject(ex);
  53038. }
  53039. cachedChunks = [];
  53040. };
  53041. var readPromise = new Promise(function (resolve, reject) {
  53042. var readChunk = function (chunk) {
  53043. try {
  53044. ensureNotTerminated();
  53045. if (chunk.done) {
  53046. if (!pdfManager) {
  53047. flushChunks();
  53048. }
  53049. cancelXHRs = null;
  53050. return;
  53051. }
  53052. var data = chunk.value;
  53053. loaded += arrayByteLength(data);
  53054. if (!fullRequest.isStreamingSupported) {
  53055. handler.send('DocProgress', {
  53056. loaded: loaded,
  53057. total: Math.max(loaded, fullRequest.contentLength || 0)
  53058. });
  53059. }
  53060. if (pdfManager) {
  53061. pdfManager.sendProgressiveData(data);
  53062. } else {
  53063. cachedChunks.push(data);
  53064. }
  53065. fullRequest.read().then(readChunk, reject);
  53066. } catch (e) {
  53067. reject(e);
  53068. }
  53069. };
  53070. fullRequest.read().then(readChunk, reject);
  53071. });
  53072. readPromise.catch(function (e) {
  53073. pdfManagerCapability.reject(e);
  53074. cancelXHRs = null;
  53075. });
  53076. cancelXHRs = function () {
  53077. pdfStream.cancelAllRequests('abort');
  53078. };
  53079. return pdfManagerCapability.promise;
  53080. }
  53081. var setupDoc = function (data) {
  53082. var onSuccess = function (doc) {
  53083. ensureNotTerminated();
  53084. handler.send('GetDoc', { pdfInfo: doc });
  53085. };
  53086. var onFailure = function (e) {
  53087. if (e instanceof PasswordException) {
  53088. if (e.code === PasswordResponses.NEED_PASSWORD) {
  53089. handler.send('NeedPassword', e);
  53090. } else if (e.code === PasswordResponses.INCORRECT_PASSWORD) {
  53091. handler.send('IncorrectPassword', e);
  53092. }
  53093. } else if (e instanceof InvalidPDFException) {
  53094. handler.send('InvalidPDF', e);
  53095. } else if (e instanceof MissingPDFException) {
  53096. handler.send('MissingPDF', e);
  53097. } else if (e instanceof UnexpectedResponseException) {
  53098. handler.send('UnexpectedResponse', e);
  53099. } else {
  53100. handler.send('UnknownError', new UnknownErrorException(e.message, e.toString()));
  53101. }
  53102. };
  53103. ensureNotTerminated();
  53104. var cMapOptions = {
  53105. url: data.cMapUrl === undefined ? null : data.cMapUrl,
  53106. packed: data.cMapPacked === true
  53107. };
  53108. var evaluatorOptions = {
  53109. forceDataSchema: data.disableCreateObjectURL,
  53110. maxImageSize: data.maxImageSize === undefined ? -1 : data.maxImageSize,
  53111. disableFontFace: data.disableFontFace,
  53112. cMapOptions: cMapOptions
  53113. };
  53114. getPdfManager(data, evaluatorOptions).then(function (newPdfManager) {
  53115. if (terminated) {
  53116. // We were in a process of setting up the manager, but it got
  53117. // terminated in the middle.
  53118. newPdfManager.terminate();
  53119. throw new Error('Worker was terminated');
  53120. }
  53121. pdfManager = newPdfManager;
  53122. handler.send('PDFManagerReady', null);
  53123. pdfManager.onLoadedStream().then(function (stream) {
  53124. handler.send('DataLoaded', { length: stream.bytes.byteLength });
  53125. });
  53126. }).then(function pdfManagerReady() {
  53127. ensureNotTerminated();
  53128. loadDocument(false).then(onSuccess, function loadFailure(ex) {
  53129. ensureNotTerminated();
  53130. // Try again with recoveryMode == true
  53131. if (!(ex instanceof XRefParseException)) {
  53132. if (ex instanceof PasswordException) {
  53133. // after password exception prepare to receive a new password
  53134. // to repeat loading
  53135. pdfManager.passwordChanged().then(pdfManagerReady);
  53136. }
  53137. onFailure(ex);
  53138. return;
  53139. }
  53140. pdfManager.requestLoadedStream();
  53141. pdfManager.onLoadedStream().then(function () {
  53142. ensureNotTerminated();
  53143. loadDocument(true).then(onSuccess, onFailure);
  53144. });
  53145. }, onFailure);
  53146. }, onFailure);
  53147. };
  53148. handler.on('GetPage', function wphSetupGetPage(data) {
  53149. return pdfManager.getPage(data.pageIndex).then(function (page) {
  53150. var rotatePromise = pdfManager.ensure(page, 'rotate');
  53151. var refPromise = pdfManager.ensure(page, 'ref');
  53152. var viewPromise = pdfManager.ensure(page, 'view');
  53153. return Promise.all([
  53154. rotatePromise,
  53155. refPromise,
  53156. viewPromise
  53157. ]).then(function (results) {
  53158. return {
  53159. rotate: results[0],
  53160. ref: results[1],
  53161. view: results[2]
  53162. };
  53163. });
  53164. });
  53165. });
  53166. handler.on('GetPageIndex', function wphSetupGetPageIndex(data) {
  53167. var ref = new Ref(data.ref.num, data.ref.gen);
  53168. var catalog = pdfManager.pdfDocument.catalog;
  53169. return catalog.getPageIndex(ref);
  53170. });
  53171. handler.on('GetDestinations', function wphSetupGetDestinations(data) {
  53172. return pdfManager.ensureCatalog('destinations');
  53173. });
  53174. handler.on('GetDestination', function wphSetupGetDestination(data) {
  53175. return pdfManager.ensureCatalog('getDestination', [data.id]);
  53176. });
  53177. handler.on('GetPageLabels', function wphSetupGetPageLabels(data) {
  53178. return pdfManager.ensureCatalog('pageLabels');
  53179. });
  53180. handler.on('GetAttachments', function wphSetupGetAttachments(data) {
  53181. return pdfManager.ensureCatalog('attachments');
  53182. });
  53183. handler.on('GetJavaScript', function wphSetupGetJavaScript(data) {
  53184. return pdfManager.ensureCatalog('javaScript');
  53185. });
  53186. handler.on('GetOutline', function wphSetupGetOutline(data) {
  53187. return pdfManager.ensureCatalog('documentOutline');
  53188. });
  53189. handler.on('GetMetadata', function wphSetupGetMetadata(data) {
  53190. return Promise.all([
  53191. pdfManager.ensureDoc('documentInfo'),
  53192. pdfManager.ensureCatalog('metadata')
  53193. ]);
  53194. });
  53195. handler.on('GetData', function wphSetupGetData(data) {
  53196. pdfManager.requestLoadedStream();
  53197. return pdfManager.onLoadedStream().then(function (stream) {
  53198. return stream.bytes;
  53199. });
  53200. });
  53201. handler.on('GetStats', function wphSetupGetStats(data) {
  53202. return pdfManager.pdfDocument.xref.stats;
  53203. });
  53204. handler.on('UpdatePassword', function wphSetupUpdatePassword(data) {
  53205. pdfManager.updatePassword(data);
  53206. });
  53207. handler.on('GetAnnotations', function wphSetupGetAnnotations(data) {
  53208. return pdfManager.getPage(data.pageIndex).then(function (page) {
  53209. return pdfManager.ensure(page, 'getAnnotationsData', [data.intent]);
  53210. });
  53211. });
  53212. handler.on('RenderPageRequest', function wphSetupRenderPage(data) {
  53213. var pageIndex = data.pageIndex;
  53214. pdfManager.getPage(pageIndex).then(function (page) {
  53215. var task = new WorkerTask('RenderPageRequest: page ' + pageIndex);
  53216. startWorkerTask(task);
  53217. var pageNum = pageIndex + 1;
  53218. var start = Date.now();
  53219. // Pre compile the pdf page and fetch the fonts/images.
  53220. page.getOperatorList(handler, task, data.intent, data.renderInteractiveForms).then(function (operatorList) {
  53221. finishWorkerTask(task);
  53222. info('page=' + pageNum + ' - getOperatorList: time=' + (Date.now() - start) + 'ms, len=' + operatorList.totalLength);
  53223. }, function (e) {
  53224. finishWorkerTask(task);
  53225. if (task.terminated) {
  53226. return;
  53227. }
  53228. // ignoring errors from the terminated thread
  53229. // For compatibility with older behavior, generating unknown
  53230. // unsupported feature notification on errors.
  53231. handler.send('UnsupportedFeature', { featureId: UNSUPPORTED_FEATURES.unknown });
  53232. var minimumStackMessage = 'worker.js: while trying to getPage() and getOperatorList()';
  53233. var wrappedException;
  53234. // Turn the error into an obj that can be serialized
  53235. if (typeof e === 'string') {
  53236. wrappedException = {
  53237. message: e,
  53238. stack: minimumStackMessage
  53239. };
  53240. } else if (typeof e === 'object') {
  53241. wrappedException = {
  53242. message: e.message || e.toString(),
  53243. stack: e.stack || minimumStackMessage
  53244. };
  53245. } else {
  53246. wrappedException = {
  53247. message: 'Unknown exception type: ' + typeof e,
  53248. stack: minimumStackMessage
  53249. };
  53250. }
  53251. handler.send('PageError', {
  53252. pageNum: pageNum,
  53253. error: wrappedException,
  53254. intent: data.intent
  53255. });
  53256. });
  53257. });
  53258. }, this);
  53259. handler.on('GetTextContent', function wphExtractText(data) {
  53260. var pageIndex = data.pageIndex;
  53261. var normalizeWhitespace = data.normalizeWhitespace;
  53262. var combineTextItems = data.combineTextItems;
  53263. return pdfManager.getPage(pageIndex).then(function (page) {
  53264. var task = new WorkerTask('GetTextContent: page ' + pageIndex);
  53265. startWorkerTask(task);
  53266. var pageNum = pageIndex + 1;
  53267. var start = Date.now();
  53268. return page.extractTextContent(task, normalizeWhitespace, combineTextItems).then(function (textContent) {
  53269. finishWorkerTask(task);
  53270. info('text indexing: page=' + pageNum + ' - time=' + (Date.now() - start) + 'ms');
  53271. return textContent;
  53272. }, function (reason) {
  53273. finishWorkerTask(task);
  53274. if (task.terminated) {
  53275. return;
  53276. }
  53277. // ignoring errors from the terminated thread
  53278. throw reason;
  53279. });
  53280. });
  53281. });
  53282. handler.on('Cleanup', function wphCleanup(data) {
  53283. return pdfManager.cleanup();
  53284. });
  53285. handler.on('Terminate', function wphTerminate(data) {
  53286. terminated = true;
  53287. if (pdfManager) {
  53288. pdfManager.terminate();
  53289. pdfManager = null;
  53290. }
  53291. if (cancelXHRs) {
  53292. cancelXHRs();
  53293. }
  53294. var waitOn = [];
  53295. WorkerTasks.forEach(function (task) {
  53296. waitOn.push(task.finished);
  53297. task.terminate();
  53298. });
  53299. return Promise.all(waitOn).then(function () {
  53300. // Notice that even if we destroying handler, resolved response promise
  53301. // must be sent back.
  53302. handler.destroy();
  53303. handler = null;
  53304. });
  53305. });
  53306. handler.on('Ready', function wphReady(data) {
  53307. setupDoc(docParams);
  53308. docParams = null;
  53309. });
  53310. // we don't need docParams anymore -- saving memory.
  53311. return workerHandlerName;
  53312. }
  53313. };
  53314. function initializeWorker() {
  53315. if (!('console' in globalScope)) {
  53316. var consoleTimer = {};
  53317. var workerConsole = {
  53318. log: function log() {
  53319. var args = Array.prototype.slice.call(arguments);
  53320. globalScope.postMessage({
  53321. targetName: 'main',
  53322. action: 'console_log',
  53323. data: args
  53324. });
  53325. },
  53326. error: function error() {
  53327. var args = Array.prototype.slice.call(arguments);
  53328. globalScope.postMessage({
  53329. targetName: 'main',
  53330. action: 'console_error',
  53331. data: args
  53332. });
  53333. throw 'pdf.js execution error';
  53334. },
  53335. time: function time(name) {
  53336. consoleTimer[name] = Date.now();
  53337. },
  53338. timeEnd: function timeEnd(name) {
  53339. var time = consoleTimer[name];
  53340. if (!time) {
  53341. error('Unknown timer name ' + name);
  53342. }
  53343. this.log('Timer:', name, Date.now() - time);
  53344. }
  53345. };
  53346. globalScope.console = workerConsole;
  53347. }
  53348. var handler = new MessageHandler('worker', 'main', self);
  53349. WorkerMessageHandler.setup(handler, self);
  53350. handler.send('ready', null);
  53351. }
  53352. // Worker thread (and not node.js)?
  53353. if (typeof window === 'undefined' && !(typeof module !== 'undefined' && module.require)) {
  53354. initializeWorker();
  53355. }
  53356. exports.setPDFNetworkStreamClass = setPDFNetworkStreamClass;
  53357. exports.WorkerTask = WorkerTask;
  53358. exports.WorkerMessageHandler = WorkerMessageHandler;
  53359. }));
  53360. (function (root, factory) {
  53361. factory(root.pdfjsCoreNetwork = {}, root.pdfjsSharedUtil, root.pdfjsCoreWorker);
  53362. }(this, function (exports, sharedUtil, coreWorker) {
  53363. var OK_RESPONSE = 200;
  53364. var PARTIAL_CONTENT_RESPONSE = 206;
  53365. function NetworkManager(url, args) {
  53366. this.url = url;
  53367. args = args || {};
  53368. this.isHttp = /^https?:/i.test(url);
  53369. this.httpHeaders = this.isHttp && args.httpHeaders || {};
  53370. this.withCredentials = args.withCredentials || false;
  53371. this.getXhr = args.getXhr || function NetworkManager_getXhr() {
  53372. return new XMLHttpRequest();
  53373. };
  53374. this.currXhrId = 0;
  53375. this.pendingRequests = Object.create(null);
  53376. this.loadedRequests = Object.create(null);
  53377. }
  53378. function getArrayBuffer(xhr) {
  53379. var data = xhr.response;
  53380. if (typeof data !== 'string') {
  53381. return data;
  53382. }
  53383. var length = data.length;
  53384. var array = new Uint8Array(length);
  53385. for (var i = 0; i < length; i++) {
  53386. array[i] = data.charCodeAt(i) & 0xFF;
  53387. }
  53388. return array.buffer;
  53389. }
  53390. var supportsMozChunked = function supportsMozChunkedClosure() {
  53391. try {
  53392. var x = new XMLHttpRequest();
  53393. // Firefox 37- required .open() to be called before setting responseType.
  53394. // https://bugzilla.mozilla.org/show_bug.cgi?id=707484
  53395. // Even though the URL is not visited, .open() could fail if the URL is
  53396. // blocked, e.g. via the connect-src CSP directive or the NoScript addon.
  53397. // When this error occurs, this feature detection method will mistakenly
  53398. // report that moz-chunked-arraybuffer is not supported in Firefox 37-.
  53399. x.open('GET', 'https://example.com');
  53400. x.responseType = 'moz-chunked-arraybuffer';
  53401. return x.responseType === 'moz-chunked-arraybuffer';
  53402. } catch (e) {
  53403. return false;
  53404. }
  53405. }();
  53406. NetworkManager.prototype = {
  53407. requestRange: function NetworkManager_requestRange(begin, end, listeners) {
  53408. var args = {
  53409. begin: begin,
  53410. end: end
  53411. };
  53412. for (var prop in listeners) {
  53413. args[prop] = listeners[prop];
  53414. }
  53415. return this.request(args);
  53416. },
  53417. requestFull: function NetworkManager_requestFull(listeners) {
  53418. return this.request(listeners);
  53419. },
  53420. request: function NetworkManager_request(args) {
  53421. var xhr = this.getXhr();
  53422. var xhrId = this.currXhrId++;
  53423. var pendingRequest = this.pendingRequests[xhrId] = { xhr: xhr };
  53424. xhr.open('GET', this.url);
  53425. xhr.withCredentials = this.withCredentials;
  53426. for (var property in this.httpHeaders) {
  53427. var value = this.httpHeaders[property];
  53428. if (typeof value === 'undefined') {
  53429. continue;
  53430. }
  53431. xhr.setRequestHeader(property, value);
  53432. }
  53433. if (this.isHttp && 'begin' in args && 'end' in args) {
  53434. var rangeStr = args.begin + '-' + (args.end - 1);
  53435. xhr.setRequestHeader('Range', 'bytes=' + rangeStr);
  53436. pendingRequest.expectedStatus = 206;
  53437. } else {
  53438. pendingRequest.expectedStatus = 200;
  53439. }
  53440. var useMozChunkedLoading = supportsMozChunked && !!args.onProgressiveData;
  53441. if (useMozChunkedLoading) {
  53442. xhr.responseType = 'moz-chunked-arraybuffer';
  53443. pendingRequest.onProgressiveData = args.onProgressiveData;
  53444. pendingRequest.mozChunked = true;
  53445. } else {
  53446. xhr.responseType = 'arraybuffer';
  53447. }
  53448. if (args.onError) {
  53449. xhr.onerror = function (evt) {
  53450. args.onError(xhr.status);
  53451. };
  53452. }
  53453. xhr.onreadystatechange = this.onStateChange.bind(this, xhrId);
  53454. xhr.onprogress = this.onProgress.bind(this, xhrId);
  53455. pendingRequest.onHeadersReceived = args.onHeadersReceived;
  53456. pendingRequest.onDone = args.onDone;
  53457. pendingRequest.onError = args.onError;
  53458. pendingRequest.onProgress = args.onProgress;
  53459. xhr.send(null);
  53460. return xhrId;
  53461. },
  53462. onProgress: function NetworkManager_onProgress(xhrId, evt) {
  53463. var pendingRequest = this.pendingRequests[xhrId];
  53464. if (!pendingRequest) {
  53465. // Maybe abortRequest was called...
  53466. return;
  53467. }
  53468. if (pendingRequest.mozChunked) {
  53469. var chunk = getArrayBuffer(pendingRequest.xhr);
  53470. pendingRequest.onProgressiveData(chunk);
  53471. }
  53472. var onProgress = pendingRequest.onProgress;
  53473. if (onProgress) {
  53474. onProgress(evt);
  53475. }
  53476. },
  53477. onStateChange: function NetworkManager_onStateChange(xhrId, evt) {
  53478. var pendingRequest = this.pendingRequests[xhrId];
  53479. if (!pendingRequest) {
  53480. // Maybe abortRequest was called...
  53481. return;
  53482. }
  53483. var xhr = pendingRequest.xhr;
  53484. if (xhr.readyState >= 2 && pendingRequest.onHeadersReceived) {
  53485. pendingRequest.onHeadersReceived();
  53486. delete pendingRequest.onHeadersReceived;
  53487. }
  53488. if (xhr.readyState !== 4) {
  53489. return;
  53490. }
  53491. if (!(xhrId in this.pendingRequests)) {
  53492. // The XHR request might have been aborted in onHeadersReceived()
  53493. // callback, in which case we should abort request
  53494. return;
  53495. }
  53496. delete this.pendingRequests[xhrId];
  53497. // success status == 0 can be on ftp, file and other protocols
  53498. if (xhr.status === 0 && this.isHttp) {
  53499. if (pendingRequest.onError) {
  53500. pendingRequest.onError(xhr.status);
  53501. }
  53502. return;
  53503. }
  53504. var xhrStatus = xhr.status || OK_RESPONSE;
  53505. // From http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.2:
  53506. // "A server MAY ignore the Range header". This means it's possible to
  53507. // get a 200 rather than a 206 response from a range request.
  53508. var ok_response_on_range_request = xhrStatus === OK_RESPONSE && pendingRequest.expectedStatus === PARTIAL_CONTENT_RESPONSE;
  53509. if (!ok_response_on_range_request && xhrStatus !== pendingRequest.expectedStatus) {
  53510. if (pendingRequest.onError) {
  53511. pendingRequest.onError(xhr.status);
  53512. }
  53513. return;
  53514. }
  53515. this.loadedRequests[xhrId] = true;
  53516. var chunk = getArrayBuffer(xhr);
  53517. if (xhrStatus === PARTIAL_CONTENT_RESPONSE) {
  53518. var rangeHeader = xhr.getResponseHeader('Content-Range');
  53519. var matches = /bytes (\d+)-(\d+)\/(\d+)/.exec(rangeHeader);
  53520. var begin = parseInt(matches[1], 10);
  53521. pendingRequest.onDone({
  53522. begin: begin,
  53523. chunk: chunk
  53524. });
  53525. } else if (pendingRequest.onProgressiveData) {
  53526. pendingRequest.onDone(null);
  53527. } else if (chunk) {
  53528. pendingRequest.onDone({
  53529. begin: 0,
  53530. chunk: chunk
  53531. });
  53532. } else if (pendingRequest.onError) {
  53533. pendingRequest.onError(xhr.status);
  53534. }
  53535. },
  53536. hasPendingRequests: function NetworkManager_hasPendingRequests() {
  53537. for (var xhrId in this.pendingRequests) {
  53538. return true;
  53539. }
  53540. return false;
  53541. },
  53542. getRequestXhr: function NetworkManager_getXhr(xhrId) {
  53543. return this.pendingRequests[xhrId].xhr;
  53544. },
  53545. isStreamingRequest: function NetworkManager_isStreamingRequest(xhrId) {
  53546. return !!this.pendingRequests[xhrId].onProgressiveData;
  53547. },
  53548. isPendingRequest: function NetworkManager_isPendingRequest(xhrId) {
  53549. return xhrId in this.pendingRequests;
  53550. },
  53551. isLoadedRequest: function NetworkManager_isLoadedRequest(xhrId) {
  53552. return xhrId in this.loadedRequests;
  53553. },
  53554. abortAllRequests: function NetworkManager_abortAllRequests() {
  53555. for (var xhrId in this.pendingRequests) {
  53556. this.abortRequest(xhrId | 0);
  53557. }
  53558. },
  53559. abortRequest: function NetworkManager_abortRequest(xhrId) {
  53560. var xhr = this.pendingRequests[xhrId].xhr;
  53561. delete this.pendingRequests[xhrId];
  53562. xhr.abort();
  53563. }
  53564. };
  53565. var assert = sharedUtil.assert;
  53566. var createPromiseCapability = sharedUtil.createPromiseCapability;
  53567. var isInt = sharedUtil.isInt;
  53568. var MissingPDFException = sharedUtil.MissingPDFException;
  53569. var UnexpectedResponseException = sharedUtil.UnexpectedResponseException;
  53570. /** @implements {IPDFStream} */
  53571. function PDFNetworkStream(options) {
  53572. this._options = options;
  53573. var source = options.source;
  53574. this._manager = new NetworkManager(source.url, {
  53575. httpHeaders: source.httpHeaders,
  53576. withCredentials: source.withCredentials
  53577. });
  53578. this._rangeChunkSize = source.rangeChunkSize;
  53579. this._fullRequestReader = null;
  53580. this._rangeRequestReaders = [];
  53581. }
  53582. PDFNetworkStream.prototype = {
  53583. _onRangeRequestReaderClosed: function PDFNetworkStream_onRangeRequestReaderClosed(reader) {
  53584. var i = this._rangeRequestReaders.indexOf(reader);
  53585. if (i >= 0) {
  53586. this._rangeRequestReaders.splice(i, 1);
  53587. }
  53588. },
  53589. getFullReader: function PDFNetworkStream_getFullReader() {
  53590. assert(!this._fullRequestReader);
  53591. this._fullRequestReader = new PDFNetworkStreamFullRequestReader(this._manager, this._options);
  53592. return this._fullRequestReader;
  53593. },
  53594. getRangeReader: function PDFNetworkStream_getRangeReader(begin, end) {
  53595. var reader = new PDFNetworkStreamRangeRequestReader(this._manager, begin, end);
  53596. reader.onClosed = this._onRangeRequestReaderClosed.bind(this);
  53597. this._rangeRequestReaders.push(reader);
  53598. return reader;
  53599. },
  53600. cancelAllRequests: function PDFNetworkStream_cancelAllRequests(reason) {
  53601. if (this._fullRequestReader) {
  53602. this._fullRequestReader.cancel(reason);
  53603. }
  53604. var readers = this._rangeRequestReaders.slice(0);
  53605. readers.forEach(function (reader) {
  53606. reader.cancel(reason);
  53607. });
  53608. }
  53609. };
  53610. /** @implements {IPDFStreamReader} */
  53611. function PDFNetworkStreamFullRequestReader(manager, options) {
  53612. this._manager = manager;
  53613. var source = options.source;
  53614. var args = {
  53615. onHeadersReceived: this._onHeadersReceived.bind(this),
  53616. onProgressiveData: source.disableStream ? null : this._onProgressiveData.bind(this),
  53617. onDone: this._onDone.bind(this),
  53618. onError: this._onError.bind(this),
  53619. onProgress: this._onProgress.bind(this)
  53620. };
  53621. this._url = source.url;
  53622. this._fullRequestId = manager.requestFull(args);
  53623. this._headersReceivedCapability = createPromiseCapability();
  53624. this._disableRange = options.disableRange || false;
  53625. this._contentLength = source.length;
  53626. // optional
  53627. this._rangeChunkSize = source.rangeChunkSize;
  53628. if (!this._rangeChunkSize && !this._disableRange) {
  53629. this._disableRange = true;
  53630. }
  53631. this._isStreamingSupported = false;
  53632. this._isRangeSupported = false;
  53633. this._cachedChunks = [];
  53634. this._requests = [];
  53635. this._done = false;
  53636. this._storedError = undefined;
  53637. this.onProgress = null;
  53638. }
  53639. PDFNetworkStreamFullRequestReader.prototype = {
  53640. _validateRangeRequestCapabilities: function PDFNetworkStreamFullRequestReader_validateRangeRequestCapabilities() {
  53641. if (this._disableRange) {
  53642. return false;
  53643. }
  53644. var networkManager = this._manager;
  53645. var fullRequestXhrId = this._fullRequestId;
  53646. var fullRequestXhr = networkManager.getRequestXhr(fullRequestXhrId);
  53647. if (fullRequestXhr.getResponseHeader('Accept-Ranges') !== 'bytes') {
  53648. return false;
  53649. }
  53650. var contentEncoding = fullRequestXhr.getResponseHeader('Content-Encoding') || 'identity';
  53651. if (contentEncoding !== 'identity') {
  53652. return false;
  53653. }
  53654. var length = fullRequestXhr.getResponseHeader('Content-Length');
  53655. length = parseInt(length, 10);
  53656. if (!isInt(length)) {
  53657. return false;
  53658. }
  53659. this._contentLength = length;
  53660. // setting right content length
  53661. if (length <= 2 * this._rangeChunkSize) {
  53662. // The file size is smaller than the size of two chunks, so it does
  53663. // not make any sense to abort the request and retry with a range
  53664. // request.
  53665. return false;
  53666. }
  53667. return true;
  53668. },
  53669. _onHeadersReceived: function PDFNetworkStreamFullRequestReader_onHeadersReceived() {
  53670. if (this._validateRangeRequestCapabilities()) {
  53671. this._isRangeSupported = true;
  53672. }
  53673. var networkManager = this._manager;
  53674. var fullRequestXhrId = this._fullRequestId;
  53675. if (networkManager.isStreamingRequest(fullRequestXhrId)) {
  53676. // We can continue fetching when progressive loading is enabled,
  53677. // and we don't need the autoFetch feature.
  53678. this._isStreamingSupported = true;
  53679. } else if (this._isRangeSupported) {
  53680. // NOTE: by cancelling the full request, and then issuing range
  53681. // requests, there will be an issue for sites where you can only
  53682. // request the pdf once. However, if this is the case, then the
  53683. // server should not be returning that it can support range
  53684. // requests.
  53685. networkManager.abortRequest(fullRequestXhrId);
  53686. }
  53687. this._headersReceivedCapability.resolve();
  53688. },
  53689. _onProgressiveData: function PDFNetworkStreamFullRequestReader_onProgressiveData(chunk) {
  53690. if (this._requests.length > 0) {
  53691. var requestCapability = this._requests.shift();
  53692. requestCapability.resolve({
  53693. value: chunk,
  53694. done: false
  53695. });
  53696. } else {
  53697. this._cachedChunks.push(chunk);
  53698. }
  53699. },
  53700. _onDone: function PDFNetworkStreamFullRequestReader_onDone(args) {
  53701. if (args) {
  53702. this._onProgressiveData(args.chunk);
  53703. }
  53704. this._done = true;
  53705. if (this._cachedChunks.length > 0) {
  53706. return;
  53707. }
  53708. this._requests.forEach(function (requestCapability) {
  53709. requestCapability.resolve({
  53710. value: undefined,
  53711. done: true
  53712. });
  53713. });
  53714. this._requests = [];
  53715. },
  53716. _onError: function PDFNetworkStreamFullRequestReader_onError(status) {
  53717. var url = this._url;
  53718. var exception;
  53719. if (status === 404 || status === 0 && /^file:/.test(url)) {
  53720. exception = new MissingPDFException('Missing PDF "' + url + '".');
  53721. } else {
  53722. exception = new UnexpectedResponseException('Unexpected server response (' + status + ') while retrieving PDF "' + url + '".', status);
  53723. }
  53724. this._storedError = exception;
  53725. this._headersReceivedCapability.reject(exception);
  53726. this._requests.forEach(function (requestCapability) {
  53727. requestCapability.reject(exception);
  53728. });
  53729. this._requests = [];
  53730. this._cachedChunks = [];
  53731. },
  53732. _onProgress: function PDFNetworkStreamFullRequestReader_onProgress(data) {
  53733. if (this.onProgress) {
  53734. this.onProgress({
  53735. loaded: data.loaded,
  53736. total: data.lengthComputable ? data.total : this._contentLength
  53737. });
  53738. }
  53739. },
  53740. get isRangeSupported() {
  53741. return this._isRangeSupported;
  53742. },
  53743. get isStreamingSupported() {
  53744. return this._isStreamingSupported;
  53745. },
  53746. get contentLength() {
  53747. return this._contentLength;
  53748. },
  53749. get headersReady() {
  53750. return this._headersReceivedCapability.promise;
  53751. },
  53752. read: function PDFNetworkStreamFullRequestReader_read() {
  53753. if (this._storedError) {
  53754. return Promise.reject(this._storedError);
  53755. }
  53756. if (this._cachedChunks.length > 0) {
  53757. var chunk = this._cachedChunks.shift();
  53758. return Promise.resolve(chunk);
  53759. }
  53760. if (this._done) {
  53761. return Promise.resolve({
  53762. value: undefined,
  53763. done: true
  53764. });
  53765. }
  53766. var requestCapability = createPromiseCapability();
  53767. this._requests.push(requestCapability);
  53768. return requestCapability.promise;
  53769. },
  53770. cancel: function PDFNetworkStreamFullRequestReader_cancel(reason) {
  53771. this._done = true;
  53772. this._headersReceivedCapability.reject(reason);
  53773. this._requests.forEach(function (requestCapability) {
  53774. requestCapability.resolve({
  53775. value: undefined,
  53776. done: true
  53777. });
  53778. });
  53779. this._requests = [];
  53780. if (this._manager.isPendingRequest(this._fullRequestId)) {
  53781. this._manager.abortRequest(this._fullRequestId);
  53782. }
  53783. this._fullRequestReader = null;
  53784. }
  53785. };
  53786. /** @implements {IPDFStreamRangeReader} */
  53787. function PDFNetworkStreamRangeRequestReader(manager, begin, end) {
  53788. this._manager = manager;
  53789. var args = {
  53790. onDone: this._onDone.bind(this),
  53791. onProgress: this._onProgress.bind(this)
  53792. };
  53793. this._requestId = manager.requestRange(begin, end, args);
  53794. this._requests = [];
  53795. this._queuedChunk = null;
  53796. this._done = false;
  53797. this.onProgress = null;
  53798. this.onClosed = null;
  53799. }
  53800. PDFNetworkStreamRangeRequestReader.prototype = {
  53801. _close: function PDFNetworkStreamRangeRequestReader_close() {
  53802. if (this.onClosed) {
  53803. this.onClosed(this);
  53804. }
  53805. },
  53806. _onDone: function PDFNetworkStreamRangeRequestReader_onDone(data) {
  53807. var chunk = data.chunk;
  53808. if (this._requests.length > 0) {
  53809. var requestCapability = this._requests.shift();
  53810. requestCapability.resolve({
  53811. value: chunk,
  53812. done: false
  53813. });
  53814. } else {
  53815. this._queuedChunk = chunk;
  53816. }
  53817. this._done = true;
  53818. this._requests.forEach(function (requestCapability) {
  53819. requestCapability.resolve({
  53820. value: undefined,
  53821. done: true
  53822. });
  53823. });
  53824. this._requests = [];
  53825. this._close();
  53826. },
  53827. _onProgress: function PDFNetworkStreamRangeRequestReader_onProgress(evt) {
  53828. if (!this.isStreamingSupported && this.onProgress) {
  53829. this.onProgress({ loaded: evt.loaded });
  53830. }
  53831. },
  53832. get isStreamingSupported() {
  53833. return false;
  53834. },
  53835. // TODO allow progressive range bytes loading
  53836. read: function PDFNetworkStreamRangeRequestReader_read() {
  53837. if (this._queuedChunk !== null) {
  53838. var chunk = this._queuedChunk;
  53839. this._queuedChunk = null;
  53840. return Promise.resolve({
  53841. value: chunk,
  53842. done: false
  53843. });
  53844. }
  53845. if (this._done) {
  53846. return Promise.resolve({
  53847. value: undefined,
  53848. done: true
  53849. });
  53850. }
  53851. var requestCapability = createPromiseCapability();
  53852. this._requests.push(requestCapability);
  53853. return requestCapability.promise;
  53854. },
  53855. cancel: function PDFNetworkStreamRangeRequestReader_cancel(reason) {
  53856. this._done = true;
  53857. this._requests.forEach(function (requestCapability) {
  53858. requestCapability.resolve({
  53859. value: undefined,
  53860. done: true
  53861. });
  53862. });
  53863. this._requests = [];
  53864. if (this._manager.isPendingRequest(this._requestId)) {
  53865. this._manager.abortRequest(this._requestId);
  53866. }
  53867. this._close();
  53868. }
  53869. };
  53870. coreWorker.setPDFNetworkStreamClass(PDFNetworkStream);
  53871. exports.PDFNetworkStream = PDFNetworkStream;
  53872. exports.NetworkManager = NetworkManager;
  53873. }));
  53874. }.call(pdfjsLibs));
  53875. exports.WorkerMessageHandler = pdfjsLibs.pdfjsCoreWorker.WorkerMessageHandler;
  53876. }));