pdf.worker.js 1.7 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843368443684536846368473684836849368503685136852368533685436855368563685736858368593686036861368623686336864368653686636867368683686936870368713687236873368743687536876368773687836879368803688136882368833688436885368863688736888368893689036891368923689336894368953689636897368983689936900369013690236903369043690536906369073690836909369103691136912369133691436915369163691736918369193692036921369223692336924369253692636927369283692936930369313693236933369343693536936369373693836939369403694136942369433694436945369463694736948369493695036951369523695336954369553695636957369583695936960369613696236963369643696536966369673696836969369703697136972369733697436975369763697736978369793698036981369823698336984369853698636987369883698936990369913699236993369943699536996369973699836999370003700137002370033700437005370063700737008370093701037011370123701337014370153701637017370183701937020370213702237023370243702537026370273702837029370303703137032370333703437035370363703737038370393704037041370423704337044370453704637047370483704937050370513705237053370543705537056370573705837059370603706137062370633706437065370663706737068370693707037071370723707337074370753707637077370783707937080370813708237083370843708537086370873708837089370903709137092370933709437095370963709737098370993710037101371023710337104371053710637107371083710937110371113711237113371143711537116371173711837119371203712137122371233712437125371263712737128371293713037131371323713337134371353713637137371383713937140371413714237143371443714537146371473714837149371503715137152371533715437155371563715737158371593716037161371623716337164371653716637167371683716937170371713717237173371743717537176371773717837179371803718137182371833718437185371863718737188371893719037191371923719337194371953719637197371983719937200372013720237203372043720537206372073720837209372103721137212372133721437215372163721737218372193722037221372223722337224372253722637227372283722937230372313723237233372343723537236372373723837239372403724137242372433724437245372463724737248372493725037251372523725337254372553725637257372583725937260372613726237263372643726537266372673726837269372703727137272372733727437275372763727737278372793728037281372823728337284372853728637287372883728937290372913729237293372943729537296372973729837299373003730137302373033730437305373063730737308373093731037311373123731337314373153731637317373183731937320373213732237323373243732537326373273732837329373303733137332373333733437335373363733737338373393734037341373423734337344373453734637347373483734937350373513735237353373543735537356373573735837359373603736137362373633736437365373663736737368373693737037371373723737337374373753737637377373783737937380373813738237383373843738537386373873738837389373903739137392373933739437395373963739737398373993740037401374023740337404374053740637407374083740937410374113741237413374143741537416374173741837419374203742137422374233742437425374263742737428374293743037431374323743337434374353743637437374383743937440374413744237443374443744537446374473744837449374503745137452374533745437455374563745737458374593746037461374623746337464374653746637467374683746937470374713747237473374743747537476374773747837479374803748137482374833748437485374863748737488374893749037491374923749337494374953749637497374983749937500375013750237503375043750537506375073750837509375103751137512375133751437515375163751737518375193752037521375223752337524375253752637527375283752937530375313753237533375343753537536375373753837539375403754137542375433754437545375463754737548375493755037551375523755337554375553755637557375583755937560375613756237563375643756537566375673756837569375703757137572375733757437575375763757737578375793758037581375823758337584375853758637587375883758937590375913759237593375943759537596375973759837599376003760137602376033760437605376063760737608376093761037611376123761337614376153761637617376183761937620376213762237623376243762537626376273762837629376303763137632376333763437635376363763737638376393764037641376423764337644376453764637647376483764937650376513765237653376543765537656376573765837659376603766137662376633766437665376663766737668376693767037671376723767337674376753767637677376783767937680376813768237683376843768537686376873768837689376903769137692376933769437695376963769737698376993770037701377023770337704377053770637707377083770937710377113771237713377143771537716377173771837719377203772137722377233772437725377263772737728377293773037731377323773337734377353773637737377383773937740377413774237743377443774537746377473774837749377503775137752377533775437755377563775737758377593776037761377623776337764377653776637767377683776937770377713777237773377743777537776377773777837779377803778137782377833778437785377863778737788377893779037791377923779337794377953779637797377983779937800378013780237803378043780537806378073780837809378103781137812378133781437815378163781737818378193782037821378223782337824378253782637827378283782937830378313783237833378343783537836378373783837839378403784137842378433784437845378463784737848378493785037851378523785337854378553785637857378583785937860378613786237863378643786537866378673786837869378703787137872378733787437875378763787737878378793788037881378823788337884378853788637887378883788937890378913789237893378943789537896378973789837899379003790137902379033790437905379063790737908379093791037911379123791337914379153791637917379183791937920379213792237923379243792537926379273792837929379303793137932379333793437935379363793737938379393794037941379423794337944379453794637947379483794937950379513795237953379543795537956379573795837959379603796137962379633796437965379663796737968379693797037971379723797337974379753797637977379783797937980379813798237983379843798537986379873798837989379903799137992379933799437995379963799737998379993800038001380023800338004380053800638007380083800938010380113801238013380143801538016380173801838019380203802138022380233802438025380263802738028380293803038031380323803338034380353803638037380383803938040380413804238043380443804538046380473804838049380503805138052380533805438055380563805738058380593806038061380623806338064380653806638067380683806938070380713807238073380743807538076380773807838079380803808138082380833808438085380863808738088380893809038091380923809338094380953809638097380983809938100381013810238103381043810538106381073810838109381103811138112381133811438115381163811738118381193812038121381223812338124381253812638127381283812938130381313813238133381343813538136381373813838139381403814138142381433814438145381463814738148381493815038151381523815338154381553815638157381583815938160381613816238163381643816538166381673816838169381703817138172381733817438175381763817738178381793818038181381823818338184381853818638187381883818938190381913819238193381943819538196381973819838199382003820138202382033820438205382063820738208382093821038211382123821338214382153821638217382183821938220382213822238223382243822538226382273822838229382303823138232382333823438235382363823738238382393824038241382423824338244382453824638247382483824938250382513825238253382543825538256382573825838259382603826138262382633826438265382663826738268382693827038271382723827338274382753827638277382783827938280382813828238283382843828538286382873828838289382903829138292382933829438295382963829738298382993830038301383023830338304383053830638307383083830938310383113831238313383143831538316383173831838319383203832138322383233832438325383263832738328383293833038331383323833338334383353833638337383383833938340383413834238343383443834538346383473834838349383503835138352383533835438355383563835738358383593836038361383623836338364383653836638367383683836938370383713837238373383743837538376383773837838379383803838138382383833838438385383863838738388383893839038391383923839338394383953839638397383983839938400384013840238403384043840538406384073840838409384103841138412384133841438415384163841738418384193842038421384223842338424384253842638427384283842938430384313843238433384343843538436384373843838439384403844138442384433844438445384463844738448384493845038451384523845338454384553845638457384583845938460384613846238463384643846538466384673846838469384703847138472384733847438475384763847738478384793848038481384823848338484384853848638487384883848938490384913849238493384943849538496384973849838499385003850138502385033850438505385063850738508385093851038511385123851338514385153851638517385183851938520385213852238523385243852538526385273852838529385303853138532385333853438535385363853738538385393854038541385423854338544385453854638547385483854938550385513855238553385543855538556385573855838559385603856138562385633856438565385663856738568385693857038571385723857338574385753857638577385783857938580385813858238583385843858538586385873858838589385903859138592385933859438595385963859738598385993860038601386023860338604386053860638607386083860938610386113861238613386143861538616386173861838619386203862138622386233862438625386263862738628386293863038631386323863338634386353863638637386383863938640386413864238643386443864538646386473864838649386503865138652386533865438655386563865738658386593866038661386623866338664386653866638667386683866938670386713867238673386743867538676386773867838679386803868138682386833868438685386863868738688386893869038691386923869338694386953869638697386983869938700387013870238703387043870538706387073870838709387103871138712387133871438715387163871738718387193872038721387223872338724387253872638727387283872938730387313873238733387343873538736387373873838739387403874138742387433874438745387463874738748387493875038751387523875338754387553875638757387583875938760387613876238763387643876538766387673876838769387703877138772387733877438775387763877738778387793878038781387823878338784387853878638787387883878938790387913879238793387943879538796387973879838799388003880138802388033880438805388063880738808388093881038811388123881338814388153881638817388183881938820388213882238823388243882538826388273882838829388303883138832388333883438835388363883738838388393884038841388423884338844388453884638847388483884938850388513885238853388543885538856388573885838859388603886138862388633886438865388663886738868388693887038871388723887338874388753887638877388783887938880388813888238883388843888538886388873888838889388903889138892388933889438895388963889738898388993890038901389023890338904389053890638907389083890938910389113891238913389143891538916389173891838919389203892138922389233892438925389263892738928389293893038931389323893338934389353893638937389383893938940389413894238943389443894538946389473894838949389503895138952389533895438955389563895738958389593896038961389623896338964389653896638967389683896938970389713897238973389743897538976389773897838979389803898138982389833898438985389863898738988389893899038991389923899338994389953899638997389983899939000390013900239003390043900539006390073900839009390103901139012390133901439015390163901739018390193902039021390223902339024390253902639027390283902939030390313903239033390343903539036390373903839039390403904139042390433904439045390463904739048390493905039051390523905339054390553905639057390583905939060390613906239063390643906539066390673906839069390703907139072390733907439075390763907739078390793908039081390823908339084390853908639087390883908939090390913909239093390943909539096390973909839099391003910139102391033910439105391063910739108391093911039111391123911339114391153911639117391183911939120391213912239123391243912539126391273912839129391303913139132391333913439135391363913739138391393914039141391423914339144391453914639147391483914939150391513915239153391543915539156391573915839159391603916139162391633916439165391663916739168391693917039171391723917339174391753917639177391783917939180391813918239183391843918539186391873918839189391903919139192391933919439195391963919739198391993920039201392023920339204392053920639207392083920939210392113921239213392143921539216392173921839219392203922139222392233922439225392263922739228392293923039231392323923339234392353923639237392383923939240392413924239243392443924539246392473924839249392503925139252392533925439255392563925739258392593926039261392623926339264392653926639267392683926939270392713927239273392743927539276392773927839279392803928139282392833928439285392863928739288392893929039291392923929339294392953929639297392983929939300393013930239303393043930539306393073930839309393103931139312393133931439315393163931739318393193932039321393223932339324393253932639327393283932939330393313933239333393343933539336393373933839339393403934139342393433934439345393463934739348393493935039351393523935339354393553935639357393583935939360393613936239363393643936539366393673936839369393703937139372393733937439375393763937739378393793938039381393823938339384393853938639387393883938939390393913939239393393943939539396393973939839399394003940139402394033940439405394063940739408394093941039411394123941339414394153941639417394183941939420394213942239423394243942539426394273942839429394303943139432394333943439435394363943739438394393944039441394423944339444394453944639447394483944939450394513945239453394543945539456394573945839459394603946139462394633946439465394663946739468394693947039471394723947339474394753947639477394783947939480394813948239483394843948539486394873948839489394903949139492394933949439495394963949739498394993950039501395023950339504395053950639507395083950939510395113951239513395143951539516395173951839519395203952139522395233952439525395263952739528395293953039531395323953339534395353953639537395383953939540395413954239543395443954539546395473954839549395503955139552395533955439555395563955739558395593956039561395623956339564395653956639567395683956939570395713957239573395743957539576395773957839579395803958139582395833958439585395863958739588395893959039591395923959339594395953959639597395983959939600396013960239603396043960539606396073960839609396103961139612396133961439615396163961739618396193962039621396223962339624396253962639627396283962939630396313963239633396343963539636396373963839639396403964139642396433964439645396463964739648396493965039651396523965339654396553965639657396583965939660396613966239663396643966539666396673966839669396703967139672396733967439675396763967739678396793968039681396823968339684396853968639687396883968939690396913969239693396943969539696396973969839699397003970139702397033970439705397063970739708397093971039711397123971339714397153971639717397183971939720397213972239723397243972539726397273972839729397303973139732397333973439735397363973739738397393974039741397423974339744397453974639747397483974939750397513975239753397543975539756397573975839759397603976139762397633976439765397663976739768397693977039771397723977339774397753977639777397783977939780397813978239783397843978539786397873978839789397903979139792397933979439795397963979739798397993980039801398023980339804398053980639807398083980939810398113981239813398143981539816398173981839819398203982139822398233982439825398263982739828398293983039831398323983339834398353983639837398383983939840398413984239843398443984539846398473984839849398503985139852398533985439855398563985739858398593986039861398623986339864398653986639867398683986939870398713987239873398743987539876398773987839879398803988139882398833988439885398863988739888398893989039891398923989339894398953989639897398983989939900399013990239903399043990539906399073990839909399103991139912399133991439915399163991739918399193992039921399223992339924399253992639927399283992939930399313993239933399343993539936399373993839939399403994139942399433994439945399463994739948399493995039951399523995339954399553995639957399583995939960399613996239963399643996539966399673996839969399703997139972399733997439975399763997739978399793998039981399823998339984399853998639987399883998939990399913999239993399943999539996399973999839999400004000140002400034000440005400064000740008400094001040011400124001340014400154001640017400184001940020400214002240023400244002540026400274002840029400304003140032400334003440035400364003740038400394004040041400424004340044400454004640047400484004940050400514005240053400544005540056400574005840059400604006140062400634006440065400664006740068400694007040071400724007340074400754007640077400784007940080400814008240083400844008540086400874008840089400904009140092400934009440095400964009740098400994010040101401024010340104401054010640107401084010940110401114011240113401144011540116401174011840119401204012140122401234012440125401264012740128401294013040131401324013340134401354013640137401384013940140401414014240143401444014540146401474014840149401504015140152401534015440155401564015740158401594016040161401624016340164401654016640167401684016940170401714017240173401744017540176401774017840179401804018140182401834018440185401864018740188401894019040191401924019340194401954019640197401984019940200402014020240203402044020540206402074020840209402104021140212402134021440215402164021740218402194022040221402224022340224402254022640227402284022940230402314023240233402344023540236402374023840239402404024140242402434024440245402464024740248402494025040251402524025340254402554025640257402584025940260402614026240263402644026540266402674026840269402704027140272402734027440275402764027740278402794028040281402824028340284402854028640287402884028940290402914029240293402944029540296402974029840299403004030140302403034030440305403064030740308403094031040311403124031340314403154031640317403184031940320403214032240323403244032540326403274032840329403304033140332403334033440335403364033740338403394034040341403424034340344403454034640347403484034940350403514035240353403544035540356403574035840359403604036140362403634036440365403664036740368403694037040371403724037340374403754037640377403784037940380403814038240383403844038540386403874038840389403904039140392403934039440395403964039740398403994040040401404024040340404404054040640407404084040940410404114041240413404144041540416404174041840419404204042140422404234042440425404264042740428404294043040431404324043340434404354043640437404384043940440404414044240443404444044540446404474044840449404504045140452404534045440455404564045740458404594046040461404624046340464404654046640467404684046940470404714047240473404744047540476404774047840479404804048140482404834048440485404864048740488404894049040491404924049340494404954049640497404984049940500405014050240503405044050540506405074050840509405104051140512405134051440515405164051740518405194052040521405224052340524405254052640527405284052940530405314053240533405344053540536405374053840539405404054140542405434054440545405464054740548405494055040551405524055340554405554055640557405584055940560405614056240563405644056540566405674056840569405704057140572405734057440575405764057740578405794058040581405824058340584405854058640587405884058940590405914059240593405944059540596405974059840599406004060140602406034060440605406064060740608406094061040611406124061340614406154061640617406184061940620406214062240623406244062540626406274062840629406304063140632406334063440635406364063740638406394064040641406424064340644406454064640647406484064940650406514065240653406544065540656406574065840659406604066140662406634066440665406664066740668406694067040671406724067340674406754067640677406784067940680406814068240683406844068540686406874068840689406904069140692406934069440695406964069740698406994070040701407024070340704407054070640707407084070940710407114071240713407144071540716407174071840719407204072140722407234072440725407264072740728407294073040731407324073340734407354073640737407384073940740407414074240743407444074540746407474074840749407504075140752407534075440755407564075740758407594076040761407624076340764407654076640767407684076940770407714077240773407744077540776407774077840779407804078140782407834078440785407864078740788407894079040791407924079340794407954079640797407984079940800408014080240803408044080540806408074080840809408104081140812408134081440815408164081740818408194082040821408224082340824408254082640827408284082940830408314083240833408344083540836408374083840839408404084140842408434084440845408464084740848408494085040851408524085340854408554085640857408584085940860408614086240863408644086540866408674086840869408704087140872408734087440875408764087740878408794088040881408824088340884408854088640887408884088940890408914089240893408944089540896408974089840899409004090140902409034090440905409064090740908409094091040911409124091340914409154091640917409184091940920409214092240923409244092540926409274092840929409304093140932409334093440935409364093740938409394094040941409424094340944409454094640947409484094940950409514095240953409544095540956409574095840959409604096140962409634096440965409664096740968409694097040971409724097340974409754097640977409784097940980409814098240983409844098540986409874098840989409904099140992409934099440995409964099740998409994100041001410024100341004410054100641007410084100941010410114101241013410144101541016410174101841019410204102141022410234102441025410264102741028410294103041031410324103341034410354103641037410384103941040410414104241043410444104541046410474104841049410504105141052410534105441055410564105741058410594106041061410624106341064410654106641067410684106941070410714107241073410744107541076410774107841079410804108141082410834108441085410864108741088410894109041091410924109341094410954109641097410984109941100411014110241103411044110541106411074110841109411104111141112411134111441115411164111741118411194112041121411224112341124411254112641127411284112941130411314113241133411344113541136411374113841139411404114141142411434114441145411464114741148411494115041151411524115341154411554115641157411584115941160411614116241163411644116541166411674116841169411704117141172411734117441175411764117741178411794118041181411824118341184411854118641187411884118941190411914119241193411944119541196411974119841199412004120141202412034120441205412064120741208412094121041211412124121341214412154121641217412184121941220412214122241223412244122541226412274122841229412304123141232412334123441235412364123741238412394124041241412424124341244412454124641247412484124941250412514125241253412544125541256412574125841259412604126141262412634126441265412664126741268412694127041271412724127341274412754127641277412784127941280412814128241283412844128541286412874128841289412904129141292412934129441295412964129741298412994130041301413024130341304413054130641307413084130941310413114131241313413144131541316413174131841319413204132141322413234132441325413264132741328413294133041331413324133341334413354133641337413384133941340413414134241343413444134541346413474134841349413504135141352413534135441355413564135741358413594136041361413624136341364413654136641367413684136941370413714137241373413744137541376413774137841379413804138141382413834138441385413864138741388413894139041391413924139341394413954139641397413984139941400414014140241403414044140541406414074140841409414104141141412414134141441415414164141741418414194142041421414224142341424414254142641427414284142941430414314143241433414344143541436414374143841439414404144141442414434144441445414464144741448414494145041451414524145341454414554145641457414584145941460414614146241463414644146541466414674146841469414704147141472414734147441475414764147741478414794148041481414824148341484414854148641487414884148941490414914149241493414944149541496414974149841499415004150141502415034150441505415064150741508415094151041511415124151341514415154151641517415184151941520415214152241523415244152541526415274152841529415304153141532415334153441535415364153741538415394154041541415424154341544415454154641547415484154941550415514155241553415544155541556415574155841559415604156141562415634156441565415664156741568415694157041571415724157341574415754157641577415784157941580415814158241583415844158541586415874158841589415904159141592415934159441595415964159741598415994160041601416024160341604416054160641607416084160941610416114161241613416144161541616416174161841619416204162141622416234162441625416264162741628416294163041631416324163341634416354163641637416384163941640416414164241643416444164541646416474164841649416504165141652416534165441655416564165741658416594166041661416624166341664416654166641667416684166941670416714167241673416744167541676416774167841679416804168141682416834168441685416864168741688416894169041691416924169341694416954169641697416984169941700417014170241703417044170541706417074170841709417104171141712417134171441715417164171741718417194172041721417224172341724417254172641727417284172941730417314173241733417344173541736417374173841739417404174141742417434174441745417464174741748417494175041751417524175341754417554175641757417584175941760417614176241763417644176541766417674176841769417704177141772417734177441775417764177741778417794178041781417824178341784417854178641787417884178941790417914179241793417944179541796417974179841799418004180141802418034180441805418064180741808418094181041811418124181341814418154181641817418184181941820418214182241823418244182541826418274182841829418304183141832418334183441835418364183741838418394184041841418424184341844418454184641847418484184941850418514185241853418544185541856418574185841859418604186141862418634186441865418664186741868418694187041871418724187341874418754187641877418784187941880418814188241883418844188541886418874188841889418904189141892418934189441895418964189741898418994190041901419024190341904419054190641907419084190941910419114191241913419144191541916419174191841919419204192141922419234192441925419264192741928419294193041931419324193341934419354193641937419384193941940419414194241943419444194541946419474194841949419504195141952419534195441955419564195741958419594196041961419624196341964419654196641967419684196941970419714197241973419744197541976419774197841979419804198141982419834198441985419864198741988419894199041991419924199341994419954199641997419984199942000420014200242003420044200542006420074200842009420104201142012420134201442015420164201742018420194202042021420224202342024420254202642027420284202942030420314203242033420344203542036420374203842039420404204142042420434204442045420464204742048420494205042051420524205342054420554205642057420584205942060420614206242063420644206542066420674206842069420704207142072420734207442075420764207742078420794208042081420824208342084420854208642087420884208942090420914209242093420944209542096420974209842099421004210142102421034210442105421064210742108421094211042111421124211342114421154211642117421184211942120421214212242123421244212542126421274212842129421304213142132421334213442135421364213742138421394214042141421424214342144421454214642147421484214942150421514215242153421544215542156421574215842159421604216142162421634216442165421664216742168421694217042171421724217342174421754217642177421784217942180421814218242183421844218542186421874218842189421904219142192421934219442195421964219742198421994220042201422024220342204422054220642207422084220942210422114221242213422144221542216422174221842219422204222142222422234222442225422264222742228422294223042231422324223342234422354223642237422384223942240422414224242243422444224542246422474224842249422504225142252422534225442255422564225742258422594226042261422624226342264422654226642267422684226942270422714227242273422744227542276422774227842279422804228142282422834228442285422864228742288422894229042291422924229342294422954229642297422984229942300423014230242303423044230542306423074230842309423104231142312423134231442315423164231742318423194232042321423224232342324423254232642327423284232942330423314233242333423344233542336423374233842339423404234142342423434234442345423464234742348423494235042351423524235342354423554235642357423584235942360423614236242363423644236542366423674236842369423704237142372423734237442375423764237742378423794238042381423824238342384423854238642387423884238942390423914239242393423944239542396423974239842399424004240142402424034240442405424064240742408424094241042411424124241342414424154241642417424184241942420424214242242423424244242542426424274242842429424304243142432424334243442435424364243742438424394244042441424424244342444424454244642447424484244942450424514245242453424544245542456424574245842459424604246142462424634246442465424664246742468424694247042471424724247342474424754247642477424784247942480424814248242483424844248542486424874248842489424904249142492424934249442495424964249742498424994250042501425024250342504425054250642507425084250942510425114251242513425144251542516425174251842519425204252142522425234252442525425264252742528425294253042531425324253342534425354253642537425384253942540425414254242543425444254542546425474254842549425504255142552425534255442555425564255742558425594256042561425624256342564425654256642567425684256942570425714257242573425744257542576425774257842579425804258142582425834258442585425864258742588425894259042591425924259342594425954259642597425984259942600426014260242603426044260542606426074260842609426104261142612426134261442615426164261742618426194262042621426224262342624426254262642627426284262942630426314263242633426344263542636426374263842639426404264142642426434264442645426464264742648426494265042651426524265342654426554265642657426584265942660426614266242663426644266542666426674266842669426704267142672426734267442675426764267742678426794268042681426824268342684426854268642687426884268942690426914269242693426944269542696426974269842699427004270142702427034270442705427064270742708427094271042711427124271342714427154271642717427184271942720427214272242723427244272542726427274272842729427304273142732427334273442735427364273742738427394274042741427424274342744427454274642747427484274942750427514275242753427544275542756427574275842759427604276142762427634276442765427664276742768427694277042771427724277342774427754277642777427784277942780427814278242783427844278542786427874278842789427904279142792427934279442795427964279742798427994280042801428024280342804428054280642807428084280942810428114281242813428144281542816428174281842819428204282142822428234282442825428264282742828428294283042831428324283342834428354283642837428384283942840428414284242843428444284542846428474284842849428504285142852428534285442855428564285742858428594286042861428624286342864428654286642867428684286942870428714287242873428744287542876428774287842879428804288142882428834288442885428864288742888428894289042891428924289342894428954289642897428984289942900429014290242903429044290542906429074290842909429104291142912429134291442915429164291742918429194292042921429224292342924429254292642927429284292942930429314293242933429344293542936429374293842939429404294142942429434294442945429464294742948429494295042951429524295342954429554295642957429584295942960429614296242963429644296542966429674296842969429704297142972429734297442975429764297742978429794298042981429824298342984429854298642987429884298942990429914299242993429944299542996429974299842999430004300143002430034300443005430064300743008430094301043011430124301343014430154301643017430184301943020430214302243023430244302543026430274302843029430304303143032430334303443035430364303743038430394304043041430424304343044430454304643047430484304943050430514305243053430544305543056430574305843059430604306143062430634306443065430664306743068430694307043071430724307343074430754307643077430784307943080430814308243083430844308543086430874308843089430904309143092430934309443095430964309743098430994310043101431024310343104431054310643107431084310943110431114311243113431144311543116431174311843119431204312143122431234312443125431264312743128431294313043131431324313343134431354313643137431384313943140431414314243143431444314543146431474314843149431504315143152431534315443155431564315743158431594316043161431624316343164431654316643167431684316943170431714317243173431744317543176431774317843179431804318143182431834318443185431864318743188431894319043191431924319343194431954319643197431984319943200432014320243203432044320543206432074320843209432104321143212432134321443215432164321743218432194322043221432224322343224432254322643227432284322943230432314323243233432344323543236432374323843239432404324143242432434324443245432464324743248432494325043251432524325343254432554325643257432584325943260432614326243263432644326543266432674326843269432704327143272432734327443275432764327743278432794328043281432824328343284432854328643287432884328943290432914329243293432944329543296432974329843299433004330143302433034330443305433064330743308433094331043311433124331343314433154331643317433184331943320433214332243323433244332543326433274332843329433304333143332433334333443335433364333743338433394334043341433424334343344433454334643347433484334943350433514335243353433544335543356433574335843359433604336143362433634336443365433664336743368433694337043371433724337343374433754337643377433784337943380433814338243383433844338543386433874338843389433904339143392433934339443395433964339743398433994340043401434024340343404434054340643407434084340943410434114341243413434144341543416434174341843419434204342143422434234342443425434264342743428434294343043431434324343343434434354343643437434384343943440434414344243443434444344543446434474344843449434504345143452434534345443455434564345743458434594346043461434624346343464434654346643467434684346943470434714347243473434744347543476434774347843479434804348143482434834348443485434864348743488434894349043491434924349343494434954349643497434984349943500435014350243503435044350543506435074350843509435104351143512435134351443515435164351743518435194352043521435224352343524435254352643527435284352943530435314353243533435344353543536435374353843539435404354143542435434354443545435464354743548435494355043551435524355343554435554355643557435584355943560435614356243563435644356543566435674356843569435704357143572435734357443575435764357743578435794358043581435824358343584435854358643587435884358943590435914359243593435944359543596435974359843599436004360143602436034360443605436064360743608436094361043611436124361343614436154361643617436184361943620436214362243623436244362543626436274362843629436304363143632436334363443635436364363743638436394364043641436424364343644436454364643647436484364943650436514365243653436544365543656436574365843659436604366143662436634366443665436664366743668436694367043671436724367343674436754367643677436784367943680436814368243683436844368543686436874368843689436904369143692436934369443695436964369743698436994370043701437024370343704437054370643707437084370943710437114371243713437144371543716437174371843719437204372143722437234372443725437264372743728437294373043731437324373343734437354373643737437384373943740437414374243743437444374543746437474374843749437504375143752437534375443755437564375743758437594376043761437624376343764437654376643767437684376943770437714377243773437744377543776437774377843779437804378143782437834378443785437864378743788437894379043791437924379343794437954379643797437984379943800438014380243803438044380543806438074380843809438104381143812438134381443815438164381743818438194382043821438224382343824438254382643827438284382943830438314383243833438344383543836438374383843839438404384143842438434384443845438464384743848438494385043851438524385343854438554385643857438584385943860438614386243863438644386543866438674386843869438704387143872438734387443875438764387743878438794388043881438824388343884438854388643887438884388943890438914389243893438944389543896438974389843899439004390143902439034390443905439064390743908439094391043911439124391343914439154391643917439184391943920439214392243923439244392543926439274392843929439304393143932439334393443935439364393743938439394394043941439424394343944439454394643947439484394943950439514395243953439544395543956439574395843959439604396143962439634396443965439664396743968439694397043971439724397343974439754397643977439784397943980439814398243983439844398543986439874398843989439904399143992439934399443995439964399743998439994400044001440024400344004440054400644007440084400944010440114401244013440144401544016440174401844019440204402144022440234402444025440264402744028440294403044031440324403344034440354403644037440384403944040440414404244043440444404544046440474404844049440504405144052440534405444055440564405744058440594406044061440624406344064440654406644067440684406944070440714407244073440744407544076440774407844079440804408144082440834408444085440864408744088440894409044091440924409344094440954409644097440984409944100441014410244103441044410544106441074410844109441104411144112441134411444115441164411744118441194412044121441224412344124441254412644127441284412944130441314413244133441344413544136441374413844139441404414144142441434414444145441464414744148441494415044151441524415344154441554415644157441584415944160441614416244163441644416544166441674416844169441704417144172441734417444175441764417744178441794418044181441824418344184441854418644187441884418944190441914419244193441944419544196441974419844199442004420144202442034420444205442064420744208442094421044211442124421344214442154421644217442184421944220442214422244223442244422544226442274422844229442304423144232442334423444235442364423744238442394424044241442424424344244442454424644247442484424944250442514425244253442544425544256442574425844259442604426144262442634426444265442664426744268442694427044271442724427344274442754427644277442784427944280442814428244283442844428544286442874428844289442904429144292442934429444295442964429744298442994430044301443024430344304443054430644307443084430944310443114431244313443144431544316443174431844319443204432144322443234432444325443264432744328443294433044331443324433344334443354433644337443384433944340443414434244343443444434544346443474434844349443504435144352443534435444355443564435744358443594436044361443624436344364443654436644367443684436944370443714437244373443744437544376443774437844379443804438144382443834438444385443864438744388443894439044391443924439344394443954439644397443984439944400444014440244403444044440544406444074440844409444104441144412444134441444415444164441744418444194442044421444224442344424444254442644427444284442944430444314443244433444344443544436444374443844439444404444144442444434444444445444464444744448444494445044451444524445344454444554445644457444584445944460444614446244463444644446544466444674446844469444704447144472444734447444475444764447744478444794448044481444824448344484444854448644487444884448944490444914449244493444944449544496444974449844499445004450144502445034450444505445064450744508445094451044511445124451344514445154451644517445184451944520445214452244523445244452544526445274452844529445304453144532445334453444535445364453744538445394454044541445424454344544445454454644547445484454944550445514455244553445544455544556445574455844559445604456144562445634456444565445664456744568445694457044571445724457344574445754457644577445784457944580445814458244583445844458544586445874458844589445904459144592445934459444595445964459744598445994460044601446024460344604446054460644607446084460944610446114461244613446144461544616446174461844619446204462144622446234462444625446264462744628446294463044631446324463344634446354463644637446384463944640446414464244643446444464544646446474464844649446504465144652446534465444655446564465744658446594466044661446624466344664446654466644667446684466944670446714467244673446744467544676446774467844679446804468144682446834468444685446864468744688446894469044691446924469344694446954469644697446984469944700447014470244703447044470544706447074470844709447104471144712447134471444715447164471744718447194472044721447224472344724447254472644727447284472944730447314473244733447344473544736447374473844739447404474144742447434474444745447464474744748447494475044751447524475344754447554475644757447584475944760447614476244763447644476544766447674476844769447704477144772447734477444775447764477744778447794478044781447824478344784447854478644787447884478944790447914479244793447944479544796447974479844799448004480144802448034480444805448064480744808448094481044811448124481344814448154481644817448184481944820448214482244823448244482544826448274482844829448304483144832448334483444835448364483744838448394484044841448424484344844448454484644847448484484944850448514485244853448544485544856448574485844859448604486144862448634486444865448664486744868448694487044871448724487344874448754487644877448784487944880448814488244883448844488544886448874488844889448904489144892448934489444895448964489744898448994490044901449024490344904449054490644907449084490944910449114491244913449144491544916449174491844919449204492144922449234492444925449264492744928449294493044931449324493344934449354493644937449384493944940449414494244943449444494544946449474494844949449504495144952449534495444955449564495744958449594496044961449624496344964449654496644967449684496944970449714497244973449744497544976449774497844979449804498144982449834498444985449864498744988449894499044991449924499344994449954499644997449984499945000450014500245003450044500545006450074500845009450104501145012450134501445015450164501745018450194502045021450224502345024450254502645027450284502945030450314503245033450344503545036450374503845039450404504145042450434504445045450464504745048450494505045051450524505345054450554505645057450584505945060450614506245063450644506545066450674506845069450704507145072450734507445075450764507745078450794508045081450824508345084450854508645087450884508945090450914509245093450944509545096450974509845099451004510145102451034510445105451064510745108451094511045111451124511345114451154511645117451184511945120451214512245123451244512545126451274512845129451304513145132451334513445135451364513745138451394514045141451424514345144451454514645147451484514945150451514515245153451544515545156451574515845159451604516145162451634516445165451664516745168451694517045171451724517345174451754517645177451784517945180451814518245183451844518545186451874518845189451904519145192451934519445195451964519745198451994520045201452024520345204452054520645207452084520945210452114521245213452144521545216452174521845219452204522145222452234522445225452264522745228452294523045231452324523345234452354523645237452384523945240452414524245243452444524545246452474524845249452504525145252452534525445255452564525745258452594526045261452624526345264452654526645267452684526945270452714527245273452744527545276452774527845279452804528145282452834528445285452864528745288452894529045291452924529345294452954529645297452984529945300453014530245303453044530545306453074530845309453104531145312453134531445315453164531745318453194532045321453224532345324453254532645327453284532945330453314533245333453344533545336453374533845339453404534145342453434534445345453464534745348453494535045351453524535345354453554535645357453584535945360453614536245363453644536545366453674536845369453704537145372453734537445375453764537745378453794538045381453824538345384453854538645387453884538945390453914539245393453944539545396453974539845399454004540145402454034540445405454064540745408454094541045411454124541345414454154541645417454184541945420454214542245423454244542545426454274542845429454304543145432454334543445435454364543745438454394544045441454424544345444454454544645447454484544945450454514545245453454544545545456454574545845459454604546145462454634546445465454664546745468454694547045471454724547345474454754547645477454784547945480454814548245483454844548545486454874548845489454904549145492454934549445495454964549745498454994550045501455024550345504455054550645507455084550945510455114551245513455144551545516455174551845519455204552145522455234552445525455264552745528455294553045531455324553345534455354553645537455384553945540455414554245543455444554545546455474554845549455504555145552455534555445555455564555745558455594556045561455624556345564455654556645567455684556945570455714557245573455744557545576455774557845579455804558145582455834558445585455864558745588455894559045591455924559345594455954559645597455984559945600456014560245603456044560545606456074560845609456104561145612456134561445615456164561745618456194562045621456224562345624456254562645627456284562945630456314563245633456344563545636456374563845639456404564145642456434564445645456464564745648456494565045651456524565345654456554565645657456584565945660456614566245663456644566545666456674566845669456704567145672456734567445675456764567745678456794568045681456824568345684456854568645687456884568945690456914569245693456944569545696456974569845699457004570145702457034570445705457064570745708457094571045711457124571345714457154571645717457184571945720457214572245723457244572545726457274572845729457304573145732457334573445735457364573745738457394574045741457424574345744457454574645747457484574945750457514575245753457544575545756457574575845759457604576145762457634576445765457664576745768457694577045771457724577345774457754577645777457784577945780457814578245783457844578545786457874578845789457904579145792457934579445795457964579745798457994580045801458024580345804458054580645807458084580945810458114581245813458144581545816458174581845819458204582145822458234582445825458264582745828458294583045831458324583345834458354583645837458384583945840458414584245843458444584545846458474584845849458504585145852458534585445855458564585745858458594586045861458624586345864458654586645867458684586945870458714587245873458744587545876458774587845879458804588145882458834588445885458864588745888458894589045891458924589345894458954589645897458984589945900459014590245903459044590545906459074590845909459104591145912459134591445915459164591745918459194592045921459224592345924459254592645927459284592945930459314593245933459344593545936459374593845939459404594145942459434594445945459464594745948459494595045951459524595345954459554595645957459584595945960459614596245963459644596545966459674596845969459704597145972459734597445975459764597745978459794598045981459824598345984459854598645987459884598945990459914599245993459944599545996459974599845999460004600146002460034600446005460064600746008460094601046011460124601346014460154601646017460184601946020460214602246023460244602546026460274602846029460304603146032460334603446035460364603746038460394604046041460424604346044460454604646047460484604946050460514605246053460544605546056460574605846059460604606146062460634606446065460664606746068460694607046071460724607346074460754607646077460784607946080460814608246083460844608546086460874608846089460904609146092460934609446095460964609746098460994610046101461024610346104461054610646107461084610946110461114611246113461144611546116461174611846119461204612146122461234612446125461264612746128461294613046131461324613346134461354613646137461384613946140461414614246143461444614546146461474614846149461504615146152461534615446155461564615746158461594616046161461624616346164461654616646167461684616946170461714617246173461744617546176461774617846179461804618146182461834618446185461864618746188461894619046191461924619346194461954619646197461984619946200462014620246203462044620546206462074620846209462104621146212462134621446215462164621746218462194622046221462224622346224462254622646227462284622946230462314623246233462344623546236462374623846239462404624146242462434624446245462464624746248462494625046251462524625346254462554625646257462584625946260462614626246263462644626546266462674626846269462704627146272462734627446275462764627746278462794628046281462824628346284462854628646287462884628946290462914629246293462944629546296462974629846299463004630146302463034630446305463064630746308463094631046311463124631346314463154631646317463184631946320463214632246323463244632546326463274632846329463304633146332463334633446335463364633746338463394634046341463424634346344463454634646347463484634946350463514635246353463544635546356463574635846359463604636146362463634636446365463664636746368463694637046371463724637346374463754637646377463784637946380463814638246383463844638546386463874638846389463904639146392463934639446395463964639746398463994640046401464024640346404464054640646407464084640946410464114641246413464144641546416464174641846419464204642146422464234642446425464264642746428464294643046431464324643346434464354643646437464384643946440464414644246443464444644546446464474644846449464504645146452464534645446455464564645746458464594646046461464624646346464464654646646467464684646946470464714647246473464744647546476464774647846479464804648146482464834648446485464864648746488464894649046491464924649346494464954649646497464984649946500465014650246503465044650546506465074650846509465104651146512465134651446515465164651746518465194652046521465224652346524465254652646527465284652946530465314653246533465344653546536465374653846539465404654146542465434654446545465464654746548465494655046551465524655346554465554655646557465584655946560465614656246563465644656546566465674656846569465704657146572465734657446575465764657746578465794658046581465824658346584465854658646587465884658946590465914659246593465944659546596465974659846599466004660146602466034660446605466064660746608466094661046611466124661346614466154661646617466184661946620466214662246623466244662546626466274662846629466304663146632466334663446635466364663746638466394664046641466424664346644466454664646647466484664946650466514665246653466544665546656466574665846659466604666146662466634666446665466664666746668466694667046671466724667346674466754667646677466784667946680466814668246683466844668546686466874668846689466904669146692466934669446695466964669746698466994670046701467024670346704467054670646707467084670946710467114671246713467144671546716467174671846719467204672146722467234672446725467264672746728467294673046731467324673346734467354673646737467384673946740467414674246743467444674546746467474674846749467504675146752467534675446755467564675746758467594676046761467624676346764467654676646767467684676946770467714677246773467744677546776467774677846779467804678146782467834678446785467864678746788467894679046791467924679346794467954679646797467984679946800468014680246803468044680546806468074680846809468104681146812468134681446815468164681746818468194682046821468224682346824468254682646827468284682946830468314683246833468344683546836468374683846839468404684146842468434684446845468464684746848468494685046851468524685346854468554685646857468584685946860468614686246863468644686546866468674686846869468704687146872468734687446875468764687746878468794688046881468824688346884468854688646887468884688946890468914689246893468944689546896468974689846899469004690146902469034690446905469064690746908469094691046911469124691346914469154691646917469184691946920469214692246923469244692546926469274692846929469304693146932469334693446935469364693746938469394694046941469424694346944469454694646947469484694946950469514695246953469544695546956469574695846959469604696146962469634696446965469664696746968469694697046971469724697346974469754697646977469784697946980469814698246983469844698546986469874698846989469904699146992469934699446995469964699746998469994700047001470024700347004470054700647007470084700947010470114701247013470144701547016470174701847019470204702147022470234702447025470264702747028470294703047031470324703347034470354703647037470384703947040470414704247043470444704547046470474704847049470504705147052470534705447055470564705747058470594706047061470624706347064470654706647067470684706947070470714707247073470744707547076470774707847079470804708147082470834708447085470864708747088470894709047091470924709347094470954709647097470984709947100471014710247103471044710547106471074710847109471104711147112471134711447115471164711747118471194712047121471224712347124471254712647127471284712947130471314713247133471344713547136471374713847139471404714147142471434714447145471464714747148471494715047151471524715347154471554715647157471584715947160471614716247163471644716547166471674716847169471704717147172471734717447175471764717747178471794718047181471824718347184471854718647187471884718947190471914719247193471944719547196471974719847199472004720147202472034720447205472064720747208472094721047211472124721347214472154721647217472184721947220472214722247223472244722547226472274722847229472304723147232472334723447235472364723747238472394724047241472424724347244472454724647247472484724947250472514725247253472544725547256472574725847259472604726147262472634726447265472664726747268472694727047271472724727347274472754727647277472784727947280472814728247283472844728547286472874728847289472904729147292472934729447295472964729747298472994730047301473024730347304473054730647307473084730947310473114731247313473144731547316473174731847319473204732147322473234732447325473264732747328473294733047331473324733347334473354733647337473384733947340473414734247343473444734547346473474734847349473504735147352473534735447355473564735747358473594736047361473624736347364473654736647367473684736947370473714737247373473744737547376473774737847379473804738147382473834738447385473864738747388473894739047391473924739347394473954739647397473984739947400474014740247403474044740547406474074740847409474104741147412474134741447415474164741747418474194742047421474224742347424474254742647427474284742947430474314743247433474344743547436474374743847439474404744147442474434744447445474464744747448474494745047451474524745347454474554745647457474584745947460474614746247463474644746547466474674746847469474704747147472474734747447475474764747747478474794748047481474824748347484474854748647487474884748947490474914749247493474944749547496474974749847499475004750147502475034750447505475064750747508475094751047511475124751347514475154751647517475184751947520475214752247523475244752547526475274752847529475304753147532475334753447535475364753747538475394754047541475424754347544475454754647547475484754947550475514755247553475544755547556475574755847559475604756147562475634756447565475664756747568475694757047571475724757347574475754757647577475784757947580475814758247583475844758547586475874758847589475904759147592475934759447595475964759747598475994760047601476024760347604476054760647607476084760947610476114761247613476144761547616476174761847619476204762147622476234762447625476264762747628476294763047631476324763347634476354763647637476384763947640476414764247643476444764547646476474764847649476504765147652476534765447655476564765747658476594766047661476624766347664476654766647667476684766947670476714767247673476744767547676476774767847679476804768147682476834768447685476864768747688476894769047691476924769347694476954769647697476984769947700477014770247703477044770547706477074770847709477104771147712477134771447715477164771747718477194772047721477224772347724477254772647727477284772947730477314773247733477344773547736477374773847739477404774147742477434774447745477464774747748477494775047751477524775347754477554775647757477584775947760477614776247763477644776547766477674776847769477704777147772477734777447775477764777747778477794778047781477824778347784477854778647787477884778947790477914779247793477944779547796477974779847799478004780147802478034780447805478064780747808478094781047811478124781347814478154781647817478184781947820478214782247823478244782547826478274782847829478304783147832478334783447835478364783747838478394784047841478424784347844478454784647847478484784947850478514785247853478544785547856478574785847859478604786147862478634786447865478664786747868478694787047871478724787347874478754787647877478784787947880478814788247883478844788547886478874788847889478904789147892478934789447895478964789747898478994790047901479024790347904479054790647907479084790947910479114791247913479144791547916479174791847919479204792147922479234792447925479264792747928479294793047931479324793347934479354793647937479384793947940479414794247943479444794547946479474794847949479504795147952479534795447955479564795747958479594796047961479624796347964479654796647967479684796947970479714797247973479744797547976479774797847979479804798147982479834798447985479864798747988479894799047991479924799347994479954799647997479984799948000480014800248003480044800548006480074800848009480104801148012480134801448015480164801748018480194802048021480224802348024480254802648027480284802948030480314803248033480344803548036480374803848039480404804148042480434804448045480464804748048480494805048051480524805348054480554805648057480584805948060480614806248063480644806548066480674806848069480704807148072480734807448075480764807748078480794808048081480824808348084480854808648087480884808948090480914809248093480944809548096480974809848099481004810148102481034810448105481064810748108481094811048111481124811348114481154811648117481184811948120481214812248123481244812548126481274812848129481304813148132481334813448135481364813748138481394814048141481424814348144481454814648147481484814948150481514815248153481544815548156481574815848159481604816148162481634816448165481664816748168481694817048171481724817348174481754817648177481784817948180481814818248183481844818548186481874818848189481904819148192481934819448195481964819748198481994820048201482024820348204482054820648207482084820948210482114821248213482144821548216482174821848219482204822148222482234822448225482264822748228482294823048231482324823348234482354823648237482384823948240482414824248243482444824548246482474824848249482504825148252482534825448255482564825748258482594826048261482624826348264482654826648267482684826948270482714827248273482744827548276482774827848279482804828148282482834828448285482864828748288482894829048291482924829348294482954829648297482984829948300483014830248303483044830548306483074830848309483104831148312483134831448315483164831748318483194832048321483224832348324483254832648327483284832948330483314833248333483344833548336483374833848339483404834148342483434834448345483464834748348483494835048351483524835348354483554835648357483584835948360483614836248363483644836548366483674836848369483704837148372483734837448375483764837748378483794838048381483824838348384483854838648387483884838948390483914839248393483944839548396483974839848399484004840148402484034840448405484064840748408484094841048411484124841348414484154841648417484184841948420484214842248423484244842548426484274842848429484304843148432484334843448435484364843748438484394844048441484424844348444484454844648447484484844948450484514845248453484544845548456484574845848459484604846148462484634846448465484664846748468484694847048471484724847348474484754847648477484784847948480484814848248483484844848548486484874848848489484904849148492484934849448495484964849748498484994850048501485024850348504485054850648507485084850948510485114851248513485144851548516485174851848519485204852148522485234852448525485264852748528485294853048531485324853348534485354853648537485384853948540485414854248543485444854548546485474854848549485504855148552485534855448555485564855748558485594856048561485624856348564485654856648567485684856948570485714857248573485744857548576485774857848579485804858148582485834858448585485864858748588485894859048591485924859348594485954859648597485984859948600486014860248603486044860548606486074860848609486104861148612486134861448615486164861748618486194862048621486224862348624486254862648627486284862948630486314863248633486344863548636486374863848639486404864148642486434864448645486464864748648486494865048651486524865348654486554865648657486584865948660486614866248663486644866548666486674866848669486704867148672486734867448675486764867748678486794868048681486824868348684486854868648687486884868948690486914869248693486944869548696486974869848699487004870148702487034870448705487064870748708487094871048711487124871348714487154871648717487184871948720487214872248723487244872548726487274872848729487304873148732487334873448735487364873748738487394874048741487424874348744487454874648747487484874948750487514875248753487544875548756487574875848759487604876148762487634876448765487664876748768487694877048771487724877348774487754877648777487784877948780487814878248783487844878548786487874878848789487904879148792487934879448795487964879748798487994880048801488024880348804488054880648807488084880948810488114881248813488144881548816488174881848819488204882148822488234882448825488264882748828488294883048831488324883348834488354883648837488384883948840488414884248843488444884548846488474884848849488504885148852488534885448855488564885748858488594886048861488624886348864488654886648867488684886948870488714887248873488744887548876488774887848879488804888148882488834888448885488864888748888488894889048891488924889348894488954889648897488984889948900489014890248903489044890548906489074890848909489104891148912489134891448915489164891748918489194892048921489224892348924489254892648927489284892948930489314893248933489344893548936489374893848939489404894148942489434894448945489464894748948489494895048951489524895348954489554895648957489584895948960489614896248963489644896548966489674896848969489704897148972489734897448975489764897748978489794898048981489824898348984489854898648987489884898948990489914899248993489944899548996489974899848999490004900149002490034900449005490064900749008490094901049011490124901349014490154901649017490184901949020490214902249023490244902549026490274902849029490304903149032490334903449035490364903749038490394904049041490424904349044490454904649047490484904949050490514905249053490544905549056490574905849059490604906149062490634906449065490664906749068490694907049071490724907349074490754907649077490784907949080490814908249083490844908549086490874908849089490904909149092490934909449095490964909749098490994910049101491024910349104491054910649107491084910949110491114911249113491144911549116491174911849119491204912149122491234912449125491264912749128491294913049131491324913349134491354913649137491384913949140491414914249143491444914549146491474914849149491504915149152491534915449155491564915749158491594916049161491624916349164491654916649167491684916949170491714917249173491744917549176491774917849179491804918149182491834918449185491864918749188491894919049191491924919349194491954919649197491984919949200492014920249203492044920549206492074920849209492104921149212492134921449215492164921749218492194922049221492224922349224492254922649227492284922949230492314923249233492344923549236492374923849239492404924149242492434924449245492464924749248492494925049251492524925349254492554925649257492584925949260492614926249263492644926549266492674926849269492704927149272492734927449275492764927749278492794928049281492824928349284492854928649287492884928949290492914929249293492944929549296492974929849299493004930149302493034930449305493064930749308493094931049311493124931349314493154931649317493184931949320493214932249323493244932549326493274932849329493304933149332493334933449335493364933749338493394934049341493424934349344493454934649347493484934949350493514935249353493544935549356493574935849359493604936149362493634936449365493664936749368493694937049371493724937349374493754937649377493784937949380493814938249383493844938549386493874938849389493904939149392493934939449395493964939749398493994940049401494024940349404494054940649407494084940949410494114941249413494144941549416494174941849419494204942149422494234942449425494264942749428494294943049431494324943349434494354943649437494384943949440494414944249443494444944549446494474944849449494504945149452494534945449455494564945749458494594946049461494624946349464494654946649467494684946949470494714947249473494744947549476494774947849479494804948149482494834948449485494864948749488494894949049491494924949349494494954949649497494984949949500495014950249503495044950549506495074950849509495104951149512495134951449515495164951749518495194952049521495224952349524495254952649527495284952949530495314953249533495344953549536495374953849539495404954149542495434954449545495464954749548495494955049551495524955349554495554955649557495584955949560495614956249563495644956549566495674956849569495704957149572495734957449575495764957749578495794958049581495824958349584495854958649587495884958949590495914959249593495944959549596495974959849599496004960149602496034960449605496064960749608496094961049611496124961349614496154961649617496184961949620496214962249623496244962549626496274962849629496304963149632496334963449635496364963749638496394964049641496424964349644496454964649647496484964949650496514965249653496544965549656496574965849659496604966149662496634966449665496664966749668496694967049671496724967349674496754967649677496784967949680496814968249683496844968549686496874968849689496904969149692496934969449695496964969749698496994970049701497024970349704497054970649707497084970949710497114971249713497144971549716497174971849719497204972149722497234972449725497264972749728497294973049731497324973349734497354973649737497384973949740497414974249743497444974549746497474974849749497504975149752497534975449755497564975749758497594976049761497624976349764497654976649767497684976949770497714977249773497744977549776497774977849779497804978149782497834978449785497864978749788497894979049791497924979349794497954979649797497984979949800498014980249803498044980549806498074980849809498104981149812498134981449815498164981749818498194982049821498224982349824498254982649827498284982949830498314983249833498344983549836498374983849839498404984149842498434984449845498464984749848498494985049851498524985349854498554985649857498584985949860498614986249863498644986549866498674986849869498704987149872498734987449875498764987749878498794988049881498824988349884498854988649887498884988949890498914989249893498944989549896498974989849899499004990149902499034990449905499064990749908499094991049911499124991349914499154991649917499184991949920499214992249923499244992549926499274992849929499304993149932499334993449935499364993749938499394994049941499424994349944499454994649947499484994949950499514995249953499544995549956499574995849959499604996149962499634996449965499664996749968499694997049971499724997349974499754997649977499784997949980499814998249983499844998549986499874998849989499904999149992499934999449995499964999749998499995000050001500025000350004500055000650007500085000950010500115001250013500145001550016500175001850019500205002150022500235002450025500265002750028500295003050031500325003350034500355003650037500385003950040500415004250043500445004550046500475004850049500505005150052500535005450055500565005750058500595006050061500625006350064500655006650067500685006950070500715007250073500745007550076500775007850079500805008150082500835008450085500865008750088500895009050091500925009350094500955009650097500985009950100501015010250103501045010550106501075010850109501105011150112501135011450115501165011750118501195012050121501225012350124501255012650127501285012950130501315013250133501345013550136501375013850139501405014150142501435014450145501465014750148501495015050151501525015350154501555015650157501585015950160501615016250163501645016550166501675016850169501705017150172501735017450175501765017750178501795018050181501825018350184501855018650187501885018950190501915019250193501945019550196501975019850199502005020150202502035020450205502065020750208502095021050211502125021350214502155021650217502185021950220502215022250223502245022550226502275022850229502305023150232502335023450235502365023750238502395024050241502425024350244502455024650247502485024950250502515025250253502545025550256502575025850259502605026150262502635026450265502665026750268502695027050271502725027350274502755027650277502785027950280502815028250283502845028550286502875028850289502905029150292502935029450295502965029750298502995030050301503025030350304503055030650307503085030950310503115031250313503145031550316503175031850319503205032150322503235032450325503265032750328503295033050331503325033350334503355033650337503385033950340503415034250343503445034550346503475034850349503505035150352503535035450355503565035750358503595036050361503625036350364503655036650367503685036950370503715037250373503745037550376503775037850379503805038150382503835038450385503865038750388503895039050391503925039350394503955039650397503985039950400504015040250403504045040550406504075040850409504105041150412504135041450415504165041750418504195042050421504225042350424504255042650427504285042950430504315043250433504345043550436504375043850439504405044150442504435044450445504465044750448504495045050451504525045350454504555045650457504585045950460504615046250463504645046550466504675046850469504705047150472504735047450475504765047750478504795048050481504825048350484504855048650487504885048950490504915049250493504945049550496504975049850499505005050150502505035050450505505065050750508505095051050511505125051350514505155051650517505185051950520505215052250523505245052550526505275052850529505305053150532505335053450535505365053750538505395054050541505425054350544505455054650547505485054950550505515055250553505545055550556505575055850559505605056150562505635056450565505665056750568505695057050571505725057350574505755057650577505785057950580505815058250583505845058550586505875058850589505905059150592505935059450595505965059750598505995060050601506025060350604506055060650607506085060950610506115061250613506145061550616506175061850619506205062150622506235062450625506265062750628506295063050631506325063350634506355063650637506385063950640506415064250643506445064550646506475064850649506505065150652506535065450655506565065750658506595066050661506625066350664506655066650667506685066950670506715067250673506745067550676506775067850679506805068150682506835068450685506865068750688506895069050691506925069350694506955069650697506985069950700507015070250703507045070550706507075070850709507105071150712507135071450715507165071750718507195072050721507225072350724507255072650727507285072950730507315073250733507345073550736507375073850739507405074150742507435074450745507465074750748507495075050751507525075350754507555075650757507585075950760507615076250763507645076550766507675076850769507705077150772507735077450775507765077750778507795078050781507825078350784507855078650787507885078950790507915079250793507945079550796507975079850799508005080150802508035080450805508065080750808508095081050811508125081350814508155081650817508185081950820508215082250823508245082550826508275082850829508305083150832508335083450835508365083750838508395084050841508425084350844508455084650847508485084950850508515085250853508545085550856508575085850859508605086150862508635086450865508665086750868508695087050871508725087350874508755087650877508785087950880508815088250883508845088550886508875088850889508905089150892508935089450895508965089750898508995090050901509025090350904509055090650907509085090950910509115091250913509145091550916509175091850919509205092150922509235092450925509265092750928509295093050931509325093350934509355093650937509385093950940509415094250943509445094550946509475094850949509505095150952509535095450955509565095750958509595096050961509625096350964509655096650967509685096950970509715097250973509745097550976509775097850979509805098150982509835098450985509865098750988509895099050991509925099350994509955099650997509985099951000510015100251003510045100551006510075100851009510105101151012510135101451015510165101751018510195102051021510225102351024510255102651027510285102951030510315103251033510345103551036510375103851039510405104151042510435104451045510465104751048510495105051051510525105351054510555105651057510585105951060510615106251063510645106551066510675106851069510705107151072510735107451075510765107751078510795108051081510825108351084510855108651087510885108951090510915109251093510945109551096510975109851099511005110151102511035110451105511065110751108511095111051111511125111351114511155111651117511185111951120511215112251123511245112551126511275112851129511305113151132511335113451135511365113751138511395114051141511425114351144511455114651147511485114951150511515115251153511545115551156511575115851159511605116151162511635116451165511665116751168511695117051171511725117351174511755117651177511785117951180511815118251183511845118551186511875118851189511905119151192511935119451195511965119751198511995120051201512025120351204512055120651207512085120951210512115121251213512145121551216512175121851219512205122151222512235122451225512265122751228512295123051231512325123351234512355123651237512385123951240512415124251243512445124551246512475124851249512505125151252512535125451255512565125751258512595126051261512625126351264512655126651267512685126951270512715127251273512745127551276512775127851279512805128151282512835128451285512865128751288512895129051291512925129351294512955129651297512985129951300513015130251303513045130551306513075130851309513105131151312513135131451315513165131751318513195132051321513225132351324513255132651327513285132951330513315133251333513345133551336513375133851339513405134151342513435134451345513465134751348513495135051351513525135351354513555135651357513585135951360513615136251363513645136551366513675136851369513705137151372513735137451375513765137751378513795138051381513825138351384513855138651387513885138951390513915139251393513945139551396513975139851399514005140151402514035140451405514065140751408514095141051411514125141351414514155141651417514185141951420514215142251423514245142551426514275142851429514305143151432514335143451435514365143751438514395144051441514425144351444514455144651447514485144951450514515145251453514545145551456514575145851459514605146151462514635146451465514665146751468514695147051471514725147351474514755147651477514785147951480514815148251483514845148551486514875148851489514905149151492514935149451495514965149751498514995150051501515025150351504515055150651507515085150951510515115151251513515145151551516515175151851519515205152151522515235152451525515265152751528515295153051531515325153351534515355153651537515385153951540515415154251543515445154551546515475154851549515505155151552515535155451555515565155751558515595156051561515625156351564515655156651567515685156951570515715157251573515745157551576515775157851579515805158151582515835158451585515865158751588515895159051591515925159351594515955159651597515985159951600516015160251603516045160551606516075160851609516105161151612516135161451615516165161751618516195162051621516225162351624516255162651627516285162951630516315163251633516345163551636516375163851639516405164151642516435164451645516465164751648516495165051651516525165351654516555165651657516585165951660516615166251663516645166551666516675166851669516705167151672516735167451675516765167751678516795168051681516825168351684516855168651687516885168951690516915169251693516945169551696516975169851699517005170151702517035170451705517065170751708517095171051711517125171351714517155171651717517185171951720517215172251723517245172551726517275172851729517305173151732517335173451735517365173751738517395174051741517425174351744517455174651747517485174951750517515175251753517545175551756517575175851759517605176151762517635176451765517665176751768517695177051771517725177351774517755177651777517785177951780517815178251783517845178551786517875178851789517905179151792517935179451795517965179751798517995180051801518025180351804518055180651807518085180951810518115181251813518145181551816518175181851819518205182151822518235182451825518265182751828518295183051831518325183351834518355183651837518385183951840518415184251843518445184551846518475184851849518505185151852518535185451855518565185751858518595186051861518625186351864518655186651867518685186951870518715187251873518745187551876518775187851879518805188151882518835188451885518865188751888518895189051891518925189351894518955189651897518985189951900519015190251903519045190551906519075190851909519105191151912519135191451915519165191751918519195192051921519225192351924519255192651927519285192951930519315193251933519345193551936519375193851939519405194151942519435194451945519465194751948519495195051951519525195351954519555195651957519585195951960519615196251963519645196551966519675196851969519705197151972519735197451975519765197751978519795198051981519825198351984519855198651987519885198951990519915199251993519945199551996519975199851999520005200152002520035200452005520065200752008520095201052011520125201352014520155201652017520185201952020520215202252023520245202552026520275202852029520305203152032520335203452035520365203752038520395204052041520425204352044520455204652047520485204952050520515205252053520545205552056520575205852059520605206152062520635206452065520665206752068520695207052071520725207352074520755207652077520785207952080520815208252083520845208552086520875208852089520905209152092520935209452095520965209752098520995210052101521025210352104521055210652107521085210952110521115211252113521145211552116521175211852119521205212152122521235212452125521265212752128521295213052131521325213352134521355213652137521385213952140521415214252143521445214552146521475214852149521505215152152521535215452155521565215752158521595216052161521625216352164521655216652167521685216952170521715217252173521745217552176521775217852179521805218152182521835218452185521865218752188521895219052191521925219352194521955219652197521985219952200522015220252203522045220552206522075220852209522105221152212522135221452215522165221752218522195222052221522225222352224522255222652227522285222952230522315223252233522345223552236522375223852239522405224152242522435224452245522465224752248522495225052251522525225352254522555225652257522585225952260522615226252263522645226552266522675226852269522705227152272522735227452275522765227752278522795228052281522825228352284522855228652287522885228952290522915229252293522945229552296522975229852299523005230152302523035230452305523065230752308523095231052311523125231352314523155231652317523185231952320523215232252323523245232552326523275232852329523305233152332523335233452335523365233752338523395234052341523425234352344523455234652347523485234952350523515235252353523545235552356523575235852359523605236152362523635236452365523665236752368523695237052371523725237352374523755237652377523785237952380523815238252383523845238552386523875238852389523905239152392523935239452395523965239752398523995240052401524025240352404524055240652407524085240952410524115241252413524145241552416524175241852419524205242152422524235242452425524265242752428524295243052431524325243352434524355243652437524385243952440524415244252443524445244552446524475244852449524505245152452524535245452455524565245752458524595246052461524625246352464524655246652467524685246952470524715247252473524745247552476524775247852479524805248152482524835248452485524865248752488524895249052491524925249352494524955249652497524985249952500525015250252503525045250552506525075250852509525105251152512525135251452515525165251752518525195252052521525225252352524525255252652527525285252952530525315253252533525345253552536525375253852539525405254152542525435254452545525465254752548525495255052551525525255352554525555255652557525585255952560525615256252563525645256552566525675256852569525705257152572525735257452575525765257752578525795258052581525825258352584525855258652587525885258952590525915259252593525945259552596525975259852599526005260152602526035260452605526065260752608526095261052611526125261352614526155261652617526185261952620526215262252623526245262552626526275262852629526305263152632526335263452635526365263752638526395264052641526425264352644526455264652647526485264952650526515265252653526545265552656526575265852659526605266152662526635266452665526665266752668526695267052671526725267352674526755267652677526785267952680526815268252683526845268552686526875268852689526905269152692526935269452695526965269752698526995270052701527025270352704527055270652707527085270952710527115271252713527145271552716527175271852719527205272152722527235272452725527265272752728527295273052731527325273352734527355273652737527385273952740527415274252743527445274552746527475274852749527505275152752527535275452755527565275752758527595276052761527625276352764527655276652767527685276952770527715277252773527745277552776527775277852779527805278152782527835278452785527865278752788527895279052791527925279352794527955279652797527985279952800528015280252803528045280552806528075280852809528105281152812528135281452815528165281752818528195282052821528225282352824528255282652827528285282952830528315283252833528345283552836528375283852839528405284152842528435284452845528465284752848528495285052851528525285352854528555285652857528585285952860528615286252863528645286552866528675286852869528705287152872528735287452875528765287752878528795288052881528825288352884528855288652887528885288952890528915289252893528945289552896528975289852899529005290152902529035290452905529065290752908529095291052911529125291352914529155291652917529185291952920529215292252923529245292552926529275292852929529305293152932529335293452935529365293752938529395294052941529425294352944529455294652947529485294952950529515295252953529545295552956529575295852959529605296152962529635296452965529665296752968529695297052971529725297352974529755297652977529785297952980529815298252983529845298552986529875298852989529905299152992529935299452995529965299752998529995300053001530025300353004530055300653007530085300953010530115301253013530145301553016530175301853019530205302153022530235302453025530265302753028530295303053031530325303353034530355303653037530385303953040530415304253043530445304553046530475304853049530505305153052530535305453055530565305753058530595306053061530625306353064530655306653067530685306953070530715307253073530745307553076530775307853079530805308153082530835308453085530865308753088530895309053091530925309353094530955309653097530985309953100531015310253103531045310553106531075310853109531105311153112531135311453115531165311753118531195312053121531225312353124531255312653127531285312953130531315313253133531345313553136531375313853139531405314153142531435314453145531465314753148531495315053151531525315353154531555315653157531585315953160531615316253163531645316553166531675316853169531705317153172531735317453175531765317753178531795318053181531825318353184531855318653187531885318953190531915319253193531945319553196531975319853199532005320153202532035320453205532065320753208532095321053211532125321353214532155321653217532185321953220532215322253223532245322553226532275322853229532305323153232532335323453235532365323753238532395324053241532425324353244532455324653247532485324953250532515325253253532545325553256532575325853259532605326153262532635326453265532665326753268532695327053271532725327353274532755327653277532785327953280532815328253283532845328553286532875328853289532905329153292532935329453295532965329753298532995330053301533025330353304533055330653307533085330953310533115331253313533145331553316533175331853319533205332153322533235332453325533265332753328533295333053331533325333353334533355333653337533385333953340533415334253343533445334553346533475334853349533505335153352533535335453355533565335753358533595336053361533625336353364533655336653367533685336953370533715337253373533745337553376533775337853379533805338153382533835338453385533865338753388533895339053391533925339353394533955339653397533985339953400534015340253403534045340553406534075340853409534105341153412534135341453415534165341753418534195342053421534225342353424534255342653427534285342953430534315343253433534345343553436534375343853439534405344153442534435344453445534465344753448534495345053451534525345353454534555345653457534585345953460534615346253463534645346553466534675346853469534705347153472534735347453475534765347753478534795348053481534825348353484534855348653487534885348953490534915349253493534945349553496534975349853499535005350153502535035350453505535065350753508535095351053511535125351353514535155351653517535185351953520535215352253523535245352553526535275352853529535305353153532535335353453535535365353753538535395354053541535425354353544535455354653547535485354953550535515355253553535545355553556535575355853559535605356153562535635356453565535665356753568535695357053571535725357353574535755357653577535785357953580535815358253583535845358553586535875358853589535905359153592535935359453595535965359753598535995360053601536025360353604536055360653607536085360953610536115361253613536145361553616536175361853619536205362153622536235362453625536265362753628536295363053631536325363353634536355363653637536385363953640536415364253643536445364553646536475364853649536505365153652536535365453655536565365753658536595366053661536625366353664536655366653667536685366953670536715367253673536745367553676536775367853679536805368153682536835368453685536865368753688536895369053691536925369353694536955369653697536985369953700537015370253703537045370553706537075370853709537105371153712537135371453715537165371753718537195372053721537225372353724537255372653727537285372953730537315373253733537345373553736537375373853739537405374153742537435374453745537465374753748537495375053751537525375353754537555375653757537585375953760537615376253763537645376553766537675376853769537705377153772537735377453775537765377753778537795378053781537825378353784537855378653787537885378953790537915379253793537945379553796537975379853799538005380153802538035380453805538065380753808538095381053811538125381353814538155381653817538185381953820538215382253823538245382553826538275382853829538305383153832538335383453835538365383753838538395384053841538425384353844538455384653847538485384953850538515385253853538545385553856538575385853859538605386153862538635386453865538665386753868538695387053871538725387353874538755387653877538785387953880538815388253883538845388553886538875388853889538905389153892538935389453895538965389753898538995390053901539025390353904539055390653907539085390953910539115391253913
  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.313';
  28. var pdfjsBuild = 'c23f124';
  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. warn('CFFParser_parseDict: "' + value + '" is a reserved command.');
  6851. return NaN;
  6852. }
  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. var valueLength = value.length;
  7492. // ignore empty values
  7493. if (valueLength === 0) {
  7494. return true;
  7495. }
  7496. // Ignore invalid values (fixes bug1068432.pdf and bug1308536.pdf).
  7497. for (var i = 0; i < valueLength; i++) {
  7498. if (isNaN(value[i])) {
  7499. warn('Invalid CFFDict value: "' + value + '" for key "' + key + '".');
  7500. return true;
  7501. }
  7502. }
  7503. var type = this.types[key];
  7504. // remove the array wrapping these types of values
  7505. if (type === 'num' || type === 'sid' || type === 'offset') {
  7506. value = value[0];
  7507. }
  7508. this.values[key] = value;
  7509. return true;
  7510. },
  7511. setByName: function CFFDict_setByName(name, value) {
  7512. if (!(name in this.nameToKeyMap)) {
  7513. error('Invalid dictionary name "' + name + '"');
  7514. }
  7515. this.values[this.nameToKeyMap[name]] = value;
  7516. },
  7517. hasName: function CFFDict_hasName(name) {
  7518. return this.nameToKeyMap[name] in this.values;
  7519. },
  7520. getByName: function CFFDict_getByName(name) {
  7521. if (!(name in this.nameToKeyMap)) {
  7522. error('Invalid dictionary name "' + name + '"');
  7523. }
  7524. var key = this.nameToKeyMap[name];
  7525. if (!(key in this.values)) {
  7526. return this.defaults[key];
  7527. }
  7528. return this.values[key];
  7529. },
  7530. removeByName: function CFFDict_removeByName(name) {
  7531. delete this.values[this.nameToKeyMap[name]];
  7532. }
  7533. };
  7534. CFFDict.createTables = function CFFDict_createTables(layout) {
  7535. var tables = {
  7536. keyToNameMap: {},
  7537. nameToKeyMap: {},
  7538. defaults: {},
  7539. types: {},
  7540. opcodes: {},
  7541. order: []
  7542. };
  7543. for (var i = 0, ii = layout.length; i < ii; ++i) {
  7544. var entry = layout[i];
  7545. var key = isArray(entry[0]) ? (entry[0][0] << 8) + entry[0][1] : entry[0];
  7546. tables.keyToNameMap[key] = entry[1];
  7547. tables.nameToKeyMap[entry[1]] = key;
  7548. tables.types[key] = entry[2];
  7549. tables.defaults[key] = entry[3];
  7550. tables.opcodes[key] = isArray(entry[0]) ? entry[0] : [entry[0]];
  7551. tables.order.push(key);
  7552. }
  7553. return tables;
  7554. };
  7555. return CFFDict;
  7556. }();
  7557. var CFFTopDict = function CFFTopDictClosure() {
  7558. var layout = [
  7559. [
  7560. [
  7561. 12,
  7562. 30
  7563. ],
  7564. 'ROS',
  7565. [
  7566. 'sid',
  7567. 'sid',
  7568. 'num'
  7569. ],
  7570. null
  7571. ],
  7572. [
  7573. [
  7574. 12,
  7575. 20
  7576. ],
  7577. 'SyntheticBase',
  7578. 'num',
  7579. null
  7580. ],
  7581. [
  7582. 0,
  7583. 'version',
  7584. 'sid',
  7585. null
  7586. ],
  7587. [
  7588. 1,
  7589. 'Notice',
  7590. 'sid',
  7591. null
  7592. ],
  7593. [
  7594. [
  7595. 12,
  7596. 0
  7597. ],
  7598. 'Copyright',
  7599. 'sid',
  7600. null
  7601. ],
  7602. [
  7603. 2,
  7604. 'FullName',
  7605. 'sid',
  7606. null
  7607. ],
  7608. [
  7609. 3,
  7610. 'FamilyName',
  7611. 'sid',
  7612. null
  7613. ],
  7614. [
  7615. 4,
  7616. 'Weight',
  7617. 'sid',
  7618. null
  7619. ],
  7620. [
  7621. [
  7622. 12,
  7623. 1
  7624. ],
  7625. 'isFixedPitch',
  7626. 'num',
  7627. 0
  7628. ],
  7629. [
  7630. [
  7631. 12,
  7632. 2
  7633. ],
  7634. 'ItalicAngle',
  7635. 'num',
  7636. 0
  7637. ],
  7638. [
  7639. [
  7640. 12,
  7641. 3
  7642. ],
  7643. 'UnderlinePosition',
  7644. 'num',
  7645. -100
  7646. ],
  7647. [
  7648. [
  7649. 12,
  7650. 4
  7651. ],
  7652. 'UnderlineThickness',
  7653. 'num',
  7654. 50
  7655. ],
  7656. [
  7657. [
  7658. 12,
  7659. 5
  7660. ],
  7661. 'PaintType',
  7662. 'num',
  7663. 0
  7664. ],
  7665. [
  7666. [
  7667. 12,
  7668. 6
  7669. ],
  7670. 'CharstringType',
  7671. 'num',
  7672. 2
  7673. ],
  7674. [
  7675. [
  7676. 12,
  7677. 7
  7678. ],
  7679. 'FontMatrix',
  7680. [
  7681. 'num',
  7682. 'num',
  7683. 'num',
  7684. 'num',
  7685. 'num',
  7686. 'num'
  7687. ],
  7688. [
  7689. 0.001,
  7690. 0,
  7691. 0,
  7692. 0.001,
  7693. 0,
  7694. 0
  7695. ]
  7696. ],
  7697. [
  7698. 13,
  7699. 'UniqueID',
  7700. 'num',
  7701. null
  7702. ],
  7703. [
  7704. 5,
  7705. 'FontBBox',
  7706. [
  7707. 'num',
  7708. 'num',
  7709. 'num',
  7710. 'num'
  7711. ],
  7712. [
  7713. 0,
  7714. 0,
  7715. 0,
  7716. 0
  7717. ]
  7718. ],
  7719. [
  7720. [
  7721. 12,
  7722. 8
  7723. ],
  7724. 'StrokeWidth',
  7725. 'num',
  7726. 0
  7727. ],
  7728. [
  7729. 14,
  7730. 'XUID',
  7731. 'array',
  7732. null
  7733. ],
  7734. [
  7735. 15,
  7736. 'charset',
  7737. 'offset',
  7738. 0
  7739. ],
  7740. [
  7741. 16,
  7742. 'Encoding',
  7743. 'offset',
  7744. 0
  7745. ],
  7746. [
  7747. 17,
  7748. 'CharStrings',
  7749. 'offset',
  7750. 0
  7751. ],
  7752. [
  7753. 18,
  7754. 'Private',
  7755. [
  7756. 'offset',
  7757. 'offset'
  7758. ],
  7759. null
  7760. ],
  7761. [
  7762. [
  7763. 12,
  7764. 21
  7765. ],
  7766. 'PostScript',
  7767. 'sid',
  7768. null
  7769. ],
  7770. [
  7771. [
  7772. 12,
  7773. 22
  7774. ],
  7775. 'BaseFontName',
  7776. 'sid',
  7777. null
  7778. ],
  7779. [
  7780. [
  7781. 12,
  7782. 23
  7783. ],
  7784. 'BaseFontBlend',
  7785. 'delta',
  7786. null
  7787. ],
  7788. [
  7789. [
  7790. 12,
  7791. 31
  7792. ],
  7793. 'CIDFontVersion',
  7794. 'num',
  7795. 0
  7796. ],
  7797. [
  7798. [
  7799. 12,
  7800. 32
  7801. ],
  7802. 'CIDFontRevision',
  7803. 'num',
  7804. 0
  7805. ],
  7806. [
  7807. [
  7808. 12,
  7809. 33
  7810. ],
  7811. 'CIDFontType',
  7812. 'num',
  7813. 0
  7814. ],
  7815. [
  7816. [
  7817. 12,
  7818. 34
  7819. ],
  7820. 'CIDCount',
  7821. 'num',
  7822. 8720
  7823. ],
  7824. [
  7825. [
  7826. 12,
  7827. 35
  7828. ],
  7829. 'UIDBase',
  7830. 'num',
  7831. null
  7832. ],
  7833. // XXX: CID Fonts on DirectWrite 6.1 only seem to work if FDSelect comes
  7834. // before FDArray.
  7835. [
  7836. [
  7837. 12,
  7838. 37
  7839. ],
  7840. 'FDSelect',
  7841. 'offset',
  7842. null
  7843. ],
  7844. [
  7845. [
  7846. 12,
  7847. 36
  7848. ],
  7849. 'FDArray',
  7850. 'offset',
  7851. null
  7852. ],
  7853. [
  7854. [
  7855. 12,
  7856. 38
  7857. ],
  7858. 'FontName',
  7859. 'sid',
  7860. null
  7861. ]
  7862. ];
  7863. var tables = null;
  7864. function CFFTopDict(strings) {
  7865. if (tables === null) {
  7866. tables = CFFDict.createTables(layout);
  7867. }
  7868. CFFDict.call(this, tables, strings);
  7869. this.privateDict = null;
  7870. }
  7871. CFFTopDict.prototype = Object.create(CFFDict.prototype);
  7872. return CFFTopDict;
  7873. }();
  7874. var CFFPrivateDict = function CFFPrivateDictClosure() {
  7875. var layout = [
  7876. [
  7877. 6,
  7878. 'BlueValues',
  7879. 'delta',
  7880. null
  7881. ],
  7882. [
  7883. 7,
  7884. 'OtherBlues',
  7885. 'delta',
  7886. null
  7887. ],
  7888. [
  7889. 8,
  7890. 'FamilyBlues',
  7891. 'delta',
  7892. null
  7893. ],
  7894. [
  7895. 9,
  7896. 'FamilyOtherBlues',
  7897. 'delta',
  7898. null
  7899. ],
  7900. [
  7901. [
  7902. 12,
  7903. 9
  7904. ],
  7905. 'BlueScale',
  7906. 'num',
  7907. 0.039625
  7908. ],
  7909. [
  7910. [
  7911. 12,
  7912. 10
  7913. ],
  7914. 'BlueShift',
  7915. 'num',
  7916. 7
  7917. ],
  7918. [
  7919. [
  7920. 12,
  7921. 11
  7922. ],
  7923. 'BlueFuzz',
  7924. 'num',
  7925. 1
  7926. ],
  7927. [
  7928. 10,
  7929. 'StdHW',
  7930. 'num',
  7931. null
  7932. ],
  7933. [
  7934. 11,
  7935. 'StdVW',
  7936. 'num',
  7937. null
  7938. ],
  7939. [
  7940. [
  7941. 12,
  7942. 12
  7943. ],
  7944. 'StemSnapH',
  7945. 'delta',
  7946. null
  7947. ],
  7948. [
  7949. [
  7950. 12,
  7951. 13
  7952. ],
  7953. 'StemSnapV',
  7954. 'delta',
  7955. null
  7956. ],
  7957. [
  7958. [
  7959. 12,
  7960. 14
  7961. ],
  7962. 'ForceBold',
  7963. 'num',
  7964. 0
  7965. ],
  7966. [
  7967. [
  7968. 12,
  7969. 17
  7970. ],
  7971. 'LanguageGroup',
  7972. 'num',
  7973. 0
  7974. ],
  7975. [
  7976. [
  7977. 12,
  7978. 18
  7979. ],
  7980. 'ExpansionFactor',
  7981. 'num',
  7982. 0.06
  7983. ],
  7984. [
  7985. [
  7986. 12,
  7987. 19
  7988. ],
  7989. 'initialRandomSeed',
  7990. 'num',
  7991. 0
  7992. ],
  7993. [
  7994. 20,
  7995. 'defaultWidthX',
  7996. 'num',
  7997. 0
  7998. ],
  7999. [
  8000. 21,
  8001. 'nominalWidthX',
  8002. 'num',
  8003. 0
  8004. ],
  8005. [
  8006. 19,
  8007. 'Subrs',
  8008. 'offset',
  8009. null
  8010. ]
  8011. ];
  8012. var tables = null;
  8013. function CFFPrivateDict(strings) {
  8014. if (tables === null) {
  8015. tables = CFFDict.createTables(layout);
  8016. }
  8017. CFFDict.call(this, tables, strings);
  8018. this.subrsIndex = null;
  8019. }
  8020. CFFPrivateDict.prototype = Object.create(CFFDict.prototype);
  8021. return CFFPrivateDict;
  8022. }();
  8023. var CFFCharsetPredefinedTypes = {
  8024. ISO_ADOBE: 0,
  8025. EXPERT: 1,
  8026. EXPERT_SUBSET: 2
  8027. };
  8028. var CFFCharset = function CFFCharsetClosure() {
  8029. function CFFCharset(predefined, format, charset, raw) {
  8030. this.predefined = predefined;
  8031. this.format = format;
  8032. this.charset = charset;
  8033. this.raw = raw;
  8034. }
  8035. return CFFCharset;
  8036. }();
  8037. var CFFEncoding = function CFFEncodingClosure() {
  8038. function CFFEncoding(predefined, format, encoding, raw) {
  8039. this.predefined = predefined;
  8040. this.format = format;
  8041. this.encoding = encoding;
  8042. this.raw = raw;
  8043. }
  8044. return CFFEncoding;
  8045. }();
  8046. var CFFFDSelect = function CFFFDSelectClosure() {
  8047. function CFFFDSelect(fdSelect, raw) {
  8048. this.fdSelect = fdSelect;
  8049. this.raw = raw;
  8050. }
  8051. CFFFDSelect.prototype = {
  8052. getFDIndex: function CFFFDSelect_get(glyphIndex) {
  8053. if (glyphIndex < 0 || glyphIndex >= this.fdSelect.length) {
  8054. return -1;
  8055. }
  8056. return this.fdSelect[glyphIndex];
  8057. }
  8058. };
  8059. return CFFFDSelect;
  8060. }();
  8061. // Helper class to keep track of where an offset is within the data and helps
  8062. // filling in that offset once it's known.
  8063. var CFFOffsetTracker = function CFFOffsetTrackerClosure() {
  8064. function CFFOffsetTracker() {
  8065. this.offsets = Object.create(null);
  8066. }
  8067. CFFOffsetTracker.prototype = {
  8068. isTracking: function CFFOffsetTracker_isTracking(key) {
  8069. return key in this.offsets;
  8070. },
  8071. track: function CFFOffsetTracker_track(key, location) {
  8072. if (key in this.offsets) {
  8073. error('Already tracking location of ' + key);
  8074. }
  8075. this.offsets[key] = location;
  8076. },
  8077. offset: function CFFOffsetTracker_offset(value) {
  8078. for (var key in this.offsets) {
  8079. this.offsets[key] += value;
  8080. }
  8081. },
  8082. setEntryLocation: function CFFOffsetTracker_setEntryLocation(key, values, output) {
  8083. if (!(key in this.offsets)) {
  8084. error('Not tracking location of ' + key);
  8085. }
  8086. var data = output.data;
  8087. var dataOffset = this.offsets[key];
  8088. var size = 5;
  8089. for (var i = 0, ii = values.length; i < ii; ++i) {
  8090. var offset0 = i * size + dataOffset;
  8091. var offset1 = offset0 + 1;
  8092. var offset2 = offset0 + 2;
  8093. var offset3 = offset0 + 3;
  8094. var offset4 = offset0 + 4;
  8095. // It's easy to screw up offsets so perform this sanity check.
  8096. if (data[offset0] !== 0x1d || data[offset1] !== 0 || data[offset2] !== 0 || data[offset3] !== 0 || data[offset4] !== 0) {
  8097. error('writing to an offset that is not empty');
  8098. }
  8099. var value = values[i];
  8100. data[offset0] = 0x1d;
  8101. data[offset1] = value >> 24 & 0xFF;
  8102. data[offset2] = value >> 16 & 0xFF;
  8103. data[offset3] = value >> 8 & 0xFF;
  8104. data[offset4] = value & 0xFF;
  8105. }
  8106. }
  8107. };
  8108. return CFFOffsetTracker;
  8109. }();
  8110. // Takes a CFF and converts it to the binary representation.
  8111. var CFFCompiler = function CFFCompilerClosure() {
  8112. function CFFCompiler(cff) {
  8113. this.cff = cff;
  8114. }
  8115. CFFCompiler.prototype = {
  8116. compile: function CFFCompiler_compile() {
  8117. var cff = this.cff;
  8118. var output = {
  8119. data: [],
  8120. length: 0,
  8121. add: function CFFCompiler_add(data) {
  8122. this.data = this.data.concat(data);
  8123. this.length = this.data.length;
  8124. }
  8125. };
  8126. // Compile the five entries that must be in order.
  8127. var header = this.compileHeader(cff.header);
  8128. output.add(header);
  8129. var nameIndex = this.compileNameIndex(cff.names);
  8130. output.add(nameIndex);
  8131. if (cff.isCIDFont) {
  8132. // The spec is unclear on how font matrices should relate to each other
  8133. // when there is one in the main top dict and the sub top dicts.
  8134. // Windows handles this differently than linux and osx so we have to
  8135. // normalize to work on all.
  8136. // Rules based off of some mailing list discussions:
  8137. // - If main font has a matrix and subfont doesn't, use the main matrix.
  8138. // - If no main font matrix and there is a subfont matrix, use the
  8139. // subfont matrix.
  8140. // - If both have matrices, concat together.
  8141. // - If neither have matrices, use default.
  8142. // To make this work on all platforms we move the top matrix into each
  8143. // sub top dict and concat if necessary.
  8144. if (cff.topDict.hasName('FontMatrix')) {
  8145. var base = cff.topDict.getByName('FontMatrix');
  8146. cff.topDict.removeByName('FontMatrix');
  8147. for (var i = 0, ii = cff.fdArray.length; i < ii; i++) {
  8148. var subDict = cff.fdArray[i];
  8149. var matrix = base.slice(0);
  8150. if (subDict.hasName('FontMatrix')) {
  8151. matrix = Util.transform(matrix, subDict.getByName('FontMatrix'));
  8152. }
  8153. subDict.setByName('FontMatrix', matrix);
  8154. }
  8155. }
  8156. }
  8157. var compiled = this.compileTopDicts([cff.topDict], output.length, cff.isCIDFont);
  8158. output.add(compiled.output);
  8159. var topDictTracker = compiled.trackers[0];
  8160. var stringIndex = this.compileStringIndex(cff.strings.strings);
  8161. output.add(stringIndex);
  8162. var globalSubrIndex = this.compileIndex(cff.globalSubrIndex);
  8163. output.add(globalSubrIndex);
  8164. // Now start on the other entries that have no specific order.
  8165. if (cff.encoding && cff.topDict.hasName('Encoding')) {
  8166. if (cff.encoding.predefined) {
  8167. topDictTracker.setEntryLocation('Encoding', [cff.encoding.format], output);
  8168. } else {
  8169. var encoding = this.compileEncoding(cff.encoding);
  8170. topDictTracker.setEntryLocation('Encoding', [output.length], output);
  8171. output.add(encoding);
  8172. }
  8173. }
  8174. if (cff.charset && cff.topDict.hasName('charset')) {
  8175. if (cff.charset.predefined) {
  8176. topDictTracker.setEntryLocation('charset', [cff.charset.format], output);
  8177. } else {
  8178. var charset = this.compileCharset(cff.charset);
  8179. topDictTracker.setEntryLocation('charset', [output.length], output);
  8180. output.add(charset);
  8181. }
  8182. }
  8183. var charStrings = this.compileCharStrings(cff.charStrings);
  8184. topDictTracker.setEntryLocation('CharStrings', [output.length], output);
  8185. output.add(charStrings);
  8186. if (cff.isCIDFont) {
  8187. // For some reason FDSelect must be in front of FDArray on windows. OSX
  8188. // and linux don't seem to care.
  8189. topDictTracker.setEntryLocation('FDSelect', [output.length], output);
  8190. var fdSelect = this.compileFDSelect(cff.fdSelect.raw);
  8191. output.add(fdSelect);
  8192. // It is unclear if the sub font dictionary can have CID related
  8193. // dictionary keys, but the sanitizer doesn't like them so remove them.
  8194. compiled = this.compileTopDicts(cff.fdArray, output.length, true);
  8195. topDictTracker.setEntryLocation('FDArray', [output.length], output);
  8196. output.add(compiled.output);
  8197. var fontDictTrackers = compiled.trackers;
  8198. this.compilePrivateDicts(cff.fdArray, fontDictTrackers, output);
  8199. }
  8200. this.compilePrivateDicts([cff.topDict], [topDictTracker], output);
  8201. // If the font data ends with INDEX whose object data is zero-length,
  8202. // the sanitizer will bail out. Add a dummy byte to avoid that.
  8203. output.add([0]);
  8204. return output.data;
  8205. },
  8206. encodeNumber: function CFFCompiler_encodeNumber(value) {
  8207. if (parseFloat(value) === parseInt(value, 10) && !isNaN(value)) {
  8208. // isInt
  8209. return this.encodeInteger(value);
  8210. } else {
  8211. return this.encodeFloat(value);
  8212. }
  8213. },
  8214. encodeFloat: function CFFCompiler_encodeFloat(num) {
  8215. var value = num.toString();
  8216. // rounding inaccurate doubles
  8217. var m = /\.(\d*?)(?:9{5,20}|0{5,20})\d{0,2}(?:e(.+)|$)/.exec(value);
  8218. if (m) {
  8219. var epsilon = parseFloat('1e' + ((m[2] ? +m[2] : 0) + m[1].length));
  8220. value = (Math.round(num * epsilon) / epsilon).toString();
  8221. }
  8222. var nibbles = '';
  8223. var i, ii;
  8224. for (i = 0, ii = value.length; i < ii; ++i) {
  8225. var a = value[i];
  8226. if (a === 'e') {
  8227. nibbles += value[++i] === '-' ? 'c' : 'b';
  8228. } else if (a === '.') {
  8229. nibbles += 'a';
  8230. } else if (a === '-') {
  8231. nibbles += 'e';
  8232. } else {
  8233. nibbles += a;
  8234. }
  8235. }
  8236. nibbles += nibbles.length & 1 ? 'f' : 'ff';
  8237. var out = [30];
  8238. for (i = 0, ii = nibbles.length; i < ii; i += 2) {
  8239. out.push(parseInt(nibbles.substr(i, 2), 16));
  8240. }
  8241. return out;
  8242. },
  8243. encodeInteger: function CFFCompiler_encodeInteger(value) {
  8244. var code;
  8245. if (value >= -107 && value <= 107) {
  8246. code = [value + 139];
  8247. } else if (value >= 108 && value <= 1131) {
  8248. value = value - 108;
  8249. code = [
  8250. (value >> 8) + 247,
  8251. value & 0xFF
  8252. ];
  8253. } else if (value >= -1131 && value <= -108) {
  8254. value = -value - 108;
  8255. code = [
  8256. (value >> 8) + 251,
  8257. value & 0xFF
  8258. ];
  8259. } else if (value >= -32768 && value <= 32767) {
  8260. code = [
  8261. 0x1c,
  8262. value >> 8 & 0xFF,
  8263. value & 0xFF
  8264. ];
  8265. } else {
  8266. code = [
  8267. 0x1d,
  8268. value >> 24 & 0xFF,
  8269. value >> 16 & 0xFF,
  8270. value >> 8 & 0xFF,
  8271. value & 0xFF
  8272. ];
  8273. }
  8274. return code;
  8275. },
  8276. compileHeader: function CFFCompiler_compileHeader(header) {
  8277. return [
  8278. header.major,
  8279. header.minor,
  8280. header.hdrSize,
  8281. header.offSize
  8282. ];
  8283. },
  8284. compileNameIndex: function CFFCompiler_compileNameIndex(names) {
  8285. var nameIndex = new CFFIndex();
  8286. for (var i = 0, ii = names.length; i < ii; ++i) {
  8287. nameIndex.add(stringToBytes(names[i]));
  8288. }
  8289. return this.compileIndex(nameIndex);
  8290. },
  8291. compileTopDicts: function CFFCompiler_compileTopDicts(dicts, length, removeCidKeys) {
  8292. var fontDictTrackers = [];
  8293. var fdArrayIndex = new CFFIndex();
  8294. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  8295. var fontDict = dicts[i];
  8296. if (removeCidKeys) {
  8297. fontDict.removeByName('CIDFontVersion');
  8298. fontDict.removeByName('CIDFontRevision');
  8299. fontDict.removeByName('CIDFontType');
  8300. fontDict.removeByName('CIDCount');
  8301. fontDict.removeByName('UIDBase');
  8302. }
  8303. var fontDictTracker = new CFFOffsetTracker();
  8304. var fontDictData = this.compileDict(fontDict, fontDictTracker);
  8305. fontDictTrackers.push(fontDictTracker);
  8306. fdArrayIndex.add(fontDictData);
  8307. fontDictTracker.offset(length);
  8308. }
  8309. fdArrayIndex = this.compileIndex(fdArrayIndex, fontDictTrackers);
  8310. return {
  8311. trackers: fontDictTrackers,
  8312. output: fdArrayIndex
  8313. };
  8314. },
  8315. compilePrivateDicts: function CFFCompiler_compilePrivateDicts(dicts, trackers, output) {
  8316. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  8317. var fontDict = dicts[i];
  8318. assert(fontDict.privateDict && fontDict.hasName('Private'), 'There must be an private dictionary.');
  8319. var privateDict = fontDict.privateDict;
  8320. var privateDictTracker = new CFFOffsetTracker();
  8321. var privateDictData = this.compileDict(privateDict, privateDictTracker);
  8322. var outputLength = output.length;
  8323. privateDictTracker.offset(outputLength);
  8324. if (!privateDictData.length) {
  8325. // The private dictionary was empty, set the output length to zero to
  8326. // ensure the offset length isn't out of bounds in the eyes of the
  8327. // sanitizer.
  8328. outputLength = 0;
  8329. }
  8330. trackers[i].setEntryLocation('Private', [
  8331. privateDictData.length,
  8332. outputLength
  8333. ], output);
  8334. output.add(privateDictData);
  8335. if (privateDict.subrsIndex && privateDict.hasName('Subrs')) {
  8336. var subrs = this.compileIndex(privateDict.subrsIndex);
  8337. privateDictTracker.setEntryLocation('Subrs', [privateDictData.length], output);
  8338. output.add(subrs);
  8339. }
  8340. }
  8341. },
  8342. compileDict: function CFFCompiler_compileDict(dict, offsetTracker) {
  8343. var out = [];
  8344. // The dictionary keys must be in a certain order.
  8345. var order = dict.order;
  8346. for (var i = 0; i < order.length; ++i) {
  8347. var key = order[i];
  8348. if (!(key in dict.values)) {
  8349. continue;
  8350. }
  8351. var values = dict.values[key];
  8352. var types = dict.types[key];
  8353. if (!isArray(types)) {
  8354. types = [types];
  8355. }
  8356. if (!isArray(values)) {
  8357. values = [values];
  8358. }
  8359. // Remove any empty dict values.
  8360. if (values.length === 0) {
  8361. continue;
  8362. }
  8363. for (var j = 0, jj = types.length; j < jj; ++j) {
  8364. var type = types[j];
  8365. var value = values[j];
  8366. switch (type) {
  8367. case 'num':
  8368. case 'sid':
  8369. out = out.concat(this.encodeNumber(value));
  8370. break;
  8371. case 'offset':
  8372. // For offsets we just insert a 32bit integer so we don't have to
  8373. // deal with figuring out the length of the offset when it gets
  8374. // replaced later on by the compiler.
  8375. var name = dict.keyToNameMap[key];
  8376. // Some offsets have the offset and the length, so just record the
  8377. // position of the first one.
  8378. if (!offsetTracker.isTracking(name)) {
  8379. offsetTracker.track(name, out.length);
  8380. }
  8381. out = out.concat([
  8382. 0x1d,
  8383. 0,
  8384. 0,
  8385. 0,
  8386. 0
  8387. ]);
  8388. break;
  8389. case 'array':
  8390. case 'delta':
  8391. out = out.concat(this.encodeNumber(value));
  8392. for (var k = 1, kk = values.length; k < kk; ++k) {
  8393. out = out.concat(this.encodeNumber(values[k]));
  8394. }
  8395. break;
  8396. default:
  8397. error('Unknown data type of ' + type);
  8398. break;
  8399. }
  8400. }
  8401. out = out.concat(dict.opcodes[key]);
  8402. }
  8403. return out;
  8404. },
  8405. compileStringIndex: function CFFCompiler_compileStringIndex(strings) {
  8406. var stringIndex = new CFFIndex();
  8407. for (var i = 0, ii = strings.length; i < ii; ++i) {
  8408. stringIndex.add(stringToBytes(strings[i]));
  8409. }
  8410. return this.compileIndex(stringIndex);
  8411. },
  8412. compileGlobalSubrIndex: function CFFCompiler_compileGlobalSubrIndex() {
  8413. var globalSubrIndex = this.cff.globalSubrIndex;
  8414. this.out.writeByteArray(this.compileIndex(globalSubrIndex));
  8415. },
  8416. compileCharStrings: function CFFCompiler_compileCharStrings(charStrings) {
  8417. return this.compileIndex(charStrings);
  8418. },
  8419. compileCharset: function CFFCompiler_compileCharset(charset) {
  8420. return this.compileTypedArray(charset.raw);
  8421. },
  8422. compileEncoding: function CFFCompiler_compileEncoding(encoding) {
  8423. return this.compileTypedArray(encoding.raw);
  8424. },
  8425. compileFDSelect: function CFFCompiler_compileFDSelect(fdSelect) {
  8426. return this.compileTypedArray(fdSelect);
  8427. },
  8428. compileTypedArray: function CFFCompiler_compileTypedArray(data) {
  8429. var out = [];
  8430. for (var i = 0, ii = data.length; i < ii; ++i) {
  8431. out[i] = data[i];
  8432. }
  8433. return out;
  8434. },
  8435. compileIndex: function CFFCompiler_compileIndex(index, trackers) {
  8436. trackers = trackers || [];
  8437. var objects = index.objects;
  8438. // First 2 bytes contains the number of objects contained into this index
  8439. var count = objects.length;
  8440. // If there is no object, just create an index. This technically
  8441. // should just be [0, 0] but OTS has an issue with that.
  8442. if (count === 0) {
  8443. return [
  8444. 0,
  8445. 0,
  8446. 0
  8447. ];
  8448. }
  8449. var data = [
  8450. count >> 8 & 0xFF,
  8451. count & 0xff
  8452. ];
  8453. var lastOffset = 1, i;
  8454. for (i = 0; i < count; ++i) {
  8455. lastOffset += objects[i].length;
  8456. }
  8457. var offsetSize;
  8458. if (lastOffset < 0x100) {
  8459. offsetSize = 1;
  8460. } else if (lastOffset < 0x10000) {
  8461. offsetSize = 2;
  8462. } else if (lastOffset < 0x1000000) {
  8463. offsetSize = 3;
  8464. } else {
  8465. offsetSize = 4;
  8466. }
  8467. // Next byte contains the offset size use to reference object in the file
  8468. data.push(offsetSize);
  8469. // Add another offset after this one because we need a new offset
  8470. var relativeOffset = 1;
  8471. for (i = 0; i < count + 1; i++) {
  8472. if (offsetSize === 1) {
  8473. data.push(relativeOffset & 0xFF);
  8474. } else if (offsetSize === 2) {
  8475. data.push(relativeOffset >> 8 & 0xFF, relativeOffset & 0xFF);
  8476. } else if (offsetSize === 3) {
  8477. data.push(relativeOffset >> 16 & 0xFF, relativeOffset >> 8 & 0xFF, relativeOffset & 0xFF);
  8478. } else {
  8479. data.push(relativeOffset >>> 24 & 0xFF, relativeOffset >> 16 & 0xFF, relativeOffset >> 8 & 0xFF, relativeOffset & 0xFF);
  8480. }
  8481. if (objects[i]) {
  8482. relativeOffset += objects[i].length;
  8483. }
  8484. }
  8485. for (i = 0; i < count; i++) {
  8486. // Notify the tracker where the object will be offset in the data.
  8487. if (trackers[i]) {
  8488. trackers[i].offset(data.length);
  8489. }
  8490. for (var j = 0, jj = objects[i].length; j < jj; j++) {
  8491. data.push(objects[i][j]);
  8492. }
  8493. }
  8494. return data;
  8495. }
  8496. };
  8497. return CFFCompiler;
  8498. }();
  8499. exports.CFFStandardStrings = CFFStandardStrings;
  8500. exports.CFFParser = CFFParser;
  8501. exports.CFF = CFF;
  8502. exports.CFFHeader = CFFHeader;
  8503. exports.CFFStrings = CFFStrings;
  8504. exports.CFFIndex = CFFIndex;
  8505. exports.CFFCharset = CFFCharset;
  8506. exports.CFFTopDict = CFFTopDict;
  8507. exports.CFFPrivateDict = CFFPrivateDict;
  8508. exports.CFFCompiler = CFFCompiler;
  8509. }));
  8510. (function (root, factory) {
  8511. factory(root.pdfjsCoreChunkedStream = {}, root.pdfjsSharedUtil);
  8512. }(this, function (exports, sharedUtil) {
  8513. var MissingDataException = sharedUtil.MissingDataException;
  8514. var arrayByteLength = sharedUtil.arrayByteLength;
  8515. var arraysToBytes = sharedUtil.arraysToBytes;
  8516. var assert = sharedUtil.assert;
  8517. var createPromiseCapability = sharedUtil.createPromiseCapability;
  8518. var isInt = sharedUtil.isInt;
  8519. var isEmptyObj = sharedUtil.isEmptyObj;
  8520. var ChunkedStream = function ChunkedStreamClosure() {
  8521. function ChunkedStream(length, chunkSize, manager) {
  8522. this.bytes = new Uint8Array(length);
  8523. this.start = 0;
  8524. this.pos = 0;
  8525. this.end = length;
  8526. this.chunkSize = chunkSize;
  8527. this.loadedChunks = [];
  8528. this.numChunksLoaded = 0;
  8529. this.numChunks = Math.ceil(length / chunkSize);
  8530. this.manager = manager;
  8531. this.progressiveDataLength = 0;
  8532. this.lastSuccessfulEnsureByteChunk = -1;
  8533. }
  8534. // a single-entry cache
  8535. // required methods for a stream. if a particular stream does not
  8536. // implement these, an error should be thrown
  8537. ChunkedStream.prototype = {
  8538. getMissingChunks: function ChunkedStream_getMissingChunks() {
  8539. var chunks = [];
  8540. for (var chunk = 0, n = this.numChunks; chunk < n; ++chunk) {
  8541. if (!this.loadedChunks[chunk]) {
  8542. chunks.push(chunk);
  8543. }
  8544. }
  8545. return chunks;
  8546. },
  8547. getBaseStreams: function ChunkedStream_getBaseStreams() {
  8548. return [this];
  8549. },
  8550. allChunksLoaded: function ChunkedStream_allChunksLoaded() {
  8551. return this.numChunksLoaded === this.numChunks;
  8552. },
  8553. onReceiveData: function ChunkedStream_onReceiveData(begin, chunk) {
  8554. var end = begin + chunk.byteLength;
  8555. assert(begin % this.chunkSize === 0, 'Bad begin offset: ' + begin);
  8556. // Using this.length is inaccurate here since this.start can be moved
  8557. // See ChunkedStream.moveStart()
  8558. var length = this.bytes.length;
  8559. assert(end % this.chunkSize === 0 || end === length, 'Bad end offset: ' + end);
  8560. this.bytes.set(new Uint8Array(chunk), begin);
  8561. var chunkSize = this.chunkSize;
  8562. var beginChunk = Math.floor(begin / chunkSize);
  8563. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  8564. var curChunk;
  8565. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  8566. if (!this.loadedChunks[curChunk]) {
  8567. this.loadedChunks[curChunk] = true;
  8568. ++this.numChunksLoaded;
  8569. }
  8570. }
  8571. },
  8572. onReceiveProgressiveData: function ChunkedStream_onReceiveProgressiveData(data) {
  8573. var position = this.progressiveDataLength;
  8574. var beginChunk = Math.floor(position / this.chunkSize);
  8575. this.bytes.set(new Uint8Array(data), position);
  8576. position += data.byteLength;
  8577. this.progressiveDataLength = position;
  8578. var endChunk = position >= this.end ? this.numChunks : Math.floor(position / this.chunkSize);
  8579. var curChunk;
  8580. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  8581. if (!this.loadedChunks[curChunk]) {
  8582. this.loadedChunks[curChunk] = true;
  8583. ++this.numChunksLoaded;
  8584. }
  8585. }
  8586. },
  8587. ensureByte: function ChunkedStream_ensureByte(pos) {
  8588. var chunk = Math.floor(pos / this.chunkSize);
  8589. if (chunk === this.lastSuccessfulEnsureByteChunk) {
  8590. return;
  8591. }
  8592. if (!this.loadedChunks[chunk]) {
  8593. throw new MissingDataException(pos, pos + 1);
  8594. }
  8595. this.lastSuccessfulEnsureByteChunk = chunk;
  8596. },
  8597. ensureRange: function ChunkedStream_ensureRange(begin, end) {
  8598. if (begin >= end) {
  8599. return;
  8600. }
  8601. if (end <= this.progressiveDataLength) {
  8602. return;
  8603. }
  8604. var chunkSize = this.chunkSize;
  8605. var beginChunk = Math.floor(begin / chunkSize);
  8606. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  8607. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  8608. if (!this.loadedChunks[chunk]) {
  8609. throw new MissingDataException(begin, end);
  8610. }
  8611. }
  8612. },
  8613. nextEmptyChunk: function ChunkedStream_nextEmptyChunk(beginChunk) {
  8614. var chunk, numChunks = this.numChunks;
  8615. for (var i = 0; i < numChunks; ++i) {
  8616. chunk = (beginChunk + i) % numChunks;
  8617. // Wrap around to beginning
  8618. if (!this.loadedChunks[chunk]) {
  8619. return chunk;
  8620. }
  8621. }
  8622. return null;
  8623. },
  8624. hasChunk: function ChunkedStream_hasChunk(chunk) {
  8625. return !!this.loadedChunks[chunk];
  8626. },
  8627. get length() {
  8628. return this.end - this.start;
  8629. },
  8630. get isEmpty() {
  8631. return this.length === 0;
  8632. },
  8633. getByte: function ChunkedStream_getByte() {
  8634. var pos = this.pos;
  8635. if (pos >= this.end) {
  8636. return -1;
  8637. }
  8638. this.ensureByte(pos);
  8639. return this.bytes[this.pos++];
  8640. },
  8641. getUint16: function ChunkedStream_getUint16() {
  8642. var b0 = this.getByte();
  8643. var b1 = this.getByte();
  8644. if (b0 === -1 || b1 === -1) {
  8645. return -1;
  8646. }
  8647. return (b0 << 8) + b1;
  8648. },
  8649. getInt32: function ChunkedStream_getInt32() {
  8650. var b0 = this.getByte();
  8651. var b1 = this.getByte();
  8652. var b2 = this.getByte();
  8653. var b3 = this.getByte();
  8654. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  8655. },
  8656. // returns subarray of original buffer
  8657. // should only be read
  8658. getBytes: function ChunkedStream_getBytes(length) {
  8659. var bytes = this.bytes;
  8660. var pos = this.pos;
  8661. var strEnd = this.end;
  8662. if (!length) {
  8663. this.ensureRange(pos, strEnd);
  8664. return bytes.subarray(pos, strEnd);
  8665. }
  8666. var end = pos + length;
  8667. if (end > strEnd) {
  8668. end = strEnd;
  8669. }
  8670. this.ensureRange(pos, end);
  8671. this.pos = end;
  8672. return bytes.subarray(pos, end);
  8673. },
  8674. peekByte: function ChunkedStream_peekByte() {
  8675. var peekedByte = this.getByte();
  8676. this.pos--;
  8677. return peekedByte;
  8678. },
  8679. peekBytes: function ChunkedStream_peekBytes(length) {
  8680. var bytes = this.getBytes(length);
  8681. this.pos -= bytes.length;
  8682. return bytes;
  8683. },
  8684. getByteRange: function ChunkedStream_getBytes(begin, end) {
  8685. this.ensureRange(begin, end);
  8686. return this.bytes.subarray(begin, end);
  8687. },
  8688. skip: function ChunkedStream_skip(n) {
  8689. if (!n) {
  8690. n = 1;
  8691. }
  8692. this.pos += n;
  8693. },
  8694. reset: function ChunkedStream_reset() {
  8695. this.pos = this.start;
  8696. },
  8697. moveStart: function ChunkedStream_moveStart() {
  8698. this.start = this.pos;
  8699. },
  8700. makeSubStream: function ChunkedStream_makeSubStream(start, length, dict) {
  8701. this.ensureRange(start, start + length);
  8702. function ChunkedStreamSubstream() {
  8703. }
  8704. ChunkedStreamSubstream.prototype = Object.create(this);
  8705. ChunkedStreamSubstream.prototype.getMissingChunks = function () {
  8706. var chunkSize = this.chunkSize;
  8707. var beginChunk = Math.floor(this.start / chunkSize);
  8708. var endChunk = Math.floor((this.end - 1) / chunkSize) + 1;
  8709. var missingChunks = [];
  8710. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  8711. if (!this.loadedChunks[chunk]) {
  8712. missingChunks.push(chunk);
  8713. }
  8714. }
  8715. return missingChunks;
  8716. };
  8717. var subStream = new ChunkedStreamSubstream();
  8718. subStream.pos = subStream.start = start;
  8719. subStream.end = start + length || this.end;
  8720. subStream.dict = dict;
  8721. return subStream;
  8722. },
  8723. isStream: true
  8724. };
  8725. return ChunkedStream;
  8726. }();
  8727. var ChunkedStreamManager = function ChunkedStreamManagerClosure() {
  8728. function ChunkedStreamManager(pdfNetworkStream, args) {
  8729. var chunkSize = args.rangeChunkSize;
  8730. var length = args.length;
  8731. this.stream = new ChunkedStream(length, chunkSize, this);
  8732. this.length = length;
  8733. this.chunkSize = chunkSize;
  8734. this.pdfNetworkStream = pdfNetworkStream;
  8735. this.url = args.url;
  8736. this.disableAutoFetch = args.disableAutoFetch;
  8737. this.msgHandler = args.msgHandler;
  8738. this.currRequestId = 0;
  8739. this.chunksNeededByRequest = Object.create(null);
  8740. this.requestsByChunk = Object.create(null);
  8741. this.promisesByRequest = Object.create(null);
  8742. this.progressiveDataLength = 0;
  8743. this.aborted = false;
  8744. this._loadedStreamCapability = createPromiseCapability();
  8745. }
  8746. ChunkedStreamManager.prototype = {
  8747. onLoadedStream: function ChunkedStreamManager_getLoadedStream() {
  8748. return this._loadedStreamCapability.promise;
  8749. },
  8750. sendRequest: function ChunkedStreamManager_sendRequest(begin, end) {
  8751. var rangeReader = this.pdfNetworkStream.getRangeReader(begin, end);
  8752. if (!rangeReader.isStreamingSupported) {
  8753. rangeReader.onProgress = this.onProgress.bind(this);
  8754. }
  8755. var chunks = [], loaded = 0;
  8756. var manager = this;
  8757. var promise = new Promise(function (resolve, reject) {
  8758. var readChunk = function (chunk) {
  8759. try {
  8760. if (!chunk.done) {
  8761. var data = chunk.value;
  8762. chunks.push(data);
  8763. loaded += arrayByteLength(data);
  8764. if (rangeReader.isStreamingSupported) {
  8765. manager.onProgress({ loaded: loaded });
  8766. }
  8767. rangeReader.read().then(readChunk, reject);
  8768. return;
  8769. }
  8770. var chunkData = arraysToBytes(chunks);
  8771. chunks = null;
  8772. resolve(chunkData);
  8773. } catch (e) {
  8774. reject(e);
  8775. }
  8776. };
  8777. rangeReader.read().then(readChunk, reject);
  8778. });
  8779. promise.then(function (data) {
  8780. if (this.aborted) {
  8781. return;
  8782. }
  8783. // ignoring any data after abort
  8784. this.onReceiveData({
  8785. chunk: data,
  8786. begin: begin
  8787. });
  8788. }.bind(this));
  8789. },
  8790. // TODO check errors
  8791. // Get all the chunks that are not yet loaded and groups them into
  8792. // contiguous ranges to load in as few requests as possible
  8793. requestAllChunks: function ChunkedStreamManager_requestAllChunks() {
  8794. var missingChunks = this.stream.getMissingChunks();
  8795. this._requestChunks(missingChunks);
  8796. return this._loadedStreamCapability.promise;
  8797. },
  8798. _requestChunks: function ChunkedStreamManager_requestChunks(chunks) {
  8799. var requestId = this.currRequestId++;
  8800. var i, ii;
  8801. var chunksNeeded = Object.create(null);
  8802. this.chunksNeededByRequest[requestId] = chunksNeeded;
  8803. for (i = 0, ii = chunks.length; i < ii; i++) {
  8804. if (!this.stream.hasChunk(chunks[i])) {
  8805. chunksNeeded[chunks[i]] = true;
  8806. }
  8807. }
  8808. if (isEmptyObj(chunksNeeded)) {
  8809. return Promise.resolve();
  8810. }
  8811. var capability = createPromiseCapability();
  8812. this.promisesByRequest[requestId] = capability;
  8813. var chunksToRequest = [];
  8814. for (var chunk in chunksNeeded) {
  8815. chunk = chunk | 0;
  8816. if (!(chunk in this.requestsByChunk)) {
  8817. this.requestsByChunk[chunk] = [];
  8818. chunksToRequest.push(chunk);
  8819. }
  8820. this.requestsByChunk[chunk].push(requestId);
  8821. }
  8822. if (!chunksToRequest.length) {
  8823. return capability.promise;
  8824. }
  8825. var groupedChunksToRequest = this.groupChunks(chunksToRequest);
  8826. for (i = 0; i < groupedChunksToRequest.length; ++i) {
  8827. var groupedChunk = groupedChunksToRequest[i];
  8828. var begin = groupedChunk.beginChunk * this.chunkSize;
  8829. var end = Math.min(groupedChunk.endChunk * this.chunkSize, this.length);
  8830. this.sendRequest(begin, end);
  8831. }
  8832. return capability.promise;
  8833. },
  8834. getStream: function ChunkedStreamManager_getStream() {
  8835. return this.stream;
  8836. },
  8837. // Loads any chunks in the requested range that are not yet loaded
  8838. requestRange: function ChunkedStreamManager_requestRange(begin, end) {
  8839. end = Math.min(end, this.length);
  8840. var beginChunk = this.getBeginChunk(begin);
  8841. var endChunk = this.getEndChunk(end);
  8842. var chunks = [];
  8843. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  8844. chunks.push(chunk);
  8845. }
  8846. return this._requestChunks(chunks);
  8847. },
  8848. requestRanges: function ChunkedStreamManager_requestRanges(ranges) {
  8849. ranges = ranges || [];
  8850. var chunksToRequest = [];
  8851. for (var i = 0; i < ranges.length; i++) {
  8852. var beginChunk = this.getBeginChunk(ranges[i].begin);
  8853. var endChunk = this.getEndChunk(ranges[i].end);
  8854. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  8855. if (chunksToRequest.indexOf(chunk) < 0) {
  8856. chunksToRequest.push(chunk);
  8857. }
  8858. }
  8859. }
  8860. chunksToRequest.sort(function (a, b) {
  8861. return a - b;
  8862. });
  8863. return this._requestChunks(chunksToRequest);
  8864. },
  8865. // Groups a sorted array of chunks into as few contiguous larger
  8866. // chunks as possible
  8867. groupChunks: function ChunkedStreamManager_groupChunks(chunks) {
  8868. var groupedChunks = [];
  8869. var beginChunk = -1;
  8870. var prevChunk = -1;
  8871. for (var i = 0; i < chunks.length; ++i) {
  8872. var chunk = chunks[i];
  8873. if (beginChunk < 0) {
  8874. beginChunk = chunk;
  8875. }
  8876. if (prevChunk >= 0 && prevChunk + 1 !== chunk) {
  8877. groupedChunks.push({
  8878. beginChunk: beginChunk,
  8879. endChunk: prevChunk + 1
  8880. });
  8881. beginChunk = chunk;
  8882. }
  8883. if (i + 1 === chunks.length) {
  8884. groupedChunks.push({
  8885. beginChunk: beginChunk,
  8886. endChunk: chunk + 1
  8887. });
  8888. }
  8889. prevChunk = chunk;
  8890. }
  8891. return groupedChunks;
  8892. },
  8893. onProgress: function ChunkedStreamManager_onProgress(args) {
  8894. var bytesLoaded = this.stream.numChunksLoaded * this.chunkSize + args.loaded;
  8895. this.msgHandler.send('DocProgress', {
  8896. loaded: bytesLoaded,
  8897. total: this.length
  8898. });
  8899. },
  8900. onReceiveData: function ChunkedStreamManager_onReceiveData(args) {
  8901. var chunk = args.chunk;
  8902. var isProgressive = args.begin === undefined;
  8903. var begin = isProgressive ? this.progressiveDataLength : args.begin;
  8904. var end = begin + chunk.byteLength;
  8905. var beginChunk = Math.floor(begin / this.chunkSize);
  8906. var endChunk = end < this.length ? Math.floor(end / this.chunkSize) : Math.ceil(end / this.chunkSize);
  8907. if (isProgressive) {
  8908. this.stream.onReceiveProgressiveData(chunk);
  8909. this.progressiveDataLength = end;
  8910. } else {
  8911. this.stream.onReceiveData(begin, chunk);
  8912. }
  8913. if (this.stream.allChunksLoaded()) {
  8914. this._loadedStreamCapability.resolve(this.stream);
  8915. }
  8916. var loadedRequests = [];
  8917. var i, requestId;
  8918. for (chunk = beginChunk; chunk < endChunk; ++chunk) {
  8919. // The server might return more chunks than requested
  8920. var requestIds = this.requestsByChunk[chunk] || [];
  8921. delete this.requestsByChunk[chunk];
  8922. for (i = 0; i < requestIds.length; ++i) {
  8923. requestId = requestIds[i];
  8924. var chunksNeeded = this.chunksNeededByRequest[requestId];
  8925. if (chunk in chunksNeeded) {
  8926. delete chunksNeeded[chunk];
  8927. }
  8928. if (!isEmptyObj(chunksNeeded)) {
  8929. continue;
  8930. }
  8931. loadedRequests.push(requestId);
  8932. }
  8933. }
  8934. // If there are no pending requests, automatically fetch the next
  8935. // unfetched chunk of the PDF
  8936. if (!this.disableAutoFetch && isEmptyObj(this.requestsByChunk)) {
  8937. var nextEmptyChunk;
  8938. if (this.stream.numChunksLoaded === 1) {
  8939. // This is a special optimization so that after fetching the first
  8940. // chunk, rather than fetching the second chunk, we fetch the last
  8941. // chunk.
  8942. var lastChunk = this.stream.numChunks - 1;
  8943. if (!this.stream.hasChunk(lastChunk)) {
  8944. nextEmptyChunk = lastChunk;
  8945. }
  8946. } else {
  8947. nextEmptyChunk = this.stream.nextEmptyChunk(endChunk);
  8948. }
  8949. if (isInt(nextEmptyChunk)) {
  8950. this._requestChunks([nextEmptyChunk]);
  8951. }
  8952. }
  8953. for (i = 0; i < loadedRequests.length; ++i) {
  8954. requestId = loadedRequests[i];
  8955. var capability = this.promisesByRequest[requestId];
  8956. delete this.promisesByRequest[requestId];
  8957. capability.resolve();
  8958. }
  8959. this.msgHandler.send('DocProgress', {
  8960. loaded: this.stream.numChunksLoaded * this.chunkSize,
  8961. total: this.length
  8962. });
  8963. },
  8964. onError: function ChunkedStreamManager_onError(err) {
  8965. this._loadedStreamCapability.reject(err);
  8966. },
  8967. getBeginChunk: function ChunkedStreamManager_getBeginChunk(begin) {
  8968. var chunk = Math.floor(begin / this.chunkSize);
  8969. return chunk;
  8970. },
  8971. getEndChunk: function ChunkedStreamManager_getEndChunk(end) {
  8972. var chunk = Math.floor((end - 1) / this.chunkSize) + 1;
  8973. return chunk;
  8974. },
  8975. abort: function ChunkedStreamManager_abort() {
  8976. this.aborted = true;
  8977. if (this.pdfNetworkStream) {
  8978. this.pdfNetworkStream.cancelAllRequests('abort');
  8979. }
  8980. for (var requestId in this.promisesByRequest) {
  8981. var capability = this.promisesByRequest[requestId];
  8982. capability.reject(new Error('Request was aborted'));
  8983. }
  8984. }
  8985. };
  8986. return ChunkedStreamManager;
  8987. }();
  8988. exports.ChunkedStream = ChunkedStream;
  8989. exports.ChunkedStreamManager = ChunkedStreamManager;
  8990. }));
  8991. (function (root, factory) {
  8992. factory(root.pdfjsCoreGlyphList = {}, root.pdfjsSharedUtil);
  8993. }(this, function (exports, sharedUtil) {
  8994. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  8995. var getGlyphsUnicode = getLookupTableFactory(function (t) {
  8996. t['A'] = 0x0041;
  8997. t['AE'] = 0x00C6;
  8998. t['AEacute'] = 0x01FC;
  8999. t['AEmacron'] = 0x01E2;
  9000. t['AEsmall'] = 0xF7E6;
  9001. t['Aacute'] = 0x00C1;
  9002. t['Aacutesmall'] = 0xF7E1;
  9003. t['Abreve'] = 0x0102;
  9004. t['Abreveacute'] = 0x1EAE;
  9005. t['Abrevecyrillic'] = 0x04D0;
  9006. t['Abrevedotbelow'] = 0x1EB6;
  9007. t['Abrevegrave'] = 0x1EB0;
  9008. t['Abrevehookabove'] = 0x1EB2;
  9009. t['Abrevetilde'] = 0x1EB4;
  9010. t['Acaron'] = 0x01CD;
  9011. t['Acircle'] = 0x24B6;
  9012. t['Acircumflex'] = 0x00C2;
  9013. t['Acircumflexacute'] = 0x1EA4;
  9014. t['Acircumflexdotbelow'] = 0x1EAC;
  9015. t['Acircumflexgrave'] = 0x1EA6;
  9016. t['Acircumflexhookabove'] = 0x1EA8;
  9017. t['Acircumflexsmall'] = 0xF7E2;
  9018. t['Acircumflextilde'] = 0x1EAA;
  9019. t['Acute'] = 0xF6C9;
  9020. t['Acutesmall'] = 0xF7B4;
  9021. t['Acyrillic'] = 0x0410;
  9022. t['Adblgrave'] = 0x0200;
  9023. t['Adieresis'] = 0x00C4;
  9024. t['Adieresiscyrillic'] = 0x04D2;
  9025. t['Adieresismacron'] = 0x01DE;
  9026. t['Adieresissmall'] = 0xF7E4;
  9027. t['Adotbelow'] = 0x1EA0;
  9028. t['Adotmacron'] = 0x01E0;
  9029. t['Agrave'] = 0x00C0;
  9030. t['Agravesmall'] = 0xF7E0;
  9031. t['Ahookabove'] = 0x1EA2;
  9032. t['Aiecyrillic'] = 0x04D4;
  9033. t['Ainvertedbreve'] = 0x0202;
  9034. t['Alpha'] = 0x0391;
  9035. t['Alphatonos'] = 0x0386;
  9036. t['Amacron'] = 0x0100;
  9037. t['Amonospace'] = 0xFF21;
  9038. t['Aogonek'] = 0x0104;
  9039. t['Aring'] = 0x00C5;
  9040. t['Aringacute'] = 0x01FA;
  9041. t['Aringbelow'] = 0x1E00;
  9042. t['Aringsmall'] = 0xF7E5;
  9043. t['Asmall'] = 0xF761;
  9044. t['Atilde'] = 0x00C3;
  9045. t['Atildesmall'] = 0xF7E3;
  9046. t['Aybarmenian'] = 0x0531;
  9047. t['B'] = 0x0042;
  9048. t['Bcircle'] = 0x24B7;
  9049. t['Bdotaccent'] = 0x1E02;
  9050. t['Bdotbelow'] = 0x1E04;
  9051. t['Becyrillic'] = 0x0411;
  9052. t['Benarmenian'] = 0x0532;
  9053. t['Beta'] = 0x0392;
  9054. t['Bhook'] = 0x0181;
  9055. t['Blinebelow'] = 0x1E06;
  9056. t['Bmonospace'] = 0xFF22;
  9057. t['Brevesmall'] = 0xF6F4;
  9058. t['Bsmall'] = 0xF762;
  9059. t['Btopbar'] = 0x0182;
  9060. t['C'] = 0x0043;
  9061. t['Caarmenian'] = 0x053E;
  9062. t['Cacute'] = 0x0106;
  9063. t['Caron'] = 0xF6CA;
  9064. t['Caronsmall'] = 0xF6F5;
  9065. t['Ccaron'] = 0x010C;
  9066. t['Ccedilla'] = 0x00C7;
  9067. t['Ccedillaacute'] = 0x1E08;
  9068. t['Ccedillasmall'] = 0xF7E7;
  9069. t['Ccircle'] = 0x24B8;
  9070. t['Ccircumflex'] = 0x0108;
  9071. t['Cdot'] = 0x010A;
  9072. t['Cdotaccent'] = 0x010A;
  9073. t['Cedillasmall'] = 0xF7B8;
  9074. t['Chaarmenian'] = 0x0549;
  9075. t['Cheabkhasiancyrillic'] = 0x04BC;
  9076. t['Checyrillic'] = 0x0427;
  9077. t['Chedescenderabkhasiancyrillic'] = 0x04BE;
  9078. t['Chedescendercyrillic'] = 0x04B6;
  9079. t['Chedieresiscyrillic'] = 0x04F4;
  9080. t['Cheharmenian'] = 0x0543;
  9081. t['Chekhakassiancyrillic'] = 0x04CB;
  9082. t['Cheverticalstrokecyrillic'] = 0x04B8;
  9083. t['Chi'] = 0x03A7;
  9084. t['Chook'] = 0x0187;
  9085. t['Circumflexsmall'] = 0xF6F6;
  9086. t['Cmonospace'] = 0xFF23;
  9087. t['Coarmenian'] = 0x0551;
  9088. t['Csmall'] = 0xF763;
  9089. t['D'] = 0x0044;
  9090. t['DZ'] = 0x01F1;
  9091. t['DZcaron'] = 0x01C4;
  9092. t['Daarmenian'] = 0x0534;
  9093. t['Dafrican'] = 0x0189;
  9094. t['Dcaron'] = 0x010E;
  9095. t['Dcedilla'] = 0x1E10;
  9096. t['Dcircle'] = 0x24B9;
  9097. t['Dcircumflexbelow'] = 0x1E12;
  9098. t['Dcroat'] = 0x0110;
  9099. t['Ddotaccent'] = 0x1E0A;
  9100. t['Ddotbelow'] = 0x1E0C;
  9101. t['Decyrillic'] = 0x0414;
  9102. t['Deicoptic'] = 0x03EE;
  9103. t['Delta'] = 0x2206;
  9104. t['Deltagreek'] = 0x0394;
  9105. t['Dhook'] = 0x018A;
  9106. t['Dieresis'] = 0xF6CB;
  9107. t['DieresisAcute'] = 0xF6CC;
  9108. t['DieresisGrave'] = 0xF6CD;
  9109. t['Dieresissmall'] = 0xF7A8;
  9110. t['Digammagreek'] = 0x03DC;
  9111. t['Djecyrillic'] = 0x0402;
  9112. t['Dlinebelow'] = 0x1E0E;
  9113. t['Dmonospace'] = 0xFF24;
  9114. t['Dotaccentsmall'] = 0xF6F7;
  9115. t['Dslash'] = 0x0110;
  9116. t['Dsmall'] = 0xF764;
  9117. t['Dtopbar'] = 0x018B;
  9118. t['Dz'] = 0x01F2;
  9119. t['Dzcaron'] = 0x01C5;
  9120. t['Dzeabkhasiancyrillic'] = 0x04E0;
  9121. t['Dzecyrillic'] = 0x0405;
  9122. t['Dzhecyrillic'] = 0x040F;
  9123. t['E'] = 0x0045;
  9124. t['Eacute'] = 0x00C9;
  9125. t['Eacutesmall'] = 0xF7E9;
  9126. t['Ebreve'] = 0x0114;
  9127. t['Ecaron'] = 0x011A;
  9128. t['Ecedillabreve'] = 0x1E1C;
  9129. t['Echarmenian'] = 0x0535;
  9130. t['Ecircle'] = 0x24BA;
  9131. t['Ecircumflex'] = 0x00CA;
  9132. t['Ecircumflexacute'] = 0x1EBE;
  9133. t['Ecircumflexbelow'] = 0x1E18;
  9134. t['Ecircumflexdotbelow'] = 0x1EC6;
  9135. t['Ecircumflexgrave'] = 0x1EC0;
  9136. t['Ecircumflexhookabove'] = 0x1EC2;
  9137. t['Ecircumflexsmall'] = 0xF7EA;
  9138. t['Ecircumflextilde'] = 0x1EC4;
  9139. t['Ecyrillic'] = 0x0404;
  9140. t['Edblgrave'] = 0x0204;
  9141. t['Edieresis'] = 0x00CB;
  9142. t['Edieresissmall'] = 0xF7EB;
  9143. t['Edot'] = 0x0116;
  9144. t['Edotaccent'] = 0x0116;
  9145. t['Edotbelow'] = 0x1EB8;
  9146. t['Efcyrillic'] = 0x0424;
  9147. t['Egrave'] = 0x00C8;
  9148. t['Egravesmall'] = 0xF7E8;
  9149. t['Eharmenian'] = 0x0537;
  9150. t['Ehookabove'] = 0x1EBA;
  9151. t['Eightroman'] = 0x2167;
  9152. t['Einvertedbreve'] = 0x0206;
  9153. t['Eiotifiedcyrillic'] = 0x0464;
  9154. t['Elcyrillic'] = 0x041B;
  9155. t['Elevenroman'] = 0x216A;
  9156. t['Emacron'] = 0x0112;
  9157. t['Emacronacute'] = 0x1E16;
  9158. t['Emacrongrave'] = 0x1E14;
  9159. t['Emcyrillic'] = 0x041C;
  9160. t['Emonospace'] = 0xFF25;
  9161. t['Encyrillic'] = 0x041D;
  9162. t['Endescendercyrillic'] = 0x04A2;
  9163. t['Eng'] = 0x014A;
  9164. t['Enghecyrillic'] = 0x04A4;
  9165. t['Enhookcyrillic'] = 0x04C7;
  9166. t['Eogonek'] = 0x0118;
  9167. t['Eopen'] = 0x0190;
  9168. t['Epsilon'] = 0x0395;
  9169. t['Epsilontonos'] = 0x0388;
  9170. t['Ercyrillic'] = 0x0420;
  9171. t['Ereversed'] = 0x018E;
  9172. t['Ereversedcyrillic'] = 0x042D;
  9173. t['Escyrillic'] = 0x0421;
  9174. t['Esdescendercyrillic'] = 0x04AA;
  9175. t['Esh'] = 0x01A9;
  9176. t['Esmall'] = 0xF765;
  9177. t['Eta'] = 0x0397;
  9178. t['Etarmenian'] = 0x0538;
  9179. t['Etatonos'] = 0x0389;
  9180. t['Eth'] = 0x00D0;
  9181. t['Ethsmall'] = 0xF7F0;
  9182. t['Etilde'] = 0x1EBC;
  9183. t['Etildebelow'] = 0x1E1A;
  9184. t['Euro'] = 0x20AC;
  9185. t['Ezh'] = 0x01B7;
  9186. t['Ezhcaron'] = 0x01EE;
  9187. t['Ezhreversed'] = 0x01B8;
  9188. t['F'] = 0x0046;
  9189. t['Fcircle'] = 0x24BB;
  9190. t['Fdotaccent'] = 0x1E1E;
  9191. t['Feharmenian'] = 0x0556;
  9192. t['Feicoptic'] = 0x03E4;
  9193. t['Fhook'] = 0x0191;
  9194. t['Fitacyrillic'] = 0x0472;
  9195. t['Fiveroman'] = 0x2164;
  9196. t['Fmonospace'] = 0xFF26;
  9197. t['Fourroman'] = 0x2163;
  9198. t['Fsmall'] = 0xF766;
  9199. t['G'] = 0x0047;
  9200. t['GBsquare'] = 0x3387;
  9201. t['Gacute'] = 0x01F4;
  9202. t['Gamma'] = 0x0393;
  9203. t['Gammaafrican'] = 0x0194;
  9204. t['Gangiacoptic'] = 0x03EA;
  9205. t['Gbreve'] = 0x011E;
  9206. t['Gcaron'] = 0x01E6;
  9207. t['Gcedilla'] = 0x0122;
  9208. t['Gcircle'] = 0x24BC;
  9209. t['Gcircumflex'] = 0x011C;
  9210. t['Gcommaaccent'] = 0x0122;
  9211. t['Gdot'] = 0x0120;
  9212. t['Gdotaccent'] = 0x0120;
  9213. t['Gecyrillic'] = 0x0413;
  9214. t['Ghadarmenian'] = 0x0542;
  9215. t['Ghemiddlehookcyrillic'] = 0x0494;
  9216. t['Ghestrokecyrillic'] = 0x0492;
  9217. t['Gheupturncyrillic'] = 0x0490;
  9218. t['Ghook'] = 0x0193;
  9219. t['Gimarmenian'] = 0x0533;
  9220. t['Gjecyrillic'] = 0x0403;
  9221. t['Gmacron'] = 0x1E20;
  9222. t['Gmonospace'] = 0xFF27;
  9223. t['Grave'] = 0xF6CE;
  9224. t['Gravesmall'] = 0xF760;
  9225. t['Gsmall'] = 0xF767;
  9226. t['Gsmallhook'] = 0x029B;
  9227. t['Gstroke'] = 0x01E4;
  9228. t['H'] = 0x0048;
  9229. t['H18533'] = 0x25CF;
  9230. t['H18543'] = 0x25AA;
  9231. t['H18551'] = 0x25AB;
  9232. t['H22073'] = 0x25A1;
  9233. t['HPsquare'] = 0x33CB;
  9234. t['Haabkhasiancyrillic'] = 0x04A8;
  9235. t['Hadescendercyrillic'] = 0x04B2;
  9236. t['Hardsigncyrillic'] = 0x042A;
  9237. t['Hbar'] = 0x0126;
  9238. t['Hbrevebelow'] = 0x1E2A;
  9239. t['Hcedilla'] = 0x1E28;
  9240. t['Hcircle'] = 0x24BD;
  9241. t['Hcircumflex'] = 0x0124;
  9242. t['Hdieresis'] = 0x1E26;
  9243. t['Hdotaccent'] = 0x1E22;
  9244. t['Hdotbelow'] = 0x1E24;
  9245. t['Hmonospace'] = 0xFF28;
  9246. t['Hoarmenian'] = 0x0540;
  9247. t['Horicoptic'] = 0x03E8;
  9248. t['Hsmall'] = 0xF768;
  9249. t['Hungarumlaut'] = 0xF6CF;
  9250. t['Hungarumlautsmall'] = 0xF6F8;
  9251. t['Hzsquare'] = 0x3390;
  9252. t['I'] = 0x0049;
  9253. t['IAcyrillic'] = 0x042F;
  9254. t['IJ'] = 0x0132;
  9255. t['IUcyrillic'] = 0x042E;
  9256. t['Iacute'] = 0x00CD;
  9257. t['Iacutesmall'] = 0xF7ED;
  9258. t['Ibreve'] = 0x012C;
  9259. t['Icaron'] = 0x01CF;
  9260. t['Icircle'] = 0x24BE;
  9261. t['Icircumflex'] = 0x00CE;
  9262. t['Icircumflexsmall'] = 0xF7EE;
  9263. t['Icyrillic'] = 0x0406;
  9264. t['Idblgrave'] = 0x0208;
  9265. t['Idieresis'] = 0x00CF;
  9266. t['Idieresisacute'] = 0x1E2E;
  9267. t['Idieresiscyrillic'] = 0x04E4;
  9268. t['Idieresissmall'] = 0xF7EF;
  9269. t['Idot'] = 0x0130;
  9270. t['Idotaccent'] = 0x0130;
  9271. t['Idotbelow'] = 0x1ECA;
  9272. t['Iebrevecyrillic'] = 0x04D6;
  9273. t['Iecyrillic'] = 0x0415;
  9274. t['Ifraktur'] = 0x2111;
  9275. t['Igrave'] = 0x00CC;
  9276. t['Igravesmall'] = 0xF7EC;
  9277. t['Ihookabove'] = 0x1EC8;
  9278. t['Iicyrillic'] = 0x0418;
  9279. t['Iinvertedbreve'] = 0x020A;
  9280. t['Iishortcyrillic'] = 0x0419;
  9281. t['Imacron'] = 0x012A;
  9282. t['Imacroncyrillic'] = 0x04E2;
  9283. t['Imonospace'] = 0xFF29;
  9284. t['Iniarmenian'] = 0x053B;
  9285. t['Iocyrillic'] = 0x0401;
  9286. t['Iogonek'] = 0x012E;
  9287. t['Iota'] = 0x0399;
  9288. t['Iotaafrican'] = 0x0196;
  9289. t['Iotadieresis'] = 0x03AA;
  9290. t['Iotatonos'] = 0x038A;
  9291. t['Ismall'] = 0xF769;
  9292. t['Istroke'] = 0x0197;
  9293. t['Itilde'] = 0x0128;
  9294. t['Itildebelow'] = 0x1E2C;
  9295. t['Izhitsacyrillic'] = 0x0474;
  9296. t['Izhitsadblgravecyrillic'] = 0x0476;
  9297. t['J'] = 0x004A;
  9298. t['Jaarmenian'] = 0x0541;
  9299. t['Jcircle'] = 0x24BF;
  9300. t['Jcircumflex'] = 0x0134;
  9301. t['Jecyrillic'] = 0x0408;
  9302. t['Jheharmenian'] = 0x054B;
  9303. t['Jmonospace'] = 0xFF2A;
  9304. t['Jsmall'] = 0xF76A;
  9305. t['K'] = 0x004B;
  9306. t['KBsquare'] = 0x3385;
  9307. t['KKsquare'] = 0x33CD;
  9308. t['Kabashkircyrillic'] = 0x04A0;
  9309. t['Kacute'] = 0x1E30;
  9310. t['Kacyrillic'] = 0x041A;
  9311. t['Kadescendercyrillic'] = 0x049A;
  9312. t['Kahookcyrillic'] = 0x04C3;
  9313. t['Kappa'] = 0x039A;
  9314. t['Kastrokecyrillic'] = 0x049E;
  9315. t['Kaverticalstrokecyrillic'] = 0x049C;
  9316. t['Kcaron'] = 0x01E8;
  9317. t['Kcedilla'] = 0x0136;
  9318. t['Kcircle'] = 0x24C0;
  9319. t['Kcommaaccent'] = 0x0136;
  9320. t['Kdotbelow'] = 0x1E32;
  9321. t['Keharmenian'] = 0x0554;
  9322. t['Kenarmenian'] = 0x053F;
  9323. t['Khacyrillic'] = 0x0425;
  9324. t['Kheicoptic'] = 0x03E6;
  9325. t['Khook'] = 0x0198;
  9326. t['Kjecyrillic'] = 0x040C;
  9327. t['Klinebelow'] = 0x1E34;
  9328. t['Kmonospace'] = 0xFF2B;
  9329. t['Koppacyrillic'] = 0x0480;
  9330. t['Koppagreek'] = 0x03DE;
  9331. t['Ksicyrillic'] = 0x046E;
  9332. t['Ksmall'] = 0xF76B;
  9333. t['L'] = 0x004C;
  9334. t['LJ'] = 0x01C7;
  9335. t['LL'] = 0xF6BF;
  9336. t['Lacute'] = 0x0139;
  9337. t['Lambda'] = 0x039B;
  9338. t['Lcaron'] = 0x013D;
  9339. t['Lcedilla'] = 0x013B;
  9340. t['Lcircle'] = 0x24C1;
  9341. t['Lcircumflexbelow'] = 0x1E3C;
  9342. t['Lcommaaccent'] = 0x013B;
  9343. t['Ldot'] = 0x013F;
  9344. t['Ldotaccent'] = 0x013F;
  9345. t['Ldotbelow'] = 0x1E36;
  9346. t['Ldotbelowmacron'] = 0x1E38;
  9347. t['Liwnarmenian'] = 0x053C;
  9348. t['Lj'] = 0x01C8;
  9349. t['Ljecyrillic'] = 0x0409;
  9350. t['Llinebelow'] = 0x1E3A;
  9351. t['Lmonospace'] = 0xFF2C;
  9352. t['Lslash'] = 0x0141;
  9353. t['Lslashsmall'] = 0xF6F9;
  9354. t['Lsmall'] = 0xF76C;
  9355. t['M'] = 0x004D;
  9356. t['MBsquare'] = 0x3386;
  9357. t['Macron'] = 0xF6D0;
  9358. t['Macronsmall'] = 0xF7AF;
  9359. t['Macute'] = 0x1E3E;
  9360. t['Mcircle'] = 0x24C2;
  9361. t['Mdotaccent'] = 0x1E40;
  9362. t['Mdotbelow'] = 0x1E42;
  9363. t['Menarmenian'] = 0x0544;
  9364. t['Mmonospace'] = 0xFF2D;
  9365. t['Msmall'] = 0xF76D;
  9366. t['Mturned'] = 0x019C;
  9367. t['Mu'] = 0x039C;
  9368. t['N'] = 0x004E;
  9369. t['NJ'] = 0x01CA;
  9370. t['Nacute'] = 0x0143;
  9371. t['Ncaron'] = 0x0147;
  9372. t['Ncedilla'] = 0x0145;
  9373. t['Ncircle'] = 0x24C3;
  9374. t['Ncircumflexbelow'] = 0x1E4A;
  9375. t['Ncommaaccent'] = 0x0145;
  9376. t['Ndotaccent'] = 0x1E44;
  9377. t['Ndotbelow'] = 0x1E46;
  9378. t['Nhookleft'] = 0x019D;
  9379. t['Nineroman'] = 0x2168;
  9380. t['Nj'] = 0x01CB;
  9381. t['Njecyrillic'] = 0x040A;
  9382. t['Nlinebelow'] = 0x1E48;
  9383. t['Nmonospace'] = 0xFF2E;
  9384. t['Nowarmenian'] = 0x0546;
  9385. t['Nsmall'] = 0xF76E;
  9386. t['Ntilde'] = 0x00D1;
  9387. t['Ntildesmall'] = 0xF7F1;
  9388. t['Nu'] = 0x039D;
  9389. t['O'] = 0x004F;
  9390. t['OE'] = 0x0152;
  9391. t['OEsmall'] = 0xF6FA;
  9392. t['Oacute'] = 0x00D3;
  9393. t['Oacutesmall'] = 0xF7F3;
  9394. t['Obarredcyrillic'] = 0x04E8;
  9395. t['Obarreddieresiscyrillic'] = 0x04EA;
  9396. t['Obreve'] = 0x014E;
  9397. t['Ocaron'] = 0x01D1;
  9398. t['Ocenteredtilde'] = 0x019F;
  9399. t['Ocircle'] = 0x24C4;
  9400. t['Ocircumflex'] = 0x00D4;
  9401. t['Ocircumflexacute'] = 0x1ED0;
  9402. t['Ocircumflexdotbelow'] = 0x1ED8;
  9403. t['Ocircumflexgrave'] = 0x1ED2;
  9404. t['Ocircumflexhookabove'] = 0x1ED4;
  9405. t['Ocircumflexsmall'] = 0xF7F4;
  9406. t['Ocircumflextilde'] = 0x1ED6;
  9407. t['Ocyrillic'] = 0x041E;
  9408. t['Odblacute'] = 0x0150;
  9409. t['Odblgrave'] = 0x020C;
  9410. t['Odieresis'] = 0x00D6;
  9411. t['Odieresiscyrillic'] = 0x04E6;
  9412. t['Odieresissmall'] = 0xF7F6;
  9413. t['Odotbelow'] = 0x1ECC;
  9414. t['Ogoneksmall'] = 0xF6FB;
  9415. t['Ograve'] = 0x00D2;
  9416. t['Ogravesmall'] = 0xF7F2;
  9417. t['Oharmenian'] = 0x0555;
  9418. t['Ohm'] = 0x2126;
  9419. t['Ohookabove'] = 0x1ECE;
  9420. t['Ohorn'] = 0x01A0;
  9421. t['Ohornacute'] = 0x1EDA;
  9422. t['Ohorndotbelow'] = 0x1EE2;
  9423. t['Ohorngrave'] = 0x1EDC;
  9424. t['Ohornhookabove'] = 0x1EDE;
  9425. t['Ohorntilde'] = 0x1EE0;
  9426. t['Ohungarumlaut'] = 0x0150;
  9427. t['Oi'] = 0x01A2;
  9428. t['Oinvertedbreve'] = 0x020E;
  9429. t['Omacron'] = 0x014C;
  9430. t['Omacronacute'] = 0x1E52;
  9431. t['Omacrongrave'] = 0x1E50;
  9432. t['Omega'] = 0x2126;
  9433. t['Omegacyrillic'] = 0x0460;
  9434. t['Omegagreek'] = 0x03A9;
  9435. t['Omegaroundcyrillic'] = 0x047A;
  9436. t['Omegatitlocyrillic'] = 0x047C;
  9437. t['Omegatonos'] = 0x038F;
  9438. t['Omicron'] = 0x039F;
  9439. t['Omicrontonos'] = 0x038C;
  9440. t['Omonospace'] = 0xFF2F;
  9441. t['Oneroman'] = 0x2160;
  9442. t['Oogonek'] = 0x01EA;
  9443. t['Oogonekmacron'] = 0x01EC;
  9444. t['Oopen'] = 0x0186;
  9445. t['Oslash'] = 0x00D8;
  9446. t['Oslashacute'] = 0x01FE;
  9447. t['Oslashsmall'] = 0xF7F8;
  9448. t['Osmall'] = 0xF76F;
  9449. t['Ostrokeacute'] = 0x01FE;
  9450. t['Otcyrillic'] = 0x047E;
  9451. t['Otilde'] = 0x00D5;
  9452. t['Otildeacute'] = 0x1E4C;
  9453. t['Otildedieresis'] = 0x1E4E;
  9454. t['Otildesmall'] = 0xF7F5;
  9455. t['P'] = 0x0050;
  9456. t['Pacute'] = 0x1E54;
  9457. t['Pcircle'] = 0x24C5;
  9458. t['Pdotaccent'] = 0x1E56;
  9459. t['Pecyrillic'] = 0x041F;
  9460. t['Peharmenian'] = 0x054A;
  9461. t['Pemiddlehookcyrillic'] = 0x04A6;
  9462. t['Phi'] = 0x03A6;
  9463. t['Phook'] = 0x01A4;
  9464. t['Pi'] = 0x03A0;
  9465. t['Piwrarmenian'] = 0x0553;
  9466. t['Pmonospace'] = 0xFF30;
  9467. t['Psi'] = 0x03A8;
  9468. t['Psicyrillic'] = 0x0470;
  9469. t['Psmall'] = 0xF770;
  9470. t['Q'] = 0x0051;
  9471. t['Qcircle'] = 0x24C6;
  9472. t['Qmonospace'] = 0xFF31;
  9473. t['Qsmall'] = 0xF771;
  9474. t['R'] = 0x0052;
  9475. t['Raarmenian'] = 0x054C;
  9476. t['Racute'] = 0x0154;
  9477. t['Rcaron'] = 0x0158;
  9478. t['Rcedilla'] = 0x0156;
  9479. t['Rcircle'] = 0x24C7;
  9480. t['Rcommaaccent'] = 0x0156;
  9481. t['Rdblgrave'] = 0x0210;
  9482. t['Rdotaccent'] = 0x1E58;
  9483. t['Rdotbelow'] = 0x1E5A;
  9484. t['Rdotbelowmacron'] = 0x1E5C;
  9485. t['Reharmenian'] = 0x0550;
  9486. t['Rfraktur'] = 0x211C;
  9487. t['Rho'] = 0x03A1;
  9488. t['Ringsmall'] = 0xF6FC;
  9489. t['Rinvertedbreve'] = 0x0212;
  9490. t['Rlinebelow'] = 0x1E5E;
  9491. t['Rmonospace'] = 0xFF32;
  9492. t['Rsmall'] = 0xF772;
  9493. t['Rsmallinverted'] = 0x0281;
  9494. t['Rsmallinvertedsuperior'] = 0x02B6;
  9495. t['S'] = 0x0053;
  9496. t['SF010000'] = 0x250C;
  9497. t['SF020000'] = 0x2514;
  9498. t['SF030000'] = 0x2510;
  9499. t['SF040000'] = 0x2518;
  9500. t['SF050000'] = 0x253C;
  9501. t['SF060000'] = 0x252C;
  9502. t['SF070000'] = 0x2534;
  9503. t['SF080000'] = 0x251C;
  9504. t['SF090000'] = 0x2524;
  9505. t['SF100000'] = 0x2500;
  9506. t['SF110000'] = 0x2502;
  9507. t['SF190000'] = 0x2561;
  9508. t['SF200000'] = 0x2562;
  9509. t['SF210000'] = 0x2556;
  9510. t['SF220000'] = 0x2555;
  9511. t['SF230000'] = 0x2563;
  9512. t['SF240000'] = 0x2551;
  9513. t['SF250000'] = 0x2557;
  9514. t['SF260000'] = 0x255D;
  9515. t['SF270000'] = 0x255C;
  9516. t['SF280000'] = 0x255B;
  9517. t['SF360000'] = 0x255E;
  9518. t['SF370000'] = 0x255F;
  9519. t['SF380000'] = 0x255A;
  9520. t['SF390000'] = 0x2554;
  9521. t['SF400000'] = 0x2569;
  9522. t['SF410000'] = 0x2566;
  9523. t['SF420000'] = 0x2560;
  9524. t['SF430000'] = 0x2550;
  9525. t['SF440000'] = 0x256C;
  9526. t['SF450000'] = 0x2567;
  9527. t['SF460000'] = 0x2568;
  9528. t['SF470000'] = 0x2564;
  9529. t['SF480000'] = 0x2565;
  9530. t['SF490000'] = 0x2559;
  9531. t['SF500000'] = 0x2558;
  9532. t['SF510000'] = 0x2552;
  9533. t['SF520000'] = 0x2553;
  9534. t['SF530000'] = 0x256B;
  9535. t['SF540000'] = 0x256A;
  9536. t['Sacute'] = 0x015A;
  9537. t['Sacutedotaccent'] = 0x1E64;
  9538. t['Sampigreek'] = 0x03E0;
  9539. t['Scaron'] = 0x0160;
  9540. t['Scarondotaccent'] = 0x1E66;
  9541. t['Scaronsmall'] = 0xF6FD;
  9542. t['Scedilla'] = 0x015E;
  9543. t['Schwa'] = 0x018F;
  9544. t['Schwacyrillic'] = 0x04D8;
  9545. t['Schwadieresiscyrillic'] = 0x04DA;
  9546. t['Scircle'] = 0x24C8;
  9547. t['Scircumflex'] = 0x015C;
  9548. t['Scommaaccent'] = 0x0218;
  9549. t['Sdotaccent'] = 0x1E60;
  9550. t['Sdotbelow'] = 0x1E62;
  9551. t['Sdotbelowdotaccent'] = 0x1E68;
  9552. t['Seharmenian'] = 0x054D;
  9553. t['Sevenroman'] = 0x2166;
  9554. t['Shaarmenian'] = 0x0547;
  9555. t['Shacyrillic'] = 0x0428;
  9556. t['Shchacyrillic'] = 0x0429;
  9557. t['Sheicoptic'] = 0x03E2;
  9558. t['Shhacyrillic'] = 0x04BA;
  9559. t['Shimacoptic'] = 0x03EC;
  9560. t['Sigma'] = 0x03A3;
  9561. t['Sixroman'] = 0x2165;
  9562. t['Smonospace'] = 0xFF33;
  9563. t['Softsigncyrillic'] = 0x042C;
  9564. t['Ssmall'] = 0xF773;
  9565. t['Stigmagreek'] = 0x03DA;
  9566. t['T'] = 0x0054;
  9567. t['Tau'] = 0x03A4;
  9568. t['Tbar'] = 0x0166;
  9569. t['Tcaron'] = 0x0164;
  9570. t['Tcedilla'] = 0x0162;
  9571. t['Tcircle'] = 0x24C9;
  9572. t['Tcircumflexbelow'] = 0x1E70;
  9573. t['Tcommaaccent'] = 0x0162;
  9574. t['Tdotaccent'] = 0x1E6A;
  9575. t['Tdotbelow'] = 0x1E6C;
  9576. t['Tecyrillic'] = 0x0422;
  9577. t['Tedescendercyrillic'] = 0x04AC;
  9578. t['Tenroman'] = 0x2169;
  9579. t['Tetsecyrillic'] = 0x04B4;
  9580. t['Theta'] = 0x0398;
  9581. t['Thook'] = 0x01AC;
  9582. t['Thorn'] = 0x00DE;
  9583. t['Thornsmall'] = 0xF7FE;
  9584. t['Threeroman'] = 0x2162;
  9585. t['Tildesmall'] = 0xF6FE;
  9586. t['Tiwnarmenian'] = 0x054F;
  9587. t['Tlinebelow'] = 0x1E6E;
  9588. t['Tmonospace'] = 0xFF34;
  9589. t['Toarmenian'] = 0x0539;
  9590. t['Tonefive'] = 0x01BC;
  9591. t['Tonesix'] = 0x0184;
  9592. t['Tonetwo'] = 0x01A7;
  9593. t['Tretroflexhook'] = 0x01AE;
  9594. t['Tsecyrillic'] = 0x0426;
  9595. t['Tshecyrillic'] = 0x040B;
  9596. t['Tsmall'] = 0xF774;
  9597. t['Twelveroman'] = 0x216B;
  9598. t['Tworoman'] = 0x2161;
  9599. t['U'] = 0x0055;
  9600. t['Uacute'] = 0x00DA;
  9601. t['Uacutesmall'] = 0xF7FA;
  9602. t['Ubreve'] = 0x016C;
  9603. t['Ucaron'] = 0x01D3;
  9604. t['Ucircle'] = 0x24CA;
  9605. t['Ucircumflex'] = 0x00DB;
  9606. t['Ucircumflexbelow'] = 0x1E76;
  9607. t['Ucircumflexsmall'] = 0xF7FB;
  9608. t['Ucyrillic'] = 0x0423;
  9609. t['Udblacute'] = 0x0170;
  9610. t['Udblgrave'] = 0x0214;
  9611. t['Udieresis'] = 0x00DC;
  9612. t['Udieresisacute'] = 0x01D7;
  9613. t['Udieresisbelow'] = 0x1E72;
  9614. t['Udieresiscaron'] = 0x01D9;
  9615. t['Udieresiscyrillic'] = 0x04F0;
  9616. t['Udieresisgrave'] = 0x01DB;
  9617. t['Udieresismacron'] = 0x01D5;
  9618. t['Udieresissmall'] = 0xF7FC;
  9619. t['Udotbelow'] = 0x1EE4;
  9620. t['Ugrave'] = 0x00D9;
  9621. t['Ugravesmall'] = 0xF7F9;
  9622. t['Uhookabove'] = 0x1EE6;
  9623. t['Uhorn'] = 0x01AF;
  9624. t['Uhornacute'] = 0x1EE8;
  9625. t['Uhorndotbelow'] = 0x1EF0;
  9626. t['Uhorngrave'] = 0x1EEA;
  9627. t['Uhornhookabove'] = 0x1EEC;
  9628. t['Uhorntilde'] = 0x1EEE;
  9629. t['Uhungarumlaut'] = 0x0170;
  9630. t['Uhungarumlautcyrillic'] = 0x04F2;
  9631. t['Uinvertedbreve'] = 0x0216;
  9632. t['Ukcyrillic'] = 0x0478;
  9633. t['Umacron'] = 0x016A;
  9634. t['Umacroncyrillic'] = 0x04EE;
  9635. t['Umacrondieresis'] = 0x1E7A;
  9636. t['Umonospace'] = 0xFF35;
  9637. t['Uogonek'] = 0x0172;
  9638. t['Upsilon'] = 0x03A5;
  9639. t['Upsilon1'] = 0x03D2;
  9640. t['Upsilonacutehooksymbolgreek'] = 0x03D3;
  9641. t['Upsilonafrican'] = 0x01B1;
  9642. t['Upsilondieresis'] = 0x03AB;
  9643. t['Upsilondieresishooksymbolgreek'] = 0x03D4;
  9644. t['Upsilonhooksymbol'] = 0x03D2;
  9645. t['Upsilontonos'] = 0x038E;
  9646. t['Uring'] = 0x016E;
  9647. t['Ushortcyrillic'] = 0x040E;
  9648. t['Usmall'] = 0xF775;
  9649. t['Ustraightcyrillic'] = 0x04AE;
  9650. t['Ustraightstrokecyrillic'] = 0x04B0;
  9651. t['Utilde'] = 0x0168;
  9652. t['Utildeacute'] = 0x1E78;
  9653. t['Utildebelow'] = 0x1E74;
  9654. t['V'] = 0x0056;
  9655. t['Vcircle'] = 0x24CB;
  9656. t['Vdotbelow'] = 0x1E7E;
  9657. t['Vecyrillic'] = 0x0412;
  9658. t['Vewarmenian'] = 0x054E;
  9659. t['Vhook'] = 0x01B2;
  9660. t['Vmonospace'] = 0xFF36;
  9661. t['Voarmenian'] = 0x0548;
  9662. t['Vsmall'] = 0xF776;
  9663. t['Vtilde'] = 0x1E7C;
  9664. t['W'] = 0x0057;
  9665. t['Wacute'] = 0x1E82;
  9666. t['Wcircle'] = 0x24CC;
  9667. t['Wcircumflex'] = 0x0174;
  9668. t['Wdieresis'] = 0x1E84;
  9669. t['Wdotaccent'] = 0x1E86;
  9670. t['Wdotbelow'] = 0x1E88;
  9671. t['Wgrave'] = 0x1E80;
  9672. t['Wmonospace'] = 0xFF37;
  9673. t['Wsmall'] = 0xF777;
  9674. t['X'] = 0x0058;
  9675. t['Xcircle'] = 0x24CD;
  9676. t['Xdieresis'] = 0x1E8C;
  9677. t['Xdotaccent'] = 0x1E8A;
  9678. t['Xeharmenian'] = 0x053D;
  9679. t['Xi'] = 0x039E;
  9680. t['Xmonospace'] = 0xFF38;
  9681. t['Xsmall'] = 0xF778;
  9682. t['Y'] = 0x0059;
  9683. t['Yacute'] = 0x00DD;
  9684. t['Yacutesmall'] = 0xF7FD;
  9685. t['Yatcyrillic'] = 0x0462;
  9686. t['Ycircle'] = 0x24CE;
  9687. t['Ycircumflex'] = 0x0176;
  9688. t['Ydieresis'] = 0x0178;
  9689. t['Ydieresissmall'] = 0xF7FF;
  9690. t['Ydotaccent'] = 0x1E8E;
  9691. t['Ydotbelow'] = 0x1EF4;
  9692. t['Yericyrillic'] = 0x042B;
  9693. t['Yerudieresiscyrillic'] = 0x04F8;
  9694. t['Ygrave'] = 0x1EF2;
  9695. t['Yhook'] = 0x01B3;
  9696. t['Yhookabove'] = 0x1EF6;
  9697. t['Yiarmenian'] = 0x0545;
  9698. t['Yicyrillic'] = 0x0407;
  9699. t['Yiwnarmenian'] = 0x0552;
  9700. t['Ymonospace'] = 0xFF39;
  9701. t['Ysmall'] = 0xF779;
  9702. t['Ytilde'] = 0x1EF8;
  9703. t['Yusbigcyrillic'] = 0x046A;
  9704. t['Yusbigiotifiedcyrillic'] = 0x046C;
  9705. t['Yuslittlecyrillic'] = 0x0466;
  9706. t['Yuslittleiotifiedcyrillic'] = 0x0468;
  9707. t['Z'] = 0x005A;
  9708. t['Zaarmenian'] = 0x0536;
  9709. t['Zacute'] = 0x0179;
  9710. t['Zcaron'] = 0x017D;
  9711. t['Zcaronsmall'] = 0xF6FF;
  9712. t['Zcircle'] = 0x24CF;
  9713. t['Zcircumflex'] = 0x1E90;
  9714. t['Zdot'] = 0x017B;
  9715. t['Zdotaccent'] = 0x017B;
  9716. t['Zdotbelow'] = 0x1E92;
  9717. t['Zecyrillic'] = 0x0417;
  9718. t['Zedescendercyrillic'] = 0x0498;
  9719. t['Zedieresiscyrillic'] = 0x04DE;
  9720. t['Zeta'] = 0x0396;
  9721. t['Zhearmenian'] = 0x053A;
  9722. t['Zhebrevecyrillic'] = 0x04C1;
  9723. t['Zhecyrillic'] = 0x0416;
  9724. t['Zhedescendercyrillic'] = 0x0496;
  9725. t['Zhedieresiscyrillic'] = 0x04DC;
  9726. t['Zlinebelow'] = 0x1E94;
  9727. t['Zmonospace'] = 0xFF3A;
  9728. t['Zsmall'] = 0xF77A;
  9729. t['Zstroke'] = 0x01B5;
  9730. t['a'] = 0x0061;
  9731. t['aabengali'] = 0x0986;
  9732. t['aacute'] = 0x00E1;
  9733. t['aadeva'] = 0x0906;
  9734. t['aagujarati'] = 0x0A86;
  9735. t['aagurmukhi'] = 0x0A06;
  9736. t['aamatragurmukhi'] = 0x0A3E;
  9737. t['aarusquare'] = 0x3303;
  9738. t['aavowelsignbengali'] = 0x09BE;
  9739. t['aavowelsigndeva'] = 0x093E;
  9740. t['aavowelsigngujarati'] = 0x0ABE;
  9741. t['abbreviationmarkarmenian'] = 0x055F;
  9742. t['abbreviationsigndeva'] = 0x0970;
  9743. t['abengali'] = 0x0985;
  9744. t['abopomofo'] = 0x311A;
  9745. t['abreve'] = 0x0103;
  9746. t['abreveacute'] = 0x1EAF;
  9747. t['abrevecyrillic'] = 0x04D1;
  9748. t['abrevedotbelow'] = 0x1EB7;
  9749. t['abrevegrave'] = 0x1EB1;
  9750. t['abrevehookabove'] = 0x1EB3;
  9751. t['abrevetilde'] = 0x1EB5;
  9752. t['acaron'] = 0x01CE;
  9753. t['acircle'] = 0x24D0;
  9754. t['acircumflex'] = 0x00E2;
  9755. t['acircumflexacute'] = 0x1EA5;
  9756. t['acircumflexdotbelow'] = 0x1EAD;
  9757. t['acircumflexgrave'] = 0x1EA7;
  9758. t['acircumflexhookabove'] = 0x1EA9;
  9759. t['acircumflextilde'] = 0x1EAB;
  9760. t['acute'] = 0x00B4;
  9761. t['acutebelowcmb'] = 0x0317;
  9762. t['acutecmb'] = 0x0301;
  9763. t['acutecomb'] = 0x0301;
  9764. t['acutedeva'] = 0x0954;
  9765. t['acutelowmod'] = 0x02CF;
  9766. t['acutetonecmb'] = 0x0341;
  9767. t['acyrillic'] = 0x0430;
  9768. t['adblgrave'] = 0x0201;
  9769. t['addakgurmukhi'] = 0x0A71;
  9770. t['adeva'] = 0x0905;
  9771. t['adieresis'] = 0x00E4;
  9772. t['adieresiscyrillic'] = 0x04D3;
  9773. t['adieresismacron'] = 0x01DF;
  9774. t['adotbelow'] = 0x1EA1;
  9775. t['adotmacron'] = 0x01E1;
  9776. t['ae'] = 0x00E6;
  9777. t['aeacute'] = 0x01FD;
  9778. t['aekorean'] = 0x3150;
  9779. t['aemacron'] = 0x01E3;
  9780. t['afii00208'] = 0x2015;
  9781. t['afii08941'] = 0x20A4;
  9782. t['afii10017'] = 0x0410;
  9783. t['afii10018'] = 0x0411;
  9784. t['afii10019'] = 0x0412;
  9785. t['afii10020'] = 0x0413;
  9786. t['afii10021'] = 0x0414;
  9787. t['afii10022'] = 0x0415;
  9788. t['afii10023'] = 0x0401;
  9789. t['afii10024'] = 0x0416;
  9790. t['afii10025'] = 0x0417;
  9791. t['afii10026'] = 0x0418;
  9792. t['afii10027'] = 0x0419;
  9793. t['afii10028'] = 0x041A;
  9794. t['afii10029'] = 0x041B;
  9795. t['afii10030'] = 0x041C;
  9796. t['afii10031'] = 0x041D;
  9797. t['afii10032'] = 0x041E;
  9798. t['afii10033'] = 0x041F;
  9799. t['afii10034'] = 0x0420;
  9800. t['afii10035'] = 0x0421;
  9801. t['afii10036'] = 0x0422;
  9802. t['afii10037'] = 0x0423;
  9803. t['afii10038'] = 0x0424;
  9804. t['afii10039'] = 0x0425;
  9805. t['afii10040'] = 0x0426;
  9806. t['afii10041'] = 0x0427;
  9807. t['afii10042'] = 0x0428;
  9808. t['afii10043'] = 0x0429;
  9809. t['afii10044'] = 0x042A;
  9810. t['afii10045'] = 0x042B;
  9811. t['afii10046'] = 0x042C;
  9812. t['afii10047'] = 0x042D;
  9813. t['afii10048'] = 0x042E;
  9814. t['afii10049'] = 0x042F;
  9815. t['afii10050'] = 0x0490;
  9816. t['afii10051'] = 0x0402;
  9817. t['afii10052'] = 0x0403;
  9818. t['afii10053'] = 0x0404;
  9819. t['afii10054'] = 0x0405;
  9820. t['afii10055'] = 0x0406;
  9821. t['afii10056'] = 0x0407;
  9822. t['afii10057'] = 0x0408;
  9823. t['afii10058'] = 0x0409;
  9824. t['afii10059'] = 0x040A;
  9825. t['afii10060'] = 0x040B;
  9826. t['afii10061'] = 0x040C;
  9827. t['afii10062'] = 0x040E;
  9828. t['afii10063'] = 0xF6C4;
  9829. t['afii10064'] = 0xF6C5;
  9830. t['afii10065'] = 0x0430;
  9831. t['afii10066'] = 0x0431;
  9832. t['afii10067'] = 0x0432;
  9833. t['afii10068'] = 0x0433;
  9834. t['afii10069'] = 0x0434;
  9835. t['afii10070'] = 0x0435;
  9836. t['afii10071'] = 0x0451;
  9837. t['afii10072'] = 0x0436;
  9838. t['afii10073'] = 0x0437;
  9839. t['afii10074'] = 0x0438;
  9840. t['afii10075'] = 0x0439;
  9841. t['afii10076'] = 0x043A;
  9842. t['afii10077'] = 0x043B;
  9843. t['afii10078'] = 0x043C;
  9844. t['afii10079'] = 0x043D;
  9845. t['afii10080'] = 0x043E;
  9846. t['afii10081'] = 0x043F;
  9847. t['afii10082'] = 0x0440;
  9848. t['afii10083'] = 0x0441;
  9849. t['afii10084'] = 0x0442;
  9850. t['afii10085'] = 0x0443;
  9851. t['afii10086'] = 0x0444;
  9852. t['afii10087'] = 0x0445;
  9853. t['afii10088'] = 0x0446;
  9854. t['afii10089'] = 0x0447;
  9855. t['afii10090'] = 0x0448;
  9856. t['afii10091'] = 0x0449;
  9857. t['afii10092'] = 0x044A;
  9858. t['afii10093'] = 0x044B;
  9859. t['afii10094'] = 0x044C;
  9860. t['afii10095'] = 0x044D;
  9861. t['afii10096'] = 0x044E;
  9862. t['afii10097'] = 0x044F;
  9863. t['afii10098'] = 0x0491;
  9864. t['afii10099'] = 0x0452;
  9865. t['afii10100'] = 0x0453;
  9866. t['afii10101'] = 0x0454;
  9867. t['afii10102'] = 0x0455;
  9868. t['afii10103'] = 0x0456;
  9869. t['afii10104'] = 0x0457;
  9870. t['afii10105'] = 0x0458;
  9871. t['afii10106'] = 0x0459;
  9872. t['afii10107'] = 0x045A;
  9873. t['afii10108'] = 0x045B;
  9874. t['afii10109'] = 0x045C;
  9875. t['afii10110'] = 0x045E;
  9876. t['afii10145'] = 0x040F;
  9877. t['afii10146'] = 0x0462;
  9878. t['afii10147'] = 0x0472;
  9879. t['afii10148'] = 0x0474;
  9880. t['afii10192'] = 0xF6C6;
  9881. t['afii10193'] = 0x045F;
  9882. t['afii10194'] = 0x0463;
  9883. t['afii10195'] = 0x0473;
  9884. t['afii10196'] = 0x0475;
  9885. t['afii10831'] = 0xF6C7;
  9886. t['afii10832'] = 0xF6C8;
  9887. t['afii10846'] = 0x04D9;
  9888. t['afii299'] = 0x200E;
  9889. t['afii300'] = 0x200F;
  9890. t['afii301'] = 0x200D;
  9891. t['afii57381'] = 0x066A;
  9892. t['afii57388'] = 0x060C;
  9893. t['afii57392'] = 0x0660;
  9894. t['afii57393'] = 0x0661;
  9895. t['afii57394'] = 0x0662;
  9896. t['afii57395'] = 0x0663;
  9897. t['afii57396'] = 0x0664;
  9898. t['afii57397'] = 0x0665;
  9899. t['afii57398'] = 0x0666;
  9900. t['afii57399'] = 0x0667;
  9901. t['afii57400'] = 0x0668;
  9902. t['afii57401'] = 0x0669;
  9903. t['afii57403'] = 0x061B;
  9904. t['afii57407'] = 0x061F;
  9905. t['afii57409'] = 0x0621;
  9906. t['afii57410'] = 0x0622;
  9907. t['afii57411'] = 0x0623;
  9908. t['afii57412'] = 0x0624;
  9909. t['afii57413'] = 0x0625;
  9910. t['afii57414'] = 0x0626;
  9911. t['afii57415'] = 0x0627;
  9912. t['afii57416'] = 0x0628;
  9913. t['afii57417'] = 0x0629;
  9914. t['afii57418'] = 0x062A;
  9915. t['afii57419'] = 0x062B;
  9916. t['afii57420'] = 0x062C;
  9917. t['afii57421'] = 0x062D;
  9918. t['afii57422'] = 0x062E;
  9919. t['afii57423'] = 0x062F;
  9920. t['afii57424'] = 0x0630;
  9921. t['afii57425'] = 0x0631;
  9922. t['afii57426'] = 0x0632;
  9923. t['afii57427'] = 0x0633;
  9924. t['afii57428'] = 0x0634;
  9925. t['afii57429'] = 0x0635;
  9926. t['afii57430'] = 0x0636;
  9927. t['afii57431'] = 0x0637;
  9928. t['afii57432'] = 0x0638;
  9929. t['afii57433'] = 0x0639;
  9930. t['afii57434'] = 0x063A;
  9931. t['afii57440'] = 0x0640;
  9932. t['afii57441'] = 0x0641;
  9933. t['afii57442'] = 0x0642;
  9934. t['afii57443'] = 0x0643;
  9935. t['afii57444'] = 0x0644;
  9936. t['afii57445'] = 0x0645;
  9937. t['afii57446'] = 0x0646;
  9938. t['afii57448'] = 0x0648;
  9939. t['afii57449'] = 0x0649;
  9940. t['afii57450'] = 0x064A;
  9941. t['afii57451'] = 0x064B;
  9942. t['afii57452'] = 0x064C;
  9943. t['afii57453'] = 0x064D;
  9944. t['afii57454'] = 0x064E;
  9945. t['afii57455'] = 0x064F;
  9946. t['afii57456'] = 0x0650;
  9947. t['afii57457'] = 0x0651;
  9948. t['afii57458'] = 0x0652;
  9949. t['afii57470'] = 0x0647;
  9950. t['afii57505'] = 0x06A4;
  9951. t['afii57506'] = 0x067E;
  9952. t['afii57507'] = 0x0686;
  9953. t['afii57508'] = 0x0698;
  9954. t['afii57509'] = 0x06AF;
  9955. t['afii57511'] = 0x0679;
  9956. t['afii57512'] = 0x0688;
  9957. t['afii57513'] = 0x0691;
  9958. t['afii57514'] = 0x06BA;
  9959. t['afii57519'] = 0x06D2;
  9960. t['afii57534'] = 0x06D5;
  9961. t['afii57636'] = 0x20AA;
  9962. t['afii57645'] = 0x05BE;
  9963. t['afii57658'] = 0x05C3;
  9964. t['afii57664'] = 0x05D0;
  9965. t['afii57665'] = 0x05D1;
  9966. t['afii57666'] = 0x05D2;
  9967. t['afii57667'] = 0x05D3;
  9968. t['afii57668'] = 0x05D4;
  9969. t['afii57669'] = 0x05D5;
  9970. t['afii57670'] = 0x05D6;
  9971. t['afii57671'] = 0x05D7;
  9972. t['afii57672'] = 0x05D8;
  9973. t['afii57673'] = 0x05D9;
  9974. t['afii57674'] = 0x05DA;
  9975. t['afii57675'] = 0x05DB;
  9976. t['afii57676'] = 0x05DC;
  9977. t['afii57677'] = 0x05DD;
  9978. t['afii57678'] = 0x05DE;
  9979. t['afii57679'] = 0x05DF;
  9980. t['afii57680'] = 0x05E0;
  9981. t['afii57681'] = 0x05E1;
  9982. t['afii57682'] = 0x05E2;
  9983. t['afii57683'] = 0x05E3;
  9984. t['afii57684'] = 0x05E4;
  9985. t['afii57685'] = 0x05E5;
  9986. t['afii57686'] = 0x05E6;
  9987. t['afii57687'] = 0x05E7;
  9988. t['afii57688'] = 0x05E8;
  9989. t['afii57689'] = 0x05E9;
  9990. t['afii57690'] = 0x05EA;
  9991. t['afii57694'] = 0xFB2A;
  9992. t['afii57695'] = 0xFB2B;
  9993. t['afii57700'] = 0xFB4B;
  9994. t['afii57705'] = 0xFB1F;
  9995. t['afii57716'] = 0x05F0;
  9996. t['afii57717'] = 0x05F1;
  9997. t['afii57718'] = 0x05F2;
  9998. t['afii57723'] = 0xFB35;
  9999. t['afii57793'] = 0x05B4;
  10000. t['afii57794'] = 0x05B5;
  10001. t['afii57795'] = 0x05B6;
  10002. t['afii57796'] = 0x05BB;
  10003. t['afii57797'] = 0x05B8;
  10004. t['afii57798'] = 0x05B7;
  10005. t['afii57799'] = 0x05B0;
  10006. t['afii57800'] = 0x05B2;
  10007. t['afii57801'] = 0x05B1;
  10008. t['afii57802'] = 0x05B3;
  10009. t['afii57803'] = 0x05C2;
  10010. t['afii57804'] = 0x05C1;
  10011. t['afii57806'] = 0x05B9;
  10012. t['afii57807'] = 0x05BC;
  10013. t['afii57839'] = 0x05BD;
  10014. t['afii57841'] = 0x05BF;
  10015. t['afii57842'] = 0x05C0;
  10016. t['afii57929'] = 0x02BC;
  10017. t['afii61248'] = 0x2105;
  10018. t['afii61289'] = 0x2113;
  10019. t['afii61352'] = 0x2116;
  10020. t['afii61573'] = 0x202C;
  10021. t['afii61574'] = 0x202D;
  10022. t['afii61575'] = 0x202E;
  10023. t['afii61664'] = 0x200C;
  10024. t['afii63167'] = 0x066D;
  10025. t['afii64937'] = 0x02BD;
  10026. t['agrave'] = 0x00E0;
  10027. t['agujarati'] = 0x0A85;
  10028. t['agurmukhi'] = 0x0A05;
  10029. t['ahiragana'] = 0x3042;
  10030. t['ahookabove'] = 0x1EA3;
  10031. t['aibengali'] = 0x0990;
  10032. t['aibopomofo'] = 0x311E;
  10033. t['aideva'] = 0x0910;
  10034. t['aiecyrillic'] = 0x04D5;
  10035. t['aigujarati'] = 0x0A90;
  10036. t['aigurmukhi'] = 0x0A10;
  10037. t['aimatragurmukhi'] = 0x0A48;
  10038. t['ainarabic'] = 0x0639;
  10039. t['ainfinalarabic'] = 0xFECA;
  10040. t['aininitialarabic'] = 0xFECB;
  10041. t['ainmedialarabic'] = 0xFECC;
  10042. t['ainvertedbreve'] = 0x0203;
  10043. t['aivowelsignbengali'] = 0x09C8;
  10044. t['aivowelsigndeva'] = 0x0948;
  10045. t['aivowelsigngujarati'] = 0x0AC8;
  10046. t['akatakana'] = 0x30A2;
  10047. t['akatakanahalfwidth'] = 0xFF71;
  10048. t['akorean'] = 0x314F;
  10049. t['alef'] = 0x05D0;
  10050. t['alefarabic'] = 0x0627;
  10051. t['alefdageshhebrew'] = 0xFB30;
  10052. t['aleffinalarabic'] = 0xFE8E;
  10053. t['alefhamzaabovearabic'] = 0x0623;
  10054. t['alefhamzaabovefinalarabic'] = 0xFE84;
  10055. t['alefhamzabelowarabic'] = 0x0625;
  10056. t['alefhamzabelowfinalarabic'] = 0xFE88;
  10057. t['alefhebrew'] = 0x05D0;
  10058. t['aleflamedhebrew'] = 0xFB4F;
  10059. t['alefmaddaabovearabic'] = 0x0622;
  10060. t['alefmaddaabovefinalarabic'] = 0xFE82;
  10061. t['alefmaksuraarabic'] = 0x0649;
  10062. t['alefmaksurafinalarabic'] = 0xFEF0;
  10063. t['alefmaksurainitialarabic'] = 0xFEF3;
  10064. t['alefmaksuramedialarabic'] = 0xFEF4;
  10065. t['alefpatahhebrew'] = 0xFB2E;
  10066. t['alefqamatshebrew'] = 0xFB2F;
  10067. t['aleph'] = 0x2135;
  10068. t['allequal'] = 0x224C;
  10069. t['alpha'] = 0x03B1;
  10070. t['alphatonos'] = 0x03AC;
  10071. t['amacron'] = 0x0101;
  10072. t['amonospace'] = 0xFF41;
  10073. t['ampersand'] = 0x0026;
  10074. t['ampersandmonospace'] = 0xFF06;
  10075. t['ampersandsmall'] = 0xF726;
  10076. t['amsquare'] = 0x33C2;
  10077. t['anbopomofo'] = 0x3122;
  10078. t['angbopomofo'] = 0x3124;
  10079. t['angbracketleft'] = 0x3008;
  10080. // Glyph is missing from Adobe's original list.
  10081. t['angbracketright'] = 0x3009;
  10082. // Glyph is missing from Adobe's original list.
  10083. t['angkhankhuthai'] = 0x0E5A;
  10084. t['angle'] = 0x2220;
  10085. t['anglebracketleft'] = 0x3008;
  10086. t['anglebracketleftvertical'] = 0xFE3F;
  10087. t['anglebracketright'] = 0x3009;
  10088. t['anglebracketrightvertical'] = 0xFE40;
  10089. t['angleleft'] = 0x2329;
  10090. t['angleright'] = 0x232A;
  10091. t['angstrom'] = 0x212B;
  10092. t['anoteleia'] = 0x0387;
  10093. t['anudattadeva'] = 0x0952;
  10094. t['anusvarabengali'] = 0x0982;
  10095. t['anusvaradeva'] = 0x0902;
  10096. t['anusvaragujarati'] = 0x0A82;
  10097. t['aogonek'] = 0x0105;
  10098. t['apaatosquare'] = 0x3300;
  10099. t['aparen'] = 0x249C;
  10100. t['apostrophearmenian'] = 0x055A;
  10101. t['apostrophemod'] = 0x02BC;
  10102. t['apple'] = 0xF8FF;
  10103. t['approaches'] = 0x2250;
  10104. t['approxequal'] = 0x2248;
  10105. t['approxequalorimage'] = 0x2252;
  10106. t['approximatelyequal'] = 0x2245;
  10107. t['araeaekorean'] = 0x318E;
  10108. t['araeakorean'] = 0x318D;
  10109. t['arc'] = 0x2312;
  10110. t['arighthalfring'] = 0x1E9A;
  10111. t['aring'] = 0x00E5;
  10112. t['aringacute'] = 0x01FB;
  10113. t['aringbelow'] = 0x1E01;
  10114. t['arrowboth'] = 0x2194;
  10115. t['arrowdashdown'] = 0x21E3;
  10116. t['arrowdashleft'] = 0x21E0;
  10117. t['arrowdashright'] = 0x21E2;
  10118. t['arrowdashup'] = 0x21E1;
  10119. t['arrowdblboth'] = 0x21D4;
  10120. t['arrowdbldown'] = 0x21D3;
  10121. t['arrowdblleft'] = 0x21D0;
  10122. t['arrowdblright'] = 0x21D2;
  10123. t['arrowdblup'] = 0x21D1;
  10124. t['arrowdown'] = 0x2193;
  10125. t['arrowdownleft'] = 0x2199;
  10126. t['arrowdownright'] = 0x2198;
  10127. t['arrowdownwhite'] = 0x21E9;
  10128. t['arrowheaddownmod'] = 0x02C5;
  10129. t['arrowheadleftmod'] = 0x02C2;
  10130. t['arrowheadrightmod'] = 0x02C3;
  10131. t['arrowheadupmod'] = 0x02C4;
  10132. t['arrowhorizex'] = 0xF8E7;
  10133. t['arrowleft'] = 0x2190;
  10134. t['arrowleftdbl'] = 0x21D0;
  10135. t['arrowleftdblstroke'] = 0x21CD;
  10136. t['arrowleftoverright'] = 0x21C6;
  10137. t['arrowleftwhite'] = 0x21E6;
  10138. t['arrowright'] = 0x2192;
  10139. t['arrowrightdblstroke'] = 0x21CF;
  10140. t['arrowrightheavy'] = 0x279E;
  10141. t['arrowrightoverleft'] = 0x21C4;
  10142. t['arrowrightwhite'] = 0x21E8;
  10143. t['arrowtableft'] = 0x21E4;
  10144. t['arrowtabright'] = 0x21E5;
  10145. t['arrowup'] = 0x2191;
  10146. t['arrowupdn'] = 0x2195;
  10147. t['arrowupdnbse'] = 0x21A8;
  10148. t['arrowupdownbase'] = 0x21A8;
  10149. t['arrowupleft'] = 0x2196;
  10150. t['arrowupleftofdown'] = 0x21C5;
  10151. t['arrowupright'] = 0x2197;
  10152. t['arrowupwhite'] = 0x21E7;
  10153. t['arrowvertex'] = 0xF8E6;
  10154. t['asciicircum'] = 0x005E;
  10155. t['asciicircummonospace'] = 0xFF3E;
  10156. t['asciitilde'] = 0x007E;
  10157. t['asciitildemonospace'] = 0xFF5E;
  10158. t['ascript'] = 0x0251;
  10159. t['ascriptturned'] = 0x0252;
  10160. t['asmallhiragana'] = 0x3041;
  10161. t['asmallkatakana'] = 0x30A1;
  10162. t['asmallkatakanahalfwidth'] = 0xFF67;
  10163. t['asterisk'] = 0x002A;
  10164. t['asteriskaltonearabic'] = 0x066D;
  10165. t['asteriskarabic'] = 0x066D;
  10166. t['asteriskmath'] = 0x2217;
  10167. t['asteriskmonospace'] = 0xFF0A;
  10168. t['asterisksmall'] = 0xFE61;
  10169. t['asterism'] = 0x2042;
  10170. t['asuperior'] = 0xF6E9;
  10171. t['asymptoticallyequal'] = 0x2243;
  10172. t['at'] = 0x0040;
  10173. t['atilde'] = 0x00E3;
  10174. t['atmonospace'] = 0xFF20;
  10175. t['atsmall'] = 0xFE6B;
  10176. t['aturned'] = 0x0250;
  10177. t['aubengali'] = 0x0994;
  10178. t['aubopomofo'] = 0x3120;
  10179. t['audeva'] = 0x0914;
  10180. t['augujarati'] = 0x0A94;
  10181. t['augurmukhi'] = 0x0A14;
  10182. t['aulengthmarkbengali'] = 0x09D7;
  10183. t['aumatragurmukhi'] = 0x0A4C;
  10184. t['auvowelsignbengali'] = 0x09CC;
  10185. t['auvowelsigndeva'] = 0x094C;
  10186. t['auvowelsigngujarati'] = 0x0ACC;
  10187. t['avagrahadeva'] = 0x093D;
  10188. t['aybarmenian'] = 0x0561;
  10189. t['ayin'] = 0x05E2;
  10190. t['ayinaltonehebrew'] = 0xFB20;
  10191. t['ayinhebrew'] = 0x05E2;
  10192. t['b'] = 0x0062;
  10193. t['babengali'] = 0x09AC;
  10194. t['backslash'] = 0x005C;
  10195. t['backslashmonospace'] = 0xFF3C;
  10196. t['badeva'] = 0x092C;
  10197. t['bagujarati'] = 0x0AAC;
  10198. t['bagurmukhi'] = 0x0A2C;
  10199. t['bahiragana'] = 0x3070;
  10200. t['bahtthai'] = 0x0E3F;
  10201. t['bakatakana'] = 0x30D0;
  10202. t['bar'] = 0x007C;
  10203. t['barmonospace'] = 0xFF5C;
  10204. t['bbopomofo'] = 0x3105;
  10205. t['bcircle'] = 0x24D1;
  10206. t['bdotaccent'] = 0x1E03;
  10207. t['bdotbelow'] = 0x1E05;
  10208. t['beamedsixteenthnotes'] = 0x266C;
  10209. t['because'] = 0x2235;
  10210. t['becyrillic'] = 0x0431;
  10211. t['beharabic'] = 0x0628;
  10212. t['behfinalarabic'] = 0xFE90;
  10213. t['behinitialarabic'] = 0xFE91;
  10214. t['behiragana'] = 0x3079;
  10215. t['behmedialarabic'] = 0xFE92;
  10216. t['behmeeminitialarabic'] = 0xFC9F;
  10217. t['behmeemisolatedarabic'] = 0xFC08;
  10218. t['behnoonfinalarabic'] = 0xFC6D;
  10219. t['bekatakana'] = 0x30D9;
  10220. t['benarmenian'] = 0x0562;
  10221. t['bet'] = 0x05D1;
  10222. t['beta'] = 0x03B2;
  10223. t['betasymbolgreek'] = 0x03D0;
  10224. t['betdagesh'] = 0xFB31;
  10225. t['betdageshhebrew'] = 0xFB31;
  10226. t['bethebrew'] = 0x05D1;
  10227. t['betrafehebrew'] = 0xFB4C;
  10228. t['bhabengali'] = 0x09AD;
  10229. t['bhadeva'] = 0x092D;
  10230. t['bhagujarati'] = 0x0AAD;
  10231. t['bhagurmukhi'] = 0x0A2D;
  10232. t['bhook'] = 0x0253;
  10233. t['bihiragana'] = 0x3073;
  10234. t['bikatakana'] = 0x30D3;
  10235. t['bilabialclick'] = 0x0298;
  10236. t['bindigurmukhi'] = 0x0A02;
  10237. t['birusquare'] = 0x3331;
  10238. t['blackcircle'] = 0x25CF;
  10239. t['blackdiamond'] = 0x25C6;
  10240. t['blackdownpointingtriangle'] = 0x25BC;
  10241. t['blackleftpointingpointer'] = 0x25C4;
  10242. t['blackleftpointingtriangle'] = 0x25C0;
  10243. t['blacklenticularbracketleft'] = 0x3010;
  10244. t['blacklenticularbracketleftvertical'] = 0xFE3B;
  10245. t['blacklenticularbracketright'] = 0x3011;
  10246. t['blacklenticularbracketrightvertical'] = 0xFE3C;
  10247. t['blacklowerlefttriangle'] = 0x25E3;
  10248. t['blacklowerrighttriangle'] = 0x25E2;
  10249. t['blackrectangle'] = 0x25AC;
  10250. t['blackrightpointingpointer'] = 0x25BA;
  10251. t['blackrightpointingtriangle'] = 0x25B6;
  10252. t['blacksmallsquare'] = 0x25AA;
  10253. t['blacksmilingface'] = 0x263B;
  10254. t['blacksquare'] = 0x25A0;
  10255. t['blackstar'] = 0x2605;
  10256. t['blackupperlefttriangle'] = 0x25E4;
  10257. t['blackupperrighttriangle'] = 0x25E5;
  10258. t['blackuppointingsmalltriangle'] = 0x25B4;
  10259. t['blackuppointingtriangle'] = 0x25B2;
  10260. t['blank'] = 0x2423;
  10261. t['blinebelow'] = 0x1E07;
  10262. t['block'] = 0x2588;
  10263. t['bmonospace'] = 0xFF42;
  10264. t['bobaimaithai'] = 0x0E1A;
  10265. t['bohiragana'] = 0x307C;
  10266. t['bokatakana'] = 0x30DC;
  10267. t['bparen'] = 0x249D;
  10268. t['bqsquare'] = 0x33C3;
  10269. t['braceex'] = 0xF8F4;
  10270. t['braceleft'] = 0x007B;
  10271. t['braceleftbt'] = 0xF8F3;
  10272. t['braceleftmid'] = 0xF8F2;
  10273. t['braceleftmonospace'] = 0xFF5B;
  10274. t['braceleftsmall'] = 0xFE5B;
  10275. t['bracelefttp'] = 0xF8F1;
  10276. t['braceleftvertical'] = 0xFE37;
  10277. t['braceright'] = 0x007D;
  10278. t['bracerightbt'] = 0xF8FE;
  10279. t['bracerightmid'] = 0xF8FD;
  10280. t['bracerightmonospace'] = 0xFF5D;
  10281. t['bracerightsmall'] = 0xFE5C;
  10282. t['bracerighttp'] = 0xF8FC;
  10283. t['bracerightvertical'] = 0xFE38;
  10284. t['bracketleft'] = 0x005B;
  10285. t['bracketleftbt'] = 0xF8F0;
  10286. t['bracketleftex'] = 0xF8EF;
  10287. t['bracketleftmonospace'] = 0xFF3B;
  10288. t['bracketlefttp'] = 0xF8EE;
  10289. t['bracketright'] = 0x005D;
  10290. t['bracketrightbt'] = 0xF8FB;
  10291. t['bracketrightex'] = 0xF8FA;
  10292. t['bracketrightmonospace'] = 0xFF3D;
  10293. t['bracketrighttp'] = 0xF8F9;
  10294. t['breve'] = 0x02D8;
  10295. t['brevebelowcmb'] = 0x032E;
  10296. t['brevecmb'] = 0x0306;
  10297. t['breveinvertedbelowcmb'] = 0x032F;
  10298. t['breveinvertedcmb'] = 0x0311;
  10299. t['breveinverteddoublecmb'] = 0x0361;
  10300. t['bridgebelowcmb'] = 0x032A;
  10301. t['bridgeinvertedbelowcmb'] = 0x033A;
  10302. t['brokenbar'] = 0x00A6;
  10303. t['bstroke'] = 0x0180;
  10304. t['bsuperior'] = 0xF6EA;
  10305. t['btopbar'] = 0x0183;
  10306. t['buhiragana'] = 0x3076;
  10307. t['bukatakana'] = 0x30D6;
  10308. t['bullet'] = 0x2022;
  10309. t['bulletinverse'] = 0x25D8;
  10310. t['bulletoperator'] = 0x2219;
  10311. t['bullseye'] = 0x25CE;
  10312. t['c'] = 0x0063;
  10313. t['caarmenian'] = 0x056E;
  10314. t['cabengali'] = 0x099A;
  10315. t['cacute'] = 0x0107;
  10316. t['cadeva'] = 0x091A;
  10317. t['cagujarati'] = 0x0A9A;
  10318. t['cagurmukhi'] = 0x0A1A;
  10319. t['calsquare'] = 0x3388;
  10320. t['candrabindubengali'] = 0x0981;
  10321. t['candrabinducmb'] = 0x0310;
  10322. t['candrabindudeva'] = 0x0901;
  10323. t['candrabindugujarati'] = 0x0A81;
  10324. t['capslock'] = 0x21EA;
  10325. t['careof'] = 0x2105;
  10326. t['caron'] = 0x02C7;
  10327. t['caronbelowcmb'] = 0x032C;
  10328. t['caroncmb'] = 0x030C;
  10329. t['carriagereturn'] = 0x21B5;
  10330. t['cbopomofo'] = 0x3118;
  10331. t['ccaron'] = 0x010D;
  10332. t['ccedilla'] = 0x00E7;
  10333. t['ccedillaacute'] = 0x1E09;
  10334. t['ccircle'] = 0x24D2;
  10335. t['ccircumflex'] = 0x0109;
  10336. t['ccurl'] = 0x0255;
  10337. t['cdot'] = 0x010B;
  10338. t['cdotaccent'] = 0x010B;
  10339. t['cdsquare'] = 0x33C5;
  10340. t['cedilla'] = 0x00B8;
  10341. t['cedillacmb'] = 0x0327;
  10342. t['cent'] = 0x00A2;
  10343. t['centigrade'] = 0x2103;
  10344. t['centinferior'] = 0xF6DF;
  10345. t['centmonospace'] = 0xFFE0;
  10346. t['centoldstyle'] = 0xF7A2;
  10347. t['centsuperior'] = 0xF6E0;
  10348. t['chaarmenian'] = 0x0579;
  10349. t['chabengali'] = 0x099B;
  10350. t['chadeva'] = 0x091B;
  10351. t['chagujarati'] = 0x0A9B;
  10352. t['chagurmukhi'] = 0x0A1B;
  10353. t['chbopomofo'] = 0x3114;
  10354. t['cheabkhasiancyrillic'] = 0x04BD;
  10355. t['checkmark'] = 0x2713;
  10356. t['checyrillic'] = 0x0447;
  10357. t['chedescenderabkhasiancyrillic'] = 0x04BF;
  10358. t['chedescendercyrillic'] = 0x04B7;
  10359. t['chedieresiscyrillic'] = 0x04F5;
  10360. t['cheharmenian'] = 0x0573;
  10361. t['chekhakassiancyrillic'] = 0x04CC;
  10362. t['cheverticalstrokecyrillic'] = 0x04B9;
  10363. t['chi'] = 0x03C7;
  10364. t['chieuchacirclekorean'] = 0x3277;
  10365. t['chieuchaparenkorean'] = 0x3217;
  10366. t['chieuchcirclekorean'] = 0x3269;
  10367. t['chieuchkorean'] = 0x314A;
  10368. t['chieuchparenkorean'] = 0x3209;
  10369. t['chochangthai'] = 0x0E0A;
  10370. t['chochanthai'] = 0x0E08;
  10371. t['chochingthai'] = 0x0E09;
  10372. t['chochoethai'] = 0x0E0C;
  10373. t['chook'] = 0x0188;
  10374. t['cieucacirclekorean'] = 0x3276;
  10375. t['cieucaparenkorean'] = 0x3216;
  10376. t['cieuccirclekorean'] = 0x3268;
  10377. t['cieuckorean'] = 0x3148;
  10378. t['cieucparenkorean'] = 0x3208;
  10379. t['cieucuparenkorean'] = 0x321C;
  10380. t['circle'] = 0x25CB;
  10381. t['circlecopyrt'] = 0x00A9;
  10382. // Glyph is missing from Adobe's original list.
  10383. t['circlemultiply'] = 0x2297;
  10384. t['circleot'] = 0x2299;
  10385. t['circleplus'] = 0x2295;
  10386. t['circlepostalmark'] = 0x3036;
  10387. t['circlewithlefthalfblack'] = 0x25D0;
  10388. t['circlewithrighthalfblack'] = 0x25D1;
  10389. t['circumflex'] = 0x02C6;
  10390. t['circumflexbelowcmb'] = 0x032D;
  10391. t['circumflexcmb'] = 0x0302;
  10392. t['clear'] = 0x2327;
  10393. t['clickalveolar'] = 0x01C2;
  10394. t['clickdental'] = 0x01C0;
  10395. t['clicklateral'] = 0x01C1;
  10396. t['clickretroflex'] = 0x01C3;
  10397. t['club'] = 0x2663;
  10398. t['clubsuitblack'] = 0x2663;
  10399. t['clubsuitwhite'] = 0x2667;
  10400. t['cmcubedsquare'] = 0x33A4;
  10401. t['cmonospace'] = 0xFF43;
  10402. t['cmsquaredsquare'] = 0x33A0;
  10403. t['coarmenian'] = 0x0581;
  10404. t['colon'] = 0x003A;
  10405. t['colonmonetary'] = 0x20A1;
  10406. t['colonmonospace'] = 0xFF1A;
  10407. t['colonsign'] = 0x20A1;
  10408. t['colonsmall'] = 0xFE55;
  10409. t['colontriangularhalfmod'] = 0x02D1;
  10410. t['colontriangularmod'] = 0x02D0;
  10411. t['comma'] = 0x002C;
  10412. t['commaabovecmb'] = 0x0313;
  10413. t['commaaboverightcmb'] = 0x0315;
  10414. t['commaaccent'] = 0xF6C3;
  10415. t['commaarabic'] = 0x060C;
  10416. t['commaarmenian'] = 0x055D;
  10417. t['commainferior'] = 0xF6E1;
  10418. t['commamonospace'] = 0xFF0C;
  10419. t['commareversedabovecmb'] = 0x0314;
  10420. t['commareversedmod'] = 0x02BD;
  10421. t['commasmall'] = 0xFE50;
  10422. t['commasuperior'] = 0xF6E2;
  10423. t['commaturnedabovecmb'] = 0x0312;
  10424. t['commaturnedmod'] = 0x02BB;
  10425. t['compass'] = 0x263C;
  10426. t['congruent'] = 0x2245;
  10427. t['contourintegral'] = 0x222E;
  10428. t['control'] = 0x2303;
  10429. t['controlACK'] = 0x0006;
  10430. t['controlBEL'] = 0x0007;
  10431. t['controlBS'] = 0x0008;
  10432. t['controlCAN'] = 0x0018;
  10433. t['controlCR'] = 0x000D;
  10434. t['controlDC1'] = 0x0011;
  10435. t['controlDC2'] = 0x0012;
  10436. t['controlDC3'] = 0x0013;
  10437. t['controlDC4'] = 0x0014;
  10438. t['controlDEL'] = 0x007F;
  10439. t['controlDLE'] = 0x0010;
  10440. t['controlEM'] = 0x0019;
  10441. t['controlENQ'] = 0x0005;
  10442. t['controlEOT'] = 0x0004;
  10443. t['controlESC'] = 0x001B;
  10444. t['controlETB'] = 0x0017;
  10445. t['controlETX'] = 0x0003;
  10446. t['controlFF'] = 0x000C;
  10447. t['controlFS'] = 0x001C;
  10448. t['controlGS'] = 0x001D;
  10449. t['controlHT'] = 0x0009;
  10450. t['controlLF'] = 0x000A;
  10451. t['controlNAK'] = 0x0015;
  10452. t['controlRS'] = 0x001E;
  10453. t['controlSI'] = 0x000F;
  10454. t['controlSO'] = 0x000E;
  10455. t['controlSOT'] = 0x0002;
  10456. t['controlSTX'] = 0x0001;
  10457. t['controlSUB'] = 0x001A;
  10458. t['controlSYN'] = 0x0016;
  10459. t['controlUS'] = 0x001F;
  10460. t['controlVT'] = 0x000B;
  10461. t['copyright'] = 0x00A9;
  10462. t['copyrightsans'] = 0xF8E9;
  10463. t['copyrightserif'] = 0xF6D9;
  10464. t['cornerbracketleft'] = 0x300C;
  10465. t['cornerbracketlefthalfwidth'] = 0xFF62;
  10466. t['cornerbracketleftvertical'] = 0xFE41;
  10467. t['cornerbracketright'] = 0x300D;
  10468. t['cornerbracketrighthalfwidth'] = 0xFF63;
  10469. t['cornerbracketrightvertical'] = 0xFE42;
  10470. t['corporationsquare'] = 0x337F;
  10471. t['cosquare'] = 0x33C7;
  10472. t['coverkgsquare'] = 0x33C6;
  10473. t['cparen'] = 0x249E;
  10474. t['cruzeiro'] = 0x20A2;
  10475. t['cstretched'] = 0x0297;
  10476. t['curlyand'] = 0x22CF;
  10477. t['curlyor'] = 0x22CE;
  10478. t['currency'] = 0x00A4;
  10479. t['cyrBreve'] = 0xF6D1;
  10480. t['cyrFlex'] = 0xF6D2;
  10481. t['cyrbreve'] = 0xF6D4;
  10482. t['cyrflex'] = 0xF6D5;
  10483. t['d'] = 0x0064;
  10484. t['daarmenian'] = 0x0564;
  10485. t['dabengali'] = 0x09A6;
  10486. t['dadarabic'] = 0x0636;
  10487. t['dadeva'] = 0x0926;
  10488. t['dadfinalarabic'] = 0xFEBE;
  10489. t['dadinitialarabic'] = 0xFEBF;
  10490. t['dadmedialarabic'] = 0xFEC0;
  10491. t['dagesh'] = 0x05BC;
  10492. t['dageshhebrew'] = 0x05BC;
  10493. t['dagger'] = 0x2020;
  10494. t['daggerdbl'] = 0x2021;
  10495. t['dagujarati'] = 0x0AA6;
  10496. t['dagurmukhi'] = 0x0A26;
  10497. t['dahiragana'] = 0x3060;
  10498. t['dakatakana'] = 0x30C0;
  10499. t['dalarabic'] = 0x062F;
  10500. t['dalet'] = 0x05D3;
  10501. t['daletdagesh'] = 0xFB33;
  10502. t['daletdageshhebrew'] = 0xFB33;
  10503. t['dalethebrew'] = 0x05D3;
  10504. t['dalfinalarabic'] = 0xFEAA;
  10505. t['dammaarabic'] = 0x064F;
  10506. t['dammalowarabic'] = 0x064F;
  10507. t['dammatanaltonearabic'] = 0x064C;
  10508. t['dammatanarabic'] = 0x064C;
  10509. t['danda'] = 0x0964;
  10510. t['dargahebrew'] = 0x05A7;
  10511. t['dargalefthebrew'] = 0x05A7;
  10512. t['dasiapneumatacyrilliccmb'] = 0x0485;
  10513. t['dblGrave'] = 0xF6D3;
  10514. t['dblanglebracketleft'] = 0x300A;
  10515. t['dblanglebracketleftvertical'] = 0xFE3D;
  10516. t['dblanglebracketright'] = 0x300B;
  10517. t['dblanglebracketrightvertical'] = 0xFE3E;
  10518. t['dblarchinvertedbelowcmb'] = 0x032B;
  10519. t['dblarrowleft'] = 0x21D4;
  10520. t['dblarrowright'] = 0x21D2;
  10521. t['dbldanda'] = 0x0965;
  10522. t['dblgrave'] = 0xF6D6;
  10523. t['dblgravecmb'] = 0x030F;
  10524. t['dblintegral'] = 0x222C;
  10525. t['dbllowline'] = 0x2017;
  10526. t['dbllowlinecmb'] = 0x0333;
  10527. t['dbloverlinecmb'] = 0x033F;
  10528. t['dblprimemod'] = 0x02BA;
  10529. t['dblverticalbar'] = 0x2016;
  10530. t['dblverticallineabovecmb'] = 0x030E;
  10531. t['dbopomofo'] = 0x3109;
  10532. t['dbsquare'] = 0x33C8;
  10533. t['dcaron'] = 0x010F;
  10534. t['dcedilla'] = 0x1E11;
  10535. t['dcircle'] = 0x24D3;
  10536. t['dcircumflexbelow'] = 0x1E13;
  10537. t['dcroat'] = 0x0111;
  10538. t['ddabengali'] = 0x09A1;
  10539. t['ddadeva'] = 0x0921;
  10540. t['ddagujarati'] = 0x0AA1;
  10541. t['ddagurmukhi'] = 0x0A21;
  10542. t['ddalarabic'] = 0x0688;
  10543. t['ddalfinalarabic'] = 0xFB89;
  10544. t['dddhadeva'] = 0x095C;
  10545. t['ddhabengali'] = 0x09A2;
  10546. t['ddhadeva'] = 0x0922;
  10547. t['ddhagujarati'] = 0x0AA2;
  10548. t['ddhagurmukhi'] = 0x0A22;
  10549. t['ddotaccent'] = 0x1E0B;
  10550. t['ddotbelow'] = 0x1E0D;
  10551. t['decimalseparatorarabic'] = 0x066B;
  10552. t['decimalseparatorpersian'] = 0x066B;
  10553. t['decyrillic'] = 0x0434;
  10554. t['degree'] = 0x00B0;
  10555. t['dehihebrew'] = 0x05AD;
  10556. t['dehiragana'] = 0x3067;
  10557. t['deicoptic'] = 0x03EF;
  10558. t['dekatakana'] = 0x30C7;
  10559. t['deleteleft'] = 0x232B;
  10560. t['deleteright'] = 0x2326;
  10561. t['delta'] = 0x03B4;
  10562. t['deltaturned'] = 0x018D;
  10563. t['denominatorminusonenumeratorbengali'] = 0x09F8;
  10564. t['dezh'] = 0x02A4;
  10565. t['dhabengali'] = 0x09A7;
  10566. t['dhadeva'] = 0x0927;
  10567. t['dhagujarati'] = 0x0AA7;
  10568. t['dhagurmukhi'] = 0x0A27;
  10569. t['dhook'] = 0x0257;
  10570. t['dialytikatonos'] = 0x0385;
  10571. t['dialytikatonoscmb'] = 0x0344;
  10572. t['diamond'] = 0x2666;
  10573. t['diamondsuitwhite'] = 0x2662;
  10574. t['dieresis'] = 0x00A8;
  10575. t['dieresisacute'] = 0xF6D7;
  10576. t['dieresisbelowcmb'] = 0x0324;
  10577. t['dieresiscmb'] = 0x0308;
  10578. t['dieresisgrave'] = 0xF6D8;
  10579. t['dieresistonos'] = 0x0385;
  10580. t['dihiragana'] = 0x3062;
  10581. t['dikatakana'] = 0x30C2;
  10582. t['dittomark'] = 0x3003;
  10583. t['divide'] = 0x00F7;
  10584. t['divides'] = 0x2223;
  10585. t['divisionslash'] = 0x2215;
  10586. t['djecyrillic'] = 0x0452;
  10587. t['dkshade'] = 0x2593;
  10588. t['dlinebelow'] = 0x1E0F;
  10589. t['dlsquare'] = 0x3397;
  10590. t['dmacron'] = 0x0111;
  10591. t['dmonospace'] = 0xFF44;
  10592. t['dnblock'] = 0x2584;
  10593. t['dochadathai'] = 0x0E0E;
  10594. t['dodekthai'] = 0x0E14;
  10595. t['dohiragana'] = 0x3069;
  10596. t['dokatakana'] = 0x30C9;
  10597. t['dollar'] = 0x0024;
  10598. t['dollarinferior'] = 0xF6E3;
  10599. t['dollarmonospace'] = 0xFF04;
  10600. t['dollaroldstyle'] = 0xF724;
  10601. t['dollarsmall'] = 0xFE69;
  10602. t['dollarsuperior'] = 0xF6E4;
  10603. t['dong'] = 0x20AB;
  10604. t['dorusquare'] = 0x3326;
  10605. t['dotaccent'] = 0x02D9;
  10606. t['dotaccentcmb'] = 0x0307;
  10607. t['dotbelowcmb'] = 0x0323;
  10608. t['dotbelowcomb'] = 0x0323;
  10609. t['dotkatakana'] = 0x30FB;
  10610. t['dotlessi'] = 0x0131;
  10611. t['dotlessj'] = 0xF6BE;
  10612. t['dotlessjstrokehook'] = 0x0284;
  10613. t['dotmath'] = 0x22C5;
  10614. t['dottedcircle'] = 0x25CC;
  10615. t['doubleyodpatah'] = 0xFB1F;
  10616. t['doubleyodpatahhebrew'] = 0xFB1F;
  10617. t['downtackbelowcmb'] = 0x031E;
  10618. t['downtackmod'] = 0x02D5;
  10619. t['dparen'] = 0x249F;
  10620. t['dsuperior'] = 0xF6EB;
  10621. t['dtail'] = 0x0256;
  10622. t['dtopbar'] = 0x018C;
  10623. t['duhiragana'] = 0x3065;
  10624. t['dukatakana'] = 0x30C5;
  10625. t['dz'] = 0x01F3;
  10626. t['dzaltone'] = 0x02A3;
  10627. t['dzcaron'] = 0x01C6;
  10628. t['dzcurl'] = 0x02A5;
  10629. t['dzeabkhasiancyrillic'] = 0x04E1;
  10630. t['dzecyrillic'] = 0x0455;
  10631. t['dzhecyrillic'] = 0x045F;
  10632. t['e'] = 0x0065;
  10633. t['eacute'] = 0x00E9;
  10634. t['earth'] = 0x2641;
  10635. t['ebengali'] = 0x098F;
  10636. t['ebopomofo'] = 0x311C;
  10637. t['ebreve'] = 0x0115;
  10638. t['ecandradeva'] = 0x090D;
  10639. t['ecandragujarati'] = 0x0A8D;
  10640. t['ecandravowelsigndeva'] = 0x0945;
  10641. t['ecandravowelsigngujarati'] = 0x0AC5;
  10642. t['ecaron'] = 0x011B;
  10643. t['ecedillabreve'] = 0x1E1D;
  10644. t['echarmenian'] = 0x0565;
  10645. t['echyiwnarmenian'] = 0x0587;
  10646. t['ecircle'] = 0x24D4;
  10647. t['ecircumflex'] = 0x00EA;
  10648. t['ecircumflexacute'] = 0x1EBF;
  10649. t['ecircumflexbelow'] = 0x1E19;
  10650. t['ecircumflexdotbelow'] = 0x1EC7;
  10651. t['ecircumflexgrave'] = 0x1EC1;
  10652. t['ecircumflexhookabove'] = 0x1EC3;
  10653. t['ecircumflextilde'] = 0x1EC5;
  10654. t['ecyrillic'] = 0x0454;
  10655. t['edblgrave'] = 0x0205;
  10656. t['edeva'] = 0x090F;
  10657. t['edieresis'] = 0x00EB;
  10658. t['edot'] = 0x0117;
  10659. t['edotaccent'] = 0x0117;
  10660. t['edotbelow'] = 0x1EB9;
  10661. t['eegurmukhi'] = 0x0A0F;
  10662. t['eematragurmukhi'] = 0x0A47;
  10663. t['efcyrillic'] = 0x0444;
  10664. t['egrave'] = 0x00E8;
  10665. t['egujarati'] = 0x0A8F;
  10666. t['eharmenian'] = 0x0567;
  10667. t['ehbopomofo'] = 0x311D;
  10668. t['ehiragana'] = 0x3048;
  10669. t['ehookabove'] = 0x1EBB;
  10670. t['eibopomofo'] = 0x311F;
  10671. t['eight'] = 0x0038;
  10672. t['eightarabic'] = 0x0668;
  10673. t['eightbengali'] = 0x09EE;
  10674. t['eightcircle'] = 0x2467;
  10675. t['eightcircleinversesansserif'] = 0x2791;
  10676. t['eightdeva'] = 0x096E;
  10677. t['eighteencircle'] = 0x2471;
  10678. t['eighteenparen'] = 0x2485;
  10679. t['eighteenperiod'] = 0x2499;
  10680. t['eightgujarati'] = 0x0AEE;
  10681. t['eightgurmukhi'] = 0x0A6E;
  10682. t['eighthackarabic'] = 0x0668;
  10683. t['eighthangzhou'] = 0x3028;
  10684. t['eighthnotebeamed'] = 0x266B;
  10685. t['eightideographicparen'] = 0x3227;
  10686. t['eightinferior'] = 0x2088;
  10687. t['eightmonospace'] = 0xFF18;
  10688. t['eightoldstyle'] = 0xF738;
  10689. t['eightparen'] = 0x247B;
  10690. t['eightperiod'] = 0x248F;
  10691. t['eightpersian'] = 0x06F8;
  10692. t['eightroman'] = 0x2177;
  10693. t['eightsuperior'] = 0x2078;
  10694. t['eightthai'] = 0x0E58;
  10695. t['einvertedbreve'] = 0x0207;
  10696. t['eiotifiedcyrillic'] = 0x0465;
  10697. t['ekatakana'] = 0x30A8;
  10698. t['ekatakanahalfwidth'] = 0xFF74;
  10699. t['ekonkargurmukhi'] = 0x0A74;
  10700. t['ekorean'] = 0x3154;
  10701. t['elcyrillic'] = 0x043B;
  10702. t['element'] = 0x2208;
  10703. t['elevencircle'] = 0x246A;
  10704. t['elevenparen'] = 0x247E;
  10705. t['elevenperiod'] = 0x2492;
  10706. t['elevenroman'] = 0x217A;
  10707. t['ellipsis'] = 0x2026;
  10708. t['ellipsisvertical'] = 0x22EE;
  10709. t['emacron'] = 0x0113;
  10710. t['emacronacute'] = 0x1E17;
  10711. t['emacrongrave'] = 0x1E15;
  10712. t['emcyrillic'] = 0x043C;
  10713. t['emdash'] = 0x2014;
  10714. t['emdashvertical'] = 0xFE31;
  10715. t['emonospace'] = 0xFF45;
  10716. t['emphasismarkarmenian'] = 0x055B;
  10717. t['emptyset'] = 0x2205;
  10718. t['enbopomofo'] = 0x3123;
  10719. t['encyrillic'] = 0x043D;
  10720. t['endash'] = 0x2013;
  10721. t['endashvertical'] = 0xFE32;
  10722. t['endescendercyrillic'] = 0x04A3;
  10723. t['eng'] = 0x014B;
  10724. t['engbopomofo'] = 0x3125;
  10725. t['enghecyrillic'] = 0x04A5;
  10726. t['enhookcyrillic'] = 0x04C8;
  10727. t['enspace'] = 0x2002;
  10728. t['eogonek'] = 0x0119;
  10729. t['eokorean'] = 0x3153;
  10730. t['eopen'] = 0x025B;
  10731. t['eopenclosed'] = 0x029A;
  10732. t['eopenreversed'] = 0x025C;
  10733. t['eopenreversedclosed'] = 0x025E;
  10734. t['eopenreversedhook'] = 0x025D;
  10735. t['eparen'] = 0x24A0;
  10736. t['epsilon'] = 0x03B5;
  10737. t['epsilontonos'] = 0x03AD;
  10738. t['equal'] = 0x003D;
  10739. t['equalmonospace'] = 0xFF1D;
  10740. t['equalsmall'] = 0xFE66;
  10741. t['equalsuperior'] = 0x207C;
  10742. t['equivalence'] = 0x2261;
  10743. t['erbopomofo'] = 0x3126;
  10744. t['ercyrillic'] = 0x0440;
  10745. t['ereversed'] = 0x0258;
  10746. t['ereversedcyrillic'] = 0x044D;
  10747. t['escyrillic'] = 0x0441;
  10748. t['esdescendercyrillic'] = 0x04AB;
  10749. t['esh'] = 0x0283;
  10750. t['eshcurl'] = 0x0286;
  10751. t['eshortdeva'] = 0x090E;
  10752. t['eshortvowelsigndeva'] = 0x0946;
  10753. t['eshreversedloop'] = 0x01AA;
  10754. t['eshsquatreversed'] = 0x0285;
  10755. t['esmallhiragana'] = 0x3047;
  10756. t['esmallkatakana'] = 0x30A7;
  10757. t['esmallkatakanahalfwidth'] = 0xFF6A;
  10758. t['estimated'] = 0x212E;
  10759. t['esuperior'] = 0xF6EC;
  10760. t['eta'] = 0x03B7;
  10761. t['etarmenian'] = 0x0568;
  10762. t['etatonos'] = 0x03AE;
  10763. t['eth'] = 0x00F0;
  10764. t['etilde'] = 0x1EBD;
  10765. t['etildebelow'] = 0x1E1B;
  10766. t['etnahtafoukhhebrew'] = 0x0591;
  10767. t['etnahtafoukhlefthebrew'] = 0x0591;
  10768. t['etnahtahebrew'] = 0x0591;
  10769. t['etnahtalefthebrew'] = 0x0591;
  10770. t['eturned'] = 0x01DD;
  10771. t['eukorean'] = 0x3161;
  10772. t['euro'] = 0x20AC;
  10773. t['evowelsignbengali'] = 0x09C7;
  10774. t['evowelsigndeva'] = 0x0947;
  10775. t['evowelsigngujarati'] = 0x0AC7;
  10776. t['exclam'] = 0x0021;
  10777. t['exclamarmenian'] = 0x055C;
  10778. t['exclamdbl'] = 0x203C;
  10779. t['exclamdown'] = 0x00A1;
  10780. t['exclamdownsmall'] = 0xF7A1;
  10781. t['exclammonospace'] = 0xFF01;
  10782. t['exclamsmall'] = 0xF721;
  10783. t['existential'] = 0x2203;
  10784. t['ezh'] = 0x0292;
  10785. t['ezhcaron'] = 0x01EF;
  10786. t['ezhcurl'] = 0x0293;
  10787. t['ezhreversed'] = 0x01B9;
  10788. t['ezhtail'] = 0x01BA;
  10789. t['f'] = 0x0066;
  10790. t['fadeva'] = 0x095E;
  10791. t['fagurmukhi'] = 0x0A5E;
  10792. t['fahrenheit'] = 0x2109;
  10793. t['fathaarabic'] = 0x064E;
  10794. t['fathalowarabic'] = 0x064E;
  10795. t['fathatanarabic'] = 0x064B;
  10796. t['fbopomofo'] = 0x3108;
  10797. t['fcircle'] = 0x24D5;
  10798. t['fdotaccent'] = 0x1E1F;
  10799. t['feharabic'] = 0x0641;
  10800. t['feharmenian'] = 0x0586;
  10801. t['fehfinalarabic'] = 0xFED2;
  10802. t['fehinitialarabic'] = 0xFED3;
  10803. t['fehmedialarabic'] = 0xFED4;
  10804. t['feicoptic'] = 0x03E5;
  10805. t['female'] = 0x2640;
  10806. t['ff'] = 0xFB00;
  10807. t['ffi'] = 0xFB03;
  10808. t['ffl'] = 0xFB04;
  10809. t['fi'] = 0xFB01;
  10810. t['fifteencircle'] = 0x246E;
  10811. t['fifteenparen'] = 0x2482;
  10812. t['fifteenperiod'] = 0x2496;
  10813. t['figuredash'] = 0x2012;
  10814. t['filledbox'] = 0x25A0;
  10815. t['filledrect'] = 0x25AC;
  10816. t['finalkaf'] = 0x05DA;
  10817. t['finalkafdagesh'] = 0xFB3A;
  10818. t['finalkafdageshhebrew'] = 0xFB3A;
  10819. t['finalkafhebrew'] = 0x05DA;
  10820. t['finalmem'] = 0x05DD;
  10821. t['finalmemhebrew'] = 0x05DD;
  10822. t['finalnun'] = 0x05DF;
  10823. t['finalnunhebrew'] = 0x05DF;
  10824. t['finalpe'] = 0x05E3;
  10825. t['finalpehebrew'] = 0x05E3;
  10826. t['finaltsadi'] = 0x05E5;
  10827. t['finaltsadihebrew'] = 0x05E5;
  10828. t['firsttonechinese'] = 0x02C9;
  10829. t['fisheye'] = 0x25C9;
  10830. t['fitacyrillic'] = 0x0473;
  10831. t['five'] = 0x0035;
  10832. t['fivearabic'] = 0x0665;
  10833. t['fivebengali'] = 0x09EB;
  10834. t['fivecircle'] = 0x2464;
  10835. t['fivecircleinversesansserif'] = 0x278E;
  10836. t['fivedeva'] = 0x096B;
  10837. t['fiveeighths'] = 0x215D;
  10838. t['fivegujarati'] = 0x0AEB;
  10839. t['fivegurmukhi'] = 0x0A6B;
  10840. t['fivehackarabic'] = 0x0665;
  10841. t['fivehangzhou'] = 0x3025;
  10842. t['fiveideographicparen'] = 0x3224;
  10843. t['fiveinferior'] = 0x2085;
  10844. t['fivemonospace'] = 0xFF15;
  10845. t['fiveoldstyle'] = 0xF735;
  10846. t['fiveparen'] = 0x2478;
  10847. t['fiveperiod'] = 0x248C;
  10848. t['fivepersian'] = 0x06F5;
  10849. t['fiveroman'] = 0x2174;
  10850. t['fivesuperior'] = 0x2075;
  10851. t['fivethai'] = 0x0E55;
  10852. t['fl'] = 0xFB02;
  10853. t['florin'] = 0x0192;
  10854. t['fmonospace'] = 0xFF46;
  10855. t['fmsquare'] = 0x3399;
  10856. t['fofanthai'] = 0x0E1F;
  10857. t['fofathai'] = 0x0E1D;
  10858. t['fongmanthai'] = 0x0E4F;
  10859. t['forall'] = 0x2200;
  10860. t['four'] = 0x0034;
  10861. t['fourarabic'] = 0x0664;
  10862. t['fourbengali'] = 0x09EA;
  10863. t['fourcircle'] = 0x2463;
  10864. t['fourcircleinversesansserif'] = 0x278D;
  10865. t['fourdeva'] = 0x096A;
  10866. t['fourgujarati'] = 0x0AEA;
  10867. t['fourgurmukhi'] = 0x0A6A;
  10868. t['fourhackarabic'] = 0x0664;
  10869. t['fourhangzhou'] = 0x3024;
  10870. t['fourideographicparen'] = 0x3223;
  10871. t['fourinferior'] = 0x2084;
  10872. t['fourmonospace'] = 0xFF14;
  10873. t['fournumeratorbengali'] = 0x09F7;
  10874. t['fouroldstyle'] = 0xF734;
  10875. t['fourparen'] = 0x2477;
  10876. t['fourperiod'] = 0x248B;
  10877. t['fourpersian'] = 0x06F4;
  10878. t['fourroman'] = 0x2173;
  10879. t['foursuperior'] = 0x2074;
  10880. t['fourteencircle'] = 0x246D;
  10881. t['fourteenparen'] = 0x2481;
  10882. t['fourteenperiod'] = 0x2495;
  10883. t['fourthai'] = 0x0E54;
  10884. t['fourthtonechinese'] = 0x02CB;
  10885. t['fparen'] = 0x24A1;
  10886. t['fraction'] = 0x2044;
  10887. t['franc'] = 0x20A3;
  10888. t['g'] = 0x0067;
  10889. t['gabengali'] = 0x0997;
  10890. t['gacute'] = 0x01F5;
  10891. t['gadeva'] = 0x0917;
  10892. t['gafarabic'] = 0x06AF;
  10893. t['gaffinalarabic'] = 0xFB93;
  10894. t['gafinitialarabic'] = 0xFB94;
  10895. t['gafmedialarabic'] = 0xFB95;
  10896. t['gagujarati'] = 0x0A97;
  10897. t['gagurmukhi'] = 0x0A17;
  10898. t['gahiragana'] = 0x304C;
  10899. t['gakatakana'] = 0x30AC;
  10900. t['gamma'] = 0x03B3;
  10901. t['gammalatinsmall'] = 0x0263;
  10902. t['gammasuperior'] = 0x02E0;
  10903. t['gangiacoptic'] = 0x03EB;
  10904. t['gbopomofo'] = 0x310D;
  10905. t['gbreve'] = 0x011F;
  10906. t['gcaron'] = 0x01E7;
  10907. t['gcedilla'] = 0x0123;
  10908. t['gcircle'] = 0x24D6;
  10909. t['gcircumflex'] = 0x011D;
  10910. t['gcommaaccent'] = 0x0123;
  10911. t['gdot'] = 0x0121;
  10912. t['gdotaccent'] = 0x0121;
  10913. t['gecyrillic'] = 0x0433;
  10914. t['gehiragana'] = 0x3052;
  10915. t['gekatakana'] = 0x30B2;
  10916. t['geometricallyequal'] = 0x2251;
  10917. t['gereshaccenthebrew'] = 0x059C;
  10918. t['gereshhebrew'] = 0x05F3;
  10919. t['gereshmuqdamhebrew'] = 0x059D;
  10920. t['germandbls'] = 0x00DF;
  10921. t['gershayimaccenthebrew'] = 0x059E;
  10922. t['gershayimhebrew'] = 0x05F4;
  10923. t['getamark'] = 0x3013;
  10924. t['ghabengali'] = 0x0998;
  10925. t['ghadarmenian'] = 0x0572;
  10926. t['ghadeva'] = 0x0918;
  10927. t['ghagujarati'] = 0x0A98;
  10928. t['ghagurmukhi'] = 0x0A18;
  10929. t['ghainarabic'] = 0x063A;
  10930. t['ghainfinalarabic'] = 0xFECE;
  10931. t['ghaininitialarabic'] = 0xFECF;
  10932. t['ghainmedialarabic'] = 0xFED0;
  10933. t['ghemiddlehookcyrillic'] = 0x0495;
  10934. t['ghestrokecyrillic'] = 0x0493;
  10935. t['gheupturncyrillic'] = 0x0491;
  10936. t['ghhadeva'] = 0x095A;
  10937. t['ghhagurmukhi'] = 0x0A5A;
  10938. t['ghook'] = 0x0260;
  10939. t['ghzsquare'] = 0x3393;
  10940. t['gihiragana'] = 0x304E;
  10941. t['gikatakana'] = 0x30AE;
  10942. t['gimarmenian'] = 0x0563;
  10943. t['gimel'] = 0x05D2;
  10944. t['gimeldagesh'] = 0xFB32;
  10945. t['gimeldageshhebrew'] = 0xFB32;
  10946. t['gimelhebrew'] = 0x05D2;
  10947. t['gjecyrillic'] = 0x0453;
  10948. t['glottalinvertedstroke'] = 0x01BE;
  10949. t['glottalstop'] = 0x0294;
  10950. t['glottalstopinverted'] = 0x0296;
  10951. t['glottalstopmod'] = 0x02C0;
  10952. t['glottalstopreversed'] = 0x0295;
  10953. t['glottalstopreversedmod'] = 0x02C1;
  10954. t['glottalstopreversedsuperior'] = 0x02E4;
  10955. t['glottalstopstroke'] = 0x02A1;
  10956. t['glottalstopstrokereversed'] = 0x02A2;
  10957. t['gmacron'] = 0x1E21;
  10958. t['gmonospace'] = 0xFF47;
  10959. t['gohiragana'] = 0x3054;
  10960. t['gokatakana'] = 0x30B4;
  10961. t['gparen'] = 0x24A2;
  10962. t['gpasquare'] = 0x33AC;
  10963. t['gradient'] = 0x2207;
  10964. t['grave'] = 0x0060;
  10965. t['gravebelowcmb'] = 0x0316;
  10966. t['gravecmb'] = 0x0300;
  10967. t['gravecomb'] = 0x0300;
  10968. t['gravedeva'] = 0x0953;
  10969. t['gravelowmod'] = 0x02CE;
  10970. t['gravemonospace'] = 0xFF40;
  10971. t['gravetonecmb'] = 0x0340;
  10972. t['greater'] = 0x003E;
  10973. t['greaterequal'] = 0x2265;
  10974. t['greaterequalorless'] = 0x22DB;
  10975. t['greatermonospace'] = 0xFF1E;
  10976. t['greaterorequivalent'] = 0x2273;
  10977. t['greaterorless'] = 0x2277;
  10978. t['greateroverequal'] = 0x2267;
  10979. t['greatersmall'] = 0xFE65;
  10980. t['gscript'] = 0x0261;
  10981. t['gstroke'] = 0x01E5;
  10982. t['guhiragana'] = 0x3050;
  10983. t['guillemotleft'] = 0x00AB;
  10984. t['guillemotright'] = 0x00BB;
  10985. t['guilsinglleft'] = 0x2039;
  10986. t['guilsinglright'] = 0x203A;
  10987. t['gukatakana'] = 0x30B0;
  10988. t['guramusquare'] = 0x3318;
  10989. t['gysquare'] = 0x33C9;
  10990. t['h'] = 0x0068;
  10991. t['haabkhasiancyrillic'] = 0x04A9;
  10992. t['haaltonearabic'] = 0x06C1;
  10993. t['habengali'] = 0x09B9;
  10994. t['hadescendercyrillic'] = 0x04B3;
  10995. t['hadeva'] = 0x0939;
  10996. t['hagujarati'] = 0x0AB9;
  10997. t['hagurmukhi'] = 0x0A39;
  10998. t['haharabic'] = 0x062D;
  10999. t['hahfinalarabic'] = 0xFEA2;
  11000. t['hahinitialarabic'] = 0xFEA3;
  11001. t['hahiragana'] = 0x306F;
  11002. t['hahmedialarabic'] = 0xFEA4;
  11003. t['haitusquare'] = 0x332A;
  11004. t['hakatakana'] = 0x30CF;
  11005. t['hakatakanahalfwidth'] = 0xFF8A;
  11006. t['halantgurmukhi'] = 0x0A4D;
  11007. t['hamzaarabic'] = 0x0621;
  11008. t['hamzalowarabic'] = 0x0621;
  11009. t['hangulfiller'] = 0x3164;
  11010. t['hardsigncyrillic'] = 0x044A;
  11011. t['harpoonleftbarbup'] = 0x21BC;
  11012. t['harpoonrightbarbup'] = 0x21C0;
  11013. t['hasquare'] = 0x33CA;
  11014. t['hatafpatah'] = 0x05B2;
  11015. t['hatafpatah16'] = 0x05B2;
  11016. t['hatafpatah23'] = 0x05B2;
  11017. t['hatafpatah2f'] = 0x05B2;
  11018. t['hatafpatahhebrew'] = 0x05B2;
  11019. t['hatafpatahnarrowhebrew'] = 0x05B2;
  11020. t['hatafpatahquarterhebrew'] = 0x05B2;
  11021. t['hatafpatahwidehebrew'] = 0x05B2;
  11022. t['hatafqamats'] = 0x05B3;
  11023. t['hatafqamats1b'] = 0x05B3;
  11024. t['hatafqamats28'] = 0x05B3;
  11025. t['hatafqamats34'] = 0x05B3;
  11026. t['hatafqamatshebrew'] = 0x05B3;
  11027. t['hatafqamatsnarrowhebrew'] = 0x05B3;
  11028. t['hatafqamatsquarterhebrew'] = 0x05B3;
  11029. t['hatafqamatswidehebrew'] = 0x05B3;
  11030. t['hatafsegol'] = 0x05B1;
  11031. t['hatafsegol17'] = 0x05B1;
  11032. t['hatafsegol24'] = 0x05B1;
  11033. t['hatafsegol30'] = 0x05B1;
  11034. t['hatafsegolhebrew'] = 0x05B1;
  11035. t['hatafsegolnarrowhebrew'] = 0x05B1;
  11036. t['hatafsegolquarterhebrew'] = 0x05B1;
  11037. t['hatafsegolwidehebrew'] = 0x05B1;
  11038. t['hbar'] = 0x0127;
  11039. t['hbopomofo'] = 0x310F;
  11040. t['hbrevebelow'] = 0x1E2B;
  11041. t['hcedilla'] = 0x1E29;
  11042. t['hcircle'] = 0x24D7;
  11043. t['hcircumflex'] = 0x0125;
  11044. t['hdieresis'] = 0x1E27;
  11045. t['hdotaccent'] = 0x1E23;
  11046. t['hdotbelow'] = 0x1E25;
  11047. t['he'] = 0x05D4;
  11048. t['heart'] = 0x2665;
  11049. t['heartsuitblack'] = 0x2665;
  11050. t['heartsuitwhite'] = 0x2661;
  11051. t['hedagesh'] = 0xFB34;
  11052. t['hedageshhebrew'] = 0xFB34;
  11053. t['hehaltonearabic'] = 0x06C1;
  11054. t['heharabic'] = 0x0647;
  11055. t['hehebrew'] = 0x05D4;
  11056. t['hehfinalaltonearabic'] = 0xFBA7;
  11057. t['hehfinalalttwoarabic'] = 0xFEEA;
  11058. t['hehfinalarabic'] = 0xFEEA;
  11059. t['hehhamzaabovefinalarabic'] = 0xFBA5;
  11060. t['hehhamzaaboveisolatedarabic'] = 0xFBA4;
  11061. t['hehinitialaltonearabic'] = 0xFBA8;
  11062. t['hehinitialarabic'] = 0xFEEB;
  11063. t['hehiragana'] = 0x3078;
  11064. t['hehmedialaltonearabic'] = 0xFBA9;
  11065. t['hehmedialarabic'] = 0xFEEC;
  11066. t['heiseierasquare'] = 0x337B;
  11067. t['hekatakana'] = 0x30D8;
  11068. t['hekatakanahalfwidth'] = 0xFF8D;
  11069. t['hekutaarusquare'] = 0x3336;
  11070. t['henghook'] = 0x0267;
  11071. t['herutusquare'] = 0x3339;
  11072. t['het'] = 0x05D7;
  11073. t['hethebrew'] = 0x05D7;
  11074. t['hhook'] = 0x0266;
  11075. t['hhooksuperior'] = 0x02B1;
  11076. t['hieuhacirclekorean'] = 0x327B;
  11077. t['hieuhaparenkorean'] = 0x321B;
  11078. t['hieuhcirclekorean'] = 0x326D;
  11079. t['hieuhkorean'] = 0x314E;
  11080. t['hieuhparenkorean'] = 0x320D;
  11081. t['hihiragana'] = 0x3072;
  11082. t['hikatakana'] = 0x30D2;
  11083. t['hikatakanahalfwidth'] = 0xFF8B;
  11084. t['hiriq'] = 0x05B4;
  11085. t['hiriq14'] = 0x05B4;
  11086. t['hiriq21'] = 0x05B4;
  11087. t['hiriq2d'] = 0x05B4;
  11088. t['hiriqhebrew'] = 0x05B4;
  11089. t['hiriqnarrowhebrew'] = 0x05B4;
  11090. t['hiriqquarterhebrew'] = 0x05B4;
  11091. t['hiriqwidehebrew'] = 0x05B4;
  11092. t['hlinebelow'] = 0x1E96;
  11093. t['hmonospace'] = 0xFF48;
  11094. t['hoarmenian'] = 0x0570;
  11095. t['hohipthai'] = 0x0E2B;
  11096. t['hohiragana'] = 0x307B;
  11097. t['hokatakana'] = 0x30DB;
  11098. t['hokatakanahalfwidth'] = 0xFF8E;
  11099. t['holam'] = 0x05B9;
  11100. t['holam19'] = 0x05B9;
  11101. t['holam26'] = 0x05B9;
  11102. t['holam32'] = 0x05B9;
  11103. t['holamhebrew'] = 0x05B9;
  11104. t['holamnarrowhebrew'] = 0x05B9;
  11105. t['holamquarterhebrew'] = 0x05B9;
  11106. t['holamwidehebrew'] = 0x05B9;
  11107. t['honokhukthai'] = 0x0E2E;
  11108. t['hookabovecomb'] = 0x0309;
  11109. t['hookcmb'] = 0x0309;
  11110. t['hookpalatalizedbelowcmb'] = 0x0321;
  11111. t['hookretroflexbelowcmb'] = 0x0322;
  11112. t['hoonsquare'] = 0x3342;
  11113. t['horicoptic'] = 0x03E9;
  11114. t['horizontalbar'] = 0x2015;
  11115. t['horncmb'] = 0x031B;
  11116. t['hotsprings'] = 0x2668;
  11117. t['house'] = 0x2302;
  11118. t['hparen'] = 0x24A3;
  11119. t['hsuperior'] = 0x02B0;
  11120. t['hturned'] = 0x0265;
  11121. t['huhiragana'] = 0x3075;
  11122. t['huiitosquare'] = 0x3333;
  11123. t['hukatakana'] = 0x30D5;
  11124. t['hukatakanahalfwidth'] = 0xFF8C;
  11125. t['hungarumlaut'] = 0x02DD;
  11126. t['hungarumlautcmb'] = 0x030B;
  11127. t['hv'] = 0x0195;
  11128. t['hyphen'] = 0x002D;
  11129. t['hypheninferior'] = 0xF6E5;
  11130. t['hyphenmonospace'] = 0xFF0D;
  11131. t['hyphensmall'] = 0xFE63;
  11132. t['hyphensuperior'] = 0xF6E6;
  11133. t['hyphentwo'] = 0x2010;
  11134. t['i'] = 0x0069;
  11135. t['iacute'] = 0x00ED;
  11136. t['iacyrillic'] = 0x044F;
  11137. t['ibengali'] = 0x0987;
  11138. t['ibopomofo'] = 0x3127;
  11139. t['ibreve'] = 0x012D;
  11140. t['icaron'] = 0x01D0;
  11141. t['icircle'] = 0x24D8;
  11142. t['icircumflex'] = 0x00EE;
  11143. t['icyrillic'] = 0x0456;
  11144. t['idblgrave'] = 0x0209;
  11145. t['ideographearthcircle'] = 0x328F;
  11146. t['ideographfirecircle'] = 0x328B;
  11147. t['ideographicallianceparen'] = 0x323F;
  11148. t['ideographiccallparen'] = 0x323A;
  11149. t['ideographiccentrecircle'] = 0x32A5;
  11150. t['ideographicclose'] = 0x3006;
  11151. t['ideographiccomma'] = 0x3001;
  11152. t['ideographiccommaleft'] = 0xFF64;
  11153. t['ideographiccongratulationparen'] = 0x3237;
  11154. t['ideographiccorrectcircle'] = 0x32A3;
  11155. t['ideographicearthparen'] = 0x322F;
  11156. t['ideographicenterpriseparen'] = 0x323D;
  11157. t['ideographicexcellentcircle'] = 0x329D;
  11158. t['ideographicfestivalparen'] = 0x3240;
  11159. t['ideographicfinancialcircle'] = 0x3296;
  11160. t['ideographicfinancialparen'] = 0x3236;
  11161. t['ideographicfireparen'] = 0x322B;
  11162. t['ideographichaveparen'] = 0x3232;
  11163. t['ideographichighcircle'] = 0x32A4;
  11164. t['ideographiciterationmark'] = 0x3005;
  11165. t['ideographiclaborcircle'] = 0x3298;
  11166. t['ideographiclaborparen'] = 0x3238;
  11167. t['ideographicleftcircle'] = 0x32A7;
  11168. t['ideographiclowcircle'] = 0x32A6;
  11169. t['ideographicmedicinecircle'] = 0x32A9;
  11170. t['ideographicmetalparen'] = 0x322E;
  11171. t['ideographicmoonparen'] = 0x322A;
  11172. t['ideographicnameparen'] = 0x3234;
  11173. t['ideographicperiod'] = 0x3002;
  11174. t['ideographicprintcircle'] = 0x329E;
  11175. t['ideographicreachparen'] = 0x3243;
  11176. t['ideographicrepresentparen'] = 0x3239;
  11177. t['ideographicresourceparen'] = 0x323E;
  11178. t['ideographicrightcircle'] = 0x32A8;
  11179. t['ideographicsecretcircle'] = 0x3299;
  11180. t['ideographicselfparen'] = 0x3242;
  11181. t['ideographicsocietyparen'] = 0x3233;
  11182. t['ideographicspace'] = 0x3000;
  11183. t['ideographicspecialparen'] = 0x3235;
  11184. t['ideographicstockparen'] = 0x3231;
  11185. t['ideographicstudyparen'] = 0x323B;
  11186. t['ideographicsunparen'] = 0x3230;
  11187. t['ideographicsuperviseparen'] = 0x323C;
  11188. t['ideographicwaterparen'] = 0x322C;
  11189. t['ideographicwoodparen'] = 0x322D;
  11190. t['ideographiczero'] = 0x3007;
  11191. t['ideographmetalcircle'] = 0x328E;
  11192. t['ideographmooncircle'] = 0x328A;
  11193. t['ideographnamecircle'] = 0x3294;
  11194. t['ideographsuncircle'] = 0x3290;
  11195. t['ideographwatercircle'] = 0x328C;
  11196. t['ideographwoodcircle'] = 0x328D;
  11197. t['ideva'] = 0x0907;
  11198. t['idieresis'] = 0x00EF;
  11199. t['idieresisacute'] = 0x1E2F;
  11200. t['idieresiscyrillic'] = 0x04E5;
  11201. t['idotbelow'] = 0x1ECB;
  11202. t['iebrevecyrillic'] = 0x04D7;
  11203. t['iecyrillic'] = 0x0435;
  11204. t['ieungacirclekorean'] = 0x3275;
  11205. t['ieungaparenkorean'] = 0x3215;
  11206. t['ieungcirclekorean'] = 0x3267;
  11207. t['ieungkorean'] = 0x3147;
  11208. t['ieungparenkorean'] = 0x3207;
  11209. t['igrave'] = 0x00EC;
  11210. t['igujarati'] = 0x0A87;
  11211. t['igurmukhi'] = 0x0A07;
  11212. t['ihiragana'] = 0x3044;
  11213. t['ihookabove'] = 0x1EC9;
  11214. t['iibengali'] = 0x0988;
  11215. t['iicyrillic'] = 0x0438;
  11216. t['iideva'] = 0x0908;
  11217. t['iigujarati'] = 0x0A88;
  11218. t['iigurmukhi'] = 0x0A08;
  11219. t['iimatragurmukhi'] = 0x0A40;
  11220. t['iinvertedbreve'] = 0x020B;
  11221. t['iishortcyrillic'] = 0x0439;
  11222. t['iivowelsignbengali'] = 0x09C0;
  11223. t['iivowelsigndeva'] = 0x0940;
  11224. t['iivowelsigngujarati'] = 0x0AC0;
  11225. t['ij'] = 0x0133;
  11226. t['ikatakana'] = 0x30A4;
  11227. t['ikatakanahalfwidth'] = 0xFF72;
  11228. t['ikorean'] = 0x3163;
  11229. t['ilde'] = 0x02DC;
  11230. t['iluyhebrew'] = 0x05AC;
  11231. t['imacron'] = 0x012B;
  11232. t['imacroncyrillic'] = 0x04E3;
  11233. t['imageorapproximatelyequal'] = 0x2253;
  11234. t['imatragurmukhi'] = 0x0A3F;
  11235. t['imonospace'] = 0xFF49;
  11236. t['increment'] = 0x2206;
  11237. t['infinity'] = 0x221E;
  11238. t['iniarmenian'] = 0x056B;
  11239. t['integral'] = 0x222B;
  11240. t['integralbottom'] = 0x2321;
  11241. t['integralbt'] = 0x2321;
  11242. t['integralex'] = 0xF8F5;
  11243. t['integraltop'] = 0x2320;
  11244. t['integraltp'] = 0x2320;
  11245. t['intersection'] = 0x2229;
  11246. t['intisquare'] = 0x3305;
  11247. t['invbullet'] = 0x25D8;
  11248. t['invcircle'] = 0x25D9;
  11249. t['invsmileface'] = 0x263B;
  11250. t['iocyrillic'] = 0x0451;
  11251. t['iogonek'] = 0x012F;
  11252. t['iota'] = 0x03B9;
  11253. t['iotadieresis'] = 0x03CA;
  11254. t['iotadieresistonos'] = 0x0390;
  11255. t['iotalatin'] = 0x0269;
  11256. t['iotatonos'] = 0x03AF;
  11257. t['iparen'] = 0x24A4;
  11258. t['irigurmukhi'] = 0x0A72;
  11259. t['ismallhiragana'] = 0x3043;
  11260. t['ismallkatakana'] = 0x30A3;
  11261. t['ismallkatakanahalfwidth'] = 0xFF68;
  11262. t['issharbengali'] = 0x09FA;
  11263. t['istroke'] = 0x0268;
  11264. t['isuperior'] = 0xF6ED;
  11265. t['iterationhiragana'] = 0x309D;
  11266. t['iterationkatakana'] = 0x30FD;
  11267. t['itilde'] = 0x0129;
  11268. t['itildebelow'] = 0x1E2D;
  11269. t['iubopomofo'] = 0x3129;
  11270. t['iucyrillic'] = 0x044E;
  11271. t['ivowelsignbengali'] = 0x09BF;
  11272. t['ivowelsigndeva'] = 0x093F;
  11273. t['ivowelsigngujarati'] = 0x0ABF;
  11274. t['izhitsacyrillic'] = 0x0475;
  11275. t['izhitsadblgravecyrillic'] = 0x0477;
  11276. t['j'] = 0x006A;
  11277. t['jaarmenian'] = 0x0571;
  11278. t['jabengali'] = 0x099C;
  11279. t['jadeva'] = 0x091C;
  11280. t['jagujarati'] = 0x0A9C;
  11281. t['jagurmukhi'] = 0x0A1C;
  11282. t['jbopomofo'] = 0x3110;
  11283. t['jcaron'] = 0x01F0;
  11284. t['jcircle'] = 0x24D9;
  11285. t['jcircumflex'] = 0x0135;
  11286. t['jcrossedtail'] = 0x029D;
  11287. t['jdotlessstroke'] = 0x025F;
  11288. t['jecyrillic'] = 0x0458;
  11289. t['jeemarabic'] = 0x062C;
  11290. t['jeemfinalarabic'] = 0xFE9E;
  11291. t['jeeminitialarabic'] = 0xFE9F;
  11292. t['jeemmedialarabic'] = 0xFEA0;
  11293. t['jeharabic'] = 0x0698;
  11294. t['jehfinalarabic'] = 0xFB8B;
  11295. t['jhabengali'] = 0x099D;
  11296. t['jhadeva'] = 0x091D;
  11297. t['jhagujarati'] = 0x0A9D;
  11298. t['jhagurmukhi'] = 0x0A1D;
  11299. t['jheharmenian'] = 0x057B;
  11300. t['jis'] = 0x3004;
  11301. t['jmonospace'] = 0xFF4A;
  11302. t['jparen'] = 0x24A5;
  11303. t['jsuperior'] = 0x02B2;
  11304. t['k'] = 0x006B;
  11305. t['kabashkircyrillic'] = 0x04A1;
  11306. t['kabengali'] = 0x0995;
  11307. t['kacute'] = 0x1E31;
  11308. t['kacyrillic'] = 0x043A;
  11309. t['kadescendercyrillic'] = 0x049B;
  11310. t['kadeva'] = 0x0915;
  11311. t['kaf'] = 0x05DB;
  11312. t['kafarabic'] = 0x0643;
  11313. t['kafdagesh'] = 0xFB3B;
  11314. t['kafdageshhebrew'] = 0xFB3B;
  11315. t['kaffinalarabic'] = 0xFEDA;
  11316. t['kafhebrew'] = 0x05DB;
  11317. t['kafinitialarabic'] = 0xFEDB;
  11318. t['kafmedialarabic'] = 0xFEDC;
  11319. t['kafrafehebrew'] = 0xFB4D;
  11320. t['kagujarati'] = 0x0A95;
  11321. t['kagurmukhi'] = 0x0A15;
  11322. t['kahiragana'] = 0x304B;
  11323. t['kahookcyrillic'] = 0x04C4;
  11324. t['kakatakana'] = 0x30AB;
  11325. t['kakatakanahalfwidth'] = 0xFF76;
  11326. t['kappa'] = 0x03BA;
  11327. t['kappasymbolgreek'] = 0x03F0;
  11328. t['kapyeounmieumkorean'] = 0x3171;
  11329. t['kapyeounphieuphkorean'] = 0x3184;
  11330. t['kapyeounpieupkorean'] = 0x3178;
  11331. t['kapyeounssangpieupkorean'] = 0x3179;
  11332. t['karoriisquare'] = 0x330D;
  11333. t['kashidaautoarabic'] = 0x0640;
  11334. t['kashidaautonosidebearingarabic'] = 0x0640;
  11335. t['kasmallkatakana'] = 0x30F5;
  11336. t['kasquare'] = 0x3384;
  11337. t['kasraarabic'] = 0x0650;
  11338. t['kasratanarabic'] = 0x064D;
  11339. t['kastrokecyrillic'] = 0x049F;
  11340. t['katahiraprolongmarkhalfwidth'] = 0xFF70;
  11341. t['kaverticalstrokecyrillic'] = 0x049D;
  11342. t['kbopomofo'] = 0x310E;
  11343. t['kcalsquare'] = 0x3389;
  11344. t['kcaron'] = 0x01E9;
  11345. t['kcedilla'] = 0x0137;
  11346. t['kcircle'] = 0x24DA;
  11347. t['kcommaaccent'] = 0x0137;
  11348. t['kdotbelow'] = 0x1E33;
  11349. t['keharmenian'] = 0x0584;
  11350. t['kehiragana'] = 0x3051;
  11351. t['kekatakana'] = 0x30B1;
  11352. t['kekatakanahalfwidth'] = 0xFF79;
  11353. t['kenarmenian'] = 0x056F;
  11354. t['kesmallkatakana'] = 0x30F6;
  11355. t['kgreenlandic'] = 0x0138;
  11356. t['khabengali'] = 0x0996;
  11357. t['khacyrillic'] = 0x0445;
  11358. t['khadeva'] = 0x0916;
  11359. t['khagujarati'] = 0x0A96;
  11360. t['khagurmukhi'] = 0x0A16;
  11361. t['khaharabic'] = 0x062E;
  11362. t['khahfinalarabic'] = 0xFEA6;
  11363. t['khahinitialarabic'] = 0xFEA7;
  11364. t['khahmedialarabic'] = 0xFEA8;
  11365. t['kheicoptic'] = 0x03E7;
  11366. t['khhadeva'] = 0x0959;
  11367. t['khhagurmukhi'] = 0x0A59;
  11368. t['khieukhacirclekorean'] = 0x3278;
  11369. t['khieukhaparenkorean'] = 0x3218;
  11370. t['khieukhcirclekorean'] = 0x326A;
  11371. t['khieukhkorean'] = 0x314B;
  11372. t['khieukhparenkorean'] = 0x320A;
  11373. t['khokhaithai'] = 0x0E02;
  11374. t['khokhonthai'] = 0x0E05;
  11375. t['khokhuatthai'] = 0x0E03;
  11376. t['khokhwaithai'] = 0x0E04;
  11377. t['khomutthai'] = 0x0E5B;
  11378. t['khook'] = 0x0199;
  11379. t['khorakhangthai'] = 0x0E06;
  11380. t['khzsquare'] = 0x3391;
  11381. t['kihiragana'] = 0x304D;
  11382. t['kikatakana'] = 0x30AD;
  11383. t['kikatakanahalfwidth'] = 0xFF77;
  11384. t['kiroguramusquare'] = 0x3315;
  11385. t['kiromeetorusquare'] = 0x3316;
  11386. t['kirosquare'] = 0x3314;
  11387. t['kiyeokacirclekorean'] = 0x326E;
  11388. t['kiyeokaparenkorean'] = 0x320E;
  11389. t['kiyeokcirclekorean'] = 0x3260;
  11390. t['kiyeokkorean'] = 0x3131;
  11391. t['kiyeokparenkorean'] = 0x3200;
  11392. t['kiyeoksioskorean'] = 0x3133;
  11393. t['kjecyrillic'] = 0x045C;
  11394. t['klinebelow'] = 0x1E35;
  11395. t['klsquare'] = 0x3398;
  11396. t['kmcubedsquare'] = 0x33A6;
  11397. t['kmonospace'] = 0xFF4B;
  11398. t['kmsquaredsquare'] = 0x33A2;
  11399. t['kohiragana'] = 0x3053;
  11400. t['kohmsquare'] = 0x33C0;
  11401. t['kokaithai'] = 0x0E01;
  11402. t['kokatakana'] = 0x30B3;
  11403. t['kokatakanahalfwidth'] = 0xFF7A;
  11404. t['kooposquare'] = 0x331E;
  11405. t['koppacyrillic'] = 0x0481;
  11406. t['koreanstandardsymbol'] = 0x327F;
  11407. t['koroniscmb'] = 0x0343;
  11408. t['kparen'] = 0x24A6;
  11409. t['kpasquare'] = 0x33AA;
  11410. t['ksicyrillic'] = 0x046F;
  11411. t['ktsquare'] = 0x33CF;
  11412. t['kturned'] = 0x029E;
  11413. t['kuhiragana'] = 0x304F;
  11414. t['kukatakana'] = 0x30AF;
  11415. t['kukatakanahalfwidth'] = 0xFF78;
  11416. t['kvsquare'] = 0x33B8;
  11417. t['kwsquare'] = 0x33BE;
  11418. t['l'] = 0x006C;
  11419. t['labengali'] = 0x09B2;
  11420. t['lacute'] = 0x013A;
  11421. t['ladeva'] = 0x0932;
  11422. t['lagujarati'] = 0x0AB2;
  11423. t['lagurmukhi'] = 0x0A32;
  11424. t['lakkhangyaothai'] = 0x0E45;
  11425. t['lamaleffinalarabic'] = 0xFEFC;
  11426. t['lamalefhamzaabovefinalarabic'] = 0xFEF8;
  11427. t['lamalefhamzaaboveisolatedarabic'] = 0xFEF7;
  11428. t['lamalefhamzabelowfinalarabic'] = 0xFEFA;
  11429. t['lamalefhamzabelowisolatedarabic'] = 0xFEF9;
  11430. t['lamalefisolatedarabic'] = 0xFEFB;
  11431. t['lamalefmaddaabovefinalarabic'] = 0xFEF6;
  11432. t['lamalefmaddaaboveisolatedarabic'] = 0xFEF5;
  11433. t['lamarabic'] = 0x0644;
  11434. t['lambda'] = 0x03BB;
  11435. t['lambdastroke'] = 0x019B;
  11436. t['lamed'] = 0x05DC;
  11437. t['lameddagesh'] = 0xFB3C;
  11438. t['lameddageshhebrew'] = 0xFB3C;
  11439. t['lamedhebrew'] = 0x05DC;
  11440. t['lamfinalarabic'] = 0xFEDE;
  11441. t['lamhahinitialarabic'] = 0xFCCA;
  11442. t['laminitialarabic'] = 0xFEDF;
  11443. t['lamjeeminitialarabic'] = 0xFCC9;
  11444. t['lamkhahinitialarabic'] = 0xFCCB;
  11445. t['lamlamhehisolatedarabic'] = 0xFDF2;
  11446. t['lammedialarabic'] = 0xFEE0;
  11447. t['lammeemhahinitialarabic'] = 0xFD88;
  11448. t['lammeeminitialarabic'] = 0xFCCC;
  11449. t['largecircle'] = 0x25EF;
  11450. t['lbar'] = 0x019A;
  11451. t['lbelt'] = 0x026C;
  11452. t['lbopomofo'] = 0x310C;
  11453. t['lcaron'] = 0x013E;
  11454. t['lcedilla'] = 0x013C;
  11455. t['lcircle'] = 0x24DB;
  11456. t['lcircumflexbelow'] = 0x1E3D;
  11457. t['lcommaaccent'] = 0x013C;
  11458. t['ldot'] = 0x0140;
  11459. t['ldotaccent'] = 0x0140;
  11460. t['ldotbelow'] = 0x1E37;
  11461. t['ldotbelowmacron'] = 0x1E39;
  11462. t['leftangleabovecmb'] = 0x031A;
  11463. t['lefttackbelowcmb'] = 0x0318;
  11464. t['less'] = 0x003C;
  11465. t['lessequal'] = 0x2264;
  11466. t['lessequalorgreater'] = 0x22DA;
  11467. t['lessmonospace'] = 0xFF1C;
  11468. t['lessorequivalent'] = 0x2272;
  11469. t['lessorgreater'] = 0x2276;
  11470. t['lessoverequal'] = 0x2266;
  11471. t['lesssmall'] = 0xFE64;
  11472. t['lezh'] = 0x026E;
  11473. t['lfblock'] = 0x258C;
  11474. t['lhookretroflex'] = 0x026D;
  11475. t['lira'] = 0x20A4;
  11476. t['liwnarmenian'] = 0x056C;
  11477. t['lj'] = 0x01C9;
  11478. t['ljecyrillic'] = 0x0459;
  11479. t['ll'] = 0xF6C0;
  11480. t['lladeva'] = 0x0933;
  11481. t['llagujarati'] = 0x0AB3;
  11482. t['llinebelow'] = 0x1E3B;
  11483. t['llladeva'] = 0x0934;
  11484. t['llvocalicbengali'] = 0x09E1;
  11485. t['llvocalicdeva'] = 0x0961;
  11486. t['llvocalicvowelsignbengali'] = 0x09E3;
  11487. t['llvocalicvowelsigndeva'] = 0x0963;
  11488. t['lmiddletilde'] = 0x026B;
  11489. t['lmonospace'] = 0xFF4C;
  11490. t['lmsquare'] = 0x33D0;
  11491. t['lochulathai'] = 0x0E2C;
  11492. t['logicaland'] = 0x2227;
  11493. t['logicalnot'] = 0x00AC;
  11494. t['logicalnotreversed'] = 0x2310;
  11495. t['logicalor'] = 0x2228;
  11496. t['lolingthai'] = 0x0E25;
  11497. t['longs'] = 0x017F;
  11498. t['lowlinecenterline'] = 0xFE4E;
  11499. t['lowlinecmb'] = 0x0332;
  11500. t['lowlinedashed'] = 0xFE4D;
  11501. t['lozenge'] = 0x25CA;
  11502. t['lparen'] = 0x24A7;
  11503. t['lslash'] = 0x0142;
  11504. t['lsquare'] = 0x2113;
  11505. t['lsuperior'] = 0xF6EE;
  11506. t['ltshade'] = 0x2591;
  11507. t['luthai'] = 0x0E26;
  11508. t['lvocalicbengali'] = 0x098C;
  11509. t['lvocalicdeva'] = 0x090C;
  11510. t['lvocalicvowelsignbengali'] = 0x09E2;
  11511. t['lvocalicvowelsigndeva'] = 0x0962;
  11512. t['lxsquare'] = 0x33D3;
  11513. t['m'] = 0x006D;
  11514. t['mabengali'] = 0x09AE;
  11515. t['macron'] = 0x00AF;
  11516. t['macronbelowcmb'] = 0x0331;
  11517. t['macroncmb'] = 0x0304;
  11518. t['macronlowmod'] = 0x02CD;
  11519. t['macronmonospace'] = 0xFFE3;
  11520. t['macute'] = 0x1E3F;
  11521. t['madeva'] = 0x092E;
  11522. t['magujarati'] = 0x0AAE;
  11523. t['magurmukhi'] = 0x0A2E;
  11524. t['mahapakhhebrew'] = 0x05A4;
  11525. t['mahapakhlefthebrew'] = 0x05A4;
  11526. t['mahiragana'] = 0x307E;
  11527. t['maichattawalowleftthai'] = 0xF895;
  11528. t['maichattawalowrightthai'] = 0xF894;
  11529. t['maichattawathai'] = 0x0E4B;
  11530. t['maichattawaupperleftthai'] = 0xF893;
  11531. t['maieklowleftthai'] = 0xF88C;
  11532. t['maieklowrightthai'] = 0xF88B;
  11533. t['maiekthai'] = 0x0E48;
  11534. t['maiekupperleftthai'] = 0xF88A;
  11535. t['maihanakatleftthai'] = 0xF884;
  11536. t['maihanakatthai'] = 0x0E31;
  11537. t['maitaikhuleftthai'] = 0xF889;
  11538. t['maitaikhuthai'] = 0x0E47;
  11539. t['maitholowleftthai'] = 0xF88F;
  11540. t['maitholowrightthai'] = 0xF88E;
  11541. t['maithothai'] = 0x0E49;
  11542. t['maithoupperleftthai'] = 0xF88D;
  11543. t['maitrilowleftthai'] = 0xF892;
  11544. t['maitrilowrightthai'] = 0xF891;
  11545. t['maitrithai'] = 0x0E4A;
  11546. t['maitriupperleftthai'] = 0xF890;
  11547. t['maiyamokthai'] = 0x0E46;
  11548. t['makatakana'] = 0x30DE;
  11549. t['makatakanahalfwidth'] = 0xFF8F;
  11550. t['male'] = 0x2642;
  11551. t['mansyonsquare'] = 0x3347;
  11552. t['maqafhebrew'] = 0x05BE;
  11553. t['mars'] = 0x2642;
  11554. t['masoracirclehebrew'] = 0x05AF;
  11555. t['masquare'] = 0x3383;
  11556. t['mbopomofo'] = 0x3107;
  11557. t['mbsquare'] = 0x33D4;
  11558. t['mcircle'] = 0x24DC;
  11559. t['mcubedsquare'] = 0x33A5;
  11560. t['mdotaccent'] = 0x1E41;
  11561. t['mdotbelow'] = 0x1E43;
  11562. t['meemarabic'] = 0x0645;
  11563. t['meemfinalarabic'] = 0xFEE2;
  11564. t['meeminitialarabic'] = 0xFEE3;
  11565. t['meemmedialarabic'] = 0xFEE4;
  11566. t['meemmeeminitialarabic'] = 0xFCD1;
  11567. t['meemmeemisolatedarabic'] = 0xFC48;
  11568. t['meetorusquare'] = 0x334D;
  11569. t['mehiragana'] = 0x3081;
  11570. t['meizierasquare'] = 0x337E;
  11571. t['mekatakana'] = 0x30E1;
  11572. t['mekatakanahalfwidth'] = 0xFF92;
  11573. t['mem'] = 0x05DE;
  11574. t['memdagesh'] = 0xFB3E;
  11575. t['memdageshhebrew'] = 0xFB3E;
  11576. t['memhebrew'] = 0x05DE;
  11577. t['menarmenian'] = 0x0574;
  11578. t['merkhahebrew'] = 0x05A5;
  11579. t['merkhakefulahebrew'] = 0x05A6;
  11580. t['merkhakefulalefthebrew'] = 0x05A6;
  11581. t['merkhalefthebrew'] = 0x05A5;
  11582. t['mhook'] = 0x0271;
  11583. t['mhzsquare'] = 0x3392;
  11584. t['middledotkatakanahalfwidth'] = 0xFF65;
  11585. t['middot'] = 0x00B7;
  11586. t['mieumacirclekorean'] = 0x3272;
  11587. t['mieumaparenkorean'] = 0x3212;
  11588. t['mieumcirclekorean'] = 0x3264;
  11589. t['mieumkorean'] = 0x3141;
  11590. t['mieumpansioskorean'] = 0x3170;
  11591. t['mieumparenkorean'] = 0x3204;
  11592. t['mieumpieupkorean'] = 0x316E;
  11593. t['mieumsioskorean'] = 0x316F;
  11594. t['mihiragana'] = 0x307F;
  11595. t['mikatakana'] = 0x30DF;
  11596. t['mikatakanahalfwidth'] = 0xFF90;
  11597. t['minus'] = 0x2212;
  11598. t['minusbelowcmb'] = 0x0320;
  11599. t['minuscircle'] = 0x2296;
  11600. t['minusmod'] = 0x02D7;
  11601. t['minusplus'] = 0x2213;
  11602. t['minute'] = 0x2032;
  11603. t['miribaarusquare'] = 0x334A;
  11604. t['mirisquare'] = 0x3349;
  11605. t['mlonglegturned'] = 0x0270;
  11606. t['mlsquare'] = 0x3396;
  11607. t['mmcubedsquare'] = 0x33A3;
  11608. t['mmonospace'] = 0xFF4D;
  11609. t['mmsquaredsquare'] = 0x339F;
  11610. t['mohiragana'] = 0x3082;
  11611. t['mohmsquare'] = 0x33C1;
  11612. t['mokatakana'] = 0x30E2;
  11613. t['mokatakanahalfwidth'] = 0xFF93;
  11614. t['molsquare'] = 0x33D6;
  11615. t['momathai'] = 0x0E21;
  11616. t['moverssquare'] = 0x33A7;
  11617. t['moverssquaredsquare'] = 0x33A8;
  11618. t['mparen'] = 0x24A8;
  11619. t['mpasquare'] = 0x33AB;
  11620. t['mssquare'] = 0x33B3;
  11621. t['msuperior'] = 0xF6EF;
  11622. t['mturned'] = 0x026F;
  11623. t['mu'] = 0x00B5;
  11624. t['mu1'] = 0x00B5;
  11625. t['muasquare'] = 0x3382;
  11626. t['muchgreater'] = 0x226B;
  11627. t['muchless'] = 0x226A;
  11628. t['mufsquare'] = 0x338C;
  11629. t['mugreek'] = 0x03BC;
  11630. t['mugsquare'] = 0x338D;
  11631. t['muhiragana'] = 0x3080;
  11632. t['mukatakana'] = 0x30E0;
  11633. t['mukatakanahalfwidth'] = 0xFF91;
  11634. t['mulsquare'] = 0x3395;
  11635. t['multiply'] = 0x00D7;
  11636. t['mumsquare'] = 0x339B;
  11637. t['munahhebrew'] = 0x05A3;
  11638. t['munahlefthebrew'] = 0x05A3;
  11639. t['musicalnote'] = 0x266A;
  11640. t['musicalnotedbl'] = 0x266B;
  11641. t['musicflatsign'] = 0x266D;
  11642. t['musicsharpsign'] = 0x266F;
  11643. t['mussquare'] = 0x33B2;
  11644. t['muvsquare'] = 0x33B6;
  11645. t['muwsquare'] = 0x33BC;
  11646. t['mvmegasquare'] = 0x33B9;
  11647. t['mvsquare'] = 0x33B7;
  11648. t['mwmegasquare'] = 0x33BF;
  11649. t['mwsquare'] = 0x33BD;
  11650. t['n'] = 0x006E;
  11651. t['nabengali'] = 0x09A8;
  11652. t['nabla'] = 0x2207;
  11653. t['nacute'] = 0x0144;
  11654. t['nadeva'] = 0x0928;
  11655. t['nagujarati'] = 0x0AA8;
  11656. t['nagurmukhi'] = 0x0A28;
  11657. t['nahiragana'] = 0x306A;
  11658. t['nakatakana'] = 0x30CA;
  11659. t['nakatakanahalfwidth'] = 0xFF85;
  11660. t['napostrophe'] = 0x0149;
  11661. t['nasquare'] = 0x3381;
  11662. t['nbopomofo'] = 0x310B;
  11663. t['nbspace'] = 0x00A0;
  11664. t['ncaron'] = 0x0148;
  11665. t['ncedilla'] = 0x0146;
  11666. t['ncircle'] = 0x24DD;
  11667. t['ncircumflexbelow'] = 0x1E4B;
  11668. t['ncommaaccent'] = 0x0146;
  11669. t['ndotaccent'] = 0x1E45;
  11670. t['ndotbelow'] = 0x1E47;
  11671. t['nehiragana'] = 0x306D;
  11672. t['nekatakana'] = 0x30CD;
  11673. t['nekatakanahalfwidth'] = 0xFF88;
  11674. t['newsheqelsign'] = 0x20AA;
  11675. t['nfsquare'] = 0x338B;
  11676. t['ngabengali'] = 0x0999;
  11677. t['ngadeva'] = 0x0919;
  11678. t['ngagujarati'] = 0x0A99;
  11679. t['ngagurmukhi'] = 0x0A19;
  11680. t['ngonguthai'] = 0x0E07;
  11681. t['nhiragana'] = 0x3093;
  11682. t['nhookleft'] = 0x0272;
  11683. t['nhookretroflex'] = 0x0273;
  11684. t['nieunacirclekorean'] = 0x326F;
  11685. t['nieunaparenkorean'] = 0x320F;
  11686. t['nieuncieuckorean'] = 0x3135;
  11687. t['nieuncirclekorean'] = 0x3261;
  11688. t['nieunhieuhkorean'] = 0x3136;
  11689. t['nieunkorean'] = 0x3134;
  11690. t['nieunpansioskorean'] = 0x3168;
  11691. t['nieunparenkorean'] = 0x3201;
  11692. t['nieunsioskorean'] = 0x3167;
  11693. t['nieuntikeutkorean'] = 0x3166;
  11694. t['nihiragana'] = 0x306B;
  11695. t['nikatakana'] = 0x30CB;
  11696. t['nikatakanahalfwidth'] = 0xFF86;
  11697. t['nikhahitleftthai'] = 0xF899;
  11698. t['nikhahitthai'] = 0x0E4D;
  11699. t['nine'] = 0x0039;
  11700. t['ninearabic'] = 0x0669;
  11701. t['ninebengali'] = 0x09EF;
  11702. t['ninecircle'] = 0x2468;
  11703. t['ninecircleinversesansserif'] = 0x2792;
  11704. t['ninedeva'] = 0x096F;
  11705. t['ninegujarati'] = 0x0AEF;
  11706. t['ninegurmukhi'] = 0x0A6F;
  11707. t['ninehackarabic'] = 0x0669;
  11708. t['ninehangzhou'] = 0x3029;
  11709. t['nineideographicparen'] = 0x3228;
  11710. t['nineinferior'] = 0x2089;
  11711. t['ninemonospace'] = 0xFF19;
  11712. t['nineoldstyle'] = 0xF739;
  11713. t['nineparen'] = 0x247C;
  11714. t['nineperiod'] = 0x2490;
  11715. t['ninepersian'] = 0x06F9;
  11716. t['nineroman'] = 0x2178;
  11717. t['ninesuperior'] = 0x2079;
  11718. t['nineteencircle'] = 0x2472;
  11719. t['nineteenparen'] = 0x2486;
  11720. t['nineteenperiod'] = 0x249A;
  11721. t['ninethai'] = 0x0E59;
  11722. t['nj'] = 0x01CC;
  11723. t['njecyrillic'] = 0x045A;
  11724. t['nkatakana'] = 0x30F3;
  11725. t['nkatakanahalfwidth'] = 0xFF9D;
  11726. t['nlegrightlong'] = 0x019E;
  11727. t['nlinebelow'] = 0x1E49;
  11728. t['nmonospace'] = 0xFF4E;
  11729. t['nmsquare'] = 0x339A;
  11730. t['nnabengali'] = 0x09A3;
  11731. t['nnadeva'] = 0x0923;
  11732. t['nnagujarati'] = 0x0AA3;
  11733. t['nnagurmukhi'] = 0x0A23;
  11734. t['nnnadeva'] = 0x0929;
  11735. t['nohiragana'] = 0x306E;
  11736. t['nokatakana'] = 0x30CE;
  11737. t['nokatakanahalfwidth'] = 0xFF89;
  11738. t['nonbreakingspace'] = 0x00A0;
  11739. t['nonenthai'] = 0x0E13;
  11740. t['nonuthai'] = 0x0E19;
  11741. t['noonarabic'] = 0x0646;
  11742. t['noonfinalarabic'] = 0xFEE6;
  11743. t['noonghunnaarabic'] = 0x06BA;
  11744. t['noonghunnafinalarabic'] = 0xFB9F;
  11745. t['nooninitialarabic'] = 0xFEE7;
  11746. t['noonjeeminitialarabic'] = 0xFCD2;
  11747. t['noonjeemisolatedarabic'] = 0xFC4B;
  11748. t['noonmedialarabic'] = 0xFEE8;
  11749. t['noonmeeminitialarabic'] = 0xFCD5;
  11750. t['noonmeemisolatedarabic'] = 0xFC4E;
  11751. t['noonnoonfinalarabic'] = 0xFC8D;
  11752. t['notcontains'] = 0x220C;
  11753. t['notelement'] = 0x2209;
  11754. t['notelementof'] = 0x2209;
  11755. t['notequal'] = 0x2260;
  11756. t['notgreater'] = 0x226F;
  11757. t['notgreaternorequal'] = 0x2271;
  11758. t['notgreaternorless'] = 0x2279;
  11759. t['notidentical'] = 0x2262;
  11760. t['notless'] = 0x226E;
  11761. t['notlessnorequal'] = 0x2270;
  11762. t['notparallel'] = 0x2226;
  11763. t['notprecedes'] = 0x2280;
  11764. t['notsubset'] = 0x2284;
  11765. t['notsucceeds'] = 0x2281;
  11766. t['notsuperset'] = 0x2285;
  11767. t['nowarmenian'] = 0x0576;
  11768. t['nparen'] = 0x24A9;
  11769. t['nssquare'] = 0x33B1;
  11770. t['nsuperior'] = 0x207F;
  11771. t['ntilde'] = 0x00F1;
  11772. t['nu'] = 0x03BD;
  11773. t['nuhiragana'] = 0x306C;
  11774. t['nukatakana'] = 0x30CC;
  11775. t['nukatakanahalfwidth'] = 0xFF87;
  11776. t['nuktabengali'] = 0x09BC;
  11777. t['nuktadeva'] = 0x093C;
  11778. t['nuktagujarati'] = 0x0ABC;
  11779. t['nuktagurmukhi'] = 0x0A3C;
  11780. t['numbersign'] = 0x0023;
  11781. t['numbersignmonospace'] = 0xFF03;
  11782. t['numbersignsmall'] = 0xFE5F;
  11783. t['numeralsigngreek'] = 0x0374;
  11784. t['numeralsignlowergreek'] = 0x0375;
  11785. t['numero'] = 0x2116;
  11786. t['nun'] = 0x05E0;
  11787. t['nundagesh'] = 0xFB40;
  11788. t['nundageshhebrew'] = 0xFB40;
  11789. t['nunhebrew'] = 0x05E0;
  11790. t['nvsquare'] = 0x33B5;
  11791. t['nwsquare'] = 0x33BB;
  11792. t['nyabengali'] = 0x099E;
  11793. t['nyadeva'] = 0x091E;
  11794. t['nyagujarati'] = 0x0A9E;
  11795. t['nyagurmukhi'] = 0x0A1E;
  11796. t['o'] = 0x006F;
  11797. t['oacute'] = 0x00F3;
  11798. t['oangthai'] = 0x0E2D;
  11799. t['obarred'] = 0x0275;
  11800. t['obarredcyrillic'] = 0x04E9;
  11801. t['obarreddieresiscyrillic'] = 0x04EB;
  11802. t['obengali'] = 0x0993;
  11803. t['obopomofo'] = 0x311B;
  11804. t['obreve'] = 0x014F;
  11805. t['ocandradeva'] = 0x0911;
  11806. t['ocandragujarati'] = 0x0A91;
  11807. t['ocandravowelsigndeva'] = 0x0949;
  11808. t['ocandravowelsigngujarati'] = 0x0AC9;
  11809. t['ocaron'] = 0x01D2;
  11810. t['ocircle'] = 0x24DE;
  11811. t['ocircumflex'] = 0x00F4;
  11812. t['ocircumflexacute'] = 0x1ED1;
  11813. t['ocircumflexdotbelow'] = 0x1ED9;
  11814. t['ocircumflexgrave'] = 0x1ED3;
  11815. t['ocircumflexhookabove'] = 0x1ED5;
  11816. t['ocircumflextilde'] = 0x1ED7;
  11817. t['ocyrillic'] = 0x043E;
  11818. t['odblacute'] = 0x0151;
  11819. t['odblgrave'] = 0x020D;
  11820. t['odeva'] = 0x0913;
  11821. t['odieresis'] = 0x00F6;
  11822. t['odieresiscyrillic'] = 0x04E7;
  11823. t['odotbelow'] = 0x1ECD;
  11824. t['oe'] = 0x0153;
  11825. t['oekorean'] = 0x315A;
  11826. t['ogonek'] = 0x02DB;
  11827. t['ogonekcmb'] = 0x0328;
  11828. t['ograve'] = 0x00F2;
  11829. t['ogujarati'] = 0x0A93;
  11830. t['oharmenian'] = 0x0585;
  11831. t['ohiragana'] = 0x304A;
  11832. t['ohookabove'] = 0x1ECF;
  11833. t['ohorn'] = 0x01A1;
  11834. t['ohornacute'] = 0x1EDB;
  11835. t['ohorndotbelow'] = 0x1EE3;
  11836. t['ohorngrave'] = 0x1EDD;
  11837. t['ohornhookabove'] = 0x1EDF;
  11838. t['ohorntilde'] = 0x1EE1;
  11839. t['ohungarumlaut'] = 0x0151;
  11840. t['oi'] = 0x01A3;
  11841. t['oinvertedbreve'] = 0x020F;
  11842. t['okatakana'] = 0x30AA;
  11843. t['okatakanahalfwidth'] = 0xFF75;
  11844. t['okorean'] = 0x3157;
  11845. t['olehebrew'] = 0x05AB;
  11846. t['omacron'] = 0x014D;
  11847. t['omacronacute'] = 0x1E53;
  11848. t['omacrongrave'] = 0x1E51;
  11849. t['omdeva'] = 0x0950;
  11850. t['omega'] = 0x03C9;
  11851. t['omega1'] = 0x03D6;
  11852. t['omegacyrillic'] = 0x0461;
  11853. t['omegalatinclosed'] = 0x0277;
  11854. t['omegaroundcyrillic'] = 0x047B;
  11855. t['omegatitlocyrillic'] = 0x047D;
  11856. t['omegatonos'] = 0x03CE;
  11857. t['omgujarati'] = 0x0AD0;
  11858. t['omicron'] = 0x03BF;
  11859. t['omicrontonos'] = 0x03CC;
  11860. t['omonospace'] = 0xFF4F;
  11861. t['one'] = 0x0031;
  11862. t['onearabic'] = 0x0661;
  11863. t['onebengali'] = 0x09E7;
  11864. t['onecircle'] = 0x2460;
  11865. t['onecircleinversesansserif'] = 0x278A;
  11866. t['onedeva'] = 0x0967;
  11867. t['onedotenleader'] = 0x2024;
  11868. t['oneeighth'] = 0x215B;
  11869. t['onefitted'] = 0xF6DC;
  11870. t['onegujarati'] = 0x0AE7;
  11871. t['onegurmukhi'] = 0x0A67;
  11872. t['onehackarabic'] = 0x0661;
  11873. t['onehalf'] = 0x00BD;
  11874. t['onehangzhou'] = 0x3021;
  11875. t['oneideographicparen'] = 0x3220;
  11876. t['oneinferior'] = 0x2081;
  11877. t['onemonospace'] = 0xFF11;
  11878. t['onenumeratorbengali'] = 0x09F4;
  11879. t['oneoldstyle'] = 0xF731;
  11880. t['oneparen'] = 0x2474;
  11881. t['oneperiod'] = 0x2488;
  11882. t['onepersian'] = 0x06F1;
  11883. t['onequarter'] = 0x00BC;
  11884. t['oneroman'] = 0x2170;
  11885. t['onesuperior'] = 0x00B9;
  11886. t['onethai'] = 0x0E51;
  11887. t['onethird'] = 0x2153;
  11888. t['oogonek'] = 0x01EB;
  11889. t['oogonekmacron'] = 0x01ED;
  11890. t['oogurmukhi'] = 0x0A13;
  11891. t['oomatragurmukhi'] = 0x0A4B;
  11892. t['oopen'] = 0x0254;
  11893. t['oparen'] = 0x24AA;
  11894. t['openbullet'] = 0x25E6;
  11895. t['option'] = 0x2325;
  11896. t['ordfeminine'] = 0x00AA;
  11897. t['ordmasculine'] = 0x00BA;
  11898. t['orthogonal'] = 0x221F;
  11899. t['oshortdeva'] = 0x0912;
  11900. t['oshortvowelsigndeva'] = 0x094A;
  11901. t['oslash'] = 0x00F8;
  11902. t['oslashacute'] = 0x01FF;
  11903. t['osmallhiragana'] = 0x3049;
  11904. t['osmallkatakana'] = 0x30A9;
  11905. t['osmallkatakanahalfwidth'] = 0xFF6B;
  11906. t['ostrokeacute'] = 0x01FF;
  11907. t['osuperior'] = 0xF6F0;
  11908. t['otcyrillic'] = 0x047F;
  11909. t['otilde'] = 0x00F5;
  11910. t['otildeacute'] = 0x1E4D;
  11911. t['otildedieresis'] = 0x1E4F;
  11912. t['oubopomofo'] = 0x3121;
  11913. t['overline'] = 0x203E;
  11914. t['overlinecenterline'] = 0xFE4A;
  11915. t['overlinecmb'] = 0x0305;
  11916. t['overlinedashed'] = 0xFE49;
  11917. t['overlinedblwavy'] = 0xFE4C;
  11918. t['overlinewavy'] = 0xFE4B;
  11919. t['overscore'] = 0x00AF;
  11920. t['ovowelsignbengali'] = 0x09CB;
  11921. t['ovowelsigndeva'] = 0x094B;
  11922. t['ovowelsigngujarati'] = 0x0ACB;
  11923. t['p'] = 0x0070;
  11924. t['paampssquare'] = 0x3380;
  11925. t['paasentosquare'] = 0x332B;
  11926. t['pabengali'] = 0x09AA;
  11927. t['pacute'] = 0x1E55;
  11928. t['padeva'] = 0x092A;
  11929. t['pagedown'] = 0x21DF;
  11930. t['pageup'] = 0x21DE;
  11931. t['pagujarati'] = 0x0AAA;
  11932. t['pagurmukhi'] = 0x0A2A;
  11933. t['pahiragana'] = 0x3071;
  11934. t['paiyannoithai'] = 0x0E2F;
  11935. t['pakatakana'] = 0x30D1;
  11936. t['palatalizationcyrilliccmb'] = 0x0484;
  11937. t['palochkacyrillic'] = 0x04C0;
  11938. t['pansioskorean'] = 0x317F;
  11939. t['paragraph'] = 0x00B6;
  11940. t['parallel'] = 0x2225;
  11941. t['parenleft'] = 0x0028;
  11942. t['parenleftaltonearabic'] = 0xFD3E;
  11943. t['parenleftbt'] = 0xF8ED;
  11944. t['parenleftex'] = 0xF8EC;
  11945. t['parenleftinferior'] = 0x208D;
  11946. t['parenleftmonospace'] = 0xFF08;
  11947. t['parenleftsmall'] = 0xFE59;
  11948. t['parenleftsuperior'] = 0x207D;
  11949. t['parenlefttp'] = 0xF8EB;
  11950. t['parenleftvertical'] = 0xFE35;
  11951. t['parenright'] = 0x0029;
  11952. t['parenrightaltonearabic'] = 0xFD3F;
  11953. t['parenrightbt'] = 0xF8F8;
  11954. t['parenrightex'] = 0xF8F7;
  11955. t['parenrightinferior'] = 0x208E;
  11956. t['parenrightmonospace'] = 0xFF09;
  11957. t['parenrightsmall'] = 0xFE5A;
  11958. t['parenrightsuperior'] = 0x207E;
  11959. t['parenrighttp'] = 0xF8F6;
  11960. t['parenrightvertical'] = 0xFE36;
  11961. t['partialdiff'] = 0x2202;
  11962. t['paseqhebrew'] = 0x05C0;
  11963. t['pashtahebrew'] = 0x0599;
  11964. t['pasquare'] = 0x33A9;
  11965. t['patah'] = 0x05B7;
  11966. t['patah11'] = 0x05B7;
  11967. t['patah1d'] = 0x05B7;
  11968. t['patah2a'] = 0x05B7;
  11969. t['patahhebrew'] = 0x05B7;
  11970. t['patahnarrowhebrew'] = 0x05B7;
  11971. t['patahquarterhebrew'] = 0x05B7;
  11972. t['patahwidehebrew'] = 0x05B7;
  11973. t['pazerhebrew'] = 0x05A1;
  11974. t['pbopomofo'] = 0x3106;
  11975. t['pcircle'] = 0x24DF;
  11976. t['pdotaccent'] = 0x1E57;
  11977. t['pe'] = 0x05E4;
  11978. t['pecyrillic'] = 0x043F;
  11979. t['pedagesh'] = 0xFB44;
  11980. t['pedageshhebrew'] = 0xFB44;
  11981. t['peezisquare'] = 0x333B;
  11982. t['pefinaldageshhebrew'] = 0xFB43;
  11983. t['peharabic'] = 0x067E;
  11984. t['peharmenian'] = 0x057A;
  11985. t['pehebrew'] = 0x05E4;
  11986. t['pehfinalarabic'] = 0xFB57;
  11987. t['pehinitialarabic'] = 0xFB58;
  11988. t['pehiragana'] = 0x307A;
  11989. t['pehmedialarabic'] = 0xFB59;
  11990. t['pekatakana'] = 0x30DA;
  11991. t['pemiddlehookcyrillic'] = 0x04A7;
  11992. t['perafehebrew'] = 0xFB4E;
  11993. t['percent'] = 0x0025;
  11994. t['percentarabic'] = 0x066A;
  11995. t['percentmonospace'] = 0xFF05;
  11996. t['percentsmall'] = 0xFE6A;
  11997. t['period'] = 0x002E;
  11998. t['periodarmenian'] = 0x0589;
  11999. t['periodcentered'] = 0x00B7;
  12000. t['periodhalfwidth'] = 0xFF61;
  12001. t['periodinferior'] = 0xF6E7;
  12002. t['periodmonospace'] = 0xFF0E;
  12003. t['periodsmall'] = 0xFE52;
  12004. t['periodsuperior'] = 0xF6E8;
  12005. t['perispomenigreekcmb'] = 0x0342;
  12006. t['perpendicular'] = 0x22A5;
  12007. t['perthousand'] = 0x2030;
  12008. t['peseta'] = 0x20A7;
  12009. t['pfsquare'] = 0x338A;
  12010. t['phabengali'] = 0x09AB;
  12011. t['phadeva'] = 0x092B;
  12012. t['phagujarati'] = 0x0AAB;
  12013. t['phagurmukhi'] = 0x0A2B;
  12014. t['phi'] = 0x03C6;
  12015. t['phi1'] = 0x03D5;
  12016. t['phieuphacirclekorean'] = 0x327A;
  12017. t['phieuphaparenkorean'] = 0x321A;
  12018. t['phieuphcirclekorean'] = 0x326C;
  12019. t['phieuphkorean'] = 0x314D;
  12020. t['phieuphparenkorean'] = 0x320C;
  12021. t['philatin'] = 0x0278;
  12022. t['phinthuthai'] = 0x0E3A;
  12023. t['phisymbolgreek'] = 0x03D5;
  12024. t['phook'] = 0x01A5;
  12025. t['phophanthai'] = 0x0E1E;
  12026. t['phophungthai'] = 0x0E1C;
  12027. t['phosamphaothai'] = 0x0E20;
  12028. t['pi'] = 0x03C0;
  12029. t['pieupacirclekorean'] = 0x3273;
  12030. t['pieupaparenkorean'] = 0x3213;
  12031. t['pieupcieuckorean'] = 0x3176;
  12032. t['pieupcirclekorean'] = 0x3265;
  12033. t['pieupkiyeokkorean'] = 0x3172;
  12034. t['pieupkorean'] = 0x3142;
  12035. t['pieupparenkorean'] = 0x3205;
  12036. t['pieupsioskiyeokkorean'] = 0x3174;
  12037. t['pieupsioskorean'] = 0x3144;
  12038. t['pieupsiostikeutkorean'] = 0x3175;
  12039. t['pieupthieuthkorean'] = 0x3177;
  12040. t['pieuptikeutkorean'] = 0x3173;
  12041. t['pihiragana'] = 0x3074;
  12042. t['pikatakana'] = 0x30D4;
  12043. t['pisymbolgreek'] = 0x03D6;
  12044. t['piwrarmenian'] = 0x0583;
  12045. t['plus'] = 0x002B;
  12046. t['plusbelowcmb'] = 0x031F;
  12047. t['pluscircle'] = 0x2295;
  12048. t['plusminus'] = 0x00B1;
  12049. t['plusmod'] = 0x02D6;
  12050. t['plusmonospace'] = 0xFF0B;
  12051. t['plussmall'] = 0xFE62;
  12052. t['plussuperior'] = 0x207A;
  12053. t['pmonospace'] = 0xFF50;
  12054. t['pmsquare'] = 0x33D8;
  12055. t['pohiragana'] = 0x307D;
  12056. t['pointingindexdownwhite'] = 0x261F;
  12057. t['pointingindexleftwhite'] = 0x261C;
  12058. t['pointingindexrightwhite'] = 0x261E;
  12059. t['pointingindexupwhite'] = 0x261D;
  12060. t['pokatakana'] = 0x30DD;
  12061. t['poplathai'] = 0x0E1B;
  12062. t['postalmark'] = 0x3012;
  12063. t['postalmarkface'] = 0x3020;
  12064. t['pparen'] = 0x24AB;
  12065. t['precedes'] = 0x227A;
  12066. t['prescription'] = 0x211E;
  12067. t['primemod'] = 0x02B9;
  12068. t['primereversed'] = 0x2035;
  12069. t['product'] = 0x220F;
  12070. t['projective'] = 0x2305;
  12071. t['prolongedkana'] = 0x30FC;
  12072. t['propellor'] = 0x2318;
  12073. t['propersubset'] = 0x2282;
  12074. t['propersuperset'] = 0x2283;
  12075. t['proportion'] = 0x2237;
  12076. t['proportional'] = 0x221D;
  12077. t['psi'] = 0x03C8;
  12078. t['psicyrillic'] = 0x0471;
  12079. t['psilipneumatacyrilliccmb'] = 0x0486;
  12080. t['pssquare'] = 0x33B0;
  12081. t['puhiragana'] = 0x3077;
  12082. t['pukatakana'] = 0x30D7;
  12083. t['pvsquare'] = 0x33B4;
  12084. t['pwsquare'] = 0x33BA;
  12085. t['q'] = 0x0071;
  12086. t['qadeva'] = 0x0958;
  12087. t['qadmahebrew'] = 0x05A8;
  12088. t['qafarabic'] = 0x0642;
  12089. t['qaffinalarabic'] = 0xFED6;
  12090. t['qafinitialarabic'] = 0xFED7;
  12091. t['qafmedialarabic'] = 0xFED8;
  12092. t['qamats'] = 0x05B8;
  12093. t['qamats10'] = 0x05B8;
  12094. t['qamats1a'] = 0x05B8;
  12095. t['qamats1c'] = 0x05B8;
  12096. t['qamats27'] = 0x05B8;
  12097. t['qamats29'] = 0x05B8;
  12098. t['qamats33'] = 0x05B8;
  12099. t['qamatsde'] = 0x05B8;
  12100. t['qamatshebrew'] = 0x05B8;
  12101. t['qamatsnarrowhebrew'] = 0x05B8;
  12102. t['qamatsqatanhebrew'] = 0x05B8;
  12103. t['qamatsqatannarrowhebrew'] = 0x05B8;
  12104. t['qamatsqatanquarterhebrew'] = 0x05B8;
  12105. t['qamatsqatanwidehebrew'] = 0x05B8;
  12106. t['qamatsquarterhebrew'] = 0x05B8;
  12107. t['qamatswidehebrew'] = 0x05B8;
  12108. t['qarneyparahebrew'] = 0x059F;
  12109. t['qbopomofo'] = 0x3111;
  12110. t['qcircle'] = 0x24E0;
  12111. t['qhook'] = 0x02A0;
  12112. t['qmonospace'] = 0xFF51;
  12113. t['qof'] = 0x05E7;
  12114. t['qofdagesh'] = 0xFB47;
  12115. t['qofdageshhebrew'] = 0xFB47;
  12116. t['qofhebrew'] = 0x05E7;
  12117. t['qparen'] = 0x24AC;
  12118. t['quarternote'] = 0x2669;
  12119. t['qubuts'] = 0x05BB;
  12120. t['qubuts18'] = 0x05BB;
  12121. t['qubuts25'] = 0x05BB;
  12122. t['qubuts31'] = 0x05BB;
  12123. t['qubutshebrew'] = 0x05BB;
  12124. t['qubutsnarrowhebrew'] = 0x05BB;
  12125. t['qubutsquarterhebrew'] = 0x05BB;
  12126. t['qubutswidehebrew'] = 0x05BB;
  12127. t['question'] = 0x003F;
  12128. t['questionarabic'] = 0x061F;
  12129. t['questionarmenian'] = 0x055E;
  12130. t['questiondown'] = 0x00BF;
  12131. t['questiondownsmall'] = 0xF7BF;
  12132. t['questiongreek'] = 0x037E;
  12133. t['questionmonospace'] = 0xFF1F;
  12134. t['questionsmall'] = 0xF73F;
  12135. t['quotedbl'] = 0x0022;
  12136. t['quotedblbase'] = 0x201E;
  12137. t['quotedblleft'] = 0x201C;
  12138. t['quotedblmonospace'] = 0xFF02;
  12139. t['quotedblprime'] = 0x301E;
  12140. t['quotedblprimereversed'] = 0x301D;
  12141. t['quotedblright'] = 0x201D;
  12142. t['quoteleft'] = 0x2018;
  12143. t['quoteleftreversed'] = 0x201B;
  12144. t['quotereversed'] = 0x201B;
  12145. t['quoteright'] = 0x2019;
  12146. t['quoterightn'] = 0x0149;
  12147. t['quotesinglbase'] = 0x201A;
  12148. t['quotesingle'] = 0x0027;
  12149. t['quotesinglemonospace'] = 0xFF07;
  12150. t['r'] = 0x0072;
  12151. t['raarmenian'] = 0x057C;
  12152. t['rabengali'] = 0x09B0;
  12153. t['racute'] = 0x0155;
  12154. t['radeva'] = 0x0930;
  12155. t['radical'] = 0x221A;
  12156. t['radicalex'] = 0xF8E5;
  12157. t['radoverssquare'] = 0x33AE;
  12158. t['radoverssquaredsquare'] = 0x33AF;
  12159. t['radsquare'] = 0x33AD;
  12160. t['rafe'] = 0x05BF;
  12161. t['rafehebrew'] = 0x05BF;
  12162. t['ragujarati'] = 0x0AB0;
  12163. t['ragurmukhi'] = 0x0A30;
  12164. t['rahiragana'] = 0x3089;
  12165. t['rakatakana'] = 0x30E9;
  12166. t['rakatakanahalfwidth'] = 0xFF97;
  12167. t['ralowerdiagonalbengali'] = 0x09F1;
  12168. t['ramiddlediagonalbengali'] = 0x09F0;
  12169. t['ramshorn'] = 0x0264;
  12170. t['ratio'] = 0x2236;
  12171. t['rbopomofo'] = 0x3116;
  12172. t['rcaron'] = 0x0159;
  12173. t['rcedilla'] = 0x0157;
  12174. t['rcircle'] = 0x24E1;
  12175. t['rcommaaccent'] = 0x0157;
  12176. t['rdblgrave'] = 0x0211;
  12177. t['rdotaccent'] = 0x1E59;
  12178. t['rdotbelow'] = 0x1E5B;
  12179. t['rdotbelowmacron'] = 0x1E5D;
  12180. t['referencemark'] = 0x203B;
  12181. t['reflexsubset'] = 0x2286;
  12182. t['reflexsuperset'] = 0x2287;
  12183. t['registered'] = 0x00AE;
  12184. t['registersans'] = 0xF8E8;
  12185. t['registerserif'] = 0xF6DA;
  12186. t['reharabic'] = 0x0631;
  12187. t['reharmenian'] = 0x0580;
  12188. t['rehfinalarabic'] = 0xFEAE;
  12189. t['rehiragana'] = 0x308C;
  12190. t['rekatakana'] = 0x30EC;
  12191. t['rekatakanahalfwidth'] = 0xFF9A;
  12192. t['resh'] = 0x05E8;
  12193. t['reshdageshhebrew'] = 0xFB48;
  12194. t['reshhebrew'] = 0x05E8;
  12195. t['reversedtilde'] = 0x223D;
  12196. t['reviahebrew'] = 0x0597;
  12197. t['reviamugrashhebrew'] = 0x0597;
  12198. t['revlogicalnot'] = 0x2310;
  12199. t['rfishhook'] = 0x027E;
  12200. t['rfishhookreversed'] = 0x027F;
  12201. t['rhabengali'] = 0x09DD;
  12202. t['rhadeva'] = 0x095D;
  12203. t['rho'] = 0x03C1;
  12204. t['rhook'] = 0x027D;
  12205. t['rhookturned'] = 0x027B;
  12206. t['rhookturnedsuperior'] = 0x02B5;
  12207. t['rhosymbolgreek'] = 0x03F1;
  12208. t['rhotichookmod'] = 0x02DE;
  12209. t['rieulacirclekorean'] = 0x3271;
  12210. t['rieulaparenkorean'] = 0x3211;
  12211. t['rieulcirclekorean'] = 0x3263;
  12212. t['rieulhieuhkorean'] = 0x3140;
  12213. t['rieulkiyeokkorean'] = 0x313A;
  12214. t['rieulkiyeoksioskorean'] = 0x3169;
  12215. t['rieulkorean'] = 0x3139;
  12216. t['rieulmieumkorean'] = 0x313B;
  12217. t['rieulpansioskorean'] = 0x316C;
  12218. t['rieulparenkorean'] = 0x3203;
  12219. t['rieulphieuphkorean'] = 0x313F;
  12220. t['rieulpieupkorean'] = 0x313C;
  12221. t['rieulpieupsioskorean'] = 0x316B;
  12222. t['rieulsioskorean'] = 0x313D;
  12223. t['rieulthieuthkorean'] = 0x313E;
  12224. t['rieultikeutkorean'] = 0x316A;
  12225. t['rieulyeorinhieuhkorean'] = 0x316D;
  12226. t['rightangle'] = 0x221F;
  12227. t['righttackbelowcmb'] = 0x0319;
  12228. t['righttriangle'] = 0x22BF;
  12229. t['rihiragana'] = 0x308A;
  12230. t['rikatakana'] = 0x30EA;
  12231. t['rikatakanahalfwidth'] = 0xFF98;
  12232. t['ring'] = 0x02DA;
  12233. t['ringbelowcmb'] = 0x0325;
  12234. t['ringcmb'] = 0x030A;
  12235. t['ringhalfleft'] = 0x02BF;
  12236. t['ringhalfleftarmenian'] = 0x0559;
  12237. t['ringhalfleftbelowcmb'] = 0x031C;
  12238. t['ringhalfleftcentered'] = 0x02D3;
  12239. t['ringhalfright'] = 0x02BE;
  12240. t['ringhalfrightbelowcmb'] = 0x0339;
  12241. t['ringhalfrightcentered'] = 0x02D2;
  12242. t['rinvertedbreve'] = 0x0213;
  12243. t['rittorusquare'] = 0x3351;
  12244. t['rlinebelow'] = 0x1E5F;
  12245. t['rlongleg'] = 0x027C;
  12246. t['rlonglegturned'] = 0x027A;
  12247. t['rmonospace'] = 0xFF52;
  12248. t['rohiragana'] = 0x308D;
  12249. t['rokatakana'] = 0x30ED;
  12250. t['rokatakanahalfwidth'] = 0xFF9B;
  12251. t['roruathai'] = 0x0E23;
  12252. t['rparen'] = 0x24AD;
  12253. t['rrabengali'] = 0x09DC;
  12254. t['rradeva'] = 0x0931;
  12255. t['rragurmukhi'] = 0x0A5C;
  12256. t['rreharabic'] = 0x0691;
  12257. t['rrehfinalarabic'] = 0xFB8D;
  12258. t['rrvocalicbengali'] = 0x09E0;
  12259. t['rrvocalicdeva'] = 0x0960;
  12260. t['rrvocalicgujarati'] = 0x0AE0;
  12261. t['rrvocalicvowelsignbengali'] = 0x09C4;
  12262. t['rrvocalicvowelsigndeva'] = 0x0944;
  12263. t['rrvocalicvowelsigngujarati'] = 0x0AC4;
  12264. t['rsuperior'] = 0xF6F1;
  12265. t['rtblock'] = 0x2590;
  12266. t['rturned'] = 0x0279;
  12267. t['rturnedsuperior'] = 0x02B4;
  12268. t['ruhiragana'] = 0x308B;
  12269. t['rukatakana'] = 0x30EB;
  12270. t['rukatakanahalfwidth'] = 0xFF99;
  12271. t['rupeemarkbengali'] = 0x09F2;
  12272. t['rupeesignbengali'] = 0x09F3;
  12273. t['rupiah'] = 0xF6DD;
  12274. t['ruthai'] = 0x0E24;
  12275. t['rvocalicbengali'] = 0x098B;
  12276. t['rvocalicdeva'] = 0x090B;
  12277. t['rvocalicgujarati'] = 0x0A8B;
  12278. t['rvocalicvowelsignbengali'] = 0x09C3;
  12279. t['rvocalicvowelsigndeva'] = 0x0943;
  12280. t['rvocalicvowelsigngujarati'] = 0x0AC3;
  12281. t['s'] = 0x0073;
  12282. t['sabengali'] = 0x09B8;
  12283. t['sacute'] = 0x015B;
  12284. t['sacutedotaccent'] = 0x1E65;
  12285. t['sadarabic'] = 0x0635;
  12286. t['sadeva'] = 0x0938;
  12287. t['sadfinalarabic'] = 0xFEBA;
  12288. t['sadinitialarabic'] = 0xFEBB;
  12289. t['sadmedialarabic'] = 0xFEBC;
  12290. t['sagujarati'] = 0x0AB8;
  12291. t['sagurmukhi'] = 0x0A38;
  12292. t['sahiragana'] = 0x3055;
  12293. t['sakatakana'] = 0x30B5;
  12294. t['sakatakanahalfwidth'] = 0xFF7B;
  12295. t['sallallahoualayhewasallamarabic'] = 0xFDFA;
  12296. t['samekh'] = 0x05E1;
  12297. t['samekhdagesh'] = 0xFB41;
  12298. t['samekhdageshhebrew'] = 0xFB41;
  12299. t['samekhhebrew'] = 0x05E1;
  12300. t['saraaathai'] = 0x0E32;
  12301. t['saraaethai'] = 0x0E41;
  12302. t['saraaimaimalaithai'] = 0x0E44;
  12303. t['saraaimaimuanthai'] = 0x0E43;
  12304. t['saraamthai'] = 0x0E33;
  12305. t['saraathai'] = 0x0E30;
  12306. t['saraethai'] = 0x0E40;
  12307. t['saraiileftthai'] = 0xF886;
  12308. t['saraiithai'] = 0x0E35;
  12309. t['saraileftthai'] = 0xF885;
  12310. t['saraithai'] = 0x0E34;
  12311. t['saraothai'] = 0x0E42;
  12312. t['saraueeleftthai'] = 0xF888;
  12313. t['saraueethai'] = 0x0E37;
  12314. t['saraueleftthai'] = 0xF887;
  12315. t['sarauethai'] = 0x0E36;
  12316. t['sarauthai'] = 0x0E38;
  12317. t['sarauuthai'] = 0x0E39;
  12318. t['sbopomofo'] = 0x3119;
  12319. t['scaron'] = 0x0161;
  12320. t['scarondotaccent'] = 0x1E67;
  12321. t['scedilla'] = 0x015F;
  12322. t['schwa'] = 0x0259;
  12323. t['schwacyrillic'] = 0x04D9;
  12324. t['schwadieresiscyrillic'] = 0x04DB;
  12325. t['schwahook'] = 0x025A;
  12326. t['scircle'] = 0x24E2;
  12327. t['scircumflex'] = 0x015D;
  12328. t['scommaaccent'] = 0x0219;
  12329. t['sdotaccent'] = 0x1E61;
  12330. t['sdotbelow'] = 0x1E63;
  12331. t['sdotbelowdotaccent'] = 0x1E69;
  12332. t['seagullbelowcmb'] = 0x033C;
  12333. t['second'] = 0x2033;
  12334. t['secondtonechinese'] = 0x02CA;
  12335. t['section'] = 0x00A7;
  12336. t['seenarabic'] = 0x0633;
  12337. t['seenfinalarabic'] = 0xFEB2;
  12338. t['seeninitialarabic'] = 0xFEB3;
  12339. t['seenmedialarabic'] = 0xFEB4;
  12340. t['segol'] = 0x05B6;
  12341. t['segol13'] = 0x05B6;
  12342. t['segol1f'] = 0x05B6;
  12343. t['segol2c'] = 0x05B6;
  12344. t['segolhebrew'] = 0x05B6;
  12345. t['segolnarrowhebrew'] = 0x05B6;
  12346. t['segolquarterhebrew'] = 0x05B6;
  12347. t['segoltahebrew'] = 0x0592;
  12348. t['segolwidehebrew'] = 0x05B6;
  12349. t['seharmenian'] = 0x057D;
  12350. t['sehiragana'] = 0x305B;
  12351. t['sekatakana'] = 0x30BB;
  12352. t['sekatakanahalfwidth'] = 0xFF7E;
  12353. t['semicolon'] = 0x003B;
  12354. t['semicolonarabic'] = 0x061B;
  12355. t['semicolonmonospace'] = 0xFF1B;
  12356. t['semicolonsmall'] = 0xFE54;
  12357. t['semivoicedmarkkana'] = 0x309C;
  12358. t['semivoicedmarkkanahalfwidth'] = 0xFF9F;
  12359. t['sentisquare'] = 0x3322;
  12360. t['sentosquare'] = 0x3323;
  12361. t['seven'] = 0x0037;
  12362. t['sevenarabic'] = 0x0667;
  12363. t['sevenbengali'] = 0x09ED;
  12364. t['sevencircle'] = 0x2466;
  12365. t['sevencircleinversesansserif'] = 0x2790;
  12366. t['sevendeva'] = 0x096D;
  12367. t['seveneighths'] = 0x215E;
  12368. t['sevengujarati'] = 0x0AED;
  12369. t['sevengurmukhi'] = 0x0A6D;
  12370. t['sevenhackarabic'] = 0x0667;
  12371. t['sevenhangzhou'] = 0x3027;
  12372. t['sevenideographicparen'] = 0x3226;
  12373. t['seveninferior'] = 0x2087;
  12374. t['sevenmonospace'] = 0xFF17;
  12375. t['sevenoldstyle'] = 0xF737;
  12376. t['sevenparen'] = 0x247A;
  12377. t['sevenperiod'] = 0x248E;
  12378. t['sevenpersian'] = 0x06F7;
  12379. t['sevenroman'] = 0x2176;
  12380. t['sevensuperior'] = 0x2077;
  12381. t['seventeencircle'] = 0x2470;
  12382. t['seventeenparen'] = 0x2484;
  12383. t['seventeenperiod'] = 0x2498;
  12384. t['seventhai'] = 0x0E57;
  12385. t['sfthyphen'] = 0x00AD;
  12386. t['shaarmenian'] = 0x0577;
  12387. t['shabengali'] = 0x09B6;
  12388. t['shacyrillic'] = 0x0448;
  12389. t['shaddaarabic'] = 0x0651;
  12390. t['shaddadammaarabic'] = 0xFC61;
  12391. t['shaddadammatanarabic'] = 0xFC5E;
  12392. t['shaddafathaarabic'] = 0xFC60;
  12393. t['shaddakasraarabic'] = 0xFC62;
  12394. t['shaddakasratanarabic'] = 0xFC5F;
  12395. t['shade'] = 0x2592;
  12396. t['shadedark'] = 0x2593;
  12397. t['shadelight'] = 0x2591;
  12398. t['shademedium'] = 0x2592;
  12399. t['shadeva'] = 0x0936;
  12400. t['shagujarati'] = 0x0AB6;
  12401. t['shagurmukhi'] = 0x0A36;
  12402. t['shalshelethebrew'] = 0x0593;
  12403. t['shbopomofo'] = 0x3115;
  12404. t['shchacyrillic'] = 0x0449;
  12405. t['sheenarabic'] = 0x0634;
  12406. t['sheenfinalarabic'] = 0xFEB6;
  12407. t['sheeninitialarabic'] = 0xFEB7;
  12408. t['sheenmedialarabic'] = 0xFEB8;
  12409. t['sheicoptic'] = 0x03E3;
  12410. t['sheqel'] = 0x20AA;
  12411. t['sheqelhebrew'] = 0x20AA;
  12412. t['sheva'] = 0x05B0;
  12413. t['sheva115'] = 0x05B0;
  12414. t['sheva15'] = 0x05B0;
  12415. t['sheva22'] = 0x05B0;
  12416. t['sheva2e'] = 0x05B0;
  12417. t['shevahebrew'] = 0x05B0;
  12418. t['shevanarrowhebrew'] = 0x05B0;
  12419. t['shevaquarterhebrew'] = 0x05B0;
  12420. t['shevawidehebrew'] = 0x05B0;
  12421. t['shhacyrillic'] = 0x04BB;
  12422. t['shimacoptic'] = 0x03ED;
  12423. t['shin'] = 0x05E9;
  12424. t['shindagesh'] = 0xFB49;
  12425. t['shindageshhebrew'] = 0xFB49;
  12426. t['shindageshshindot'] = 0xFB2C;
  12427. t['shindageshshindothebrew'] = 0xFB2C;
  12428. t['shindageshsindot'] = 0xFB2D;
  12429. t['shindageshsindothebrew'] = 0xFB2D;
  12430. t['shindothebrew'] = 0x05C1;
  12431. t['shinhebrew'] = 0x05E9;
  12432. t['shinshindot'] = 0xFB2A;
  12433. t['shinshindothebrew'] = 0xFB2A;
  12434. t['shinsindot'] = 0xFB2B;
  12435. t['shinsindothebrew'] = 0xFB2B;
  12436. t['shook'] = 0x0282;
  12437. t['sigma'] = 0x03C3;
  12438. t['sigma1'] = 0x03C2;
  12439. t['sigmafinal'] = 0x03C2;
  12440. t['sigmalunatesymbolgreek'] = 0x03F2;
  12441. t['sihiragana'] = 0x3057;
  12442. t['sikatakana'] = 0x30B7;
  12443. t['sikatakanahalfwidth'] = 0xFF7C;
  12444. t['siluqhebrew'] = 0x05BD;
  12445. t['siluqlefthebrew'] = 0x05BD;
  12446. t['similar'] = 0x223C;
  12447. t['sindothebrew'] = 0x05C2;
  12448. t['siosacirclekorean'] = 0x3274;
  12449. t['siosaparenkorean'] = 0x3214;
  12450. t['sioscieuckorean'] = 0x317E;
  12451. t['sioscirclekorean'] = 0x3266;
  12452. t['sioskiyeokkorean'] = 0x317A;
  12453. t['sioskorean'] = 0x3145;
  12454. t['siosnieunkorean'] = 0x317B;
  12455. t['siosparenkorean'] = 0x3206;
  12456. t['siospieupkorean'] = 0x317D;
  12457. t['siostikeutkorean'] = 0x317C;
  12458. t['six'] = 0x0036;
  12459. t['sixarabic'] = 0x0666;
  12460. t['sixbengali'] = 0x09EC;
  12461. t['sixcircle'] = 0x2465;
  12462. t['sixcircleinversesansserif'] = 0x278F;
  12463. t['sixdeva'] = 0x096C;
  12464. t['sixgujarati'] = 0x0AEC;
  12465. t['sixgurmukhi'] = 0x0A6C;
  12466. t['sixhackarabic'] = 0x0666;
  12467. t['sixhangzhou'] = 0x3026;
  12468. t['sixideographicparen'] = 0x3225;
  12469. t['sixinferior'] = 0x2086;
  12470. t['sixmonospace'] = 0xFF16;
  12471. t['sixoldstyle'] = 0xF736;
  12472. t['sixparen'] = 0x2479;
  12473. t['sixperiod'] = 0x248D;
  12474. t['sixpersian'] = 0x06F6;
  12475. t['sixroman'] = 0x2175;
  12476. t['sixsuperior'] = 0x2076;
  12477. t['sixteencircle'] = 0x246F;
  12478. t['sixteencurrencydenominatorbengali'] = 0x09F9;
  12479. t['sixteenparen'] = 0x2483;
  12480. t['sixteenperiod'] = 0x2497;
  12481. t['sixthai'] = 0x0E56;
  12482. t['slash'] = 0x002F;
  12483. t['slashmonospace'] = 0xFF0F;
  12484. t['slong'] = 0x017F;
  12485. t['slongdotaccent'] = 0x1E9B;
  12486. t['smileface'] = 0x263A;
  12487. t['smonospace'] = 0xFF53;
  12488. t['sofpasuqhebrew'] = 0x05C3;
  12489. t['softhyphen'] = 0x00AD;
  12490. t['softsigncyrillic'] = 0x044C;
  12491. t['sohiragana'] = 0x305D;
  12492. t['sokatakana'] = 0x30BD;
  12493. t['sokatakanahalfwidth'] = 0xFF7F;
  12494. t['soliduslongoverlaycmb'] = 0x0338;
  12495. t['solidusshortoverlaycmb'] = 0x0337;
  12496. t['sorusithai'] = 0x0E29;
  12497. t['sosalathai'] = 0x0E28;
  12498. t['sosothai'] = 0x0E0B;
  12499. t['sosuathai'] = 0x0E2A;
  12500. t['space'] = 0x0020;
  12501. t['spacehackarabic'] = 0x0020;
  12502. t['spade'] = 0x2660;
  12503. t['spadesuitblack'] = 0x2660;
  12504. t['spadesuitwhite'] = 0x2664;
  12505. t['sparen'] = 0x24AE;
  12506. t['squarebelowcmb'] = 0x033B;
  12507. t['squarecc'] = 0x33C4;
  12508. t['squarecm'] = 0x339D;
  12509. t['squarediagonalcrosshatchfill'] = 0x25A9;
  12510. t['squarehorizontalfill'] = 0x25A4;
  12511. t['squarekg'] = 0x338F;
  12512. t['squarekm'] = 0x339E;
  12513. t['squarekmcapital'] = 0x33CE;
  12514. t['squareln'] = 0x33D1;
  12515. t['squarelog'] = 0x33D2;
  12516. t['squaremg'] = 0x338E;
  12517. t['squaremil'] = 0x33D5;
  12518. t['squaremm'] = 0x339C;
  12519. t['squaremsquared'] = 0x33A1;
  12520. t['squareorthogonalcrosshatchfill'] = 0x25A6;
  12521. t['squareupperlefttolowerrightfill'] = 0x25A7;
  12522. t['squareupperrighttolowerleftfill'] = 0x25A8;
  12523. t['squareverticalfill'] = 0x25A5;
  12524. t['squarewhitewithsmallblack'] = 0x25A3;
  12525. t['srsquare'] = 0x33DB;
  12526. t['ssabengali'] = 0x09B7;
  12527. t['ssadeva'] = 0x0937;
  12528. t['ssagujarati'] = 0x0AB7;
  12529. t['ssangcieuckorean'] = 0x3149;
  12530. t['ssanghieuhkorean'] = 0x3185;
  12531. t['ssangieungkorean'] = 0x3180;
  12532. t['ssangkiyeokkorean'] = 0x3132;
  12533. t['ssangnieunkorean'] = 0x3165;
  12534. t['ssangpieupkorean'] = 0x3143;
  12535. t['ssangsioskorean'] = 0x3146;
  12536. t['ssangtikeutkorean'] = 0x3138;
  12537. t['ssuperior'] = 0xF6F2;
  12538. t['sterling'] = 0x00A3;
  12539. t['sterlingmonospace'] = 0xFFE1;
  12540. t['strokelongoverlaycmb'] = 0x0336;
  12541. t['strokeshortoverlaycmb'] = 0x0335;
  12542. t['subset'] = 0x2282;
  12543. t['subsetnotequal'] = 0x228A;
  12544. t['subsetorequal'] = 0x2286;
  12545. t['succeeds'] = 0x227B;
  12546. t['suchthat'] = 0x220B;
  12547. t['suhiragana'] = 0x3059;
  12548. t['sukatakana'] = 0x30B9;
  12549. t['sukatakanahalfwidth'] = 0xFF7D;
  12550. t['sukunarabic'] = 0x0652;
  12551. t['summation'] = 0x2211;
  12552. t['sun'] = 0x263C;
  12553. t['superset'] = 0x2283;
  12554. t['supersetnotequal'] = 0x228B;
  12555. t['supersetorequal'] = 0x2287;
  12556. t['svsquare'] = 0x33DC;
  12557. t['syouwaerasquare'] = 0x337C;
  12558. t['t'] = 0x0074;
  12559. t['tabengali'] = 0x09A4;
  12560. t['tackdown'] = 0x22A4;
  12561. t['tackleft'] = 0x22A3;
  12562. t['tadeva'] = 0x0924;
  12563. t['tagujarati'] = 0x0AA4;
  12564. t['tagurmukhi'] = 0x0A24;
  12565. t['taharabic'] = 0x0637;
  12566. t['tahfinalarabic'] = 0xFEC2;
  12567. t['tahinitialarabic'] = 0xFEC3;
  12568. t['tahiragana'] = 0x305F;
  12569. t['tahmedialarabic'] = 0xFEC4;
  12570. t['taisyouerasquare'] = 0x337D;
  12571. t['takatakana'] = 0x30BF;
  12572. t['takatakanahalfwidth'] = 0xFF80;
  12573. t['tatweelarabic'] = 0x0640;
  12574. t['tau'] = 0x03C4;
  12575. t['tav'] = 0x05EA;
  12576. t['tavdages'] = 0xFB4A;
  12577. t['tavdagesh'] = 0xFB4A;
  12578. t['tavdageshhebrew'] = 0xFB4A;
  12579. t['tavhebrew'] = 0x05EA;
  12580. t['tbar'] = 0x0167;
  12581. t['tbopomofo'] = 0x310A;
  12582. t['tcaron'] = 0x0165;
  12583. t['tccurl'] = 0x02A8;
  12584. t['tcedilla'] = 0x0163;
  12585. t['tcheharabic'] = 0x0686;
  12586. t['tchehfinalarabic'] = 0xFB7B;
  12587. t['tchehinitialarabic'] = 0xFB7C;
  12588. t['tchehmedialarabic'] = 0xFB7D;
  12589. t['tcircle'] = 0x24E3;
  12590. t['tcircumflexbelow'] = 0x1E71;
  12591. t['tcommaaccent'] = 0x0163;
  12592. t['tdieresis'] = 0x1E97;
  12593. t['tdotaccent'] = 0x1E6B;
  12594. t['tdotbelow'] = 0x1E6D;
  12595. t['tecyrillic'] = 0x0442;
  12596. t['tedescendercyrillic'] = 0x04AD;
  12597. t['teharabic'] = 0x062A;
  12598. t['tehfinalarabic'] = 0xFE96;
  12599. t['tehhahinitialarabic'] = 0xFCA2;
  12600. t['tehhahisolatedarabic'] = 0xFC0C;
  12601. t['tehinitialarabic'] = 0xFE97;
  12602. t['tehiragana'] = 0x3066;
  12603. t['tehjeeminitialarabic'] = 0xFCA1;
  12604. t['tehjeemisolatedarabic'] = 0xFC0B;
  12605. t['tehmarbutaarabic'] = 0x0629;
  12606. t['tehmarbutafinalarabic'] = 0xFE94;
  12607. t['tehmedialarabic'] = 0xFE98;
  12608. t['tehmeeminitialarabic'] = 0xFCA4;
  12609. t['tehmeemisolatedarabic'] = 0xFC0E;
  12610. t['tehnoonfinalarabic'] = 0xFC73;
  12611. t['tekatakana'] = 0x30C6;
  12612. t['tekatakanahalfwidth'] = 0xFF83;
  12613. t['telephone'] = 0x2121;
  12614. t['telephoneblack'] = 0x260E;
  12615. t['telishagedolahebrew'] = 0x05A0;
  12616. t['telishaqetanahebrew'] = 0x05A9;
  12617. t['tencircle'] = 0x2469;
  12618. t['tenideographicparen'] = 0x3229;
  12619. t['tenparen'] = 0x247D;
  12620. t['tenperiod'] = 0x2491;
  12621. t['tenroman'] = 0x2179;
  12622. t['tesh'] = 0x02A7;
  12623. t['tet'] = 0x05D8;
  12624. t['tetdagesh'] = 0xFB38;
  12625. t['tetdageshhebrew'] = 0xFB38;
  12626. t['tethebrew'] = 0x05D8;
  12627. t['tetsecyrillic'] = 0x04B5;
  12628. t['tevirhebrew'] = 0x059B;
  12629. t['tevirlefthebrew'] = 0x059B;
  12630. t['thabengali'] = 0x09A5;
  12631. t['thadeva'] = 0x0925;
  12632. t['thagujarati'] = 0x0AA5;
  12633. t['thagurmukhi'] = 0x0A25;
  12634. t['thalarabic'] = 0x0630;
  12635. t['thalfinalarabic'] = 0xFEAC;
  12636. t['thanthakhatlowleftthai'] = 0xF898;
  12637. t['thanthakhatlowrightthai'] = 0xF897;
  12638. t['thanthakhatthai'] = 0x0E4C;
  12639. t['thanthakhatupperleftthai'] = 0xF896;
  12640. t['theharabic'] = 0x062B;
  12641. t['thehfinalarabic'] = 0xFE9A;
  12642. t['thehinitialarabic'] = 0xFE9B;
  12643. t['thehmedialarabic'] = 0xFE9C;
  12644. t['thereexists'] = 0x2203;
  12645. t['therefore'] = 0x2234;
  12646. t['theta'] = 0x03B8;
  12647. t['theta1'] = 0x03D1;
  12648. t['thetasymbolgreek'] = 0x03D1;
  12649. t['thieuthacirclekorean'] = 0x3279;
  12650. t['thieuthaparenkorean'] = 0x3219;
  12651. t['thieuthcirclekorean'] = 0x326B;
  12652. t['thieuthkorean'] = 0x314C;
  12653. t['thieuthparenkorean'] = 0x320B;
  12654. t['thirteencircle'] = 0x246C;
  12655. t['thirteenparen'] = 0x2480;
  12656. t['thirteenperiod'] = 0x2494;
  12657. t['thonangmonthothai'] = 0x0E11;
  12658. t['thook'] = 0x01AD;
  12659. t['thophuthaothai'] = 0x0E12;
  12660. t['thorn'] = 0x00FE;
  12661. t['thothahanthai'] = 0x0E17;
  12662. t['thothanthai'] = 0x0E10;
  12663. t['thothongthai'] = 0x0E18;
  12664. t['thothungthai'] = 0x0E16;
  12665. t['thousandcyrillic'] = 0x0482;
  12666. t['thousandsseparatorarabic'] = 0x066C;
  12667. t['thousandsseparatorpersian'] = 0x066C;
  12668. t['three'] = 0x0033;
  12669. t['threearabic'] = 0x0663;
  12670. t['threebengali'] = 0x09E9;
  12671. t['threecircle'] = 0x2462;
  12672. t['threecircleinversesansserif'] = 0x278C;
  12673. t['threedeva'] = 0x0969;
  12674. t['threeeighths'] = 0x215C;
  12675. t['threegujarati'] = 0x0AE9;
  12676. t['threegurmukhi'] = 0x0A69;
  12677. t['threehackarabic'] = 0x0663;
  12678. t['threehangzhou'] = 0x3023;
  12679. t['threeideographicparen'] = 0x3222;
  12680. t['threeinferior'] = 0x2083;
  12681. t['threemonospace'] = 0xFF13;
  12682. t['threenumeratorbengali'] = 0x09F6;
  12683. t['threeoldstyle'] = 0xF733;
  12684. t['threeparen'] = 0x2476;
  12685. t['threeperiod'] = 0x248A;
  12686. t['threepersian'] = 0x06F3;
  12687. t['threequarters'] = 0x00BE;
  12688. t['threequartersemdash'] = 0xF6DE;
  12689. t['threeroman'] = 0x2172;
  12690. t['threesuperior'] = 0x00B3;
  12691. t['threethai'] = 0x0E53;
  12692. t['thzsquare'] = 0x3394;
  12693. t['tihiragana'] = 0x3061;
  12694. t['tikatakana'] = 0x30C1;
  12695. t['tikatakanahalfwidth'] = 0xFF81;
  12696. t['tikeutacirclekorean'] = 0x3270;
  12697. t['tikeutaparenkorean'] = 0x3210;
  12698. t['tikeutcirclekorean'] = 0x3262;
  12699. t['tikeutkorean'] = 0x3137;
  12700. t['tikeutparenkorean'] = 0x3202;
  12701. t['tilde'] = 0x02DC;
  12702. t['tildebelowcmb'] = 0x0330;
  12703. t['tildecmb'] = 0x0303;
  12704. t['tildecomb'] = 0x0303;
  12705. t['tildedoublecmb'] = 0x0360;
  12706. t['tildeoperator'] = 0x223C;
  12707. t['tildeoverlaycmb'] = 0x0334;
  12708. t['tildeverticalcmb'] = 0x033E;
  12709. t['timescircle'] = 0x2297;
  12710. t['tipehahebrew'] = 0x0596;
  12711. t['tipehalefthebrew'] = 0x0596;
  12712. t['tippigurmukhi'] = 0x0A70;
  12713. t['titlocyrilliccmb'] = 0x0483;
  12714. t['tiwnarmenian'] = 0x057F;
  12715. t['tlinebelow'] = 0x1E6F;
  12716. t['tmonospace'] = 0xFF54;
  12717. t['toarmenian'] = 0x0569;
  12718. t['tohiragana'] = 0x3068;
  12719. t['tokatakana'] = 0x30C8;
  12720. t['tokatakanahalfwidth'] = 0xFF84;
  12721. t['tonebarextrahighmod'] = 0x02E5;
  12722. t['tonebarextralowmod'] = 0x02E9;
  12723. t['tonebarhighmod'] = 0x02E6;
  12724. t['tonebarlowmod'] = 0x02E8;
  12725. t['tonebarmidmod'] = 0x02E7;
  12726. t['tonefive'] = 0x01BD;
  12727. t['tonesix'] = 0x0185;
  12728. t['tonetwo'] = 0x01A8;
  12729. t['tonos'] = 0x0384;
  12730. t['tonsquare'] = 0x3327;
  12731. t['topatakthai'] = 0x0E0F;
  12732. t['tortoiseshellbracketleft'] = 0x3014;
  12733. t['tortoiseshellbracketleftsmall'] = 0xFE5D;
  12734. t['tortoiseshellbracketleftvertical'] = 0xFE39;
  12735. t['tortoiseshellbracketright'] = 0x3015;
  12736. t['tortoiseshellbracketrightsmall'] = 0xFE5E;
  12737. t['tortoiseshellbracketrightvertical'] = 0xFE3A;
  12738. t['totaothai'] = 0x0E15;
  12739. t['tpalatalhook'] = 0x01AB;
  12740. t['tparen'] = 0x24AF;
  12741. t['trademark'] = 0x2122;
  12742. t['trademarksans'] = 0xF8EA;
  12743. t['trademarkserif'] = 0xF6DB;
  12744. t['tretroflexhook'] = 0x0288;
  12745. t['triagdn'] = 0x25BC;
  12746. t['triaglf'] = 0x25C4;
  12747. t['triagrt'] = 0x25BA;
  12748. t['triagup'] = 0x25B2;
  12749. t['ts'] = 0x02A6;
  12750. t['tsadi'] = 0x05E6;
  12751. t['tsadidagesh'] = 0xFB46;
  12752. t['tsadidageshhebrew'] = 0xFB46;
  12753. t['tsadihebrew'] = 0x05E6;
  12754. t['tsecyrillic'] = 0x0446;
  12755. t['tsere'] = 0x05B5;
  12756. t['tsere12'] = 0x05B5;
  12757. t['tsere1e'] = 0x05B5;
  12758. t['tsere2b'] = 0x05B5;
  12759. t['tserehebrew'] = 0x05B5;
  12760. t['tserenarrowhebrew'] = 0x05B5;
  12761. t['tserequarterhebrew'] = 0x05B5;
  12762. t['tserewidehebrew'] = 0x05B5;
  12763. t['tshecyrillic'] = 0x045B;
  12764. t['tsuperior'] = 0xF6F3;
  12765. t['ttabengali'] = 0x099F;
  12766. t['ttadeva'] = 0x091F;
  12767. t['ttagujarati'] = 0x0A9F;
  12768. t['ttagurmukhi'] = 0x0A1F;
  12769. t['tteharabic'] = 0x0679;
  12770. t['ttehfinalarabic'] = 0xFB67;
  12771. t['ttehinitialarabic'] = 0xFB68;
  12772. t['ttehmedialarabic'] = 0xFB69;
  12773. t['tthabengali'] = 0x09A0;
  12774. t['tthadeva'] = 0x0920;
  12775. t['tthagujarati'] = 0x0AA0;
  12776. t['tthagurmukhi'] = 0x0A20;
  12777. t['tturned'] = 0x0287;
  12778. t['tuhiragana'] = 0x3064;
  12779. t['tukatakana'] = 0x30C4;
  12780. t['tukatakanahalfwidth'] = 0xFF82;
  12781. t['tusmallhiragana'] = 0x3063;
  12782. t['tusmallkatakana'] = 0x30C3;
  12783. t['tusmallkatakanahalfwidth'] = 0xFF6F;
  12784. t['twelvecircle'] = 0x246B;
  12785. t['twelveparen'] = 0x247F;
  12786. t['twelveperiod'] = 0x2493;
  12787. t['twelveroman'] = 0x217B;
  12788. t['twentycircle'] = 0x2473;
  12789. t['twentyhangzhou'] = 0x5344;
  12790. t['twentyparen'] = 0x2487;
  12791. t['twentyperiod'] = 0x249B;
  12792. t['two'] = 0x0032;
  12793. t['twoarabic'] = 0x0662;
  12794. t['twobengali'] = 0x09E8;
  12795. t['twocircle'] = 0x2461;
  12796. t['twocircleinversesansserif'] = 0x278B;
  12797. t['twodeva'] = 0x0968;
  12798. t['twodotenleader'] = 0x2025;
  12799. t['twodotleader'] = 0x2025;
  12800. t['twodotleadervertical'] = 0xFE30;
  12801. t['twogujarati'] = 0x0AE8;
  12802. t['twogurmukhi'] = 0x0A68;
  12803. t['twohackarabic'] = 0x0662;
  12804. t['twohangzhou'] = 0x3022;
  12805. t['twoideographicparen'] = 0x3221;
  12806. t['twoinferior'] = 0x2082;
  12807. t['twomonospace'] = 0xFF12;
  12808. t['twonumeratorbengali'] = 0x09F5;
  12809. t['twooldstyle'] = 0xF732;
  12810. t['twoparen'] = 0x2475;
  12811. t['twoperiod'] = 0x2489;
  12812. t['twopersian'] = 0x06F2;
  12813. t['tworoman'] = 0x2171;
  12814. t['twostroke'] = 0x01BB;
  12815. t['twosuperior'] = 0x00B2;
  12816. t['twothai'] = 0x0E52;
  12817. t['twothirds'] = 0x2154;
  12818. t['u'] = 0x0075;
  12819. t['uacute'] = 0x00FA;
  12820. t['ubar'] = 0x0289;
  12821. t['ubengali'] = 0x0989;
  12822. t['ubopomofo'] = 0x3128;
  12823. t['ubreve'] = 0x016D;
  12824. t['ucaron'] = 0x01D4;
  12825. t['ucircle'] = 0x24E4;
  12826. t['ucircumflex'] = 0x00FB;
  12827. t['ucircumflexbelow'] = 0x1E77;
  12828. t['ucyrillic'] = 0x0443;
  12829. t['udattadeva'] = 0x0951;
  12830. t['udblacute'] = 0x0171;
  12831. t['udblgrave'] = 0x0215;
  12832. t['udeva'] = 0x0909;
  12833. t['udieresis'] = 0x00FC;
  12834. t['udieresisacute'] = 0x01D8;
  12835. t['udieresisbelow'] = 0x1E73;
  12836. t['udieresiscaron'] = 0x01DA;
  12837. t['udieresiscyrillic'] = 0x04F1;
  12838. t['udieresisgrave'] = 0x01DC;
  12839. t['udieresismacron'] = 0x01D6;
  12840. t['udotbelow'] = 0x1EE5;
  12841. t['ugrave'] = 0x00F9;
  12842. t['ugujarati'] = 0x0A89;
  12843. t['ugurmukhi'] = 0x0A09;
  12844. t['uhiragana'] = 0x3046;
  12845. t['uhookabove'] = 0x1EE7;
  12846. t['uhorn'] = 0x01B0;
  12847. t['uhornacute'] = 0x1EE9;
  12848. t['uhorndotbelow'] = 0x1EF1;
  12849. t['uhorngrave'] = 0x1EEB;
  12850. t['uhornhookabove'] = 0x1EED;
  12851. t['uhorntilde'] = 0x1EEF;
  12852. t['uhungarumlaut'] = 0x0171;
  12853. t['uhungarumlautcyrillic'] = 0x04F3;
  12854. t['uinvertedbreve'] = 0x0217;
  12855. t['ukatakana'] = 0x30A6;
  12856. t['ukatakanahalfwidth'] = 0xFF73;
  12857. t['ukcyrillic'] = 0x0479;
  12858. t['ukorean'] = 0x315C;
  12859. t['umacron'] = 0x016B;
  12860. t['umacroncyrillic'] = 0x04EF;
  12861. t['umacrondieresis'] = 0x1E7B;
  12862. t['umatragurmukhi'] = 0x0A41;
  12863. t['umonospace'] = 0xFF55;
  12864. t['underscore'] = 0x005F;
  12865. t['underscoredbl'] = 0x2017;
  12866. t['underscoremonospace'] = 0xFF3F;
  12867. t['underscorevertical'] = 0xFE33;
  12868. t['underscorewavy'] = 0xFE4F;
  12869. t['union'] = 0x222A;
  12870. t['universal'] = 0x2200;
  12871. t['uogonek'] = 0x0173;
  12872. t['uparen'] = 0x24B0;
  12873. t['upblock'] = 0x2580;
  12874. t['upperdothebrew'] = 0x05C4;
  12875. t['upsilon'] = 0x03C5;
  12876. t['upsilondieresis'] = 0x03CB;
  12877. t['upsilondieresistonos'] = 0x03B0;
  12878. t['upsilonlatin'] = 0x028A;
  12879. t['upsilontonos'] = 0x03CD;
  12880. t['uptackbelowcmb'] = 0x031D;
  12881. t['uptackmod'] = 0x02D4;
  12882. t['uragurmukhi'] = 0x0A73;
  12883. t['uring'] = 0x016F;
  12884. t['ushortcyrillic'] = 0x045E;
  12885. t['usmallhiragana'] = 0x3045;
  12886. t['usmallkatakana'] = 0x30A5;
  12887. t['usmallkatakanahalfwidth'] = 0xFF69;
  12888. t['ustraightcyrillic'] = 0x04AF;
  12889. t['ustraightstrokecyrillic'] = 0x04B1;
  12890. t['utilde'] = 0x0169;
  12891. t['utildeacute'] = 0x1E79;
  12892. t['utildebelow'] = 0x1E75;
  12893. t['uubengali'] = 0x098A;
  12894. t['uudeva'] = 0x090A;
  12895. t['uugujarati'] = 0x0A8A;
  12896. t['uugurmukhi'] = 0x0A0A;
  12897. t['uumatragurmukhi'] = 0x0A42;
  12898. t['uuvowelsignbengali'] = 0x09C2;
  12899. t['uuvowelsigndeva'] = 0x0942;
  12900. t['uuvowelsigngujarati'] = 0x0AC2;
  12901. t['uvowelsignbengali'] = 0x09C1;
  12902. t['uvowelsigndeva'] = 0x0941;
  12903. t['uvowelsigngujarati'] = 0x0AC1;
  12904. t['v'] = 0x0076;
  12905. t['vadeva'] = 0x0935;
  12906. t['vagujarati'] = 0x0AB5;
  12907. t['vagurmukhi'] = 0x0A35;
  12908. t['vakatakana'] = 0x30F7;
  12909. t['vav'] = 0x05D5;
  12910. t['vavdagesh'] = 0xFB35;
  12911. t['vavdagesh65'] = 0xFB35;
  12912. t['vavdageshhebrew'] = 0xFB35;
  12913. t['vavhebrew'] = 0x05D5;
  12914. t['vavholam'] = 0xFB4B;
  12915. t['vavholamhebrew'] = 0xFB4B;
  12916. t['vavvavhebrew'] = 0x05F0;
  12917. t['vavyodhebrew'] = 0x05F1;
  12918. t['vcircle'] = 0x24E5;
  12919. t['vdotbelow'] = 0x1E7F;
  12920. t['vecyrillic'] = 0x0432;
  12921. t['veharabic'] = 0x06A4;
  12922. t['vehfinalarabic'] = 0xFB6B;
  12923. t['vehinitialarabic'] = 0xFB6C;
  12924. t['vehmedialarabic'] = 0xFB6D;
  12925. t['vekatakana'] = 0x30F9;
  12926. t['venus'] = 0x2640;
  12927. t['verticalbar'] = 0x007C;
  12928. t['verticallineabovecmb'] = 0x030D;
  12929. t['verticallinebelowcmb'] = 0x0329;
  12930. t['verticallinelowmod'] = 0x02CC;
  12931. t['verticallinemod'] = 0x02C8;
  12932. t['vewarmenian'] = 0x057E;
  12933. t['vhook'] = 0x028B;
  12934. t['vikatakana'] = 0x30F8;
  12935. t['viramabengali'] = 0x09CD;
  12936. t['viramadeva'] = 0x094D;
  12937. t['viramagujarati'] = 0x0ACD;
  12938. t['visargabengali'] = 0x0983;
  12939. t['visargadeva'] = 0x0903;
  12940. t['visargagujarati'] = 0x0A83;
  12941. t['vmonospace'] = 0xFF56;
  12942. t['voarmenian'] = 0x0578;
  12943. t['voicediterationhiragana'] = 0x309E;
  12944. t['voicediterationkatakana'] = 0x30FE;
  12945. t['voicedmarkkana'] = 0x309B;
  12946. t['voicedmarkkanahalfwidth'] = 0xFF9E;
  12947. t['vokatakana'] = 0x30FA;
  12948. t['vparen'] = 0x24B1;
  12949. t['vtilde'] = 0x1E7D;
  12950. t['vturned'] = 0x028C;
  12951. t['vuhiragana'] = 0x3094;
  12952. t['vukatakana'] = 0x30F4;
  12953. t['w'] = 0x0077;
  12954. t['wacute'] = 0x1E83;
  12955. t['waekorean'] = 0x3159;
  12956. t['wahiragana'] = 0x308F;
  12957. t['wakatakana'] = 0x30EF;
  12958. t['wakatakanahalfwidth'] = 0xFF9C;
  12959. t['wakorean'] = 0x3158;
  12960. t['wasmallhiragana'] = 0x308E;
  12961. t['wasmallkatakana'] = 0x30EE;
  12962. t['wattosquare'] = 0x3357;
  12963. t['wavedash'] = 0x301C;
  12964. t['wavyunderscorevertical'] = 0xFE34;
  12965. t['wawarabic'] = 0x0648;
  12966. t['wawfinalarabic'] = 0xFEEE;
  12967. t['wawhamzaabovearabic'] = 0x0624;
  12968. t['wawhamzaabovefinalarabic'] = 0xFE86;
  12969. t['wbsquare'] = 0x33DD;
  12970. t['wcircle'] = 0x24E6;
  12971. t['wcircumflex'] = 0x0175;
  12972. t['wdieresis'] = 0x1E85;
  12973. t['wdotaccent'] = 0x1E87;
  12974. t['wdotbelow'] = 0x1E89;
  12975. t['wehiragana'] = 0x3091;
  12976. t['weierstrass'] = 0x2118;
  12977. t['wekatakana'] = 0x30F1;
  12978. t['wekorean'] = 0x315E;
  12979. t['weokorean'] = 0x315D;
  12980. t['wgrave'] = 0x1E81;
  12981. t['whitebullet'] = 0x25E6;
  12982. t['whitecircle'] = 0x25CB;
  12983. t['whitecircleinverse'] = 0x25D9;
  12984. t['whitecornerbracketleft'] = 0x300E;
  12985. t['whitecornerbracketleftvertical'] = 0xFE43;
  12986. t['whitecornerbracketright'] = 0x300F;
  12987. t['whitecornerbracketrightvertical'] = 0xFE44;
  12988. t['whitediamond'] = 0x25C7;
  12989. t['whitediamondcontainingblacksmalldiamond'] = 0x25C8;
  12990. t['whitedownpointingsmalltriangle'] = 0x25BF;
  12991. t['whitedownpointingtriangle'] = 0x25BD;
  12992. t['whiteleftpointingsmalltriangle'] = 0x25C3;
  12993. t['whiteleftpointingtriangle'] = 0x25C1;
  12994. t['whitelenticularbracketleft'] = 0x3016;
  12995. t['whitelenticularbracketright'] = 0x3017;
  12996. t['whiterightpointingsmalltriangle'] = 0x25B9;
  12997. t['whiterightpointingtriangle'] = 0x25B7;
  12998. t['whitesmallsquare'] = 0x25AB;
  12999. t['whitesmilingface'] = 0x263A;
  13000. t['whitesquare'] = 0x25A1;
  13001. t['whitestar'] = 0x2606;
  13002. t['whitetelephone'] = 0x260F;
  13003. t['whitetortoiseshellbracketleft'] = 0x3018;
  13004. t['whitetortoiseshellbracketright'] = 0x3019;
  13005. t['whiteuppointingsmalltriangle'] = 0x25B5;
  13006. t['whiteuppointingtriangle'] = 0x25B3;
  13007. t['wihiragana'] = 0x3090;
  13008. t['wikatakana'] = 0x30F0;
  13009. t['wikorean'] = 0x315F;
  13010. t['wmonospace'] = 0xFF57;
  13011. t['wohiragana'] = 0x3092;
  13012. t['wokatakana'] = 0x30F2;
  13013. t['wokatakanahalfwidth'] = 0xFF66;
  13014. t['won'] = 0x20A9;
  13015. t['wonmonospace'] = 0xFFE6;
  13016. t['wowaenthai'] = 0x0E27;
  13017. t['wparen'] = 0x24B2;
  13018. t['wring'] = 0x1E98;
  13019. t['wsuperior'] = 0x02B7;
  13020. t['wturned'] = 0x028D;
  13021. t['wynn'] = 0x01BF;
  13022. t['x'] = 0x0078;
  13023. t['xabovecmb'] = 0x033D;
  13024. t['xbopomofo'] = 0x3112;
  13025. t['xcircle'] = 0x24E7;
  13026. t['xdieresis'] = 0x1E8D;
  13027. t['xdotaccent'] = 0x1E8B;
  13028. t['xeharmenian'] = 0x056D;
  13029. t['xi'] = 0x03BE;
  13030. t['xmonospace'] = 0xFF58;
  13031. t['xparen'] = 0x24B3;
  13032. t['xsuperior'] = 0x02E3;
  13033. t['y'] = 0x0079;
  13034. t['yaadosquare'] = 0x334E;
  13035. t['yabengali'] = 0x09AF;
  13036. t['yacute'] = 0x00FD;
  13037. t['yadeva'] = 0x092F;
  13038. t['yaekorean'] = 0x3152;
  13039. t['yagujarati'] = 0x0AAF;
  13040. t['yagurmukhi'] = 0x0A2F;
  13041. t['yahiragana'] = 0x3084;
  13042. t['yakatakana'] = 0x30E4;
  13043. t['yakatakanahalfwidth'] = 0xFF94;
  13044. t['yakorean'] = 0x3151;
  13045. t['yamakkanthai'] = 0x0E4E;
  13046. t['yasmallhiragana'] = 0x3083;
  13047. t['yasmallkatakana'] = 0x30E3;
  13048. t['yasmallkatakanahalfwidth'] = 0xFF6C;
  13049. t['yatcyrillic'] = 0x0463;
  13050. t['ycircle'] = 0x24E8;
  13051. t['ycircumflex'] = 0x0177;
  13052. t['ydieresis'] = 0x00FF;
  13053. t['ydotaccent'] = 0x1E8F;
  13054. t['ydotbelow'] = 0x1EF5;
  13055. t['yeharabic'] = 0x064A;
  13056. t['yehbarreearabic'] = 0x06D2;
  13057. t['yehbarreefinalarabic'] = 0xFBAF;
  13058. t['yehfinalarabic'] = 0xFEF2;
  13059. t['yehhamzaabovearabic'] = 0x0626;
  13060. t['yehhamzaabovefinalarabic'] = 0xFE8A;
  13061. t['yehhamzaaboveinitialarabic'] = 0xFE8B;
  13062. t['yehhamzaabovemedialarabic'] = 0xFE8C;
  13063. t['yehinitialarabic'] = 0xFEF3;
  13064. t['yehmedialarabic'] = 0xFEF4;
  13065. t['yehmeeminitialarabic'] = 0xFCDD;
  13066. t['yehmeemisolatedarabic'] = 0xFC58;
  13067. t['yehnoonfinalarabic'] = 0xFC94;
  13068. t['yehthreedotsbelowarabic'] = 0x06D1;
  13069. t['yekorean'] = 0x3156;
  13070. t['yen'] = 0x00A5;
  13071. t['yenmonospace'] = 0xFFE5;
  13072. t['yeokorean'] = 0x3155;
  13073. t['yeorinhieuhkorean'] = 0x3186;
  13074. t['yerahbenyomohebrew'] = 0x05AA;
  13075. t['yerahbenyomolefthebrew'] = 0x05AA;
  13076. t['yericyrillic'] = 0x044B;
  13077. t['yerudieresiscyrillic'] = 0x04F9;
  13078. t['yesieungkorean'] = 0x3181;
  13079. t['yesieungpansioskorean'] = 0x3183;
  13080. t['yesieungsioskorean'] = 0x3182;
  13081. t['yetivhebrew'] = 0x059A;
  13082. t['ygrave'] = 0x1EF3;
  13083. t['yhook'] = 0x01B4;
  13084. t['yhookabove'] = 0x1EF7;
  13085. t['yiarmenian'] = 0x0575;
  13086. t['yicyrillic'] = 0x0457;
  13087. t['yikorean'] = 0x3162;
  13088. t['yinyang'] = 0x262F;
  13089. t['yiwnarmenian'] = 0x0582;
  13090. t['ymonospace'] = 0xFF59;
  13091. t['yod'] = 0x05D9;
  13092. t['yoddagesh'] = 0xFB39;
  13093. t['yoddageshhebrew'] = 0xFB39;
  13094. t['yodhebrew'] = 0x05D9;
  13095. t['yodyodhebrew'] = 0x05F2;
  13096. t['yodyodpatahhebrew'] = 0xFB1F;
  13097. t['yohiragana'] = 0x3088;
  13098. t['yoikorean'] = 0x3189;
  13099. t['yokatakana'] = 0x30E8;
  13100. t['yokatakanahalfwidth'] = 0xFF96;
  13101. t['yokorean'] = 0x315B;
  13102. t['yosmallhiragana'] = 0x3087;
  13103. t['yosmallkatakana'] = 0x30E7;
  13104. t['yosmallkatakanahalfwidth'] = 0xFF6E;
  13105. t['yotgreek'] = 0x03F3;
  13106. t['yoyaekorean'] = 0x3188;
  13107. t['yoyakorean'] = 0x3187;
  13108. t['yoyakthai'] = 0x0E22;
  13109. t['yoyingthai'] = 0x0E0D;
  13110. t['yparen'] = 0x24B4;
  13111. t['ypogegrammeni'] = 0x037A;
  13112. t['ypogegrammenigreekcmb'] = 0x0345;
  13113. t['yr'] = 0x01A6;
  13114. t['yring'] = 0x1E99;
  13115. t['ysuperior'] = 0x02B8;
  13116. t['ytilde'] = 0x1EF9;
  13117. t['yturned'] = 0x028E;
  13118. t['yuhiragana'] = 0x3086;
  13119. t['yuikorean'] = 0x318C;
  13120. t['yukatakana'] = 0x30E6;
  13121. t['yukatakanahalfwidth'] = 0xFF95;
  13122. t['yukorean'] = 0x3160;
  13123. t['yusbigcyrillic'] = 0x046B;
  13124. t['yusbigiotifiedcyrillic'] = 0x046D;
  13125. t['yuslittlecyrillic'] = 0x0467;
  13126. t['yuslittleiotifiedcyrillic'] = 0x0469;
  13127. t['yusmallhiragana'] = 0x3085;
  13128. t['yusmallkatakana'] = 0x30E5;
  13129. t['yusmallkatakanahalfwidth'] = 0xFF6D;
  13130. t['yuyekorean'] = 0x318B;
  13131. t['yuyeokorean'] = 0x318A;
  13132. t['yyabengali'] = 0x09DF;
  13133. t['yyadeva'] = 0x095F;
  13134. t['z'] = 0x007A;
  13135. t['zaarmenian'] = 0x0566;
  13136. t['zacute'] = 0x017A;
  13137. t['zadeva'] = 0x095B;
  13138. t['zagurmukhi'] = 0x0A5B;
  13139. t['zaharabic'] = 0x0638;
  13140. t['zahfinalarabic'] = 0xFEC6;
  13141. t['zahinitialarabic'] = 0xFEC7;
  13142. t['zahiragana'] = 0x3056;
  13143. t['zahmedialarabic'] = 0xFEC8;
  13144. t['zainarabic'] = 0x0632;
  13145. t['zainfinalarabic'] = 0xFEB0;
  13146. t['zakatakana'] = 0x30B6;
  13147. t['zaqefgadolhebrew'] = 0x0595;
  13148. t['zaqefqatanhebrew'] = 0x0594;
  13149. t['zarqahebrew'] = 0x0598;
  13150. t['zayin'] = 0x05D6;
  13151. t['zayindagesh'] = 0xFB36;
  13152. t['zayindageshhebrew'] = 0xFB36;
  13153. t['zayinhebrew'] = 0x05D6;
  13154. t['zbopomofo'] = 0x3117;
  13155. t['zcaron'] = 0x017E;
  13156. t['zcircle'] = 0x24E9;
  13157. t['zcircumflex'] = 0x1E91;
  13158. t['zcurl'] = 0x0291;
  13159. t['zdot'] = 0x017C;
  13160. t['zdotaccent'] = 0x017C;
  13161. t['zdotbelow'] = 0x1E93;
  13162. t['zecyrillic'] = 0x0437;
  13163. t['zedescendercyrillic'] = 0x0499;
  13164. t['zedieresiscyrillic'] = 0x04DF;
  13165. t['zehiragana'] = 0x305C;
  13166. t['zekatakana'] = 0x30BC;
  13167. t['zero'] = 0x0030;
  13168. t['zeroarabic'] = 0x0660;
  13169. t['zerobengali'] = 0x09E6;
  13170. t['zerodeva'] = 0x0966;
  13171. t['zerogujarati'] = 0x0AE6;
  13172. t['zerogurmukhi'] = 0x0A66;
  13173. t['zerohackarabic'] = 0x0660;
  13174. t['zeroinferior'] = 0x2080;
  13175. t['zeromonospace'] = 0xFF10;
  13176. t['zerooldstyle'] = 0xF730;
  13177. t['zeropersian'] = 0x06F0;
  13178. t['zerosuperior'] = 0x2070;
  13179. t['zerothai'] = 0x0E50;
  13180. t['zerowidthjoiner'] = 0xFEFF;
  13181. t['zerowidthnonjoiner'] = 0x200C;
  13182. t['zerowidthspace'] = 0x200B;
  13183. t['zeta'] = 0x03B6;
  13184. t['zhbopomofo'] = 0x3113;
  13185. t['zhearmenian'] = 0x056A;
  13186. t['zhebrevecyrillic'] = 0x04C2;
  13187. t['zhecyrillic'] = 0x0436;
  13188. t['zhedescendercyrillic'] = 0x0497;
  13189. t['zhedieresiscyrillic'] = 0x04DD;
  13190. t['zihiragana'] = 0x3058;
  13191. t['zikatakana'] = 0x30B8;
  13192. t['zinorhebrew'] = 0x05AE;
  13193. t['zlinebelow'] = 0x1E95;
  13194. t['zmonospace'] = 0xFF5A;
  13195. t['zohiragana'] = 0x305E;
  13196. t['zokatakana'] = 0x30BE;
  13197. t['zparen'] = 0x24B5;
  13198. t['zretroflexhook'] = 0x0290;
  13199. t['zstroke'] = 0x01B6;
  13200. t['zuhiragana'] = 0x305A;
  13201. t['zukatakana'] = 0x30BA;
  13202. t['.notdef'] = 0x0000;
  13203. });
  13204. var getDingbatsGlyphsUnicode = getLookupTableFactory(function (t) {
  13205. t['space'] = 0x0020;
  13206. t['a1'] = 0x2701;
  13207. t['a2'] = 0x2702;
  13208. t['a202'] = 0x2703;
  13209. t['a3'] = 0x2704;
  13210. t['a4'] = 0x260E;
  13211. t['a5'] = 0x2706;
  13212. t['a119'] = 0x2707;
  13213. t['a118'] = 0x2708;
  13214. t['a117'] = 0x2709;
  13215. t['a11'] = 0x261B;
  13216. t['a12'] = 0x261E;
  13217. t['a13'] = 0x270C;
  13218. t['a14'] = 0x270D;
  13219. t['a15'] = 0x270E;
  13220. t['a16'] = 0x270F;
  13221. t['a105'] = 0x2710;
  13222. t['a17'] = 0x2711;
  13223. t['a18'] = 0x2712;
  13224. t['a19'] = 0x2713;
  13225. t['a20'] = 0x2714;
  13226. t['a21'] = 0x2715;
  13227. t['a22'] = 0x2716;
  13228. t['a23'] = 0x2717;
  13229. t['a24'] = 0x2718;
  13230. t['a25'] = 0x2719;
  13231. t['a26'] = 0x271A;
  13232. t['a27'] = 0x271B;
  13233. t['a28'] = 0x271C;
  13234. t['a6'] = 0x271D;
  13235. t['a7'] = 0x271E;
  13236. t['a8'] = 0x271F;
  13237. t['a9'] = 0x2720;
  13238. t['a10'] = 0x2721;
  13239. t['a29'] = 0x2722;
  13240. t['a30'] = 0x2723;
  13241. t['a31'] = 0x2724;
  13242. t['a32'] = 0x2725;
  13243. t['a33'] = 0x2726;
  13244. t['a34'] = 0x2727;
  13245. t['a35'] = 0x2605;
  13246. t['a36'] = 0x2729;
  13247. t['a37'] = 0x272A;
  13248. t['a38'] = 0x272B;
  13249. t['a39'] = 0x272C;
  13250. t['a40'] = 0x272D;
  13251. t['a41'] = 0x272E;
  13252. t['a42'] = 0x272F;
  13253. t['a43'] = 0x2730;
  13254. t['a44'] = 0x2731;
  13255. t['a45'] = 0x2732;
  13256. t['a46'] = 0x2733;
  13257. t['a47'] = 0x2734;
  13258. t['a48'] = 0x2735;
  13259. t['a49'] = 0x2736;
  13260. t['a50'] = 0x2737;
  13261. t['a51'] = 0x2738;
  13262. t['a52'] = 0x2739;
  13263. t['a53'] = 0x273A;
  13264. t['a54'] = 0x273B;
  13265. t['a55'] = 0x273C;
  13266. t['a56'] = 0x273D;
  13267. t['a57'] = 0x273E;
  13268. t['a58'] = 0x273F;
  13269. t['a59'] = 0x2740;
  13270. t['a60'] = 0x2741;
  13271. t['a61'] = 0x2742;
  13272. t['a62'] = 0x2743;
  13273. t['a63'] = 0x2744;
  13274. t['a64'] = 0x2745;
  13275. t['a65'] = 0x2746;
  13276. t['a66'] = 0x2747;
  13277. t['a67'] = 0x2748;
  13278. t['a68'] = 0x2749;
  13279. t['a69'] = 0x274A;
  13280. t['a70'] = 0x274B;
  13281. t['a71'] = 0x25CF;
  13282. t['a72'] = 0x274D;
  13283. t['a73'] = 0x25A0;
  13284. t['a74'] = 0x274F;
  13285. t['a203'] = 0x2750;
  13286. t['a75'] = 0x2751;
  13287. t['a204'] = 0x2752;
  13288. t['a76'] = 0x25B2;
  13289. t['a77'] = 0x25BC;
  13290. t['a78'] = 0x25C6;
  13291. t['a79'] = 0x2756;
  13292. t['a81'] = 0x25D7;
  13293. t['a82'] = 0x2758;
  13294. t['a83'] = 0x2759;
  13295. t['a84'] = 0x275A;
  13296. t['a97'] = 0x275B;
  13297. t['a98'] = 0x275C;
  13298. t['a99'] = 0x275D;
  13299. t['a100'] = 0x275E;
  13300. t['a101'] = 0x2761;
  13301. t['a102'] = 0x2762;
  13302. t['a103'] = 0x2763;
  13303. t['a104'] = 0x2764;
  13304. t['a106'] = 0x2765;
  13305. t['a107'] = 0x2766;
  13306. t['a108'] = 0x2767;
  13307. t['a112'] = 0x2663;
  13308. t['a111'] = 0x2666;
  13309. t['a110'] = 0x2665;
  13310. t['a109'] = 0x2660;
  13311. t['a120'] = 0x2460;
  13312. t['a121'] = 0x2461;
  13313. t['a122'] = 0x2462;
  13314. t['a123'] = 0x2463;
  13315. t['a124'] = 0x2464;
  13316. t['a125'] = 0x2465;
  13317. t['a126'] = 0x2466;
  13318. t['a127'] = 0x2467;
  13319. t['a128'] = 0x2468;
  13320. t['a129'] = 0x2469;
  13321. t['a130'] = 0x2776;
  13322. t['a131'] = 0x2777;
  13323. t['a132'] = 0x2778;
  13324. t['a133'] = 0x2779;
  13325. t['a134'] = 0x277A;
  13326. t['a135'] = 0x277B;
  13327. t['a136'] = 0x277C;
  13328. t['a137'] = 0x277D;
  13329. t['a138'] = 0x277E;
  13330. t['a139'] = 0x277F;
  13331. t['a140'] = 0x2780;
  13332. t['a141'] = 0x2781;
  13333. t['a142'] = 0x2782;
  13334. t['a143'] = 0x2783;
  13335. t['a144'] = 0x2784;
  13336. t['a145'] = 0x2785;
  13337. t['a146'] = 0x2786;
  13338. t['a147'] = 0x2787;
  13339. t['a148'] = 0x2788;
  13340. t['a149'] = 0x2789;
  13341. t['a150'] = 0x278A;
  13342. t['a151'] = 0x278B;
  13343. t['a152'] = 0x278C;
  13344. t['a153'] = 0x278D;
  13345. t['a154'] = 0x278E;
  13346. t['a155'] = 0x278F;
  13347. t['a156'] = 0x2790;
  13348. t['a157'] = 0x2791;
  13349. t['a158'] = 0x2792;
  13350. t['a159'] = 0x2793;
  13351. t['a160'] = 0x2794;
  13352. t['a161'] = 0x2192;
  13353. t['a163'] = 0x2194;
  13354. t['a164'] = 0x2195;
  13355. t['a196'] = 0x2798;
  13356. t['a165'] = 0x2799;
  13357. t['a192'] = 0x279A;
  13358. t['a166'] = 0x279B;
  13359. t['a167'] = 0x279C;
  13360. t['a168'] = 0x279D;
  13361. t['a169'] = 0x279E;
  13362. t['a170'] = 0x279F;
  13363. t['a171'] = 0x27A0;
  13364. t['a172'] = 0x27A1;
  13365. t['a173'] = 0x27A2;
  13366. t['a162'] = 0x27A3;
  13367. t['a174'] = 0x27A4;
  13368. t['a175'] = 0x27A5;
  13369. t['a176'] = 0x27A6;
  13370. t['a177'] = 0x27A7;
  13371. t['a178'] = 0x27A8;
  13372. t['a179'] = 0x27A9;
  13373. t['a193'] = 0x27AA;
  13374. t['a180'] = 0x27AB;
  13375. t['a199'] = 0x27AC;
  13376. t['a181'] = 0x27AD;
  13377. t['a200'] = 0x27AE;
  13378. t['a182'] = 0x27AF;
  13379. t['a201'] = 0x27B1;
  13380. t['a183'] = 0x27B2;
  13381. t['a184'] = 0x27B3;
  13382. t['a197'] = 0x27B4;
  13383. t['a185'] = 0x27B5;
  13384. t['a194'] = 0x27B6;
  13385. t['a198'] = 0x27B7;
  13386. t['a186'] = 0x27B8;
  13387. t['a195'] = 0x27B9;
  13388. t['a187'] = 0x27BA;
  13389. t['a188'] = 0x27BB;
  13390. t['a189'] = 0x27BC;
  13391. t['a190'] = 0x27BD;
  13392. t['a191'] = 0x27BE;
  13393. t['a89'] = 0x2768;
  13394. // 0xF8D7
  13395. t['a90'] = 0x2769;
  13396. // 0xF8D8
  13397. t['a93'] = 0x276A;
  13398. // 0xF8D9
  13399. t['a94'] = 0x276B;
  13400. // 0xF8DA
  13401. t['a91'] = 0x276C;
  13402. // 0xF8DB
  13403. t['a92'] = 0x276D;
  13404. // 0xF8DC
  13405. t['a205'] = 0x276E;
  13406. // 0xF8DD
  13407. t['a85'] = 0x276F;
  13408. // 0xF8DE
  13409. t['a206'] = 0x2770;
  13410. // 0xF8DF
  13411. t['a86'] = 0x2771;
  13412. // 0xF8E0
  13413. t['a87'] = 0x2772;
  13414. // 0xF8E1
  13415. t['a88'] = 0x2773;
  13416. // 0xF8E2
  13417. t['a95'] = 0x2774;
  13418. // 0xF8E3
  13419. t['a96'] = 0x2775;
  13420. // 0xF8E4
  13421. t['.notdef'] = 0x0000;
  13422. });
  13423. exports.getGlyphsUnicode = getGlyphsUnicode;
  13424. exports.getDingbatsGlyphsUnicode = getDingbatsGlyphsUnicode;
  13425. }));
  13426. (function (root, factory) {
  13427. factory(root.pdfjsCoreJbig2 = {}, root.pdfjsSharedUtil, root.pdfjsCoreArithmeticDecoder);
  13428. }(this, function (exports, sharedUtil, coreArithmeticDecoder) {
  13429. var error = sharedUtil.error;
  13430. var log2 = sharedUtil.log2;
  13431. var readInt8 = sharedUtil.readInt8;
  13432. var readUint16 = sharedUtil.readUint16;
  13433. var readUint32 = sharedUtil.readUint32;
  13434. var shadow = sharedUtil.shadow;
  13435. var ArithmeticDecoder = coreArithmeticDecoder.ArithmeticDecoder;
  13436. var Jbig2Image = function Jbig2ImageClosure() {
  13437. // Utility data structures
  13438. function ContextCache() {
  13439. }
  13440. ContextCache.prototype = {
  13441. getContexts: function (id) {
  13442. if (id in this) {
  13443. return this[id];
  13444. }
  13445. return this[id] = new Int8Array(1 << 16);
  13446. }
  13447. };
  13448. function DecodingContext(data, start, end) {
  13449. this.data = data;
  13450. this.start = start;
  13451. this.end = end;
  13452. }
  13453. DecodingContext.prototype = {
  13454. get decoder() {
  13455. var decoder = new ArithmeticDecoder(this.data, this.start, this.end);
  13456. return shadow(this, 'decoder', decoder);
  13457. },
  13458. get contextCache() {
  13459. var cache = new ContextCache();
  13460. return shadow(this, 'contextCache', cache);
  13461. }
  13462. };
  13463. // Annex A. Arithmetic Integer Decoding Procedure
  13464. // A.2 Procedure for decoding values
  13465. function decodeInteger(contextCache, procedure, decoder) {
  13466. var contexts = contextCache.getContexts(procedure);
  13467. var prev = 1;
  13468. function readBits(length) {
  13469. var v = 0;
  13470. for (var i = 0; i < length; i++) {
  13471. var bit = decoder.readBit(contexts, prev);
  13472. prev = prev < 256 ? prev << 1 | bit : (prev << 1 | bit) & 511 | 256;
  13473. v = v << 1 | bit;
  13474. }
  13475. return v >>> 0;
  13476. }
  13477. var sign = readBits(1);
  13478. 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);
  13479. return sign === 0 ? value : value > 0 ? -value : null;
  13480. }
  13481. // A.3 The IAID decoding procedure
  13482. function decodeIAID(contextCache, decoder, codeLength) {
  13483. var contexts = contextCache.getContexts('IAID');
  13484. var prev = 1;
  13485. for (var i = 0; i < codeLength; i++) {
  13486. var bit = decoder.readBit(contexts, prev);
  13487. prev = prev << 1 | bit;
  13488. }
  13489. if (codeLength < 31) {
  13490. return prev & (1 << codeLength) - 1;
  13491. }
  13492. return prev & 0x7FFFFFFF;
  13493. }
  13494. // 7.3 Segment types
  13495. var SegmentTypes = [
  13496. 'SymbolDictionary',
  13497. null,
  13498. null,
  13499. null,
  13500. 'IntermediateTextRegion',
  13501. null,
  13502. 'ImmediateTextRegion',
  13503. 'ImmediateLosslessTextRegion',
  13504. null,
  13505. null,
  13506. null,
  13507. null,
  13508. null,
  13509. null,
  13510. null,
  13511. null,
  13512. 'patternDictionary',
  13513. null,
  13514. null,
  13515. null,
  13516. 'IntermediateHalftoneRegion',
  13517. null,
  13518. 'ImmediateHalftoneRegion',
  13519. 'ImmediateLosslessHalftoneRegion',
  13520. null,
  13521. null,
  13522. null,
  13523. null,
  13524. null,
  13525. null,
  13526. null,
  13527. null,
  13528. null,
  13529. null,
  13530. null,
  13531. null,
  13532. 'IntermediateGenericRegion',
  13533. null,
  13534. 'ImmediateGenericRegion',
  13535. 'ImmediateLosslessGenericRegion',
  13536. 'IntermediateGenericRefinementRegion',
  13537. null,
  13538. 'ImmediateGenericRefinementRegion',
  13539. 'ImmediateLosslessGenericRefinementRegion',
  13540. null,
  13541. null,
  13542. null,
  13543. null,
  13544. 'PageInformation',
  13545. 'EndOfPage',
  13546. 'EndOfStripe',
  13547. 'EndOfFile',
  13548. 'Profiles',
  13549. 'Tables',
  13550. null,
  13551. null,
  13552. null,
  13553. null,
  13554. null,
  13555. null,
  13556. null,
  13557. null,
  13558. 'Extension'
  13559. ];
  13560. var CodingTemplates = [
  13561. [
  13562. {
  13563. x: -1,
  13564. y: -2
  13565. },
  13566. {
  13567. x: 0,
  13568. y: -2
  13569. },
  13570. {
  13571. x: 1,
  13572. y: -2
  13573. },
  13574. {
  13575. x: -2,
  13576. y: -1
  13577. },
  13578. {
  13579. x: -1,
  13580. y: -1
  13581. },
  13582. {
  13583. x: 0,
  13584. y: -1
  13585. },
  13586. {
  13587. x: 1,
  13588. y: -1
  13589. },
  13590. {
  13591. x: 2,
  13592. y: -1
  13593. },
  13594. {
  13595. x: -4,
  13596. y: 0
  13597. },
  13598. {
  13599. x: -3,
  13600. y: 0
  13601. },
  13602. {
  13603. x: -2,
  13604. y: 0
  13605. },
  13606. {
  13607. x: -1,
  13608. y: 0
  13609. }
  13610. ],
  13611. [
  13612. {
  13613. x: -1,
  13614. y: -2
  13615. },
  13616. {
  13617. x: 0,
  13618. y: -2
  13619. },
  13620. {
  13621. x: 1,
  13622. y: -2
  13623. },
  13624. {
  13625. x: 2,
  13626. y: -2
  13627. },
  13628. {
  13629. x: -2,
  13630. y: -1
  13631. },
  13632. {
  13633. x: -1,
  13634. y: -1
  13635. },
  13636. {
  13637. x: 0,
  13638. y: -1
  13639. },
  13640. {
  13641. x: 1,
  13642. y: -1
  13643. },
  13644. {
  13645. x: 2,
  13646. y: -1
  13647. },
  13648. {
  13649. x: -3,
  13650. y: 0
  13651. },
  13652. {
  13653. x: -2,
  13654. y: 0
  13655. },
  13656. {
  13657. x: -1,
  13658. y: 0
  13659. }
  13660. ],
  13661. [
  13662. {
  13663. x: -1,
  13664. y: -2
  13665. },
  13666. {
  13667. x: 0,
  13668. y: -2
  13669. },
  13670. {
  13671. x: 1,
  13672. y: -2
  13673. },
  13674. {
  13675. x: -2,
  13676. y: -1
  13677. },
  13678. {
  13679. x: -1,
  13680. y: -1
  13681. },
  13682. {
  13683. x: 0,
  13684. y: -1
  13685. },
  13686. {
  13687. x: 1,
  13688. y: -1
  13689. },
  13690. {
  13691. x: -2,
  13692. y: 0
  13693. },
  13694. {
  13695. x: -1,
  13696. y: 0
  13697. }
  13698. ],
  13699. [
  13700. {
  13701. x: -3,
  13702. y: -1
  13703. },
  13704. {
  13705. x: -2,
  13706. y: -1
  13707. },
  13708. {
  13709. x: -1,
  13710. y: -1
  13711. },
  13712. {
  13713. x: 0,
  13714. y: -1
  13715. },
  13716. {
  13717. x: 1,
  13718. y: -1
  13719. },
  13720. {
  13721. x: -4,
  13722. y: 0
  13723. },
  13724. {
  13725. x: -3,
  13726. y: 0
  13727. },
  13728. {
  13729. x: -2,
  13730. y: 0
  13731. },
  13732. {
  13733. x: -1,
  13734. y: 0
  13735. }
  13736. ]
  13737. ];
  13738. var RefinementTemplates = [
  13739. {
  13740. coding: [
  13741. {
  13742. x: 0,
  13743. y: -1
  13744. },
  13745. {
  13746. x: 1,
  13747. y: -1
  13748. },
  13749. {
  13750. x: -1,
  13751. y: 0
  13752. }
  13753. ],
  13754. reference: [
  13755. {
  13756. x: 0,
  13757. y: -1
  13758. },
  13759. {
  13760. x: 1,
  13761. y: -1
  13762. },
  13763. {
  13764. x: -1,
  13765. y: 0
  13766. },
  13767. {
  13768. x: 0,
  13769. y: 0
  13770. },
  13771. {
  13772. x: 1,
  13773. y: 0
  13774. },
  13775. {
  13776. x: -1,
  13777. y: 1
  13778. },
  13779. {
  13780. x: 0,
  13781. y: 1
  13782. },
  13783. {
  13784. x: 1,
  13785. y: 1
  13786. }
  13787. ]
  13788. },
  13789. {
  13790. coding: [
  13791. {
  13792. x: -1,
  13793. y: -1
  13794. },
  13795. {
  13796. x: 0,
  13797. y: -1
  13798. },
  13799. {
  13800. x: 1,
  13801. y: -1
  13802. },
  13803. {
  13804. x: -1,
  13805. y: 0
  13806. }
  13807. ],
  13808. reference: [
  13809. {
  13810. x: 0,
  13811. y: -1
  13812. },
  13813. {
  13814. x: -1,
  13815. y: 0
  13816. },
  13817. {
  13818. x: 0,
  13819. y: 0
  13820. },
  13821. {
  13822. x: 1,
  13823. y: 0
  13824. },
  13825. {
  13826. x: 0,
  13827. y: 1
  13828. },
  13829. {
  13830. x: 1,
  13831. y: 1
  13832. }
  13833. ]
  13834. }
  13835. ];
  13836. // See 6.2.5.7 Decoding the bitmap.
  13837. var ReusedContexts = [
  13838. 0x9B25,
  13839. // 10011 0110010 0101
  13840. 0x0795,
  13841. // 0011 110010 101
  13842. 0x00E5,
  13843. // 001 11001 01
  13844. 0x0195
  13845. ];
  13846. // 011001 0101
  13847. var RefinementReusedContexts = [
  13848. 0x0020,
  13849. // '000' + '0' (coding) + '00010000' + '0' (reference)
  13850. 0x0008
  13851. ];
  13852. // '0000' + '001000'
  13853. function decodeBitmapTemplate0(width, height, decodingContext) {
  13854. var decoder = decodingContext.decoder;
  13855. var contexts = decodingContext.contextCache.getContexts('GB');
  13856. var contextLabel, i, j, pixel, row, row1, row2, bitmap = [];
  13857. // ...ooooo....
  13858. // ..ooooooo... Context template for current pixel (X)
  13859. // .ooooX...... (concatenate values of 'o'-pixels to get contextLabel)
  13860. var OLD_PIXEL_MASK = 0x7BF7;
  13861. // 01111 0111111 0111
  13862. for (i = 0; i < height; i++) {
  13863. row = bitmap[i] = new Uint8Array(width);
  13864. row1 = i < 1 ? row : bitmap[i - 1];
  13865. row2 = i < 2 ? row : bitmap[i - 2];
  13866. // At the beginning of each row:
  13867. // Fill contextLabel with pixels that are above/right of (X)
  13868. contextLabel = row2[0] << 13 | row2[1] << 12 | row2[2] << 11 | row1[0] << 7 | row1[1] << 6 | row1[2] << 5 | row1[3] << 4;
  13869. for (j = 0; j < width; j++) {
  13870. row[j] = pixel = decoder.readBit(contexts, contextLabel);
  13871. // At each pixel: Clear contextLabel pixels that are shifted
  13872. // out of the context, then add new ones.
  13873. contextLabel = (contextLabel & OLD_PIXEL_MASK) << 1 | (j + 3 < width ? row2[j + 3] << 11 : 0) | (j + 4 < width ? row1[j + 4] << 4 : 0) | pixel;
  13874. }
  13875. }
  13876. return bitmap;
  13877. }
  13878. // 6.2 Generic Region Decoding Procedure
  13879. function decodeBitmap(mmr, width, height, templateIndex, prediction, skip, at, decodingContext) {
  13880. if (mmr) {
  13881. error('JBIG2 error: MMR encoding is not supported');
  13882. }
  13883. // Use optimized version for the most common case
  13884. 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) {
  13885. return decodeBitmapTemplate0(width, height, decodingContext);
  13886. }
  13887. var useskip = !!skip;
  13888. var template = CodingTemplates[templateIndex].concat(at);
  13889. // Sorting is non-standard, and it is not required. But sorting increases
  13890. // the number of template bits that can be reused from the previous
  13891. // contextLabel in the main loop.
  13892. template.sort(function (a, b) {
  13893. return a.y - b.y || a.x - b.x;
  13894. });
  13895. var templateLength = template.length;
  13896. var templateX = new Int8Array(templateLength);
  13897. var templateY = new Int8Array(templateLength);
  13898. var changingTemplateEntries = [];
  13899. var reuseMask = 0, minX = 0, maxX = 0, minY = 0;
  13900. var c, k;
  13901. for (k = 0; k < templateLength; k++) {
  13902. templateX[k] = template[k].x;
  13903. templateY[k] = template[k].y;
  13904. minX = Math.min(minX, template[k].x);
  13905. maxX = Math.max(maxX, template[k].x);
  13906. minY = Math.min(minY, template[k].y);
  13907. // Check if the template pixel appears in two consecutive context labels,
  13908. // so it can be reused. Otherwise, we add it to the list of changing
  13909. // template entries.
  13910. if (k < templateLength - 1 && template[k].y === template[k + 1].y && template[k].x === template[k + 1].x - 1) {
  13911. reuseMask |= 1 << templateLength - 1 - k;
  13912. } else {
  13913. changingTemplateEntries.push(k);
  13914. }
  13915. }
  13916. var changingEntriesLength = changingTemplateEntries.length;
  13917. var changingTemplateX = new Int8Array(changingEntriesLength);
  13918. var changingTemplateY = new Int8Array(changingEntriesLength);
  13919. var changingTemplateBit = new Uint16Array(changingEntriesLength);
  13920. for (c = 0; c < changingEntriesLength; c++) {
  13921. k = changingTemplateEntries[c];
  13922. changingTemplateX[c] = template[k].x;
  13923. changingTemplateY[c] = template[k].y;
  13924. changingTemplateBit[c] = 1 << templateLength - 1 - k;
  13925. }
  13926. // Get the safe bounding box edges from the width, height, minX, maxX, minY
  13927. var sbb_left = -minX;
  13928. var sbb_top = -minY;
  13929. var sbb_right = width - maxX;
  13930. var pseudoPixelContext = ReusedContexts[templateIndex];
  13931. var row = new Uint8Array(width);
  13932. var bitmap = [];
  13933. var decoder = decodingContext.decoder;
  13934. var contexts = decodingContext.contextCache.getContexts('GB');
  13935. var ltp = 0, j, i0, j0, contextLabel = 0, bit, shift;
  13936. for (var i = 0; i < height; i++) {
  13937. if (prediction) {
  13938. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  13939. ltp ^= sltp;
  13940. if (ltp) {
  13941. bitmap.push(row);
  13942. // duplicate previous row
  13943. continue;
  13944. }
  13945. }
  13946. row = new Uint8Array(row);
  13947. bitmap.push(row);
  13948. for (j = 0; j < width; j++) {
  13949. if (useskip && skip[i][j]) {
  13950. row[j] = 0;
  13951. continue;
  13952. }
  13953. // Are we in the middle of a scanline, so we can reuse contextLabel
  13954. // bits?
  13955. if (j >= sbb_left && j < sbb_right && i >= sbb_top) {
  13956. // If yes, we can just shift the bits that are reusable and only
  13957. // fetch the remaining ones.
  13958. contextLabel = contextLabel << 1 & reuseMask;
  13959. for (k = 0; k < changingEntriesLength; k++) {
  13960. i0 = i + changingTemplateY[k];
  13961. j0 = j + changingTemplateX[k];
  13962. bit = bitmap[i0][j0];
  13963. if (bit) {
  13964. bit = changingTemplateBit[k];
  13965. contextLabel |= bit;
  13966. }
  13967. }
  13968. } else {
  13969. // compute the contextLabel from scratch
  13970. contextLabel = 0;
  13971. shift = templateLength - 1;
  13972. for (k = 0; k < templateLength; k++, shift--) {
  13973. j0 = j + templateX[k];
  13974. if (j0 >= 0 && j0 < width) {
  13975. i0 = i + templateY[k];
  13976. if (i0 >= 0) {
  13977. bit = bitmap[i0][j0];
  13978. if (bit) {
  13979. contextLabel |= bit << shift;
  13980. }
  13981. }
  13982. }
  13983. }
  13984. }
  13985. var pixel = decoder.readBit(contexts, contextLabel);
  13986. row[j] = pixel;
  13987. }
  13988. }
  13989. return bitmap;
  13990. }
  13991. // 6.3.2 Generic Refinement Region Decoding Procedure
  13992. function decodeRefinement(width, height, templateIndex, referenceBitmap, offsetX, offsetY, prediction, at, decodingContext) {
  13993. var codingTemplate = RefinementTemplates[templateIndex].coding;
  13994. if (templateIndex === 0) {
  13995. codingTemplate = codingTemplate.concat([at[0]]);
  13996. }
  13997. var codingTemplateLength = codingTemplate.length;
  13998. var codingTemplateX = new Int32Array(codingTemplateLength);
  13999. var codingTemplateY = new Int32Array(codingTemplateLength);
  14000. var k;
  14001. for (k = 0; k < codingTemplateLength; k++) {
  14002. codingTemplateX[k] = codingTemplate[k].x;
  14003. codingTemplateY[k] = codingTemplate[k].y;
  14004. }
  14005. var referenceTemplate = RefinementTemplates[templateIndex].reference;
  14006. if (templateIndex === 0) {
  14007. referenceTemplate = referenceTemplate.concat([at[1]]);
  14008. }
  14009. var referenceTemplateLength = referenceTemplate.length;
  14010. var referenceTemplateX = new Int32Array(referenceTemplateLength);
  14011. var referenceTemplateY = new Int32Array(referenceTemplateLength);
  14012. for (k = 0; k < referenceTemplateLength; k++) {
  14013. referenceTemplateX[k] = referenceTemplate[k].x;
  14014. referenceTemplateY[k] = referenceTemplate[k].y;
  14015. }
  14016. var referenceWidth = referenceBitmap[0].length;
  14017. var referenceHeight = referenceBitmap.length;
  14018. var pseudoPixelContext = RefinementReusedContexts[templateIndex];
  14019. var bitmap = [];
  14020. var decoder = decodingContext.decoder;
  14021. var contexts = decodingContext.contextCache.getContexts('GR');
  14022. var ltp = 0;
  14023. for (var i = 0; i < height; i++) {
  14024. if (prediction) {
  14025. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  14026. ltp ^= sltp;
  14027. if (ltp) {
  14028. error('JBIG2 error: prediction is not supported');
  14029. }
  14030. }
  14031. var row = new Uint8Array(width);
  14032. bitmap.push(row);
  14033. for (var j = 0; j < width; j++) {
  14034. var i0, j0;
  14035. var contextLabel = 0;
  14036. for (k = 0; k < codingTemplateLength; k++) {
  14037. i0 = i + codingTemplateY[k];
  14038. j0 = j + codingTemplateX[k];
  14039. if (i0 < 0 || j0 < 0 || j0 >= width) {
  14040. contextLabel <<= 1;
  14041. } else
  14042. // out of bound pixel
  14043. {
  14044. contextLabel = contextLabel << 1 | bitmap[i0][j0];
  14045. }
  14046. }
  14047. for (k = 0; k < referenceTemplateLength; k++) {
  14048. i0 = i + referenceTemplateY[k] + offsetY;
  14049. j0 = j + referenceTemplateX[k] + offsetX;
  14050. if (i0 < 0 || i0 >= referenceHeight || j0 < 0 || j0 >= referenceWidth) {
  14051. contextLabel <<= 1;
  14052. } else
  14053. // out of bound pixel
  14054. {
  14055. contextLabel = contextLabel << 1 | referenceBitmap[i0][j0];
  14056. }
  14057. }
  14058. var pixel = decoder.readBit(contexts, contextLabel);
  14059. row[j] = pixel;
  14060. }
  14061. }
  14062. return bitmap;
  14063. }
  14064. // 6.5.5 Decoding the symbol dictionary
  14065. function decodeSymbolDictionary(huffman, refinement, symbols, numberOfNewSymbols, numberOfExportedSymbols, huffmanTables, templateIndex, at, refinementTemplateIndex, refinementAt, decodingContext) {
  14066. if (huffman) {
  14067. error('JBIG2 error: huffman is not supported');
  14068. }
  14069. var newSymbols = [];
  14070. var currentHeight = 0;
  14071. var symbolCodeLength = log2(symbols.length + numberOfNewSymbols);
  14072. var decoder = decodingContext.decoder;
  14073. var contextCache = decodingContext.contextCache;
  14074. while (newSymbols.length < numberOfNewSymbols) {
  14075. var deltaHeight = decodeInteger(contextCache, 'IADH', decoder);
  14076. // 6.5.6
  14077. currentHeight += deltaHeight;
  14078. var currentWidth = 0;
  14079. var totalWidth = 0;
  14080. while (true) {
  14081. var deltaWidth = decodeInteger(contextCache, 'IADW', decoder);
  14082. // 6.5.7
  14083. if (deltaWidth === null) {
  14084. break;
  14085. }
  14086. // OOB
  14087. currentWidth += deltaWidth;
  14088. totalWidth += currentWidth;
  14089. var bitmap;
  14090. if (refinement) {
  14091. // 6.5.8.2 Refinement/aggregate-coded symbol bitmap
  14092. var numberOfInstances = decodeInteger(contextCache, 'IAAI', decoder);
  14093. if (numberOfInstances > 1) {
  14094. bitmap = decodeTextRegion(huffman, refinement, currentWidth, currentHeight, 0, numberOfInstances, 1, //strip size
  14095. symbols.concat(newSymbols), symbolCodeLength, 0, //transposed
  14096. 0, //ds offset
  14097. 1, //top left 7.4.3.1.1
  14098. 0, //OR operator
  14099. huffmanTables, refinementTemplateIndex, refinementAt, decodingContext);
  14100. } else {
  14101. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  14102. var rdx = decodeInteger(contextCache, 'IARDX', decoder);
  14103. // 6.4.11.3
  14104. var rdy = decodeInteger(contextCache, 'IARDY', decoder);
  14105. // 6.4.11.4
  14106. var symbol = symbolId < symbols.length ? symbols[symbolId] : newSymbols[symbolId - symbols.length];
  14107. bitmap = decodeRefinement(currentWidth, currentHeight, refinementTemplateIndex, symbol, rdx, rdy, false, refinementAt, decodingContext);
  14108. }
  14109. } else {
  14110. // 6.5.8.1 Direct-coded symbol bitmap
  14111. bitmap = decodeBitmap(false, currentWidth, currentHeight, templateIndex, false, null, at, decodingContext);
  14112. }
  14113. newSymbols.push(bitmap);
  14114. }
  14115. }
  14116. // 6.5.10 Exported symbols
  14117. var exportedSymbols = [];
  14118. var flags = [], currentFlag = false;
  14119. var totalSymbolsLength = symbols.length + numberOfNewSymbols;
  14120. while (flags.length < totalSymbolsLength) {
  14121. var runLength = decodeInteger(contextCache, 'IAEX', decoder);
  14122. while (runLength--) {
  14123. flags.push(currentFlag);
  14124. }
  14125. currentFlag = !currentFlag;
  14126. }
  14127. for (var i = 0, ii = symbols.length; i < ii; i++) {
  14128. if (flags[i]) {
  14129. exportedSymbols.push(symbols[i]);
  14130. }
  14131. }
  14132. for (var j = 0; j < numberOfNewSymbols; i++, j++) {
  14133. if (flags[i]) {
  14134. exportedSymbols.push(newSymbols[j]);
  14135. }
  14136. }
  14137. return exportedSymbols;
  14138. }
  14139. function decodeTextRegion(huffman, refinement, width, height, defaultPixelValue, numberOfSymbolInstances, stripSize, inputSymbols, symbolCodeLength, transposed, dsOffset, referenceCorner, combinationOperator, huffmanTables, refinementTemplateIndex, refinementAt, decodingContext) {
  14140. if (huffman) {
  14141. error('JBIG2 error: huffman is not supported');
  14142. }
  14143. // Prepare bitmap
  14144. var bitmap = [];
  14145. var i, row;
  14146. for (i = 0; i < height; i++) {
  14147. row = new Uint8Array(width);
  14148. if (defaultPixelValue) {
  14149. for (var j = 0; j < width; j++) {
  14150. row[j] = defaultPixelValue;
  14151. }
  14152. }
  14153. bitmap.push(row);
  14154. }
  14155. var decoder = decodingContext.decoder;
  14156. var contextCache = decodingContext.contextCache;
  14157. var stripT = -decodeInteger(contextCache, 'IADT', decoder);
  14158. // 6.4.6
  14159. var firstS = 0;
  14160. i = 0;
  14161. while (i < numberOfSymbolInstances) {
  14162. var deltaT = decodeInteger(contextCache, 'IADT', decoder);
  14163. // 6.4.6
  14164. stripT += deltaT;
  14165. var deltaFirstS = decodeInteger(contextCache, 'IAFS', decoder);
  14166. // 6.4.7
  14167. firstS += deltaFirstS;
  14168. var currentS = firstS;
  14169. do {
  14170. var currentT = stripSize === 1 ? 0 : decodeInteger(contextCache, 'IAIT', decoder);
  14171. // 6.4.9
  14172. var t = stripSize * stripT + currentT;
  14173. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  14174. var applyRefinement = refinement && decodeInteger(contextCache, 'IARI', decoder);
  14175. var symbolBitmap = inputSymbols[symbolId];
  14176. var symbolWidth = symbolBitmap[0].length;
  14177. var symbolHeight = symbolBitmap.length;
  14178. if (applyRefinement) {
  14179. var rdw = decodeInteger(contextCache, 'IARDW', decoder);
  14180. // 6.4.11.1
  14181. var rdh = decodeInteger(contextCache, 'IARDH', decoder);
  14182. // 6.4.11.2
  14183. var rdx = decodeInteger(contextCache, 'IARDX', decoder);
  14184. // 6.4.11.3
  14185. var rdy = decodeInteger(contextCache, 'IARDY', decoder);
  14186. // 6.4.11.4
  14187. symbolWidth += rdw;
  14188. symbolHeight += rdh;
  14189. symbolBitmap = decodeRefinement(symbolWidth, symbolHeight, refinementTemplateIndex, symbolBitmap, (rdw >> 1) + rdx, (rdh >> 1) + rdy, false, refinementAt, decodingContext);
  14190. }
  14191. var offsetT = t - (referenceCorner & 1 ? 0 : symbolHeight);
  14192. var offsetS = currentS - (referenceCorner & 2 ? symbolWidth : 0);
  14193. var s2, t2, symbolRow;
  14194. if (transposed) {
  14195. // Place Symbol Bitmap from T1,S1
  14196. for (s2 = 0; s2 < symbolHeight; s2++) {
  14197. row = bitmap[offsetS + s2];
  14198. if (!row) {
  14199. continue;
  14200. }
  14201. symbolRow = symbolBitmap[s2];
  14202. // To ignore Parts of Symbol bitmap which goes
  14203. // outside bitmap region
  14204. var maxWidth = Math.min(width - offsetT, symbolWidth);
  14205. switch (combinationOperator) {
  14206. case 0:
  14207. // OR
  14208. for (t2 = 0; t2 < maxWidth; t2++) {
  14209. row[offsetT + t2] |= symbolRow[t2];
  14210. }
  14211. break;
  14212. case 2:
  14213. // XOR
  14214. for (t2 = 0; t2 < maxWidth; t2++) {
  14215. row[offsetT + t2] ^= symbolRow[t2];
  14216. }
  14217. break;
  14218. default:
  14219. error('JBIG2 error: operator ' + combinationOperator + ' is not supported');
  14220. }
  14221. }
  14222. currentS += symbolHeight - 1;
  14223. } else {
  14224. for (t2 = 0; t2 < symbolHeight; t2++) {
  14225. row = bitmap[offsetT + t2];
  14226. if (!row) {
  14227. continue;
  14228. }
  14229. symbolRow = symbolBitmap[t2];
  14230. switch (combinationOperator) {
  14231. case 0:
  14232. // OR
  14233. for (s2 = 0; s2 < symbolWidth; s2++) {
  14234. row[offsetS + s2] |= symbolRow[s2];
  14235. }
  14236. break;
  14237. case 2:
  14238. // XOR
  14239. for (s2 = 0; s2 < symbolWidth; s2++) {
  14240. row[offsetS + s2] ^= symbolRow[s2];
  14241. }
  14242. break;
  14243. default:
  14244. error('JBIG2 error: operator ' + combinationOperator + ' is not supported');
  14245. }
  14246. }
  14247. currentS += symbolWidth - 1;
  14248. }
  14249. i++;
  14250. var deltaS = decodeInteger(contextCache, 'IADS', decoder);
  14251. // 6.4.8
  14252. if (deltaS === null) {
  14253. break;
  14254. }
  14255. // OOB
  14256. currentS += deltaS + dsOffset;
  14257. } while (true);
  14258. }
  14259. return bitmap;
  14260. }
  14261. function readSegmentHeader(data, start) {
  14262. var segmentHeader = {};
  14263. segmentHeader.number = readUint32(data, start);
  14264. var flags = data[start + 4];
  14265. var segmentType = flags & 0x3F;
  14266. if (!SegmentTypes[segmentType]) {
  14267. error('JBIG2 error: invalid segment type: ' + segmentType);
  14268. }
  14269. segmentHeader.type = segmentType;
  14270. segmentHeader.typeName = SegmentTypes[segmentType];
  14271. segmentHeader.deferredNonRetain = !!(flags & 0x80);
  14272. var pageAssociationFieldSize = !!(flags & 0x40);
  14273. var referredFlags = data[start + 5];
  14274. var referredToCount = referredFlags >> 5 & 7;
  14275. var retainBits = [referredFlags & 31];
  14276. var position = start + 6;
  14277. if (referredFlags === 7) {
  14278. referredToCount = readUint32(data, position - 1) & 0x1FFFFFFF;
  14279. position += 3;
  14280. var bytes = referredToCount + 7 >> 3;
  14281. retainBits[0] = data[position++];
  14282. while (--bytes > 0) {
  14283. retainBits.push(data[position++]);
  14284. }
  14285. } else if (referredFlags === 5 || referredFlags === 6) {
  14286. error('JBIG2 error: invalid referred-to flags');
  14287. }
  14288. segmentHeader.retainBits = retainBits;
  14289. var referredToSegmentNumberSize = segmentHeader.number <= 256 ? 1 : segmentHeader.number <= 65536 ? 2 : 4;
  14290. var referredTo = [];
  14291. var i, ii;
  14292. for (i = 0; i < referredToCount; i++) {
  14293. var number = referredToSegmentNumberSize === 1 ? data[position] : referredToSegmentNumberSize === 2 ? readUint16(data, position) : readUint32(data, position);
  14294. referredTo.push(number);
  14295. position += referredToSegmentNumberSize;
  14296. }
  14297. segmentHeader.referredTo = referredTo;
  14298. if (!pageAssociationFieldSize) {
  14299. segmentHeader.pageAssociation = data[position++];
  14300. } else {
  14301. segmentHeader.pageAssociation = readUint32(data, position);
  14302. position += 4;
  14303. }
  14304. segmentHeader.length = readUint32(data, position);
  14305. position += 4;
  14306. if (segmentHeader.length === 0xFFFFFFFF) {
  14307. // 7.2.7 Segment data length, unknown segment length
  14308. if (segmentType === 38) {
  14309. // ImmediateGenericRegion
  14310. var genericRegionInfo = readRegionSegmentInformation(data, position);
  14311. var genericRegionSegmentFlags = data[position + RegionSegmentInformationFieldLength];
  14312. var genericRegionMmr = !!(genericRegionSegmentFlags & 1);
  14313. // searching for the segment end
  14314. var searchPatternLength = 6;
  14315. var searchPattern = new Uint8Array(searchPatternLength);
  14316. if (!genericRegionMmr) {
  14317. searchPattern[0] = 0xFF;
  14318. searchPattern[1] = 0xAC;
  14319. }
  14320. searchPattern[2] = genericRegionInfo.height >>> 24 & 0xFF;
  14321. searchPattern[3] = genericRegionInfo.height >> 16 & 0xFF;
  14322. searchPattern[4] = genericRegionInfo.height >> 8 & 0xFF;
  14323. searchPattern[5] = genericRegionInfo.height & 0xFF;
  14324. for (i = position, ii = data.length; i < ii; i++) {
  14325. var j = 0;
  14326. while (j < searchPatternLength && searchPattern[j] === data[i + j]) {
  14327. j++;
  14328. }
  14329. if (j === searchPatternLength) {
  14330. segmentHeader.length = i + searchPatternLength;
  14331. break;
  14332. }
  14333. }
  14334. if (segmentHeader.length === 0xFFFFFFFF) {
  14335. error('JBIG2 error: segment end was not found');
  14336. }
  14337. } else {
  14338. error('JBIG2 error: invalid unknown segment length');
  14339. }
  14340. }
  14341. segmentHeader.headerEnd = position;
  14342. return segmentHeader;
  14343. }
  14344. function readSegments(header, data, start, end) {
  14345. var segments = [];
  14346. var position = start;
  14347. while (position < end) {
  14348. var segmentHeader = readSegmentHeader(data, position);
  14349. position = segmentHeader.headerEnd;
  14350. var segment = {
  14351. header: segmentHeader,
  14352. data: data
  14353. };
  14354. if (!header.randomAccess) {
  14355. segment.start = position;
  14356. position += segmentHeader.length;
  14357. segment.end = position;
  14358. }
  14359. segments.push(segment);
  14360. if (segmentHeader.type === 51) {
  14361. break;
  14362. }
  14363. }
  14364. // end of file is found
  14365. if (header.randomAccess) {
  14366. for (var i = 0, ii = segments.length; i < ii; i++) {
  14367. segments[i].start = position;
  14368. position += segments[i].header.length;
  14369. segments[i].end = position;
  14370. }
  14371. }
  14372. return segments;
  14373. }
  14374. // 7.4.1 Region segment information field
  14375. function readRegionSegmentInformation(data, start) {
  14376. return {
  14377. width: readUint32(data, start),
  14378. height: readUint32(data, start + 4),
  14379. x: readUint32(data, start + 8),
  14380. y: readUint32(data, start + 12),
  14381. combinationOperator: data[start + 16] & 7
  14382. };
  14383. }
  14384. var RegionSegmentInformationFieldLength = 17;
  14385. function processSegment(segment, visitor) {
  14386. var header = segment.header;
  14387. var data = segment.data, position = segment.start, end = segment.end;
  14388. var args, at, i, atLength;
  14389. switch (header.type) {
  14390. case 0:
  14391. // SymbolDictionary
  14392. // 7.4.2 Symbol dictionary segment syntax
  14393. var dictionary = {};
  14394. var dictionaryFlags = readUint16(data, position);
  14395. // 7.4.2.1.1
  14396. dictionary.huffman = !!(dictionaryFlags & 1);
  14397. dictionary.refinement = !!(dictionaryFlags & 2);
  14398. dictionary.huffmanDHSelector = dictionaryFlags >> 2 & 3;
  14399. dictionary.huffmanDWSelector = dictionaryFlags >> 4 & 3;
  14400. dictionary.bitmapSizeSelector = dictionaryFlags >> 6 & 1;
  14401. dictionary.aggregationInstancesSelector = dictionaryFlags >> 7 & 1;
  14402. dictionary.bitmapCodingContextUsed = !!(dictionaryFlags & 256);
  14403. dictionary.bitmapCodingContextRetained = !!(dictionaryFlags & 512);
  14404. dictionary.template = dictionaryFlags >> 10 & 3;
  14405. dictionary.refinementTemplate = dictionaryFlags >> 12 & 1;
  14406. position += 2;
  14407. if (!dictionary.huffman) {
  14408. atLength = dictionary.template === 0 ? 4 : 1;
  14409. at = [];
  14410. for (i = 0; i < atLength; i++) {
  14411. at.push({
  14412. x: readInt8(data, position),
  14413. y: readInt8(data, position + 1)
  14414. });
  14415. position += 2;
  14416. }
  14417. dictionary.at = at;
  14418. }
  14419. if (dictionary.refinement && !dictionary.refinementTemplate) {
  14420. at = [];
  14421. for (i = 0; i < 2; i++) {
  14422. at.push({
  14423. x: readInt8(data, position),
  14424. y: readInt8(data, position + 1)
  14425. });
  14426. position += 2;
  14427. }
  14428. dictionary.refinementAt = at;
  14429. }
  14430. dictionary.numberOfExportedSymbols = readUint32(data, position);
  14431. position += 4;
  14432. dictionary.numberOfNewSymbols = readUint32(data, position);
  14433. position += 4;
  14434. args = [
  14435. dictionary,
  14436. header.number,
  14437. header.referredTo,
  14438. data,
  14439. position,
  14440. end
  14441. ];
  14442. break;
  14443. case 6:
  14444. // ImmediateTextRegion
  14445. case 7:
  14446. // ImmediateLosslessTextRegion
  14447. var textRegion = {};
  14448. textRegion.info = readRegionSegmentInformation(data, position);
  14449. position += RegionSegmentInformationFieldLength;
  14450. var textRegionSegmentFlags = readUint16(data, position);
  14451. position += 2;
  14452. textRegion.huffman = !!(textRegionSegmentFlags & 1);
  14453. textRegion.refinement = !!(textRegionSegmentFlags & 2);
  14454. textRegion.stripSize = 1 << (textRegionSegmentFlags >> 2 & 3);
  14455. textRegion.referenceCorner = textRegionSegmentFlags >> 4 & 3;
  14456. textRegion.transposed = !!(textRegionSegmentFlags & 64);
  14457. textRegion.combinationOperator = textRegionSegmentFlags >> 7 & 3;
  14458. textRegion.defaultPixelValue = textRegionSegmentFlags >> 9 & 1;
  14459. textRegion.dsOffset = textRegionSegmentFlags << 17 >> 27;
  14460. textRegion.refinementTemplate = textRegionSegmentFlags >> 15 & 1;
  14461. if (textRegion.huffman) {
  14462. var textRegionHuffmanFlags = readUint16(data, position);
  14463. position += 2;
  14464. textRegion.huffmanFS = textRegionHuffmanFlags & 3;
  14465. textRegion.huffmanDS = textRegionHuffmanFlags >> 2 & 3;
  14466. textRegion.huffmanDT = textRegionHuffmanFlags >> 4 & 3;
  14467. textRegion.huffmanRefinementDW = textRegionHuffmanFlags >> 6 & 3;
  14468. textRegion.huffmanRefinementDH = textRegionHuffmanFlags >> 8 & 3;
  14469. textRegion.huffmanRefinementDX = textRegionHuffmanFlags >> 10 & 3;
  14470. textRegion.huffmanRefinementDY = textRegionHuffmanFlags >> 12 & 3;
  14471. textRegion.huffmanRefinementSizeSelector = !!(textRegionHuffmanFlags & 14);
  14472. }
  14473. if (textRegion.refinement && !textRegion.refinementTemplate) {
  14474. at = [];
  14475. for (i = 0; i < 2; i++) {
  14476. at.push({
  14477. x: readInt8(data, position),
  14478. y: readInt8(data, position + 1)
  14479. });
  14480. position += 2;
  14481. }
  14482. textRegion.refinementAt = at;
  14483. }
  14484. textRegion.numberOfSymbolInstances = readUint32(data, position);
  14485. position += 4;
  14486. // TODO 7.4.3.1.7 Symbol ID Huffman table decoding
  14487. if (textRegion.huffman) {
  14488. error('JBIG2 error: huffman is not supported');
  14489. }
  14490. args = [
  14491. textRegion,
  14492. header.referredTo,
  14493. data,
  14494. position,
  14495. end
  14496. ];
  14497. break;
  14498. case 38:
  14499. // ImmediateGenericRegion
  14500. case 39:
  14501. // ImmediateLosslessGenericRegion
  14502. var genericRegion = {};
  14503. genericRegion.info = readRegionSegmentInformation(data, position);
  14504. position += RegionSegmentInformationFieldLength;
  14505. var genericRegionSegmentFlags = data[position++];
  14506. genericRegion.mmr = !!(genericRegionSegmentFlags & 1);
  14507. genericRegion.template = genericRegionSegmentFlags >> 1 & 3;
  14508. genericRegion.prediction = !!(genericRegionSegmentFlags & 8);
  14509. if (!genericRegion.mmr) {
  14510. atLength = genericRegion.template === 0 ? 4 : 1;
  14511. at = [];
  14512. for (i = 0; i < atLength; i++) {
  14513. at.push({
  14514. x: readInt8(data, position),
  14515. y: readInt8(data, position + 1)
  14516. });
  14517. position += 2;
  14518. }
  14519. genericRegion.at = at;
  14520. }
  14521. args = [
  14522. genericRegion,
  14523. data,
  14524. position,
  14525. end
  14526. ];
  14527. break;
  14528. case 48:
  14529. // PageInformation
  14530. var pageInfo = {
  14531. width: readUint32(data, position),
  14532. height: readUint32(data, position + 4),
  14533. resolutionX: readUint32(data, position + 8),
  14534. resolutionY: readUint32(data, position + 12)
  14535. };
  14536. if (pageInfo.height === 0xFFFFFFFF) {
  14537. delete pageInfo.height;
  14538. }
  14539. var pageSegmentFlags = data[position + 16];
  14540. var pageStripingInformation = readUint16(data, position + 17);
  14541. pageInfo.lossless = !!(pageSegmentFlags & 1);
  14542. pageInfo.refinement = !!(pageSegmentFlags & 2);
  14543. pageInfo.defaultPixelValue = pageSegmentFlags >> 2 & 1;
  14544. pageInfo.combinationOperator = pageSegmentFlags >> 3 & 3;
  14545. pageInfo.requiresBuffer = !!(pageSegmentFlags & 32);
  14546. pageInfo.combinationOperatorOverride = !!(pageSegmentFlags & 64);
  14547. args = [pageInfo];
  14548. break;
  14549. case 49:
  14550. // EndOfPage
  14551. break;
  14552. case 50:
  14553. // EndOfStripe
  14554. break;
  14555. case 51:
  14556. // EndOfFile
  14557. break;
  14558. case 62:
  14559. // 7.4.15 defines 2 extension types which
  14560. // are comments and can be ignored.
  14561. break;
  14562. default:
  14563. error('JBIG2 error: segment type ' + header.typeName + '(' + header.type + ') is not implemented');
  14564. }
  14565. var callbackName = 'on' + header.typeName;
  14566. if (callbackName in visitor) {
  14567. visitor[callbackName].apply(visitor, args);
  14568. }
  14569. }
  14570. function processSegments(segments, visitor) {
  14571. for (var i = 0, ii = segments.length; i < ii; i++) {
  14572. processSegment(segments[i], visitor);
  14573. }
  14574. }
  14575. function parseJbig2(data, start, end) {
  14576. var position = start;
  14577. 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) {
  14578. error('JBIG2 error: invalid header');
  14579. }
  14580. var header = {};
  14581. position += 8;
  14582. var flags = data[position++];
  14583. header.randomAccess = !(flags & 1);
  14584. if (!(flags & 2)) {
  14585. header.numberOfPages = readUint32(data, position);
  14586. position += 4;
  14587. }
  14588. var segments = readSegments(header, data, position, end);
  14589. error('Not implemented');
  14590. }
  14591. // processSegments(segments, new SimpleSegmentVisitor());
  14592. function parseJbig2Chunks(chunks) {
  14593. var visitor = new SimpleSegmentVisitor();
  14594. for (var i = 0, ii = chunks.length; i < ii; i++) {
  14595. var chunk = chunks[i];
  14596. var segments = readSegments({}, chunk.data, chunk.start, chunk.end);
  14597. processSegments(segments, visitor);
  14598. }
  14599. return visitor.buffer;
  14600. }
  14601. function SimpleSegmentVisitor() {
  14602. }
  14603. SimpleSegmentVisitor.prototype = {
  14604. onPageInformation: function SimpleSegmentVisitor_onPageInformation(info) {
  14605. this.currentPageInfo = info;
  14606. var rowSize = info.width + 7 >> 3;
  14607. var buffer = new Uint8Array(rowSize * info.height);
  14608. // The contents of ArrayBuffers are initialized to 0.
  14609. // Fill the buffer with 0xFF only if info.defaultPixelValue is set
  14610. if (info.defaultPixelValue) {
  14611. for (var i = 0, ii = buffer.length; i < ii; i++) {
  14612. buffer[i] = 0xFF;
  14613. }
  14614. }
  14615. this.buffer = buffer;
  14616. },
  14617. drawBitmap: function SimpleSegmentVisitor_drawBitmap(regionInfo, bitmap) {
  14618. var pageInfo = this.currentPageInfo;
  14619. var width = regionInfo.width, height = regionInfo.height;
  14620. var rowSize = pageInfo.width + 7 >> 3;
  14621. var combinationOperator = pageInfo.combinationOperatorOverride ? regionInfo.combinationOperator : pageInfo.combinationOperator;
  14622. var buffer = this.buffer;
  14623. var mask0 = 128 >> (regionInfo.x & 7);
  14624. var offset0 = regionInfo.y * rowSize + (regionInfo.x >> 3);
  14625. var i, j, mask, offset;
  14626. switch (combinationOperator) {
  14627. case 0:
  14628. // OR
  14629. for (i = 0; i < height; i++) {
  14630. mask = mask0;
  14631. offset = offset0;
  14632. for (j = 0; j < width; j++) {
  14633. if (bitmap[i][j]) {
  14634. buffer[offset] |= mask;
  14635. }
  14636. mask >>= 1;
  14637. if (!mask) {
  14638. mask = 128;
  14639. offset++;
  14640. }
  14641. }
  14642. offset0 += rowSize;
  14643. }
  14644. break;
  14645. case 2:
  14646. // XOR
  14647. for (i = 0; i < height; i++) {
  14648. mask = mask0;
  14649. offset = offset0;
  14650. for (j = 0; j < width; j++) {
  14651. if (bitmap[i][j]) {
  14652. buffer[offset] ^= mask;
  14653. }
  14654. mask >>= 1;
  14655. if (!mask) {
  14656. mask = 128;
  14657. offset++;
  14658. }
  14659. }
  14660. offset0 += rowSize;
  14661. }
  14662. break;
  14663. default:
  14664. error('JBIG2 error: operator ' + combinationOperator + ' is not supported');
  14665. }
  14666. },
  14667. onImmediateGenericRegion: function SimpleSegmentVisitor_onImmediateGenericRegion(region, data, start, end) {
  14668. var regionInfo = region.info;
  14669. var decodingContext = new DecodingContext(data, start, end);
  14670. var bitmap = decodeBitmap(region.mmr, regionInfo.width, regionInfo.height, region.template, region.prediction, null, region.at, decodingContext);
  14671. this.drawBitmap(regionInfo, bitmap);
  14672. },
  14673. onImmediateLosslessGenericRegion: function SimpleSegmentVisitor_onImmediateLosslessGenericRegion() {
  14674. this.onImmediateGenericRegion.apply(this, arguments);
  14675. },
  14676. onSymbolDictionary: function SimpleSegmentVisitor_onSymbolDictionary(dictionary, currentSegment, referredSegments, data, start, end) {
  14677. var huffmanTables;
  14678. if (dictionary.huffman) {
  14679. error('JBIG2 error: huffman is not supported');
  14680. }
  14681. // Combines exported symbols from all referred segments
  14682. var symbols = this.symbols;
  14683. if (!symbols) {
  14684. this.symbols = symbols = {};
  14685. }
  14686. var inputSymbols = [];
  14687. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  14688. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  14689. }
  14690. var decodingContext = new DecodingContext(data, start, end);
  14691. symbols[currentSegment] = decodeSymbolDictionary(dictionary.huffman, dictionary.refinement, inputSymbols, dictionary.numberOfNewSymbols, dictionary.numberOfExportedSymbols, huffmanTables, dictionary.template, dictionary.at, dictionary.refinementTemplate, dictionary.refinementAt, decodingContext);
  14692. },
  14693. onImmediateTextRegion: function SimpleSegmentVisitor_onImmediateTextRegion(region, referredSegments, data, start, end) {
  14694. var regionInfo = region.info;
  14695. var huffmanTables;
  14696. // Combines exported symbols from all referred segments
  14697. var symbols = this.symbols;
  14698. var inputSymbols = [];
  14699. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  14700. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  14701. }
  14702. var symbolCodeLength = log2(inputSymbols.length);
  14703. var decodingContext = new DecodingContext(data, start, end);
  14704. 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);
  14705. this.drawBitmap(regionInfo, bitmap);
  14706. },
  14707. onImmediateLosslessTextRegion: function SimpleSegmentVisitor_onImmediateLosslessTextRegion() {
  14708. this.onImmediateTextRegion.apply(this, arguments);
  14709. }
  14710. };
  14711. function Jbig2Image() {
  14712. }
  14713. Jbig2Image.prototype = {
  14714. parseChunks: function Jbig2Image_parseChunks(chunks) {
  14715. return parseJbig2Chunks(chunks);
  14716. }
  14717. };
  14718. return Jbig2Image;
  14719. }();
  14720. exports.Jbig2Image = Jbig2Image;
  14721. }));
  14722. (function (root, factory) {
  14723. factory(root.pdfjsCoreJpg = {}, root.pdfjsSharedUtil);
  14724. }(this, function (exports, sharedUtil) {
  14725. var error = sharedUtil.error;
  14726. /**
  14727. * This code was forked from https://github.com/notmasteryet/jpgjs.
  14728. * The original version was created by GitHub user notmasteryet.
  14729. *
  14730. * - The JPEG specification can be found in the ITU CCITT Recommendation T.81
  14731. * (www.w3.org/Graphics/JPEG/itu-t81.pdf)
  14732. * - The JFIF specification can be found in the JPEG File Interchange Format
  14733. * (www.w3.org/Graphics/JPEG/jfif3.pdf)
  14734. * - The Adobe Application-Specific JPEG markers in the
  14735. * Supporting the DCT Filters in PostScript Level 2, Technical Note #5116
  14736. * (partners.adobe.com/public/developer/en/ps/sdk/5116.DCT_Filter.pdf)
  14737. */
  14738. var JpegImage = function JpegImageClosure() {
  14739. var dctZigZag = new Uint8Array([
  14740. 0,
  14741. 1,
  14742. 8,
  14743. 16,
  14744. 9,
  14745. 2,
  14746. 3,
  14747. 10,
  14748. 17,
  14749. 24,
  14750. 32,
  14751. 25,
  14752. 18,
  14753. 11,
  14754. 4,
  14755. 5,
  14756. 12,
  14757. 19,
  14758. 26,
  14759. 33,
  14760. 40,
  14761. 48,
  14762. 41,
  14763. 34,
  14764. 27,
  14765. 20,
  14766. 13,
  14767. 6,
  14768. 7,
  14769. 14,
  14770. 21,
  14771. 28,
  14772. 35,
  14773. 42,
  14774. 49,
  14775. 56,
  14776. 57,
  14777. 50,
  14778. 43,
  14779. 36,
  14780. 29,
  14781. 22,
  14782. 15,
  14783. 23,
  14784. 30,
  14785. 37,
  14786. 44,
  14787. 51,
  14788. 58,
  14789. 59,
  14790. 52,
  14791. 45,
  14792. 38,
  14793. 31,
  14794. 39,
  14795. 46,
  14796. 53,
  14797. 60,
  14798. 61,
  14799. 54,
  14800. 47,
  14801. 55,
  14802. 62,
  14803. 63
  14804. ]);
  14805. var dctCos1 = 4017;
  14806. // cos(pi/16)
  14807. var dctSin1 = 799;
  14808. // sin(pi/16)
  14809. var dctCos3 = 3406;
  14810. // cos(3*pi/16)
  14811. var dctSin3 = 2276;
  14812. // sin(3*pi/16)
  14813. var dctCos6 = 1567;
  14814. // cos(6*pi/16)
  14815. var dctSin6 = 3784;
  14816. // sin(6*pi/16)
  14817. var dctSqrt2 = 5793;
  14818. // sqrt(2)
  14819. var dctSqrt1d2 = 2896;
  14820. // sqrt(2) / 2
  14821. function JpegImage() {
  14822. this.decodeTransform = null;
  14823. this.colorTransform = -1;
  14824. }
  14825. function buildHuffmanTable(codeLengths, values) {
  14826. var k = 0, code = [], i, j, length = 16;
  14827. while (length > 0 && !codeLengths[length - 1]) {
  14828. length--;
  14829. }
  14830. code.push({
  14831. children: [],
  14832. index: 0
  14833. });
  14834. var p = code[0], q;
  14835. for (i = 0; i < length; i++) {
  14836. for (j = 0; j < codeLengths[i]; j++) {
  14837. p = code.pop();
  14838. p.children[p.index] = values[k];
  14839. while (p.index > 0) {
  14840. p = code.pop();
  14841. }
  14842. p.index++;
  14843. code.push(p);
  14844. while (code.length <= i) {
  14845. code.push(q = {
  14846. children: [],
  14847. index: 0
  14848. });
  14849. p.children[p.index] = q.children;
  14850. p = q;
  14851. }
  14852. k++;
  14853. }
  14854. if (i + 1 < length) {
  14855. // p here points to last code
  14856. code.push(q = {
  14857. children: [],
  14858. index: 0
  14859. });
  14860. p.children[p.index] = q.children;
  14861. p = q;
  14862. }
  14863. }
  14864. return code[0].children;
  14865. }
  14866. function getBlockBufferOffset(component, row, col) {
  14867. return 64 * ((component.blocksPerLine + 1) * row + col);
  14868. }
  14869. function decodeScan(data, offset, frame, components, resetInterval, spectralStart, spectralEnd, successivePrev, successive) {
  14870. var mcusPerLine = frame.mcusPerLine;
  14871. var progressive = frame.progressive;
  14872. var startOffset = offset, bitsData = 0, bitsCount = 0;
  14873. function readBit() {
  14874. if (bitsCount > 0) {
  14875. bitsCount--;
  14876. return bitsData >> bitsCount & 1;
  14877. }
  14878. bitsData = data[offset++];
  14879. if (bitsData === 0xFF) {
  14880. var nextByte = data[offset++];
  14881. if (nextByte) {
  14882. error('JPEG error: unexpected marker ' + (bitsData << 8 | nextByte).toString(16));
  14883. }
  14884. }
  14885. // unstuff 0
  14886. bitsCount = 7;
  14887. return bitsData >>> 7;
  14888. }
  14889. function decodeHuffman(tree) {
  14890. var node = tree;
  14891. while (true) {
  14892. node = node[readBit()];
  14893. if (typeof node === 'number') {
  14894. return node;
  14895. }
  14896. if (typeof node !== 'object') {
  14897. error('JPEG error: invalid huffman sequence');
  14898. }
  14899. }
  14900. }
  14901. function receive(length) {
  14902. var n = 0;
  14903. while (length > 0) {
  14904. n = n << 1 | readBit();
  14905. length--;
  14906. }
  14907. return n;
  14908. }
  14909. function receiveAndExtend(length) {
  14910. if (length === 1) {
  14911. return readBit() === 1 ? 1 : -1;
  14912. }
  14913. var n = receive(length);
  14914. if (n >= 1 << length - 1) {
  14915. return n;
  14916. }
  14917. return n + (-1 << length) + 1;
  14918. }
  14919. function decodeBaseline(component, offset) {
  14920. var t = decodeHuffman(component.huffmanTableDC);
  14921. var diff = t === 0 ? 0 : receiveAndExtend(t);
  14922. component.blockData[offset] = component.pred += diff;
  14923. var k = 1;
  14924. while (k < 64) {
  14925. var rs = decodeHuffman(component.huffmanTableAC);
  14926. var s = rs & 15, r = rs >> 4;
  14927. if (s === 0) {
  14928. if (r < 15) {
  14929. break;
  14930. }
  14931. k += 16;
  14932. continue;
  14933. }
  14934. k += r;
  14935. var z = dctZigZag[k];
  14936. component.blockData[offset + z] = receiveAndExtend(s);
  14937. k++;
  14938. }
  14939. }
  14940. function decodeDCFirst(component, offset) {
  14941. var t = decodeHuffman(component.huffmanTableDC);
  14942. var diff = t === 0 ? 0 : receiveAndExtend(t) << successive;
  14943. component.blockData[offset] = component.pred += diff;
  14944. }
  14945. function decodeDCSuccessive(component, offset) {
  14946. component.blockData[offset] |= readBit() << successive;
  14947. }
  14948. var eobrun = 0;
  14949. function decodeACFirst(component, offset) {
  14950. if (eobrun > 0) {
  14951. eobrun--;
  14952. return;
  14953. }
  14954. var k = spectralStart, e = spectralEnd;
  14955. while (k <= e) {
  14956. var rs = decodeHuffman(component.huffmanTableAC);
  14957. var s = rs & 15, r = rs >> 4;
  14958. if (s === 0) {
  14959. if (r < 15) {
  14960. eobrun = receive(r) + (1 << r) - 1;
  14961. break;
  14962. }
  14963. k += 16;
  14964. continue;
  14965. }
  14966. k += r;
  14967. var z = dctZigZag[k];
  14968. component.blockData[offset + z] = receiveAndExtend(s) * (1 << successive);
  14969. k++;
  14970. }
  14971. }
  14972. var successiveACState = 0, successiveACNextValue;
  14973. function decodeACSuccessive(component, offset) {
  14974. var k = spectralStart;
  14975. var e = spectralEnd;
  14976. var r = 0;
  14977. var s;
  14978. var rs;
  14979. while (k <= e) {
  14980. var z = dctZigZag[k];
  14981. switch (successiveACState) {
  14982. case 0:
  14983. // initial state
  14984. rs = decodeHuffman(component.huffmanTableAC);
  14985. s = rs & 15;
  14986. r = rs >> 4;
  14987. if (s === 0) {
  14988. if (r < 15) {
  14989. eobrun = receive(r) + (1 << r);
  14990. successiveACState = 4;
  14991. } else {
  14992. r = 16;
  14993. successiveACState = 1;
  14994. }
  14995. } else {
  14996. if (s !== 1) {
  14997. error('JPEG error: invalid ACn encoding');
  14998. }
  14999. successiveACNextValue = receiveAndExtend(s);
  15000. successiveACState = r ? 2 : 3;
  15001. }
  15002. continue;
  15003. case 1:
  15004. // skipping r zero items
  15005. case 2:
  15006. if (component.blockData[offset + z]) {
  15007. component.blockData[offset + z] += readBit() << successive;
  15008. } else {
  15009. r--;
  15010. if (r === 0) {
  15011. successiveACState = successiveACState === 2 ? 3 : 0;
  15012. }
  15013. }
  15014. break;
  15015. case 3:
  15016. // set value for a zero item
  15017. if (component.blockData[offset + z]) {
  15018. component.blockData[offset + z] += readBit() << successive;
  15019. } else {
  15020. component.blockData[offset + z] = successiveACNextValue << successive;
  15021. successiveACState = 0;
  15022. }
  15023. break;
  15024. case 4:
  15025. // eob
  15026. if (component.blockData[offset + z]) {
  15027. component.blockData[offset + z] += readBit() << successive;
  15028. }
  15029. break;
  15030. }
  15031. k++;
  15032. }
  15033. if (successiveACState === 4) {
  15034. eobrun--;
  15035. if (eobrun === 0) {
  15036. successiveACState = 0;
  15037. }
  15038. }
  15039. }
  15040. function decodeMcu(component, decode, mcu, row, col) {
  15041. var mcuRow = mcu / mcusPerLine | 0;
  15042. var mcuCol = mcu % mcusPerLine;
  15043. var blockRow = mcuRow * component.v + row;
  15044. var blockCol = mcuCol * component.h + col;
  15045. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  15046. decode(component, offset);
  15047. }
  15048. function decodeBlock(component, decode, mcu) {
  15049. var blockRow = mcu / component.blocksPerLine | 0;
  15050. var blockCol = mcu % component.blocksPerLine;
  15051. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  15052. decode(component, offset);
  15053. }
  15054. var componentsLength = components.length;
  15055. var component, i, j, k, n;
  15056. var decodeFn;
  15057. if (progressive) {
  15058. if (spectralStart === 0) {
  15059. decodeFn = successivePrev === 0 ? decodeDCFirst : decodeDCSuccessive;
  15060. } else {
  15061. decodeFn = successivePrev === 0 ? decodeACFirst : decodeACSuccessive;
  15062. }
  15063. } else {
  15064. decodeFn = decodeBaseline;
  15065. }
  15066. var mcu = 0, marker;
  15067. var mcuExpected;
  15068. if (componentsLength === 1) {
  15069. mcuExpected = components[0].blocksPerLine * components[0].blocksPerColumn;
  15070. } else {
  15071. mcuExpected = mcusPerLine * frame.mcusPerColumn;
  15072. }
  15073. if (!resetInterval) {
  15074. resetInterval = mcuExpected;
  15075. }
  15076. var h, v;
  15077. while (mcu < mcuExpected) {
  15078. // reset interval stuff
  15079. for (i = 0; i < componentsLength; i++) {
  15080. components[i].pred = 0;
  15081. }
  15082. eobrun = 0;
  15083. if (componentsLength === 1) {
  15084. component = components[0];
  15085. for (n = 0; n < resetInterval; n++) {
  15086. decodeBlock(component, decodeFn, mcu);
  15087. mcu++;
  15088. }
  15089. } else {
  15090. for (n = 0; n < resetInterval; n++) {
  15091. for (i = 0; i < componentsLength; i++) {
  15092. component = components[i];
  15093. h = component.h;
  15094. v = component.v;
  15095. for (j = 0; j < v; j++) {
  15096. for (k = 0; k < h; k++) {
  15097. decodeMcu(component, decodeFn, mcu, j, k);
  15098. }
  15099. }
  15100. }
  15101. mcu++;
  15102. }
  15103. }
  15104. // find marker
  15105. bitsCount = 0;
  15106. marker = data[offset] << 8 | data[offset + 1];
  15107. // Some bad images seem to pad Scan blocks with zero bytes, skip past
  15108. // those to attempt to find a valid marker (fixes issue4090.pdf).
  15109. while (data[offset] === 0x00 && offset < data.length - 1) {
  15110. offset++;
  15111. marker = data[offset] << 8 | data[offset + 1];
  15112. }
  15113. if (marker <= 0xFF00) {
  15114. error('JPEG error: marker was not found');
  15115. }
  15116. if (marker >= 0xFFD0 && marker <= 0xFFD7) {
  15117. // RSTx
  15118. offset += 2;
  15119. } else {
  15120. break;
  15121. }
  15122. }
  15123. return offset - startOffset;
  15124. }
  15125. // A port of poppler's IDCT method which in turn is taken from:
  15126. // Christoph Loeffler, Adriaan Ligtenberg, George S. Moschytz,
  15127. // 'Practical Fast 1-D DCT Algorithms with 11 Multiplications',
  15128. // IEEE Intl. Conf. on Acoustics, Speech & Signal Processing, 1989,
  15129. // 988-991.
  15130. function quantizeAndInverse(component, blockBufferOffset, p) {
  15131. var qt = component.quantizationTable, blockData = component.blockData;
  15132. var v0, v1, v2, v3, v4, v5, v6, v7;
  15133. var p0, p1, p2, p3, p4, p5, p6, p7;
  15134. var t;
  15135. if (!qt) {
  15136. error('JPEG error: missing required Quantization Table.');
  15137. }
  15138. // inverse DCT on rows
  15139. for (var row = 0; row < 64; row += 8) {
  15140. // gather block data
  15141. p0 = blockData[blockBufferOffset + row];
  15142. p1 = blockData[blockBufferOffset + row + 1];
  15143. p2 = blockData[blockBufferOffset + row + 2];
  15144. p3 = blockData[blockBufferOffset + row + 3];
  15145. p4 = blockData[blockBufferOffset + row + 4];
  15146. p5 = blockData[blockBufferOffset + row + 5];
  15147. p6 = blockData[blockBufferOffset + row + 6];
  15148. p7 = blockData[blockBufferOffset + row + 7];
  15149. // dequant p0
  15150. p0 *= qt[row];
  15151. // check for all-zero AC coefficients
  15152. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  15153. t = dctSqrt2 * p0 + 512 >> 10;
  15154. p[row] = t;
  15155. p[row + 1] = t;
  15156. p[row + 2] = t;
  15157. p[row + 3] = t;
  15158. p[row + 4] = t;
  15159. p[row + 5] = t;
  15160. p[row + 6] = t;
  15161. p[row + 7] = t;
  15162. continue;
  15163. }
  15164. // dequant p1 ... p7
  15165. p1 *= qt[row + 1];
  15166. p2 *= qt[row + 2];
  15167. p3 *= qt[row + 3];
  15168. p4 *= qt[row + 4];
  15169. p5 *= qt[row + 5];
  15170. p6 *= qt[row + 6];
  15171. p7 *= qt[row + 7];
  15172. // stage 4
  15173. v0 = dctSqrt2 * p0 + 128 >> 8;
  15174. v1 = dctSqrt2 * p4 + 128 >> 8;
  15175. v2 = p2;
  15176. v3 = p6;
  15177. v4 = dctSqrt1d2 * (p1 - p7) + 128 >> 8;
  15178. v7 = dctSqrt1d2 * (p1 + p7) + 128 >> 8;
  15179. v5 = p3 << 4;
  15180. v6 = p5 << 4;
  15181. // stage 3
  15182. v0 = v0 + v1 + 1 >> 1;
  15183. v1 = v0 - v1;
  15184. t = v2 * dctSin6 + v3 * dctCos6 + 128 >> 8;
  15185. v2 = v2 * dctCos6 - v3 * dctSin6 + 128 >> 8;
  15186. v3 = t;
  15187. v4 = v4 + v6 + 1 >> 1;
  15188. v6 = v4 - v6;
  15189. v7 = v7 + v5 + 1 >> 1;
  15190. v5 = v7 - v5;
  15191. // stage 2
  15192. v0 = v0 + v3 + 1 >> 1;
  15193. v3 = v0 - v3;
  15194. v1 = v1 + v2 + 1 >> 1;
  15195. v2 = v1 - v2;
  15196. t = v4 * dctSin3 + v7 * dctCos3 + 2048 >> 12;
  15197. v4 = v4 * dctCos3 - v7 * dctSin3 + 2048 >> 12;
  15198. v7 = t;
  15199. t = v5 * dctSin1 + v6 * dctCos1 + 2048 >> 12;
  15200. v5 = v5 * dctCos1 - v6 * dctSin1 + 2048 >> 12;
  15201. v6 = t;
  15202. // stage 1
  15203. p[row] = v0 + v7;
  15204. p[row + 7] = v0 - v7;
  15205. p[row + 1] = v1 + v6;
  15206. p[row + 6] = v1 - v6;
  15207. p[row + 2] = v2 + v5;
  15208. p[row + 5] = v2 - v5;
  15209. p[row + 3] = v3 + v4;
  15210. p[row + 4] = v3 - v4;
  15211. }
  15212. // inverse DCT on columns
  15213. for (var col = 0; col < 8; ++col) {
  15214. p0 = p[col];
  15215. p1 = p[col + 8];
  15216. p2 = p[col + 16];
  15217. p3 = p[col + 24];
  15218. p4 = p[col + 32];
  15219. p5 = p[col + 40];
  15220. p6 = p[col + 48];
  15221. p7 = p[col + 56];
  15222. // check for all-zero AC coefficients
  15223. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  15224. t = dctSqrt2 * p0 + 8192 >> 14;
  15225. // convert to 8 bit
  15226. t = t < -2040 ? 0 : t >= 2024 ? 255 : t + 2056 >> 4;
  15227. blockData[blockBufferOffset + col] = t;
  15228. blockData[blockBufferOffset + col + 8] = t;
  15229. blockData[blockBufferOffset + col + 16] = t;
  15230. blockData[blockBufferOffset + col + 24] = t;
  15231. blockData[blockBufferOffset + col + 32] = t;
  15232. blockData[blockBufferOffset + col + 40] = t;
  15233. blockData[blockBufferOffset + col + 48] = t;
  15234. blockData[blockBufferOffset + col + 56] = t;
  15235. continue;
  15236. }
  15237. // stage 4
  15238. v0 = dctSqrt2 * p0 + 2048 >> 12;
  15239. v1 = dctSqrt2 * p4 + 2048 >> 12;
  15240. v2 = p2;
  15241. v3 = p6;
  15242. v4 = dctSqrt1d2 * (p1 - p7) + 2048 >> 12;
  15243. v7 = dctSqrt1d2 * (p1 + p7) + 2048 >> 12;
  15244. v5 = p3;
  15245. v6 = p5;
  15246. // stage 3
  15247. // Shift v0 by 128.5 << 5 here, so we don't need to shift p0...p7 when
  15248. // converting to UInt8 range later.
  15249. v0 = (v0 + v1 + 1 >> 1) + 4112;
  15250. v1 = v0 - v1;
  15251. t = v2 * dctSin6 + v3 * dctCos6 + 2048 >> 12;
  15252. v2 = v2 * dctCos6 - v3 * dctSin6 + 2048 >> 12;
  15253. v3 = t;
  15254. v4 = v4 + v6 + 1 >> 1;
  15255. v6 = v4 - v6;
  15256. v7 = v7 + v5 + 1 >> 1;
  15257. v5 = v7 - v5;
  15258. // stage 2
  15259. v0 = v0 + v3 + 1 >> 1;
  15260. v3 = v0 - v3;
  15261. v1 = v1 + v2 + 1 >> 1;
  15262. v2 = v1 - v2;
  15263. t = v4 * dctSin3 + v7 * dctCos3 + 2048 >> 12;
  15264. v4 = v4 * dctCos3 - v7 * dctSin3 + 2048 >> 12;
  15265. v7 = t;
  15266. t = v5 * dctSin1 + v6 * dctCos1 + 2048 >> 12;
  15267. v5 = v5 * dctCos1 - v6 * dctSin1 + 2048 >> 12;
  15268. v6 = t;
  15269. // stage 1
  15270. p0 = v0 + v7;
  15271. p7 = v0 - v7;
  15272. p1 = v1 + v6;
  15273. p6 = v1 - v6;
  15274. p2 = v2 + v5;
  15275. p5 = v2 - v5;
  15276. p3 = v3 + v4;
  15277. p4 = v3 - v4;
  15278. // convert to 8-bit integers
  15279. p0 = p0 < 16 ? 0 : p0 >= 4080 ? 255 : p0 >> 4;
  15280. p1 = p1 < 16 ? 0 : p1 >= 4080 ? 255 : p1 >> 4;
  15281. p2 = p2 < 16 ? 0 : p2 >= 4080 ? 255 : p2 >> 4;
  15282. p3 = p3 < 16 ? 0 : p3 >= 4080 ? 255 : p3 >> 4;
  15283. p4 = p4 < 16 ? 0 : p4 >= 4080 ? 255 : p4 >> 4;
  15284. p5 = p5 < 16 ? 0 : p5 >= 4080 ? 255 : p5 >> 4;
  15285. p6 = p6 < 16 ? 0 : p6 >= 4080 ? 255 : p6 >> 4;
  15286. p7 = p7 < 16 ? 0 : p7 >= 4080 ? 255 : p7 >> 4;
  15287. // store block data
  15288. blockData[blockBufferOffset + col] = p0;
  15289. blockData[blockBufferOffset + col + 8] = p1;
  15290. blockData[blockBufferOffset + col + 16] = p2;
  15291. blockData[blockBufferOffset + col + 24] = p3;
  15292. blockData[blockBufferOffset + col + 32] = p4;
  15293. blockData[blockBufferOffset + col + 40] = p5;
  15294. blockData[blockBufferOffset + col + 48] = p6;
  15295. blockData[blockBufferOffset + col + 56] = p7;
  15296. }
  15297. }
  15298. function buildComponentData(frame, component) {
  15299. var blocksPerLine = component.blocksPerLine;
  15300. var blocksPerColumn = component.blocksPerColumn;
  15301. var computationBuffer = new Int16Array(64);
  15302. for (var blockRow = 0; blockRow < blocksPerColumn; blockRow++) {
  15303. for (var blockCol = 0; blockCol < blocksPerLine; blockCol++) {
  15304. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  15305. quantizeAndInverse(component, offset, computationBuffer);
  15306. }
  15307. }
  15308. return component.blockData;
  15309. }
  15310. function clamp0to255(a) {
  15311. return a <= 0 ? 0 : a >= 255 ? 255 : a;
  15312. }
  15313. JpegImage.prototype = {
  15314. parse: function parse(data) {
  15315. function readUint16() {
  15316. var value = data[offset] << 8 | data[offset + 1];
  15317. offset += 2;
  15318. return value;
  15319. }
  15320. function readDataBlock() {
  15321. var length = readUint16();
  15322. var array = data.subarray(offset, offset + length - 2);
  15323. offset += array.length;
  15324. return array;
  15325. }
  15326. function prepareComponents(frame) {
  15327. var mcusPerLine = Math.ceil(frame.samplesPerLine / 8 / frame.maxH);
  15328. var mcusPerColumn = Math.ceil(frame.scanLines / 8 / frame.maxV);
  15329. for (var i = 0; i < frame.components.length; i++) {
  15330. component = frame.components[i];
  15331. var blocksPerLine = Math.ceil(Math.ceil(frame.samplesPerLine / 8) * component.h / frame.maxH);
  15332. var blocksPerColumn = Math.ceil(Math.ceil(frame.scanLines / 8) * component.v / frame.maxV);
  15333. var blocksPerLineForMcu = mcusPerLine * component.h;
  15334. var blocksPerColumnForMcu = mcusPerColumn * component.v;
  15335. var blocksBufferSize = 64 * blocksPerColumnForMcu * (blocksPerLineForMcu + 1);
  15336. component.blockData = new Int16Array(blocksBufferSize);
  15337. component.blocksPerLine = blocksPerLine;
  15338. component.blocksPerColumn = blocksPerColumn;
  15339. }
  15340. frame.mcusPerLine = mcusPerLine;
  15341. frame.mcusPerColumn = mcusPerColumn;
  15342. }
  15343. var offset = 0;
  15344. var jfif = null;
  15345. var adobe = null;
  15346. var frame, resetInterval;
  15347. var quantizationTables = [];
  15348. var huffmanTablesAC = [], huffmanTablesDC = [];
  15349. var fileMarker = readUint16();
  15350. if (fileMarker !== 0xFFD8) {
  15351. // SOI (Start of Image)
  15352. error('JPEG error: SOI not found');
  15353. }
  15354. fileMarker = readUint16();
  15355. while (fileMarker !== 0xFFD9) {
  15356. // EOI (End of image)
  15357. var i, j, l;
  15358. switch (fileMarker) {
  15359. case 0xFFE0:
  15360. // APP0 (Application Specific)
  15361. case 0xFFE1:
  15362. // APP1
  15363. case 0xFFE2:
  15364. // APP2
  15365. case 0xFFE3:
  15366. // APP3
  15367. case 0xFFE4:
  15368. // APP4
  15369. case 0xFFE5:
  15370. // APP5
  15371. case 0xFFE6:
  15372. // APP6
  15373. case 0xFFE7:
  15374. // APP7
  15375. case 0xFFE8:
  15376. // APP8
  15377. case 0xFFE9:
  15378. // APP9
  15379. case 0xFFEA:
  15380. // APP10
  15381. case 0xFFEB:
  15382. // APP11
  15383. case 0xFFEC:
  15384. // APP12
  15385. case 0xFFED:
  15386. // APP13
  15387. case 0xFFEE:
  15388. // APP14
  15389. case 0xFFEF:
  15390. // APP15
  15391. case 0xFFFE:
  15392. // COM (Comment)
  15393. var appData = readDataBlock();
  15394. if (fileMarker === 0xFFE0) {
  15395. if (appData[0] === 0x4A && appData[1] === 0x46 && appData[2] === 0x49 && appData[3] === 0x46 && appData[4] === 0) {
  15396. // 'JFIF\x00'
  15397. jfif = {
  15398. version: {
  15399. major: appData[5],
  15400. minor: appData[6]
  15401. },
  15402. densityUnits: appData[7],
  15403. xDensity: appData[8] << 8 | appData[9],
  15404. yDensity: appData[10] << 8 | appData[11],
  15405. thumbWidth: appData[12],
  15406. thumbHeight: appData[13],
  15407. thumbData: appData.subarray(14, 14 + 3 * appData[12] * appData[13])
  15408. };
  15409. }
  15410. }
  15411. // TODO APP1 - Exif
  15412. if (fileMarker === 0xFFEE) {
  15413. if (appData[0] === 0x41 && appData[1] === 0x64 && appData[2] === 0x6F && appData[3] === 0x62 && appData[4] === 0x65) {
  15414. // 'Adobe'
  15415. adobe = {
  15416. version: appData[5] << 8 | appData[6],
  15417. flags0: appData[7] << 8 | appData[8],
  15418. flags1: appData[9] << 8 | appData[10],
  15419. transformCode: appData[11]
  15420. };
  15421. }
  15422. }
  15423. break;
  15424. case 0xFFDB:
  15425. // DQT (Define Quantization Tables)
  15426. var quantizationTablesLength = readUint16();
  15427. var quantizationTablesEnd = quantizationTablesLength + offset - 2;
  15428. var z;
  15429. while (offset < quantizationTablesEnd) {
  15430. var quantizationTableSpec = data[offset++];
  15431. var tableData = new Uint16Array(64);
  15432. if (quantizationTableSpec >> 4 === 0) {
  15433. // 8 bit values
  15434. for (j = 0; j < 64; j++) {
  15435. z = dctZigZag[j];
  15436. tableData[z] = data[offset++];
  15437. }
  15438. } else if (quantizationTableSpec >> 4 === 1) {
  15439. //16 bit
  15440. for (j = 0; j < 64; j++) {
  15441. z = dctZigZag[j];
  15442. tableData[z] = readUint16();
  15443. }
  15444. } else {
  15445. error('JPEG error: DQT - invalid table spec');
  15446. }
  15447. quantizationTables[quantizationTableSpec & 15] = tableData;
  15448. }
  15449. break;
  15450. case 0xFFC0:
  15451. // SOF0 (Start of Frame, Baseline DCT)
  15452. case 0xFFC1:
  15453. // SOF1 (Start of Frame, Extended DCT)
  15454. case 0xFFC2:
  15455. // SOF2 (Start of Frame, Progressive DCT)
  15456. if (frame) {
  15457. error('JPEG error: Only single frame JPEGs supported');
  15458. }
  15459. readUint16();
  15460. // skip data length
  15461. frame = {};
  15462. frame.extended = fileMarker === 0xFFC1;
  15463. frame.progressive = fileMarker === 0xFFC2;
  15464. frame.precision = data[offset++];
  15465. frame.scanLines = readUint16();
  15466. frame.samplesPerLine = readUint16();
  15467. frame.components = [];
  15468. frame.componentIds = {};
  15469. var componentsCount = data[offset++], componentId;
  15470. var maxH = 0, maxV = 0;
  15471. for (i = 0; i < componentsCount; i++) {
  15472. componentId = data[offset];
  15473. var h = data[offset + 1] >> 4;
  15474. var v = data[offset + 1] & 15;
  15475. if (maxH < h) {
  15476. maxH = h;
  15477. }
  15478. if (maxV < v) {
  15479. maxV = v;
  15480. }
  15481. var qId = data[offset + 2];
  15482. l = frame.components.push({
  15483. h: h,
  15484. v: v,
  15485. quantizationId: qId,
  15486. quantizationTable: null
  15487. });
  15488. // See comment below.
  15489. frame.componentIds[componentId] = l - 1;
  15490. offset += 3;
  15491. }
  15492. frame.maxH = maxH;
  15493. frame.maxV = maxV;
  15494. prepareComponents(frame);
  15495. break;
  15496. case 0xFFC4:
  15497. // DHT (Define Huffman Tables)
  15498. var huffmanLength = readUint16();
  15499. for (i = 2; i < huffmanLength;) {
  15500. var huffmanTableSpec = data[offset++];
  15501. var codeLengths = new Uint8Array(16);
  15502. var codeLengthSum = 0;
  15503. for (j = 0; j < 16; j++, offset++) {
  15504. codeLengthSum += codeLengths[j] = data[offset];
  15505. }
  15506. var huffmanValues = new Uint8Array(codeLengthSum);
  15507. for (j = 0; j < codeLengthSum; j++, offset++) {
  15508. huffmanValues[j] = data[offset];
  15509. }
  15510. i += 17 + codeLengthSum;
  15511. (huffmanTableSpec >> 4 === 0 ? huffmanTablesDC : huffmanTablesAC)[huffmanTableSpec & 15] = buildHuffmanTable(codeLengths, huffmanValues);
  15512. }
  15513. break;
  15514. case 0xFFDD:
  15515. // DRI (Define Restart Interval)
  15516. readUint16();
  15517. // skip data length
  15518. resetInterval = readUint16();
  15519. break;
  15520. case 0xFFDA:
  15521. // SOS (Start of Scan)
  15522. var scanLength = readUint16();
  15523. var selectorsCount = data[offset++];
  15524. var components = [], component;
  15525. for (i = 0; i < selectorsCount; i++) {
  15526. var componentIndex = frame.componentIds[data[offset++]];
  15527. component = frame.components[componentIndex];
  15528. var tableSpec = data[offset++];
  15529. component.huffmanTableDC = huffmanTablesDC[tableSpec >> 4];
  15530. component.huffmanTableAC = huffmanTablesAC[tableSpec & 15];
  15531. components.push(component);
  15532. }
  15533. var spectralStart = data[offset++];
  15534. var spectralEnd = data[offset++];
  15535. var successiveApproximation = data[offset++];
  15536. var processed = decodeScan(data, offset, frame, components, resetInterval, spectralStart, spectralEnd, successiveApproximation >> 4, successiveApproximation & 15);
  15537. offset += processed;
  15538. break;
  15539. case 0xFFFF:
  15540. // Fill bytes
  15541. if (data[offset] !== 0xFF) {
  15542. // Avoid skipping a valid marker.
  15543. offset--;
  15544. }
  15545. break;
  15546. default:
  15547. if (data[offset - 3] === 0xFF && data[offset - 2] >= 0xC0 && data[offset - 2] <= 0xFE) {
  15548. // could be incorrect encoding -- last 0xFF byte of the previous
  15549. // block was eaten by the encoder
  15550. offset -= 3;
  15551. break;
  15552. }
  15553. error('JPEG error: unknown marker ' + fileMarker.toString(16));
  15554. }
  15555. fileMarker = readUint16();
  15556. }
  15557. this.width = frame.samplesPerLine;
  15558. this.height = frame.scanLines;
  15559. this.jfif = jfif;
  15560. this.adobe = adobe;
  15561. this.components = [];
  15562. for (i = 0; i < frame.components.length; i++) {
  15563. component = frame.components[i];
  15564. // Prevent errors when DQT markers are placed after SOF{n} markers,
  15565. // by assigning the `quantizationTable` entry after the entire image
  15566. // has been parsed (fixes issue7406.pdf).
  15567. var quantizationTable = quantizationTables[component.quantizationId];
  15568. if (quantizationTable) {
  15569. component.quantizationTable = quantizationTable;
  15570. }
  15571. this.components.push({
  15572. output: buildComponentData(frame, component),
  15573. scaleX: component.h / frame.maxH,
  15574. scaleY: component.v / frame.maxV,
  15575. blocksPerLine: component.blocksPerLine,
  15576. blocksPerColumn: component.blocksPerColumn
  15577. });
  15578. }
  15579. this.numComponents = this.components.length;
  15580. },
  15581. _getLinearizedBlockData: function getLinearizedBlockData(width, height) {
  15582. var scaleX = this.width / width, scaleY = this.height / height;
  15583. var component, componentScaleX, componentScaleY, blocksPerScanline;
  15584. var x, y, i, j, k;
  15585. var index;
  15586. var offset = 0;
  15587. var output;
  15588. var numComponents = this.components.length;
  15589. var dataLength = width * height * numComponents;
  15590. var data = new Uint8Array(dataLength);
  15591. var xScaleBlockOffset = new Uint32Array(width);
  15592. var mask3LSB = 0xfffffff8;
  15593. // used to clear the 3 LSBs
  15594. for (i = 0; i < numComponents; i++) {
  15595. component = this.components[i];
  15596. componentScaleX = component.scaleX * scaleX;
  15597. componentScaleY = component.scaleY * scaleY;
  15598. offset = i;
  15599. output = component.output;
  15600. blocksPerScanline = component.blocksPerLine + 1 << 3;
  15601. // precalculate the xScaleBlockOffset
  15602. for (x = 0; x < width; x++) {
  15603. j = 0 | x * componentScaleX;
  15604. xScaleBlockOffset[x] = (j & mask3LSB) << 3 | j & 7;
  15605. }
  15606. // linearize the blocks of the component
  15607. for (y = 0; y < height; y++) {
  15608. j = 0 | y * componentScaleY;
  15609. index = blocksPerScanline * (j & mask3LSB) | (j & 7) << 3;
  15610. for (x = 0; x < width; x++) {
  15611. data[offset] = output[index + xScaleBlockOffset[x]];
  15612. offset += numComponents;
  15613. }
  15614. }
  15615. }
  15616. // decodeTransform contains pairs of multiplier (-256..256) and additive
  15617. var transform = this.decodeTransform;
  15618. if (transform) {
  15619. for (i = 0; i < dataLength;) {
  15620. for (j = 0, k = 0; j < numComponents; j++, i++, k += 2) {
  15621. data[i] = (data[i] * transform[k] >> 8) + transform[k + 1];
  15622. }
  15623. }
  15624. }
  15625. return data;
  15626. },
  15627. _isColorConversionNeeded: function isColorConversionNeeded() {
  15628. if (this.adobe && this.adobe.transformCode) {
  15629. // The adobe transform marker overrides any previous setting
  15630. return true;
  15631. } else if (this.numComponents === 3) {
  15632. if (!this.adobe && this.colorTransform === 0) {
  15633. // If the Adobe transform marker is not present and the image
  15634. // dictionary has a 'ColorTransform' entry, explicitly set to `0`,
  15635. // then the colours should *not* be transformed.
  15636. return false;
  15637. }
  15638. return true;
  15639. } else {
  15640. // `this.numComponents !== 3`
  15641. if (!this.adobe && this.colorTransform === 1) {
  15642. // If the Adobe transform marker is not present and the image
  15643. // dictionary has a 'ColorTransform' entry, explicitly set to `1`,
  15644. // then the colours should be transformed.
  15645. return true;
  15646. }
  15647. return false;
  15648. }
  15649. },
  15650. _convertYccToRgb: function convertYccToRgb(data) {
  15651. var Y, Cb, Cr;
  15652. for (var i = 0, length = data.length; i < length; i += 3) {
  15653. Y = data[i];
  15654. Cb = data[i + 1];
  15655. Cr = data[i + 2];
  15656. data[i] = clamp0to255(Y - 179.456 + 1.402 * Cr);
  15657. data[i + 1] = clamp0to255(Y + 135.459 - 0.344 * Cb - 0.714 * Cr);
  15658. data[i + 2] = clamp0to255(Y - 226.816 + 1.772 * Cb);
  15659. }
  15660. return data;
  15661. },
  15662. _convertYcckToRgb: function convertYcckToRgb(data) {
  15663. var Y, Cb, Cr, k;
  15664. var offset = 0;
  15665. for (var i = 0, length = data.length; i < length; i += 4) {
  15666. Y = data[i];
  15667. Cb = data[i + 1];
  15668. Cr = data[i + 2];
  15669. k = data[i + 3];
  15670. 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);
  15671. 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);
  15672. 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);
  15673. data[offset++] = clamp0to255(r);
  15674. data[offset++] = clamp0to255(g);
  15675. data[offset++] = clamp0to255(b);
  15676. }
  15677. return data;
  15678. },
  15679. _convertYcckToCmyk: function convertYcckToCmyk(data) {
  15680. var Y, Cb, Cr;
  15681. for (var i = 0, length = data.length; i < length; i += 4) {
  15682. Y = data[i];
  15683. Cb = data[i + 1];
  15684. Cr = data[i + 2];
  15685. data[i] = clamp0to255(434.456 - Y - 1.402 * Cr);
  15686. data[i + 1] = clamp0to255(119.541 - Y + 0.344 * Cb + 0.714 * Cr);
  15687. data[i + 2] = clamp0to255(481.816 - Y - 1.772 * Cb);
  15688. }
  15689. // K in data[i + 3] is unchanged
  15690. return data;
  15691. },
  15692. _convertCmykToRgb: function convertCmykToRgb(data) {
  15693. var c, m, y, k;
  15694. var offset = 0;
  15695. var min = -255 * 255 * 255;
  15696. var scale = 1 / 255 / 255;
  15697. for (var i = 0, length = data.length; i < length; i += 4) {
  15698. c = data[i];
  15699. m = data[i + 1];
  15700. y = data[i + 2];
  15701. k = data[i + 3];
  15702. 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);
  15703. 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);
  15704. 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);
  15705. data[offset++] = r >= 0 ? 255 : r <= min ? 0 : 255 + r * scale | 0;
  15706. data[offset++] = g >= 0 ? 255 : g <= min ? 0 : 255 + g * scale | 0;
  15707. data[offset++] = b >= 0 ? 255 : b <= min ? 0 : 255 + b * scale | 0;
  15708. }
  15709. return data;
  15710. },
  15711. getData: function getData(width, height, forceRGBoutput) {
  15712. if (this.numComponents > 4) {
  15713. error('JPEG error: Unsupported color mode');
  15714. }
  15715. // type of data: Uint8Array(width * height * numComponents)
  15716. var data = this._getLinearizedBlockData(width, height);
  15717. if (this.numComponents === 1 && forceRGBoutput) {
  15718. var dataLength = data.length;
  15719. var rgbData = new Uint8Array(dataLength * 3);
  15720. var offset = 0;
  15721. for (var i = 0; i < dataLength; i++) {
  15722. var grayColor = data[i];
  15723. rgbData[offset++] = grayColor;
  15724. rgbData[offset++] = grayColor;
  15725. rgbData[offset++] = grayColor;
  15726. }
  15727. return rgbData;
  15728. } else if (this.numComponents === 3 && this._isColorConversionNeeded()) {
  15729. return this._convertYccToRgb(data);
  15730. } else if (this.numComponents === 4) {
  15731. if (this._isColorConversionNeeded()) {
  15732. if (forceRGBoutput) {
  15733. return this._convertYcckToRgb(data);
  15734. } else {
  15735. return this._convertYcckToCmyk(data);
  15736. }
  15737. } else if (forceRGBoutput) {
  15738. return this._convertCmykToRgb(data);
  15739. }
  15740. }
  15741. return data;
  15742. }
  15743. };
  15744. return JpegImage;
  15745. }();
  15746. exports.JpegImage = JpegImage;
  15747. }));
  15748. (function (root, factory) {
  15749. factory(root.pdfjsCoreJpx = {}, root.pdfjsSharedUtil, root.pdfjsCoreArithmeticDecoder);
  15750. }(this, function (exports, sharedUtil, coreArithmeticDecoder) {
  15751. var info = sharedUtil.info;
  15752. var warn = sharedUtil.warn;
  15753. var error = sharedUtil.error;
  15754. var log2 = sharedUtil.log2;
  15755. var readUint16 = sharedUtil.readUint16;
  15756. var readUint32 = sharedUtil.readUint32;
  15757. var ArithmeticDecoder = coreArithmeticDecoder.ArithmeticDecoder;
  15758. var JpxImage = function JpxImageClosure() {
  15759. // Table E.1
  15760. var SubbandsGainLog2 = {
  15761. 'LL': 0,
  15762. 'LH': 1,
  15763. 'HL': 1,
  15764. 'HH': 2
  15765. };
  15766. function JpxImage() {
  15767. this.failOnCorruptedImage = false;
  15768. }
  15769. JpxImage.prototype = {
  15770. parse: function JpxImage_parse(data) {
  15771. var head = readUint16(data, 0);
  15772. // No box header, immediate start of codestream (SOC)
  15773. if (head === 0xFF4F) {
  15774. this.parseCodestream(data, 0, data.length);
  15775. return;
  15776. }
  15777. var position = 0, length = data.length;
  15778. while (position < length) {
  15779. var headerSize = 8;
  15780. var lbox = readUint32(data, position);
  15781. var tbox = readUint32(data, position + 4);
  15782. position += headerSize;
  15783. if (lbox === 1) {
  15784. // XLBox: read UInt64 according to spec.
  15785. // JavaScript's int precision of 53 bit should be sufficient here.
  15786. lbox = readUint32(data, position) * 4294967296 + readUint32(data, position + 4);
  15787. position += 8;
  15788. headerSize += 8;
  15789. }
  15790. if (lbox === 0) {
  15791. lbox = length - position + headerSize;
  15792. }
  15793. if (lbox < headerSize) {
  15794. error('JPX Error: Invalid box field size');
  15795. }
  15796. var dataLength = lbox - headerSize;
  15797. var jumpDataLength = true;
  15798. switch (tbox) {
  15799. case 0x6A703268:
  15800. // 'jp2h'
  15801. jumpDataLength = false;
  15802. // parsing child boxes
  15803. break;
  15804. case 0x636F6C72:
  15805. // 'colr'
  15806. // Colorspaces are not used, the CS from the PDF is used.
  15807. var method = data[position];
  15808. if (method === 1) {
  15809. // enumerated colorspace
  15810. var colorspace = readUint32(data, position + 3);
  15811. switch (colorspace) {
  15812. case 16:
  15813. // this indicates a sRGB colorspace
  15814. case 17:
  15815. // this indicates a grayscale colorspace
  15816. case 18:
  15817. // this indicates a YUV colorspace
  15818. break;
  15819. default:
  15820. warn('Unknown colorspace ' + colorspace);
  15821. break;
  15822. }
  15823. } else if (method === 2) {
  15824. info('ICC profile not supported');
  15825. }
  15826. break;
  15827. case 0x6A703263:
  15828. // 'jp2c'
  15829. this.parseCodestream(data, position, position + dataLength);
  15830. break;
  15831. case 0x6A502020:
  15832. // 'jP\024\024'
  15833. if (0x0d0a870a !== readUint32(data, position)) {
  15834. warn('Invalid JP2 signature');
  15835. }
  15836. break;
  15837. // The following header types are valid but currently not used:
  15838. case 0x6A501A1A:
  15839. // 'jP\032\032'
  15840. case 0x66747970:
  15841. // 'ftyp'
  15842. case 0x72726571:
  15843. // 'rreq'
  15844. case 0x72657320:
  15845. // 'res '
  15846. case 0x69686472:
  15847. // 'ihdr'
  15848. break;
  15849. default:
  15850. var headerType = String.fromCharCode(tbox >> 24 & 0xFF, tbox >> 16 & 0xFF, tbox >> 8 & 0xFF, tbox & 0xFF);
  15851. warn('Unsupported header type ' + tbox + ' (' + headerType + ')');
  15852. break;
  15853. }
  15854. if (jumpDataLength) {
  15855. position += dataLength;
  15856. }
  15857. }
  15858. },
  15859. parseImageProperties: function JpxImage_parseImageProperties(stream) {
  15860. var newByte = stream.getByte();
  15861. while (newByte >= 0) {
  15862. var oldByte = newByte;
  15863. newByte = stream.getByte();
  15864. var code = oldByte << 8 | newByte;
  15865. // Image and tile size (SIZ)
  15866. if (code === 0xFF51) {
  15867. stream.skip(4);
  15868. var Xsiz = stream.getInt32() >>> 0;
  15869. // Byte 4
  15870. var Ysiz = stream.getInt32() >>> 0;
  15871. // Byte 8
  15872. var XOsiz = stream.getInt32() >>> 0;
  15873. // Byte 12
  15874. var YOsiz = stream.getInt32() >>> 0;
  15875. // Byte 16
  15876. stream.skip(16);
  15877. var Csiz = stream.getUint16();
  15878. // Byte 36
  15879. this.width = Xsiz - XOsiz;
  15880. this.height = Ysiz - YOsiz;
  15881. this.componentsCount = Csiz;
  15882. // Results are always returned as Uint8Arrays
  15883. this.bitsPerComponent = 8;
  15884. return;
  15885. }
  15886. }
  15887. error('JPX Error: No size marker found in JPX stream');
  15888. },
  15889. parseCodestream: function JpxImage_parseCodestream(data, start, end) {
  15890. var context = {};
  15891. var doNotRecover = false;
  15892. try {
  15893. var position = start;
  15894. while (position + 1 < end) {
  15895. var code = readUint16(data, position);
  15896. position += 2;
  15897. var length = 0, j, sqcd, spqcds, spqcdSize, scalarExpounded, tile;
  15898. switch (code) {
  15899. case 0xFF4F:
  15900. // Start of codestream (SOC)
  15901. context.mainHeader = true;
  15902. break;
  15903. case 0xFFD9:
  15904. // End of codestream (EOC)
  15905. break;
  15906. case 0xFF51:
  15907. // Image and tile size (SIZ)
  15908. length = readUint16(data, position);
  15909. var siz = {};
  15910. siz.Xsiz = readUint32(data, position + 4);
  15911. siz.Ysiz = readUint32(data, position + 8);
  15912. siz.XOsiz = readUint32(data, position + 12);
  15913. siz.YOsiz = readUint32(data, position + 16);
  15914. siz.XTsiz = readUint32(data, position + 20);
  15915. siz.YTsiz = readUint32(data, position + 24);
  15916. siz.XTOsiz = readUint32(data, position + 28);
  15917. siz.YTOsiz = readUint32(data, position + 32);
  15918. var componentsCount = readUint16(data, position + 36);
  15919. siz.Csiz = componentsCount;
  15920. var components = [];
  15921. j = position + 38;
  15922. for (var i = 0; i < componentsCount; i++) {
  15923. var component = {
  15924. precision: (data[j] & 0x7F) + 1,
  15925. isSigned: !!(data[j] & 0x80),
  15926. XRsiz: data[j + 1],
  15927. YRsiz: data[j + 1]
  15928. };
  15929. calculateComponentDimensions(component, siz);
  15930. components.push(component);
  15931. }
  15932. context.SIZ = siz;
  15933. context.components = components;
  15934. calculateTileGrids(context, components);
  15935. context.QCC = [];
  15936. context.COC = [];
  15937. break;
  15938. case 0xFF5C:
  15939. // Quantization default (QCD)
  15940. length = readUint16(data, position);
  15941. var qcd = {};
  15942. j = position + 2;
  15943. sqcd = data[j++];
  15944. switch (sqcd & 0x1F) {
  15945. case 0:
  15946. spqcdSize = 8;
  15947. scalarExpounded = true;
  15948. break;
  15949. case 1:
  15950. spqcdSize = 16;
  15951. scalarExpounded = false;
  15952. break;
  15953. case 2:
  15954. spqcdSize = 16;
  15955. scalarExpounded = true;
  15956. break;
  15957. default:
  15958. throw new Error('Invalid SQcd value ' + sqcd);
  15959. }
  15960. qcd.noQuantization = spqcdSize === 8;
  15961. qcd.scalarExpounded = scalarExpounded;
  15962. qcd.guardBits = sqcd >> 5;
  15963. spqcds = [];
  15964. while (j < length + position) {
  15965. var spqcd = {};
  15966. if (spqcdSize === 8) {
  15967. spqcd.epsilon = data[j++] >> 3;
  15968. spqcd.mu = 0;
  15969. } else {
  15970. spqcd.epsilon = data[j] >> 3;
  15971. spqcd.mu = (data[j] & 0x7) << 8 | data[j + 1];
  15972. j += 2;
  15973. }
  15974. spqcds.push(spqcd);
  15975. }
  15976. qcd.SPqcds = spqcds;
  15977. if (context.mainHeader) {
  15978. context.QCD = qcd;
  15979. } else {
  15980. context.currentTile.QCD = qcd;
  15981. context.currentTile.QCC = [];
  15982. }
  15983. break;
  15984. case 0xFF5D:
  15985. // Quantization component (QCC)
  15986. length = readUint16(data, position);
  15987. var qcc = {};
  15988. j = position + 2;
  15989. var cqcc;
  15990. if (context.SIZ.Csiz < 257) {
  15991. cqcc = data[j++];
  15992. } else {
  15993. cqcc = readUint16(data, j);
  15994. j += 2;
  15995. }
  15996. sqcd = data[j++];
  15997. switch (sqcd & 0x1F) {
  15998. case 0:
  15999. spqcdSize = 8;
  16000. scalarExpounded = true;
  16001. break;
  16002. case 1:
  16003. spqcdSize = 16;
  16004. scalarExpounded = false;
  16005. break;
  16006. case 2:
  16007. spqcdSize = 16;
  16008. scalarExpounded = true;
  16009. break;
  16010. default:
  16011. throw new Error('Invalid SQcd value ' + sqcd);
  16012. }
  16013. qcc.noQuantization = spqcdSize === 8;
  16014. qcc.scalarExpounded = scalarExpounded;
  16015. qcc.guardBits = sqcd >> 5;
  16016. spqcds = [];
  16017. while (j < length + position) {
  16018. spqcd = {};
  16019. if (spqcdSize === 8) {
  16020. spqcd.epsilon = data[j++] >> 3;
  16021. spqcd.mu = 0;
  16022. } else {
  16023. spqcd.epsilon = data[j] >> 3;
  16024. spqcd.mu = (data[j] & 0x7) << 8 | data[j + 1];
  16025. j += 2;
  16026. }
  16027. spqcds.push(spqcd);
  16028. }
  16029. qcc.SPqcds = spqcds;
  16030. if (context.mainHeader) {
  16031. context.QCC[cqcc] = qcc;
  16032. } else {
  16033. context.currentTile.QCC[cqcc] = qcc;
  16034. }
  16035. break;
  16036. case 0xFF52:
  16037. // Coding style default (COD)
  16038. length = readUint16(data, position);
  16039. var cod = {};
  16040. j = position + 2;
  16041. var scod = data[j++];
  16042. cod.entropyCoderWithCustomPrecincts = !!(scod & 1);
  16043. cod.sopMarkerUsed = !!(scod & 2);
  16044. cod.ephMarkerUsed = !!(scod & 4);
  16045. cod.progressionOrder = data[j++];
  16046. cod.layersCount = readUint16(data, j);
  16047. j += 2;
  16048. cod.multipleComponentTransform = data[j++];
  16049. cod.decompositionLevelsCount = data[j++];
  16050. cod.xcb = (data[j++] & 0xF) + 2;
  16051. cod.ycb = (data[j++] & 0xF) + 2;
  16052. var blockStyle = data[j++];
  16053. cod.selectiveArithmeticCodingBypass = !!(blockStyle & 1);
  16054. cod.resetContextProbabilities = !!(blockStyle & 2);
  16055. cod.terminationOnEachCodingPass = !!(blockStyle & 4);
  16056. cod.verticalyStripe = !!(blockStyle & 8);
  16057. cod.predictableTermination = !!(blockStyle & 16);
  16058. cod.segmentationSymbolUsed = !!(blockStyle & 32);
  16059. cod.reversibleTransformation = data[j++];
  16060. if (cod.entropyCoderWithCustomPrecincts) {
  16061. var precinctsSizes = [];
  16062. while (j < length + position) {
  16063. var precinctsSize = data[j++];
  16064. precinctsSizes.push({
  16065. PPx: precinctsSize & 0xF,
  16066. PPy: precinctsSize >> 4
  16067. });
  16068. }
  16069. cod.precinctsSizes = precinctsSizes;
  16070. }
  16071. var unsupported = [];
  16072. if (cod.selectiveArithmeticCodingBypass) {
  16073. unsupported.push('selectiveArithmeticCodingBypass');
  16074. }
  16075. if (cod.resetContextProbabilities) {
  16076. unsupported.push('resetContextProbabilities');
  16077. }
  16078. if (cod.terminationOnEachCodingPass) {
  16079. unsupported.push('terminationOnEachCodingPass');
  16080. }
  16081. if (cod.verticalyStripe) {
  16082. unsupported.push('verticalyStripe');
  16083. }
  16084. if (cod.predictableTermination) {
  16085. unsupported.push('predictableTermination');
  16086. }
  16087. if (unsupported.length > 0) {
  16088. doNotRecover = true;
  16089. throw new Error('Unsupported COD options (' + unsupported.join(', ') + ')');
  16090. }
  16091. if (context.mainHeader) {
  16092. context.COD = cod;
  16093. } else {
  16094. context.currentTile.COD = cod;
  16095. context.currentTile.COC = [];
  16096. }
  16097. break;
  16098. case 0xFF90:
  16099. // Start of tile-part (SOT)
  16100. length = readUint16(data, position);
  16101. tile = {};
  16102. tile.index = readUint16(data, position + 2);
  16103. tile.length = readUint32(data, position + 4);
  16104. tile.dataEnd = tile.length + position - 2;
  16105. tile.partIndex = data[position + 8];
  16106. tile.partsCount = data[position + 9];
  16107. context.mainHeader = false;
  16108. if (tile.partIndex === 0) {
  16109. // reset component specific settings
  16110. tile.COD = context.COD;
  16111. tile.COC = context.COC.slice(0);
  16112. // clone of the global COC
  16113. tile.QCD = context.QCD;
  16114. tile.QCC = context.QCC.slice(0);
  16115. }
  16116. // clone of the global COC
  16117. context.currentTile = tile;
  16118. break;
  16119. case 0xFF93:
  16120. // Start of data (SOD)
  16121. tile = context.currentTile;
  16122. if (tile.partIndex === 0) {
  16123. initializeTile(context, tile.index);
  16124. buildPackets(context);
  16125. }
  16126. // moving to the end of the data
  16127. length = tile.dataEnd - position;
  16128. parseTilePackets(context, data, position, length);
  16129. break;
  16130. case 0xFF55:
  16131. // Tile-part lengths, main header (TLM)
  16132. case 0xFF57:
  16133. // Packet length, main header (PLM)
  16134. case 0xFF58:
  16135. // Packet length, tile-part header (PLT)
  16136. case 0xFF64:
  16137. // Comment (COM)
  16138. length = readUint16(data, position);
  16139. // skipping content
  16140. break;
  16141. case 0xFF53:
  16142. // Coding style component (COC)
  16143. throw new Error('Codestream code 0xFF53 (COC) is ' + 'not implemented');
  16144. default:
  16145. throw new Error('Unknown codestream code: ' + code.toString(16));
  16146. }
  16147. position += length;
  16148. }
  16149. } catch (e) {
  16150. if (doNotRecover || this.failOnCorruptedImage) {
  16151. error('JPX Error: ' + e.message);
  16152. } else {
  16153. warn('JPX: Trying to recover from: ' + e.message);
  16154. }
  16155. }
  16156. this.tiles = transformComponents(context);
  16157. this.width = context.SIZ.Xsiz - context.SIZ.XOsiz;
  16158. this.height = context.SIZ.Ysiz - context.SIZ.YOsiz;
  16159. this.componentsCount = context.SIZ.Csiz;
  16160. }
  16161. };
  16162. function calculateComponentDimensions(component, siz) {
  16163. // Section B.2 Component mapping
  16164. component.x0 = Math.ceil(siz.XOsiz / component.XRsiz);
  16165. component.x1 = Math.ceil(siz.Xsiz / component.XRsiz);
  16166. component.y0 = Math.ceil(siz.YOsiz / component.YRsiz);
  16167. component.y1 = Math.ceil(siz.Ysiz / component.YRsiz);
  16168. component.width = component.x1 - component.x0;
  16169. component.height = component.y1 - component.y0;
  16170. }
  16171. function calculateTileGrids(context, components) {
  16172. var siz = context.SIZ;
  16173. // Section B.3 Division into tile and tile-components
  16174. var tile, tiles = [];
  16175. var numXtiles = Math.ceil((siz.Xsiz - siz.XTOsiz) / siz.XTsiz);
  16176. var numYtiles = Math.ceil((siz.Ysiz - siz.YTOsiz) / siz.YTsiz);
  16177. for (var q = 0; q < numYtiles; q++) {
  16178. for (var p = 0; p < numXtiles; p++) {
  16179. tile = {};
  16180. tile.tx0 = Math.max(siz.XTOsiz + p * siz.XTsiz, siz.XOsiz);
  16181. tile.ty0 = Math.max(siz.YTOsiz + q * siz.YTsiz, siz.YOsiz);
  16182. tile.tx1 = Math.min(siz.XTOsiz + (p + 1) * siz.XTsiz, siz.Xsiz);
  16183. tile.ty1 = Math.min(siz.YTOsiz + (q + 1) * siz.YTsiz, siz.Ysiz);
  16184. tile.width = tile.tx1 - tile.tx0;
  16185. tile.height = tile.ty1 - tile.ty0;
  16186. tile.components = [];
  16187. tiles.push(tile);
  16188. }
  16189. }
  16190. context.tiles = tiles;
  16191. var componentsCount = siz.Csiz;
  16192. for (var i = 0, ii = componentsCount; i < ii; i++) {
  16193. var component = components[i];
  16194. for (var j = 0, jj = tiles.length; j < jj; j++) {
  16195. var tileComponent = {};
  16196. tile = tiles[j];
  16197. tileComponent.tcx0 = Math.ceil(tile.tx0 / component.XRsiz);
  16198. tileComponent.tcy0 = Math.ceil(tile.ty0 / component.YRsiz);
  16199. tileComponent.tcx1 = Math.ceil(tile.tx1 / component.XRsiz);
  16200. tileComponent.tcy1 = Math.ceil(tile.ty1 / component.YRsiz);
  16201. tileComponent.width = tileComponent.tcx1 - tileComponent.tcx0;
  16202. tileComponent.height = tileComponent.tcy1 - tileComponent.tcy0;
  16203. tile.components[i] = tileComponent;
  16204. }
  16205. }
  16206. }
  16207. function getBlocksDimensions(context, component, r) {
  16208. var codOrCoc = component.codingStyleParameters;
  16209. var result = {};
  16210. if (!codOrCoc.entropyCoderWithCustomPrecincts) {
  16211. result.PPx = 15;
  16212. result.PPy = 15;
  16213. } else {
  16214. result.PPx = codOrCoc.precinctsSizes[r].PPx;
  16215. result.PPy = codOrCoc.precinctsSizes[r].PPy;
  16216. }
  16217. // calculate codeblock size as described in section B.7
  16218. result.xcb_ = r > 0 ? Math.min(codOrCoc.xcb, result.PPx - 1) : Math.min(codOrCoc.xcb, result.PPx);
  16219. result.ycb_ = r > 0 ? Math.min(codOrCoc.ycb, result.PPy - 1) : Math.min(codOrCoc.ycb, result.PPy);
  16220. return result;
  16221. }
  16222. function buildPrecincts(context, resolution, dimensions) {
  16223. // Section B.6 Division resolution to precincts
  16224. var precinctWidth = 1 << dimensions.PPx;
  16225. var precinctHeight = 1 << dimensions.PPy;
  16226. // Jasper introduces codeblock groups for mapping each subband codeblocks
  16227. // to precincts. Precinct partition divides a resolution according to width
  16228. // and height parameters. The subband that belongs to the resolution level
  16229. // has a different size than the level, unless it is the zero resolution.
  16230. // From Jasper documentation: jpeg2000.pdf, section K: Tier-2 coding:
  16231. // The precinct partitioning for a particular subband is derived from a
  16232. // partitioning of its parent LL band (i.e., the LL band at the next higher
  16233. // resolution level)... The LL band associated with each resolution level is
  16234. // divided into precincts... Each of the resulting precinct regions is then
  16235. // mapped into its child subbands (if any) at the next lower resolution
  16236. // level. This is accomplished by using the coordinate transformation
  16237. // (u, v) = (ceil(x/2), ceil(y/2)) where (x, y) and (u, v) are the
  16238. // coordinates of a point in the LL band and child subband, respectively.
  16239. var isZeroRes = resolution.resLevel === 0;
  16240. var precinctWidthInSubband = 1 << dimensions.PPx + (isZeroRes ? 0 : -1);
  16241. var precinctHeightInSubband = 1 << dimensions.PPy + (isZeroRes ? 0 : -1);
  16242. var numprecinctswide = resolution.trx1 > resolution.trx0 ? Math.ceil(resolution.trx1 / precinctWidth) - Math.floor(resolution.trx0 / precinctWidth) : 0;
  16243. var numprecinctshigh = resolution.try1 > resolution.try0 ? Math.ceil(resolution.try1 / precinctHeight) - Math.floor(resolution.try0 / precinctHeight) : 0;
  16244. var numprecincts = numprecinctswide * numprecinctshigh;
  16245. resolution.precinctParameters = {
  16246. precinctWidth: precinctWidth,
  16247. precinctHeight: precinctHeight,
  16248. numprecinctswide: numprecinctswide,
  16249. numprecinctshigh: numprecinctshigh,
  16250. numprecincts: numprecincts,
  16251. precinctWidthInSubband: precinctWidthInSubband,
  16252. precinctHeightInSubband: precinctHeightInSubband
  16253. };
  16254. }
  16255. function buildCodeblocks(context, subband, dimensions) {
  16256. // Section B.7 Division sub-band into code-blocks
  16257. var xcb_ = dimensions.xcb_;
  16258. var ycb_ = dimensions.ycb_;
  16259. var codeblockWidth = 1 << xcb_;
  16260. var codeblockHeight = 1 << ycb_;
  16261. var cbx0 = subband.tbx0 >> xcb_;
  16262. var cby0 = subband.tby0 >> ycb_;
  16263. var cbx1 = subband.tbx1 + codeblockWidth - 1 >> xcb_;
  16264. var cby1 = subband.tby1 + codeblockHeight - 1 >> ycb_;
  16265. var precinctParameters = subband.resolution.precinctParameters;
  16266. var codeblocks = [];
  16267. var precincts = [];
  16268. var i, j, codeblock, precinctNumber;
  16269. for (j = cby0; j < cby1; j++) {
  16270. for (i = cbx0; i < cbx1; i++) {
  16271. codeblock = {
  16272. cbx: i,
  16273. cby: j,
  16274. tbx0: codeblockWidth * i,
  16275. tby0: codeblockHeight * j,
  16276. tbx1: codeblockWidth * (i + 1),
  16277. tby1: codeblockHeight * (j + 1)
  16278. };
  16279. codeblock.tbx0_ = Math.max(subband.tbx0, codeblock.tbx0);
  16280. codeblock.tby0_ = Math.max(subband.tby0, codeblock.tby0);
  16281. codeblock.tbx1_ = Math.min(subband.tbx1, codeblock.tbx1);
  16282. codeblock.tby1_ = Math.min(subband.tby1, codeblock.tby1);
  16283. // Calculate precinct number for this codeblock, codeblock position
  16284. // should be relative to its subband, use actual dimension and position
  16285. // See comment about codeblock group width and height
  16286. var pi = Math.floor((codeblock.tbx0_ - subband.tbx0) / precinctParameters.precinctWidthInSubband);
  16287. var pj = Math.floor((codeblock.tby0_ - subband.tby0) / precinctParameters.precinctHeightInSubband);
  16288. precinctNumber = pi + pj * precinctParameters.numprecinctswide;
  16289. codeblock.precinctNumber = precinctNumber;
  16290. codeblock.subbandType = subband.type;
  16291. codeblock.Lblock = 3;
  16292. if (codeblock.tbx1_ <= codeblock.tbx0_ || codeblock.tby1_ <= codeblock.tby0_) {
  16293. continue;
  16294. }
  16295. codeblocks.push(codeblock);
  16296. // building precinct for the sub-band
  16297. var precinct = precincts[precinctNumber];
  16298. if (precinct !== undefined) {
  16299. if (i < precinct.cbxMin) {
  16300. precinct.cbxMin = i;
  16301. } else if (i > precinct.cbxMax) {
  16302. precinct.cbxMax = i;
  16303. }
  16304. if (j < precinct.cbyMin) {
  16305. precinct.cbxMin = j;
  16306. } else if (j > precinct.cbyMax) {
  16307. precinct.cbyMax = j;
  16308. }
  16309. } else {
  16310. precincts[precinctNumber] = precinct = {
  16311. cbxMin: i,
  16312. cbyMin: j,
  16313. cbxMax: i,
  16314. cbyMax: j
  16315. };
  16316. }
  16317. codeblock.precinct = precinct;
  16318. }
  16319. }
  16320. subband.codeblockParameters = {
  16321. codeblockWidth: xcb_,
  16322. codeblockHeight: ycb_,
  16323. numcodeblockwide: cbx1 - cbx0 + 1,
  16324. numcodeblockhigh: cby1 - cby0 + 1
  16325. };
  16326. subband.codeblocks = codeblocks;
  16327. subband.precincts = precincts;
  16328. }
  16329. function createPacket(resolution, precinctNumber, layerNumber) {
  16330. var precinctCodeblocks = [];
  16331. // Section B.10.8 Order of info in packet
  16332. var subbands = resolution.subbands;
  16333. // sub-bands already ordered in 'LL', 'HL', 'LH', and 'HH' sequence
  16334. for (var i = 0, ii = subbands.length; i < ii; i++) {
  16335. var subband = subbands[i];
  16336. var codeblocks = subband.codeblocks;
  16337. for (var j = 0, jj = codeblocks.length; j < jj; j++) {
  16338. var codeblock = codeblocks[j];
  16339. if (codeblock.precinctNumber !== precinctNumber) {
  16340. continue;
  16341. }
  16342. precinctCodeblocks.push(codeblock);
  16343. }
  16344. }
  16345. return {
  16346. layerNumber: layerNumber,
  16347. codeblocks: precinctCodeblocks
  16348. };
  16349. }
  16350. function LayerResolutionComponentPositionIterator(context) {
  16351. var siz = context.SIZ;
  16352. var tileIndex = context.currentTile.index;
  16353. var tile = context.tiles[tileIndex];
  16354. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  16355. var componentsCount = siz.Csiz;
  16356. var maxDecompositionLevelsCount = 0;
  16357. for (var q = 0; q < componentsCount; q++) {
  16358. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount, tile.components[q].codingStyleParameters.decompositionLevelsCount);
  16359. }
  16360. var l = 0, r = 0, i = 0, k = 0;
  16361. this.nextPacket = function JpxImage_nextPacket() {
  16362. // Section B.12.1.1 Layer-resolution-component-position
  16363. for (; l < layersCount; l++) {
  16364. for (; r <= maxDecompositionLevelsCount; r++) {
  16365. for (; i < componentsCount; i++) {
  16366. var component = tile.components[i];
  16367. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  16368. continue;
  16369. }
  16370. var resolution = component.resolutions[r];
  16371. var numprecincts = resolution.precinctParameters.numprecincts;
  16372. for (; k < numprecincts;) {
  16373. var packet = createPacket(resolution, k, l);
  16374. k++;
  16375. return packet;
  16376. }
  16377. k = 0;
  16378. }
  16379. i = 0;
  16380. }
  16381. r = 0;
  16382. }
  16383. error('JPX Error: Out of packets');
  16384. };
  16385. }
  16386. function ResolutionLayerComponentPositionIterator(context) {
  16387. var siz = context.SIZ;
  16388. var tileIndex = context.currentTile.index;
  16389. var tile = context.tiles[tileIndex];
  16390. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  16391. var componentsCount = siz.Csiz;
  16392. var maxDecompositionLevelsCount = 0;
  16393. for (var q = 0; q < componentsCount; q++) {
  16394. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount, tile.components[q].codingStyleParameters.decompositionLevelsCount);
  16395. }
  16396. var r = 0, l = 0, i = 0, k = 0;
  16397. this.nextPacket = function JpxImage_nextPacket() {
  16398. // Section B.12.1.2 Resolution-layer-component-position
  16399. for (; r <= maxDecompositionLevelsCount; r++) {
  16400. for (; l < layersCount; l++) {
  16401. for (; i < componentsCount; i++) {
  16402. var component = tile.components[i];
  16403. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  16404. continue;
  16405. }
  16406. var resolution = component.resolutions[r];
  16407. var numprecincts = resolution.precinctParameters.numprecincts;
  16408. for (; k < numprecincts;) {
  16409. var packet = createPacket(resolution, k, l);
  16410. k++;
  16411. return packet;
  16412. }
  16413. k = 0;
  16414. }
  16415. i = 0;
  16416. }
  16417. l = 0;
  16418. }
  16419. error('JPX Error: Out of packets');
  16420. };
  16421. }
  16422. function ResolutionPositionComponentLayerIterator(context) {
  16423. var siz = context.SIZ;
  16424. var tileIndex = context.currentTile.index;
  16425. var tile = context.tiles[tileIndex];
  16426. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  16427. var componentsCount = siz.Csiz;
  16428. var l, r, c, p;
  16429. var maxDecompositionLevelsCount = 0;
  16430. for (c = 0; c < componentsCount; c++) {
  16431. var component = tile.components[c];
  16432. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount, component.codingStyleParameters.decompositionLevelsCount);
  16433. }
  16434. var maxNumPrecinctsInLevel = new Int32Array(maxDecompositionLevelsCount + 1);
  16435. for (r = 0; r <= maxDecompositionLevelsCount; ++r) {
  16436. var maxNumPrecincts = 0;
  16437. for (c = 0; c < componentsCount; ++c) {
  16438. var resolutions = tile.components[c].resolutions;
  16439. if (r < resolutions.length) {
  16440. maxNumPrecincts = Math.max(maxNumPrecincts, resolutions[r].precinctParameters.numprecincts);
  16441. }
  16442. }
  16443. maxNumPrecinctsInLevel[r] = maxNumPrecincts;
  16444. }
  16445. l = 0;
  16446. r = 0;
  16447. c = 0;
  16448. p = 0;
  16449. this.nextPacket = function JpxImage_nextPacket() {
  16450. // Section B.12.1.3 Resolution-position-component-layer
  16451. for (; r <= maxDecompositionLevelsCount; r++) {
  16452. for (; p < maxNumPrecinctsInLevel[r]; p++) {
  16453. for (; c < componentsCount; c++) {
  16454. var component = tile.components[c];
  16455. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  16456. continue;
  16457. }
  16458. var resolution = component.resolutions[r];
  16459. var numprecincts = resolution.precinctParameters.numprecincts;
  16460. if (p >= numprecincts) {
  16461. continue;
  16462. }
  16463. for (; l < layersCount;) {
  16464. var packet = createPacket(resolution, p, l);
  16465. l++;
  16466. return packet;
  16467. }
  16468. l = 0;
  16469. }
  16470. c = 0;
  16471. }
  16472. p = 0;
  16473. }
  16474. error('JPX Error: Out of packets');
  16475. };
  16476. }
  16477. function PositionComponentResolutionLayerIterator(context) {
  16478. var siz = context.SIZ;
  16479. var tileIndex = context.currentTile.index;
  16480. var tile = context.tiles[tileIndex];
  16481. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  16482. var componentsCount = siz.Csiz;
  16483. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  16484. var precinctsIterationSizes = precinctsSizes;
  16485. var l = 0, r = 0, c = 0, px = 0, py = 0;
  16486. this.nextPacket = function JpxImage_nextPacket() {
  16487. // Section B.12.1.4 Position-component-resolution-layer
  16488. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  16489. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  16490. for (; c < componentsCount; c++) {
  16491. var component = tile.components[c];
  16492. var decompositionLevelsCount = component.codingStyleParameters.decompositionLevelsCount;
  16493. for (; r <= decompositionLevelsCount; r++) {
  16494. var resolution = component.resolutions[r];
  16495. var sizeInImageScale = precinctsSizes.components[c].resolutions[r];
  16496. var k = getPrecinctIndexIfExist(px, py, sizeInImageScale, precinctsIterationSizes, resolution);
  16497. if (k === null) {
  16498. continue;
  16499. }
  16500. for (; l < layersCount;) {
  16501. var packet = createPacket(resolution, k, l);
  16502. l++;
  16503. return packet;
  16504. }
  16505. l = 0;
  16506. }
  16507. r = 0;
  16508. }
  16509. c = 0;
  16510. }
  16511. px = 0;
  16512. }
  16513. error('JPX Error: Out of packets');
  16514. };
  16515. }
  16516. function ComponentPositionResolutionLayerIterator(context) {
  16517. var siz = context.SIZ;
  16518. var tileIndex = context.currentTile.index;
  16519. var tile = context.tiles[tileIndex];
  16520. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  16521. var componentsCount = siz.Csiz;
  16522. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  16523. var l = 0, r = 0, c = 0, px = 0, py = 0;
  16524. this.nextPacket = function JpxImage_nextPacket() {
  16525. // Section B.12.1.5 Component-position-resolution-layer
  16526. for (; c < componentsCount; ++c) {
  16527. var component = tile.components[c];
  16528. var precinctsIterationSizes = precinctsSizes.components[c];
  16529. var decompositionLevelsCount = component.codingStyleParameters.decompositionLevelsCount;
  16530. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  16531. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  16532. for (; r <= decompositionLevelsCount; r++) {
  16533. var resolution = component.resolutions[r];
  16534. var sizeInImageScale = precinctsIterationSizes.resolutions[r];
  16535. var k = getPrecinctIndexIfExist(px, py, sizeInImageScale, precinctsIterationSizes, resolution);
  16536. if (k === null) {
  16537. continue;
  16538. }
  16539. for (; l < layersCount;) {
  16540. var packet = createPacket(resolution, k, l);
  16541. l++;
  16542. return packet;
  16543. }
  16544. l = 0;
  16545. }
  16546. r = 0;
  16547. }
  16548. px = 0;
  16549. }
  16550. py = 0;
  16551. }
  16552. error('JPX Error: Out of packets');
  16553. };
  16554. }
  16555. function getPrecinctIndexIfExist(pxIndex, pyIndex, sizeInImageScale, precinctIterationSizes, resolution) {
  16556. var posX = pxIndex * precinctIterationSizes.minWidth;
  16557. var posY = pyIndex * precinctIterationSizes.minHeight;
  16558. if (posX % sizeInImageScale.width !== 0 || posY % sizeInImageScale.height !== 0) {
  16559. return null;
  16560. }
  16561. var startPrecinctRowIndex = posY / sizeInImageScale.width * resolution.precinctParameters.numprecinctswide;
  16562. return posX / sizeInImageScale.height + startPrecinctRowIndex;
  16563. }
  16564. function getPrecinctSizesInImageScale(tile) {
  16565. var componentsCount = tile.components.length;
  16566. var minWidth = Number.MAX_VALUE;
  16567. var minHeight = Number.MAX_VALUE;
  16568. var maxNumWide = 0;
  16569. var maxNumHigh = 0;
  16570. var sizePerComponent = new Array(componentsCount);
  16571. for (var c = 0; c < componentsCount; c++) {
  16572. var component = tile.components[c];
  16573. var decompositionLevelsCount = component.codingStyleParameters.decompositionLevelsCount;
  16574. var sizePerResolution = new Array(decompositionLevelsCount + 1);
  16575. var minWidthCurrentComponent = Number.MAX_VALUE;
  16576. var minHeightCurrentComponent = Number.MAX_VALUE;
  16577. var maxNumWideCurrentComponent = 0;
  16578. var maxNumHighCurrentComponent = 0;
  16579. var scale = 1;
  16580. for (var r = decompositionLevelsCount; r >= 0; --r) {
  16581. var resolution = component.resolutions[r];
  16582. var widthCurrentResolution = scale * resolution.precinctParameters.precinctWidth;
  16583. var heightCurrentResolution = scale * resolution.precinctParameters.precinctHeight;
  16584. minWidthCurrentComponent = Math.min(minWidthCurrentComponent, widthCurrentResolution);
  16585. minHeightCurrentComponent = Math.min(minHeightCurrentComponent, heightCurrentResolution);
  16586. maxNumWideCurrentComponent = Math.max(maxNumWideCurrentComponent, resolution.precinctParameters.numprecinctswide);
  16587. maxNumHighCurrentComponent = Math.max(maxNumHighCurrentComponent, resolution.precinctParameters.numprecinctshigh);
  16588. sizePerResolution[r] = {
  16589. width: widthCurrentResolution,
  16590. height: heightCurrentResolution
  16591. };
  16592. scale <<= 1;
  16593. }
  16594. minWidth = Math.min(minWidth, minWidthCurrentComponent);
  16595. minHeight = Math.min(minHeight, minHeightCurrentComponent);
  16596. maxNumWide = Math.max(maxNumWide, maxNumWideCurrentComponent);
  16597. maxNumHigh = Math.max(maxNumHigh, maxNumHighCurrentComponent);
  16598. sizePerComponent[c] = {
  16599. resolutions: sizePerResolution,
  16600. minWidth: minWidthCurrentComponent,
  16601. minHeight: minHeightCurrentComponent,
  16602. maxNumWide: maxNumWideCurrentComponent,
  16603. maxNumHigh: maxNumHighCurrentComponent
  16604. };
  16605. }
  16606. return {
  16607. components: sizePerComponent,
  16608. minWidth: minWidth,
  16609. minHeight: minHeight,
  16610. maxNumWide: maxNumWide,
  16611. maxNumHigh: maxNumHigh
  16612. };
  16613. }
  16614. function buildPackets(context) {
  16615. var siz = context.SIZ;
  16616. var tileIndex = context.currentTile.index;
  16617. var tile = context.tiles[tileIndex];
  16618. var componentsCount = siz.Csiz;
  16619. // Creating resolutions and sub-bands for each component
  16620. for (var c = 0; c < componentsCount; c++) {
  16621. var component = tile.components[c];
  16622. var decompositionLevelsCount = component.codingStyleParameters.decompositionLevelsCount;
  16623. // Section B.5 Resolution levels and sub-bands
  16624. var resolutions = [];
  16625. var subbands = [];
  16626. for (var r = 0; r <= decompositionLevelsCount; r++) {
  16627. var blocksDimensions = getBlocksDimensions(context, component, r);
  16628. var resolution = {};
  16629. var scale = 1 << decompositionLevelsCount - r;
  16630. resolution.trx0 = Math.ceil(component.tcx0 / scale);
  16631. resolution.try0 = Math.ceil(component.tcy0 / scale);
  16632. resolution.trx1 = Math.ceil(component.tcx1 / scale);
  16633. resolution.try1 = Math.ceil(component.tcy1 / scale);
  16634. resolution.resLevel = r;
  16635. buildPrecincts(context, resolution, blocksDimensions);
  16636. resolutions.push(resolution);
  16637. var subband;
  16638. if (r === 0) {
  16639. // one sub-band (LL) with last decomposition
  16640. subband = {};
  16641. subband.type = 'LL';
  16642. subband.tbx0 = Math.ceil(component.tcx0 / scale);
  16643. subband.tby0 = Math.ceil(component.tcy0 / scale);
  16644. subband.tbx1 = Math.ceil(component.tcx1 / scale);
  16645. subband.tby1 = Math.ceil(component.tcy1 / scale);
  16646. subband.resolution = resolution;
  16647. buildCodeblocks(context, subband, blocksDimensions);
  16648. subbands.push(subband);
  16649. resolution.subbands = [subband];
  16650. } else {
  16651. var bscale = 1 << decompositionLevelsCount - r + 1;
  16652. var resolutionSubbands = [];
  16653. // three sub-bands (HL, LH and HH) with rest of decompositions
  16654. subband = {};
  16655. subband.type = 'HL';
  16656. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  16657. subband.tby0 = Math.ceil(component.tcy0 / bscale);
  16658. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  16659. subband.tby1 = Math.ceil(component.tcy1 / bscale);
  16660. subband.resolution = resolution;
  16661. buildCodeblocks(context, subband, blocksDimensions);
  16662. subbands.push(subband);
  16663. resolutionSubbands.push(subband);
  16664. subband = {};
  16665. subband.type = 'LH';
  16666. subband.tbx0 = Math.ceil(component.tcx0 / bscale);
  16667. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  16668. subband.tbx1 = Math.ceil(component.tcx1 / bscale);
  16669. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  16670. subband.resolution = resolution;
  16671. buildCodeblocks(context, subband, blocksDimensions);
  16672. subbands.push(subband);
  16673. resolutionSubbands.push(subband);
  16674. subband = {};
  16675. subband.type = 'HH';
  16676. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  16677. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  16678. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  16679. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  16680. subband.resolution = resolution;
  16681. buildCodeblocks(context, subband, blocksDimensions);
  16682. subbands.push(subband);
  16683. resolutionSubbands.push(subband);
  16684. resolution.subbands = resolutionSubbands;
  16685. }
  16686. }
  16687. component.resolutions = resolutions;
  16688. component.subbands = subbands;
  16689. }
  16690. // Generate the packets sequence
  16691. var progressionOrder = tile.codingStyleDefaultParameters.progressionOrder;
  16692. switch (progressionOrder) {
  16693. case 0:
  16694. tile.packetsIterator = new LayerResolutionComponentPositionIterator(context);
  16695. break;
  16696. case 1:
  16697. tile.packetsIterator = new ResolutionLayerComponentPositionIterator(context);
  16698. break;
  16699. case 2:
  16700. tile.packetsIterator = new ResolutionPositionComponentLayerIterator(context);
  16701. break;
  16702. case 3:
  16703. tile.packetsIterator = new PositionComponentResolutionLayerIterator(context);
  16704. break;
  16705. case 4:
  16706. tile.packetsIterator = new ComponentPositionResolutionLayerIterator(context);
  16707. break;
  16708. default:
  16709. error('JPX Error: Unsupported progression order ' + progressionOrder);
  16710. }
  16711. }
  16712. function parseTilePackets(context, data, offset, dataLength) {
  16713. var position = 0;
  16714. var buffer, bufferSize = 0, skipNextBit = false;
  16715. function readBits(count) {
  16716. while (bufferSize < count) {
  16717. var b = data[offset + position];
  16718. position++;
  16719. if (skipNextBit) {
  16720. buffer = buffer << 7 | b;
  16721. bufferSize += 7;
  16722. skipNextBit = false;
  16723. } else {
  16724. buffer = buffer << 8 | b;
  16725. bufferSize += 8;
  16726. }
  16727. if (b === 0xFF) {
  16728. skipNextBit = true;
  16729. }
  16730. }
  16731. bufferSize -= count;
  16732. return buffer >>> bufferSize & (1 << count) - 1;
  16733. }
  16734. function skipMarkerIfEqual(value) {
  16735. if (data[offset + position - 1] === 0xFF && data[offset + position] === value) {
  16736. skipBytes(1);
  16737. return true;
  16738. } else if (data[offset + position] === 0xFF && data[offset + position + 1] === value) {
  16739. skipBytes(2);
  16740. return true;
  16741. }
  16742. return false;
  16743. }
  16744. function skipBytes(count) {
  16745. position += count;
  16746. }
  16747. function alignToByte() {
  16748. bufferSize = 0;
  16749. if (skipNextBit) {
  16750. position++;
  16751. skipNextBit = false;
  16752. }
  16753. }
  16754. function readCodingpasses() {
  16755. if (readBits(1) === 0) {
  16756. return 1;
  16757. }
  16758. if (readBits(1) === 0) {
  16759. return 2;
  16760. }
  16761. var value = readBits(2);
  16762. if (value < 3) {
  16763. return value + 3;
  16764. }
  16765. value = readBits(5);
  16766. if (value < 31) {
  16767. return value + 6;
  16768. }
  16769. value = readBits(7);
  16770. return value + 37;
  16771. }
  16772. var tileIndex = context.currentTile.index;
  16773. var tile = context.tiles[tileIndex];
  16774. var sopMarkerUsed = context.COD.sopMarkerUsed;
  16775. var ephMarkerUsed = context.COD.ephMarkerUsed;
  16776. var packetsIterator = tile.packetsIterator;
  16777. while (position < dataLength) {
  16778. alignToByte();
  16779. if (sopMarkerUsed && skipMarkerIfEqual(0x91)) {
  16780. // Skip also marker segment length and packet sequence ID
  16781. skipBytes(4);
  16782. }
  16783. var packet = packetsIterator.nextPacket();
  16784. if (!readBits(1)) {
  16785. continue;
  16786. }
  16787. var layerNumber = packet.layerNumber;
  16788. var queue = [], codeblock;
  16789. for (var i = 0, ii = packet.codeblocks.length; i < ii; i++) {
  16790. codeblock = packet.codeblocks[i];
  16791. var precinct = codeblock.precinct;
  16792. var codeblockColumn = codeblock.cbx - precinct.cbxMin;
  16793. var codeblockRow = codeblock.cby - precinct.cbyMin;
  16794. var codeblockIncluded = false;
  16795. var firstTimeInclusion = false;
  16796. var valueReady;
  16797. if (codeblock['included'] !== undefined) {
  16798. codeblockIncluded = !!readBits(1);
  16799. } else {
  16800. // reading inclusion tree
  16801. precinct = codeblock.precinct;
  16802. var inclusionTree, zeroBitPlanesTree;
  16803. if (precinct['inclusionTree'] !== undefined) {
  16804. inclusionTree = precinct.inclusionTree;
  16805. } else {
  16806. // building inclusion and zero bit-planes trees
  16807. var width = precinct.cbxMax - precinct.cbxMin + 1;
  16808. var height = precinct.cbyMax - precinct.cbyMin + 1;
  16809. inclusionTree = new InclusionTree(width, height, layerNumber);
  16810. zeroBitPlanesTree = new TagTree(width, height);
  16811. precinct.inclusionTree = inclusionTree;
  16812. precinct.zeroBitPlanesTree = zeroBitPlanesTree;
  16813. }
  16814. if (inclusionTree.reset(codeblockColumn, codeblockRow, layerNumber)) {
  16815. while (true) {
  16816. if (readBits(1)) {
  16817. valueReady = !inclusionTree.nextLevel();
  16818. if (valueReady) {
  16819. codeblock.included = true;
  16820. codeblockIncluded = firstTimeInclusion = true;
  16821. break;
  16822. }
  16823. } else {
  16824. inclusionTree.incrementValue(layerNumber);
  16825. break;
  16826. }
  16827. }
  16828. }
  16829. }
  16830. if (!codeblockIncluded) {
  16831. continue;
  16832. }
  16833. if (firstTimeInclusion) {
  16834. zeroBitPlanesTree = precinct.zeroBitPlanesTree;
  16835. zeroBitPlanesTree.reset(codeblockColumn, codeblockRow);
  16836. while (true) {
  16837. if (readBits(1)) {
  16838. valueReady = !zeroBitPlanesTree.nextLevel();
  16839. if (valueReady) {
  16840. break;
  16841. }
  16842. } else {
  16843. zeroBitPlanesTree.incrementValue();
  16844. }
  16845. }
  16846. codeblock.zeroBitPlanes = zeroBitPlanesTree.value;
  16847. }
  16848. var codingpasses = readCodingpasses();
  16849. while (readBits(1)) {
  16850. codeblock.Lblock++;
  16851. }
  16852. var codingpassesLog2 = log2(codingpasses);
  16853. // rounding down log2
  16854. var bits = (codingpasses < 1 << codingpassesLog2 ? codingpassesLog2 - 1 : codingpassesLog2) + codeblock.Lblock;
  16855. var codedDataLength = readBits(bits);
  16856. queue.push({
  16857. codeblock: codeblock,
  16858. codingpasses: codingpasses,
  16859. dataLength: codedDataLength
  16860. });
  16861. }
  16862. alignToByte();
  16863. if (ephMarkerUsed) {
  16864. skipMarkerIfEqual(0x92);
  16865. }
  16866. while (queue.length > 0) {
  16867. var packetItem = queue.shift();
  16868. codeblock = packetItem.codeblock;
  16869. if (codeblock['data'] === undefined) {
  16870. codeblock.data = [];
  16871. }
  16872. codeblock.data.push({
  16873. data: data,
  16874. start: offset + position,
  16875. end: offset + position + packetItem.dataLength,
  16876. codingpasses: packetItem.codingpasses
  16877. });
  16878. position += packetItem.dataLength;
  16879. }
  16880. }
  16881. return position;
  16882. }
  16883. function copyCoefficients(coefficients, levelWidth, levelHeight, subband, delta, mb, reversible, segmentationSymbolUsed) {
  16884. var x0 = subband.tbx0;
  16885. var y0 = subband.tby0;
  16886. var width = subband.tbx1 - subband.tbx0;
  16887. var codeblocks = subband.codeblocks;
  16888. var right = subband.type.charAt(0) === 'H' ? 1 : 0;
  16889. var bottom = subband.type.charAt(1) === 'H' ? levelWidth : 0;
  16890. for (var i = 0, ii = codeblocks.length; i < ii; ++i) {
  16891. var codeblock = codeblocks[i];
  16892. var blockWidth = codeblock.tbx1_ - codeblock.tbx0_;
  16893. var blockHeight = codeblock.tby1_ - codeblock.tby0_;
  16894. if (blockWidth === 0 || blockHeight === 0) {
  16895. continue;
  16896. }
  16897. if (codeblock['data'] === undefined) {
  16898. continue;
  16899. }
  16900. var bitModel, currentCodingpassType;
  16901. bitModel = new BitModel(blockWidth, blockHeight, codeblock.subbandType, codeblock.zeroBitPlanes, mb);
  16902. currentCodingpassType = 2;
  16903. // first bit plane starts from cleanup
  16904. // collect data
  16905. var data = codeblock.data, totalLength = 0, codingpasses = 0;
  16906. var j, jj, dataItem;
  16907. for (j = 0, jj = data.length; j < jj; j++) {
  16908. dataItem = data[j];
  16909. totalLength += dataItem.end - dataItem.start;
  16910. codingpasses += dataItem.codingpasses;
  16911. }
  16912. var encodedData = new Uint8Array(totalLength);
  16913. var position = 0;
  16914. for (j = 0, jj = data.length; j < jj; j++) {
  16915. dataItem = data[j];
  16916. var chunk = dataItem.data.subarray(dataItem.start, dataItem.end);
  16917. encodedData.set(chunk, position);
  16918. position += chunk.length;
  16919. }
  16920. // decoding the item
  16921. var decoder = new ArithmeticDecoder(encodedData, 0, totalLength);
  16922. bitModel.setDecoder(decoder);
  16923. for (j = 0; j < codingpasses; j++) {
  16924. switch (currentCodingpassType) {
  16925. case 0:
  16926. bitModel.runSignificancePropagationPass();
  16927. break;
  16928. case 1:
  16929. bitModel.runMagnitudeRefinementPass();
  16930. break;
  16931. case 2:
  16932. bitModel.runCleanupPass();
  16933. if (segmentationSymbolUsed) {
  16934. bitModel.checkSegmentationSymbol();
  16935. }
  16936. break;
  16937. }
  16938. currentCodingpassType = (currentCodingpassType + 1) % 3;
  16939. }
  16940. var offset = codeblock.tbx0_ - x0 + (codeblock.tby0_ - y0) * width;
  16941. var sign = bitModel.coefficentsSign;
  16942. var magnitude = bitModel.coefficentsMagnitude;
  16943. var bitsDecoded = bitModel.bitsDecoded;
  16944. var magnitudeCorrection = reversible ? 0 : 0.5;
  16945. var k, n, nb;
  16946. position = 0;
  16947. // Do the interleaving of Section F.3.3 here, so we do not need
  16948. // to copy later. LL level is not interleaved, just copied.
  16949. var interleave = subband.type !== 'LL';
  16950. for (j = 0; j < blockHeight; j++) {
  16951. var row = offset / width | 0;
  16952. // row in the non-interleaved subband
  16953. var levelOffset = 2 * row * (levelWidth - width) + right + bottom;
  16954. for (k = 0; k < blockWidth; k++) {
  16955. n = magnitude[position];
  16956. if (n !== 0) {
  16957. n = (n + magnitudeCorrection) * delta;
  16958. if (sign[position] !== 0) {
  16959. n = -n;
  16960. }
  16961. nb = bitsDecoded[position];
  16962. var pos = interleave ? levelOffset + (offset << 1) : offset;
  16963. if (reversible && nb >= mb) {
  16964. coefficients[pos] = n;
  16965. } else {
  16966. coefficients[pos] = n * (1 << mb - nb);
  16967. }
  16968. }
  16969. offset++;
  16970. position++;
  16971. }
  16972. offset += width - blockWidth;
  16973. }
  16974. }
  16975. }
  16976. function transformTile(context, tile, c) {
  16977. var component = tile.components[c];
  16978. var codingStyleParameters = component.codingStyleParameters;
  16979. var quantizationParameters = component.quantizationParameters;
  16980. var decompositionLevelsCount = codingStyleParameters.decompositionLevelsCount;
  16981. var spqcds = quantizationParameters.SPqcds;
  16982. var scalarExpounded = quantizationParameters.scalarExpounded;
  16983. var guardBits = quantizationParameters.guardBits;
  16984. var segmentationSymbolUsed = codingStyleParameters.segmentationSymbolUsed;
  16985. var precision = context.components[c].precision;
  16986. var reversible = codingStyleParameters.reversibleTransformation;
  16987. var transform = reversible ? new ReversibleTransform() : new IrreversibleTransform();
  16988. var subbandCoefficients = [];
  16989. var b = 0;
  16990. for (var i = 0; i <= decompositionLevelsCount; i++) {
  16991. var resolution = component.resolutions[i];
  16992. var width = resolution.trx1 - resolution.trx0;
  16993. var height = resolution.try1 - resolution.try0;
  16994. // Allocate space for the whole sublevel.
  16995. var coefficients = new Float32Array(width * height);
  16996. for (var j = 0, jj = resolution.subbands.length; j < jj; j++) {
  16997. var mu, epsilon;
  16998. if (!scalarExpounded) {
  16999. // formula E-5
  17000. mu = spqcds[0].mu;
  17001. epsilon = spqcds[0].epsilon + (i > 0 ? 1 - i : 0);
  17002. } else {
  17003. mu = spqcds[b].mu;
  17004. epsilon = spqcds[b].epsilon;
  17005. b++;
  17006. }
  17007. var subband = resolution.subbands[j];
  17008. var gainLog2 = SubbandsGainLog2[subband.type];
  17009. // calculate quantization coefficient (Section E.1.1.1)
  17010. var delta = reversible ? 1 : Math.pow(2, precision + gainLog2 - epsilon) * (1 + mu / 2048);
  17011. var mb = guardBits + epsilon - 1;
  17012. // In the first resolution level, copyCoefficients will fill the
  17013. // whole array with coefficients. In the succeeding passes,
  17014. // copyCoefficients will consecutively fill in the values that belong
  17015. // to the interleaved positions of the HL, LH, and HH coefficients.
  17016. // The LL coefficients will then be interleaved in Transform.iterate().
  17017. copyCoefficients(coefficients, width, height, subband, delta, mb, reversible, segmentationSymbolUsed);
  17018. }
  17019. subbandCoefficients.push({
  17020. width: width,
  17021. height: height,
  17022. items: coefficients
  17023. });
  17024. }
  17025. var result = transform.calculate(subbandCoefficients, component.tcx0, component.tcy0);
  17026. return {
  17027. left: component.tcx0,
  17028. top: component.tcy0,
  17029. width: result.width,
  17030. height: result.height,
  17031. items: result.items
  17032. };
  17033. }
  17034. function transformComponents(context) {
  17035. var siz = context.SIZ;
  17036. var components = context.components;
  17037. var componentsCount = siz.Csiz;
  17038. var resultImages = [];
  17039. for (var i = 0, ii = context.tiles.length; i < ii; i++) {
  17040. var tile = context.tiles[i];
  17041. var transformedTiles = [];
  17042. var c;
  17043. for (c = 0; c < componentsCount; c++) {
  17044. transformedTiles[c] = transformTile(context, tile, c);
  17045. }
  17046. var tile0 = transformedTiles[0];
  17047. var out = new Uint8Array(tile0.items.length * componentsCount);
  17048. var result = {
  17049. left: tile0.left,
  17050. top: tile0.top,
  17051. width: tile0.width,
  17052. height: tile0.height,
  17053. items: out
  17054. };
  17055. // Section G.2.2 Inverse multi component transform
  17056. var shift, offset, max, min, maxK;
  17057. var pos = 0, j, jj, y0, y1, y2, r, g, b, k, val;
  17058. if (tile.codingStyleDefaultParameters.multipleComponentTransform) {
  17059. var fourComponents = componentsCount === 4;
  17060. var y0items = transformedTiles[0].items;
  17061. var y1items = transformedTiles[1].items;
  17062. var y2items = transformedTiles[2].items;
  17063. var y3items = fourComponents ? transformedTiles[3].items : null;
  17064. // HACK: The multiple component transform formulas below assume that
  17065. // all components have the same precision. With this in mind, we
  17066. // compute shift and offset only once.
  17067. shift = components[0].precision - 8;
  17068. offset = (128 << shift) + 0.5;
  17069. max = 255 * (1 << shift);
  17070. maxK = max * 0.5;
  17071. min = -maxK;
  17072. var component0 = tile.components[0];
  17073. var alpha01 = componentsCount - 3;
  17074. jj = y0items.length;
  17075. if (!component0.codingStyleParameters.reversibleTransformation) {
  17076. // inverse irreversible multiple component transform
  17077. for (j = 0; j < jj; j++, pos += alpha01) {
  17078. y0 = y0items[j] + offset;
  17079. y1 = y1items[j];
  17080. y2 = y2items[j];
  17081. r = y0 + 1.402 * y2;
  17082. g = y0 - 0.34413 * y1 - 0.71414 * y2;
  17083. b = y0 + 1.772 * y1;
  17084. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  17085. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  17086. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  17087. }
  17088. } else {
  17089. // inverse reversible multiple component transform
  17090. for (j = 0; j < jj; j++, pos += alpha01) {
  17091. y0 = y0items[j] + offset;
  17092. y1 = y1items[j];
  17093. y2 = y2items[j];
  17094. g = y0 - (y2 + y1 >> 2);
  17095. r = g + y2;
  17096. b = g + y1;
  17097. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  17098. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  17099. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  17100. }
  17101. }
  17102. if (fourComponents) {
  17103. for (j = 0, pos = 3; j < jj; j++, pos += 4) {
  17104. k = y3items[j];
  17105. out[pos] = k <= min ? 0 : k >= maxK ? 255 : k + offset >> shift;
  17106. }
  17107. }
  17108. } else {
  17109. // no multi-component transform
  17110. for (c = 0; c < componentsCount; c++) {
  17111. var items = transformedTiles[c].items;
  17112. shift = components[c].precision - 8;
  17113. offset = (128 << shift) + 0.5;
  17114. max = 127.5 * (1 << shift);
  17115. min = -max;
  17116. for (pos = c, j = 0, jj = items.length; j < jj; j++) {
  17117. val = items[j];
  17118. out[pos] = val <= min ? 0 : val >= max ? 255 : val + offset >> shift;
  17119. pos += componentsCount;
  17120. }
  17121. }
  17122. }
  17123. resultImages.push(result);
  17124. }
  17125. return resultImages;
  17126. }
  17127. function initializeTile(context, tileIndex) {
  17128. var siz = context.SIZ;
  17129. var componentsCount = siz.Csiz;
  17130. var tile = context.tiles[tileIndex];
  17131. for (var c = 0; c < componentsCount; c++) {
  17132. var component = tile.components[c];
  17133. var qcdOrQcc = context.currentTile.QCC[c] !== undefined ? context.currentTile.QCC[c] : context.currentTile.QCD;
  17134. component.quantizationParameters = qcdOrQcc;
  17135. var codOrCoc = context.currentTile.COC[c] !== undefined ? context.currentTile.COC[c] : context.currentTile.COD;
  17136. component.codingStyleParameters = codOrCoc;
  17137. }
  17138. tile.codingStyleDefaultParameters = context.currentTile.COD;
  17139. }
  17140. // Section B.10.2 Tag trees
  17141. var TagTree = function TagTreeClosure() {
  17142. function TagTree(width, height) {
  17143. var levelsLength = log2(Math.max(width, height)) + 1;
  17144. this.levels = [];
  17145. for (var i = 0; i < levelsLength; i++) {
  17146. var level = {
  17147. width: width,
  17148. height: height,
  17149. items: []
  17150. };
  17151. this.levels.push(level);
  17152. width = Math.ceil(width / 2);
  17153. height = Math.ceil(height / 2);
  17154. }
  17155. }
  17156. TagTree.prototype = {
  17157. reset: function TagTree_reset(i, j) {
  17158. var currentLevel = 0, value = 0, level;
  17159. while (currentLevel < this.levels.length) {
  17160. level = this.levels[currentLevel];
  17161. var index = i + j * level.width;
  17162. if (level.items[index] !== undefined) {
  17163. value = level.items[index];
  17164. break;
  17165. }
  17166. level.index = index;
  17167. i >>= 1;
  17168. j >>= 1;
  17169. currentLevel++;
  17170. }
  17171. currentLevel--;
  17172. level = this.levels[currentLevel];
  17173. level.items[level.index] = value;
  17174. this.currentLevel = currentLevel;
  17175. delete this.value;
  17176. },
  17177. incrementValue: function TagTree_incrementValue() {
  17178. var level = this.levels[this.currentLevel];
  17179. level.items[level.index]++;
  17180. },
  17181. nextLevel: function TagTree_nextLevel() {
  17182. var currentLevel = this.currentLevel;
  17183. var level = this.levels[currentLevel];
  17184. var value = level.items[level.index];
  17185. currentLevel--;
  17186. if (currentLevel < 0) {
  17187. this.value = value;
  17188. return false;
  17189. }
  17190. this.currentLevel = currentLevel;
  17191. level = this.levels[currentLevel];
  17192. level.items[level.index] = value;
  17193. return true;
  17194. }
  17195. };
  17196. return TagTree;
  17197. }();
  17198. var InclusionTree = function InclusionTreeClosure() {
  17199. function InclusionTree(width, height, defaultValue) {
  17200. var levelsLength = log2(Math.max(width, height)) + 1;
  17201. this.levels = [];
  17202. for (var i = 0; i < levelsLength; i++) {
  17203. var items = new Uint8Array(width * height);
  17204. for (var j = 0, jj = items.length; j < jj; j++) {
  17205. items[j] = defaultValue;
  17206. }
  17207. var level = {
  17208. width: width,
  17209. height: height,
  17210. items: items
  17211. };
  17212. this.levels.push(level);
  17213. width = Math.ceil(width / 2);
  17214. height = Math.ceil(height / 2);
  17215. }
  17216. }
  17217. InclusionTree.prototype = {
  17218. reset: function InclusionTree_reset(i, j, stopValue) {
  17219. var currentLevel = 0;
  17220. while (currentLevel < this.levels.length) {
  17221. var level = this.levels[currentLevel];
  17222. var index = i + j * level.width;
  17223. level.index = index;
  17224. var value = level.items[index];
  17225. if (value === 0xFF) {
  17226. break;
  17227. }
  17228. if (value > stopValue) {
  17229. this.currentLevel = currentLevel;
  17230. // already know about this one, propagating the value to top levels
  17231. this.propagateValues();
  17232. return false;
  17233. }
  17234. i >>= 1;
  17235. j >>= 1;
  17236. currentLevel++;
  17237. }
  17238. this.currentLevel = currentLevel - 1;
  17239. return true;
  17240. },
  17241. incrementValue: function InclusionTree_incrementValue(stopValue) {
  17242. var level = this.levels[this.currentLevel];
  17243. level.items[level.index] = stopValue + 1;
  17244. this.propagateValues();
  17245. },
  17246. propagateValues: function InclusionTree_propagateValues() {
  17247. var levelIndex = this.currentLevel;
  17248. var level = this.levels[levelIndex];
  17249. var currentValue = level.items[level.index];
  17250. while (--levelIndex >= 0) {
  17251. level = this.levels[levelIndex];
  17252. level.items[level.index] = currentValue;
  17253. }
  17254. },
  17255. nextLevel: function InclusionTree_nextLevel() {
  17256. var currentLevel = this.currentLevel;
  17257. var level = this.levels[currentLevel];
  17258. var value = level.items[level.index];
  17259. level.items[level.index] = 0xFF;
  17260. currentLevel--;
  17261. if (currentLevel < 0) {
  17262. return false;
  17263. }
  17264. this.currentLevel = currentLevel;
  17265. level = this.levels[currentLevel];
  17266. level.items[level.index] = value;
  17267. return true;
  17268. }
  17269. };
  17270. return InclusionTree;
  17271. }();
  17272. // Section D. Coefficient bit modeling
  17273. var BitModel = function BitModelClosure() {
  17274. var UNIFORM_CONTEXT = 17;
  17275. var RUNLENGTH_CONTEXT = 18;
  17276. // Table D-1
  17277. // The index is binary presentation: 0dddvvhh, ddd - sum of Di (0..4),
  17278. // vv - sum of Vi (0..2), and hh - sum of Hi (0..2)
  17279. var LLAndLHContextsLabel = new Uint8Array([
  17280. 0,
  17281. 5,
  17282. 8,
  17283. 0,
  17284. 3,
  17285. 7,
  17286. 8,
  17287. 0,
  17288. 4,
  17289. 7,
  17290. 8,
  17291. 0,
  17292. 0,
  17293. 0,
  17294. 0,
  17295. 0,
  17296. 1,
  17297. 6,
  17298. 8,
  17299. 0,
  17300. 3,
  17301. 7,
  17302. 8,
  17303. 0,
  17304. 4,
  17305. 7,
  17306. 8,
  17307. 0,
  17308. 0,
  17309. 0,
  17310. 0,
  17311. 0,
  17312. 2,
  17313. 6,
  17314. 8,
  17315. 0,
  17316. 3,
  17317. 7,
  17318. 8,
  17319. 0,
  17320. 4,
  17321. 7,
  17322. 8,
  17323. 0,
  17324. 0,
  17325. 0,
  17326. 0,
  17327. 0,
  17328. 2,
  17329. 6,
  17330. 8,
  17331. 0,
  17332. 3,
  17333. 7,
  17334. 8,
  17335. 0,
  17336. 4,
  17337. 7,
  17338. 8,
  17339. 0,
  17340. 0,
  17341. 0,
  17342. 0,
  17343. 0,
  17344. 2,
  17345. 6,
  17346. 8,
  17347. 0,
  17348. 3,
  17349. 7,
  17350. 8,
  17351. 0,
  17352. 4,
  17353. 7,
  17354. 8
  17355. ]);
  17356. var HLContextLabel = new Uint8Array([
  17357. 0,
  17358. 3,
  17359. 4,
  17360. 0,
  17361. 5,
  17362. 7,
  17363. 7,
  17364. 0,
  17365. 8,
  17366. 8,
  17367. 8,
  17368. 0,
  17369. 0,
  17370. 0,
  17371. 0,
  17372. 0,
  17373. 1,
  17374. 3,
  17375. 4,
  17376. 0,
  17377. 6,
  17378. 7,
  17379. 7,
  17380. 0,
  17381. 8,
  17382. 8,
  17383. 8,
  17384. 0,
  17385. 0,
  17386. 0,
  17387. 0,
  17388. 0,
  17389. 2,
  17390. 3,
  17391. 4,
  17392. 0,
  17393. 6,
  17394. 7,
  17395. 7,
  17396. 0,
  17397. 8,
  17398. 8,
  17399. 8,
  17400. 0,
  17401. 0,
  17402. 0,
  17403. 0,
  17404. 0,
  17405. 2,
  17406. 3,
  17407. 4,
  17408. 0,
  17409. 6,
  17410. 7,
  17411. 7,
  17412. 0,
  17413. 8,
  17414. 8,
  17415. 8,
  17416. 0,
  17417. 0,
  17418. 0,
  17419. 0,
  17420. 0,
  17421. 2,
  17422. 3,
  17423. 4,
  17424. 0,
  17425. 6,
  17426. 7,
  17427. 7,
  17428. 0,
  17429. 8,
  17430. 8,
  17431. 8
  17432. ]);
  17433. var HHContextLabel = new Uint8Array([
  17434. 0,
  17435. 1,
  17436. 2,
  17437. 0,
  17438. 1,
  17439. 2,
  17440. 2,
  17441. 0,
  17442. 2,
  17443. 2,
  17444. 2,
  17445. 0,
  17446. 0,
  17447. 0,
  17448. 0,
  17449. 0,
  17450. 3,
  17451. 4,
  17452. 5,
  17453. 0,
  17454. 4,
  17455. 5,
  17456. 5,
  17457. 0,
  17458. 5,
  17459. 5,
  17460. 5,
  17461. 0,
  17462. 0,
  17463. 0,
  17464. 0,
  17465. 0,
  17466. 6,
  17467. 7,
  17468. 7,
  17469. 0,
  17470. 7,
  17471. 7,
  17472. 7,
  17473. 0,
  17474. 7,
  17475. 7,
  17476. 7,
  17477. 0,
  17478. 0,
  17479. 0,
  17480. 0,
  17481. 0,
  17482. 8,
  17483. 8,
  17484. 8,
  17485. 0,
  17486. 8,
  17487. 8,
  17488. 8,
  17489. 0,
  17490. 8,
  17491. 8,
  17492. 8,
  17493. 0,
  17494. 0,
  17495. 0,
  17496. 0,
  17497. 0,
  17498. 8,
  17499. 8,
  17500. 8,
  17501. 0,
  17502. 8,
  17503. 8,
  17504. 8,
  17505. 0,
  17506. 8,
  17507. 8,
  17508. 8
  17509. ]);
  17510. function BitModel(width, height, subband, zeroBitPlanes, mb) {
  17511. this.width = width;
  17512. this.height = height;
  17513. this.contextLabelTable = subband === 'HH' ? HHContextLabel : subband === 'HL' ? HLContextLabel : LLAndLHContextsLabel;
  17514. var coefficientCount = width * height;
  17515. // coefficients outside the encoding region treated as insignificant
  17516. // add border state cells for significanceState
  17517. this.neighborsSignificance = new Uint8Array(coefficientCount);
  17518. this.coefficentsSign = new Uint8Array(coefficientCount);
  17519. this.coefficentsMagnitude = mb > 14 ? new Uint32Array(coefficientCount) : mb > 6 ? new Uint16Array(coefficientCount) : new Uint8Array(coefficientCount);
  17520. this.processingFlags = new Uint8Array(coefficientCount);
  17521. var bitsDecoded = new Uint8Array(coefficientCount);
  17522. if (zeroBitPlanes !== 0) {
  17523. for (var i = 0; i < coefficientCount; i++) {
  17524. bitsDecoded[i] = zeroBitPlanes;
  17525. }
  17526. }
  17527. this.bitsDecoded = bitsDecoded;
  17528. this.reset();
  17529. }
  17530. BitModel.prototype = {
  17531. setDecoder: function BitModel_setDecoder(decoder) {
  17532. this.decoder = decoder;
  17533. },
  17534. reset: function BitModel_reset() {
  17535. // We have 17 contexts that are accessed via context labels,
  17536. // plus the uniform and runlength context.
  17537. this.contexts = new Int8Array(19);
  17538. // Contexts are packed into 1 byte:
  17539. // highest 7 bits carry the index, lowest bit carries mps
  17540. this.contexts[0] = 4 << 1 | 0;
  17541. this.contexts[UNIFORM_CONTEXT] = 46 << 1 | 0;
  17542. this.contexts[RUNLENGTH_CONTEXT] = 3 << 1 | 0;
  17543. },
  17544. setNeighborsSignificance: function BitModel_setNeighborsSignificance(row, column, index) {
  17545. var neighborsSignificance = this.neighborsSignificance;
  17546. var width = this.width, height = this.height;
  17547. var left = column > 0;
  17548. var right = column + 1 < width;
  17549. var i;
  17550. if (row > 0) {
  17551. i = index - width;
  17552. if (left) {
  17553. neighborsSignificance[i - 1] += 0x10;
  17554. }
  17555. if (right) {
  17556. neighborsSignificance[i + 1] += 0x10;
  17557. }
  17558. neighborsSignificance[i] += 0x04;
  17559. }
  17560. if (row + 1 < height) {
  17561. i = index + width;
  17562. if (left) {
  17563. neighborsSignificance[i - 1] += 0x10;
  17564. }
  17565. if (right) {
  17566. neighborsSignificance[i + 1] += 0x10;
  17567. }
  17568. neighborsSignificance[i] += 0x04;
  17569. }
  17570. if (left) {
  17571. neighborsSignificance[index - 1] += 0x01;
  17572. }
  17573. if (right) {
  17574. neighborsSignificance[index + 1] += 0x01;
  17575. }
  17576. neighborsSignificance[index] |= 0x80;
  17577. },
  17578. runSignificancePropagationPass: function BitModel_runSignificancePropagationPass() {
  17579. var decoder = this.decoder;
  17580. var width = this.width, height = this.height;
  17581. var coefficentsMagnitude = this.coefficentsMagnitude;
  17582. var coefficentsSign = this.coefficentsSign;
  17583. var neighborsSignificance = this.neighborsSignificance;
  17584. var processingFlags = this.processingFlags;
  17585. var contexts = this.contexts;
  17586. var labels = this.contextLabelTable;
  17587. var bitsDecoded = this.bitsDecoded;
  17588. var processedInverseMask = ~1;
  17589. var processedMask = 1;
  17590. var firstMagnitudeBitMask = 2;
  17591. for (var i0 = 0; i0 < height; i0 += 4) {
  17592. for (var j = 0; j < width; j++) {
  17593. var index = i0 * width + j;
  17594. for (var i1 = 0; i1 < 4; i1++, index += width) {
  17595. var i = i0 + i1;
  17596. if (i >= height) {
  17597. break;
  17598. }
  17599. // clear processed flag first
  17600. processingFlags[index] &= processedInverseMask;
  17601. if (coefficentsMagnitude[index] || !neighborsSignificance[index]) {
  17602. continue;
  17603. }
  17604. var contextLabel = labels[neighborsSignificance[index]];
  17605. var decision = decoder.readBit(contexts, contextLabel);
  17606. if (decision) {
  17607. var sign = this.decodeSignBit(i, j, index);
  17608. coefficentsSign[index] = sign;
  17609. coefficentsMagnitude[index] = 1;
  17610. this.setNeighborsSignificance(i, j, index);
  17611. processingFlags[index] |= firstMagnitudeBitMask;
  17612. }
  17613. bitsDecoded[index]++;
  17614. processingFlags[index] |= processedMask;
  17615. }
  17616. }
  17617. }
  17618. },
  17619. decodeSignBit: function BitModel_decodeSignBit(row, column, index) {
  17620. var width = this.width, height = this.height;
  17621. var coefficentsMagnitude = this.coefficentsMagnitude;
  17622. var coefficentsSign = this.coefficentsSign;
  17623. var contribution, sign0, sign1, significance1;
  17624. var contextLabel, decoded;
  17625. // calculate horizontal contribution
  17626. significance1 = column > 0 && coefficentsMagnitude[index - 1] !== 0;
  17627. if (column + 1 < width && coefficentsMagnitude[index + 1] !== 0) {
  17628. sign1 = coefficentsSign[index + 1];
  17629. if (significance1) {
  17630. sign0 = coefficentsSign[index - 1];
  17631. contribution = 1 - sign1 - sign0;
  17632. } else {
  17633. contribution = 1 - sign1 - sign1;
  17634. }
  17635. } else if (significance1) {
  17636. sign0 = coefficentsSign[index - 1];
  17637. contribution = 1 - sign0 - sign0;
  17638. } else {
  17639. contribution = 0;
  17640. }
  17641. var horizontalContribution = 3 * contribution;
  17642. // calculate vertical contribution and combine with the horizontal
  17643. significance1 = row > 0 && coefficentsMagnitude[index - width] !== 0;
  17644. if (row + 1 < height && coefficentsMagnitude[index + width] !== 0) {
  17645. sign1 = coefficentsSign[index + width];
  17646. if (significance1) {
  17647. sign0 = coefficentsSign[index - width];
  17648. contribution = 1 - sign1 - sign0 + horizontalContribution;
  17649. } else {
  17650. contribution = 1 - sign1 - sign1 + horizontalContribution;
  17651. }
  17652. } else if (significance1) {
  17653. sign0 = coefficentsSign[index - width];
  17654. contribution = 1 - sign0 - sign0 + horizontalContribution;
  17655. } else {
  17656. contribution = horizontalContribution;
  17657. }
  17658. if (contribution >= 0) {
  17659. contextLabel = 9 + contribution;
  17660. decoded = this.decoder.readBit(this.contexts, contextLabel);
  17661. } else {
  17662. contextLabel = 9 - contribution;
  17663. decoded = this.decoder.readBit(this.contexts, contextLabel) ^ 1;
  17664. }
  17665. return decoded;
  17666. },
  17667. runMagnitudeRefinementPass: function BitModel_runMagnitudeRefinementPass() {
  17668. var decoder = this.decoder;
  17669. var width = this.width, height = this.height;
  17670. var coefficentsMagnitude = this.coefficentsMagnitude;
  17671. var neighborsSignificance = this.neighborsSignificance;
  17672. var contexts = this.contexts;
  17673. var bitsDecoded = this.bitsDecoded;
  17674. var processingFlags = this.processingFlags;
  17675. var processedMask = 1;
  17676. var firstMagnitudeBitMask = 2;
  17677. var length = width * height;
  17678. var width4 = width * 4;
  17679. for (var index0 = 0, indexNext; index0 < length; index0 = indexNext) {
  17680. indexNext = Math.min(length, index0 + width4);
  17681. for (var j = 0; j < width; j++) {
  17682. for (var index = index0 + j; index < indexNext; index += width) {
  17683. // significant but not those that have just become
  17684. if (!coefficentsMagnitude[index] || (processingFlags[index] & processedMask) !== 0) {
  17685. continue;
  17686. }
  17687. var contextLabel = 16;
  17688. if ((processingFlags[index] & firstMagnitudeBitMask) !== 0) {
  17689. processingFlags[index] ^= firstMagnitudeBitMask;
  17690. // first refinement
  17691. var significance = neighborsSignificance[index] & 127;
  17692. contextLabel = significance === 0 ? 15 : 14;
  17693. }
  17694. var bit = decoder.readBit(contexts, contextLabel);
  17695. coefficentsMagnitude[index] = coefficentsMagnitude[index] << 1 | bit;
  17696. bitsDecoded[index]++;
  17697. processingFlags[index] |= processedMask;
  17698. }
  17699. }
  17700. }
  17701. },
  17702. runCleanupPass: function BitModel_runCleanupPass() {
  17703. var decoder = this.decoder;
  17704. var width = this.width, height = this.height;
  17705. var neighborsSignificance = this.neighborsSignificance;
  17706. var coefficentsMagnitude = this.coefficentsMagnitude;
  17707. var coefficentsSign = this.coefficentsSign;
  17708. var contexts = this.contexts;
  17709. var labels = this.contextLabelTable;
  17710. var bitsDecoded = this.bitsDecoded;
  17711. var processingFlags = this.processingFlags;
  17712. var processedMask = 1;
  17713. var firstMagnitudeBitMask = 2;
  17714. var oneRowDown = width;
  17715. var twoRowsDown = width * 2;
  17716. var threeRowsDown = width * 3;
  17717. var iNext;
  17718. for (var i0 = 0; i0 < height; i0 = iNext) {
  17719. iNext = Math.min(i0 + 4, height);
  17720. var indexBase = i0 * width;
  17721. var checkAllEmpty = i0 + 3 < height;
  17722. for (var j = 0; j < width; j++) {
  17723. var index0 = indexBase + j;
  17724. // using the property: labels[neighborsSignificance[index]] === 0
  17725. // when neighborsSignificance[index] === 0
  17726. 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;
  17727. var i1 = 0, index = index0;
  17728. var i = i0, sign;
  17729. if (allEmpty) {
  17730. var hasSignificantCoefficent = decoder.readBit(contexts, RUNLENGTH_CONTEXT);
  17731. if (!hasSignificantCoefficent) {
  17732. bitsDecoded[index0]++;
  17733. bitsDecoded[index0 + oneRowDown]++;
  17734. bitsDecoded[index0 + twoRowsDown]++;
  17735. bitsDecoded[index0 + threeRowsDown]++;
  17736. continue;
  17737. }
  17738. // next column
  17739. i1 = decoder.readBit(contexts, UNIFORM_CONTEXT) << 1 | decoder.readBit(contexts, UNIFORM_CONTEXT);
  17740. if (i1 !== 0) {
  17741. i = i0 + i1;
  17742. index += i1 * width;
  17743. }
  17744. sign = this.decodeSignBit(i, j, index);
  17745. coefficentsSign[index] = sign;
  17746. coefficentsMagnitude[index] = 1;
  17747. this.setNeighborsSignificance(i, j, index);
  17748. processingFlags[index] |= firstMagnitudeBitMask;
  17749. index = index0;
  17750. for (var i2 = i0; i2 <= i; i2++, index += width) {
  17751. bitsDecoded[index]++;
  17752. }
  17753. i1++;
  17754. }
  17755. for (i = i0 + i1; i < iNext; i++, index += width) {
  17756. if (coefficentsMagnitude[index] || (processingFlags[index] & processedMask) !== 0) {
  17757. continue;
  17758. }
  17759. var contextLabel = labels[neighborsSignificance[index]];
  17760. var decision = decoder.readBit(contexts, contextLabel);
  17761. if (decision === 1) {
  17762. sign = this.decodeSignBit(i, j, index);
  17763. coefficentsSign[index] = sign;
  17764. coefficentsMagnitude[index] = 1;
  17765. this.setNeighborsSignificance(i, j, index);
  17766. processingFlags[index] |= firstMagnitudeBitMask;
  17767. }
  17768. bitsDecoded[index]++;
  17769. }
  17770. }
  17771. }
  17772. },
  17773. checkSegmentationSymbol: function BitModel_checkSegmentationSymbol() {
  17774. var decoder = this.decoder;
  17775. var contexts = this.contexts;
  17776. 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);
  17777. if (symbol !== 0xA) {
  17778. error('JPX Error: Invalid segmentation symbol');
  17779. }
  17780. }
  17781. };
  17782. return BitModel;
  17783. }();
  17784. // Section F, Discrete wavelet transformation
  17785. var Transform = function TransformClosure() {
  17786. function Transform() {
  17787. }
  17788. Transform.prototype.calculate = function transformCalculate(subbands, u0, v0) {
  17789. var ll = subbands[0];
  17790. for (var i = 1, ii = subbands.length; i < ii; i++) {
  17791. ll = this.iterate(ll, subbands[i], u0, v0);
  17792. }
  17793. return ll;
  17794. };
  17795. Transform.prototype.extend = function extend(buffer, offset, size) {
  17796. // Section F.3.7 extending... using max extension of 4
  17797. var i1 = offset - 1, j1 = offset + 1;
  17798. var i2 = offset + size - 2, j2 = offset + size;
  17799. buffer[i1--] = buffer[j1++];
  17800. buffer[j2++] = buffer[i2--];
  17801. buffer[i1--] = buffer[j1++];
  17802. buffer[j2++] = buffer[i2--];
  17803. buffer[i1--] = buffer[j1++];
  17804. buffer[j2++] = buffer[i2--];
  17805. buffer[i1] = buffer[j1];
  17806. buffer[j2] = buffer[i2];
  17807. };
  17808. Transform.prototype.iterate = function Transform_iterate(ll, hl_lh_hh, u0, v0) {
  17809. var llWidth = ll.width, llHeight = ll.height, llItems = ll.items;
  17810. var width = hl_lh_hh.width;
  17811. var height = hl_lh_hh.height;
  17812. var items = hl_lh_hh.items;
  17813. var i, j, k, l, u, v;
  17814. // Interleave LL according to Section F.3.3
  17815. for (k = 0, i = 0; i < llHeight; i++) {
  17816. l = i * 2 * width;
  17817. for (j = 0; j < llWidth; j++, k++, l += 2) {
  17818. items[l] = llItems[k];
  17819. }
  17820. }
  17821. // The LL band is not needed anymore.
  17822. llItems = ll.items = null;
  17823. var bufferPadding = 4;
  17824. var rowBuffer = new Float32Array(width + 2 * bufferPadding);
  17825. // Section F.3.4 HOR_SR
  17826. if (width === 1) {
  17827. // if width = 1, when u0 even keep items as is, when odd divide by 2
  17828. if ((u0 & 1) !== 0) {
  17829. for (v = 0, k = 0; v < height; v++, k += width) {
  17830. items[k] *= 0.5;
  17831. }
  17832. }
  17833. } else {
  17834. for (v = 0, k = 0; v < height; v++, k += width) {
  17835. rowBuffer.set(items.subarray(k, k + width), bufferPadding);
  17836. this.extend(rowBuffer, bufferPadding, width);
  17837. this.filter(rowBuffer, bufferPadding, width);
  17838. items.set(rowBuffer.subarray(bufferPadding, bufferPadding + width), k);
  17839. }
  17840. }
  17841. // Accesses to the items array can take long, because it may not fit into
  17842. // CPU cache and has to be fetched from main memory. Since subsequent
  17843. // accesses to the items array are not local when reading columns, we
  17844. // have a cache miss every time. To reduce cache misses, get up to
  17845. // 'numBuffers' items at a time and store them into the individual
  17846. // buffers. The colBuffers should be small enough to fit into CPU cache.
  17847. var numBuffers = 16;
  17848. var colBuffers = [];
  17849. for (i = 0; i < numBuffers; i++) {
  17850. colBuffers.push(new Float32Array(height + 2 * bufferPadding));
  17851. }
  17852. var b, currentBuffer = 0;
  17853. ll = bufferPadding + height;
  17854. // Section F.3.5 VER_SR
  17855. if (height === 1) {
  17856. // if height = 1, when v0 even keep items as is, when odd divide by 2
  17857. if ((v0 & 1) !== 0) {
  17858. for (u = 0; u < width; u++) {
  17859. items[u] *= 0.5;
  17860. }
  17861. }
  17862. } else {
  17863. for (u = 0; u < width; u++) {
  17864. // if we ran out of buffers, copy several image columns at once
  17865. if (currentBuffer === 0) {
  17866. numBuffers = Math.min(width - u, numBuffers);
  17867. for (k = u, l = bufferPadding; l < ll; k += width, l++) {
  17868. for (b = 0; b < numBuffers; b++) {
  17869. colBuffers[b][l] = items[k + b];
  17870. }
  17871. }
  17872. currentBuffer = numBuffers;
  17873. }
  17874. currentBuffer--;
  17875. var buffer = colBuffers[currentBuffer];
  17876. this.extend(buffer, bufferPadding, height);
  17877. this.filter(buffer, bufferPadding, height);
  17878. // If this is last buffer in this group of buffers, flush all buffers.
  17879. if (currentBuffer === 0) {
  17880. k = u - numBuffers + 1;
  17881. for (l = bufferPadding; l < ll; k += width, l++) {
  17882. for (b = 0; b < numBuffers; b++) {
  17883. items[k + b] = colBuffers[b][l];
  17884. }
  17885. }
  17886. }
  17887. }
  17888. }
  17889. return {
  17890. width: width,
  17891. height: height,
  17892. items: items
  17893. };
  17894. };
  17895. return Transform;
  17896. }();
  17897. // Section 3.8.2 Irreversible 9-7 filter
  17898. var IrreversibleTransform = function IrreversibleTransformClosure() {
  17899. function IrreversibleTransform() {
  17900. Transform.call(this);
  17901. }
  17902. IrreversibleTransform.prototype = Object.create(Transform.prototype);
  17903. IrreversibleTransform.prototype.filter = function irreversibleTransformFilter(x, offset, length) {
  17904. var len = length >> 1;
  17905. offset = offset | 0;
  17906. var j, n, current, next;
  17907. var alpha = -1.586134342059924;
  17908. var beta = -0.052980118572961;
  17909. var gamma = 0.882911075530934;
  17910. var delta = 0.443506852043971;
  17911. var K = 1.230174104914001;
  17912. var K_ = 1 / K;
  17913. // step 1 is combined with step 3
  17914. // step 2
  17915. j = offset - 3;
  17916. for (n = len + 4; n--; j += 2) {
  17917. x[j] *= K_;
  17918. }
  17919. // step 1 & 3
  17920. j = offset - 2;
  17921. current = delta * x[j - 1];
  17922. for (n = len + 3; n--; j += 2) {
  17923. next = delta * x[j + 1];
  17924. x[j] = K * x[j] - current - next;
  17925. if (n--) {
  17926. j += 2;
  17927. current = delta * x[j + 1];
  17928. x[j] = K * x[j] - current - next;
  17929. } else {
  17930. break;
  17931. }
  17932. }
  17933. // step 4
  17934. j = offset - 1;
  17935. current = gamma * x[j - 1];
  17936. for (n = len + 2; n--; j += 2) {
  17937. next = gamma * x[j + 1];
  17938. x[j] -= current + next;
  17939. if (n--) {
  17940. j += 2;
  17941. current = gamma * x[j + 1];
  17942. x[j] -= current + next;
  17943. } else {
  17944. break;
  17945. }
  17946. }
  17947. // step 5
  17948. j = offset;
  17949. current = beta * x[j - 1];
  17950. for (n = len + 1; n--; j += 2) {
  17951. next = beta * x[j + 1];
  17952. x[j] -= current + next;
  17953. if (n--) {
  17954. j += 2;
  17955. current = beta * x[j + 1];
  17956. x[j] -= current + next;
  17957. } else {
  17958. break;
  17959. }
  17960. }
  17961. // step 6
  17962. if (len !== 0) {
  17963. j = offset + 1;
  17964. current = alpha * x[j - 1];
  17965. for (n = len; n--; j += 2) {
  17966. next = alpha * x[j + 1];
  17967. x[j] -= current + next;
  17968. if (n--) {
  17969. j += 2;
  17970. current = alpha * x[j + 1];
  17971. x[j] -= current + next;
  17972. } else {
  17973. break;
  17974. }
  17975. }
  17976. }
  17977. };
  17978. return IrreversibleTransform;
  17979. }();
  17980. // Section 3.8.1 Reversible 5-3 filter
  17981. var ReversibleTransform = function ReversibleTransformClosure() {
  17982. function ReversibleTransform() {
  17983. Transform.call(this);
  17984. }
  17985. ReversibleTransform.prototype = Object.create(Transform.prototype);
  17986. ReversibleTransform.prototype.filter = function reversibleTransformFilter(x, offset, length) {
  17987. var len = length >> 1;
  17988. offset = offset | 0;
  17989. var j, n;
  17990. for (j = offset, n = len + 1; n--; j += 2) {
  17991. x[j] -= x[j - 1] + x[j + 1] + 2 >> 2;
  17992. }
  17993. for (j = offset + 1, n = len; n--; j += 2) {
  17994. x[j] += x[j - 1] + x[j + 1] >> 1;
  17995. }
  17996. };
  17997. return ReversibleTransform;
  17998. }();
  17999. return JpxImage;
  18000. }();
  18001. exports.JpxImage = JpxImage;
  18002. }));
  18003. (function (root, factory) {
  18004. factory(root.pdfjsCoreMetrics = {}, root.pdfjsSharedUtil);
  18005. }(this, function (exports, sharedUtil) {
  18006. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  18007. // The Metrics object contains glyph widths (in glyph space units).
  18008. // As per PDF spec, for most fonts (Type 3 being an exception) a glyph
  18009. // space unit corresponds to 1/1000th of text space unit.
  18010. var getMetrics = getLookupTableFactory(function (t) {
  18011. t['Courier'] = 600;
  18012. t['Courier-Bold'] = 600;
  18013. t['Courier-BoldOblique'] = 600;
  18014. t['Courier-Oblique'] = 600;
  18015. t['Helvetica'] = getLookupTableFactory(function (t) {
  18016. t['space'] = 278;
  18017. t['exclam'] = 278;
  18018. t['quotedbl'] = 355;
  18019. t['numbersign'] = 556;
  18020. t['dollar'] = 556;
  18021. t['percent'] = 889;
  18022. t['ampersand'] = 667;
  18023. t['quoteright'] = 222;
  18024. t['parenleft'] = 333;
  18025. t['parenright'] = 333;
  18026. t['asterisk'] = 389;
  18027. t['plus'] = 584;
  18028. t['comma'] = 278;
  18029. t['hyphen'] = 333;
  18030. t['period'] = 278;
  18031. t['slash'] = 278;
  18032. t['zero'] = 556;
  18033. t['one'] = 556;
  18034. t['two'] = 556;
  18035. t['three'] = 556;
  18036. t['four'] = 556;
  18037. t['five'] = 556;
  18038. t['six'] = 556;
  18039. t['seven'] = 556;
  18040. t['eight'] = 556;
  18041. t['nine'] = 556;
  18042. t['colon'] = 278;
  18043. t['semicolon'] = 278;
  18044. t['less'] = 584;
  18045. t['equal'] = 584;
  18046. t['greater'] = 584;
  18047. t['question'] = 556;
  18048. t['at'] = 1015;
  18049. t['A'] = 667;
  18050. t['B'] = 667;
  18051. t['C'] = 722;
  18052. t['D'] = 722;
  18053. t['E'] = 667;
  18054. t['F'] = 611;
  18055. t['G'] = 778;
  18056. t['H'] = 722;
  18057. t['I'] = 278;
  18058. t['J'] = 500;
  18059. t['K'] = 667;
  18060. t['L'] = 556;
  18061. t['M'] = 833;
  18062. t['N'] = 722;
  18063. t['O'] = 778;
  18064. t['P'] = 667;
  18065. t['Q'] = 778;
  18066. t['R'] = 722;
  18067. t['S'] = 667;
  18068. t['T'] = 611;
  18069. t['U'] = 722;
  18070. t['V'] = 667;
  18071. t['W'] = 944;
  18072. t['X'] = 667;
  18073. t['Y'] = 667;
  18074. t['Z'] = 611;
  18075. t['bracketleft'] = 278;
  18076. t['backslash'] = 278;
  18077. t['bracketright'] = 278;
  18078. t['asciicircum'] = 469;
  18079. t['underscore'] = 556;
  18080. t['quoteleft'] = 222;
  18081. t['a'] = 556;
  18082. t['b'] = 556;
  18083. t['c'] = 500;
  18084. t['d'] = 556;
  18085. t['e'] = 556;
  18086. t['f'] = 278;
  18087. t['g'] = 556;
  18088. t['h'] = 556;
  18089. t['i'] = 222;
  18090. t['j'] = 222;
  18091. t['k'] = 500;
  18092. t['l'] = 222;
  18093. t['m'] = 833;
  18094. t['n'] = 556;
  18095. t['o'] = 556;
  18096. t['p'] = 556;
  18097. t['q'] = 556;
  18098. t['r'] = 333;
  18099. t['s'] = 500;
  18100. t['t'] = 278;
  18101. t['u'] = 556;
  18102. t['v'] = 500;
  18103. t['w'] = 722;
  18104. t['x'] = 500;
  18105. t['y'] = 500;
  18106. t['z'] = 500;
  18107. t['braceleft'] = 334;
  18108. t['bar'] = 260;
  18109. t['braceright'] = 334;
  18110. t['asciitilde'] = 584;
  18111. t['exclamdown'] = 333;
  18112. t['cent'] = 556;
  18113. t['sterling'] = 556;
  18114. t['fraction'] = 167;
  18115. t['yen'] = 556;
  18116. t['florin'] = 556;
  18117. t['section'] = 556;
  18118. t['currency'] = 556;
  18119. t['quotesingle'] = 191;
  18120. t['quotedblleft'] = 333;
  18121. t['guillemotleft'] = 556;
  18122. t['guilsinglleft'] = 333;
  18123. t['guilsinglright'] = 333;
  18124. t['fi'] = 500;
  18125. t['fl'] = 500;
  18126. t['endash'] = 556;
  18127. t['dagger'] = 556;
  18128. t['daggerdbl'] = 556;
  18129. t['periodcentered'] = 278;
  18130. t['paragraph'] = 537;
  18131. t['bullet'] = 350;
  18132. t['quotesinglbase'] = 222;
  18133. t['quotedblbase'] = 333;
  18134. t['quotedblright'] = 333;
  18135. t['guillemotright'] = 556;
  18136. t['ellipsis'] = 1000;
  18137. t['perthousand'] = 1000;
  18138. t['questiondown'] = 611;
  18139. t['grave'] = 333;
  18140. t['acute'] = 333;
  18141. t['circumflex'] = 333;
  18142. t['tilde'] = 333;
  18143. t['macron'] = 333;
  18144. t['breve'] = 333;
  18145. t['dotaccent'] = 333;
  18146. t['dieresis'] = 333;
  18147. t['ring'] = 333;
  18148. t['cedilla'] = 333;
  18149. t['hungarumlaut'] = 333;
  18150. t['ogonek'] = 333;
  18151. t['caron'] = 333;
  18152. t['emdash'] = 1000;
  18153. t['AE'] = 1000;
  18154. t['ordfeminine'] = 370;
  18155. t['Lslash'] = 556;
  18156. t['Oslash'] = 778;
  18157. t['OE'] = 1000;
  18158. t['ordmasculine'] = 365;
  18159. t['ae'] = 889;
  18160. t['dotlessi'] = 278;
  18161. t['lslash'] = 222;
  18162. t['oslash'] = 611;
  18163. t['oe'] = 944;
  18164. t['germandbls'] = 611;
  18165. t['Idieresis'] = 278;
  18166. t['eacute'] = 556;
  18167. t['abreve'] = 556;
  18168. t['uhungarumlaut'] = 556;
  18169. t['ecaron'] = 556;
  18170. t['Ydieresis'] = 667;
  18171. t['divide'] = 584;
  18172. t['Yacute'] = 667;
  18173. t['Acircumflex'] = 667;
  18174. t['aacute'] = 556;
  18175. t['Ucircumflex'] = 722;
  18176. t['yacute'] = 500;
  18177. t['scommaaccent'] = 500;
  18178. t['ecircumflex'] = 556;
  18179. t['Uring'] = 722;
  18180. t['Udieresis'] = 722;
  18181. t['aogonek'] = 556;
  18182. t['Uacute'] = 722;
  18183. t['uogonek'] = 556;
  18184. t['Edieresis'] = 667;
  18185. t['Dcroat'] = 722;
  18186. t['commaaccent'] = 250;
  18187. t['copyright'] = 737;
  18188. t['Emacron'] = 667;
  18189. t['ccaron'] = 500;
  18190. t['aring'] = 556;
  18191. t['Ncommaaccent'] = 722;
  18192. t['lacute'] = 222;
  18193. t['agrave'] = 556;
  18194. t['Tcommaaccent'] = 611;
  18195. t['Cacute'] = 722;
  18196. t['atilde'] = 556;
  18197. t['Edotaccent'] = 667;
  18198. t['scaron'] = 500;
  18199. t['scedilla'] = 500;
  18200. t['iacute'] = 278;
  18201. t['lozenge'] = 471;
  18202. t['Rcaron'] = 722;
  18203. t['Gcommaaccent'] = 778;
  18204. t['ucircumflex'] = 556;
  18205. t['acircumflex'] = 556;
  18206. t['Amacron'] = 667;
  18207. t['rcaron'] = 333;
  18208. t['ccedilla'] = 500;
  18209. t['Zdotaccent'] = 611;
  18210. t['Thorn'] = 667;
  18211. t['Omacron'] = 778;
  18212. t['Racute'] = 722;
  18213. t['Sacute'] = 667;
  18214. t['dcaron'] = 643;
  18215. t['Umacron'] = 722;
  18216. t['uring'] = 556;
  18217. t['threesuperior'] = 333;
  18218. t['Ograve'] = 778;
  18219. t['Agrave'] = 667;
  18220. t['Abreve'] = 667;
  18221. t['multiply'] = 584;
  18222. t['uacute'] = 556;
  18223. t['Tcaron'] = 611;
  18224. t['partialdiff'] = 476;
  18225. t['ydieresis'] = 500;
  18226. t['Nacute'] = 722;
  18227. t['icircumflex'] = 278;
  18228. t['Ecircumflex'] = 667;
  18229. t['adieresis'] = 556;
  18230. t['edieresis'] = 556;
  18231. t['cacute'] = 500;
  18232. t['nacute'] = 556;
  18233. t['umacron'] = 556;
  18234. t['Ncaron'] = 722;
  18235. t['Iacute'] = 278;
  18236. t['plusminus'] = 584;
  18237. t['brokenbar'] = 260;
  18238. t['registered'] = 737;
  18239. t['Gbreve'] = 778;
  18240. t['Idotaccent'] = 278;
  18241. t['summation'] = 600;
  18242. t['Egrave'] = 667;
  18243. t['racute'] = 333;
  18244. t['omacron'] = 556;
  18245. t['Zacute'] = 611;
  18246. t['Zcaron'] = 611;
  18247. t['greaterequal'] = 549;
  18248. t['Eth'] = 722;
  18249. t['Ccedilla'] = 722;
  18250. t['lcommaaccent'] = 222;
  18251. t['tcaron'] = 317;
  18252. t['eogonek'] = 556;
  18253. t['Uogonek'] = 722;
  18254. t['Aacute'] = 667;
  18255. t['Adieresis'] = 667;
  18256. t['egrave'] = 556;
  18257. t['zacute'] = 500;
  18258. t['iogonek'] = 222;
  18259. t['Oacute'] = 778;
  18260. t['oacute'] = 556;
  18261. t['amacron'] = 556;
  18262. t['sacute'] = 500;
  18263. t['idieresis'] = 278;
  18264. t['Ocircumflex'] = 778;
  18265. t['Ugrave'] = 722;
  18266. t['Delta'] = 612;
  18267. t['thorn'] = 556;
  18268. t['twosuperior'] = 333;
  18269. t['Odieresis'] = 778;
  18270. t['mu'] = 556;
  18271. t['igrave'] = 278;
  18272. t['ohungarumlaut'] = 556;
  18273. t['Eogonek'] = 667;
  18274. t['dcroat'] = 556;
  18275. t['threequarters'] = 834;
  18276. t['Scedilla'] = 667;
  18277. t['lcaron'] = 299;
  18278. t['Kcommaaccent'] = 667;
  18279. t['Lacute'] = 556;
  18280. t['trademark'] = 1000;
  18281. t['edotaccent'] = 556;
  18282. t['Igrave'] = 278;
  18283. t['Imacron'] = 278;
  18284. t['Lcaron'] = 556;
  18285. t['onehalf'] = 834;
  18286. t['lessequal'] = 549;
  18287. t['ocircumflex'] = 556;
  18288. t['ntilde'] = 556;
  18289. t['Uhungarumlaut'] = 722;
  18290. t['Eacute'] = 667;
  18291. t['emacron'] = 556;
  18292. t['gbreve'] = 556;
  18293. t['onequarter'] = 834;
  18294. t['Scaron'] = 667;
  18295. t['Scommaaccent'] = 667;
  18296. t['Ohungarumlaut'] = 778;
  18297. t['degree'] = 400;
  18298. t['ograve'] = 556;
  18299. t['Ccaron'] = 722;
  18300. t['ugrave'] = 556;
  18301. t['radical'] = 453;
  18302. t['Dcaron'] = 722;
  18303. t['rcommaaccent'] = 333;
  18304. t['Ntilde'] = 722;
  18305. t['otilde'] = 556;
  18306. t['Rcommaaccent'] = 722;
  18307. t['Lcommaaccent'] = 556;
  18308. t['Atilde'] = 667;
  18309. t['Aogonek'] = 667;
  18310. t['Aring'] = 667;
  18311. t['Otilde'] = 778;
  18312. t['zdotaccent'] = 500;
  18313. t['Ecaron'] = 667;
  18314. t['Iogonek'] = 278;
  18315. t['kcommaaccent'] = 500;
  18316. t['minus'] = 584;
  18317. t['Icircumflex'] = 278;
  18318. t['ncaron'] = 556;
  18319. t['tcommaaccent'] = 278;
  18320. t['logicalnot'] = 584;
  18321. t['odieresis'] = 556;
  18322. t['udieresis'] = 556;
  18323. t['notequal'] = 549;
  18324. t['gcommaaccent'] = 556;
  18325. t['eth'] = 556;
  18326. t['zcaron'] = 500;
  18327. t['ncommaaccent'] = 556;
  18328. t['onesuperior'] = 333;
  18329. t['imacron'] = 278;
  18330. t['Euro'] = 556;
  18331. });
  18332. t['Helvetica-Bold'] = getLookupTableFactory(function (t) {
  18333. t['space'] = 278;
  18334. t['exclam'] = 333;
  18335. t['quotedbl'] = 474;
  18336. t['numbersign'] = 556;
  18337. t['dollar'] = 556;
  18338. t['percent'] = 889;
  18339. t['ampersand'] = 722;
  18340. t['quoteright'] = 278;
  18341. t['parenleft'] = 333;
  18342. t['parenright'] = 333;
  18343. t['asterisk'] = 389;
  18344. t['plus'] = 584;
  18345. t['comma'] = 278;
  18346. t['hyphen'] = 333;
  18347. t['period'] = 278;
  18348. t['slash'] = 278;
  18349. t['zero'] = 556;
  18350. t['one'] = 556;
  18351. t['two'] = 556;
  18352. t['three'] = 556;
  18353. t['four'] = 556;
  18354. t['five'] = 556;
  18355. t['six'] = 556;
  18356. t['seven'] = 556;
  18357. t['eight'] = 556;
  18358. t['nine'] = 556;
  18359. t['colon'] = 333;
  18360. t['semicolon'] = 333;
  18361. t['less'] = 584;
  18362. t['equal'] = 584;
  18363. t['greater'] = 584;
  18364. t['question'] = 611;
  18365. t['at'] = 975;
  18366. t['A'] = 722;
  18367. t['B'] = 722;
  18368. t['C'] = 722;
  18369. t['D'] = 722;
  18370. t['E'] = 667;
  18371. t['F'] = 611;
  18372. t['G'] = 778;
  18373. t['H'] = 722;
  18374. t['I'] = 278;
  18375. t['J'] = 556;
  18376. t['K'] = 722;
  18377. t['L'] = 611;
  18378. t['M'] = 833;
  18379. t['N'] = 722;
  18380. t['O'] = 778;
  18381. t['P'] = 667;
  18382. t['Q'] = 778;
  18383. t['R'] = 722;
  18384. t['S'] = 667;
  18385. t['T'] = 611;
  18386. t['U'] = 722;
  18387. t['V'] = 667;
  18388. t['W'] = 944;
  18389. t['X'] = 667;
  18390. t['Y'] = 667;
  18391. t['Z'] = 611;
  18392. t['bracketleft'] = 333;
  18393. t['backslash'] = 278;
  18394. t['bracketright'] = 333;
  18395. t['asciicircum'] = 584;
  18396. t['underscore'] = 556;
  18397. t['quoteleft'] = 278;
  18398. t['a'] = 556;
  18399. t['b'] = 611;
  18400. t['c'] = 556;
  18401. t['d'] = 611;
  18402. t['e'] = 556;
  18403. t['f'] = 333;
  18404. t['g'] = 611;
  18405. t['h'] = 611;
  18406. t['i'] = 278;
  18407. t['j'] = 278;
  18408. t['k'] = 556;
  18409. t['l'] = 278;
  18410. t['m'] = 889;
  18411. t['n'] = 611;
  18412. t['o'] = 611;
  18413. t['p'] = 611;
  18414. t['q'] = 611;
  18415. t['r'] = 389;
  18416. t['s'] = 556;
  18417. t['t'] = 333;
  18418. t['u'] = 611;
  18419. t['v'] = 556;
  18420. t['w'] = 778;
  18421. t['x'] = 556;
  18422. t['y'] = 556;
  18423. t['z'] = 500;
  18424. t['braceleft'] = 389;
  18425. t['bar'] = 280;
  18426. t['braceright'] = 389;
  18427. t['asciitilde'] = 584;
  18428. t['exclamdown'] = 333;
  18429. t['cent'] = 556;
  18430. t['sterling'] = 556;
  18431. t['fraction'] = 167;
  18432. t['yen'] = 556;
  18433. t['florin'] = 556;
  18434. t['section'] = 556;
  18435. t['currency'] = 556;
  18436. t['quotesingle'] = 238;
  18437. t['quotedblleft'] = 500;
  18438. t['guillemotleft'] = 556;
  18439. t['guilsinglleft'] = 333;
  18440. t['guilsinglright'] = 333;
  18441. t['fi'] = 611;
  18442. t['fl'] = 611;
  18443. t['endash'] = 556;
  18444. t['dagger'] = 556;
  18445. t['daggerdbl'] = 556;
  18446. t['periodcentered'] = 278;
  18447. t['paragraph'] = 556;
  18448. t['bullet'] = 350;
  18449. t['quotesinglbase'] = 278;
  18450. t['quotedblbase'] = 500;
  18451. t['quotedblright'] = 500;
  18452. t['guillemotright'] = 556;
  18453. t['ellipsis'] = 1000;
  18454. t['perthousand'] = 1000;
  18455. t['questiondown'] = 611;
  18456. t['grave'] = 333;
  18457. t['acute'] = 333;
  18458. t['circumflex'] = 333;
  18459. t['tilde'] = 333;
  18460. t['macron'] = 333;
  18461. t['breve'] = 333;
  18462. t['dotaccent'] = 333;
  18463. t['dieresis'] = 333;
  18464. t['ring'] = 333;
  18465. t['cedilla'] = 333;
  18466. t['hungarumlaut'] = 333;
  18467. t['ogonek'] = 333;
  18468. t['caron'] = 333;
  18469. t['emdash'] = 1000;
  18470. t['AE'] = 1000;
  18471. t['ordfeminine'] = 370;
  18472. t['Lslash'] = 611;
  18473. t['Oslash'] = 778;
  18474. t['OE'] = 1000;
  18475. t['ordmasculine'] = 365;
  18476. t['ae'] = 889;
  18477. t['dotlessi'] = 278;
  18478. t['lslash'] = 278;
  18479. t['oslash'] = 611;
  18480. t['oe'] = 944;
  18481. t['germandbls'] = 611;
  18482. t['Idieresis'] = 278;
  18483. t['eacute'] = 556;
  18484. t['abreve'] = 556;
  18485. t['uhungarumlaut'] = 611;
  18486. t['ecaron'] = 556;
  18487. t['Ydieresis'] = 667;
  18488. t['divide'] = 584;
  18489. t['Yacute'] = 667;
  18490. t['Acircumflex'] = 722;
  18491. t['aacute'] = 556;
  18492. t['Ucircumflex'] = 722;
  18493. t['yacute'] = 556;
  18494. t['scommaaccent'] = 556;
  18495. t['ecircumflex'] = 556;
  18496. t['Uring'] = 722;
  18497. t['Udieresis'] = 722;
  18498. t['aogonek'] = 556;
  18499. t['Uacute'] = 722;
  18500. t['uogonek'] = 611;
  18501. t['Edieresis'] = 667;
  18502. t['Dcroat'] = 722;
  18503. t['commaaccent'] = 250;
  18504. t['copyright'] = 737;
  18505. t['Emacron'] = 667;
  18506. t['ccaron'] = 556;
  18507. t['aring'] = 556;
  18508. t['Ncommaaccent'] = 722;
  18509. t['lacute'] = 278;
  18510. t['agrave'] = 556;
  18511. t['Tcommaaccent'] = 611;
  18512. t['Cacute'] = 722;
  18513. t['atilde'] = 556;
  18514. t['Edotaccent'] = 667;
  18515. t['scaron'] = 556;
  18516. t['scedilla'] = 556;
  18517. t['iacute'] = 278;
  18518. t['lozenge'] = 494;
  18519. t['Rcaron'] = 722;
  18520. t['Gcommaaccent'] = 778;
  18521. t['ucircumflex'] = 611;
  18522. t['acircumflex'] = 556;
  18523. t['Amacron'] = 722;
  18524. t['rcaron'] = 389;
  18525. t['ccedilla'] = 556;
  18526. t['Zdotaccent'] = 611;
  18527. t['Thorn'] = 667;
  18528. t['Omacron'] = 778;
  18529. t['Racute'] = 722;
  18530. t['Sacute'] = 667;
  18531. t['dcaron'] = 743;
  18532. t['Umacron'] = 722;
  18533. t['uring'] = 611;
  18534. t['threesuperior'] = 333;
  18535. t['Ograve'] = 778;
  18536. t['Agrave'] = 722;
  18537. t['Abreve'] = 722;
  18538. t['multiply'] = 584;
  18539. t['uacute'] = 611;
  18540. t['Tcaron'] = 611;
  18541. t['partialdiff'] = 494;
  18542. t['ydieresis'] = 556;
  18543. t['Nacute'] = 722;
  18544. t['icircumflex'] = 278;
  18545. t['Ecircumflex'] = 667;
  18546. t['adieresis'] = 556;
  18547. t['edieresis'] = 556;
  18548. t['cacute'] = 556;
  18549. t['nacute'] = 611;
  18550. t['umacron'] = 611;
  18551. t['Ncaron'] = 722;
  18552. t['Iacute'] = 278;
  18553. t['plusminus'] = 584;
  18554. t['brokenbar'] = 280;
  18555. t['registered'] = 737;
  18556. t['Gbreve'] = 778;
  18557. t['Idotaccent'] = 278;
  18558. t['summation'] = 600;
  18559. t['Egrave'] = 667;
  18560. t['racute'] = 389;
  18561. t['omacron'] = 611;
  18562. t['Zacute'] = 611;
  18563. t['Zcaron'] = 611;
  18564. t['greaterequal'] = 549;
  18565. t['Eth'] = 722;
  18566. t['Ccedilla'] = 722;
  18567. t['lcommaaccent'] = 278;
  18568. t['tcaron'] = 389;
  18569. t['eogonek'] = 556;
  18570. t['Uogonek'] = 722;
  18571. t['Aacute'] = 722;
  18572. t['Adieresis'] = 722;
  18573. t['egrave'] = 556;
  18574. t['zacute'] = 500;
  18575. t['iogonek'] = 278;
  18576. t['Oacute'] = 778;
  18577. t['oacute'] = 611;
  18578. t['amacron'] = 556;
  18579. t['sacute'] = 556;
  18580. t['idieresis'] = 278;
  18581. t['Ocircumflex'] = 778;
  18582. t['Ugrave'] = 722;
  18583. t['Delta'] = 612;
  18584. t['thorn'] = 611;
  18585. t['twosuperior'] = 333;
  18586. t['Odieresis'] = 778;
  18587. t['mu'] = 611;
  18588. t['igrave'] = 278;
  18589. t['ohungarumlaut'] = 611;
  18590. t['Eogonek'] = 667;
  18591. t['dcroat'] = 611;
  18592. t['threequarters'] = 834;
  18593. t['Scedilla'] = 667;
  18594. t['lcaron'] = 400;
  18595. t['Kcommaaccent'] = 722;
  18596. t['Lacute'] = 611;
  18597. t['trademark'] = 1000;
  18598. t['edotaccent'] = 556;
  18599. t['Igrave'] = 278;
  18600. t['Imacron'] = 278;
  18601. t['Lcaron'] = 611;
  18602. t['onehalf'] = 834;
  18603. t['lessequal'] = 549;
  18604. t['ocircumflex'] = 611;
  18605. t['ntilde'] = 611;
  18606. t['Uhungarumlaut'] = 722;
  18607. t['Eacute'] = 667;
  18608. t['emacron'] = 556;
  18609. t['gbreve'] = 611;
  18610. t['onequarter'] = 834;
  18611. t['Scaron'] = 667;
  18612. t['Scommaaccent'] = 667;
  18613. t['Ohungarumlaut'] = 778;
  18614. t['degree'] = 400;
  18615. t['ograve'] = 611;
  18616. t['Ccaron'] = 722;
  18617. t['ugrave'] = 611;
  18618. t['radical'] = 549;
  18619. t['Dcaron'] = 722;
  18620. t['rcommaaccent'] = 389;
  18621. t['Ntilde'] = 722;
  18622. t['otilde'] = 611;
  18623. t['Rcommaaccent'] = 722;
  18624. t['Lcommaaccent'] = 611;
  18625. t['Atilde'] = 722;
  18626. t['Aogonek'] = 722;
  18627. t['Aring'] = 722;
  18628. t['Otilde'] = 778;
  18629. t['zdotaccent'] = 500;
  18630. t['Ecaron'] = 667;
  18631. t['Iogonek'] = 278;
  18632. t['kcommaaccent'] = 556;
  18633. t['minus'] = 584;
  18634. t['Icircumflex'] = 278;
  18635. t['ncaron'] = 611;
  18636. t['tcommaaccent'] = 333;
  18637. t['logicalnot'] = 584;
  18638. t['odieresis'] = 611;
  18639. t['udieresis'] = 611;
  18640. t['notequal'] = 549;
  18641. t['gcommaaccent'] = 611;
  18642. t['eth'] = 611;
  18643. t['zcaron'] = 500;
  18644. t['ncommaaccent'] = 611;
  18645. t['onesuperior'] = 333;
  18646. t['imacron'] = 278;
  18647. t['Euro'] = 556;
  18648. });
  18649. t['Helvetica-BoldOblique'] = getLookupTableFactory(function (t) {
  18650. t['space'] = 278;
  18651. t['exclam'] = 333;
  18652. t['quotedbl'] = 474;
  18653. t['numbersign'] = 556;
  18654. t['dollar'] = 556;
  18655. t['percent'] = 889;
  18656. t['ampersand'] = 722;
  18657. t['quoteright'] = 278;
  18658. t['parenleft'] = 333;
  18659. t['parenright'] = 333;
  18660. t['asterisk'] = 389;
  18661. t['plus'] = 584;
  18662. t['comma'] = 278;
  18663. t['hyphen'] = 333;
  18664. t['period'] = 278;
  18665. t['slash'] = 278;
  18666. t['zero'] = 556;
  18667. t['one'] = 556;
  18668. t['two'] = 556;
  18669. t['three'] = 556;
  18670. t['four'] = 556;
  18671. t['five'] = 556;
  18672. t['six'] = 556;
  18673. t['seven'] = 556;
  18674. t['eight'] = 556;
  18675. t['nine'] = 556;
  18676. t['colon'] = 333;
  18677. t['semicolon'] = 333;
  18678. t['less'] = 584;
  18679. t['equal'] = 584;
  18680. t['greater'] = 584;
  18681. t['question'] = 611;
  18682. t['at'] = 975;
  18683. t['A'] = 722;
  18684. t['B'] = 722;
  18685. t['C'] = 722;
  18686. t['D'] = 722;
  18687. t['E'] = 667;
  18688. t['F'] = 611;
  18689. t['G'] = 778;
  18690. t['H'] = 722;
  18691. t['I'] = 278;
  18692. t['J'] = 556;
  18693. t['K'] = 722;
  18694. t['L'] = 611;
  18695. t['M'] = 833;
  18696. t['N'] = 722;
  18697. t['O'] = 778;
  18698. t['P'] = 667;
  18699. t['Q'] = 778;
  18700. t['R'] = 722;
  18701. t['S'] = 667;
  18702. t['T'] = 611;
  18703. t['U'] = 722;
  18704. t['V'] = 667;
  18705. t['W'] = 944;
  18706. t['X'] = 667;
  18707. t['Y'] = 667;
  18708. t['Z'] = 611;
  18709. t['bracketleft'] = 333;
  18710. t['backslash'] = 278;
  18711. t['bracketright'] = 333;
  18712. t['asciicircum'] = 584;
  18713. t['underscore'] = 556;
  18714. t['quoteleft'] = 278;
  18715. t['a'] = 556;
  18716. t['b'] = 611;
  18717. t['c'] = 556;
  18718. t['d'] = 611;
  18719. t['e'] = 556;
  18720. t['f'] = 333;
  18721. t['g'] = 611;
  18722. t['h'] = 611;
  18723. t['i'] = 278;
  18724. t['j'] = 278;
  18725. t['k'] = 556;
  18726. t['l'] = 278;
  18727. t['m'] = 889;
  18728. t['n'] = 611;
  18729. t['o'] = 611;
  18730. t['p'] = 611;
  18731. t['q'] = 611;
  18732. t['r'] = 389;
  18733. t['s'] = 556;
  18734. t['t'] = 333;
  18735. t['u'] = 611;
  18736. t['v'] = 556;
  18737. t['w'] = 778;
  18738. t['x'] = 556;
  18739. t['y'] = 556;
  18740. t['z'] = 500;
  18741. t['braceleft'] = 389;
  18742. t['bar'] = 280;
  18743. t['braceright'] = 389;
  18744. t['asciitilde'] = 584;
  18745. t['exclamdown'] = 333;
  18746. t['cent'] = 556;
  18747. t['sterling'] = 556;
  18748. t['fraction'] = 167;
  18749. t['yen'] = 556;
  18750. t['florin'] = 556;
  18751. t['section'] = 556;
  18752. t['currency'] = 556;
  18753. t['quotesingle'] = 238;
  18754. t['quotedblleft'] = 500;
  18755. t['guillemotleft'] = 556;
  18756. t['guilsinglleft'] = 333;
  18757. t['guilsinglright'] = 333;
  18758. t['fi'] = 611;
  18759. t['fl'] = 611;
  18760. t['endash'] = 556;
  18761. t['dagger'] = 556;
  18762. t['daggerdbl'] = 556;
  18763. t['periodcentered'] = 278;
  18764. t['paragraph'] = 556;
  18765. t['bullet'] = 350;
  18766. t['quotesinglbase'] = 278;
  18767. t['quotedblbase'] = 500;
  18768. t['quotedblright'] = 500;
  18769. t['guillemotright'] = 556;
  18770. t['ellipsis'] = 1000;
  18771. t['perthousand'] = 1000;
  18772. t['questiondown'] = 611;
  18773. t['grave'] = 333;
  18774. t['acute'] = 333;
  18775. t['circumflex'] = 333;
  18776. t['tilde'] = 333;
  18777. t['macron'] = 333;
  18778. t['breve'] = 333;
  18779. t['dotaccent'] = 333;
  18780. t['dieresis'] = 333;
  18781. t['ring'] = 333;
  18782. t['cedilla'] = 333;
  18783. t['hungarumlaut'] = 333;
  18784. t['ogonek'] = 333;
  18785. t['caron'] = 333;
  18786. t['emdash'] = 1000;
  18787. t['AE'] = 1000;
  18788. t['ordfeminine'] = 370;
  18789. t['Lslash'] = 611;
  18790. t['Oslash'] = 778;
  18791. t['OE'] = 1000;
  18792. t['ordmasculine'] = 365;
  18793. t['ae'] = 889;
  18794. t['dotlessi'] = 278;
  18795. t['lslash'] = 278;
  18796. t['oslash'] = 611;
  18797. t['oe'] = 944;
  18798. t['germandbls'] = 611;
  18799. t['Idieresis'] = 278;
  18800. t['eacute'] = 556;
  18801. t['abreve'] = 556;
  18802. t['uhungarumlaut'] = 611;
  18803. t['ecaron'] = 556;
  18804. t['Ydieresis'] = 667;
  18805. t['divide'] = 584;
  18806. t['Yacute'] = 667;
  18807. t['Acircumflex'] = 722;
  18808. t['aacute'] = 556;
  18809. t['Ucircumflex'] = 722;
  18810. t['yacute'] = 556;
  18811. t['scommaaccent'] = 556;
  18812. t['ecircumflex'] = 556;
  18813. t['Uring'] = 722;
  18814. t['Udieresis'] = 722;
  18815. t['aogonek'] = 556;
  18816. t['Uacute'] = 722;
  18817. t['uogonek'] = 611;
  18818. t['Edieresis'] = 667;
  18819. t['Dcroat'] = 722;
  18820. t['commaaccent'] = 250;
  18821. t['copyright'] = 737;
  18822. t['Emacron'] = 667;
  18823. t['ccaron'] = 556;
  18824. t['aring'] = 556;
  18825. t['Ncommaaccent'] = 722;
  18826. t['lacute'] = 278;
  18827. t['agrave'] = 556;
  18828. t['Tcommaaccent'] = 611;
  18829. t['Cacute'] = 722;
  18830. t['atilde'] = 556;
  18831. t['Edotaccent'] = 667;
  18832. t['scaron'] = 556;
  18833. t['scedilla'] = 556;
  18834. t['iacute'] = 278;
  18835. t['lozenge'] = 494;
  18836. t['Rcaron'] = 722;
  18837. t['Gcommaaccent'] = 778;
  18838. t['ucircumflex'] = 611;
  18839. t['acircumflex'] = 556;
  18840. t['Amacron'] = 722;
  18841. t['rcaron'] = 389;
  18842. t['ccedilla'] = 556;
  18843. t['Zdotaccent'] = 611;
  18844. t['Thorn'] = 667;
  18845. t['Omacron'] = 778;
  18846. t['Racute'] = 722;
  18847. t['Sacute'] = 667;
  18848. t['dcaron'] = 743;
  18849. t['Umacron'] = 722;
  18850. t['uring'] = 611;
  18851. t['threesuperior'] = 333;
  18852. t['Ograve'] = 778;
  18853. t['Agrave'] = 722;
  18854. t['Abreve'] = 722;
  18855. t['multiply'] = 584;
  18856. t['uacute'] = 611;
  18857. t['Tcaron'] = 611;
  18858. t['partialdiff'] = 494;
  18859. t['ydieresis'] = 556;
  18860. t['Nacute'] = 722;
  18861. t['icircumflex'] = 278;
  18862. t['Ecircumflex'] = 667;
  18863. t['adieresis'] = 556;
  18864. t['edieresis'] = 556;
  18865. t['cacute'] = 556;
  18866. t['nacute'] = 611;
  18867. t['umacron'] = 611;
  18868. t['Ncaron'] = 722;
  18869. t['Iacute'] = 278;
  18870. t['plusminus'] = 584;
  18871. t['brokenbar'] = 280;
  18872. t['registered'] = 737;
  18873. t['Gbreve'] = 778;
  18874. t['Idotaccent'] = 278;
  18875. t['summation'] = 600;
  18876. t['Egrave'] = 667;
  18877. t['racute'] = 389;
  18878. t['omacron'] = 611;
  18879. t['Zacute'] = 611;
  18880. t['Zcaron'] = 611;
  18881. t['greaterequal'] = 549;
  18882. t['Eth'] = 722;
  18883. t['Ccedilla'] = 722;
  18884. t['lcommaaccent'] = 278;
  18885. t['tcaron'] = 389;
  18886. t['eogonek'] = 556;
  18887. t['Uogonek'] = 722;
  18888. t['Aacute'] = 722;
  18889. t['Adieresis'] = 722;
  18890. t['egrave'] = 556;
  18891. t['zacute'] = 500;
  18892. t['iogonek'] = 278;
  18893. t['Oacute'] = 778;
  18894. t['oacute'] = 611;
  18895. t['amacron'] = 556;
  18896. t['sacute'] = 556;
  18897. t['idieresis'] = 278;
  18898. t['Ocircumflex'] = 778;
  18899. t['Ugrave'] = 722;
  18900. t['Delta'] = 612;
  18901. t['thorn'] = 611;
  18902. t['twosuperior'] = 333;
  18903. t['Odieresis'] = 778;
  18904. t['mu'] = 611;
  18905. t['igrave'] = 278;
  18906. t['ohungarumlaut'] = 611;
  18907. t['Eogonek'] = 667;
  18908. t['dcroat'] = 611;
  18909. t['threequarters'] = 834;
  18910. t['Scedilla'] = 667;
  18911. t['lcaron'] = 400;
  18912. t['Kcommaaccent'] = 722;
  18913. t['Lacute'] = 611;
  18914. t['trademark'] = 1000;
  18915. t['edotaccent'] = 556;
  18916. t['Igrave'] = 278;
  18917. t['Imacron'] = 278;
  18918. t['Lcaron'] = 611;
  18919. t['onehalf'] = 834;
  18920. t['lessequal'] = 549;
  18921. t['ocircumflex'] = 611;
  18922. t['ntilde'] = 611;
  18923. t['Uhungarumlaut'] = 722;
  18924. t['Eacute'] = 667;
  18925. t['emacron'] = 556;
  18926. t['gbreve'] = 611;
  18927. t['onequarter'] = 834;
  18928. t['Scaron'] = 667;
  18929. t['Scommaaccent'] = 667;
  18930. t['Ohungarumlaut'] = 778;
  18931. t['degree'] = 400;
  18932. t['ograve'] = 611;
  18933. t['Ccaron'] = 722;
  18934. t['ugrave'] = 611;
  18935. t['radical'] = 549;
  18936. t['Dcaron'] = 722;
  18937. t['rcommaaccent'] = 389;
  18938. t['Ntilde'] = 722;
  18939. t['otilde'] = 611;
  18940. t['Rcommaaccent'] = 722;
  18941. t['Lcommaaccent'] = 611;
  18942. t['Atilde'] = 722;
  18943. t['Aogonek'] = 722;
  18944. t['Aring'] = 722;
  18945. t['Otilde'] = 778;
  18946. t['zdotaccent'] = 500;
  18947. t['Ecaron'] = 667;
  18948. t['Iogonek'] = 278;
  18949. t['kcommaaccent'] = 556;
  18950. t['minus'] = 584;
  18951. t['Icircumflex'] = 278;
  18952. t['ncaron'] = 611;
  18953. t['tcommaaccent'] = 333;
  18954. t['logicalnot'] = 584;
  18955. t['odieresis'] = 611;
  18956. t['udieresis'] = 611;
  18957. t['notequal'] = 549;
  18958. t['gcommaaccent'] = 611;
  18959. t['eth'] = 611;
  18960. t['zcaron'] = 500;
  18961. t['ncommaaccent'] = 611;
  18962. t['onesuperior'] = 333;
  18963. t['imacron'] = 278;
  18964. t['Euro'] = 556;
  18965. });
  18966. t['Helvetica-Oblique'] = getLookupTableFactory(function (t) {
  18967. t['space'] = 278;
  18968. t['exclam'] = 278;
  18969. t['quotedbl'] = 355;
  18970. t['numbersign'] = 556;
  18971. t['dollar'] = 556;
  18972. t['percent'] = 889;
  18973. t['ampersand'] = 667;
  18974. t['quoteright'] = 222;
  18975. t['parenleft'] = 333;
  18976. t['parenright'] = 333;
  18977. t['asterisk'] = 389;
  18978. t['plus'] = 584;
  18979. t['comma'] = 278;
  18980. t['hyphen'] = 333;
  18981. t['period'] = 278;
  18982. t['slash'] = 278;
  18983. t['zero'] = 556;
  18984. t['one'] = 556;
  18985. t['two'] = 556;
  18986. t['three'] = 556;
  18987. t['four'] = 556;
  18988. t['five'] = 556;
  18989. t['six'] = 556;
  18990. t['seven'] = 556;
  18991. t['eight'] = 556;
  18992. t['nine'] = 556;
  18993. t['colon'] = 278;
  18994. t['semicolon'] = 278;
  18995. t['less'] = 584;
  18996. t['equal'] = 584;
  18997. t['greater'] = 584;
  18998. t['question'] = 556;
  18999. t['at'] = 1015;
  19000. t['A'] = 667;
  19001. t['B'] = 667;
  19002. t['C'] = 722;
  19003. t['D'] = 722;
  19004. t['E'] = 667;
  19005. t['F'] = 611;
  19006. t['G'] = 778;
  19007. t['H'] = 722;
  19008. t['I'] = 278;
  19009. t['J'] = 500;
  19010. t['K'] = 667;
  19011. t['L'] = 556;
  19012. t['M'] = 833;
  19013. t['N'] = 722;
  19014. t['O'] = 778;
  19015. t['P'] = 667;
  19016. t['Q'] = 778;
  19017. t['R'] = 722;
  19018. t['S'] = 667;
  19019. t['T'] = 611;
  19020. t['U'] = 722;
  19021. t['V'] = 667;
  19022. t['W'] = 944;
  19023. t['X'] = 667;
  19024. t['Y'] = 667;
  19025. t['Z'] = 611;
  19026. t['bracketleft'] = 278;
  19027. t['backslash'] = 278;
  19028. t['bracketright'] = 278;
  19029. t['asciicircum'] = 469;
  19030. t['underscore'] = 556;
  19031. t['quoteleft'] = 222;
  19032. t['a'] = 556;
  19033. t['b'] = 556;
  19034. t['c'] = 500;
  19035. t['d'] = 556;
  19036. t['e'] = 556;
  19037. t['f'] = 278;
  19038. t['g'] = 556;
  19039. t['h'] = 556;
  19040. t['i'] = 222;
  19041. t['j'] = 222;
  19042. t['k'] = 500;
  19043. t['l'] = 222;
  19044. t['m'] = 833;
  19045. t['n'] = 556;
  19046. t['o'] = 556;
  19047. t['p'] = 556;
  19048. t['q'] = 556;
  19049. t['r'] = 333;
  19050. t['s'] = 500;
  19051. t['t'] = 278;
  19052. t['u'] = 556;
  19053. t['v'] = 500;
  19054. t['w'] = 722;
  19055. t['x'] = 500;
  19056. t['y'] = 500;
  19057. t['z'] = 500;
  19058. t['braceleft'] = 334;
  19059. t['bar'] = 260;
  19060. t['braceright'] = 334;
  19061. t['asciitilde'] = 584;
  19062. t['exclamdown'] = 333;
  19063. t['cent'] = 556;
  19064. t['sterling'] = 556;
  19065. t['fraction'] = 167;
  19066. t['yen'] = 556;
  19067. t['florin'] = 556;
  19068. t['section'] = 556;
  19069. t['currency'] = 556;
  19070. t['quotesingle'] = 191;
  19071. t['quotedblleft'] = 333;
  19072. t['guillemotleft'] = 556;
  19073. t['guilsinglleft'] = 333;
  19074. t['guilsinglright'] = 333;
  19075. t['fi'] = 500;
  19076. t['fl'] = 500;
  19077. t['endash'] = 556;
  19078. t['dagger'] = 556;
  19079. t['daggerdbl'] = 556;
  19080. t['periodcentered'] = 278;
  19081. t['paragraph'] = 537;
  19082. t['bullet'] = 350;
  19083. t['quotesinglbase'] = 222;
  19084. t['quotedblbase'] = 333;
  19085. t['quotedblright'] = 333;
  19086. t['guillemotright'] = 556;
  19087. t['ellipsis'] = 1000;
  19088. t['perthousand'] = 1000;
  19089. t['questiondown'] = 611;
  19090. t['grave'] = 333;
  19091. t['acute'] = 333;
  19092. t['circumflex'] = 333;
  19093. t['tilde'] = 333;
  19094. t['macron'] = 333;
  19095. t['breve'] = 333;
  19096. t['dotaccent'] = 333;
  19097. t['dieresis'] = 333;
  19098. t['ring'] = 333;
  19099. t['cedilla'] = 333;
  19100. t['hungarumlaut'] = 333;
  19101. t['ogonek'] = 333;
  19102. t['caron'] = 333;
  19103. t['emdash'] = 1000;
  19104. t['AE'] = 1000;
  19105. t['ordfeminine'] = 370;
  19106. t['Lslash'] = 556;
  19107. t['Oslash'] = 778;
  19108. t['OE'] = 1000;
  19109. t['ordmasculine'] = 365;
  19110. t['ae'] = 889;
  19111. t['dotlessi'] = 278;
  19112. t['lslash'] = 222;
  19113. t['oslash'] = 611;
  19114. t['oe'] = 944;
  19115. t['germandbls'] = 611;
  19116. t['Idieresis'] = 278;
  19117. t['eacute'] = 556;
  19118. t['abreve'] = 556;
  19119. t['uhungarumlaut'] = 556;
  19120. t['ecaron'] = 556;
  19121. t['Ydieresis'] = 667;
  19122. t['divide'] = 584;
  19123. t['Yacute'] = 667;
  19124. t['Acircumflex'] = 667;
  19125. t['aacute'] = 556;
  19126. t['Ucircumflex'] = 722;
  19127. t['yacute'] = 500;
  19128. t['scommaaccent'] = 500;
  19129. t['ecircumflex'] = 556;
  19130. t['Uring'] = 722;
  19131. t['Udieresis'] = 722;
  19132. t['aogonek'] = 556;
  19133. t['Uacute'] = 722;
  19134. t['uogonek'] = 556;
  19135. t['Edieresis'] = 667;
  19136. t['Dcroat'] = 722;
  19137. t['commaaccent'] = 250;
  19138. t['copyright'] = 737;
  19139. t['Emacron'] = 667;
  19140. t['ccaron'] = 500;
  19141. t['aring'] = 556;
  19142. t['Ncommaaccent'] = 722;
  19143. t['lacute'] = 222;
  19144. t['agrave'] = 556;
  19145. t['Tcommaaccent'] = 611;
  19146. t['Cacute'] = 722;
  19147. t['atilde'] = 556;
  19148. t['Edotaccent'] = 667;
  19149. t['scaron'] = 500;
  19150. t['scedilla'] = 500;
  19151. t['iacute'] = 278;
  19152. t['lozenge'] = 471;
  19153. t['Rcaron'] = 722;
  19154. t['Gcommaaccent'] = 778;
  19155. t['ucircumflex'] = 556;
  19156. t['acircumflex'] = 556;
  19157. t['Amacron'] = 667;
  19158. t['rcaron'] = 333;
  19159. t['ccedilla'] = 500;
  19160. t['Zdotaccent'] = 611;
  19161. t['Thorn'] = 667;
  19162. t['Omacron'] = 778;
  19163. t['Racute'] = 722;
  19164. t['Sacute'] = 667;
  19165. t['dcaron'] = 643;
  19166. t['Umacron'] = 722;
  19167. t['uring'] = 556;
  19168. t['threesuperior'] = 333;
  19169. t['Ograve'] = 778;
  19170. t['Agrave'] = 667;
  19171. t['Abreve'] = 667;
  19172. t['multiply'] = 584;
  19173. t['uacute'] = 556;
  19174. t['Tcaron'] = 611;
  19175. t['partialdiff'] = 476;
  19176. t['ydieresis'] = 500;
  19177. t['Nacute'] = 722;
  19178. t['icircumflex'] = 278;
  19179. t['Ecircumflex'] = 667;
  19180. t['adieresis'] = 556;
  19181. t['edieresis'] = 556;
  19182. t['cacute'] = 500;
  19183. t['nacute'] = 556;
  19184. t['umacron'] = 556;
  19185. t['Ncaron'] = 722;
  19186. t['Iacute'] = 278;
  19187. t['plusminus'] = 584;
  19188. t['brokenbar'] = 260;
  19189. t['registered'] = 737;
  19190. t['Gbreve'] = 778;
  19191. t['Idotaccent'] = 278;
  19192. t['summation'] = 600;
  19193. t['Egrave'] = 667;
  19194. t['racute'] = 333;
  19195. t['omacron'] = 556;
  19196. t['Zacute'] = 611;
  19197. t['Zcaron'] = 611;
  19198. t['greaterequal'] = 549;
  19199. t['Eth'] = 722;
  19200. t['Ccedilla'] = 722;
  19201. t['lcommaaccent'] = 222;
  19202. t['tcaron'] = 317;
  19203. t['eogonek'] = 556;
  19204. t['Uogonek'] = 722;
  19205. t['Aacute'] = 667;
  19206. t['Adieresis'] = 667;
  19207. t['egrave'] = 556;
  19208. t['zacute'] = 500;
  19209. t['iogonek'] = 222;
  19210. t['Oacute'] = 778;
  19211. t['oacute'] = 556;
  19212. t['amacron'] = 556;
  19213. t['sacute'] = 500;
  19214. t['idieresis'] = 278;
  19215. t['Ocircumflex'] = 778;
  19216. t['Ugrave'] = 722;
  19217. t['Delta'] = 612;
  19218. t['thorn'] = 556;
  19219. t['twosuperior'] = 333;
  19220. t['Odieresis'] = 778;
  19221. t['mu'] = 556;
  19222. t['igrave'] = 278;
  19223. t['ohungarumlaut'] = 556;
  19224. t['Eogonek'] = 667;
  19225. t['dcroat'] = 556;
  19226. t['threequarters'] = 834;
  19227. t['Scedilla'] = 667;
  19228. t['lcaron'] = 299;
  19229. t['Kcommaaccent'] = 667;
  19230. t['Lacute'] = 556;
  19231. t['trademark'] = 1000;
  19232. t['edotaccent'] = 556;
  19233. t['Igrave'] = 278;
  19234. t['Imacron'] = 278;
  19235. t['Lcaron'] = 556;
  19236. t['onehalf'] = 834;
  19237. t['lessequal'] = 549;
  19238. t['ocircumflex'] = 556;
  19239. t['ntilde'] = 556;
  19240. t['Uhungarumlaut'] = 722;
  19241. t['Eacute'] = 667;
  19242. t['emacron'] = 556;
  19243. t['gbreve'] = 556;
  19244. t['onequarter'] = 834;
  19245. t['Scaron'] = 667;
  19246. t['Scommaaccent'] = 667;
  19247. t['Ohungarumlaut'] = 778;
  19248. t['degree'] = 400;
  19249. t['ograve'] = 556;
  19250. t['Ccaron'] = 722;
  19251. t['ugrave'] = 556;
  19252. t['radical'] = 453;
  19253. t['Dcaron'] = 722;
  19254. t['rcommaaccent'] = 333;
  19255. t['Ntilde'] = 722;
  19256. t['otilde'] = 556;
  19257. t['Rcommaaccent'] = 722;
  19258. t['Lcommaaccent'] = 556;
  19259. t['Atilde'] = 667;
  19260. t['Aogonek'] = 667;
  19261. t['Aring'] = 667;
  19262. t['Otilde'] = 778;
  19263. t['zdotaccent'] = 500;
  19264. t['Ecaron'] = 667;
  19265. t['Iogonek'] = 278;
  19266. t['kcommaaccent'] = 500;
  19267. t['minus'] = 584;
  19268. t['Icircumflex'] = 278;
  19269. t['ncaron'] = 556;
  19270. t['tcommaaccent'] = 278;
  19271. t['logicalnot'] = 584;
  19272. t['odieresis'] = 556;
  19273. t['udieresis'] = 556;
  19274. t['notequal'] = 549;
  19275. t['gcommaaccent'] = 556;
  19276. t['eth'] = 556;
  19277. t['zcaron'] = 500;
  19278. t['ncommaaccent'] = 556;
  19279. t['onesuperior'] = 333;
  19280. t['imacron'] = 278;
  19281. t['Euro'] = 556;
  19282. });
  19283. t['Symbol'] = getLookupTableFactory(function (t) {
  19284. t['space'] = 250;
  19285. t['exclam'] = 333;
  19286. t['universal'] = 713;
  19287. t['numbersign'] = 500;
  19288. t['existential'] = 549;
  19289. t['percent'] = 833;
  19290. t['ampersand'] = 778;
  19291. t['suchthat'] = 439;
  19292. t['parenleft'] = 333;
  19293. t['parenright'] = 333;
  19294. t['asteriskmath'] = 500;
  19295. t['plus'] = 549;
  19296. t['comma'] = 250;
  19297. t['minus'] = 549;
  19298. t['period'] = 250;
  19299. t['slash'] = 278;
  19300. t['zero'] = 500;
  19301. t['one'] = 500;
  19302. t['two'] = 500;
  19303. t['three'] = 500;
  19304. t['four'] = 500;
  19305. t['five'] = 500;
  19306. t['six'] = 500;
  19307. t['seven'] = 500;
  19308. t['eight'] = 500;
  19309. t['nine'] = 500;
  19310. t['colon'] = 278;
  19311. t['semicolon'] = 278;
  19312. t['less'] = 549;
  19313. t['equal'] = 549;
  19314. t['greater'] = 549;
  19315. t['question'] = 444;
  19316. t['congruent'] = 549;
  19317. t['Alpha'] = 722;
  19318. t['Beta'] = 667;
  19319. t['Chi'] = 722;
  19320. t['Delta'] = 612;
  19321. t['Epsilon'] = 611;
  19322. t['Phi'] = 763;
  19323. t['Gamma'] = 603;
  19324. t['Eta'] = 722;
  19325. t['Iota'] = 333;
  19326. t['theta1'] = 631;
  19327. t['Kappa'] = 722;
  19328. t['Lambda'] = 686;
  19329. t['Mu'] = 889;
  19330. t['Nu'] = 722;
  19331. t['Omicron'] = 722;
  19332. t['Pi'] = 768;
  19333. t['Theta'] = 741;
  19334. t['Rho'] = 556;
  19335. t['Sigma'] = 592;
  19336. t['Tau'] = 611;
  19337. t['Upsilon'] = 690;
  19338. t['sigma1'] = 439;
  19339. t['Omega'] = 768;
  19340. t['Xi'] = 645;
  19341. t['Psi'] = 795;
  19342. t['Zeta'] = 611;
  19343. t['bracketleft'] = 333;
  19344. t['therefore'] = 863;
  19345. t['bracketright'] = 333;
  19346. t['perpendicular'] = 658;
  19347. t['underscore'] = 500;
  19348. t['radicalex'] = 500;
  19349. t['alpha'] = 631;
  19350. t['beta'] = 549;
  19351. t['chi'] = 549;
  19352. t['delta'] = 494;
  19353. t['epsilon'] = 439;
  19354. t['phi'] = 521;
  19355. t['gamma'] = 411;
  19356. t['eta'] = 603;
  19357. t['iota'] = 329;
  19358. t['phi1'] = 603;
  19359. t['kappa'] = 549;
  19360. t['lambda'] = 549;
  19361. t['mu'] = 576;
  19362. t['nu'] = 521;
  19363. t['omicron'] = 549;
  19364. t['pi'] = 549;
  19365. t['theta'] = 521;
  19366. t['rho'] = 549;
  19367. t['sigma'] = 603;
  19368. t['tau'] = 439;
  19369. t['upsilon'] = 576;
  19370. t['omega1'] = 713;
  19371. t['omega'] = 686;
  19372. t['xi'] = 493;
  19373. t['psi'] = 686;
  19374. t['zeta'] = 494;
  19375. t['braceleft'] = 480;
  19376. t['bar'] = 200;
  19377. t['braceright'] = 480;
  19378. t['similar'] = 549;
  19379. t['Euro'] = 750;
  19380. t['Upsilon1'] = 620;
  19381. t['minute'] = 247;
  19382. t['lessequal'] = 549;
  19383. t['fraction'] = 167;
  19384. t['infinity'] = 713;
  19385. t['florin'] = 500;
  19386. t['club'] = 753;
  19387. t['diamond'] = 753;
  19388. t['heart'] = 753;
  19389. t['spade'] = 753;
  19390. t['arrowboth'] = 1042;
  19391. t['arrowleft'] = 987;
  19392. t['arrowup'] = 603;
  19393. t['arrowright'] = 987;
  19394. t['arrowdown'] = 603;
  19395. t['degree'] = 400;
  19396. t['plusminus'] = 549;
  19397. t['second'] = 411;
  19398. t['greaterequal'] = 549;
  19399. t['multiply'] = 549;
  19400. t['proportional'] = 713;
  19401. t['partialdiff'] = 494;
  19402. t['bullet'] = 460;
  19403. t['divide'] = 549;
  19404. t['notequal'] = 549;
  19405. t['equivalence'] = 549;
  19406. t['approxequal'] = 549;
  19407. t['ellipsis'] = 1000;
  19408. t['arrowvertex'] = 603;
  19409. t['arrowhorizex'] = 1000;
  19410. t['carriagereturn'] = 658;
  19411. t['aleph'] = 823;
  19412. t['Ifraktur'] = 686;
  19413. t['Rfraktur'] = 795;
  19414. t['weierstrass'] = 987;
  19415. t['circlemultiply'] = 768;
  19416. t['circleplus'] = 768;
  19417. t['emptyset'] = 823;
  19418. t['intersection'] = 768;
  19419. t['union'] = 768;
  19420. t['propersuperset'] = 713;
  19421. t['reflexsuperset'] = 713;
  19422. t['notsubset'] = 713;
  19423. t['propersubset'] = 713;
  19424. t['reflexsubset'] = 713;
  19425. t['element'] = 713;
  19426. t['notelement'] = 713;
  19427. t['angle'] = 768;
  19428. t['gradient'] = 713;
  19429. t['registerserif'] = 790;
  19430. t['copyrightserif'] = 790;
  19431. t['trademarkserif'] = 890;
  19432. t['product'] = 823;
  19433. t['radical'] = 549;
  19434. t['dotmath'] = 250;
  19435. t['logicalnot'] = 713;
  19436. t['logicaland'] = 603;
  19437. t['logicalor'] = 603;
  19438. t['arrowdblboth'] = 1042;
  19439. t['arrowdblleft'] = 987;
  19440. t['arrowdblup'] = 603;
  19441. t['arrowdblright'] = 987;
  19442. t['arrowdbldown'] = 603;
  19443. t['lozenge'] = 494;
  19444. t['angleleft'] = 329;
  19445. t['registersans'] = 790;
  19446. t['copyrightsans'] = 790;
  19447. t['trademarksans'] = 786;
  19448. t['summation'] = 713;
  19449. t['parenlefttp'] = 384;
  19450. t['parenleftex'] = 384;
  19451. t['parenleftbt'] = 384;
  19452. t['bracketlefttp'] = 384;
  19453. t['bracketleftex'] = 384;
  19454. t['bracketleftbt'] = 384;
  19455. t['bracelefttp'] = 494;
  19456. t['braceleftmid'] = 494;
  19457. t['braceleftbt'] = 494;
  19458. t['braceex'] = 494;
  19459. t['angleright'] = 329;
  19460. t['integral'] = 274;
  19461. t['integraltp'] = 686;
  19462. t['integralex'] = 686;
  19463. t['integralbt'] = 686;
  19464. t['parenrighttp'] = 384;
  19465. t['parenrightex'] = 384;
  19466. t['parenrightbt'] = 384;
  19467. t['bracketrighttp'] = 384;
  19468. t['bracketrightex'] = 384;
  19469. t['bracketrightbt'] = 384;
  19470. t['bracerighttp'] = 494;
  19471. t['bracerightmid'] = 494;
  19472. t['bracerightbt'] = 494;
  19473. t['apple'] = 790;
  19474. });
  19475. t['Times-Roman'] = getLookupTableFactory(function (t) {
  19476. t['space'] = 250;
  19477. t['exclam'] = 333;
  19478. t['quotedbl'] = 408;
  19479. t['numbersign'] = 500;
  19480. t['dollar'] = 500;
  19481. t['percent'] = 833;
  19482. t['ampersand'] = 778;
  19483. t['quoteright'] = 333;
  19484. t['parenleft'] = 333;
  19485. t['parenright'] = 333;
  19486. t['asterisk'] = 500;
  19487. t['plus'] = 564;
  19488. t['comma'] = 250;
  19489. t['hyphen'] = 333;
  19490. t['period'] = 250;
  19491. t['slash'] = 278;
  19492. t['zero'] = 500;
  19493. t['one'] = 500;
  19494. t['two'] = 500;
  19495. t['three'] = 500;
  19496. t['four'] = 500;
  19497. t['five'] = 500;
  19498. t['six'] = 500;
  19499. t['seven'] = 500;
  19500. t['eight'] = 500;
  19501. t['nine'] = 500;
  19502. t['colon'] = 278;
  19503. t['semicolon'] = 278;
  19504. t['less'] = 564;
  19505. t['equal'] = 564;
  19506. t['greater'] = 564;
  19507. t['question'] = 444;
  19508. t['at'] = 921;
  19509. t['A'] = 722;
  19510. t['B'] = 667;
  19511. t['C'] = 667;
  19512. t['D'] = 722;
  19513. t['E'] = 611;
  19514. t['F'] = 556;
  19515. t['G'] = 722;
  19516. t['H'] = 722;
  19517. t['I'] = 333;
  19518. t['J'] = 389;
  19519. t['K'] = 722;
  19520. t['L'] = 611;
  19521. t['M'] = 889;
  19522. t['N'] = 722;
  19523. t['O'] = 722;
  19524. t['P'] = 556;
  19525. t['Q'] = 722;
  19526. t['R'] = 667;
  19527. t['S'] = 556;
  19528. t['T'] = 611;
  19529. t['U'] = 722;
  19530. t['V'] = 722;
  19531. t['W'] = 944;
  19532. t['X'] = 722;
  19533. t['Y'] = 722;
  19534. t['Z'] = 611;
  19535. t['bracketleft'] = 333;
  19536. t['backslash'] = 278;
  19537. t['bracketright'] = 333;
  19538. t['asciicircum'] = 469;
  19539. t['underscore'] = 500;
  19540. t['quoteleft'] = 333;
  19541. t['a'] = 444;
  19542. t['b'] = 500;
  19543. t['c'] = 444;
  19544. t['d'] = 500;
  19545. t['e'] = 444;
  19546. t['f'] = 333;
  19547. t['g'] = 500;
  19548. t['h'] = 500;
  19549. t['i'] = 278;
  19550. t['j'] = 278;
  19551. t['k'] = 500;
  19552. t['l'] = 278;
  19553. t['m'] = 778;
  19554. t['n'] = 500;
  19555. t['o'] = 500;
  19556. t['p'] = 500;
  19557. t['q'] = 500;
  19558. t['r'] = 333;
  19559. t['s'] = 389;
  19560. t['t'] = 278;
  19561. t['u'] = 500;
  19562. t['v'] = 500;
  19563. t['w'] = 722;
  19564. t['x'] = 500;
  19565. t['y'] = 500;
  19566. t['z'] = 444;
  19567. t['braceleft'] = 480;
  19568. t['bar'] = 200;
  19569. t['braceright'] = 480;
  19570. t['asciitilde'] = 541;
  19571. t['exclamdown'] = 333;
  19572. t['cent'] = 500;
  19573. t['sterling'] = 500;
  19574. t['fraction'] = 167;
  19575. t['yen'] = 500;
  19576. t['florin'] = 500;
  19577. t['section'] = 500;
  19578. t['currency'] = 500;
  19579. t['quotesingle'] = 180;
  19580. t['quotedblleft'] = 444;
  19581. t['guillemotleft'] = 500;
  19582. t['guilsinglleft'] = 333;
  19583. t['guilsinglright'] = 333;
  19584. t['fi'] = 556;
  19585. t['fl'] = 556;
  19586. t['endash'] = 500;
  19587. t['dagger'] = 500;
  19588. t['daggerdbl'] = 500;
  19589. t['periodcentered'] = 250;
  19590. t['paragraph'] = 453;
  19591. t['bullet'] = 350;
  19592. t['quotesinglbase'] = 333;
  19593. t['quotedblbase'] = 444;
  19594. t['quotedblright'] = 444;
  19595. t['guillemotright'] = 500;
  19596. t['ellipsis'] = 1000;
  19597. t['perthousand'] = 1000;
  19598. t['questiondown'] = 444;
  19599. t['grave'] = 333;
  19600. t['acute'] = 333;
  19601. t['circumflex'] = 333;
  19602. t['tilde'] = 333;
  19603. t['macron'] = 333;
  19604. t['breve'] = 333;
  19605. t['dotaccent'] = 333;
  19606. t['dieresis'] = 333;
  19607. t['ring'] = 333;
  19608. t['cedilla'] = 333;
  19609. t['hungarumlaut'] = 333;
  19610. t['ogonek'] = 333;
  19611. t['caron'] = 333;
  19612. t['emdash'] = 1000;
  19613. t['AE'] = 889;
  19614. t['ordfeminine'] = 276;
  19615. t['Lslash'] = 611;
  19616. t['Oslash'] = 722;
  19617. t['OE'] = 889;
  19618. t['ordmasculine'] = 310;
  19619. t['ae'] = 667;
  19620. t['dotlessi'] = 278;
  19621. t['lslash'] = 278;
  19622. t['oslash'] = 500;
  19623. t['oe'] = 722;
  19624. t['germandbls'] = 500;
  19625. t['Idieresis'] = 333;
  19626. t['eacute'] = 444;
  19627. t['abreve'] = 444;
  19628. t['uhungarumlaut'] = 500;
  19629. t['ecaron'] = 444;
  19630. t['Ydieresis'] = 722;
  19631. t['divide'] = 564;
  19632. t['Yacute'] = 722;
  19633. t['Acircumflex'] = 722;
  19634. t['aacute'] = 444;
  19635. t['Ucircumflex'] = 722;
  19636. t['yacute'] = 500;
  19637. t['scommaaccent'] = 389;
  19638. t['ecircumflex'] = 444;
  19639. t['Uring'] = 722;
  19640. t['Udieresis'] = 722;
  19641. t['aogonek'] = 444;
  19642. t['Uacute'] = 722;
  19643. t['uogonek'] = 500;
  19644. t['Edieresis'] = 611;
  19645. t['Dcroat'] = 722;
  19646. t['commaaccent'] = 250;
  19647. t['copyright'] = 760;
  19648. t['Emacron'] = 611;
  19649. t['ccaron'] = 444;
  19650. t['aring'] = 444;
  19651. t['Ncommaaccent'] = 722;
  19652. t['lacute'] = 278;
  19653. t['agrave'] = 444;
  19654. t['Tcommaaccent'] = 611;
  19655. t['Cacute'] = 667;
  19656. t['atilde'] = 444;
  19657. t['Edotaccent'] = 611;
  19658. t['scaron'] = 389;
  19659. t['scedilla'] = 389;
  19660. t['iacute'] = 278;
  19661. t['lozenge'] = 471;
  19662. t['Rcaron'] = 667;
  19663. t['Gcommaaccent'] = 722;
  19664. t['ucircumflex'] = 500;
  19665. t['acircumflex'] = 444;
  19666. t['Amacron'] = 722;
  19667. t['rcaron'] = 333;
  19668. t['ccedilla'] = 444;
  19669. t['Zdotaccent'] = 611;
  19670. t['Thorn'] = 556;
  19671. t['Omacron'] = 722;
  19672. t['Racute'] = 667;
  19673. t['Sacute'] = 556;
  19674. t['dcaron'] = 588;
  19675. t['Umacron'] = 722;
  19676. t['uring'] = 500;
  19677. t['threesuperior'] = 300;
  19678. t['Ograve'] = 722;
  19679. t['Agrave'] = 722;
  19680. t['Abreve'] = 722;
  19681. t['multiply'] = 564;
  19682. t['uacute'] = 500;
  19683. t['Tcaron'] = 611;
  19684. t['partialdiff'] = 476;
  19685. t['ydieresis'] = 500;
  19686. t['Nacute'] = 722;
  19687. t['icircumflex'] = 278;
  19688. t['Ecircumflex'] = 611;
  19689. t['adieresis'] = 444;
  19690. t['edieresis'] = 444;
  19691. t['cacute'] = 444;
  19692. t['nacute'] = 500;
  19693. t['umacron'] = 500;
  19694. t['Ncaron'] = 722;
  19695. t['Iacute'] = 333;
  19696. t['plusminus'] = 564;
  19697. t['brokenbar'] = 200;
  19698. t['registered'] = 760;
  19699. t['Gbreve'] = 722;
  19700. t['Idotaccent'] = 333;
  19701. t['summation'] = 600;
  19702. t['Egrave'] = 611;
  19703. t['racute'] = 333;
  19704. t['omacron'] = 500;
  19705. t['Zacute'] = 611;
  19706. t['Zcaron'] = 611;
  19707. t['greaterequal'] = 549;
  19708. t['Eth'] = 722;
  19709. t['Ccedilla'] = 667;
  19710. t['lcommaaccent'] = 278;
  19711. t['tcaron'] = 326;
  19712. t['eogonek'] = 444;
  19713. t['Uogonek'] = 722;
  19714. t['Aacute'] = 722;
  19715. t['Adieresis'] = 722;
  19716. t['egrave'] = 444;
  19717. t['zacute'] = 444;
  19718. t['iogonek'] = 278;
  19719. t['Oacute'] = 722;
  19720. t['oacute'] = 500;
  19721. t['amacron'] = 444;
  19722. t['sacute'] = 389;
  19723. t['idieresis'] = 278;
  19724. t['Ocircumflex'] = 722;
  19725. t['Ugrave'] = 722;
  19726. t['Delta'] = 612;
  19727. t['thorn'] = 500;
  19728. t['twosuperior'] = 300;
  19729. t['Odieresis'] = 722;
  19730. t['mu'] = 500;
  19731. t['igrave'] = 278;
  19732. t['ohungarumlaut'] = 500;
  19733. t['Eogonek'] = 611;
  19734. t['dcroat'] = 500;
  19735. t['threequarters'] = 750;
  19736. t['Scedilla'] = 556;
  19737. t['lcaron'] = 344;
  19738. t['Kcommaaccent'] = 722;
  19739. t['Lacute'] = 611;
  19740. t['trademark'] = 980;
  19741. t['edotaccent'] = 444;
  19742. t['Igrave'] = 333;
  19743. t['Imacron'] = 333;
  19744. t['Lcaron'] = 611;
  19745. t['onehalf'] = 750;
  19746. t['lessequal'] = 549;
  19747. t['ocircumflex'] = 500;
  19748. t['ntilde'] = 500;
  19749. t['Uhungarumlaut'] = 722;
  19750. t['Eacute'] = 611;
  19751. t['emacron'] = 444;
  19752. t['gbreve'] = 500;
  19753. t['onequarter'] = 750;
  19754. t['Scaron'] = 556;
  19755. t['Scommaaccent'] = 556;
  19756. t['Ohungarumlaut'] = 722;
  19757. t['degree'] = 400;
  19758. t['ograve'] = 500;
  19759. t['Ccaron'] = 667;
  19760. t['ugrave'] = 500;
  19761. t['radical'] = 453;
  19762. t['Dcaron'] = 722;
  19763. t['rcommaaccent'] = 333;
  19764. t['Ntilde'] = 722;
  19765. t['otilde'] = 500;
  19766. t['Rcommaaccent'] = 667;
  19767. t['Lcommaaccent'] = 611;
  19768. t['Atilde'] = 722;
  19769. t['Aogonek'] = 722;
  19770. t['Aring'] = 722;
  19771. t['Otilde'] = 722;
  19772. t['zdotaccent'] = 444;
  19773. t['Ecaron'] = 611;
  19774. t['Iogonek'] = 333;
  19775. t['kcommaaccent'] = 500;
  19776. t['minus'] = 564;
  19777. t['Icircumflex'] = 333;
  19778. t['ncaron'] = 500;
  19779. t['tcommaaccent'] = 278;
  19780. t['logicalnot'] = 564;
  19781. t['odieresis'] = 500;
  19782. t['udieresis'] = 500;
  19783. t['notequal'] = 549;
  19784. t['gcommaaccent'] = 500;
  19785. t['eth'] = 500;
  19786. t['zcaron'] = 444;
  19787. t['ncommaaccent'] = 500;
  19788. t['onesuperior'] = 300;
  19789. t['imacron'] = 278;
  19790. t['Euro'] = 500;
  19791. });
  19792. t['Times-Bold'] = getLookupTableFactory(function (t) {
  19793. t['space'] = 250;
  19794. t['exclam'] = 333;
  19795. t['quotedbl'] = 555;
  19796. t['numbersign'] = 500;
  19797. t['dollar'] = 500;
  19798. t['percent'] = 1000;
  19799. t['ampersand'] = 833;
  19800. t['quoteright'] = 333;
  19801. t['parenleft'] = 333;
  19802. t['parenright'] = 333;
  19803. t['asterisk'] = 500;
  19804. t['plus'] = 570;
  19805. t['comma'] = 250;
  19806. t['hyphen'] = 333;
  19807. t['period'] = 250;
  19808. t['slash'] = 278;
  19809. t['zero'] = 500;
  19810. t['one'] = 500;
  19811. t['two'] = 500;
  19812. t['three'] = 500;
  19813. t['four'] = 500;
  19814. t['five'] = 500;
  19815. t['six'] = 500;
  19816. t['seven'] = 500;
  19817. t['eight'] = 500;
  19818. t['nine'] = 500;
  19819. t['colon'] = 333;
  19820. t['semicolon'] = 333;
  19821. t['less'] = 570;
  19822. t['equal'] = 570;
  19823. t['greater'] = 570;
  19824. t['question'] = 500;
  19825. t['at'] = 930;
  19826. t['A'] = 722;
  19827. t['B'] = 667;
  19828. t['C'] = 722;
  19829. t['D'] = 722;
  19830. t['E'] = 667;
  19831. t['F'] = 611;
  19832. t['G'] = 778;
  19833. t['H'] = 778;
  19834. t['I'] = 389;
  19835. t['J'] = 500;
  19836. t['K'] = 778;
  19837. t['L'] = 667;
  19838. t['M'] = 944;
  19839. t['N'] = 722;
  19840. t['O'] = 778;
  19841. t['P'] = 611;
  19842. t['Q'] = 778;
  19843. t['R'] = 722;
  19844. t['S'] = 556;
  19845. t['T'] = 667;
  19846. t['U'] = 722;
  19847. t['V'] = 722;
  19848. t['W'] = 1000;
  19849. t['X'] = 722;
  19850. t['Y'] = 722;
  19851. t['Z'] = 667;
  19852. t['bracketleft'] = 333;
  19853. t['backslash'] = 278;
  19854. t['bracketright'] = 333;
  19855. t['asciicircum'] = 581;
  19856. t['underscore'] = 500;
  19857. t['quoteleft'] = 333;
  19858. t['a'] = 500;
  19859. t['b'] = 556;
  19860. t['c'] = 444;
  19861. t['d'] = 556;
  19862. t['e'] = 444;
  19863. t['f'] = 333;
  19864. t['g'] = 500;
  19865. t['h'] = 556;
  19866. t['i'] = 278;
  19867. t['j'] = 333;
  19868. t['k'] = 556;
  19869. t['l'] = 278;
  19870. t['m'] = 833;
  19871. t['n'] = 556;
  19872. t['o'] = 500;
  19873. t['p'] = 556;
  19874. t['q'] = 556;
  19875. t['r'] = 444;
  19876. t['s'] = 389;
  19877. t['t'] = 333;
  19878. t['u'] = 556;
  19879. t['v'] = 500;
  19880. t['w'] = 722;
  19881. t['x'] = 500;
  19882. t['y'] = 500;
  19883. t['z'] = 444;
  19884. t['braceleft'] = 394;
  19885. t['bar'] = 220;
  19886. t['braceright'] = 394;
  19887. t['asciitilde'] = 520;
  19888. t['exclamdown'] = 333;
  19889. t['cent'] = 500;
  19890. t['sterling'] = 500;
  19891. t['fraction'] = 167;
  19892. t['yen'] = 500;
  19893. t['florin'] = 500;
  19894. t['section'] = 500;
  19895. t['currency'] = 500;
  19896. t['quotesingle'] = 278;
  19897. t['quotedblleft'] = 500;
  19898. t['guillemotleft'] = 500;
  19899. t['guilsinglleft'] = 333;
  19900. t['guilsinglright'] = 333;
  19901. t['fi'] = 556;
  19902. t['fl'] = 556;
  19903. t['endash'] = 500;
  19904. t['dagger'] = 500;
  19905. t['daggerdbl'] = 500;
  19906. t['periodcentered'] = 250;
  19907. t['paragraph'] = 540;
  19908. t['bullet'] = 350;
  19909. t['quotesinglbase'] = 333;
  19910. t['quotedblbase'] = 500;
  19911. t['quotedblright'] = 500;
  19912. t['guillemotright'] = 500;
  19913. t['ellipsis'] = 1000;
  19914. t['perthousand'] = 1000;
  19915. t['questiondown'] = 500;
  19916. t['grave'] = 333;
  19917. t['acute'] = 333;
  19918. t['circumflex'] = 333;
  19919. t['tilde'] = 333;
  19920. t['macron'] = 333;
  19921. t['breve'] = 333;
  19922. t['dotaccent'] = 333;
  19923. t['dieresis'] = 333;
  19924. t['ring'] = 333;
  19925. t['cedilla'] = 333;
  19926. t['hungarumlaut'] = 333;
  19927. t['ogonek'] = 333;
  19928. t['caron'] = 333;
  19929. t['emdash'] = 1000;
  19930. t['AE'] = 1000;
  19931. t['ordfeminine'] = 300;
  19932. t['Lslash'] = 667;
  19933. t['Oslash'] = 778;
  19934. t['OE'] = 1000;
  19935. t['ordmasculine'] = 330;
  19936. t['ae'] = 722;
  19937. t['dotlessi'] = 278;
  19938. t['lslash'] = 278;
  19939. t['oslash'] = 500;
  19940. t['oe'] = 722;
  19941. t['germandbls'] = 556;
  19942. t['Idieresis'] = 389;
  19943. t['eacute'] = 444;
  19944. t['abreve'] = 500;
  19945. t['uhungarumlaut'] = 556;
  19946. t['ecaron'] = 444;
  19947. t['Ydieresis'] = 722;
  19948. t['divide'] = 570;
  19949. t['Yacute'] = 722;
  19950. t['Acircumflex'] = 722;
  19951. t['aacute'] = 500;
  19952. t['Ucircumflex'] = 722;
  19953. t['yacute'] = 500;
  19954. t['scommaaccent'] = 389;
  19955. t['ecircumflex'] = 444;
  19956. t['Uring'] = 722;
  19957. t['Udieresis'] = 722;
  19958. t['aogonek'] = 500;
  19959. t['Uacute'] = 722;
  19960. t['uogonek'] = 556;
  19961. t['Edieresis'] = 667;
  19962. t['Dcroat'] = 722;
  19963. t['commaaccent'] = 250;
  19964. t['copyright'] = 747;
  19965. t['Emacron'] = 667;
  19966. t['ccaron'] = 444;
  19967. t['aring'] = 500;
  19968. t['Ncommaaccent'] = 722;
  19969. t['lacute'] = 278;
  19970. t['agrave'] = 500;
  19971. t['Tcommaaccent'] = 667;
  19972. t['Cacute'] = 722;
  19973. t['atilde'] = 500;
  19974. t['Edotaccent'] = 667;
  19975. t['scaron'] = 389;
  19976. t['scedilla'] = 389;
  19977. t['iacute'] = 278;
  19978. t['lozenge'] = 494;
  19979. t['Rcaron'] = 722;
  19980. t['Gcommaaccent'] = 778;
  19981. t['ucircumflex'] = 556;
  19982. t['acircumflex'] = 500;
  19983. t['Amacron'] = 722;
  19984. t['rcaron'] = 444;
  19985. t['ccedilla'] = 444;
  19986. t['Zdotaccent'] = 667;
  19987. t['Thorn'] = 611;
  19988. t['Omacron'] = 778;
  19989. t['Racute'] = 722;
  19990. t['Sacute'] = 556;
  19991. t['dcaron'] = 672;
  19992. t['Umacron'] = 722;
  19993. t['uring'] = 556;
  19994. t['threesuperior'] = 300;
  19995. t['Ograve'] = 778;
  19996. t['Agrave'] = 722;
  19997. t['Abreve'] = 722;
  19998. t['multiply'] = 570;
  19999. t['uacute'] = 556;
  20000. t['Tcaron'] = 667;
  20001. t['partialdiff'] = 494;
  20002. t['ydieresis'] = 500;
  20003. t['Nacute'] = 722;
  20004. t['icircumflex'] = 278;
  20005. t['Ecircumflex'] = 667;
  20006. t['adieresis'] = 500;
  20007. t['edieresis'] = 444;
  20008. t['cacute'] = 444;
  20009. t['nacute'] = 556;
  20010. t['umacron'] = 556;
  20011. t['Ncaron'] = 722;
  20012. t['Iacute'] = 389;
  20013. t['plusminus'] = 570;
  20014. t['brokenbar'] = 220;
  20015. t['registered'] = 747;
  20016. t['Gbreve'] = 778;
  20017. t['Idotaccent'] = 389;
  20018. t['summation'] = 600;
  20019. t['Egrave'] = 667;
  20020. t['racute'] = 444;
  20021. t['omacron'] = 500;
  20022. t['Zacute'] = 667;
  20023. t['Zcaron'] = 667;
  20024. t['greaterequal'] = 549;
  20025. t['Eth'] = 722;
  20026. t['Ccedilla'] = 722;
  20027. t['lcommaaccent'] = 278;
  20028. t['tcaron'] = 416;
  20029. t['eogonek'] = 444;
  20030. t['Uogonek'] = 722;
  20031. t['Aacute'] = 722;
  20032. t['Adieresis'] = 722;
  20033. t['egrave'] = 444;
  20034. t['zacute'] = 444;
  20035. t['iogonek'] = 278;
  20036. t['Oacute'] = 778;
  20037. t['oacute'] = 500;
  20038. t['amacron'] = 500;
  20039. t['sacute'] = 389;
  20040. t['idieresis'] = 278;
  20041. t['Ocircumflex'] = 778;
  20042. t['Ugrave'] = 722;
  20043. t['Delta'] = 612;
  20044. t['thorn'] = 556;
  20045. t['twosuperior'] = 300;
  20046. t['Odieresis'] = 778;
  20047. t['mu'] = 556;
  20048. t['igrave'] = 278;
  20049. t['ohungarumlaut'] = 500;
  20050. t['Eogonek'] = 667;
  20051. t['dcroat'] = 556;
  20052. t['threequarters'] = 750;
  20053. t['Scedilla'] = 556;
  20054. t['lcaron'] = 394;
  20055. t['Kcommaaccent'] = 778;
  20056. t['Lacute'] = 667;
  20057. t['trademark'] = 1000;
  20058. t['edotaccent'] = 444;
  20059. t['Igrave'] = 389;
  20060. t['Imacron'] = 389;
  20061. t['Lcaron'] = 667;
  20062. t['onehalf'] = 750;
  20063. t['lessequal'] = 549;
  20064. t['ocircumflex'] = 500;
  20065. t['ntilde'] = 556;
  20066. t['Uhungarumlaut'] = 722;
  20067. t['Eacute'] = 667;
  20068. t['emacron'] = 444;
  20069. t['gbreve'] = 500;
  20070. t['onequarter'] = 750;
  20071. t['Scaron'] = 556;
  20072. t['Scommaaccent'] = 556;
  20073. t['Ohungarumlaut'] = 778;
  20074. t['degree'] = 400;
  20075. t['ograve'] = 500;
  20076. t['Ccaron'] = 722;
  20077. t['ugrave'] = 556;
  20078. t['radical'] = 549;
  20079. t['Dcaron'] = 722;
  20080. t['rcommaaccent'] = 444;
  20081. t['Ntilde'] = 722;
  20082. t['otilde'] = 500;
  20083. t['Rcommaaccent'] = 722;
  20084. t['Lcommaaccent'] = 667;
  20085. t['Atilde'] = 722;
  20086. t['Aogonek'] = 722;
  20087. t['Aring'] = 722;
  20088. t['Otilde'] = 778;
  20089. t['zdotaccent'] = 444;
  20090. t['Ecaron'] = 667;
  20091. t['Iogonek'] = 389;
  20092. t['kcommaaccent'] = 556;
  20093. t['minus'] = 570;
  20094. t['Icircumflex'] = 389;
  20095. t['ncaron'] = 556;
  20096. t['tcommaaccent'] = 333;
  20097. t['logicalnot'] = 570;
  20098. t['odieresis'] = 500;
  20099. t['udieresis'] = 556;
  20100. t['notequal'] = 549;
  20101. t['gcommaaccent'] = 500;
  20102. t['eth'] = 500;
  20103. t['zcaron'] = 444;
  20104. t['ncommaaccent'] = 556;
  20105. t['onesuperior'] = 300;
  20106. t['imacron'] = 278;
  20107. t['Euro'] = 500;
  20108. });
  20109. t['Times-BoldItalic'] = getLookupTableFactory(function (t) {
  20110. t['space'] = 250;
  20111. t['exclam'] = 389;
  20112. t['quotedbl'] = 555;
  20113. t['numbersign'] = 500;
  20114. t['dollar'] = 500;
  20115. t['percent'] = 833;
  20116. t['ampersand'] = 778;
  20117. t['quoteright'] = 333;
  20118. t['parenleft'] = 333;
  20119. t['parenright'] = 333;
  20120. t['asterisk'] = 500;
  20121. t['plus'] = 570;
  20122. t['comma'] = 250;
  20123. t['hyphen'] = 333;
  20124. t['period'] = 250;
  20125. t['slash'] = 278;
  20126. t['zero'] = 500;
  20127. t['one'] = 500;
  20128. t['two'] = 500;
  20129. t['three'] = 500;
  20130. t['four'] = 500;
  20131. t['five'] = 500;
  20132. t['six'] = 500;
  20133. t['seven'] = 500;
  20134. t['eight'] = 500;
  20135. t['nine'] = 500;
  20136. t['colon'] = 333;
  20137. t['semicolon'] = 333;
  20138. t['less'] = 570;
  20139. t['equal'] = 570;
  20140. t['greater'] = 570;
  20141. t['question'] = 500;
  20142. t['at'] = 832;
  20143. t['A'] = 667;
  20144. t['B'] = 667;
  20145. t['C'] = 667;
  20146. t['D'] = 722;
  20147. t['E'] = 667;
  20148. t['F'] = 667;
  20149. t['G'] = 722;
  20150. t['H'] = 778;
  20151. t['I'] = 389;
  20152. t['J'] = 500;
  20153. t['K'] = 667;
  20154. t['L'] = 611;
  20155. t['M'] = 889;
  20156. t['N'] = 722;
  20157. t['O'] = 722;
  20158. t['P'] = 611;
  20159. t['Q'] = 722;
  20160. t['R'] = 667;
  20161. t['S'] = 556;
  20162. t['T'] = 611;
  20163. t['U'] = 722;
  20164. t['V'] = 667;
  20165. t['W'] = 889;
  20166. t['X'] = 667;
  20167. t['Y'] = 611;
  20168. t['Z'] = 611;
  20169. t['bracketleft'] = 333;
  20170. t['backslash'] = 278;
  20171. t['bracketright'] = 333;
  20172. t['asciicircum'] = 570;
  20173. t['underscore'] = 500;
  20174. t['quoteleft'] = 333;
  20175. t['a'] = 500;
  20176. t['b'] = 500;
  20177. t['c'] = 444;
  20178. t['d'] = 500;
  20179. t['e'] = 444;
  20180. t['f'] = 333;
  20181. t['g'] = 500;
  20182. t['h'] = 556;
  20183. t['i'] = 278;
  20184. t['j'] = 278;
  20185. t['k'] = 500;
  20186. t['l'] = 278;
  20187. t['m'] = 778;
  20188. t['n'] = 556;
  20189. t['o'] = 500;
  20190. t['p'] = 500;
  20191. t['q'] = 500;
  20192. t['r'] = 389;
  20193. t['s'] = 389;
  20194. t['t'] = 278;
  20195. t['u'] = 556;
  20196. t['v'] = 444;
  20197. t['w'] = 667;
  20198. t['x'] = 500;
  20199. t['y'] = 444;
  20200. t['z'] = 389;
  20201. t['braceleft'] = 348;
  20202. t['bar'] = 220;
  20203. t['braceright'] = 348;
  20204. t['asciitilde'] = 570;
  20205. t['exclamdown'] = 389;
  20206. t['cent'] = 500;
  20207. t['sterling'] = 500;
  20208. t['fraction'] = 167;
  20209. t['yen'] = 500;
  20210. t['florin'] = 500;
  20211. t['section'] = 500;
  20212. t['currency'] = 500;
  20213. t['quotesingle'] = 278;
  20214. t['quotedblleft'] = 500;
  20215. t['guillemotleft'] = 500;
  20216. t['guilsinglleft'] = 333;
  20217. t['guilsinglright'] = 333;
  20218. t['fi'] = 556;
  20219. t['fl'] = 556;
  20220. t['endash'] = 500;
  20221. t['dagger'] = 500;
  20222. t['daggerdbl'] = 500;
  20223. t['periodcentered'] = 250;
  20224. t['paragraph'] = 500;
  20225. t['bullet'] = 350;
  20226. t['quotesinglbase'] = 333;
  20227. t['quotedblbase'] = 500;
  20228. t['quotedblright'] = 500;
  20229. t['guillemotright'] = 500;
  20230. t['ellipsis'] = 1000;
  20231. t['perthousand'] = 1000;
  20232. t['questiondown'] = 500;
  20233. t['grave'] = 333;
  20234. t['acute'] = 333;
  20235. t['circumflex'] = 333;
  20236. t['tilde'] = 333;
  20237. t['macron'] = 333;
  20238. t['breve'] = 333;
  20239. t['dotaccent'] = 333;
  20240. t['dieresis'] = 333;
  20241. t['ring'] = 333;
  20242. t['cedilla'] = 333;
  20243. t['hungarumlaut'] = 333;
  20244. t['ogonek'] = 333;
  20245. t['caron'] = 333;
  20246. t['emdash'] = 1000;
  20247. t['AE'] = 944;
  20248. t['ordfeminine'] = 266;
  20249. t['Lslash'] = 611;
  20250. t['Oslash'] = 722;
  20251. t['OE'] = 944;
  20252. t['ordmasculine'] = 300;
  20253. t['ae'] = 722;
  20254. t['dotlessi'] = 278;
  20255. t['lslash'] = 278;
  20256. t['oslash'] = 500;
  20257. t['oe'] = 722;
  20258. t['germandbls'] = 500;
  20259. t['Idieresis'] = 389;
  20260. t['eacute'] = 444;
  20261. t['abreve'] = 500;
  20262. t['uhungarumlaut'] = 556;
  20263. t['ecaron'] = 444;
  20264. t['Ydieresis'] = 611;
  20265. t['divide'] = 570;
  20266. t['Yacute'] = 611;
  20267. t['Acircumflex'] = 667;
  20268. t['aacute'] = 500;
  20269. t['Ucircumflex'] = 722;
  20270. t['yacute'] = 444;
  20271. t['scommaaccent'] = 389;
  20272. t['ecircumflex'] = 444;
  20273. t['Uring'] = 722;
  20274. t['Udieresis'] = 722;
  20275. t['aogonek'] = 500;
  20276. t['Uacute'] = 722;
  20277. t['uogonek'] = 556;
  20278. t['Edieresis'] = 667;
  20279. t['Dcroat'] = 722;
  20280. t['commaaccent'] = 250;
  20281. t['copyright'] = 747;
  20282. t['Emacron'] = 667;
  20283. t['ccaron'] = 444;
  20284. t['aring'] = 500;
  20285. t['Ncommaaccent'] = 722;
  20286. t['lacute'] = 278;
  20287. t['agrave'] = 500;
  20288. t['Tcommaaccent'] = 611;
  20289. t['Cacute'] = 667;
  20290. t['atilde'] = 500;
  20291. t['Edotaccent'] = 667;
  20292. t['scaron'] = 389;
  20293. t['scedilla'] = 389;
  20294. t['iacute'] = 278;
  20295. t['lozenge'] = 494;
  20296. t['Rcaron'] = 667;
  20297. t['Gcommaaccent'] = 722;
  20298. t['ucircumflex'] = 556;
  20299. t['acircumflex'] = 500;
  20300. t['Amacron'] = 667;
  20301. t['rcaron'] = 389;
  20302. t['ccedilla'] = 444;
  20303. t['Zdotaccent'] = 611;
  20304. t['Thorn'] = 611;
  20305. t['Omacron'] = 722;
  20306. t['Racute'] = 667;
  20307. t['Sacute'] = 556;
  20308. t['dcaron'] = 608;
  20309. t['Umacron'] = 722;
  20310. t['uring'] = 556;
  20311. t['threesuperior'] = 300;
  20312. t['Ograve'] = 722;
  20313. t['Agrave'] = 667;
  20314. t['Abreve'] = 667;
  20315. t['multiply'] = 570;
  20316. t['uacute'] = 556;
  20317. t['Tcaron'] = 611;
  20318. t['partialdiff'] = 494;
  20319. t['ydieresis'] = 444;
  20320. t['Nacute'] = 722;
  20321. t['icircumflex'] = 278;
  20322. t['Ecircumflex'] = 667;
  20323. t['adieresis'] = 500;
  20324. t['edieresis'] = 444;
  20325. t['cacute'] = 444;
  20326. t['nacute'] = 556;
  20327. t['umacron'] = 556;
  20328. t['Ncaron'] = 722;
  20329. t['Iacute'] = 389;
  20330. t['plusminus'] = 570;
  20331. t['brokenbar'] = 220;
  20332. t['registered'] = 747;
  20333. t['Gbreve'] = 722;
  20334. t['Idotaccent'] = 389;
  20335. t['summation'] = 600;
  20336. t['Egrave'] = 667;
  20337. t['racute'] = 389;
  20338. t['omacron'] = 500;
  20339. t['Zacute'] = 611;
  20340. t['Zcaron'] = 611;
  20341. t['greaterequal'] = 549;
  20342. t['Eth'] = 722;
  20343. t['Ccedilla'] = 667;
  20344. t['lcommaaccent'] = 278;
  20345. t['tcaron'] = 366;
  20346. t['eogonek'] = 444;
  20347. t['Uogonek'] = 722;
  20348. t['Aacute'] = 667;
  20349. t['Adieresis'] = 667;
  20350. t['egrave'] = 444;
  20351. t['zacute'] = 389;
  20352. t['iogonek'] = 278;
  20353. t['Oacute'] = 722;
  20354. t['oacute'] = 500;
  20355. t['amacron'] = 500;
  20356. t['sacute'] = 389;
  20357. t['idieresis'] = 278;
  20358. t['Ocircumflex'] = 722;
  20359. t['Ugrave'] = 722;
  20360. t['Delta'] = 612;
  20361. t['thorn'] = 500;
  20362. t['twosuperior'] = 300;
  20363. t['Odieresis'] = 722;
  20364. t['mu'] = 576;
  20365. t['igrave'] = 278;
  20366. t['ohungarumlaut'] = 500;
  20367. t['Eogonek'] = 667;
  20368. t['dcroat'] = 500;
  20369. t['threequarters'] = 750;
  20370. t['Scedilla'] = 556;
  20371. t['lcaron'] = 382;
  20372. t['Kcommaaccent'] = 667;
  20373. t['Lacute'] = 611;
  20374. t['trademark'] = 1000;
  20375. t['edotaccent'] = 444;
  20376. t['Igrave'] = 389;
  20377. t['Imacron'] = 389;
  20378. t['Lcaron'] = 611;
  20379. t['onehalf'] = 750;
  20380. t['lessequal'] = 549;
  20381. t['ocircumflex'] = 500;
  20382. t['ntilde'] = 556;
  20383. t['Uhungarumlaut'] = 722;
  20384. t['Eacute'] = 667;
  20385. t['emacron'] = 444;
  20386. t['gbreve'] = 500;
  20387. t['onequarter'] = 750;
  20388. t['Scaron'] = 556;
  20389. t['Scommaaccent'] = 556;
  20390. t['Ohungarumlaut'] = 722;
  20391. t['degree'] = 400;
  20392. t['ograve'] = 500;
  20393. t['Ccaron'] = 667;
  20394. t['ugrave'] = 556;
  20395. t['radical'] = 549;
  20396. t['Dcaron'] = 722;
  20397. t['rcommaaccent'] = 389;
  20398. t['Ntilde'] = 722;
  20399. t['otilde'] = 500;
  20400. t['Rcommaaccent'] = 667;
  20401. t['Lcommaaccent'] = 611;
  20402. t['Atilde'] = 667;
  20403. t['Aogonek'] = 667;
  20404. t['Aring'] = 667;
  20405. t['Otilde'] = 722;
  20406. t['zdotaccent'] = 389;
  20407. t['Ecaron'] = 667;
  20408. t['Iogonek'] = 389;
  20409. t['kcommaaccent'] = 500;
  20410. t['minus'] = 606;
  20411. t['Icircumflex'] = 389;
  20412. t['ncaron'] = 556;
  20413. t['tcommaaccent'] = 278;
  20414. t['logicalnot'] = 606;
  20415. t['odieresis'] = 500;
  20416. t['udieresis'] = 556;
  20417. t['notequal'] = 549;
  20418. t['gcommaaccent'] = 500;
  20419. t['eth'] = 500;
  20420. t['zcaron'] = 389;
  20421. t['ncommaaccent'] = 556;
  20422. t['onesuperior'] = 300;
  20423. t['imacron'] = 278;
  20424. t['Euro'] = 500;
  20425. });
  20426. t['Times-Italic'] = getLookupTableFactory(function (t) {
  20427. t['space'] = 250;
  20428. t['exclam'] = 333;
  20429. t['quotedbl'] = 420;
  20430. t['numbersign'] = 500;
  20431. t['dollar'] = 500;
  20432. t['percent'] = 833;
  20433. t['ampersand'] = 778;
  20434. t['quoteright'] = 333;
  20435. t['parenleft'] = 333;
  20436. t['parenright'] = 333;
  20437. t['asterisk'] = 500;
  20438. t['plus'] = 675;
  20439. t['comma'] = 250;
  20440. t['hyphen'] = 333;
  20441. t['period'] = 250;
  20442. t['slash'] = 278;
  20443. t['zero'] = 500;
  20444. t['one'] = 500;
  20445. t['two'] = 500;
  20446. t['three'] = 500;
  20447. t['four'] = 500;
  20448. t['five'] = 500;
  20449. t['six'] = 500;
  20450. t['seven'] = 500;
  20451. t['eight'] = 500;
  20452. t['nine'] = 500;
  20453. t['colon'] = 333;
  20454. t['semicolon'] = 333;
  20455. t['less'] = 675;
  20456. t['equal'] = 675;
  20457. t['greater'] = 675;
  20458. t['question'] = 500;
  20459. t['at'] = 920;
  20460. t['A'] = 611;
  20461. t['B'] = 611;
  20462. t['C'] = 667;
  20463. t['D'] = 722;
  20464. t['E'] = 611;
  20465. t['F'] = 611;
  20466. t['G'] = 722;
  20467. t['H'] = 722;
  20468. t['I'] = 333;
  20469. t['J'] = 444;
  20470. t['K'] = 667;
  20471. t['L'] = 556;
  20472. t['M'] = 833;
  20473. t['N'] = 667;
  20474. t['O'] = 722;
  20475. t['P'] = 611;
  20476. t['Q'] = 722;
  20477. t['R'] = 611;
  20478. t['S'] = 500;
  20479. t['T'] = 556;
  20480. t['U'] = 722;
  20481. t['V'] = 611;
  20482. t['W'] = 833;
  20483. t['X'] = 611;
  20484. t['Y'] = 556;
  20485. t['Z'] = 556;
  20486. t['bracketleft'] = 389;
  20487. t['backslash'] = 278;
  20488. t['bracketright'] = 389;
  20489. t['asciicircum'] = 422;
  20490. t['underscore'] = 500;
  20491. t['quoteleft'] = 333;
  20492. t['a'] = 500;
  20493. t['b'] = 500;
  20494. t['c'] = 444;
  20495. t['d'] = 500;
  20496. t['e'] = 444;
  20497. t['f'] = 278;
  20498. t['g'] = 500;
  20499. t['h'] = 500;
  20500. t['i'] = 278;
  20501. t['j'] = 278;
  20502. t['k'] = 444;
  20503. t['l'] = 278;
  20504. t['m'] = 722;
  20505. t['n'] = 500;
  20506. t['o'] = 500;
  20507. t['p'] = 500;
  20508. t['q'] = 500;
  20509. t['r'] = 389;
  20510. t['s'] = 389;
  20511. t['t'] = 278;
  20512. t['u'] = 500;
  20513. t['v'] = 444;
  20514. t['w'] = 667;
  20515. t['x'] = 444;
  20516. t['y'] = 444;
  20517. t['z'] = 389;
  20518. t['braceleft'] = 400;
  20519. t['bar'] = 275;
  20520. t['braceright'] = 400;
  20521. t['asciitilde'] = 541;
  20522. t['exclamdown'] = 389;
  20523. t['cent'] = 500;
  20524. t['sterling'] = 500;
  20525. t['fraction'] = 167;
  20526. t['yen'] = 500;
  20527. t['florin'] = 500;
  20528. t['section'] = 500;
  20529. t['currency'] = 500;
  20530. t['quotesingle'] = 214;
  20531. t['quotedblleft'] = 556;
  20532. t['guillemotleft'] = 500;
  20533. t['guilsinglleft'] = 333;
  20534. t['guilsinglright'] = 333;
  20535. t['fi'] = 500;
  20536. t['fl'] = 500;
  20537. t['endash'] = 500;
  20538. t['dagger'] = 500;
  20539. t['daggerdbl'] = 500;
  20540. t['periodcentered'] = 250;
  20541. t['paragraph'] = 523;
  20542. t['bullet'] = 350;
  20543. t['quotesinglbase'] = 333;
  20544. t['quotedblbase'] = 556;
  20545. t['quotedblright'] = 556;
  20546. t['guillemotright'] = 500;
  20547. t['ellipsis'] = 889;
  20548. t['perthousand'] = 1000;
  20549. t['questiondown'] = 500;
  20550. t['grave'] = 333;
  20551. t['acute'] = 333;
  20552. t['circumflex'] = 333;
  20553. t['tilde'] = 333;
  20554. t['macron'] = 333;
  20555. t['breve'] = 333;
  20556. t['dotaccent'] = 333;
  20557. t['dieresis'] = 333;
  20558. t['ring'] = 333;
  20559. t['cedilla'] = 333;
  20560. t['hungarumlaut'] = 333;
  20561. t['ogonek'] = 333;
  20562. t['caron'] = 333;
  20563. t['emdash'] = 889;
  20564. t['AE'] = 889;
  20565. t['ordfeminine'] = 276;
  20566. t['Lslash'] = 556;
  20567. t['Oslash'] = 722;
  20568. t['OE'] = 944;
  20569. t['ordmasculine'] = 310;
  20570. t['ae'] = 667;
  20571. t['dotlessi'] = 278;
  20572. t['lslash'] = 278;
  20573. t['oslash'] = 500;
  20574. t['oe'] = 667;
  20575. t['germandbls'] = 500;
  20576. t['Idieresis'] = 333;
  20577. t['eacute'] = 444;
  20578. t['abreve'] = 500;
  20579. t['uhungarumlaut'] = 500;
  20580. t['ecaron'] = 444;
  20581. t['Ydieresis'] = 556;
  20582. t['divide'] = 675;
  20583. t['Yacute'] = 556;
  20584. t['Acircumflex'] = 611;
  20585. t['aacute'] = 500;
  20586. t['Ucircumflex'] = 722;
  20587. t['yacute'] = 444;
  20588. t['scommaaccent'] = 389;
  20589. t['ecircumflex'] = 444;
  20590. t['Uring'] = 722;
  20591. t['Udieresis'] = 722;
  20592. t['aogonek'] = 500;
  20593. t['Uacute'] = 722;
  20594. t['uogonek'] = 500;
  20595. t['Edieresis'] = 611;
  20596. t['Dcroat'] = 722;
  20597. t['commaaccent'] = 250;
  20598. t['copyright'] = 760;
  20599. t['Emacron'] = 611;
  20600. t['ccaron'] = 444;
  20601. t['aring'] = 500;
  20602. t['Ncommaaccent'] = 667;
  20603. t['lacute'] = 278;
  20604. t['agrave'] = 500;
  20605. t['Tcommaaccent'] = 556;
  20606. t['Cacute'] = 667;
  20607. t['atilde'] = 500;
  20608. t['Edotaccent'] = 611;
  20609. t['scaron'] = 389;
  20610. t['scedilla'] = 389;
  20611. t['iacute'] = 278;
  20612. t['lozenge'] = 471;
  20613. t['Rcaron'] = 611;
  20614. t['Gcommaaccent'] = 722;
  20615. t['ucircumflex'] = 500;
  20616. t['acircumflex'] = 500;
  20617. t['Amacron'] = 611;
  20618. t['rcaron'] = 389;
  20619. t['ccedilla'] = 444;
  20620. t['Zdotaccent'] = 556;
  20621. t['Thorn'] = 611;
  20622. t['Omacron'] = 722;
  20623. t['Racute'] = 611;
  20624. t['Sacute'] = 500;
  20625. t['dcaron'] = 544;
  20626. t['Umacron'] = 722;
  20627. t['uring'] = 500;
  20628. t['threesuperior'] = 300;
  20629. t['Ograve'] = 722;
  20630. t['Agrave'] = 611;
  20631. t['Abreve'] = 611;
  20632. t['multiply'] = 675;
  20633. t['uacute'] = 500;
  20634. t['Tcaron'] = 556;
  20635. t['partialdiff'] = 476;
  20636. t['ydieresis'] = 444;
  20637. t['Nacute'] = 667;
  20638. t['icircumflex'] = 278;
  20639. t['Ecircumflex'] = 611;
  20640. t['adieresis'] = 500;
  20641. t['edieresis'] = 444;
  20642. t['cacute'] = 444;
  20643. t['nacute'] = 500;
  20644. t['umacron'] = 500;
  20645. t['Ncaron'] = 667;
  20646. t['Iacute'] = 333;
  20647. t['plusminus'] = 675;
  20648. t['brokenbar'] = 275;
  20649. t['registered'] = 760;
  20650. t['Gbreve'] = 722;
  20651. t['Idotaccent'] = 333;
  20652. t['summation'] = 600;
  20653. t['Egrave'] = 611;
  20654. t['racute'] = 389;
  20655. t['omacron'] = 500;
  20656. t['Zacute'] = 556;
  20657. t['Zcaron'] = 556;
  20658. t['greaterequal'] = 549;
  20659. t['Eth'] = 722;
  20660. t['Ccedilla'] = 667;
  20661. t['lcommaaccent'] = 278;
  20662. t['tcaron'] = 300;
  20663. t['eogonek'] = 444;
  20664. t['Uogonek'] = 722;
  20665. t['Aacute'] = 611;
  20666. t['Adieresis'] = 611;
  20667. t['egrave'] = 444;
  20668. t['zacute'] = 389;
  20669. t['iogonek'] = 278;
  20670. t['Oacute'] = 722;
  20671. t['oacute'] = 500;
  20672. t['amacron'] = 500;
  20673. t['sacute'] = 389;
  20674. t['idieresis'] = 278;
  20675. t['Ocircumflex'] = 722;
  20676. t['Ugrave'] = 722;
  20677. t['Delta'] = 612;
  20678. t['thorn'] = 500;
  20679. t['twosuperior'] = 300;
  20680. t['Odieresis'] = 722;
  20681. t['mu'] = 500;
  20682. t['igrave'] = 278;
  20683. t['ohungarumlaut'] = 500;
  20684. t['Eogonek'] = 611;
  20685. t['dcroat'] = 500;
  20686. t['threequarters'] = 750;
  20687. t['Scedilla'] = 500;
  20688. t['lcaron'] = 300;
  20689. t['Kcommaaccent'] = 667;
  20690. t['Lacute'] = 556;
  20691. t['trademark'] = 980;
  20692. t['edotaccent'] = 444;
  20693. t['Igrave'] = 333;
  20694. t['Imacron'] = 333;
  20695. t['Lcaron'] = 611;
  20696. t['onehalf'] = 750;
  20697. t['lessequal'] = 549;
  20698. t['ocircumflex'] = 500;
  20699. t['ntilde'] = 500;
  20700. t['Uhungarumlaut'] = 722;
  20701. t['Eacute'] = 611;
  20702. t['emacron'] = 444;
  20703. t['gbreve'] = 500;
  20704. t['onequarter'] = 750;
  20705. t['Scaron'] = 500;
  20706. t['Scommaaccent'] = 500;
  20707. t['Ohungarumlaut'] = 722;
  20708. t['degree'] = 400;
  20709. t['ograve'] = 500;
  20710. t['Ccaron'] = 667;
  20711. t['ugrave'] = 500;
  20712. t['radical'] = 453;
  20713. t['Dcaron'] = 722;
  20714. t['rcommaaccent'] = 389;
  20715. t['Ntilde'] = 667;
  20716. t['otilde'] = 500;
  20717. t['Rcommaaccent'] = 611;
  20718. t['Lcommaaccent'] = 556;
  20719. t['Atilde'] = 611;
  20720. t['Aogonek'] = 611;
  20721. t['Aring'] = 611;
  20722. t['Otilde'] = 722;
  20723. t['zdotaccent'] = 389;
  20724. t['Ecaron'] = 611;
  20725. t['Iogonek'] = 333;
  20726. t['kcommaaccent'] = 444;
  20727. t['minus'] = 675;
  20728. t['Icircumflex'] = 333;
  20729. t['ncaron'] = 500;
  20730. t['tcommaaccent'] = 278;
  20731. t['logicalnot'] = 675;
  20732. t['odieresis'] = 500;
  20733. t['udieresis'] = 500;
  20734. t['notequal'] = 549;
  20735. t['gcommaaccent'] = 500;
  20736. t['eth'] = 500;
  20737. t['zcaron'] = 389;
  20738. t['ncommaaccent'] = 500;
  20739. t['onesuperior'] = 300;
  20740. t['imacron'] = 278;
  20741. t['Euro'] = 500;
  20742. });
  20743. t['ZapfDingbats'] = getLookupTableFactory(function (t) {
  20744. t['space'] = 278;
  20745. t['a1'] = 974;
  20746. t['a2'] = 961;
  20747. t['a202'] = 974;
  20748. t['a3'] = 980;
  20749. t['a4'] = 719;
  20750. t['a5'] = 789;
  20751. t['a119'] = 790;
  20752. t['a118'] = 791;
  20753. t['a117'] = 690;
  20754. t['a11'] = 960;
  20755. t['a12'] = 939;
  20756. t['a13'] = 549;
  20757. t['a14'] = 855;
  20758. t['a15'] = 911;
  20759. t['a16'] = 933;
  20760. t['a105'] = 911;
  20761. t['a17'] = 945;
  20762. t['a18'] = 974;
  20763. t['a19'] = 755;
  20764. t['a20'] = 846;
  20765. t['a21'] = 762;
  20766. t['a22'] = 761;
  20767. t['a23'] = 571;
  20768. t['a24'] = 677;
  20769. t['a25'] = 763;
  20770. t['a26'] = 760;
  20771. t['a27'] = 759;
  20772. t['a28'] = 754;
  20773. t['a6'] = 494;
  20774. t['a7'] = 552;
  20775. t['a8'] = 537;
  20776. t['a9'] = 577;
  20777. t['a10'] = 692;
  20778. t['a29'] = 786;
  20779. t['a30'] = 788;
  20780. t['a31'] = 788;
  20781. t['a32'] = 790;
  20782. t['a33'] = 793;
  20783. t['a34'] = 794;
  20784. t['a35'] = 816;
  20785. t['a36'] = 823;
  20786. t['a37'] = 789;
  20787. t['a38'] = 841;
  20788. t['a39'] = 823;
  20789. t['a40'] = 833;
  20790. t['a41'] = 816;
  20791. t['a42'] = 831;
  20792. t['a43'] = 923;
  20793. t['a44'] = 744;
  20794. t['a45'] = 723;
  20795. t['a46'] = 749;
  20796. t['a47'] = 790;
  20797. t['a48'] = 792;
  20798. t['a49'] = 695;
  20799. t['a50'] = 776;
  20800. t['a51'] = 768;
  20801. t['a52'] = 792;
  20802. t['a53'] = 759;
  20803. t['a54'] = 707;
  20804. t['a55'] = 708;
  20805. t['a56'] = 682;
  20806. t['a57'] = 701;
  20807. t['a58'] = 826;
  20808. t['a59'] = 815;
  20809. t['a60'] = 789;
  20810. t['a61'] = 789;
  20811. t['a62'] = 707;
  20812. t['a63'] = 687;
  20813. t['a64'] = 696;
  20814. t['a65'] = 689;
  20815. t['a66'] = 786;
  20816. t['a67'] = 787;
  20817. t['a68'] = 713;
  20818. t['a69'] = 791;
  20819. t['a70'] = 785;
  20820. t['a71'] = 791;
  20821. t['a72'] = 873;
  20822. t['a73'] = 761;
  20823. t['a74'] = 762;
  20824. t['a203'] = 762;
  20825. t['a75'] = 759;
  20826. t['a204'] = 759;
  20827. t['a76'] = 892;
  20828. t['a77'] = 892;
  20829. t['a78'] = 788;
  20830. t['a79'] = 784;
  20831. t['a81'] = 438;
  20832. t['a82'] = 138;
  20833. t['a83'] = 277;
  20834. t['a84'] = 415;
  20835. t['a97'] = 392;
  20836. t['a98'] = 392;
  20837. t['a99'] = 668;
  20838. t['a100'] = 668;
  20839. t['a89'] = 390;
  20840. t['a90'] = 390;
  20841. t['a93'] = 317;
  20842. t['a94'] = 317;
  20843. t['a91'] = 276;
  20844. t['a92'] = 276;
  20845. t['a205'] = 509;
  20846. t['a85'] = 509;
  20847. t['a206'] = 410;
  20848. t['a86'] = 410;
  20849. t['a87'] = 234;
  20850. t['a88'] = 234;
  20851. t['a95'] = 334;
  20852. t['a96'] = 334;
  20853. t['a101'] = 732;
  20854. t['a102'] = 544;
  20855. t['a103'] = 544;
  20856. t['a104'] = 910;
  20857. t['a106'] = 667;
  20858. t['a107'] = 760;
  20859. t['a108'] = 760;
  20860. t['a112'] = 776;
  20861. t['a111'] = 595;
  20862. t['a110'] = 694;
  20863. t['a109'] = 626;
  20864. t['a120'] = 788;
  20865. t['a121'] = 788;
  20866. t['a122'] = 788;
  20867. t['a123'] = 788;
  20868. t['a124'] = 788;
  20869. t['a125'] = 788;
  20870. t['a126'] = 788;
  20871. t['a127'] = 788;
  20872. t['a128'] = 788;
  20873. t['a129'] = 788;
  20874. t['a130'] = 788;
  20875. t['a131'] = 788;
  20876. t['a132'] = 788;
  20877. t['a133'] = 788;
  20878. t['a134'] = 788;
  20879. t['a135'] = 788;
  20880. t['a136'] = 788;
  20881. t['a137'] = 788;
  20882. t['a138'] = 788;
  20883. t['a139'] = 788;
  20884. t['a140'] = 788;
  20885. t['a141'] = 788;
  20886. t['a142'] = 788;
  20887. t['a143'] = 788;
  20888. t['a144'] = 788;
  20889. t['a145'] = 788;
  20890. t['a146'] = 788;
  20891. t['a147'] = 788;
  20892. t['a148'] = 788;
  20893. t['a149'] = 788;
  20894. t['a150'] = 788;
  20895. t['a151'] = 788;
  20896. t['a152'] = 788;
  20897. t['a153'] = 788;
  20898. t['a154'] = 788;
  20899. t['a155'] = 788;
  20900. t['a156'] = 788;
  20901. t['a157'] = 788;
  20902. t['a158'] = 788;
  20903. t['a159'] = 788;
  20904. t['a160'] = 894;
  20905. t['a161'] = 838;
  20906. t['a163'] = 1016;
  20907. t['a164'] = 458;
  20908. t['a196'] = 748;
  20909. t['a165'] = 924;
  20910. t['a192'] = 748;
  20911. t['a166'] = 918;
  20912. t['a167'] = 927;
  20913. t['a168'] = 928;
  20914. t['a169'] = 928;
  20915. t['a170'] = 834;
  20916. t['a171'] = 873;
  20917. t['a172'] = 828;
  20918. t['a173'] = 924;
  20919. t['a162'] = 924;
  20920. t['a174'] = 917;
  20921. t['a175'] = 930;
  20922. t['a176'] = 931;
  20923. t['a177'] = 463;
  20924. t['a178'] = 883;
  20925. t['a179'] = 836;
  20926. t['a193'] = 836;
  20927. t['a180'] = 867;
  20928. t['a199'] = 867;
  20929. t['a181'] = 696;
  20930. t['a200'] = 696;
  20931. t['a182'] = 874;
  20932. t['a201'] = 874;
  20933. t['a183'] = 760;
  20934. t['a184'] = 946;
  20935. t['a197'] = 771;
  20936. t['a185'] = 865;
  20937. t['a194'] = 771;
  20938. t['a198'] = 888;
  20939. t['a186'] = 967;
  20940. t['a195'] = 888;
  20941. t['a187'] = 831;
  20942. t['a188'] = 873;
  20943. t['a189'] = 927;
  20944. t['a190'] = 970;
  20945. t['a191'] = 918;
  20946. });
  20947. });
  20948. exports.getMetrics = getMetrics;
  20949. }));
  20950. (function (root, factory) {
  20951. factory(root.pdfjsCoreMurmurHash3 = {}, root.pdfjsSharedUtil);
  20952. }(this, function (exports, sharedUtil) {
  20953. var Uint32ArrayView = sharedUtil.Uint32ArrayView;
  20954. var MurmurHash3_64 = function MurmurHash3_64Closure(seed) {
  20955. // Workaround for missing math precision in JS.
  20956. var MASK_HIGH = 0xffff0000;
  20957. var MASK_LOW = 0xffff;
  20958. function MurmurHash3_64(seed) {
  20959. var SEED = 0xc3d2e1f0;
  20960. this.h1 = seed ? seed & 0xffffffff : SEED;
  20961. this.h2 = seed ? seed & 0xffffffff : SEED;
  20962. }
  20963. var alwaysUseUint32ArrayView = false;
  20964. // old webkits have issues with non-aligned arrays
  20965. try {
  20966. new Uint32Array(new Uint8Array(5).buffer, 0, 1);
  20967. } catch (e) {
  20968. alwaysUseUint32ArrayView = true;
  20969. }
  20970. MurmurHash3_64.prototype = {
  20971. update: function MurmurHash3_64_update(input) {
  20972. var useUint32ArrayView = alwaysUseUint32ArrayView;
  20973. var i;
  20974. if (typeof input === 'string') {
  20975. var data = new Uint8Array(input.length * 2);
  20976. var length = 0;
  20977. for (i = 0; i < input.length; i++) {
  20978. var code = input.charCodeAt(i);
  20979. if (code <= 0xff) {
  20980. data[length++] = code;
  20981. } else {
  20982. data[length++] = code >>> 8;
  20983. data[length++] = code & 0xff;
  20984. }
  20985. }
  20986. } else if (input instanceof Uint8Array) {
  20987. data = input;
  20988. length = data.length;
  20989. } else if (typeof input === 'object' && 'length' in input) {
  20990. // processing regular arrays as well, e.g. for IE9
  20991. data = input;
  20992. length = data.length;
  20993. useUint32ArrayView = true;
  20994. } else {
  20995. throw new Error('Wrong data format in MurmurHash3_64_update. ' + 'Input must be a string or array.');
  20996. }
  20997. var blockCounts = length >> 2;
  20998. var tailLength = length - blockCounts * 4;
  20999. // we don't care about endianness here
  21000. var dataUint32 = useUint32ArrayView ? new Uint32ArrayView(data, blockCounts) : new Uint32Array(data.buffer, 0, blockCounts);
  21001. var k1 = 0;
  21002. var k2 = 0;
  21003. var h1 = this.h1;
  21004. var h2 = this.h2;
  21005. var C1 = 0xcc9e2d51;
  21006. var C2 = 0x1b873593;
  21007. var C1_LOW = C1 & MASK_LOW;
  21008. var C2_LOW = C2 & MASK_LOW;
  21009. for (i = 0; i < blockCounts; i++) {
  21010. if (i & 1) {
  21011. k1 = dataUint32[i];
  21012. k1 = k1 * C1 & MASK_HIGH | k1 * C1_LOW & MASK_LOW;
  21013. k1 = k1 << 15 | k1 >>> 17;
  21014. k1 = k1 * C2 & MASK_HIGH | k1 * C2_LOW & MASK_LOW;
  21015. h1 ^= k1;
  21016. h1 = h1 << 13 | h1 >>> 19;
  21017. h1 = h1 * 5 + 0xe6546b64;
  21018. } else {
  21019. k2 = dataUint32[i];
  21020. k2 = k2 * C1 & MASK_HIGH | k2 * C1_LOW & MASK_LOW;
  21021. k2 = k2 << 15 | k2 >>> 17;
  21022. k2 = k2 * C2 & MASK_HIGH | k2 * C2_LOW & MASK_LOW;
  21023. h2 ^= k2;
  21024. h2 = h2 << 13 | h2 >>> 19;
  21025. h2 = h2 * 5 + 0xe6546b64;
  21026. }
  21027. }
  21028. k1 = 0;
  21029. switch (tailLength) {
  21030. case 3:
  21031. k1 ^= data[blockCounts * 4 + 2] << 16;
  21032. case 2:
  21033. k1 ^= data[blockCounts * 4 + 1] << 8;
  21034. case 1:
  21035. k1 ^= data[blockCounts * 4];
  21036. k1 = k1 * C1 & MASK_HIGH | k1 * C1_LOW & MASK_LOW;
  21037. k1 = k1 << 15 | k1 >>> 17;
  21038. k1 = k1 * C2 & MASK_HIGH | k1 * C2_LOW & MASK_LOW;
  21039. if (blockCounts & 1) {
  21040. h1 ^= k1;
  21041. } else {
  21042. h2 ^= k1;
  21043. }
  21044. }
  21045. this.h1 = h1;
  21046. this.h2 = h2;
  21047. return this;
  21048. },
  21049. hexdigest: function MurmurHash3_64_hexdigest() {
  21050. var h1 = this.h1;
  21051. var h2 = this.h2;
  21052. h1 ^= h2 >>> 1;
  21053. h1 = h1 * 0xed558ccd & MASK_HIGH | h1 * 0x8ccd & MASK_LOW;
  21054. h2 = h2 * 0xff51afd7 & MASK_HIGH | ((h2 << 16 | h1 >>> 16) * 0xafd7ed55 & MASK_HIGH) >>> 16;
  21055. h1 ^= h2 >>> 1;
  21056. h1 = h1 * 0x1a85ec53 & MASK_HIGH | h1 * 0xec53 & MASK_LOW;
  21057. h2 = h2 * 0xc4ceb9fe & MASK_HIGH | ((h2 << 16 | h1 >>> 16) * 0xb9fe1a85 & MASK_HIGH) >>> 16;
  21058. h1 ^= h2 >>> 1;
  21059. for (var i = 0, arr = [
  21060. h1,
  21061. h2
  21062. ], str = ''; i < arr.length; i++) {
  21063. var hex = (arr[i] >>> 0).toString(16);
  21064. while (hex.length < 8) {
  21065. hex = '0' + hex;
  21066. }
  21067. str += hex;
  21068. }
  21069. return str;
  21070. }
  21071. };
  21072. return MurmurHash3_64;
  21073. }();
  21074. exports.MurmurHash3_64 = MurmurHash3_64;
  21075. }));
  21076. (function (root, factory) {
  21077. factory(root.pdfjsCorePrimitives = {}, root.pdfjsSharedUtil);
  21078. }(this, function (exports, sharedUtil) {
  21079. var isArray = sharedUtil.isArray;
  21080. var Name = function NameClosure() {
  21081. function Name(name) {
  21082. this.name = name;
  21083. }
  21084. Name.prototype = {};
  21085. var nameCache = Object.create(null);
  21086. Name.get = function Name_get(name) {
  21087. var nameValue = nameCache[name];
  21088. return nameValue ? nameValue : nameCache[name] = new Name(name);
  21089. };
  21090. return Name;
  21091. }();
  21092. var Cmd = function CmdClosure() {
  21093. function Cmd(cmd) {
  21094. this.cmd = cmd;
  21095. }
  21096. Cmd.prototype = {};
  21097. var cmdCache = Object.create(null);
  21098. Cmd.get = function Cmd_get(cmd) {
  21099. var cmdValue = cmdCache[cmd];
  21100. return cmdValue ? cmdValue : cmdCache[cmd] = new Cmd(cmd);
  21101. };
  21102. return Cmd;
  21103. }();
  21104. var Dict = function DictClosure() {
  21105. var nonSerializable = function nonSerializableClosure() {
  21106. return nonSerializable;
  21107. };
  21108. // creating closure on some variable
  21109. // xref is optional
  21110. function Dict(xref) {
  21111. // Map should only be used internally, use functions below to access.
  21112. this.map = Object.create(null);
  21113. this.xref = xref;
  21114. this.objId = null;
  21115. this.suppressEncryption = false;
  21116. this.__nonSerializable__ = nonSerializable;
  21117. }
  21118. // disable cloning of the Dict
  21119. Dict.prototype = {
  21120. assignXref: function Dict_assignXref(newXref) {
  21121. this.xref = newXref;
  21122. },
  21123. // automatically dereferences Ref objects
  21124. get: function Dict_get(key1, key2, key3) {
  21125. var value;
  21126. var xref = this.xref, suppressEncryption = this.suppressEncryption;
  21127. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map || typeof key2 === 'undefined') {
  21128. return xref ? xref.fetchIfRef(value, suppressEncryption) : value;
  21129. }
  21130. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map || typeof key3 === 'undefined') {
  21131. return xref ? xref.fetchIfRef(value, suppressEncryption) : value;
  21132. }
  21133. value = this.map[key3] || null;
  21134. return xref ? xref.fetchIfRef(value, suppressEncryption) : value;
  21135. },
  21136. // Same as get(), but returns a promise and uses fetchIfRefAsync().
  21137. getAsync: function Dict_getAsync(key1, key2, key3) {
  21138. var value;
  21139. var xref = this.xref, suppressEncryption = this.suppressEncryption;
  21140. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map || typeof key2 === 'undefined') {
  21141. if (xref) {
  21142. return xref.fetchIfRefAsync(value, suppressEncryption);
  21143. }
  21144. return Promise.resolve(value);
  21145. }
  21146. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map || typeof key3 === 'undefined') {
  21147. if (xref) {
  21148. return xref.fetchIfRefAsync(value, suppressEncryption);
  21149. }
  21150. return Promise.resolve(value);
  21151. }
  21152. value = this.map[key3] || null;
  21153. if (xref) {
  21154. return xref.fetchIfRefAsync(value, suppressEncryption);
  21155. }
  21156. return Promise.resolve(value);
  21157. },
  21158. // Same as get(), but dereferences all elements if the result is an Array.
  21159. getArray: function Dict_getArray(key1, key2, key3) {
  21160. var value = this.get(key1, key2, key3);
  21161. var xref = this.xref, suppressEncryption = this.suppressEncryption;
  21162. if (!isArray(value) || !xref) {
  21163. return value;
  21164. }
  21165. value = value.slice();
  21166. // Ensure that we don't modify the Dict data.
  21167. for (var i = 0, ii = value.length; i < ii; i++) {
  21168. if (!isRef(value[i])) {
  21169. continue;
  21170. }
  21171. value[i] = xref.fetch(value[i], suppressEncryption);
  21172. }
  21173. return value;
  21174. },
  21175. // no dereferencing
  21176. getRaw: function Dict_getRaw(key) {
  21177. return this.map[key];
  21178. },
  21179. getKeys: function Dict_getKeys() {
  21180. return Object.keys(this.map);
  21181. },
  21182. set: function Dict_set(key, value) {
  21183. this.map[key] = value;
  21184. },
  21185. has: function Dict_has(key) {
  21186. return key in this.map;
  21187. },
  21188. forEach: function Dict_forEach(callback) {
  21189. for (var key in this.map) {
  21190. callback(key, this.get(key));
  21191. }
  21192. }
  21193. };
  21194. Dict.empty = new Dict(null);
  21195. Dict.merge = function Dict_merge(xref, dictArray) {
  21196. var mergedDict = new Dict(xref);
  21197. for (var i = 0, ii = dictArray.length; i < ii; i++) {
  21198. var dict = dictArray[i];
  21199. if (!isDict(dict)) {
  21200. continue;
  21201. }
  21202. for (var keyName in dict.map) {
  21203. if (mergedDict.map[keyName]) {
  21204. continue;
  21205. }
  21206. mergedDict.map[keyName] = dict.map[keyName];
  21207. }
  21208. }
  21209. return mergedDict;
  21210. };
  21211. return Dict;
  21212. }();
  21213. var Ref = function RefClosure() {
  21214. function Ref(num, gen) {
  21215. this.num = num;
  21216. this.gen = gen;
  21217. }
  21218. Ref.prototype = {
  21219. toString: function Ref_toString() {
  21220. // This function is hot, so we make the string as compact as possible.
  21221. // |this.gen| is almost always zero, so we treat that case specially.
  21222. var str = this.num + 'R';
  21223. if (this.gen !== 0) {
  21224. str += this.gen;
  21225. }
  21226. return str;
  21227. }
  21228. };
  21229. return Ref;
  21230. }();
  21231. // The reference is identified by number and generation.
  21232. // This structure stores only one instance of the reference.
  21233. var RefSet = function RefSetClosure() {
  21234. function RefSet() {
  21235. this.dict = Object.create(null);
  21236. }
  21237. RefSet.prototype = {
  21238. has: function RefSet_has(ref) {
  21239. return ref.toString() in this.dict;
  21240. },
  21241. put: function RefSet_put(ref) {
  21242. this.dict[ref.toString()] = true;
  21243. },
  21244. remove: function RefSet_remove(ref) {
  21245. delete this.dict[ref.toString()];
  21246. }
  21247. };
  21248. return RefSet;
  21249. }();
  21250. var RefSetCache = function RefSetCacheClosure() {
  21251. function RefSetCache() {
  21252. this.dict = Object.create(null);
  21253. }
  21254. RefSetCache.prototype = {
  21255. get: function RefSetCache_get(ref) {
  21256. return this.dict[ref.toString()];
  21257. },
  21258. has: function RefSetCache_has(ref) {
  21259. return ref.toString() in this.dict;
  21260. },
  21261. put: function RefSetCache_put(ref, obj) {
  21262. this.dict[ref.toString()] = obj;
  21263. },
  21264. putAlias: function RefSetCache_putAlias(ref, aliasRef) {
  21265. this.dict[ref.toString()] = this.get(aliasRef);
  21266. },
  21267. forEach: function RefSetCache_forEach(fn, thisArg) {
  21268. for (var i in this.dict) {
  21269. fn.call(thisArg, this.dict[i]);
  21270. }
  21271. },
  21272. clear: function RefSetCache_clear() {
  21273. this.dict = Object.create(null);
  21274. }
  21275. };
  21276. return RefSetCache;
  21277. }();
  21278. function isName(v, name) {
  21279. return v instanceof Name && (name === undefined || v.name === name);
  21280. }
  21281. function isCmd(v, cmd) {
  21282. return v instanceof Cmd && (cmd === undefined || v.cmd === cmd);
  21283. }
  21284. function isDict(v, type) {
  21285. return v instanceof Dict && (type === undefined || isName(v.get('Type'), type));
  21286. }
  21287. function isRef(v) {
  21288. return v instanceof Ref;
  21289. }
  21290. function isRefsEqual(v1, v2) {
  21291. return v1.num === v2.num && v1.gen === v2.gen;
  21292. }
  21293. function isStream(v) {
  21294. return typeof v === 'object' && v !== null && v.getBytes !== undefined;
  21295. }
  21296. exports.Cmd = Cmd;
  21297. exports.Dict = Dict;
  21298. exports.Name = Name;
  21299. exports.Ref = Ref;
  21300. exports.RefSet = RefSet;
  21301. exports.RefSetCache = RefSetCache;
  21302. exports.isCmd = isCmd;
  21303. exports.isDict = isDict;
  21304. exports.isName = isName;
  21305. exports.isRef = isRef;
  21306. exports.isRefsEqual = isRefsEqual;
  21307. exports.isStream = isStream;
  21308. }));
  21309. (function (root, factory) {
  21310. factory(root.pdfjsCoreStandardFonts = {}, root.pdfjsSharedUtil);
  21311. }(this, function (exports, sharedUtil) {
  21312. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  21313. /**
  21314. * Hold a map of decoded fonts and of the standard fourteen Type1
  21315. * fonts and their acronyms.
  21316. */
  21317. var getStdFontMap = getLookupTableFactory(function (t) {
  21318. t['ArialNarrow'] = 'Helvetica';
  21319. t['ArialNarrow-Bold'] = 'Helvetica-Bold';
  21320. t['ArialNarrow-BoldItalic'] = 'Helvetica-BoldOblique';
  21321. t['ArialNarrow-Italic'] = 'Helvetica-Oblique';
  21322. t['ArialBlack'] = 'Helvetica';
  21323. t['ArialBlack-Bold'] = 'Helvetica-Bold';
  21324. t['ArialBlack-BoldItalic'] = 'Helvetica-BoldOblique';
  21325. t['ArialBlack-Italic'] = 'Helvetica-Oblique';
  21326. t['Arial'] = 'Helvetica';
  21327. t['Arial-Bold'] = 'Helvetica-Bold';
  21328. t['Arial-BoldItalic'] = 'Helvetica-BoldOblique';
  21329. t['Arial-Italic'] = 'Helvetica-Oblique';
  21330. t['Arial-BoldItalicMT'] = 'Helvetica-BoldOblique';
  21331. t['Arial-BoldMT'] = 'Helvetica-Bold';
  21332. t['Arial-ItalicMT'] = 'Helvetica-Oblique';
  21333. t['ArialMT'] = 'Helvetica';
  21334. t['Courier-Bold'] = 'Courier-Bold';
  21335. t['Courier-BoldItalic'] = 'Courier-BoldOblique';
  21336. t['Courier-Italic'] = 'Courier-Oblique';
  21337. t['CourierNew'] = 'Courier';
  21338. t['CourierNew-Bold'] = 'Courier-Bold';
  21339. t['CourierNew-BoldItalic'] = 'Courier-BoldOblique';
  21340. t['CourierNew-Italic'] = 'Courier-Oblique';
  21341. t['CourierNewPS-BoldItalicMT'] = 'Courier-BoldOblique';
  21342. t['CourierNewPS-BoldMT'] = 'Courier-Bold';
  21343. t['CourierNewPS-ItalicMT'] = 'Courier-Oblique';
  21344. t['CourierNewPSMT'] = 'Courier';
  21345. t['Helvetica'] = 'Helvetica';
  21346. t['Helvetica-Bold'] = 'Helvetica-Bold';
  21347. t['Helvetica-BoldItalic'] = 'Helvetica-BoldOblique';
  21348. t['Helvetica-BoldOblique'] = 'Helvetica-BoldOblique';
  21349. t['Helvetica-Italic'] = 'Helvetica-Oblique';
  21350. t['Helvetica-Oblique'] = 'Helvetica-Oblique';
  21351. t['Symbol-Bold'] = 'Symbol';
  21352. t['Symbol-BoldItalic'] = 'Symbol';
  21353. t['Symbol-Italic'] = 'Symbol';
  21354. t['TimesNewRoman'] = 'Times-Roman';
  21355. t['TimesNewRoman-Bold'] = 'Times-Bold';
  21356. t['TimesNewRoman-BoldItalic'] = 'Times-BoldItalic';
  21357. t['TimesNewRoman-Italic'] = 'Times-Italic';
  21358. t['TimesNewRomanPS'] = 'Times-Roman';
  21359. t['TimesNewRomanPS-Bold'] = 'Times-Bold';
  21360. t['TimesNewRomanPS-BoldItalic'] = 'Times-BoldItalic';
  21361. t['TimesNewRomanPS-BoldItalicMT'] = 'Times-BoldItalic';
  21362. t['TimesNewRomanPS-BoldMT'] = 'Times-Bold';
  21363. t['TimesNewRomanPS-Italic'] = 'Times-Italic';
  21364. t['TimesNewRomanPS-ItalicMT'] = 'Times-Italic';
  21365. t['TimesNewRomanPSMT'] = 'Times-Roman';
  21366. t['TimesNewRomanPSMT-Bold'] = 'Times-Bold';
  21367. t['TimesNewRomanPSMT-BoldItalic'] = 'Times-BoldItalic';
  21368. t['TimesNewRomanPSMT-Italic'] = 'Times-Italic';
  21369. });
  21370. /**
  21371. * Holds the map of the non-standard fonts that might be included as
  21372. * a standard fonts without glyph data.
  21373. */
  21374. var getNonStdFontMap = getLookupTableFactory(function (t) {
  21375. t['CenturyGothic'] = 'Helvetica';
  21376. t['CenturyGothic-Bold'] = 'Helvetica-Bold';
  21377. t['CenturyGothic-BoldItalic'] = 'Helvetica-BoldOblique';
  21378. t['CenturyGothic-Italic'] = 'Helvetica-Oblique';
  21379. t['ComicSansMS'] = 'Comic Sans MS';
  21380. t['ComicSansMS-Bold'] = 'Comic Sans MS-Bold';
  21381. t['ComicSansMS-BoldItalic'] = 'Comic Sans MS-BoldItalic';
  21382. t['ComicSansMS-Italic'] = 'Comic Sans MS-Italic';
  21383. t['LucidaConsole'] = 'Courier';
  21384. t['LucidaConsole-Bold'] = 'Courier-Bold';
  21385. t['LucidaConsole-BoldItalic'] = 'Courier-BoldOblique';
  21386. t['LucidaConsole-Italic'] = 'Courier-Oblique';
  21387. t['MS-Gothic'] = 'MS Gothic';
  21388. t['MS-Gothic-Bold'] = 'MS Gothic-Bold';
  21389. t['MS-Gothic-BoldItalic'] = 'MS Gothic-BoldItalic';
  21390. t['MS-Gothic-Italic'] = 'MS Gothic-Italic';
  21391. t['MS-Mincho'] = 'MS Mincho';
  21392. t['MS-Mincho-Bold'] = 'MS Mincho-Bold';
  21393. t['MS-Mincho-BoldItalic'] = 'MS Mincho-BoldItalic';
  21394. t['MS-Mincho-Italic'] = 'MS Mincho-Italic';
  21395. t['MS-PGothic'] = 'MS PGothic';
  21396. t['MS-PGothic-Bold'] = 'MS PGothic-Bold';
  21397. t['MS-PGothic-BoldItalic'] = 'MS PGothic-BoldItalic';
  21398. t['MS-PGothic-Italic'] = 'MS PGothic-Italic';
  21399. t['MS-PMincho'] = 'MS PMincho';
  21400. t['MS-PMincho-Bold'] = 'MS PMincho-Bold';
  21401. t['MS-PMincho-BoldItalic'] = 'MS PMincho-BoldItalic';
  21402. t['MS-PMincho-Italic'] = 'MS PMincho-Italic';
  21403. t['Wingdings'] = 'ZapfDingbats';
  21404. });
  21405. var getSerifFonts = getLookupTableFactory(function (t) {
  21406. t['Adobe Jenson'] = true;
  21407. t['Adobe Text'] = true;
  21408. t['Albertus'] = true;
  21409. t['Aldus'] = true;
  21410. t['Alexandria'] = true;
  21411. t['Algerian'] = true;
  21412. t['American Typewriter'] = true;
  21413. t['Antiqua'] = true;
  21414. t['Apex'] = true;
  21415. t['Arno'] = true;
  21416. t['Aster'] = true;
  21417. t['Aurora'] = true;
  21418. t['Baskerville'] = true;
  21419. t['Bell'] = true;
  21420. t['Bembo'] = true;
  21421. t['Bembo Schoolbook'] = true;
  21422. t['Benguiat'] = true;
  21423. t['Berkeley Old Style'] = true;
  21424. t['Bernhard Modern'] = true;
  21425. t['Berthold City'] = true;
  21426. t['Bodoni'] = true;
  21427. t['Bauer Bodoni'] = true;
  21428. t['Book Antiqua'] = true;
  21429. t['Bookman'] = true;
  21430. t['Bordeaux Roman'] = true;
  21431. t['Californian FB'] = true;
  21432. t['Calisto'] = true;
  21433. t['Calvert'] = true;
  21434. t['Capitals'] = true;
  21435. t['Cambria'] = true;
  21436. t['Cartier'] = true;
  21437. t['Caslon'] = true;
  21438. t['Catull'] = true;
  21439. t['Centaur'] = true;
  21440. t['Century Old Style'] = true;
  21441. t['Century Schoolbook'] = true;
  21442. t['Chaparral'] = true;
  21443. t['Charis SIL'] = true;
  21444. t['Cheltenham'] = true;
  21445. t['Cholla Slab'] = true;
  21446. t['Clarendon'] = true;
  21447. t['Clearface'] = true;
  21448. t['Cochin'] = true;
  21449. t['Colonna'] = true;
  21450. t['Computer Modern'] = true;
  21451. t['Concrete Roman'] = true;
  21452. t['Constantia'] = true;
  21453. t['Cooper Black'] = true;
  21454. t['Corona'] = true;
  21455. t['Ecotype'] = true;
  21456. t['Egyptienne'] = true;
  21457. t['Elephant'] = true;
  21458. t['Excelsior'] = true;
  21459. t['Fairfield'] = true;
  21460. t['FF Scala'] = true;
  21461. t['Folkard'] = true;
  21462. t['Footlight'] = true;
  21463. t['FreeSerif'] = true;
  21464. t['Friz Quadrata'] = true;
  21465. t['Garamond'] = true;
  21466. t['Gentium'] = true;
  21467. t['Georgia'] = true;
  21468. t['Gloucester'] = true;
  21469. t['Goudy Old Style'] = true;
  21470. t['Goudy Schoolbook'] = true;
  21471. t['Goudy Pro Font'] = true;
  21472. t['Granjon'] = true;
  21473. t['Guardian Egyptian'] = true;
  21474. t['Heather'] = true;
  21475. t['Hercules'] = true;
  21476. t['High Tower Text'] = true;
  21477. t['Hiroshige'] = true;
  21478. t['Hoefler Text'] = true;
  21479. t['Humana Serif'] = true;
  21480. t['Imprint'] = true;
  21481. t['Ionic No. 5'] = true;
  21482. t['Janson'] = true;
  21483. t['Joanna'] = true;
  21484. t['Korinna'] = true;
  21485. t['Lexicon'] = true;
  21486. t['Liberation Serif'] = true;
  21487. t['Linux Libertine'] = true;
  21488. t['Literaturnaya'] = true;
  21489. t['Lucida'] = true;
  21490. t['Lucida Bright'] = true;
  21491. t['Melior'] = true;
  21492. t['Memphis'] = true;
  21493. t['Miller'] = true;
  21494. t['Minion'] = true;
  21495. t['Modern'] = true;
  21496. t['Mona Lisa'] = true;
  21497. t['Mrs Eaves'] = true;
  21498. t['MS Serif'] = true;
  21499. t['Museo Slab'] = true;
  21500. t['New York'] = true;
  21501. t['Nimbus Roman'] = true;
  21502. t['NPS Rawlinson Roadway'] = true;
  21503. t['Palatino'] = true;
  21504. t['Perpetua'] = true;
  21505. t['Plantin'] = true;
  21506. t['Plantin Schoolbook'] = true;
  21507. t['Playbill'] = true;
  21508. t['Poor Richard'] = true;
  21509. t['Rawlinson Roadway'] = true;
  21510. t['Renault'] = true;
  21511. t['Requiem'] = true;
  21512. t['Rockwell'] = true;
  21513. t['Roman'] = true;
  21514. t['Rotis Serif'] = true;
  21515. t['Sabon'] = true;
  21516. t['Scala'] = true;
  21517. t['Seagull'] = true;
  21518. t['Sistina'] = true;
  21519. t['Souvenir'] = true;
  21520. t['STIX'] = true;
  21521. t['Stone Informal'] = true;
  21522. t['Stone Serif'] = true;
  21523. t['Sylfaen'] = true;
  21524. t['Times'] = true;
  21525. t['Trajan'] = true;
  21526. t['Trinité'] = true;
  21527. t['Trump Mediaeval'] = true;
  21528. t['Utopia'] = true;
  21529. t['Vale Type'] = true;
  21530. t['Bitstream Vera'] = true;
  21531. t['Vera Serif'] = true;
  21532. t['Versailles'] = true;
  21533. t['Wanted'] = true;
  21534. t['Weiss'] = true;
  21535. t['Wide Latin'] = true;
  21536. t['Windsor'] = true;
  21537. t['XITS'] = true;
  21538. });
  21539. var getSymbolsFonts = getLookupTableFactory(function (t) {
  21540. t['Dingbats'] = true;
  21541. t['Symbol'] = true;
  21542. t['ZapfDingbats'] = true;
  21543. });
  21544. // Glyph map for well-known standard fonts. Sometimes Ghostscript uses CID
  21545. // fonts, but does not embed the CID to GID mapping. The mapping is incomplete
  21546. // for all glyphs, but common for some set of the standard fonts.
  21547. var getGlyphMapForStandardFonts = getLookupTableFactory(function (t) {
  21548. t[2] = 10;
  21549. t[3] = 32;
  21550. t[4] = 33;
  21551. t[5] = 34;
  21552. t[6] = 35;
  21553. t[7] = 36;
  21554. t[8] = 37;
  21555. t[9] = 38;
  21556. t[10] = 39;
  21557. t[11] = 40;
  21558. t[12] = 41;
  21559. t[13] = 42;
  21560. t[14] = 43;
  21561. t[15] = 44;
  21562. t[16] = 45;
  21563. t[17] = 46;
  21564. t[18] = 47;
  21565. t[19] = 48;
  21566. t[20] = 49;
  21567. t[21] = 50;
  21568. t[22] = 51;
  21569. t[23] = 52;
  21570. t[24] = 53;
  21571. t[25] = 54;
  21572. t[26] = 55;
  21573. t[27] = 56;
  21574. t[28] = 57;
  21575. t[29] = 58;
  21576. t[30] = 894;
  21577. t[31] = 60;
  21578. t[32] = 61;
  21579. t[33] = 62;
  21580. t[34] = 63;
  21581. t[35] = 64;
  21582. t[36] = 65;
  21583. t[37] = 66;
  21584. t[38] = 67;
  21585. t[39] = 68;
  21586. t[40] = 69;
  21587. t[41] = 70;
  21588. t[42] = 71;
  21589. t[43] = 72;
  21590. t[44] = 73;
  21591. t[45] = 74;
  21592. t[46] = 75;
  21593. t[47] = 76;
  21594. t[48] = 77;
  21595. t[49] = 78;
  21596. t[50] = 79;
  21597. t[51] = 80;
  21598. t[52] = 81;
  21599. t[53] = 82;
  21600. t[54] = 83;
  21601. t[55] = 84;
  21602. t[56] = 85;
  21603. t[57] = 86;
  21604. t[58] = 87;
  21605. t[59] = 88;
  21606. t[60] = 89;
  21607. t[61] = 90;
  21608. t[62] = 91;
  21609. t[63] = 92;
  21610. t[64] = 93;
  21611. t[65] = 94;
  21612. t[66] = 95;
  21613. t[67] = 96;
  21614. t[68] = 97;
  21615. t[69] = 98;
  21616. t[70] = 99;
  21617. t[71] = 100;
  21618. t[72] = 101;
  21619. t[73] = 102;
  21620. t[74] = 103;
  21621. t[75] = 104;
  21622. t[76] = 105;
  21623. t[77] = 106;
  21624. t[78] = 107;
  21625. t[79] = 108;
  21626. t[80] = 109;
  21627. t[81] = 110;
  21628. t[82] = 111;
  21629. t[83] = 112;
  21630. t[84] = 113;
  21631. t[85] = 114;
  21632. t[86] = 115;
  21633. t[87] = 116;
  21634. t[88] = 117;
  21635. t[89] = 118;
  21636. t[90] = 119;
  21637. t[91] = 120;
  21638. t[92] = 121;
  21639. t[93] = 122;
  21640. t[94] = 123;
  21641. t[95] = 124;
  21642. t[96] = 125;
  21643. t[97] = 126;
  21644. t[98] = 196;
  21645. t[99] = 197;
  21646. t[100] = 199;
  21647. t[101] = 201;
  21648. t[102] = 209;
  21649. t[103] = 214;
  21650. t[104] = 220;
  21651. t[105] = 225;
  21652. t[106] = 224;
  21653. t[107] = 226;
  21654. t[108] = 228;
  21655. t[109] = 227;
  21656. t[110] = 229;
  21657. t[111] = 231;
  21658. t[112] = 233;
  21659. t[113] = 232;
  21660. t[114] = 234;
  21661. t[115] = 235;
  21662. t[116] = 237;
  21663. t[117] = 236;
  21664. t[118] = 238;
  21665. t[119] = 239;
  21666. t[120] = 241;
  21667. t[121] = 243;
  21668. t[122] = 242;
  21669. t[123] = 244;
  21670. t[124] = 246;
  21671. t[125] = 245;
  21672. t[126] = 250;
  21673. t[127] = 249;
  21674. t[128] = 251;
  21675. t[129] = 252;
  21676. t[130] = 8224;
  21677. t[131] = 176;
  21678. t[132] = 162;
  21679. t[133] = 163;
  21680. t[134] = 167;
  21681. t[135] = 8226;
  21682. t[136] = 182;
  21683. t[137] = 223;
  21684. t[138] = 174;
  21685. t[139] = 169;
  21686. t[140] = 8482;
  21687. t[141] = 180;
  21688. t[142] = 168;
  21689. t[143] = 8800;
  21690. t[144] = 198;
  21691. t[145] = 216;
  21692. t[146] = 8734;
  21693. t[147] = 177;
  21694. t[148] = 8804;
  21695. t[149] = 8805;
  21696. t[150] = 165;
  21697. t[151] = 181;
  21698. t[152] = 8706;
  21699. t[153] = 8721;
  21700. t[154] = 8719;
  21701. t[156] = 8747;
  21702. t[157] = 170;
  21703. t[158] = 186;
  21704. t[159] = 8486;
  21705. t[160] = 230;
  21706. t[161] = 248;
  21707. t[162] = 191;
  21708. t[163] = 161;
  21709. t[164] = 172;
  21710. t[165] = 8730;
  21711. t[166] = 402;
  21712. t[167] = 8776;
  21713. t[168] = 8710;
  21714. t[169] = 171;
  21715. t[170] = 187;
  21716. t[171] = 8230;
  21717. t[210] = 218;
  21718. t[223] = 711;
  21719. t[224] = 321;
  21720. t[225] = 322;
  21721. t[227] = 353;
  21722. t[229] = 382;
  21723. t[234] = 253;
  21724. t[252] = 263;
  21725. t[253] = 268;
  21726. t[254] = 269;
  21727. t[258] = 258;
  21728. t[260] = 260;
  21729. t[261] = 261;
  21730. t[265] = 280;
  21731. t[266] = 281;
  21732. t[268] = 283;
  21733. t[269] = 313;
  21734. t[275] = 323;
  21735. t[276] = 324;
  21736. t[278] = 328;
  21737. t[284] = 345;
  21738. t[285] = 346;
  21739. t[286] = 347;
  21740. t[292] = 367;
  21741. t[295] = 377;
  21742. t[296] = 378;
  21743. t[298] = 380;
  21744. t[305] = 963;
  21745. t[306] = 964;
  21746. t[307] = 966;
  21747. t[308] = 8215;
  21748. t[309] = 8252;
  21749. t[310] = 8319;
  21750. t[311] = 8359;
  21751. t[312] = 8592;
  21752. t[313] = 8593;
  21753. t[337] = 9552;
  21754. t[493] = 1039;
  21755. t[494] = 1040;
  21756. t[705] = 1524;
  21757. t[706] = 8362;
  21758. t[710] = 64288;
  21759. t[711] = 64298;
  21760. t[759] = 1617;
  21761. t[761] = 1776;
  21762. t[763] = 1778;
  21763. t[775] = 1652;
  21764. t[777] = 1764;
  21765. t[778] = 1780;
  21766. t[779] = 1781;
  21767. t[780] = 1782;
  21768. t[782] = 771;
  21769. t[783] = 64726;
  21770. t[786] = 8363;
  21771. t[788] = 8532;
  21772. t[790] = 768;
  21773. t[791] = 769;
  21774. t[792] = 768;
  21775. t[795] = 803;
  21776. t[797] = 64336;
  21777. t[798] = 64337;
  21778. t[799] = 64342;
  21779. t[800] = 64343;
  21780. t[801] = 64344;
  21781. t[802] = 64345;
  21782. t[803] = 64362;
  21783. t[804] = 64363;
  21784. t[805] = 64364;
  21785. t[2424] = 7821;
  21786. t[2425] = 7822;
  21787. t[2426] = 7823;
  21788. t[2427] = 7824;
  21789. t[2428] = 7825;
  21790. t[2429] = 7826;
  21791. t[2430] = 7827;
  21792. t[2433] = 7682;
  21793. t[2678] = 8045;
  21794. t[2679] = 8046;
  21795. t[2830] = 1552;
  21796. t[2838] = 686;
  21797. t[2840] = 751;
  21798. t[2842] = 753;
  21799. t[2843] = 754;
  21800. t[2844] = 755;
  21801. t[2846] = 757;
  21802. t[2856] = 767;
  21803. t[2857] = 848;
  21804. t[2858] = 849;
  21805. t[2862] = 853;
  21806. t[2863] = 854;
  21807. t[2864] = 855;
  21808. t[2865] = 861;
  21809. t[2866] = 862;
  21810. t[2906] = 7460;
  21811. t[2908] = 7462;
  21812. t[2909] = 7463;
  21813. t[2910] = 7464;
  21814. t[2912] = 7466;
  21815. t[2913] = 7467;
  21816. t[2914] = 7468;
  21817. t[2916] = 7470;
  21818. t[2917] = 7471;
  21819. t[2918] = 7472;
  21820. t[2920] = 7474;
  21821. t[2921] = 7475;
  21822. t[2922] = 7476;
  21823. t[2924] = 7478;
  21824. t[2925] = 7479;
  21825. t[2926] = 7480;
  21826. t[2928] = 7482;
  21827. t[2929] = 7483;
  21828. t[2930] = 7484;
  21829. t[2932] = 7486;
  21830. t[2933] = 7487;
  21831. t[2934] = 7488;
  21832. t[2936] = 7490;
  21833. t[2937] = 7491;
  21834. t[2938] = 7492;
  21835. t[2940] = 7494;
  21836. t[2941] = 7495;
  21837. t[2942] = 7496;
  21838. t[2944] = 7498;
  21839. t[2946] = 7500;
  21840. t[2948] = 7502;
  21841. t[2950] = 7504;
  21842. t[2951] = 7505;
  21843. t[2952] = 7506;
  21844. t[2954] = 7508;
  21845. t[2955] = 7509;
  21846. t[2956] = 7510;
  21847. t[2958] = 7512;
  21848. t[2959] = 7513;
  21849. t[2960] = 7514;
  21850. t[2962] = 7516;
  21851. t[2963] = 7517;
  21852. t[2964] = 7518;
  21853. t[2966] = 7520;
  21854. t[2967] = 7521;
  21855. t[2968] = 7522;
  21856. t[2970] = 7524;
  21857. t[2971] = 7525;
  21858. t[2972] = 7526;
  21859. t[2974] = 7528;
  21860. t[2975] = 7529;
  21861. t[2976] = 7530;
  21862. t[2978] = 1537;
  21863. t[2979] = 1538;
  21864. t[2980] = 1539;
  21865. t[2982] = 1549;
  21866. t[2983] = 1551;
  21867. t[2984] = 1552;
  21868. t[2986] = 1554;
  21869. t[2987] = 1555;
  21870. t[2988] = 1556;
  21871. t[2990] = 1623;
  21872. t[2991] = 1624;
  21873. t[2995] = 1775;
  21874. t[2999] = 1791;
  21875. t[3002] = 64290;
  21876. t[3003] = 64291;
  21877. t[3004] = 64292;
  21878. t[3006] = 64294;
  21879. t[3007] = 64295;
  21880. t[3008] = 64296;
  21881. t[3011] = 1900;
  21882. t[3014] = 8223;
  21883. t[3015] = 8244;
  21884. t[3017] = 7532;
  21885. t[3018] = 7533;
  21886. t[3019] = 7534;
  21887. t[3075] = 7590;
  21888. t[3076] = 7591;
  21889. t[3079] = 7594;
  21890. t[3080] = 7595;
  21891. t[3083] = 7598;
  21892. t[3084] = 7599;
  21893. t[3087] = 7602;
  21894. t[3088] = 7603;
  21895. t[3091] = 7606;
  21896. t[3092] = 7607;
  21897. t[3095] = 7610;
  21898. t[3096] = 7611;
  21899. t[3099] = 7614;
  21900. t[3100] = 7615;
  21901. t[3103] = 7618;
  21902. t[3104] = 7619;
  21903. t[3107] = 8337;
  21904. t[3108] = 8338;
  21905. t[3116] = 1884;
  21906. t[3119] = 1885;
  21907. t[3120] = 1885;
  21908. t[3123] = 1886;
  21909. t[3124] = 1886;
  21910. t[3127] = 1887;
  21911. t[3128] = 1887;
  21912. t[3131] = 1888;
  21913. t[3132] = 1888;
  21914. t[3135] = 1889;
  21915. t[3136] = 1889;
  21916. t[3139] = 1890;
  21917. t[3140] = 1890;
  21918. t[3143] = 1891;
  21919. t[3144] = 1891;
  21920. t[3147] = 1892;
  21921. t[3148] = 1892;
  21922. t[3153] = 580;
  21923. t[3154] = 581;
  21924. t[3157] = 584;
  21925. t[3158] = 585;
  21926. t[3161] = 588;
  21927. t[3162] = 589;
  21928. t[3165] = 891;
  21929. t[3166] = 892;
  21930. t[3169] = 1274;
  21931. t[3170] = 1275;
  21932. t[3173] = 1278;
  21933. t[3174] = 1279;
  21934. t[3181] = 7622;
  21935. t[3182] = 7623;
  21936. t[3282] = 11799;
  21937. t[3316] = 578;
  21938. t[3379] = 42785;
  21939. t[3393] = 1159;
  21940. t[3416] = 8377;
  21941. });
  21942. // The glyph map for ArialBlack differs slightly from the glyph map used for
  21943. // other well-known standard fonts. Hence we use this (incomplete) CID to GID
  21944. // mapping to adjust the glyph map for non-embedded ArialBlack fonts.
  21945. var getSupplementalGlyphMapForArialBlack = getLookupTableFactory(function (t) {
  21946. t[227] = 322;
  21947. t[264] = 261;
  21948. t[291] = 346;
  21949. });
  21950. exports.getStdFontMap = getStdFontMap;
  21951. exports.getNonStdFontMap = getNonStdFontMap;
  21952. exports.getSerifFonts = getSerifFonts;
  21953. exports.getSymbolsFonts = getSymbolsFonts;
  21954. exports.getGlyphMapForStandardFonts = getGlyphMapForStandardFonts;
  21955. exports.getSupplementalGlyphMapForArialBlack = getSupplementalGlyphMapForArialBlack;
  21956. }));
  21957. (function (root, factory) {
  21958. factory(root.pdfjsCoreUnicode = {}, root.pdfjsSharedUtil);
  21959. }(this, function (exports, sharedUtil) {
  21960. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  21961. // Some characters, e.g. copyrightserif, are mapped to the private use area
  21962. // and might not be displayed using standard fonts. Mapping/hacking well-known
  21963. // chars to the similar equivalents in the normal characters range.
  21964. var getSpecialPUASymbols = getLookupTableFactory(function (t) {
  21965. t[63721] = 0x00A9;
  21966. // copyrightsans (0xF8E9) => copyright
  21967. t[63193] = 0x00A9;
  21968. // copyrightserif (0xF6D9) => copyright
  21969. t[63720] = 0x00AE;
  21970. // registersans (0xF8E8) => registered
  21971. t[63194] = 0x00AE;
  21972. // registerserif (0xF6DA) => registered
  21973. t[63722] = 0x2122;
  21974. // trademarksans (0xF8EA) => trademark
  21975. t[63195] = 0x2122;
  21976. // trademarkserif (0xF6DB) => trademark
  21977. t[63729] = 0x23A7;
  21978. // bracelefttp (0xF8F1)
  21979. t[63730] = 0x23A8;
  21980. // braceleftmid (0xF8F2)
  21981. t[63731] = 0x23A9;
  21982. // braceleftbt (0xF8F3)
  21983. t[63740] = 0x23AB;
  21984. // bracerighttp (0xF8FC)
  21985. t[63741] = 0x23AC;
  21986. // bracerightmid (0xF8FD)
  21987. t[63742] = 0x23AD;
  21988. // bracerightbt (0xF8FE)
  21989. t[63726] = 0x23A1;
  21990. // bracketlefttp (0xF8EE)
  21991. t[63727] = 0x23A2;
  21992. // bracketleftex (0xF8EF)
  21993. t[63728] = 0x23A3;
  21994. // bracketleftbt (0xF8F0)
  21995. t[63737] = 0x23A4;
  21996. // bracketrighttp (0xF8F9)
  21997. t[63738] = 0x23A5;
  21998. // bracketrightex (0xF8FA)
  21999. t[63739] = 0x23A6;
  22000. // bracketrightbt (0xF8FB)
  22001. t[63723] = 0x239B;
  22002. // parenlefttp (0xF8EB)
  22003. t[63724] = 0x239C;
  22004. // parenleftex (0xF8EC)
  22005. t[63725] = 0x239D;
  22006. // parenleftbt (0xF8ED)
  22007. t[63734] = 0x239E;
  22008. // parenrighttp (0xF8F6)
  22009. t[63735] = 0x239F;
  22010. // parenrightex (0xF8F7)
  22011. t[63736] = 0x23A0;
  22012. });
  22013. // parenrightbt (0xF8F8)
  22014. function mapSpecialUnicodeValues(code) {
  22015. if (code >= 0xFFF0 && code <= 0xFFFF) {
  22016. // Specials unicode block.
  22017. return 0;
  22018. } else if (code >= 0xF600 && code <= 0xF8FF) {
  22019. return getSpecialPUASymbols()[code] || code;
  22020. }
  22021. return code;
  22022. }
  22023. function getUnicodeForGlyph(name, glyphsUnicodeMap) {
  22024. var unicode = glyphsUnicodeMap[name];
  22025. if (unicode !== undefined) {
  22026. return unicode;
  22027. }
  22028. if (!name) {
  22029. return -1;
  22030. }
  22031. // Try to recover valid Unicode values from 'uniXXXX'/'uXXXX{XX}' glyphs.
  22032. if (name[0] === 'u') {
  22033. var nameLen = name.length, hexStr;
  22034. if (nameLen === 7 && name[1] === 'n' && name[2] === 'i') {
  22035. // 'uniXXXX'
  22036. hexStr = name.substr(3);
  22037. } else if (nameLen >= 5 && nameLen <= 7) {
  22038. // 'uXXXX{XX}'
  22039. hexStr = name.substr(1);
  22040. } else {
  22041. return -1;
  22042. }
  22043. // Check for upper-case hexadecimal characters, to avoid false positives.
  22044. if (hexStr === hexStr.toUpperCase()) {
  22045. unicode = parseInt(hexStr, 16);
  22046. if (unicode >= 0) {
  22047. return unicode;
  22048. }
  22049. }
  22050. }
  22051. return -1;
  22052. }
  22053. var UnicodeRanges = [
  22054. {
  22055. 'begin': 0x0000,
  22056. 'end': 0x007F
  22057. },
  22058. // Basic Latin
  22059. {
  22060. 'begin': 0x0080,
  22061. 'end': 0x00FF
  22062. },
  22063. // Latin-1 Supplement
  22064. {
  22065. 'begin': 0x0100,
  22066. 'end': 0x017F
  22067. },
  22068. // Latin Extended-A
  22069. {
  22070. 'begin': 0x0180,
  22071. 'end': 0x024F
  22072. },
  22073. // Latin Extended-B
  22074. {
  22075. 'begin': 0x0250,
  22076. 'end': 0x02AF
  22077. },
  22078. // IPA Extensions
  22079. {
  22080. 'begin': 0x02B0,
  22081. 'end': 0x02FF
  22082. },
  22083. // Spacing Modifier Letters
  22084. {
  22085. 'begin': 0x0300,
  22086. 'end': 0x036F
  22087. },
  22088. // Combining Diacritical Marks
  22089. {
  22090. 'begin': 0x0370,
  22091. 'end': 0x03FF
  22092. },
  22093. // Greek and Coptic
  22094. {
  22095. 'begin': 0x2C80,
  22096. 'end': 0x2CFF
  22097. },
  22098. // Coptic
  22099. {
  22100. 'begin': 0x0400,
  22101. 'end': 0x04FF
  22102. },
  22103. // Cyrillic
  22104. {
  22105. 'begin': 0x0530,
  22106. 'end': 0x058F
  22107. },
  22108. // Armenian
  22109. {
  22110. 'begin': 0x0590,
  22111. 'end': 0x05FF
  22112. },
  22113. // Hebrew
  22114. {
  22115. 'begin': 0xA500,
  22116. 'end': 0xA63F
  22117. },
  22118. // Vai
  22119. {
  22120. 'begin': 0x0600,
  22121. 'end': 0x06FF
  22122. },
  22123. // Arabic
  22124. {
  22125. 'begin': 0x07C0,
  22126. 'end': 0x07FF
  22127. },
  22128. // NKo
  22129. {
  22130. 'begin': 0x0900,
  22131. 'end': 0x097F
  22132. },
  22133. // Devanagari
  22134. {
  22135. 'begin': 0x0980,
  22136. 'end': 0x09FF
  22137. },
  22138. // Bengali
  22139. {
  22140. 'begin': 0x0A00,
  22141. 'end': 0x0A7F
  22142. },
  22143. // Gurmukhi
  22144. {
  22145. 'begin': 0x0A80,
  22146. 'end': 0x0AFF
  22147. },
  22148. // Gujarati
  22149. {
  22150. 'begin': 0x0B00,
  22151. 'end': 0x0B7F
  22152. },
  22153. // Oriya
  22154. {
  22155. 'begin': 0x0B80,
  22156. 'end': 0x0BFF
  22157. },
  22158. // Tamil
  22159. {
  22160. 'begin': 0x0C00,
  22161. 'end': 0x0C7F
  22162. },
  22163. // Telugu
  22164. {
  22165. 'begin': 0x0C80,
  22166. 'end': 0x0CFF
  22167. },
  22168. // Kannada
  22169. {
  22170. 'begin': 0x0D00,
  22171. 'end': 0x0D7F
  22172. },
  22173. // Malayalam
  22174. {
  22175. 'begin': 0x0E00,
  22176. 'end': 0x0E7F
  22177. },
  22178. // Thai
  22179. {
  22180. 'begin': 0x0E80,
  22181. 'end': 0x0EFF
  22182. },
  22183. // Lao
  22184. {
  22185. 'begin': 0x10A0,
  22186. 'end': 0x10FF
  22187. },
  22188. // Georgian
  22189. {
  22190. 'begin': 0x1B00,
  22191. 'end': 0x1B7F
  22192. },
  22193. // Balinese
  22194. {
  22195. 'begin': 0x1100,
  22196. 'end': 0x11FF
  22197. },
  22198. // Hangul Jamo
  22199. {
  22200. 'begin': 0x1E00,
  22201. 'end': 0x1EFF
  22202. },
  22203. // Latin Extended Additional
  22204. {
  22205. 'begin': 0x1F00,
  22206. 'end': 0x1FFF
  22207. },
  22208. // Greek Extended
  22209. {
  22210. 'begin': 0x2000,
  22211. 'end': 0x206F
  22212. },
  22213. // General Punctuation
  22214. {
  22215. 'begin': 0x2070,
  22216. 'end': 0x209F
  22217. },
  22218. // Superscripts And Subscripts
  22219. {
  22220. 'begin': 0x20A0,
  22221. 'end': 0x20CF
  22222. },
  22223. // Currency Symbol
  22224. {
  22225. 'begin': 0x20D0,
  22226. 'end': 0x20FF
  22227. },
  22228. // Combining Diacritical Marks
  22229. {
  22230. 'begin': 0x2100,
  22231. 'end': 0x214F
  22232. },
  22233. // Letterlike Symbols
  22234. {
  22235. 'begin': 0x2150,
  22236. 'end': 0x218F
  22237. },
  22238. // Number Forms
  22239. {
  22240. 'begin': 0x2190,
  22241. 'end': 0x21FF
  22242. },
  22243. // Arrows
  22244. {
  22245. 'begin': 0x2200,
  22246. 'end': 0x22FF
  22247. },
  22248. // Mathematical Operators
  22249. {
  22250. 'begin': 0x2300,
  22251. 'end': 0x23FF
  22252. },
  22253. // Miscellaneous Technical
  22254. {
  22255. 'begin': 0x2400,
  22256. 'end': 0x243F
  22257. },
  22258. // Control Pictures
  22259. {
  22260. 'begin': 0x2440,
  22261. 'end': 0x245F
  22262. },
  22263. // Optical Character Recognition
  22264. {
  22265. 'begin': 0x2460,
  22266. 'end': 0x24FF
  22267. },
  22268. // Enclosed Alphanumerics
  22269. {
  22270. 'begin': 0x2500,
  22271. 'end': 0x257F
  22272. },
  22273. // Box Drawing
  22274. {
  22275. 'begin': 0x2580,
  22276. 'end': 0x259F
  22277. },
  22278. // Block Elements
  22279. {
  22280. 'begin': 0x25A0,
  22281. 'end': 0x25FF
  22282. },
  22283. // Geometric Shapes
  22284. {
  22285. 'begin': 0x2600,
  22286. 'end': 0x26FF
  22287. },
  22288. // Miscellaneous Symbols
  22289. {
  22290. 'begin': 0x2700,
  22291. 'end': 0x27BF
  22292. },
  22293. // Dingbats
  22294. {
  22295. 'begin': 0x3000,
  22296. 'end': 0x303F
  22297. },
  22298. // CJK Symbols And Punctuation
  22299. {
  22300. 'begin': 0x3040,
  22301. 'end': 0x309F
  22302. },
  22303. // Hiragana
  22304. {
  22305. 'begin': 0x30A0,
  22306. 'end': 0x30FF
  22307. },
  22308. // Katakana
  22309. {
  22310. 'begin': 0x3100,
  22311. 'end': 0x312F
  22312. },
  22313. // Bopomofo
  22314. {
  22315. 'begin': 0x3130,
  22316. 'end': 0x318F
  22317. },
  22318. // Hangul Compatibility Jamo
  22319. {
  22320. 'begin': 0xA840,
  22321. 'end': 0xA87F
  22322. },
  22323. // Phags-pa
  22324. {
  22325. 'begin': 0x3200,
  22326. 'end': 0x32FF
  22327. },
  22328. // Enclosed CJK Letters And Months
  22329. {
  22330. 'begin': 0x3300,
  22331. 'end': 0x33FF
  22332. },
  22333. // CJK Compatibility
  22334. {
  22335. 'begin': 0xAC00,
  22336. 'end': 0xD7AF
  22337. },
  22338. // Hangul Syllables
  22339. {
  22340. 'begin': 0xD800,
  22341. 'end': 0xDFFF
  22342. },
  22343. // Non-Plane 0 *
  22344. {
  22345. 'begin': 0x10900,
  22346. 'end': 0x1091F
  22347. },
  22348. // Phoenicia
  22349. {
  22350. 'begin': 0x4E00,
  22351. 'end': 0x9FFF
  22352. },
  22353. // CJK Unified Ideographs
  22354. {
  22355. 'begin': 0xE000,
  22356. 'end': 0xF8FF
  22357. },
  22358. // Private Use Area (plane 0)
  22359. {
  22360. 'begin': 0x31C0,
  22361. 'end': 0x31EF
  22362. },
  22363. // CJK Strokes
  22364. {
  22365. 'begin': 0xFB00,
  22366. 'end': 0xFB4F
  22367. },
  22368. // Alphabetic Presentation Forms
  22369. {
  22370. 'begin': 0xFB50,
  22371. 'end': 0xFDFF
  22372. },
  22373. // Arabic Presentation Forms-A
  22374. {
  22375. 'begin': 0xFE20,
  22376. 'end': 0xFE2F
  22377. },
  22378. // Combining Half Marks
  22379. {
  22380. 'begin': 0xFE10,
  22381. 'end': 0xFE1F
  22382. },
  22383. // Vertical Forms
  22384. {
  22385. 'begin': 0xFE50,
  22386. 'end': 0xFE6F
  22387. },
  22388. // Small Form Variants
  22389. {
  22390. 'begin': 0xFE70,
  22391. 'end': 0xFEFF
  22392. },
  22393. // Arabic Presentation Forms-B
  22394. {
  22395. 'begin': 0xFF00,
  22396. 'end': 0xFFEF
  22397. },
  22398. // Halfwidth And Fullwidth Forms
  22399. {
  22400. 'begin': 0xFFF0,
  22401. 'end': 0xFFFF
  22402. },
  22403. // Specials
  22404. {
  22405. 'begin': 0x0F00,
  22406. 'end': 0x0FFF
  22407. },
  22408. // Tibetan
  22409. {
  22410. 'begin': 0x0700,
  22411. 'end': 0x074F
  22412. },
  22413. // Syriac
  22414. {
  22415. 'begin': 0x0780,
  22416. 'end': 0x07BF
  22417. },
  22418. // Thaana
  22419. {
  22420. 'begin': 0x0D80,
  22421. 'end': 0x0DFF
  22422. },
  22423. // Sinhala
  22424. {
  22425. 'begin': 0x1000,
  22426. 'end': 0x109F
  22427. },
  22428. // Myanmar
  22429. {
  22430. 'begin': 0x1200,
  22431. 'end': 0x137F
  22432. },
  22433. // Ethiopic
  22434. {
  22435. 'begin': 0x13A0,
  22436. 'end': 0x13FF
  22437. },
  22438. // Cherokee
  22439. {
  22440. 'begin': 0x1400,
  22441. 'end': 0x167F
  22442. },
  22443. // Unified Canadian Aboriginal Syllabics
  22444. {
  22445. 'begin': 0x1680,
  22446. 'end': 0x169F
  22447. },
  22448. // Ogham
  22449. {
  22450. 'begin': 0x16A0,
  22451. 'end': 0x16FF
  22452. },
  22453. // Runic
  22454. {
  22455. 'begin': 0x1780,
  22456. 'end': 0x17FF
  22457. },
  22458. // Khmer
  22459. {
  22460. 'begin': 0x1800,
  22461. 'end': 0x18AF
  22462. },
  22463. // Mongolian
  22464. {
  22465. 'begin': 0x2800,
  22466. 'end': 0x28FF
  22467. },
  22468. // Braille Patterns
  22469. {
  22470. 'begin': 0xA000,
  22471. 'end': 0xA48F
  22472. },
  22473. // Yi Syllables
  22474. {
  22475. 'begin': 0x1700,
  22476. 'end': 0x171F
  22477. },
  22478. // Tagalog
  22479. {
  22480. 'begin': 0x10300,
  22481. 'end': 0x1032F
  22482. },
  22483. // Old Italic
  22484. {
  22485. 'begin': 0x10330,
  22486. 'end': 0x1034F
  22487. },
  22488. // Gothic
  22489. {
  22490. 'begin': 0x10400,
  22491. 'end': 0x1044F
  22492. },
  22493. // Deseret
  22494. {
  22495. 'begin': 0x1D000,
  22496. 'end': 0x1D0FF
  22497. },
  22498. // Byzantine Musical Symbols
  22499. {
  22500. 'begin': 0x1D400,
  22501. 'end': 0x1D7FF
  22502. },
  22503. // Mathematical Alphanumeric Symbols
  22504. {
  22505. 'begin': 0xFF000,
  22506. 'end': 0xFFFFD
  22507. },
  22508. // Private Use (plane 15)
  22509. {
  22510. 'begin': 0xFE00,
  22511. 'end': 0xFE0F
  22512. },
  22513. // Variation Selectors
  22514. {
  22515. 'begin': 0xE0000,
  22516. 'end': 0xE007F
  22517. },
  22518. // Tags
  22519. {
  22520. 'begin': 0x1900,
  22521. 'end': 0x194F
  22522. },
  22523. // Limbu
  22524. {
  22525. 'begin': 0x1950,
  22526. 'end': 0x197F
  22527. },
  22528. // Tai Le
  22529. {
  22530. 'begin': 0x1980,
  22531. 'end': 0x19DF
  22532. },
  22533. // New Tai Lue
  22534. {
  22535. 'begin': 0x1A00,
  22536. 'end': 0x1A1F
  22537. },
  22538. // Buginese
  22539. {
  22540. 'begin': 0x2C00,
  22541. 'end': 0x2C5F
  22542. },
  22543. // Glagolitic
  22544. {
  22545. 'begin': 0x2D30,
  22546. 'end': 0x2D7F
  22547. },
  22548. // Tifinagh
  22549. {
  22550. 'begin': 0x4DC0,
  22551. 'end': 0x4DFF
  22552. },
  22553. // Yijing Hexagram Symbols
  22554. {
  22555. 'begin': 0xA800,
  22556. 'end': 0xA82F
  22557. },
  22558. // Syloti Nagri
  22559. {
  22560. 'begin': 0x10000,
  22561. 'end': 0x1007F
  22562. },
  22563. // Linear B Syllabary
  22564. {
  22565. 'begin': 0x10140,
  22566. 'end': 0x1018F
  22567. },
  22568. // Ancient Greek Numbers
  22569. {
  22570. 'begin': 0x10380,
  22571. 'end': 0x1039F
  22572. },
  22573. // Ugaritic
  22574. {
  22575. 'begin': 0x103A0,
  22576. 'end': 0x103DF
  22577. },
  22578. // Old Persian
  22579. {
  22580. 'begin': 0x10450,
  22581. 'end': 0x1047F
  22582. },
  22583. // Shavian
  22584. {
  22585. 'begin': 0x10480,
  22586. 'end': 0x104AF
  22587. },
  22588. // Osmanya
  22589. {
  22590. 'begin': 0x10800,
  22591. 'end': 0x1083F
  22592. },
  22593. // Cypriot Syllabary
  22594. {
  22595. 'begin': 0x10A00,
  22596. 'end': 0x10A5F
  22597. },
  22598. // Kharoshthi
  22599. {
  22600. 'begin': 0x1D300,
  22601. 'end': 0x1D35F
  22602. },
  22603. // Tai Xuan Jing Symbols
  22604. {
  22605. 'begin': 0x12000,
  22606. 'end': 0x123FF
  22607. },
  22608. // Cuneiform
  22609. {
  22610. 'begin': 0x1D360,
  22611. 'end': 0x1D37F
  22612. },
  22613. // Counting Rod Numerals
  22614. {
  22615. 'begin': 0x1B80,
  22616. 'end': 0x1BBF
  22617. },
  22618. // Sundanese
  22619. {
  22620. 'begin': 0x1C00,
  22621. 'end': 0x1C4F
  22622. },
  22623. // Lepcha
  22624. {
  22625. 'begin': 0x1C50,
  22626. 'end': 0x1C7F
  22627. },
  22628. // Ol Chiki
  22629. {
  22630. 'begin': 0xA880,
  22631. 'end': 0xA8DF
  22632. },
  22633. // Saurashtra
  22634. {
  22635. 'begin': 0xA900,
  22636. 'end': 0xA92F
  22637. },
  22638. // Kayah Li
  22639. {
  22640. 'begin': 0xA930,
  22641. 'end': 0xA95F
  22642. },
  22643. // Rejang
  22644. {
  22645. 'begin': 0xAA00,
  22646. 'end': 0xAA5F
  22647. },
  22648. // Cham
  22649. {
  22650. 'begin': 0x10190,
  22651. 'end': 0x101CF
  22652. },
  22653. // Ancient Symbols
  22654. {
  22655. 'begin': 0x101D0,
  22656. 'end': 0x101FF
  22657. },
  22658. // Phaistos Disc
  22659. {
  22660. 'begin': 0x102A0,
  22661. 'end': 0x102DF
  22662. },
  22663. // Carian
  22664. {
  22665. 'begin': 0x1F030,
  22666. 'end': 0x1F09F
  22667. }
  22668. ];
  22669. // Domino Tiles
  22670. function getUnicodeRangeFor(value) {
  22671. for (var i = 0, ii = UnicodeRanges.length; i < ii; i++) {
  22672. var range = UnicodeRanges[i];
  22673. if (value >= range.begin && value < range.end) {
  22674. return i;
  22675. }
  22676. }
  22677. return -1;
  22678. }
  22679. function isRTLRangeFor(value) {
  22680. var range = UnicodeRanges[13];
  22681. if (value >= range.begin && value < range.end) {
  22682. return true;
  22683. }
  22684. range = UnicodeRanges[11];
  22685. if (value >= range.begin && value < range.end) {
  22686. return true;
  22687. }
  22688. return false;
  22689. }
  22690. // The normalization table is obtained by filtering the Unicode characters
  22691. // database with <compat> entries.
  22692. var getNormalizedUnicodes = getLookupTableFactory(function (t) {
  22693. t['\u00A8'] = '\u0020\u0308';
  22694. t['\u00AF'] = '\u0020\u0304';
  22695. t['\u00B4'] = '\u0020\u0301';
  22696. t['\u00B5'] = '\u03BC';
  22697. t['\u00B8'] = '\u0020\u0327';
  22698. t['\u0132'] = '\u0049\u004A';
  22699. t['\u0133'] = '\u0069\u006A';
  22700. t['\u013F'] = '\u004C\u00B7';
  22701. t['\u0140'] = '\u006C\u00B7';
  22702. t['\u0149'] = '\u02BC\u006E';
  22703. t['\u017F'] = '\u0073';
  22704. t['\u01C4'] = '\u0044\u017D';
  22705. t['\u01C5'] = '\u0044\u017E';
  22706. t['\u01C6'] = '\u0064\u017E';
  22707. t['\u01C7'] = '\u004C\u004A';
  22708. t['\u01C8'] = '\u004C\u006A';
  22709. t['\u01C9'] = '\u006C\u006A';
  22710. t['\u01CA'] = '\u004E\u004A';
  22711. t['\u01CB'] = '\u004E\u006A';
  22712. t['\u01CC'] = '\u006E\u006A';
  22713. t['\u01F1'] = '\u0044\u005A';
  22714. t['\u01F2'] = '\u0044\u007A';
  22715. t['\u01F3'] = '\u0064\u007A';
  22716. t['\u02D8'] = '\u0020\u0306';
  22717. t['\u02D9'] = '\u0020\u0307';
  22718. t['\u02DA'] = '\u0020\u030A';
  22719. t['\u02DB'] = '\u0020\u0328';
  22720. t['\u02DC'] = '\u0020\u0303';
  22721. t['\u02DD'] = '\u0020\u030B';
  22722. t['\u037A'] = '\u0020\u0345';
  22723. t['\u0384'] = '\u0020\u0301';
  22724. t['\u03D0'] = '\u03B2';
  22725. t['\u03D1'] = '\u03B8';
  22726. t['\u03D2'] = '\u03A5';
  22727. t['\u03D5'] = '\u03C6';
  22728. t['\u03D6'] = '\u03C0';
  22729. t['\u03F0'] = '\u03BA';
  22730. t['\u03F1'] = '\u03C1';
  22731. t['\u03F2'] = '\u03C2';
  22732. t['\u03F4'] = '\u0398';
  22733. t['\u03F5'] = '\u03B5';
  22734. t['\u03F9'] = '\u03A3';
  22735. t['\u0587'] = '\u0565\u0582';
  22736. t['\u0675'] = '\u0627\u0674';
  22737. t['\u0676'] = '\u0648\u0674';
  22738. t['\u0677'] = '\u06C7\u0674';
  22739. t['\u0678'] = '\u064A\u0674';
  22740. t['\u0E33'] = '\u0E4D\u0E32';
  22741. t['\u0EB3'] = '\u0ECD\u0EB2';
  22742. t['\u0EDC'] = '\u0EAB\u0E99';
  22743. t['\u0EDD'] = '\u0EAB\u0EA1';
  22744. t['\u0F77'] = '\u0FB2\u0F81';
  22745. t['\u0F79'] = '\u0FB3\u0F81';
  22746. t['\u1E9A'] = '\u0061\u02BE';
  22747. t['\u1FBD'] = '\u0020\u0313';
  22748. t['\u1FBF'] = '\u0020\u0313';
  22749. t['\u1FC0'] = '\u0020\u0342';
  22750. t['\u1FFE'] = '\u0020\u0314';
  22751. t['\u2002'] = '\u0020';
  22752. t['\u2003'] = '\u0020';
  22753. t['\u2004'] = '\u0020';
  22754. t['\u2005'] = '\u0020';
  22755. t['\u2006'] = '\u0020';
  22756. t['\u2008'] = '\u0020';
  22757. t['\u2009'] = '\u0020';
  22758. t['\u200A'] = '\u0020';
  22759. t['\u2017'] = '\u0020\u0333';
  22760. t['\u2024'] = '\u002E';
  22761. t['\u2025'] = '\u002E\u002E';
  22762. t['\u2026'] = '\u002E\u002E\u002E';
  22763. t['\u2033'] = '\u2032\u2032';
  22764. t['\u2034'] = '\u2032\u2032\u2032';
  22765. t['\u2036'] = '\u2035\u2035';
  22766. t['\u2037'] = '\u2035\u2035\u2035';
  22767. t['\u203C'] = '\u0021\u0021';
  22768. t['\u203E'] = '\u0020\u0305';
  22769. t['\u2047'] = '\u003F\u003F';
  22770. t['\u2048'] = '\u003F\u0021';
  22771. t['\u2049'] = '\u0021\u003F';
  22772. t['\u2057'] = '\u2032\u2032\u2032\u2032';
  22773. t['\u205F'] = '\u0020';
  22774. t['\u20A8'] = '\u0052\u0073';
  22775. t['\u2100'] = '\u0061\u002F\u0063';
  22776. t['\u2101'] = '\u0061\u002F\u0073';
  22777. t['\u2103'] = '\u00B0\u0043';
  22778. t['\u2105'] = '\u0063\u002F\u006F';
  22779. t['\u2106'] = '\u0063\u002F\u0075';
  22780. t['\u2107'] = '\u0190';
  22781. t['\u2109'] = '\u00B0\u0046';
  22782. t['\u2116'] = '\u004E\u006F';
  22783. t['\u2121'] = '\u0054\u0045\u004C';
  22784. t['\u2135'] = '\u05D0';
  22785. t['\u2136'] = '\u05D1';
  22786. t['\u2137'] = '\u05D2';
  22787. t['\u2138'] = '\u05D3';
  22788. t['\u213B'] = '\u0046\u0041\u0058';
  22789. t['\u2160'] = '\u0049';
  22790. t['\u2161'] = '\u0049\u0049';
  22791. t['\u2162'] = '\u0049\u0049\u0049';
  22792. t['\u2163'] = '\u0049\u0056';
  22793. t['\u2164'] = '\u0056';
  22794. t['\u2165'] = '\u0056\u0049';
  22795. t['\u2166'] = '\u0056\u0049\u0049';
  22796. t['\u2167'] = '\u0056\u0049\u0049\u0049';
  22797. t['\u2168'] = '\u0049\u0058';
  22798. t['\u2169'] = '\u0058';
  22799. t['\u216A'] = '\u0058\u0049';
  22800. t['\u216B'] = '\u0058\u0049\u0049';
  22801. t['\u216C'] = '\u004C';
  22802. t['\u216D'] = '\u0043';
  22803. t['\u216E'] = '\u0044';
  22804. t['\u216F'] = '\u004D';
  22805. t['\u2170'] = '\u0069';
  22806. t['\u2171'] = '\u0069\u0069';
  22807. t['\u2172'] = '\u0069\u0069\u0069';
  22808. t['\u2173'] = '\u0069\u0076';
  22809. t['\u2174'] = '\u0076';
  22810. t['\u2175'] = '\u0076\u0069';
  22811. t['\u2176'] = '\u0076\u0069\u0069';
  22812. t['\u2177'] = '\u0076\u0069\u0069\u0069';
  22813. t['\u2178'] = '\u0069\u0078';
  22814. t['\u2179'] = '\u0078';
  22815. t['\u217A'] = '\u0078\u0069';
  22816. t['\u217B'] = '\u0078\u0069\u0069';
  22817. t['\u217C'] = '\u006C';
  22818. t['\u217D'] = '\u0063';
  22819. t['\u217E'] = '\u0064';
  22820. t['\u217F'] = '\u006D';
  22821. t['\u222C'] = '\u222B\u222B';
  22822. t['\u222D'] = '\u222B\u222B\u222B';
  22823. t['\u222F'] = '\u222E\u222E';
  22824. t['\u2230'] = '\u222E\u222E\u222E';
  22825. t['\u2474'] = '\u0028\u0031\u0029';
  22826. t['\u2475'] = '\u0028\u0032\u0029';
  22827. t['\u2476'] = '\u0028\u0033\u0029';
  22828. t['\u2477'] = '\u0028\u0034\u0029';
  22829. t['\u2478'] = '\u0028\u0035\u0029';
  22830. t['\u2479'] = '\u0028\u0036\u0029';
  22831. t['\u247A'] = '\u0028\u0037\u0029';
  22832. t['\u247B'] = '\u0028\u0038\u0029';
  22833. t['\u247C'] = '\u0028\u0039\u0029';
  22834. t['\u247D'] = '\u0028\u0031\u0030\u0029';
  22835. t['\u247E'] = '\u0028\u0031\u0031\u0029';
  22836. t['\u247F'] = '\u0028\u0031\u0032\u0029';
  22837. t['\u2480'] = '\u0028\u0031\u0033\u0029';
  22838. t['\u2481'] = '\u0028\u0031\u0034\u0029';
  22839. t['\u2482'] = '\u0028\u0031\u0035\u0029';
  22840. t['\u2483'] = '\u0028\u0031\u0036\u0029';
  22841. t['\u2484'] = '\u0028\u0031\u0037\u0029';
  22842. t['\u2485'] = '\u0028\u0031\u0038\u0029';
  22843. t['\u2486'] = '\u0028\u0031\u0039\u0029';
  22844. t['\u2487'] = '\u0028\u0032\u0030\u0029';
  22845. t['\u2488'] = '\u0031\u002E';
  22846. t['\u2489'] = '\u0032\u002E';
  22847. t['\u248A'] = '\u0033\u002E';
  22848. t['\u248B'] = '\u0034\u002E';
  22849. t['\u248C'] = '\u0035\u002E';
  22850. t['\u248D'] = '\u0036\u002E';
  22851. t['\u248E'] = '\u0037\u002E';
  22852. t['\u248F'] = '\u0038\u002E';
  22853. t['\u2490'] = '\u0039\u002E';
  22854. t['\u2491'] = '\u0031\u0030\u002E';
  22855. t['\u2492'] = '\u0031\u0031\u002E';
  22856. t['\u2493'] = '\u0031\u0032\u002E';
  22857. t['\u2494'] = '\u0031\u0033\u002E';
  22858. t['\u2495'] = '\u0031\u0034\u002E';
  22859. t['\u2496'] = '\u0031\u0035\u002E';
  22860. t['\u2497'] = '\u0031\u0036\u002E';
  22861. t['\u2498'] = '\u0031\u0037\u002E';
  22862. t['\u2499'] = '\u0031\u0038\u002E';
  22863. t['\u249A'] = '\u0031\u0039\u002E';
  22864. t['\u249B'] = '\u0032\u0030\u002E';
  22865. t['\u249C'] = '\u0028\u0061\u0029';
  22866. t['\u249D'] = '\u0028\u0062\u0029';
  22867. t['\u249E'] = '\u0028\u0063\u0029';
  22868. t['\u249F'] = '\u0028\u0064\u0029';
  22869. t['\u24A0'] = '\u0028\u0065\u0029';
  22870. t['\u24A1'] = '\u0028\u0066\u0029';
  22871. t['\u24A2'] = '\u0028\u0067\u0029';
  22872. t['\u24A3'] = '\u0028\u0068\u0029';
  22873. t['\u24A4'] = '\u0028\u0069\u0029';
  22874. t['\u24A5'] = '\u0028\u006A\u0029';
  22875. t['\u24A6'] = '\u0028\u006B\u0029';
  22876. t['\u24A7'] = '\u0028\u006C\u0029';
  22877. t['\u24A8'] = '\u0028\u006D\u0029';
  22878. t['\u24A9'] = '\u0028\u006E\u0029';
  22879. t['\u24AA'] = '\u0028\u006F\u0029';
  22880. t['\u24AB'] = '\u0028\u0070\u0029';
  22881. t['\u24AC'] = '\u0028\u0071\u0029';
  22882. t['\u24AD'] = '\u0028\u0072\u0029';
  22883. t['\u24AE'] = '\u0028\u0073\u0029';
  22884. t['\u24AF'] = '\u0028\u0074\u0029';
  22885. t['\u24B0'] = '\u0028\u0075\u0029';
  22886. t['\u24B1'] = '\u0028\u0076\u0029';
  22887. t['\u24B2'] = '\u0028\u0077\u0029';
  22888. t['\u24B3'] = '\u0028\u0078\u0029';
  22889. t['\u24B4'] = '\u0028\u0079\u0029';
  22890. t['\u24B5'] = '\u0028\u007A\u0029';
  22891. t['\u2A0C'] = '\u222B\u222B\u222B\u222B';
  22892. t['\u2A74'] = '\u003A\u003A\u003D';
  22893. t['\u2A75'] = '\u003D\u003D';
  22894. t['\u2A76'] = '\u003D\u003D\u003D';
  22895. t['\u2E9F'] = '\u6BCD';
  22896. t['\u2EF3'] = '\u9F9F';
  22897. t['\u2F00'] = '\u4E00';
  22898. t['\u2F01'] = '\u4E28';
  22899. t['\u2F02'] = '\u4E36';
  22900. t['\u2F03'] = '\u4E3F';
  22901. t['\u2F04'] = '\u4E59';
  22902. t['\u2F05'] = '\u4E85';
  22903. t['\u2F06'] = '\u4E8C';
  22904. t['\u2F07'] = '\u4EA0';
  22905. t['\u2F08'] = '\u4EBA';
  22906. t['\u2F09'] = '\u513F';
  22907. t['\u2F0A'] = '\u5165';
  22908. t['\u2F0B'] = '\u516B';
  22909. t['\u2F0C'] = '\u5182';
  22910. t['\u2F0D'] = '\u5196';
  22911. t['\u2F0E'] = '\u51AB';
  22912. t['\u2F0F'] = '\u51E0';
  22913. t['\u2F10'] = '\u51F5';
  22914. t['\u2F11'] = '\u5200';
  22915. t['\u2F12'] = '\u529B';
  22916. t['\u2F13'] = '\u52F9';
  22917. t['\u2F14'] = '\u5315';
  22918. t['\u2F15'] = '\u531A';
  22919. t['\u2F16'] = '\u5338';
  22920. t['\u2F17'] = '\u5341';
  22921. t['\u2F18'] = '\u535C';
  22922. t['\u2F19'] = '\u5369';
  22923. t['\u2F1A'] = '\u5382';
  22924. t['\u2F1B'] = '\u53B6';
  22925. t['\u2F1C'] = '\u53C8';
  22926. t['\u2F1D'] = '\u53E3';
  22927. t['\u2F1E'] = '\u56D7';
  22928. t['\u2F1F'] = '\u571F';
  22929. t['\u2F20'] = '\u58EB';
  22930. t['\u2F21'] = '\u5902';
  22931. t['\u2F22'] = '\u590A';
  22932. t['\u2F23'] = '\u5915';
  22933. t['\u2F24'] = '\u5927';
  22934. t['\u2F25'] = '\u5973';
  22935. t['\u2F26'] = '\u5B50';
  22936. t['\u2F27'] = '\u5B80';
  22937. t['\u2F28'] = '\u5BF8';
  22938. t['\u2F29'] = '\u5C0F';
  22939. t['\u2F2A'] = '\u5C22';
  22940. t['\u2F2B'] = '\u5C38';
  22941. t['\u2F2C'] = '\u5C6E';
  22942. t['\u2F2D'] = '\u5C71';
  22943. t['\u2F2E'] = '\u5DDB';
  22944. t['\u2F2F'] = '\u5DE5';
  22945. t['\u2F30'] = '\u5DF1';
  22946. t['\u2F31'] = '\u5DFE';
  22947. t['\u2F32'] = '\u5E72';
  22948. t['\u2F33'] = '\u5E7A';
  22949. t['\u2F34'] = '\u5E7F';
  22950. t['\u2F35'] = '\u5EF4';
  22951. t['\u2F36'] = '\u5EFE';
  22952. t['\u2F37'] = '\u5F0B';
  22953. t['\u2F38'] = '\u5F13';
  22954. t['\u2F39'] = '\u5F50';
  22955. t['\u2F3A'] = '\u5F61';
  22956. t['\u2F3B'] = '\u5F73';
  22957. t['\u2F3C'] = '\u5FC3';
  22958. t['\u2F3D'] = '\u6208';
  22959. t['\u2F3E'] = '\u6236';
  22960. t['\u2F3F'] = '\u624B';
  22961. t['\u2F40'] = '\u652F';
  22962. t['\u2F41'] = '\u6534';
  22963. t['\u2F42'] = '\u6587';
  22964. t['\u2F43'] = '\u6597';
  22965. t['\u2F44'] = '\u65A4';
  22966. t['\u2F45'] = '\u65B9';
  22967. t['\u2F46'] = '\u65E0';
  22968. t['\u2F47'] = '\u65E5';
  22969. t['\u2F48'] = '\u66F0';
  22970. t['\u2F49'] = '\u6708';
  22971. t['\u2F4A'] = '\u6728';
  22972. t['\u2F4B'] = '\u6B20';
  22973. t['\u2F4C'] = '\u6B62';
  22974. t['\u2F4D'] = '\u6B79';
  22975. t['\u2F4E'] = '\u6BB3';
  22976. t['\u2F4F'] = '\u6BCB';
  22977. t['\u2F50'] = '\u6BD4';
  22978. t['\u2F51'] = '\u6BDB';
  22979. t['\u2F52'] = '\u6C0F';
  22980. t['\u2F53'] = '\u6C14';
  22981. t['\u2F54'] = '\u6C34';
  22982. t['\u2F55'] = '\u706B';
  22983. t['\u2F56'] = '\u722A';
  22984. t['\u2F57'] = '\u7236';
  22985. t['\u2F58'] = '\u723B';
  22986. t['\u2F59'] = '\u723F';
  22987. t['\u2F5A'] = '\u7247';
  22988. t['\u2F5B'] = '\u7259';
  22989. t['\u2F5C'] = '\u725B';
  22990. t['\u2F5D'] = '\u72AC';
  22991. t['\u2F5E'] = '\u7384';
  22992. t['\u2F5F'] = '\u7389';
  22993. t['\u2F60'] = '\u74DC';
  22994. t['\u2F61'] = '\u74E6';
  22995. t['\u2F62'] = '\u7518';
  22996. t['\u2F63'] = '\u751F';
  22997. t['\u2F64'] = '\u7528';
  22998. t['\u2F65'] = '\u7530';
  22999. t['\u2F66'] = '\u758B';
  23000. t['\u2F67'] = '\u7592';
  23001. t['\u2F68'] = '\u7676';
  23002. t['\u2F69'] = '\u767D';
  23003. t['\u2F6A'] = '\u76AE';
  23004. t['\u2F6B'] = '\u76BF';
  23005. t['\u2F6C'] = '\u76EE';
  23006. t['\u2F6D'] = '\u77DB';
  23007. t['\u2F6E'] = '\u77E2';
  23008. t['\u2F6F'] = '\u77F3';
  23009. t['\u2F70'] = '\u793A';
  23010. t['\u2F71'] = '\u79B8';
  23011. t['\u2F72'] = '\u79BE';
  23012. t['\u2F73'] = '\u7A74';
  23013. t['\u2F74'] = '\u7ACB';
  23014. t['\u2F75'] = '\u7AF9';
  23015. t['\u2F76'] = '\u7C73';
  23016. t['\u2F77'] = '\u7CF8';
  23017. t['\u2F78'] = '\u7F36';
  23018. t['\u2F79'] = '\u7F51';
  23019. t['\u2F7A'] = '\u7F8A';
  23020. t['\u2F7B'] = '\u7FBD';
  23021. t['\u2F7C'] = '\u8001';
  23022. t['\u2F7D'] = '\u800C';
  23023. t['\u2F7E'] = '\u8012';
  23024. t['\u2F7F'] = '\u8033';
  23025. t['\u2F80'] = '\u807F';
  23026. t['\u2F81'] = '\u8089';
  23027. t['\u2F82'] = '\u81E3';
  23028. t['\u2F83'] = '\u81EA';
  23029. t['\u2F84'] = '\u81F3';
  23030. t['\u2F85'] = '\u81FC';
  23031. t['\u2F86'] = '\u820C';
  23032. t['\u2F87'] = '\u821B';
  23033. t['\u2F88'] = '\u821F';
  23034. t['\u2F89'] = '\u826E';
  23035. t['\u2F8A'] = '\u8272';
  23036. t['\u2F8B'] = '\u8278';
  23037. t['\u2F8C'] = '\u864D';
  23038. t['\u2F8D'] = '\u866B';
  23039. t['\u2F8E'] = '\u8840';
  23040. t['\u2F8F'] = '\u884C';
  23041. t['\u2F90'] = '\u8863';
  23042. t['\u2F91'] = '\u897E';
  23043. t['\u2F92'] = '\u898B';
  23044. t['\u2F93'] = '\u89D2';
  23045. t['\u2F94'] = '\u8A00';
  23046. t['\u2F95'] = '\u8C37';
  23047. t['\u2F96'] = '\u8C46';
  23048. t['\u2F97'] = '\u8C55';
  23049. t['\u2F98'] = '\u8C78';
  23050. t['\u2F99'] = '\u8C9D';
  23051. t['\u2F9A'] = '\u8D64';
  23052. t['\u2F9B'] = '\u8D70';
  23053. t['\u2F9C'] = '\u8DB3';
  23054. t['\u2F9D'] = '\u8EAB';
  23055. t['\u2F9E'] = '\u8ECA';
  23056. t['\u2F9F'] = '\u8F9B';
  23057. t['\u2FA0'] = '\u8FB0';
  23058. t['\u2FA1'] = '\u8FB5';
  23059. t['\u2FA2'] = '\u9091';
  23060. t['\u2FA3'] = '\u9149';
  23061. t['\u2FA4'] = '\u91C6';
  23062. t['\u2FA5'] = '\u91CC';
  23063. t['\u2FA6'] = '\u91D1';
  23064. t['\u2FA7'] = '\u9577';
  23065. t['\u2FA8'] = '\u9580';
  23066. t['\u2FA9'] = '\u961C';
  23067. t['\u2FAA'] = '\u96B6';
  23068. t['\u2FAB'] = '\u96B9';
  23069. t['\u2FAC'] = '\u96E8';
  23070. t['\u2FAD'] = '\u9751';
  23071. t['\u2FAE'] = '\u975E';
  23072. t['\u2FAF'] = '\u9762';
  23073. t['\u2FB0'] = '\u9769';
  23074. t['\u2FB1'] = '\u97CB';
  23075. t['\u2FB2'] = '\u97ED';
  23076. t['\u2FB3'] = '\u97F3';
  23077. t['\u2FB4'] = '\u9801';
  23078. t['\u2FB5'] = '\u98A8';
  23079. t['\u2FB6'] = '\u98DB';
  23080. t['\u2FB7'] = '\u98DF';
  23081. t['\u2FB8'] = '\u9996';
  23082. t['\u2FB9'] = '\u9999';
  23083. t['\u2FBA'] = '\u99AC';
  23084. t['\u2FBB'] = '\u9AA8';
  23085. t['\u2FBC'] = '\u9AD8';
  23086. t['\u2FBD'] = '\u9ADF';
  23087. t['\u2FBE'] = '\u9B25';
  23088. t['\u2FBF'] = '\u9B2F';
  23089. t['\u2FC0'] = '\u9B32';
  23090. t['\u2FC1'] = '\u9B3C';
  23091. t['\u2FC2'] = '\u9B5A';
  23092. t['\u2FC3'] = '\u9CE5';
  23093. t['\u2FC4'] = '\u9E75';
  23094. t['\u2FC5'] = '\u9E7F';
  23095. t['\u2FC6'] = '\u9EA5';
  23096. t['\u2FC7'] = '\u9EBB';
  23097. t['\u2FC8'] = '\u9EC3';
  23098. t['\u2FC9'] = '\u9ECD';
  23099. t['\u2FCA'] = '\u9ED1';
  23100. t['\u2FCB'] = '\u9EF9';
  23101. t['\u2FCC'] = '\u9EFD';
  23102. t['\u2FCD'] = '\u9F0E';
  23103. t['\u2FCE'] = '\u9F13';
  23104. t['\u2FCF'] = '\u9F20';
  23105. t['\u2FD0'] = '\u9F3B';
  23106. t['\u2FD1'] = '\u9F4A';
  23107. t['\u2FD2'] = '\u9F52';
  23108. t['\u2FD3'] = '\u9F8D';
  23109. t['\u2FD4'] = '\u9F9C';
  23110. t['\u2FD5'] = '\u9FA0';
  23111. t['\u3036'] = '\u3012';
  23112. t['\u3038'] = '\u5341';
  23113. t['\u3039'] = '\u5344';
  23114. t['\u303A'] = '\u5345';
  23115. t['\u309B'] = '\u0020\u3099';
  23116. t['\u309C'] = '\u0020\u309A';
  23117. t['\u3131'] = '\u1100';
  23118. t['\u3132'] = '\u1101';
  23119. t['\u3133'] = '\u11AA';
  23120. t['\u3134'] = '\u1102';
  23121. t['\u3135'] = '\u11AC';
  23122. t['\u3136'] = '\u11AD';
  23123. t['\u3137'] = '\u1103';
  23124. t['\u3138'] = '\u1104';
  23125. t['\u3139'] = '\u1105';
  23126. t['\u313A'] = '\u11B0';
  23127. t['\u313B'] = '\u11B1';
  23128. t['\u313C'] = '\u11B2';
  23129. t['\u313D'] = '\u11B3';
  23130. t['\u313E'] = '\u11B4';
  23131. t['\u313F'] = '\u11B5';
  23132. t['\u3140'] = '\u111A';
  23133. t['\u3141'] = '\u1106';
  23134. t['\u3142'] = '\u1107';
  23135. t['\u3143'] = '\u1108';
  23136. t['\u3144'] = '\u1121';
  23137. t['\u3145'] = '\u1109';
  23138. t['\u3146'] = '\u110A';
  23139. t['\u3147'] = '\u110B';
  23140. t['\u3148'] = '\u110C';
  23141. t['\u3149'] = '\u110D';
  23142. t['\u314A'] = '\u110E';
  23143. t['\u314B'] = '\u110F';
  23144. t['\u314C'] = '\u1110';
  23145. t['\u314D'] = '\u1111';
  23146. t['\u314E'] = '\u1112';
  23147. t['\u314F'] = '\u1161';
  23148. t['\u3150'] = '\u1162';
  23149. t['\u3151'] = '\u1163';
  23150. t['\u3152'] = '\u1164';
  23151. t['\u3153'] = '\u1165';
  23152. t['\u3154'] = '\u1166';
  23153. t['\u3155'] = '\u1167';
  23154. t['\u3156'] = '\u1168';
  23155. t['\u3157'] = '\u1169';
  23156. t['\u3158'] = '\u116A';
  23157. t['\u3159'] = '\u116B';
  23158. t['\u315A'] = '\u116C';
  23159. t['\u315B'] = '\u116D';
  23160. t['\u315C'] = '\u116E';
  23161. t['\u315D'] = '\u116F';
  23162. t['\u315E'] = '\u1170';
  23163. t['\u315F'] = '\u1171';
  23164. t['\u3160'] = '\u1172';
  23165. t['\u3161'] = '\u1173';
  23166. t['\u3162'] = '\u1174';
  23167. t['\u3163'] = '\u1175';
  23168. t['\u3164'] = '\u1160';
  23169. t['\u3165'] = '\u1114';
  23170. t['\u3166'] = '\u1115';
  23171. t['\u3167'] = '\u11C7';
  23172. t['\u3168'] = '\u11C8';
  23173. t['\u3169'] = '\u11CC';
  23174. t['\u316A'] = '\u11CE';
  23175. t['\u316B'] = '\u11D3';
  23176. t['\u316C'] = '\u11D7';
  23177. t['\u316D'] = '\u11D9';
  23178. t['\u316E'] = '\u111C';
  23179. t['\u316F'] = '\u11DD';
  23180. t['\u3170'] = '\u11DF';
  23181. t['\u3171'] = '\u111D';
  23182. t['\u3172'] = '\u111E';
  23183. t['\u3173'] = '\u1120';
  23184. t['\u3174'] = '\u1122';
  23185. t['\u3175'] = '\u1123';
  23186. t['\u3176'] = '\u1127';
  23187. t['\u3177'] = '\u1129';
  23188. t['\u3178'] = '\u112B';
  23189. t['\u3179'] = '\u112C';
  23190. t['\u317A'] = '\u112D';
  23191. t['\u317B'] = '\u112E';
  23192. t['\u317C'] = '\u112F';
  23193. t['\u317D'] = '\u1132';
  23194. t['\u317E'] = '\u1136';
  23195. t['\u317F'] = '\u1140';
  23196. t['\u3180'] = '\u1147';
  23197. t['\u3181'] = '\u114C';
  23198. t['\u3182'] = '\u11F1';
  23199. t['\u3183'] = '\u11F2';
  23200. t['\u3184'] = '\u1157';
  23201. t['\u3185'] = '\u1158';
  23202. t['\u3186'] = '\u1159';
  23203. t['\u3187'] = '\u1184';
  23204. t['\u3188'] = '\u1185';
  23205. t['\u3189'] = '\u1188';
  23206. t['\u318A'] = '\u1191';
  23207. t['\u318B'] = '\u1192';
  23208. t['\u318C'] = '\u1194';
  23209. t['\u318D'] = '\u119E';
  23210. t['\u318E'] = '\u11A1';
  23211. t['\u3200'] = '\u0028\u1100\u0029';
  23212. t['\u3201'] = '\u0028\u1102\u0029';
  23213. t['\u3202'] = '\u0028\u1103\u0029';
  23214. t['\u3203'] = '\u0028\u1105\u0029';
  23215. t['\u3204'] = '\u0028\u1106\u0029';
  23216. t['\u3205'] = '\u0028\u1107\u0029';
  23217. t['\u3206'] = '\u0028\u1109\u0029';
  23218. t['\u3207'] = '\u0028\u110B\u0029';
  23219. t['\u3208'] = '\u0028\u110C\u0029';
  23220. t['\u3209'] = '\u0028\u110E\u0029';
  23221. t['\u320A'] = '\u0028\u110F\u0029';
  23222. t['\u320B'] = '\u0028\u1110\u0029';
  23223. t['\u320C'] = '\u0028\u1111\u0029';
  23224. t['\u320D'] = '\u0028\u1112\u0029';
  23225. t['\u320E'] = '\u0028\u1100\u1161\u0029';
  23226. t['\u320F'] = '\u0028\u1102\u1161\u0029';
  23227. t['\u3210'] = '\u0028\u1103\u1161\u0029';
  23228. t['\u3211'] = '\u0028\u1105\u1161\u0029';
  23229. t['\u3212'] = '\u0028\u1106\u1161\u0029';
  23230. t['\u3213'] = '\u0028\u1107\u1161\u0029';
  23231. t['\u3214'] = '\u0028\u1109\u1161\u0029';
  23232. t['\u3215'] = '\u0028\u110B\u1161\u0029';
  23233. t['\u3216'] = '\u0028\u110C\u1161\u0029';
  23234. t['\u3217'] = '\u0028\u110E\u1161\u0029';
  23235. t['\u3218'] = '\u0028\u110F\u1161\u0029';
  23236. t['\u3219'] = '\u0028\u1110\u1161\u0029';
  23237. t['\u321A'] = '\u0028\u1111\u1161\u0029';
  23238. t['\u321B'] = '\u0028\u1112\u1161\u0029';
  23239. t['\u321C'] = '\u0028\u110C\u116E\u0029';
  23240. t['\u321D'] = '\u0028\u110B\u1169\u110C\u1165\u11AB\u0029';
  23241. t['\u321E'] = '\u0028\u110B\u1169\u1112\u116E\u0029';
  23242. t['\u3220'] = '\u0028\u4E00\u0029';
  23243. t['\u3221'] = '\u0028\u4E8C\u0029';
  23244. t['\u3222'] = '\u0028\u4E09\u0029';
  23245. t['\u3223'] = '\u0028\u56DB\u0029';
  23246. t['\u3224'] = '\u0028\u4E94\u0029';
  23247. t['\u3225'] = '\u0028\u516D\u0029';
  23248. t['\u3226'] = '\u0028\u4E03\u0029';
  23249. t['\u3227'] = '\u0028\u516B\u0029';
  23250. t['\u3228'] = '\u0028\u4E5D\u0029';
  23251. t['\u3229'] = '\u0028\u5341\u0029';
  23252. t['\u322A'] = '\u0028\u6708\u0029';
  23253. t['\u322B'] = '\u0028\u706B\u0029';
  23254. t['\u322C'] = '\u0028\u6C34\u0029';
  23255. t['\u322D'] = '\u0028\u6728\u0029';
  23256. t['\u322E'] = '\u0028\u91D1\u0029';
  23257. t['\u322F'] = '\u0028\u571F\u0029';
  23258. t['\u3230'] = '\u0028\u65E5\u0029';
  23259. t['\u3231'] = '\u0028\u682A\u0029';
  23260. t['\u3232'] = '\u0028\u6709\u0029';
  23261. t['\u3233'] = '\u0028\u793E\u0029';
  23262. t['\u3234'] = '\u0028\u540D\u0029';
  23263. t['\u3235'] = '\u0028\u7279\u0029';
  23264. t['\u3236'] = '\u0028\u8CA1\u0029';
  23265. t['\u3237'] = '\u0028\u795D\u0029';
  23266. t['\u3238'] = '\u0028\u52B4\u0029';
  23267. t['\u3239'] = '\u0028\u4EE3\u0029';
  23268. t['\u323A'] = '\u0028\u547C\u0029';
  23269. t['\u323B'] = '\u0028\u5B66\u0029';
  23270. t['\u323C'] = '\u0028\u76E3\u0029';
  23271. t['\u323D'] = '\u0028\u4F01\u0029';
  23272. t['\u323E'] = '\u0028\u8CC7\u0029';
  23273. t['\u323F'] = '\u0028\u5354\u0029';
  23274. t['\u3240'] = '\u0028\u796D\u0029';
  23275. t['\u3241'] = '\u0028\u4F11\u0029';
  23276. t['\u3242'] = '\u0028\u81EA\u0029';
  23277. t['\u3243'] = '\u0028\u81F3\u0029';
  23278. t['\u32C0'] = '\u0031\u6708';
  23279. t['\u32C1'] = '\u0032\u6708';
  23280. t['\u32C2'] = '\u0033\u6708';
  23281. t['\u32C3'] = '\u0034\u6708';
  23282. t['\u32C4'] = '\u0035\u6708';
  23283. t['\u32C5'] = '\u0036\u6708';
  23284. t['\u32C6'] = '\u0037\u6708';
  23285. t['\u32C7'] = '\u0038\u6708';
  23286. t['\u32C8'] = '\u0039\u6708';
  23287. t['\u32C9'] = '\u0031\u0030\u6708';
  23288. t['\u32CA'] = '\u0031\u0031\u6708';
  23289. t['\u32CB'] = '\u0031\u0032\u6708';
  23290. t['\u3358'] = '\u0030\u70B9';
  23291. t['\u3359'] = '\u0031\u70B9';
  23292. t['\u335A'] = '\u0032\u70B9';
  23293. t['\u335B'] = '\u0033\u70B9';
  23294. t['\u335C'] = '\u0034\u70B9';
  23295. t['\u335D'] = '\u0035\u70B9';
  23296. t['\u335E'] = '\u0036\u70B9';
  23297. t['\u335F'] = '\u0037\u70B9';
  23298. t['\u3360'] = '\u0038\u70B9';
  23299. t['\u3361'] = '\u0039\u70B9';
  23300. t['\u3362'] = '\u0031\u0030\u70B9';
  23301. t['\u3363'] = '\u0031\u0031\u70B9';
  23302. t['\u3364'] = '\u0031\u0032\u70B9';
  23303. t['\u3365'] = '\u0031\u0033\u70B9';
  23304. t['\u3366'] = '\u0031\u0034\u70B9';
  23305. t['\u3367'] = '\u0031\u0035\u70B9';
  23306. t['\u3368'] = '\u0031\u0036\u70B9';
  23307. t['\u3369'] = '\u0031\u0037\u70B9';
  23308. t['\u336A'] = '\u0031\u0038\u70B9';
  23309. t['\u336B'] = '\u0031\u0039\u70B9';
  23310. t['\u336C'] = '\u0032\u0030\u70B9';
  23311. t['\u336D'] = '\u0032\u0031\u70B9';
  23312. t['\u336E'] = '\u0032\u0032\u70B9';
  23313. t['\u336F'] = '\u0032\u0033\u70B9';
  23314. t['\u3370'] = '\u0032\u0034\u70B9';
  23315. t['\u33E0'] = '\u0031\u65E5';
  23316. t['\u33E1'] = '\u0032\u65E5';
  23317. t['\u33E2'] = '\u0033\u65E5';
  23318. t['\u33E3'] = '\u0034\u65E5';
  23319. t['\u33E4'] = '\u0035\u65E5';
  23320. t['\u33E5'] = '\u0036\u65E5';
  23321. t['\u33E6'] = '\u0037\u65E5';
  23322. t['\u33E7'] = '\u0038\u65E5';
  23323. t['\u33E8'] = '\u0039\u65E5';
  23324. t['\u33E9'] = '\u0031\u0030\u65E5';
  23325. t['\u33EA'] = '\u0031\u0031\u65E5';
  23326. t['\u33EB'] = '\u0031\u0032\u65E5';
  23327. t['\u33EC'] = '\u0031\u0033\u65E5';
  23328. t['\u33ED'] = '\u0031\u0034\u65E5';
  23329. t['\u33EE'] = '\u0031\u0035\u65E5';
  23330. t['\u33EF'] = '\u0031\u0036\u65E5';
  23331. t['\u33F0'] = '\u0031\u0037\u65E5';
  23332. t['\u33F1'] = '\u0031\u0038\u65E5';
  23333. t['\u33F2'] = '\u0031\u0039\u65E5';
  23334. t['\u33F3'] = '\u0032\u0030\u65E5';
  23335. t['\u33F4'] = '\u0032\u0031\u65E5';
  23336. t['\u33F5'] = '\u0032\u0032\u65E5';
  23337. t['\u33F6'] = '\u0032\u0033\u65E5';
  23338. t['\u33F7'] = '\u0032\u0034\u65E5';
  23339. t['\u33F8'] = '\u0032\u0035\u65E5';
  23340. t['\u33F9'] = '\u0032\u0036\u65E5';
  23341. t['\u33FA'] = '\u0032\u0037\u65E5';
  23342. t['\u33FB'] = '\u0032\u0038\u65E5';
  23343. t['\u33FC'] = '\u0032\u0039\u65E5';
  23344. t['\u33FD'] = '\u0033\u0030\u65E5';
  23345. t['\u33FE'] = '\u0033\u0031\u65E5';
  23346. t['\uFB00'] = '\u0066\u0066';
  23347. t['\uFB01'] = '\u0066\u0069';
  23348. t['\uFB02'] = '\u0066\u006C';
  23349. t['\uFB03'] = '\u0066\u0066\u0069';
  23350. t['\uFB04'] = '\u0066\u0066\u006C';
  23351. t['\uFB05'] = '\u017F\u0074';
  23352. t['\uFB06'] = '\u0073\u0074';
  23353. t['\uFB13'] = '\u0574\u0576';
  23354. t['\uFB14'] = '\u0574\u0565';
  23355. t['\uFB15'] = '\u0574\u056B';
  23356. t['\uFB16'] = '\u057E\u0576';
  23357. t['\uFB17'] = '\u0574\u056D';
  23358. t['\uFB4F'] = '\u05D0\u05DC';
  23359. t['\uFB50'] = '\u0671';
  23360. t['\uFB51'] = '\u0671';
  23361. t['\uFB52'] = '\u067B';
  23362. t['\uFB53'] = '\u067B';
  23363. t['\uFB54'] = '\u067B';
  23364. t['\uFB55'] = '\u067B';
  23365. t['\uFB56'] = '\u067E';
  23366. t['\uFB57'] = '\u067E';
  23367. t['\uFB58'] = '\u067E';
  23368. t['\uFB59'] = '\u067E';
  23369. t['\uFB5A'] = '\u0680';
  23370. t['\uFB5B'] = '\u0680';
  23371. t['\uFB5C'] = '\u0680';
  23372. t['\uFB5D'] = '\u0680';
  23373. t['\uFB5E'] = '\u067A';
  23374. t['\uFB5F'] = '\u067A';
  23375. t['\uFB60'] = '\u067A';
  23376. t['\uFB61'] = '\u067A';
  23377. t['\uFB62'] = '\u067F';
  23378. t['\uFB63'] = '\u067F';
  23379. t['\uFB64'] = '\u067F';
  23380. t['\uFB65'] = '\u067F';
  23381. t['\uFB66'] = '\u0679';
  23382. t['\uFB67'] = '\u0679';
  23383. t['\uFB68'] = '\u0679';
  23384. t['\uFB69'] = '\u0679';
  23385. t['\uFB6A'] = '\u06A4';
  23386. t['\uFB6B'] = '\u06A4';
  23387. t['\uFB6C'] = '\u06A4';
  23388. t['\uFB6D'] = '\u06A4';
  23389. t['\uFB6E'] = '\u06A6';
  23390. t['\uFB6F'] = '\u06A6';
  23391. t['\uFB70'] = '\u06A6';
  23392. t['\uFB71'] = '\u06A6';
  23393. t['\uFB72'] = '\u0684';
  23394. t['\uFB73'] = '\u0684';
  23395. t['\uFB74'] = '\u0684';
  23396. t['\uFB75'] = '\u0684';
  23397. t['\uFB76'] = '\u0683';
  23398. t['\uFB77'] = '\u0683';
  23399. t['\uFB78'] = '\u0683';
  23400. t['\uFB79'] = '\u0683';
  23401. t['\uFB7A'] = '\u0686';
  23402. t['\uFB7B'] = '\u0686';
  23403. t['\uFB7C'] = '\u0686';
  23404. t['\uFB7D'] = '\u0686';
  23405. t['\uFB7E'] = '\u0687';
  23406. t['\uFB7F'] = '\u0687';
  23407. t['\uFB80'] = '\u0687';
  23408. t['\uFB81'] = '\u0687';
  23409. t['\uFB82'] = '\u068D';
  23410. t['\uFB83'] = '\u068D';
  23411. t['\uFB84'] = '\u068C';
  23412. t['\uFB85'] = '\u068C';
  23413. t['\uFB86'] = '\u068E';
  23414. t['\uFB87'] = '\u068E';
  23415. t['\uFB88'] = '\u0688';
  23416. t['\uFB89'] = '\u0688';
  23417. t['\uFB8A'] = '\u0698';
  23418. t['\uFB8B'] = '\u0698';
  23419. t['\uFB8C'] = '\u0691';
  23420. t['\uFB8D'] = '\u0691';
  23421. t['\uFB8E'] = '\u06A9';
  23422. t['\uFB8F'] = '\u06A9';
  23423. t['\uFB90'] = '\u06A9';
  23424. t['\uFB91'] = '\u06A9';
  23425. t['\uFB92'] = '\u06AF';
  23426. t['\uFB93'] = '\u06AF';
  23427. t['\uFB94'] = '\u06AF';
  23428. t['\uFB95'] = '\u06AF';
  23429. t['\uFB96'] = '\u06B3';
  23430. t['\uFB97'] = '\u06B3';
  23431. t['\uFB98'] = '\u06B3';
  23432. t['\uFB99'] = '\u06B3';
  23433. t['\uFB9A'] = '\u06B1';
  23434. t['\uFB9B'] = '\u06B1';
  23435. t['\uFB9C'] = '\u06B1';
  23436. t['\uFB9D'] = '\u06B1';
  23437. t['\uFB9E'] = '\u06BA';
  23438. t['\uFB9F'] = '\u06BA';
  23439. t['\uFBA0'] = '\u06BB';
  23440. t['\uFBA1'] = '\u06BB';
  23441. t['\uFBA2'] = '\u06BB';
  23442. t['\uFBA3'] = '\u06BB';
  23443. t['\uFBA4'] = '\u06C0';
  23444. t['\uFBA5'] = '\u06C0';
  23445. t['\uFBA6'] = '\u06C1';
  23446. t['\uFBA7'] = '\u06C1';
  23447. t['\uFBA8'] = '\u06C1';
  23448. t['\uFBA9'] = '\u06C1';
  23449. t['\uFBAA'] = '\u06BE';
  23450. t['\uFBAB'] = '\u06BE';
  23451. t['\uFBAC'] = '\u06BE';
  23452. t['\uFBAD'] = '\u06BE';
  23453. t['\uFBAE'] = '\u06D2';
  23454. t['\uFBAF'] = '\u06D2';
  23455. t['\uFBB0'] = '\u06D3';
  23456. t['\uFBB1'] = '\u06D3';
  23457. t['\uFBD3'] = '\u06AD';
  23458. t['\uFBD4'] = '\u06AD';
  23459. t['\uFBD5'] = '\u06AD';
  23460. t['\uFBD6'] = '\u06AD';
  23461. t['\uFBD7'] = '\u06C7';
  23462. t['\uFBD8'] = '\u06C7';
  23463. t['\uFBD9'] = '\u06C6';
  23464. t['\uFBDA'] = '\u06C6';
  23465. t['\uFBDB'] = '\u06C8';
  23466. t['\uFBDC'] = '\u06C8';
  23467. t['\uFBDD'] = '\u0677';
  23468. t['\uFBDE'] = '\u06CB';
  23469. t['\uFBDF'] = '\u06CB';
  23470. t['\uFBE0'] = '\u06C5';
  23471. t['\uFBE1'] = '\u06C5';
  23472. t['\uFBE2'] = '\u06C9';
  23473. t['\uFBE3'] = '\u06C9';
  23474. t['\uFBE4'] = '\u06D0';
  23475. t['\uFBE5'] = '\u06D0';
  23476. t['\uFBE6'] = '\u06D0';
  23477. t['\uFBE7'] = '\u06D0';
  23478. t['\uFBE8'] = '\u0649';
  23479. t['\uFBE9'] = '\u0649';
  23480. t['\uFBEA'] = '\u0626\u0627';
  23481. t['\uFBEB'] = '\u0626\u0627';
  23482. t['\uFBEC'] = '\u0626\u06D5';
  23483. t['\uFBED'] = '\u0626\u06D5';
  23484. t['\uFBEE'] = '\u0626\u0648';
  23485. t['\uFBEF'] = '\u0626\u0648';
  23486. t['\uFBF0'] = '\u0626\u06C7';
  23487. t['\uFBF1'] = '\u0626\u06C7';
  23488. t['\uFBF2'] = '\u0626\u06C6';
  23489. t['\uFBF3'] = '\u0626\u06C6';
  23490. t['\uFBF4'] = '\u0626\u06C8';
  23491. t['\uFBF5'] = '\u0626\u06C8';
  23492. t['\uFBF6'] = '\u0626\u06D0';
  23493. t['\uFBF7'] = '\u0626\u06D0';
  23494. t['\uFBF8'] = '\u0626\u06D0';
  23495. t['\uFBF9'] = '\u0626\u0649';
  23496. t['\uFBFA'] = '\u0626\u0649';
  23497. t['\uFBFB'] = '\u0626\u0649';
  23498. t['\uFBFC'] = '\u06CC';
  23499. t['\uFBFD'] = '\u06CC';
  23500. t['\uFBFE'] = '\u06CC';
  23501. t['\uFBFF'] = '\u06CC';
  23502. t['\uFC00'] = '\u0626\u062C';
  23503. t['\uFC01'] = '\u0626\u062D';
  23504. t['\uFC02'] = '\u0626\u0645';
  23505. t['\uFC03'] = '\u0626\u0649';
  23506. t['\uFC04'] = '\u0626\u064A';
  23507. t['\uFC05'] = '\u0628\u062C';
  23508. t['\uFC06'] = '\u0628\u062D';
  23509. t['\uFC07'] = '\u0628\u062E';
  23510. t['\uFC08'] = '\u0628\u0645';
  23511. t['\uFC09'] = '\u0628\u0649';
  23512. t['\uFC0A'] = '\u0628\u064A';
  23513. t['\uFC0B'] = '\u062A\u062C';
  23514. t['\uFC0C'] = '\u062A\u062D';
  23515. t['\uFC0D'] = '\u062A\u062E';
  23516. t['\uFC0E'] = '\u062A\u0645';
  23517. t['\uFC0F'] = '\u062A\u0649';
  23518. t['\uFC10'] = '\u062A\u064A';
  23519. t['\uFC11'] = '\u062B\u062C';
  23520. t['\uFC12'] = '\u062B\u0645';
  23521. t['\uFC13'] = '\u062B\u0649';
  23522. t['\uFC14'] = '\u062B\u064A';
  23523. t['\uFC15'] = '\u062C\u062D';
  23524. t['\uFC16'] = '\u062C\u0645';
  23525. t['\uFC17'] = '\u062D\u062C';
  23526. t['\uFC18'] = '\u062D\u0645';
  23527. t['\uFC19'] = '\u062E\u062C';
  23528. t['\uFC1A'] = '\u062E\u062D';
  23529. t['\uFC1B'] = '\u062E\u0645';
  23530. t['\uFC1C'] = '\u0633\u062C';
  23531. t['\uFC1D'] = '\u0633\u062D';
  23532. t['\uFC1E'] = '\u0633\u062E';
  23533. t['\uFC1F'] = '\u0633\u0645';
  23534. t['\uFC20'] = '\u0635\u062D';
  23535. t['\uFC21'] = '\u0635\u0645';
  23536. t['\uFC22'] = '\u0636\u062C';
  23537. t['\uFC23'] = '\u0636\u062D';
  23538. t['\uFC24'] = '\u0636\u062E';
  23539. t['\uFC25'] = '\u0636\u0645';
  23540. t['\uFC26'] = '\u0637\u062D';
  23541. t['\uFC27'] = '\u0637\u0645';
  23542. t['\uFC28'] = '\u0638\u0645';
  23543. t['\uFC29'] = '\u0639\u062C';
  23544. t['\uFC2A'] = '\u0639\u0645';
  23545. t['\uFC2B'] = '\u063A\u062C';
  23546. t['\uFC2C'] = '\u063A\u0645';
  23547. t['\uFC2D'] = '\u0641\u062C';
  23548. t['\uFC2E'] = '\u0641\u062D';
  23549. t['\uFC2F'] = '\u0641\u062E';
  23550. t['\uFC30'] = '\u0641\u0645';
  23551. t['\uFC31'] = '\u0641\u0649';
  23552. t['\uFC32'] = '\u0641\u064A';
  23553. t['\uFC33'] = '\u0642\u062D';
  23554. t['\uFC34'] = '\u0642\u0645';
  23555. t['\uFC35'] = '\u0642\u0649';
  23556. t['\uFC36'] = '\u0642\u064A';
  23557. t['\uFC37'] = '\u0643\u0627';
  23558. t['\uFC38'] = '\u0643\u062C';
  23559. t['\uFC39'] = '\u0643\u062D';
  23560. t['\uFC3A'] = '\u0643\u062E';
  23561. t['\uFC3B'] = '\u0643\u0644';
  23562. t['\uFC3C'] = '\u0643\u0645';
  23563. t['\uFC3D'] = '\u0643\u0649';
  23564. t['\uFC3E'] = '\u0643\u064A';
  23565. t['\uFC3F'] = '\u0644\u062C';
  23566. t['\uFC40'] = '\u0644\u062D';
  23567. t['\uFC41'] = '\u0644\u062E';
  23568. t['\uFC42'] = '\u0644\u0645';
  23569. t['\uFC43'] = '\u0644\u0649';
  23570. t['\uFC44'] = '\u0644\u064A';
  23571. t['\uFC45'] = '\u0645\u062C';
  23572. t['\uFC46'] = '\u0645\u062D';
  23573. t['\uFC47'] = '\u0645\u062E';
  23574. t['\uFC48'] = '\u0645\u0645';
  23575. t['\uFC49'] = '\u0645\u0649';
  23576. t['\uFC4A'] = '\u0645\u064A';
  23577. t['\uFC4B'] = '\u0646\u062C';
  23578. t['\uFC4C'] = '\u0646\u062D';
  23579. t['\uFC4D'] = '\u0646\u062E';
  23580. t['\uFC4E'] = '\u0646\u0645';
  23581. t['\uFC4F'] = '\u0646\u0649';
  23582. t['\uFC50'] = '\u0646\u064A';
  23583. t['\uFC51'] = '\u0647\u062C';
  23584. t['\uFC52'] = '\u0647\u0645';
  23585. t['\uFC53'] = '\u0647\u0649';
  23586. t['\uFC54'] = '\u0647\u064A';
  23587. t['\uFC55'] = '\u064A\u062C';
  23588. t['\uFC56'] = '\u064A\u062D';
  23589. t['\uFC57'] = '\u064A\u062E';
  23590. t['\uFC58'] = '\u064A\u0645';
  23591. t['\uFC59'] = '\u064A\u0649';
  23592. t['\uFC5A'] = '\u064A\u064A';
  23593. t['\uFC5B'] = '\u0630\u0670';
  23594. t['\uFC5C'] = '\u0631\u0670';
  23595. t['\uFC5D'] = '\u0649\u0670';
  23596. t['\uFC5E'] = '\u0020\u064C\u0651';
  23597. t['\uFC5F'] = '\u0020\u064D\u0651';
  23598. t['\uFC60'] = '\u0020\u064E\u0651';
  23599. t['\uFC61'] = '\u0020\u064F\u0651';
  23600. t['\uFC62'] = '\u0020\u0650\u0651';
  23601. t['\uFC63'] = '\u0020\u0651\u0670';
  23602. t['\uFC64'] = '\u0626\u0631';
  23603. t['\uFC65'] = '\u0626\u0632';
  23604. t['\uFC66'] = '\u0626\u0645';
  23605. t['\uFC67'] = '\u0626\u0646';
  23606. t['\uFC68'] = '\u0626\u0649';
  23607. t['\uFC69'] = '\u0626\u064A';
  23608. t['\uFC6A'] = '\u0628\u0631';
  23609. t['\uFC6B'] = '\u0628\u0632';
  23610. t['\uFC6C'] = '\u0628\u0645';
  23611. t['\uFC6D'] = '\u0628\u0646';
  23612. t['\uFC6E'] = '\u0628\u0649';
  23613. t['\uFC6F'] = '\u0628\u064A';
  23614. t['\uFC70'] = '\u062A\u0631';
  23615. t['\uFC71'] = '\u062A\u0632';
  23616. t['\uFC72'] = '\u062A\u0645';
  23617. t['\uFC73'] = '\u062A\u0646';
  23618. t['\uFC74'] = '\u062A\u0649';
  23619. t['\uFC75'] = '\u062A\u064A';
  23620. t['\uFC76'] = '\u062B\u0631';
  23621. t['\uFC77'] = '\u062B\u0632';
  23622. t['\uFC78'] = '\u062B\u0645';
  23623. t['\uFC79'] = '\u062B\u0646';
  23624. t['\uFC7A'] = '\u062B\u0649';
  23625. t['\uFC7B'] = '\u062B\u064A';
  23626. t['\uFC7C'] = '\u0641\u0649';
  23627. t['\uFC7D'] = '\u0641\u064A';
  23628. t['\uFC7E'] = '\u0642\u0649';
  23629. t['\uFC7F'] = '\u0642\u064A';
  23630. t['\uFC80'] = '\u0643\u0627';
  23631. t['\uFC81'] = '\u0643\u0644';
  23632. t['\uFC82'] = '\u0643\u0645';
  23633. t['\uFC83'] = '\u0643\u0649';
  23634. t['\uFC84'] = '\u0643\u064A';
  23635. t['\uFC85'] = '\u0644\u0645';
  23636. t['\uFC86'] = '\u0644\u0649';
  23637. t['\uFC87'] = '\u0644\u064A';
  23638. t['\uFC88'] = '\u0645\u0627';
  23639. t['\uFC89'] = '\u0645\u0645';
  23640. t['\uFC8A'] = '\u0646\u0631';
  23641. t['\uFC8B'] = '\u0646\u0632';
  23642. t['\uFC8C'] = '\u0646\u0645';
  23643. t['\uFC8D'] = '\u0646\u0646';
  23644. t['\uFC8E'] = '\u0646\u0649';
  23645. t['\uFC8F'] = '\u0646\u064A';
  23646. t['\uFC90'] = '\u0649\u0670';
  23647. t['\uFC91'] = '\u064A\u0631';
  23648. t['\uFC92'] = '\u064A\u0632';
  23649. t['\uFC93'] = '\u064A\u0645';
  23650. t['\uFC94'] = '\u064A\u0646';
  23651. t['\uFC95'] = '\u064A\u0649';
  23652. t['\uFC96'] = '\u064A\u064A';
  23653. t['\uFC97'] = '\u0626\u062C';
  23654. t['\uFC98'] = '\u0626\u062D';
  23655. t['\uFC99'] = '\u0626\u062E';
  23656. t['\uFC9A'] = '\u0626\u0645';
  23657. t['\uFC9B'] = '\u0626\u0647';
  23658. t['\uFC9C'] = '\u0628\u062C';
  23659. t['\uFC9D'] = '\u0628\u062D';
  23660. t['\uFC9E'] = '\u0628\u062E';
  23661. t['\uFC9F'] = '\u0628\u0645';
  23662. t['\uFCA0'] = '\u0628\u0647';
  23663. t['\uFCA1'] = '\u062A\u062C';
  23664. t['\uFCA2'] = '\u062A\u062D';
  23665. t['\uFCA3'] = '\u062A\u062E';
  23666. t['\uFCA4'] = '\u062A\u0645';
  23667. t['\uFCA5'] = '\u062A\u0647';
  23668. t['\uFCA6'] = '\u062B\u0645';
  23669. t['\uFCA7'] = '\u062C\u062D';
  23670. t['\uFCA8'] = '\u062C\u0645';
  23671. t['\uFCA9'] = '\u062D\u062C';
  23672. t['\uFCAA'] = '\u062D\u0645';
  23673. t['\uFCAB'] = '\u062E\u062C';
  23674. t['\uFCAC'] = '\u062E\u0645';
  23675. t['\uFCAD'] = '\u0633\u062C';
  23676. t['\uFCAE'] = '\u0633\u062D';
  23677. t['\uFCAF'] = '\u0633\u062E';
  23678. t['\uFCB0'] = '\u0633\u0645';
  23679. t['\uFCB1'] = '\u0635\u062D';
  23680. t['\uFCB2'] = '\u0635\u062E';
  23681. t['\uFCB3'] = '\u0635\u0645';
  23682. t['\uFCB4'] = '\u0636\u062C';
  23683. t['\uFCB5'] = '\u0636\u062D';
  23684. t['\uFCB6'] = '\u0636\u062E';
  23685. t['\uFCB7'] = '\u0636\u0645';
  23686. t['\uFCB8'] = '\u0637\u062D';
  23687. t['\uFCB9'] = '\u0638\u0645';
  23688. t['\uFCBA'] = '\u0639\u062C';
  23689. t['\uFCBB'] = '\u0639\u0645';
  23690. t['\uFCBC'] = '\u063A\u062C';
  23691. t['\uFCBD'] = '\u063A\u0645';
  23692. t['\uFCBE'] = '\u0641\u062C';
  23693. t['\uFCBF'] = '\u0641\u062D';
  23694. t['\uFCC0'] = '\u0641\u062E';
  23695. t['\uFCC1'] = '\u0641\u0645';
  23696. t['\uFCC2'] = '\u0642\u062D';
  23697. t['\uFCC3'] = '\u0642\u0645';
  23698. t['\uFCC4'] = '\u0643\u062C';
  23699. t['\uFCC5'] = '\u0643\u062D';
  23700. t['\uFCC6'] = '\u0643\u062E';
  23701. t['\uFCC7'] = '\u0643\u0644';
  23702. t['\uFCC8'] = '\u0643\u0645';
  23703. t['\uFCC9'] = '\u0644\u062C';
  23704. t['\uFCCA'] = '\u0644\u062D';
  23705. t['\uFCCB'] = '\u0644\u062E';
  23706. t['\uFCCC'] = '\u0644\u0645';
  23707. t['\uFCCD'] = '\u0644\u0647';
  23708. t['\uFCCE'] = '\u0645\u062C';
  23709. t['\uFCCF'] = '\u0645\u062D';
  23710. t['\uFCD0'] = '\u0645\u062E';
  23711. t['\uFCD1'] = '\u0645\u0645';
  23712. t['\uFCD2'] = '\u0646\u062C';
  23713. t['\uFCD3'] = '\u0646\u062D';
  23714. t['\uFCD4'] = '\u0646\u062E';
  23715. t['\uFCD5'] = '\u0646\u0645';
  23716. t['\uFCD6'] = '\u0646\u0647';
  23717. t['\uFCD7'] = '\u0647\u062C';
  23718. t['\uFCD8'] = '\u0647\u0645';
  23719. t['\uFCD9'] = '\u0647\u0670';
  23720. t['\uFCDA'] = '\u064A\u062C';
  23721. t['\uFCDB'] = '\u064A\u062D';
  23722. t['\uFCDC'] = '\u064A\u062E';
  23723. t['\uFCDD'] = '\u064A\u0645';
  23724. t['\uFCDE'] = '\u064A\u0647';
  23725. t['\uFCDF'] = '\u0626\u0645';
  23726. t['\uFCE0'] = '\u0626\u0647';
  23727. t['\uFCE1'] = '\u0628\u0645';
  23728. t['\uFCE2'] = '\u0628\u0647';
  23729. t['\uFCE3'] = '\u062A\u0645';
  23730. t['\uFCE4'] = '\u062A\u0647';
  23731. t['\uFCE5'] = '\u062B\u0645';
  23732. t['\uFCE6'] = '\u062B\u0647';
  23733. t['\uFCE7'] = '\u0633\u0645';
  23734. t['\uFCE8'] = '\u0633\u0647';
  23735. t['\uFCE9'] = '\u0634\u0645';
  23736. t['\uFCEA'] = '\u0634\u0647';
  23737. t['\uFCEB'] = '\u0643\u0644';
  23738. t['\uFCEC'] = '\u0643\u0645';
  23739. t['\uFCED'] = '\u0644\u0645';
  23740. t['\uFCEE'] = '\u0646\u0645';
  23741. t['\uFCEF'] = '\u0646\u0647';
  23742. t['\uFCF0'] = '\u064A\u0645';
  23743. t['\uFCF1'] = '\u064A\u0647';
  23744. t['\uFCF2'] = '\u0640\u064E\u0651';
  23745. t['\uFCF3'] = '\u0640\u064F\u0651';
  23746. t['\uFCF4'] = '\u0640\u0650\u0651';
  23747. t['\uFCF5'] = '\u0637\u0649';
  23748. t['\uFCF6'] = '\u0637\u064A';
  23749. t['\uFCF7'] = '\u0639\u0649';
  23750. t['\uFCF8'] = '\u0639\u064A';
  23751. t['\uFCF9'] = '\u063A\u0649';
  23752. t['\uFCFA'] = '\u063A\u064A';
  23753. t['\uFCFB'] = '\u0633\u0649';
  23754. t['\uFCFC'] = '\u0633\u064A';
  23755. t['\uFCFD'] = '\u0634\u0649';
  23756. t['\uFCFE'] = '\u0634\u064A';
  23757. t['\uFCFF'] = '\u062D\u0649';
  23758. t['\uFD00'] = '\u062D\u064A';
  23759. t['\uFD01'] = '\u062C\u0649';
  23760. t['\uFD02'] = '\u062C\u064A';
  23761. t['\uFD03'] = '\u062E\u0649';
  23762. t['\uFD04'] = '\u062E\u064A';
  23763. t['\uFD05'] = '\u0635\u0649';
  23764. t['\uFD06'] = '\u0635\u064A';
  23765. t['\uFD07'] = '\u0636\u0649';
  23766. t['\uFD08'] = '\u0636\u064A';
  23767. t['\uFD09'] = '\u0634\u062C';
  23768. t['\uFD0A'] = '\u0634\u062D';
  23769. t['\uFD0B'] = '\u0634\u062E';
  23770. t['\uFD0C'] = '\u0634\u0645';
  23771. t['\uFD0D'] = '\u0634\u0631';
  23772. t['\uFD0E'] = '\u0633\u0631';
  23773. t['\uFD0F'] = '\u0635\u0631';
  23774. t['\uFD10'] = '\u0636\u0631';
  23775. t['\uFD11'] = '\u0637\u0649';
  23776. t['\uFD12'] = '\u0637\u064A';
  23777. t['\uFD13'] = '\u0639\u0649';
  23778. t['\uFD14'] = '\u0639\u064A';
  23779. t['\uFD15'] = '\u063A\u0649';
  23780. t['\uFD16'] = '\u063A\u064A';
  23781. t['\uFD17'] = '\u0633\u0649';
  23782. t['\uFD18'] = '\u0633\u064A';
  23783. t['\uFD19'] = '\u0634\u0649';
  23784. t['\uFD1A'] = '\u0634\u064A';
  23785. t['\uFD1B'] = '\u062D\u0649';
  23786. t['\uFD1C'] = '\u062D\u064A';
  23787. t['\uFD1D'] = '\u062C\u0649';
  23788. t['\uFD1E'] = '\u062C\u064A';
  23789. t['\uFD1F'] = '\u062E\u0649';
  23790. t['\uFD20'] = '\u062E\u064A';
  23791. t['\uFD21'] = '\u0635\u0649';
  23792. t['\uFD22'] = '\u0635\u064A';
  23793. t['\uFD23'] = '\u0636\u0649';
  23794. t['\uFD24'] = '\u0636\u064A';
  23795. t['\uFD25'] = '\u0634\u062C';
  23796. t['\uFD26'] = '\u0634\u062D';
  23797. t['\uFD27'] = '\u0634\u062E';
  23798. t['\uFD28'] = '\u0634\u0645';
  23799. t['\uFD29'] = '\u0634\u0631';
  23800. t['\uFD2A'] = '\u0633\u0631';
  23801. t['\uFD2B'] = '\u0635\u0631';
  23802. t['\uFD2C'] = '\u0636\u0631';
  23803. t['\uFD2D'] = '\u0634\u062C';
  23804. t['\uFD2E'] = '\u0634\u062D';
  23805. t['\uFD2F'] = '\u0634\u062E';
  23806. t['\uFD30'] = '\u0634\u0645';
  23807. t['\uFD31'] = '\u0633\u0647';
  23808. t['\uFD32'] = '\u0634\u0647';
  23809. t['\uFD33'] = '\u0637\u0645';
  23810. t['\uFD34'] = '\u0633\u062C';
  23811. t['\uFD35'] = '\u0633\u062D';
  23812. t['\uFD36'] = '\u0633\u062E';
  23813. t['\uFD37'] = '\u0634\u062C';
  23814. t['\uFD38'] = '\u0634\u062D';
  23815. t['\uFD39'] = '\u0634\u062E';
  23816. t['\uFD3A'] = '\u0637\u0645';
  23817. t['\uFD3B'] = '\u0638\u0645';
  23818. t['\uFD3C'] = '\u0627\u064B';
  23819. t['\uFD3D'] = '\u0627\u064B';
  23820. t['\uFD50'] = '\u062A\u062C\u0645';
  23821. t['\uFD51'] = '\u062A\u062D\u062C';
  23822. t['\uFD52'] = '\u062A\u062D\u062C';
  23823. t['\uFD53'] = '\u062A\u062D\u0645';
  23824. t['\uFD54'] = '\u062A\u062E\u0645';
  23825. t['\uFD55'] = '\u062A\u0645\u062C';
  23826. t['\uFD56'] = '\u062A\u0645\u062D';
  23827. t['\uFD57'] = '\u062A\u0645\u062E';
  23828. t['\uFD58'] = '\u062C\u0645\u062D';
  23829. t['\uFD59'] = '\u062C\u0645\u062D';
  23830. t['\uFD5A'] = '\u062D\u0645\u064A';
  23831. t['\uFD5B'] = '\u062D\u0645\u0649';
  23832. t['\uFD5C'] = '\u0633\u062D\u062C';
  23833. t['\uFD5D'] = '\u0633\u062C\u062D';
  23834. t['\uFD5E'] = '\u0633\u062C\u0649';
  23835. t['\uFD5F'] = '\u0633\u0645\u062D';
  23836. t['\uFD60'] = '\u0633\u0645\u062D';
  23837. t['\uFD61'] = '\u0633\u0645\u062C';
  23838. t['\uFD62'] = '\u0633\u0645\u0645';
  23839. t['\uFD63'] = '\u0633\u0645\u0645';
  23840. t['\uFD64'] = '\u0635\u062D\u062D';
  23841. t['\uFD65'] = '\u0635\u062D\u062D';
  23842. t['\uFD66'] = '\u0635\u0645\u0645';
  23843. t['\uFD67'] = '\u0634\u062D\u0645';
  23844. t['\uFD68'] = '\u0634\u062D\u0645';
  23845. t['\uFD69'] = '\u0634\u062C\u064A';
  23846. t['\uFD6A'] = '\u0634\u0645\u062E';
  23847. t['\uFD6B'] = '\u0634\u0645\u062E';
  23848. t['\uFD6C'] = '\u0634\u0645\u0645';
  23849. t['\uFD6D'] = '\u0634\u0645\u0645';
  23850. t['\uFD6E'] = '\u0636\u062D\u0649';
  23851. t['\uFD6F'] = '\u0636\u062E\u0645';
  23852. t['\uFD70'] = '\u0636\u062E\u0645';
  23853. t['\uFD71'] = '\u0637\u0645\u062D';
  23854. t['\uFD72'] = '\u0637\u0645\u062D';
  23855. t['\uFD73'] = '\u0637\u0645\u0645';
  23856. t['\uFD74'] = '\u0637\u0645\u064A';
  23857. t['\uFD75'] = '\u0639\u062C\u0645';
  23858. t['\uFD76'] = '\u0639\u0645\u0645';
  23859. t['\uFD77'] = '\u0639\u0645\u0645';
  23860. t['\uFD78'] = '\u0639\u0645\u0649';
  23861. t['\uFD79'] = '\u063A\u0645\u0645';
  23862. t['\uFD7A'] = '\u063A\u0645\u064A';
  23863. t['\uFD7B'] = '\u063A\u0645\u0649';
  23864. t['\uFD7C'] = '\u0641\u062E\u0645';
  23865. t['\uFD7D'] = '\u0641\u062E\u0645';
  23866. t['\uFD7E'] = '\u0642\u0645\u062D';
  23867. t['\uFD7F'] = '\u0642\u0645\u0645';
  23868. t['\uFD80'] = '\u0644\u062D\u0645';
  23869. t['\uFD81'] = '\u0644\u062D\u064A';
  23870. t['\uFD82'] = '\u0644\u062D\u0649';
  23871. t['\uFD83'] = '\u0644\u062C\u062C';
  23872. t['\uFD84'] = '\u0644\u062C\u062C';
  23873. t['\uFD85'] = '\u0644\u062E\u0645';
  23874. t['\uFD86'] = '\u0644\u062E\u0645';
  23875. t['\uFD87'] = '\u0644\u0645\u062D';
  23876. t['\uFD88'] = '\u0644\u0645\u062D';
  23877. t['\uFD89'] = '\u0645\u062D\u062C';
  23878. t['\uFD8A'] = '\u0645\u062D\u0645';
  23879. t['\uFD8B'] = '\u0645\u062D\u064A';
  23880. t['\uFD8C'] = '\u0645\u062C\u062D';
  23881. t['\uFD8D'] = '\u0645\u062C\u0645';
  23882. t['\uFD8E'] = '\u0645\u062E\u062C';
  23883. t['\uFD8F'] = '\u0645\u062E\u0645';
  23884. t['\uFD92'] = '\u0645\u062C\u062E';
  23885. t['\uFD93'] = '\u0647\u0645\u062C';
  23886. t['\uFD94'] = '\u0647\u0645\u0645';
  23887. t['\uFD95'] = '\u0646\u062D\u0645';
  23888. t['\uFD96'] = '\u0646\u062D\u0649';
  23889. t['\uFD97'] = '\u0646\u062C\u0645';
  23890. t['\uFD98'] = '\u0646\u062C\u0645';
  23891. t['\uFD99'] = '\u0646\u062C\u0649';
  23892. t['\uFD9A'] = '\u0646\u0645\u064A';
  23893. t['\uFD9B'] = '\u0646\u0645\u0649';
  23894. t['\uFD9C'] = '\u064A\u0645\u0645';
  23895. t['\uFD9D'] = '\u064A\u0645\u0645';
  23896. t['\uFD9E'] = '\u0628\u062E\u064A';
  23897. t['\uFD9F'] = '\u062A\u062C\u064A';
  23898. t['\uFDA0'] = '\u062A\u062C\u0649';
  23899. t['\uFDA1'] = '\u062A\u062E\u064A';
  23900. t['\uFDA2'] = '\u062A\u062E\u0649';
  23901. t['\uFDA3'] = '\u062A\u0645\u064A';
  23902. t['\uFDA4'] = '\u062A\u0645\u0649';
  23903. t['\uFDA5'] = '\u062C\u0645\u064A';
  23904. t['\uFDA6'] = '\u062C\u062D\u0649';
  23905. t['\uFDA7'] = '\u062C\u0645\u0649';
  23906. t['\uFDA8'] = '\u0633\u062E\u0649';
  23907. t['\uFDA9'] = '\u0635\u062D\u064A';
  23908. t['\uFDAA'] = '\u0634\u062D\u064A';
  23909. t['\uFDAB'] = '\u0636\u062D\u064A';
  23910. t['\uFDAC'] = '\u0644\u062C\u064A';
  23911. t['\uFDAD'] = '\u0644\u0645\u064A';
  23912. t['\uFDAE'] = '\u064A\u062D\u064A';
  23913. t['\uFDAF'] = '\u064A\u062C\u064A';
  23914. t['\uFDB0'] = '\u064A\u0645\u064A';
  23915. t['\uFDB1'] = '\u0645\u0645\u064A';
  23916. t['\uFDB2'] = '\u0642\u0645\u064A';
  23917. t['\uFDB3'] = '\u0646\u062D\u064A';
  23918. t['\uFDB4'] = '\u0642\u0645\u062D';
  23919. t['\uFDB5'] = '\u0644\u062D\u0645';
  23920. t['\uFDB6'] = '\u0639\u0645\u064A';
  23921. t['\uFDB7'] = '\u0643\u0645\u064A';
  23922. t['\uFDB8'] = '\u0646\u062C\u062D';
  23923. t['\uFDB9'] = '\u0645\u062E\u064A';
  23924. t['\uFDBA'] = '\u0644\u062C\u0645';
  23925. t['\uFDBB'] = '\u0643\u0645\u0645';
  23926. t['\uFDBC'] = '\u0644\u062C\u0645';
  23927. t['\uFDBD'] = '\u0646\u062C\u062D';
  23928. t['\uFDBE'] = '\u062C\u062D\u064A';
  23929. t['\uFDBF'] = '\u062D\u062C\u064A';
  23930. t['\uFDC0'] = '\u0645\u062C\u064A';
  23931. t['\uFDC1'] = '\u0641\u0645\u064A';
  23932. t['\uFDC2'] = '\u0628\u062D\u064A';
  23933. t['\uFDC3'] = '\u0643\u0645\u0645';
  23934. t['\uFDC4'] = '\u0639\u062C\u0645';
  23935. t['\uFDC5'] = '\u0635\u0645\u0645';
  23936. t['\uFDC6'] = '\u0633\u062E\u064A';
  23937. t['\uFDC7'] = '\u0646\u062C\u064A';
  23938. t['\uFE49'] = '\u203E';
  23939. t['\uFE4A'] = '\u203E';
  23940. t['\uFE4B'] = '\u203E';
  23941. t['\uFE4C'] = '\u203E';
  23942. t['\uFE4D'] = '\u005F';
  23943. t['\uFE4E'] = '\u005F';
  23944. t['\uFE4F'] = '\u005F';
  23945. t['\uFE80'] = '\u0621';
  23946. t['\uFE81'] = '\u0622';
  23947. t['\uFE82'] = '\u0622';
  23948. t['\uFE83'] = '\u0623';
  23949. t['\uFE84'] = '\u0623';
  23950. t['\uFE85'] = '\u0624';
  23951. t['\uFE86'] = '\u0624';
  23952. t['\uFE87'] = '\u0625';
  23953. t['\uFE88'] = '\u0625';
  23954. t['\uFE89'] = '\u0626';
  23955. t['\uFE8A'] = '\u0626';
  23956. t['\uFE8B'] = '\u0626';
  23957. t['\uFE8C'] = '\u0626';
  23958. t['\uFE8D'] = '\u0627';
  23959. t['\uFE8E'] = '\u0627';
  23960. t['\uFE8F'] = '\u0628';
  23961. t['\uFE90'] = '\u0628';
  23962. t['\uFE91'] = '\u0628';
  23963. t['\uFE92'] = '\u0628';
  23964. t['\uFE93'] = '\u0629';
  23965. t['\uFE94'] = '\u0629';
  23966. t['\uFE95'] = '\u062A';
  23967. t['\uFE96'] = '\u062A';
  23968. t['\uFE97'] = '\u062A';
  23969. t['\uFE98'] = '\u062A';
  23970. t['\uFE99'] = '\u062B';
  23971. t['\uFE9A'] = '\u062B';
  23972. t['\uFE9B'] = '\u062B';
  23973. t['\uFE9C'] = '\u062B';
  23974. t['\uFE9D'] = '\u062C';
  23975. t['\uFE9E'] = '\u062C';
  23976. t['\uFE9F'] = '\u062C';
  23977. t['\uFEA0'] = '\u062C';
  23978. t['\uFEA1'] = '\u062D';
  23979. t['\uFEA2'] = '\u062D';
  23980. t['\uFEA3'] = '\u062D';
  23981. t['\uFEA4'] = '\u062D';
  23982. t['\uFEA5'] = '\u062E';
  23983. t['\uFEA6'] = '\u062E';
  23984. t['\uFEA7'] = '\u062E';
  23985. t['\uFEA8'] = '\u062E';
  23986. t['\uFEA9'] = '\u062F';
  23987. t['\uFEAA'] = '\u062F';
  23988. t['\uFEAB'] = '\u0630';
  23989. t['\uFEAC'] = '\u0630';
  23990. t['\uFEAD'] = '\u0631';
  23991. t['\uFEAE'] = '\u0631';
  23992. t['\uFEAF'] = '\u0632';
  23993. t['\uFEB0'] = '\u0632';
  23994. t['\uFEB1'] = '\u0633';
  23995. t['\uFEB2'] = '\u0633';
  23996. t['\uFEB3'] = '\u0633';
  23997. t['\uFEB4'] = '\u0633';
  23998. t['\uFEB5'] = '\u0634';
  23999. t['\uFEB6'] = '\u0634';
  24000. t['\uFEB7'] = '\u0634';
  24001. t['\uFEB8'] = '\u0634';
  24002. t['\uFEB9'] = '\u0635';
  24003. t['\uFEBA'] = '\u0635';
  24004. t['\uFEBB'] = '\u0635';
  24005. t['\uFEBC'] = '\u0635';
  24006. t['\uFEBD'] = '\u0636';
  24007. t['\uFEBE'] = '\u0636';
  24008. t['\uFEBF'] = '\u0636';
  24009. t['\uFEC0'] = '\u0636';
  24010. t['\uFEC1'] = '\u0637';
  24011. t['\uFEC2'] = '\u0637';
  24012. t['\uFEC3'] = '\u0637';
  24013. t['\uFEC4'] = '\u0637';
  24014. t['\uFEC5'] = '\u0638';
  24015. t['\uFEC6'] = '\u0638';
  24016. t['\uFEC7'] = '\u0638';
  24017. t['\uFEC8'] = '\u0638';
  24018. t['\uFEC9'] = '\u0639';
  24019. t['\uFECA'] = '\u0639';
  24020. t['\uFECB'] = '\u0639';
  24021. t['\uFECC'] = '\u0639';
  24022. t['\uFECD'] = '\u063A';
  24023. t['\uFECE'] = '\u063A';
  24024. t['\uFECF'] = '\u063A';
  24025. t['\uFED0'] = '\u063A';
  24026. t['\uFED1'] = '\u0641';
  24027. t['\uFED2'] = '\u0641';
  24028. t['\uFED3'] = '\u0641';
  24029. t['\uFED4'] = '\u0641';
  24030. t['\uFED5'] = '\u0642';
  24031. t['\uFED6'] = '\u0642';
  24032. t['\uFED7'] = '\u0642';
  24033. t['\uFED8'] = '\u0642';
  24034. t['\uFED9'] = '\u0643';
  24035. t['\uFEDA'] = '\u0643';
  24036. t['\uFEDB'] = '\u0643';
  24037. t['\uFEDC'] = '\u0643';
  24038. t['\uFEDD'] = '\u0644';
  24039. t['\uFEDE'] = '\u0644';
  24040. t['\uFEDF'] = '\u0644';
  24041. t['\uFEE0'] = '\u0644';
  24042. t['\uFEE1'] = '\u0645';
  24043. t['\uFEE2'] = '\u0645';
  24044. t['\uFEE3'] = '\u0645';
  24045. t['\uFEE4'] = '\u0645';
  24046. t['\uFEE5'] = '\u0646';
  24047. t['\uFEE6'] = '\u0646';
  24048. t['\uFEE7'] = '\u0646';
  24049. t['\uFEE8'] = '\u0646';
  24050. t['\uFEE9'] = '\u0647';
  24051. t['\uFEEA'] = '\u0647';
  24052. t['\uFEEB'] = '\u0647';
  24053. t['\uFEEC'] = '\u0647';
  24054. t['\uFEED'] = '\u0648';
  24055. t['\uFEEE'] = '\u0648';
  24056. t['\uFEEF'] = '\u0649';
  24057. t['\uFEF0'] = '\u0649';
  24058. t['\uFEF1'] = '\u064A';
  24059. t['\uFEF2'] = '\u064A';
  24060. t['\uFEF3'] = '\u064A';
  24061. t['\uFEF4'] = '\u064A';
  24062. t['\uFEF5'] = '\u0644\u0622';
  24063. t['\uFEF6'] = '\u0644\u0622';
  24064. t['\uFEF7'] = '\u0644\u0623';
  24065. t['\uFEF8'] = '\u0644\u0623';
  24066. t['\uFEF9'] = '\u0644\u0625';
  24067. t['\uFEFA'] = '\u0644\u0625';
  24068. t['\uFEFB'] = '\u0644\u0627';
  24069. t['\uFEFC'] = '\u0644\u0627';
  24070. });
  24071. function reverseIfRtl(chars) {
  24072. var charsLength = chars.length;
  24073. //reverse an arabic ligature
  24074. if (charsLength <= 1 || !isRTLRangeFor(chars.charCodeAt(0))) {
  24075. return chars;
  24076. }
  24077. var s = '';
  24078. for (var ii = charsLength - 1; ii >= 0; ii--) {
  24079. s += chars[ii];
  24080. }
  24081. return s;
  24082. }
  24083. exports.mapSpecialUnicodeValues = mapSpecialUnicodeValues;
  24084. exports.reverseIfRtl = reverseIfRtl;
  24085. exports.getUnicodeRangeFor = getUnicodeRangeFor;
  24086. exports.getNormalizedUnicodes = getNormalizedUnicodes;
  24087. exports.getUnicodeForGlyph = getUnicodeForGlyph;
  24088. }));
  24089. (function (root, factory) {
  24090. factory(root.pdfjsCoreStream = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCoreJbig2, root.pdfjsCoreJpg, root.pdfjsCoreJpx);
  24091. }(this, function (exports, sharedUtil, corePrimitives, coreJbig2, coreJpg, coreJpx) {
  24092. var Util = sharedUtil.Util;
  24093. var error = sharedUtil.error;
  24094. var info = sharedUtil.info;
  24095. var isInt = sharedUtil.isInt;
  24096. var isArray = sharedUtil.isArray;
  24097. var createObjectURL = sharedUtil.createObjectURL;
  24098. var shadow = sharedUtil.shadow;
  24099. var warn = sharedUtil.warn;
  24100. var isSpace = sharedUtil.isSpace;
  24101. var Dict = corePrimitives.Dict;
  24102. var isDict = corePrimitives.isDict;
  24103. var isStream = corePrimitives.isStream;
  24104. var Jbig2Image = coreJbig2.Jbig2Image;
  24105. var JpegImage = coreJpg.JpegImage;
  24106. var JpxImage = coreJpx.JpxImage;
  24107. var Stream = function StreamClosure() {
  24108. function Stream(arrayBuffer, start, length, dict) {
  24109. this.bytes = arrayBuffer instanceof Uint8Array ? arrayBuffer : new Uint8Array(arrayBuffer);
  24110. this.start = start || 0;
  24111. this.pos = this.start;
  24112. this.end = start + length || this.bytes.length;
  24113. this.dict = dict;
  24114. }
  24115. // required methods for a stream. if a particular stream does not
  24116. // implement these, an error should be thrown
  24117. Stream.prototype = {
  24118. get length() {
  24119. return this.end - this.start;
  24120. },
  24121. get isEmpty() {
  24122. return this.length === 0;
  24123. },
  24124. getByte: function Stream_getByte() {
  24125. if (this.pos >= this.end) {
  24126. return -1;
  24127. }
  24128. return this.bytes[this.pos++];
  24129. },
  24130. getUint16: function Stream_getUint16() {
  24131. var b0 = this.getByte();
  24132. var b1 = this.getByte();
  24133. if (b0 === -1 || b1 === -1) {
  24134. return -1;
  24135. }
  24136. return (b0 << 8) + b1;
  24137. },
  24138. getInt32: function Stream_getInt32() {
  24139. var b0 = this.getByte();
  24140. var b1 = this.getByte();
  24141. var b2 = this.getByte();
  24142. var b3 = this.getByte();
  24143. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  24144. },
  24145. // returns subarray of original buffer
  24146. // should only be read
  24147. getBytes: function Stream_getBytes(length) {
  24148. var bytes = this.bytes;
  24149. var pos = this.pos;
  24150. var strEnd = this.end;
  24151. if (!length) {
  24152. return bytes.subarray(pos, strEnd);
  24153. }
  24154. var end = pos + length;
  24155. if (end > strEnd) {
  24156. end = strEnd;
  24157. }
  24158. this.pos = end;
  24159. return bytes.subarray(pos, end);
  24160. },
  24161. peekByte: function Stream_peekByte() {
  24162. var peekedByte = this.getByte();
  24163. this.pos--;
  24164. return peekedByte;
  24165. },
  24166. peekBytes: function Stream_peekBytes(length) {
  24167. var bytes = this.getBytes(length);
  24168. this.pos -= bytes.length;
  24169. return bytes;
  24170. },
  24171. skip: function Stream_skip(n) {
  24172. if (!n) {
  24173. n = 1;
  24174. }
  24175. this.pos += n;
  24176. },
  24177. reset: function Stream_reset() {
  24178. this.pos = this.start;
  24179. },
  24180. moveStart: function Stream_moveStart() {
  24181. this.start = this.pos;
  24182. },
  24183. makeSubStream: function Stream_makeSubStream(start, length, dict) {
  24184. return new Stream(this.bytes.buffer, start, length, dict);
  24185. },
  24186. isStream: true
  24187. };
  24188. return Stream;
  24189. }();
  24190. var StringStream = function StringStreamClosure() {
  24191. function StringStream(str) {
  24192. var length = str.length;
  24193. var bytes = new Uint8Array(length);
  24194. for (var n = 0; n < length; ++n) {
  24195. bytes[n] = str.charCodeAt(n);
  24196. }
  24197. Stream.call(this, bytes);
  24198. }
  24199. StringStream.prototype = Stream.prototype;
  24200. return StringStream;
  24201. }();
  24202. // super class for the decoding streams
  24203. var DecodeStream = function DecodeStreamClosure() {
  24204. // Lots of DecodeStreams are created whose buffers are never used. For these
  24205. // we share a single empty buffer. This is (a) space-efficient and (b) avoids
  24206. // having special cases that would be required if we used |null| for an empty
  24207. // buffer.
  24208. var emptyBuffer = new Uint8Array(0);
  24209. function DecodeStream(maybeMinBufferLength) {
  24210. this.pos = 0;
  24211. this.bufferLength = 0;
  24212. this.eof = false;
  24213. this.buffer = emptyBuffer;
  24214. this.minBufferLength = 512;
  24215. if (maybeMinBufferLength) {
  24216. // Compute the first power of two that is as big as maybeMinBufferLength.
  24217. while (this.minBufferLength < maybeMinBufferLength) {
  24218. this.minBufferLength *= 2;
  24219. }
  24220. }
  24221. }
  24222. DecodeStream.prototype = {
  24223. get isEmpty() {
  24224. while (!this.eof && this.bufferLength === 0) {
  24225. this.readBlock();
  24226. }
  24227. return this.bufferLength === 0;
  24228. },
  24229. ensureBuffer: function DecodeStream_ensureBuffer(requested) {
  24230. var buffer = this.buffer;
  24231. if (requested <= buffer.byteLength) {
  24232. return buffer;
  24233. }
  24234. var size = this.minBufferLength;
  24235. while (size < requested) {
  24236. size *= 2;
  24237. }
  24238. var buffer2 = new Uint8Array(size);
  24239. buffer2.set(buffer);
  24240. return this.buffer = buffer2;
  24241. },
  24242. getByte: function DecodeStream_getByte() {
  24243. var pos = this.pos;
  24244. while (this.bufferLength <= pos) {
  24245. if (this.eof) {
  24246. return -1;
  24247. }
  24248. this.readBlock();
  24249. }
  24250. return this.buffer[this.pos++];
  24251. },
  24252. getUint16: function DecodeStream_getUint16() {
  24253. var b0 = this.getByte();
  24254. var b1 = this.getByte();
  24255. if (b0 === -1 || b1 === -1) {
  24256. return -1;
  24257. }
  24258. return (b0 << 8) + b1;
  24259. },
  24260. getInt32: function DecodeStream_getInt32() {
  24261. var b0 = this.getByte();
  24262. var b1 = this.getByte();
  24263. var b2 = this.getByte();
  24264. var b3 = this.getByte();
  24265. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  24266. },
  24267. getBytes: function DecodeStream_getBytes(length) {
  24268. var end, pos = this.pos;
  24269. if (length) {
  24270. this.ensureBuffer(pos + length);
  24271. end = pos + length;
  24272. while (!this.eof && this.bufferLength < end) {
  24273. this.readBlock();
  24274. }
  24275. var bufEnd = this.bufferLength;
  24276. if (end > bufEnd) {
  24277. end = bufEnd;
  24278. }
  24279. } else {
  24280. while (!this.eof) {
  24281. this.readBlock();
  24282. }
  24283. end = this.bufferLength;
  24284. }
  24285. this.pos = end;
  24286. return this.buffer.subarray(pos, end);
  24287. },
  24288. peekByte: function DecodeStream_peekByte() {
  24289. var peekedByte = this.getByte();
  24290. this.pos--;
  24291. return peekedByte;
  24292. },
  24293. peekBytes: function DecodeStream_peekBytes(length) {
  24294. var bytes = this.getBytes(length);
  24295. this.pos -= bytes.length;
  24296. return bytes;
  24297. },
  24298. makeSubStream: function DecodeStream_makeSubStream(start, length, dict) {
  24299. var end = start + length;
  24300. while (this.bufferLength <= end && !this.eof) {
  24301. this.readBlock();
  24302. }
  24303. return new Stream(this.buffer, start, length, dict);
  24304. },
  24305. skip: function DecodeStream_skip(n) {
  24306. if (!n) {
  24307. n = 1;
  24308. }
  24309. this.pos += n;
  24310. },
  24311. reset: function DecodeStream_reset() {
  24312. this.pos = 0;
  24313. },
  24314. getBaseStreams: function DecodeStream_getBaseStreams() {
  24315. if (this.str && this.str.getBaseStreams) {
  24316. return this.str.getBaseStreams();
  24317. }
  24318. return [];
  24319. }
  24320. };
  24321. return DecodeStream;
  24322. }();
  24323. var StreamsSequenceStream = function StreamsSequenceStreamClosure() {
  24324. function StreamsSequenceStream(streams) {
  24325. this.streams = streams;
  24326. DecodeStream.call(this, /* maybeLength = */
  24327. null);
  24328. }
  24329. StreamsSequenceStream.prototype = Object.create(DecodeStream.prototype);
  24330. StreamsSequenceStream.prototype.readBlock = function streamSequenceStreamReadBlock() {
  24331. var streams = this.streams;
  24332. if (streams.length === 0) {
  24333. this.eof = true;
  24334. return;
  24335. }
  24336. var stream = streams.shift();
  24337. var chunk = stream.getBytes();
  24338. var bufferLength = this.bufferLength;
  24339. var newLength = bufferLength + chunk.length;
  24340. var buffer = this.ensureBuffer(newLength);
  24341. buffer.set(chunk, bufferLength);
  24342. this.bufferLength = newLength;
  24343. };
  24344. StreamsSequenceStream.prototype.getBaseStreams = function StreamsSequenceStream_getBaseStreams() {
  24345. var baseStreams = [];
  24346. for (var i = 0, ii = this.streams.length; i < ii; i++) {
  24347. var stream = this.streams[i];
  24348. if (stream.getBaseStreams) {
  24349. Util.appendToArray(baseStreams, stream.getBaseStreams());
  24350. }
  24351. }
  24352. return baseStreams;
  24353. };
  24354. return StreamsSequenceStream;
  24355. }();
  24356. var FlateStream = function FlateStreamClosure() {
  24357. var codeLenCodeMap = new Int32Array([
  24358. 16,
  24359. 17,
  24360. 18,
  24361. 0,
  24362. 8,
  24363. 7,
  24364. 9,
  24365. 6,
  24366. 10,
  24367. 5,
  24368. 11,
  24369. 4,
  24370. 12,
  24371. 3,
  24372. 13,
  24373. 2,
  24374. 14,
  24375. 1,
  24376. 15
  24377. ]);
  24378. var lengthDecode = new Int32Array([
  24379. 0x00003,
  24380. 0x00004,
  24381. 0x00005,
  24382. 0x00006,
  24383. 0x00007,
  24384. 0x00008,
  24385. 0x00009,
  24386. 0x0000a,
  24387. 0x1000b,
  24388. 0x1000d,
  24389. 0x1000f,
  24390. 0x10011,
  24391. 0x20013,
  24392. 0x20017,
  24393. 0x2001b,
  24394. 0x2001f,
  24395. 0x30023,
  24396. 0x3002b,
  24397. 0x30033,
  24398. 0x3003b,
  24399. 0x40043,
  24400. 0x40053,
  24401. 0x40063,
  24402. 0x40073,
  24403. 0x50083,
  24404. 0x500a3,
  24405. 0x500c3,
  24406. 0x500e3,
  24407. 0x00102,
  24408. 0x00102,
  24409. 0x00102
  24410. ]);
  24411. var distDecode = new Int32Array([
  24412. 0x00001,
  24413. 0x00002,
  24414. 0x00003,
  24415. 0x00004,
  24416. 0x10005,
  24417. 0x10007,
  24418. 0x20009,
  24419. 0x2000d,
  24420. 0x30011,
  24421. 0x30019,
  24422. 0x40021,
  24423. 0x40031,
  24424. 0x50041,
  24425. 0x50061,
  24426. 0x60081,
  24427. 0x600c1,
  24428. 0x70101,
  24429. 0x70181,
  24430. 0x80201,
  24431. 0x80301,
  24432. 0x90401,
  24433. 0x90601,
  24434. 0xa0801,
  24435. 0xa0c01,
  24436. 0xb1001,
  24437. 0xb1801,
  24438. 0xc2001,
  24439. 0xc3001,
  24440. 0xd4001,
  24441. 0xd6001
  24442. ]);
  24443. var fixedLitCodeTab = [
  24444. new Int32Array([
  24445. 0x70100,
  24446. 0x80050,
  24447. 0x80010,
  24448. 0x80118,
  24449. 0x70110,
  24450. 0x80070,
  24451. 0x80030,
  24452. 0x900c0,
  24453. 0x70108,
  24454. 0x80060,
  24455. 0x80020,
  24456. 0x900a0,
  24457. 0x80000,
  24458. 0x80080,
  24459. 0x80040,
  24460. 0x900e0,
  24461. 0x70104,
  24462. 0x80058,
  24463. 0x80018,
  24464. 0x90090,
  24465. 0x70114,
  24466. 0x80078,
  24467. 0x80038,
  24468. 0x900d0,
  24469. 0x7010c,
  24470. 0x80068,
  24471. 0x80028,
  24472. 0x900b0,
  24473. 0x80008,
  24474. 0x80088,
  24475. 0x80048,
  24476. 0x900f0,
  24477. 0x70102,
  24478. 0x80054,
  24479. 0x80014,
  24480. 0x8011c,
  24481. 0x70112,
  24482. 0x80074,
  24483. 0x80034,
  24484. 0x900c8,
  24485. 0x7010a,
  24486. 0x80064,
  24487. 0x80024,
  24488. 0x900a8,
  24489. 0x80004,
  24490. 0x80084,
  24491. 0x80044,
  24492. 0x900e8,
  24493. 0x70106,
  24494. 0x8005c,
  24495. 0x8001c,
  24496. 0x90098,
  24497. 0x70116,
  24498. 0x8007c,
  24499. 0x8003c,
  24500. 0x900d8,
  24501. 0x7010e,
  24502. 0x8006c,
  24503. 0x8002c,
  24504. 0x900b8,
  24505. 0x8000c,
  24506. 0x8008c,
  24507. 0x8004c,
  24508. 0x900f8,
  24509. 0x70101,
  24510. 0x80052,
  24511. 0x80012,
  24512. 0x8011a,
  24513. 0x70111,
  24514. 0x80072,
  24515. 0x80032,
  24516. 0x900c4,
  24517. 0x70109,
  24518. 0x80062,
  24519. 0x80022,
  24520. 0x900a4,
  24521. 0x80002,
  24522. 0x80082,
  24523. 0x80042,
  24524. 0x900e4,
  24525. 0x70105,
  24526. 0x8005a,
  24527. 0x8001a,
  24528. 0x90094,
  24529. 0x70115,
  24530. 0x8007a,
  24531. 0x8003a,
  24532. 0x900d4,
  24533. 0x7010d,
  24534. 0x8006a,
  24535. 0x8002a,
  24536. 0x900b4,
  24537. 0x8000a,
  24538. 0x8008a,
  24539. 0x8004a,
  24540. 0x900f4,
  24541. 0x70103,
  24542. 0x80056,
  24543. 0x80016,
  24544. 0x8011e,
  24545. 0x70113,
  24546. 0x80076,
  24547. 0x80036,
  24548. 0x900cc,
  24549. 0x7010b,
  24550. 0x80066,
  24551. 0x80026,
  24552. 0x900ac,
  24553. 0x80006,
  24554. 0x80086,
  24555. 0x80046,
  24556. 0x900ec,
  24557. 0x70107,
  24558. 0x8005e,
  24559. 0x8001e,
  24560. 0x9009c,
  24561. 0x70117,
  24562. 0x8007e,
  24563. 0x8003e,
  24564. 0x900dc,
  24565. 0x7010f,
  24566. 0x8006e,
  24567. 0x8002e,
  24568. 0x900bc,
  24569. 0x8000e,
  24570. 0x8008e,
  24571. 0x8004e,
  24572. 0x900fc,
  24573. 0x70100,
  24574. 0x80051,
  24575. 0x80011,
  24576. 0x80119,
  24577. 0x70110,
  24578. 0x80071,
  24579. 0x80031,
  24580. 0x900c2,
  24581. 0x70108,
  24582. 0x80061,
  24583. 0x80021,
  24584. 0x900a2,
  24585. 0x80001,
  24586. 0x80081,
  24587. 0x80041,
  24588. 0x900e2,
  24589. 0x70104,
  24590. 0x80059,
  24591. 0x80019,
  24592. 0x90092,
  24593. 0x70114,
  24594. 0x80079,
  24595. 0x80039,
  24596. 0x900d2,
  24597. 0x7010c,
  24598. 0x80069,
  24599. 0x80029,
  24600. 0x900b2,
  24601. 0x80009,
  24602. 0x80089,
  24603. 0x80049,
  24604. 0x900f2,
  24605. 0x70102,
  24606. 0x80055,
  24607. 0x80015,
  24608. 0x8011d,
  24609. 0x70112,
  24610. 0x80075,
  24611. 0x80035,
  24612. 0x900ca,
  24613. 0x7010a,
  24614. 0x80065,
  24615. 0x80025,
  24616. 0x900aa,
  24617. 0x80005,
  24618. 0x80085,
  24619. 0x80045,
  24620. 0x900ea,
  24621. 0x70106,
  24622. 0x8005d,
  24623. 0x8001d,
  24624. 0x9009a,
  24625. 0x70116,
  24626. 0x8007d,
  24627. 0x8003d,
  24628. 0x900da,
  24629. 0x7010e,
  24630. 0x8006d,
  24631. 0x8002d,
  24632. 0x900ba,
  24633. 0x8000d,
  24634. 0x8008d,
  24635. 0x8004d,
  24636. 0x900fa,
  24637. 0x70101,
  24638. 0x80053,
  24639. 0x80013,
  24640. 0x8011b,
  24641. 0x70111,
  24642. 0x80073,
  24643. 0x80033,
  24644. 0x900c6,
  24645. 0x70109,
  24646. 0x80063,
  24647. 0x80023,
  24648. 0x900a6,
  24649. 0x80003,
  24650. 0x80083,
  24651. 0x80043,
  24652. 0x900e6,
  24653. 0x70105,
  24654. 0x8005b,
  24655. 0x8001b,
  24656. 0x90096,
  24657. 0x70115,
  24658. 0x8007b,
  24659. 0x8003b,
  24660. 0x900d6,
  24661. 0x7010d,
  24662. 0x8006b,
  24663. 0x8002b,
  24664. 0x900b6,
  24665. 0x8000b,
  24666. 0x8008b,
  24667. 0x8004b,
  24668. 0x900f6,
  24669. 0x70103,
  24670. 0x80057,
  24671. 0x80017,
  24672. 0x8011f,
  24673. 0x70113,
  24674. 0x80077,
  24675. 0x80037,
  24676. 0x900ce,
  24677. 0x7010b,
  24678. 0x80067,
  24679. 0x80027,
  24680. 0x900ae,
  24681. 0x80007,
  24682. 0x80087,
  24683. 0x80047,
  24684. 0x900ee,
  24685. 0x70107,
  24686. 0x8005f,
  24687. 0x8001f,
  24688. 0x9009e,
  24689. 0x70117,
  24690. 0x8007f,
  24691. 0x8003f,
  24692. 0x900de,
  24693. 0x7010f,
  24694. 0x8006f,
  24695. 0x8002f,
  24696. 0x900be,
  24697. 0x8000f,
  24698. 0x8008f,
  24699. 0x8004f,
  24700. 0x900fe,
  24701. 0x70100,
  24702. 0x80050,
  24703. 0x80010,
  24704. 0x80118,
  24705. 0x70110,
  24706. 0x80070,
  24707. 0x80030,
  24708. 0x900c1,
  24709. 0x70108,
  24710. 0x80060,
  24711. 0x80020,
  24712. 0x900a1,
  24713. 0x80000,
  24714. 0x80080,
  24715. 0x80040,
  24716. 0x900e1,
  24717. 0x70104,
  24718. 0x80058,
  24719. 0x80018,
  24720. 0x90091,
  24721. 0x70114,
  24722. 0x80078,
  24723. 0x80038,
  24724. 0x900d1,
  24725. 0x7010c,
  24726. 0x80068,
  24727. 0x80028,
  24728. 0x900b1,
  24729. 0x80008,
  24730. 0x80088,
  24731. 0x80048,
  24732. 0x900f1,
  24733. 0x70102,
  24734. 0x80054,
  24735. 0x80014,
  24736. 0x8011c,
  24737. 0x70112,
  24738. 0x80074,
  24739. 0x80034,
  24740. 0x900c9,
  24741. 0x7010a,
  24742. 0x80064,
  24743. 0x80024,
  24744. 0x900a9,
  24745. 0x80004,
  24746. 0x80084,
  24747. 0x80044,
  24748. 0x900e9,
  24749. 0x70106,
  24750. 0x8005c,
  24751. 0x8001c,
  24752. 0x90099,
  24753. 0x70116,
  24754. 0x8007c,
  24755. 0x8003c,
  24756. 0x900d9,
  24757. 0x7010e,
  24758. 0x8006c,
  24759. 0x8002c,
  24760. 0x900b9,
  24761. 0x8000c,
  24762. 0x8008c,
  24763. 0x8004c,
  24764. 0x900f9,
  24765. 0x70101,
  24766. 0x80052,
  24767. 0x80012,
  24768. 0x8011a,
  24769. 0x70111,
  24770. 0x80072,
  24771. 0x80032,
  24772. 0x900c5,
  24773. 0x70109,
  24774. 0x80062,
  24775. 0x80022,
  24776. 0x900a5,
  24777. 0x80002,
  24778. 0x80082,
  24779. 0x80042,
  24780. 0x900e5,
  24781. 0x70105,
  24782. 0x8005a,
  24783. 0x8001a,
  24784. 0x90095,
  24785. 0x70115,
  24786. 0x8007a,
  24787. 0x8003a,
  24788. 0x900d5,
  24789. 0x7010d,
  24790. 0x8006a,
  24791. 0x8002a,
  24792. 0x900b5,
  24793. 0x8000a,
  24794. 0x8008a,
  24795. 0x8004a,
  24796. 0x900f5,
  24797. 0x70103,
  24798. 0x80056,
  24799. 0x80016,
  24800. 0x8011e,
  24801. 0x70113,
  24802. 0x80076,
  24803. 0x80036,
  24804. 0x900cd,
  24805. 0x7010b,
  24806. 0x80066,
  24807. 0x80026,
  24808. 0x900ad,
  24809. 0x80006,
  24810. 0x80086,
  24811. 0x80046,
  24812. 0x900ed,
  24813. 0x70107,
  24814. 0x8005e,
  24815. 0x8001e,
  24816. 0x9009d,
  24817. 0x70117,
  24818. 0x8007e,
  24819. 0x8003e,
  24820. 0x900dd,
  24821. 0x7010f,
  24822. 0x8006e,
  24823. 0x8002e,
  24824. 0x900bd,
  24825. 0x8000e,
  24826. 0x8008e,
  24827. 0x8004e,
  24828. 0x900fd,
  24829. 0x70100,
  24830. 0x80051,
  24831. 0x80011,
  24832. 0x80119,
  24833. 0x70110,
  24834. 0x80071,
  24835. 0x80031,
  24836. 0x900c3,
  24837. 0x70108,
  24838. 0x80061,
  24839. 0x80021,
  24840. 0x900a3,
  24841. 0x80001,
  24842. 0x80081,
  24843. 0x80041,
  24844. 0x900e3,
  24845. 0x70104,
  24846. 0x80059,
  24847. 0x80019,
  24848. 0x90093,
  24849. 0x70114,
  24850. 0x80079,
  24851. 0x80039,
  24852. 0x900d3,
  24853. 0x7010c,
  24854. 0x80069,
  24855. 0x80029,
  24856. 0x900b3,
  24857. 0x80009,
  24858. 0x80089,
  24859. 0x80049,
  24860. 0x900f3,
  24861. 0x70102,
  24862. 0x80055,
  24863. 0x80015,
  24864. 0x8011d,
  24865. 0x70112,
  24866. 0x80075,
  24867. 0x80035,
  24868. 0x900cb,
  24869. 0x7010a,
  24870. 0x80065,
  24871. 0x80025,
  24872. 0x900ab,
  24873. 0x80005,
  24874. 0x80085,
  24875. 0x80045,
  24876. 0x900eb,
  24877. 0x70106,
  24878. 0x8005d,
  24879. 0x8001d,
  24880. 0x9009b,
  24881. 0x70116,
  24882. 0x8007d,
  24883. 0x8003d,
  24884. 0x900db,
  24885. 0x7010e,
  24886. 0x8006d,
  24887. 0x8002d,
  24888. 0x900bb,
  24889. 0x8000d,
  24890. 0x8008d,
  24891. 0x8004d,
  24892. 0x900fb,
  24893. 0x70101,
  24894. 0x80053,
  24895. 0x80013,
  24896. 0x8011b,
  24897. 0x70111,
  24898. 0x80073,
  24899. 0x80033,
  24900. 0x900c7,
  24901. 0x70109,
  24902. 0x80063,
  24903. 0x80023,
  24904. 0x900a7,
  24905. 0x80003,
  24906. 0x80083,
  24907. 0x80043,
  24908. 0x900e7,
  24909. 0x70105,
  24910. 0x8005b,
  24911. 0x8001b,
  24912. 0x90097,
  24913. 0x70115,
  24914. 0x8007b,
  24915. 0x8003b,
  24916. 0x900d7,
  24917. 0x7010d,
  24918. 0x8006b,
  24919. 0x8002b,
  24920. 0x900b7,
  24921. 0x8000b,
  24922. 0x8008b,
  24923. 0x8004b,
  24924. 0x900f7,
  24925. 0x70103,
  24926. 0x80057,
  24927. 0x80017,
  24928. 0x8011f,
  24929. 0x70113,
  24930. 0x80077,
  24931. 0x80037,
  24932. 0x900cf,
  24933. 0x7010b,
  24934. 0x80067,
  24935. 0x80027,
  24936. 0x900af,
  24937. 0x80007,
  24938. 0x80087,
  24939. 0x80047,
  24940. 0x900ef,
  24941. 0x70107,
  24942. 0x8005f,
  24943. 0x8001f,
  24944. 0x9009f,
  24945. 0x70117,
  24946. 0x8007f,
  24947. 0x8003f,
  24948. 0x900df,
  24949. 0x7010f,
  24950. 0x8006f,
  24951. 0x8002f,
  24952. 0x900bf,
  24953. 0x8000f,
  24954. 0x8008f,
  24955. 0x8004f,
  24956. 0x900ff
  24957. ]),
  24958. 9
  24959. ];
  24960. var fixedDistCodeTab = [
  24961. new Int32Array([
  24962. 0x50000,
  24963. 0x50010,
  24964. 0x50008,
  24965. 0x50018,
  24966. 0x50004,
  24967. 0x50014,
  24968. 0x5000c,
  24969. 0x5001c,
  24970. 0x50002,
  24971. 0x50012,
  24972. 0x5000a,
  24973. 0x5001a,
  24974. 0x50006,
  24975. 0x50016,
  24976. 0x5000e,
  24977. 0x00000,
  24978. 0x50001,
  24979. 0x50011,
  24980. 0x50009,
  24981. 0x50019,
  24982. 0x50005,
  24983. 0x50015,
  24984. 0x5000d,
  24985. 0x5001d,
  24986. 0x50003,
  24987. 0x50013,
  24988. 0x5000b,
  24989. 0x5001b,
  24990. 0x50007,
  24991. 0x50017,
  24992. 0x5000f,
  24993. 0x00000
  24994. ]),
  24995. 5
  24996. ];
  24997. function FlateStream(str, maybeLength) {
  24998. this.str = str;
  24999. this.dict = str.dict;
  25000. var cmf = str.getByte();
  25001. var flg = str.getByte();
  25002. if (cmf === -1 || flg === -1) {
  25003. error('Invalid header in flate stream: ' + cmf + ', ' + flg);
  25004. }
  25005. if ((cmf & 0x0f) !== 0x08) {
  25006. error('Unknown compression method in flate stream: ' + cmf + ', ' + flg);
  25007. }
  25008. if (((cmf << 8) + flg) % 31 !== 0) {
  25009. error('Bad FCHECK in flate stream: ' + cmf + ', ' + flg);
  25010. }
  25011. if (flg & 0x20) {
  25012. error('FDICT bit set in flate stream: ' + cmf + ', ' + flg);
  25013. }
  25014. this.codeSize = 0;
  25015. this.codeBuf = 0;
  25016. DecodeStream.call(this, maybeLength);
  25017. }
  25018. FlateStream.prototype = Object.create(DecodeStream.prototype);
  25019. FlateStream.prototype.getBits = function FlateStream_getBits(bits) {
  25020. var str = this.str;
  25021. var codeSize = this.codeSize;
  25022. var codeBuf = this.codeBuf;
  25023. var b;
  25024. while (codeSize < bits) {
  25025. if ((b = str.getByte()) === -1) {
  25026. error('Bad encoding in flate stream');
  25027. }
  25028. codeBuf |= b << codeSize;
  25029. codeSize += 8;
  25030. }
  25031. b = codeBuf & (1 << bits) - 1;
  25032. this.codeBuf = codeBuf >> bits;
  25033. this.codeSize = codeSize -= bits;
  25034. return b;
  25035. };
  25036. FlateStream.prototype.getCode = function FlateStream_getCode(table) {
  25037. var str = this.str;
  25038. var codes = table[0];
  25039. var maxLen = table[1];
  25040. var codeSize = this.codeSize;
  25041. var codeBuf = this.codeBuf;
  25042. var b;
  25043. while (codeSize < maxLen) {
  25044. if ((b = str.getByte()) === -1) {
  25045. // premature end of stream. code might however still be valid.
  25046. // codeSize < codeLen check below guards against incomplete codeVal.
  25047. break;
  25048. }
  25049. codeBuf |= b << codeSize;
  25050. codeSize += 8;
  25051. }
  25052. var code = codes[codeBuf & (1 << maxLen) - 1];
  25053. var codeLen = code >> 16;
  25054. var codeVal = code & 0xffff;
  25055. if (codeLen < 1 || codeSize < codeLen) {
  25056. error('Bad encoding in flate stream');
  25057. }
  25058. this.codeBuf = codeBuf >> codeLen;
  25059. this.codeSize = codeSize - codeLen;
  25060. return codeVal;
  25061. };
  25062. FlateStream.prototype.generateHuffmanTable = function flateStreamGenerateHuffmanTable(lengths) {
  25063. var n = lengths.length;
  25064. // find max code length
  25065. var maxLen = 0;
  25066. var i;
  25067. for (i = 0; i < n; ++i) {
  25068. if (lengths[i] > maxLen) {
  25069. maxLen = lengths[i];
  25070. }
  25071. }
  25072. // build the table
  25073. var size = 1 << maxLen;
  25074. var codes = new Int32Array(size);
  25075. for (var len = 1, code = 0, skip = 2; len <= maxLen; ++len, code <<= 1, skip <<= 1) {
  25076. for (var val = 0; val < n; ++val) {
  25077. if (lengths[val] === len) {
  25078. // bit-reverse the code
  25079. var code2 = 0;
  25080. var t = code;
  25081. for (i = 0; i < len; ++i) {
  25082. code2 = code2 << 1 | t & 1;
  25083. t >>= 1;
  25084. }
  25085. // fill the table entries
  25086. for (i = code2; i < size; i += skip) {
  25087. codes[i] = len << 16 | val;
  25088. }
  25089. ++code;
  25090. }
  25091. }
  25092. }
  25093. return [
  25094. codes,
  25095. maxLen
  25096. ];
  25097. };
  25098. FlateStream.prototype.readBlock = function FlateStream_readBlock() {
  25099. var buffer, len;
  25100. var str = this.str;
  25101. // read block header
  25102. var hdr = this.getBits(3);
  25103. if (hdr & 1) {
  25104. this.eof = true;
  25105. }
  25106. hdr >>= 1;
  25107. if (hdr === 0) {
  25108. // uncompressed block
  25109. var b;
  25110. if ((b = str.getByte()) === -1) {
  25111. error('Bad block header in flate stream');
  25112. }
  25113. var blockLen = b;
  25114. if ((b = str.getByte()) === -1) {
  25115. error('Bad block header in flate stream');
  25116. }
  25117. blockLen |= b << 8;
  25118. if ((b = str.getByte()) === -1) {
  25119. error('Bad block header in flate stream');
  25120. }
  25121. var check = b;
  25122. if ((b = str.getByte()) === -1) {
  25123. error('Bad block header in flate stream');
  25124. }
  25125. check |= b << 8;
  25126. if (check !== (~blockLen & 0xffff) && (blockLen !== 0 || check !== 0)) {
  25127. // Ignoring error for bad "empty" block (see issue 1277)
  25128. error('Bad uncompressed block length in flate stream');
  25129. }
  25130. this.codeBuf = 0;
  25131. this.codeSize = 0;
  25132. var bufferLength = this.bufferLength;
  25133. buffer = this.ensureBuffer(bufferLength + blockLen);
  25134. var end = bufferLength + blockLen;
  25135. this.bufferLength = end;
  25136. if (blockLen === 0) {
  25137. if (str.peekByte() === -1) {
  25138. this.eof = true;
  25139. }
  25140. } else {
  25141. for (var n = bufferLength; n < end; ++n) {
  25142. if ((b = str.getByte()) === -1) {
  25143. this.eof = true;
  25144. break;
  25145. }
  25146. buffer[n] = b;
  25147. }
  25148. }
  25149. return;
  25150. }
  25151. var litCodeTable;
  25152. var distCodeTable;
  25153. if (hdr === 1) {
  25154. // compressed block, fixed codes
  25155. litCodeTable = fixedLitCodeTab;
  25156. distCodeTable = fixedDistCodeTab;
  25157. } else if (hdr === 2) {
  25158. // compressed block, dynamic codes
  25159. var numLitCodes = this.getBits(5) + 257;
  25160. var numDistCodes = this.getBits(5) + 1;
  25161. var numCodeLenCodes = this.getBits(4) + 4;
  25162. // build the code lengths code table
  25163. var codeLenCodeLengths = new Uint8Array(codeLenCodeMap.length);
  25164. var i;
  25165. for (i = 0; i < numCodeLenCodes; ++i) {
  25166. codeLenCodeLengths[codeLenCodeMap[i]] = this.getBits(3);
  25167. }
  25168. var codeLenCodeTab = this.generateHuffmanTable(codeLenCodeLengths);
  25169. // build the literal and distance code tables
  25170. len = 0;
  25171. i = 0;
  25172. var codes = numLitCodes + numDistCodes;
  25173. var codeLengths = new Uint8Array(codes);
  25174. var bitsLength, bitsOffset, what;
  25175. while (i < codes) {
  25176. var code = this.getCode(codeLenCodeTab);
  25177. if (code === 16) {
  25178. bitsLength = 2;
  25179. bitsOffset = 3;
  25180. what = len;
  25181. } else if (code === 17) {
  25182. bitsLength = 3;
  25183. bitsOffset = 3;
  25184. what = len = 0;
  25185. } else if (code === 18) {
  25186. bitsLength = 7;
  25187. bitsOffset = 11;
  25188. what = len = 0;
  25189. } else {
  25190. codeLengths[i++] = len = code;
  25191. continue;
  25192. }
  25193. var repeatLength = this.getBits(bitsLength) + bitsOffset;
  25194. while (repeatLength-- > 0) {
  25195. codeLengths[i++] = what;
  25196. }
  25197. }
  25198. litCodeTable = this.generateHuffmanTable(codeLengths.subarray(0, numLitCodes));
  25199. distCodeTable = this.generateHuffmanTable(codeLengths.subarray(numLitCodes, codes));
  25200. } else {
  25201. error('Unknown block type in flate stream');
  25202. }
  25203. buffer = this.buffer;
  25204. var limit = buffer ? buffer.length : 0;
  25205. var pos = this.bufferLength;
  25206. while (true) {
  25207. var code1 = this.getCode(litCodeTable);
  25208. if (code1 < 256) {
  25209. if (pos + 1 >= limit) {
  25210. buffer = this.ensureBuffer(pos + 1);
  25211. limit = buffer.length;
  25212. }
  25213. buffer[pos++] = code1;
  25214. continue;
  25215. }
  25216. if (code1 === 256) {
  25217. this.bufferLength = pos;
  25218. return;
  25219. }
  25220. code1 -= 257;
  25221. code1 = lengthDecode[code1];
  25222. var code2 = code1 >> 16;
  25223. if (code2 > 0) {
  25224. code2 = this.getBits(code2);
  25225. }
  25226. len = (code1 & 0xffff) + code2;
  25227. code1 = this.getCode(distCodeTable);
  25228. code1 = distDecode[code1];
  25229. code2 = code1 >> 16;
  25230. if (code2 > 0) {
  25231. code2 = this.getBits(code2);
  25232. }
  25233. var dist = (code1 & 0xffff) + code2;
  25234. if (pos + len >= limit) {
  25235. buffer = this.ensureBuffer(pos + len);
  25236. limit = buffer.length;
  25237. }
  25238. for (var k = 0; k < len; ++k, ++pos) {
  25239. buffer[pos] = buffer[pos - dist];
  25240. }
  25241. }
  25242. };
  25243. return FlateStream;
  25244. }();
  25245. var PredictorStream = function PredictorStreamClosure() {
  25246. function PredictorStream(str, maybeLength, params) {
  25247. if (!isDict(params)) {
  25248. return str;
  25249. }
  25250. // no prediction
  25251. var predictor = this.predictor = params.get('Predictor') || 1;
  25252. if (predictor <= 1) {
  25253. return str;
  25254. }
  25255. // no prediction
  25256. if (predictor !== 2 && (predictor < 10 || predictor > 15)) {
  25257. error('Unsupported predictor: ' + predictor);
  25258. }
  25259. if (predictor === 2) {
  25260. this.readBlock = this.readBlockTiff;
  25261. } else {
  25262. this.readBlock = this.readBlockPng;
  25263. }
  25264. this.str = str;
  25265. this.dict = str.dict;
  25266. var colors = this.colors = params.get('Colors') || 1;
  25267. var bits = this.bits = params.get('BitsPerComponent') || 8;
  25268. var columns = this.columns = params.get('Columns') || 1;
  25269. this.pixBytes = colors * bits + 7 >> 3;
  25270. this.rowBytes = columns * colors * bits + 7 >> 3;
  25271. DecodeStream.call(this, maybeLength);
  25272. return this;
  25273. }
  25274. PredictorStream.prototype = Object.create(DecodeStream.prototype);
  25275. PredictorStream.prototype.readBlockTiff = function predictorStreamReadBlockTiff() {
  25276. var rowBytes = this.rowBytes;
  25277. var bufferLength = this.bufferLength;
  25278. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  25279. var bits = this.bits;
  25280. var colors = this.colors;
  25281. var rawBytes = this.str.getBytes(rowBytes);
  25282. this.eof = !rawBytes.length;
  25283. if (this.eof) {
  25284. return;
  25285. }
  25286. var inbuf = 0, outbuf = 0;
  25287. var inbits = 0, outbits = 0;
  25288. var pos = bufferLength;
  25289. var i;
  25290. if (bits === 1) {
  25291. for (i = 0; i < rowBytes; ++i) {
  25292. var c = rawBytes[i];
  25293. inbuf = inbuf << 8 | c;
  25294. // bitwise addition is exclusive or
  25295. // first shift inbuf and then add
  25296. buffer[pos++] = (c ^ inbuf >> colors) & 0xFF;
  25297. // truncate inbuf (assumes colors < 16)
  25298. inbuf &= 0xFFFF;
  25299. }
  25300. } else if (bits === 8) {
  25301. for (i = 0; i < colors; ++i) {
  25302. buffer[pos++] = rawBytes[i];
  25303. }
  25304. for (; i < rowBytes; ++i) {
  25305. buffer[pos] = buffer[pos - colors] + rawBytes[i];
  25306. pos++;
  25307. }
  25308. } else {
  25309. var compArray = new Uint8Array(colors + 1);
  25310. var bitMask = (1 << bits) - 1;
  25311. var j = 0, k = bufferLength;
  25312. var columns = this.columns;
  25313. for (i = 0; i < columns; ++i) {
  25314. for (var kk = 0; kk < colors; ++kk) {
  25315. if (inbits < bits) {
  25316. inbuf = inbuf << 8 | rawBytes[j++] & 0xFF;
  25317. inbits += 8;
  25318. }
  25319. compArray[kk] = compArray[kk] + (inbuf >> inbits - bits) & bitMask;
  25320. inbits -= bits;
  25321. outbuf = outbuf << bits | compArray[kk];
  25322. outbits += bits;
  25323. if (outbits >= 8) {
  25324. buffer[k++] = outbuf >> outbits - 8 & 0xFF;
  25325. outbits -= 8;
  25326. }
  25327. }
  25328. }
  25329. if (outbits > 0) {
  25330. buffer[k++] = (outbuf << 8 - outbits) + (inbuf & (1 << 8 - outbits) - 1);
  25331. }
  25332. }
  25333. this.bufferLength += rowBytes;
  25334. };
  25335. PredictorStream.prototype.readBlockPng = function predictorStreamReadBlockPng() {
  25336. var rowBytes = this.rowBytes;
  25337. var pixBytes = this.pixBytes;
  25338. var predictor = this.str.getByte();
  25339. var rawBytes = this.str.getBytes(rowBytes);
  25340. this.eof = !rawBytes.length;
  25341. if (this.eof) {
  25342. return;
  25343. }
  25344. var bufferLength = this.bufferLength;
  25345. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  25346. var prevRow = buffer.subarray(bufferLength - rowBytes, bufferLength);
  25347. if (prevRow.length === 0) {
  25348. prevRow = new Uint8Array(rowBytes);
  25349. }
  25350. var i, j = bufferLength, up, c;
  25351. switch (predictor) {
  25352. case 0:
  25353. for (i = 0; i < rowBytes; ++i) {
  25354. buffer[j++] = rawBytes[i];
  25355. }
  25356. break;
  25357. case 1:
  25358. for (i = 0; i < pixBytes; ++i) {
  25359. buffer[j++] = rawBytes[i];
  25360. }
  25361. for (; i < rowBytes; ++i) {
  25362. buffer[j] = buffer[j - pixBytes] + rawBytes[i] & 0xFF;
  25363. j++;
  25364. }
  25365. break;
  25366. case 2:
  25367. for (i = 0; i < rowBytes; ++i) {
  25368. buffer[j++] = prevRow[i] + rawBytes[i] & 0xFF;
  25369. }
  25370. break;
  25371. case 3:
  25372. for (i = 0; i < pixBytes; ++i) {
  25373. buffer[j++] = (prevRow[i] >> 1) + rawBytes[i];
  25374. }
  25375. for (; i < rowBytes; ++i) {
  25376. buffer[j] = (prevRow[i] + buffer[j - pixBytes] >> 1) + rawBytes[i] & 0xFF;
  25377. j++;
  25378. }
  25379. break;
  25380. case 4:
  25381. // we need to save the up left pixels values. the simplest way
  25382. // is to create a new buffer
  25383. for (i = 0; i < pixBytes; ++i) {
  25384. up = prevRow[i];
  25385. c = rawBytes[i];
  25386. buffer[j++] = up + c;
  25387. }
  25388. for (; i < rowBytes; ++i) {
  25389. up = prevRow[i];
  25390. var upLeft = prevRow[i - pixBytes];
  25391. var left = buffer[j - pixBytes];
  25392. var p = left + up - upLeft;
  25393. var pa = p - left;
  25394. if (pa < 0) {
  25395. pa = -pa;
  25396. }
  25397. var pb = p - up;
  25398. if (pb < 0) {
  25399. pb = -pb;
  25400. }
  25401. var pc = p - upLeft;
  25402. if (pc < 0) {
  25403. pc = -pc;
  25404. }
  25405. c = rawBytes[i];
  25406. if (pa <= pb && pa <= pc) {
  25407. buffer[j++] = left + c;
  25408. } else if (pb <= pc) {
  25409. buffer[j++] = up + c;
  25410. } else {
  25411. buffer[j++] = upLeft + c;
  25412. }
  25413. }
  25414. break;
  25415. default:
  25416. error('Unsupported predictor: ' + predictor);
  25417. }
  25418. this.bufferLength += rowBytes;
  25419. };
  25420. return PredictorStream;
  25421. }();
  25422. /**
  25423. * Depending on the type of JPEG a JpegStream is handled in different ways. For
  25424. * JPEG's that are supported natively such as DeviceGray and DeviceRGB the image
  25425. * data is stored and then loaded by the browser. For unsupported JPEG's we use
  25426. * a library to decode these images and the stream behaves like all the other
  25427. * DecodeStreams.
  25428. */
  25429. var JpegStream = function JpegStreamClosure() {
  25430. function JpegStream(stream, maybeLength, dict, params) {
  25431. // Some images may contain 'junk' before the SOI (start-of-image) marker.
  25432. // Note: this seems to mainly affect inline images.
  25433. var ch;
  25434. while ((ch = stream.getByte()) !== -1) {
  25435. if (ch === 0xFF) {
  25436. // Find the first byte of the SOI marker (0xFFD8).
  25437. stream.skip(-1);
  25438. // Reset the stream position to the SOI.
  25439. break;
  25440. }
  25441. }
  25442. this.stream = stream;
  25443. this.maybeLength = maybeLength;
  25444. this.dict = dict;
  25445. this.params = params;
  25446. DecodeStream.call(this, maybeLength);
  25447. }
  25448. JpegStream.prototype = Object.create(DecodeStream.prototype);
  25449. Object.defineProperty(JpegStream.prototype, 'bytes', {
  25450. get: function JpegStream_bytes() {
  25451. // If this.maybeLength is null, we'll get the entire stream.
  25452. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  25453. },
  25454. configurable: true
  25455. });
  25456. JpegStream.prototype.ensureBuffer = function JpegStream_ensureBuffer(req) {
  25457. if (this.bufferLength) {
  25458. return;
  25459. }
  25460. var jpegImage = new JpegImage();
  25461. // Checking if values need to be transformed before conversion.
  25462. var decodeArr = this.dict.getArray('Decode', 'D');
  25463. if (this.forceRGB && isArray(decodeArr)) {
  25464. var bitsPerComponent = this.dict.get('BitsPerComponent') || 8;
  25465. var decodeArrLength = decodeArr.length;
  25466. var transform = new Int32Array(decodeArrLength);
  25467. var transformNeeded = false;
  25468. var maxValue = (1 << bitsPerComponent) - 1;
  25469. for (var i = 0; i < decodeArrLength; i += 2) {
  25470. transform[i] = (decodeArr[i + 1] - decodeArr[i]) * 256 | 0;
  25471. transform[i + 1] = decodeArr[i] * maxValue | 0;
  25472. if (transform[i] !== 256 || transform[i + 1] !== 0) {
  25473. transformNeeded = true;
  25474. }
  25475. }
  25476. if (transformNeeded) {
  25477. jpegImage.decodeTransform = transform;
  25478. }
  25479. }
  25480. // Fetching the 'ColorTransform' entry, if it exists.
  25481. if (isDict(this.params)) {
  25482. var colorTransform = this.params.get('ColorTransform');
  25483. if (isInt(colorTransform)) {
  25484. jpegImage.colorTransform = colorTransform;
  25485. }
  25486. }
  25487. jpegImage.parse(this.bytes);
  25488. var data = jpegImage.getData(this.drawWidth, this.drawHeight, this.forceRGB);
  25489. this.buffer = data;
  25490. this.bufferLength = data.length;
  25491. this.eof = true;
  25492. };
  25493. JpegStream.prototype.getBytes = function JpegStream_getBytes(length) {
  25494. this.ensureBuffer();
  25495. return this.buffer;
  25496. };
  25497. JpegStream.prototype.getIR = function JpegStream_getIR(forceDataSchema) {
  25498. return createObjectURL(this.bytes, 'image/jpeg', forceDataSchema);
  25499. };
  25500. return JpegStream;
  25501. }();
  25502. /**
  25503. * For JPEG 2000's we use a library to decode these images and
  25504. * the stream behaves like all the other DecodeStreams.
  25505. */
  25506. var JpxStream = function JpxStreamClosure() {
  25507. function JpxStream(stream, maybeLength, dict, params) {
  25508. this.stream = stream;
  25509. this.maybeLength = maybeLength;
  25510. this.dict = dict;
  25511. this.params = params;
  25512. DecodeStream.call(this, maybeLength);
  25513. }
  25514. JpxStream.prototype = Object.create(DecodeStream.prototype);
  25515. Object.defineProperty(JpxStream.prototype, 'bytes', {
  25516. get: function JpxStream_bytes() {
  25517. // If this.maybeLength is null, we'll get the entire stream.
  25518. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  25519. },
  25520. configurable: true
  25521. });
  25522. JpxStream.prototype.ensureBuffer = function JpxStream_ensureBuffer(req) {
  25523. if (this.bufferLength) {
  25524. return;
  25525. }
  25526. var jpxImage = new JpxImage();
  25527. jpxImage.parse(this.bytes);
  25528. var width = jpxImage.width;
  25529. var height = jpxImage.height;
  25530. var componentsCount = jpxImage.componentsCount;
  25531. var tileCount = jpxImage.tiles.length;
  25532. if (tileCount === 1) {
  25533. this.buffer = jpxImage.tiles[0].items;
  25534. } else {
  25535. var data = new Uint8Array(width * height * componentsCount);
  25536. for (var k = 0; k < tileCount; k++) {
  25537. var tileComponents = jpxImage.tiles[k];
  25538. var tileWidth = tileComponents.width;
  25539. var tileHeight = tileComponents.height;
  25540. var tileLeft = tileComponents.left;
  25541. var tileTop = tileComponents.top;
  25542. var src = tileComponents.items;
  25543. var srcPosition = 0;
  25544. var dataPosition = (width * tileTop + tileLeft) * componentsCount;
  25545. var imgRowSize = width * componentsCount;
  25546. var tileRowSize = tileWidth * componentsCount;
  25547. for (var j = 0; j < tileHeight; j++) {
  25548. var rowBytes = src.subarray(srcPosition, srcPosition + tileRowSize);
  25549. data.set(rowBytes, dataPosition);
  25550. srcPosition += tileRowSize;
  25551. dataPosition += imgRowSize;
  25552. }
  25553. }
  25554. this.buffer = data;
  25555. }
  25556. this.bufferLength = this.buffer.length;
  25557. this.eof = true;
  25558. };
  25559. return JpxStream;
  25560. }();
  25561. /**
  25562. * For JBIG2's we use a library to decode these images and
  25563. * the stream behaves like all the other DecodeStreams.
  25564. */
  25565. var Jbig2Stream = function Jbig2StreamClosure() {
  25566. function Jbig2Stream(stream, maybeLength, dict, params) {
  25567. this.stream = stream;
  25568. this.maybeLength = maybeLength;
  25569. this.dict = dict;
  25570. this.params = params;
  25571. DecodeStream.call(this, maybeLength);
  25572. }
  25573. Jbig2Stream.prototype = Object.create(DecodeStream.prototype);
  25574. Object.defineProperty(Jbig2Stream.prototype, 'bytes', {
  25575. get: function Jbig2Stream_bytes() {
  25576. // If this.maybeLength is null, we'll get the entire stream.
  25577. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  25578. },
  25579. configurable: true
  25580. });
  25581. Jbig2Stream.prototype.ensureBuffer = function Jbig2Stream_ensureBuffer(req) {
  25582. if (this.bufferLength) {
  25583. return;
  25584. }
  25585. var jbig2Image = new Jbig2Image();
  25586. var chunks = [];
  25587. if (isDict(this.params)) {
  25588. var globalsStream = this.params.get('JBIG2Globals');
  25589. if (isStream(globalsStream)) {
  25590. var globals = globalsStream.getBytes();
  25591. chunks.push({
  25592. data: globals,
  25593. start: 0,
  25594. end: globals.length
  25595. });
  25596. }
  25597. }
  25598. chunks.push({
  25599. data: this.bytes,
  25600. start: 0,
  25601. end: this.bytes.length
  25602. });
  25603. var data = jbig2Image.parseChunks(chunks);
  25604. var dataLength = data.length;
  25605. // JBIG2 had black as 1 and white as 0, inverting the colors
  25606. for (var i = 0; i < dataLength; i++) {
  25607. data[i] ^= 0xFF;
  25608. }
  25609. this.buffer = data;
  25610. this.bufferLength = dataLength;
  25611. this.eof = true;
  25612. };
  25613. return Jbig2Stream;
  25614. }();
  25615. var DecryptStream = function DecryptStreamClosure() {
  25616. function DecryptStream(str, maybeLength, decrypt) {
  25617. this.str = str;
  25618. this.dict = str.dict;
  25619. this.decrypt = decrypt;
  25620. this.nextChunk = null;
  25621. this.initialized = false;
  25622. DecodeStream.call(this, maybeLength);
  25623. }
  25624. var chunkSize = 512;
  25625. DecryptStream.prototype = Object.create(DecodeStream.prototype);
  25626. DecryptStream.prototype.readBlock = function DecryptStream_readBlock() {
  25627. var chunk;
  25628. if (this.initialized) {
  25629. chunk = this.nextChunk;
  25630. } else {
  25631. chunk = this.str.getBytes(chunkSize);
  25632. this.initialized = true;
  25633. }
  25634. if (!chunk || chunk.length === 0) {
  25635. this.eof = true;
  25636. return;
  25637. }
  25638. this.nextChunk = this.str.getBytes(chunkSize);
  25639. var hasMoreData = this.nextChunk && this.nextChunk.length > 0;
  25640. var decrypt = this.decrypt;
  25641. chunk = decrypt(chunk, !hasMoreData);
  25642. var bufferLength = this.bufferLength;
  25643. var i, n = chunk.length;
  25644. var buffer = this.ensureBuffer(bufferLength + n);
  25645. for (i = 0; i < n; i++) {
  25646. buffer[bufferLength++] = chunk[i];
  25647. }
  25648. this.bufferLength = bufferLength;
  25649. };
  25650. return DecryptStream;
  25651. }();
  25652. var Ascii85Stream = function Ascii85StreamClosure() {
  25653. function Ascii85Stream(str, maybeLength) {
  25654. this.str = str;
  25655. this.dict = str.dict;
  25656. this.input = new Uint8Array(5);
  25657. // Most streams increase in size when decoded, but Ascii85 streams
  25658. // typically shrink by ~20%.
  25659. if (maybeLength) {
  25660. maybeLength = 0.8 * maybeLength;
  25661. }
  25662. DecodeStream.call(this, maybeLength);
  25663. }
  25664. Ascii85Stream.prototype = Object.create(DecodeStream.prototype);
  25665. Ascii85Stream.prototype.readBlock = function Ascii85Stream_readBlock() {
  25666. var TILDA_CHAR = 0x7E;
  25667. // '~'
  25668. var Z_LOWER_CHAR = 0x7A;
  25669. // 'z'
  25670. var EOF = -1;
  25671. var str = this.str;
  25672. var c = str.getByte();
  25673. while (isSpace(c)) {
  25674. c = str.getByte();
  25675. }
  25676. if (c === EOF || c === TILDA_CHAR) {
  25677. this.eof = true;
  25678. return;
  25679. }
  25680. var bufferLength = this.bufferLength, buffer;
  25681. var i;
  25682. // special code for z
  25683. if (c === Z_LOWER_CHAR) {
  25684. buffer = this.ensureBuffer(bufferLength + 4);
  25685. for (i = 0; i < 4; ++i) {
  25686. buffer[bufferLength + i] = 0;
  25687. }
  25688. this.bufferLength += 4;
  25689. } else {
  25690. var input = this.input;
  25691. input[0] = c;
  25692. for (i = 1; i < 5; ++i) {
  25693. c = str.getByte();
  25694. while (isSpace(c)) {
  25695. c = str.getByte();
  25696. }
  25697. input[i] = c;
  25698. if (c === EOF || c === TILDA_CHAR) {
  25699. break;
  25700. }
  25701. }
  25702. buffer = this.ensureBuffer(bufferLength + i - 1);
  25703. this.bufferLength += i - 1;
  25704. // partial ending;
  25705. if (i < 5) {
  25706. for (; i < 5; ++i) {
  25707. input[i] = 0x21 + 84;
  25708. }
  25709. this.eof = true;
  25710. }
  25711. var t = 0;
  25712. for (i = 0; i < 5; ++i) {
  25713. t = t * 85 + (input[i] - 0x21);
  25714. }
  25715. for (i = 3; i >= 0; --i) {
  25716. buffer[bufferLength + i] = t & 0xFF;
  25717. t >>= 8;
  25718. }
  25719. }
  25720. };
  25721. return Ascii85Stream;
  25722. }();
  25723. var AsciiHexStream = function AsciiHexStreamClosure() {
  25724. function AsciiHexStream(str, maybeLength) {
  25725. this.str = str;
  25726. this.dict = str.dict;
  25727. this.firstDigit = -1;
  25728. // Most streams increase in size when decoded, but AsciiHex streams shrink
  25729. // by 50%.
  25730. if (maybeLength) {
  25731. maybeLength = 0.5 * maybeLength;
  25732. }
  25733. DecodeStream.call(this, maybeLength);
  25734. }
  25735. AsciiHexStream.prototype = Object.create(DecodeStream.prototype);
  25736. AsciiHexStream.prototype.readBlock = function AsciiHexStream_readBlock() {
  25737. var UPSTREAM_BLOCK_SIZE = 8000;
  25738. var bytes = this.str.getBytes(UPSTREAM_BLOCK_SIZE);
  25739. if (!bytes.length) {
  25740. this.eof = true;
  25741. return;
  25742. }
  25743. var maxDecodeLength = bytes.length + 1 >> 1;
  25744. var buffer = this.ensureBuffer(this.bufferLength + maxDecodeLength);
  25745. var bufferLength = this.bufferLength;
  25746. var firstDigit = this.firstDigit;
  25747. for (var i = 0, ii = bytes.length; i < ii; i++) {
  25748. var ch = bytes[i], digit;
  25749. if (ch >= 0x30 && ch <= 0x39) {
  25750. // '0'-'9'
  25751. digit = ch & 0x0F;
  25752. } else if (ch >= 0x41 && ch <= 0x46 || ch >= 0x61 && ch <= 0x66) {
  25753. // 'A'-'Z', 'a'-'z'
  25754. digit = (ch & 0x0F) + 9;
  25755. } else if (ch === 0x3E) {
  25756. // '>'
  25757. this.eof = true;
  25758. break;
  25759. } else {
  25760. // probably whitespace
  25761. continue;
  25762. }
  25763. // ignoring
  25764. if (firstDigit < 0) {
  25765. firstDigit = digit;
  25766. } else {
  25767. buffer[bufferLength++] = firstDigit << 4 | digit;
  25768. firstDigit = -1;
  25769. }
  25770. }
  25771. if (firstDigit >= 0 && this.eof) {
  25772. // incomplete byte
  25773. buffer[bufferLength++] = firstDigit << 4;
  25774. firstDigit = -1;
  25775. }
  25776. this.firstDigit = firstDigit;
  25777. this.bufferLength = bufferLength;
  25778. };
  25779. return AsciiHexStream;
  25780. }();
  25781. var RunLengthStream = function RunLengthStreamClosure() {
  25782. function RunLengthStream(str, maybeLength) {
  25783. this.str = str;
  25784. this.dict = str.dict;
  25785. DecodeStream.call(this, maybeLength);
  25786. }
  25787. RunLengthStream.prototype = Object.create(DecodeStream.prototype);
  25788. RunLengthStream.prototype.readBlock = function RunLengthStream_readBlock() {
  25789. // The repeatHeader has following format. The first byte defines type of run
  25790. // and amount of bytes to repeat/copy: n = 0 through 127 - copy next n bytes
  25791. // (in addition to the second byte from the header), n = 129 through 255 -
  25792. // duplicate the second byte from the header (257 - n) times, n = 128 - end.
  25793. var repeatHeader = this.str.getBytes(2);
  25794. if (!repeatHeader || repeatHeader.length < 2 || repeatHeader[0] === 128) {
  25795. this.eof = true;
  25796. return;
  25797. }
  25798. var buffer;
  25799. var bufferLength = this.bufferLength;
  25800. var n = repeatHeader[0];
  25801. if (n < 128) {
  25802. // copy n bytes
  25803. buffer = this.ensureBuffer(bufferLength + n + 1);
  25804. buffer[bufferLength++] = repeatHeader[1];
  25805. if (n > 0) {
  25806. var source = this.str.getBytes(n);
  25807. buffer.set(source, bufferLength);
  25808. bufferLength += n;
  25809. }
  25810. } else {
  25811. n = 257 - n;
  25812. var b = repeatHeader[1];
  25813. buffer = this.ensureBuffer(bufferLength + n + 1);
  25814. for (var i = 0; i < n; i++) {
  25815. buffer[bufferLength++] = b;
  25816. }
  25817. }
  25818. this.bufferLength = bufferLength;
  25819. };
  25820. return RunLengthStream;
  25821. }();
  25822. var CCITTFaxStream = function CCITTFaxStreamClosure() {
  25823. var ccittEOL = -2;
  25824. var ccittEOF = -1;
  25825. var twoDimPass = 0;
  25826. var twoDimHoriz = 1;
  25827. var twoDimVert0 = 2;
  25828. var twoDimVertR1 = 3;
  25829. var twoDimVertL1 = 4;
  25830. var twoDimVertR2 = 5;
  25831. var twoDimVertL2 = 6;
  25832. var twoDimVertR3 = 7;
  25833. var twoDimVertL3 = 8;
  25834. var twoDimTable = [
  25835. [
  25836. -1,
  25837. -1
  25838. ],
  25839. [
  25840. -1,
  25841. -1
  25842. ],
  25843. // 000000x
  25844. [
  25845. 7,
  25846. twoDimVertL3
  25847. ],
  25848. // 0000010
  25849. [
  25850. 7,
  25851. twoDimVertR3
  25852. ],
  25853. // 0000011
  25854. [
  25855. 6,
  25856. twoDimVertL2
  25857. ],
  25858. [
  25859. 6,
  25860. twoDimVertL2
  25861. ],
  25862. // 000010x
  25863. [
  25864. 6,
  25865. twoDimVertR2
  25866. ],
  25867. [
  25868. 6,
  25869. twoDimVertR2
  25870. ],
  25871. // 000011x
  25872. [
  25873. 4,
  25874. twoDimPass
  25875. ],
  25876. [
  25877. 4,
  25878. twoDimPass
  25879. ],
  25880. // 0001xxx
  25881. [
  25882. 4,
  25883. twoDimPass
  25884. ],
  25885. [
  25886. 4,
  25887. twoDimPass
  25888. ],
  25889. [
  25890. 4,
  25891. twoDimPass
  25892. ],
  25893. [
  25894. 4,
  25895. twoDimPass
  25896. ],
  25897. [
  25898. 4,
  25899. twoDimPass
  25900. ],
  25901. [
  25902. 4,
  25903. twoDimPass
  25904. ],
  25905. [
  25906. 3,
  25907. twoDimHoriz
  25908. ],
  25909. [
  25910. 3,
  25911. twoDimHoriz
  25912. ],
  25913. // 001xxxx
  25914. [
  25915. 3,
  25916. twoDimHoriz
  25917. ],
  25918. [
  25919. 3,
  25920. twoDimHoriz
  25921. ],
  25922. [
  25923. 3,
  25924. twoDimHoriz
  25925. ],
  25926. [
  25927. 3,
  25928. twoDimHoriz
  25929. ],
  25930. [
  25931. 3,
  25932. twoDimHoriz
  25933. ],
  25934. [
  25935. 3,
  25936. twoDimHoriz
  25937. ],
  25938. [
  25939. 3,
  25940. twoDimHoriz
  25941. ],
  25942. [
  25943. 3,
  25944. twoDimHoriz
  25945. ],
  25946. [
  25947. 3,
  25948. twoDimHoriz
  25949. ],
  25950. [
  25951. 3,
  25952. twoDimHoriz
  25953. ],
  25954. [
  25955. 3,
  25956. twoDimHoriz
  25957. ],
  25958. [
  25959. 3,
  25960. twoDimHoriz
  25961. ],
  25962. [
  25963. 3,
  25964. twoDimHoriz
  25965. ],
  25966. [
  25967. 3,
  25968. twoDimHoriz
  25969. ],
  25970. [
  25971. 3,
  25972. twoDimVertL1
  25973. ],
  25974. [
  25975. 3,
  25976. twoDimVertL1
  25977. ],
  25978. // 010xxxx
  25979. [
  25980. 3,
  25981. twoDimVertL1
  25982. ],
  25983. [
  25984. 3,
  25985. twoDimVertL1
  25986. ],
  25987. [
  25988. 3,
  25989. twoDimVertL1
  25990. ],
  25991. [
  25992. 3,
  25993. twoDimVertL1
  25994. ],
  25995. [
  25996. 3,
  25997. twoDimVertL1
  25998. ],
  25999. [
  26000. 3,
  26001. twoDimVertL1
  26002. ],
  26003. [
  26004. 3,
  26005. twoDimVertL1
  26006. ],
  26007. [
  26008. 3,
  26009. twoDimVertL1
  26010. ],
  26011. [
  26012. 3,
  26013. twoDimVertL1
  26014. ],
  26015. [
  26016. 3,
  26017. twoDimVertL1
  26018. ],
  26019. [
  26020. 3,
  26021. twoDimVertL1
  26022. ],
  26023. [
  26024. 3,
  26025. twoDimVertL1
  26026. ],
  26027. [
  26028. 3,
  26029. twoDimVertL1
  26030. ],
  26031. [
  26032. 3,
  26033. twoDimVertL1
  26034. ],
  26035. [
  26036. 3,
  26037. twoDimVertR1
  26038. ],
  26039. [
  26040. 3,
  26041. twoDimVertR1
  26042. ],
  26043. // 011xxxx
  26044. [
  26045. 3,
  26046. twoDimVertR1
  26047. ],
  26048. [
  26049. 3,
  26050. twoDimVertR1
  26051. ],
  26052. [
  26053. 3,
  26054. twoDimVertR1
  26055. ],
  26056. [
  26057. 3,
  26058. twoDimVertR1
  26059. ],
  26060. [
  26061. 3,
  26062. twoDimVertR1
  26063. ],
  26064. [
  26065. 3,
  26066. twoDimVertR1
  26067. ],
  26068. [
  26069. 3,
  26070. twoDimVertR1
  26071. ],
  26072. [
  26073. 3,
  26074. twoDimVertR1
  26075. ],
  26076. [
  26077. 3,
  26078. twoDimVertR1
  26079. ],
  26080. [
  26081. 3,
  26082. twoDimVertR1
  26083. ],
  26084. [
  26085. 3,
  26086. twoDimVertR1
  26087. ],
  26088. [
  26089. 3,
  26090. twoDimVertR1
  26091. ],
  26092. [
  26093. 3,
  26094. twoDimVertR1
  26095. ],
  26096. [
  26097. 3,
  26098. twoDimVertR1
  26099. ],
  26100. [
  26101. 1,
  26102. twoDimVert0
  26103. ],
  26104. [
  26105. 1,
  26106. twoDimVert0
  26107. ],
  26108. // 1xxxxxx
  26109. [
  26110. 1,
  26111. twoDimVert0
  26112. ],
  26113. [
  26114. 1,
  26115. twoDimVert0
  26116. ],
  26117. [
  26118. 1,
  26119. twoDimVert0
  26120. ],
  26121. [
  26122. 1,
  26123. twoDimVert0
  26124. ],
  26125. [
  26126. 1,
  26127. twoDimVert0
  26128. ],
  26129. [
  26130. 1,
  26131. twoDimVert0
  26132. ],
  26133. [
  26134. 1,
  26135. twoDimVert0
  26136. ],
  26137. [
  26138. 1,
  26139. twoDimVert0
  26140. ],
  26141. [
  26142. 1,
  26143. twoDimVert0
  26144. ],
  26145. [
  26146. 1,
  26147. twoDimVert0
  26148. ],
  26149. [
  26150. 1,
  26151. twoDimVert0
  26152. ],
  26153. [
  26154. 1,
  26155. twoDimVert0
  26156. ],
  26157. [
  26158. 1,
  26159. twoDimVert0
  26160. ],
  26161. [
  26162. 1,
  26163. twoDimVert0
  26164. ],
  26165. [
  26166. 1,
  26167. twoDimVert0
  26168. ],
  26169. [
  26170. 1,
  26171. twoDimVert0
  26172. ],
  26173. [
  26174. 1,
  26175. twoDimVert0
  26176. ],
  26177. [
  26178. 1,
  26179. twoDimVert0
  26180. ],
  26181. [
  26182. 1,
  26183. twoDimVert0
  26184. ],
  26185. [
  26186. 1,
  26187. twoDimVert0
  26188. ],
  26189. [
  26190. 1,
  26191. twoDimVert0
  26192. ],
  26193. [
  26194. 1,
  26195. twoDimVert0
  26196. ],
  26197. [
  26198. 1,
  26199. twoDimVert0
  26200. ],
  26201. [
  26202. 1,
  26203. twoDimVert0
  26204. ],
  26205. [
  26206. 1,
  26207. twoDimVert0
  26208. ],
  26209. [
  26210. 1,
  26211. twoDimVert0
  26212. ],
  26213. [
  26214. 1,
  26215. twoDimVert0
  26216. ],
  26217. [
  26218. 1,
  26219. twoDimVert0
  26220. ],
  26221. [
  26222. 1,
  26223. twoDimVert0
  26224. ],
  26225. [
  26226. 1,
  26227. twoDimVert0
  26228. ],
  26229. [
  26230. 1,
  26231. twoDimVert0
  26232. ],
  26233. [
  26234. 1,
  26235. twoDimVert0
  26236. ],
  26237. [
  26238. 1,
  26239. twoDimVert0
  26240. ],
  26241. [
  26242. 1,
  26243. twoDimVert0
  26244. ],
  26245. [
  26246. 1,
  26247. twoDimVert0
  26248. ],
  26249. [
  26250. 1,
  26251. twoDimVert0
  26252. ],
  26253. [
  26254. 1,
  26255. twoDimVert0
  26256. ],
  26257. [
  26258. 1,
  26259. twoDimVert0
  26260. ],
  26261. [
  26262. 1,
  26263. twoDimVert0
  26264. ],
  26265. [
  26266. 1,
  26267. twoDimVert0
  26268. ],
  26269. [
  26270. 1,
  26271. twoDimVert0
  26272. ],
  26273. [
  26274. 1,
  26275. twoDimVert0
  26276. ],
  26277. [
  26278. 1,
  26279. twoDimVert0
  26280. ],
  26281. [
  26282. 1,
  26283. twoDimVert0
  26284. ],
  26285. [
  26286. 1,
  26287. twoDimVert0
  26288. ],
  26289. [
  26290. 1,
  26291. twoDimVert0
  26292. ],
  26293. [
  26294. 1,
  26295. twoDimVert0
  26296. ],
  26297. [
  26298. 1,
  26299. twoDimVert0
  26300. ],
  26301. [
  26302. 1,
  26303. twoDimVert0
  26304. ],
  26305. [
  26306. 1,
  26307. twoDimVert0
  26308. ],
  26309. [
  26310. 1,
  26311. twoDimVert0
  26312. ],
  26313. [
  26314. 1,
  26315. twoDimVert0
  26316. ],
  26317. [
  26318. 1,
  26319. twoDimVert0
  26320. ],
  26321. [
  26322. 1,
  26323. twoDimVert0
  26324. ],
  26325. [
  26326. 1,
  26327. twoDimVert0
  26328. ],
  26329. [
  26330. 1,
  26331. twoDimVert0
  26332. ],
  26333. [
  26334. 1,
  26335. twoDimVert0
  26336. ],
  26337. [
  26338. 1,
  26339. twoDimVert0
  26340. ],
  26341. [
  26342. 1,
  26343. twoDimVert0
  26344. ],
  26345. [
  26346. 1,
  26347. twoDimVert0
  26348. ],
  26349. [
  26350. 1,
  26351. twoDimVert0
  26352. ],
  26353. [
  26354. 1,
  26355. twoDimVert0
  26356. ]
  26357. ];
  26358. var whiteTable1 = [
  26359. [
  26360. -1,
  26361. -1
  26362. ],
  26363. // 00000
  26364. [
  26365. 12,
  26366. ccittEOL
  26367. ],
  26368. // 00001
  26369. [
  26370. -1,
  26371. -1
  26372. ],
  26373. [
  26374. -1,
  26375. -1
  26376. ],
  26377. // 0001x
  26378. [
  26379. -1,
  26380. -1
  26381. ],
  26382. [
  26383. -1,
  26384. -1
  26385. ],
  26386. [
  26387. -1,
  26388. -1
  26389. ],
  26390. [
  26391. -1,
  26392. -1
  26393. ],
  26394. // 001xx
  26395. [
  26396. -1,
  26397. -1
  26398. ],
  26399. [
  26400. -1,
  26401. -1
  26402. ],
  26403. [
  26404. -1,
  26405. -1
  26406. ],
  26407. [
  26408. -1,
  26409. -1
  26410. ],
  26411. // 010xx
  26412. [
  26413. -1,
  26414. -1
  26415. ],
  26416. [
  26417. -1,
  26418. -1
  26419. ],
  26420. [
  26421. -1,
  26422. -1
  26423. ],
  26424. [
  26425. -1,
  26426. -1
  26427. ],
  26428. // 011xx
  26429. [
  26430. 11,
  26431. 1792
  26432. ],
  26433. [
  26434. 11,
  26435. 1792
  26436. ],
  26437. // 1000x
  26438. [
  26439. 12,
  26440. 1984
  26441. ],
  26442. // 10010
  26443. [
  26444. 12,
  26445. 2048
  26446. ],
  26447. // 10011
  26448. [
  26449. 12,
  26450. 2112
  26451. ],
  26452. // 10100
  26453. [
  26454. 12,
  26455. 2176
  26456. ],
  26457. // 10101
  26458. [
  26459. 12,
  26460. 2240
  26461. ],
  26462. // 10110
  26463. [
  26464. 12,
  26465. 2304
  26466. ],
  26467. // 10111
  26468. [
  26469. 11,
  26470. 1856
  26471. ],
  26472. [
  26473. 11,
  26474. 1856
  26475. ],
  26476. // 1100x
  26477. [
  26478. 11,
  26479. 1920
  26480. ],
  26481. [
  26482. 11,
  26483. 1920
  26484. ],
  26485. // 1101x
  26486. [
  26487. 12,
  26488. 2368
  26489. ],
  26490. // 11100
  26491. [
  26492. 12,
  26493. 2432
  26494. ],
  26495. // 11101
  26496. [
  26497. 12,
  26498. 2496
  26499. ],
  26500. // 11110
  26501. [
  26502. 12,
  26503. 2560
  26504. ]
  26505. ];
  26506. // 11111
  26507. var whiteTable2 = [
  26508. [
  26509. -1,
  26510. -1
  26511. ],
  26512. [
  26513. -1,
  26514. -1
  26515. ],
  26516. [
  26517. -1,
  26518. -1
  26519. ],
  26520. [
  26521. -1,
  26522. -1
  26523. ],
  26524. // 0000000xx
  26525. [
  26526. 8,
  26527. 29
  26528. ],
  26529. [
  26530. 8,
  26531. 29
  26532. ],
  26533. // 00000010x
  26534. [
  26535. 8,
  26536. 30
  26537. ],
  26538. [
  26539. 8,
  26540. 30
  26541. ],
  26542. // 00000011x
  26543. [
  26544. 8,
  26545. 45
  26546. ],
  26547. [
  26548. 8,
  26549. 45
  26550. ],
  26551. // 00000100x
  26552. [
  26553. 8,
  26554. 46
  26555. ],
  26556. [
  26557. 8,
  26558. 46
  26559. ],
  26560. // 00000101x
  26561. [
  26562. 7,
  26563. 22
  26564. ],
  26565. [
  26566. 7,
  26567. 22
  26568. ],
  26569. [
  26570. 7,
  26571. 22
  26572. ],
  26573. [
  26574. 7,
  26575. 22
  26576. ],
  26577. // 0000011xx
  26578. [
  26579. 7,
  26580. 23
  26581. ],
  26582. [
  26583. 7,
  26584. 23
  26585. ],
  26586. [
  26587. 7,
  26588. 23
  26589. ],
  26590. [
  26591. 7,
  26592. 23
  26593. ],
  26594. // 0000100xx
  26595. [
  26596. 8,
  26597. 47
  26598. ],
  26599. [
  26600. 8,
  26601. 47
  26602. ],
  26603. // 00001010x
  26604. [
  26605. 8,
  26606. 48
  26607. ],
  26608. [
  26609. 8,
  26610. 48
  26611. ],
  26612. // 00001011x
  26613. [
  26614. 6,
  26615. 13
  26616. ],
  26617. [
  26618. 6,
  26619. 13
  26620. ],
  26621. [
  26622. 6,
  26623. 13
  26624. ],
  26625. [
  26626. 6,
  26627. 13
  26628. ],
  26629. // 000011xxx
  26630. [
  26631. 6,
  26632. 13
  26633. ],
  26634. [
  26635. 6,
  26636. 13
  26637. ],
  26638. [
  26639. 6,
  26640. 13
  26641. ],
  26642. [
  26643. 6,
  26644. 13
  26645. ],
  26646. [
  26647. 7,
  26648. 20
  26649. ],
  26650. [
  26651. 7,
  26652. 20
  26653. ],
  26654. [
  26655. 7,
  26656. 20
  26657. ],
  26658. [
  26659. 7,
  26660. 20
  26661. ],
  26662. // 0001000xx
  26663. [
  26664. 8,
  26665. 33
  26666. ],
  26667. [
  26668. 8,
  26669. 33
  26670. ],
  26671. // 00010010x
  26672. [
  26673. 8,
  26674. 34
  26675. ],
  26676. [
  26677. 8,
  26678. 34
  26679. ],
  26680. // 00010011x
  26681. [
  26682. 8,
  26683. 35
  26684. ],
  26685. [
  26686. 8,
  26687. 35
  26688. ],
  26689. // 00010100x
  26690. [
  26691. 8,
  26692. 36
  26693. ],
  26694. [
  26695. 8,
  26696. 36
  26697. ],
  26698. // 00010101x
  26699. [
  26700. 8,
  26701. 37
  26702. ],
  26703. [
  26704. 8,
  26705. 37
  26706. ],
  26707. // 00010110x
  26708. [
  26709. 8,
  26710. 38
  26711. ],
  26712. [
  26713. 8,
  26714. 38
  26715. ],
  26716. // 00010111x
  26717. [
  26718. 7,
  26719. 19
  26720. ],
  26721. [
  26722. 7,
  26723. 19
  26724. ],
  26725. [
  26726. 7,
  26727. 19
  26728. ],
  26729. [
  26730. 7,
  26731. 19
  26732. ],
  26733. // 0001100xx
  26734. [
  26735. 8,
  26736. 31
  26737. ],
  26738. [
  26739. 8,
  26740. 31
  26741. ],
  26742. // 00011010x
  26743. [
  26744. 8,
  26745. 32
  26746. ],
  26747. [
  26748. 8,
  26749. 32
  26750. ],
  26751. // 00011011x
  26752. [
  26753. 6,
  26754. 1
  26755. ],
  26756. [
  26757. 6,
  26758. 1
  26759. ],
  26760. [
  26761. 6,
  26762. 1
  26763. ],
  26764. [
  26765. 6,
  26766. 1
  26767. ],
  26768. // 000111xxx
  26769. [
  26770. 6,
  26771. 1
  26772. ],
  26773. [
  26774. 6,
  26775. 1
  26776. ],
  26777. [
  26778. 6,
  26779. 1
  26780. ],
  26781. [
  26782. 6,
  26783. 1
  26784. ],
  26785. [
  26786. 6,
  26787. 12
  26788. ],
  26789. [
  26790. 6,
  26791. 12
  26792. ],
  26793. [
  26794. 6,
  26795. 12
  26796. ],
  26797. [
  26798. 6,
  26799. 12
  26800. ],
  26801. // 001000xxx
  26802. [
  26803. 6,
  26804. 12
  26805. ],
  26806. [
  26807. 6,
  26808. 12
  26809. ],
  26810. [
  26811. 6,
  26812. 12
  26813. ],
  26814. [
  26815. 6,
  26816. 12
  26817. ],
  26818. [
  26819. 8,
  26820. 53
  26821. ],
  26822. [
  26823. 8,
  26824. 53
  26825. ],
  26826. // 00100100x
  26827. [
  26828. 8,
  26829. 54
  26830. ],
  26831. [
  26832. 8,
  26833. 54
  26834. ],
  26835. // 00100101x
  26836. [
  26837. 7,
  26838. 26
  26839. ],
  26840. [
  26841. 7,
  26842. 26
  26843. ],
  26844. [
  26845. 7,
  26846. 26
  26847. ],
  26848. [
  26849. 7,
  26850. 26
  26851. ],
  26852. // 0010011xx
  26853. [
  26854. 8,
  26855. 39
  26856. ],
  26857. [
  26858. 8,
  26859. 39
  26860. ],
  26861. // 00101000x
  26862. [
  26863. 8,
  26864. 40
  26865. ],
  26866. [
  26867. 8,
  26868. 40
  26869. ],
  26870. // 00101001x
  26871. [
  26872. 8,
  26873. 41
  26874. ],
  26875. [
  26876. 8,
  26877. 41
  26878. ],
  26879. // 00101010x
  26880. [
  26881. 8,
  26882. 42
  26883. ],
  26884. [
  26885. 8,
  26886. 42
  26887. ],
  26888. // 00101011x
  26889. [
  26890. 8,
  26891. 43
  26892. ],
  26893. [
  26894. 8,
  26895. 43
  26896. ],
  26897. // 00101100x
  26898. [
  26899. 8,
  26900. 44
  26901. ],
  26902. [
  26903. 8,
  26904. 44
  26905. ],
  26906. // 00101101x
  26907. [
  26908. 7,
  26909. 21
  26910. ],
  26911. [
  26912. 7,
  26913. 21
  26914. ],
  26915. [
  26916. 7,
  26917. 21
  26918. ],
  26919. [
  26920. 7,
  26921. 21
  26922. ],
  26923. // 0010111xx
  26924. [
  26925. 7,
  26926. 28
  26927. ],
  26928. [
  26929. 7,
  26930. 28
  26931. ],
  26932. [
  26933. 7,
  26934. 28
  26935. ],
  26936. [
  26937. 7,
  26938. 28
  26939. ],
  26940. // 0011000xx
  26941. [
  26942. 8,
  26943. 61
  26944. ],
  26945. [
  26946. 8,
  26947. 61
  26948. ],
  26949. // 00110010x
  26950. [
  26951. 8,
  26952. 62
  26953. ],
  26954. [
  26955. 8,
  26956. 62
  26957. ],
  26958. // 00110011x
  26959. [
  26960. 8,
  26961. 63
  26962. ],
  26963. [
  26964. 8,
  26965. 63
  26966. ],
  26967. // 00110100x
  26968. [
  26969. 8,
  26970. 0
  26971. ],
  26972. [
  26973. 8,
  26974. 0
  26975. ],
  26976. // 00110101x
  26977. [
  26978. 8,
  26979. 320
  26980. ],
  26981. [
  26982. 8,
  26983. 320
  26984. ],
  26985. // 00110110x
  26986. [
  26987. 8,
  26988. 384
  26989. ],
  26990. [
  26991. 8,
  26992. 384
  26993. ],
  26994. // 00110111x
  26995. [
  26996. 5,
  26997. 10
  26998. ],
  26999. [
  27000. 5,
  27001. 10
  27002. ],
  27003. [
  27004. 5,
  27005. 10
  27006. ],
  27007. [
  27008. 5,
  27009. 10
  27010. ],
  27011. // 00111xxxx
  27012. [
  27013. 5,
  27014. 10
  27015. ],
  27016. [
  27017. 5,
  27018. 10
  27019. ],
  27020. [
  27021. 5,
  27022. 10
  27023. ],
  27024. [
  27025. 5,
  27026. 10
  27027. ],
  27028. [
  27029. 5,
  27030. 10
  27031. ],
  27032. [
  27033. 5,
  27034. 10
  27035. ],
  27036. [
  27037. 5,
  27038. 10
  27039. ],
  27040. [
  27041. 5,
  27042. 10
  27043. ],
  27044. [
  27045. 5,
  27046. 10
  27047. ],
  27048. [
  27049. 5,
  27050. 10
  27051. ],
  27052. [
  27053. 5,
  27054. 10
  27055. ],
  27056. [
  27057. 5,
  27058. 10
  27059. ],
  27060. [
  27061. 5,
  27062. 11
  27063. ],
  27064. [
  27065. 5,
  27066. 11
  27067. ],
  27068. [
  27069. 5,
  27070. 11
  27071. ],
  27072. [
  27073. 5,
  27074. 11
  27075. ],
  27076. // 01000xxxx
  27077. [
  27078. 5,
  27079. 11
  27080. ],
  27081. [
  27082. 5,
  27083. 11
  27084. ],
  27085. [
  27086. 5,
  27087. 11
  27088. ],
  27089. [
  27090. 5,
  27091. 11
  27092. ],
  27093. [
  27094. 5,
  27095. 11
  27096. ],
  27097. [
  27098. 5,
  27099. 11
  27100. ],
  27101. [
  27102. 5,
  27103. 11
  27104. ],
  27105. [
  27106. 5,
  27107. 11
  27108. ],
  27109. [
  27110. 5,
  27111. 11
  27112. ],
  27113. [
  27114. 5,
  27115. 11
  27116. ],
  27117. [
  27118. 5,
  27119. 11
  27120. ],
  27121. [
  27122. 5,
  27123. 11
  27124. ],
  27125. [
  27126. 7,
  27127. 27
  27128. ],
  27129. [
  27130. 7,
  27131. 27
  27132. ],
  27133. [
  27134. 7,
  27135. 27
  27136. ],
  27137. [
  27138. 7,
  27139. 27
  27140. ],
  27141. // 0100100xx
  27142. [
  27143. 8,
  27144. 59
  27145. ],
  27146. [
  27147. 8,
  27148. 59
  27149. ],
  27150. // 01001010x
  27151. [
  27152. 8,
  27153. 60
  27154. ],
  27155. [
  27156. 8,
  27157. 60
  27158. ],
  27159. // 01001011x
  27160. [
  27161. 9,
  27162. 1472
  27163. ],
  27164. // 010011000
  27165. [
  27166. 9,
  27167. 1536
  27168. ],
  27169. // 010011001
  27170. [
  27171. 9,
  27172. 1600
  27173. ],
  27174. // 010011010
  27175. [
  27176. 9,
  27177. 1728
  27178. ],
  27179. // 010011011
  27180. [
  27181. 7,
  27182. 18
  27183. ],
  27184. [
  27185. 7,
  27186. 18
  27187. ],
  27188. [
  27189. 7,
  27190. 18
  27191. ],
  27192. [
  27193. 7,
  27194. 18
  27195. ],
  27196. // 0100111xx
  27197. [
  27198. 7,
  27199. 24
  27200. ],
  27201. [
  27202. 7,
  27203. 24
  27204. ],
  27205. [
  27206. 7,
  27207. 24
  27208. ],
  27209. [
  27210. 7,
  27211. 24
  27212. ],
  27213. // 0101000xx
  27214. [
  27215. 8,
  27216. 49
  27217. ],
  27218. [
  27219. 8,
  27220. 49
  27221. ],
  27222. // 01010010x
  27223. [
  27224. 8,
  27225. 50
  27226. ],
  27227. [
  27228. 8,
  27229. 50
  27230. ],
  27231. // 01010011x
  27232. [
  27233. 8,
  27234. 51
  27235. ],
  27236. [
  27237. 8,
  27238. 51
  27239. ],
  27240. // 01010100x
  27241. [
  27242. 8,
  27243. 52
  27244. ],
  27245. [
  27246. 8,
  27247. 52
  27248. ],
  27249. // 01010101x
  27250. [
  27251. 7,
  27252. 25
  27253. ],
  27254. [
  27255. 7,
  27256. 25
  27257. ],
  27258. [
  27259. 7,
  27260. 25
  27261. ],
  27262. [
  27263. 7,
  27264. 25
  27265. ],
  27266. // 0101011xx
  27267. [
  27268. 8,
  27269. 55
  27270. ],
  27271. [
  27272. 8,
  27273. 55
  27274. ],
  27275. // 01011000x
  27276. [
  27277. 8,
  27278. 56
  27279. ],
  27280. [
  27281. 8,
  27282. 56
  27283. ],
  27284. // 01011001x
  27285. [
  27286. 8,
  27287. 57
  27288. ],
  27289. [
  27290. 8,
  27291. 57
  27292. ],
  27293. // 01011010x
  27294. [
  27295. 8,
  27296. 58
  27297. ],
  27298. [
  27299. 8,
  27300. 58
  27301. ],
  27302. // 01011011x
  27303. [
  27304. 6,
  27305. 192
  27306. ],
  27307. [
  27308. 6,
  27309. 192
  27310. ],
  27311. [
  27312. 6,
  27313. 192
  27314. ],
  27315. [
  27316. 6,
  27317. 192
  27318. ],
  27319. // 010111xxx
  27320. [
  27321. 6,
  27322. 192
  27323. ],
  27324. [
  27325. 6,
  27326. 192
  27327. ],
  27328. [
  27329. 6,
  27330. 192
  27331. ],
  27332. [
  27333. 6,
  27334. 192
  27335. ],
  27336. [
  27337. 6,
  27338. 1664
  27339. ],
  27340. [
  27341. 6,
  27342. 1664
  27343. ],
  27344. [
  27345. 6,
  27346. 1664
  27347. ],
  27348. [
  27349. 6,
  27350. 1664
  27351. ],
  27352. // 011000xxx
  27353. [
  27354. 6,
  27355. 1664
  27356. ],
  27357. [
  27358. 6,
  27359. 1664
  27360. ],
  27361. [
  27362. 6,
  27363. 1664
  27364. ],
  27365. [
  27366. 6,
  27367. 1664
  27368. ],
  27369. [
  27370. 8,
  27371. 448
  27372. ],
  27373. [
  27374. 8,
  27375. 448
  27376. ],
  27377. // 01100100x
  27378. [
  27379. 8,
  27380. 512
  27381. ],
  27382. [
  27383. 8,
  27384. 512
  27385. ],
  27386. // 01100101x
  27387. [
  27388. 9,
  27389. 704
  27390. ],
  27391. // 011001100
  27392. [
  27393. 9,
  27394. 768
  27395. ],
  27396. // 011001101
  27397. [
  27398. 8,
  27399. 640
  27400. ],
  27401. [
  27402. 8,
  27403. 640
  27404. ],
  27405. // 01100111x
  27406. [
  27407. 8,
  27408. 576
  27409. ],
  27410. [
  27411. 8,
  27412. 576
  27413. ],
  27414. // 01101000x
  27415. [
  27416. 9,
  27417. 832
  27418. ],
  27419. // 011010010
  27420. [
  27421. 9,
  27422. 896
  27423. ],
  27424. // 011010011
  27425. [
  27426. 9,
  27427. 960
  27428. ],
  27429. // 011010100
  27430. [
  27431. 9,
  27432. 1024
  27433. ],
  27434. // 011010101
  27435. [
  27436. 9,
  27437. 1088
  27438. ],
  27439. // 011010110
  27440. [
  27441. 9,
  27442. 1152
  27443. ],
  27444. // 011010111
  27445. [
  27446. 9,
  27447. 1216
  27448. ],
  27449. // 011011000
  27450. [
  27451. 9,
  27452. 1280
  27453. ],
  27454. // 011011001
  27455. [
  27456. 9,
  27457. 1344
  27458. ],
  27459. // 011011010
  27460. [
  27461. 9,
  27462. 1408
  27463. ],
  27464. // 011011011
  27465. [
  27466. 7,
  27467. 256
  27468. ],
  27469. [
  27470. 7,
  27471. 256
  27472. ],
  27473. [
  27474. 7,
  27475. 256
  27476. ],
  27477. [
  27478. 7,
  27479. 256
  27480. ],
  27481. // 0110111xx
  27482. [
  27483. 4,
  27484. 2
  27485. ],
  27486. [
  27487. 4,
  27488. 2
  27489. ],
  27490. [
  27491. 4,
  27492. 2
  27493. ],
  27494. [
  27495. 4,
  27496. 2
  27497. ],
  27498. // 0111xxxxx
  27499. [
  27500. 4,
  27501. 2
  27502. ],
  27503. [
  27504. 4,
  27505. 2
  27506. ],
  27507. [
  27508. 4,
  27509. 2
  27510. ],
  27511. [
  27512. 4,
  27513. 2
  27514. ],
  27515. [
  27516. 4,
  27517. 2
  27518. ],
  27519. [
  27520. 4,
  27521. 2
  27522. ],
  27523. [
  27524. 4,
  27525. 2
  27526. ],
  27527. [
  27528. 4,
  27529. 2
  27530. ],
  27531. [
  27532. 4,
  27533. 2
  27534. ],
  27535. [
  27536. 4,
  27537. 2
  27538. ],
  27539. [
  27540. 4,
  27541. 2
  27542. ],
  27543. [
  27544. 4,
  27545. 2
  27546. ],
  27547. [
  27548. 4,
  27549. 2
  27550. ],
  27551. [
  27552. 4,
  27553. 2
  27554. ],
  27555. [
  27556. 4,
  27557. 2
  27558. ],
  27559. [
  27560. 4,
  27561. 2
  27562. ],
  27563. [
  27564. 4,
  27565. 2
  27566. ],
  27567. [
  27568. 4,
  27569. 2
  27570. ],
  27571. [
  27572. 4,
  27573. 2
  27574. ],
  27575. [
  27576. 4,
  27577. 2
  27578. ],
  27579. [
  27580. 4,
  27581. 2
  27582. ],
  27583. [
  27584. 4,
  27585. 2
  27586. ],
  27587. [
  27588. 4,
  27589. 2
  27590. ],
  27591. [
  27592. 4,
  27593. 2
  27594. ],
  27595. [
  27596. 4,
  27597. 2
  27598. ],
  27599. [
  27600. 4,
  27601. 2
  27602. ],
  27603. [
  27604. 4,
  27605. 2
  27606. ],
  27607. [
  27608. 4,
  27609. 2
  27610. ],
  27611. [
  27612. 4,
  27613. 3
  27614. ],
  27615. [
  27616. 4,
  27617. 3
  27618. ],
  27619. [
  27620. 4,
  27621. 3
  27622. ],
  27623. [
  27624. 4,
  27625. 3
  27626. ],
  27627. // 1000xxxxx
  27628. [
  27629. 4,
  27630. 3
  27631. ],
  27632. [
  27633. 4,
  27634. 3
  27635. ],
  27636. [
  27637. 4,
  27638. 3
  27639. ],
  27640. [
  27641. 4,
  27642. 3
  27643. ],
  27644. [
  27645. 4,
  27646. 3
  27647. ],
  27648. [
  27649. 4,
  27650. 3
  27651. ],
  27652. [
  27653. 4,
  27654. 3
  27655. ],
  27656. [
  27657. 4,
  27658. 3
  27659. ],
  27660. [
  27661. 4,
  27662. 3
  27663. ],
  27664. [
  27665. 4,
  27666. 3
  27667. ],
  27668. [
  27669. 4,
  27670. 3
  27671. ],
  27672. [
  27673. 4,
  27674. 3
  27675. ],
  27676. [
  27677. 4,
  27678. 3
  27679. ],
  27680. [
  27681. 4,
  27682. 3
  27683. ],
  27684. [
  27685. 4,
  27686. 3
  27687. ],
  27688. [
  27689. 4,
  27690. 3
  27691. ],
  27692. [
  27693. 4,
  27694. 3
  27695. ],
  27696. [
  27697. 4,
  27698. 3
  27699. ],
  27700. [
  27701. 4,
  27702. 3
  27703. ],
  27704. [
  27705. 4,
  27706. 3
  27707. ],
  27708. [
  27709. 4,
  27710. 3
  27711. ],
  27712. [
  27713. 4,
  27714. 3
  27715. ],
  27716. [
  27717. 4,
  27718. 3
  27719. ],
  27720. [
  27721. 4,
  27722. 3
  27723. ],
  27724. [
  27725. 4,
  27726. 3
  27727. ],
  27728. [
  27729. 4,
  27730. 3
  27731. ],
  27732. [
  27733. 4,
  27734. 3
  27735. ],
  27736. [
  27737. 4,
  27738. 3
  27739. ],
  27740. [
  27741. 5,
  27742. 128
  27743. ],
  27744. [
  27745. 5,
  27746. 128
  27747. ],
  27748. [
  27749. 5,
  27750. 128
  27751. ],
  27752. [
  27753. 5,
  27754. 128
  27755. ],
  27756. // 10010xxxx
  27757. [
  27758. 5,
  27759. 128
  27760. ],
  27761. [
  27762. 5,
  27763. 128
  27764. ],
  27765. [
  27766. 5,
  27767. 128
  27768. ],
  27769. [
  27770. 5,
  27771. 128
  27772. ],
  27773. [
  27774. 5,
  27775. 128
  27776. ],
  27777. [
  27778. 5,
  27779. 128
  27780. ],
  27781. [
  27782. 5,
  27783. 128
  27784. ],
  27785. [
  27786. 5,
  27787. 128
  27788. ],
  27789. [
  27790. 5,
  27791. 128
  27792. ],
  27793. [
  27794. 5,
  27795. 128
  27796. ],
  27797. [
  27798. 5,
  27799. 128
  27800. ],
  27801. [
  27802. 5,
  27803. 128
  27804. ],
  27805. [
  27806. 5,
  27807. 8
  27808. ],
  27809. [
  27810. 5,
  27811. 8
  27812. ],
  27813. [
  27814. 5,
  27815. 8
  27816. ],
  27817. [
  27818. 5,
  27819. 8
  27820. ],
  27821. // 10011xxxx
  27822. [
  27823. 5,
  27824. 8
  27825. ],
  27826. [
  27827. 5,
  27828. 8
  27829. ],
  27830. [
  27831. 5,
  27832. 8
  27833. ],
  27834. [
  27835. 5,
  27836. 8
  27837. ],
  27838. [
  27839. 5,
  27840. 8
  27841. ],
  27842. [
  27843. 5,
  27844. 8
  27845. ],
  27846. [
  27847. 5,
  27848. 8
  27849. ],
  27850. [
  27851. 5,
  27852. 8
  27853. ],
  27854. [
  27855. 5,
  27856. 8
  27857. ],
  27858. [
  27859. 5,
  27860. 8
  27861. ],
  27862. [
  27863. 5,
  27864. 8
  27865. ],
  27866. [
  27867. 5,
  27868. 8
  27869. ],
  27870. [
  27871. 5,
  27872. 9
  27873. ],
  27874. [
  27875. 5,
  27876. 9
  27877. ],
  27878. [
  27879. 5,
  27880. 9
  27881. ],
  27882. [
  27883. 5,
  27884. 9
  27885. ],
  27886. // 10100xxxx
  27887. [
  27888. 5,
  27889. 9
  27890. ],
  27891. [
  27892. 5,
  27893. 9
  27894. ],
  27895. [
  27896. 5,
  27897. 9
  27898. ],
  27899. [
  27900. 5,
  27901. 9
  27902. ],
  27903. [
  27904. 5,
  27905. 9
  27906. ],
  27907. [
  27908. 5,
  27909. 9
  27910. ],
  27911. [
  27912. 5,
  27913. 9
  27914. ],
  27915. [
  27916. 5,
  27917. 9
  27918. ],
  27919. [
  27920. 5,
  27921. 9
  27922. ],
  27923. [
  27924. 5,
  27925. 9
  27926. ],
  27927. [
  27928. 5,
  27929. 9
  27930. ],
  27931. [
  27932. 5,
  27933. 9
  27934. ],
  27935. [
  27936. 6,
  27937. 16
  27938. ],
  27939. [
  27940. 6,
  27941. 16
  27942. ],
  27943. [
  27944. 6,
  27945. 16
  27946. ],
  27947. [
  27948. 6,
  27949. 16
  27950. ],
  27951. // 101010xxx
  27952. [
  27953. 6,
  27954. 16
  27955. ],
  27956. [
  27957. 6,
  27958. 16
  27959. ],
  27960. [
  27961. 6,
  27962. 16
  27963. ],
  27964. [
  27965. 6,
  27966. 16
  27967. ],
  27968. [
  27969. 6,
  27970. 17
  27971. ],
  27972. [
  27973. 6,
  27974. 17
  27975. ],
  27976. [
  27977. 6,
  27978. 17
  27979. ],
  27980. [
  27981. 6,
  27982. 17
  27983. ],
  27984. // 101011xxx
  27985. [
  27986. 6,
  27987. 17
  27988. ],
  27989. [
  27990. 6,
  27991. 17
  27992. ],
  27993. [
  27994. 6,
  27995. 17
  27996. ],
  27997. [
  27998. 6,
  27999. 17
  28000. ],
  28001. [
  28002. 4,
  28003. 4
  28004. ],
  28005. [
  28006. 4,
  28007. 4
  28008. ],
  28009. [
  28010. 4,
  28011. 4
  28012. ],
  28013. [
  28014. 4,
  28015. 4
  28016. ],
  28017. // 1011xxxxx
  28018. [
  28019. 4,
  28020. 4
  28021. ],
  28022. [
  28023. 4,
  28024. 4
  28025. ],
  28026. [
  28027. 4,
  28028. 4
  28029. ],
  28030. [
  28031. 4,
  28032. 4
  28033. ],
  28034. [
  28035. 4,
  28036. 4
  28037. ],
  28038. [
  28039. 4,
  28040. 4
  28041. ],
  28042. [
  28043. 4,
  28044. 4
  28045. ],
  28046. [
  28047. 4,
  28048. 4
  28049. ],
  28050. [
  28051. 4,
  28052. 4
  28053. ],
  28054. [
  28055. 4,
  28056. 4
  28057. ],
  28058. [
  28059. 4,
  28060. 4
  28061. ],
  28062. [
  28063. 4,
  28064. 4
  28065. ],
  28066. [
  28067. 4,
  28068. 4
  28069. ],
  28070. [
  28071. 4,
  28072. 4
  28073. ],
  28074. [
  28075. 4,
  28076. 4
  28077. ],
  28078. [
  28079. 4,
  28080. 4
  28081. ],
  28082. [
  28083. 4,
  28084. 4
  28085. ],
  28086. [
  28087. 4,
  28088. 4
  28089. ],
  28090. [
  28091. 4,
  28092. 4
  28093. ],
  28094. [
  28095. 4,
  28096. 4
  28097. ],
  28098. [
  28099. 4,
  28100. 4
  28101. ],
  28102. [
  28103. 4,
  28104. 4
  28105. ],
  28106. [
  28107. 4,
  28108. 4
  28109. ],
  28110. [
  28111. 4,
  28112. 4
  28113. ],
  28114. [
  28115. 4,
  28116. 4
  28117. ],
  28118. [
  28119. 4,
  28120. 4
  28121. ],
  28122. [
  28123. 4,
  28124. 4
  28125. ],
  28126. [
  28127. 4,
  28128. 4
  28129. ],
  28130. [
  28131. 4,
  28132. 5
  28133. ],
  28134. [
  28135. 4,
  28136. 5
  28137. ],
  28138. [
  28139. 4,
  28140. 5
  28141. ],
  28142. [
  28143. 4,
  28144. 5
  28145. ],
  28146. // 1100xxxxx
  28147. [
  28148. 4,
  28149. 5
  28150. ],
  28151. [
  28152. 4,
  28153. 5
  28154. ],
  28155. [
  28156. 4,
  28157. 5
  28158. ],
  28159. [
  28160. 4,
  28161. 5
  28162. ],
  28163. [
  28164. 4,
  28165. 5
  28166. ],
  28167. [
  28168. 4,
  28169. 5
  28170. ],
  28171. [
  28172. 4,
  28173. 5
  28174. ],
  28175. [
  28176. 4,
  28177. 5
  28178. ],
  28179. [
  28180. 4,
  28181. 5
  28182. ],
  28183. [
  28184. 4,
  28185. 5
  28186. ],
  28187. [
  28188. 4,
  28189. 5
  28190. ],
  28191. [
  28192. 4,
  28193. 5
  28194. ],
  28195. [
  28196. 4,
  28197. 5
  28198. ],
  28199. [
  28200. 4,
  28201. 5
  28202. ],
  28203. [
  28204. 4,
  28205. 5
  28206. ],
  28207. [
  28208. 4,
  28209. 5
  28210. ],
  28211. [
  28212. 4,
  28213. 5
  28214. ],
  28215. [
  28216. 4,
  28217. 5
  28218. ],
  28219. [
  28220. 4,
  28221. 5
  28222. ],
  28223. [
  28224. 4,
  28225. 5
  28226. ],
  28227. [
  28228. 4,
  28229. 5
  28230. ],
  28231. [
  28232. 4,
  28233. 5
  28234. ],
  28235. [
  28236. 4,
  28237. 5
  28238. ],
  28239. [
  28240. 4,
  28241. 5
  28242. ],
  28243. [
  28244. 4,
  28245. 5
  28246. ],
  28247. [
  28248. 4,
  28249. 5
  28250. ],
  28251. [
  28252. 4,
  28253. 5
  28254. ],
  28255. [
  28256. 4,
  28257. 5
  28258. ],
  28259. [
  28260. 6,
  28261. 14
  28262. ],
  28263. [
  28264. 6,
  28265. 14
  28266. ],
  28267. [
  28268. 6,
  28269. 14
  28270. ],
  28271. [
  28272. 6,
  28273. 14
  28274. ],
  28275. // 110100xxx
  28276. [
  28277. 6,
  28278. 14
  28279. ],
  28280. [
  28281. 6,
  28282. 14
  28283. ],
  28284. [
  28285. 6,
  28286. 14
  28287. ],
  28288. [
  28289. 6,
  28290. 14
  28291. ],
  28292. [
  28293. 6,
  28294. 15
  28295. ],
  28296. [
  28297. 6,
  28298. 15
  28299. ],
  28300. [
  28301. 6,
  28302. 15
  28303. ],
  28304. [
  28305. 6,
  28306. 15
  28307. ],
  28308. // 110101xxx
  28309. [
  28310. 6,
  28311. 15
  28312. ],
  28313. [
  28314. 6,
  28315. 15
  28316. ],
  28317. [
  28318. 6,
  28319. 15
  28320. ],
  28321. [
  28322. 6,
  28323. 15
  28324. ],
  28325. [
  28326. 5,
  28327. 64
  28328. ],
  28329. [
  28330. 5,
  28331. 64
  28332. ],
  28333. [
  28334. 5,
  28335. 64
  28336. ],
  28337. [
  28338. 5,
  28339. 64
  28340. ],
  28341. // 11011xxxx
  28342. [
  28343. 5,
  28344. 64
  28345. ],
  28346. [
  28347. 5,
  28348. 64
  28349. ],
  28350. [
  28351. 5,
  28352. 64
  28353. ],
  28354. [
  28355. 5,
  28356. 64
  28357. ],
  28358. [
  28359. 5,
  28360. 64
  28361. ],
  28362. [
  28363. 5,
  28364. 64
  28365. ],
  28366. [
  28367. 5,
  28368. 64
  28369. ],
  28370. [
  28371. 5,
  28372. 64
  28373. ],
  28374. [
  28375. 5,
  28376. 64
  28377. ],
  28378. [
  28379. 5,
  28380. 64
  28381. ],
  28382. [
  28383. 5,
  28384. 64
  28385. ],
  28386. [
  28387. 5,
  28388. 64
  28389. ],
  28390. [
  28391. 4,
  28392. 6
  28393. ],
  28394. [
  28395. 4,
  28396. 6
  28397. ],
  28398. [
  28399. 4,
  28400. 6
  28401. ],
  28402. [
  28403. 4,
  28404. 6
  28405. ],
  28406. // 1110xxxxx
  28407. [
  28408. 4,
  28409. 6
  28410. ],
  28411. [
  28412. 4,
  28413. 6
  28414. ],
  28415. [
  28416. 4,
  28417. 6
  28418. ],
  28419. [
  28420. 4,
  28421. 6
  28422. ],
  28423. [
  28424. 4,
  28425. 6
  28426. ],
  28427. [
  28428. 4,
  28429. 6
  28430. ],
  28431. [
  28432. 4,
  28433. 6
  28434. ],
  28435. [
  28436. 4,
  28437. 6
  28438. ],
  28439. [
  28440. 4,
  28441. 6
  28442. ],
  28443. [
  28444. 4,
  28445. 6
  28446. ],
  28447. [
  28448. 4,
  28449. 6
  28450. ],
  28451. [
  28452. 4,
  28453. 6
  28454. ],
  28455. [
  28456. 4,
  28457. 6
  28458. ],
  28459. [
  28460. 4,
  28461. 6
  28462. ],
  28463. [
  28464. 4,
  28465. 6
  28466. ],
  28467. [
  28468. 4,
  28469. 6
  28470. ],
  28471. [
  28472. 4,
  28473. 6
  28474. ],
  28475. [
  28476. 4,
  28477. 6
  28478. ],
  28479. [
  28480. 4,
  28481. 6
  28482. ],
  28483. [
  28484. 4,
  28485. 6
  28486. ],
  28487. [
  28488. 4,
  28489. 6
  28490. ],
  28491. [
  28492. 4,
  28493. 6
  28494. ],
  28495. [
  28496. 4,
  28497. 6
  28498. ],
  28499. [
  28500. 4,
  28501. 6
  28502. ],
  28503. [
  28504. 4,
  28505. 6
  28506. ],
  28507. [
  28508. 4,
  28509. 6
  28510. ],
  28511. [
  28512. 4,
  28513. 6
  28514. ],
  28515. [
  28516. 4,
  28517. 6
  28518. ],
  28519. [
  28520. 4,
  28521. 7
  28522. ],
  28523. [
  28524. 4,
  28525. 7
  28526. ],
  28527. [
  28528. 4,
  28529. 7
  28530. ],
  28531. [
  28532. 4,
  28533. 7
  28534. ],
  28535. // 1111xxxxx
  28536. [
  28537. 4,
  28538. 7
  28539. ],
  28540. [
  28541. 4,
  28542. 7
  28543. ],
  28544. [
  28545. 4,
  28546. 7
  28547. ],
  28548. [
  28549. 4,
  28550. 7
  28551. ],
  28552. [
  28553. 4,
  28554. 7
  28555. ],
  28556. [
  28557. 4,
  28558. 7
  28559. ],
  28560. [
  28561. 4,
  28562. 7
  28563. ],
  28564. [
  28565. 4,
  28566. 7
  28567. ],
  28568. [
  28569. 4,
  28570. 7
  28571. ],
  28572. [
  28573. 4,
  28574. 7
  28575. ],
  28576. [
  28577. 4,
  28578. 7
  28579. ],
  28580. [
  28581. 4,
  28582. 7
  28583. ],
  28584. [
  28585. 4,
  28586. 7
  28587. ],
  28588. [
  28589. 4,
  28590. 7
  28591. ],
  28592. [
  28593. 4,
  28594. 7
  28595. ],
  28596. [
  28597. 4,
  28598. 7
  28599. ],
  28600. [
  28601. 4,
  28602. 7
  28603. ],
  28604. [
  28605. 4,
  28606. 7
  28607. ],
  28608. [
  28609. 4,
  28610. 7
  28611. ],
  28612. [
  28613. 4,
  28614. 7
  28615. ],
  28616. [
  28617. 4,
  28618. 7
  28619. ],
  28620. [
  28621. 4,
  28622. 7
  28623. ],
  28624. [
  28625. 4,
  28626. 7
  28627. ],
  28628. [
  28629. 4,
  28630. 7
  28631. ],
  28632. [
  28633. 4,
  28634. 7
  28635. ],
  28636. [
  28637. 4,
  28638. 7
  28639. ],
  28640. [
  28641. 4,
  28642. 7
  28643. ],
  28644. [
  28645. 4,
  28646. 7
  28647. ]
  28648. ];
  28649. var blackTable1 = [
  28650. [
  28651. -1,
  28652. -1
  28653. ],
  28654. [
  28655. -1,
  28656. -1
  28657. ],
  28658. // 000000000000x
  28659. [
  28660. 12,
  28661. ccittEOL
  28662. ],
  28663. [
  28664. 12,
  28665. ccittEOL
  28666. ],
  28667. // 000000000001x
  28668. [
  28669. -1,
  28670. -1
  28671. ],
  28672. [
  28673. -1,
  28674. -1
  28675. ],
  28676. [
  28677. -1,
  28678. -1
  28679. ],
  28680. [
  28681. -1,
  28682. -1
  28683. ],
  28684. // 00000000001xx
  28685. [
  28686. -1,
  28687. -1
  28688. ],
  28689. [
  28690. -1,
  28691. -1
  28692. ],
  28693. [
  28694. -1,
  28695. -1
  28696. ],
  28697. [
  28698. -1,
  28699. -1
  28700. ],
  28701. // 00000000010xx
  28702. [
  28703. -1,
  28704. -1
  28705. ],
  28706. [
  28707. -1,
  28708. -1
  28709. ],
  28710. [
  28711. -1,
  28712. -1
  28713. ],
  28714. [
  28715. -1,
  28716. -1
  28717. ],
  28718. // 00000000011xx
  28719. [
  28720. -1,
  28721. -1
  28722. ],
  28723. [
  28724. -1,
  28725. -1
  28726. ],
  28727. [
  28728. -1,
  28729. -1
  28730. ],
  28731. [
  28732. -1,
  28733. -1
  28734. ],
  28735. // 00000000100xx
  28736. [
  28737. -1,
  28738. -1
  28739. ],
  28740. [
  28741. -1,
  28742. -1
  28743. ],
  28744. [
  28745. -1,
  28746. -1
  28747. ],
  28748. [
  28749. -1,
  28750. -1
  28751. ],
  28752. // 00000000101xx
  28753. [
  28754. -1,
  28755. -1
  28756. ],
  28757. [
  28758. -1,
  28759. -1
  28760. ],
  28761. [
  28762. -1,
  28763. -1
  28764. ],
  28765. [
  28766. -1,
  28767. -1
  28768. ],
  28769. // 00000000110xx
  28770. [
  28771. -1,
  28772. -1
  28773. ],
  28774. [
  28775. -1,
  28776. -1
  28777. ],
  28778. [
  28779. -1,
  28780. -1
  28781. ],
  28782. [
  28783. -1,
  28784. -1
  28785. ],
  28786. // 00000000111xx
  28787. [
  28788. 11,
  28789. 1792
  28790. ],
  28791. [
  28792. 11,
  28793. 1792
  28794. ],
  28795. [
  28796. 11,
  28797. 1792
  28798. ],
  28799. [
  28800. 11,
  28801. 1792
  28802. ],
  28803. // 00000001000xx
  28804. [
  28805. 12,
  28806. 1984
  28807. ],
  28808. [
  28809. 12,
  28810. 1984
  28811. ],
  28812. // 000000010010x
  28813. [
  28814. 12,
  28815. 2048
  28816. ],
  28817. [
  28818. 12,
  28819. 2048
  28820. ],
  28821. // 000000010011x
  28822. [
  28823. 12,
  28824. 2112
  28825. ],
  28826. [
  28827. 12,
  28828. 2112
  28829. ],
  28830. // 000000010100x
  28831. [
  28832. 12,
  28833. 2176
  28834. ],
  28835. [
  28836. 12,
  28837. 2176
  28838. ],
  28839. // 000000010101x
  28840. [
  28841. 12,
  28842. 2240
  28843. ],
  28844. [
  28845. 12,
  28846. 2240
  28847. ],
  28848. // 000000010110x
  28849. [
  28850. 12,
  28851. 2304
  28852. ],
  28853. [
  28854. 12,
  28855. 2304
  28856. ],
  28857. // 000000010111x
  28858. [
  28859. 11,
  28860. 1856
  28861. ],
  28862. [
  28863. 11,
  28864. 1856
  28865. ],
  28866. [
  28867. 11,
  28868. 1856
  28869. ],
  28870. [
  28871. 11,
  28872. 1856
  28873. ],
  28874. // 00000001100xx
  28875. [
  28876. 11,
  28877. 1920
  28878. ],
  28879. [
  28880. 11,
  28881. 1920
  28882. ],
  28883. [
  28884. 11,
  28885. 1920
  28886. ],
  28887. [
  28888. 11,
  28889. 1920
  28890. ],
  28891. // 00000001101xx
  28892. [
  28893. 12,
  28894. 2368
  28895. ],
  28896. [
  28897. 12,
  28898. 2368
  28899. ],
  28900. // 000000011100x
  28901. [
  28902. 12,
  28903. 2432
  28904. ],
  28905. [
  28906. 12,
  28907. 2432
  28908. ],
  28909. // 000000011101x
  28910. [
  28911. 12,
  28912. 2496
  28913. ],
  28914. [
  28915. 12,
  28916. 2496
  28917. ],
  28918. // 000000011110x
  28919. [
  28920. 12,
  28921. 2560
  28922. ],
  28923. [
  28924. 12,
  28925. 2560
  28926. ],
  28927. // 000000011111x
  28928. [
  28929. 10,
  28930. 18
  28931. ],
  28932. [
  28933. 10,
  28934. 18
  28935. ],
  28936. [
  28937. 10,
  28938. 18
  28939. ],
  28940. [
  28941. 10,
  28942. 18
  28943. ],
  28944. // 0000001000xxx
  28945. [
  28946. 10,
  28947. 18
  28948. ],
  28949. [
  28950. 10,
  28951. 18
  28952. ],
  28953. [
  28954. 10,
  28955. 18
  28956. ],
  28957. [
  28958. 10,
  28959. 18
  28960. ],
  28961. [
  28962. 12,
  28963. 52
  28964. ],
  28965. [
  28966. 12,
  28967. 52
  28968. ],
  28969. // 000000100100x
  28970. [
  28971. 13,
  28972. 640
  28973. ],
  28974. // 0000001001010
  28975. [
  28976. 13,
  28977. 704
  28978. ],
  28979. // 0000001001011
  28980. [
  28981. 13,
  28982. 768
  28983. ],
  28984. // 0000001001100
  28985. [
  28986. 13,
  28987. 832
  28988. ],
  28989. // 0000001001101
  28990. [
  28991. 12,
  28992. 55
  28993. ],
  28994. [
  28995. 12,
  28996. 55
  28997. ],
  28998. // 000000100111x
  28999. [
  29000. 12,
  29001. 56
  29002. ],
  29003. [
  29004. 12,
  29005. 56
  29006. ],
  29007. // 000000101000x
  29008. [
  29009. 13,
  29010. 1280
  29011. ],
  29012. // 0000001010010
  29013. [
  29014. 13,
  29015. 1344
  29016. ],
  29017. // 0000001010011
  29018. [
  29019. 13,
  29020. 1408
  29021. ],
  29022. // 0000001010100
  29023. [
  29024. 13,
  29025. 1472
  29026. ],
  29027. // 0000001010101
  29028. [
  29029. 12,
  29030. 59
  29031. ],
  29032. [
  29033. 12,
  29034. 59
  29035. ],
  29036. // 000000101011x
  29037. [
  29038. 12,
  29039. 60
  29040. ],
  29041. [
  29042. 12,
  29043. 60
  29044. ],
  29045. // 000000101100x
  29046. [
  29047. 13,
  29048. 1536
  29049. ],
  29050. // 0000001011010
  29051. [
  29052. 13,
  29053. 1600
  29054. ],
  29055. // 0000001011011
  29056. [
  29057. 11,
  29058. 24
  29059. ],
  29060. [
  29061. 11,
  29062. 24
  29063. ],
  29064. [
  29065. 11,
  29066. 24
  29067. ],
  29068. [
  29069. 11,
  29070. 24
  29071. ],
  29072. // 00000010111xx
  29073. [
  29074. 11,
  29075. 25
  29076. ],
  29077. [
  29078. 11,
  29079. 25
  29080. ],
  29081. [
  29082. 11,
  29083. 25
  29084. ],
  29085. [
  29086. 11,
  29087. 25
  29088. ],
  29089. // 00000011000xx
  29090. [
  29091. 13,
  29092. 1664
  29093. ],
  29094. // 0000001100100
  29095. [
  29096. 13,
  29097. 1728
  29098. ],
  29099. // 0000001100101
  29100. [
  29101. 12,
  29102. 320
  29103. ],
  29104. [
  29105. 12,
  29106. 320
  29107. ],
  29108. // 000000110011x
  29109. [
  29110. 12,
  29111. 384
  29112. ],
  29113. [
  29114. 12,
  29115. 384
  29116. ],
  29117. // 000000110100x
  29118. [
  29119. 12,
  29120. 448
  29121. ],
  29122. [
  29123. 12,
  29124. 448
  29125. ],
  29126. // 000000110101x
  29127. [
  29128. 13,
  29129. 512
  29130. ],
  29131. // 0000001101100
  29132. [
  29133. 13,
  29134. 576
  29135. ],
  29136. // 0000001101101
  29137. [
  29138. 12,
  29139. 53
  29140. ],
  29141. [
  29142. 12,
  29143. 53
  29144. ],
  29145. // 000000110111x
  29146. [
  29147. 12,
  29148. 54
  29149. ],
  29150. [
  29151. 12,
  29152. 54
  29153. ],
  29154. // 000000111000x
  29155. [
  29156. 13,
  29157. 896
  29158. ],
  29159. // 0000001110010
  29160. [
  29161. 13,
  29162. 960
  29163. ],
  29164. // 0000001110011
  29165. [
  29166. 13,
  29167. 1024
  29168. ],
  29169. // 0000001110100
  29170. [
  29171. 13,
  29172. 1088
  29173. ],
  29174. // 0000001110101
  29175. [
  29176. 13,
  29177. 1152
  29178. ],
  29179. // 0000001110110
  29180. [
  29181. 13,
  29182. 1216
  29183. ],
  29184. // 0000001110111
  29185. [
  29186. 10,
  29187. 64
  29188. ],
  29189. [
  29190. 10,
  29191. 64
  29192. ],
  29193. [
  29194. 10,
  29195. 64
  29196. ],
  29197. [
  29198. 10,
  29199. 64
  29200. ],
  29201. // 0000001111xxx
  29202. [
  29203. 10,
  29204. 64
  29205. ],
  29206. [
  29207. 10,
  29208. 64
  29209. ],
  29210. [
  29211. 10,
  29212. 64
  29213. ],
  29214. [
  29215. 10,
  29216. 64
  29217. ]
  29218. ];
  29219. var blackTable2 = [
  29220. [
  29221. 8,
  29222. 13
  29223. ],
  29224. [
  29225. 8,
  29226. 13
  29227. ],
  29228. [
  29229. 8,
  29230. 13
  29231. ],
  29232. [
  29233. 8,
  29234. 13
  29235. ],
  29236. // 00000100xxxx
  29237. [
  29238. 8,
  29239. 13
  29240. ],
  29241. [
  29242. 8,
  29243. 13
  29244. ],
  29245. [
  29246. 8,
  29247. 13
  29248. ],
  29249. [
  29250. 8,
  29251. 13
  29252. ],
  29253. [
  29254. 8,
  29255. 13
  29256. ],
  29257. [
  29258. 8,
  29259. 13
  29260. ],
  29261. [
  29262. 8,
  29263. 13
  29264. ],
  29265. [
  29266. 8,
  29267. 13
  29268. ],
  29269. [
  29270. 8,
  29271. 13
  29272. ],
  29273. [
  29274. 8,
  29275. 13
  29276. ],
  29277. [
  29278. 8,
  29279. 13
  29280. ],
  29281. [
  29282. 8,
  29283. 13
  29284. ],
  29285. [
  29286. 11,
  29287. 23
  29288. ],
  29289. [
  29290. 11,
  29291. 23
  29292. ],
  29293. // 00000101000x
  29294. [
  29295. 12,
  29296. 50
  29297. ],
  29298. // 000001010010
  29299. [
  29300. 12,
  29301. 51
  29302. ],
  29303. // 000001010011
  29304. [
  29305. 12,
  29306. 44
  29307. ],
  29308. // 000001010100
  29309. [
  29310. 12,
  29311. 45
  29312. ],
  29313. // 000001010101
  29314. [
  29315. 12,
  29316. 46
  29317. ],
  29318. // 000001010110
  29319. [
  29320. 12,
  29321. 47
  29322. ],
  29323. // 000001010111
  29324. [
  29325. 12,
  29326. 57
  29327. ],
  29328. // 000001011000
  29329. [
  29330. 12,
  29331. 58
  29332. ],
  29333. // 000001011001
  29334. [
  29335. 12,
  29336. 61
  29337. ],
  29338. // 000001011010
  29339. [
  29340. 12,
  29341. 256
  29342. ],
  29343. // 000001011011
  29344. [
  29345. 10,
  29346. 16
  29347. ],
  29348. [
  29349. 10,
  29350. 16
  29351. ],
  29352. [
  29353. 10,
  29354. 16
  29355. ],
  29356. [
  29357. 10,
  29358. 16
  29359. ],
  29360. // 0000010111xx
  29361. [
  29362. 10,
  29363. 17
  29364. ],
  29365. [
  29366. 10,
  29367. 17
  29368. ],
  29369. [
  29370. 10,
  29371. 17
  29372. ],
  29373. [
  29374. 10,
  29375. 17
  29376. ],
  29377. // 0000011000xx
  29378. [
  29379. 12,
  29380. 48
  29381. ],
  29382. // 000001100100
  29383. [
  29384. 12,
  29385. 49
  29386. ],
  29387. // 000001100101
  29388. [
  29389. 12,
  29390. 62
  29391. ],
  29392. // 000001100110
  29393. [
  29394. 12,
  29395. 63
  29396. ],
  29397. // 000001100111
  29398. [
  29399. 12,
  29400. 30
  29401. ],
  29402. // 000001101000
  29403. [
  29404. 12,
  29405. 31
  29406. ],
  29407. // 000001101001
  29408. [
  29409. 12,
  29410. 32
  29411. ],
  29412. // 000001101010
  29413. [
  29414. 12,
  29415. 33
  29416. ],
  29417. // 000001101011
  29418. [
  29419. 12,
  29420. 40
  29421. ],
  29422. // 000001101100
  29423. [
  29424. 12,
  29425. 41
  29426. ],
  29427. // 000001101101
  29428. [
  29429. 11,
  29430. 22
  29431. ],
  29432. [
  29433. 11,
  29434. 22
  29435. ],
  29436. // 00000110111x
  29437. [
  29438. 8,
  29439. 14
  29440. ],
  29441. [
  29442. 8,
  29443. 14
  29444. ],
  29445. [
  29446. 8,
  29447. 14
  29448. ],
  29449. [
  29450. 8,
  29451. 14
  29452. ],
  29453. // 00000111xxxx
  29454. [
  29455. 8,
  29456. 14
  29457. ],
  29458. [
  29459. 8,
  29460. 14
  29461. ],
  29462. [
  29463. 8,
  29464. 14
  29465. ],
  29466. [
  29467. 8,
  29468. 14
  29469. ],
  29470. [
  29471. 8,
  29472. 14
  29473. ],
  29474. [
  29475. 8,
  29476. 14
  29477. ],
  29478. [
  29479. 8,
  29480. 14
  29481. ],
  29482. [
  29483. 8,
  29484. 14
  29485. ],
  29486. [
  29487. 8,
  29488. 14
  29489. ],
  29490. [
  29491. 8,
  29492. 14
  29493. ],
  29494. [
  29495. 8,
  29496. 14
  29497. ],
  29498. [
  29499. 8,
  29500. 14
  29501. ],
  29502. [
  29503. 7,
  29504. 10
  29505. ],
  29506. [
  29507. 7,
  29508. 10
  29509. ],
  29510. [
  29511. 7,
  29512. 10
  29513. ],
  29514. [
  29515. 7,
  29516. 10
  29517. ],
  29518. // 0000100xxxxx
  29519. [
  29520. 7,
  29521. 10
  29522. ],
  29523. [
  29524. 7,
  29525. 10
  29526. ],
  29527. [
  29528. 7,
  29529. 10
  29530. ],
  29531. [
  29532. 7,
  29533. 10
  29534. ],
  29535. [
  29536. 7,
  29537. 10
  29538. ],
  29539. [
  29540. 7,
  29541. 10
  29542. ],
  29543. [
  29544. 7,
  29545. 10
  29546. ],
  29547. [
  29548. 7,
  29549. 10
  29550. ],
  29551. [
  29552. 7,
  29553. 10
  29554. ],
  29555. [
  29556. 7,
  29557. 10
  29558. ],
  29559. [
  29560. 7,
  29561. 10
  29562. ],
  29563. [
  29564. 7,
  29565. 10
  29566. ],
  29567. [
  29568. 7,
  29569. 10
  29570. ],
  29571. [
  29572. 7,
  29573. 10
  29574. ],
  29575. [
  29576. 7,
  29577. 10
  29578. ],
  29579. [
  29580. 7,
  29581. 10
  29582. ],
  29583. [
  29584. 7,
  29585. 10
  29586. ],
  29587. [
  29588. 7,
  29589. 10
  29590. ],
  29591. [
  29592. 7,
  29593. 10
  29594. ],
  29595. [
  29596. 7,
  29597. 10
  29598. ],
  29599. [
  29600. 7,
  29601. 10
  29602. ],
  29603. [
  29604. 7,
  29605. 10
  29606. ],
  29607. [
  29608. 7,
  29609. 10
  29610. ],
  29611. [
  29612. 7,
  29613. 10
  29614. ],
  29615. [
  29616. 7,
  29617. 10
  29618. ],
  29619. [
  29620. 7,
  29621. 10
  29622. ],
  29623. [
  29624. 7,
  29625. 10
  29626. ],
  29627. [
  29628. 7,
  29629. 10
  29630. ],
  29631. [
  29632. 7,
  29633. 11
  29634. ],
  29635. [
  29636. 7,
  29637. 11
  29638. ],
  29639. [
  29640. 7,
  29641. 11
  29642. ],
  29643. [
  29644. 7,
  29645. 11
  29646. ],
  29647. // 0000101xxxxx
  29648. [
  29649. 7,
  29650. 11
  29651. ],
  29652. [
  29653. 7,
  29654. 11
  29655. ],
  29656. [
  29657. 7,
  29658. 11
  29659. ],
  29660. [
  29661. 7,
  29662. 11
  29663. ],
  29664. [
  29665. 7,
  29666. 11
  29667. ],
  29668. [
  29669. 7,
  29670. 11
  29671. ],
  29672. [
  29673. 7,
  29674. 11
  29675. ],
  29676. [
  29677. 7,
  29678. 11
  29679. ],
  29680. [
  29681. 7,
  29682. 11
  29683. ],
  29684. [
  29685. 7,
  29686. 11
  29687. ],
  29688. [
  29689. 7,
  29690. 11
  29691. ],
  29692. [
  29693. 7,
  29694. 11
  29695. ],
  29696. [
  29697. 7,
  29698. 11
  29699. ],
  29700. [
  29701. 7,
  29702. 11
  29703. ],
  29704. [
  29705. 7,
  29706. 11
  29707. ],
  29708. [
  29709. 7,
  29710. 11
  29711. ],
  29712. [
  29713. 7,
  29714. 11
  29715. ],
  29716. [
  29717. 7,
  29718. 11
  29719. ],
  29720. [
  29721. 7,
  29722. 11
  29723. ],
  29724. [
  29725. 7,
  29726. 11
  29727. ],
  29728. [
  29729. 7,
  29730. 11
  29731. ],
  29732. [
  29733. 7,
  29734. 11
  29735. ],
  29736. [
  29737. 7,
  29738. 11
  29739. ],
  29740. [
  29741. 7,
  29742. 11
  29743. ],
  29744. [
  29745. 7,
  29746. 11
  29747. ],
  29748. [
  29749. 7,
  29750. 11
  29751. ],
  29752. [
  29753. 7,
  29754. 11
  29755. ],
  29756. [
  29757. 7,
  29758. 11
  29759. ],
  29760. [
  29761. 9,
  29762. 15
  29763. ],
  29764. [
  29765. 9,
  29766. 15
  29767. ],
  29768. [
  29769. 9,
  29770. 15
  29771. ],
  29772. [
  29773. 9,
  29774. 15
  29775. ],
  29776. // 000011000xxx
  29777. [
  29778. 9,
  29779. 15
  29780. ],
  29781. [
  29782. 9,
  29783. 15
  29784. ],
  29785. [
  29786. 9,
  29787. 15
  29788. ],
  29789. [
  29790. 9,
  29791. 15
  29792. ],
  29793. [
  29794. 12,
  29795. 128
  29796. ],
  29797. // 000011001000
  29798. [
  29799. 12,
  29800. 192
  29801. ],
  29802. // 000011001001
  29803. [
  29804. 12,
  29805. 26
  29806. ],
  29807. // 000011001010
  29808. [
  29809. 12,
  29810. 27
  29811. ],
  29812. // 000011001011
  29813. [
  29814. 12,
  29815. 28
  29816. ],
  29817. // 000011001100
  29818. [
  29819. 12,
  29820. 29
  29821. ],
  29822. // 000011001101
  29823. [
  29824. 11,
  29825. 19
  29826. ],
  29827. [
  29828. 11,
  29829. 19
  29830. ],
  29831. // 00001100111x
  29832. [
  29833. 11,
  29834. 20
  29835. ],
  29836. [
  29837. 11,
  29838. 20
  29839. ],
  29840. // 00001101000x
  29841. [
  29842. 12,
  29843. 34
  29844. ],
  29845. // 000011010010
  29846. [
  29847. 12,
  29848. 35
  29849. ],
  29850. // 000011010011
  29851. [
  29852. 12,
  29853. 36
  29854. ],
  29855. // 000011010100
  29856. [
  29857. 12,
  29858. 37
  29859. ],
  29860. // 000011010101
  29861. [
  29862. 12,
  29863. 38
  29864. ],
  29865. // 000011010110
  29866. [
  29867. 12,
  29868. 39
  29869. ],
  29870. // 000011010111
  29871. [
  29872. 11,
  29873. 21
  29874. ],
  29875. [
  29876. 11,
  29877. 21
  29878. ],
  29879. // 00001101100x
  29880. [
  29881. 12,
  29882. 42
  29883. ],
  29884. // 000011011010
  29885. [
  29886. 12,
  29887. 43
  29888. ],
  29889. // 000011011011
  29890. [
  29891. 10,
  29892. 0
  29893. ],
  29894. [
  29895. 10,
  29896. 0
  29897. ],
  29898. [
  29899. 10,
  29900. 0
  29901. ],
  29902. [
  29903. 10,
  29904. 0
  29905. ],
  29906. // 0000110111xx
  29907. [
  29908. 7,
  29909. 12
  29910. ],
  29911. [
  29912. 7,
  29913. 12
  29914. ],
  29915. [
  29916. 7,
  29917. 12
  29918. ],
  29919. [
  29920. 7,
  29921. 12
  29922. ],
  29923. // 0000111xxxxx
  29924. [
  29925. 7,
  29926. 12
  29927. ],
  29928. [
  29929. 7,
  29930. 12
  29931. ],
  29932. [
  29933. 7,
  29934. 12
  29935. ],
  29936. [
  29937. 7,
  29938. 12
  29939. ],
  29940. [
  29941. 7,
  29942. 12
  29943. ],
  29944. [
  29945. 7,
  29946. 12
  29947. ],
  29948. [
  29949. 7,
  29950. 12
  29951. ],
  29952. [
  29953. 7,
  29954. 12
  29955. ],
  29956. [
  29957. 7,
  29958. 12
  29959. ],
  29960. [
  29961. 7,
  29962. 12
  29963. ],
  29964. [
  29965. 7,
  29966. 12
  29967. ],
  29968. [
  29969. 7,
  29970. 12
  29971. ],
  29972. [
  29973. 7,
  29974. 12
  29975. ],
  29976. [
  29977. 7,
  29978. 12
  29979. ],
  29980. [
  29981. 7,
  29982. 12
  29983. ],
  29984. [
  29985. 7,
  29986. 12
  29987. ],
  29988. [
  29989. 7,
  29990. 12
  29991. ],
  29992. [
  29993. 7,
  29994. 12
  29995. ],
  29996. [
  29997. 7,
  29998. 12
  29999. ],
  30000. [
  30001. 7,
  30002. 12
  30003. ],
  30004. [
  30005. 7,
  30006. 12
  30007. ],
  30008. [
  30009. 7,
  30010. 12
  30011. ],
  30012. [
  30013. 7,
  30014. 12
  30015. ],
  30016. [
  30017. 7,
  30018. 12
  30019. ],
  30020. [
  30021. 7,
  30022. 12
  30023. ],
  30024. [
  30025. 7,
  30026. 12
  30027. ],
  30028. [
  30029. 7,
  30030. 12
  30031. ],
  30032. [
  30033. 7,
  30034. 12
  30035. ]
  30036. ];
  30037. var blackTable3 = [
  30038. [
  30039. -1,
  30040. -1
  30041. ],
  30042. [
  30043. -1,
  30044. -1
  30045. ],
  30046. [
  30047. -1,
  30048. -1
  30049. ],
  30050. [
  30051. -1,
  30052. -1
  30053. ],
  30054. // 0000xx
  30055. [
  30056. 6,
  30057. 9
  30058. ],
  30059. // 000100
  30060. [
  30061. 6,
  30062. 8
  30063. ],
  30064. // 000101
  30065. [
  30066. 5,
  30067. 7
  30068. ],
  30069. [
  30070. 5,
  30071. 7
  30072. ],
  30073. // 00011x
  30074. [
  30075. 4,
  30076. 6
  30077. ],
  30078. [
  30079. 4,
  30080. 6
  30081. ],
  30082. [
  30083. 4,
  30084. 6
  30085. ],
  30086. [
  30087. 4,
  30088. 6
  30089. ],
  30090. // 0010xx
  30091. [
  30092. 4,
  30093. 5
  30094. ],
  30095. [
  30096. 4,
  30097. 5
  30098. ],
  30099. [
  30100. 4,
  30101. 5
  30102. ],
  30103. [
  30104. 4,
  30105. 5
  30106. ],
  30107. // 0011xx
  30108. [
  30109. 3,
  30110. 1
  30111. ],
  30112. [
  30113. 3,
  30114. 1
  30115. ],
  30116. [
  30117. 3,
  30118. 1
  30119. ],
  30120. [
  30121. 3,
  30122. 1
  30123. ],
  30124. // 010xxx
  30125. [
  30126. 3,
  30127. 1
  30128. ],
  30129. [
  30130. 3,
  30131. 1
  30132. ],
  30133. [
  30134. 3,
  30135. 1
  30136. ],
  30137. [
  30138. 3,
  30139. 1
  30140. ],
  30141. [
  30142. 3,
  30143. 4
  30144. ],
  30145. [
  30146. 3,
  30147. 4
  30148. ],
  30149. [
  30150. 3,
  30151. 4
  30152. ],
  30153. [
  30154. 3,
  30155. 4
  30156. ],
  30157. // 011xxx
  30158. [
  30159. 3,
  30160. 4
  30161. ],
  30162. [
  30163. 3,
  30164. 4
  30165. ],
  30166. [
  30167. 3,
  30168. 4
  30169. ],
  30170. [
  30171. 3,
  30172. 4
  30173. ],
  30174. [
  30175. 2,
  30176. 3
  30177. ],
  30178. [
  30179. 2,
  30180. 3
  30181. ],
  30182. [
  30183. 2,
  30184. 3
  30185. ],
  30186. [
  30187. 2,
  30188. 3
  30189. ],
  30190. // 10xxxx
  30191. [
  30192. 2,
  30193. 3
  30194. ],
  30195. [
  30196. 2,
  30197. 3
  30198. ],
  30199. [
  30200. 2,
  30201. 3
  30202. ],
  30203. [
  30204. 2,
  30205. 3
  30206. ],
  30207. [
  30208. 2,
  30209. 3
  30210. ],
  30211. [
  30212. 2,
  30213. 3
  30214. ],
  30215. [
  30216. 2,
  30217. 3
  30218. ],
  30219. [
  30220. 2,
  30221. 3
  30222. ],
  30223. [
  30224. 2,
  30225. 3
  30226. ],
  30227. [
  30228. 2,
  30229. 3
  30230. ],
  30231. [
  30232. 2,
  30233. 3
  30234. ],
  30235. [
  30236. 2,
  30237. 3
  30238. ],
  30239. [
  30240. 2,
  30241. 2
  30242. ],
  30243. [
  30244. 2,
  30245. 2
  30246. ],
  30247. [
  30248. 2,
  30249. 2
  30250. ],
  30251. [
  30252. 2,
  30253. 2
  30254. ],
  30255. // 11xxxx
  30256. [
  30257. 2,
  30258. 2
  30259. ],
  30260. [
  30261. 2,
  30262. 2
  30263. ],
  30264. [
  30265. 2,
  30266. 2
  30267. ],
  30268. [
  30269. 2,
  30270. 2
  30271. ],
  30272. [
  30273. 2,
  30274. 2
  30275. ],
  30276. [
  30277. 2,
  30278. 2
  30279. ],
  30280. [
  30281. 2,
  30282. 2
  30283. ],
  30284. [
  30285. 2,
  30286. 2
  30287. ],
  30288. [
  30289. 2,
  30290. 2
  30291. ],
  30292. [
  30293. 2,
  30294. 2
  30295. ],
  30296. [
  30297. 2,
  30298. 2
  30299. ],
  30300. [
  30301. 2,
  30302. 2
  30303. ]
  30304. ];
  30305. function CCITTFaxStream(str, maybeLength, params) {
  30306. this.str = str;
  30307. this.dict = str.dict;
  30308. params = params || Dict.empty;
  30309. this.encoding = params.get('K') || 0;
  30310. this.eoline = params.get('EndOfLine') || false;
  30311. this.byteAlign = params.get('EncodedByteAlign') || false;
  30312. this.columns = params.get('Columns') || 1728;
  30313. this.rows = params.get('Rows') || 0;
  30314. var eoblock = params.get('EndOfBlock');
  30315. if (eoblock === null || eoblock === undefined) {
  30316. eoblock = true;
  30317. }
  30318. this.eoblock = eoblock;
  30319. this.black = params.get('BlackIs1') || false;
  30320. this.codingLine = new Uint32Array(this.columns + 1);
  30321. this.refLine = new Uint32Array(this.columns + 2);
  30322. this.codingLine[0] = this.columns;
  30323. this.codingPos = 0;
  30324. this.row = 0;
  30325. this.nextLine2D = this.encoding < 0;
  30326. this.inputBits = 0;
  30327. this.inputBuf = 0;
  30328. this.outputBits = 0;
  30329. var code1;
  30330. while ((code1 = this.lookBits(12)) === 0) {
  30331. this.eatBits(1);
  30332. }
  30333. if (code1 === 1) {
  30334. this.eatBits(12);
  30335. }
  30336. if (this.encoding > 0) {
  30337. this.nextLine2D = !this.lookBits(1);
  30338. this.eatBits(1);
  30339. }
  30340. DecodeStream.call(this, maybeLength);
  30341. }
  30342. CCITTFaxStream.prototype = Object.create(DecodeStream.prototype);
  30343. CCITTFaxStream.prototype.readBlock = function CCITTFaxStream_readBlock() {
  30344. while (!this.eof) {
  30345. var c = this.lookChar();
  30346. this.ensureBuffer(this.bufferLength + 1);
  30347. this.buffer[this.bufferLength++] = c;
  30348. }
  30349. };
  30350. CCITTFaxStream.prototype.addPixels = function ccittFaxStreamAddPixels(a1, blackPixels) {
  30351. var codingLine = this.codingLine;
  30352. var codingPos = this.codingPos;
  30353. if (a1 > codingLine[codingPos]) {
  30354. if (a1 > this.columns) {
  30355. info('row is wrong length');
  30356. this.err = true;
  30357. a1 = this.columns;
  30358. }
  30359. if (codingPos & 1 ^ blackPixels) {
  30360. ++codingPos;
  30361. }
  30362. codingLine[codingPos] = a1;
  30363. }
  30364. this.codingPos = codingPos;
  30365. };
  30366. CCITTFaxStream.prototype.addPixelsNeg = function ccittFaxStreamAddPixelsNeg(a1, blackPixels) {
  30367. var codingLine = this.codingLine;
  30368. var codingPos = this.codingPos;
  30369. if (a1 > codingLine[codingPos]) {
  30370. if (a1 > this.columns) {
  30371. info('row is wrong length');
  30372. this.err = true;
  30373. a1 = this.columns;
  30374. }
  30375. if (codingPos & 1 ^ blackPixels) {
  30376. ++codingPos;
  30377. }
  30378. codingLine[codingPos] = a1;
  30379. } else if (a1 < codingLine[codingPos]) {
  30380. if (a1 < 0) {
  30381. info('invalid code');
  30382. this.err = true;
  30383. a1 = 0;
  30384. }
  30385. while (codingPos > 0 && a1 < codingLine[codingPos - 1]) {
  30386. --codingPos;
  30387. }
  30388. codingLine[codingPos] = a1;
  30389. }
  30390. this.codingPos = codingPos;
  30391. };
  30392. CCITTFaxStream.prototype.lookChar = function CCITTFaxStream_lookChar() {
  30393. var refLine = this.refLine;
  30394. var codingLine = this.codingLine;
  30395. var columns = this.columns;
  30396. var refPos, blackPixels, bits, i;
  30397. if (this.outputBits === 0) {
  30398. if (this.eof) {
  30399. return null;
  30400. }
  30401. this.err = false;
  30402. var code1, code2, code3;
  30403. if (this.nextLine2D) {
  30404. for (i = 0; codingLine[i] < columns; ++i) {
  30405. refLine[i] = codingLine[i];
  30406. }
  30407. refLine[i++] = columns;
  30408. refLine[i] = columns;
  30409. codingLine[0] = 0;
  30410. this.codingPos = 0;
  30411. refPos = 0;
  30412. blackPixels = 0;
  30413. while (codingLine[this.codingPos] < columns) {
  30414. code1 = this.getTwoDimCode();
  30415. switch (code1) {
  30416. case twoDimPass:
  30417. this.addPixels(refLine[refPos + 1], blackPixels);
  30418. if (refLine[refPos + 1] < columns) {
  30419. refPos += 2;
  30420. }
  30421. break;
  30422. case twoDimHoriz:
  30423. code1 = code2 = 0;
  30424. if (blackPixels) {
  30425. do {
  30426. code1 += code3 = this.getBlackCode();
  30427. } while (code3 >= 64);
  30428. do {
  30429. code2 += code3 = this.getWhiteCode();
  30430. } while (code3 >= 64);
  30431. } else {
  30432. do {
  30433. code1 += code3 = this.getWhiteCode();
  30434. } while (code3 >= 64);
  30435. do {
  30436. code2 += code3 = this.getBlackCode();
  30437. } while (code3 >= 64);
  30438. }
  30439. this.addPixels(codingLine[this.codingPos] + code1, blackPixels);
  30440. if (codingLine[this.codingPos] < columns) {
  30441. this.addPixels(codingLine[this.codingPos] + code2, blackPixels ^ 1);
  30442. }
  30443. while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
  30444. refPos += 2;
  30445. }
  30446. break;
  30447. case twoDimVertR3:
  30448. this.addPixels(refLine[refPos] + 3, blackPixels);
  30449. blackPixels ^= 1;
  30450. if (codingLine[this.codingPos] < columns) {
  30451. ++refPos;
  30452. while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
  30453. refPos += 2;
  30454. }
  30455. }
  30456. break;
  30457. case twoDimVertR2:
  30458. this.addPixels(refLine[refPos] + 2, blackPixels);
  30459. blackPixels ^= 1;
  30460. if (codingLine[this.codingPos] < columns) {
  30461. ++refPos;
  30462. while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
  30463. refPos += 2;
  30464. }
  30465. }
  30466. break;
  30467. case twoDimVertR1:
  30468. this.addPixels(refLine[refPos] + 1, blackPixels);
  30469. blackPixels ^= 1;
  30470. if (codingLine[this.codingPos] < columns) {
  30471. ++refPos;
  30472. while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
  30473. refPos += 2;
  30474. }
  30475. }
  30476. break;
  30477. case twoDimVert0:
  30478. this.addPixels(refLine[refPos], blackPixels);
  30479. blackPixels ^= 1;
  30480. if (codingLine[this.codingPos] < columns) {
  30481. ++refPos;
  30482. while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
  30483. refPos += 2;
  30484. }
  30485. }
  30486. break;
  30487. case twoDimVertL3:
  30488. this.addPixelsNeg(refLine[refPos] - 3, blackPixels);
  30489. blackPixels ^= 1;
  30490. if (codingLine[this.codingPos] < columns) {
  30491. if (refPos > 0) {
  30492. --refPos;
  30493. } else {
  30494. ++refPos;
  30495. }
  30496. while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
  30497. refPos += 2;
  30498. }
  30499. }
  30500. break;
  30501. case twoDimVertL2:
  30502. this.addPixelsNeg(refLine[refPos] - 2, blackPixels);
  30503. blackPixels ^= 1;
  30504. if (codingLine[this.codingPos] < columns) {
  30505. if (refPos > 0) {
  30506. --refPos;
  30507. } else {
  30508. ++refPos;
  30509. }
  30510. while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
  30511. refPos += 2;
  30512. }
  30513. }
  30514. break;
  30515. case twoDimVertL1:
  30516. this.addPixelsNeg(refLine[refPos] - 1, blackPixels);
  30517. blackPixels ^= 1;
  30518. if (codingLine[this.codingPos] < columns) {
  30519. if (refPos > 0) {
  30520. --refPos;
  30521. } else {
  30522. ++refPos;
  30523. }
  30524. while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
  30525. refPos += 2;
  30526. }
  30527. }
  30528. break;
  30529. case ccittEOF:
  30530. this.addPixels(columns, 0);
  30531. this.eof = true;
  30532. break;
  30533. default:
  30534. info('bad 2d code');
  30535. this.addPixels(columns, 0);
  30536. this.err = true;
  30537. }
  30538. }
  30539. } else {
  30540. codingLine[0] = 0;
  30541. this.codingPos = 0;
  30542. blackPixels = 0;
  30543. while (codingLine[this.codingPos] < columns) {
  30544. code1 = 0;
  30545. if (blackPixels) {
  30546. do {
  30547. code1 += code3 = this.getBlackCode();
  30548. } while (code3 >= 64);
  30549. } else {
  30550. do {
  30551. code1 += code3 = this.getWhiteCode();
  30552. } while (code3 >= 64);
  30553. }
  30554. this.addPixels(codingLine[this.codingPos] + code1, blackPixels);
  30555. blackPixels ^= 1;
  30556. }
  30557. }
  30558. var gotEOL = false;
  30559. if (this.byteAlign) {
  30560. this.inputBits &= ~7;
  30561. }
  30562. if (!this.eoblock && this.row === this.rows - 1) {
  30563. this.eof = true;
  30564. } else {
  30565. code1 = this.lookBits(12);
  30566. if (this.eoline) {
  30567. while (code1 !== ccittEOF && code1 !== 1) {
  30568. this.eatBits(1);
  30569. code1 = this.lookBits(12);
  30570. }
  30571. } else {
  30572. while (code1 === 0) {
  30573. this.eatBits(1);
  30574. code1 = this.lookBits(12);
  30575. }
  30576. }
  30577. if (code1 === 1) {
  30578. this.eatBits(12);
  30579. gotEOL = true;
  30580. } else if (code1 === ccittEOF) {
  30581. this.eof = true;
  30582. }
  30583. }
  30584. if (!this.eof && this.encoding > 0) {
  30585. this.nextLine2D = !this.lookBits(1);
  30586. this.eatBits(1);
  30587. }
  30588. if (this.eoblock && gotEOL && this.byteAlign) {
  30589. code1 = this.lookBits(12);
  30590. if (code1 === 1) {
  30591. this.eatBits(12);
  30592. if (this.encoding > 0) {
  30593. this.lookBits(1);
  30594. this.eatBits(1);
  30595. }
  30596. if (this.encoding >= 0) {
  30597. for (i = 0; i < 4; ++i) {
  30598. code1 = this.lookBits(12);
  30599. if (code1 !== 1) {
  30600. info('bad rtc code: ' + code1);
  30601. }
  30602. this.eatBits(12);
  30603. if (this.encoding > 0) {
  30604. this.lookBits(1);
  30605. this.eatBits(1);
  30606. }
  30607. }
  30608. }
  30609. this.eof = true;
  30610. }
  30611. } else if (this.err && this.eoline) {
  30612. while (true) {
  30613. code1 = this.lookBits(13);
  30614. if (code1 === ccittEOF) {
  30615. this.eof = true;
  30616. return null;
  30617. }
  30618. if (code1 >> 1 === 1) {
  30619. break;
  30620. }
  30621. this.eatBits(1);
  30622. }
  30623. this.eatBits(12);
  30624. if (this.encoding > 0) {
  30625. this.eatBits(1);
  30626. this.nextLine2D = !(code1 & 1);
  30627. }
  30628. }
  30629. if (codingLine[0] > 0) {
  30630. this.outputBits = codingLine[this.codingPos = 0];
  30631. } else {
  30632. this.outputBits = codingLine[this.codingPos = 1];
  30633. }
  30634. this.row++;
  30635. }
  30636. var c;
  30637. if (this.outputBits >= 8) {
  30638. c = this.codingPos & 1 ? 0 : 0xFF;
  30639. this.outputBits -= 8;
  30640. if (this.outputBits === 0 && codingLine[this.codingPos] < columns) {
  30641. this.codingPos++;
  30642. this.outputBits = codingLine[this.codingPos] - codingLine[this.codingPos - 1];
  30643. }
  30644. } else {
  30645. bits = 8;
  30646. c = 0;
  30647. do {
  30648. if (this.outputBits > bits) {
  30649. c <<= bits;
  30650. if (!(this.codingPos & 1)) {
  30651. c |= 0xFF >> 8 - bits;
  30652. }
  30653. this.outputBits -= bits;
  30654. bits = 0;
  30655. } else {
  30656. c <<= this.outputBits;
  30657. if (!(this.codingPos & 1)) {
  30658. c |= 0xFF >> 8 - this.outputBits;
  30659. }
  30660. bits -= this.outputBits;
  30661. this.outputBits = 0;
  30662. if (codingLine[this.codingPos] < columns) {
  30663. this.codingPos++;
  30664. this.outputBits = codingLine[this.codingPos] - codingLine[this.codingPos - 1];
  30665. } else if (bits > 0) {
  30666. c <<= bits;
  30667. bits = 0;
  30668. }
  30669. }
  30670. } while (bits);
  30671. }
  30672. if (this.black) {
  30673. c ^= 0xFF;
  30674. }
  30675. return c;
  30676. };
  30677. // This functions returns the code found from the table.
  30678. // The start and end parameters set the boundaries for searching the table.
  30679. // The limit parameter is optional. Function returns an array with three
  30680. // values. The first array element indicates whether a valid code is being
  30681. // returned. The second array element is the actual code. The third array
  30682. // element indicates whether EOF was reached.
  30683. CCITTFaxStream.prototype.findTableCode = function ccittFaxStreamFindTableCode(start, end, table, limit) {
  30684. var limitValue = limit || 0;
  30685. for (var i = start; i <= end; ++i) {
  30686. var code = this.lookBits(i);
  30687. if (code === ccittEOF) {
  30688. return [
  30689. true,
  30690. 1,
  30691. false
  30692. ];
  30693. }
  30694. if (i < end) {
  30695. code <<= end - i;
  30696. }
  30697. if (!limitValue || code >= limitValue) {
  30698. var p = table[code - limitValue];
  30699. if (p[0] === i) {
  30700. this.eatBits(i);
  30701. return [
  30702. true,
  30703. p[1],
  30704. true
  30705. ];
  30706. }
  30707. }
  30708. }
  30709. return [
  30710. false,
  30711. 0,
  30712. false
  30713. ];
  30714. };
  30715. CCITTFaxStream.prototype.getTwoDimCode = function ccittFaxStreamGetTwoDimCode() {
  30716. var code = 0;
  30717. var p;
  30718. if (this.eoblock) {
  30719. code = this.lookBits(7);
  30720. p = twoDimTable[code];
  30721. if (p && p[0] > 0) {
  30722. this.eatBits(p[0]);
  30723. return p[1];
  30724. }
  30725. } else {
  30726. var result = this.findTableCode(1, 7, twoDimTable);
  30727. if (result[0] && result[2]) {
  30728. return result[1];
  30729. }
  30730. }
  30731. info('Bad two dim code');
  30732. return ccittEOF;
  30733. };
  30734. CCITTFaxStream.prototype.getWhiteCode = function ccittFaxStreamGetWhiteCode() {
  30735. var code = 0;
  30736. var p;
  30737. if (this.eoblock) {
  30738. code = this.lookBits(12);
  30739. if (code === ccittEOF) {
  30740. return 1;
  30741. }
  30742. if (code >> 5 === 0) {
  30743. p = whiteTable1[code];
  30744. } else {
  30745. p = whiteTable2[code >> 3];
  30746. }
  30747. if (p[0] > 0) {
  30748. this.eatBits(p[0]);
  30749. return p[1];
  30750. }
  30751. } else {
  30752. var result = this.findTableCode(1, 9, whiteTable2);
  30753. if (result[0]) {
  30754. return result[1];
  30755. }
  30756. result = this.findTableCode(11, 12, whiteTable1);
  30757. if (result[0]) {
  30758. return result[1];
  30759. }
  30760. }
  30761. info('bad white code');
  30762. this.eatBits(1);
  30763. return 1;
  30764. };
  30765. CCITTFaxStream.prototype.getBlackCode = function ccittFaxStreamGetBlackCode() {
  30766. var code, p;
  30767. if (this.eoblock) {
  30768. code = this.lookBits(13);
  30769. if (code === ccittEOF) {
  30770. return 1;
  30771. }
  30772. if (code >> 7 === 0) {
  30773. p = blackTable1[code];
  30774. } else if (code >> 9 === 0 && code >> 7 !== 0) {
  30775. p = blackTable2[(code >> 1) - 64];
  30776. } else {
  30777. p = blackTable3[code >> 7];
  30778. }
  30779. if (p[0] > 0) {
  30780. this.eatBits(p[0]);
  30781. return p[1];
  30782. }
  30783. } else {
  30784. var result = this.findTableCode(2, 6, blackTable3);
  30785. if (result[0]) {
  30786. return result[1];
  30787. }
  30788. result = this.findTableCode(7, 12, blackTable2, 64);
  30789. if (result[0]) {
  30790. return result[1];
  30791. }
  30792. result = this.findTableCode(10, 13, blackTable1);
  30793. if (result[0]) {
  30794. return result[1];
  30795. }
  30796. }
  30797. info('bad black code');
  30798. this.eatBits(1);
  30799. return 1;
  30800. };
  30801. CCITTFaxStream.prototype.lookBits = function CCITTFaxStream_lookBits(n) {
  30802. var c;
  30803. while (this.inputBits < n) {
  30804. if ((c = this.str.getByte()) === -1) {
  30805. if (this.inputBits === 0) {
  30806. return ccittEOF;
  30807. }
  30808. return this.inputBuf << n - this.inputBits & 0xFFFF >> 16 - n;
  30809. }
  30810. this.inputBuf = this.inputBuf << 8 | c;
  30811. this.inputBits += 8;
  30812. }
  30813. return this.inputBuf >> this.inputBits - n & 0xFFFF >> 16 - n;
  30814. };
  30815. CCITTFaxStream.prototype.eatBits = function CCITTFaxStream_eatBits(n) {
  30816. if ((this.inputBits -= n) < 0) {
  30817. this.inputBits = 0;
  30818. }
  30819. };
  30820. return CCITTFaxStream;
  30821. }();
  30822. var LZWStream = function LZWStreamClosure() {
  30823. function LZWStream(str, maybeLength, earlyChange) {
  30824. this.str = str;
  30825. this.dict = str.dict;
  30826. this.cachedData = 0;
  30827. this.bitsCached = 0;
  30828. var maxLzwDictionarySize = 4096;
  30829. var lzwState = {
  30830. earlyChange: earlyChange,
  30831. codeLength: 9,
  30832. nextCode: 258,
  30833. dictionaryValues: new Uint8Array(maxLzwDictionarySize),
  30834. dictionaryLengths: new Uint16Array(maxLzwDictionarySize),
  30835. dictionaryPrevCodes: new Uint16Array(maxLzwDictionarySize),
  30836. currentSequence: new Uint8Array(maxLzwDictionarySize),
  30837. currentSequenceLength: 0
  30838. };
  30839. for (var i = 0; i < 256; ++i) {
  30840. lzwState.dictionaryValues[i] = i;
  30841. lzwState.dictionaryLengths[i] = 1;
  30842. }
  30843. this.lzwState = lzwState;
  30844. DecodeStream.call(this, maybeLength);
  30845. }
  30846. LZWStream.prototype = Object.create(DecodeStream.prototype);
  30847. LZWStream.prototype.readBits = function LZWStream_readBits(n) {
  30848. var bitsCached = this.bitsCached;
  30849. var cachedData = this.cachedData;
  30850. while (bitsCached < n) {
  30851. var c = this.str.getByte();
  30852. if (c === -1) {
  30853. this.eof = true;
  30854. return null;
  30855. }
  30856. cachedData = cachedData << 8 | c;
  30857. bitsCached += 8;
  30858. }
  30859. this.bitsCached = bitsCached -= n;
  30860. this.cachedData = cachedData;
  30861. this.lastCode = null;
  30862. return cachedData >>> bitsCached & (1 << n) - 1;
  30863. };
  30864. LZWStream.prototype.readBlock = function LZWStream_readBlock() {
  30865. var blockSize = 512;
  30866. var estimatedDecodedSize = blockSize * 2, decodedSizeDelta = blockSize;
  30867. var i, j, q;
  30868. var lzwState = this.lzwState;
  30869. if (!lzwState) {
  30870. return;
  30871. }
  30872. // eof was found
  30873. var earlyChange = lzwState.earlyChange;
  30874. var nextCode = lzwState.nextCode;
  30875. var dictionaryValues = lzwState.dictionaryValues;
  30876. var dictionaryLengths = lzwState.dictionaryLengths;
  30877. var dictionaryPrevCodes = lzwState.dictionaryPrevCodes;
  30878. var codeLength = lzwState.codeLength;
  30879. var prevCode = lzwState.prevCode;
  30880. var currentSequence = lzwState.currentSequence;
  30881. var currentSequenceLength = lzwState.currentSequenceLength;
  30882. var decodedLength = 0;
  30883. var currentBufferLength = this.bufferLength;
  30884. var buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  30885. for (i = 0; i < blockSize; i++) {
  30886. var code = this.readBits(codeLength);
  30887. var hasPrev = currentSequenceLength > 0;
  30888. if (code < 256) {
  30889. currentSequence[0] = code;
  30890. currentSequenceLength = 1;
  30891. } else if (code >= 258) {
  30892. if (code < nextCode) {
  30893. currentSequenceLength = dictionaryLengths[code];
  30894. for (j = currentSequenceLength - 1, q = code; j >= 0; j--) {
  30895. currentSequence[j] = dictionaryValues[q];
  30896. q = dictionaryPrevCodes[q];
  30897. }
  30898. } else {
  30899. currentSequence[currentSequenceLength++] = currentSequence[0];
  30900. }
  30901. } else if (code === 256) {
  30902. codeLength = 9;
  30903. nextCode = 258;
  30904. currentSequenceLength = 0;
  30905. continue;
  30906. } else {
  30907. this.eof = true;
  30908. delete this.lzwState;
  30909. break;
  30910. }
  30911. if (hasPrev) {
  30912. dictionaryPrevCodes[nextCode] = prevCode;
  30913. dictionaryLengths[nextCode] = dictionaryLengths[prevCode] + 1;
  30914. dictionaryValues[nextCode] = currentSequence[0];
  30915. nextCode++;
  30916. codeLength = nextCode + earlyChange & nextCode + earlyChange - 1 ? codeLength : Math.min(Math.log(nextCode + earlyChange) / 0.6931471805599453 + 1, 12) | 0;
  30917. }
  30918. prevCode = code;
  30919. decodedLength += currentSequenceLength;
  30920. if (estimatedDecodedSize < decodedLength) {
  30921. do {
  30922. estimatedDecodedSize += decodedSizeDelta;
  30923. } while (estimatedDecodedSize < decodedLength);
  30924. buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  30925. }
  30926. for (j = 0; j < currentSequenceLength; j++) {
  30927. buffer[currentBufferLength++] = currentSequence[j];
  30928. }
  30929. }
  30930. lzwState.nextCode = nextCode;
  30931. lzwState.codeLength = codeLength;
  30932. lzwState.prevCode = prevCode;
  30933. lzwState.currentSequenceLength = currentSequenceLength;
  30934. this.bufferLength = currentBufferLength;
  30935. };
  30936. return LZWStream;
  30937. }();
  30938. var NullStream = function NullStreamClosure() {
  30939. function NullStream() {
  30940. Stream.call(this, new Uint8Array(0));
  30941. }
  30942. NullStream.prototype = Stream.prototype;
  30943. return NullStream;
  30944. }();
  30945. exports.Ascii85Stream = Ascii85Stream;
  30946. exports.AsciiHexStream = AsciiHexStream;
  30947. exports.CCITTFaxStream = CCITTFaxStream;
  30948. exports.DecryptStream = DecryptStream;
  30949. exports.DecodeStream = DecodeStream;
  30950. exports.FlateStream = FlateStream;
  30951. exports.Jbig2Stream = Jbig2Stream;
  30952. exports.JpegStream = JpegStream;
  30953. exports.JpxStream = JpxStream;
  30954. exports.NullStream = NullStream;
  30955. exports.PredictorStream = PredictorStream;
  30956. exports.RunLengthStream = RunLengthStream;
  30957. exports.Stream = Stream;
  30958. exports.StreamsSequenceStream = StreamsSequenceStream;
  30959. exports.StringStream = StringStream;
  30960. exports.LZWStream = LZWStream;
  30961. }));
  30962. (function (root, factory) {
  30963. factory(root.pdfjsCoreCrypto = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCoreStream);
  30964. }(this, function (exports, sharedUtil, corePrimitives, coreStream) {
  30965. var PasswordException = sharedUtil.PasswordException;
  30966. var PasswordResponses = sharedUtil.PasswordResponses;
  30967. var bytesToString = sharedUtil.bytesToString;
  30968. var warn = sharedUtil.warn;
  30969. var error = sharedUtil.error;
  30970. var assert = sharedUtil.assert;
  30971. var isInt = sharedUtil.isInt;
  30972. var stringToBytes = sharedUtil.stringToBytes;
  30973. var utf8StringToString = sharedUtil.utf8StringToString;
  30974. var Name = corePrimitives.Name;
  30975. var isName = corePrimitives.isName;
  30976. var isDict = corePrimitives.isDict;
  30977. var DecryptStream = coreStream.DecryptStream;
  30978. var ARCFourCipher = function ARCFourCipherClosure() {
  30979. function ARCFourCipher(key) {
  30980. this.a = 0;
  30981. this.b = 0;
  30982. var s = new Uint8Array(256);
  30983. var i, j = 0, tmp, keyLength = key.length;
  30984. for (i = 0; i < 256; ++i) {
  30985. s[i] = i;
  30986. }
  30987. for (i = 0; i < 256; ++i) {
  30988. tmp = s[i];
  30989. j = j + tmp + key[i % keyLength] & 0xFF;
  30990. s[i] = s[j];
  30991. s[j] = tmp;
  30992. }
  30993. this.s = s;
  30994. }
  30995. ARCFourCipher.prototype = {
  30996. encryptBlock: function ARCFourCipher_encryptBlock(data) {
  30997. var i, n = data.length, tmp, tmp2;
  30998. var a = this.a, b = this.b, s = this.s;
  30999. var output = new Uint8Array(n);
  31000. for (i = 0; i < n; ++i) {
  31001. a = a + 1 & 0xFF;
  31002. tmp = s[a];
  31003. b = b + tmp & 0xFF;
  31004. tmp2 = s[b];
  31005. s[a] = tmp2;
  31006. s[b] = tmp;
  31007. output[i] = data[i] ^ s[tmp + tmp2 & 0xFF];
  31008. }
  31009. this.a = a;
  31010. this.b = b;
  31011. return output;
  31012. }
  31013. };
  31014. ARCFourCipher.prototype.decryptBlock = ARCFourCipher.prototype.encryptBlock;
  31015. return ARCFourCipher;
  31016. }();
  31017. var calculateMD5 = function calculateMD5Closure() {
  31018. var r = new Uint8Array([
  31019. 7,
  31020. 12,
  31021. 17,
  31022. 22,
  31023. 7,
  31024. 12,
  31025. 17,
  31026. 22,
  31027. 7,
  31028. 12,
  31029. 17,
  31030. 22,
  31031. 7,
  31032. 12,
  31033. 17,
  31034. 22,
  31035. 5,
  31036. 9,
  31037. 14,
  31038. 20,
  31039. 5,
  31040. 9,
  31041. 14,
  31042. 20,
  31043. 5,
  31044. 9,
  31045. 14,
  31046. 20,
  31047. 5,
  31048. 9,
  31049. 14,
  31050. 20,
  31051. 4,
  31052. 11,
  31053. 16,
  31054. 23,
  31055. 4,
  31056. 11,
  31057. 16,
  31058. 23,
  31059. 4,
  31060. 11,
  31061. 16,
  31062. 23,
  31063. 4,
  31064. 11,
  31065. 16,
  31066. 23,
  31067. 6,
  31068. 10,
  31069. 15,
  31070. 21,
  31071. 6,
  31072. 10,
  31073. 15,
  31074. 21,
  31075. 6,
  31076. 10,
  31077. 15,
  31078. 21,
  31079. 6,
  31080. 10,
  31081. 15,
  31082. 21
  31083. ]);
  31084. var k = new Int32Array([
  31085. -680876936,
  31086. -389564586,
  31087. 606105819,
  31088. -1044525330,
  31089. -176418897,
  31090. 1200080426,
  31091. -1473231341,
  31092. -45705983,
  31093. 1770035416,
  31094. -1958414417,
  31095. -42063,
  31096. -1990404162,
  31097. 1804603682,
  31098. -40341101,
  31099. -1502002290,
  31100. 1236535329,
  31101. -165796510,
  31102. -1069501632,
  31103. 643717713,
  31104. -373897302,
  31105. -701558691,
  31106. 38016083,
  31107. -660478335,
  31108. -405537848,
  31109. 568446438,
  31110. -1019803690,
  31111. -187363961,
  31112. 1163531501,
  31113. -1444681467,
  31114. -51403784,
  31115. 1735328473,
  31116. -1926607734,
  31117. -378558,
  31118. -2022574463,
  31119. 1839030562,
  31120. -35309556,
  31121. -1530992060,
  31122. 1272893353,
  31123. -155497632,
  31124. -1094730640,
  31125. 681279174,
  31126. -358537222,
  31127. -722521979,
  31128. 76029189,
  31129. -640364487,
  31130. -421815835,
  31131. 530742520,
  31132. -995338651,
  31133. -198630844,
  31134. 1126891415,
  31135. -1416354905,
  31136. -57434055,
  31137. 1700485571,
  31138. -1894986606,
  31139. -1051523,
  31140. -2054922799,
  31141. 1873313359,
  31142. -30611744,
  31143. -1560198380,
  31144. 1309151649,
  31145. -145523070,
  31146. -1120210379,
  31147. 718787259,
  31148. -343485551
  31149. ]);
  31150. function hash(data, offset, length) {
  31151. var h0 = 1732584193, h1 = -271733879, h2 = -1732584194, h3 = 271733878;
  31152. // pre-processing
  31153. var paddedLength = length + 72 & ~63;
  31154. // data + 9 extra bytes
  31155. var padded = new Uint8Array(paddedLength);
  31156. var i, j, n;
  31157. for (i = 0; i < length; ++i) {
  31158. padded[i] = data[offset++];
  31159. }
  31160. padded[i++] = 0x80;
  31161. n = paddedLength - 8;
  31162. while (i < n) {
  31163. padded[i++] = 0;
  31164. }
  31165. padded[i++] = length << 3 & 0xFF;
  31166. padded[i++] = length >> 5 & 0xFF;
  31167. padded[i++] = length >> 13 & 0xFF;
  31168. padded[i++] = length >> 21 & 0xFF;
  31169. padded[i++] = length >>> 29 & 0xFF;
  31170. padded[i++] = 0;
  31171. padded[i++] = 0;
  31172. padded[i++] = 0;
  31173. var w = new Int32Array(16);
  31174. for (i = 0; i < paddedLength;) {
  31175. for (j = 0; j < 16; ++j, i += 4) {
  31176. w[j] = padded[i] | padded[i + 1] << 8 | padded[i + 2] << 16 | padded[i + 3] << 24;
  31177. }
  31178. var a = h0, b = h1, c = h2, d = h3, f, g;
  31179. for (j = 0; j < 64; ++j) {
  31180. if (j < 16) {
  31181. f = b & c | ~b & d;
  31182. g = j;
  31183. } else if (j < 32) {
  31184. f = d & b | ~d & c;
  31185. g = 5 * j + 1 & 15;
  31186. } else if (j < 48) {
  31187. f = b ^ c ^ d;
  31188. g = 3 * j + 5 & 15;
  31189. } else {
  31190. f = c ^ (b | ~d);
  31191. g = 7 * j & 15;
  31192. }
  31193. var tmp = d, rotateArg = a + f + k[j] + w[g] | 0, rotate = r[j];
  31194. d = c;
  31195. c = b;
  31196. b = b + (rotateArg << rotate | rotateArg >>> 32 - rotate) | 0;
  31197. a = tmp;
  31198. }
  31199. h0 = h0 + a | 0;
  31200. h1 = h1 + b | 0;
  31201. h2 = h2 + c | 0;
  31202. h3 = h3 + d | 0;
  31203. }
  31204. return new Uint8Array([
  31205. h0 & 0xFF,
  31206. h0 >> 8 & 0xFF,
  31207. h0 >> 16 & 0xFF,
  31208. h0 >>> 24 & 0xFF,
  31209. h1 & 0xFF,
  31210. h1 >> 8 & 0xFF,
  31211. h1 >> 16 & 0xFF,
  31212. h1 >>> 24 & 0xFF,
  31213. h2 & 0xFF,
  31214. h2 >> 8 & 0xFF,
  31215. h2 >> 16 & 0xFF,
  31216. h2 >>> 24 & 0xFF,
  31217. h3 & 0xFF,
  31218. h3 >> 8 & 0xFF,
  31219. h3 >> 16 & 0xFF,
  31220. h3 >>> 24 & 0xFF
  31221. ]);
  31222. }
  31223. return hash;
  31224. }();
  31225. var Word64 = function Word64Closure() {
  31226. function Word64(highInteger, lowInteger) {
  31227. this.high = highInteger | 0;
  31228. this.low = lowInteger | 0;
  31229. }
  31230. Word64.prototype = {
  31231. and: function Word64_and(word) {
  31232. this.high &= word.high;
  31233. this.low &= word.low;
  31234. },
  31235. xor: function Word64_xor(word) {
  31236. this.high ^= word.high;
  31237. this.low ^= word.low;
  31238. },
  31239. or: function Word64_or(word) {
  31240. this.high |= word.high;
  31241. this.low |= word.low;
  31242. },
  31243. shiftRight: function Word64_shiftRight(places) {
  31244. if (places >= 32) {
  31245. this.low = this.high >>> places - 32 | 0;
  31246. this.high = 0;
  31247. } else {
  31248. this.low = this.low >>> places | this.high << 32 - places;
  31249. this.high = this.high >>> places | 0;
  31250. }
  31251. },
  31252. shiftLeft: function Word64_shiftLeft(places) {
  31253. if (places >= 32) {
  31254. this.high = this.low << places - 32;
  31255. this.low = 0;
  31256. } else {
  31257. this.high = this.high << places | this.low >>> 32 - places;
  31258. this.low = this.low << places;
  31259. }
  31260. },
  31261. rotateRight: function Word64_rotateRight(places) {
  31262. var low, high;
  31263. if (places & 32) {
  31264. high = this.low;
  31265. low = this.high;
  31266. } else {
  31267. low = this.low;
  31268. high = this.high;
  31269. }
  31270. places &= 31;
  31271. this.low = low >>> places | high << 32 - places;
  31272. this.high = high >>> places | low << 32 - places;
  31273. },
  31274. not: function Word64_not() {
  31275. this.high = ~this.high;
  31276. this.low = ~this.low;
  31277. },
  31278. add: function Word64_add(word) {
  31279. var lowAdd = (this.low >>> 0) + (word.low >>> 0);
  31280. var highAdd = (this.high >>> 0) + (word.high >>> 0);
  31281. if (lowAdd > 0xFFFFFFFF) {
  31282. highAdd += 1;
  31283. }
  31284. this.low = lowAdd | 0;
  31285. this.high = highAdd | 0;
  31286. },
  31287. copyTo: function Word64_copyTo(bytes, offset) {
  31288. bytes[offset] = this.high >>> 24 & 0xFF;
  31289. bytes[offset + 1] = this.high >> 16 & 0xFF;
  31290. bytes[offset + 2] = this.high >> 8 & 0xFF;
  31291. bytes[offset + 3] = this.high & 0xFF;
  31292. bytes[offset + 4] = this.low >>> 24 & 0xFF;
  31293. bytes[offset + 5] = this.low >> 16 & 0xFF;
  31294. bytes[offset + 6] = this.low >> 8 & 0xFF;
  31295. bytes[offset + 7] = this.low & 0xFF;
  31296. },
  31297. assign: function Word64_assign(word) {
  31298. this.high = word.high;
  31299. this.low = word.low;
  31300. }
  31301. };
  31302. return Word64;
  31303. }();
  31304. var calculateSHA256 = function calculateSHA256Closure() {
  31305. function rotr(x, n) {
  31306. return x >>> n | x << 32 - n;
  31307. }
  31308. function ch(x, y, z) {
  31309. return x & y ^ ~x & z;
  31310. }
  31311. function maj(x, y, z) {
  31312. return x & y ^ x & z ^ y & z;
  31313. }
  31314. function sigma(x) {
  31315. return rotr(x, 2) ^ rotr(x, 13) ^ rotr(x, 22);
  31316. }
  31317. function sigmaPrime(x) {
  31318. return rotr(x, 6) ^ rotr(x, 11) ^ rotr(x, 25);
  31319. }
  31320. function littleSigma(x) {
  31321. return rotr(x, 7) ^ rotr(x, 18) ^ x >>> 3;
  31322. }
  31323. function littleSigmaPrime(x) {
  31324. return rotr(x, 17) ^ rotr(x, 19) ^ x >>> 10;
  31325. }
  31326. var k = [
  31327. 0x428a2f98,
  31328. 0x71374491,
  31329. 0xb5c0fbcf,
  31330. 0xe9b5dba5,
  31331. 0x3956c25b,
  31332. 0x59f111f1,
  31333. 0x923f82a4,
  31334. 0xab1c5ed5,
  31335. 0xd807aa98,
  31336. 0x12835b01,
  31337. 0x243185be,
  31338. 0x550c7dc3,
  31339. 0x72be5d74,
  31340. 0x80deb1fe,
  31341. 0x9bdc06a7,
  31342. 0xc19bf174,
  31343. 0xe49b69c1,
  31344. 0xefbe4786,
  31345. 0x0fc19dc6,
  31346. 0x240ca1cc,
  31347. 0x2de92c6f,
  31348. 0x4a7484aa,
  31349. 0x5cb0a9dc,
  31350. 0x76f988da,
  31351. 0x983e5152,
  31352. 0xa831c66d,
  31353. 0xb00327c8,
  31354. 0xbf597fc7,
  31355. 0xc6e00bf3,
  31356. 0xd5a79147,
  31357. 0x06ca6351,
  31358. 0x14292967,
  31359. 0x27b70a85,
  31360. 0x2e1b2138,
  31361. 0x4d2c6dfc,
  31362. 0x53380d13,
  31363. 0x650a7354,
  31364. 0x766a0abb,
  31365. 0x81c2c92e,
  31366. 0x92722c85,
  31367. 0xa2bfe8a1,
  31368. 0xa81a664b,
  31369. 0xc24b8b70,
  31370. 0xc76c51a3,
  31371. 0xd192e819,
  31372. 0xd6990624,
  31373. 0xf40e3585,
  31374. 0x106aa070,
  31375. 0x19a4c116,
  31376. 0x1e376c08,
  31377. 0x2748774c,
  31378. 0x34b0bcb5,
  31379. 0x391c0cb3,
  31380. 0x4ed8aa4a,
  31381. 0x5b9cca4f,
  31382. 0x682e6ff3,
  31383. 0x748f82ee,
  31384. 0x78a5636f,
  31385. 0x84c87814,
  31386. 0x8cc70208,
  31387. 0x90befffa,
  31388. 0xa4506ceb,
  31389. 0xbef9a3f7,
  31390. 0xc67178f2
  31391. ];
  31392. function hash(data, offset, length) {
  31393. // initial hash values
  31394. var h0 = 0x6a09e667, h1 = 0xbb67ae85, h2 = 0x3c6ef372, h3 = 0xa54ff53a, h4 = 0x510e527f, h5 = 0x9b05688c, h6 = 0x1f83d9ab, h7 = 0x5be0cd19;
  31395. // pre-processing
  31396. var paddedLength = Math.ceil((length + 9) / 64) * 64;
  31397. var padded = new Uint8Array(paddedLength);
  31398. var i, j, n;
  31399. for (i = 0; i < length; ++i) {
  31400. padded[i] = data[offset++];
  31401. }
  31402. padded[i++] = 0x80;
  31403. n = paddedLength - 8;
  31404. while (i < n) {
  31405. padded[i++] = 0;
  31406. }
  31407. padded[i++] = 0;
  31408. padded[i++] = 0;
  31409. padded[i++] = 0;
  31410. padded[i++] = length >>> 29 & 0xFF;
  31411. padded[i++] = length >> 21 & 0xFF;
  31412. padded[i++] = length >> 13 & 0xFF;
  31413. padded[i++] = length >> 5 & 0xFF;
  31414. padded[i++] = length << 3 & 0xFF;
  31415. var w = new Uint32Array(64);
  31416. // for each 512 bit block
  31417. for (i = 0; i < paddedLength;) {
  31418. for (j = 0; j < 16; ++j) {
  31419. w[j] = padded[i] << 24 | padded[i + 1] << 16 | padded[i + 2] << 8 | padded[i + 3];
  31420. i += 4;
  31421. }
  31422. for (j = 16; j < 64; ++j) {
  31423. w[j] = littleSigmaPrime(w[j - 2]) + w[j - 7] + littleSigma(w[j - 15]) + w[j - 16] | 0;
  31424. }
  31425. var a = h0, b = h1, c = h2, d = h3, e = h4, f = h5, g = h6, h = h7, t1, t2;
  31426. for (j = 0; j < 64; ++j) {
  31427. t1 = h + sigmaPrime(e) + ch(e, f, g) + k[j] + w[j];
  31428. t2 = sigma(a) + maj(a, b, c);
  31429. h = g;
  31430. g = f;
  31431. f = e;
  31432. e = d + t1 | 0;
  31433. d = c;
  31434. c = b;
  31435. b = a;
  31436. a = t1 + t2 | 0;
  31437. }
  31438. h0 = h0 + a | 0;
  31439. h1 = h1 + b | 0;
  31440. h2 = h2 + c | 0;
  31441. h3 = h3 + d | 0;
  31442. h4 = h4 + e | 0;
  31443. h5 = h5 + f | 0;
  31444. h6 = h6 + g | 0;
  31445. h7 = h7 + h | 0;
  31446. }
  31447. return new Uint8Array([
  31448. h0 >> 24 & 0xFF,
  31449. h0 >> 16 & 0xFF,
  31450. h0 >> 8 & 0xFF,
  31451. h0 & 0xFF,
  31452. h1 >> 24 & 0xFF,
  31453. h1 >> 16 & 0xFF,
  31454. h1 >> 8 & 0xFF,
  31455. h1 & 0xFF,
  31456. h2 >> 24 & 0xFF,
  31457. h2 >> 16 & 0xFF,
  31458. h2 >> 8 & 0xFF,
  31459. h2 & 0xFF,
  31460. h3 >> 24 & 0xFF,
  31461. h3 >> 16 & 0xFF,
  31462. h3 >> 8 & 0xFF,
  31463. h3 & 0xFF,
  31464. h4 >> 24 & 0xFF,
  31465. h4 >> 16 & 0xFF,
  31466. h4 >> 8 & 0xFF,
  31467. h4 & 0xFF,
  31468. h5 >> 24 & 0xFF,
  31469. h5 >> 16 & 0xFF,
  31470. h5 >> 8 & 0xFF,
  31471. h5 & 0xFF,
  31472. h6 >> 24 & 0xFF,
  31473. h6 >> 16 & 0xFF,
  31474. h6 >> 8 & 0xFF,
  31475. h6 & 0xFF,
  31476. h7 >> 24 & 0xFF,
  31477. h7 >> 16 & 0xFF,
  31478. h7 >> 8 & 0xFF,
  31479. h7 & 0xFF
  31480. ]);
  31481. }
  31482. return hash;
  31483. }();
  31484. var calculateSHA512 = function calculateSHA512Closure() {
  31485. function ch(result, x, y, z, tmp) {
  31486. result.assign(x);
  31487. result.and(y);
  31488. tmp.assign(x);
  31489. tmp.not();
  31490. tmp.and(z);
  31491. result.xor(tmp);
  31492. }
  31493. function maj(result, x, y, z, tmp) {
  31494. result.assign(x);
  31495. result.and(y);
  31496. tmp.assign(x);
  31497. tmp.and(z);
  31498. result.xor(tmp);
  31499. tmp.assign(y);
  31500. tmp.and(z);
  31501. result.xor(tmp);
  31502. }
  31503. function sigma(result, x, tmp) {
  31504. result.assign(x);
  31505. result.rotateRight(28);
  31506. tmp.assign(x);
  31507. tmp.rotateRight(34);
  31508. result.xor(tmp);
  31509. tmp.assign(x);
  31510. tmp.rotateRight(39);
  31511. result.xor(tmp);
  31512. }
  31513. function sigmaPrime(result, x, tmp) {
  31514. result.assign(x);
  31515. result.rotateRight(14);
  31516. tmp.assign(x);
  31517. tmp.rotateRight(18);
  31518. result.xor(tmp);
  31519. tmp.assign(x);
  31520. tmp.rotateRight(41);
  31521. result.xor(tmp);
  31522. }
  31523. function littleSigma(result, x, tmp) {
  31524. result.assign(x);
  31525. result.rotateRight(1);
  31526. tmp.assign(x);
  31527. tmp.rotateRight(8);
  31528. result.xor(tmp);
  31529. tmp.assign(x);
  31530. tmp.shiftRight(7);
  31531. result.xor(tmp);
  31532. }
  31533. function littleSigmaPrime(result, x, tmp) {
  31534. result.assign(x);
  31535. result.rotateRight(19);
  31536. tmp.assign(x);
  31537. tmp.rotateRight(61);
  31538. result.xor(tmp);
  31539. tmp.assign(x);
  31540. tmp.shiftRight(6);
  31541. result.xor(tmp);
  31542. }
  31543. var k = [
  31544. new Word64(0x428a2f98, 0xd728ae22),
  31545. new Word64(0x71374491, 0x23ef65cd),
  31546. new Word64(0xb5c0fbcf, 0xec4d3b2f),
  31547. new Word64(0xe9b5dba5, 0x8189dbbc),
  31548. new Word64(0x3956c25b, 0xf348b538),
  31549. new Word64(0x59f111f1, 0xb605d019),
  31550. new Word64(0x923f82a4, 0xaf194f9b),
  31551. new Word64(0xab1c5ed5, 0xda6d8118),
  31552. new Word64(0xd807aa98, 0xa3030242),
  31553. new Word64(0x12835b01, 0x45706fbe),
  31554. new Word64(0x243185be, 0x4ee4b28c),
  31555. new Word64(0x550c7dc3, 0xd5ffb4e2),
  31556. new Word64(0x72be5d74, 0xf27b896f),
  31557. new Word64(0x80deb1fe, 0x3b1696b1),
  31558. new Word64(0x9bdc06a7, 0x25c71235),
  31559. new Word64(0xc19bf174, 0xcf692694),
  31560. new Word64(0xe49b69c1, 0x9ef14ad2),
  31561. new Word64(0xefbe4786, 0x384f25e3),
  31562. new Word64(0x0fc19dc6, 0x8b8cd5b5),
  31563. new Word64(0x240ca1cc, 0x77ac9c65),
  31564. new Word64(0x2de92c6f, 0x592b0275),
  31565. new Word64(0x4a7484aa, 0x6ea6e483),
  31566. new Word64(0x5cb0a9dc, 0xbd41fbd4),
  31567. new Word64(0x76f988da, 0x831153b5),
  31568. new Word64(0x983e5152, 0xee66dfab),
  31569. new Word64(0xa831c66d, 0x2db43210),
  31570. new Word64(0xb00327c8, 0x98fb213f),
  31571. new Word64(0xbf597fc7, 0xbeef0ee4),
  31572. new Word64(0xc6e00bf3, 0x3da88fc2),
  31573. new Word64(0xd5a79147, 0x930aa725),
  31574. new Word64(0x06ca6351, 0xe003826f),
  31575. new Word64(0x14292967, 0x0a0e6e70),
  31576. new Word64(0x27b70a85, 0x46d22ffc),
  31577. new Word64(0x2e1b2138, 0x5c26c926),
  31578. new Word64(0x4d2c6dfc, 0x5ac42aed),
  31579. new Word64(0x53380d13, 0x9d95b3df),
  31580. new Word64(0x650a7354, 0x8baf63de),
  31581. new Word64(0x766a0abb, 0x3c77b2a8),
  31582. new Word64(0x81c2c92e, 0x47edaee6),
  31583. new Word64(0x92722c85, 0x1482353b),
  31584. new Word64(0xa2bfe8a1, 0x4cf10364),
  31585. new Word64(0xa81a664b, 0xbc423001),
  31586. new Word64(0xc24b8b70, 0xd0f89791),
  31587. new Word64(0xc76c51a3, 0x0654be30),
  31588. new Word64(0xd192e819, 0xd6ef5218),
  31589. new Word64(0xd6990624, 0x5565a910),
  31590. new Word64(0xf40e3585, 0x5771202a),
  31591. new Word64(0x106aa070, 0x32bbd1b8),
  31592. new Word64(0x19a4c116, 0xb8d2d0c8),
  31593. new Word64(0x1e376c08, 0x5141ab53),
  31594. new Word64(0x2748774c, 0xdf8eeb99),
  31595. new Word64(0x34b0bcb5, 0xe19b48a8),
  31596. new Word64(0x391c0cb3, 0xc5c95a63),
  31597. new Word64(0x4ed8aa4a, 0xe3418acb),
  31598. new Word64(0x5b9cca4f, 0x7763e373),
  31599. new Word64(0x682e6ff3, 0xd6b2b8a3),
  31600. new Word64(0x748f82ee, 0x5defb2fc),
  31601. new Word64(0x78a5636f, 0x43172f60),
  31602. new Word64(0x84c87814, 0xa1f0ab72),
  31603. new Word64(0x8cc70208, 0x1a6439ec),
  31604. new Word64(0x90befffa, 0x23631e28),
  31605. new Word64(0xa4506ceb, 0xde82bde9),
  31606. new Word64(0xbef9a3f7, 0xb2c67915),
  31607. new Word64(0xc67178f2, 0xe372532b),
  31608. new Word64(0xca273ece, 0xea26619c),
  31609. new Word64(0xd186b8c7, 0x21c0c207),
  31610. new Word64(0xeada7dd6, 0xcde0eb1e),
  31611. new Word64(0xf57d4f7f, 0xee6ed178),
  31612. new Word64(0x06f067aa, 0x72176fba),
  31613. new Word64(0x0a637dc5, 0xa2c898a6),
  31614. new Word64(0x113f9804, 0xbef90dae),
  31615. new Word64(0x1b710b35, 0x131c471b),
  31616. new Word64(0x28db77f5, 0x23047d84),
  31617. new Word64(0x32caab7b, 0x40c72493),
  31618. new Word64(0x3c9ebe0a, 0x15c9bebc),
  31619. new Word64(0x431d67c4, 0x9c100d4c),
  31620. new Word64(0x4cc5d4be, 0xcb3e42b6),
  31621. new Word64(0x597f299c, 0xfc657e2a),
  31622. new Word64(0x5fcb6fab, 0x3ad6faec),
  31623. new Word64(0x6c44198c, 0x4a475817)
  31624. ];
  31625. function hash(data, offset, length, mode384) {
  31626. mode384 = !!mode384;
  31627. // initial hash values
  31628. var h0, h1, h2, h3, h4, h5, h6, h7;
  31629. if (!mode384) {
  31630. h0 = new Word64(0x6a09e667, 0xf3bcc908);
  31631. h1 = new Word64(0xbb67ae85, 0x84caa73b);
  31632. h2 = new Word64(0x3c6ef372, 0xfe94f82b);
  31633. h3 = new Word64(0xa54ff53a, 0x5f1d36f1);
  31634. h4 = new Word64(0x510e527f, 0xade682d1);
  31635. h5 = new Word64(0x9b05688c, 0x2b3e6c1f);
  31636. h6 = new Word64(0x1f83d9ab, 0xfb41bd6b);
  31637. h7 = new Word64(0x5be0cd19, 0x137e2179);
  31638. } else {
  31639. // SHA384 is exactly the same
  31640. // except with different starting values and a trimmed result
  31641. h0 = new Word64(0xcbbb9d5d, 0xc1059ed8);
  31642. h1 = new Word64(0x629a292a, 0x367cd507);
  31643. h2 = new Word64(0x9159015a, 0x3070dd17);
  31644. h3 = new Word64(0x152fecd8, 0xf70e5939);
  31645. h4 = new Word64(0x67332667, 0xffc00b31);
  31646. h5 = new Word64(0x8eb44a87, 0x68581511);
  31647. h6 = new Word64(0xdb0c2e0d, 0x64f98fa7);
  31648. h7 = new Word64(0x47b5481d, 0xbefa4fa4);
  31649. }
  31650. // pre-processing
  31651. var paddedLength = Math.ceil((length + 17) / 128) * 128;
  31652. var padded = new Uint8Array(paddedLength);
  31653. var i, j, n;
  31654. for (i = 0; i < length; ++i) {
  31655. padded[i] = data[offset++];
  31656. }
  31657. padded[i++] = 0x80;
  31658. n = paddedLength - 16;
  31659. while (i < n) {
  31660. padded[i++] = 0;
  31661. }
  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++] = 0;
  31671. padded[i++] = 0;
  31672. padded[i++] = 0;
  31673. padded[i++] = length >>> 29 & 0xFF;
  31674. padded[i++] = length >> 21 & 0xFF;
  31675. padded[i++] = length >> 13 & 0xFF;
  31676. padded[i++] = length >> 5 & 0xFF;
  31677. padded[i++] = length << 3 & 0xFF;
  31678. var w = new Array(80);
  31679. for (i = 0; i < 80; i++) {
  31680. w[i] = new Word64(0, 0);
  31681. }
  31682. var a = new Word64(0, 0), b = new Word64(0, 0), c = new Word64(0, 0);
  31683. var d = new Word64(0, 0), e = new Word64(0, 0), f = new Word64(0, 0);
  31684. var g = new Word64(0, 0), h = new Word64(0, 0);
  31685. var t1 = new Word64(0, 0), t2 = new Word64(0, 0);
  31686. var tmp1 = new Word64(0, 0), tmp2 = new Word64(0, 0), tmp3;
  31687. // for each 1024 bit block
  31688. for (i = 0; i < paddedLength;) {
  31689. for (j = 0; j < 16; ++j) {
  31690. w[j].high = padded[i] << 24 | padded[i + 1] << 16 | padded[i + 2] << 8 | padded[i + 3];
  31691. w[j].low = padded[i + 4] << 24 | padded[i + 5] << 16 | padded[i + 6] << 8 | padded[i + 7];
  31692. i += 8;
  31693. }
  31694. for (j = 16; j < 80; ++j) {
  31695. tmp3 = w[j];
  31696. littleSigmaPrime(tmp3, w[j - 2], tmp2);
  31697. tmp3.add(w[j - 7]);
  31698. littleSigma(tmp1, w[j - 15], tmp2);
  31699. tmp3.add(tmp1);
  31700. tmp3.add(w[j - 16]);
  31701. }
  31702. a.assign(h0);
  31703. b.assign(h1);
  31704. c.assign(h2);
  31705. d.assign(h3);
  31706. e.assign(h4);
  31707. f.assign(h5);
  31708. g.assign(h6);
  31709. h.assign(h7);
  31710. for (j = 0; j < 80; ++j) {
  31711. t1.assign(h);
  31712. sigmaPrime(tmp1, e, tmp2);
  31713. t1.add(tmp1);
  31714. ch(tmp1, e, f, g, tmp2);
  31715. t1.add(tmp1);
  31716. t1.add(k[j]);
  31717. t1.add(w[j]);
  31718. sigma(t2, a, tmp2);
  31719. maj(tmp1, a, b, c, tmp2);
  31720. t2.add(tmp1);
  31721. tmp3 = h;
  31722. h = g;
  31723. g = f;
  31724. f = e;
  31725. d.add(t1);
  31726. e = d;
  31727. d = c;
  31728. c = b;
  31729. b = a;
  31730. tmp3.assign(t1);
  31731. tmp3.add(t2);
  31732. a = tmp3;
  31733. }
  31734. h0.add(a);
  31735. h1.add(b);
  31736. h2.add(c);
  31737. h3.add(d);
  31738. h4.add(e);
  31739. h5.add(f);
  31740. h6.add(g);
  31741. h7.add(h);
  31742. }
  31743. var result;
  31744. if (!mode384) {
  31745. result = new Uint8Array(64);
  31746. h0.copyTo(result, 0);
  31747. h1.copyTo(result, 8);
  31748. h2.copyTo(result, 16);
  31749. h3.copyTo(result, 24);
  31750. h4.copyTo(result, 32);
  31751. h5.copyTo(result, 40);
  31752. h6.copyTo(result, 48);
  31753. h7.copyTo(result, 56);
  31754. } else {
  31755. result = new Uint8Array(48);
  31756. h0.copyTo(result, 0);
  31757. h1.copyTo(result, 8);
  31758. h2.copyTo(result, 16);
  31759. h3.copyTo(result, 24);
  31760. h4.copyTo(result, 32);
  31761. h5.copyTo(result, 40);
  31762. }
  31763. return result;
  31764. }
  31765. return hash;
  31766. }();
  31767. var calculateSHA384 = function calculateSHA384Closure() {
  31768. function hash(data, offset, length) {
  31769. return calculateSHA512(data, offset, length, true);
  31770. }
  31771. return hash;
  31772. }();
  31773. var NullCipher = function NullCipherClosure() {
  31774. function NullCipher() {
  31775. }
  31776. NullCipher.prototype = {
  31777. decryptBlock: function NullCipher_decryptBlock(data) {
  31778. return data;
  31779. }
  31780. };
  31781. return NullCipher;
  31782. }();
  31783. var AES128Cipher = function AES128CipherClosure() {
  31784. var rcon = new Uint8Array([
  31785. 0x8d,
  31786. 0x01,
  31787. 0x02,
  31788. 0x04,
  31789. 0x08,
  31790. 0x10,
  31791. 0x20,
  31792. 0x40,
  31793. 0x80,
  31794. 0x1b,
  31795. 0x36,
  31796. 0x6c,
  31797. 0xd8,
  31798. 0xab,
  31799. 0x4d,
  31800. 0x9a,
  31801. 0x2f,
  31802. 0x5e,
  31803. 0xbc,
  31804. 0x63,
  31805. 0xc6,
  31806. 0x97,
  31807. 0x35,
  31808. 0x6a,
  31809. 0xd4,
  31810. 0xb3,
  31811. 0x7d,
  31812. 0xfa,
  31813. 0xef,
  31814. 0xc5,
  31815. 0x91,
  31816. 0x39,
  31817. 0x72,
  31818. 0xe4,
  31819. 0xd3,
  31820. 0xbd,
  31821. 0x61,
  31822. 0xc2,
  31823. 0x9f,
  31824. 0x25,
  31825. 0x4a,
  31826. 0x94,
  31827. 0x33,
  31828. 0x66,
  31829. 0xcc,
  31830. 0x83,
  31831. 0x1d,
  31832. 0x3a,
  31833. 0x74,
  31834. 0xe8,
  31835. 0xcb,
  31836. 0x8d,
  31837. 0x01,
  31838. 0x02,
  31839. 0x04,
  31840. 0x08,
  31841. 0x10,
  31842. 0x20,
  31843. 0x40,
  31844. 0x80,
  31845. 0x1b,
  31846. 0x36,
  31847. 0x6c,
  31848. 0xd8,
  31849. 0xab,
  31850. 0x4d,
  31851. 0x9a,
  31852. 0x2f,
  31853. 0x5e,
  31854. 0xbc,
  31855. 0x63,
  31856. 0xc6,
  31857. 0x97,
  31858. 0x35,
  31859. 0x6a,
  31860. 0xd4,
  31861. 0xb3,
  31862. 0x7d,
  31863. 0xfa,
  31864. 0xef,
  31865. 0xc5,
  31866. 0x91,
  31867. 0x39,
  31868. 0x72,
  31869. 0xe4,
  31870. 0xd3,
  31871. 0xbd,
  31872. 0x61,
  31873. 0xc2,
  31874. 0x9f,
  31875. 0x25,
  31876. 0x4a,
  31877. 0x94,
  31878. 0x33,
  31879. 0x66,
  31880. 0xcc,
  31881. 0x83,
  31882. 0x1d,
  31883. 0x3a,
  31884. 0x74,
  31885. 0xe8,
  31886. 0xcb,
  31887. 0x8d,
  31888. 0x01,
  31889. 0x02,
  31890. 0x04,
  31891. 0x08,
  31892. 0x10,
  31893. 0x20,
  31894. 0x40,
  31895. 0x80,
  31896. 0x1b,
  31897. 0x36,
  31898. 0x6c,
  31899. 0xd8,
  31900. 0xab,
  31901. 0x4d,
  31902. 0x9a,
  31903. 0x2f,
  31904. 0x5e,
  31905. 0xbc,
  31906. 0x63,
  31907. 0xc6,
  31908. 0x97,
  31909. 0x35,
  31910. 0x6a,
  31911. 0xd4,
  31912. 0xb3,
  31913. 0x7d,
  31914. 0xfa,
  31915. 0xef,
  31916. 0xc5,
  31917. 0x91,
  31918. 0x39,
  31919. 0x72,
  31920. 0xe4,
  31921. 0xd3,
  31922. 0xbd,
  31923. 0x61,
  31924. 0xc2,
  31925. 0x9f,
  31926. 0x25,
  31927. 0x4a,
  31928. 0x94,
  31929. 0x33,
  31930. 0x66,
  31931. 0xcc,
  31932. 0x83,
  31933. 0x1d,
  31934. 0x3a,
  31935. 0x74,
  31936. 0xe8,
  31937. 0xcb,
  31938. 0x8d,
  31939. 0x01,
  31940. 0x02,
  31941. 0x04,
  31942. 0x08,
  31943. 0x10,
  31944. 0x20,
  31945. 0x40,
  31946. 0x80,
  31947. 0x1b,
  31948. 0x36,
  31949. 0x6c,
  31950. 0xd8,
  31951. 0xab,
  31952. 0x4d,
  31953. 0x9a,
  31954. 0x2f,
  31955. 0x5e,
  31956. 0xbc,
  31957. 0x63,
  31958. 0xc6,
  31959. 0x97,
  31960. 0x35,
  31961. 0x6a,
  31962. 0xd4,
  31963. 0xb3,
  31964. 0x7d,
  31965. 0xfa,
  31966. 0xef,
  31967. 0xc5,
  31968. 0x91,
  31969. 0x39,
  31970. 0x72,
  31971. 0xe4,
  31972. 0xd3,
  31973. 0xbd,
  31974. 0x61,
  31975. 0xc2,
  31976. 0x9f,
  31977. 0x25,
  31978. 0x4a,
  31979. 0x94,
  31980. 0x33,
  31981. 0x66,
  31982. 0xcc,
  31983. 0x83,
  31984. 0x1d,
  31985. 0x3a,
  31986. 0x74,
  31987. 0xe8,
  31988. 0xcb,
  31989. 0x8d,
  31990. 0x01,
  31991. 0x02,
  31992. 0x04,
  31993. 0x08,
  31994. 0x10,
  31995. 0x20,
  31996. 0x40,
  31997. 0x80,
  31998. 0x1b,
  31999. 0x36,
  32000. 0x6c,
  32001. 0xd8,
  32002. 0xab,
  32003. 0x4d,
  32004. 0x9a,
  32005. 0x2f,
  32006. 0x5e,
  32007. 0xbc,
  32008. 0x63,
  32009. 0xc6,
  32010. 0x97,
  32011. 0x35,
  32012. 0x6a,
  32013. 0xd4,
  32014. 0xb3,
  32015. 0x7d,
  32016. 0xfa,
  32017. 0xef,
  32018. 0xc5,
  32019. 0x91,
  32020. 0x39,
  32021. 0x72,
  32022. 0xe4,
  32023. 0xd3,
  32024. 0xbd,
  32025. 0x61,
  32026. 0xc2,
  32027. 0x9f,
  32028. 0x25,
  32029. 0x4a,
  32030. 0x94,
  32031. 0x33,
  32032. 0x66,
  32033. 0xcc,
  32034. 0x83,
  32035. 0x1d,
  32036. 0x3a,
  32037. 0x74,
  32038. 0xe8,
  32039. 0xcb,
  32040. 0x8d
  32041. ]);
  32042. var s = new Uint8Array([
  32043. 0x63,
  32044. 0x7c,
  32045. 0x77,
  32046. 0x7b,
  32047. 0xf2,
  32048. 0x6b,
  32049. 0x6f,
  32050. 0xc5,
  32051. 0x30,
  32052. 0x01,
  32053. 0x67,
  32054. 0x2b,
  32055. 0xfe,
  32056. 0xd7,
  32057. 0xab,
  32058. 0x76,
  32059. 0xca,
  32060. 0x82,
  32061. 0xc9,
  32062. 0x7d,
  32063. 0xfa,
  32064. 0x59,
  32065. 0x47,
  32066. 0xf0,
  32067. 0xad,
  32068. 0xd4,
  32069. 0xa2,
  32070. 0xaf,
  32071. 0x9c,
  32072. 0xa4,
  32073. 0x72,
  32074. 0xc0,
  32075. 0xb7,
  32076. 0xfd,
  32077. 0x93,
  32078. 0x26,
  32079. 0x36,
  32080. 0x3f,
  32081. 0xf7,
  32082. 0xcc,
  32083. 0x34,
  32084. 0xa5,
  32085. 0xe5,
  32086. 0xf1,
  32087. 0x71,
  32088. 0xd8,
  32089. 0x31,
  32090. 0x15,
  32091. 0x04,
  32092. 0xc7,
  32093. 0x23,
  32094. 0xc3,
  32095. 0x18,
  32096. 0x96,
  32097. 0x05,
  32098. 0x9a,
  32099. 0x07,
  32100. 0x12,
  32101. 0x80,
  32102. 0xe2,
  32103. 0xeb,
  32104. 0x27,
  32105. 0xb2,
  32106. 0x75,
  32107. 0x09,
  32108. 0x83,
  32109. 0x2c,
  32110. 0x1a,
  32111. 0x1b,
  32112. 0x6e,
  32113. 0x5a,
  32114. 0xa0,
  32115. 0x52,
  32116. 0x3b,
  32117. 0xd6,
  32118. 0xb3,
  32119. 0x29,
  32120. 0xe3,
  32121. 0x2f,
  32122. 0x84,
  32123. 0x53,
  32124. 0xd1,
  32125. 0x00,
  32126. 0xed,
  32127. 0x20,
  32128. 0xfc,
  32129. 0xb1,
  32130. 0x5b,
  32131. 0x6a,
  32132. 0xcb,
  32133. 0xbe,
  32134. 0x39,
  32135. 0x4a,
  32136. 0x4c,
  32137. 0x58,
  32138. 0xcf,
  32139. 0xd0,
  32140. 0xef,
  32141. 0xaa,
  32142. 0xfb,
  32143. 0x43,
  32144. 0x4d,
  32145. 0x33,
  32146. 0x85,
  32147. 0x45,
  32148. 0xf9,
  32149. 0x02,
  32150. 0x7f,
  32151. 0x50,
  32152. 0x3c,
  32153. 0x9f,
  32154. 0xa8,
  32155. 0x51,
  32156. 0xa3,
  32157. 0x40,
  32158. 0x8f,
  32159. 0x92,
  32160. 0x9d,
  32161. 0x38,
  32162. 0xf5,
  32163. 0xbc,
  32164. 0xb6,
  32165. 0xda,
  32166. 0x21,
  32167. 0x10,
  32168. 0xff,
  32169. 0xf3,
  32170. 0xd2,
  32171. 0xcd,
  32172. 0x0c,
  32173. 0x13,
  32174. 0xec,
  32175. 0x5f,
  32176. 0x97,
  32177. 0x44,
  32178. 0x17,
  32179. 0xc4,
  32180. 0xa7,
  32181. 0x7e,
  32182. 0x3d,
  32183. 0x64,
  32184. 0x5d,
  32185. 0x19,
  32186. 0x73,
  32187. 0x60,
  32188. 0x81,
  32189. 0x4f,
  32190. 0xdc,
  32191. 0x22,
  32192. 0x2a,
  32193. 0x90,
  32194. 0x88,
  32195. 0x46,
  32196. 0xee,
  32197. 0xb8,
  32198. 0x14,
  32199. 0xde,
  32200. 0x5e,
  32201. 0x0b,
  32202. 0xdb,
  32203. 0xe0,
  32204. 0x32,
  32205. 0x3a,
  32206. 0x0a,
  32207. 0x49,
  32208. 0x06,
  32209. 0x24,
  32210. 0x5c,
  32211. 0xc2,
  32212. 0xd3,
  32213. 0xac,
  32214. 0x62,
  32215. 0x91,
  32216. 0x95,
  32217. 0xe4,
  32218. 0x79,
  32219. 0xe7,
  32220. 0xc8,
  32221. 0x37,
  32222. 0x6d,
  32223. 0x8d,
  32224. 0xd5,
  32225. 0x4e,
  32226. 0xa9,
  32227. 0x6c,
  32228. 0x56,
  32229. 0xf4,
  32230. 0xea,
  32231. 0x65,
  32232. 0x7a,
  32233. 0xae,
  32234. 0x08,
  32235. 0xba,
  32236. 0x78,
  32237. 0x25,
  32238. 0x2e,
  32239. 0x1c,
  32240. 0xa6,
  32241. 0xb4,
  32242. 0xc6,
  32243. 0xe8,
  32244. 0xdd,
  32245. 0x74,
  32246. 0x1f,
  32247. 0x4b,
  32248. 0xbd,
  32249. 0x8b,
  32250. 0x8a,
  32251. 0x70,
  32252. 0x3e,
  32253. 0xb5,
  32254. 0x66,
  32255. 0x48,
  32256. 0x03,
  32257. 0xf6,
  32258. 0x0e,
  32259. 0x61,
  32260. 0x35,
  32261. 0x57,
  32262. 0xb9,
  32263. 0x86,
  32264. 0xc1,
  32265. 0x1d,
  32266. 0x9e,
  32267. 0xe1,
  32268. 0xf8,
  32269. 0x98,
  32270. 0x11,
  32271. 0x69,
  32272. 0xd9,
  32273. 0x8e,
  32274. 0x94,
  32275. 0x9b,
  32276. 0x1e,
  32277. 0x87,
  32278. 0xe9,
  32279. 0xce,
  32280. 0x55,
  32281. 0x28,
  32282. 0xdf,
  32283. 0x8c,
  32284. 0xa1,
  32285. 0x89,
  32286. 0x0d,
  32287. 0xbf,
  32288. 0xe6,
  32289. 0x42,
  32290. 0x68,
  32291. 0x41,
  32292. 0x99,
  32293. 0x2d,
  32294. 0x0f,
  32295. 0xb0,
  32296. 0x54,
  32297. 0xbb,
  32298. 0x16
  32299. ]);
  32300. var inv_s = new Uint8Array([
  32301. 0x52,
  32302. 0x09,
  32303. 0x6a,
  32304. 0xd5,
  32305. 0x30,
  32306. 0x36,
  32307. 0xa5,
  32308. 0x38,
  32309. 0xbf,
  32310. 0x40,
  32311. 0xa3,
  32312. 0x9e,
  32313. 0x81,
  32314. 0xf3,
  32315. 0xd7,
  32316. 0xfb,
  32317. 0x7c,
  32318. 0xe3,
  32319. 0x39,
  32320. 0x82,
  32321. 0x9b,
  32322. 0x2f,
  32323. 0xff,
  32324. 0x87,
  32325. 0x34,
  32326. 0x8e,
  32327. 0x43,
  32328. 0x44,
  32329. 0xc4,
  32330. 0xde,
  32331. 0xe9,
  32332. 0xcb,
  32333. 0x54,
  32334. 0x7b,
  32335. 0x94,
  32336. 0x32,
  32337. 0xa6,
  32338. 0xc2,
  32339. 0x23,
  32340. 0x3d,
  32341. 0xee,
  32342. 0x4c,
  32343. 0x95,
  32344. 0x0b,
  32345. 0x42,
  32346. 0xfa,
  32347. 0xc3,
  32348. 0x4e,
  32349. 0x08,
  32350. 0x2e,
  32351. 0xa1,
  32352. 0x66,
  32353. 0x28,
  32354. 0xd9,
  32355. 0x24,
  32356. 0xb2,
  32357. 0x76,
  32358. 0x5b,
  32359. 0xa2,
  32360. 0x49,
  32361. 0x6d,
  32362. 0x8b,
  32363. 0xd1,
  32364. 0x25,
  32365. 0x72,
  32366. 0xf8,
  32367. 0xf6,
  32368. 0x64,
  32369. 0x86,
  32370. 0x68,
  32371. 0x98,
  32372. 0x16,
  32373. 0xd4,
  32374. 0xa4,
  32375. 0x5c,
  32376. 0xcc,
  32377. 0x5d,
  32378. 0x65,
  32379. 0xb6,
  32380. 0x92,
  32381. 0x6c,
  32382. 0x70,
  32383. 0x48,
  32384. 0x50,
  32385. 0xfd,
  32386. 0xed,
  32387. 0xb9,
  32388. 0xda,
  32389. 0x5e,
  32390. 0x15,
  32391. 0x46,
  32392. 0x57,
  32393. 0xa7,
  32394. 0x8d,
  32395. 0x9d,
  32396. 0x84,
  32397. 0x90,
  32398. 0xd8,
  32399. 0xab,
  32400. 0x00,
  32401. 0x8c,
  32402. 0xbc,
  32403. 0xd3,
  32404. 0x0a,
  32405. 0xf7,
  32406. 0xe4,
  32407. 0x58,
  32408. 0x05,
  32409. 0xb8,
  32410. 0xb3,
  32411. 0x45,
  32412. 0x06,
  32413. 0xd0,
  32414. 0x2c,
  32415. 0x1e,
  32416. 0x8f,
  32417. 0xca,
  32418. 0x3f,
  32419. 0x0f,
  32420. 0x02,
  32421. 0xc1,
  32422. 0xaf,
  32423. 0xbd,
  32424. 0x03,
  32425. 0x01,
  32426. 0x13,
  32427. 0x8a,
  32428. 0x6b,
  32429. 0x3a,
  32430. 0x91,
  32431. 0x11,
  32432. 0x41,
  32433. 0x4f,
  32434. 0x67,
  32435. 0xdc,
  32436. 0xea,
  32437. 0x97,
  32438. 0xf2,
  32439. 0xcf,
  32440. 0xce,
  32441. 0xf0,
  32442. 0xb4,
  32443. 0xe6,
  32444. 0x73,
  32445. 0x96,
  32446. 0xac,
  32447. 0x74,
  32448. 0x22,
  32449. 0xe7,
  32450. 0xad,
  32451. 0x35,
  32452. 0x85,
  32453. 0xe2,
  32454. 0xf9,
  32455. 0x37,
  32456. 0xe8,
  32457. 0x1c,
  32458. 0x75,
  32459. 0xdf,
  32460. 0x6e,
  32461. 0x47,
  32462. 0xf1,
  32463. 0x1a,
  32464. 0x71,
  32465. 0x1d,
  32466. 0x29,
  32467. 0xc5,
  32468. 0x89,
  32469. 0x6f,
  32470. 0xb7,
  32471. 0x62,
  32472. 0x0e,
  32473. 0xaa,
  32474. 0x18,
  32475. 0xbe,
  32476. 0x1b,
  32477. 0xfc,
  32478. 0x56,
  32479. 0x3e,
  32480. 0x4b,
  32481. 0xc6,
  32482. 0xd2,
  32483. 0x79,
  32484. 0x20,
  32485. 0x9a,
  32486. 0xdb,
  32487. 0xc0,
  32488. 0xfe,
  32489. 0x78,
  32490. 0xcd,
  32491. 0x5a,
  32492. 0xf4,
  32493. 0x1f,
  32494. 0xdd,
  32495. 0xa8,
  32496. 0x33,
  32497. 0x88,
  32498. 0x07,
  32499. 0xc7,
  32500. 0x31,
  32501. 0xb1,
  32502. 0x12,
  32503. 0x10,
  32504. 0x59,
  32505. 0x27,
  32506. 0x80,
  32507. 0xec,
  32508. 0x5f,
  32509. 0x60,
  32510. 0x51,
  32511. 0x7f,
  32512. 0xa9,
  32513. 0x19,
  32514. 0xb5,
  32515. 0x4a,
  32516. 0x0d,
  32517. 0x2d,
  32518. 0xe5,
  32519. 0x7a,
  32520. 0x9f,
  32521. 0x93,
  32522. 0xc9,
  32523. 0x9c,
  32524. 0xef,
  32525. 0xa0,
  32526. 0xe0,
  32527. 0x3b,
  32528. 0x4d,
  32529. 0xae,
  32530. 0x2a,
  32531. 0xf5,
  32532. 0xb0,
  32533. 0xc8,
  32534. 0xeb,
  32535. 0xbb,
  32536. 0x3c,
  32537. 0x83,
  32538. 0x53,
  32539. 0x99,
  32540. 0x61,
  32541. 0x17,
  32542. 0x2b,
  32543. 0x04,
  32544. 0x7e,
  32545. 0xba,
  32546. 0x77,
  32547. 0xd6,
  32548. 0x26,
  32549. 0xe1,
  32550. 0x69,
  32551. 0x14,
  32552. 0x63,
  32553. 0x55,
  32554. 0x21,
  32555. 0x0c,
  32556. 0x7d
  32557. ]);
  32558. var mixCol = new Uint8Array(256);
  32559. for (var i = 0; i < 256; i++) {
  32560. if (i < 128) {
  32561. mixCol[i] = i << 1;
  32562. } else {
  32563. mixCol[i] = i << 1 ^ 0x1b;
  32564. }
  32565. }
  32566. var mix = new Uint32Array([
  32567. 0x00000000,
  32568. 0x0e090d0b,
  32569. 0x1c121a16,
  32570. 0x121b171d,
  32571. 0x3824342c,
  32572. 0x362d3927,
  32573. 0x24362e3a,
  32574. 0x2a3f2331,
  32575. 0x70486858,
  32576. 0x7e416553,
  32577. 0x6c5a724e,
  32578. 0x62537f45,
  32579. 0x486c5c74,
  32580. 0x4665517f,
  32581. 0x547e4662,
  32582. 0x5a774b69,
  32583. 0xe090d0b0,
  32584. 0xee99ddbb,
  32585. 0xfc82caa6,
  32586. 0xf28bc7ad,
  32587. 0xd8b4e49c,
  32588. 0xd6bde997,
  32589. 0xc4a6fe8a,
  32590. 0xcaaff381,
  32591. 0x90d8b8e8,
  32592. 0x9ed1b5e3,
  32593. 0x8ccaa2fe,
  32594. 0x82c3aff5,
  32595. 0xa8fc8cc4,
  32596. 0xa6f581cf,
  32597. 0xb4ee96d2,
  32598. 0xbae79bd9,
  32599. 0xdb3bbb7b,
  32600. 0xd532b670,
  32601. 0xc729a16d,
  32602. 0xc920ac66,
  32603. 0xe31f8f57,
  32604. 0xed16825c,
  32605. 0xff0d9541,
  32606. 0xf104984a,
  32607. 0xab73d323,
  32608. 0xa57ade28,
  32609. 0xb761c935,
  32610. 0xb968c43e,
  32611. 0x9357e70f,
  32612. 0x9d5eea04,
  32613. 0x8f45fd19,
  32614. 0x814cf012,
  32615. 0x3bab6bcb,
  32616. 0x35a266c0,
  32617. 0x27b971dd,
  32618. 0x29b07cd6,
  32619. 0x038f5fe7,
  32620. 0x0d8652ec,
  32621. 0x1f9d45f1,
  32622. 0x119448fa,
  32623. 0x4be30393,
  32624. 0x45ea0e98,
  32625. 0x57f11985,
  32626. 0x59f8148e,
  32627. 0x73c737bf,
  32628. 0x7dce3ab4,
  32629. 0x6fd52da9,
  32630. 0x61dc20a2,
  32631. 0xad766df6,
  32632. 0xa37f60fd,
  32633. 0xb16477e0,
  32634. 0xbf6d7aeb,
  32635. 0x955259da,
  32636. 0x9b5b54d1,
  32637. 0x894043cc,
  32638. 0x87494ec7,
  32639. 0xdd3e05ae,
  32640. 0xd33708a5,
  32641. 0xc12c1fb8,
  32642. 0xcf2512b3,
  32643. 0xe51a3182,
  32644. 0xeb133c89,
  32645. 0xf9082b94,
  32646. 0xf701269f,
  32647. 0x4de6bd46,
  32648. 0x43efb04d,
  32649. 0x51f4a750,
  32650. 0x5ffdaa5b,
  32651. 0x75c2896a,
  32652. 0x7bcb8461,
  32653. 0x69d0937c,
  32654. 0x67d99e77,
  32655. 0x3daed51e,
  32656. 0x33a7d815,
  32657. 0x21bccf08,
  32658. 0x2fb5c203,
  32659. 0x058ae132,
  32660. 0x0b83ec39,
  32661. 0x1998fb24,
  32662. 0x1791f62f,
  32663. 0x764dd68d,
  32664. 0x7844db86,
  32665. 0x6a5fcc9b,
  32666. 0x6456c190,
  32667. 0x4e69e2a1,
  32668. 0x4060efaa,
  32669. 0x527bf8b7,
  32670. 0x5c72f5bc,
  32671. 0x0605bed5,
  32672. 0x080cb3de,
  32673. 0x1a17a4c3,
  32674. 0x141ea9c8,
  32675. 0x3e218af9,
  32676. 0x302887f2,
  32677. 0x223390ef,
  32678. 0x2c3a9de4,
  32679. 0x96dd063d,
  32680. 0x98d40b36,
  32681. 0x8acf1c2b,
  32682. 0x84c61120,
  32683. 0xaef93211,
  32684. 0xa0f03f1a,
  32685. 0xb2eb2807,
  32686. 0xbce2250c,
  32687. 0xe6956e65,
  32688. 0xe89c636e,
  32689. 0xfa877473,
  32690. 0xf48e7978,
  32691. 0xdeb15a49,
  32692. 0xd0b85742,
  32693. 0xc2a3405f,
  32694. 0xccaa4d54,
  32695. 0x41ecdaf7,
  32696. 0x4fe5d7fc,
  32697. 0x5dfec0e1,
  32698. 0x53f7cdea,
  32699. 0x79c8eedb,
  32700. 0x77c1e3d0,
  32701. 0x65daf4cd,
  32702. 0x6bd3f9c6,
  32703. 0x31a4b2af,
  32704. 0x3fadbfa4,
  32705. 0x2db6a8b9,
  32706. 0x23bfa5b2,
  32707. 0x09808683,
  32708. 0x07898b88,
  32709. 0x15929c95,
  32710. 0x1b9b919e,
  32711. 0xa17c0a47,
  32712. 0xaf75074c,
  32713. 0xbd6e1051,
  32714. 0xb3671d5a,
  32715. 0x99583e6b,
  32716. 0x97513360,
  32717. 0x854a247d,
  32718. 0x8b432976,
  32719. 0xd134621f,
  32720. 0xdf3d6f14,
  32721. 0xcd267809,
  32722. 0xc32f7502,
  32723. 0xe9105633,
  32724. 0xe7195b38,
  32725. 0xf5024c25,
  32726. 0xfb0b412e,
  32727. 0x9ad7618c,
  32728. 0x94de6c87,
  32729. 0x86c57b9a,
  32730. 0x88cc7691,
  32731. 0xa2f355a0,
  32732. 0xacfa58ab,
  32733. 0xbee14fb6,
  32734. 0xb0e842bd,
  32735. 0xea9f09d4,
  32736. 0xe49604df,
  32737. 0xf68d13c2,
  32738. 0xf8841ec9,
  32739. 0xd2bb3df8,
  32740. 0xdcb230f3,
  32741. 0xcea927ee,
  32742. 0xc0a02ae5,
  32743. 0x7a47b13c,
  32744. 0x744ebc37,
  32745. 0x6655ab2a,
  32746. 0x685ca621,
  32747. 0x42638510,
  32748. 0x4c6a881b,
  32749. 0x5e719f06,
  32750. 0x5078920d,
  32751. 0x0a0fd964,
  32752. 0x0406d46f,
  32753. 0x161dc372,
  32754. 0x1814ce79,
  32755. 0x322bed48,
  32756. 0x3c22e043,
  32757. 0x2e39f75e,
  32758. 0x2030fa55,
  32759. 0xec9ab701,
  32760. 0xe293ba0a,
  32761. 0xf088ad17,
  32762. 0xfe81a01c,
  32763. 0xd4be832d,
  32764. 0xdab78e26,
  32765. 0xc8ac993b,
  32766. 0xc6a59430,
  32767. 0x9cd2df59,
  32768. 0x92dbd252,
  32769. 0x80c0c54f,
  32770. 0x8ec9c844,
  32771. 0xa4f6eb75,
  32772. 0xaaffe67e,
  32773. 0xb8e4f163,
  32774. 0xb6edfc68,
  32775. 0x0c0a67b1,
  32776. 0x02036aba,
  32777. 0x10187da7,
  32778. 0x1e1170ac,
  32779. 0x342e539d,
  32780. 0x3a275e96,
  32781. 0x283c498b,
  32782. 0x26354480,
  32783. 0x7c420fe9,
  32784. 0x724b02e2,
  32785. 0x605015ff,
  32786. 0x6e5918f4,
  32787. 0x44663bc5,
  32788. 0x4a6f36ce,
  32789. 0x587421d3,
  32790. 0x567d2cd8,
  32791. 0x37a10c7a,
  32792. 0x39a80171,
  32793. 0x2bb3166c,
  32794. 0x25ba1b67,
  32795. 0x0f853856,
  32796. 0x018c355d,
  32797. 0x13972240,
  32798. 0x1d9e2f4b,
  32799. 0x47e96422,
  32800. 0x49e06929,
  32801. 0x5bfb7e34,
  32802. 0x55f2733f,
  32803. 0x7fcd500e,
  32804. 0x71c45d05,
  32805. 0x63df4a18,
  32806. 0x6dd64713,
  32807. 0xd731dcca,
  32808. 0xd938d1c1,
  32809. 0xcb23c6dc,
  32810. 0xc52acbd7,
  32811. 0xef15e8e6,
  32812. 0xe11ce5ed,
  32813. 0xf307f2f0,
  32814. 0xfd0efffb,
  32815. 0xa779b492,
  32816. 0xa970b999,
  32817. 0xbb6bae84,
  32818. 0xb562a38f,
  32819. 0x9f5d80be,
  32820. 0x91548db5,
  32821. 0x834f9aa8,
  32822. 0x8d4697a3
  32823. ]);
  32824. function expandKey128(cipherKey) {
  32825. var b = 176, result = new Uint8Array(b);
  32826. result.set(cipherKey);
  32827. for (var j = 16, i = 1; j < b; ++i) {
  32828. // RotWord
  32829. var t1 = result[j - 3], t2 = result[j - 2], t3 = result[j - 1], t4 = result[j - 4];
  32830. // SubWord
  32831. t1 = s[t1];
  32832. t2 = s[t2];
  32833. t3 = s[t3];
  32834. t4 = s[t4];
  32835. // Rcon
  32836. t1 = t1 ^ rcon[i];
  32837. for (var n = 0; n < 4; ++n) {
  32838. result[j] = t1 ^= result[j - 16];
  32839. j++;
  32840. result[j] = t2 ^= result[j - 16];
  32841. j++;
  32842. result[j] = t3 ^= result[j - 16];
  32843. j++;
  32844. result[j] = t4 ^= result[j - 16];
  32845. j++;
  32846. }
  32847. }
  32848. return result;
  32849. }
  32850. function decrypt128(input, key) {
  32851. var state = new Uint8Array(16);
  32852. state.set(input);
  32853. var i, j, k;
  32854. var t, u, v;
  32855. // AddRoundKey
  32856. for (j = 0, k = 160; j < 16; ++j, ++k) {
  32857. state[j] ^= key[k];
  32858. }
  32859. for (i = 9; i >= 1; --i) {
  32860. // InvShiftRows
  32861. t = state[13];
  32862. state[13] = state[9];
  32863. state[9] = state[5];
  32864. state[5] = state[1];
  32865. state[1] = t;
  32866. t = state[14];
  32867. u = state[10];
  32868. state[14] = state[6];
  32869. state[10] = state[2];
  32870. state[6] = t;
  32871. state[2] = u;
  32872. t = state[15];
  32873. u = state[11];
  32874. v = state[7];
  32875. state[15] = state[3];
  32876. state[11] = t;
  32877. state[7] = u;
  32878. state[3] = v;
  32879. // InvSubBytes
  32880. for (j = 0; j < 16; ++j) {
  32881. state[j] = inv_s[state[j]];
  32882. }
  32883. // AddRoundKey
  32884. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  32885. state[j] ^= key[k];
  32886. }
  32887. // InvMixColumns
  32888. for (j = 0; j < 16; j += 4) {
  32889. var s0 = mix[state[j]], s1 = mix[state[j + 1]], s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  32890. t = s0 ^ s1 >>> 8 ^ s1 << 24 ^ s2 >>> 16 ^ s2 << 16 ^ s3 >>> 24 ^ s3 << 8;
  32891. state[j] = t >>> 24 & 0xFF;
  32892. state[j + 1] = t >> 16 & 0xFF;
  32893. state[j + 2] = t >> 8 & 0xFF;
  32894. state[j + 3] = t & 0xFF;
  32895. }
  32896. }
  32897. // InvShiftRows
  32898. t = state[13];
  32899. state[13] = state[9];
  32900. state[9] = state[5];
  32901. state[5] = state[1];
  32902. state[1] = t;
  32903. t = state[14];
  32904. u = state[10];
  32905. state[14] = state[6];
  32906. state[10] = state[2];
  32907. state[6] = t;
  32908. state[2] = u;
  32909. t = state[15];
  32910. u = state[11];
  32911. v = state[7];
  32912. state[15] = state[3];
  32913. state[11] = t;
  32914. state[7] = u;
  32915. state[3] = v;
  32916. for (j = 0; j < 16; ++j) {
  32917. // InvSubBytes
  32918. state[j] = inv_s[state[j]];
  32919. // AddRoundKey
  32920. state[j] ^= key[j];
  32921. }
  32922. return state;
  32923. }
  32924. function encrypt128(input, key) {
  32925. var t, u, v, k;
  32926. var state = new Uint8Array(16);
  32927. state.set(input);
  32928. for (j = 0; j < 16; ++j) {
  32929. // AddRoundKey
  32930. state[j] ^= key[j];
  32931. }
  32932. for (i = 1; i < 10; i++) {
  32933. //SubBytes
  32934. for (j = 0; j < 16; ++j) {
  32935. state[j] = s[state[j]];
  32936. }
  32937. //ShiftRows
  32938. v = state[1];
  32939. state[1] = state[5];
  32940. state[5] = state[9];
  32941. state[9] = state[13];
  32942. state[13] = v;
  32943. v = state[2];
  32944. u = state[6];
  32945. state[2] = state[10];
  32946. state[6] = state[14];
  32947. state[10] = v;
  32948. state[14] = u;
  32949. v = state[3];
  32950. u = state[7];
  32951. t = state[11];
  32952. state[3] = state[15];
  32953. state[7] = v;
  32954. state[11] = u;
  32955. state[15] = t;
  32956. //MixColumns
  32957. for (var j = 0; j < 16; j += 4) {
  32958. var s0 = state[j + 0], s1 = state[j + 1];
  32959. var s2 = state[j + 2], s3 = state[j + 3];
  32960. t = s0 ^ s1 ^ s2 ^ s3;
  32961. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  32962. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  32963. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  32964. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  32965. }
  32966. //AddRoundKey
  32967. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  32968. state[j] ^= key[k];
  32969. }
  32970. }
  32971. //SubBytes
  32972. for (j = 0; j < 16; ++j) {
  32973. state[j] = s[state[j]];
  32974. }
  32975. //ShiftRows
  32976. v = state[1];
  32977. state[1] = state[5];
  32978. state[5] = state[9];
  32979. state[9] = state[13];
  32980. state[13] = v;
  32981. v = state[2];
  32982. u = state[6];
  32983. state[2] = state[10];
  32984. state[6] = state[14];
  32985. state[10] = v;
  32986. state[14] = u;
  32987. v = state[3];
  32988. u = state[7];
  32989. t = state[11];
  32990. state[3] = state[15];
  32991. state[7] = v;
  32992. state[11] = u;
  32993. state[15] = t;
  32994. //AddRoundKey
  32995. for (j = 0, k = 160; j < 16; ++j, ++k) {
  32996. state[j] ^= key[k];
  32997. }
  32998. return state;
  32999. }
  33000. function AES128Cipher(key) {
  33001. this.key = expandKey128(key);
  33002. this.buffer = new Uint8Array(16);
  33003. this.bufferPosition = 0;
  33004. }
  33005. function decryptBlock2(data, finalize) {
  33006. var i, j, ii, sourceLength = data.length, buffer = this.buffer, bufferLength = this.bufferPosition, result = [], iv = this.iv;
  33007. for (i = 0; i < sourceLength; ++i) {
  33008. buffer[bufferLength] = data[i];
  33009. ++bufferLength;
  33010. if (bufferLength < 16) {
  33011. continue;
  33012. }
  33013. // buffer is full, decrypting
  33014. var plain = decrypt128(buffer, this.key);
  33015. // xor-ing the IV vector to get plain text
  33016. for (j = 0; j < 16; ++j) {
  33017. plain[j] ^= iv[j];
  33018. }
  33019. iv = buffer;
  33020. result.push(plain);
  33021. buffer = new Uint8Array(16);
  33022. bufferLength = 0;
  33023. }
  33024. // saving incomplete buffer
  33025. this.buffer = buffer;
  33026. this.bufferLength = bufferLength;
  33027. this.iv = iv;
  33028. if (result.length === 0) {
  33029. return new Uint8Array([]);
  33030. }
  33031. // combining plain text blocks into one
  33032. var outputLength = 16 * result.length;
  33033. if (finalize) {
  33034. // undo a padding that is described in RFC 2898
  33035. var lastBlock = result[result.length - 1];
  33036. var psLen = lastBlock[15];
  33037. if (psLen <= 16) {
  33038. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  33039. if (lastBlock[i] !== psLen) {
  33040. // Invalid padding, assume that the block has no padding.
  33041. psLen = 0;
  33042. break;
  33043. }
  33044. }
  33045. outputLength -= psLen;
  33046. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  33047. }
  33048. }
  33049. var output = new Uint8Array(outputLength);
  33050. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  33051. output.set(result[i], j);
  33052. }
  33053. return output;
  33054. }
  33055. AES128Cipher.prototype = {
  33056. decryptBlock: function AES128Cipher_decryptBlock(data, finalize) {
  33057. var i, sourceLength = data.length;
  33058. var buffer = this.buffer, bufferLength = this.bufferPosition;
  33059. // waiting for IV values -- they are at the start of the stream
  33060. for (i = 0; bufferLength < 16 && i < sourceLength; ++i, ++bufferLength) {
  33061. buffer[bufferLength] = data[i];
  33062. }
  33063. if (bufferLength < 16) {
  33064. // need more data
  33065. this.bufferLength = bufferLength;
  33066. return new Uint8Array([]);
  33067. }
  33068. this.iv = buffer;
  33069. this.buffer = new Uint8Array(16);
  33070. this.bufferLength = 0;
  33071. // starting decryption
  33072. this.decryptBlock = decryptBlock2;
  33073. return this.decryptBlock(data.subarray(16), finalize);
  33074. },
  33075. encrypt: function AES128Cipher_encrypt(data, iv) {
  33076. var i, j, ii, sourceLength = data.length, buffer = this.buffer, bufferLength = this.bufferPosition, result = [];
  33077. if (!iv) {
  33078. iv = new Uint8Array(16);
  33079. }
  33080. for (i = 0; i < sourceLength; ++i) {
  33081. buffer[bufferLength] = data[i];
  33082. ++bufferLength;
  33083. if (bufferLength < 16) {
  33084. continue;
  33085. }
  33086. for (j = 0; j < 16; ++j) {
  33087. buffer[j] ^= iv[j];
  33088. }
  33089. // buffer is full, encrypting
  33090. var cipher = encrypt128(buffer, this.key);
  33091. iv = cipher;
  33092. result.push(cipher);
  33093. buffer = new Uint8Array(16);
  33094. bufferLength = 0;
  33095. }
  33096. // saving incomplete buffer
  33097. this.buffer = buffer;
  33098. this.bufferLength = bufferLength;
  33099. this.iv = iv;
  33100. if (result.length === 0) {
  33101. return new Uint8Array([]);
  33102. }
  33103. // combining plain text blocks into one
  33104. var outputLength = 16 * result.length;
  33105. var output = new Uint8Array(outputLength);
  33106. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  33107. output.set(result[i], j);
  33108. }
  33109. return output;
  33110. }
  33111. };
  33112. return AES128Cipher;
  33113. }();
  33114. var AES256Cipher = function AES256CipherClosure() {
  33115. var rcon = new Uint8Array([
  33116. 0x8d,
  33117. 0x01,
  33118. 0x02,
  33119. 0x04,
  33120. 0x08,
  33121. 0x10,
  33122. 0x20,
  33123. 0x40,
  33124. 0x80,
  33125. 0x1b,
  33126. 0x36,
  33127. 0x6c,
  33128. 0xd8,
  33129. 0xab,
  33130. 0x4d,
  33131. 0x9a,
  33132. 0x2f,
  33133. 0x5e,
  33134. 0xbc,
  33135. 0x63,
  33136. 0xc6,
  33137. 0x97,
  33138. 0x35,
  33139. 0x6a,
  33140. 0xd4,
  33141. 0xb3,
  33142. 0x7d,
  33143. 0xfa,
  33144. 0xef,
  33145. 0xc5,
  33146. 0x91,
  33147. 0x39,
  33148. 0x72,
  33149. 0xe4,
  33150. 0xd3,
  33151. 0xbd,
  33152. 0x61,
  33153. 0xc2,
  33154. 0x9f,
  33155. 0x25,
  33156. 0x4a,
  33157. 0x94,
  33158. 0x33,
  33159. 0x66,
  33160. 0xcc,
  33161. 0x83,
  33162. 0x1d,
  33163. 0x3a,
  33164. 0x74,
  33165. 0xe8,
  33166. 0xcb,
  33167. 0x8d,
  33168. 0x01,
  33169. 0x02,
  33170. 0x04,
  33171. 0x08,
  33172. 0x10,
  33173. 0x20,
  33174. 0x40,
  33175. 0x80,
  33176. 0x1b,
  33177. 0x36,
  33178. 0x6c,
  33179. 0xd8,
  33180. 0xab,
  33181. 0x4d,
  33182. 0x9a,
  33183. 0x2f,
  33184. 0x5e,
  33185. 0xbc,
  33186. 0x63,
  33187. 0xc6,
  33188. 0x97,
  33189. 0x35,
  33190. 0x6a,
  33191. 0xd4,
  33192. 0xb3,
  33193. 0x7d,
  33194. 0xfa,
  33195. 0xef,
  33196. 0xc5,
  33197. 0x91,
  33198. 0x39,
  33199. 0x72,
  33200. 0xe4,
  33201. 0xd3,
  33202. 0xbd,
  33203. 0x61,
  33204. 0xc2,
  33205. 0x9f,
  33206. 0x25,
  33207. 0x4a,
  33208. 0x94,
  33209. 0x33,
  33210. 0x66,
  33211. 0xcc,
  33212. 0x83,
  33213. 0x1d,
  33214. 0x3a,
  33215. 0x74,
  33216. 0xe8,
  33217. 0xcb,
  33218. 0x8d,
  33219. 0x01,
  33220. 0x02,
  33221. 0x04,
  33222. 0x08,
  33223. 0x10,
  33224. 0x20,
  33225. 0x40,
  33226. 0x80,
  33227. 0x1b,
  33228. 0x36,
  33229. 0x6c,
  33230. 0xd8,
  33231. 0xab,
  33232. 0x4d,
  33233. 0x9a,
  33234. 0x2f,
  33235. 0x5e,
  33236. 0xbc,
  33237. 0x63,
  33238. 0xc6,
  33239. 0x97,
  33240. 0x35,
  33241. 0x6a,
  33242. 0xd4,
  33243. 0xb3,
  33244. 0x7d,
  33245. 0xfa,
  33246. 0xef,
  33247. 0xc5,
  33248. 0x91,
  33249. 0x39,
  33250. 0x72,
  33251. 0xe4,
  33252. 0xd3,
  33253. 0xbd,
  33254. 0x61,
  33255. 0xc2,
  33256. 0x9f,
  33257. 0x25,
  33258. 0x4a,
  33259. 0x94,
  33260. 0x33,
  33261. 0x66,
  33262. 0xcc,
  33263. 0x83,
  33264. 0x1d,
  33265. 0x3a,
  33266. 0x74,
  33267. 0xe8,
  33268. 0xcb,
  33269. 0x8d,
  33270. 0x01,
  33271. 0x02,
  33272. 0x04,
  33273. 0x08,
  33274. 0x10,
  33275. 0x20,
  33276. 0x40,
  33277. 0x80,
  33278. 0x1b,
  33279. 0x36,
  33280. 0x6c,
  33281. 0xd8,
  33282. 0xab,
  33283. 0x4d,
  33284. 0x9a,
  33285. 0x2f,
  33286. 0x5e,
  33287. 0xbc,
  33288. 0x63,
  33289. 0xc6,
  33290. 0x97,
  33291. 0x35,
  33292. 0x6a,
  33293. 0xd4,
  33294. 0xb3,
  33295. 0x7d,
  33296. 0xfa,
  33297. 0xef,
  33298. 0xc5,
  33299. 0x91,
  33300. 0x39,
  33301. 0x72,
  33302. 0xe4,
  33303. 0xd3,
  33304. 0xbd,
  33305. 0x61,
  33306. 0xc2,
  33307. 0x9f,
  33308. 0x25,
  33309. 0x4a,
  33310. 0x94,
  33311. 0x33,
  33312. 0x66,
  33313. 0xcc,
  33314. 0x83,
  33315. 0x1d,
  33316. 0x3a,
  33317. 0x74,
  33318. 0xe8,
  33319. 0xcb,
  33320. 0x8d,
  33321. 0x01,
  33322. 0x02,
  33323. 0x04,
  33324. 0x08,
  33325. 0x10,
  33326. 0x20,
  33327. 0x40,
  33328. 0x80,
  33329. 0x1b,
  33330. 0x36,
  33331. 0x6c,
  33332. 0xd8,
  33333. 0xab,
  33334. 0x4d,
  33335. 0x9a,
  33336. 0x2f,
  33337. 0x5e,
  33338. 0xbc,
  33339. 0x63,
  33340. 0xc6,
  33341. 0x97,
  33342. 0x35,
  33343. 0x6a,
  33344. 0xd4,
  33345. 0xb3,
  33346. 0x7d,
  33347. 0xfa,
  33348. 0xef,
  33349. 0xc5,
  33350. 0x91,
  33351. 0x39,
  33352. 0x72,
  33353. 0xe4,
  33354. 0xd3,
  33355. 0xbd,
  33356. 0x61,
  33357. 0xc2,
  33358. 0x9f,
  33359. 0x25,
  33360. 0x4a,
  33361. 0x94,
  33362. 0x33,
  33363. 0x66,
  33364. 0xcc,
  33365. 0x83,
  33366. 0x1d,
  33367. 0x3a,
  33368. 0x74,
  33369. 0xe8,
  33370. 0xcb,
  33371. 0x8d
  33372. ]);
  33373. var s = new Uint8Array([
  33374. 0x63,
  33375. 0x7c,
  33376. 0x77,
  33377. 0x7b,
  33378. 0xf2,
  33379. 0x6b,
  33380. 0x6f,
  33381. 0xc5,
  33382. 0x30,
  33383. 0x01,
  33384. 0x67,
  33385. 0x2b,
  33386. 0xfe,
  33387. 0xd7,
  33388. 0xab,
  33389. 0x76,
  33390. 0xca,
  33391. 0x82,
  33392. 0xc9,
  33393. 0x7d,
  33394. 0xfa,
  33395. 0x59,
  33396. 0x47,
  33397. 0xf0,
  33398. 0xad,
  33399. 0xd4,
  33400. 0xa2,
  33401. 0xaf,
  33402. 0x9c,
  33403. 0xa4,
  33404. 0x72,
  33405. 0xc0,
  33406. 0xb7,
  33407. 0xfd,
  33408. 0x93,
  33409. 0x26,
  33410. 0x36,
  33411. 0x3f,
  33412. 0xf7,
  33413. 0xcc,
  33414. 0x34,
  33415. 0xa5,
  33416. 0xe5,
  33417. 0xf1,
  33418. 0x71,
  33419. 0xd8,
  33420. 0x31,
  33421. 0x15,
  33422. 0x04,
  33423. 0xc7,
  33424. 0x23,
  33425. 0xc3,
  33426. 0x18,
  33427. 0x96,
  33428. 0x05,
  33429. 0x9a,
  33430. 0x07,
  33431. 0x12,
  33432. 0x80,
  33433. 0xe2,
  33434. 0xeb,
  33435. 0x27,
  33436. 0xb2,
  33437. 0x75,
  33438. 0x09,
  33439. 0x83,
  33440. 0x2c,
  33441. 0x1a,
  33442. 0x1b,
  33443. 0x6e,
  33444. 0x5a,
  33445. 0xa0,
  33446. 0x52,
  33447. 0x3b,
  33448. 0xd6,
  33449. 0xb3,
  33450. 0x29,
  33451. 0xe3,
  33452. 0x2f,
  33453. 0x84,
  33454. 0x53,
  33455. 0xd1,
  33456. 0x00,
  33457. 0xed,
  33458. 0x20,
  33459. 0xfc,
  33460. 0xb1,
  33461. 0x5b,
  33462. 0x6a,
  33463. 0xcb,
  33464. 0xbe,
  33465. 0x39,
  33466. 0x4a,
  33467. 0x4c,
  33468. 0x58,
  33469. 0xcf,
  33470. 0xd0,
  33471. 0xef,
  33472. 0xaa,
  33473. 0xfb,
  33474. 0x43,
  33475. 0x4d,
  33476. 0x33,
  33477. 0x85,
  33478. 0x45,
  33479. 0xf9,
  33480. 0x02,
  33481. 0x7f,
  33482. 0x50,
  33483. 0x3c,
  33484. 0x9f,
  33485. 0xa8,
  33486. 0x51,
  33487. 0xa3,
  33488. 0x40,
  33489. 0x8f,
  33490. 0x92,
  33491. 0x9d,
  33492. 0x38,
  33493. 0xf5,
  33494. 0xbc,
  33495. 0xb6,
  33496. 0xda,
  33497. 0x21,
  33498. 0x10,
  33499. 0xff,
  33500. 0xf3,
  33501. 0xd2,
  33502. 0xcd,
  33503. 0x0c,
  33504. 0x13,
  33505. 0xec,
  33506. 0x5f,
  33507. 0x97,
  33508. 0x44,
  33509. 0x17,
  33510. 0xc4,
  33511. 0xa7,
  33512. 0x7e,
  33513. 0x3d,
  33514. 0x64,
  33515. 0x5d,
  33516. 0x19,
  33517. 0x73,
  33518. 0x60,
  33519. 0x81,
  33520. 0x4f,
  33521. 0xdc,
  33522. 0x22,
  33523. 0x2a,
  33524. 0x90,
  33525. 0x88,
  33526. 0x46,
  33527. 0xee,
  33528. 0xb8,
  33529. 0x14,
  33530. 0xde,
  33531. 0x5e,
  33532. 0x0b,
  33533. 0xdb,
  33534. 0xe0,
  33535. 0x32,
  33536. 0x3a,
  33537. 0x0a,
  33538. 0x49,
  33539. 0x06,
  33540. 0x24,
  33541. 0x5c,
  33542. 0xc2,
  33543. 0xd3,
  33544. 0xac,
  33545. 0x62,
  33546. 0x91,
  33547. 0x95,
  33548. 0xe4,
  33549. 0x79,
  33550. 0xe7,
  33551. 0xc8,
  33552. 0x37,
  33553. 0x6d,
  33554. 0x8d,
  33555. 0xd5,
  33556. 0x4e,
  33557. 0xa9,
  33558. 0x6c,
  33559. 0x56,
  33560. 0xf4,
  33561. 0xea,
  33562. 0x65,
  33563. 0x7a,
  33564. 0xae,
  33565. 0x08,
  33566. 0xba,
  33567. 0x78,
  33568. 0x25,
  33569. 0x2e,
  33570. 0x1c,
  33571. 0xa6,
  33572. 0xb4,
  33573. 0xc6,
  33574. 0xe8,
  33575. 0xdd,
  33576. 0x74,
  33577. 0x1f,
  33578. 0x4b,
  33579. 0xbd,
  33580. 0x8b,
  33581. 0x8a,
  33582. 0x70,
  33583. 0x3e,
  33584. 0xb5,
  33585. 0x66,
  33586. 0x48,
  33587. 0x03,
  33588. 0xf6,
  33589. 0x0e,
  33590. 0x61,
  33591. 0x35,
  33592. 0x57,
  33593. 0xb9,
  33594. 0x86,
  33595. 0xc1,
  33596. 0x1d,
  33597. 0x9e,
  33598. 0xe1,
  33599. 0xf8,
  33600. 0x98,
  33601. 0x11,
  33602. 0x69,
  33603. 0xd9,
  33604. 0x8e,
  33605. 0x94,
  33606. 0x9b,
  33607. 0x1e,
  33608. 0x87,
  33609. 0xe9,
  33610. 0xce,
  33611. 0x55,
  33612. 0x28,
  33613. 0xdf,
  33614. 0x8c,
  33615. 0xa1,
  33616. 0x89,
  33617. 0x0d,
  33618. 0xbf,
  33619. 0xe6,
  33620. 0x42,
  33621. 0x68,
  33622. 0x41,
  33623. 0x99,
  33624. 0x2d,
  33625. 0x0f,
  33626. 0xb0,
  33627. 0x54,
  33628. 0xbb,
  33629. 0x16
  33630. ]);
  33631. var inv_s = new Uint8Array([
  33632. 0x52,
  33633. 0x09,
  33634. 0x6a,
  33635. 0xd5,
  33636. 0x30,
  33637. 0x36,
  33638. 0xa5,
  33639. 0x38,
  33640. 0xbf,
  33641. 0x40,
  33642. 0xa3,
  33643. 0x9e,
  33644. 0x81,
  33645. 0xf3,
  33646. 0xd7,
  33647. 0xfb,
  33648. 0x7c,
  33649. 0xe3,
  33650. 0x39,
  33651. 0x82,
  33652. 0x9b,
  33653. 0x2f,
  33654. 0xff,
  33655. 0x87,
  33656. 0x34,
  33657. 0x8e,
  33658. 0x43,
  33659. 0x44,
  33660. 0xc4,
  33661. 0xde,
  33662. 0xe9,
  33663. 0xcb,
  33664. 0x54,
  33665. 0x7b,
  33666. 0x94,
  33667. 0x32,
  33668. 0xa6,
  33669. 0xc2,
  33670. 0x23,
  33671. 0x3d,
  33672. 0xee,
  33673. 0x4c,
  33674. 0x95,
  33675. 0x0b,
  33676. 0x42,
  33677. 0xfa,
  33678. 0xc3,
  33679. 0x4e,
  33680. 0x08,
  33681. 0x2e,
  33682. 0xa1,
  33683. 0x66,
  33684. 0x28,
  33685. 0xd9,
  33686. 0x24,
  33687. 0xb2,
  33688. 0x76,
  33689. 0x5b,
  33690. 0xa2,
  33691. 0x49,
  33692. 0x6d,
  33693. 0x8b,
  33694. 0xd1,
  33695. 0x25,
  33696. 0x72,
  33697. 0xf8,
  33698. 0xf6,
  33699. 0x64,
  33700. 0x86,
  33701. 0x68,
  33702. 0x98,
  33703. 0x16,
  33704. 0xd4,
  33705. 0xa4,
  33706. 0x5c,
  33707. 0xcc,
  33708. 0x5d,
  33709. 0x65,
  33710. 0xb6,
  33711. 0x92,
  33712. 0x6c,
  33713. 0x70,
  33714. 0x48,
  33715. 0x50,
  33716. 0xfd,
  33717. 0xed,
  33718. 0xb9,
  33719. 0xda,
  33720. 0x5e,
  33721. 0x15,
  33722. 0x46,
  33723. 0x57,
  33724. 0xa7,
  33725. 0x8d,
  33726. 0x9d,
  33727. 0x84,
  33728. 0x90,
  33729. 0xd8,
  33730. 0xab,
  33731. 0x00,
  33732. 0x8c,
  33733. 0xbc,
  33734. 0xd3,
  33735. 0x0a,
  33736. 0xf7,
  33737. 0xe4,
  33738. 0x58,
  33739. 0x05,
  33740. 0xb8,
  33741. 0xb3,
  33742. 0x45,
  33743. 0x06,
  33744. 0xd0,
  33745. 0x2c,
  33746. 0x1e,
  33747. 0x8f,
  33748. 0xca,
  33749. 0x3f,
  33750. 0x0f,
  33751. 0x02,
  33752. 0xc1,
  33753. 0xaf,
  33754. 0xbd,
  33755. 0x03,
  33756. 0x01,
  33757. 0x13,
  33758. 0x8a,
  33759. 0x6b,
  33760. 0x3a,
  33761. 0x91,
  33762. 0x11,
  33763. 0x41,
  33764. 0x4f,
  33765. 0x67,
  33766. 0xdc,
  33767. 0xea,
  33768. 0x97,
  33769. 0xf2,
  33770. 0xcf,
  33771. 0xce,
  33772. 0xf0,
  33773. 0xb4,
  33774. 0xe6,
  33775. 0x73,
  33776. 0x96,
  33777. 0xac,
  33778. 0x74,
  33779. 0x22,
  33780. 0xe7,
  33781. 0xad,
  33782. 0x35,
  33783. 0x85,
  33784. 0xe2,
  33785. 0xf9,
  33786. 0x37,
  33787. 0xe8,
  33788. 0x1c,
  33789. 0x75,
  33790. 0xdf,
  33791. 0x6e,
  33792. 0x47,
  33793. 0xf1,
  33794. 0x1a,
  33795. 0x71,
  33796. 0x1d,
  33797. 0x29,
  33798. 0xc5,
  33799. 0x89,
  33800. 0x6f,
  33801. 0xb7,
  33802. 0x62,
  33803. 0x0e,
  33804. 0xaa,
  33805. 0x18,
  33806. 0xbe,
  33807. 0x1b,
  33808. 0xfc,
  33809. 0x56,
  33810. 0x3e,
  33811. 0x4b,
  33812. 0xc6,
  33813. 0xd2,
  33814. 0x79,
  33815. 0x20,
  33816. 0x9a,
  33817. 0xdb,
  33818. 0xc0,
  33819. 0xfe,
  33820. 0x78,
  33821. 0xcd,
  33822. 0x5a,
  33823. 0xf4,
  33824. 0x1f,
  33825. 0xdd,
  33826. 0xa8,
  33827. 0x33,
  33828. 0x88,
  33829. 0x07,
  33830. 0xc7,
  33831. 0x31,
  33832. 0xb1,
  33833. 0x12,
  33834. 0x10,
  33835. 0x59,
  33836. 0x27,
  33837. 0x80,
  33838. 0xec,
  33839. 0x5f,
  33840. 0x60,
  33841. 0x51,
  33842. 0x7f,
  33843. 0xa9,
  33844. 0x19,
  33845. 0xb5,
  33846. 0x4a,
  33847. 0x0d,
  33848. 0x2d,
  33849. 0xe5,
  33850. 0x7a,
  33851. 0x9f,
  33852. 0x93,
  33853. 0xc9,
  33854. 0x9c,
  33855. 0xef,
  33856. 0xa0,
  33857. 0xe0,
  33858. 0x3b,
  33859. 0x4d,
  33860. 0xae,
  33861. 0x2a,
  33862. 0xf5,
  33863. 0xb0,
  33864. 0xc8,
  33865. 0xeb,
  33866. 0xbb,
  33867. 0x3c,
  33868. 0x83,
  33869. 0x53,
  33870. 0x99,
  33871. 0x61,
  33872. 0x17,
  33873. 0x2b,
  33874. 0x04,
  33875. 0x7e,
  33876. 0xba,
  33877. 0x77,
  33878. 0xd6,
  33879. 0x26,
  33880. 0xe1,
  33881. 0x69,
  33882. 0x14,
  33883. 0x63,
  33884. 0x55,
  33885. 0x21,
  33886. 0x0c,
  33887. 0x7d
  33888. ]);
  33889. var mixCol = new Uint8Array(256);
  33890. for (var i = 0; i < 256; i++) {
  33891. if (i < 128) {
  33892. mixCol[i] = i << 1;
  33893. } else {
  33894. mixCol[i] = i << 1 ^ 0x1b;
  33895. }
  33896. }
  33897. var mix = new Uint32Array([
  33898. 0x00000000,
  33899. 0x0e090d0b,
  33900. 0x1c121a16,
  33901. 0x121b171d,
  33902. 0x3824342c,
  33903. 0x362d3927,
  33904. 0x24362e3a,
  33905. 0x2a3f2331,
  33906. 0x70486858,
  33907. 0x7e416553,
  33908. 0x6c5a724e,
  33909. 0x62537f45,
  33910. 0x486c5c74,
  33911. 0x4665517f,
  33912. 0x547e4662,
  33913. 0x5a774b69,
  33914. 0xe090d0b0,
  33915. 0xee99ddbb,
  33916. 0xfc82caa6,
  33917. 0xf28bc7ad,
  33918. 0xd8b4e49c,
  33919. 0xd6bde997,
  33920. 0xc4a6fe8a,
  33921. 0xcaaff381,
  33922. 0x90d8b8e8,
  33923. 0x9ed1b5e3,
  33924. 0x8ccaa2fe,
  33925. 0x82c3aff5,
  33926. 0xa8fc8cc4,
  33927. 0xa6f581cf,
  33928. 0xb4ee96d2,
  33929. 0xbae79bd9,
  33930. 0xdb3bbb7b,
  33931. 0xd532b670,
  33932. 0xc729a16d,
  33933. 0xc920ac66,
  33934. 0xe31f8f57,
  33935. 0xed16825c,
  33936. 0xff0d9541,
  33937. 0xf104984a,
  33938. 0xab73d323,
  33939. 0xa57ade28,
  33940. 0xb761c935,
  33941. 0xb968c43e,
  33942. 0x9357e70f,
  33943. 0x9d5eea04,
  33944. 0x8f45fd19,
  33945. 0x814cf012,
  33946. 0x3bab6bcb,
  33947. 0x35a266c0,
  33948. 0x27b971dd,
  33949. 0x29b07cd6,
  33950. 0x038f5fe7,
  33951. 0x0d8652ec,
  33952. 0x1f9d45f1,
  33953. 0x119448fa,
  33954. 0x4be30393,
  33955. 0x45ea0e98,
  33956. 0x57f11985,
  33957. 0x59f8148e,
  33958. 0x73c737bf,
  33959. 0x7dce3ab4,
  33960. 0x6fd52da9,
  33961. 0x61dc20a2,
  33962. 0xad766df6,
  33963. 0xa37f60fd,
  33964. 0xb16477e0,
  33965. 0xbf6d7aeb,
  33966. 0x955259da,
  33967. 0x9b5b54d1,
  33968. 0x894043cc,
  33969. 0x87494ec7,
  33970. 0xdd3e05ae,
  33971. 0xd33708a5,
  33972. 0xc12c1fb8,
  33973. 0xcf2512b3,
  33974. 0xe51a3182,
  33975. 0xeb133c89,
  33976. 0xf9082b94,
  33977. 0xf701269f,
  33978. 0x4de6bd46,
  33979. 0x43efb04d,
  33980. 0x51f4a750,
  33981. 0x5ffdaa5b,
  33982. 0x75c2896a,
  33983. 0x7bcb8461,
  33984. 0x69d0937c,
  33985. 0x67d99e77,
  33986. 0x3daed51e,
  33987. 0x33a7d815,
  33988. 0x21bccf08,
  33989. 0x2fb5c203,
  33990. 0x058ae132,
  33991. 0x0b83ec39,
  33992. 0x1998fb24,
  33993. 0x1791f62f,
  33994. 0x764dd68d,
  33995. 0x7844db86,
  33996. 0x6a5fcc9b,
  33997. 0x6456c190,
  33998. 0x4e69e2a1,
  33999. 0x4060efaa,
  34000. 0x527bf8b7,
  34001. 0x5c72f5bc,
  34002. 0x0605bed5,
  34003. 0x080cb3de,
  34004. 0x1a17a4c3,
  34005. 0x141ea9c8,
  34006. 0x3e218af9,
  34007. 0x302887f2,
  34008. 0x223390ef,
  34009. 0x2c3a9de4,
  34010. 0x96dd063d,
  34011. 0x98d40b36,
  34012. 0x8acf1c2b,
  34013. 0x84c61120,
  34014. 0xaef93211,
  34015. 0xa0f03f1a,
  34016. 0xb2eb2807,
  34017. 0xbce2250c,
  34018. 0xe6956e65,
  34019. 0xe89c636e,
  34020. 0xfa877473,
  34021. 0xf48e7978,
  34022. 0xdeb15a49,
  34023. 0xd0b85742,
  34024. 0xc2a3405f,
  34025. 0xccaa4d54,
  34026. 0x41ecdaf7,
  34027. 0x4fe5d7fc,
  34028. 0x5dfec0e1,
  34029. 0x53f7cdea,
  34030. 0x79c8eedb,
  34031. 0x77c1e3d0,
  34032. 0x65daf4cd,
  34033. 0x6bd3f9c6,
  34034. 0x31a4b2af,
  34035. 0x3fadbfa4,
  34036. 0x2db6a8b9,
  34037. 0x23bfa5b2,
  34038. 0x09808683,
  34039. 0x07898b88,
  34040. 0x15929c95,
  34041. 0x1b9b919e,
  34042. 0xa17c0a47,
  34043. 0xaf75074c,
  34044. 0xbd6e1051,
  34045. 0xb3671d5a,
  34046. 0x99583e6b,
  34047. 0x97513360,
  34048. 0x854a247d,
  34049. 0x8b432976,
  34050. 0xd134621f,
  34051. 0xdf3d6f14,
  34052. 0xcd267809,
  34053. 0xc32f7502,
  34054. 0xe9105633,
  34055. 0xe7195b38,
  34056. 0xf5024c25,
  34057. 0xfb0b412e,
  34058. 0x9ad7618c,
  34059. 0x94de6c87,
  34060. 0x86c57b9a,
  34061. 0x88cc7691,
  34062. 0xa2f355a0,
  34063. 0xacfa58ab,
  34064. 0xbee14fb6,
  34065. 0xb0e842bd,
  34066. 0xea9f09d4,
  34067. 0xe49604df,
  34068. 0xf68d13c2,
  34069. 0xf8841ec9,
  34070. 0xd2bb3df8,
  34071. 0xdcb230f3,
  34072. 0xcea927ee,
  34073. 0xc0a02ae5,
  34074. 0x7a47b13c,
  34075. 0x744ebc37,
  34076. 0x6655ab2a,
  34077. 0x685ca621,
  34078. 0x42638510,
  34079. 0x4c6a881b,
  34080. 0x5e719f06,
  34081. 0x5078920d,
  34082. 0x0a0fd964,
  34083. 0x0406d46f,
  34084. 0x161dc372,
  34085. 0x1814ce79,
  34086. 0x322bed48,
  34087. 0x3c22e043,
  34088. 0x2e39f75e,
  34089. 0x2030fa55,
  34090. 0xec9ab701,
  34091. 0xe293ba0a,
  34092. 0xf088ad17,
  34093. 0xfe81a01c,
  34094. 0xd4be832d,
  34095. 0xdab78e26,
  34096. 0xc8ac993b,
  34097. 0xc6a59430,
  34098. 0x9cd2df59,
  34099. 0x92dbd252,
  34100. 0x80c0c54f,
  34101. 0x8ec9c844,
  34102. 0xa4f6eb75,
  34103. 0xaaffe67e,
  34104. 0xb8e4f163,
  34105. 0xb6edfc68,
  34106. 0x0c0a67b1,
  34107. 0x02036aba,
  34108. 0x10187da7,
  34109. 0x1e1170ac,
  34110. 0x342e539d,
  34111. 0x3a275e96,
  34112. 0x283c498b,
  34113. 0x26354480,
  34114. 0x7c420fe9,
  34115. 0x724b02e2,
  34116. 0x605015ff,
  34117. 0x6e5918f4,
  34118. 0x44663bc5,
  34119. 0x4a6f36ce,
  34120. 0x587421d3,
  34121. 0x567d2cd8,
  34122. 0x37a10c7a,
  34123. 0x39a80171,
  34124. 0x2bb3166c,
  34125. 0x25ba1b67,
  34126. 0x0f853856,
  34127. 0x018c355d,
  34128. 0x13972240,
  34129. 0x1d9e2f4b,
  34130. 0x47e96422,
  34131. 0x49e06929,
  34132. 0x5bfb7e34,
  34133. 0x55f2733f,
  34134. 0x7fcd500e,
  34135. 0x71c45d05,
  34136. 0x63df4a18,
  34137. 0x6dd64713,
  34138. 0xd731dcca,
  34139. 0xd938d1c1,
  34140. 0xcb23c6dc,
  34141. 0xc52acbd7,
  34142. 0xef15e8e6,
  34143. 0xe11ce5ed,
  34144. 0xf307f2f0,
  34145. 0xfd0efffb,
  34146. 0xa779b492,
  34147. 0xa970b999,
  34148. 0xbb6bae84,
  34149. 0xb562a38f,
  34150. 0x9f5d80be,
  34151. 0x91548db5,
  34152. 0x834f9aa8,
  34153. 0x8d4697a3
  34154. ]);
  34155. function expandKey256(cipherKey) {
  34156. var b = 240, result = new Uint8Array(b);
  34157. var r = 1;
  34158. result.set(cipherKey);
  34159. for (var j = 32, i = 1; j < b; ++i) {
  34160. if (j % 32 === 16) {
  34161. t1 = s[t1];
  34162. t2 = s[t2];
  34163. t3 = s[t3];
  34164. t4 = s[t4];
  34165. } else if (j % 32 === 0) {
  34166. // RotWord
  34167. var t1 = result[j - 3], t2 = result[j - 2], t3 = result[j - 1], t4 = result[j - 4];
  34168. // SubWord
  34169. t1 = s[t1];
  34170. t2 = s[t2];
  34171. t3 = s[t3];
  34172. t4 = s[t4];
  34173. // Rcon
  34174. t1 = t1 ^ r;
  34175. if ((r <<= 1) >= 256) {
  34176. r = (r ^ 0x1b) & 0xFF;
  34177. }
  34178. }
  34179. for (var n = 0; n < 4; ++n) {
  34180. result[j] = t1 ^= result[j - 32];
  34181. j++;
  34182. result[j] = t2 ^= result[j - 32];
  34183. j++;
  34184. result[j] = t3 ^= result[j - 32];
  34185. j++;
  34186. result[j] = t4 ^= result[j - 32];
  34187. j++;
  34188. }
  34189. }
  34190. return result;
  34191. }
  34192. function decrypt256(input, key) {
  34193. var state = new Uint8Array(16);
  34194. state.set(input);
  34195. var i, j, k;
  34196. var t, u, v;
  34197. // AddRoundKey
  34198. for (j = 0, k = 224; j < 16; ++j, ++k) {
  34199. state[j] ^= key[k];
  34200. }
  34201. for (i = 13; i >= 1; --i) {
  34202. // InvShiftRows
  34203. t = state[13];
  34204. state[13] = state[9];
  34205. state[9] = state[5];
  34206. state[5] = state[1];
  34207. state[1] = t;
  34208. t = state[14];
  34209. u = state[10];
  34210. state[14] = state[6];
  34211. state[10] = state[2];
  34212. state[6] = t;
  34213. state[2] = u;
  34214. t = state[15];
  34215. u = state[11];
  34216. v = state[7];
  34217. state[15] = state[3];
  34218. state[11] = t;
  34219. state[7] = u;
  34220. state[3] = v;
  34221. // InvSubBytes
  34222. for (j = 0; j < 16; ++j) {
  34223. state[j] = inv_s[state[j]];
  34224. }
  34225. // AddRoundKey
  34226. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  34227. state[j] ^= key[k];
  34228. }
  34229. // InvMixColumns
  34230. for (j = 0; j < 16; j += 4) {
  34231. var s0 = mix[state[j]], s1 = mix[state[j + 1]], s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  34232. t = s0 ^ s1 >>> 8 ^ s1 << 24 ^ s2 >>> 16 ^ s2 << 16 ^ s3 >>> 24 ^ s3 << 8;
  34233. state[j] = t >>> 24 & 0xFF;
  34234. state[j + 1] = t >> 16 & 0xFF;
  34235. state[j + 2] = t >> 8 & 0xFF;
  34236. state[j + 3] = t & 0xFF;
  34237. }
  34238. }
  34239. // InvShiftRows
  34240. t = state[13];
  34241. state[13] = state[9];
  34242. state[9] = state[5];
  34243. state[5] = state[1];
  34244. state[1] = t;
  34245. t = state[14];
  34246. u = state[10];
  34247. state[14] = state[6];
  34248. state[10] = state[2];
  34249. state[6] = t;
  34250. state[2] = u;
  34251. t = state[15];
  34252. u = state[11];
  34253. v = state[7];
  34254. state[15] = state[3];
  34255. state[11] = t;
  34256. state[7] = u;
  34257. state[3] = v;
  34258. for (j = 0; j < 16; ++j) {
  34259. // InvSubBytes
  34260. state[j] = inv_s[state[j]];
  34261. // AddRoundKey
  34262. state[j] ^= key[j];
  34263. }
  34264. return state;
  34265. }
  34266. function encrypt256(input, key) {
  34267. var t, u, v, k;
  34268. var state = new Uint8Array(16);
  34269. state.set(input);
  34270. for (j = 0; j < 16; ++j) {
  34271. // AddRoundKey
  34272. state[j] ^= key[j];
  34273. }
  34274. for (i = 1; i < 14; i++) {
  34275. //SubBytes
  34276. for (j = 0; j < 16; ++j) {
  34277. state[j] = s[state[j]];
  34278. }
  34279. //ShiftRows
  34280. v = state[1];
  34281. state[1] = state[5];
  34282. state[5] = state[9];
  34283. state[9] = state[13];
  34284. state[13] = v;
  34285. v = state[2];
  34286. u = state[6];
  34287. state[2] = state[10];
  34288. state[6] = state[14];
  34289. state[10] = v;
  34290. state[14] = u;
  34291. v = state[3];
  34292. u = state[7];
  34293. t = state[11];
  34294. state[3] = state[15];
  34295. state[7] = v;
  34296. state[11] = u;
  34297. state[15] = t;
  34298. //MixColumns
  34299. for (var j = 0; j < 16; j += 4) {
  34300. var s0 = state[j + 0], s1 = state[j + 1];
  34301. var s2 = state[j + 2], s3 = state[j + 3];
  34302. t = s0 ^ s1 ^ s2 ^ s3;
  34303. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  34304. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  34305. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  34306. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  34307. }
  34308. //AddRoundKey
  34309. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  34310. state[j] ^= key[k];
  34311. }
  34312. }
  34313. //SubBytes
  34314. for (j = 0; j < 16; ++j) {
  34315. state[j] = s[state[j]];
  34316. }
  34317. //ShiftRows
  34318. v = state[1];
  34319. state[1] = state[5];
  34320. state[5] = state[9];
  34321. state[9] = state[13];
  34322. state[13] = v;
  34323. v = state[2];
  34324. u = state[6];
  34325. state[2] = state[10];
  34326. state[6] = state[14];
  34327. state[10] = v;
  34328. state[14] = u;
  34329. v = state[3];
  34330. u = state[7];
  34331. t = state[11];
  34332. state[3] = state[15];
  34333. state[7] = v;
  34334. state[11] = u;
  34335. state[15] = t;
  34336. //AddRoundKey
  34337. for (j = 0, k = 224; j < 16; ++j, ++k) {
  34338. state[j] ^= key[k];
  34339. }
  34340. return state;
  34341. }
  34342. function AES256Cipher(key) {
  34343. this.key = expandKey256(key);
  34344. this.buffer = new Uint8Array(16);
  34345. this.bufferPosition = 0;
  34346. }
  34347. function decryptBlock2(data, finalize) {
  34348. var i, j, ii, sourceLength = data.length, buffer = this.buffer, bufferLength = this.bufferPosition, result = [], iv = this.iv;
  34349. for (i = 0; i < sourceLength; ++i) {
  34350. buffer[bufferLength] = data[i];
  34351. ++bufferLength;
  34352. if (bufferLength < 16) {
  34353. continue;
  34354. }
  34355. // buffer is full, decrypting
  34356. var plain = decrypt256(buffer, this.key);
  34357. // xor-ing the IV vector to get plain text
  34358. for (j = 0; j < 16; ++j) {
  34359. plain[j] ^= iv[j];
  34360. }
  34361. iv = buffer;
  34362. result.push(plain);
  34363. buffer = new Uint8Array(16);
  34364. bufferLength = 0;
  34365. }
  34366. // saving incomplete buffer
  34367. this.buffer = buffer;
  34368. this.bufferLength = bufferLength;
  34369. this.iv = iv;
  34370. if (result.length === 0) {
  34371. return new Uint8Array([]);
  34372. }
  34373. // combining plain text blocks into one
  34374. var outputLength = 16 * result.length;
  34375. if (finalize) {
  34376. // undo a padding that is described in RFC 2898
  34377. var lastBlock = result[result.length - 1];
  34378. var psLen = lastBlock[15];
  34379. if (psLen <= 16) {
  34380. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  34381. if (lastBlock[i] !== psLen) {
  34382. // Invalid padding, assume that the block has no padding.
  34383. psLen = 0;
  34384. break;
  34385. }
  34386. }
  34387. outputLength -= psLen;
  34388. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  34389. }
  34390. }
  34391. var output = new Uint8Array(outputLength);
  34392. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  34393. output.set(result[i], j);
  34394. }
  34395. return output;
  34396. }
  34397. AES256Cipher.prototype = {
  34398. decryptBlock: function AES256Cipher_decryptBlock(data, finalize, iv) {
  34399. var i, sourceLength = data.length;
  34400. var buffer = this.buffer, bufferLength = this.bufferPosition;
  34401. // if not supplied an IV wait for IV values
  34402. // they are at the start of the stream
  34403. if (iv) {
  34404. this.iv = iv;
  34405. } else {
  34406. for (i = 0; bufferLength < 16 && i < sourceLength; ++i, ++bufferLength) {
  34407. buffer[bufferLength] = data[i];
  34408. }
  34409. if (bufferLength < 16) {
  34410. //need more data
  34411. this.bufferLength = bufferLength;
  34412. return new Uint8Array([]);
  34413. }
  34414. this.iv = buffer;
  34415. data = data.subarray(16);
  34416. }
  34417. this.buffer = new Uint8Array(16);
  34418. this.bufferLength = 0;
  34419. // starting decryption
  34420. this.decryptBlock = decryptBlock2;
  34421. return this.decryptBlock(data, finalize);
  34422. },
  34423. encrypt: function AES256Cipher_encrypt(data, iv) {
  34424. var i, j, ii, sourceLength = data.length, buffer = this.buffer, bufferLength = this.bufferPosition, result = [];
  34425. if (!iv) {
  34426. iv = new Uint8Array(16);
  34427. }
  34428. for (i = 0; i < sourceLength; ++i) {
  34429. buffer[bufferLength] = data[i];
  34430. ++bufferLength;
  34431. if (bufferLength < 16) {
  34432. continue;
  34433. }
  34434. for (j = 0; j < 16; ++j) {
  34435. buffer[j] ^= iv[j];
  34436. }
  34437. // buffer is full, encrypting
  34438. var cipher = encrypt256(buffer, this.key);
  34439. this.iv = cipher;
  34440. result.push(cipher);
  34441. buffer = new Uint8Array(16);
  34442. bufferLength = 0;
  34443. }
  34444. // saving incomplete buffer
  34445. this.buffer = buffer;
  34446. this.bufferLength = bufferLength;
  34447. this.iv = iv;
  34448. if (result.length === 0) {
  34449. return new Uint8Array([]);
  34450. }
  34451. // combining plain text blocks into one
  34452. var outputLength = 16 * result.length;
  34453. var output = new Uint8Array(outputLength);
  34454. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  34455. output.set(result[i], j);
  34456. }
  34457. return output;
  34458. }
  34459. };
  34460. return AES256Cipher;
  34461. }();
  34462. var PDF17 = function PDF17Closure() {
  34463. function compareByteArrays(array1, array2) {
  34464. if (array1.length !== array2.length) {
  34465. return false;
  34466. }
  34467. for (var i = 0; i < array1.length; i++) {
  34468. if (array1[i] !== array2[i]) {
  34469. return false;
  34470. }
  34471. }
  34472. return true;
  34473. }
  34474. function PDF17() {
  34475. }
  34476. PDF17.prototype = {
  34477. checkOwnerPassword: function PDF17_checkOwnerPassword(password, ownerValidationSalt, userBytes, ownerPassword) {
  34478. var hashData = new Uint8Array(password.length + 56);
  34479. hashData.set(password, 0);
  34480. hashData.set(ownerValidationSalt, password.length);
  34481. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  34482. var result = calculateSHA256(hashData, 0, hashData.length);
  34483. return compareByteArrays(result, ownerPassword);
  34484. },
  34485. checkUserPassword: function PDF17_checkUserPassword(password, userValidationSalt, userPassword) {
  34486. var hashData = new Uint8Array(password.length + 8);
  34487. hashData.set(password, 0);
  34488. hashData.set(userValidationSalt, password.length);
  34489. var result = calculateSHA256(hashData, 0, hashData.length);
  34490. return compareByteArrays(result, userPassword);
  34491. },
  34492. getOwnerKey: function PDF17_getOwnerKey(password, ownerKeySalt, userBytes, ownerEncryption) {
  34493. var hashData = new Uint8Array(password.length + 56);
  34494. hashData.set(password, 0);
  34495. hashData.set(ownerKeySalt, password.length);
  34496. hashData.set(userBytes, password.length + ownerKeySalt.length);
  34497. var key = calculateSHA256(hashData, 0, hashData.length);
  34498. var cipher = new AES256Cipher(key);
  34499. return cipher.decryptBlock(ownerEncryption, false, new Uint8Array(16));
  34500. },
  34501. getUserKey: function PDF17_getUserKey(password, userKeySalt, userEncryption) {
  34502. var hashData = new Uint8Array(password.length + 8);
  34503. hashData.set(password, 0);
  34504. hashData.set(userKeySalt, password.length);
  34505. //key is the decryption key for the UE string
  34506. var key = calculateSHA256(hashData, 0, hashData.length);
  34507. var cipher = new AES256Cipher(key);
  34508. return cipher.decryptBlock(userEncryption, false, new Uint8Array(16));
  34509. }
  34510. };
  34511. return PDF17;
  34512. }();
  34513. var PDF20 = function PDF20Closure() {
  34514. function concatArrays(array1, array2) {
  34515. var t = new Uint8Array(array1.length + array2.length);
  34516. t.set(array1, 0);
  34517. t.set(array2, array1.length);
  34518. return t;
  34519. }
  34520. function calculatePDF20Hash(password, input, userBytes) {
  34521. //This refers to Algorithm 2.B as defined in ISO 32000-2
  34522. var k = calculateSHA256(input, 0, input.length).subarray(0, 32);
  34523. var e = [0];
  34524. var i = 0;
  34525. while (i < 64 || e[e.length - 1] > i - 32) {
  34526. var arrayLength = password.length + k.length + userBytes.length;
  34527. var k1 = new Uint8Array(arrayLength * 64);
  34528. var array = concatArrays(password, k);
  34529. array = concatArrays(array, userBytes);
  34530. for (var j = 0, pos = 0; j < 64; j++, pos += arrayLength) {
  34531. k1.set(array, pos);
  34532. }
  34533. //AES128 CBC NO PADDING with
  34534. //first 16 bytes of k as the key and the second 16 as the iv.
  34535. var cipher = new AES128Cipher(k.subarray(0, 16));
  34536. e = cipher.encrypt(k1, k.subarray(16, 32));
  34537. //Now we have to take the first 16 bytes of an unsigned
  34538. //big endian integer... and compute the remainder
  34539. //modulo 3.... That is a fairly large number and
  34540. //JavaScript isn't going to handle that well...
  34541. //So we're using a trick that allows us to perform
  34542. //modulo math byte by byte
  34543. var remainder = 0;
  34544. for (var z = 0; z < 16; z++) {
  34545. remainder *= 256 % 3;
  34546. remainder %= 3;
  34547. remainder += (e[z] >>> 0) % 3;
  34548. remainder %= 3;
  34549. }
  34550. if (remainder === 0) {
  34551. k = calculateSHA256(e, 0, e.length);
  34552. } else if (remainder === 1) {
  34553. k = calculateSHA384(e, 0, e.length);
  34554. } else if (remainder === 2) {
  34555. k = calculateSHA512(e, 0, e.length);
  34556. }
  34557. i++;
  34558. }
  34559. return k.subarray(0, 32);
  34560. }
  34561. function PDF20() {
  34562. }
  34563. function compareByteArrays(array1, array2) {
  34564. if (array1.length !== array2.length) {
  34565. return false;
  34566. }
  34567. for (var i = 0; i < array1.length; i++) {
  34568. if (array1[i] !== array2[i]) {
  34569. return false;
  34570. }
  34571. }
  34572. return true;
  34573. }
  34574. PDF20.prototype = {
  34575. hash: function PDF20_hash(password, concatBytes, userBytes) {
  34576. return calculatePDF20Hash(password, concatBytes, userBytes);
  34577. },
  34578. checkOwnerPassword: function PDF20_checkOwnerPassword(password, ownerValidationSalt, userBytes, ownerPassword) {
  34579. var hashData = new Uint8Array(password.length + 56);
  34580. hashData.set(password, 0);
  34581. hashData.set(ownerValidationSalt, password.length);
  34582. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  34583. var result = calculatePDF20Hash(password, hashData, userBytes);
  34584. return compareByteArrays(result, ownerPassword);
  34585. },
  34586. checkUserPassword: function PDF20_checkUserPassword(password, userValidationSalt, userPassword) {
  34587. var hashData = new Uint8Array(password.length + 8);
  34588. hashData.set(password, 0);
  34589. hashData.set(userValidationSalt, password.length);
  34590. var result = calculatePDF20Hash(password, hashData, []);
  34591. return compareByteArrays(result, userPassword);
  34592. },
  34593. getOwnerKey: function PDF20_getOwnerKey(password, ownerKeySalt, userBytes, ownerEncryption) {
  34594. var hashData = new Uint8Array(password.length + 56);
  34595. hashData.set(password, 0);
  34596. hashData.set(ownerKeySalt, password.length);
  34597. hashData.set(userBytes, password.length + ownerKeySalt.length);
  34598. var key = calculatePDF20Hash(password, hashData, userBytes);
  34599. var cipher = new AES256Cipher(key);
  34600. return cipher.decryptBlock(ownerEncryption, false, new Uint8Array(16));
  34601. },
  34602. getUserKey: function PDF20_getUserKey(password, userKeySalt, userEncryption) {
  34603. var hashData = new Uint8Array(password.length + 8);
  34604. hashData.set(password, 0);
  34605. hashData.set(userKeySalt, password.length);
  34606. //key is the decryption key for the UE string
  34607. var key = calculatePDF20Hash(password, hashData, []);
  34608. var cipher = new AES256Cipher(key);
  34609. return cipher.decryptBlock(userEncryption, false, new Uint8Array(16));
  34610. }
  34611. };
  34612. return PDF20;
  34613. }();
  34614. var CipherTransform = function CipherTransformClosure() {
  34615. function CipherTransform(stringCipherConstructor, streamCipherConstructor) {
  34616. this.stringCipherConstructor = stringCipherConstructor;
  34617. this.streamCipherConstructor = streamCipherConstructor;
  34618. }
  34619. CipherTransform.prototype = {
  34620. createStream: function CipherTransform_createStream(stream, length) {
  34621. var cipher = new this.streamCipherConstructor();
  34622. return new DecryptStream(stream, length, function cipherTransformDecryptStream(data, finalize) {
  34623. return cipher.decryptBlock(data, finalize);
  34624. });
  34625. },
  34626. decryptString: function CipherTransform_decryptString(s) {
  34627. var cipher = new this.stringCipherConstructor();
  34628. var data = stringToBytes(s);
  34629. data = cipher.decryptBlock(data, true);
  34630. return bytesToString(data);
  34631. }
  34632. };
  34633. return CipherTransform;
  34634. }();
  34635. var CipherTransformFactory = function CipherTransformFactoryClosure() {
  34636. var defaultPasswordBytes = new Uint8Array([
  34637. 0x28,
  34638. 0xBF,
  34639. 0x4E,
  34640. 0x5E,
  34641. 0x4E,
  34642. 0x75,
  34643. 0x8A,
  34644. 0x41,
  34645. 0x64,
  34646. 0x00,
  34647. 0x4E,
  34648. 0x56,
  34649. 0xFF,
  34650. 0xFA,
  34651. 0x01,
  34652. 0x08,
  34653. 0x2E,
  34654. 0x2E,
  34655. 0x00,
  34656. 0xB6,
  34657. 0xD0,
  34658. 0x68,
  34659. 0x3E,
  34660. 0x80,
  34661. 0x2F,
  34662. 0x0C,
  34663. 0xA9,
  34664. 0xFE,
  34665. 0x64,
  34666. 0x53,
  34667. 0x69,
  34668. 0x7A
  34669. ]);
  34670. function createEncryptionKey20(revision, password, ownerPassword, ownerValidationSalt, ownerKeySalt, uBytes, userPassword, userValidationSalt, userKeySalt, ownerEncryption, userEncryption, perms) {
  34671. if (password) {
  34672. var passwordLength = Math.min(127, password.length);
  34673. password = password.subarray(0, passwordLength);
  34674. } else {
  34675. password = [];
  34676. }
  34677. var pdfAlgorithm;
  34678. if (revision === 6) {
  34679. pdfAlgorithm = new PDF20();
  34680. } else {
  34681. pdfAlgorithm = new PDF17();
  34682. }
  34683. if (pdfAlgorithm.checkUserPassword(password, userValidationSalt, userPassword)) {
  34684. return pdfAlgorithm.getUserKey(password, userKeySalt, userEncryption);
  34685. } else if (password.length && pdfAlgorithm.checkOwnerPassword(password, ownerValidationSalt, uBytes, ownerPassword)) {
  34686. return pdfAlgorithm.getOwnerKey(password, ownerKeySalt, uBytes, ownerEncryption);
  34687. }
  34688. return null;
  34689. }
  34690. function prepareKeyData(fileId, password, ownerPassword, userPassword, flags, revision, keyLength, encryptMetadata) {
  34691. var hashDataSize = 40 + ownerPassword.length + fileId.length;
  34692. var hashData = new Uint8Array(hashDataSize), i = 0, j, n;
  34693. if (password) {
  34694. n = Math.min(32, password.length);
  34695. for (; i < n; ++i) {
  34696. hashData[i] = password[i];
  34697. }
  34698. }
  34699. j = 0;
  34700. while (i < 32) {
  34701. hashData[i++] = defaultPasswordBytes[j++];
  34702. }
  34703. // as now the padded password in the hashData[0..i]
  34704. for (j = 0, n = ownerPassword.length; j < n; ++j) {
  34705. hashData[i++] = ownerPassword[j];
  34706. }
  34707. hashData[i++] = flags & 0xFF;
  34708. hashData[i++] = flags >> 8 & 0xFF;
  34709. hashData[i++] = flags >> 16 & 0xFF;
  34710. hashData[i++] = flags >>> 24 & 0xFF;
  34711. for (j = 0, n = fileId.length; j < n; ++j) {
  34712. hashData[i++] = fileId[j];
  34713. }
  34714. if (revision >= 4 && !encryptMetadata) {
  34715. hashData[i++] = 0xFF;
  34716. hashData[i++] = 0xFF;
  34717. hashData[i++] = 0xFF;
  34718. hashData[i++] = 0xFF;
  34719. }
  34720. var hash = calculateMD5(hashData, 0, i);
  34721. var keyLengthInBytes = keyLength >> 3;
  34722. if (revision >= 3) {
  34723. for (j = 0; j < 50; ++j) {
  34724. hash = calculateMD5(hash, 0, keyLengthInBytes);
  34725. }
  34726. }
  34727. var encryptionKey = hash.subarray(0, keyLengthInBytes);
  34728. var cipher, checkData;
  34729. if (revision >= 3) {
  34730. for (i = 0; i < 32; ++i) {
  34731. hashData[i] = defaultPasswordBytes[i];
  34732. }
  34733. for (j = 0, n = fileId.length; j < n; ++j) {
  34734. hashData[i++] = fileId[j];
  34735. }
  34736. cipher = new ARCFourCipher(encryptionKey);
  34737. checkData = cipher.encryptBlock(calculateMD5(hashData, 0, i));
  34738. n = encryptionKey.length;
  34739. var derivedKey = new Uint8Array(n), k;
  34740. for (j = 1; j <= 19; ++j) {
  34741. for (k = 0; k < n; ++k) {
  34742. derivedKey[k] = encryptionKey[k] ^ j;
  34743. }
  34744. cipher = new ARCFourCipher(derivedKey);
  34745. checkData = cipher.encryptBlock(checkData);
  34746. }
  34747. for (j = 0, n = checkData.length; j < n; ++j) {
  34748. if (userPassword[j] !== checkData[j]) {
  34749. return null;
  34750. }
  34751. }
  34752. } else {
  34753. cipher = new ARCFourCipher(encryptionKey);
  34754. checkData = cipher.encryptBlock(defaultPasswordBytes);
  34755. for (j = 0, n = checkData.length; j < n; ++j) {
  34756. if (userPassword[j] !== checkData[j]) {
  34757. return null;
  34758. }
  34759. }
  34760. }
  34761. return encryptionKey;
  34762. }
  34763. function decodeUserPassword(password, ownerPassword, revision, keyLength) {
  34764. var hashData = new Uint8Array(32), i = 0, j, n;
  34765. n = Math.min(32, password.length);
  34766. for (; i < n; ++i) {
  34767. hashData[i] = password[i];
  34768. }
  34769. j = 0;
  34770. while (i < 32) {
  34771. hashData[i++] = defaultPasswordBytes[j++];
  34772. }
  34773. var hash = calculateMD5(hashData, 0, i);
  34774. var keyLengthInBytes = keyLength >> 3;
  34775. if (revision >= 3) {
  34776. for (j = 0; j < 50; ++j) {
  34777. hash = calculateMD5(hash, 0, hash.length);
  34778. }
  34779. }
  34780. var cipher, userPassword;
  34781. if (revision >= 3) {
  34782. userPassword = ownerPassword;
  34783. var derivedKey = new Uint8Array(keyLengthInBytes), k;
  34784. for (j = 19; j >= 0; j--) {
  34785. for (k = 0; k < keyLengthInBytes; ++k) {
  34786. derivedKey[k] = hash[k] ^ j;
  34787. }
  34788. cipher = new ARCFourCipher(derivedKey);
  34789. userPassword = cipher.encryptBlock(userPassword);
  34790. }
  34791. } else {
  34792. cipher = new ARCFourCipher(hash.subarray(0, keyLengthInBytes));
  34793. userPassword = cipher.encryptBlock(ownerPassword);
  34794. }
  34795. return userPassword;
  34796. }
  34797. var identityName = Name.get('Identity');
  34798. function CipherTransformFactory(dict, fileId, password) {
  34799. var filter = dict.get('Filter');
  34800. if (!isName(filter, 'Standard')) {
  34801. error('unknown encryption method');
  34802. }
  34803. this.dict = dict;
  34804. var algorithm = dict.get('V');
  34805. if (!isInt(algorithm) || algorithm !== 1 && algorithm !== 2 && algorithm !== 4 && algorithm !== 5) {
  34806. error('unsupported encryption algorithm');
  34807. }
  34808. this.algorithm = algorithm;
  34809. var keyLength = dict.get('Length');
  34810. if (!keyLength) {
  34811. // Spec asks to rely on encryption dictionary's Length entry, however
  34812. // some PDFs don't have it. Trying to recover.
  34813. if (algorithm <= 3) {
  34814. // For 1 and 2 it's fixed to 40-bit, for 3 40-bit is a minimal value.
  34815. keyLength = 40;
  34816. } else {
  34817. // Trying to find default handler -- it usually has Length.
  34818. var cfDict = dict.get('CF');
  34819. var streamCryptoName = dict.get('StmF');
  34820. if (isDict(cfDict) && isName(streamCryptoName)) {
  34821. cfDict.suppressEncryption = true;
  34822. // See comment below.
  34823. var handlerDict = cfDict.get(streamCryptoName.name);
  34824. keyLength = handlerDict && handlerDict.get('Length') || 128;
  34825. if (keyLength < 40) {
  34826. // Sometimes it's incorrect value of bits, generators specify bytes.
  34827. keyLength <<= 3;
  34828. }
  34829. }
  34830. }
  34831. }
  34832. if (!isInt(keyLength) || keyLength < 40 || keyLength % 8 !== 0) {
  34833. error('invalid key length');
  34834. }
  34835. // prepare keys
  34836. var ownerPassword = stringToBytes(dict.get('O')).subarray(0, 32);
  34837. var userPassword = stringToBytes(dict.get('U')).subarray(0, 32);
  34838. var flags = dict.get('P');
  34839. var revision = dict.get('R');
  34840. // meaningful when V is 4 or 5
  34841. var encryptMetadata = (algorithm === 4 || algorithm === 5) && dict.get('EncryptMetadata') !== false;
  34842. this.encryptMetadata = encryptMetadata;
  34843. var fileIdBytes = stringToBytes(fileId);
  34844. var passwordBytes;
  34845. if (password) {
  34846. if (revision === 6) {
  34847. try {
  34848. password = utf8StringToString(password);
  34849. } catch (ex) {
  34850. warn('CipherTransformFactory: ' + 'Unable to convert UTF8 encoded password.');
  34851. }
  34852. }
  34853. passwordBytes = stringToBytes(password);
  34854. }
  34855. var encryptionKey;
  34856. if (algorithm !== 5) {
  34857. encryptionKey = prepareKeyData(fileIdBytes, passwordBytes, ownerPassword, userPassword, flags, revision, keyLength, encryptMetadata);
  34858. } else {
  34859. var ownerValidationSalt = stringToBytes(dict.get('O')).subarray(32, 40);
  34860. var ownerKeySalt = stringToBytes(dict.get('O')).subarray(40, 48);
  34861. var uBytes = stringToBytes(dict.get('U')).subarray(0, 48);
  34862. var userValidationSalt = stringToBytes(dict.get('U')).subarray(32, 40);
  34863. var userKeySalt = stringToBytes(dict.get('U')).subarray(40, 48);
  34864. var ownerEncryption = stringToBytes(dict.get('OE'));
  34865. var userEncryption = stringToBytes(dict.get('UE'));
  34866. var perms = stringToBytes(dict.get('Perms'));
  34867. encryptionKey = createEncryptionKey20(revision, passwordBytes, ownerPassword, ownerValidationSalt, ownerKeySalt, uBytes, userPassword, userValidationSalt, userKeySalt, ownerEncryption, userEncryption, perms);
  34868. }
  34869. if (!encryptionKey && !password) {
  34870. throw new PasswordException('No password given', PasswordResponses.NEED_PASSWORD);
  34871. } else if (!encryptionKey && password) {
  34872. // Attempting use the password as an owner password
  34873. var decodedPassword = decodeUserPassword(passwordBytes, ownerPassword, revision, keyLength);
  34874. encryptionKey = prepareKeyData(fileIdBytes, decodedPassword, ownerPassword, userPassword, flags, revision, keyLength, encryptMetadata);
  34875. }
  34876. if (!encryptionKey) {
  34877. throw new PasswordException('Incorrect Password', PasswordResponses.INCORRECT_PASSWORD);
  34878. }
  34879. this.encryptionKey = encryptionKey;
  34880. if (algorithm >= 4) {
  34881. var cf = dict.get('CF');
  34882. if (isDict(cf)) {
  34883. // The 'CF' dictionary itself should not be encrypted, and by setting
  34884. // `suppressEncryption` we can prevent an infinite loop inside of
  34885. // `XRef_fetchUncompressed` if the dictionary contains indirect objects
  34886. // (fixes issue7665.pdf).
  34887. cf.suppressEncryption = true;
  34888. }
  34889. this.cf = cf;
  34890. this.stmf = dict.get('StmF') || identityName;
  34891. this.strf = dict.get('StrF') || identityName;
  34892. this.eff = dict.get('EFF') || this.stmf;
  34893. }
  34894. }
  34895. function buildObjectKey(num, gen, encryptionKey, isAes) {
  34896. var key = new Uint8Array(encryptionKey.length + 9), i, n;
  34897. for (i = 0, n = encryptionKey.length; i < n; ++i) {
  34898. key[i] = encryptionKey[i];
  34899. }
  34900. key[i++] = num & 0xFF;
  34901. key[i++] = num >> 8 & 0xFF;
  34902. key[i++] = num >> 16 & 0xFF;
  34903. key[i++] = gen & 0xFF;
  34904. key[i++] = gen >> 8 & 0xFF;
  34905. if (isAes) {
  34906. key[i++] = 0x73;
  34907. key[i++] = 0x41;
  34908. key[i++] = 0x6C;
  34909. key[i++] = 0x54;
  34910. }
  34911. var hash = calculateMD5(key, 0, i);
  34912. return hash.subarray(0, Math.min(encryptionKey.length + 5, 16));
  34913. }
  34914. function buildCipherConstructor(cf, name, num, gen, key) {
  34915. assert(isName(name), 'Invalid crypt filter name.');
  34916. var cryptFilter = cf.get(name.name);
  34917. var cfm;
  34918. if (cryptFilter !== null && cryptFilter !== undefined) {
  34919. cfm = cryptFilter.get('CFM');
  34920. }
  34921. if (!cfm || cfm.name === 'None') {
  34922. return function cipherTransformFactoryBuildCipherConstructorNone() {
  34923. return new NullCipher();
  34924. };
  34925. }
  34926. if ('V2' === cfm.name) {
  34927. return function cipherTransformFactoryBuildCipherConstructorV2() {
  34928. return new ARCFourCipher(buildObjectKey(num, gen, key, false));
  34929. };
  34930. }
  34931. if ('AESV2' === cfm.name) {
  34932. return function cipherTransformFactoryBuildCipherConstructorAESV2() {
  34933. return new AES128Cipher(buildObjectKey(num, gen, key, true));
  34934. };
  34935. }
  34936. if ('AESV3' === cfm.name) {
  34937. return function cipherTransformFactoryBuildCipherConstructorAESV3() {
  34938. return new AES256Cipher(key);
  34939. };
  34940. }
  34941. error('Unknown crypto method');
  34942. }
  34943. CipherTransformFactory.prototype = {
  34944. createCipherTransform: function CipherTransformFactory_createCipherTransform(num, gen) {
  34945. if (this.algorithm === 4 || this.algorithm === 5) {
  34946. return new CipherTransform(buildCipherConstructor(this.cf, this.stmf, num, gen, this.encryptionKey), buildCipherConstructor(this.cf, this.strf, num, gen, this.encryptionKey));
  34947. }
  34948. // algorithms 1 and 2
  34949. var key = buildObjectKey(num, gen, this.encryptionKey, false);
  34950. var cipherConstructor = function buildCipherCipherConstructor() {
  34951. return new ARCFourCipher(key);
  34952. };
  34953. return new CipherTransform(cipherConstructor, cipherConstructor);
  34954. }
  34955. };
  34956. return CipherTransformFactory;
  34957. }();
  34958. exports.AES128Cipher = AES128Cipher;
  34959. exports.AES256Cipher = AES256Cipher;
  34960. exports.ARCFourCipher = ARCFourCipher;
  34961. exports.CipherTransformFactory = CipherTransformFactory;
  34962. exports.PDF17 = PDF17;
  34963. exports.PDF20 = PDF20;
  34964. exports.calculateMD5 = calculateMD5;
  34965. exports.calculateSHA256 = calculateSHA256;
  34966. exports.calculateSHA384 = calculateSHA384;
  34967. exports.calculateSHA512 = calculateSHA512;
  34968. }));
  34969. (function (root, factory) {
  34970. factory(root.pdfjsCoreFontRenderer = {}, root.pdfjsSharedUtil, root.pdfjsCoreStream, root.pdfjsCoreGlyphList, root.pdfjsCoreEncodings, root.pdfjsCoreCFFParser);
  34971. }(this, function (exports, sharedUtil, coreStream, coreGlyphList, coreEncodings, coreCFFParser) {
  34972. var Util = sharedUtil.Util;
  34973. var bytesToString = sharedUtil.bytesToString;
  34974. var error = sharedUtil.error;
  34975. var Stream = coreStream.Stream;
  34976. var getGlyphsUnicode = coreGlyphList.getGlyphsUnicode;
  34977. var StandardEncoding = coreEncodings.StandardEncoding;
  34978. var CFFParser = coreCFFParser.CFFParser;
  34979. var FontRendererFactory = function FontRendererFactoryClosure() {
  34980. function getLong(data, offset) {
  34981. return data[offset] << 24 | data[offset + 1] << 16 | data[offset + 2] << 8 | data[offset + 3];
  34982. }
  34983. function getUshort(data, offset) {
  34984. return data[offset] << 8 | data[offset + 1];
  34985. }
  34986. function parseCmap(data, start, end) {
  34987. var offset = getUshort(data, start + 2) === 1 ? getLong(data, start + 8) : getLong(data, start + 16);
  34988. var format = getUshort(data, start + offset);
  34989. var length, ranges, p, i;
  34990. if (format === 4) {
  34991. length = getUshort(data, start + offset + 2);
  34992. var segCount = getUshort(data, start + offset + 6) >> 1;
  34993. p = start + offset + 14;
  34994. ranges = [];
  34995. for (i = 0; i < segCount; i++, p += 2) {
  34996. ranges[i] = { end: getUshort(data, p) };
  34997. }
  34998. p += 2;
  34999. for (i = 0; i < segCount; i++, p += 2) {
  35000. ranges[i].start = getUshort(data, p);
  35001. }
  35002. for (i = 0; i < segCount; i++, p += 2) {
  35003. ranges[i].idDelta = getUshort(data, p);
  35004. }
  35005. for (i = 0; i < segCount; i++, p += 2) {
  35006. var idOffset = getUshort(data, p);
  35007. if (idOffset === 0) {
  35008. continue;
  35009. }
  35010. ranges[i].ids = [];
  35011. for (var j = 0, jj = ranges[i].end - ranges[i].start + 1; j < jj; j++) {
  35012. ranges[i].ids[j] = getUshort(data, p + idOffset);
  35013. idOffset += 2;
  35014. }
  35015. }
  35016. return ranges;
  35017. } else if (format === 12) {
  35018. length = getLong(data, start + offset + 4);
  35019. var groups = getLong(data, start + offset + 12);
  35020. p = start + offset + 16;
  35021. ranges = [];
  35022. for (i = 0; i < groups; i++) {
  35023. ranges.push({
  35024. start: getLong(data, p),
  35025. end: getLong(data, p + 4),
  35026. idDelta: getLong(data, p + 8) - getLong(data, p)
  35027. });
  35028. p += 12;
  35029. }
  35030. return ranges;
  35031. }
  35032. error('not supported cmap: ' + format);
  35033. }
  35034. function parseCff(data, start, end, seacAnalysisEnabled) {
  35035. var properties = {};
  35036. var parser = new CFFParser(new Stream(data, start, end - start), properties, seacAnalysisEnabled);
  35037. var cff = parser.parse();
  35038. return {
  35039. glyphs: cff.charStrings.objects,
  35040. subrs: cff.topDict.privateDict && cff.topDict.privateDict.subrsIndex && cff.topDict.privateDict.subrsIndex.objects,
  35041. gsubrs: cff.globalSubrIndex && cff.globalSubrIndex.objects
  35042. };
  35043. }
  35044. function parseGlyfTable(glyf, loca, isGlyphLocationsLong) {
  35045. var itemSize, itemDecode;
  35046. if (isGlyphLocationsLong) {
  35047. itemSize = 4;
  35048. itemDecode = function fontItemDecodeLong(data, offset) {
  35049. return data[offset] << 24 | data[offset + 1] << 16 | data[offset + 2] << 8 | data[offset + 3];
  35050. };
  35051. } else {
  35052. itemSize = 2;
  35053. itemDecode = function fontItemDecode(data, offset) {
  35054. return data[offset] << 9 | data[offset + 1] << 1;
  35055. };
  35056. }
  35057. var glyphs = [];
  35058. var startOffset = itemDecode(loca, 0);
  35059. for (var j = itemSize; j < loca.length; j += itemSize) {
  35060. var endOffset = itemDecode(loca, j);
  35061. glyphs.push(glyf.subarray(startOffset, endOffset));
  35062. startOffset = endOffset;
  35063. }
  35064. return glyphs;
  35065. }
  35066. function lookupCmap(ranges, unicode) {
  35067. var code = unicode.charCodeAt(0), gid = 0;
  35068. var l = 0, r = ranges.length - 1;
  35069. while (l < r) {
  35070. var c = l + r + 1 >> 1;
  35071. if (code < ranges[c].start) {
  35072. r = c - 1;
  35073. } else {
  35074. l = c;
  35075. }
  35076. }
  35077. if (ranges[l].start <= code && code <= ranges[l].end) {
  35078. gid = ranges[l].idDelta + (ranges[l].ids ? ranges[l].ids[code - ranges[l].start] : code) & 0xFFFF;
  35079. }
  35080. return {
  35081. charCode: code,
  35082. glyphId: gid
  35083. };
  35084. }
  35085. function compileGlyf(code, cmds, font) {
  35086. function moveTo(x, y) {
  35087. cmds.push({
  35088. cmd: 'moveTo',
  35089. args: [
  35090. x,
  35091. y
  35092. ]
  35093. });
  35094. }
  35095. function lineTo(x, y) {
  35096. cmds.push({
  35097. cmd: 'lineTo',
  35098. args: [
  35099. x,
  35100. y
  35101. ]
  35102. });
  35103. }
  35104. function quadraticCurveTo(xa, ya, x, y) {
  35105. cmds.push({
  35106. cmd: 'quadraticCurveTo',
  35107. args: [
  35108. xa,
  35109. ya,
  35110. x,
  35111. y
  35112. ]
  35113. });
  35114. }
  35115. var i = 0;
  35116. var numberOfContours = (code[i] << 24 | code[i + 1] << 16) >> 16;
  35117. var flags;
  35118. var x = 0, y = 0;
  35119. i += 10;
  35120. if (numberOfContours < 0) {
  35121. // composite glyph
  35122. do {
  35123. flags = code[i] << 8 | code[i + 1];
  35124. var glyphIndex = code[i + 2] << 8 | code[i + 3];
  35125. i += 4;
  35126. var arg1, arg2;
  35127. if (flags & 0x01) {
  35128. arg1 = (code[i] << 24 | code[i + 1] << 16) >> 16;
  35129. arg2 = (code[i + 2] << 24 | code[i + 3] << 16) >> 16;
  35130. i += 4;
  35131. } else {
  35132. arg1 = code[i++];
  35133. arg2 = code[i++];
  35134. }
  35135. if (flags & 0x02) {
  35136. x = arg1;
  35137. y = arg2;
  35138. } else {
  35139. x = 0;
  35140. y = 0;
  35141. }
  35142. // TODO "they are points" ?
  35143. var scaleX = 1, scaleY = 1, scale01 = 0, scale10 = 0;
  35144. if (flags & 0x08) {
  35145. scaleX = scaleY = (code[i] << 24 | code[i + 1] << 16) / 1073741824;
  35146. i += 2;
  35147. } else if (flags & 0x40) {
  35148. scaleX = (code[i] << 24 | code[i + 1] << 16) / 1073741824;
  35149. scaleY = (code[i + 2] << 24 | code[i + 3] << 16) / 1073741824;
  35150. i += 4;
  35151. } else if (flags & 0x80) {
  35152. scaleX = (code[i] << 24 | code[i + 1] << 16) / 1073741824;
  35153. scale01 = (code[i + 2] << 24 | code[i + 3] << 16) / 1073741824;
  35154. scale10 = (code[i + 4] << 24 | code[i + 5] << 16) / 1073741824;
  35155. scaleY = (code[i + 6] << 24 | code[i + 7] << 16) / 1073741824;
  35156. i += 8;
  35157. }
  35158. var subglyph = font.glyphs[glyphIndex];
  35159. if (subglyph) {
  35160. cmds.push({ cmd: 'save' });
  35161. cmds.push({
  35162. cmd: 'transform',
  35163. args: [
  35164. scaleX,
  35165. scale01,
  35166. scale10,
  35167. scaleY,
  35168. x,
  35169. y
  35170. ]
  35171. });
  35172. compileGlyf(subglyph, cmds, font);
  35173. cmds.push({ cmd: 'restore' });
  35174. }
  35175. } while (flags & 0x20);
  35176. } else {
  35177. // simple glyph
  35178. var endPtsOfContours = [];
  35179. var j, jj;
  35180. for (j = 0; j < numberOfContours; j++) {
  35181. endPtsOfContours.push(code[i] << 8 | code[i + 1]);
  35182. i += 2;
  35183. }
  35184. var instructionLength = code[i] << 8 | code[i + 1];
  35185. i += 2 + instructionLength;
  35186. // skipping the instructions
  35187. var numberOfPoints = endPtsOfContours[endPtsOfContours.length - 1] + 1;
  35188. var points = [];
  35189. while (points.length < numberOfPoints) {
  35190. flags = code[i++];
  35191. var repeat = 1;
  35192. if (flags & 0x08) {
  35193. repeat += code[i++];
  35194. }
  35195. while (repeat-- > 0) {
  35196. points.push({ flags: flags });
  35197. }
  35198. }
  35199. for (j = 0; j < numberOfPoints; j++) {
  35200. switch (points[j].flags & 0x12) {
  35201. case 0x00:
  35202. x += (code[i] << 24 | code[i + 1] << 16) >> 16;
  35203. i += 2;
  35204. break;
  35205. case 0x02:
  35206. x -= code[i++];
  35207. break;
  35208. case 0x12:
  35209. x += code[i++];
  35210. break;
  35211. }
  35212. points[j].x = x;
  35213. }
  35214. for (j = 0; j < numberOfPoints; j++) {
  35215. switch (points[j].flags & 0x24) {
  35216. case 0x00:
  35217. y += (code[i] << 24 | code[i + 1] << 16) >> 16;
  35218. i += 2;
  35219. break;
  35220. case 0x04:
  35221. y -= code[i++];
  35222. break;
  35223. case 0x24:
  35224. y += code[i++];
  35225. break;
  35226. }
  35227. points[j].y = y;
  35228. }
  35229. var startPoint = 0;
  35230. for (i = 0; i < numberOfContours; i++) {
  35231. var endPoint = endPtsOfContours[i];
  35232. // contours might have implicit points, which is located in the middle
  35233. // between two neighboring off-curve points
  35234. var contour = points.slice(startPoint, endPoint + 1);
  35235. if (contour[0].flags & 1) {
  35236. contour.push(contour[0]);
  35237. } else // using start point at the contour end
  35238. if (contour[contour.length - 1].flags & 1) {
  35239. // first is off-curve point, trying to use one from the end
  35240. contour.unshift(contour[contour.length - 1]);
  35241. } else {
  35242. // start and end are off-curve points, creating implicit one
  35243. var p = {
  35244. flags: 1,
  35245. x: (contour[0].x + contour[contour.length - 1].x) / 2,
  35246. y: (contour[0].y + contour[contour.length - 1].y) / 2
  35247. };
  35248. contour.unshift(p);
  35249. contour.push(p);
  35250. }
  35251. moveTo(contour[0].x, contour[0].y);
  35252. for (j = 1, jj = contour.length; j < jj; j++) {
  35253. if (contour[j].flags & 1) {
  35254. lineTo(contour[j].x, contour[j].y);
  35255. } else if (contour[j + 1].flags & 1) {
  35256. quadraticCurveTo(contour[j].x, contour[j].y, contour[j + 1].x, contour[j + 1].y);
  35257. j++;
  35258. } else {
  35259. quadraticCurveTo(contour[j].x, contour[j].y, (contour[j].x + contour[j + 1].x) / 2, (contour[j].y + contour[j + 1].y) / 2);
  35260. }
  35261. }
  35262. startPoint = endPoint + 1;
  35263. }
  35264. }
  35265. }
  35266. function compileCharString(code, cmds, font) {
  35267. var stack = [];
  35268. var x = 0, y = 0;
  35269. var stems = 0;
  35270. function moveTo(x, y) {
  35271. cmds.push({
  35272. cmd: 'moveTo',
  35273. args: [
  35274. x,
  35275. y
  35276. ]
  35277. });
  35278. }
  35279. function lineTo(x, y) {
  35280. cmds.push({
  35281. cmd: 'lineTo',
  35282. args: [
  35283. x,
  35284. y
  35285. ]
  35286. });
  35287. }
  35288. function bezierCurveTo(x1, y1, x2, y2, x, y) {
  35289. cmds.push({
  35290. cmd: 'bezierCurveTo',
  35291. args: [
  35292. x1,
  35293. y1,
  35294. x2,
  35295. y2,
  35296. x,
  35297. y
  35298. ]
  35299. });
  35300. }
  35301. function parse(code) {
  35302. var i = 0;
  35303. while (i < code.length) {
  35304. var stackClean = false;
  35305. var v = code[i++];
  35306. var xa, xb, ya, yb, y1, y2, y3, n, subrCode;
  35307. switch (v) {
  35308. case 1:
  35309. // hstem
  35310. stems += stack.length >> 1;
  35311. stackClean = true;
  35312. break;
  35313. case 3:
  35314. // vstem
  35315. stems += stack.length >> 1;
  35316. stackClean = true;
  35317. break;
  35318. case 4:
  35319. // vmoveto
  35320. y += stack.pop();
  35321. moveTo(x, y);
  35322. stackClean = true;
  35323. break;
  35324. case 5:
  35325. // rlineto
  35326. while (stack.length > 0) {
  35327. x += stack.shift();
  35328. y += stack.shift();
  35329. lineTo(x, y);
  35330. }
  35331. break;
  35332. case 6:
  35333. // hlineto
  35334. while (stack.length > 0) {
  35335. x += stack.shift();
  35336. lineTo(x, y);
  35337. if (stack.length === 0) {
  35338. break;
  35339. }
  35340. y += stack.shift();
  35341. lineTo(x, y);
  35342. }
  35343. break;
  35344. case 7:
  35345. // vlineto
  35346. while (stack.length > 0) {
  35347. y += stack.shift();
  35348. lineTo(x, y);
  35349. if (stack.length === 0) {
  35350. break;
  35351. }
  35352. x += stack.shift();
  35353. lineTo(x, y);
  35354. }
  35355. break;
  35356. case 8:
  35357. // rrcurveto
  35358. while (stack.length > 0) {
  35359. xa = x + stack.shift();
  35360. ya = y + stack.shift();
  35361. xb = xa + stack.shift();
  35362. yb = ya + stack.shift();
  35363. x = xb + stack.shift();
  35364. y = yb + stack.shift();
  35365. bezierCurveTo(xa, ya, xb, yb, x, y);
  35366. }
  35367. break;
  35368. case 10:
  35369. // callsubr
  35370. n = stack.pop() + font.subrsBias;
  35371. subrCode = font.subrs[n];
  35372. if (subrCode) {
  35373. parse(subrCode);
  35374. }
  35375. break;
  35376. case 11:
  35377. // return
  35378. return;
  35379. case 12:
  35380. v = code[i++];
  35381. switch (v) {
  35382. case 34:
  35383. // flex
  35384. xa = x + stack.shift();
  35385. xb = xa + stack.shift();
  35386. y1 = y + stack.shift();
  35387. x = xb + stack.shift();
  35388. bezierCurveTo(xa, y, xb, y1, x, y1);
  35389. xa = x + stack.shift();
  35390. xb = xa + stack.shift();
  35391. x = xb + stack.shift();
  35392. bezierCurveTo(xa, y1, xb, y, x, y);
  35393. break;
  35394. case 35:
  35395. // flex
  35396. xa = x + stack.shift();
  35397. ya = y + stack.shift();
  35398. xb = xa + stack.shift();
  35399. yb = ya + stack.shift();
  35400. x = xb + stack.shift();
  35401. y = yb + stack.shift();
  35402. bezierCurveTo(xa, ya, xb, yb, x, y);
  35403. xa = x + stack.shift();
  35404. ya = y + stack.shift();
  35405. xb = xa + stack.shift();
  35406. yb = ya + stack.shift();
  35407. x = xb + stack.shift();
  35408. y = yb + stack.shift();
  35409. bezierCurveTo(xa, ya, xb, yb, x, y);
  35410. stack.pop();
  35411. // fd
  35412. break;
  35413. case 36:
  35414. // hflex1
  35415. xa = x + stack.shift();
  35416. y1 = y + stack.shift();
  35417. xb = xa + stack.shift();
  35418. y2 = y1 + stack.shift();
  35419. x = xb + stack.shift();
  35420. bezierCurveTo(xa, y1, xb, y2, x, y2);
  35421. xa = x + stack.shift();
  35422. xb = xa + stack.shift();
  35423. y3 = y2 + stack.shift();
  35424. x = xb + stack.shift();
  35425. bezierCurveTo(xa, y2, xb, y3, x, y);
  35426. break;
  35427. case 37:
  35428. // flex1
  35429. var x0 = x, y0 = y;
  35430. xa = x + stack.shift();
  35431. ya = y + stack.shift();
  35432. xb = xa + stack.shift();
  35433. yb = ya + stack.shift();
  35434. x = xb + stack.shift();
  35435. y = yb + stack.shift();
  35436. bezierCurveTo(xa, ya, xb, yb, x, y);
  35437. xa = x + stack.shift();
  35438. ya = y + stack.shift();
  35439. xb = xa + stack.shift();
  35440. yb = ya + stack.shift();
  35441. x = xb;
  35442. y = yb;
  35443. if (Math.abs(x - x0) > Math.abs(y - y0)) {
  35444. x += stack.shift();
  35445. } else {
  35446. y += stack.shift();
  35447. }
  35448. bezierCurveTo(xa, ya, xb, yb, x, y);
  35449. break;
  35450. default:
  35451. error('unknown operator: 12 ' + v);
  35452. }
  35453. break;
  35454. case 14:
  35455. // endchar
  35456. if (stack.length >= 4) {
  35457. var achar = stack.pop();
  35458. var bchar = stack.pop();
  35459. y = stack.pop();
  35460. x = stack.pop();
  35461. cmds.push({ cmd: 'save' });
  35462. cmds.push({
  35463. cmd: 'translate',
  35464. args: [
  35465. x,
  35466. y
  35467. ]
  35468. });
  35469. var cmap = lookupCmap(font.cmap, String.fromCharCode(font.glyphNameMap[StandardEncoding[achar]]));
  35470. compileCharString(font.glyphs[cmap.glyphId], cmds, font);
  35471. cmds.push({ cmd: 'restore' });
  35472. cmap = lookupCmap(font.cmap, String.fromCharCode(font.glyphNameMap[StandardEncoding[bchar]]));
  35473. compileCharString(font.glyphs[cmap.glyphId], cmds, font);
  35474. }
  35475. return;
  35476. case 18:
  35477. // hstemhm
  35478. stems += stack.length >> 1;
  35479. stackClean = true;
  35480. break;
  35481. case 19:
  35482. // hintmask
  35483. stems += stack.length >> 1;
  35484. i += stems + 7 >> 3;
  35485. stackClean = true;
  35486. break;
  35487. case 20:
  35488. // cntrmask
  35489. stems += stack.length >> 1;
  35490. i += stems + 7 >> 3;
  35491. stackClean = true;
  35492. break;
  35493. case 21:
  35494. // rmoveto
  35495. y += stack.pop();
  35496. x += stack.pop();
  35497. moveTo(x, y);
  35498. stackClean = true;
  35499. break;
  35500. case 22:
  35501. // hmoveto
  35502. x += stack.pop();
  35503. moveTo(x, y);
  35504. stackClean = true;
  35505. break;
  35506. case 23:
  35507. // vstemhm
  35508. stems += stack.length >> 1;
  35509. stackClean = true;
  35510. break;
  35511. case 24:
  35512. // rcurveline
  35513. while (stack.length > 2) {
  35514. xa = x + stack.shift();
  35515. ya = y + stack.shift();
  35516. xb = xa + stack.shift();
  35517. yb = ya + stack.shift();
  35518. x = xb + stack.shift();
  35519. y = yb + stack.shift();
  35520. bezierCurveTo(xa, ya, xb, yb, x, y);
  35521. }
  35522. x += stack.shift();
  35523. y += stack.shift();
  35524. lineTo(x, y);
  35525. break;
  35526. case 25:
  35527. // rlinecurve
  35528. while (stack.length > 6) {
  35529. x += stack.shift();
  35530. y += stack.shift();
  35531. lineTo(x, y);
  35532. }
  35533. xa = x + stack.shift();
  35534. ya = y + stack.shift();
  35535. xb = xa + stack.shift();
  35536. yb = ya + stack.shift();
  35537. x = xb + stack.shift();
  35538. y = yb + stack.shift();
  35539. bezierCurveTo(xa, ya, xb, yb, x, y);
  35540. break;
  35541. case 26:
  35542. // vvcurveto
  35543. if (stack.length % 2) {
  35544. x += stack.shift();
  35545. }
  35546. while (stack.length > 0) {
  35547. xa = x;
  35548. ya = y + stack.shift();
  35549. xb = xa + stack.shift();
  35550. yb = ya + stack.shift();
  35551. x = xb;
  35552. y = yb + stack.shift();
  35553. bezierCurveTo(xa, ya, xb, yb, x, y);
  35554. }
  35555. break;
  35556. case 27:
  35557. // hhcurveto
  35558. if (stack.length % 2) {
  35559. y += stack.shift();
  35560. }
  35561. while (stack.length > 0) {
  35562. xa = x + stack.shift();
  35563. ya = y;
  35564. xb = xa + stack.shift();
  35565. yb = ya + stack.shift();
  35566. x = xb + stack.shift();
  35567. y = yb;
  35568. bezierCurveTo(xa, ya, xb, yb, x, y);
  35569. }
  35570. break;
  35571. case 28:
  35572. stack.push((code[i] << 24 | code[i + 1] << 16) >> 16);
  35573. i += 2;
  35574. break;
  35575. case 29:
  35576. // callgsubr
  35577. n = stack.pop() + font.gsubrsBias;
  35578. subrCode = font.gsubrs[n];
  35579. if (subrCode) {
  35580. parse(subrCode);
  35581. }
  35582. break;
  35583. case 30:
  35584. // vhcurveto
  35585. while (stack.length > 0) {
  35586. xa = x;
  35587. ya = y + stack.shift();
  35588. xb = xa + stack.shift();
  35589. yb = ya + stack.shift();
  35590. x = xb + stack.shift();
  35591. y = yb + (stack.length === 1 ? stack.shift() : 0);
  35592. bezierCurveTo(xa, ya, xb, yb, x, y);
  35593. if (stack.length === 0) {
  35594. break;
  35595. }
  35596. xa = x + stack.shift();
  35597. ya = y;
  35598. xb = xa + stack.shift();
  35599. yb = ya + stack.shift();
  35600. y = yb + stack.shift();
  35601. x = xb + (stack.length === 1 ? stack.shift() : 0);
  35602. bezierCurveTo(xa, ya, xb, yb, x, y);
  35603. }
  35604. break;
  35605. case 31:
  35606. // hvcurveto
  35607. while (stack.length > 0) {
  35608. xa = x + stack.shift();
  35609. ya = y;
  35610. xb = xa + stack.shift();
  35611. yb = ya + stack.shift();
  35612. y = yb + stack.shift();
  35613. x = xb + (stack.length === 1 ? stack.shift() : 0);
  35614. bezierCurveTo(xa, ya, xb, yb, x, y);
  35615. if (stack.length === 0) {
  35616. break;
  35617. }
  35618. xa = x;
  35619. ya = y + stack.shift();
  35620. xb = xa + stack.shift();
  35621. yb = ya + stack.shift();
  35622. x = xb + stack.shift();
  35623. y = yb + (stack.length === 1 ? stack.shift() : 0);
  35624. bezierCurveTo(xa, ya, xb, yb, x, y);
  35625. }
  35626. break;
  35627. default:
  35628. if (v < 32) {
  35629. error('unknown operator: ' + v);
  35630. }
  35631. if (v < 247) {
  35632. stack.push(v - 139);
  35633. } else if (v < 251) {
  35634. stack.push((v - 247) * 256 + code[i++] + 108);
  35635. } else if (v < 255) {
  35636. stack.push(-(v - 251) * 256 - code[i++] - 108);
  35637. } else {
  35638. stack.push((code[i] << 24 | code[i + 1] << 16 | code[i + 2] << 8 | code[i + 3]) / 65536);
  35639. i += 4;
  35640. }
  35641. break;
  35642. }
  35643. if (stackClean) {
  35644. stack.length = 0;
  35645. }
  35646. }
  35647. }
  35648. parse(code);
  35649. }
  35650. var noop = '';
  35651. function CompiledFont(fontMatrix) {
  35652. this.compiledGlyphs = Object.create(null);
  35653. this.compiledCharCodeToGlyphId = Object.create(null);
  35654. this.fontMatrix = fontMatrix;
  35655. }
  35656. CompiledFont.prototype = {
  35657. getPathJs: function (unicode) {
  35658. var cmap = lookupCmap(this.cmap, unicode);
  35659. var fn = this.compiledGlyphs[cmap.glyphId];
  35660. if (!fn) {
  35661. fn = this.compileGlyph(this.glyphs[cmap.glyphId]);
  35662. this.compiledGlyphs[cmap.glyphId] = fn;
  35663. }
  35664. if (this.compiledCharCodeToGlyphId[cmap.charCode] === undefined) {
  35665. this.compiledCharCodeToGlyphId[cmap.charCode] = cmap.glyphId;
  35666. }
  35667. return fn;
  35668. },
  35669. compileGlyph: function (code) {
  35670. if (!code || code.length === 0 || code[0] === 14) {
  35671. return noop;
  35672. }
  35673. var cmds = [];
  35674. cmds.push({ cmd: 'save' });
  35675. cmds.push({
  35676. cmd: 'transform',
  35677. args: this.fontMatrix.slice()
  35678. });
  35679. cmds.push({
  35680. cmd: 'scale',
  35681. args: [
  35682. 'size',
  35683. '-size'
  35684. ]
  35685. });
  35686. this.compileGlyphImpl(code, cmds);
  35687. cmds.push({ cmd: 'restore' });
  35688. return cmds;
  35689. },
  35690. compileGlyphImpl: function () {
  35691. error('Children classes should implement this.');
  35692. },
  35693. hasBuiltPath: function (unicode) {
  35694. var cmap = lookupCmap(this.cmap, unicode);
  35695. return this.compiledGlyphs[cmap.glyphId] !== undefined && this.compiledCharCodeToGlyphId[cmap.charCode] !== undefined;
  35696. }
  35697. };
  35698. function TrueTypeCompiled(glyphs, cmap, fontMatrix) {
  35699. fontMatrix = fontMatrix || [
  35700. 0.000488,
  35701. 0,
  35702. 0,
  35703. 0.000488,
  35704. 0,
  35705. 0
  35706. ];
  35707. CompiledFont.call(this, fontMatrix);
  35708. this.glyphs = glyphs;
  35709. this.cmap = cmap;
  35710. }
  35711. Util.inherit(TrueTypeCompiled, CompiledFont, {
  35712. compileGlyphImpl: function (code, cmds) {
  35713. compileGlyf(code, cmds, this);
  35714. }
  35715. });
  35716. function Type2Compiled(cffInfo, cmap, fontMatrix, glyphNameMap) {
  35717. fontMatrix = fontMatrix || [
  35718. 0.001,
  35719. 0,
  35720. 0,
  35721. 0.001,
  35722. 0,
  35723. 0
  35724. ];
  35725. CompiledFont.call(this, fontMatrix);
  35726. this.glyphs = cffInfo.glyphs;
  35727. this.gsubrs = cffInfo.gsubrs || [];
  35728. this.subrs = cffInfo.subrs || [];
  35729. this.cmap = cmap;
  35730. this.glyphNameMap = glyphNameMap || getGlyphsUnicode();
  35731. this.gsubrsBias = this.gsubrs.length < 1240 ? 107 : this.gsubrs.length < 33900 ? 1131 : 32768;
  35732. this.subrsBias = this.subrs.length < 1240 ? 107 : this.subrs.length < 33900 ? 1131 : 32768;
  35733. }
  35734. Util.inherit(Type2Compiled, CompiledFont, {
  35735. compileGlyphImpl: function (code, cmds) {
  35736. compileCharString(code, cmds, this);
  35737. }
  35738. });
  35739. return {
  35740. create: function FontRendererFactory_create(font, seacAnalysisEnabled) {
  35741. var data = new Uint8Array(font.data);
  35742. var cmap, glyf, loca, cff, indexToLocFormat, unitsPerEm;
  35743. var numTables = getUshort(data, 4);
  35744. for (var i = 0, p = 12; i < numTables; i++, p += 16) {
  35745. var tag = bytesToString(data.subarray(p, p + 4));
  35746. var offset = getLong(data, p + 8);
  35747. var length = getLong(data, p + 12);
  35748. switch (tag) {
  35749. case 'cmap':
  35750. cmap = parseCmap(data, offset, offset + length);
  35751. break;
  35752. case 'glyf':
  35753. glyf = data.subarray(offset, offset + length);
  35754. break;
  35755. case 'loca':
  35756. loca = data.subarray(offset, offset + length);
  35757. break;
  35758. case 'head':
  35759. unitsPerEm = getUshort(data, offset + 18);
  35760. indexToLocFormat = getUshort(data, offset + 50);
  35761. break;
  35762. case 'CFF ':
  35763. cff = parseCff(data, offset, offset + length, seacAnalysisEnabled);
  35764. break;
  35765. }
  35766. }
  35767. if (glyf) {
  35768. var fontMatrix = !unitsPerEm ? font.fontMatrix : [
  35769. 1 / unitsPerEm,
  35770. 0,
  35771. 0,
  35772. 1 / unitsPerEm,
  35773. 0,
  35774. 0
  35775. ];
  35776. return new TrueTypeCompiled(parseGlyfTable(glyf, loca, indexToLocFormat), cmap, fontMatrix);
  35777. } else {
  35778. return new Type2Compiled(cff, cmap, font.fontMatrix, font.glyphNameMap);
  35779. }
  35780. }
  35781. };
  35782. }();
  35783. exports.FontRendererFactory = FontRendererFactory;
  35784. }));
  35785. (function (root, factory) {
  35786. factory(root.pdfjsCoreParser = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCoreStream);
  35787. }(this, function (exports, sharedUtil, corePrimitives, coreStream) {
  35788. var MissingDataException = sharedUtil.MissingDataException;
  35789. var StreamType = sharedUtil.StreamType;
  35790. var assert = sharedUtil.assert;
  35791. var error = sharedUtil.error;
  35792. var info = sharedUtil.info;
  35793. var isArray = sharedUtil.isArray;
  35794. var isInt = sharedUtil.isInt;
  35795. var isNum = sharedUtil.isNum;
  35796. var isString = sharedUtil.isString;
  35797. var warn = sharedUtil.warn;
  35798. var Cmd = corePrimitives.Cmd;
  35799. var Dict = corePrimitives.Dict;
  35800. var Name = corePrimitives.Name;
  35801. var Ref = corePrimitives.Ref;
  35802. var isCmd = corePrimitives.isCmd;
  35803. var isDict = corePrimitives.isDict;
  35804. var isName = corePrimitives.isName;
  35805. var Ascii85Stream = coreStream.Ascii85Stream;
  35806. var AsciiHexStream = coreStream.AsciiHexStream;
  35807. var CCITTFaxStream = coreStream.CCITTFaxStream;
  35808. var FlateStream = coreStream.FlateStream;
  35809. var Jbig2Stream = coreStream.Jbig2Stream;
  35810. var JpegStream = coreStream.JpegStream;
  35811. var JpxStream = coreStream.JpxStream;
  35812. var LZWStream = coreStream.LZWStream;
  35813. var NullStream = coreStream.NullStream;
  35814. var PredictorStream = coreStream.PredictorStream;
  35815. var RunLengthStream = coreStream.RunLengthStream;
  35816. var EOF = {};
  35817. function isEOF(v) {
  35818. return v === EOF;
  35819. }
  35820. var MAX_LENGTH_TO_CACHE = 1000;
  35821. var Parser = function ParserClosure() {
  35822. function Parser(lexer, allowStreams, xref, recoveryMode) {
  35823. this.lexer = lexer;
  35824. this.allowStreams = allowStreams;
  35825. this.xref = xref;
  35826. this.recoveryMode = recoveryMode || false;
  35827. this.imageCache = Object.create(null);
  35828. this.refill();
  35829. }
  35830. Parser.prototype = {
  35831. refill: function Parser_refill() {
  35832. this.buf1 = this.lexer.getObj();
  35833. this.buf2 = this.lexer.getObj();
  35834. },
  35835. shift: function Parser_shift() {
  35836. if (isCmd(this.buf2, 'ID')) {
  35837. this.buf1 = this.buf2;
  35838. this.buf2 = null;
  35839. } else {
  35840. this.buf1 = this.buf2;
  35841. this.buf2 = this.lexer.getObj();
  35842. }
  35843. },
  35844. tryShift: function Parser_tryShift() {
  35845. try {
  35846. this.shift();
  35847. return true;
  35848. } catch (e) {
  35849. if (e instanceof MissingDataException) {
  35850. throw e;
  35851. }
  35852. // Upon failure, the caller should reset this.lexer.pos to a known good
  35853. // state and call this.shift() twice to reset the buffers.
  35854. return false;
  35855. }
  35856. },
  35857. getObj: function Parser_getObj(cipherTransform) {
  35858. var buf1 = this.buf1;
  35859. this.shift();
  35860. if (buf1 instanceof Cmd) {
  35861. switch (buf1.cmd) {
  35862. case 'BI':
  35863. // inline image
  35864. return this.makeInlineImage(cipherTransform);
  35865. case '[':
  35866. // array
  35867. var array = [];
  35868. while (!isCmd(this.buf1, ']') && !isEOF(this.buf1)) {
  35869. array.push(this.getObj(cipherTransform));
  35870. }
  35871. if (isEOF(this.buf1)) {
  35872. if (!this.recoveryMode) {
  35873. error('End of file inside array');
  35874. }
  35875. return array;
  35876. }
  35877. this.shift();
  35878. return array;
  35879. case '<<':
  35880. // dictionary or stream
  35881. var dict = new Dict(this.xref);
  35882. while (!isCmd(this.buf1, '>>') && !isEOF(this.buf1)) {
  35883. if (!isName(this.buf1)) {
  35884. info('Malformed dictionary: key must be a name object');
  35885. this.shift();
  35886. continue;
  35887. }
  35888. var key = this.buf1.name;
  35889. this.shift();
  35890. if (isEOF(this.buf1)) {
  35891. break;
  35892. }
  35893. dict.set(key, this.getObj(cipherTransform));
  35894. }
  35895. if (isEOF(this.buf1)) {
  35896. if (!this.recoveryMode) {
  35897. error('End of file inside dictionary');
  35898. }
  35899. return dict;
  35900. }
  35901. // Stream objects are not allowed inside content streams or
  35902. // object streams.
  35903. if (isCmd(this.buf2, 'stream')) {
  35904. return this.allowStreams ? this.makeStream(dict, cipherTransform) : dict;
  35905. }
  35906. this.shift();
  35907. return dict;
  35908. default:
  35909. // simple object
  35910. return buf1;
  35911. }
  35912. }
  35913. if (isInt(buf1)) {
  35914. // indirect reference or integer
  35915. var num = buf1;
  35916. if (isInt(this.buf1) && isCmd(this.buf2, 'R')) {
  35917. var ref = new Ref(num, this.buf1);
  35918. this.shift();
  35919. this.shift();
  35920. return ref;
  35921. }
  35922. return num;
  35923. }
  35924. if (isString(buf1)) {
  35925. // string
  35926. var str = buf1;
  35927. if (cipherTransform) {
  35928. str = cipherTransform.decryptString(str);
  35929. }
  35930. return str;
  35931. }
  35932. // simple object
  35933. return buf1;
  35934. },
  35935. /**
  35936. * Find the end of the stream by searching for the /EI\s/.
  35937. * @returns {number} The inline stream length.
  35938. */
  35939. findDefaultInlineStreamEnd: function Parser_findDefaultInlineStreamEnd(stream) {
  35940. var E = 0x45, I = 0x49, SPACE = 0x20, LF = 0xA, CR = 0xD;
  35941. var startPos = stream.pos, state = 0, ch, i, n, followingBytes;
  35942. while ((ch = stream.getByte()) !== -1) {
  35943. if (state === 0) {
  35944. state = ch === E ? 1 : 0;
  35945. } else if (state === 1) {
  35946. state = ch === I ? 2 : 0;
  35947. } else {
  35948. assert(state === 2);
  35949. if (ch === SPACE || ch === LF || ch === CR) {
  35950. // Let's check the next five bytes are ASCII... just be sure.
  35951. n = 5;
  35952. followingBytes = stream.peekBytes(n);
  35953. for (i = 0; i < n; i++) {
  35954. ch = followingBytes[i];
  35955. if (ch !== LF && ch !== CR && (ch < SPACE || ch > 0x7F)) {
  35956. // Not a LF, CR, SPACE or any visible ASCII character, i.e.
  35957. // it's binary stuff. Resetting the state.
  35958. state = 0;
  35959. break;
  35960. }
  35961. }
  35962. if (state === 2) {
  35963. break;
  35964. }
  35965. } else
  35966. // Finished!
  35967. {
  35968. state = 0;
  35969. }
  35970. }
  35971. }
  35972. return stream.pos - 4 - startPos;
  35973. },
  35974. /**
  35975. * Find the EOI (end-of-image) marker 0xFFD9 of the stream.
  35976. * @returns {number} The inline stream length.
  35977. */
  35978. findDCTDecodeInlineStreamEnd: function Parser_findDCTDecodeInlineStreamEnd(stream) {
  35979. var startPos = stream.pos, foundEOI = false, b, markerLength, length;
  35980. while ((b = stream.getByte()) !== -1) {
  35981. if (b !== 0xFF) {
  35982. // Not a valid marker.
  35983. continue;
  35984. }
  35985. switch (stream.getByte()) {
  35986. case 0x00:
  35987. // Byte stuffing.
  35988. // 0xFF00 appears to be a very common byte sequence in JPEG images.
  35989. break;
  35990. case 0xFF:
  35991. // Fill byte.
  35992. // Avoid skipping a valid marker, resetting the stream position.
  35993. stream.skip(-1);
  35994. break;
  35995. case 0xD9:
  35996. // EOI
  35997. foundEOI = true;
  35998. break;
  35999. case 0xC0:
  36000. // SOF0
  36001. case 0xC1:
  36002. // SOF1
  36003. case 0xC2:
  36004. // SOF2
  36005. case 0xC3:
  36006. // SOF3
  36007. case 0xC5:
  36008. // SOF5
  36009. case 0xC6:
  36010. // SOF6
  36011. case 0xC7:
  36012. // SOF7
  36013. case 0xC9:
  36014. // SOF9
  36015. case 0xCA:
  36016. // SOF10
  36017. case 0xCB:
  36018. // SOF11
  36019. case 0xCD:
  36020. // SOF13
  36021. case 0xCE:
  36022. // SOF14
  36023. case 0xCF:
  36024. // SOF15
  36025. case 0xC4:
  36026. // DHT
  36027. case 0xCC:
  36028. // DAC
  36029. case 0xDA:
  36030. // SOS
  36031. case 0xDB:
  36032. // DQT
  36033. case 0xDC:
  36034. // DNL
  36035. case 0xDD:
  36036. // DRI
  36037. case 0xDE:
  36038. // DHP
  36039. case 0xDF:
  36040. // EXP
  36041. case 0xE0:
  36042. // APP0
  36043. case 0xE1:
  36044. // APP1
  36045. case 0xE2:
  36046. // APP2
  36047. case 0xE3:
  36048. // APP3
  36049. case 0xE4:
  36050. // APP4
  36051. case 0xE5:
  36052. // APP5
  36053. case 0xE6:
  36054. // APP6
  36055. case 0xE7:
  36056. // APP7
  36057. case 0xE8:
  36058. // APP8
  36059. case 0xE9:
  36060. // APP9
  36061. case 0xEA:
  36062. // APP10
  36063. case 0xEB:
  36064. // APP11
  36065. case 0xEC:
  36066. // APP12
  36067. case 0xED:
  36068. // APP13
  36069. case 0xEE:
  36070. // APP14
  36071. case 0xEF:
  36072. // APP15
  36073. case 0xFE:
  36074. // COM
  36075. // The marker should be followed by the length of the segment.
  36076. markerLength = stream.getUint16();
  36077. if (markerLength > 2) {
  36078. // |markerLength| contains the byte length of the marker segment,
  36079. // including its own length (2 bytes) and excluding the marker.
  36080. stream.skip(markerLength - 2);
  36081. } else
  36082. // Jump to the next marker.
  36083. {
  36084. // The marker length is invalid, resetting the stream position.
  36085. stream.skip(-2);
  36086. }
  36087. break;
  36088. }
  36089. if (foundEOI) {
  36090. break;
  36091. }
  36092. }
  36093. length = stream.pos - startPos;
  36094. if (b === -1) {
  36095. warn('Inline DCTDecode image stream: ' + 'EOI marker not found, searching for /EI/ instead.');
  36096. stream.skip(-length);
  36097. // Reset the stream position.
  36098. return this.findDefaultInlineStreamEnd(stream);
  36099. }
  36100. this.inlineStreamSkipEI(stream);
  36101. return length;
  36102. },
  36103. /**
  36104. * Find the EOD (end-of-data) marker '~>' (i.e. TILDE + GT) of the stream.
  36105. * @returns {number} The inline stream length.
  36106. */
  36107. findASCII85DecodeInlineStreamEnd: function Parser_findASCII85DecodeInlineStreamEnd(stream) {
  36108. var TILDE = 0x7E, GT = 0x3E;
  36109. var startPos = stream.pos, ch, length;
  36110. while ((ch = stream.getByte()) !== -1) {
  36111. if (ch === TILDE && stream.peekByte() === GT) {
  36112. stream.skip();
  36113. break;
  36114. }
  36115. }
  36116. length = stream.pos - startPos;
  36117. if (ch === -1) {
  36118. warn('Inline ASCII85Decode image stream: ' + 'EOD marker not found, searching for /EI/ instead.');
  36119. stream.skip(-length);
  36120. // Reset the stream position.
  36121. return this.findDefaultInlineStreamEnd(stream);
  36122. }
  36123. this.inlineStreamSkipEI(stream);
  36124. return length;
  36125. },
  36126. /**
  36127. * Find the EOD (end-of-data) marker '>' (i.e. GT) of the stream.
  36128. * @returns {number} The inline stream length.
  36129. */
  36130. findASCIIHexDecodeInlineStreamEnd: function Parser_findASCIIHexDecodeInlineStreamEnd(stream) {
  36131. var GT = 0x3E;
  36132. var startPos = stream.pos, ch, length;
  36133. while ((ch = stream.getByte()) !== -1) {
  36134. if (ch === GT) {
  36135. break;
  36136. }
  36137. }
  36138. length = stream.pos - startPos;
  36139. if (ch === -1) {
  36140. warn('Inline ASCIIHexDecode image stream: ' + 'EOD marker not found, searching for /EI/ instead.');
  36141. stream.skip(-length);
  36142. // Reset the stream position.
  36143. return this.findDefaultInlineStreamEnd(stream);
  36144. }
  36145. this.inlineStreamSkipEI(stream);
  36146. return length;
  36147. },
  36148. /**
  36149. * Skip over the /EI/ for streams where we search for an EOD marker.
  36150. */
  36151. inlineStreamSkipEI: function Parser_inlineStreamSkipEI(stream) {
  36152. var E = 0x45, I = 0x49;
  36153. var state = 0, ch;
  36154. while ((ch = stream.getByte()) !== -1) {
  36155. if (state === 0) {
  36156. state = ch === E ? 1 : 0;
  36157. } else if (state === 1) {
  36158. state = ch === I ? 2 : 0;
  36159. } else if (state === 2) {
  36160. break;
  36161. }
  36162. }
  36163. },
  36164. makeInlineImage: function Parser_makeInlineImage(cipherTransform) {
  36165. var lexer = this.lexer;
  36166. var stream = lexer.stream;
  36167. // Parse dictionary.
  36168. var dict = new Dict(this.xref);
  36169. while (!isCmd(this.buf1, 'ID') && !isEOF(this.buf1)) {
  36170. if (!isName(this.buf1)) {
  36171. error('Dictionary key must be a name object');
  36172. }
  36173. var key = this.buf1.name;
  36174. this.shift();
  36175. if (isEOF(this.buf1)) {
  36176. break;
  36177. }
  36178. dict.set(key, this.getObj(cipherTransform));
  36179. }
  36180. // Extract the name of the first (i.e. the current) image filter.
  36181. var filter = dict.get('Filter', 'F'), filterName;
  36182. if (isName(filter)) {
  36183. filterName = filter.name;
  36184. } else if (isArray(filter) && isName(filter[0])) {
  36185. filterName = filter[0].name;
  36186. }
  36187. // Parse image stream.
  36188. var startPos = stream.pos, length, i, ii;
  36189. if (filterName === 'DCTDecode' || filterName === 'DCT') {
  36190. length = this.findDCTDecodeInlineStreamEnd(stream);
  36191. } else if (filterName === 'ASCII85Decide' || filterName === 'A85') {
  36192. length = this.findASCII85DecodeInlineStreamEnd(stream);
  36193. } else if (filterName === 'ASCIIHexDecode' || filterName === 'AHx') {
  36194. length = this.findASCIIHexDecodeInlineStreamEnd(stream);
  36195. } else {
  36196. length = this.findDefaultInlineStreamEnd(stream);
  36197. }
  36198. var imageStream = stream.makeSubStream(startPos, length, dict);
  36199. // Cache all images below the MAX_LENGTH_TO_CACHE threshold by their
  36200. // adler32 checksum.
  36201. var adler32;
  36202. if (length < MAX_LENGTH_TO_CACHE) {
  36203. var imageBytes = imageStream.getBytes();
  36204. imageStream.reset();
  36205. var a = 1;
  36206. var b = 0;
  36207. for (i = 0, ii = imageBytes.length; i < ii; ++i) {
  36208. // No modulo required in the loop if imageBytes.length < 5552.
  36209. a += imageBytes[i] & 0xff;
  36210. b += a;
  36211. }
  36212. adler32 = b % 65521 << 16 | a % 65521;
  36213. if (this.imageCache.adler32 === adler32) {
  36214. this.buf2 = Cmd.get('EI');
  36215. this.shift();
  36216. this.imageCache[adler32].reset();
  36217. return this.imageCache[adler32];
  36218. }
  36219. }
  36220. if (cipherTransform) {
  36221. imageStream = cipherTransform.createStream(imageStream, length);
  36222. }
  36223. imageStream = this.filter(imageStream, dict, length);
  36224. imageStream.dict = dict;
  36225. if (adler32 !== undefined) {
  36226. imageStream.cacheKey = 'inline_' + length + '_' + adler32;
  36227. this.imageCache[adler32] = imageStream;
  36228. }
  36229. this.buf2 = Cmd.get('EI');
  36230. this.shift();
  36231. return imageStream;
  36232. },
  36233. makeStream: function Parser_makeStream(dict, cipherTransform) {
  36234. var lexer = this.lexer;
  36235. var stream = lexer.stream;
  36236. // get stream start position
  36237. lexer.skipToNextLine();
  36238. var pos = stream.pos - 1;
  36239. // get length
  36240. var length = dict.get('Length');
  36241. if (!isInt(length)) {
  36242. info('Bad ' + length + ' attribute in stream');
  36243. length = 0;
  36244. }
  36245. // skip over the stream data
  36246. stream.pos = pos + length;
  36247. lexer.nextChar();
  36248. // Shift '>>' and check whether the new object marks the end of the stream
  36249. if (this.tryShift() && isCmd(this.buf2, 'endstream')) {
  36250. this.shift();
  36251. } else
  36252. // 'stream'
  36253. {
  36254. // bad stream length, scanning for endstream
  36255. stream.pos = pos;
  36256. var SCAN_BLOCK_SIZE = 2048;
  36257. var ENDSTREAM_SIGNATURE_LENGTH = 9;
  36258. var ENDSTREAM_SIGNATURE = [
  36259. 0x65,
  36260. 0x6E,
  36261. 0x64,
  36262. 0x73,
  36263. 0x74,
  36264. 0x72,
  36265. 0x65,
  36266. 0x61,
  36267. 0x6D
  36268. ];
  36269. var skipped = 0, found = false, i, j;
  36270. while (stream.pos < stream.end) {
  36271. var scanBytes = stream.peekBytes(SCAN_BLOCK_SIZE);
  36272. var scanLength = scanBytes.length - ENDSTREAM_SIGNATURE_LENGTH;
  36273. if (scanLength <= 0) {
  36274. break;
  36275. }
  36276. found = false;
  36277. i = 0;
  36278. while (i < scanLength) {
  36279. j = 0;
  36280. while (j < ENDSTREAM_SIGNATURE_LENGTH && scanBytes[i + j] === ENDSTREAM_SIGNATURE[j]) {
  36281. j++;
  36282. }
  36283. if (j >= ENDSTREAM_SIGNATURE_LENGTH) {
  36284. found = true;
  36285. break;
  36286. }
  36287. i++;
  36288. }
  36289. if (found) {
  36290. skipped += i;
  36291. stream.pos += i;
  36292. break;
  36293. }
  36294. skipped += scanLength;
  36295. stream.pos += scanLength;
  36296. }
  36297. if (!found) {
  36298. error('Missing endstream');
  36299. }
  36300. length = skipped;
  36301. lexer.nextChar();
  36302. this.shift();
  36303. this.shift();
  36304. }
  36305. this.shift();
  36306. // 'endstream'
  36307. stream = stream.makeSubStream(pos, length, dict);
  36308. if (cipherTransform) {
  36309. stream = cipherTransform.createStream(stream, length);
  36310. }
  36311. stream = this.filter(stream, dict, length);
  36312. stream.dict = dict;
  36313. return stream;
  36314. },
  36315. filter: function Parser_filter(stream, dict, length) {
  36316. var filter = dict.get('Filter', 'F');
  36317. var params = dict.get('DecodeParms', 'DP');
  36318. if (isName(filter)) {
  36319. if (isArray(params)) {
  36320. params = params[0];
  36321. }
  36322. return this.makeFilter(stream, filter.name, length, params);
  36323. }
  36324. var maybeLength = length;
  36325. if (isArray(filter)) {
  36326. var filterArray = filter;
  36327. var paramsArray = params;
  36328. for (var i = 0, ii = filterArray.length; i < ii; ++i) {
  36329. filter = filterArray[i];
  36330. if (!isName(filter)) {
  36331. error('Bad filter name: ' + filter);
  36332. }
  36333. params = null;
  36334. if (isArray(paramsArray) && i in paramsArray) {
  36335. params = paramsArray[i];
  36336. }
  36337. stream = this.makeFilter(stream, filter.name, maybeLength, params);
  36338. // after the first stream the length variable is invalid
  36339. maybeLength = null;
  36340. }
  36341. }
  36342. return stream;
  36343. },
  36344. makeFilter: function Parser_makeFilter(stream, name, maybeLength, params) {
  36345. // Since the 'Length' entry in the stream dictionary can be completely
  36346. // wrong, e.g. zero for non-empty streams, only skip parsing the stream
  36347. // when we can be absolutely certain that it actually is empty.
  36348. if (maybeLength === 0) {
  36349. warn('Empty "' + name + '" stream.');
  36350. return new NullStream(stream);
  36351. }
  36352. try {
  36353. if (params && this.xref) {
  36354. params = this.xref.fetchIfRef(params);
  36355. }
  36356. var xrefStreamStats = this.xref.stats.streamTypes;
  36357. if (name === 'FlateDecode' || name === 'Fl') {
  36358. xrefStreamStats[StreamType.FLATE] = true;
  36359. if (params) {
  36360. return new PredictorStream(new FlateStream(stream, maybeLength), maybeLength, params);
  36361. }
  36362. return new FlateStream(stream, maybeLength);
  36363. }
  36364. if (name === 'LZWDecode' || name === 'LZW') {
  36365. xrefStreamStats[StreamType.LZW] = true;
  36366. var earlyChange = 1;
  36367. if (params) {
  36368. if (params.has('EarlyChange')) {
  36369. earlyChange = params.get('EarlyChange');
  36370. }
  36371. return new PredictorStream(new LZWStream(stream, maybeLength, earlyChange), maybeLength, params);
  36372. }
  36373. return new LZWStream(stream, maybeLength, earlyChange);
  36374. }
  36375. if (name === 'DCTDecode' || name === 'DCT') {
  36376. xrefStreamStats[StreamType.DCT] = true;
  36377. return new JpegStream(stream, maybeLength, stream.dict, params);
  36378. }
  36379. if (name === 'JPXDecode' || name === 'JPX') {
  36380. xrefStreamStats[StreamType.JPX] = true;
  36381. return new JpxStream(stream, maybeLength, stream.dict, params);
  36382. }
  36383. if (name === 'ASCII85Decode' || name === 'A85') {
  36384. xrefStreamStats[StreamType.A85] = true;
  36385. return new Ascii85Stream(stream, maybeLength);
  36386. }
  36387. if (name === 'ASCIIHexDecode' || name === 'AHx') {
  36388. xrefStreamStats[StreamType.AHX] = true;
  36389. return new AsciiHexStream(stream, maybeLength);
  36390. }
  36391. if (name === 'CCITTFaxDecode' || name === 'CCF') {
  36392. xrefStreamStats[StreamType.CCF] = true;
  36393. return new CCITTFaxStream(stream, maybeLength, params);
  36394. }
  36395. if (name === 'RunLengthDecode' || name === 'RL') {
  36396. xrefStreamStats[StreamType.RL] = true;
  36397. return new RunLengthStream(stream, maybeLength);
  36398. }
  36399. if (name === 'JBIG2Decode') {
  36400. xrefStreamStats[StreamType.JBIG] = true;
  36401. return new Jbig2Stream(stream, maybeLength, stream.dict, params);
  36402. }
  36403. warn('filter "' + name + '" not supported yet');
  36404. return stream;
  36405. } catch (ex) {
  36406. if (ex instanceof MissingDataException) {
  36407. throw ex;
  36408. }
  36409. warn('Invalid stream: \"' + ex + '\"');
  36410. return new NullStream(stream);
  36411. }
  36412. }
  36413. };
  36414. return Parser;
  36415. }();
  36416. var Lexer = function LexerClosure() {
  36417. function Lexer(stream, knownCommands) {
  36418. this.stream = stream;
  36419. this.nextChar();
  36420. // While lexing, we build up many strings one char at a time. Using += for
  36421. // this can result in lots of garbage strings. It's better to build an
  36422. // array of single-char strings and then join() them together at the end.
  36423. // And reusing a single array (i.e. |this.strBuf|) over and over for this
  36424. // purpose uses less memory than using a new array for each string.
  36425. this.strBuf = [];
  36426. // The PDFs might have "glued" commands with other commands, operands or
  36427. // literals, e.g. "q1". The knownCommands is a dictionary of the valid
  36428. // commands and their prefixes. The prefixes are built the following way:
  36429. // if there a command that is a prefix of the other valid command or
  36430. // literal (e.g. 'f' and 'false') the following prefixes must be included,
  36431. // 'fa', 'fal', 'fals'. The prefixes are not needed, if the command has no
  36432. // other commands or literals as a prefix. The knowCommands is optional.
  36433. this.knownCommands = knownCommands;
  36434. }
  36435. // A '1' in this array means the character is white space. A '1' or
  36436. // '2' means the character ends a name or command.
  36437. var specialChars = [
  36438. 1,
  36439. 0,
  36440. 0,
  36441. 0,
  36442. 0,
  36443. 0,
  36444. 0,
  36445. 0,
  36446. 0,
  36447. 1,
  36448. 1,
  36449. 0,
  36450. 1,
  36451. 1,
  36452. 0,
  36453. 0,
  36454. // 0x
  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. 0,
  36469. 0,
  36470. 0,
  36471. // 1x
  36472. 1,
  36473. 0,
  36474. 0,
  36475. 0,
  36476. 0,
  36477. 2,
  36478. 0,
  36479. 0,
  36480. 2,
  36481. 2,
  36482. 0,
  36483. 0,
  36484. 0,
  36485. 0,
  36486. 0,
  36487. 2,
  36488. // 2x
  36489. 0,
  36490. 0,
  36491. 0,
  36492. 0,
  36493. 0,
  36494. 0,
  36495. 0,
  36496. 0,
  36497. 0,
  36498. 0,
  36499. 0,
  36500. 0,
  36501. 2,
  36502. 0,
  36503. 2,
  36504. 0,
  36505. // 3x
  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. 0,
  36520. 0,
  36521. 0,
  36522. // 4x
  36523. 0,
  36524. 0,
  36525. 0,
  36526. 0,
  36527. 0,
  36528. 0,
  36529. 0,
  36530. 0,
  36531. 0,
  36532. 0,
  36533. 0,
  36534. 2,
  36535. 0,
  36536. 2,
  36537. 0,
  36538. 0,
  36539. // 5x
  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. 0,
  36554. 0,
  36555. 0,
  36556. // 6x
  36557. 0,
  36558. 0,
  36559. 0,
  36560. 0,
  36561. 0,
  36562. 0,
  36563. 0,
  36564. 0,
  36565. 0,
  36566. 0,
  36567. 0,
  36568. 2,
  36569. 0,
  36570. 2,
  36571. 0,
  36572. 0,
  36573. // 7x
  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. 0,
  36588. 0,
  36589. 0,
  36590. // 8x
  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. 0,
  36605. 0,
  36606. 0,
  36607. // 9x
  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. 0,
  36622. 0,
  36623. 0,
  36624. // ax
  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. 0,
  36639. 0,
  36640. 0,
  36641. // bx
  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. 0,
  36656. 0,
  36657. 0,
  36658. // cx
  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. 0,
  36673. 0,
  36674. 0,
  36675. // dx
  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. 0,
  36690. 0,
  36691. 0,
  36692. // ex
  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. 0,
  36707. 0,
  36708. 0
  36709. ];
  36710. // fx
  36711. function toHexDigit(ch) {
  36712. if (ch >= 0x30 && ch <= 0x39) {
  36713. // '0'-'9'
  36714. return ch & 0x0F;
  36715. }
  36716. if (ch >= 0x41 && ch <= 0x46 || ch >= 0x61 && ch <= 0x66) {
  36717. // 'A'-'F', 'a'-'f'
  36718. return (ch & 0x0F) + 9;
  36719. }
  36720. return -1;
  36721. }
  36722. Lexer.prototype = {
  36723. nextChar: function Lexer_nextChar() {
  36724. return this.currentChar = this.stream.getByte();
  36725. },
  36726. peekChar: function Lexer_peekChar() {
  36727. return this.stream.peekByte();
  36728. },
  36729. getNumber: function Lexer_getNumber() {
  36730. var ch = this.currentChar;
  36731. var eNotation = false;
  36732. var divideBy = 0;
  36733. // different from 0 if it's a floating point value
  36734. var sign = 1;
  36735. if (ch === 0x2D) {
  36736. // '-'
  36737. sign = -1;
  36738. ch = this.nextChar();
  36739. if (ch === 0x2D) {
  36740. // '-'
  36741. // Ignore double negative (this is consistent with Adobe Reader).
  36742. ch = this.nextChar();
  36743. }
  36744. } else if (ch === 0x2B) {
  36745. // '+'
  36746. ch = this.nextChar();
  36747. }
  36748. if (ch === 0x2E) {
  36749. // '.'
  36750. divideBy = 10;
  36751. ch = this.nextChar();
  36752. }
  36753. if (ch < 0x30 || ch > 0x39) {
  36754. // '0' - '9'
  36755. error('Invalid number: ' + String.fromCharCode(ch));
  36756. return 0;
  36757. }
  36758. var baseValue = ch - 0x30;
  36759. // '0'
  36760. var powerValue = 0;
  36761. var powerValueSign = 1;
  36762. while ((ch = this.nextChar()) >= 0) {
  36763. if (0x30 <= ch && ch <= 0x39) {
  36764. // '0' - '9'
  36765. var currentDigit = ch - 0x30;
  36766. // '0'
  36767. if (eNotation) {
  36768. // We are after an 'e' or 'E'
  36769. powerValue = powerValue * 10 + currentDigit;
  36770. } else {
  36771. if (divideBy !== 0) {
  36772. // We are after a point
  36773. divideBy *= 10;
  36774. }
  36775. baseValue = baseValue * 10 + currentDigit;
  36776. }
  36777. } else if (ch === 0x2E) {
  36778. // '.'
  36779. if (divideBy === 0) {
  36780. divideBy = 1;
  36781. } else {
  36782. // A number can have only one '.'
  36783. break;
  36784. }
  36785. } else if (ch === 0x2D) {
  36786. // '-'
  36787. // ignore minus signs in the middle of numbers to match
  36788. // Adobe's behavior
  36789. warn('Badly formatted number');
  36790. } else if (ch === 0x45 || ch === 0x65) {
  36791. // 'E', 'e'
  36792. // 'E' can be either a scientific notation or the beginning of a new
  36793. // operator
  36794. ch = this.peekChar();
  36795. if (ch === 0x2B || ch === 0x2D) {
  36796. // '+', '-'
  36797. powerValueSign = ch === 0x2D ? -1 : 1;
  36798. this.nextChar();
  36799. } else // Consume the sign character
  36800. if (ch < 0x30 || ch > 0x39) {
  36801. // '0' - '9'
  36802. // The 'E' must be the beginning of a new operator
  36803. break;
  36804. }
  36805. eNotation = true;
  36806. } else {
  36807. // the last character doesn't belong to us
  36808. break;
  36809. }
  36810. }
  36811. if (divideBy !== 0) {
  36812. baseValue /= divideBy;
  36813. }
  36814. if (eNotation) {
  36815. baseValue *= Math.pow(10, powerValueSign * powerValue);
  36816. }
  36817. return sign * baseValue;
  36818. },
  36819. getString: function Lexer_getString() {
  36820. var numParen = 1;
  36821. var done = false;
  36822. var strBuf = this.strBuf;
  36823. strBuf.length = 0;
  36824. var ch = this.nextChar();
  36825. while (true) {
  36826. var charBuffered = false;
  36827. switch (ch | 0) {
  36828. case -1:
  36829. warn('Unterminated string');
  36830. done = true;
  36831. break;
  36832. case 0x28:
  36833. // '('
  36834. ++numParen;
  36835. strBuf.push('(');
  36836. break;
  36837. case 0x29:
  36838. // ')'
  36839. if (--numParen === 0) {
  36840. this.nextChar();
  36841. // consume strings ')'
  36842. done = true;
  36843. } else {
  36844. strBuf.push(')');
  36845. }
  36846. break;
  36847. case 0x5C:
  36848. // '\\'
  36849. ch = this.nextChar();
  36850. switch (ch) {
  36851. case -1:
  36852. warn('Unterminated string');
  36853. done = true;
  36854. break;
  36855. case 0x6E:
  36856. // 'n'
  36857. strBuf.push('\n');
  36858. break;
  36859. case 0x72:
  36860. // 'r'
  36861. strBuf.push('\r');
  36862. break;
  36863. case 0x74:
  36864. // 't'
  36865. strBuf.push('\t');
  36866. break;
  36867. case 0x62:
  36868. // 'b'
  36869. strBuf.push('\b');
  36870. break;
  36871. case 0x66:
  36872. // 'f'
  36873. strBuf.push('\f');
  36874. break;
  36875. case 0x5C:
  36876. // '\'
  36877. case 0x28:
  36878. // '('
  36879. case 0x29:
  36880. // ')'
  36881. strBuf.push(String.fromCharCode(ch));
  36882. break;
  36883. case 0x30:
  36884. case 0x31:
  36885. case 0x32:
  36886. case 0x33:
  36887. // '0'-'3'
  36888. case 0x34:
  36889. case 0x35:
  36890. case 0x36:
  36891. case 0x37:
  36892. // '4'-'7'
  36893. var x = ch & 0x0F;
  36894. ch = this.nextChar();
  36895. charBuffered = true;
  36896. if (ch >= 0x30 && ch <= 0x37) {
  36897. // '0'-'7'
  36898. x = (x << 3) + (ch & 0x0F);
  36899. ch = this.nextChar();
  36900. if (ch >= 0x30 && ch <= 0x37) {
  36901. // '0'-'7'
  36902. charBuffered = false;
  36903. x = (x << 3) + (ch & 0x0F);
  36904. }
  36905. }
  36906. strBuf.push(String.fromCharCode(x));
  36907. break;
  36908. case 0x0D:
  36909. // CR
  36910. if (this.peekChar() === 0x0A) {
  36911. // LF
  36912. this.nextChar();
  36913. }
  36914. break;
  36915. case 0x0A:
  36916. // LF
  36917. break;
  36918. default:
  36919. strBuf.push(String.fromCharCode(ch));
  36920. break;
  36921. }
  36922. break;
  36923. default:
  36924. strBuf.push(String.fromCharCode(ch));
  36925. break;
  36926. }
  36927. if (done) {
  36928. break;
  36929. }
  36930. if (!charBuffered) {
  36931. ch = this.nextChar();
  36932. }
  36933. }
  36934. return strBuf.join('');
  36935. },
  36936. getName: function Lexer_getName() {
  36937. var ch, previousCh;
  36938. var strBuf = this.strBuf;
  36939. strBuf.length = 0;
  36940. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  36941. if (ch === 0x23) {
  36942. // '#'
  36943. ch = this.nextChar();
  36944. if (specialChars[ch]) {
  36945. warn('Lexer_getName: ' + 'NUMBER SIGN (#) should be followed by a hexadecimal number.');
  36946. strBuf.push('#');
  36947. break;
  36948. }
  36949. var x = toHexDigit(ch);
  36950. if (x !== -1) {
  36951. previousCh = ch;
  36952. ch = this.nextChar();
  36953. var x2 = toHexDigit(ch);
  36954. if (x2 === -1) {
  36955. warn('Lexer_getName: Illegal digit (' + String.fromCharCode(ch) + ') in hexadecimal number.');
  36956. strBuf.push('#', String.fromCharCode(previousCh));
  36957. if (specialChars[ch]) {
  36958. break;
  36959. }
  36960. strBuf.push(String.fromCharCode(ch));
  36961. continue;
  36962. }
  36963. strBuf.push(String.fromCharCode(x << 4 | x2));
  36964. } else {
  36965. strBuf.push('#', String.fromCharCode(ch));
  36966. }
  36967. } else {
  36968. strBuf.push(String.fromCharCode(ch));
  36969. }
  36970. }
  36971. if (strBuf.length > 127) {
  36972. warn('name token is longer than allowed by the spec: ' + strBuf.length);
  36973. }
  36974. return Name.get(strBuf.join(''));
  36975. },
  36976. getHexString: function Lexer_getHexString() {
  36977. var strBuf = this.strBuf;
  36978. strBuf.length = 0;
  36979. var ch = this.currentChar;
  36980. var isFirstHex = true;
  36981. var firstDigit;
  36982. var secondDigit;
  36983. while (true) {
  36984. if (ch < 0) {
  36985. warn('Unterminated hex string');
  36986. break;
  36987. } else if (ch === 0x3E) {
  36988. // '>'
  36989. this.nextChar();
  36990. break;
  36991. } else if (specialChars[ch] === 1) {
  36992. ch = this.nextChar();
  36993. continue;
  36994. } else {
  36995. if (isFirstHex) {
  36996. firstDigit = toHexDigit(ch);
  36997. if (firstDigit === -1) {
  36998. warn('Ignoring invalid character "' + ch + '" in hex string');
  36999. ch = this.nextChar();
  37000. continue;
  37001. }
  37002. } else {
  37003. secondDigit = toHexDigit(ch);
  37004. if (secondDigit === -1) {
  37005. warn('Ignoring invalid character "' + ch + '" in hex string');
  37006. ch = this.nextChar();
  37007. continue;
  37008. }
  37009. strBuf.push(String.fromCharCode(firstDigit << 4 | secondDigit));
  37010. }
  37011. isFirstHex = !isFirstHex;
  37012. ch = this.nextChar();
  37013. }
  37014. }
  37015. return strBuf.join('');
  37016. },
  37017. getObj: function Lexer_getObj() {
  37018. // skip whitespace and comments
  37019. var comment = false;
  37020. var ch = this.currentChar;
  37021. while (true) {
  37022. if (ch < 0) {
  37023. return EOF;
  37024. }
  37025. if (comment) {
  37026. if (ch === 0x0A || ch === 0x0D) {
  37027. // LF, CR
  37028. comment = false;
  37029. }
  37030. } else if (ch === 0x25) {
  37031. // '%'
  37032. comment = true;
  37033. } else if (specialChars[ch] !== 1) {
  37034. break;
  37035. }
  37036. ch = this.nextChar();
  37037. }
  37038. // start reading token
  37039. switch (ch | 0) {
  37040. case 0x30:
  37041. case 0x31:
  37042. case 0x32:
  37043. case 0x33:
  37044. case 0x34:
  37045. // '0'-'4'
  37046. case 0x35:
  37047. case 0x36:
  37048. case 0x37:
  37049. case 0x38:
  37050. case 0x39:
  37051. // '5'-'9'
  37052. case 0x2B:
  37053. case 0x2D:
  37054. case 0x2E:
  37055. // '+', '-', '.'
  37056. return this.getNumber();
  37057. case 0x28:
  37058. // '('
  37059. return this.getString();
  37060. case 0x2F:
  37061. // '/'
  37062. return this.getName();
  37063. // array punctuation
  37064. case 0x5B:
  37065. // '['
  37066. this.nextChar();
  37067. return Cmd.get('[');
  37068. case 0x5D:
  37069. // ']'
  37070. this.nextChar();
  37071. return Cmd.get(']');
  37072. // hex string or dict punctuation
  37073. case 0x3C:
  37074. // '<'
  37075. ch = this.nextChar();
  37076. if (ch === 0x3C) {
  37077. // dict punctuation
  37078. this.nextChar();
  37079. return Cmd.get('<<');
  37080. }
  37081. return this.getHexString();
  37082. // dict punctuation
  37083. case 0x3E:
  37084. // '>'
  37085. ch = this.nextChar();
  37086. if (ch === 0x3E) {
  37087. this.nextChar();
  37088. return Cmd.get('>>');
  37089. }
  37090. return Cmd.get('>');
  37091. case 0x7B:
  37092. // '{'
  37093. this.nextChar();
  37094. return Cmd.get('{');
  37095. case 0x7D:
  37096. // '}'
  37097. this.nextChar();
  37098. return Cmd.get('}');
  37099. case 0x29:
  37100. // ')'
  37101. error('Illegal character: ' + ch);
  37102. break;
  37103. }
  37104. // command
  37105. var str = String.fromCharCode(ch);
  37106. var knownCommands = this.knownCommands;
  37107. var knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  37108. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  37109. // stop if known command is found and next character does not make
  37110. // the str a command
  37111. var possibleCommand = str + String.fromCharCode(ch);
  37112. if (knownCommandFound && knownCommands[possibleCommand] === undefined) {
  37113. break;
  37114. }
  37115. if (str.length === 128) {
  37116. error('Command token too long: ' + str.length);
  37117. }
  37118. str = possibleCommand;
  37119. knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  37120. }
  37121. if (str === 'true') {
  37122. return true;
  37123. }
  37124. if (str === 'false') {
  37125. return false;
  37126. }
  37127. if (str === 'null') {
  37128. return null;
  37129. }
  37130. return Cmd.get(str);
  37131. },
  37132. skipToNextLine: function Lexer_skipToNextLine() {
  37133. var ch = this.currentChar;
  37134. while (ch >= 0) {
  37135. if (ch === 0x0D) {
  37136. // CR
  37137. ch = this.nextChar();
  37138. if (ch === 0x0A) {
  37139. // LF
  37140. this.nextChar();
  37141. }
  37142. break;
  37143. } else if (ch === 0x0A) {
  37144. // LF
  37145. this.nextChar();
  37146. break;
  37147. }
  37148. ch = this.nextChar();
  37149. }
  37150. }
  37151. };
  37152. return Lexer;
  37153. }();
  37154. var Linearization = {
  37155. create: function LinearizationCreate(stream) {
  37156. function getInt(name, allowZeroValue) {
  37157. var obj = linDict.get(name);
  37158. if (isInt(obj) && (allowZeroValue ? obj >= 0 : obj > 0)) {
  37159. return obj;
  37160. }
  37161. throw new Error('The "' + name + '" parameter in the linearization ' + 'dictionary is invalid.');
  37162. }
  37163. function getHints() {
  37164. var hints = linDict.get('H'), hintsLength, item;
  37165. if (isArray(hints) && ((hintsLength = hints.length) === 2 || hintsLength === 4)) {
  37166. for (var index = 0; index < hintsLength; index++) {
  37167. if (!(isInt(item = hints[index]) && item > 0)) {
  37168. throw new Error('Hint (' + index + ') in the linearization dictionary is invalid.');
  37169. }
  37170. }
  37171. return hints;
  37172. }
  37173. throw new Error('Hint array in the linearization dictionary is invalid.');
  37174. }
  37175. var parser = new Parser(new Lexer(stream), false, null);
  37176. var obj1 = parser.getObj();
  37177. var obj2 = parser.getObj();
  37178. var obj3 = parser.getObj();
  37179. var linDict = parser.getObj();
  37180. var obj, length;
  37181. if (!(isInt(obj1) && isInt(obj2) && isCmd(obj3, 'obj') && isDict(linDict) && isNum(obj = linDict.get('Linearized')) && obj > 0)) {
  37182. return null;
  37183. } else // No valid linearization dictionary found.
  37184. if ((length = getInt('L')) !== stream.length) {
  37185. throw new Error('The "L" parameter in the linearization dictionary ' + 'does not equal the stream length.');
  37186. }
  37187. return {
  37188. length: length,
  37189. hints: getHints(),
  37190. objectNumberFirst: getInt('O'),
  37191. endFirst: getInt('E'),
  37192. numPages: getInt('N'),
  37193. mainXRefEntriesOffset: getInt('T'),
  37194. pageFirst: linDict.has('P') ? getInt('P', true) : 0
  37195. };
  37196. }
  37197. };
  37198. exports.EOF = EOF;
  37199. exports.Lexer = Lexer;
  37200. exports.Linearization = Linearization;
  37201. exports.Parser = Parser;
  37202. exports.isEOF = isEOF;
  37203. }));
  37204. (function (root, factory) {
  37205. factory(root.pdfjsCoreType1Parser = {}, root.pdfjsSharedUtil, root.pdfjsCoreStream, root.pdfjsCoreEncodings);
  37206. }(this, function (exports, sharedUtil, coreStream, coreEncodings) {
  37207. var warn = sharedUtil.warn;
  37208. var isSpace = sharedUtil.isSpace;
  37209. var Stream = coreStream.Stream;
  37210. var getEncoding = coreEncodings.getEncoding;
  37211. // Hinting is currently disabled due to unknown problems on windows
  37212. // in tracemonkey and various other pdfs with type1 fonts.
  37213. var HINTING_ENABLED = false;
  37214. /*
  37215. * CharStrings are encoded following the the CharString Encoding sequence
  37216. * describe in Chapter 6 of the "Adobe Type1 Font Format" specification.
  37217. * The value in a byte indicates a command, a number, or subsequent bytes
  37218. * that are to be interpreted in a special way.
  37219. *
  37220. * CharString Number Encoding:
  37221. * A CharString byte containing the values from 32 through 255 inclusive
  37222. * indicate an integer. These values are decoded in four ranges.
  37223. *
  37224. * 1. A CharString byte containing a value, v, between 32 and 246 inclusive,
  37225. * indicate the integer v - 139. Thus, the integer values from -107 through
  37226. * 107 inclusive may be encoded in single byte.
  37227. *
  37228. * 2. A CharString byte containing a value, v, between 247 and 250 inclusive,
  37229. * indicates an integer involving the next byte, w, according to the formula:
  37230. * [(v - 247) x 256] + w + 108
  37231. *
  37232. * 3. A CharString byte containing a value, v, between 251 and 254 inclusive,
  37233. * indicates an integer involving the next byte, w, according to the formula:
  37234. * -[(v - 251) * 256] - w - 108
  37235. *
  37236. * 4. A CharString containing the value 255 indicates that the next 4 bytes
  37237. * are a two complement signed integer. The first of these bytes contains the
  37238. * highest order bits, the second byte contains the next higher order bits
  37239. * and the fourth byte contain the lowest order bits.
  37240. *
  37241. *
  37242. * CharString Command Encoding:
  37243. * CharStrings commands are encoded in 1 or 2 bytes.
  37244. *
  37245. * Single byte commands are encoded in 1 byte that contains a value between
  37246. * 0 and 31 inclusive.
  37247. * If a command byte contains the value 12, then the value in the next byte
  37248. * indicates a command. This "escape" mechanism allows many extra commands
  37249. * to be encoded and this encoding technique helps to minimize the length of
  37250. * the charStrings.
  37251. */
  37252. var Type1CharString = function Type1CharStringClosure() {
  37253. var COMMAND_MAP = {
  37254. 'hstem': [1],
  37255. 'vstem': [3],
  37256. 'vmoveto': [4],
  37257. 'rlineto': [5],
  37258. 'hlineto': [6],
  37259. 'vlineto': [7],
  37260. 'rrcurveto': [8],
  37261. 'callsubr': [10],
  37262. 'flex': [
  37263. 12,
  37264. 35
  37265. ],
  37266. 'drop': [
  37267. 12,
  37268. 18
  37269. ],
  37270. 'endchar': [14],
  37271. 'rmoveto': [21],
  37272. 'hmoveto': [22],
  37273. 'vhcurveto': [30],
  37274. 'hvcurveto': [31]
  37275. };
  37276. function Type1CharString() {
  37277. this.width = 0;
  37278. this.lsb = 0;
  37279. this.flexing = false;
  37280. this.output = [];
  37281. this.stack = [];
  37282. }
  37283. Type1CharString.prototype = {
  37284. convert: function Type1CharString_convert(encoded, subrs, seacAnalysisEnabled) {
  37285. var count = encoded.length;
  37286. var error = false;
  37287. var wx, sbx, subrNumber;
  37288. for (var i = 0; i < count; i++) {
  37289. var value = encoded[i];
  37290. if (value < 32) {
  37291. if (value === 12) {
  37292. value = (value << 8) + encoded[++i];
  37293. }
  37294. switch (value) {
  37295. case 1:
  37296. // hstem
  37297. if (!HINTING_ENABLED) {
  37298. this.stack = [];
  37299. break;
  37300. }
  37301. error = this.executeCommand(2, COMMAND_MAP.hstem);
  37302. break;
  37303. case 3:
  37304. // vstem
  37305. if (!HINTING_ENABLED) {
  37306. this.stack = [];
  37307. break;
  37308. }
  37309. error = this.executeCommand(2, COMMAND_MAP.vstem);
  37310. break;
  37311. case 4:
  37312. // vmoveto
  37313. if (this.flexing) {
  37314. if (this.stack.length < 1) {
  37315. error = true;
  37316. break;
  37317. }
  37318. // Add the dx for flex and but also swap the values so they are
  37319. // the right order.
  37320. var dy = this.stack.pop();
  37321. this.stack.push(0, dy);
  37322. break;
  37323. }
  37324. error = this.executeCommand(1, COMMAND_MAP.vmoveto);
  37325. break;
  37326. case 5:
  37327. // rlineto
  37328. error = this.executeCommand(2, COMMAND_MAP.rlineto);
  37329. break;
  37330. case 6:
  37331. // hlineto
  37332. error = this.executeCommand(1, COMMAND_MAP.hlineto);
  37333. break;
  37334. case 7:
  37335. // vlineto
  37336. error = this.executeCommand(1, COMMAND_MAP.vlineto);
  37337. break;
  37338. case 8:
  37339. // rrcurveto
  37340. error = this.executeCommand(6, COMMAND_MAP.rrcurveto);
  37341. break;
  37342. case 9:
  37343. // closepath
  37344. // closepath is a Type1 command that does not take argument and is
  37345. // useless in Type2 and it can simply be ignored.
  37346. this.stack = [];
  37347. break;
  37348. case 10:
  37349. // callsubr
  37350. if (this.stack.length < 1) {
  37351. error = true;
  37352. break;
  37353. }
  37354. subrNumber = this.stack.pop();
  37355. error = this.convert(subrs[subrNumber], subrs, seacAnalysisEnabled);
  37356. break;
  37357. case 11:
  37358. // return
  37359. return error;
  37360. case 13:
  37361. // hsbw
  37362. if (this.stack.length < 2) {
  37363. error = true;
  37364. break;
  37365. }
  37366. // To convert to type2 we have to move the width value to the
  37367. // first part of the charstring and then use hmoveto with lsb.
  37368. wx = this.stack.pop();
  37369. sbx = this.stack.pop();
  37370. this.lsb = sbx;
  37371. this.width = wx;
  37372. this.stack.push(wx, sbx);
  37373. error = this.executeCommand(2, COMMAND_MAP.hmoveto);
  37374. break;
  37375. case 14:
  37376. // endchar
  37377. this.output.push(COMMAND_MAP.endchar[0]);
  37378. break;
  37379. case 21:
  37380. // rmoveto
  37381. if (this.flexing) {
  37382. break;
  37383. }
  37384. error = this.executeCommand(2, COMMAND_MAP.rmoveto);
  37385. break;
  37386. case 22:
  37387. // hmoveto
  37388. if (this.flexing) {
  37389. // Add the dy for flex.
  37390. this.stack.push(0);
  37391. break;
  37392. }
  37393. error = this.executeCommand(1, COMMAND_MAP.hmoveto);
  37394. break;
  37395. case 30:
  37396. // vhcurveto
  37397. error = this.executeCommand(4, COMMAND_MAP.vhcurveto);
  37398. break;
  37399. case 31:
  37400. // hvcurveto
  37401. error = this.executeCommand(4, COMMAND_MAP.hvcurveto);
  37402. break;
  37403. case (12 << 8) + 0:
  37404. // dotsection
  37405. // dotsection is a Type1 command to specify some hinting feature
  37406. // for dots that do not take a parameter and it can safely be
  37407. // ignored for Type2.
  37408. this.stack = [];
  37409. break;
  37410. case (12 << 8) + 1:
  37411. // vstem3
  37412. if (!HINTING_ENABLED) {
  37413. this.stack = [];
  37414. break;
  37415. }
  37416. // [vh]stem3 are Type1 only and Type2 supports [vh]stem with
  37417. // multiple parameters, so instead of returning [vh]stem3 take a
  37418. // shortcut and return [vhstem] instead.
  37419. error = this.executeCommand(2, COMMAND_MAP.vstem);
  37420. break;
  37421. case (12 << 8) + 2:
  37422. // hstem3
  37423. if (!HINTING_ENABLED) {
  37424. this.stack = [];
  37425. break;
  37426. }
  37427. // See vstem3.
  37428. error = this.executeCommand(2, COMMAND_MAP.hstem);
  37429. break;
  37430. case (12 << 8) + 6:
  37431. // seac
  37432. // seac is like type 2's special endchar but it doesn't use the
  37433. // first argument asb, so remove it.
  37434. if (seacAnalysisEnabled) {
  37435. this.seac = this.stack.splice(-4, 4);
  37436. error = this.executeCommand(0, COMMAND_MAP.endchar);
  37437. } else {
  37438. error = this.executeCommand(4, COMMAND_MAP.endchar);
  37439. }
  37440. break;
  37441. case (12 << 8) + 7:
  37442. // sbw
  37443. if (this.stack.length < 4) {
  37444. error = true;
  37445. break;
  37446. }
  37447. // To convert to type2 we have to move the width value to the
  37448. // first part of the charstring and then use rmoveto with
  37449. // (dx, dy). The height argument will not be used for vmtx and
  37450. // vhea tables reconstruction -- ignoring it.
  37451. var wy = this.stack.pop();
  37452. wx = this.stack.pop();
  37453. var sby = this.stack.pop();
  37454. sbx = this.stack.pop();
  37455. this.lsb = sbx;
  37456. this.width = wx;
  37457. this.stack.push(wx, sbx, sby);
  37458. error = this.executeCommand(3, COMMAND_MAP.rmoveto);
  37459. break;
  37460. case (12 << 8) + 12:
  37461. // div
  37462. if (this.stack.length < 2) {
  37463. error = true;
  37464. break;
  37465. }
  37466. var num2 = this.stack.pop();
  37467. var num1 = this.stack.pop();
  37468. this.stack.push(num1 / num2);
  37469. break;
  37470. case (12 << 8) + 16:
  37471. // callothersubr
  37472. if (this.stack.length < 2) {
  37473. error = true;
  37474. break;
  37475. }
  37476. subrNumber = this.stack.pop();
  37477. var numArgs = this.stack.pop();
  37478. if (subrNumber === 0 && numArgs === 3) {
  37479. var flexArgs = this.stack.splice(this.stack.length - 17, 17);
  37480. this.stack.push(flexArgs[2] + flexArgs[0], // bcp1x + rpx
  37481. flexArgs[3] + flexArgs[1], // bcp1y + rpy
  37482. flexArgs[4], // bcp2x
  37483. flexArgs[5], // bcp2y
  37484. flexArgs[6], // p2x
  37485. flexArgs[7], // p2y
  37486. flexArgs[8], // bcp3x
  37487. flexArgs[9], // bcp3y
  37488. flexArgs[10], // bcp4x
  37489. flexArgs[11], // bcp4y
  37490. flexArgs[12], // p3x
  37491. flexArgs[13], // p3y
  37492. flexArgs[14]);
  37493. // flexDepth
  37494. // 15 = finalx unused by flex
  37495. // 16 = finaly unused by flex
  37496. error = this.executeCommand(13, COMMAND_MAP.flex, true);
  37497. this.flexing = false;
  37498. this.stack.push(flexArgs[15], flexArgs[16]);
  37499. } else if (subrNumber === 1 && numArgs === 0) {
  37500. this.flexing = true;
  37501. }
  37502. break;
  37503. case (12 << 8) + 17:
  37504. // pop
  37505. // Ignore this since it is only used with othersubr.
  37506. break;
  37507. case (12 << 8) + 33:
  37508. // setcurrentpoint
  37509. // Ignore for now.
  37510. this.stack = [];
  37511. break;
  37512. default:
  37513. warn('Unknown type 1 charstring command of "' + value + '"');
  37514. break;
  37515. }
  37516. if (error) {
  37517. break;
  37518. }
  37519. continue;
  37520. } else if (value <= 246) {
  37521. value = value - 139;
  37522. } else if (value <= 250) {
  37523. value = (value - 247) * 256 + encoded[++i] + 108;
  37524. } else if (value <= 254) {
  37525. value = -((value - 251) * 256) - encoded[++i] - 108;
  37526. } else {
  37527. value = (encoded[++i] & 0xff) << 24 | (encoded[++i] & 0xff) << 16 | (encoded[++i] & 0xff) << 8 | (encoded[++i] & 0xff) << 0;
  37528. }
  37529. this.stack.push(value);
  37530. }
  37531. return error;
  37532. },
  37533. executeCommand: function (howManyArgs, command, keepStack) {
  37534. var stackLength = this.stack.length;
  37535. if (howManyArgs > stackLength) {
  37536. return true;
  37537. }
  37538. var start = stackLength - howManyArgs;
  37539. for (var i = start; i < stackLength; i++) {
  37540. var value = this.stack[i];
  37541. if (value === (value | 0)) {
  37542. // int
  37543. this.output.push(28, value >> 8 & 0xff, value & 0xff);
  37544. } else {
  37545. // fixed point
  37546. value = 65536 * value | 0;
  37547. this.output.push(255, value >> 24 & 0xFF, value >> 16 & 0xFF, value >> 8 & 0xFF, value & 0xFF);
  37548. }
  37549. }
  37550. this.output.push.apply(this.output, command);
  37551. if (keepStack) {
  37552. this.stack.splice(start, howManyArgs);
  37553. } else {
  37554. this.stack.length = 0;
  37555. }
  37556. return false;
  37557. }
  37558. };
  37559. return Type1CharString;
  37560. }();
  37561. /*
  37562. * Type1Parser encapsulate the needed code for parsing a Type1 font
  37563. * program. Some of its logic depends on the Type2 charstrings
  37564. * structure.
  37565. * Note: this doesn't really parse the font since that would require evaluation
  37566. * of PostScript, but it is possible in most cases to extract what we need
  37567. * without a full parse.
  37568. */
  37569. var Type1Parser = function Type1ParserClosure() {
  37570. /*
  37571. * Decrypt a Sequence of Ciphertext Bytes to Produce the Original Sequence
  37572. * of Plaintext Bytes. The function took a key as a parameter which can be
  37573. * for decrypting the eexec block of for decoding charStrings.
  37574. */
  37575. var EEXEC_ENCRYPT_KEY = 55665;
  37576. var CHAR_STRS_ENCRYPT_KEY = 4330;
  37577. function isHexDigit(code) {
  37578. return code >= 48 && code <= 57 || // '0'-'9'
  37579. code >= 65 && code <= 70 || // 'A'-'F'
  37580. code >= 97 && code <= 102;
  37581. }
  37582. // 'a'-'f'
  37583. function decrypt(data, key, discardNumber) {
  37584. if (discardNumber >= data.length) {
  37585. return new Uint8Array(0);
  37586. }
  37587. var r = key | 0, c1 = 52845, c2 = 22719, i, j;
  37588. for (i = 0; i < discardNumber; i++) {
  37589. r = (data[i] + r) * c1 + c2 & (1 << 16) - 1;
  37590. }
  37591. var count = data.length - discardNumber;
  37592. var decrypted = new Uint8Array(count);
  37593. for (i = discardNumber, j = 0; j < count; i++, j++) {
  37594. var value = data[i];
  37595. decrypted[j] = value ^ r >> 8;
  37596. r = (value + r) * c1 + c2 & (1 << 16) - 1;
  37597. }
  37598. return decrypted;
  37599. }
  37600. function decryptAscii(data, key, discardNumber) {
  37601. var r = key | 0, c1 = 52845, c2 = 22719;
  37602. var count = data.length, maybeLength = count >>> 1;
  37603. var decrypted = new Uint8Array(maybeLength);
  37604. var i, j;
  37605. for (i = 0, j = 0; i < count; i++) {
  37606. var digit1 = data[i];
  37607. if (!isHexDigit(digit1)) {
  37608. continue;
  37609. }
  37610. i++;
  37611. var digit2;
  37612. while (i < count && !isHexDigit(digit2 = data[i])) {
  37613. i++;
  37614. }
  37615. if (i < count) {
  37616. var value = parseInt(String.fromCharCode(digit1, digit2), 16);
  37617. decrypted[j++] = value ^ r >> 8;
  37618. r = (value + r) * c1 + c2 & (1 << 16) - 1;
  37619. }
  37620. }
  37621. return Array.prototype.slice.call(decrypted, discardNumber, j);
  37622. }
  37623. function isSpecial(c) {
  37624. return c === 0x2F || // '/'
  37625. c === 0x5B || c === 0x5D || // '[', ']'
  37626. c === 0x7B || c === 0x7D || // '{', '}'
  37627. c === 0x28 || c === 0x29;
  37628. }
  37629. // '(', ')'
  37630. function Type1Parser(stream, encrypted, seacAnalysisEnabled) {
  37631. if (encrypted) {
  37632. var data = stream.getBytes();
  37633. var isBinary = !(isHexDigit(data[0]) && isHexDigit(data[1]) && isHexDigit(data[2]) && isHexDigit(data[3]));
  37634. stream = new Stream(isBinary ? decrypt(data, EEXEC_ENCRYPT_KEY, 4) : decryptAscii(data, EEXEC_ENCRYPT_KEY, 4));
  37635. }
  37636. this.seacAnalysisEnabled = !!seacAnalysisEnabled;
  37637. this.stream = stream;
  37638. this.nextChar();
  37639. }
  37640. Type1Parser.prototype = {
  37641. readNumberArray: function Type1Parser_readNumberArray() {
  37642. this.getToken();
  37643. // read '[' or '{' (arrays can start with either)
  37644. var array = [];
  37645. while (true) {
  37646. var token = this.getToken();
  37647. if (token === null || token === ']' || token === '}') {
  37648. break;
  37649. }
  37650. array.push(parseFloat(token || 0));
  37651. }
  37652. return array;
  37653. },
  37654. readNumber: function Type1Parser_readNumber() {
  37655. var token = this.getToken();
  37656. return parseFloat(token || 0);
  37657. },
  37658. readInt: function Type1Parser_readInt() {
  37659. // Use '| 0' to prevent setting a double into length such as the double
  37660. // does not flow into the loop variable.
  37661. var token = this.getToken();
  37662. return parseInt(token || 0, 10) | 0;
  37663. },
  37664. readBoolean: function Type1Parser_readBoolean() {
  37665. var token = this.getToken();
  37666. // Use 1 and 0 since that's what type2 charstrings use.
  37667. return token === 'true' ? 1 : 0;
  37668. },
  37669. nextChar: function Type1_nextChar() {
  37670. return this.currentChar = this.stream.getByte();
  37671. },
  37672. getToken: function Type1Parser_getToken() {
  37673. // Eat whitespace and comments.
  37674. var comment = false;
  37675. var ch = this.currentChar;
  37676. while (true) {
  37677. if (ch === -1) {
  37678. return null;
  37679. }
  37680. if (comment) {
  37681. if (ch === 0x0A || ch === 0x0D) {
  37682. comment = false;
  37683. }
  37684. } else if (ch === 0x25) {
  37685. // '%'
  37686. comment = true;
  37687. } else if (!isSpace(ch)) {
  37688. break;
  37689. }
  37690. ch = this.nextChar();
  37691. }
  37692. if (isSpecial(ch)) {
  37693. this.nextChar();
  37694. return String.fromCharCode(ch);
  37695. }
  37696. var token = '';
  37697. do {
  37698. token += String.fromCharCode(ch);
  37699. ch = this.nextChar();
  37700. } while (ch >= 0 && !isSpace(ch) && !isSpecial(ch));
  37701. return token;
  37702. },
  37703. /*
  37704. * Returns an object containing a Subrs array and a CharStrings
  37705. * array extracted from and eexec encrypted block of data
  37706. */
  37707. extractFontProgram: function Type1Parser_extractFontProgram() {
  37708. var stream = this.stream;
  37709. var subrs = [], charstrings = [];
  37710. var privateData = Object.create(null);
  37711. privateData['lenIV'] = 4;
  37712. var program = {
  37713. subrs: [],
  37714. charstrings: [],
  37715. properties: { 'privateData': privateData }
  37716. };
  37717. var token, length, data, lenIV, encoded;
  37718. while ((token = this.getToken()) !== null) {
  37719. if (token !== '/') {
  37720. continue;
  37721. }
  37722. token = this.getToken();
  37723. switch (token) {
  37724. case 'CharStrings':
  37725. // The number immediately following CharStrings must be greater or
  37726. // equal to the number of CharStrings.
  37727. this.getToken();
  37728. this.getToken();
  37729. // read in 'dict'
  37730. this.getToken();
  37731. // read in 'dup'
  37732. this.getToken();
  37733. // read in 'begin'
  37734. while (true) {
  37735. token = this.getToken();
  37736. if (token === null || token === 'end') {
  37737. break;
  37738. }
  37739. if (token !== '/') {
  37740. continue;
  37741. }
  37742. var glyph = this.getToken();
  37743. length = this.readInt();
  37744. this.getToken();
  37745. // read in 'RD' or '-|'
  37746. data = stream.makeSubStream(stream.pos, length);
  37747. lenIV = program.properties.privateData['lenIV'];
  37748. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  37749. // Skip past the required space and binary data.
  37750. stream.skip(length);
  37751. this.nextChar();
  37752. token = this.getToken();
  37753. // read in 'ND' or '|-'
  37754. if (token === 'noaccess') {
  37755. this.getToken();
  37756. }
  37757. // read in 'def'
  37758. charstrings.push({
  37759. glyph: glyph,
  37760. encoded: encoded
  37761. });
  37762. }
  37763. break;
  37764. case 'Subrs':
  37765. var num = this.readInt();
  37766. this.getToken();
  37767. // read in 'array'
  37768. while ((token = this.getToken()) === 'dup') {
  37769. var index = this.readInt();
  37770. length = this.readInt();
  37771. this.getToken();
  37772. // read in 'RD' or '-|'
  37773. data = stream.makeSubStream(stream.pos, length);
  37774. lenIV = program.properties.privateData['lenIV'];
  37775. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  37776. // Skip past the required space and binary data.
  37777. stream.skip(length);
  37778. this.nextChar();
  37779. token = this.getToken();
  37780. // read in 'NP' or '|'
  37781. if (token === 'noaccess') {
  37782. this.getToken();
  37783. }
  37784. // read in 'put'
  37785. subrs[index] = encoded;
  37786. }
  37787. break;
  37788. case 'BlueValues':
  37789. case 'OtherBlues':
  37790. case 'FamilyBlues':
  37791. case 'FamilyOtherBlues':
  37792. var blueArray = this.readNumberArray();
  37793. // *Blue* values may contain invalid data: disables reading of
  37794. // those values when hinting is disabled.
  37795. if (blueArray.length > 0 && blueArray.length % 2 === 0 && HINTING_ENABLED) {
  37796. program.properties.privateData[token] = blueArray;
  37797. }
  37798. break;
  37799. case 'StemSnapH':
  37800. case 'StemSnapV':
  37801. program.properties.privateData[token] = this.readNumberArray();
  37802. break;
  37803. case 'StdHW':
  37804. case 'StdVW':
  37805. program.properties.privateData[token] = this.readNumberArray()[0];
  37806. break;
  37807. case 'BlueShift':
  37808. case 'lenIV':
  37809. case 'BlueFuzz':
  37810. case 'BlueScale':
  37811. case 'LanguageGroup':
  37812. case 'ExpansionFactor':
  37813. program.properties.privateData[token] = this.readNumber();
  37814. break;
  37815. case 'ForceBold':
  37816. program.properties.privateData[token] = this.readBoolean();
  37817. break;
  37818. }
  37819. }
  37820. for (var i = 0; i < charstrings.length; i++) {
  37821. glyph = charstrings[i].glyph;
  37822. encoded = charstrings[i].encoded;
  37823. var charString = new Type1CharString();
  37824. var error = charString.convert(encoded, subrs, this.seacAnalysisEnabled);
  37825. var output = charString.output;
  37826. if (error) {
  37827. // It seems when FreeType encounters an error while evaluating a glyph
  37828. // that it completely ignores the glyph so we'll mimic that behaviour
  37829. // here and put an endchar to make the validator happy.
  37830. output = [14];
  37831. }
  37832. program.charstrings.push({
  37833. glyphName: glyph,
  37834. charstring: output,
  37835. width: charString.width,
  37836. lsb: charString.lsb,
  37837. seac: charString.seac
  37838. });
  37839. }
  37840. return program;
  37841. },
  37842. extractFontHeader: function Type1Parser_extractFontHeader(properties) {
  37843. var token;
  37844. while ((token = this.getToken()) !== null) {
  37845. if (token !== '/') {
  37846. continue;
  37847. }
  37848. token = this.getToken();
  37849. switch (token) {
  37850. case 'FontMatrix':
  37851. var matrix = this.readNumberArray();
  37852. properties.fontMatrix = matrix;
  37853. break;
  37854. case 'Encoding':
  37855. var encodingArg = this.getToken();
  37856. var encoding;
  37857. if (!/^\d+$/.test(encodingArg)) {
  37858. // encoding name is specified
  37859. encoding = getEncoding(encodingArg);
  37860. } else {
  37861. encoding = [];
  37862. var size = parseInt(encodingArg, 10) | 0;
  37863. this.getToken();
  37864. // read in 'array'
  37865. for (var j = 0; j < size; j++) {
  37866. token = this.getToken();
  37867. // skipping till first dup or def (e.g. ignoring for statement)
  37868. while (token !== 'dup' && token !== 'def') {
  37869. token = this.getToken();
  37870. if (token === null) {
  37871. return;
  37872. }
  37873. }
  37874. // invalid header
  37875. if (token === 'def') {
  37876. break;
  37877. }
  37878. // read all array data
  37879. var index = this.readInt();
  37880. this.getToken();
  37881. // read in '/'
  37882. var glyph = this.getToken();
  37883. encoding[index] = glyph;
  37884. this.getToken();
  37885. }
  37886. }
  37887. // read the in 'put'
  37888. properties.builtInEncoding = encoding;
  37889. break;
  37890. case 'FontBBox':
  37891. var fontBBox = this.readNumberArray();
  37892. // adjusting ascent/descent
  37893. properties.ascent = fontBBox[3];
  37894. properties.descent = fontBBox[1];
  37895. properties.ascentScaled = true;
  37896. break;
  37897. }
  37898. }
  37899. }
  37900. };
  37901. return Type1Parser;
  37902. }();
  37903. exports.Type1Parser = Type1Parser;
  37904. }));
  37905. (function (root, factory) {
  37906. factory(root.pdfjsCoreCMap = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreParser);
  37907. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreParser) {
  37908. var Util = sharedUtil.Util;
  37909. var assert = sharedUtil.assert;
  37910. var warn = sharedUtil.warn;
  37911. var error = sharedUtil.error;
  37912. var isInt = sharedUtil.isInt;
  37913. var isString = sharedUtil.isString;
  37914. var MissingDataException = sharedUtil.MissingDataException;
  37915. var isName = corePrimitives.isName;
  37916. var isCmd = corePrimitives.isCmd;
  37917. var isStream = corePrimitives.isStream;
  37918. var StringStream = coreStream.StringStream;
  37919. var Lexer = coreParser.Lexer;
  37920. var isEOF = coreParser.isEOF;
  37921. var BUILT_IN_CMAPS = [
  37922. // << Start unicode maps.
  37923. 'Adobe-GB1-UCS2',
  37924. 'Adobe-CNS1-UCS2',
  37925. 'Adobe-Japan1-UCS2',
  37926. 'Adobe-Korea1-UCS2',
  37927. // >> End unicode maps.
  37928. '78-EUC-H',
  37929. '78-EUC-V',
  37930. '78-H',
  37931. '78-RKSJ-H',
  37932. '78-RKSJ-V',
  37933. '78-V',
  37934. '78ms-RKSJ-H',
  37935. '78ms-RKSJ-V',
  37936. '83pv-RKSJ-H',
  37937. '90ms-RKSJ-H',
  37938. '90ms-RKSJ-V',
  37939. '90msp-RKSJ-H',
  37940. '90msp-RKSJ-V',
  37941. '90pv-RKSJ-H',
  37942. '90pv-RKSJ-V',
  37943. 'Add-H',
  37944. 'Add-RKSJ-H',
  37945. 'Add-RKSJ-V',
  37946. 'Add-V',
  37947. 'Adobe-CNS1-0',
  37948. 'Adobe-CNS1-1',
  37949. 'Adobe-CNS1-2',
  37950. 'Adobe-CNS1-3',
  37951. 'Adobe-CNS1-4',
  37952. 'Adobe-CNS1-5',
  37953. 'Adobe-CNS1-6',
  37954. 'Adobe-GB1-0',
  37955. 'Adobe-GB1-1',
  37956. 'Adobe-GB1-2',
  37957. 'Adobe-GB1-3',
  37958. 'Adobe-GB1-4',
  37959. 'Adobe-GB1-5',
  37960. 'Adobe-Japan1-0',
  37961. 'Adobe-Japan1-1',
  37962. 'Adobe-Japan1-2',
  37963. 'Adobe-Japan1-3',
  37964. 'Adobe-Japan1-4',
  37965. 'Adobe-Japan1-5',
  37966. 'Adobe-Japan1-6',
  37967. 'Adobe-Korea1-0',
  37968. 'Adobe-Korea1-1',
  37969. 'Adobe-Korea1-2',
  37970. 'B5-H',
  37971. 'B5-V',
  37972. 'B5pc-H',
  37973. 'B5pc-V',
  37974. 'CNS-EUC-H',
  37975. 'CNS-EUC-V',
  37976. 'CNS1-H',
  37977. 'CNS1-V',
  37978. 'CNS2-H',
  37979. 'CNS2-V',
  37980. 'ETHK-B5-H',
  37981. 'ETHK-B5-V',
  37982. 'ETen-B5-H',
  37983. 'ETen-B5-V',
  37984. 'ETenms-B5-H',
  37985. 'ETenms-B5-V',
  37986. 'EUC-H',
  37987. 'EUC-V',
  37988. 'Ext-H',
  37989. 'Ext-RKSJ-H',
  37990. 'Ext-RKSJ-V',
  37991. 'Ext-V',
  37992. 'GB-EUC-H',
  37993. 'GB-EUC-V',
  37994. 'GB-H',
  37995. 'GB-V',
  37996. 'GBK-EUC-H',
  37997. 'GBK-EUC-V',
  37998. 'GBK2K-H',
  37999. 'GBK2K-V',
  38000. 'GBKp-EUC-H',
  38001. 'GBKp-EUC-V',
  38002. 'GBT-EUC-H',
  38003. 'GBT-EUC-V',
  38004. 'GBT-H',
  38005. 'GBT-V',
  38006. 'GBTpc-EUC-H',
  38007. 'GBTpc-EUC-V',
  38008. 'GBpc-EUC-H',
  38009. 'GBpc-EUC-V',
  38010. 'H',
  38011. 'HKdla-B5-H',
  38012. 'HKdla-B5-V',
  38013. 'HKdlb-B5-H',
  38014. 'HKdlb-B5-V',
  38015. 'HKgccs-B5-H',
  38016. 'HKgccs-B5-V',
  38017. 'HKm314-B5-H',
  38018. 'HKm314-B5-V',
  38019. 'HKm471-B5-H',
  38020. 'HKm471-B5-V',
  38021. 'HKscs-B5-H',
  38022. 'HKscs-B5-V',
  38023. 'Hankaku',
  38024. 'Hiragana',
  38025. 'KSC-EUC-H',
  38026. 'KSC-EUC-V',
  38027. 'KSC-H',
  38028. 'KSC-Johab-H',
  38029. 'KSC-Johab-V',
  38030. 'KSC-V',
  38031. 'KSCms-UHC-H',
  38032. 'KSCms-UHC-HW-H',
  38033. 'KSCms-UHC-HW-V',
  38034. 'KSCms-UHC-V',
  38035. 'KSCpc-EUC-H',
  38036. 'KSCpc-EUC-V',
  38037. 'Katakana',
  38038. 'NWP-H',
  38039. 'NWP-V',
  38040. 'RKSJ-H',
  38041. 'RKSJ-V',
  38042. 'Roman',
  38043. 'UniCNS-UCS2-H',
  38044. 'UniCNS-UCS2-V',
  38045. 'UniCNS-UTF16-H',
  38046. 'UniCNS-UTF16-V',
  38047. 'UniCNS-UTF32-H',
  38048. 'UniCNS-UTF32-V',
  38049. 'UniCNS-UTF8-H',
  38050. 'UniCNS-UTF8-V',
  38051. 'UniGB-UCS2-H',
  38052. 'UniGB-UCS2-V',
  38053. 'UniGB-UTF16-H',
  38054. 'UniGB-UTF16-V',
  38055. 'UniGB-UTF32-H',
  38056. 'UniGB-UTF32-V',
  38057. 'UniGB-UTF8-H',
  38058. 'UniGB-UTF8-V',
  38059. 'UniJIS-UCS2-H',
  38060. 'UniJIS-UCS2-HW-H',
  38061. 'UniJIS-UCS2-HW-V',
  38062. 'UniJIS-UCS2-V',
  38063. 'UniJIS-UTF16-H',
  38064. 'UniJIS-UTF16-V',
  38065. 'UniJIS-UTF32-H',
  38066. 'UniJIS-UTF32-V',
  38067. 'UniJIS-UTF8-H',
  38068. 'UniJIS-UTF8-V',
  38069. 'UniJIS2004-UTF16-H',
  38070. 'UniJIS2004-UTF16-V',
  38071. 'UniJIS2004-UTF32-H',
  38072. 'UniJIS2004-UTF32-V',
  38073. 'UniJIS2004-UTF8-H',
  38074. 'UniJIS2004-UTF8-V',
  38075. 'UniJISPro-UCS2-HW-V',
  38076. 'UniJISPro-UCS2-V',
  38077. 'UniJISPro-UTF8-V',
  38078. 'UniJISX0213-UTF32-H',
  38079. 'UniJISX0213-UTF32-V',
  38080. 'UniJISX02132004-UTF32-H',
  38081. 'UniJISX02132004-UTF32-V',
  38082. 'UniKS-UCS2-H',
  38083. 'UniKS-UCS2-V',
  38084. 'UniKS-UTF16-H',
  38085. 'UniKS-UTF16-V',
  38086. 'UniKS-UTF32-H',
  38087. 'UniKS-UTF32-V',
  38088. 'UniKS-UTF8-H',
  38089. 'UniKS-UTF8-V',
  38090. 'V',
  38091. 'WP-Symbol'
  38092. ];
  38093. // CMap, not to be confused with TrueType's cmap.
  38094. var CMap = function CMapClosure() {
  38095. function CMap(builtInCMap) {
  38096. // Codespace ranges are stored as follows:
  38097. // [[1BytePairs], [2BytePairs], [3BytePairs], [4BytePairs]]
  38098. // where nBytePairs are ranges e.g. [low1, high1, low2, high2, ...]
  38099. this.codespaceRanges = [
  38100. [],
  38101. [],
  38102. [],
  38103. []
  38104. ];
  38105. this.numCodespaceRanges = 0;
  38106. // Map entries have one of two forms.
  38107. // - cid chars are 16-bit unsigned integers, stored as integers.
  38108. // - bf chars are variable-length byte sequences, stored as strings, with
  38109. // one byte per character.
  38110. this._map = [];
  38111. this.name = '';
  38112. this.vertical = false;
  38113. this.useCMap = null;
  38114. this.builtInCMap = builtInCMap;
  38115. }
  38116. CMap.prototype = {
  38117. addCodespaceRange: function (n, low, high) {
  38118. this.codespaceRanges[n - 1].push(low, high);
  38119. this.numCodespaceRanges++;
  38120. },
  38121. mapCidRange: function (low, high, dstLow) {
  38122. while (low <= high) {
  38123. this._map[low++] = dstLow++;
  38124. }
  38125. },
  38126. mapBfRange: function (low, high, dstLow) {
  38127. var lastByte = dstLow.length - 1;
  38128. while (low <= high) {
  38129. this._map[low++] = dstLow;
  38130. // Only the last byte has to be incremented.
  38131. dstLow = dstLow.substr(0, lastByte) + String.fromCharCode(dstLow.charCodeAt(lastByte) + 1);
  38132. }
  38133. },
  38134. mapBfRangeToArray: function (low, high, array) {
  38135. var i = 0, ii = array.length;
  38136. while (low <= high && i < ii) {
  38137. this._map[low] = array[i++];
  38138. ++low;
  38139. }
  38140. },
  38141. // This is used for both bf and cid chars.
  38142. mapOne: function (src, dst) {
  38143. this._map[src] = dst;
  38144. },
  38145. lookup: function (code) {
  38146. return this._map[code];
  38147. },
  38148. contains: function (code) {
  38149. return this._map[code] !== undefined;
  38150. },
  38151. forEach: function (callback) {
  38152. // Most maps have fewer than 65536 entries, and for those we use normal
  38153. // array iteration. But really sparse tables are possible -- e.g. with
  38154. // indices in the *billions*. For such tables we use for..in, which isn't
  38155. // ideal because it stringifies the indices for all present elements, but
  38156. // it does avoid iterating over every undefined entry.
  38157. var map = this._map;
  38158. var length = map.length;
  38159. var i;
  38160. if (length <= 0x10000) {
  38161. for (i = 0; i < length; i++) {
  38162. if (map[i] !== undefined) {
  38163. callback(i, map[i]);
  38164. }
  38165. }
  38166. } else {
  38167. for (i in this._map) {
  38168. callback(i, map[i]);
  38169. }
  38170. }
  38171. },
  38172. charCodeOf: function (value) {
  38173. return this._map.indexOf(value);
  38174. },
  38175. getMap: function () {
  38176. return this._map;
  38177. },
  38178. readCharCode: function (str, offset, out) {
  38179. var c = 0;
  38180. var codespaceRanges = this.codespaceRanges;
  38181. var codespaceRangesLen = this.codespaceRanges.length;
  38182. // 9.7.6.2 CMap Mapping
  38183. // The code length is at most 4.
  38184. for (var n = 0; n < codespaceRangesLen; n++) {
  38185. c = (c << 8 | str.charCodeAt(offset + n)) >>> 0;
  38186. // Check each codespace range to see if it falls within.
  38187. var codespaceRange = codespaceRanges[n];
  38188. for (var k = 0, kk = codespaceRange.length; k < kk;) {
  38189. var low = codespaceRange[k++];
  38190. var high = codespaceRange[k++];
  38191. if (c >= low && c <= high) {
  38192. out.charcode = c;
  38193. out.length = n + 1;
  38194. return;
  38195. }
  38196. }
  38197. }
  38198. out.charcode = 0;
  38199. out.length = 1;
  38200. },
  38201. get length() {
  38202. return this._map.length;
  38203. },
  38204. get isIdentityCMap() {
  38205. if (!(this.name === 'Identity-H' || this.name === 'Identity-V')) {
  38206. return false;
  38207. }
  38208. if (this._map.length !== 0x10000) {
  38209. return false;
  38210. }
  38211. for (var i = 0; i < 0x10000; i++) {
  38212. if (this._map[i] !== i) {
  38213. return false;
  38214. }
  38215. }
  38216. return true;
  38217. }
  38218. };
  38219. return CMap;
  38220. }();
  38221. // A special case of CMap, where the _map array implicitly has a length of
  38222. // 65536 and each element is equal to its index.
  38223. var IdentityCMap = function IdentityCMapClosure() {
  38224. function IdentityCMap(vertical, n) {
  38225. CMap.call(this);
  38226. this.vertical = vertical;
  38227. this.addCodespaceRange(n, 0, 0xffff);
  38228. }
  38229. Util.inherit(IdentityCMap, CMap, {});
  38230. IdentityCMap.prototype = {
  38231. addCodespaceRange: CMap.prototype.addCodespaceRange,
  38232. mapCidRange: function (low, high, dstLow) {
  38233. error('should not call mapCidRange');
  38234. },
  38235. mapBfRange: function (low, high, dstLow) {
  38236. error('should not call mapBfRange');
  38237. },
  38238. mapBfRangeToArray: function (low, high, array) {
  38239. error('should not call mapBfRangeToArray');
  38240. },
  38241. mapOne: function (src, dst) {
  38242. error('should not call mapCidOne');
  38243. },
  38244. lookup: function (code) {
  38245. return isInt(code) && code <= 0xffff ? code : undefined;
  38246. },
  38247. contains: function (code) {
  38248. return isInt(code) && code <= 0xffff;
  38249. },
  38250. forEach: function (callback) {
  38251. for (var i = 0; i <= 0xffff; i++) {
  38252. callback(i, i);
  38253. }
  38254. },
  38255. charCodeOf: function (value) {
  38256. return isInt(value) && value <= 0xffff ? value : -1;
  38257. },
  38258. getMap: function () {
  38259. // Sometimes identity maps must be instantiated, but it's rare.
  38260. var map = new Array(0x10000);
  38261. for (var i = 0; i <= 0xffff; i++) {
  38262. map[i] = i;
  38263. }
  38264. return map;
  38265. },
  38266. readCharCode: CMap.prototype.readCharCode,
  38267. get length() {
  38268. return 0x10000;
  38269. },
  38270. get isIdentityCMap() {
  38271. error('should not access .isIdentityCMap');
  38272. }
  38273. };
  38274. return IdentityCMap;
  38275. }();
  38276. var BinaryCMapReader = function BinaryCMapReaderClosure() {
  38277. function fetchBinaryData(url) {
  38278. return new Promise(function (resolve, reject) {
  38279. var request = new XMLHttpRequest();
  38280. request.open('GET', url, true);
  38281. request.responseType = 'arraybuffer';
  38282. request.onreadystatechange = function () {
  38283. if (request.readyState === XMLHttpRequest.DONE) {
  38284. if (!request.response || request.status !== 200 && request.status !== 0) {
  38285. reject(new Error('Unable to get binary cMap at: ' + url));
  38286. } else {
  38287. resolve(new Uint8Array(request.response));
  38288. }
  38289. }
  38290. };
  38291. request.send(null);
  38292. });
  38293. }
  38294. function hexToInt(a, size) {
  38295. var n = 0;
  38296. for (var i = 0; i <= size; i++) {
  38297. n = n << 8 | a[i];
  38298. }
  38299. return n >>> 0;
  38300. }
  38301. function hexToStr(a, size) {
  38302. // This code is hot. Special-case some common values to avoid creating an
  38303. // object with subarray().
  38304. if (size === 1) {
  38305. return String.fromCharCode(a[0], a[1]);
  38306. }
  38307. if (size === 3) {
  38308. return String.fromCharCode(a[0], a[1], a[2], a[3]);
  38309. }
  38310. return String.fromCharCode.apply(null, a.subarray(0, size + 1));
  38311. }
  38312. function addHex(a, b, size) {
  38313. var c = 0;
  38314. for (var i = size; i >= 0; i--) {
  38315. c += a[i] + b[i];
  38316. a[i] = c & 255;
  38317. c >>= 8;
  38318. }
  38319. }
  38320. function incHex(a, size) {
  38321. var c = 1;
  38322. for (var i = size; i >= 0 && c > 0; i--) {
  38323. c += a[i];
  38324. a[i] = c & 255;
  38325. c >>= 8;
  38326. }
  38327. }
  38328. var MAX_NUM_SIZE = 16;
  38329. var MAX_ENCODED_NUM_SIZE = 19;
  38330. // ceil(MAX_NUM_SIZE * 7 / 8)
  38331. function BinaryCMapStream(data) {
  38332. this.buffer = data;
  38333. this.pos = 0;
  38334. this.end = data.length;
  38335. this.tmpBuf = new Uint8Array(MAX_ENCODED_NUM_SIZE);
  38336. }
  38337. BinaryCMapStream.prototype = {
  38338. readByte: function () {
  38339. if (this.pos >= this.end) {
  38340. return -1;
  38341. }
  38342. return this.buffer[this.pos++];
  38343. },
  38344. readNumber: function () {
  38345. var n = 0;
  38346. var last;
  38347. do {
  38348. var b = this.readByte();
  38349. if (b < 0) {
  38350. error('unexpected EOF in bcmap');
  38351. }
  38352. last = !(b & 0x80);
  38353. n = n << 7 | b & 0x7F;
  38354. } while (!last);
  38355. return n;
  38356. },
  38357. readSigned: function () {
  38358. var n = this.readNumber();
  38359. return n & 1 ? ~(n >>> 1) : n >>> 1;
  38360. },
  38361. readHex: function (num, size) {
  38362. num.set(this.buffer.subarray(this.pos, this.pos + size + 1));
  38363. this.pos += size + 1;
  38364. },
  38365. readHexNumber: function (num, size) {
  38366. var last;
  38367. var stack = this.tmpBuf, sp = 0;
  38368. do {
  38369. var b = this.readByte();
  38370. if (b < 0) {
  38371. error('unexpected EOF in bcmap');
  38372. }
  38373. last = !(b & 0x80);
  38374. stack[sp++] = b & 0x7F;
  38375. } while (!last);
  38376. var i = size, buffer = 0, bufferSize = 0;
  38377. while (i >= 0) {
  38378. while (bufferSize < 8 && stack.length > 0) {
  38379. buffer = stack[--sp] << bufferSize | buffer;
  38380. bufferSize += 7;
  38381. }
  38382. num[i] = buffer & 255;
  38383. i--;
  38384. buffer >>= 8;
  38385. bufferSize -= 8;
  38386. }
  38387. },
  38388. readHexSigned: function (num, size) {
  38389. this.readHexNumber(num, size);
  38390. var sign = num[size] & 1 ? 255 : 0;
  38391. var c = 0;
  38392. for (var i = 0; i <= size; i++) {
  38393. c = (c & 1) << 8 | num[i];
  38394. num[i] = c >> 1 ^ sign;
  38395. }
  38396. },
  38397. readString: function () {
  38398. var len = this.readNumber();
  38399. var s = '';
  38400. for (var i = 0; i < len; i++) {
  38401. s += String.fromCharCode(this.readNumber());
  38402. }
  38403. return s;
  38404. }
  38405. };
  38406. function processBinaryCMap(url, cMap, extend) {
  38407. return fetchBinaryData(url).then(function (data) {
  38408. var stream = new BinaryCMapStream(data);
  38409. var header = stream.readByte();
  38410. cMap.vertical = !!(header & 1);
  38411. var useCMap = null;
  38412. var start = new Uint8Array(MAX_NUM_SIZE);
  38413. var end = new Uint8Array(MAX_NUM_SIZE);
  38414. var char = new Uint8Array(MAX_NUM_SIZE);
  38415. var charCode = new Uint8Array(MAX_NUM_SIZE);
  38416. var tmp = new Uint8Array(MAX_NUM_SIZE);
  38417. var code;
  38418. var b;
  38419. while ((b = stream.readByte()) >= 0) {
  38420. var type = b >> 5;
  38421. if (type === 7) {
  38422. // metadata, e.g. comment or usecmap
  38423. switch (b & 0x1F) {
  38424. case 0:
  38425. stream.readString();
  38426. // skipping comment
  38427. break;
  38428. case 1:
  38429. useCMap = stream.readString();
  38430. break;
  38431. }
  38432. continue;
  38433. }
  38434. var sequence = !!(b & 0x10);
  38435. var dataSize = b & 15;
  38436. assert(dataSize + 1 <= MAX_NUM_SIZE);
  38437. var ucs2DataSize = 1;
  38438. var subitemsCount = stream.readNumber();
  38439. var i;
  38440. switch (type) {
  38441. case 0:
  38442. // codespacerange
  38443. stream.readHex(start, dataSize);
  38444. stream.readHexNumber(end, dataSize);
  38445. addHex(end, start, dataSize);
  38446. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize), hexToInt(end, dataSize));
  38447. for (i = 1; i < subitemsCount; i++) {
  38448. incHex(end, dataSize);
  38449. stream.readHexNumber(start, dataSize);
  38450. addHex(start, end, dataSize);
  38451. stream.readHexNumber(end, dataSize);
  38452. addHex(end, start, dataSize);
  38453. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize), hexToInt(end, dataSize));
  38454. }
  38455. break;
  38456. case 1:
  38457. // notdefrange
  38458. stream.readHex(start, dataSize);
  38459. stream.readHexNumber(end, dataSize);
  38460. addHex(end, start, dataSize);
  38461. code = stream.readNumber();
  38462. // undefined range, skipping
  38463. for (i = 1; i < subitemsCount; i++) {
  38464. incHex(end, dataSize);
  38465. stream.readHexNumber(start, dataSize);
  38466. addHex(start, end, dataSize);
  38467. stream.readHexNumber(end, dataSize);
  38468. addHex(end, start, dataSize);
  38469. code = stream.readNumber();
  38470. }
  38471. // nop
  38472. break;
  38473. case 2:
  38474. // cidchar
  38475. stream.readHex(char, dataSize);
  38476. code = stream.readNumber();
  38477. cMap.mapOne(hexToInt(char, dataSize), code);
  38478. for (i = 1; i < subitemsCount; i++) {
  38479. incHex(char, dataSize);
  38480. if (!sequence) {
  38481. stream.readHexNumber(tmp, dataSize);
  38482. addHex(char, tmp, dataSize);
  38483. }
  38484. code = stream.readSigned() + (code + 1);
  38485. cMap.mapOne(hexToInt(char, dataSize), code);
  38486. }
  38487. break;
  38488. case 3:
  38489. // cidrange
  38490. stream.readHex(start, dataSize);
  38491. stream.readHexNumber(end, dataSize);
  38492. addHex(end, start, dataSize);
  38493. code = stream.readNumber();
  38494. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize), code);
  38495. for (i = 1; i < subitemsCount; i++) {
  38496. incHex(end, dataSize);
  38497. if (!sequence) {
  38498. stream.readHexNumber(start, dataSize);
  38499. addHex(start, end, dataSize);
  38500. } else {
  38501. start.set(end);
  38502. }
  38503. stream.readHexNumber(end, dataSize);
  38504. addHex(end, start, dataSize);
  38505. code = stream.readNumber();
  38506. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize), code);
  38507. }
  38508. break;
  38509. case 4:
  38510. // bfchar
  38511. stream.readHex(char, ucs2DataSize);
  38512. stream.readHex(charCode, dataSize);
  38513. cMap.mapOne(hexToInt(char, ucs2DataSize), hexToStr(charCode, dataSize));
  38514. for (i = 1; i < subitemsCount; i++) {
  38515. incHex(char, ucs2DataSize);
  38516. if (!sequence) {
  38517. stream.readHexNumber(tmp, ucs2DataSize);
  38518. addHex(char, tmp, ucs2DataSize);
  38519. }
  38520. incHex(charCode, dataSize);
  38521. stream.readHexSigned(tmp, dataSize);
  38522. addHex(charCode, tmp, dataSize);
  38523. cMap.mapOne(hexToInt(char, ucs2DataSize), hexToStr(charCode, dataSize));
  38524. }
  38525. break;
  38526. case 5:
  38527. // bfrange
  38528. stream.readHex(start, ucs2DataSize);
  38529. stream.readHexNumber(end, ucs2DataSize);
  38530. addHex(end, start, ucs2DataSize);
  38531. stream.readHex(charCode, dataSize);
  38532. cMap.mapBfRange(hexToInt(start, ucs2DataSize), hexToInt(end, ucs2DataSize), hexToStr(charCode, dataSize));
  38533. for (i = 1; i < subitemsCount; i++) {
  38534. incHex(end, ucs2DataSize);
  38535. if (!sequence) {
  38536. stream.readHexNumber(start, ucs2DataSize);
  38537. addHex(start, end, ucs2DataSize);
  38538. } else {
  38539. start.set(end);
  38540. }
  38541. stream.readHexNumber(end, ucs2DataSize);
  38542. addHex(end, start, ucs2DataSize);
  38543. stream.readHex(charCode, dataSize);
  38544. cMap.mapBfRange(hexToInt(start, ucs2DataSize), hexToInt(end, ucs2DataSize), hexToStr(charCode, dataSize));
  38545. }
  38546. break;
  38547. default:
  38548. error('Unknown type: ' + type);
  38549. break;
  38550. }
  38551. }
  38552. if (useCMap) {
  38553. return extend(useCMap);
  38554. }
  38555. return cMap;
  38556. });
  38557. }
  38558. function BinaryCMapReader() {
  38559. }
  38560. BinaryCMapReader.prototype = { read: processBinaryCMap };
  38561. return BinaryCMapReader;
  38562. }();
  38563. var CMapFactory = function CMapFactoryClosure() {
  38564. function strToInt(str) {
  38565. var a = 0;
  38566. for (var i = 0; i < str.length; i++) {
  38567. a = a << 8 | str.charCodeAt(i);
  38568. }
  38569. return a >>> 0;
  38570. }
  38571. function expectString(obj) {
  38572. if (!isString(obj)) {
  38573. error('Malformed CMap: expected string.');
  38574. }
  38575. }
  38576. function expectInt(obj) {
  38577. if (!isInt(obj)) {
  38578. error('Malformed CMap: expected int.');
  38579. }
  38580. }
  38581. function parseBfChar(cMap, lexer) {
  38582. while (true) {
  38583. var obj = lexer.getObj();
  38584. if (isEOF(obj)) {
  38585. break;
  38586. }
  38587. if (isCmd(obj, 'endbfchar')) {
  38588. return;
  38589. }
  38590. expectString(obj);
  38591. var src = strToInt(obj);
  38592. obj = lexer.getObj();
  38593. // TODO are /dstName used?
  38594. expectString(obj);
  38595. var dst = obj;
  38596. cMap.mapOne(src, dst);
  38597. }
  38598. }
  38599. function parseBfRange(cMap, lexer) {
  38600. while (true) {
  38601. var obj = lexer.getObj();
  38602. if (isEOF(obj)) {
  38603. break;
  38604. }
  38605. if (isCmd(obj, 'endbfrange')) {
  38606. return;
  38607. }
  38608. expectString(obj);
  38609. var low = strToInt(obj);
  38610. obj = lexer.getObj();
  38611. expectString(obj);
  38612. var high = strToInt(obj);
  38613. obj = lexer.getObj();
  38614. if (isInt(obj) || isString(obj)) {
  38615. var dstLow = isInt(obj) ? String.fromCharCode(obj) : obj;
  38616. cMap.mapBfRange(low, high, dstLow);
  38617. } else if (isCmd(obj, '[')) {
  38618. obj = lexer.getObj();
  38619. var array = [];
  38620. while (!isCmd(obj, ']') && !isEOF(obj)) {
  38621. array.push(obj);
  38622. obj = lexer.getObj();
  38623. }
  38624. cMap.mapBfRangeToArray(low, high, array);
  38625. } else {
  38626. break;
  38627. }
  38628. }
  38629. error('Invalid bf range.');
  38630. }
  38631. function parseCidChar(cMap, lexer) {
  38632. while (true) {
  38633. var obj = lexer.getObj();
  38634. if (isEOF(obj)) {
  38635. break;
  38636. }
  38637. if (isCmd(obj, 'endcidchar')) {
  38638. return;
  38639. }
  38640. expectString(obj);
  38641. var src = strToInt(obj);
  38642. obj = lexer.getObj();
  38643. expectInt(obj);
  38644. var dst = obj;
  38645. cMap.mapOne(src, dst);
  38646. }
  38647. }
  38648. function parseCidRange(cMap, lexer) {
  38649. while (true) {
  38650. var obj = lexer.getObj();
  38651. if (isEOF(obj)) {
  38652. break;
  38653. }
  38654. if (isCmd(obj, 'endcidrange')) {
  38655. return;
  38656. }
  38657. expectString(obj);
  38658. var low = strToInt(obj);
  38659. obj = lexer.getObj();
  38660. expectString(obj);
  38661. var high = strToInt(obj);
  38662. obj = lexer.getObj();
  38663. expectInt(obj);
  38664. var dstLow = obj;
  38665. cMap.mapCidRange(low, high, dstLow);
  38666. }
  38667. }
  38668. function parseCodespaceRange(cMap, lexer) {
  38669. while (true) {
  38670. var obj = lexer.getObj();
  38671. if (isEOF(obj)) {
  38672. break;
  38673. }
  38674. if (isCmd(obj, 'endcodespacerange')) {
  38675. return;
  38676. }
  38677. if (!isString(obj)) {
  38678. break;
  38679. }
  38680. var low = strToInt(obj);
  38681. obj = lexer.getObj();
  38682. if (!isString(obj)) {
  38683. break;
  38684. }
  38685. var high = strToInt(obj);
  38686. cMap.addCodespaceRange(obj.length, low, high);
  38687. }
  38688. error('Invalid codespace range.');
  38689. }
  38690. function parseWMode(cMap, lexer) {
  38691. var obj = lexer.getObj();
  38692. if (isInt(obj)) {
  38693. cMap.vertical = !!obj;
  38694. }
  38695. }
  38696. function parseCMapName(cMap, lexer) {
  38697. var obj = lexer.getObj();
  38698. if (isName(obj) && isString(obj.name)) {
  38699. cMap.name = obj.name;
  38700. }
  38701. }
  38702. function parseCMap(cMap, lexer, builtInCMapParams, useCMap) {
  38703. var previous;
  38704. var embededUseCMap;
  38705. objLoop:
  38706. while (true) {
  38707. try {
  38708. var obj = lexer.getObj();
  38709. if (isEOF(obj)) {
  38710. break;
  38711. } else if (isName(obj)) {
  38712. if (obj.name === 'WMode') {
  38713. parseWMode(cMap, lexer);
  38714. } else if (obj.name === 'CMapName') {
  38715. parseCMapName(cMap, lexer);
  38716. }
  38717. previous = obj;
  38718. } else if (isCmd(obj)) {
  38719. switch (obj.cmd) {
  38720. case 'endcmap':
  38721. break objLoop;
  38722. case 'usecmap':
  38723. if (isName(previous)) {
  38724. embededUseCMap = previous.name;
  38725. }
  38726. break;
  38727. case 'begincodespacerange':
  38728. parseCodespaceRange(cMap, lexer);
  38729. break;
  38730. case 'beginbfchar':
  38731. parseBfChar(cMap, lexer);
  38732. break;
  38733. case 'begincidchar':
  38734. parseCidChar(cMap, lexer);
  38735. break;
  38736. case 'beginbfrange':
  38737. parseBfRange(cMap, lexer);
  38738. break;
  38739. case 'begincidrange':
  38740. parseCidRange(cMap, lexer);
  38741. break;
  38742. }
  38743. }
  38744. } catch (ex) {
  38745. if (ex instanceof MissingDataException) {
  38746. throw ex;
  38747. }
  38748. warn('Invalid cMap data: ' + ex);
  38749. continue;
  38750. }
  38751. }
  38752. if (!useCMap && embededUseCMap) {
  38753. // Load the usecmap definition from the file only if there wasn't one
  38754. // specified.
  38755. useCMap = embededUseCMap;
  38756. }
  38757. if (useCMap) {
  38758. return extendCMap(cMap, builtInCMapParams, useCMap);
  38759. }
  38760. return Promise.resolve(cMap);
  38761. }
  38762. function extendCMap(cMap, builtInCMapParams, useCMap) {
  38763. return createBuiltInCMap(useCMap, builtInCMapParams).then(function (newCMap) {
  38764. cMap.useCMap = newCMap;
  38765. // If there aren't any code space ranges defined clone all the parent ones
  38766. // into this cMap.
  38767. if (cMap.numCodespaceRanges === 0) {
  38768. var useCodespaceRanges = cMap.useCMap.codespaceRanges;
  38769. for (var i = 0; i < useCodespaceRanges.length; i++) {
  38770. cMap.codespaceRanges[i] = useCodespaceRanges[i].slice();
  38771. }
  38772. cMap.numCodespaceRanges = cMap.useCMap.numCodespaceRanges;
  38773. }
  38774. // Merge the map into the current one, making sure not to override
  38775. // any previously defined entries.
  38776. cMap.useCMap.forEach(function (key, value) {
  38777. if (!cMap.contains(key)) {
  38778. cMap.mapOne(key, cMap.useCMap.lookup(key));
  38779. }
  38780. });
  38781. return cMap;
  38782. });
  38783. }
  38784. function parseBinaryCMap(name, builtInCMapParams) {
  38785. var url = builtInCMapParams.url + name + '.bcmap';
  38786. var cMap = new CMap(true);
  38787. return new BinaryCMapReader().read(url, cMap, function (useCMap) {
  38788. return extendCMap(cMap, builtInCMapParams, useCMap);
  38789. });
  38790. }
  38791. function createBuiltInCMap(name, builtInCMapParams) {
  38792. if (name === 'Identity-H') {
  38793. return Promise.resolve(new IdentityCMap(false, 2));
  38794. } else if (name === 'Identity-V') {
  38795. return Promise.resolve(new IdentityCMap(true, 2));
  38796. }
  38797. if (BUILT_IN_CMAPS.indexOf(name) === -1) {
  38798. return Promise.reject(new Error('Unknown cMap name: ' + name));
  38799. }
  38800. assert(builtInCMapParams, 'built-in cMap parameters are not provided');
  38801. if (builtInCMapParams.packed) {
  38802. return parseBinaryCMap(name, builtInCMapParams);
  38803. }
  38804. return new Promise(function (resolve, reject) {
  38805. var url = builtInCMapParams.url + name;
  38806. var request = new XMLHttpRequest();
  38807. request.onreadystatechange = function () {
  38808. if (request.readyState === XMLHttpRequest.DONE) {
  38809. if (request.status === 200 || request.status === 0) {
  38810. var cMap = new CMap(true);
  38811. var lexer = new Lexer(new StringStream(request.responseText));
  38812. parseCMap(cMap, lexer, builtInCMapParams, null).then(function (parsedCMap) {
  38813. resolve(parsedCMap);
  38814. });
  38815. } else {
  38816. reject(new Error('Unable to get cMap at: ' + url));
  38817. }
  38818. }
  38819. };
  38820. request.open('GET', url, true);
  38821. request.send(null);
  38822. });
  38823. }
  38824. return {
  38825. create: function (encoding, builtInCMapParams, useCMap) {
  38826. if (isName(encoding)) {
  38827. return createBuiltInCMap(encoding.name, builtInCMapParams);
  38828. } else if (isStream(encoding)) {
  38829. var cMap = new CMap();
  38830. var lexer = new Lexer(encoding);
  38831. return parseCMap(cMap, lexer, builtInCMapParams, useCMap).then(function (parsedCMap) {
  38832. if (parsedCMap.isIdentityCMap) {
  38833. return createBuiltInCMap(parsedCMap.name, builtInCMapParams);
  38834. }
  38835. return parsedCMap;
  38836. });
  38837. }
  38838. return Promise.reject(new Error('Encoding required.'));
  38839. }
  38840. };
  38841. }();
  38842. exports.CMap = CMap;
  38843. exports.CMapFactory = CMapFactory;
  38844. exports.IdentityCMap = IdentityCMap;
  38845. }));
  38846. (function (root, factory) {
  38847. factory(root.pdfjsCoreFonts = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreGlyphList, root.pdfjsCoreFontRenderer, root.pdfjsCoreEncodings, root.pdfjsCoreStandardFonts, root.pdfjsCoreUnicode, root.pdfjsCoreType1Parser, root.pdfjsCoreCFFParser);
  38848. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreGlyphList, coreFontRenderer, coreEncodings, coreStandardFonts, coreUnicode, coreType1Parser, coreCFFParser) {
  38849. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  38850. var FontType = sharedUtil.FontType;
  38851. var assert = sharedUtil.assert;
  38852. var bytesToString = sharedUtil.bytesToString;
  38853. var error = sharedUtil.error;
  38854. var info = sharedUtil.info;
  38855. var isArray = sharedUtil.isArray;
  38856. var isInt = sharedUtil.isInt;
  38857. var isNum = sharedUtil.isNum;
  38858. var readUint32 = sharedUtil.readUint32;
  38859. var shadow = sharedUtil.shadow;
  38860. var string32 = sharedUtil.string32;
  38861. var warn = sharedUtil.warn;
  38862. var MissingDataException = sharedUtil.MissingDataException;
  38863. var isSpace = sharedUtil.isSpace;
  38864. var Stream = coreStream.Stream;
  38865. var getGlyphsUnicode = coreGlyphList.getGlyphsUnicode;
  38866. var getDingbatsGlyphsUnicode = coreGlyphList.getDingbatsGlyphsUnicode;
  38867. var FontRendererFactory = coreFontRenderer.FontRendererFactory;
  38868. var StandardEncoding = coreEncodings.StandardEncoding;
  38869. var MacRomanEncoding = coreEncodings.MacRomanEncoding;
  38870. var SymbolSetEncoding = coreEncodings.SymbolSetEncoding;
  38871. var ZapfDingbatsEncoding = coreEncodings.ZapfDingbatsEncoding;
  38872. var getEncoding = coreEncodings.getEncoding;
  38873. var getStdFontMap = coreStandardFonts.getStdFontMap;
  38874. var getNonStdFontMap = coreStandardFonts.getNonStdFontMap;
  38875. var getGlyphMapForStandardFonts = coreStandardFonts.getGlyphMapForStandardFonts;
  38876. var getSupplementalGlyphMapForArialBlack = coreStandardFonts.getSupplementalGlyphMapForArialBlack;
  38877. var getUnicodeRangeFor = coreUnicode.getUnicodeRangeFor;
  38878. var mapSpecialUnicodeValues = coreUnicode.mapSpecialUnicodeValues;
  38879. var getUnicodeForGlyph = coreUnicode.getUnicodeForGlyph;
  38880. var Type1Parser = coreType1Parser.Type1Parser;
  38881. var CFFStandardStrings = coreCFFParser.CFFStandardStrings;
  38882. var CFFParser = coreCFFParser.CFFParser;
  38883. var CFFCompiler = coreCFFParser.CFFCompiler;
  38884. var CFF = coreCFFParser.CFF;
  38885. var CFFHeader = coreCFFParser.CFFHeader;
  38886. var CFFTopDict = coreCFFParser.CFFTopDict;
  38887. var CFFPrivateDict = coreCFFParser.CFFPrivateDict;
  38888. var CFFStrings = coreCFFParser.CFFStrings;
  38889. var CFFIndex = coreCFFParser.CFFIndex;
  38890. var CFFCharset = coreCFFParser.CFFCharset;
  38891. // Unicode Private Use Area
  38892. var PRIVATE_USE_OFFSET_START = 0xE000;
  38893. var PRIVATE_USE_OFFSET_END = 0xF8FF;
  38894. var SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = false;
  38895. // PDF Glyph Space Units are one Thousandth of a TextSpace Unit
  38896. // except for Type 3 fonts
  38897. var PDF_GLYPH_SPACE_UNITS = 1000;
  38898. // Accented charactars are not displayed properly on Windows, using this flag
  38899. // to control analysis of seac charstrings.
  38900. var SEAC_ANALYSIS_ENABLED = false;
  38901. var FontFlags = {
  38902. FixedPitch: 1,
  38903. Serif: 2,
  38904. Symbolic: 4,
  38905. Script: 8,
  38906. Nonsymbolic: 32,
  38907. Italic: 64,
  38908. AllCap: 65536,
  38909. SmallCap: 131072,
  38910. ForceBold: 262144
  38911. };
  38912. var MacStandardGlyphOrdering = [
  38913. '.notdef',
  38914. '.null',
  38915. 'nonmarkingreturn',
  38916. 'space',
  38917. 'exclam',
  38918. 'quotedbl',
  38919. 'numbersign',
  38920. 'dollar',
  38921. 'percent',
  38922. 'ampersand',
  38923. 'quotesingle',
  38924. 'parenleft',
  38925. 'parenright',
  38926. 'asterisk',
  38927. 'plus',
  38928. 'comma',
  38929. 'hyphen',
  38930. 'period',
  38931. 'slash',
  38932. 'zero',
  38933. 'one',
  38934. 'two',
  38935. 'three',
  38936. 'four',
  38937. 'five',
  38938. 'six',
  38939. 'seven',
  38940. 'eight',
  38941. 'nine',
  38942. 'colon',
  38943. 'semicolon',
  38944. 'less',
  38945. 'equal',
  38946. 'greater',
  38947. 'question',
  38948. 'at',
  38949. 'A',
  38950. 'B',
  38951. 'C',
  38952. 'D',
  38953. 'E',
  38954. 'F',
  38955. 'G',
  38956. 'H',
  38957. 'I',
  38958. 'J',
  38959. 'K',
  38960. 'L',
  38961. 'M',
  38962. 'N',
  38963. 'O',
  38964. 'P',
  38965. 'Q',
  38966. 'R',
  38967. 'S',
  38968. 'T',
  38969. 'U',
  38970. 'V',
  38971. 'W',
  38972. 'X',
  38973. 'Y',
  38974. 'Z',
  38975. 'bracketleft',
  38976. 'backslash',
  38977. 'bracketright',
  38978. 'asciicircum',
  38979. 'underscore',
  38980. 'grave',
  38981. 'a',
  38982. 'b',
  38983. 'c',
  38984. 'd',
  38985. 'e',
  38986. 'f',
  38987. 'g',
  38988. 'h',
  38989. 'i',
  38990. 'j',
  38991. 'k',
  38992. 'l',
  38993. 'm',
  38994. 'n',
  38995. 'o',
  38996. 'p',
  38997. 'q',
  38998. 'r',
  38999. 's',
  39000. 't',
  39001. 'u',
  39002. 'v',
  39003. 'w',
  39004. 'x',
  39005. 'y',
  39006. 'z',
  39007. 'braceleft',
  39008. 'bar',
  39009. 'braceright',
  39010. 'asciitilde',
  39011. 'Adieresis',
  39012. 'Aring',
  39013. 'Ccedilla',
  39014. 'Eacute',
  39015. 'Ntilde',
  39016. 'Odieresis',
  39017. 'Udieresis',
  39018. 'aacute',
  39019. 'agrave',
  39020. 'acircumflex',
  39021. 'adieresis',
  39022. 'atilde',
  39023. 'aring',
  39024. 'ccedilla',
  39025. 'eacute',
  39026. 'egrave',
  39027. 'ecircumflex',
  39028. 'edieresis',
  39029. 'iacute',
  39030. 'igrave',
  39031. 'icircumflex',
  39032. 'idieresis',
  39033. 'ntilde',
  39034. 'oacute',
  39035. 'ograve',
  39036. 'ocircumflex',
  39037. 'odieresis',
  39038. 'otilde',
  39039. 'uacute',
  39040. 'ugrave',
  39041. 'ucircumflex',
  39042. 'udieresis',
  39043. 'dagger',
  39044. 'degree',
  39045. 'cent',
  39046. 'sterling',
  39047. 'section',
  39048. 'bullet',
  39049. 'paragraph',
  39050. 'germandbls',
  39051. 'registered',
  39052. 'copyright',
  39053. 'trademark',
  39054. 'acute',
  39055. 'dieresis',
  39056. 'notequal',
  39057. 'AE',
  39058. 'Oslash',
  39059. 'infinity',
  39060. 'plusminus',
  39061. 'lessequal',
  39062. 'greaterequal',
  39063. 'yen',
  39064. 'mu',
  39065. 'partialdiff',
  39066. 'summation',
  39067. 'product',
  39068. 'pi',
  39069. 'integral',
  39070. 'ordfeminine',
  39071. 'ordmasculine',
  39072. 'Omega',
  39073. 'ae',
  39074. 'oslash',
  39075. 'questiondown',
  39076. 'exclamdown',
  39077. 'logicalnot',
  39078. 'radical',
  39079. 'florin',
  39080. 'approxequal',
  39081. 'Delta',
  39082. 'guillemotleft',
  39083. 'guillemotright',
  39084. 'ellipsis',
  39085. 'nonbreakingspace',
  39086. 'Agrave',
  39087. 'Atilde',
  39088. 'Otilde',
  39089. 'OE',
  39090. 'oe',
  39091. 'endash',
  39092. 'emdash',
  39093. 'quotedblleft',
  39094. 'quotedblright',
  39095. 'quoteleft',
  39096. 'quoteright',
  39097. 'divide',
  39098. 'lozenge',
  39099. 'ydieresis',
  39100. 'Ydieresis',
  39101. 'fraction',
  39102. 'currency',
  39103. 'guilsinglleft',
  39104. 'guilsinglright',
  39105. 'fi',
  39106. 'fl',
  39107. 'daggerdbl',
  39108. 'periodcentered',
  39109. 'quotesinglbase',
  39110. 'quotedblbase',
  39111. 'perthousand',
  39112. 'Acircumflex',
  39113. 'Ecircumflex',
  39114. 'Aacute',
  39115. 'Edieresis',
  39116. 'Egrave',
  39117. 'Iacute',
  39118. 'Icircumflex',
  39119. 'Idieresis',
  39120. 'Igrave',
  39121. 'Oacute',
  39122. 'Ocircumflex',
  39123. 'apple',
  39124. 'Ograve',
  39125. 'Uacute',
  39126. 'Ucircumflex',
  39127. 'Ugrave',
  39128. 'dotlessi',
  39129. 'circumflex',
  39130. 'tilde',
  39131. 'macron',
  39132. 'breve',
  39133. 'dotaccent',
  39134. 'ring',
  39135. 'cedilla',
  39136. 'hungarumlaut',
  39137. 'ogonek',
  39138. 'caron',
  39139. 'Lslash',
  39140. 'lslash',
  39141. 'Scaron',
  39142. 'scaron',
  39143. 'Zcaron',
  39144. 'zcaron',
  39145. 'brokenbar',
  39146. 'Eth',
  39147. 'eth',
  39148. 'Yacute',
  39149. 'yacute',
  39150. 'Thorn',
  39151. 'thorn',
  39152. 'minus',
  39153. 'multiply',
  39154. 'onesuperior',
  39155. 'twosuperior',
  39156. 'threesuperior',
  39157. 'onehalf',
  39158. 'onequarter',
  39159. 'threequarters',
  39160. 'franc',
  39161. 'Gbreve',
  39162. 'gbreve',
  39163. 'Idotaccent',
  39164. 'Scedilla',
  39165. 'scedilla',
  39166. 'Cacute',
  39167. 'cacute',
  39168. 'Ccaron',
  39169. 'ccaron',
  39170. 'dcroat'
  39171. ];
  39172. function adjustWidths(properties) {
  39173. if (!properties.fontMatrix) {
  39174. return;
  39175. }
  39176. if (properties.fontMatrix[0] === FONT_IDENTITY_MATRIX[0]) {
  39177. return;
  39178. }
  39179. // adjusting width to fontMatrix scale
  39180. var scale = 0.001 / properties.fontMatrix[0];
  39181. var glyphsWidths = properties.widths;
  39182. for (var glyph in glyphsWidths) {
  39183. glyphsWidths[glyph] *= scale;
  39184. }
  39185. properties.defaultWidth *= scale;
  39186. }
  39187. function adjustToUnicode(properties, builtInEncoding) {
  39188. if (properties.hasIncludedToUnicodeMap) {
  39189. return;
  39190. }
  39191. // The font dictionary has a `ToUnicode` entry.
  39192. if (properties.hasEncoding) {
  39193. return;
  39194. }
  39195. // The font dictionary has an `Encoding` entry.
  39196. if (builtInEncoding === properties.defaultEncoding) {
  39197. return;
  39198. }
  39199. // No point in trying to adjust `toUnicode` if the encodings match.
  39200. if (properties.toUnicode instanceof IdentityToUnicodeMap) {
  39201. return;
  39202. }
  39203. var toUnicode = [], glyphsUnicodeMap = getGlyphsUnicode();
  39204. for (var charCode in builtInEncoding) {
  39205. var glyphName = builtInEncoding[charCode];
  39206. var unicode = getUnicodeForGlyph(glyphName, glyphsUnicodeMap);
  39207. if (unicode !== -1) {
  39208. toUnicode[charCode] = String.fromCharCode(unicode);
  39209. }
  39210. }
  39211. properties.toUnicode.amend(toUnicode);
  39212. }
  39213. function getFontType(type, subtype) {
  39214. switch (type) {
  39215. case 'Type1':
  39216. return subtype === 'Type1C' ? FontType.TYPE1C : FontType.TYPE1;
  39217. case 'CIDFontType0':
  39218. return subtype === 'CIDFontType0C' ? FontType.CIDFONTTYPE0C : FontType.CIDFONTTYPE0;
  39219. case 'OpenType':
  39220. return FontType.OPENTYPE;
  39221. case 'TrueType':
  39222. return FontType.TRUETYPE;
  39223. case 'CIDFontType2':
  39224. return FontType.CIDFONTTYPE2;
  39225. case 'MMType1':
  39226. return FontType.MMTYPE1;
  39227. case 'Type0':
  39228. return FontType.TYPE0;
  39229. default:
  39230. return FontType.UNKNOWN;
  39231. }
  39232. }
  39233. // Some bad PDF generators, e.g. Scribus PDF, include glyph names
  39234. // in a 'uniXXXX' format -- attempting to recover proper ones.
  39235. function recoverGlyphName(name, glyphsUnicodeMap) {
  39236. if (glyphsUnicodeMap[name] !== undefined) {
  39237. return name;
  39238. }
  39239. // The glyph name is non-standard, trying to recover.
  39240. var unicode = getUnicodeForGlyph(name, glyphsUnicodeMap);
  39241. if (unicode !== -1) {
  39242. for (var key in glyphsUnicodeMap) {
  39243. if (glyphsUnicodeMap[key] === unicode) {
  39244. return key;
  39245. }
  39246. }
  39247. }
  39248. info('Unable to recover a standard glyph name for: ' + name);
  39249. return name;
  39250. }
  39251. var Glyph = function GlyphClosure() {
  39252. function Glyph(fontChar, unicode, accent, width, vmetric, operatorListId, isSpace, isInFont) {
  39253. this.fontChar = fontChar;
  39254. this.unicode = unicode;
  39255. this.accent = accent;
  39256. this.width = width;
  39257. this.vmetric = vmetric;
  39258. this.operatorListId = operatorListId;
  39259. this.isSpace = isSpace;
  39260. this.isInFont = isInFont;
  39261. }
  39262. Glyph.prototype.matchesForCache = function (fontChar, unicode, accent, width, vmetric, operatorListId, isSpace, isInFont) {
  39263. 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;
  39264. };
  39265. return Glyph;
  39266. }();
  39267. var ToUnicodeMap = function ToUnicodeMapClosure() {
  39268. function ToUnicodeMap(cmap) {
  39269. // The elements of this._map can be integers or strings, depending on how
  39270. // |cmap| was created.
  39271. this._map = cmap;
  39272. }
  39273. ToUnicodeMap.prototype = {
  39274. get length() {
  39275. return this._map.length;
  39276. },
  39277. forEach: function (callback) {
  39278. for (var charCode in this._map) {
  39279. callback(charCode, this._map[charCode].charCodeAt(0));
  39280. }
  39281. },
  39282. has: function (i) {
  39283. return this._map[i] !== undefined;
  39284. },
  39285. get: function (i) {
  39286. return this._map[i];
  39287. },
  39288. charCodeOf: function (v) {
  39289. return this._map.indexOf(v);
  39290. },
  39291. amend: function (map) {
  39292. for (var charCode in map) {
  39293. this._map[charCode] = map[charCode];
  39294. }
  39295. }
  39296. };
  39297. return ToUnicodeMap;
  39298. }();
  39299. var IdentityToUnicodeMap = function IdentityToUnicodeMapClosure() {
  39300. function IdentityToUnicodeMap(firstChar, lastChar) {
  39301. this.firstChar = firstChar;
  39302. this.lastChar = lastChar;
  39303. }
  39304. IdentityToUnicodeMap.prototype = {
  39305. get length() {
  39306. return this.lastChar + 1 - this.firstChar;
  39307. },
  39308. forEach: function (callback) {
  39309. for (var i = this.firstChar, ii = this.lastChar; i <= ii; i++) {
  39310. callback(i, i);
  39311. }
  39312. },
  39313. has: function (i) {
  39314. return this.firstChar <= i && i <= this.lastChar;
  39315. },
  39316. get: function (i) {
  39317. if (this.firstChar <= i && i <= this.lastChar) {
  39318. return String.fromCharCode(i);
  39319. }
  39320. return undefined;
  39321. },
  39322. charCodeOf: function (v) {
  39323. return isInt(v) && v >= this.firstChar && v <= this.lastChar ? v : -1;
  39324. },
  39325. amend: function (map) {
  39326. error('Should not call amend()');
  39327. }
  39328. };
  39329. return IdentityToUnicodeMap;
  39330. }();
  39331. var OpenTypeFileBuilder = function OpenTypeFileBuilderClosure() {
  39332. function writeInt16(dest, offset, num) {
  39333. dest[offset] = num >> 8 & 0xFF;
  39334. dest[offset + 1] = num & 0xFF;
  39335. }
  39336. function writeInt32(dest, offset, num) {
  39337. dest[offset] = num >> 24 & 0xFF;
  39338. dest[offset + 1] = num >> 16 & 0xFF;
  39339. dest[offset + 2] = num >> 8 & 0xFF;
  39340. dest[offset + 3] = num & 0xFF;
  39341. }
  39342. function writeData(dest, offset, data) {
  39343. var i, ii;
  39344. if (data instanceof Uint8Array) {
  39345. dest.set(data, offset);
  39346. } else if (typeof data === 'string') {
  39347. for (i = 0, ii = data.length; i < ii; i++) {
  39348. dest[offset++] = data.charCodeAt(i) & 0xFF;
  39349. }
  39350. } else {
  39351. // treating everything else as array
  39352. for (i = 0, ii = data.length; i < ii; i++) {
  39353. dest[offset++] = data[i] & 0xFF;
  39354. }
  39355. }
  39356. }
  39357. function OpenTypeFileBuilder(sfnt) {
  39358. this.sfnt = sfnt;
  39359. this.tables = Object.create(null);
  39360. }
  39361. OpenTypeFileBuilder.getSearchParams = function OpenTypeFileBuilder_getSearchParams(entriesCount, entrySize) {
  39362. var maxPower2 = 1, log2 = 0;
  39363. while ((maxPower2 ^ entriesCount) > maxPower2) {
  39364. maxPower2 <<= 1;
  39365. log2++;
  39366. }
  39367. var searchRange = maxPower2 * entrySize;
  39368. return {
  39369. range: searchRange,
  39370. entry: log2,
  39371. rangeShift: entrySize * entriesCount - searchRange
  39372. };
  39373. };
  39374. var OTF_HEADER_SIZE = 12;
  39375. var OTF_TABLE_ENTRY_SIZE = 16;
  39376. OpenTypeFileBuilder.prototype = {
  39377. toArray: function OpenTypeFileBuilder_toArray() {
  39378. var sfnt = this.sfnt;
  39379. // Tables needs to be written by ascendant alphabetic order
  39380. var tables = this.tables;
  39381. var tablesNames = Object.keys(tables);
  39382. tablesNames.sort();
  39383. var numTables = tablesNames.length;
  39384. var i, j, jj, table, tableName;
  39385. // layout the tables data
  39386. var offset = OTF_HEADER_SIZE + numTables * OTF_TABLE_ENTRY_SIZE;
  39387. var tableOffsets = [offset];
  39388. for (i = 0; i < numTables; i++) {
  39389. table = tables[tablesNames[i]];
  39390. var paddedLength = (table.length + 3 & ~3) >>> 0;
  39391. offset += paddedLength;
  39392. tableOffsets.push(offset);
  39393. }
  39394. var file = new Uint8Array(offset);
  39395. // write the table data first (mostly for checksum)
  39396. for (i = 0; i < numTables; i++) {
  39397. table = tables[tablesNames[i]];
  39398. writeData(file, tableOffsets[i], table);
  39399. }
  39400. // sfnt version (4 bytes)
  39401. if (sfnt === 'true') {
  39402. // Windows hates the Mac TrueType sfnt version number
  39403. sfnt = string32(0x00010000);
  39404. }
  39405. file[0] = sfnt.charCodeAt(0) & 0xFF;
  39406. file[1] = sfnt.charCodeAt(1) & 0xFF;
  39407. file[2] = sfnt.charCodeAt(2) & 0xFF;
  39408. file[3] = sfnt.charCodeAt(3) & 0xFF;
  39409. // numTables (2 bytes)
  39410. writeInt16(file, 4, numTables);
  39411. var searchParams = OpenTypeFileBuilder.getSearchParams(numTables, 16);
  39412. // searchRange (2 bytes)
  39413. writeInt16(file, 6, searchParams.range);
  39414. // entrySelector (2 bytes)
  39415. writeInt16(file, 8, searchParams.entry);
  39416. // rangeShift (2 bytes)
  39417. writeInt16(file, 10, searchParams.rangeShift);
  39418. offset = OTF_HEADER_SIZE;
  39419. // writing table entries
  39420. for (i = 0; i < numTables; i++) {
  39421. tableName = tablesNames[i];
  39422. file[offset] = tableName.charCodeAt(0) & 0xFF;
  39423. file[offset + 1] = tableName.charCodeAt(1) & 0xFF;
  39424. file[offset + 2] = tableName.charCodeAt(2) & 0xFF;
  39425. file[offset + 3] = tableName.charCodeAt(3) & 0xFF;
  39426. // checksum
  39427. var checksum = 0;
  39428. for (j = tableOffsets[i], jj = tableOffsets[i + 1]; j < jj; j += 4) {
  39429. var quad = readUint32(file, j);
  39430. checksum = checksum + quad >>> 0;
  39431. }
  39432. writeInt32(file, offset + 4, checksum);
  39433. // offset
  39434. writeInt32(file, offset + 8, tableOffsets[i]);
  39435. // length
  39436. writeInt32(file, offset + 12, tables[tableName].length);
  39437. offset += OTF_TABLE_ENTRY_SIZE;
  39438. }
  39439. return file;
  39440. },
  39441. addTable: function OpenTypeFileBuilder_addTable(tag, data) {
  39442. if (tag in this.tables) {
  39443. throw new Error('Table ' + tag + ' already exists');
  39444. }
  39445. this.tables[tag] = data;
  39446. }
  39447. };
  39448. return OpenTypeFileBuilder;
  39449. }();
  39450. // Problematic Unicode characters in the fonts that needs to be moved to avoid
  39451. // issues when they are painted on the canvas, e.g. complex-script shaping or
  39452. // control/whitespace characters. The ranges are listed in pairs: the first item
  39453. // is a code of the first problematic code, the second one is the next
  39454. // non-problematic code. The ranges must be in sorted order.
  39455. var ProblematicCharRanges = new Int32Array([
  39456. // Control characters.
  39457. 0x0000,
  39458. 0x0020,
  39459. 0x007F,
  39460. 0x00A1,
  39461. 0x00AD,
  39462. 0x00AE,
  39463. // Chars that is used in complex-script shaping.
  39464. 0x0600,
  39465. 0x0780,
  39466. 0x08A0,
  39467. 0x10A0,
  39468. 0x1780,
  39469. 0x1800,
  39470. 0x1C00,
  39471. 0x1C50,
  39472. // General punctuation chars.
  39473. 0x2000,
  39474. 0x2010,
  39475. 0x2011,
  39476. 0x2012,
  39477. 0x2028,
  39478. 0x2030,
  39479. 0x205F,
  39480. 0x2070,
  39481. 0x25CC,
  39482. 0x25CD,
  39483. 0x3000,
  39484. 0x3001,
  39485. // Chars that is used in complex-script shaping.
  39486. 0xAA60,
  39487. 0xAA80,
  39488. // Specials Unicode block.
  39489. 0xFFF0,
  39490. 0x10000
  39491. ]);
  39492. /**
  39493. * 'Font' is the class the outside world should use, it encapsulate all the font
  39494. * decoding logics whatever type it is (assuming the font type is supported).
  39495. *
  39496. * For example to read a Type1 font and to attach it to the document:
  39497. * var type1Font = new Font("MyFontName", binaryFile, propertiesObject);
  39498. * type1Font.bind();
  39499. */
  39500. var Font = function FontClosure() {
  39501. function Font(name, file, properties) {
  39502. var charCode, glyphName, unicode;
  39503. this.name = name;
  39504. this.loadedName = properties.loadedName;
  39505. this.isType3Font = properties.isType3Font;
  39506. this.sizes = [];
  39507. this.missingFile = false;
  39508. this.glyphCache = Object.create(null);
  39509. var names = name.split('+');
  39510. names = names.length > 1 ? names[1] : names[0];
  39511. names = names.split(/[-,_]/g)[0];
  39512. this.isSerifFont = !!(properties.flags & FontFlags.Serif);
  39513. this.isSymbolicFont = !!(properties.flags & FontFlags.Symbolic);
  39514. this.isMonospace = !!(properties.flags & FontFlags.FixedPitch);
  39515. var type = properties.type;
  39516. var subtype = properties.subtype;
  39517. this.type = type;
  39518. this.fallbackName = this.isMonospace ? 'monospace' : this.isSerifFont ? 'serif' : 'sans-serif';
  39519. this.differences = properties.differences;
  39520. this.widths = properties.widths;
  39521. this.defaultWidth = properties.defaultWidth;
  39522. this.composite = properties.composite;
  39523. this.wideChars = properties.wideChars;
  39524. this.cMap = properties.cMap;
  39525. this.ascent = properties.ascent / PDF_GLYPH_SPACE_UNITS;
  39526. this.descent = properties.descent / PDF_GLYPH_SPACE_UNITS;
  39527. this.fontMatrix = properties.fontMatrix;
  39528. this.bbox = properties.bbox;
  39529. this.toUnicode = properties.toUnicode;
  39530. this.toFontChar = [];
  39531. if (properties.type === 'Type3') {
  39532. for (charCode = 0; charCode < 256; charCode++) {
  39533. this.toFontChar[charCode] = this.differences[charCode] || properties.defaultEncoding[charCode];
  39534. }
  39535. this.fontType = FontType.TYPE3;
  39536. return;
  39537. }
  39538. this.cidEncoding = properties.cidEncoding;
  39539. this.vertical = properties.vertical;
  39540. if (this.vertical) {
  39541. this.vmetrics = properties.vmetrics;
  39542. this.defaultVMetrics = properties.defaultVMetrics;
  39543. }
  39544. var glyphsUnicodeMap;
  39545. if (!file || file.isEmpty) {
  39546. if (file) {
  39547. // Some bad PDF generators will include empty font files,
  39548. // attempting to recover by assuming that no file exists.
  39549. warn('Font file is empty in "' + name + '" (' + this.loadedName + ')');
  39550. }
  39551. this.missingFile = true;
  39552. // The file data is not specified. Trying to fix the font name
  39553. // to be used with the canvas.font.
  39554. var fontName = name.replace(/[,_]/g, '-');
  39555. var stdFontMap = getStdFontMap(), nonStdFontMap = getNonStdFontMap();
  39556. var isStandardFont = !!stdFontMap[fontName] || !!(nonStdFontMap[fontName] && stdFontMap[nonStdFontMap[fontName]]);
  39557. fontName = stdFontMap[fontName] || nonStdFontMap[fontName] || fontName;
  39558. this.bold = fontName.search(/bold/gi) !== -1;
  39559. this.italic = fontName.search(/oblique/gi) !== -1 || fontName.search(/italic/gi) !== -1;
  39560. // Use 'name' instead of 'fontName' here because the original
  39561. // name ArialBlack for example will be replaced by Helvetica.
  39562. this.black = name.search(/Black/g) !== -1;
  39563. // if at least one width is present, remeasure all chars when exists
  39564. this.remeasure = Object.keys(this.widths).length > 0;
  39565. if (isStandardFont && type === 'CIDFontType2' && properties.cidEncoding.indexOf('Identity-') === 0) {
  39566. var GlyphMapForStandardFonts = getGlyphMapForStandardFonts();
  39567. // Standard fonts might be embedded as CID font without glyph mapping.
  39568. // Building one based on GlyphMapForStandardFonts.
  39569. var map = [];
  39570. for (charCode in GlyphMapForStandardFonts) {
  39571. map[+charCode] = GlyphMapForStandardFonts[charCode];
  39572. }
  39573. if (/ArialBlack/i.test(name)) {
  39574. var SupplementalGlyphMapForArialBlack = getSupplementalGlyphMapForArialBlack();
  39575. for (charCode in SupplementalGlyphMapForArialBlack) {
  39576. map[+charCode] = SupplementalGlyphMapForArialBlack[charCode];
  39577. }
  39578. }
  39579. var isIdentityUnicode = this.toUnicode instanceof IdentityToUnicodeMap;
  39580. if (!isIdentityUnicode) {
  39581. this.toUnicode.forEach(function (charCode, unicodeCharCode) {
  39582. map[+charCode] = unicodeCharCode;
  39583. });
  39584. }
  39585. this.toFontChar = map;
  39586. this.toUnicode = new ToUnicodeMap(map);
  39587. } else if (/Symbol/i.test(fontName)) {
  39588. this.toFontChar = buildToFontChar(SymbolSetEncoding, getGlyphsUnicode(), properties.differences);
  39589. } else if (/Dingbats/i.test(fontName)) {
  39590. if (/Wingdings/i.test(name)) {
  39591. warn('Non-embedded Wingdings font, falling back to ZapfDingbats.');
  39592. }
  39593. this.toFontChar = buildToFontChar(ZapfDingbatsEncoding, getDingbatsGlyphsUnicode(), properties.differences);
  39594. } else if (isStandardFont) {
  39595. this.toFontChar = buildToFontChar(properties.defaultEncoding, getGlyphsUnicode(), properties.differences);
  39596. } else {
  39597. glyphsUnicodeMap = getGlyphsUnicode();
  39598. this.toUnicode.forEach(function (charCode, unicodeCharCode) {
  39599. if (!this.composite) {
  39600. glyphName = properties.differences[charCode] || properties.defaultEncoding[charCode];
  39601. unicode = getUnicodeForGlyph(glyphName, glyphsUnicodeMap);
  39602. if (unicode !== -1) {
  39603. unicodeCharCode = unicode;
  39604. }
  39605. }
  39606. this.toFontChar[charCode] = unicodeCharCode;
  39607. }.bind(this));
  39608. }
  39609. this.loadedName = fontName.split('-')[0];
  39610. this.loading = false;
  39611. this.fontType = getFontType(type, subtype);
  39612. return;
  39613. }
  39614. // Some fonts might use wrong font types for Type1C or CIDFontType0C
  39615. if (subtype === 'Type1C') {
  39616. if (type !== 'Type1' && type !== 'MMType1') {
  39617. // Some TrueType fonts by mistake claim Type1C
  39618. if (isTrueTypeFile(file)) {
  39619. subtype = 'TrueType';
  39620. } else {
  39621. type = 'Type1';
  39622. }
  39623. } else if (isOpenTypeFile(file)) {
  39624. // Sometimes the type/subtype can be a complete lie (see issue7598.pdf).
  39625. type = subtype = 'OpenType';
  39626. }
  39627. }
  39628. if (subtype === 'CIDFontType0C' && type !== 'CIDFontType0') {
  39629. type = 'CIDFontType0';
  39630. }
  39631. if (subtype === 'OpenType') {
  39632. type = 'OpenType';
  39633. }
  39634. // Some CIDFontType0C fonts by mistake claim CIDFontType0.
  39635. if (type === 'CIDFontType0') {
  39636. if (isType1File(file)) {
  39637. subtype = 'CIDFontType0';
  39638. } else if (isOpenTypeFile(file)) {
  39639. // Sometimes the type/subtype can be a complete lie (see issue6782.pdf).
  39640. type = subtype = 'OpenType';
  39641. } else {
  39642. subtype = 'CIDFontType0C';
  39643. }
  39644. }
  39645. var data;
  39646. switch (type) {
  39647. case 'MMType1':
  39648. info('MMType1 font (' + name + '), falling back to Type1.');
  39649. case 'Type1':
  39650. case 'CIDFontType0':
  39651. this.mimetype = 'font/opentype';
  39652. var cff = subtype === 'Type1C' || subtype === 'CIDFontType0C' ? new CFFFont(file, properties) : new Type1Font(name, file, properties);
  39653. adjustWidths(properties);
  39654. // Wrap the CFF data inside an OTF font file
  39655. data = this.convert(name, cff, properties);
  39656. break;
  39657. case 'OpenType':
  39658. case 'TrueType':
  39659. case 'CIDFontType2':
  39660. this.mimetype = 'font/opentype';
  39661. // Repair the TrueType file. It is can be damaged in the point of
  39662. // view of the sanitizer
  39663. data = this.checkAndRepair(name, file, properties);
  39664. if (this.isOpenType) {
  39665. adjustWidths(properties);
  39666. type = 'OpenType';
  39667. }
  39668. break;
  39669. default:
  39670. error('Font ' + type + ' is not supported');
  39671. break;
  39672. }
  39673. this.data = data;
  39674. this.fontType = getFontType(type, subtype);
  39675. // Transfer some properties again that could change during font conversion
  39676. this.fontMatrix = properties.fontMatrix;
  39677. this.widths = properties.widths;
  39678. this.defaultWidth = properties.defaultWidth;
  39679. this.toUnicode = properties.toUnicode;
  39680. this.encoding = properties.baseEncoding;
  39681. this.seacMap = properties.seacMap;
  39682. this.loading = true;
  39683. }
  39684. Font.getFontID = function () {
  39685. var ID = 1;
  39686. return function Font_getFontID() {
  39687. return String(ID++);
  39688. };
  39689. }();
  39690. function int16(b0, b1) {
  39691. return (b0 << 8) + b1;
  39692. }
  39693. function signedInt16(b0, b1) {
  39694. var value = (b0 << 8) + b1;
  39695. return value & 1 << 15 ? value - 0x10000 : value;
  39696. }
  39697. function int32(b0, b1, b2, b3) {
  39698. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  39699. }
  39700. function string16(value) {
  39701. return String.fromCharCode(value >> 8 & 0xff, value & 0xff);
  39702. }
  39703. function safeString16(value) {
  39704. // clamp value to the 16-bit int range
  39705. value = value > 0x7FFF ? 0x7FFF : value < -0x8000 ? -0x8000 : value;
  39706. return String.fromCharCode(value >> 8 & 0xff, value & 0xff);
  39707. }
  39708. function isTrueTypeFile(file) {
  39709. var header = file.peekBytes(4);
  39710. return readUint32(header, 0) === 0x00010000;
  39711. }
  39712. function isOpenTypeFile(file) {
  39713. var header = file.peekBytes(4);
  39714. return bytesToString(header) === 'OTTO';
  39715. }
  39716. function isType1File(file) {
  39717. var header = file.peekBytes(2);
  39718. // All Type1 font programs must begin with the comment '%!' (0x25 + 0x21).
  39719. if (header[0] === 0x25 && header[1] === 0x21) {
  39720. return true;
  39721. }
  39722. // ... obviously some fonts violate that part of the specification,
  39723. // please refer to the comment in |Type1Font| below.
  39724. if (header[0] === 0x80 && header[1] === 0x01) {
  39725. // pfb file header.
  39726. return true;
  39727. }
  39728. return false;
  39729. }
  39730. function buildToFontChar(encoding, glyphsUnicodeMap, differences) {
  39731. var toFontChar = [], unicode;
  39732. for (var i = 0, ii = encoding.length; i < ii; i++) {
  39733. unicode = getUnicodeForGlyph(encoding[i], glyphsUnicodeMap);
  39734. if (unicode !== -1) {
  39735. toFontChar[i] = unicode;
  39736. }
  39737. }
  39738. for (var charCode in differences) {
  39739. unicode = getUnicodeForGlyph(differences[charCode], glyphsUnicodeMap);
  39740. if (unicode !== -1) {
  39741. toFontChar[+charCode] = unicode;
  39742. }
  39743. }
  39744. return toFontChar;
  39745. }
  39746. /**
  39747. * Helper function for |adjustMapping|.
  39748. * @return {boolean}
  39749. */
  39750. function isProblematicUnicodeLocation(code) {
  39751. // Using binary search to find a range start.
  39752. var i = 0, j = ProblematicCharRanges.length - 1;
  39753. while (i < j) {
  39754. var c = i + j + 1 >> 1;
  39755. if (code < ProblematicCharRanges[c]) {
  39756. j = c - 1;
  39757. } else {
  39758. i = c;
  39759. }
  39760. }
  39761. // Even index means code in problematic range.
  39762. return !(i & 1);
  39763. }
  39764. /**
  39765. * Rebuilds the char code to glyph ID map by trying to replace the char codes
  39766. * with their unicode value. It also moves char codes that are in known
  39767. * problematic locations.
  39768. * @return {Object} Two properties:
  39769. * 'toFontChar' - maps original char codes(the value that will be read
  39770. * from commands such as show text) to the char codes that will be used in the
  39771. * font that we build
  39772. * 'charCodeToGlyphId' - maps the new font char codes to glyph ids
  39773. */
  39774. function adjustMapping(charCodeToGlyphId, properties) {
  39775. var toUnicode = properties.toUnicode;
  39776. var isSymbolic = !!(properties.flags & FontFlags.Symbolic);
  39777. var isIdentityUnicode = properties.toUnicode instanceof IdentityToUnicodeMap;
  39778. var newMap = Object.create(null);
  39779. var toFontChar = [];
  39780. var usedFontCharCodes = [];
  39781. var nextAvailableFontCharCode = PRIVATE_USE_OFFSET_START;
  39782. for (var originalCharCode in charCodeToGlyphId) {
  39783. originalCharCode |= 0;
  39784. var glyphId = charCodeToGlyphId[originalCharCode];
  39785. var fontCharCode = originalCharCode;
  39786. // First try to map the value to a unicode position if a non identity map
  39787. // was created.
  39788. if (!isIdentityUnicode && toUnicode.has(originalCharCode)) {
  39789. var unicode = toUnicode.get(fontCharCode);
  39790. // TODO: Try to map ligatures to the correct spot.
  39791. if (unicode.length === 1) {
  39792. fontCharCode = unicode.charCodeAt(0);
  39793. }
  39794. }
  39795. // Try to move control characters, special characters and already mapped
  39796. // characters to the private use area since they will not be drawn by
  39797. // canvas if left in their current position. Also, move characters if the
  39798. // font was symbolic and there is only an identity unicode map since the
  39799. // characters probably aren't in the correct position (fixes an issue
  39800. // with firefox and thuluthfont).
  39801. if ((usedFontCharCodes[fontCharCode] !== undefined || isProblematicUnicodeLocation(fontCharCode) || isSymbolic && isIdentityUnicode) && nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END) {
  39802. // Room left.
  39803. // Loop to try and find a free spot in the private use area.
  39804. do {
  39805. fontCharCode = nextAvailableFontCharCode++;
  39806. if (SKIP_PRIVATE_USE_RANGE_F000_TO_F01F && fontCharCode === 0xF000) {
  39807. fontCharCode = 0xF020;
  39808. nextAvailableFontCharCode = fontCharCode + 1;
  39809. }
  39810. } while (usedFontCharCodes[fontCharCode] !== undefined && nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END);
  39811. }
  39812. newMap[fontCharCode] = glyphId;
  39813. toFontChar[originalCharCode] = fontCharCode;
  39814. usedFontCharCodes[fontCharCode] = true;
  39815. }
  39816. return {
  39817. toFontChar: toFontChar,
  39818. charCodeToGlyphId: newMap,
  39819. nextAvailableFontCharCode: nextAvailableFontCharCode
  39820. };
  39821. }
  39822. function getRanges(glyphs, numGlyphs) {
  39823. // Array.sort() sorts by characters, not numerically, so convert to an
  39824. // array of characters.
  39825. var codes = [];
  39826. for (var charCode in glyphs) {
  39827. // Remove an invalid glyph ID mappings to make OTS happy.
  39828. if (glyphs[charCode] >= numGlyphs) {
  39829. continue;
  39830. }
  39831. codes.push({
  39832. fontCharCode: charCode | 0,
  39833. glyphId: glyphs[charCode]
  39834. });
  39835. }
  39836. codes.sort(function fontGetRangesSort(a, b) {
  39837. return a.fontCharCode - b.fontCharCode;
  39838. });
  39839. // Split the sorted codes into ranges.
  39840. var ranges = [];
  39841. var length = codes.length;
  39842. for (var n = 0; n < length;) {
  39843. var start = codes[n].fontCharCode;
  39844. var codeIndices = [codes[n].glyphId];
  39845. ++n;
  39846. var end = start;
  39847. while (n < length && end + 1 === codes[n].fontCharCode) {
  39848. codeIndices.push(codes[n].glyphId);
  39849. ++end;
  39850. ++n;
  39851. if (end === 0xFFFF) {
  39852. break;
  39853. }
  39854. }
  39855. ranges.push([
  39856. start,
  39857. end,
  39858. codeIndices
  39859. ]);
  39860. }
  39861. return ranges;
  39862. }
  39863. function createCmapTable(glyphs, numGlyphs) {
  39864. var ranges = getRanges(glyphs, numGlyphs);
  39865. var numTables = ranges[ranges.length - 1][1] > 0xFFFF ? 2 : 1;
  39866. var cmap = '\x00\x00' + // version
  39867. string16(numTables) + // numTables
  39868. '\x00\x03' + // platformID
  39869. '\x00\x01' + // encodingID
  39870. string32(4 + numTables * 8);
  39871. // start of the table record
  39872. var i, ii, j, jj;
  39873. for (i = ranges.length - 1; i >= 0; --i) {
  39874. if (ranges[i][0] <= 0xFFFF) {
  39875. break;
  39876. }
  39877. }
  39878. var bmpLength = i + 1;
  39879. if (ranges[i][0] < 0xFFFF && ranges[i][1] === 0xFFFF) {
  39880. ranges[i][1] = 0xFFFE;
  39881. }
  39882. var trailingRangesCount = ranges[i][1] < 0xFFFF ? 1 : 0;
  39883. var segCount = bmpLength + trailingRangesCount;
  39884. var searchParams = OpenTypeFileBuilder.getSearchParams(segCount, 2);
  39885. // Fill up the 4 parallel arrays describing the segments.
  39886. var startCount = '';
  39887. var endCount = '';
  39888. var idDeltas = '';
  39889. var idRangeOffsets = '';
  39890. var glyphsIds = '';
  39891. var bias = 0;
  39892. var range, start, end, codes;
  39893. for (i = 0, ii = bmpLength; i < ii; i++) {
  39894. range = ranges[i];
  39895. start = range[0];
  39896. end = range[1];
  39897. startCount += string16(start);
  39898. endCount += string16(end);
  39899. codes = range[2];
  39900. var contiguous = true;
  39901. for (j = 1, jj = codes.length; j < jj; ++j) {
  39902. if (codes[j] !== codes[j - 1] + 1) {
  39903. contiguous = false;
  39904. break;
  39905. }
  39906. }
  39907. if (!contiguous) {
  39908. var offset = (segCount - i) * 2 + bias * 2;
  39909. bias += end - start + 1;
  39910. idDeltas += string16(0);
  39911. idRangeOffsets += string16(offset);
  39912. for (j = 0, jj = codes.length; j < jj; ++j) {
  39913. glyphsIds += string16(codes[j]);
  39914. }
  39915. } else {
  39916. var startCode = codes[0];
  39917. idDeltas += string16(startCode - start & 0xFFFF);
  39918. idRangeOffsets += string16(0);
  39919. }
  39920. }
  39921. if (trailingRangesCount > 0) {
  39922. endCount += '\xFF\xFF';
  39923. startCount += '\xFF\xFF';
  39924. idDeltas += '\x00\x01';
  39925. idRangeOffsets += '\x00\x00';
  39926. }
  39927. var format314 = '\x00\x00' + // language
  39928. string16(2 * segCount) + string16(searchParams.range) + string16(searchParams.entry) + string16(searchParams.rangeShift) + endCount + '\x00\x00' + startCount + idDeltas + idRangeOffsets + glyphsIds;
  39929. var format31012 = '';
  39930. var header31012 = '';
  39931. if (numTables > 1) {
  39932. cmap += '\x00\x03' + // platformID
  39933. '\x00\x0A' + // encodingID
  39934. string32(4 + numTables * 8 + 4 + format314.length);
  39935. // start of the table record
  39936. format31012 = '';
  39937. for (i = 0, ii = ranges.length; i < ii; i++) {
  39938. range = ranges[i];
  39939. start = range[0];
  39940. codes = range[2];
  39941. var code = codes[0];
  39942. for (j = 1, jj = codes.length; j < jj; ++j) {
  39943. if (codes[j] !== codes[j - 1] + 1) {
  39944. end = range[0] + j - 1;
  39945. format31012 += string32(start) + // startCharCode
  39946. string32(end) + // endCharCode
  39947. string32(code);
  39948. // startGlyphID
  39949. start = end + 1;
  39950. code = codes[j];
  39951. }
  39952. }
  39953. format31012 += string32(start) + // startCharCode
  39954. string32(range[1]) + // endCharCode
  39955. string32(code);
  39956. }
  39957. // startGlyphID
  39958. header31012 = '\x00\x0C' + // format
  39959. '\x00\x00' + // reserved
  39960. string32(format31012.length + 16) + // length
  39961. '\x00\x00\x00\x00' + // language
  39962. string32(format31012.length / 12);
  39963. }
  39964. // nGroups
  39965. return cmap + '\x00\x04' + // format
  39966. string16(format314.length + 4) + // length
  39967. format314 + header31012 + format31012;
  39968. }
  39969. function validateOS2Table(os2) {
  39970. var stream = new Stream(os2.data);
  39971. var version = stream.getUint16();
  39972. // TODO verify all OS/2 tables fields, but currently we validate only those
  39973. // that give us issues
  39974. stream.getBytes(60);
  39975. // skipping type, misc sizes, panose, unicode ranges
  39976. var selection = stream.getUint16();
  39977. if (version < 4 && selection & 0x0300) {
  39978. return false;
  39979. }
  39980. var firstChar = stream.getUint16();
  39981. var lastChar = stream.getUint16();
  39982. if (firstChar > lastChar) {
  39983. return false;
  39984. }
  39985. stream.getBytes(6);
  39986. // skipping sTypoAscender/Descender/LineGap
  39987. var usWinAscent = stream.getUint16();
  39988. if (usWinAscent === 0) {
  39989. // makes font unreadable by windows
  39990. return false;
  39991. }
  39992. // OS/2 appears to be valid, resetting some fields
  39993. os2.data[8] = os2.data[9] = 0;
  39994. // IE rejects fonts if fsType != 0
  39995. return true;
  39996. }
  39997. function createOS2Table(properties, charstrings, override) {
  39998. override = override || {
  39999. unitsPerEm: 0,
  40000. yMax: 0,
  40001. yMin: 0,
  40002. ascent: 0,
  40003. descent: 0
  40004. };
  40005. var ulUnicodeRange1 = 0;
  40006. var ulUnicodeRange2 = 0;
  40007. var ulUnicodeRange3 = 0;
  40008. var ulUnicodeRange4 = 0;
  40009. var firstCharIndex = null;
  40010. var lastCharIndex = 0;
  40011. if (charstrings) {
  40012. for (var code in charstrings) {
  40013. code |= 0;
  40014. if (firstCharIndex > code || !firstCharIndex) {
  40015. firstCharIndex = code;
  40016. }
  40017. if (lastCharIndex < code) {
  40018. lastCharIndex = code;
  40019. }
  40020. var position = getUnicodeRangeFor(code);
  40021. if (position < 32) {
  40022. ulUnicodeRange1 |= 1 << position;
  40023. } else if (position < 64) {
  40024. ulUnicodeRange2 |= 1 << position - 32;
  40025. } else if (position < 96) {
  40026. ulUnicodeRange3 |= 1 << position - 64;
  40027. } else if (position < 123) {
  40028. ulUnicodeRange4 |= 1 << position - 96;
  40029. } else {
  40030. error('Unicode ranges Bits > 123 are reserved for internal usage');
  40031. }
  40032. }
  40033. } else {
  40034. // TODO
  40035. firstCharIndex = 0;
  40036. lastCharIndex = 255;
  40037. }
  40038. var bbox = properties.bbox || [
  40039. 0,
  40040. 0,
  40041. 0,
  40042. 0
  40043. ];
  40044. var unitsPerEm = override.unitsPerEm || 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0];
  40045. // if the font units differ to the PDF glyph space units
  40046. // then scale up the values
  40047. var scale = properties.ascentScaled ? 1.0 : unitsPerEm / PDF_GLYPH_SPACE_UNITS;
  40048. var typoAscent = override.ascent || Math.round(scale * (properties.ascent || bbox[3]));
  40049. var typoDescent = override.descent || Math.round(scale * (properties.descent || bbox[1]));
  40050. if (typoDescent > 0 && properties.descent > 0 && bbox[1] < 0) {
  40051. typoDescent = -typoDescent;
  40052. }
  40053. // fixing incorrect descent
  40054. var winAscent = override.yMax || typoAscent;
  40055. var winDescent = -override.yMin || -typoDescent;
  40056. return '\x00\x03' + // version
  40057. '\x02\x24' + // xAvgCharWidth
  40058. '\x01\xF4' + // usWeightClass
  40059. '\x00\x05' + // usWidthClass
  40060. '\x00\x00' + // fstype (0 to let the font loads via font-face on IE)
  40061. '\x02\x8A' + // ySubscriptXSize
  40062. '\x02\xBB' + // ySubscriptYSize
  40063. '\x00\x00' + // ySubscriptXOffset
  40064. '\x00\x8C' + // ySubscriptYOffset
  40065. '\x02\x8A' + // ySuperScriptXSize
  40066. '\x02\xBB' + // ySuperScriptYSize
  40067. '\x00\x00' + // ySuperScriptXOffset
  40068. '\x01\xDF' + // ySuperScriptYOffset
  40069. '\x00\x31' + // yStrikeOutSize
  40070. '\x01\x02' + // yStrikeOutPosition
  40071. '\x00\x00' + // sFamilyClass
  40072. '\x00\x00\x06' + String.fromCharCode(properties.fixedPitch ? 0x09 : 0x00) + '\x00\x00\x00\x00\x00\x00' + // Panose
  40073. string32(ulUnicodeRange1) + // ulUnicodeRange1 (Bits 0-31)
  40074. string32(ulUnicodeRange2) + // ulUnicodeRange2 (Bits 32-63)
  40075. string32(ulUnicodeRange3) + // ulUnicodeRange3 (Bits 64-95)
  40076. string32(ulUnicodeRange4) + // ulUnicodeRange4 (Bits 96-127)
  40077. '\x2A\x32\x31\x2A' + // achVendID
  40078. string16(properties.italicAngle ? 1 : 0) + // fsSelection
  40079. string16(firstCharIndex || properties.firstChar) + // usFirstCharIndex
  40080. string16(lastCharIndex || properties.lastChar) + // usLastCharIndex
  40081. string16(typoAscent) + // sTypoAscender
  40082. string16(typoDescent) + // sTypoDescender
  40083. '\x00\x64' + // sTypoLineGap (7%-10% of the unitsPerEM value)
  40084. string16(winAscent) + // usWinAscent
  40085. string16(winDescent) + // usWinDescent
  40086. '\x00\x00\x00\x00' + // ulCodePageRange1 (Bits 0-31)
  40087. '\x00\x00\x00\x00' + // ulCodePageRange2 (Bits 32-63)
  40088. string16(properties.xHeight) + // sxHeight
  40089. string16(properties.capHeight) + // sCapHeight
  40090. string16(0) + // usDefaultChar
  40091. string16(firstCharIndex || properties.firstChar) + // usBreakChar
  40092. '\x00\x03';
  40093. }
  40094. // usMaxContext
  40095. function createPostTable(properties) {
  40096. var angle = Math.floor(properties.italicAngle * Math.pow(2, 16));
  40097. return '\x00\x03\x00\x00' + // Version number
  40098. string32(angle) + // italicAngle
  40099. '\x00\x00' + // underlinePosition
  40100. '\x00\x00' + // underlineThickness
  40101. string32(properties.fixedPitch) + // isFixedPitch
  40102. '\x00\x00\x00\x00' + // minMemType42
  40103. '\x00\x00\x00\x00' + // maxMemType42
  40104. '\x00\x00\x00\x00' + // minMemType1
  40105. '\x00\x00\x00\x00';
  40106. }
  40107. // maxMemType1
  40108. function createNameTable(name, proto) {
  40109. if (!proto) {
  40110. proto = [
  40111. [],
  40112. []
  40113. ];
  40114. }
  40115. // no strings and unicode strings
  40116. var strings = [
  40117. proto[0][0] || 'Original licence',
  40118. // 0.Copyright
  40119. proto[0][1] || name,
  40120. // 1.Font family
  40121. proto[0][2] || 'Unknown',
  40122. // 2.Font subfamily (font weight)
  40123. proto[0][3] || 'uniqueID',
  40124. // 3.Unique ID
  40125. proto[0][4] || name,
  40126. // 4.Full font name
  40127. proto[0][5] || 'Version 0.11',
  40128. // 5.Version
  40129. proto[0][6] || '',
  40130. // 6.Postscript name
  40131. proto[0][7] || 'Unknown',
  40132. // 7.Trademark
  40133. proto[0][8] || 'Unknown',
  40134. // 8.Manufacturer
  40135. proto[0][9] || 'Unknown'
  40136. ];
  40137. // 9.Designer
  40138. // Mac want 1-byte per character strings while Windows want
  40139. // 2-bytes per character, so duplicate the names table
  40140. var stringsUnicode = [];
  40141. var i, ii, j, jj, str;
  40142. for (i = 0, ii = strings.length; i < ii; i++) {
  40143. str = proto[1][i] || strings[i];
  40144. var strBufUnicode = [];
  40145. for (j = 0, jj = str.length; j < jj; j++) {
  40146. strBufUnicode.push(string16(str.charCodeAt(j)));
  40147. }
  40148. stringsUnicode.push(strBufUnicode.join(''));
  40149. }
  40150. var names = [
  40151. strings,
  40152. stringsUnicode
  40153. ];
  40154. var platforms = [
  40155. '\x00\x01',
  40156. '\x00\x03'
  40157. ];
  40158. var encodings = [
  40159. '\x00\x00',
  40160. '\x00\x01'
  40161. ];
  40162. var languages = [
  40163. '\x00\x00',
  40164. '\x04\x09'
  40165. ];
  40166. var namesRecordCount = strings.length * platforms.length;
  40167. var nameTable = '\x00\x00' + // format
  40168. string16(namesRecordCount) + // Number of names Record
  40169. string16(namesRecordCount * 12 + 6);
  40170. // Storage
  40171. // Build the name records field
  40172. var strOffset = 0;
  40173. for (i = 0, ii = platforms.length; i < ii; i++) {
  40174. var strs = names[i];
  40175. for (j = 0, jj = strs.length; j < jj; j++) {
  40176. str = strs[j];
  40177. var nameRecord = platforms[i] + // platform ID
  40178. encodings[i] + // encoding ID
  40179. languages[i] + // language ID
  40180. string16(j) + // name ID
  40181. string16(str.length) + string16(strOffset);
  40182. nameTable += nameRecord;
  40183. strOffset += str.length;
  40184. }
  40185. }
  40186. nameTable += strings.join('') + stringsUnicode.join('');
  40187. return nameTable;
  40188. }
  40189. Font.prototype = {
  40190. name: null,
  40191. font: null,
  40192. mimetype: null,
  40193. encoding: null,
  40194. get renderer() {
  40195. var renderer = FontRendererFactory.create(this, SEAC_ANALYSIS_ENABLED);
  40196. return shadow(this, 'renderer', renderer);
  40197. },
  40198. exportData: function Font_exportData() {
  40199. // TODO remove enumerating of the properties, e.g. hardcode exact names.
  40200. var data = {};
  40201. for (var i in this) {
  40202. if (this.hasOwnProperty(i)) {
  40203. data[i] = this[i];
  40204. }
  40205. }
  40206. return data;
  40207. },
  40208. checkAndRepair: function Font_checkAndRepair(name, font, properties) {
  40209. function readTableEntry(file) {
  40210. var tag = bytesToString(file.getBytes(4));
  40211. var checksum = file.getInt32() >>> 0;
  40212. var offset = file.getInt32() >>> 0;
  40213. var length = file.getInt32() >>> 0;
  40214. // Read the table associated data
  40215. var previousPosition = file.pos;
  40216. file.pos = file.start ? file.start : 0;
  40217. file.skip(offset);
  40218. var data = file.getBytes(length);
  40219. file.pos = previousPosition;
  40220. if (tag === 'head') {
  40221. // clearing checksum adjustment
  40222. data[8] = data[9] = data[10] = data[11] = 0;
  40223. data[17] |= 0x20;
  40224. }
  40225. //Set font optimized for cleartype flag
  40226. return {
  40227. tag: tag,
  40228. checksum: checksum,
  40229. length: length,
  40230. offset: offset,
  40231. data: data
  40232. };
  40233. }
  40234. function readOpenTypeHeader(ttf) {
  40235. return {
  40236. version: bytesToString(ttf.getBytes(4)),
  40237. numTables: ttf.getUint16(),
  40238. searchRange: ttf.getUint16(),
  40239. entrySelector: ttf.getUint16(),
  40240. rangeShift: ttf.getUint16()
  40241. };
  40242. }
  40243. /**
  40244. * Read the appropriate subtable from the cmap according to 9.6.6.4 from
  40245. * PDF spec
  40246. */
  40247. function readCmapTable(cmap, font, isSymbolicFont, hasEncoding) {
  40248. if (!cmap) {
  40249. warn('No cmap table available.');
  40250. return {
  40251. platformId: -1,
  40252. encodingId: -1,
  40253. mappings: [],
  40254. hasShortCmap: false
  40255. };
  40256. }
  40257. var segment;
  40258. var start = (font.start ? font.start : 0) + cmap.offset;
  40259. font.pos = start;
  40260. var version = font.getUint16();
  40261. var numTables = font.getUint16();
  40262. var potentialTable;
  40263. var canBreak = false;
  40264. // There's an order of preference in terms of which cmap subtable to
  40265. // use:
  40266. // - non-symbolic fonts the preference is a 3,1 table then a 1,0 table
  40267. // - symbolic fonts the preference is a 3,0 table then a 1,0 table
  40268. // The following takes advantage of the fact that the tables are sorted
  40269. // to work.
  40270. for (var i = 0; i < numTables; i++) {
  40271. var platformId = font.getUint16();
  40272. var encodingId = font.getUint16();
  40273. var offset = font.getInt32() >>> 0;
  40274. var useTable = false;
  40275. if (platformId === 0 && encodingId === 0) {
  40276. useTable = true;
  40277. } else // Continue the loop since there still may be a higher priority
  40278. // table.
  40279. if (platformId === 1 && encodingId === 0) {
  40280. useTable = true;
  40281. } else // Continue the loop since there still may be a higher priority
  40282. // table.
  40283. if (platformId === 3 && encodingId === 1 && (!isSymbolicFont && hasEncoding || !potentialTable)) {
  40284. useTable = true;
  40285. if (!isSymbolicFont) {
  40286. canBreak = true;
  40287. }
  40288. } else if (isSymbolicFont && platformId === 3 && encodingId === 0) {
  40289. useTable = true;
  40290. canBreak = true;
  40291. }
  40292. if (useTable) {
  40293. potentialTable = {
  40294. platformId: platformId,
  40295. encodingId: encodingId,
  40296. offset: offset
  40297. };
  40298. }
  40299. if (canBreak) {
  40300. break;
  40301. }
  40302. }
  40303. if (potentialTable) {
  40304. font.pos = start + potentialTable.offset;
  40305. }
  40306. if (!potentialTable || font.peekByte() === -1) {
  40307. warn('Could not find a preferred cmap table.');
  40308. return {
  40309. platformId: -1,
  40310. encodingId: -1,
  40311. mappings: [],
  40312. hasShortCmap: false
  40313. };
  40314. }
  40315. var format = font.getUint16();
  40316. var length = font.getUint16();
  40317. var language = font.getUint16();
  40318. var hasShortCmap = false;
  40319. var mappings = [];
  40320. var j, glyphId;
  40321. // TODO(mack): refactor this cmap subtable reading logic out
  40322. if (format === 0) {
  40323. for (j = 0; j < 256; j++) {
  40324. var index = font.getByte();
  40325. if (!index) {
  40326. continue;
  40327. }
  40328. mappings.push({
  40329. charCode: j,
  40330. glyphId: index
  40331. });
  40332. }
  40333. hasShortCmap = true;
  40334. } else if (format === 4) {
  40335. // re-creating the table in format 4 since the encoding
  40336. // might be changed
  40337. var segCount = font.getUint16() >> 1;
  40338. font.getBytes(6);
  40339. // skipping range fields
  40340. var segIndex, segments = [];
  40341. for (segIndex = 0; segIndex < segCount; segIndex++) {
  40342. segments.push({ end: font.getUint16() });
  40343. }
  40344. font.getUint16();
  40345. for (segIndex = 0; segIndex < segCount; segIndex++) {
  40346. segments[segIndex].start = font.getUint16();
  40347. }
  40348. for (segIndex = 0; segIndex < segCount; segIndex++) {
  40349. segments[segIndex].delta = font.getUint16();
  40350. }
  40351. var offsetsCount = 0;
  40352. for (segIndex = 0; segIndex < segCount; segIndex++) {
  40353. segment = segments[segIndex];
  40354. var rangeOffset = font.getUint16();
  40355. if (!rangeOffset) {
  40356. segment.offsetIndex = -1;
  40357. continue;
  40358. }
  40359. var offsetIndex = (rangeOffset >> 1) - (segCount - segIndex);
  40360. segment.offsetIndex = offsetIndex;
  40361. offsetsCount = Math.max(offsetsCount, offsetIndex + segment.end - segment.start + 1);
  40362. }
  40363. var offsets = [];
  40364. for (j = 0; j < offsetsCount; j++) {
  40365. offsets.push(font.getUint16());
  40366. }
  40367. for (segIndex = 0; segIndex < segCount; segIndex++) {
  40368. segment = segments[segIndex];
  40369. start = segment.start;
  40370. var end = segment.end;
  40371. var delta = segment.delta;
  40372. offsetIndex = segment.offsetIndex;
  40373. for (j = start; j <= end; j++) {
  40374. if (j === 0xFFFF) {
  40375. continue;
  40376. }
  40377. glyphId = offsetIndex < 0 ? j : offsets[offsetIndex + j - start];
  40378. glyphId = glyphId + delta & 0xFFFF;
  40379. if (glyphId === 0) {
  40380. continue;
  40381. }
  40382. mappings.push({
  40383. charCode: j,
  40384. glyphId: glyphId
  40385. });
  40386. }
  40387. }
  40388. } else if (format === 6) {
  40389. // Format 6 is a 2-bytes dense mapping, which means the font data
  40390. // lives glue together even if they are pretty far in the unicode
  40391. // table. (This looks weird, so I can have missed something), this
  40392. // works on Linux but seems to fails on Mac so let's rewrite the
  40393. // cmap table to a 3-1-4 style
  40394. var firstCode = font.getUint16();
  40395. var entryCount = font.getUint16();
  40396. for (j = 0; j < entryCount; j++) {
  40397. glyphId = font.getUint16();
  40398. var charCode = firstCode + j;
  40399. mappings.push({
  40400. charCode: charCode,
  40401. glyphId: glyphId
  40402. });
  40403. }
  40404. } else {
  40405. warn('cmap table has unsupported format: ' + format);
  40406. return {
  40407. platformId: -1,
  40408. encodingId: -1,
  40409. mappings: [],
  40410. hasShortCmap: false
  40411. };
  40412. }
  40413. // removing duplicate entries
  40414. mappings.sort(function (a, b) {
  40415. return a.charCode - b.charCode;
  40416. });
  40417. for (i = 1; i < mappings.length; i++) {
  40418. if (mappings[i - 1].charCode === mappings[i].charCode) {
  40419. mappings.splice(i, 1);
  40420. i--;
  40421. }
  40422. }
  40423. return {
  40424. platformId: potentialTable.platformId,
  40425. encodingId: potentialTable.encodingId,
  40426. mappings: mappings,
  40427. hasShortCmap: hasShortCmap
  40428. };
  40429. }
  40430. function sanitizeMetrics(font, header, metrics, numGlyphs) {
  40431. if (!header) {
  40432. if (metrics) {
  40433. metrics.data = null;
  40434. }
  40435. return;
  40436. }
  40437. font.pos = (font.start ? font.start : 0) + header.offset;
  40438. font.pos += header.length - 2;
  40439. var numOfMetrics = font.getUint16();
  40440. if (numOfMetrics > numGlyphs) {
  40441. info('The numOfMetrics (' + numOfMetrics + ') should not be ' + 'greater than the numGlyphs (' + numGlyphs + ')');
  40442. // Reduce numOfMetrics if it is greater than numGlyphs
  40443. numOfMetrics = numGlyphs;
  40444. header.data[34] = (numOfMetrics & 0xff00) >> 8;
  40445. header.data[35] = numOfMetrics & 0x00ff;
  40446. }
  40447. var numOfSidebearings = numGlyphs - numOfMetrics;
  40448. var numMissing = numOfSidebearings - (metrics.length - numOfMetrics * 4 >> 1);
  40449. if (numMissing > 0) {
  40450. // For each missing glyph, we set both the width and lsb to 0 (zero).
  40451. // Since we need to add two properties for each glyph, this explains
  40452. // the use of |numMissing * 2| when initializing the typed array.
  40453. var entries = new Uint8Array(metrics.length + numMissing * 2);
  40454. entries.set(metrics.data);
  40455. metrics.data = entries;
  40456. }
  40457. }
  40458. function sanitizeGlyph(source, sourceStart, sourceEnd, dest, destStart, hintsValid) {
  40459. if (sourceEnd - sourceStart <= 12) {
  40460. // glyph with data less than 12 is invalid one
  40461. return 0;
  40462. }
  40463. var glyf = source.subarray(sourceStart, sourceEnd);
  40464. var contoursCount = glyf[0] << 8 | glyf[1];
  40465. if (contoursCount & 0x8000) {
  40466. // complex glyph, writing as is
  40467. dest.set(glyf, destStart);
  40468. return glyf.length;
  40469. }
  40470. var i, j = 10, flagsCount = 0;
  40471. for (i = 0; i < contoursCount; i++) {
  40472. var endPoint = glyf[j] << 8 | glyf[j + 1];
  40473. flagsCount = endPoint + 1;
  40474. j += 2;
  40475. }
  40476. // skipping instructions
  40477. var instructionsStart = j;
  40478. var instructionsLength = glyf[j] << 8 | glyf[j + 1];
  40479. j += 2 + instructionsLength;
  40480. var instructionsEnd = j;
  40481. // validating flags
  40482. var coordinatesLength = 0;
  40483. for (i = 0; i < flagsCount; i++) {
  40484. var flag = glyf[j++];
  40485. if (flag & 0xC0) {
  40486. // reserved flags must be zero, cleaning up
  40487. glyf[j - 1] = flag & 0x3F;
  40488. }
  40489. var xyLength = (flag & 2 ? 1 : flag & 16 ? 0 : 2) + (flag & 4 ? 1 : flag & 32 ? 0 : 2);
  40490. coordinatesLength += xyLength;
  40491. if (flag & 8) {
  40492. var repeat = glyf[j++];
  40493. i += repeat;
  40494. coordinatesLength += repeat * xyLength;
  40495. }
  40496. }
  40497. // glyph without coordinates will be rejected
  40498. if (coordinatesLength === 0) {
  40499. return 0;
  40500. }
  40501. var glyphDataLength = j + coordinatesLength;
  40502. if (glyphDataLength > glyf.length) {
  40503. // not enough data for coordinates
  40504. return 0;
  40505. }
  40506. if (!hintsValid && instructionsLength > 0) {
  40507. dest.set(glyf.subarray(0, instructionsStart), destStart);
  40508. dest.set([
  40509. 0,
  40510. 0
  40511. ], destStart + instructionsStart);
  40512. dest.set(glyf.subarray(instructionsEnd, glyphDataLength), destStart + instructionsStart + 2);
  40513. glyphDataLength -= instructionsLength;
  40514. if (glyf.length - glyphDataLength > 3) {
  40515. glyphDataLength = glyphDataLength + 3 & ~3;
  40516. }
  40517. return glyphDataLength;
  40518. }
  40519. if (glyf.length - glyphDataLength > 3) {
  40520. // truncating and aligning to 4 bytes the long glyph data
  40521. glyphDataLength = glyphDataLength + 3 & ~3;
  40522. dest.set(glyf.subarray(0, glyphDataLength), destStart);
  40523. return glyphDataLength;
  40524. }
  40525. // glyph data is fine
  40526. dest.set(glyf, destStart);
  40527. return glyf.length;
  40528. }
  40529. function sanitizeHead(head, numGlyphs, locaLength) {
  40530. var data = head.data;
  40531. // Validate version:
  40532. // Should always be 0x00010000
  40533. var version = int32(data[0], data[1], data[2], data[3]);
  40534. if (version >> 16 !== 1) {
  40535. info('Attempting to fix invalid version in head table: ' + version);
  40536. data[0] = 0;
  40537. data[1] = 1;
  40538. data[2] = 0;
  40539. data[3] = 0;
  40540. }
  40541. var indexToLocFormat = int16(data[50], data[51]);
  40542. if (indexToLocFormat < 0 || indexToLocFormat > 1) {
  40543. info('Attempting to fix invalid indexToLocFormat in head table: ' + indexToLocFormat);
  40544. // The value of indexToLocFormat should be 0 if the loca table
  40545. // consists of short offsets, and should be 1 if the loca table
  40546. // consists of long offsets.
  40547. //
  40548. // The number of entries in the loca table should be numGlyphs + 1.
  40549. //
  40550. // Using this information, we can work backwards to deduce if the
  40551. // size of each offset in the loca table, and thus figure out the
  40552. // appropriate value for indexToLocFormat.
  40553. var numGlyphsPlusOne = numGlyphs + 1;
  40554. if (locaLength === numGlyphsPlusOne << 1) {
  40555. // 0x0000 indicates the loca table consists of short offsets
  40556. data[50] = 0;
  40557. data[51] = 0;
  40558. } else if (locaLength === numGlyphsPlusOne << 2) {
  40559. // 0x0001 indicates the loca table consists of long offsets
  40560. data[50] = 0;
  40561. data[51] = 1;
  40562. } else {
  40563. warn('Could not fix indexToLocFormat: ' + indexToLocFormat);
  40564. }
  40565. }
  40566. }
  40567. function sanitizeGlyphLocations(loca, glyf, numGlyphs, isGlyphLocationsLong, hintsValid, dupFirstEntry) {
  40568. var itemSize, itemDecode, itemEncode;
  40569. if (isGlyphLocationsLong) {
  40570. itemSize = 4;
  40571. itemDecode = function fontItemDecodeLong(data, offset) {
  40572. return data[offset] << 24 | data[offset + 1] << 16 | data[offset + 2] << 8 | data[offset + 3];
  40573. };
  40574. itemEncode = function fontItemEncodeLong(data, offset, value) {
  40575. data[offset] = value >>> 24 & 0xFF;
  40576. data[offset + 1] = value >> 16 & 0xFF;
  40577. data[offset + 2] = value >> 8 & 0xFF;
  40578. data[offset + 3] = value & 0xFF;
  40579. };
  40580. } else {
  40581. itemSize = 2;
  40582. itemDecode = function fontItemDecode(data, offset) {
  40583. return data[offset] << 9 | data[offset + 1] << 1;
  40584. };
  40585. itemEncode = function fontItemEncode(data, offset, value) {
  40586. data[offset] = value >> 9 & 0xFF;
  40587. data[offset + 1] = value >> 1 & 0xFF;
  40588. };
  40589. }
  40590. var locaData = loca.data;
  40591. var locaDataSize = itemSize * (1 + numGlyphs);
  40592. // is loca.data too short or long?
  40593. if (locaData.length !== locaDataSize) {
  40594. locaData = new Uint8Array(locaDataSize);
  40595. locaData.set(loca.data.subarray(0, locaDataSize));
  40596. loca.data = locaData;
  40597. }
  40598. // removing the invalid glyphs
  40599. var oldGlyfData = glyf.data;
  40600. var oldGlyfDataLength = oldGlyfData.length;
  40601. var newGlyfData = new Uint8Array(oldGlyfDataLength);
  40602. var startOffset = itemDecode(locaData, 0);
  40603. var writeOffset = 0;
  40604. var missingGlyphData = Object.create(null);
  40605. itemEncode(locaData, 0, writeOffset);
  40606. var i, j;
  40607. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  40608. var endOffset = itemDecode(locaData, j);
  40609. if (endOffset > oldGlyfDataLength && (oldGlyfDataLength + 3 & ~3) === endOffset) {
  40610. // Aspose breaks fonts by aligning the glyphs to the qword, but not
  40611. // the glyf table size, which makes last glyph out of range.
  40612. endOffset = oldGlyfDataLength;
  40613. }
  40614. if (endOffset > oldGlyfDataLength) {
  40615. // glyph end offset points outside glyf data, rejecting the glyph
  40616. itemEncode(locaData, j, writeOffset);
  40617. startOffset = endOffset;
  40618. continue;
  40619. }
  40620. if (startOffset === endOffset) {
  40621. missingGlyphData[i] = true;
  40622. }
  40623. var newLength = sanitizeGlyph(oldGlyfData, startOffset, endOffset, newGlyfData, writeOffset, hintsValid);
  40624. writeOffset += newLength;
  40625. itemEncode(locaData, j, writeOffset);
  40626. startOffset = endOffset;
  40627. }
  40628. if (writeOffset === 0) {
  40629. // glyf table cannot be empty -- redoing the glyf and loca tables
  40630. // to have single glyph with one point
  40631. var simpleGlyph = new Uint8Array([
  40632. 0,
  40633. 1,
  40634. 0,
  40635. 0,
  40636. 0,
  40637. 0,
  40638. 0,
  40639. 0,
  40640. 0,
  40641. 0,
  40642. 0,
  40643. 0,
  40644. 0,
  40645. 0,
  40646. 49,
  40647. 0
  40648. ]);
  40649. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  40650. itemEncode(locaData, j, simpleGlyph.length);
  40651. }
  40652. glyf.data = simpleGlyph;
  40653. return missingGlyphData;
  40654. }
  40655. if (dupFirstEntry) {
  40656. var firstEntryLength = itemDecode(locaData, itemSize);
  40657. if (newGlyfData.length > firstEntryLength + writeOffset) {
  40658. glyf.data = newGlyfData.subarray(0, firstEntryLength + writeOffset);
  40659. } else {
  40660. glyf.data = new Uint8Array(firstEntryLength + writeOffset);
  40661. glyf.data.set(newGlyfData.subarray(0, writeOffset));
  40662. }
  40663. glyf.data.set(newGlyfData.subarray(0, firstEntryLength), writeOffset);
  40664. itemEncode(loca.data, locaData.length - itemSize, writeOffset + firstEntryLength);
  40665. } else {
  40666. glyf.data = newGlyfData.subarray(0, writeOffset);
  40667. }
  40668. return missingGlyphData;
  40669. }
  40670. function readPostScriptTable(post, properties, maxpNumGlyphs) {
  40671. var start = (font.start ? font.start : 0) + post.offset;
  40672. font.pos = start;
  40673. var length = post.length, end = start + length;
  40674. var version = font.getInt32();
  40675. // skip rest to the tables
  40676. font.getBytes(28);
  40677. var glyphNames;
  40678. var valid = true;
  40679. var i;
  40680. switch (version) {
  40681. case 0x00010000:
  40682. glyphNames = MacStandardGlyphOrdering;
  40683. break;
  40684. case 0x00020000:
  40685. var numGlyphs = font.getUint16();
  40686. if (numGlyphs !== maxpNumGlyphs) {
  40687. valid = false;
  40688. break;
  40689. }
  40690. var glyphNameIndexes = [];
  40691. for (i = 0; i < numGlyphs; ++i) {
  40692. var index = font.getUint16();
  40693. if (index >= 32768) {
  40694. valid = false;
  40695. break;
  40696. }
  40697. glyphNameIndexes.push(index);
  40698. }
  40699. if (!valid) {
  40700. break;
  40701. }
  40702. var customNames = [];
  40703. var strBuf = [];
  40704. while (font.pos < end) {
  40705. var stringLength = font.getByte();
  40706. strBuf.length = stringLength;
  40707. for (i = 0; i < stringLength; ++i) {
  40708. strBuf[i] = String.fromCharCode(font.getByte());
  40709. }
  40710. customNames.push(strBuf.join(''));
  40711. }
  40712. glyphNames = [];
  40713. for (i = 0; i < numGlyphs; ++i) {
  40714. var j = glyphNameIndexes[i];
  40715. if (j < 258) {
  40716. glyphNames.push(MacStandardGlyphOrdering[j]);
  40717. continue;
  40718. }
  40719. glyphNames.push(customNames[j - 258]);
  40720. }
  40721. break;
  40722. case 0x00030000:
  40723. break;
  40724. default:
  40725. warn('Unknown/unsupported post table version ' + version);
  40726. valid = false;
  40727. if (properties.defaultEncoding) {
  40728. glyphNames = properties.defaultEncoding;
  40729. }
  40730. break;
  40731. }
  40732. properties.glyphNames = glyphNames;
  40733. return valid;
  40734. }
  40735. function readNameTable(nameTable) {
  40736. var start = (font.start ? font.start : 0) + nameTable.offset;
  40737. font.pos = start;
  40738. var names = [
  40739. [],
  40740. []
  40741. ];
  40742. var length = nameTable.length, end = start + length;
  40743. var format = font.getUint16();
  40744. var FORMAT_0_HEADER_LENGTH = 6;
  40745. if (format !== 0 || length < FORMAT_0_HEADER_LENGTH) {
  40746. // unsupported name table format or table "too" small
  40747. return names;
  40748. }
  40749. var numRecords = font.getUint16();
  40750. var stringsStart = font.getUint16();
  40751. var records = [];
  40752. var NAME_RECORD_LENGTH = 12;
  40753. var i, ii;
  40754. for (i = 0; i < numRecords && font.pos + NAME_RECORD_LENGTH <= end; i++) {
  40755. var r = {
  40756. platform: font.getUint16(),
  40757. encoding: font.getUint16(),
  40758. language: font.getUint16(),
  40759. name: font.getUint16(),
  40760. length: font.getUint16(),
  40761. offset: font.getUint16()
  40762. };
  40763. // using only Macintosh and Windows platform/encoding names
  40764. if (r.platform === 1 && r.encoding === 0 && r.language === 0 || r.platform === 3 && r.encoding === 1 && r.language === 0x409) {
  40765. records.push(r);
  40766. }
  40767. }
  40768. for (i = 0, ii = records.length; i < ii; i++) {
  40769. var record = records[i];
  40770. if (record.length <= 0) {
  40771. continue;
  40772. }
  40773. // Nothing to process, ignoring.
  40774. var pos = start + stringsStart + record.offset;
  40775. if (pos + record.length > end) {
  40776. continue;
  40777. }
  40778. // outside of name table, ignoring
  40779. font.pos = pos;
  40780. var nameIndex = record.name;
  40781. if (record.encoding) {
  40782. // unicode
  40783. var str = '';
  40784. for (var j = 0, jj = record.length; j < jj; j += 2) {
  40785. str += String.fromCharCode(font.getUint16());
  40786. }
  40787. names[1][nameIndex] = str;
  40788. } else {
  40789. names[0][nameIndex] = bytesToString(font.getBytes(record.length));
  40790. }
  40791. }
  40792. return names;
  40793. }
  40794. var TTOpsStackDeltas = [
  40795. 0,
  40796. 0,
  40797. 0,
  40798. 0,
  40799. 0,
  40800. 0,
  40801. 0,
  40802. 0,
  40803. -2,
  40804. -2,
  40805. -2,
  40806. -2,
  40807. 0,
  40808. 0,
  40809. -2,
  40810. -5,
  40811. -1,
  40812. -1,
  40813. -1,
  40814. -1,
  40815. -1,
  40816. -1,
  40817. -1,
  40818. -1,
  40819. 0,
  40820. 0,
  40821. -1,
  40822. 0,
  40823. -1,
  40824. -1,
  40825. -1,
  40826. -1,
  40827. 1,
  40828. -1,
  40829. -999,
  40830. 0,
  40831. 1,
  40832. 0,
  40833. -1,
  40834. -2,
  40835. 0,
  40836. -1,
  40837. -2,
  40838. -1,
  40839. -1,
  40840. 0,
  40841. -1,
  40842. -1,
  40843. 0,
  40844. 0,
  40845. -999,
  40846. -999,
  40847. -1,
  40848. -1,
  40849. -1,
  40850. -1,
  40851. -2,
  40852. -999,
  40853. -2,
  40854. -2,
  40855. -999,
  40856. 0,
  40857. -2,
  40858. -2,
  40859. 0,
  40860. 0,
  40861. -2,
  40862. 0,
  40863. -2,
  40864. 0,
  40865. 0,
  40866. 0,
  40867. -2,
  40868. -1,
  40869. -1,
  40870. 1,
  40871. 1,
  40872. 0,
  40873. 0,
  40874. -1,
  40875. -1,
  40876. -1,
  40877. -1,
  40878. -1,
  40879. -1,
  40880. -1,
  40881. 0,
  40882. 0,
  40883. -1,
  40884. 0,
  40885. -1,
  40886. -1,
  40887. 0,
  40888. -999,
  40889. -1,
  40890. -1,
  40891. -1,
  40892. -1,
  40893. -1,
  40894. -1,
  40895. 0,
  40896. 0,
  40897. 0,
  40898. 0,
  40899. 0,
  40900. 0,
  40901. 0,
  40902. 0,
  40903. 0,
  40904. 0,
  40905. 0,
  40906. 0,
  40907. -2,
  40908. -999,
  40909. -999,
  40910. -999,
  40911. -999,
  40912. -999,
  40913. -1,
  40914. -1,
  40915. -2,
  40916. -2,
  40917. 0,
  40918. 0,
  40919. 0,
  40920. 0,
  40921. -1,
  40922. -1,
  40923. -999,
  40924. -2,
  40925. -2,
  40926. 0,
  40927. 0,
  40928. -1,
  40929. -2,
  40930. -2,
  40931. 0,
  40932. 0,
  40933. 0,
  40934. -1,
  40935. -1,
  40936. -1,
  40937. -2
  40938. ];
  40939. // 0xC0-DF == -1 and 0xE0-FF == -2
  40940. function sanitizeTTProgram(table, ttContext) {
  40941. var data = table.data;
  40942. var i = 0, j, n, b, funcId, pc, lastEndf = 0, lastDeff = 0;
  40943. var stack = [];
  40944. var callstack = [];
  40945. var functionsCalled = [];
  40946. var tooComplexToFollowFunctions = ttContext.tooComplexToFollowFunctions;
  40947. var inFDEF = false, ifLevel = 0, inELSE = 0;
  40948. for (var ii = data.length; i < ii;) {
  40949. var op = data[i++];
  40950. // The TrueType instruction set docs can be found at
  40951. // https://developer.apple.com/fonts/TTRefMan/RM05/Chap5.html
  40952. if (op === 0x40) {
  40953. // NPUSHB - pushes n bytes
  40954. n = data[i++];
  40955. if (inFDEF || inELSE) {
  40956. i += n;
  40957. } else {
  40958. for (j = 0; j < n; j++) {
  40959. stack.push(data[i++]);
  40960. }
  40961. }
  40962. } else if (op === 0x41) {
  40963. // NPUSHW - pushes n words
  40964. n = data[i++];
  40965. if (inFDEF || inELSE) {
  40966. i += n * 2;
  40967. } else {
  40968. for (j = 0; j < n; j++) {
  40969. b = data[i++];
  40970. stack.push(b << 8 | data[i++]);
  40971. }
  40972. }
  40973. } else if ((op & 0xF8) === 0xB0) {
  40974. // PUSHB - pushes bytes
  40975. n = op - 0xB0 + 1;
  40976. if (inFDEF || inELSE) {
  40977. i += n;
  40978. } else {
  40979. for (j = 0; j < n; j++) {
  40980. stack.push(data[i++]);
  40981. }
  40982. }
  40983. } else if ((op & 0xF8) === 0xB8) {
  40984. // PUSHW - pushes words
  40985. n = op - 0xB8 + 1;
  40986. if (inFDEF || inELSE) {
  40987. i += n * 2;
  40988. } else {
  40989. for (j = 0; j < n; j++) {
  40990. b = data[i++];
  40991. stack.push(b << 8 | data[i++]);
  40992. }
  40993. }
  40994. } else if (op === 0x2B && !tooComplexToFollowFunctions) {
  40995. // CALL
  40996. if (!inFDEF && !inELSE) {
  40997. // collecting inforamtion about which functions are used
  40998. funcId = stack[stack.length - 1];
  40999. ttContext.functionsUsed[funcId] = true;
  41000. if (funcId in ttContext.functionsStackDeltas) {
  41001. stack.length += ttContext.functionsStackDeltas[funcId];
  41002. } else if (funcId in ttContext.functionsDefined && functionsCalled.indexOf(funcId) < 0) {
  41003. callstack.push({
  41004. data: data,
  41005. i: i,
  41006. stackTop: stack.length - 1
  41007. });
  41008. functionsCalled.push(funcId);
  41009. pc = ttContext.functionsDefined[funcId];
  41010. if (!pc) {
  41011. warn('TT: CALL non-existent function');
  41012. ttContext.hintsValid = false;
  41013. return;
  41014. }
  41015. data = pc.data;
  41016. i = pc.i;
  41017. }
  41018. }
  41019. } else if (op === 0x2C && !tooComplexToFollowFunctions) {
  41020. // FDEF
  41021. if (inFDEF || inELSE) {
  41022. warn('TT: nested FDEFs not allowed');
  41023. tooComplexToFollowFunctions = true;
  41024. }
  41025. inFDEF = true;
  41026. // collecting inforamtion about which functions are defined
  41027. lastDeff = i;
  41028. funcId = stack.pop();
  41029. ttContext.functionsDefined[funcId] = {
  41030. data: data,
  41031. i: i
  41032. };
  41033. } else if (op === 0x2D) {
  41034. // ENDF - end of function
  41035. if (inFDEF) {
  41036. inFDEF = false;
  41037. lastEndf = i;
  41038. } else {
  41039. pc = callstack.pop();
  41040. if (!pc) {
  41041. warn('TT: ENDF bad stack');
  41042. ttContext.hintsValid = false;
  41043. return;
  41044. }
  41045. funcId = functionsCalled.pop();
  41046. data = pc.data;
  41047. i = pc.i;
  41048. ttContext.functionsStackDeltas[funcId] = stack.length - pc.stackTop;
  41049. }
  41050. } else if (op === 0x89) {
  41051. // IDEF - instruction definition
  41052. if (inFDEF || inELSE) {
  41053. warn('TT: nested IDEFs not allowed');
  41054. tooComplexToFollowFunctions = true;
  41055. }
  41056. inFDEF = true;
  41057. // recording it as a function to track ENDF
  41058. lastDeff = i;
  41059. } else if (op === 0x58) {
  41060. // IF
  41061. ++ifLevel;
  41062. } else if (op === 0x1B) {
  41063. // ELSE
  41064. inELSE = ifLevel;
  41065. } else if (op === 0x59) {
  41066. // EIF
  41067. if (inELSE === ifLevel) {
  41068. inELSE = 0;
  41069. }
  41070. --ifLevel;
  41071. } else if (op === 0x1C) {
  41072. // JMPR
  41073. if (!inFDEF && !inELSE) {
  41074. var offset = stack[stack.length - 1];
  41075. // only jumping forward to prevent infinite loop
  41076. if (offset > 0) {
  41077. i += offset - 1;
  41078. }
  41079. }
  41080. }
  41081. // Adjusting stack not extactly, but just enough to get function id
  41082. if (!inFDEF && !inELSE) {
  41083. var stackDelta = op <= 0x8E ? TTOpsStackDeltas[op] : op >= 0xC0 && op <= 0xDF ? -1 : op >= 0xE0 ? -2 : 0;
  41084. if (op >= 0x71 && op <= 0x75) {
  41085. n = stack.pop();
  41086. if (n === n) {
  41087. stackDelta = -n * 2;
  41088. }
  41089. }
  41090. while (stackDelta < 0 && stack.length > 0) {
  41091. stack.pop();
  41092. stackDelta++;
  41093. }
  41094. while (stackDelta > 0) {
  41095. stack.push(NaN);
  41096. // pushing any number into stack
  41097. stackDelta--;
  41098. }
  41099. }
  41100. }
  41101. ttContext.tooComplexToFollowFunctions = tooComplexToFollowFunctions;
  41102. var content = [data];
  41103. if (i > data.length) {
  41104. content.push(new Uint8Array(i - data.length));
  41105. }
  41106. if (lastDeff > lastEndf) {
  41107. warn('TT: complementing a missing function tail');
  41108. // new function definition started, but not finished
  41109. // complete function by [CLEAR, ENDF]
  41110. content.push(new Uint8Array([
  41111. 0x22,
  41112. 0x2D
  41113. ]));
  41114. }
  41115. foldTTTable(table, content);
  41116. }
  41117. function checkInvalidFunctions(ttContext, maxFunctionDefs) {
  41118. if (ttContext.tooComplexToFollowFunctions) {
  41119. return;
  41120. }
  41121. if (ttContext.functionsDefined.length > maxFunctionDefs) {
  41122. warn('TT: more functions defined than expected');
  41123. ttContext.hintsValid = false;
  41124. return;
  41125. }
  41126. for (var j = 0, jj = ttContext.functionsUsed.length; j < jj; j++) {
  41127. if (j > maxFunctionDefs) {
  41128. warn('TT: invalid function id: ' + j);
  41129. ttContext.hintsValid = false;
  41130. return;
  41131. }
  41132. if (ttContext.functionsUsed[j] && !ttContext.functionsDefined[j]) {
  41133. warn('TT: undefined function: ' + j);
  41134. ttContext.hintsValid = false;
  41135. return;
  41136. }
  41137. }
  41138. }
  41139. function foldTTTable(table, content) {
  41140. if (content.length > 1) {
  41141. // concatenating the content items
  41142. var newLength = 0;
  41143. var j, jj;
  41144. for (j = 0, jj = content.length; j < jj; j++) {
  41145. newLength += content[j].length;
  41146. }
  41147. newLength = newLength + 3 & ~3;
  41148. var result = new Uint8Array(newLength);
  41149. var pos = 0;
  41150. for (j = 0, jj = content.length; j < jj; j++) {
  41151. result.set(content[j], pos);
  41152. pos += content[j].length;
  41153. }
  41154. table.data = result;
  41155. table.length = newLength;
  41156. }
  41157. }
  41158. function sanitizeTTPrograms(fpgm, prep, cvt, maxFunctionDefs) {
  41159. var ttContext = {
  41160. functionsDefined: [],
  41161. functionsUsed: [],
  41162. functionsStackDeltas: [],
  41163. tooComplexToFollowFunctions: false,
  41164. hintsValid: true
  41165. };
  41166. if (fpgm) {
  41167. sanitizeTTProgram(fpgm, ttContext);
  41168. }
  41169. if (prep) {
  41170. sanitizeTTProgram(prep, ttContext);
  41171. }
  41172. if (fpgm) {
  41173. checkInvalidFunctions(ttContext, maxFunctionDefs);
  41174. }
  41175. if (cvt && cvt.length & 1) {
  41176. var cvtData = new Uint8Array(cvt.length + 1);
  41177. cvtData.set(cvt.data);
  41178. cvt.data = cvtData;
  41179. }
  41180. return ttContext.hintsValid;
  41181. }
  41182. // The following steps modify the original font data, making copy
  41183. font = new Stream(new Uint8Array(font.getBytes()));
  41184. var VALID_TABLES = [
  41185. 'OS/2',
  41186. 'cmap',
  41187. 'head',
  41188. 'hhea',
  41189. 'hmtx',
  41190. 'maxp',
  41191. 'name',
  41192. 'post',
  41193. 'loca',
  41194. 'glyf',
  41195. 'fpgm',
  41196. 'prep',
  41197. 'cvt ',
  41198. 'CFF '
  41199. ];
  41200. var header = readOpenTypeHeader(font);
  41201. var numTables = header.numTables;
  41202. var cff, cffFile;
  41203. var tables = Object.create(null);
  41204. tables['OS/2'] = null;
  41205. tables['cmap'] = null;
  41206. tables['head'] = null;
  41207. tables['hhea'] = null;
  41208. tables['hmtx'] = null;
  41209. tables['maxp'] = null;
  41210. tables['name'] = null;
  41211. tables['post'] = null;
  41212. var table;
  41213. for (var i = 0; i < numTables; i++) {
  41214. table = readTableEntry(font);
  41215. if (VALID_TABLES.indexOf(table.tag) < 0) {
  41216. continue;
  41217. }
  41218. // skipping table if it's not a required or optional table
  41219. if (table.length === 0) {
  41220. continue;
  41221. }
  41222. // skipping empty tables
  41223. tables[table.tag] = table;
  41224. }
  41225. var isTrueType = !tables['CFF '];
  41226. if (!isTrueType) {
  41227. // OpenType font
  41228. if (header.version === 'OTTO' && properties.type !== 'CIDFontType2' || !tables['head'] || !tables['hhea'] || !tables['maxp'] || !tables['post']) {
  41229. // no major tables: throwing everything at CFFFont
  41230. cffFile = new Stream(tables['CFF '].data);
  41231. cff = new CFFFont(cffFile, properties);
  41232. adjustWidths(properties);
  41233. return this.convert(name, cff, properties);
  41234. }
  41235. delete tables['glyf'];
  41236. delete tables['loca'];
  41237. delete tables['fpgm'];
  41238. delete tables['prep'];
  41239. delete tables['cvt '];
  41240. this.isOpenType = true;
  41241. } else {
  41242. if (!tables['loca']) {
  41243. error('Required "loca" table is not found');
  41244. }
  41245. if (!tables['glyf']) {
  41246. warn('Required "glyf" table is not found -- trying to recover.');
  41247. // Note: We use `sanitizeGlyphLocations` to add dummy glyf data below.
  41248. tables['glyf'] = {
  41249. tag: 'glyf',
  41250. data: new Uint8Array(0)
  41251. };
  41252. }
  41253. this.isOpenType = false;
  41254. }
  41255. if (!tables['maxp']) {
  41256. error('Required "maxp" table is not found');
  41257. }
  41258. font.pos = (font.start || 0) + tables['maxp'].offset;
  41259. var version = font.getInt32();
  41260. var numGlyphs = font.getUint16();
  41261. var maxFunctionDefs = 0;
  41262. if (version >= 0x00010000 && tables['maxp'].length >= 22) {
  41263. // maxZones can be invalid
  41264. font.pos += 8;
  41265. var maxZones = font.getUint16();
  41266. if (maxZones > 2) {
  41267. // reset to 2 if font has invalid maxZones
  41268. tables['maxp'].data[14] = 0;
  41269. tables['maxp'].data[15] = 2;
  41270. }
  41271. font.pos += 4;
  41272. maxFunctionDefs = font.getUint16();
  41273. }
  41274. var dupFirstEntry = false;
  41275. if (properties.type === 'CIDFontType2' && properties.toUnicode && properties.toUnicode.get(0) > '\u0000') {
  41276. // oracle's defect (see 3427), duplicating first entry
  41277. dupFirstEntry = true;
  41278. numGlyphs++;
  41279. tables['maxp'].data[4] = numGlyphs >> 8;
  41280. tables['maxp'].data[5] = numGlyphs & 255;
  41281. }
  41282. var hintsValid = sanitizeTTPrograms(tables['fpgm'], tables['prep'], tables['cvt '], maxFunctionDefs);
  41283. if (!hintsValid) {
  41284. delete tables['fpgm'];
  41285. delete tables['prep'];
  41286. delete tables['cvt '];
  41287. }
  41288. // Ensure the hmtx table contains the advance width and
  41289. // sidebearings information for numGlyphs in the maxp table
  41290. sanitizeMetrics(font, tables['hhea'], tables['hmtx'], numGlyphs);
  41291. if (!tables['head']) {
  41292. error('Required "head" table is not found');
  41293. }
  41294. sanitizeHead(tables['head'], numGlyphs, isTrueType ? tables['loca'].length : 0);
  41295. var missingGlyphs = Object.create(null);
  41296. if (isTrueType) {
  41297. var isGlyphLocationsLong = int16(tables['head'].data[50], tables['head'].data[51]);
  41298. missingGlyphs = sanitizeGlyphLocations(tables['loca'], tables['glyf'], numGlyphs, isGlyphLocationsLong, hintsValid, dupFirstEntry);
  41299. }
  41300. if (!tables['hhea']) {
  41301. error('Required "hhea" table is not found');
  41302. }
  41303. // Sanitizer reduces the glyph advanceWidth to the maxAdvanceWidth
  41304. // Sometimes it's 0. That needs to be fixed
  41305. if (tables['hhea'].data[10] === 0 && tables['hhea'].data[11] === 0) {
  41306. tables['hhea'].data[10] = 0xFF;
  41307. tables['hhea'].data[11] = 0xFF;
  41308. }
  41309. // Extract some more font properties from the OpenType head and
  41310. // hhea tables; yMin and descent value are always negative.
  41311. var metricsOverride = {
  41312. unitsPerEm: int16(tables['head'].data[18], tables['head'].data[19]),
  41313. yMax: int16(tables['head'].data[42], tables['head'].data[43]),
  41314. yMin: signedInt16(tables['head'].data[38], tables['head'].data[39]),
  41315. ascent: int16(tables['hhea'].data[4], tables['hhea'].data[5]),
  41316. descent: signedInt16(tables['hhea'].data[6], tables['hhea'].data[7])
  41317. };
  41318. // PDF FontDescriptor metrics lie -- using data from actual font.
  41319. this.ascent = metricsOverride.ascent / metricsOverride.unitsPerEm;
  41320. this.descent = metricsOverride.descent / metricsOverride.unitsPerEm;
  41321. // The 'post' table has glyphs names.
  41322. if (tables['post']) {
  41323. var valid = readPostScriptTable(tables['post'], properties, numGlyphs);
  41324. if (!valid) {
  41325. tables['post'] = null;
  41326. }
  41327. }
  41328. var charCodeToGlyphId = [], charCode;
  41329. var toUnicode = properties.toUnicode, widths = properties.widths;
  41330. var skipToUnicode = toUnicode instanceof IdentityToUnicodeMap || toUnicode.length === 0x10000;
  41331. // Helper function to try to skip mapping of empty glyphs.
  41332. // Note: In some cases, just relying on the glyph data doesn't work,
  41333. // hence we also use a few heuristics to fix various PDF files.
  41334. function hasGlyph(glyphId, charCode, widthCode) {
  41335. if (!missingGlyphs[glyphId]) {
  41336. return true;
  41337. }
  41338. if (!skipToUnicode && charCode >= 0 && toUnicode.has(charCode)) {
  41339. return true;
  41340. }
  41341. if (widths && widthCode >= 0 && isNum(widths[widthCode])) {
  41342. return true;
  41343. }
  41344. return false;
  41345. }
  41346. if (properties.type === 'CIDFontType2') {
  41347. var cidToGidMap = properties.cidToGidMap || [];
  41348. var isCidToGidMapEmpty = cidToGidMap.length === 0;
  41349. properties.cMap.forEach(function (charCode, cid) {
  41350. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  41351. var glyphId = -1;
  41352. if (isCidToGidMapEmpty) {
  41353. glyphId = cid;
  41354. } else if (cidToGidMap[cid] !== undefined) {
  41355. glyphId = cidToGidMap[cid];
  41356. }
  41357. if (glyphId >= 0 && glyphId < numGlyphs && hasGlyph(glyphId, charCode, cid)) {
  41358. charCodeToGlyphId[charCode] = glyphId;
  41359. }
  41360. });
  41361. if (dupFirstEntry && (isCidToGidMapEmpty || !charCodeToGlyphId[0])) {
  41362. // We don't duplicate the first entry in the `charCodeToGlyphId` map
  41363. // if the font has a `CIDToGIDMap` which has already mapped the first
  41364. // entry to a non-zero `glyphId` (fixes issue7544.pdf).
  41365. charCodeToGlyphId[0] = numGlyphs - 1;
  41366. }
  41367. } else {
  41368. // Most of the following logic in this code branch is based on the
  41369. // 9.6.6.4 of the PDF spec.
  41370. var cmapTable = readCmapTable(tables['cmap'], font, this.isSymbolicFont, properties.hasEncoding);
  41371. var cmapPlatformId = cmapTable.platformId;
  41372. var cmapEncodingId = cmapTable.encodingId;
  41373. var cmapMappings = cmapTable.mappings;
  41374. var cmapMappingsLength = cmapMappings.length;
  41375. // The spec seems to imply that if the font is symbolic the encoding
  41376. // should be ignored, this doesn't appear to work for 'preistabelle.pdf'
  41377. // where the the font is symbolic and it has an encoding.
  41378. if (properties.hasEncoding && (cmapPlatformId === 3 && cmapEncodingId === 1 || cmapPlatformId === 1 && cmapEncodingId === 0) || cmapPlatformId === -1 && cmapEncodingId === -1 && // Temporary hack
  41379. !!getEncoding(properties.baseEncodingName)) {
  41380. // Temporary hack
  41381. // When no preferred cmap table was found and |baseEncodingName| is
  41382. // one of the predefined encodings, we seem to obtain a better
  41383. // |charCodeToGlyphId| map from the code below (fixes bug 1057544).
  41384. // TODO: Note that this is a hack which should be removed as soon as
  41385. // we have proper support for more exotic cmap tables.
  41386. var baseEncoding = [];
  41387. if (properties.baseEncodingName === 'MacRomanEncoding' || properties.baseEncodingName === 'WinAnsiEncoding') {
  41388. baseEncoding = getEncoding(properties.baseEncodingName);
  41389. }
  41390. var glyphsUnicodeMap = getGlyphsUnicode();
  41391. for (charCode = 0; charCode < 256; charCode++) {
  41392. var glyphName, standardGlyphName;
  41393. if (this.differences && charCode in this.differences) {
  41394. glyphName = this.differences[charCode];
  41395. } else if (charCode in baseEncoding && baseEncoding[charCode] !== '') {
  41396. glyphName = baseEncoding[charCode];
  41397. } else {
  41398. glyphName = StandardEncoding[charCode];
  41399. }
  41400. if (!glyphName) {
  41401. continue;
  41402. }
  41403. // Ensure that non-standard glyph names are resolved to valid ones.
  41404. standardGlyphName = recoverGlyphName(glyphName, glyphsUnicodeMap);
  41405. var unicodeOrCharCode, isUnicode = false;
  41406. if (cmapPlatformId === 3 && cmapEncodingId === 1) {
  41407. unicodeOrCharCode = glyphsUnicodeMap[standardGlyphName];
  41408. isUnicode = true;
  41409. } else if (cmapPlatformId === 1 && cmapEncodingId === 0) {
  41410. // TODO: the encoding needs to be updated with mac os table.
  41411. unicodeOrCharCode = MacRomanEncoding.indexOf(standardGlyphName);
  41412. }
  41413. var found = false;
  41414. for (i = 0; i < cmapMappingsLength; ++i) {
  41415. if (cmapMappings[i].charCode !== unicodeOrCharCode) {
  41416. continue;
  41417. }
  41418. var code = isUnicode ? charCode : unicodeOrCharCode;
  41419. if (hasGlyph(cmapMappings[i].glyphId, code, -1)) {
  41420. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  41421. found = true;
  41422. break;
  41423. }
  41424. }
  41425. if (!found && properties.glyphNames) {
  41426. // Try to map using the post table.
  41427. var glyphId = properties.glyphNames.indexOf(glyphName);
  41428. // The post table ought to use the same kind of glyph names as the
  41429. // `differences` array, but check the standard ones as a fallback.
  41430. if (glyphId === -1 && standardGlyphName !== glyphName) {
  41431. glyphId = properties.glyphNames.indexOf(standardGlyphName);
  41432. }
  41433. if (glyphId > 0 && hasGlyph(glyphId, -1, -1)) {
  41434. charCodeToGlyphId[charCode] = glyphId;
  41435. found = true;
  41436. }
  41437. }
  41438. if (!found) {
  41439. charCodeToGlyphId[charCode] = 0;
  41440. }
  41441. }
  41442. } else // notdef
  41443. if (cmapPlatformId === 0 && cmapEncodingId === 0) {
  41444. // Default Unicode semantics, use the charcodes as is.
  41445. for (i = 0; i < cmapMappingsLength; ++i) {
  41446. charCodeToGlyphId[cmapMappings[i].charCode] = cmapMappings[i].glyphId;
  41447. }
  41448. } else {
  41449. // For (3, 0) cmap tables:
  41450. // The charcode key being stored in charCodeToGlyphId is the lower
  41451. // byte of the two-byte charcodes of the cmap table since according to
  41452. // the spec: 'each byte from the string shall be prepended with the
  41453. // high byte of the range [of charcodes in the cmap table], to form
  41454. // a two-byte character, which shall be used to select the
  41455. // associated glyph description from the subtable'.
  41456. //
  41457. // For (1, 0) cmap tables:
  41458. // 'single bytes from the string shall be used to look up the
  41459. // associated glyph descriptions from the subtable'. This means
  41460. // charcodes in the cmap will be single bytes, so no-op since
  41461. // glyph.charCode & 0xFF === glyph.charCode
  41462. for (i = 0; i < cmapMappingsLength; ++i) {
  41463. charCode = cmapMappings[i].charCode & 0xFF;
  41464. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  41465. }
  41466. }
  41467. }
  41468. if (charCodeToGlyphId.length === 0) {
  41469. // defines at least one glyph
  41470. charCodeToGlyphId[0] = 0;
  41471. }
  41472. // Converting glyphs and ids into font's cmap table
  41473. var newMapping = adjustMapping(charCodeToGlyphId, properties);
  41474. this.toFontChar = newMapping.toFontChar;
  41475. tables['cmap'] = {
  41476. tag: 'cmap',
  41477. data: createCmapTable(newMapping.charCodeToGlyphId, numGlyphs)
  41478. };
  41479. if (!tables['OS/2'] || !validateOS2Table(tables['OS/2'])) {
  41480. tables['OS/2'] = {
  41481. tag: 'OS/2',
  41482. data: createOS2Table(properties, newMapping.charCodeToGlyphId, metricsOverride)
  41483. };
  41484. }
  41485. // Rewrite the 'post' table if needed
  41486. if (!tables['post']) {
  41487. tables['post'] = {
  41488. tag: 'post',
  41489. data: createPostTable(properties)
  41490. };
  41491. }
  41492. if (!isTrueType) {
  41493. try {
  41494. // Trying to repair CFF file
  41495. cffFile = new Stream(tables['CFF '].data);
  41496. var parser = new CFFParser(cffFile, properties, SEAC_ANALYSIS_ENABLED);
  41497. cff = parser.parse();
  41498. var compiler = new CFFCompiler(cff);
  41499. tables['CFF '].data = compiler.compile();
  41500. } catch (e) {
  41501. warn('Failed to compile font ' + properties.loadedName);
  41502. }
  41503. }
  41504. // Re-creating 'name' table
  41505. if (!tables['name']) {
  41506. tables['name'] = {
  41507. tag: 'name',
  41508. data: createNameTable(this.name)
  41509. };
  41510. } else {
  41511. // ... using existing 'name' table as prototype
  41512. var namePrototype = readNameTable(tables['name']);
  41513. tables['name'].data = createNameTable(name, namePrototype);
  41514. }
  41515. var builder = new OpenTypeFileBuilder(header.version);
  41516. for (var tableTag in tables) {
  41517. builder.addTable(tableTag, tables[tableTag].data);
  41518. }
  41519. return builder.toArray();
  41520. },
  41521. convert: function Font_convert(fontName, font, properties) {
  41522. // TODO: Check the charstring widths to determine this.
  41523. properties.fixedPitch = false;
  41524. if (properties.builtInEncoding) {
  41525. // For Type1 fonts that do not include either `ToUnicode` or `Encoding`
  41526. // data, attempt to use the `builtInEncoding` to improve text selection.
  41527. adjustToUnicode(properties, properties.builtInEncoding);
  41528. }
  41529. var mapping = font.getGlyphMapping(properties);
  41530. var newMapping = adjustMapping(mapping, properties);
  41531. this.toFontChar = newMapping.toFontChar;
  41532. var numGlyphs = font.numGlyphs;
  41533. function getCharCodes(charCodeToGlyphId, glyphId) {
  41534. var charCodes = null;
  41535. for (var charCode in charCodeToGlyphId) {
  41536. if (glyphId === charCodeToGlyphId[charCode]) {
  41537. if (!charCodes) {
  41538. charCodes = [];
  41539. }
  41540. charCodes.push(charCode | 0);
  41541. }
  41542. }
  41543. return charCodes;
  41544. }
  41545. function createCharCode(charCodeToGlyphId, glyphId) {
  41546. for (var charCode in charCodeToGlyphId) {
  41547. if (glyphId === charCodeToGlyphId[charCode]) {
  41548. return charCode | 0;
  41549. }
  41550. }
  41551. newMapping.charCodeToGlyphId[newMapping.nextAvailableFontCharCode] = glyphId;
  41552. return newMapping.nextAvailableFontCharCode++;
  41553. }
  41554. var seacs = font.seacs;
  41555. if (SEAC_ANALYSIS_ENABLED && seacs && seacs.length) {
  41556. var matrix = properties.fontMatrix || FONT_IDENTITY_MATRIX;
  41557. var charset = font.getCharset();
  41558. var seacMap = Object.create(null);
  41559. for (var glyphId in seacs) {
  41560. glyphId |= 0;
  41561. var seac = seacs[glyphId];
  41562. var baseGlyphName = StandardEncoding[seac[2]];
  41563. var accentGlyphName = StandardEncoding[seac[3]];
  41564. var baseGlyphId = charset.indexOf(baseGlyphName);
  41565. var accentGlyphId = charset.indexOf(accentGlyphName);
  41566. if (baseGlyphId < 0 || accentGlyphId < 0) {
  41567. continue;
  41568. }
  41569. var accentOffset = {
  41570. x: seac[0] * matrix[0] + seac[1] * matrix[2] + matrix[4],
  41571. y: seac[0] * matrix[1] + seac[1] * matrix[3] + matrix[5]
  41572. };
  41573. var charCodes = getCharCodes(mapping, glyphId);
  41574. if (!charCodes) {
  41575. // There's no point in mapping it if the char code was never mapped
  41576. // to begin with.
  41577. continue;
  41578. }
  41579. for (var i = 0, ii = charCodes.length; i < ii; i++) {
  41580. var charCode = charCodes[i];
  41581. // Find a fontCharCode that maps to the base and accent glyphs.
  41582. // If one doesn't exists, create it.
  41583. var charCodeToGlyphId = newMapping.charCodeToGlyphId;
  41584. var baseFontCharCode = createCharCode(charCodeToGlyphId, baseGlyphId);
  41585. var accentFontCharCode = createCharCode(charCodeToGlyphId, accentGlyphId);
  41586. seacMap[charCode] = {
  41587. baseFontCharCode: baseFontCharCode,
  41588. accentFontCharCode: accentFontCharCode,
  41589. accentOffset: accentOffset
  41590. };
  41591. }
  41592. }
  41593. properties.seacMap = seacMap;
  41594. }
  41595. var unitsPerEm = 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0];
  41596. var builder = new OpenTypeFileBuilder('\x4F\x54\x54\x4F');
  41597. // PostScript Font Program
  41598. builder.addTable('CFF ', font.data);
  41599. // OS/2 and Windows Specific metrics
  41600. builder.addTable('OS/2', createOS2Table(properties, newMapping.charCodeToGlyphId));
  41601. // Character to glyphs mapping
  41602. builder.addTable('cmap', createCmapTable(newMapping.charCodeToGlyphId, numGlyphs));
  41603. // Font header
  41604. builder.addTable('head', '\x00\x01\x00\x00' + // Version number
  41605. '\x00\x00\x10\x00' + // fontRevision
  41606. '\x00\x00\x00\x00' + // checksumAdjustement
  41607. '\x5F\x0F\x3C\xF5' + // magicNumber
  41608. '\x00\x00' + // Flags
  41609. safeString16(unitsPerEm) + // unitsPerEM
  41610. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // creation date
  41611. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // modifification date
  41612. '\x00\x00' + // xMin
  41613. safeString16(properties.descent) + // yMin
  41614. '\x0F\xFF' + // xMax
  41615. safeString16(properties.ascent) + // yMax
  41616. string16(properties.italicAngle ? 2 : 0) + // macStyle
  41617. '\x00\x11' + // lowestRecPPEM
  41618. '\x00\x00' + // fontDirectionHint
  41619. '\x00\x00' + // indexToLocFormat
  41620. '\x00\x00');
  41621. // glyphDataFormat
  41622. // Horizontal header
  41623. builder.addTable('hhea', '\x00\x01\x00\x00' + // Version number
  41624. safeString16(properties.ascent) + // Typographic Ascent
  41625. safeString16(properties.descent) + // Typographic Descent
  41626. '\x00\x00' + // Line Gap
  41627. '\xFF\xFF' + // advanceWidthMax
  41628. '\x00\x00' + // minLeftSidebearing
  41629. '\x00\x00' + // minRightSidebearing
  41630. '\x00\x00' + // xMaxExtent
  41631. safeString16(properties.capHeight) + // caretSlopeRise
  41632. safeString16(Math.tan(properties.italicAngle) * properties.xHeight) + // caretSlopeRun
  41633. '\x00\x00' + // caretOffset
  41634. '\x00\x00' + // -reserved-
  41635. '\x00\x00' + // -reserved-
  41636. '\x00\x00' + // -reserved-
  41637. '\x00\x00' + // -reserved-
  41638. '\x00\x00' + // metricDataFormat
  41639. string16(numGlyphs));
  41640. // Number of HMetrics
  41641. // Horizontal metrics
  41642. builder.addTable('hmtx', function fontFieldsHmtx() {
  41643. var charstrings = font.charstrings;
  41644. var cffWidths = font.cff ? font.cff.widths : null;
  41645. var hmtx = '\x00\x00\x00\x00';
  41646. // Fake .notdef
  41647. for (var i = 1, ii = numGlyphs; i < ii; i++) {
  41648. var width = 0;
  41649. if (charstrings) {
  41650. var charstring = charstrings[i - 1];
  41651. width = 'width' in charstring ? charstring.width : 0;
  41652. } else if (cffWidths) {
  41653. width = Math.ceil(cffWidths[i] || 0);
  41654. }
  41655. hmtx += string16(width) + string16(0);
  41656. }
  41657. return hmtx;
  41658. }());
  41659. // Maximum profile
  41660. builder.addTable('maxp', '\x00\x00\x50\x00' + // Version number
  41661. string16(numGlyphs));
  41662. // Num of glyphs
  41663. // Naming tables
  41664. builder.addTable('name', createNameTable(fontName));
  41665. // PostScript information
  41666. builder.addTable('post', createPostTable(properties));
  41667. return builder.toArray();
  41668. },
  41669. get spaceWidth() {
  41670. if ('_shadowWidth' in this) {
  41671. return this._shadowWidth;
  41672. }
  41673. // trying to estimate space character width
  41674. var possibleSpaceReplacements = [
  41675. 'space',
  41676. 'minus',
  41677. 'one',
  41678. 'i',
  41679. 'I'
  41680. ];
  41681. var width;
  41682. for (var i = 0, ii = possibleSpaceReplacements.length; i < ii; i++) {
  41683. var glyphName = possibleSpaceReplacements[i];
  41684. // if possible, getting width by glyph name
  41685. if (glyphName in this.widths) {
  41686. width = this.widths[glyphName];
  41687. break;
  41688. }
  41689. var glyphsUnicodeMap = getGlyphsUnicode();
  41690. var glyphUnicode = glyphsUnicodeMap[glyphName];
  41691. // finding the charcode via unicodeToCID map
  41692. var charcode = 0;
  41693. if (this.composite) {
  41694. if (this.cMap.contains(glyphUnicode)) {
  41695. charcode = this.cMap.lookup(glyphUnicode);
  41696. }
  41697. }
  41698. // ... via toUnicode map
  41699. if (!charcode && this.toUnicode) {
  41700. charcode = this.toUnicode.charCodeOf(glyphUnicode);
  41701. }
  41702. // setting it to unicode if negative or undefined
  41703. if (charcode <= 0) {
  41704. charcode = glyphUnicode;
  41705. }
  41706. // trying to get width via charcode
  41707. width = this.widths[charcode];
  41708. if (width) {
  41709. break;
  41710. }
  41711. }
  41712. // the non-zero width found
  41713. width = width || this.defaultWidth;
  41714. // Do not shadow the property here. See discussion:
  41715. // https://github.com/mozilla/pdf.js/pull/2127#discussion_r1662280
  41716. this._shadowWidth = width;
  41717. return width;
  41718. },
  41719. charToGlyph: function Font_charToGlyph(charcode, isSpace) {
  41720. var fontCharCode, width, operatorListId;
  41721. var widthCode = charcode;
  41722. if (this.cMap && this.cMap.contains(charcode)) {
  41723. widthCode = this.cMap.lookup(charcode);
  41724. }
  41725. width = this.widths[widthCode];
  41726. width = isNum(width) ? width : this.defaultWidth;
  41727. var vmetric = this.vmetrics && this.vmetrics[widthCode];
  41728. var unicode = this.toUnicode.get(charcode) || charcode;
  41729. if (typeof unicode === 'number') {
  41730. unicode = String.fromCharCode(unicode);
  41731. }
  41732. var isInFont = charcode in this.toFontChar;
  41733. // First try the toFontChar map, if it's not there then try falling
  41734. // back to the char code.
  41735. fontCharCode = this.toFontChar[charcode] || charcode;
  41736. if (this.missingFile) {
  41737. fontCharCode = mapSpecialUnicodeValues(fontCharCode);
  41738. }
  41739. if (this.isType3Font) {
  41740. // Font char code in this case is actually a glyph name.
  41741. operatorListId = fontCharCode;
  41742. }
  41743. var accent = null;
  41744. if (this.seacMap && this.seacMap[charcode]) {
  41745. isInFont = true;
  41746. var seac = this.seacMap[charcode];
  41747. fontCharCode = seac.baseFontCharCode;
  41748. accent = {
  41749. fontChar: String.fromCharCode(seac.accentFontCharCode),
  41750. offset: seac.accentOffset
  41751. };
  41752. }
  41753. var fontChar = String.fromCharCode(fontCharCode);
  41754. var glyph = this.glyphCache[charcode];
  41755. if (!glyph || !glyph.matchesForCache(fontChar, unicode, accent, width, vmetric, operatorListId, isSpace, isInFont)) {
  41756. glyph = new Glyph(fontChar, unicode, accent, width, vmetric, operatorListId, isSpace, isInFont);
  41757. this.glyphCache[charcode] = glyph;
  41758. }
  41759. return glyph;
  41760. },
  41761. charsToGlyphs: function Font_charsToGlyphs(chars) {
  41762. var charsCache = this.charsCache;
  41763. var glyphs, glyph, charcode;
  41764. // if we translated this string before, just grab it from the cache
  41765. if (charsCache) {
  41766. glyphs = charsCache[chars];
  41767. if (glyphs) {
  41768. return glyphs;
  41769. }
  41770. }
  41771. // lazily create the translation cache
  41772. if (!charsCache) {
  41773. charsCache = this.charsCache = Object.create(null);
  41774. }
  41775. glyphs = [];
  41776. var charsCacheKey = chars;
  41777. var i = 0, ii;
  41778. if (this.cMap) {
  41779. // composite fonts have multi-byte strings convert the string from
  41780. // single-byte to multi-byte
  41781. var c = Object.create(null);
  41782. while (i < chars.length) {
  41783. this.cMap.readCharCode(chars, i, c);
  41784. charcode = c.charcode;
  41785. var length = c.length;
  41786. i += length;
  41787. // Space is char with code 0x20 and length 1 in multiple-byte codes.
  41788. var isSpace = length === 1 && chars.charCodeAt(i - 1) === 0x20;
  41789. glyph = this.charToGlyph(charcode, isSpace);
  41790. glyphs.push(glyph);
  41791. }
  41792. } else {
  41793. for (i = 0, ii = chars.length; i < ii; ++i) {
  41794. charcode = chars.charCodeAt(i);
  41795. glyph = this.charToGlyph(charcode, charcode === 0x20);
  41796. glyphs.push(glyph);
  41797. }
  41798. }
  41799. // Enter the translated string into the cache
  41800. return charsCache[charsCacheKey] = glyphs;
  41801. }
  41802. };
  41803. return Font;
  41804. }();
  41805. var ErrorFont = function ErrorFontClosure() {
  41806. function ErrorFont(error) {
  41807. this.error = error;
  41808. this.loadedName = 'g_font_error';
  41809. this.loading = false;
  41810. }
  41811. ErrorFont.prototype = {
  41812. charsToGlyphs: function ErrorFont_charsToGlyphs() {
  41813. return [];
  41814. },
  41815. exportData: function ErrorFont_exportData() {
  41816. return { error: this.error };
  41817. }
  41818. };
  41819. return ErrorFont;
  41820. }();
  41821. /**
  41822. * Shared logic for building a char code to glyph id mapping for Type1 and
  41823. * simple CFF fonts. See section 9.6.6.2 of the spec.
  41824. * @param {Object} properties Font properties object.
  41825. * @param {Object} builtInEncoding The encoding contained within the actual font
  41826. * data.
  41827. * @param {Array} glyphNames Array of glyph names where the index is the
  41828. * glyph ID.
  41829. * @returns {Object} A char code to glyph ID map.
  41830. */
  41831. function type1FontGlyphMapping(properties, builtInEncoding, glyphNames) {
  41832. var charCodeToGlyphId = Object.create(null);
  41833. var glyphId, charCode, baseEncoding;
  41834. if (properties.baseEncodingName) {
  41835. // If a valid base encoding name was used, the mapping is initialized with
  41836. // that.
  41837. baseEncoding = getEncoding(properties.baseEncodingName);
  41838. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  41839. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  41840. if (glyphId >= 0) {
  41841. charCodeToGlyphId[charCode] = glyphId;
  41842. } else {
  41843. charCodeToGlyphId[charCode] = 0;
  41844. }
  41845. }
  41846. } else // notdef
  41847. if (!!(properties.flags & FontFlags.Symbolic)) {
  41848. // For a symbolic font the encoding should be the fonts built-in
  41849. // encoding.
  41850. for (charCode in builtInEncoding) {
  41851. charCodeToGlyphId[charCode] = builtInEncoding[charCode];
  41852. }
  41853. } else {
  41854. // For non-symbolic fonts that don't have a base encoding the standard
  41855. // encoding should be used.
  41856. baseEncoding = StandardEncoding;
  41857. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  41858. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  41859. if (glyphId >= 0) {
  41860. charCodeToGlyphId[charCode] = glyphId;
  41861. } else {
  41862. charCodeToGlyphId[charCode] = 0;
  41863. }
  41864. }
  41865. }
  41866. // notdef
  41867. // Lastly, merge in the differences.
  41868. var differences = properties.differences, glyphsUnicodeMap;
  41869. if (differences) {
  41870. for (charCode in differences) {
  41871. var glyphName = differences[charCode];
  41872. glyphId = glyphNames.indexOf(glyphName);
  41873. if (glyphId === -1) {
  41874. if (!glyphsUnicodeMap) {
  41875. glyphsUnicodeMap = getGlyphsUnicode();
  41876. }
  41877. var standardGlyphName = recoverGlyphName(glyphName, glyphsUnicodeMap);
  41878. if (standardGlyphName !== glyphName) {
  41879. glyphId = glyphNames.indexOf(standardGlyphName);
  41880. }
  41881. }
  41882. if (glyphId >= 0) {
  41883. charCodeToGlyphId[charCode] = glyphId;
  41884. } else {
  41885. charCodeToGlyphId[charCode] = 0;
  41886. }
  41887. }
  41888. }
  41889. // notdef
  41890. return charCodeToGlyphId;
  41891. }
  41892. // Type1Font is also a CIDFontType0.
  41893. var Type1Font = function Type1FontClosure() {
  41894. function findBlock(streamBytes, signature, startIndex) {
  41895. var streamBytesLength = streamBytes.length;
  41896. var signatureLength = signature.length;
  41897. var scanLength = streamBytesLength - signatureLength;
  41898. var i = startIndex, j, found = false;
  41899. while (i < scanLength) {
  41900. j = 0;
  41901. while (j < signatureLength && streamBytes[i + j] === signature[j]) {
  41902. j++;
  41903. }
  41904. if (j >= signatureLength) {
  41905. // `signature` found, skip over whitespace.
  41906. i += j;
  41907. while (i < streamBytesLength && isSpace(streamBytes[i])) {
  41908. i++;
  41909. }
  41910. found = true;
  41911. break;
  41912. }
  41913. i++;
  41914. }
  41915. return {
  41916. found: found,
  41917. length: i
  41918. };
  41919. }
  41920. function getHeaderBlock(stream, suggestedLength) {
  41921. var EEXEC_SIGNATURE = [
  41922. 0x65,
  41923. 0x65,
  41924. 0x78,
  41925. 0x65,
  41926. 0x63
  41927. ];
  41928. var streamStartPos = stream.pos;
  41929. // Save the initial stream position.
  41930. var headerBytes, headerBytesLength, block;
  41931. try {
  41932. headerBytes = stream.getBytes(suggestedLength);
  41933. headerBytesLength = headerBytes.length;
  41934. } catch (ex) {
  41935. if (ex instanceof MissingDataException) {
  41936. throw ex;
  41937. }
  41938. }
  41939. // Ignore errors if the `suggestedLength` is huge enough that a Uint8Array
  41940. // cannot hold the result of `getBytes`, and fallback to simply checking
  41941. // the entire stream (fixes issue3928.pdf).
  41942. if (headerBytesLength === suggestedLength) {
  41943. // Most of the time `suggestedLength` is correct, so to speed things up we
  41944. // initially only check the last few bytes to see if the header was found.
  41945. // Otherwise we (potentially) check the entire stream to prevent errors in
  41946. // `Type1Parser` (fixes issue5686.pdf).
  41947. block = findBlock(headerBytes, EEXEC_SIGNATURE, suggestedLength - 2 * EEXEC_SIGNATURE.length);
  41948. if (block.found && block.length === suggestedLength) {
  41949. return {
  41950. stream: new Stream(headerBytes),
  41951. length: suggestedLength
  41952. };
  41953. }
  41954. }
  41955. warn('Invalid "Length1" property in Type1 font -- trying to recover.');
  41956. stream.pos = streamStartPos;
  41957. // Reset the stream position.
  41958. var SCAN_BLOCK_LENGTH = 2048;
  41959. var actualLength;
  41960. while (true) {
  41961. var scanBytes = stream.peekBytes(SCAN_BLOCK_LENGTH);
  41962. block = findBlock(scanBytes, EEXEC_SIGNATURE, 0);
  41963. if (block.length === 0) {
  41964. break;
  41965. }
  41966. stream.pos += block.length;
  41967. // Update the stream position.
  41968. if (block.found) {
  41969. actualLength = stream.pos - streamStartPos;
  41970. break;
  41971. }
  41972. }
  41973. stream.pos = streamStartPos;
  41974. // Reset the stream position.
  41975. if (actualLength) {
  41976. return {
  41977. stream: new Stream(stream.getBytes(actualLength)),
  41978. length: actualLength
  41979. };
  41980. }
  41981. warn('Unable to recover "Length1" property in Type1 font -- using as is.');
  41982. return {
  41983. stream: new Stream(stream.getBytes(suggestedLength)),
  41984. length: suggestedLength
  41985. };
  41986. }
  41987. function getEexecBlock(stream, suggestedLength) {
  41988. // We should ideally parse the eexec block to ensure that `suggestedLength`
  41989. // is correct, so we don't truncate the block data if it's too small.
  41990. // However, this would also require checking if the fixed-content portion
  41991. // exists (using the 'Length3' property), and ensuring that it's valid.
  41992. //
  41993. // Given that `suggestedLength` almost always is correct, all the validation
  41994. // would require a great deal of unnecessary parsing for most fonts.
  41995. // To save time, we always fetch the entire stream instead, which also avoid
  41996. // issues if `suggestedLength` is huge (see comment in `getHeaderBlock`).
  41997. //
  41998. // NOTE: This means that the function can include the fixed-content portion
  41999. // in the returned eexec block. In practice this does *not* seem to matter,
  42000. // since `Type1Parser_extractFontProgram` will skip over any non-commands.
  42001. var eexecBytes = stream.getBytes();
  42002. return {
  42003. stream: new Stream(eexecBytes),
  42004. length: eexecBytes.length
  42005. };
  42006. }
  42007. function Type1Font(name, file, properties) {
  42008. // Some bad generators embed pfb file as is, we have to strip 6-byte header.
  42009. // Also, length1 and length2 might be off by 6 bytes as well.
  42010. // http://www.math.ubc.ca/~cass/piscript/type1.pdf
  42011. var PFB_HEADER_SIZE = 6;
  42012. var headerBlockLength = properties.length1;
  42013. var eexecBlockLength = properties.length2;
  42014. var pfbHeader = file.peekBytes(PFB_HEADER_SIZE);
  42015. var pfbHeaderPresent = pfbHeader[0] === 0x80 && pfbHeader[1] === 0x01;
  42016. if (pfbHeaderPresent) {
  42017. file.skip(PFB_HEADER_SIZE);
  42018. headerBlockLength = pfbHeader[5] << 24 | pfbHeader[4] << 16 | pfbHeader[3] << 8 | pfbHeader[2];
  42019. }
  42020. // Get the data block containing glyphs and subrs information
  42021. var headerBlock = getHeaderBlock(file, headerBlockLength);
  42022. headerBlockLength = headerBlock.length;
  42023. var headerBlockParser = new Type1Parser(headerBlock.stream, false, SEAC_ANALYSIS_ENABLED);
  42024. headerBlockParser.extractFontHeader(properties);
  42025. if (pfbHeaderPresent) {
  42026. pfbHeader = file.getBytes(PFB_HEADER_SIZE);
  42027. eexecBlockLength = pfbHeader[5] << 24 | pfbHeader[4] << 16 | pfbHeader[3] << 8 | pfbHeader[2];
  42028. }
  42029. // Decrypt the data blocks and retrieve it's content
  42030. var eexecBlock = getEexecBlock(file, eexecBlockLength);
  42031. eexecBlockLength = eexecBlock.length;
  42032. var eexecBlockParser = new Type1Parser(eexecBlock.stream, true, SEAC_ANALYSIS_ENABLED);
  42033. var data = eexecBlockParser.extractFontProgram();
  42034. for (var info in data.properties) {
  42035. properties[info] = data.properties[info];
  42036. }
  42037. var charstrings = data.charstrings;
  42038. var type2Charstrings = this.getType2Charstrings(charstrings);
  42039. var subrs = this.getType2Subrs(data.subrs);
  42040. this.charstrings = charstrings;
  42041. this.data = this.wrap(name, type2Charstrings, this.charstrings, subrs, properties);
  42042. this.seacs = this.getSeacs(data.charstrings);
  42043. }
  42044. Type1Font.prototype = {
  42045. get numGlyphs() {
  42046. return this.charstrings.length + 1;
  42047. },
  42048. getCharset: function Type1Font_getCharset() {
  42049. var charset = ['.notdef'];
  42050. var charstrings = this.charstrings;
  42051. for (var glyphId = 0; glyphId < charstrings.length; glyphId++) {
  42052. charset.push(charstrings[glyphId].glyphName);
  42053. }
  42054. return charset;
  42055. },
  42056. getGlyphMapping: function Type1Font_getGlyphMapping(properties) {
  42057. var charstrings = this.charstrings;
  42058. var glyphNames = ['.notdef'], glyphId;
  42059. for (glyphId = 0; glyphId < charstrings.length; glyphId++) {
  42060. glyphNames.push(charstrings[glyphId].glyphName);
  42061. }
  42062. var encoding = properties.builtInEncoding;
  42063. if (encoding) {
  42064. var builtInEncoding = Object.create(null);
  42065. for (var charCode in encoding) {
  42066. glyphId = glyphNames.indexOf(encoding[charCode]);
  42067. if (glyphId >= 0) {
  42068. builtInEncoding[charCode] = glyphId;
  42069. }
  42070. }
  42071. }
  42072. return type1FontGlyphMapping(properties, builtInEncoding, glyphNames);
  42073. },
  42074. getSeacs: function Type1Font_getSeacs(charstrings) {
  42075. var i, ii;
  42076. var seacMap = [];
  42077. for (i = 0, ii = charstrings.length; i < ii; i++) {
  42078. var charstring = charstrings[i];
  42079. if (charstring.seac) {
  42080. // Offset by 1 for .notdef
  42081. seacMap[i + 1] = charstring.seac;
  42082. }
  42083. }
  42084. return seacMap;
  42085. },
  42086. getType2Charstrings: function Type1Font_getType2Charstrings(type1Charstrings) {
  42087. var type2Charstrings = [];
  42088. for (var i = 0, ii = type1Charstrings.length; i < ii; i++) {
  42089. type2Charstrings.push(type1Charstrings[i].charstring);
  42090. }
  42091. return type2Charstrings;
  42092. },
  42093. getType2Subrs: function Type1Font_getType2Subrs(type1Subrs) {
  42094. var bias = 0;
  42095. var count = type1Subrs.length;
  42096. if (count < 1133) {
  42097. bias = 107;
  42098. } else if (count < 33769) {
  42099. bias = 1131;
  42100. } else {
  42101. bias = 32768;
  42102. }
  42103. // Add a bunch of empty subrs to deal with the Type2 bias
  42104. var type2Subrs = [];
  42105. var i;
  42106. for (i = 0; i < bias; i++) {
  42107. type2Subrs.push([0x0B]);
  42108. }
  42109. for (i = 0; i < count; i++) {
  42110. type2Subrs.push(type1Subrs[i]);
  42111. }
  42112. return type2Subrs;
  42113. },
  42114. wrap: function Type1Font_wrap(name, glyphs, charstrings, subrs, properties) {
  42115. var cff = new CFF();
  42116. cff.header = new CFFHeader(1, 0, 4, 4);
  42117. cff.names = [name];
  42118. var topDict = new CFFTopDict();
  42119. // CFF strings IDs 0...390 are predefined names, so refering
  42120. // to entries in our own String INDEX starts at SID 391.
  42121. topDict.setByName('version', 391);
  42122. topDict.setByName('Notice', 392);
  42123. topDict.setByName('FullName', 393);
  42124. topDict.setByName('FamilyName', 394);
  42125. topDict.setByName('Weight', 395);
  42126. topDict.setByName('Encoding', null);
  42127. // placeholder
  42128. topDict.setByName('FontMatrix', properties.fontMatrix);
  42129. topDict.setByName('FontBBox', properties.bbox);
  42130. topDict.setByName('charset', null);
  42131. // placeholder
  42132. topDict.setByName('CharStrings', null);
  42133. // placeholder
  42134. topDict.setByName('Private', null);
  42135. // placeholder
  42136. cff.topDict = topDict;
  42137. var strings = new CFFStrings();
  42138. strings.add('Version 0.11');
  42139. // Version
  42140. strings.add('See original notice');
  42141. // Notice
  42142. strings.add(name);
  42143. // FullName
  42144. strings.add(name);
  42145. // FamilyName
  42146. strings.add('Medium');
  42147. // Weight
  42148. cff.strings = strings;
  42149. cff.globalSubrIndex = new CFFIndex();
  42150. var count = glyphs.length;
  42151. var charsetArray = [0];
  42152. var i, ii;
  42153. for (i = 0; i < count; i++) {
  42154. var index = CFFStandardStrings.indexOf(charstrings[i].glyphName);
  42155. // TODO: Insert the string and correctly map it. Previously it was
  42156. // thought mapping names that aren't in the standard strings to .notdef
  42157. // was fine, however in issue818 when mapping them all to .notdef the
  42158. // adieresis glyph no longer worked.
  42159. if (index === -1) {
  42160. index = 0;
  42161. }
  42162. charsetArray.push(index >> 8 & 0xff, index & 0xff);
  42163. }
  42164. cff.charset = new CFFCharset(false, 0, [], charsetArray);
  42165. var charStringsIndex = new CFFIndex();
  42166. charStringsIndex.add([
  42167. 0x8B,
  42168. 0x0E
  42169. ]);
  42170. // .notdef
  42171. for (i = 0; i < count; i++) {
  42172. var glyph = glyphs[i];
  42173. // If the CharString outline is empty, replace it with .notdef to
  42174. // prevent OTS from rejecting the font (fixes bug1252420.pdf).
  42175. if (glyph.length === 0) {
  42176. charStringsIndex.add([
  42177. 0x8B,
  42178. 0x0E
  42179. ]);
  42180. // .notdef
  42181. continue;
  42182. }
  42183. charStringsIndex.add(glyph);
  42184. }
  42185. cff.charStrings = charStringsIndex;
  42186. var privateDict = new CFFPrivateDict();
  42187. privateDict.setByName('Subrs', null);
  42188. // placeholder
  42189. var fields = [
  42190. 'BlueValues',
  42191. 'OtherBlues',
  42192. 'FamilyBlues',
  42193. 'FamilyOtherBlues',
  42194. 'StemSnapH',
  42195. 'StemSnapV',
  42196. 'BlueShift',
  42197. 'BlueFuzz',
  42198. 'BlueScale',
  42199. 'LanguageGroup',
  42200. 'ExpansionFactor',
  42201. 'ForceBold',
  42202. 'StdHW',
  42203. 'StdVW'
  42204. ];
  42205. for (i = 0, ii = fields.length; i < ii; i++) {
  42206. var field = fields[i];
  42207. if (!(field in properties.privateData)) {
  42208. continue;
  42209. }
  42210. var value = properties.privateData[field];
  42211. if (isArray(value)) {
  42212. // All of the private dictionary array data in CFF must be stored as
  42213. // "delta-encoded" numbers.
  42214. for (var j = value.length - 1; j > 0; j--) {
  42215. value[j] -= value[j - 1];
  42216. }
  42217. }
  42218. // ... difference from previous value
  42219. privateDict.setByName(field, value);
  42220. }
  42221. cff.topDict.privateDict = privateDict;
  42222. var subrIndex = new CFFIndex();
  42223. for (i = 0, ii = subrs.length; i < ii; i++) {
  42224. subrIndex.add(subrs[i]);
  42225. }
  42226. privateDict.subrsIndex = subrIndex;
  42227. var compiler = new CFFCompiler(cff);
  42228. return compiler.compile();
  42229. }
  42230. };
  42231. return Type1Font;
  42232. }();
  42233. var CFFFont = function CFFFontClosure() {
  42234. function CFFFont(file, properties) {
  42235. this.properties = properties;
  42236. var parser = new CFFParser(file, properties, SEAC_ANALYSIS_ENABLED);
  42237. this.cff = parser.parse();
  42238. var compiler = new CFFCompiler(this.cff);
  42239. this.seacs = this.cff.seacs;
  42240. try {
  42241. this.data = compiler.compile();
  42242. } catch (e) {
  42243. warn('Failed to compile font ' + properties.loadedName);
  42244. // There may have just been an issue with the compiler, set the data
  42245. // anyway and hope the font loaded.
  42246. this.data = file;
  42247. }
  42248. }
  42249. CFFFont.prototype = {
  42250. get numGlyphs() {
  42251. return this.cff.charStrings.count;
  42252. },
  42253. getCharset: function CFFFont_getCharset() {
  42254. return this.cff.charset.charset;
  42255. },
  42256. getGlyphMapping: function CFFFont_getGlyphMapping() {
  42257. var cff = this.cff;
  42258. var properties = this.properties;
  42259. var charsets = cff.charset.charset;
  42260. var charCodeToGlyphId;
  42261. var glyphId;
  42262. if (properties.composite) {
  42263. charCodeToGlyphId = Object.create(null);
  42264. if (cff.isCIDFont) {
  42265. // If the font is actually a CID font then we should use the charset
  42266. // to map CIDs to GIDs.
  42267. for (glyphId = 0; glyphId < charsets.length; glyphId++) {
  42268. var cid = charsets[glyphId];
  42269. var charCode = properties.cMap.charCodeOf(cid);
  42270. charCodeToGlyphId[charCode] = glyphId;
  42271. }
  42272. } else {
  42273. // If it is NOT actually a CID font then CIDs should be mapped
  42274. // directly to GIDs.
  42275. for (glyphId = 0; glyphId < cff.charStrings.count; glyphId++) {
  42276. charCodeToGlyphId[glyphId] = glyphId;
  42277. }
  42278. }
  42279. return charCodeToGlyphId;
  42280. }
  42281. var encoding = cff.encoding ? cff.encoding.encoding : null;
  42282. charCodeToGlyphId = type1FontGlyphMapping(properties, encoding, charsets);
  42283. return charCodeToGlyphId;
  42284. }
  42285. };
  42286. return CFFFont;
  42287. }();
  42288. // Workaround for seac on Windows.
  42289. (function checkSeacSupport() {
  42290. if (typeof navigator !== 'undefined' && /Windows/.test(navigator.userAgent)) {
  42291. SEAC_ANALYSIS_ENABLED = true;
  42292. }
  42293. }());
  42294. // Workaround for Private Use Area characters in Chrome on Windows
  42295. // http://code.google.com/p/chromium/issues/detail?id=122465
  42296. // https://github.com/mozilla/pdf.js/issues/1689
  42297. (function checkChromeWindows() {
  42298. if (typeof navigator !== 'undefined' && /Windows.*Chrome/.test(navigator.userAgent)) {
  42299. SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = true;
  42300. }
  42301. }());
  42302. exports.ErrorFont = ErrorFont;
  42303. exports.Font = Font;
  42304. exports.FontFlags = FontFlags;
  42305. exports.IdentityToUnicodeMap = IdentityToUnicodeMap;
  42306. exports.ToUnicodeMap = ToUnicodeMap;
  42307. exports.getFontType = getFontType;
  42308. }));
  42309. (function (root, factory) {
  42310. factory(root.pdfjsCorePsParser = {}, root.pdfjsSharedUtil, root.pdfjsCoreParser);
  42311. }(this, function (exports, sharedUtil, coreParser) {
  42312. var error = sharedUtil.error;
  42313. var isSpace = sharedUtil.isSpace;
  42314. var EOF = coreParser.EOF;
  42315. var PostScriptParser = function PostScriptParserClosure() {
  42316. function PostScriptParser(lexer) {
  42317. this.lexer = lexer;
  42318. this.operators = [];
  42319. this.token = null;
  42320. this.prev = null;
  42321. }
  42322. PostScriptParser.prototype = {
  42323. nextToken: function PostScriptParser_nextToken() {
  42324. this.prev = this.token;
  42325. this.token = this.lexer.getToken();
  42326. },
  42327. accept: function PostScriptParser_accept(type) {
  42328. if (this.token.type === type) {
  42329. this.nextToken();
  42330. return true;
  42331. }
  42332. return false;
  42333. },
  42334. expect: function PostScriptParser_expect(type) {
  42335. if (this.accept(type)) {
  42336. return true;
  42337. }
  42338. error('Unexpected symbol: found ' + this.token.type + ' expected ' + type + '.');
  42339. },
  42340. parse: function PostScriptParser_parse() {
  42341. this.nextToken();
  42342. this.expect(PostScriptTokenTypes.LBRACE);
  42343. this.parseBlock();
  42344. this.expect(PostScriptTokenTypes.RBRACE);
  42345. return this.operators;
  42346. },
  42347. parseBlock: function PostScriptParser_parseBlock() {
  42348. while (true) {
  42349. if (this.accept(PostScriptTokenTypes.NUMBER)) {
  42350. this.operators.push(this.prev.value);
  42351. } else if (this.accept(PostScriptTokenTypes.OPERATOR)) {
  42352. this.operators.push(this.prev.value);
  42353. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  42354. this.parseCondition();
  42355. } else {
  42356. return;
  42357. }
  42358. }
  42359. },
  42360. parseCondition: function PostScriptParser_parseCondition() {
  42361. // Add two place holders that will be updated later
  42362. var conditionLocation = this.operators.length;
  42363. this.operators.push(null, null);
  42364. this.parseBlock();
  42365. this.expect(PostScriptTokenTypes.RBRACE);
  42366. if (this.accept(PostScriptTokenTypes.IF)) {
  42367. // The true block is right after the 'if' so it just falls through on
  42368. // true else it jumps and skips the true block.
  42369. this.operators[conditionLocation] = this.operators.length;
  42370. this.operators[conditionLocation + 1] = 'jz';
  42371. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  42372. var jumpLocation = this.operators.length;
  42373. this.operators.push(null, null);
  42374. var endOfTrue = this.operators.length;
  42375. this.parseBlock();
  42376. this.expect(PostScriptTokenTypes.RBRACE);
  42377. this.expect(PostScriptTokenTypes.IFELSE);
  42378. // The jump is added at the end of the true block to skip the false
  42379. // block.
  42380. this.operators[jumpLocation] = this.operators.length;
  42381. this.operators[jumpLocation + 1] = 'j';
  42382. this.operators[conditionLocation] = endOfTrue;
  42383. this.operators[conditionLocation + 1] = 'jz';
  42384. } else {
  42385. error('PS Function: error parsing conditional.');
  42386. }
  42387. }
  42388. };
  42389. return PostScriptParser;
  42390. }();
  42391. var PostScriptTokenTypes = {
  42392. LBRACE: 0,
  42393. RBRACE: 1,
  42394. NUMBER: 2,
  42395. OPERATOR: 3,
  42396. IF: 4,
  42397. IFELSE: 5
  42398. };
  42399. var PostScriptToken = function PostScriptTokenClosure() {
  42400. function PostScriptToken(type, value) {
  42401. this.type = type;
  42402. this.value = value;
  42403. }
  42404. var opCache = Object.create(null);
  42405. PostScriptToken.getOperator = function PostScriptToken_getOperator(op) {
  42406. var opValue = opCache[op];
  42407. if (opValue) {
  42408. return opValue;
  42409. }
  42410. return opCache[op] = new PostScriptToken(PostScriptTokenTypes.OPERATOR, op);
  42411. };
  42412. PostScriptToken.LBRACE = new PostScriptToken(PostScriptTokenTypes.LBRACE, '{');
  42413. PostScriptToken.RBRACE = new PostScriptToken(PostScriptTokenTypes.RBRACE, '}');
  42414. PostScriptToken.IF = new PostScriptToken(PostScriptTokenTypes.IF, 'IF');
  42415. PostScriptToken.IFELSE = new PostScriptToken(PostScriptTokenTypes.IFELSE, 'IFELSE');
  42416. return PostScriptToken;
  42417. }();
  42418. var PostScriptLexer = function PostScriptLexerClosure() {
  42419. function PostScriptLexer(stream) {
  42420. this.stream = stream;
  42421. this.nextChar();
  42422. this.strBuf = [];
  42423. }
  42424. PostScriptLexer.prototype = {
  42425. nextChar: function PostScriptLexer_nextChar() {
  42426. return this.currentChar = this.stream.getByte();
  42427. },
  42428. getToken: function PostScriptLexer_getToken() {
  42429. var comment = false;
  42430. var ch = this.currentChar;
  42431. // skip comments
  42432. while (true) {
  42433. if (ch < 0) {
  42434. return EOF;
  42435. }
  42436. if (comment) {
  42437. if (ch === 0x0A || ch === 0x0D) {
  42438. comment = false;
  42439. }
  42440. } else if (ch === 0x25) {
  42441. // '%'
  42442. comment = true;
  42443. } else if (!isSpace(ch)) {
  42444. break;
  42445. }
  42446. ch = this.nextChar();
  42447. }
  42448. switch (ch | 0) {
  42449. case 0x30:
  42450. case 0x31:
  42451. case 0x32:
  42452. case 0x33:
  42453. case 0x34:
  42454. // '0'-'4'
  42455. case 0x35:
  42456. case 0x36:
  42457. case 0x37:
  42458. case 0x38:
  42459. case 0x39:
  42460. // '5'-'9'
  42461. case 0x2B:
  42462. case 0x2D:
  42463. case 0x2E:
  42464. // '+', '-', '.'
  42465. return new PostScriptToken(PostScriptTokenTypes.NUMBER, this.getNumber());
  42466. case 0x7B:
  42467. // '{'
  42468. this.nextChar();
  42469. return PostScriptToken.LBRACE;
  42470. case 0x7D:
  42471. // '}'
  42472. this.nextChar();
  42473. return PostScriptToken.RBRACE;
  42474. }
  42475. // operator
  42476. var strBuf = this.strBuf;
  42477. strBuf.length = 0;
  42478. strBuf[0] = String.fromCharCode(ch);
  42479. while ((ch = this.nextChar()) >= 0 && // and 'A'-'Z', 'a'-'z'
  42480. (ch >= 0x41 && ch <= 0x5A || ch >= 0x61 && ch <= 0x7A)) {
  42481. strBuf.push(String.fromCharCode(ch));
  42482. }
  42483. var str = strBuf.join('');
  42484. switch (str.toLowerCase()) {
  42485. case 'if':
  42486. return PostScriptToken.IF;
  42487. case 'ifelse':
  42488. return PostScriptToken.IFELSE;
  42489. default:
  42490. return PostScriptToken.getOperator(str);
  42491. }
  42492. },
  42493. getNumber: function PostScriptLexer_getNumber() {
  42494. var ch = this.currentChar;
  42495. var strBuf = this.strBuf;
  42496. strBuf.length = 0;
  42497. strBuf[0] = String.fromCharCode(ch);
  42498. while ((ch = this.nextChar()) >= 0) {
  42499. if (ch >= 0x30 && ch <= 0x39 || // '0'-'9'
  42500. ch === 0x2D || ch === 0x2E) {
  42501. // '-', '.'
  42502. strBuf.push(String.fromCharCode(ch));
  42503. } else {
  42504. break;
  42505. }
  42506. }
  42507. var value = parseFloat(strBuf.join(''));
  42508. if (isNaN(value)) {
  42509. error('Invalid floating point number: ' + value);
  42510. }
  42511. return value;
  42512. }
  42513. };
  42514. return PostScriptLexer;
  42515. }();
  42516. exports.PostScriptLexer = PostScriptLexer;
  42517. exports.PostScriptParser = PostScriptParser;
  42518. }));
  42519. (function (root, factory) {
  42520. factory(root.pdfjsCoreFunction = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCorePsParser);
  42521. }(this, function (exports, sharedUtil, corePrimitives, corePsParser) {
  42522. var error = sharedUtil.error;
  42523. var info = sharedUtil.info;
  42524. var isArray = sharedUtil.isArray;
  42525. var isBool = sharedUtil.isBool;
  42526. var isDict = corePrimitives.isDict;
  42527. var isStream = corePrimitives.isStream;
  42528. var PostScriptLexer = corePsParser.PostScriptLexer;
  42529. var PostScriptParser = corePsParser.PostScriptParser;
  42530. var PDFFunction = function PDFFunctionClosure() {
  42531. var CONSTRUCT_SAMPLED = 0;
  42532. var CONSTRUCT_INTERPOLATED = 2;
  42533. var CONSTRUCT_STICHED = 3;
  42534. var CONSTRUCT_POSTSCRIPT = 4;
  42535. return {
  42536. getSampleArray: function PDFFunction_getSampleArray(size, outputSize, bps, str) {
  42537. var i, ii;
  42538. var length = 1;
  42539. for (i = 0, ii = size.length; i < ii; i++) {
  42540. length *= size[i];
  42541. }
  42542. length *= outputSize;
  42543. var array = new Array(length);
  42544. var codeSize = 0;
  42545. var codeBuf = 0;
  42546. // 32 is a valid bps so shifting won't work
  42547. var sampleMul = 1.0 / (Math.pow(2.0, bps) - 1);
  42548. var strBytes = str.getBytes((length * bps + 7) / 8);
  42549. var strIdx = 0;
  42550. for (i = 0; i < length; i++) {
  42551. while (codeSize < bps) {
  42552. codeBuf <<= 8;
  42553. codeBuf |= strBytes[strIdx++];
  42554. codeSize += 8;
  42555. }
  42556. codeSize -= bps;
  42557. array[i] = (codeBuf >> codeSize) * sampleMul;
  42558. codeBuf &= (1 << codeSize) - 1;
  42559. }
  42560. return array;
  42561. },
  42562. getIR: function PDFFunction_getIR(xref, fn) {
  42563. var dict = fn.dict;
  42564. if (!dict) {
  42565. dict = fn;
  42566. }
  42567. var types = [
  42568. this.constructSampled,
  42569. null,
  42570. this.constructInterpolated,
  42571. this.constructStiched,
  42572. this.constructPostScript
  42573. ];
  42574. var typeNum = dict.get('FunctionType');
  42575. var typeFn = types[typeNum];
  42576. if (!typeFn) {
  42577. error('Unknown type of function');
  42578. }
  42579. return typeFn.call(this, fn, dict, xref);
  42580. },
  42581. fromIR: function PDFFunction_fromIR(IR) {
  42582. var type = IR[0];
  42583. switch (type) {
  42584. case CONSTRUCT_SAMPLED:
  42585. return this.constructSampledFromIR(IR);
  42586. case CONSTRUCT_INTERPOLATED:
  42587. return this.constructInterpolatedFromIR(IR);
  42588. case CONSTRUCT_STICHED:
  42589. return this.constructStichedFromIR(IR);
  42590. //case CONSTRUCT_POSTSCRIPT:
  42591. default:
  42592. return this.constructPostScriptFromIR(IR);
  42593. }
  42594. },
  42595. parse: function PDFFunction_parse(xref, fn) {
  42596. var IR = this.getIR(xref, fn);
  42597. return this.fromIR(IR);
  42598. },
  42599. parseArray: function PDFFunction_parseArray(xref, fnObj) {
  42600. if (!isArray(fnObj)) {
  42601. // not an array -- parsing as regular function
  42602. return this.parse(xref, fnObj);
  42603. }
  42604. var fnArray = [];
  42605. for (var j = 0, jj = fnObj.length; j < jj; j++) {
  42606. var obj = xref.fetchIfRef(fnObj[j]);
  42607. fnArray.push(PDFFunction.parse(xref, obj));
  42608. }
  42609. return function (src, srcOffset, dest, destOffset) {
  42610. for (var i = 0, ii = fnArray.length; i < ii; i++) {
  42611. fnArray[i](src, srcOffset, dest, destOffset + i);
  42612. }
  42613. };
  42614. },
  42615. constructSampled: function PDFFunction_constructSampled(str, dict) {
  42616. function toMultiArray(arr) {
  42617. var inputLength = arr.length;
  42618. var out = [];
  42619. var index = 0;
  42620. for (var i = 0; i < inputLength; i += 2) {
  42621. out[index] = [
  42622. arr[i],
  42623. arr[i + 1]
  42624. ];
  42625. ++index;
  42626. }
  42627. return out;
  42628. }
  42629. var domain = dict.getArray('Domain');
  42630. var range = dict.getArray('Range');
  42631. if (!domain || !range) {
  42632. error('No domain or range');
  42633. }
  42634. var inputSize = domain.length / 2;
  42635. var outputSize = range.length / 2;
  42636. domain = toMultiArray(domain);
  42637. range = toMultiArray(range);
  42638. var size = dict.get('Size');
  42639. var bps = dict.get('BitsPerSample');
  42640. var order = dict.get('Order') || 1;
  42641. if (order !== 1) {
  42642. // No description how cubic spline interpolation works in PDF32000:2008
  42643. // As in poppler, ignoring order, linear interpolation may work as good
  42644. info('No support for cubic spline interpolation: ' + order);
  42645. }
  42646. var encode = dict.getArray('Encode');
  42647. if (!encode) {
  42648. encode = [];
  42649. for (var i = 0; i < inputSize; ++i) {
  42650. encode.push(0);
  42651. encode.push(size[i] - 1);
  42652. }
  42653. }
  42654. encode = toMultiArray(encode);
  42655. var decode = dict.getArray('Decode');
  42656. if (!decode) {
  42657. decode = range;
  42658. } else {
  42659. decode = toMultiArray(decode);
  42660. }
  42661. var samples = this.getSampleArray(size, outputSize, bps, str);
  42662. return [
  42663. CONSTRUCT_SAMPLED,
  42664. inputSize,
  42665. domain,
  42666. encode,
  42667. decode,
  42668. samples,
  42669. size,
  42670. outputSize,
  42671. Math.pow(2, bps) - 1,
  42672. range
  42673. ];
  42674. },
  42675. constructSampledFromIR: function PDFFunction_constructSampledFromIR(IR) {
  42676. // See chapter 3, page 109 of the PDF reference
  42677. function interpolate(x, xmin, xmax, ymin, ymax) {
  42678. return ymin + (x - xmin) * ((ymax - ymin) / (xmax - xmin));
  42679. }
  42680. return function constructSampledFromIRResult(src, srcOffset, dest, destOffset) {
  42681. // See chapter 3, page 110 of the PDF reference.
  42682. var m = IR[1];
  42683. var domain = IR[2];
  42684. var encode = IR[3];
  42685. var decode = IR[4];
  42686. var samples = IR[5];
  42687. var size = IR[6];
  42688. var n = IR[7];
  42689. //var mask = IR[8];
  42690. var range = IR[9];
  42691. // Building the cube vertices: its part and sample index
  42692. // http://rjwagner49.com/Mathematics/Interpolation.pdf
  42693. var cubeVertices = 1 << m;
  42694. var cubeN = new Float64Array(cubeVertices);
  42695. var cubeVertex = new Uint32Array(cubeVertices);
  42696. var i, j;
  42697. for (j = 0; j < cubeVertices; j++) {
  42698. cubeN[j] = 1;
  42699. }
  42700. var k = n, pos = 1;
  42701. // Map x_i to y_j for 0 <= i < m using the sampled function.
  42702. for (i = 0; i < m; ++i) {
  42703. // x_i' = min(max(x_i, Domain_2i), Domain_2i+1)
  42704. var domain_2i = domain[i][0];
  42705. var domain_2i_1 = domain[i][1];
  42706. var xi = Math.min(Math.max(src[srcOffset + i], domain_2i), domain_2i_1);
  42707. // e_i = Interpolate(x_i', Domain_2i, Domain_2i+1,
  42708. // Encode_2i, Encode_2i+1)
  42709. var e = interpolate(xi, domain_2i, domain_2i_1, encode[i][0], encode[i][1]);
  42710. // e_i' = min(max(e_i, 0), Size_i - 1)
  42711. var size_i = size[i];
  42712. e = Math.min(Math.max(e, 0), size_i - 1);
  42713. // Adjusting the cube: N and vertex sample index
  42714. var e0 = e < size_i - 1 ? Math.floor(e) : e - 1;
  42715. // e1 = e0 + 1;
  42716. var n0 = e0 + 1 - e;
  42717. // (e1 - e) / (e1 - e0);
  42718. var n1 = e - e0;
  42719. // (e - e0) / (e1 - e0);
  42720. var offset0 = e0 * k;
  42721. var offset1 = offset0 + k;
  42722. // e1 * k
  42723. for (j = 0; j < cubeVertices; j++) {
  42724. if (j & pos) {
  42725. cubeN[j] *= n1;
  42726. cubeVertex[j] += offset1;
  42727. } else {
  42728. cubeN[j] *= n0;
  42729. cubeVertex[j] += offset0;
  42730. }
  42731. }
  42732. k *= size_i;
  42733. pos <<= 1;
  42734. }
  42735. for (j = 0; j < n; ++j) {
  42736. // Sum all cube vertices' samples portions
  42737. var rj = 0;
  42738. for (i = 0; i < cubeVertices; i++) {
  42739. rj += samples[cubeVertex[i] + j] * cubeN[i];
  42740. }
  42741. // r_j' = Interpolate(r_j, 0, 2^BitsPerSample - 1,
  42742. // Decode_2j, Decode_2j+1)
  42743. rj = interpolate(rj, 0, 1, decode[j][0], decode[j][1]);
  42744. // y_j = min(max(r_j, range_2j), range_2j+1)
  42745. dest[destOffset + j] = Math.min(Math.max(rj, range[j][0]), range[j][1]);
  42746. }
  42747. };
  42748. },
  42749. constructInterpolated: function PDFFunction_constructInterpolated(str, dict) {
  42750. var c0 = dict.getArray('C0') || [0];
  42751. var c1 = dict.getArray('C1') || [1];
  42752. var n = dict.get('N');
  42753. if (!isArray(c0) || !isArray(c1)) {
  42754. error('Illegal dictionary for interpolated function');
  42755. }
  42756. var length = c0.length;
  42757. var diff = [];
  42758. for (var i = 0; i < length; ++i) {
  42759. diff.push(c1[i] - c0[i]);
  42760. }
  42761. return [
  42762. CONSTRUCT_INTERPOLATED,
  42763. c0,
  42764. diff,
  42765. n
  42766. ];
  42767. },
  42768. constructInterpolatedFromIR: function PDFFunction_constructInterpolatedFromIR(IR) {
  42769. var c0 = IR[1];
  42770. var diff = IR[2];
  42771. var n = IR[3];
  42772. var length = diff.length;
  42773. return function constructInterpolatedFromIRResult(src, srcOffset, dest, destOffset) {
  42774. var x = n === 1 ? src[srcOffset] : Math.pow(src[srcOffset], n);
  42775. for (var j = 0; j < length; ++j) {
  42776. dest[destOffset + j] = c0[j] + x * diff[j];
  42777. }
  42778. };
  42779. },
  42780. constructStiched: function PDFFunction_constructStiched(fn, dict, xref) {
  42781. var domain = dict.getArray('Domain');
  42782. if (!domain) {
  42783. error('No domain');
  42784. }
  42785. var inputSize = domain.length / 2;
  42786. if (inputSize !== 1) {
  42787. error('Bad domain for stiched function');
  42788. }
  42789. var fnRefs = dict.get('Functions');
  42790. var fns = [];
  42791. for (var i = 0, ii = fnRefs.length; i < ii; ++i) {
  42792. fns.push(PDFFunction.getIR(xref, xref.fetchIfRef(fnRefs[i])));
  42793. }
  42794. var bounds = dict.getArray('Bounds');
  42795. var encode = dict.getArray('Encode');
  42796. return [
  42797. CONSTRUCT_STICHED,
  42798. domain,
  42799. bounds,
  42800. encode,
  42801. fns
  42802. ];
  42803. },
  42804. constructStichedFromIR: function PDFFunction_constructStichedFromIR(IR) {
  42805. var domain = IR[1];
  42806. var bounds = IR[2];
  42807. var encode = IR[3];
  42808. var fnsIR = IR[4];
  42809. var fns = [];
  42810. var tmpBuf = new Float32Array(1);
  42811. for (var i = 0, ii = fnsIR.length; i < ii; i++) {
  42812. fns.push(PDFFunction.fromIR(fnsIR[i]));
  42813. }
  42814. return function constructStichedFromIRResult(src, srcOffset, dest, destOffset) {
  42815. var clip = function constructStichedFromIRClip(v, min, max) {
  42816. if (v > max) {
  42817. v = max;
  42818. } else if (v < min) {
  42819. v = min;
  42820. }
  42821. return v;
  42822. };
  42823. // clip to domain
  42824. var v = clip(src[srcOffset], domain[0], domain[1]);
  42825. // calculate which bound the value is in
  42826. for (var i = 0, ii = bounds.length; i < ii; ++i) {
  42827. if (v < bounds[i]) {
  42828. break;
  42829. }
  42830. }
  42831. // encode value into domain of function
  42832. var dmin = domain[0];
  42833. if (i > 0) {
  42834. dmin = bounds[i - 1];
  42835. }
  42836. var dmax = domain[1];
  42837. if (i < bounds.length) {
  42838. dmax = bounds[i];
  42839. }
  42840. var rmin = encode[2 * i];
  42841. var rmax = encode[2 * i + 1];
  42842. // Prevent the value from becoming NaN as a result
  42843. // of division by zero (fixes issue6113.pdf).
  42844. tmpBuf[0] = dmin === dmax ? rmin : rmin + (v - dmin) * (rmax - rmin) / (dmax - dmin);
  42845. // call the appropriate function
  42846. fns[i](tmpBuf, 0, dest, destOffset);
  42847. };
  42848. },
  42849. constructPostScript: function PDFFunction_constructPostScript(fn, dict, xref) {
  42850. var domain = dict.getArray('Domain');
  42851. var range = dict.getArray('Range');
  42852. if (!domain) {
  42853. error('No domain.');
  42854. }
  42855. if (!range) {
  42856. error('No range.');
  42857. }
  42858. var lexer = new PostScriptLexer(fn);
  42859. var parser = new PostScriptParser(lexer);
  42860. var code = parser.parse();
  42861. return [
  42862. CONSTRUCT_POSTSCRIPT,
  42863. domain,
  42864. range,
  42865. code
  42866. ];
  42867. },
  42868. constructPostScriptFromIR: function PDFFunction_constructPostScriptFromIR(IR) {
  42869. var domain = IR[1];
  42870. var range = IR[2];
  42871. var code = IR[3];
  42872. var compiled = new PostScriptCompiler().compile(code, domain, range);
  42873. if (compiled) {
  42874. // Compiled function consists of simple expressions such as addition,
  42875. // subtraction, Math.max, and also contains 'var' and 'return'
  42876. // statements. See the generation in the PostScriptCompiler below.
  42877. return new Function('src', 'srcOffset', 'dest', 'destOffset', compiled);
  42878. }
  42879. info('Unable to compile PS function');
  42880. var numOutputs = range.length >> 1;
  42881. var numInputs = domain.length >> 1;
  42882. var evaluator = new PostScriptEvaluator(code);
  42883. // Cache the values for a big speed up, the cache size is limited though
  42884. // since the number of possible values can be huge from a PS function.
  42885. var cache = Object.create(null);
  42886. // The MAX_CACHE_SIZE is set to ~4x the maximum number of distinct values
  42887. // seen in our tests.
  42888. var MAX_CACHE_SIZE = 2048 * 4;
  42889. var cache_available = MAX_CACHE_SIZE;
  42890. var tmpBuf = new Float32Array(numInputs);
  42891. return function constructPostScriptFromIRResult(src, srcOffset, dest, destOffset) {
  42892. var i, value;
  42893. var key = '';
  42894. var input = tmpBuf;
  42895. for (i = 0; i < numInputs; i++) {
  42896. value = src[srcOffset + i];
  42897. input[i] = value;
  42898. key += value + '_';
  42899. }
  42900. var cachedValue = cache[key];
  42901. if (cachedValue !== undefined) {
  42902. dest.set(cachedValue, destOffset);
  42903. return;
  42904. }
  42905. var output = new Float32Array(numOutputs);
  42906. var stack = evaluator.execute(input);
  42907. var stackIndex = stack.length - numOutputs;
  42908. for (i = 0; i < numOutputs; i++) {
  42909. value = stack[stackIndex + i];
  42910. var bound = range[i * 2];
  42911. if (value < bound) {
  42912. value = bound;
  42913. } else {
  42914. bound = range[i * 2 + 1];
  42915. if (value > bound) {
  42916. value = bound;
  42917. }
  42918. }
  42919. output[i] = value;
  42920. }
  42921. if (cache_available > 0) {
  42922. cache_available--;
  42923. cache[key] = output;
  42924. }
  42925. dest.set(output, destOffset);
  42926. };
  42927. }
  42928. };
  42929. }();
  42930. function isPDFFunction(v) {
  42931. var fnDict;
  42932. if (typeof v !== 'object') {
  42933. return false;
  42934. } else if (isDict(v)) {
  42935. fnDict = v;
  42936. } else if (isStream(v)) {
  42937. fnDict = v.dict;
  42938. } else {
  42939. return false;
  42940. }
  42941. return fnDict.has('FunctionType');
  42942. }
  42943. var PostScriptStack = function PostScriptStackClosure() {
  42944. var MAX_STACK_SIZE = 100;
  42945. function PostScriptStack(initialStack) {
  42946. this.stack = !initialStack ? [] : Array.prototype.slice.call(initialStack, 0);
  42947. }
  42948. PostScriptStack.prototype = {
  42949. push: function PostScriptStack_push(value) {
  42950. if (this.stack.length >= MAX_STACK_SIZE) {
  42951. error('PostScript function stack overflow.');
  42952. }
  42953. this.stack.push(value);
  42954. },
  42955. pop: function PostScriptStack_pop() {
  42956. if (this.stack.length <= 0) {
  42957. error('PostScript function stack underflow.');
  42958. }
  42959. return this.stack.pop();
  42960. },
  42961. copy: function PostScriptStack_copy(n) {
  42962. if (this.stack.length + n >= MAX_STACK_SIZE) {
  42963. error('PostScript function stack overflow.');
  42964. }
  42965. var stack = this.stack;
  42966. for (var i = stack.length - n, j = n - 1; j >= 0; j--, i++) {
  42967. stack.push(stack[i]);
  42968. }
  42969. },
  42970. index: function PostScriptStack_index(n) {
  42971. this.push(this.stack[this.stack.length - n - 1]);
  42972. },
  42973. // rotate the last n stack elements p times
  42974. roll: function PostScriptStack_roll(n, p) {
  42975. var stack = this.stack;
  42976. var l = stack.length - n;
  42977. var r = stack.length - 1, c = l + (p - Math.floor(p / n) * n), i, j, t;
  42978. for (i = l, j = r; i < j; i++, j--) {
  42979. t = stack[i];
  42980. stack[i] = stack[j];
  42981. stack[j] = t;
  42982. }
  42983. for (i = l, j = c - 1; i < j; i++, j--) {
  42984. t = stack[i];
  42985. stack[i] = stack[j];
  42986. stack[j] = t;
  42987. }
  42988. for (i = c, j = r; i < j; i++, j--) {
  42989. t = stack[i];
  42990. stack[i] = stack[j];
  42991. stack[j] = t;
  42992. }
  42993. }
  42994. };
  42995. return PostScriptStack;
  42996. }();
  42997. var PostScriptEvaluator = function PostScriptEvaluatorClosure() {
  42998. function PostScriptEvaluator(operators) {
  42999. this.operators = operators;
  43000. }
  43001. PostScriptEvaluator.prototype = {
  43002. execute: function PostScriptEvaluator_execute(initialStack) {
  43003. var stack = new PostScriptStack(initialStack);
  43004. var counter = 0;
  43005. var operators = this.operators;
  43006. var length = operators.length;
  43007. var operator, a, b;
  43008. while (counter < length) {
  43009. operator = operators[counter++];
  43010. if (typeof operator === 'number') {
  43011. // Operator is really an operand and should be pushed to the stack.
  43012. stack.push(operator);
  43013. continue;
  43014. }
  43015. switch (operator) {
  43016. // non standard ps operators
  43017. case 'jz':
  43018. // jump if false
  43019. b = stack.pop();
  43020. a = stack.pop();
  43021. if (!a) {
  43022. counter = b;
  43023. }
  43024. break;
  43025. case 'j':
  43026. // jump
  43027. a = stack.pop();
  43028. counter = a;
  43029. break;
  43030. // all ps operators in alphabetical order (excluding if/ifelse)
  43031. case 'abs':
  43032. a = stack.pop();
  43033. stack.push(Math.abs(a));
  43034. break;
  43035. case 'add':
  43036. b = stack.pop();
  43037. a = stack.pop();
  43038. stack.push(a + b);
  43039. break;
  43040. case 'and':
  43041. b = stack.pop();
  43042. a = stack.pop();
  43043. if (isBool(a) && isBool(b)) {
  43044. stack.push(a && b);
  43045. } else {
  43046. stack.push(a & b);
  43047. }
  43048. break;
  43049. case 'atan':
  43050. a = stack.pop();
  43051. stack.push(Math.atan(a));
  43052. break;
  43053. case 'bitshift':
  43054. b = stack.pop();
  43055. a = stack.pop();
  43056. if (a > 0) {
  43057. stack.push(a << b);
  43058. } else {
  43059. stack.push(a >> b);
  43060. }
  43061. break;
  43062. case 'ceiling':
  43063. a = stack.pop();
  43064. stack.push(Math.ceil(a));
  43065. break;
  43066. case 'copy':
  43067. a = stack.pop();
  43068. stack.copy(a);
  43069. break;
  43070. case 'cos':
  43071. a = stack.pop();
  43072. stack.push(Math.cos(a));
  43073. break;
  43074. case 'cvi':
  43075. a = stack.pop() | 0;
  43076. stack.push(a);
  43077. break;
  43078. case 'cvr':
  43079. // noop
  43080. break;
  43081. case 'div':
  43082. b = stack.pop();
  43083. a = stack.pop();
  43084. stack.push(a / b);
  43085. break;
  43086. case 'dup':
  43087. stack.copy(1);
  43088. break;
  43089. case 'eq':
  43090. b = stack.pop();
  43091. a = stack.pop();
  43092. stack.push(a === b);
  43093. break;
  43094. case 'exch':
  43095. stack.roll(2, 1);
  43096. break;
  43097. case 'exp':
  43098. b = stack.pop();
  43099. a = stack.pop();
  43100. stack.push(Math.pow(a, b));
  43101. break;
  43102. case 'false':
  43103. stack.push(false);
  43104. break;
  43105. case 'floor':
  43106. a = stack.pop();
  43107. stack.push(Math.floor(a));
  43108. break;
  43109. case 'ge':
  43110. b = stack.pop();
  43111. a = stack.pop();
  43112. stack.push(a >= b);
  43113. break;
  43114. case 'gt':
  43115. b = stack.pop();
  43116. a = stack.pop();
  43117. stack.push(a > b);
  43118. break;
  43119. case 'idiv':
  43120. b = stack.pop();
  43121. a = stack.pop();
  43122. stack.push(a / b | 0);
  43123. break;
  43124. case 'index':
  43125. a = stack.pop();
  43126. stack.index(a);
  43127. break;
  43128. case 'le':
  43129. b = stack.pop();
  43130. a = stack.pop();
  43131. stack.push(a <= b);
  43132. break;
  43133. case 'ln':
  43134. a = stack.pop();
  43135. stack.push(Math.log(a));
  43136. break;
  43137. case 'log':
  43138. a = stack.pop();
  43139. stack.push(Math.log(a) / Math.LN10);
  43140. break;
  43141. case 'lt':
  43142. b = stack.pop();
  43143. a = stack.pop();
  43144. stack.push(a < b);
  43145. break;
  43146. case 'mod':
  43147. b = stack.pop();
  43148. a = stack.pop();
  43149. stack.push(a % b);
  43150. break;
  43151. case 'mul':
  43152. b = stack.pop();
  43153. a = stack.pop();
  43154. stack.push(a * b);
  43155. break;
  43156. case 'ne':
  43157. b = stack.pop();
  43158. a = stack.pop();
  43159. stack.push(a !== b);
  43160. break;
  43161. case 'neg':
  43162. a = stack.pop();
  43163. stack.push(-a);
  43164. break;
  43165. case 'not':
  43166. a = stack.pop();
  43167. if (isBool(a)) {
  43168. stack.push(!a);
  43169. } else {
  43170. stack.push(~a);
  43171. }
  43172. break;
  43173. case 'or':
  43174. b = stack.pop();
  43175. a = stack.pop();
  43176. if (isBool(a) && isBool(b)) {
  43177. stack.push(a || b);
  43178. } else {
  43179. stack.push(a | b);
  43180. }
  43181. break;
  43182. case 'pop':
  43183. stack.pop();
  43184. break;
  43185. case 'roll':
  43186. b = stack.pop();
  43187. a = stack.pop();
  43188. stack.roll(a, b);
  43189. break;
  43190. case 'round':
  43191. a = stack.pop();
  43192. stack.push(Math.round(a));
  43193. break;
  43194. case 'sin':
  43195. a = stack.pop();
  43196. stack.push(Math.sin(a));
  43197. break;
  43198. case 'sqrt':
  43199. a = stack.pop();
  43200. stack.push(Math.sqrt(a));
  43201. break;
  43202. case 'sub':
  43203. b = stack.pop();
  43204. a = stack.pop();
  43205. stack.push(a - b);
  43206. break;
  43207. case 'true':
  43208. stack.push(true);
  43209. break;
  43210. case 'truncate':
  43211. a = stack.pop();
  43212. a = a < 0 ? Math.ceil(a) : Math.floor(a);
  43213. stack.push(a);
  43214. break;
  43215. case 'xor':
  43216. b = stack.pop();
  43217. a = stack.pop();
  43218. if (isBool(a) && isBool(b)) {
  43219. stack.push(a !== b);
  43220. } else {
  43221. stack.push(a ^ b);
  43222. }
  43223. break;
  43224. default:
  43225. error('Unknown operator ' + operator);
  43226. break;
  43227. }
  43228. }
  43229. return stack.stack;
  43230. }
  43231. };
  43232. return PostScriptEvaluator;
  43233. }();
  43234. // Most of the PDFs functions consist of simple operations such as:
  43235. // roll, exch, sub, cvr, pop, index, dup, mul, if, gt, add.
  43236. //
  43237. // We can compile most of such programs, and at the same moment, we can
  43238. // optimize some expressions using basic math properties. Keeping track of
  43239. // min/max values will allow us to avoid extra Math.min/Math.max calls.
  43240. var PostScriptCompiler = function PostScriptCompilerClosure() {
  43241. function AstNode(type) {
  43242. this.type = type;
  43243. }
  43244. AstNode.prototype.visit = function (visitor) {
  43245. throw new Error('abstract method');
  43246. };
  43247. function AstArgument(index, min, max) {
  43248. AstNode.call(this, 'args');
  43249. this.index = index;
  43250. this.min = min;
  43251. this.max = max;
  43252. }
  43253. AstArgument.prototype = Object.create(AstNode.prototype);
  43254. AstArgument.prototype.visit = function (visitor) {
  43255. visitor.visitArgument(this);
  43256. };
  43257. function AstLiteral(number) {
  43258. AstNode.call(this, 'literal');
  43259. this.number = number;
  43260. this.min = number;
  43261. this.max = number;
  43262. }
  43263. AstLiteral.prototype = Object.create(AstNode.prototype);
  43264. AstLiteral.prototype.visit = function (visitor) {
  43265. visitor.visitLiteral(this);
  43266. };
  43267. function AstBinaryOperation(op, arg1, arg2, min, max) {
  43268. AstNode.call(this, 'binary');
  43269. this.op = op;
  43270. this.arg1 = arg1;
  43271. this.arg2 = arg2;
  43272. this.min = min;
  43273. this.max = max;
  43274. }
  43275. AstBinaryOperation.prototype = Object.create(AstNode.prototype);
  43276. AstBinaryOperation.prototype.visit = function (visitor) {
  43277. visitor.visitBinaryOperation(this);
  43278. };
  43279. function AstMin(arg, max) {
  43280. AstNode.call(this, 'max');
  43281. this.arg = arg;
  43282. this.min = arg.min;
  43283. this.max = max;
  43284. }
  43285. AstMin.prototype = Object.create(AstNode.prototype);
  43286. AstMin.prototype.visit = function (visitor) {
  43287. visitor.visitMin(this);
  43288. };
  43289. function AstVariable(index, min, max) {
  43290. AstNode.call(this, 'var');
  43291. this.index = index;
  43292. this.min = min;
  43293. this.max = max;
  43294. }
  43295. AstVariable.prototype = Object.create(AstNode.prototype);
  43296. AstVariable.prototype.visit = function (visitor) {
  43297. visitor.visitVariable(this);
  43298. };
  43299. function AstVariableDefinition(variable, arg) {
  43300. AstNode.call(this, 'definition');
  43301. this.variable = variable;
  43302. this.arg = arg;
  43303. }
  43304. AstVariableDefinition.prototype = Object.create(AstNode.prototype);
  43305. AstVariableDefinition.prototype.visit = function (visitor) {
  43306. visitor.visitVariableDefinition(this);
  43307. };
  43308. function ExpressionBuilderVisitor() {
  43309. this.parts = [];
  43310. }
  43311. ExpressionBuilderVisitor.prototype = {
  43312. visitArgument: function (arg) {
  43313. this.parts.push('Math.max(', arg.min, ', Math.min(', arg.max, ', src[srcOffset + ', arg.index, ']))');
  43314. },
  43315. visitVariable: function (variable) {
  43316. this.parts.push('v', variable.index);
  43317. },
  43318. visitLiteral: function (literal) {
  43319. this.parts.push(literal.number);
  43320. },
  43321. visitBinaryOperation: function (operation) {
  43322. this.parts.push('(');
  43323. operation.arg1.visit(this);
  43324. this.parts.push(' ', operation.op, ' ');
  43325. operation.arg2.visit(this);
  43326. this.parts.push(')');
  43327. },
  43328. visitVariableDefinition: function (definition) {
  43329. this.parts.push('var ');
  43330. definition.variable.visit(this);
  43331. this.parts.push(' = ');
  43332. definition.arg.visit(this);
  43333. this.parts.push(';');
  43334. },
  43335. visitMin: function (max) {
  43336. this.parts.push('Math.min(');
  43337. max.arg.visit(this);
  43338. this.parts.push(', ', max.max, ')');
  43339. },
  43340. toString: function () {
  43341. return this.parts.join('');
  43342. }
  43343. };
  43344. function buildAddOperation(num1, num2) {
  43345. if (num2.type === 'literal' && num2.number === 0) {
  43346. // optimization: second operand is 0
  43347. return num1;
  43348. }
  43349. if (num1.type === 'literal' && num1.number === 0) {
  43350. // optimization: first operand is 0
  43351. return num2;
  43352. }
  43353. if (num2.type === 'literal' && num1.type === 'literal') {
  43354. // optimization: operands operand are literals
  43355. return new AstLiteral(num1.number + num2.number);
  43356. }
  43357. return new AstBinaryOperation('+', num1, num2, num1.min + num2.min, num1.max + num2.max);
  43358. }
  43359. function buildMulOperation(num1, num2) {
  43360. if (num2.type === 'literal') {
  43361. // optimization: second operands is a literal...
  43362. if (num2.number === 0) {
  43363. return new AstLiteral(0);
  43364. } else // and it's 0
  43365. if (num2.number === 1) {
  43366. return num1;
  43367. } else // and it's 1
  43368. if (num1.type === 'literal') {
  43369. // ... and first operands is a literal too
  43370. return new AstLiteral(num1.number * num2.number);
  43371. }
  43372. }
  43373. if (num1.type === 'literal') {
  43374. // optimization: first operands is a literal...
  43375. if (num1.number === 0) {
  43376. return new AstLiteral(0);
  43377. } else // and it's 0
  43378. if (num1.number === 1) {
  43379. return num2;
  43380. }
  43381. }
  43382. // and it's 1
  43383. var min = Math.min(num1.min * num2.min, num1.min * num2.max, num1.max * num2.min, num1.max * num2.max);
  43384. var max = Math.max(num1.min * num2.min, num1.min * num2.max, num1.max * num2.min, num1.max * num2.max);
  43385. return new AstBinaryOperation('*', num1, num2, min, max);
  43386. }
  43387. function buildSubOperation(num1, num2) {
  43388. if (num2.type === 'literal') {
  43389. // optimization: second operands is a literal...
  43390. if (num2.number === 0) {
  43391. return num1;
  43392. } else // ... and it's 0
  43393. if (num1.type === 'literal') {
  43394. // ... and first operands is a literal too
  43395. return new AstLiteral(num1.number - num2.number);
  43396. }
  43397. }
  43398. if (num2.type === 'binary' && num2.op === '-' && num1.type === 'literal' && num1.number === 1 && num2.arg1.type === 'literal' && num2.arg1.number === 1) {
  43399. // optimization for case: 1 - (1 - x)
  43400. return num2.arg2;
  43401. }
  43402. return new AstBinaryOperation('-', num1, num2, num1.min - num2.max, num1.max - num2.min);
  43403. }
  43404. function buildMinOperation(num1, max) {
  43405. if (num1.min >= max) {
  43406. // optimization: num1 min value is not less than required max
  43407. return new AstLiteral(max);
  43408. } else // just returning max
  43409. if (num1.max <= max) {
  43410. // optimization: num1 max value is not greater than required max
  43411. return num1;
  43412. }
  43413. // just returning an argument
  43414. return new AstMin(num1, max);
  43415. }
  43416. function PostScriptCompiler() {
  43417. }
  43418. PostScriptCompiler.prototype = {
  43419. compile: function PostScriptCompiler_compile(code, domain, range) {
  43420. var stack = [];
  43421. var i, ii;
  43422. var instructions = [];
  43423. var inputSize = domain.length >> 1, outputSize = range.length >> 1;
  43424. var lastRegister = 0;
  43425. var n, j;
  43426. var num1, num2, ast1, ast2, tmpVar, item;
  43427. for (i = 0; i < inputSize; i++) {
  43428. stack.push(new AstArgument(i, domain[i * 2], domain[i * 2 + 1]));
  43429. }
  43430. for (i = 0, ii = code.length; i < ii; i++) {
  43431. item = code[i];
  43432. if (typeof item === 'number') {
  43433. stack.push(new AstLiteral(item));
  43434. continue;
  43435. }
  43436. switch (item) {
  43437. case 'add':
  43438. if (stack.length < 2) {
  43439. return null;
  43440. }
  43441. num2 = stack.pop();
  43442. num1 = stack.pop();
  43443. stack.push(buildAddOperation(num1, num2));
  43444. break;
  43445. case 'cvr':
  43446. if (stack.length < 1) {
  43447. return null;
  43448. }
  43449. break;
  43450. case 'mul':
  43451. if (stack.length < 2) {
  43452. return null;
  43453. }
  43454. num2 = stack.pop();
  43455. num1 = stack.pop();
  43456. stack.push(buildMulOperation(num1, num2));
  43457. break;
  43458. case 'sub':
  43459. if (stack.length < 2) {
  43460. return null;
  43461. }
  43462. num2 = stack.pop();
  43463. num1 = stack.pop();
  43464. stack.push(buildSubOperation(num1, num2));
  43465. break;
  43466. case 'exch':
  43467. if (stack.length < 2) {
  43468. return null;
  43469. }
  43470. ast1 = stack.pop();
  43471. ast2 = stack.pop();
  43472. stack.push(ast1, ast2);
  43473. break;
  43474. case 'pop':
  43475. if (stack.length < 1) {
  43476. return null;
  43477. }
  43478. stack.pop();
  43479. break;
  43480. case 'index':
  43481. if (stack.length < 1) {
  43482. return null;
  43483. }
  43484. num1 = stack.pop();
  43485. if (num1.type !== 'literal') {
  43486. return null;
  43487. }
  43488. n = num1.number;
  43489. if (n < 0 || (n | 0) !== n || stack.length < n) {
  43490. return null;
  43491. }
  43492. ast1 = stack[stack.length - n - 1];
  43493. if (ast1.type === 'literal' || ast1.type === 'var') {
  43494. stack.push(ast1);
  43495. break;
  43496. }
  43497. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  43498. stack[stack.length - n - 1] = tmpVar;
  43499. stack.push(tmpVar);
  43500. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  43501. break;
  43502. case 'dup':
  43503. if (stack.length < 1) {
  43504. return null;
  43505. }
  43506. 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]) {
  43507. // special case of the commands sequence for the min operation
  43508. num1 = stack.pop();
  43509. stack.push(buildMinOperation(num1, code[i + 1]));
  43510. i += 6;
  43511. break;
  43512. }
  43513. ast1 = stack[stack.length - 1];
  43514. if (ast1.type === 'literal' || ast1.type === 'var') {
  43515. // we don't have to save into intermediate variable a literal or
  43516. // variable.
  43517. stack.push(ast1);
  43518. break;
  43519. }
  43520. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  43521. stack[stack.length - 1] = tmpVar;
  43522. stack.push(tmpVar);
  43523. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  43524. break;
  43525. case 'roll':
  43526. if (stack.length < 2) {
  43527. return null;
  43528. }
  43529. num2 = stack.pop();
  43530. num1 = stack.pop();
  43531. if (num2.type !== 'literal' || num1.type !== 'literal') {
  43532. // both roll operands must be numbers
  43533. return null;
  43534. }
  43535. j = num2.number;
  43536. n = num1.number;
  43537. if (n <= 0 || (n | 0) !== n || (j | 0) !== j || stack.length < n) {
  43538. // ... and integers
  43539. return null;
  43540. }
  43541. j = (j % n + n) % n;
  43542. if (j === 0) {
  43543. break;
  43544. }
  43545. // just skipping -- there are nothing to rotate
  43546. Array.prototype.push.apply(stack, stack.splice(stack.length - n, n - j));
  43547. break;
  43548. default:
  43549. return null;
  43550. }
  43551. }
  43552. // unsupported operator
  43553. if (stack.length !== outputSize) {
  43554. return null;
  43555. }
  43556. var result = [];
  43557. instructions.forEach(function (instruction) {
  43558. var statementBuilder = new ExpressionBuilderVisitor();
  43559. instruction.visit(statementBuilder);
  43560. result.push(statementBuilder.toString());
  43561. });
  43562. stack.forEach(function (expr, i) {
  43563. var statementBuilder = new ExpressionBuilderVisitor();
  43564. expr.visit(statementBuilder);
  43565. var min = range[i * 2], max = range[i * 2 + 1];
  43566. var out = [statementBuilder.toString()];
  43567. if (min > expr.min) {
  43568. out.unshift('Math.max(', min, ', ');
  43569. out.push(')');
  43570. }
  43571. if (max < expr.max) {
  43572. out.unshift('Math.min(', max, ', ');
  43573. out.push(')');
  43574. }
  43575. out.unshift('dest[destOffset + ', i, '] = ');
  43576. out.push(';');
  43577. result.push(out.join(''));
  43578. });
  43579. return result.join('\n');
  43580. }
  43581. };
  43582. return PostScriptCompiler;
  43583. }();
  43584. exports.isPDFFunction = isPDFFunction;
  43585. exports.PDFFunction = PDFFunction;
  43586. exports.PostScriptEvaluator = PostScriptEvaluator;
  43587. exports.PostScriptCompiler = PostScriptCompiler;
  43588. }));
  43589. (function (root, factory) {
  43590. factory(root.pdfjsCoreColorSpace = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCoreFunction);
  43591. }(this, function (exports, sharedUtil, corePrimitives, coreFunction) {
  43592. var error = sharedUtil.error;
  43593. var info = sharedUtil.info;
  43594. var isArray = sharedUtil.isArray;
  43595. var isString = sharedUtil.isString;
  43596. var shadow = sharedUtil.shadow;
  43597. var warn = sharedUtil.warn;
  43598. var isDict = corePrimitives.isDict;
  43599. var isName = corePrimitives.isName;
  43600. var isStream = corePrimitives.isStream;
  43601. var PDFFunction = coreFunction.PDFFunction;
  43602. var ColorSpace = function ColorSpaceClosure() {
  43603. /**
  43604. * Resizes an RGB image with 3 components.
  43605. * @param {TypedArray} src - The source buffer.
  43606. * @param {Number} bpc - Number of bits per component.
  43607. * @param {Number} w1 - Original width.
  43608. * @param {Number} h1 - Original height.
  43609. * @param {Number} w2 - New width.
  43610. * @param {Number} h2 - New height.
  43611. * @param {Number} alpha01 - Size reserved for the alpha channel.
  43612. * @param {TypedArray} dest - The destination buffer.
  43613. */
  43614. function resizeRgbImage(src, bpc, w1, h1, w2, h2, alpha01, dest) {
  43615. var COMPONENTS = 3;
  43616. alpha01 = alpha01 !== 1 ? 0 : alpha01;
  43617. var xRatio = w1 / w2;
  43618. var yRatio = h1 / h2;
  43619. var i, j, py, newIndex = 0, oldIndex;
  43620. var xScaled = new Uint16Array(w2);
  43621. var w1Scanline = w1 * COMPONENTS;
  43622. for (i = 0; i < w2; i++) {
  43623. xScaled[i] = Math.floor(i * xRatio) * COMPONENTS;
  43624. }
  43625. for (i = 0; i < h2; i++) {
  43626. py = Math.floor(i * yRatio) * w1Scanline;
  43627. for (j = 0; j < w2; j++) {
  43628. oldIndex = py + xScaled[j];
  43629. dest[newIndex++] = src[oldIndex++];
  43630. dest[newIndex++] = src[oldIndex++];
  43631. dest[newIndex++] = src[oldIndex++];
  43632. newIndex += alpha01;
  43633. }
  43634. }
  43635. }
  43636. // Constructor should define this.numComps, this.defaultColor, this.name
  43637. function ColorSpace() {
  43638. error('should not call ColorSpace constructor');
  43639. }
  43640. ColorSpace.prototype = {
  43641. /**
  43642. * Converts the color value to the RGB color. The color components are
  43643. * located in the src array starting from the srcOffset. Returns the array
  43644. * of the rgb components, each value ranging from [0,255].
  43645. */
  43646. getRgb: function ColorSpace_getRgb(src, srcOffset) {
  43647. var rgb = new Uint8Array(3);
  43648. this.getRgbItem(src, srcOffset, rgb, 0);
  43649. return rgb;
  43650. },
  43651. /**
  43652. * Converts the color value to the RGB color, similar to the getRgb method.
  43653. * The result placed into the dest array starting from the destOffset.
  43654. */
  43655. getRgbItem: function ColorSpace_getRgbItem(src, srcOffset, dest, destOffset) {
  43656. error('Should not call ColorSpace.getRgbItem');
  43657. },
  43658. /**
  43659. * Converts the specified number of the color values to the RGB colors.
  43660. * The colors are located in the src array starting from the srcOffset.
  43661. * The result is placed into the dest array starting from the destOffset.
  43662. * The src array items shall be in [0,2^bits) range, the dest array items
  43663. * will be in [0,255] range. alpha01 indicates how many alpha components
  43664. * there are in the dest array; it will be either 0 (RGB array) or 1 (RGBA
  43665. * array).
  43666. */
  43667. getRgbBuffer: function ColorSpace_getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
  43668. error('Should not call ColorSpace.getRgbBuffer');
  43669. },
  43670. /**
  43671. * Determines the number of bytes required to store the result of the
  43672. * conversion done by the getRgbBuffer method. As in getRgbBuffer,
  43673. * |alpha01| is either 0 (RGB output) or 1 (RGBA output).
  43674. */
  43675. getOutputLength: function ColorSpace_getOutputLength(inputLength, alpha01) {
  43676. error('Should not call ColorSpace.getOutputLength');
  43677. },
  43678. /**
  43679. * Returns true if source data will be equal the result/output data.
  43680. */
  43681. isPassthrough: function ColorSpace_isPassthrough(bits) {
  43682. return false;
  43683. },
  43684. /**
  43685. * Fills in the RGB colors in the destination buffer. alpha01 indicates
  43686. * how many alpha components there are in the dest array; it will be either
  43687. * 0 (RGB array) or 1 (RGBA array).
  43688. */
  43689. fillRgb: function ColorSpace_fillRgb(dest, originalWidth, originalHeight, width, height, actualHeight, bpc, comps, alpha01) {
  43690. var count = originalWidth * originalHeight;
  43691. var rgbBuf = null;
  43692. var numComponentColors = 1 << bpc;
  43693. var needsResizing = originalHeight !== height || originalWidth !== width;
  43694. var i, ii;
  43695. if (this.isPassthrough(bpc)) {
  43696. rgbBuf = comps;
  43697. } else if (this.numComps === 1 && count > numComponentColors && this.name !== 'DeviceGray' && this.name !== 'DeviceRGB') {
  43698. // Optimization: create a color map when there is just one component and
  43699. // we are converting more colors than the size of the color map. We
  43700. // don't build the map if the colorspace is gray or rgb since those
  43701. // methods are faster than building a map. This mainly offers big speed
  43702. // ups for indexed and alternate colorspaces.
  43703. //
  43704. // TODO it may be worth while to cache the color map. While running
  43705. // testing I never hit a cache so I will leave that out for now (perhaps
  43706. // we are reparsing colorspaces too much?).
  43707. var allColors = bpc <= 8 ? new Uint8Array(numComponentColors) : new Uint16Array(numComponentColors);
  43708. var key;
  43709. for (i = 0; i < numComponentColors; i++) {
  43710. allColors[i] = i;
  43711. }
  43712. var colorMap = new Uint8Array(numComponentColors * 3);
  43713. this.getRgbBuffer(allColors, 0, numComponentColors, colorMap, 0, bpc, /* alpha01 = */
  43714. 0);
  43715. var destPos, rgbPos;
  43716. if (!needsResizing) {
  43717. // Fill in the RGB values directly into |dest|.
  43718. destPos = 0;
  43719. for (i = 0; i < count; ++i) {
  43720. key = comps[i] * 3;
  43721. dest[destPos++] = colorMap[key];
  43722. dest[destPos++] = colorMap[key + 1];
  43723. dest[destPos++] = colorMap[key + 2];
  43724. destPos += alpha01;
  43725. }
  43726. } else {
  43727. rgbBuf = new Uint8Array(count * 3);
  43728. rgbPos = 0;
  43729. for (i = 0; i < count; ++i) {
  43730. key = comps[i] * 3;
  43731. rgbBuf[rgbPos++] = colorMap[key];
  43732. rgbBuf[rgbPos++] = colorMap[key + 1];
  43733. rgbBuf[rgbPos++] = colorMap[key + 2];
  43734. }
  43735. }
  43736. } else {
  43737. if (!needsResizing) {
  43738. // Fill in the RGB values directly into |dest|.
  43739. this.getRgbBuffer(comps, 0, width * actualHeight, dest, 0, bpc, alpha01);
  43740. } else {
  43741. rgbBuf = new Uint8Array(count * 3);
  43742. this.getRgbBuffer(comps, 0, count, rgbBuf, 0, bpc, /* alpha01 = */
  43743. 0);
  43744. }
  43745. }
  43746. if (rgbBuf) {
  43747. if (needsResizing) {
  43748. resizeRgbImage(rgbBuf, bpc, originalWidth, originalHeight, width, height, alpha01, dest);
  43749. } else {
  43750. rgbPos = 0;
  43751. destPos = 0;
  43752. for (i = 0, ii = width * actualHeight; i < ii; i++) {
  43753. dest[destPos++] = rgbBuf[rgbPos++];
  43754. dest[destPos++] = rgbBuf[rgbPos++];
  43755. dest[destPos++] = rgbBuf[rgbPos++];
  43756. destPos += alpha01;
  43757. }
  43758. }
  43759. }
  43760. },
  43761. /**
  43762. * True if the colorspace has components in the default range of [0, 1].
  43763. * This should be true for all colorspaces except for lab color spaces
  43764. * which are [0,100], [-128, 127], [-128, 127].
  43765. */
  43766. usesZeroToOneRange: true
  43767. };
  43768. ColorSpace.parse = function ColorSpace_parse(cs, xref, res) {
  43769. var IR = ColorSpace.parseToIR(cs, xref, res);
  43770. if (IR instanceof AlternateCS) {
  43771. return IR;
  43772. }
  43773. return ColorSpace.fromIR(IR);
  43774. };
  43775. ColorSpace.fromIR = function ColorSpace_fromIR(IR) {
  43776. var name = isArray(IR) ? IR[0] : IR;
  43777. var whitePoint, blackPoint, gamma;
  43778. switch (name) {
  43779. case 'DeviceGrayCS':
  43780. return this.singletons.gray;
  43781. case 'DeviceRgbCS':
  43782. return this.singletons.rgb;
  43783. case 'DeviceCmykCS':
  43784. return this.singletons.cmyk;
  43785. case 'CalGrayCS':
  43786. whitePoint = IR[1];
  43787. blackPoint = IR[2];
  43788. gamma = IR[3];
  43789. return new CalGrayCS(whitePoint, blackPoint, gamma);
  43790. case 'CalRGBCS':
  43791. whitePoint = IR[1];
  43792. blackPoint = IR[2];
  43793. gamma = IR[3];
  43794. var matrix = IR[4];
  43795. return new CalRGBCS(whitePoint, blackPoint, gamma, matrix);
  43796. case 'PatternCS':
  43797. var basePatternCS = IR[1];
  43798. if (basePatternCS) {
  43799. basePatternCS = ColorSpace.fromIR(basePatternCS);
  43800. }
  43801. return new PatternCS(basePatternCS);
  43802. case 'IndexedCS':
  43803. var baseIndexedCS = IR[1];
  43804. var hiVal = IR[2];
  43805. var lookup = IR[3];
  43806. return new IndexedCS(ColorSpace.fromIR(baseIndexedCS), hiVal, lookup);
  43807. case 'AlternateCS':
  43808. var numComps = IR[1];
  43809. var alt = IR[2];
  43810. var tintFnIR = IR[3];
  43811. return new AlternateCS(numComps, ColorSpace.fromIR(alt), PDFFunction.fromIR(tintFnIR));
  43812. case 'LabCS':
  43813. whitePoint = IR[1];
  43814. blackPoint = IR[2];
  43815. var range = IR[3];
  43816. return new LabCS(whitePoint, blackPoint, range);
  43817. default:
  43818. error('Unknown name ' + name);
  43819. }
  43820. return null;
  43821. };
  43822. ColorSpace.parseToIR = function ColorSpace_parseToIR(cs, xref, res) {
  43823. if (isName(cs)) {
  43824. var colorSpaces = res.get('ColorSpace');
  43825. if (isDict(colorSpaces)) {
  43826. var refcs = colorSpaces.get(cs.name);
  43827. if (refcs) {
  43828. cs = refcs;
  43829. }
  43830. }
  43831. }
  43832. cs = xref.fetchIfRef(cs);
  43833. var mode;
  43834. if (isName(cs)) {
  43835. mode = cs.name;
  43836. this.mode = mode;
  43837. switch (mode) {
  43838. case 'DeviceGray':
  43839. case 'G':
  43840. return 'DeviceGrayCS';
  43841. case 'DeviceRGB':
  43842. case 'RGB':
  43843. return 'DeviceRgbCS';
  43844. case 'DeviceCMYK':
  43845. case 'CMYK':
  43846. return 'DeviceCmykCS';
  43847. case 'Pattern':
  43848. return [
  43849. 'PatternCS',
  43850. null
  43851. ];
  43852. default:
  43853. error('unrecognized colorspace ' + mode);
  43854. }
  43855. } else if (isArray(cs)) {
  43856. mode = xref.fetchIfRef(cs[0]).name;
  43857. this.mode = mode;
  43858. var numComps, params, alt, whitePoint, blackPoint, gamma;
  43859. switch (mode) {
  43860. case 'DeviceGray':
  43861. case 'G':
  43862. return 'DeviceGrayCS';
  43863. case 'DeviceRGB':
  43864. case 'RGB':
  43865. return 'DeviceRgbCS';
  43866. case 'DeviceCMYK':
  43867. case 'CMYK':
  43868. return 'DeviceCmykCS';
  43869. case 'CalGray':
  43870. params = xref.fetchIfRef(cs[1]);
  43871. whitePoint = params.getArray('WhitePoint');
  43872. blackPoint = params.getArray('BlackPoint');
  43873. gamma = params.get('Gamma');
  43874. return [
  43875. 'CalGrayCS',
  43876. whitePoint,
  43877. blackPoint,
  43878. gamma
  43879. ];
  43880. case 'CalRGB':
  43881. params = xref.fetchIfRef(cs[1]);
  43882. whitePoint = params.getArray('WhitePoint');
  43883. blackPoint = params.getArray('BlackPoint');
  43884. gamma = params.getArray('Gamma');
  43885. var matrix = params.getArray('Matrix');
  43886. return [
  43887. 'CalRGBCS',
  43888. whitePoint,
  43889. blackPoint,
  43890. gamma,
  43891. matrix
  43892. ];
  43893. case 'ICCBased':
  43894. var stream = xref.fetchIfRef(cs[1]);
  43895. var dict = stream.dict;
  43896. numComps = dict.get('N');
  43897. alt = dict.get('Alternate');
  43898. if (alt) {
  43899. var altIR = ColorSpace.parseToIR(alt, xref, res);
  43900. // Parse the /Alternate CS to ensure that the number of components
  43901. // are correct, and also (indirectly) that it is not a PatternCS.
  43902. var altCS = ColorSpace.fromIR(altIR);
  43903. if (altCS.numComps === numComps) {
  43904. return altIR;
  43905. }
  43906. warn('ICCBased color space: Ignoring incorrect /Alternate entry.');
  43907. }
  43908. if (numComps === 1) {
  43909. return 'DeviceGrayCS';
  43910. } else if (numComps === 3) {
  43911. return 'DeviceRgbCS';
  43912. } else if (numComps === 4) {
  43913. return 'DeviceCmykCS';
  43914. }
  43915. break;
  43916. case 'Pattern':
  43917. var basePatternCS = cs[1] || null;
  43918. if (basePatternCS) {
  43919. basePatternCS = ColorSpace.parseToIR(basePatternCS, xref, res);
  43920. }
  43921. return [
  43922. 'PatternCS',
  43923. basePatternCS
  43924. ];
  43925. case 'Indexed':
  43926. case 'I':
  43927. var baseIndexedCS = ColorSpace.parseToIR(cs[1], xref, res);
  43928. var hiVal = xref.fetchIfRef(cs[2]) + 1;
  43929. var lookup = xref.fetchIfRef(cs[3]);
  43930. if (isStream(lookup)) {
  43931. lookup = lookup.getBytes();
  43932. }
  43933. return [
  43934. 'IndexedCS',
  43935. baseIndexedCS,
  43936. hiVal,
  43937. lookup
  43938. ];
  43939. case 'Separation':
  43940. case 'DeviceN':
  43941. var name = xref.fetchIfRef(cs[1]);
  43942. numComps = 1;
  43943. if (isName(name)) {
  43944. numComps = 1;
  43945. } else if (isArray(name)) {
  43946. numComps = name.length;
  43947. }
  43948. alt = ColorSpace.parseToIR(cs[2], xref, res);
  43949. var tintFnIR = PDFFunction.getIR(xref, xref.fetchIfRef(cs[3]));
  43950. return [
  43951. 'AlternateCS',
  43952. numComps,
  43953. alt,
  43954. tintFnIR
  43955. ];
  43956. case 'Lab':
  43957. params = xref.fetchIfRef(cs[1]);
  43958. whitePoint = params.getArray('WhitePoint');
  43959. blackPoint = params.getArray('BlackPoint');
  43960. var range = params.getArray('Range');
  43961. return [
  43962. 'LabCS',
  43963. whitePoint,
  43964. blackPoint,
  43965. range
  43966. ];
  43967. default:
  43968. error('unimplemented color space object "' + mode + '"');
  43969. }
  43970. } else {
  43971. error('unrecognized color space object: "' + cs + '"');
  43972. }
  43973. return null;
  43974. };
  43975. /**
  43976. * Checks if a decode map matches the default decode map for a color space.
  43977. * This handles the general decode maps where there are two values per
  43978. * component. e.g. [0, 1, 0, 1, 0, 1] for a RGB color.
  43979. * This does not handle Lab, Indexed, or Pattern decode maps since they are
  43980. * slightly different.
  43981. * @param {Array} decode Decode map (usually from an image).
  43982. * @param {Number} n Number of components the color space has.
  43983. */
  43984. ColorSpace.isDefaultDecode = function ColorSpace_isDefaultDecode(decode, n) {
  43985. if (!isArray(decode)) {
  43986. return true;
  43987. }
  43988. if (n * 2 !== decode.length) {
  43989. warn('The decode map is not the correct length');
  43990. return true;
  43991. }
  43992. for (var i = 0, ii = decode.length; i < ii; i += 2) {
  43993. if (decode[i] !== 0 || decode[i + 1] !== 1) {
  43994. return false;
  43995. }
  43996. }
  43997. return true;
  43998. };
  43999. ColorSpace.singletons = {
  44000. get gray() {
  44001. return shadow(this, 'gray', new DeviceGrayCS());
  44002. },
  44003. get rgb() {
  44004. return shadow(this, 'rgb', new DeviceRgbCS());
  44005. },
  44006. get cmyk() {
  44007. return shadow(this, 'cmyk', new DeviceCmykCS());
  44008. }
  44009. };
  44010. return ColorSpace;
  44011. }();
  44012. /**
  44013. * Alternate color space handles both Separation and DeviceN color spaces. A
  44014. * Separation color space is actually just a DeviceN with one color component.
  44015. * Both color spaces use a tinting function to convert colors to a base color
  44016. * space.
  44017. */
  44018. var AlternateCS = function AlternateCSClosure() {
  44019. function AlternateCS(numComps, base, tintFn) {
  44020. this.name = 'Alternate';
  44021. this.numComps = numComps;
  44022. this.defaultColor = new Float32Array(numComps);
  44023. for (var i = 0; i < numComps; ++i) {
  44024. this.defaultColor[i] = 1;
  44025. }
  44026. this.base = base;
  44027. this.tintFn = tintFn;
  44028. this.tmpBuf = new Float32Array(base.numComps);
  44029. }
  44030. AlternateCS.prototype = {
  44031. getRgb: ColorSpace.prototype.getRgb,
  44032. getRgbItem: function AlternateCS_getRgbItem(src, srcOffset, dest, destOffset) {
  44033. var tmpBuf = this.tmpBuf;
  44034. this.tintFn(src, srcOffset, tmpBuf, 0);
  44035. this.base.getRgbItem(tmpBuf, 0, dest, destOffset);
  44036. },
  44037. getRgbBuffer: function AlternateCS_getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
  44038. var tintFn = this.tintFn;
  44039. var base = this.base;
  44040. var scale = 1 / ((1 << bits) - 1);
  44041. var baseNumComps = base.numComps;
  44042. var usesZeroToOneRange = base.usesZeroToOneRange;
  44043. var isPassthrough = (base.isPassthrough(8) || !usesZeroToOneRange) && alpha01 === 0;
  44044. var pos = isPassthrough ? destOffset : 0;
  44045. var baseBuf = isPassthrough ? dest : new Uint8Array(baseNumComps * count);
  44046. var numComps = this.numComps;
  44047. var scaled = new Float32Array(numComps);
  44048. var tinted = new Float32Array(baseNumComps);
  44049. var i, j;
  44050. if (usesZeroToOneRange) {
  44051. for (i = 0; i < count; i++) {
  44052. for (j = 0; j < numComps; j++) {
  44053. scaled[j] = src[srcOffset++] * scale;
  44054. }
  44055. tintFn(scaled, 0, tinted, 0);
  44056. for (j = 0; j < baseNumComps; j++) {
  44057. baseBuf[pos++] = tinted[j] * 255;
  44058. }
  44059. }
  44060. } else {
  44061. for (i = 0; i < count; i++) {
  44062. for (j = 0; j < numComps; j++) {
  44063. scaled[j] = src[srcOffset++] * scale;
  44064. }
  44065. tintFn(scaled, 0, tinted, 0);
  44066. base.getRgbItem(tinted, 0, baseBuf, pos);
  44067. pos += baseNumComps;
  44068. }
  44069. }
  44070. if (!isPassthrough) {
  44071. base.getRgbBuffer(baseBuf, 0, count, dest, destOffset, 8, alpha01);
  44072. }
  44073. },
  44074. getOutputLength: function AlternateCS_getOutputLength(inputLength, alpha01) {
  44075. return this.base.getOutputLength(inputLength * this.base.numComps / this.numComps, alpha01);
  44076. },
  44077. isPassthrough: ColorSpace.prototype.isPassthrough,
  44078. fillRgb: ColorSpace.prototype.fillRgb,
  44079. isDefaultDecode: function AlternateCS_isDefaultDecode(decodeMap) {
  44080. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  44081. },
  44082. usesZeroToOneRange: true
  44083. };
  44084. return AlternateCS;
  44085. }();
  44086. var PatternCS = function PatternCSClosure() {
  44087. function PatternCS(baseCS) {
  44088. this.name = 'Pattern';
  44089. this.base = baseCS;
  44090. }
  44091. PatternCS.prototype = {};
  44092. return PatternCS;
  44093. }();
  44094. var IndexedCS = function IndexedCSClosure() {
  44095. function IndexedCS(base, highVal, lookup) {
  44096. this.name = 'Indexed';
  44097. this.numComps = 1;
  44098. this.defaultColor = new Uint8Array([0]);
  44099. this.base = base;
  44100. this.highVal = highVal;
  44101. var baseNumComps = base.numComps;
  44102. var length = baseNumComps * highVal;
  44103. var lookupArray;
  44104. if (isStream(lookup)) {
  44105. lookupArray = new Uint8Array(length);
  44106. var bytes = lookup.getBytes(length);
  44107. lookupArray.set(bytes);
  44108. } else if (isString(lookup)) {
  44109. lookupArray = new Uint8Array(length);
  44110. for (var i = 0; i < length; ++i) {
  44111. lookupArray[i] = lookup.charCodeAt(i);
  44112. }
  44113. } else if (lookup instanceof Uint8Array || lookup instanceof Array) {
  44114. lookupArray = lookup;
  44115. } else {
  44116. error('Unrecognized lookup table: ' + lookup);
  44117. }
  44118. this.lookup = lookupArray;
  44119. }
  44120. IndexedCS.prototype = {
  44121. getRgb: ColorSpace.prototype.getRgb,
  44122. getRgbItem: function IndexedCS_getRgbItem(src, srcOffset, dest, destOffset) {
  44123. var numComps = this.base.numComps;
  44124. var start = src[srcOffset] * numComps;
  44125. this.base.getRgbItem(this.lookup, start, dest, destOffset);
  44126. },
  44127. getRgbBuffer: function IndexedCS_getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
  44128. var base = this.base;
  44129. var numComps = base.numComps;
  44130. var outputDelta = base.getOutputLength(numComps, alpha01);
  44131. var lookup = this.lookup;
  44132. for (var i = 0; i < count; ++i) {
  44133. var lookupPos = src[srcOffset++] * numComps;
  44134. base.getRgbBuffer(lookup, lookupPos, 1, dest, destOffset, 8, alpha01);
  44135. destOffset += outputDelta;
  44136. }
  44137. },
  44138. getOutputLength: function IndexedCS_getOutputLength(inputLength, alpha01) {
  44139. return this.base.getOutputLength(inputLength * this.base.numComps, alpha01);
  44140. },
  44141. isPassthrough: ColorSpace.prototype.isPassthrough,
  44142. fillRgb: ColorSpace.prototype.fillRgb,
  44143. isDefaultDecode: function IndexedCS_isDefaultDecode(decodeMap) {
  44144. // indexed color maps shouldn't be changed
  44145. return true;
  44146. },
  44147. usesZeroToOneRange: true
  44148. };
  44149. return IndexedCS;
  44150. }();
  44151. var DeviceGrayCS = function DeviceGrayCSClosure() {
  44152. function DeviceGrayCS() {
  44153. this.name = 'DeviceGray';
  44154. this.numComps = 1;
  44155. this.defaultColor = new Float32Array([0]);
  44156. }
  44157. DeviceGrayCS.prototype = {
  44158. getRgb: ColorSpace.prototype.getRgb,
  44159. getRgbItem: function DeviceGrayCS_getRgbItem(src, srcOffset, dest, destOffset) {
  44160. var c = src[srcOffset] * 255 | 0;
  44161. c = c < 0 ? 0 : c > 255 ? 255 : c;
  44162. dest[destOffset] = dest[destOffset + 1] = dest[destOffset + 2] = c;
  44163. },
  44164. getRgbBuffer: function DeviceGrayCS_getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
  44165. var scale = 255 / ((1 << bits) - 1);
  44166. var j = srcOffset, q = destOffset;
  44167. for (var i = 0; i < count; ++i) {
  44168. var c = scale * src[j++] | 0;
  44169. dest[q++] = c;
  44170. dest[q++] = c;
  44171. dest[q++] = c;
  44172. q += alpha01;
  44173. }
  44174. },
  44175. getOutputLength: function DeviceGrayCS_getOutputLength(inputLength, alpha01) {
  44176. return inputLength * (3 + alpha01);
  44177. },
  44178. isPassthrough: ColorSpace.prototype.isPassthrough,
  44179. fillRgb: ColorSpace.prototype.fillRgb,
  44180. isDefaultDecode: function DeviceGrayCS_isDefaultDecode(decodeMap) {
  44181. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  44182. },
  44183. usesZeroToOneRange: true
  44184. };
  44185. return DeviceGrayCS;
  44186. }();
  44187. var DeviceRgbCS = function DeviceRgbCSClosure() {
  44188. function DeviceRgbCS() {
  44189. this.name = 'DeviceRGB';
  44190. this.numComps = 3;
  44191. this.defaultColor = new Float32Array([
  44192. 0,
  44193. 0,
  44194. 0
  44195. ]);
  44196. }
  44197. DeviceRgbCS.prototype = {
  44198. getRgb: ColorSpace.prototype.getRgb,
  44199. getRgbItem: function DeviceRgbCS_getRgbItem(src, srcOffset, dest, destOffset) {
  44200. var r = src[srcOffset] * 255 | 0;
  44201. var g = src[srcOffset + 1] * 255 | 0;
  44202. var b = src[srcOffset + 2] * 255 | 0;
  44203. dest[destOffset] = r < 0 ? 0 : r > 255 ? 255 : r;
  44204. dest[destOffset + 1] = g < 0 ? 0 : g > 255 ? 255 : g;
  44205. dest[destOffset + 2] = b < 0 ? 0 : b > 255 ? 255 : b;
  44206. },
  44207. getRgbBuffer: function DeviceRgbCS_getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
  44208. if (bits === 8 && alpha01 === 0) {
  44209. dest.set(src.subarray(srcOffset, srcOffset + count * 3), destOffset);
  44210. return;
  44211. }
  44212. var scale = 255 / ((1 << bits) - 1);
  44213. var j = srcOffset, q = destOffset;
  44214. for (var i = 0; i < count; ++i) {
  44215. dest[q++] = scale * src[j++] | 0;
  44216. dest[q++] = scale * src[j++] | 0;
  44217. dest[q++] = scale * src[j++] | 0;
  44218. q += alpha01;
  44219. }
  44220. },
  44221. getOutputLength: function DeviceRgbCS_getOutputLength(inputLength, alpha01) {
  44222. return inputLength * (3 + alpha01) / 3 | 0;
  44223. },
  44224. isPassthrough: function DeviceRgbCS_isPassthrough(bits) {
  44225. return bits === 8;
  44226. },
  44227. fillRgb: ColorSpace.prototype.fillRgb,
  44228. isDefaultDecode: function DeviceRgbCS_isDefaultDecode(decodeMap) {
  44229. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  44230. },
  44231. usesZeroToOneRange: true
  44232. };
  44233. return DeviceRgbCS;
  44234. }();
  44235. var DeviceCmykCS = function DeviceCmykCSClosure() {
  44236. // The coefficients below was found using numerical analysis: the method of
  44237. // steepest descent for the sum((f_i - color_value_i)^2) for r/g/b colors,
  44238. // where color_value is the tabular value from the table of sampled RGB colors
  44239. // from CMYK US Web Coated (SWOP) colorspace, and f_i is the corresponding
  44240. // CMYK color conversion using the estimation below:
  44241. // f(A, B,.. N) = Acc+Bcm+Ccy+Dck+c+Fmm+Gmy+Hmk+Im+Jyy+Kyk+Ly+Mkk+Nk+255
  44242. function convertToRgb(src, srcOffset, srcScale, dest, destOffset) {
  44243. var c = src[srcOffset + 0] * srcScale;
  44244. var m = src[srcOffset + 1] * srcScale;
  44245. var y = src[srcOffset + 2] * srcScale;
  44246. var k = src[srcOffset + 3] * srcScale;
  44247. 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;
  44248. 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;
  44249. 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;
  44250. dest[destOffset] = r > 255 ? 255 : r < 0 ? 0 : r;
  44251. dest[destOffset + 1] = g > 255 ? 255 : g < 0 ? 0 : g;
  44252. dest[destOffset + 2] = b > 255 ? 255 : b < 0 ? 0 : b;
  44253. }
  44254. function DeviceCmykCS() {
  44255. this.name = 'DeviceCMYK';
  44256. this.numComps = 4;
  44257. this.defaultColor = new Float32Array([
  44258. 0,
  44259. 0,
  44260. 0,
  44261. 1
  44262. ]);
  44263. }
  44264. DeviceCmykCS.prototype = {
  44265. getRgb: ColorSpace.prototype.getRgb,
  44266. getRgbItem: function DeviceCmykCS_getRgbItem(src, srcOffset, dest, destOffset) {
  44267. convertToRgb(src, srcOffset, 1, dest, destOffset);
  44268. },
  44269. getRgbBuffer: function DeviceCmykCS_getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
  44270. var scale = 1 / ((1 << bits) - 1);
  44271. for (var i = 0; i < count; i++) {
  44272. convertToRgb(src, srcOffset, scale, dest, destOffset);
  44273. srcOffset += 4;
  44274. destOffset += 3 + alpha01;
  44275. }
  44276. },
  44277. getOutputLength: function DeviceCmykCS_getOutputLength(inputLength, alpha01) {
  44278. return inputLength / 4 * (3 + alpha01) | 0;
  44279. },
  44280. isPassthrough: ColorSpace.prototype.isPassthrough,
  44281. fillRgb: ColorSpace.prototype.fillRgb,
  44282. isDefaultDecode: function DeviceCmykCS_isDefaultDecode(decodeMap) {
  44283. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  44284. },
  44285. usesZeroToOneRange: true
  44286. };
  44287. return DeviceCmykCS;
  44288. }();
  44289. //
  44290. // CalGrayCS: Based on "PDF Reference, Sixth Ed", p.245
  44291. //
  44292. var CalGrayCS = function CalGrayCSClosure() {
  44293. function CalGrayCS(whitePoint, blackPoint, gamma) {
  44294. this.name = 'CalGray';
  44295. this.numComps = 1;
  44296. this.defaultColor = new Float32Array([0]);
  44297. if (!whitePoint) {
  44298. error('WhitePoint missing - required for color space CalGray');
  44299. }
  44300. blackPoint = blackPoint || [
  44301. 0,
  44302. 0,
  44303. 0
  44304. ];
  44305. gamma = gamma || 1;
  44306. // Translate arguments to spec variables.
  44307. this.XW = whitePoint[0];
  44308. this.YW = whitePoint[1];
  44309. this.ZW = whitePoint[2];
  44310. this.XB = blackPoint[0];
  44311. this.YB = blackPoint[1];
  44312. this.ZB = blackPoint[2];
  44313. this.G = gamma;
  44314. // Validate variables as per spec.
  44315. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  44316. error('Invalid WhitePoint components for ' + this.name + ', no fallback available');
  44317. }
  44318. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  44319. info('Invalid BlackPoint for ' + this.name + ', falling back to default');
  44320. this.XB = this.YB = this.ZB = 0;
  44321. }
  44322. if (this.XB !== 0 || this.YB !== 0 || this.ZB !== 0) {
  44323. warn(this.name + ', BlackPoint: XB: ' + this.XB + ', YB: ' + this.YB + ', ZB: ' + this.ZB + ', only default values are supported.');
  44324. }
  44325. if (this.G < 1) {
  44326. info('Invalid Gamma: ' + this.G + ' for ' + this.name + ', falling back to default');
  44327. this.G = 1;
  44328. }
  44329. }
  44330. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  44331. // A represents a gray component of a calibrated gray space.
  44332. // A <---> AG in the spec
  44333. var A = src[srcOffset] * scale;
  44334. var AG = Math.pow(A, cs.G);
  44335. // Computes L as per spec. ( = cs.YW * AG )
  44336. // Except if other than default BlackPoint values are used.
  44337. var L = cs.YW * AG;
  44338. // http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html, Ch 4.
  44339. // Convert values to rgb range [0, 255].
  44340. var val = Math.max(295.8 * Math.pow(L, 0.333333333333333333) - 40.8, 0) | 0;
  44341. dest[destOffset] = val;
  44342. dest[destOffset + 1] = val;
  44343. dest[destOffset + 2] = val;
  44344. }
  44345. CalGrayCS.prototype = {
  44346. getRgb: ColorSpace.prototype.getRgb,
  44347. getRgbItem: function CalGrayCS_getRgbItem(src, srcOffset, dest, destOffset) {
  44348. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  44349. },
  44350. getRgbBuffer: function CalGrayCS_getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
  44351. var scale = 1 / ((1 << bits) - 1);
  44352. for (var i = 0; i < count; ++i) {
  44353. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  44354. srcOffset += 1;
  44355. destOffset += 3 + alpha01;
  44356. }
  44357. },
  44358. getOutputLength: function CalGrayCS_getOutputLength(inputLength, alpha01) {
  44359. return inputLength * (3 + alpha01);
  44360. },
  44361. isPassthrough: ColorSpace.prototype.isPassthrough,
  44362. fillRgb: ColorSpace.prototype.fillRgb,
  44363. isDefaultDecode: function CalGrayCS_isDefaultDecode(decodeMap) {
  44364. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  44365. },
  44366. usesZeroToOneRange: true
  44367. };
  44368. return CalGrayCS;
  44369. }();
  44370. //
  44371. // CalRGBCS: Based on "PDF Reference, Sixth Ed", p.247
  44372. //
  44373. var CalRGBCS = function CalRGBCSClosure() {
  44374. // See http://www.brucelindbloom.com/index.html?Eqn_ChromAdapt.html for these
  44375. // matrices.
  44376. var BRADFORD_SCALE_MATRIX = new Float32Array([
  44377. 0.8951,
  44378. 0.2664,
  44379. -0.1614,
  44380. -0.7502,
  44381. 1.7135,
  44382. 0.0367,
  44383. 0.0389,
  44384. -0.0685,
  44385. 1.0296
  44386. ]);
  44387. var BRADFORD_SCALE_INVERSE_MATRIX = new Float32Array([
  44388. 0.9869929,
  44389. -0.1470543,
  44390. 0.1599627,
  44391. 0.4323053,
  44392. 0.5183603,
  44393. 0.0492912,
  44394. -0.0085287,
  44395. 0.0400428,
  44396. 0.9684867
  44397. ]);
  44398. // See http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html.
  44399. var SRGB_D65_XYZ_TO_RGB_MATRIX = new Float32Array([
  44400. 3.2404542,
  44401. -1.5371385,
  44402. -0.4985314,
  44403. -0.9692660,
  44404. 1.8760108,
  44405. 0.0415560,
  44406. 0.0556434,
  44407. -0.2040259,
  44408. 1.0572252
  44409. ]);
  44410. var FLAT_WHITEPOINT_MATRIX = new Float32Array([
  44411. 1,
  44412. 1,
  44413. 1
  44414. ]);
  44415. var tempNormalizeMatrix = new Float32Array(3);
  44416. var tempConvertMatrix1 = new Float32Array(3);
  44417. var tempConvertMatrix2 = new Float32Array(3);
  44418. var DECODE_L_CONSTANT = Math.pow((8 + 16) / 116, 3) / 8.0;
  44419. function CalRGBCS(whitePoint, blackPoint, gamma, matrix) {
  44420. this.name = 'CalRGB';
  44421. this.numComps = 3;
  44422. this.defaultColor = new Float32Array(3);
  44423. if (!whitePoint) {
  44424. error('WhitePoint missing - required for color space CalRGB');
  44425. }
  44426. blackPoint = blackPoint || new Float32Array(3);
  44427. gamma = gamma || new Float32Array([
  44428. 1,
  44429. 1,
  44430. 1
  44431. ]);
  44432. matrix = matrix || new Float32Array([
  44433. 1,
  44434. 0,
  44435. 0,
  44436. 0,
  44437. 1,
  44438. 0,
  44439. 0,
  44440. 0,
  44441. 1
  44442. ]);
  44443. // Translate arguments to spec variables.
  44444. var XW = whitePoint[0];
  44445. var YW = whitePoint[1];
  44446. var ZW = whitePoint[2];
  44447. this.whitePoint = whitePoint;
  44448. var XB = blackPoint[0];
  44449. var YB = blackPoint[1];
  44450. var ZB = blackPoint[2];
  44451. this.blackPoint = blackPoint;
  44452. this.GR = gamma[0];
  44453. this.GG = gamma[1];
  44454. this.GB = gamma[2];
  44455. this.MXA = matrix[0];
  44456. this.MYA = matrix[1];
  44457. this.MZA = matrix[2];
  44458. this.MXB = matrix[3];
  44459. this.MYB = matrix[4];
  44460. this.MZB = matrix[5];
  44461. this.MXC = matrix[6];
  44462. this.MYC = matrix[7];
  44463. this.MZC = matrix[8];
  44464. // Validate variables as per spec.
  44465. if (XW < 0 || ZW < 0 || YW !== 1) {
  44466. error('Invalid WhitePoint components for ' + this.name + ', no fallback available');
  44467. }
  44468. if (XB < 0 || YB < 0 || ZB < 0) {
  44469. info('Invalid BlackPoint for ' + this.name + ' [' + XB + ', ' + YB + ', ' + ZB + '], falling back to default');
  44470. this.blackPoint = new Float32Array(3);
  44471. }
  44472. if (this.GR < 0 || this.GG < 0 || this.GB < 0) {
  44473. info('Invalid Gamma [' + this.GR + ', ' + this.GG + ', ' + this.GB + '] for ' + this.name + ', falling back to default');
  44474. this.GR = this.GG = this.GB = 1;
  44475. }
  44476. 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) {
  44477. 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');
  44478. this.MXA = this.MYB = this.MZC = 1;
  44479. this.MXB = this.MYA = this.MZA = this.MXC = this.MYC = this.MZB = 0;
  44480. }
  44481. }
  44482. function matrixProduct(a, b, result) {
  44483. result[0] = a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
  44484. result[1] = a[3] * b[0] + a[4] * b[1] + a[5] * b[2];
  44485. result[2] = a[6] * b[0] + a[7] * b[1] + a[8] * b[2];
  44486. }
  44487. function convertToFlat(sourceWhitePoint, LMS, result) {
  44488. result[0] = LMS[0] * 1 / sourceWhitePoint[0];
  44489. result[1] = LMS[1] * 1 / sourceWhitePoint[1];
  44490. result[2] = LMS[2] * 1 / sourceWhitePoint[2];
  44491. }
  44492. function convertToD65(sourceWhitePoint, LMS, result) {
  44493. var D65X = 0.95047;
  44494. var D65Y = 1;
  44495. var D65Z = 1.08883;
  44496. result[0] = LMS[0] * D65X / sourceWhitePoint[0];
  44497. result[1] = LMS[1] * D65Y / sourceWhitePoint[1];
  44498. result[2] = LMS[2] * D65Z / sourceWhitePoint[2];
  44499. }
  44500. function sRGBTransferFunction(color) {
  44501. // See http://en.wikipedia.org/wiki/SRGB.
  44502. if (color <= 0.0031308) {
  44503. return adjustToRange(0, 1, 12.92 * color);
  44504. }
  44505. return adjustToRange(0, 1, (1 + 0.055) * Math.pow(color, 1 / 2.4) - 0.055);
  44506. }
  44507. function adjustToRange(min, max, value) {
  44508. return Math.max(min, Math.min(max, value));
  44509. }
  44510. function decodeL(L) {
  44511. if (L < 0) {
  44512. return -decodeL(-L);
  44513. }
  44514. if (L > 8.0) {
  44515. return Math.pow((L + 16) / 116, 3);
  44516. }
  44517. return L * DECODE_L_CONSTANT;
  44518. }
  44519. function compensateBlackPoint(sourceBlackPoint, XYZ_Flat, result) {
  44520. // In case the blackPoint is already the default blackPoint then there is
  44521. // no need to do compensation.
  44522. if (sourceBlackPoint[0] === 0 && sourceBlackPoint[1] === 0 && sourceBlackPoint[2] === 0) {
  44523. result[0] = XYZ_Flat[0];
  44524. result[1] = XYZ_Flat[1];
  44525. result[2] = XYZ_Flat[2];
  44526. return;
  44527. }
  44528. // For the blackPoint calculation details, please see
  44529. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  44530. // AdobeBPC.pdf.
  44531. // The destination blackPoint is the default blackPoint [0, 0, 0].
  44532. var zeroDecodeL = decodeL(0);
  44533. var X_DST = zeroDecodeL;
  44534. var X_SRC = decodeL(sourceBlackPoint[0]);
  44535. var Y_DST = zeroDecodeL;
  44536. var Y_SRC = decodeL(sourceBlackPoint[1]);
  44537. var Z_DST = zeroDecodeL;
  44538. var Z_SRC = decodeL(sourceBlackPoint[2]);
  44539. var X_Scale = (1 - X_DST) / (1 - X_SRC);
  44540. var X_Offset = 1 - X_Scale;
  44541. var Y_Scale = (1 - Y_DST) / (1 - Y_SRC);
  44542. var Y_Offset = 1 - Y_Scale;
  44543. var Z_Scale = (1 - Z_DST) / (1 - Z_SRC);
  44544. var Z_Offset = 1 - Z_Scale;
  44545. result[0] = XYZ_Flat[0] * X_Scale + X_Offset;
  44546. result[1] = XYZ_Flat[1] * Y_Scale + Y_Offset;
  44547. result[2] = XYZ_Flat[2] * Z_Scale + Z_Offset;
  44548. }
  44549. function normalizeWhitePointToFlat(sourceWhitePoint, XYZ_In, result) {
  44550. // In case the whitePoint is already flat then there is no need to do
  44551. // normalization.
  44552. if (sourceWhitePoint[0] === 1 && sourceWhitePoint[2] === 1) {
  44553. result[0] = XYZ_In[0];
  44554. result[1] = XYZ_In[1];
  44555. result[2] = XYZ_In[2];
  44556. return;
  44557. }
  44558. var LMS = result;
  44559. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  44560. var LMS_Flat = tempNormalizeMatrix;
  44561. convertToFlat(sourceWhitePoint, LMS, LMS_Flat);
  44562. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_Flat, result);
  44563. }
  44564. function normalizeWhitePointToD65(sourceWhitePoint, XYZ_In, result) {
  44565. var LMS = result;
  44566. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  44567. var LMS_D65 = tempNormalizeMatrix;
  44568. convertToD65(sourceWhitePoint, LMS, LMS_D65);
  44569. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_D65, result);
  44570. }
  44571. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  44572. // A, B and C represent a red, green and blue components of a calibrated
  44573. // rgb space.
  44574. var A = adjustToRange(0, 1, src[srcOffset] * scale);
  44575. var B = adjustToRange(0, 1, src[srcOffset + 1] * scale);
  44576. var C = adjustToRange(0, 1, src[srcOffset + 2] * scale);
  44577. // A <---> AGR in the spec
  44578. // B <---> BGG in the spec
  44579. // C <---> CGB in the spec
  44580. var AGR = Math.pow(A, cs.GR);
  44581. var BGG = Math.pow(B, cs.GG);
  44582. var CGB = Math.pow(C, cs.GB);
  44583. // Computes intermediate variables L, M, N as per spec.
  44584. // To decode X, Y, Z values map L, M, N directly to them.
  44585. var X = cs.MXA * AGR + cs.MXB * BGG + cs.MXC * CGB;
  44586. var Y = cs.MYA * AGR + cs.MYB * BGG + cs.MYC * CGB;
  44587. var Z = cs.MZA * AGR + cs.MZB * BGG + cs.MZC * CGB;
  44588. // The following calculations are based on this document:
  44589. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  44590. // AdobeBPC.pdf.
  44591. var XYZ = tempConvertMatrix1;
  44592. XYZ[0] = X;
  44593. XYZ[1] = Y;
  44594. XYZ[2] = Z;
  44595. var XYZ_Flat = tempConvertMatrix2;
  44596. normalizeWhitePointToFlat(cs.whitePoint, XYZ, XYZ_Flat);
  44597. var XYZ_Black = tempConvertMatrix1;
  44598. compensateBlackPoint(cs.blackPoint, XYZ_Flat, XYZ_Black);
  44599. var XYZ_D65 = tempConvertMatrix2;
  44600. normalizeWhitePointToD65(FLAT_WHITEPOINT_MATRIX, XYZ_Black, XYZ_D65);
  44601. var SRGB = tempConvertMatrix1;
  44602. matrixProduct(SRGB_D65_XYZ_TO_RGB_MATRIX, XYZ_D65, SRGB);
  44603. var sR = sRGBTransferFunction(SRGB[0]);
  44604. var sG = sRGBTransferFunction(SRGB[1]);
  44605. var sB = sRGBTransferFunction(SRGB[2]);
  44606. // Convert the values to rgb range [0, 255].
  44607. dest[destOffset] = Math.round(sR * 255);
  44608. dest[destOffset + 1] = Math.round(sG * 255);
  44609. dest[destOffset + 2] = Math.round(sB * 255);
  44610. }
  44611. CalRGBCS.prototype = {
  44612. getRgb: function CalRGBCS_getRgb(src, srcOffset) {
  44613. var rgb = new Uint8Array(3);
  44614. this.getRgbItem(src, srcOffset, rgb, 0);
  44615. return rgb;
  44616. },
  44617. getRgbItem: function CalRGBCS_getRgbItem(src, srcOffset, dest, destOffset) {
  44618. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  44619. },
  44620. getRgbBuffer: function CalRGBCS_getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
  44621. var scale = 1 / ((1 << bits) - 1);
  44622. for (var i = 0; i < count; ++i) {
  44623. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  44624. srcOffset += 3;
  44625. destOffset += 3 + alpha01;
  44626. }
  44627. },
  44628. getOutputLength: function CalRGBCS_getOutputLength(inputLength, alpha01) {
  44629. return inputLength * (3 + alpha01) / 3 | 0;
  44630. },
  44631. isPassthrough: ColorSpace.prototype.isPassthrough,
  44632. fillRgb: ColorSpace.prototype.fillRgb,
  44633. isDefaultDecode: function CalRGBCS_isDefaultDecode(decodeMap) {
  44634. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  44635. },
  44636. usesZeroToOneRange: true
  44637. };
  44638. return CalRGBCS;
  44639. }();
  44640. //
  44641. // LabCS: Based on "PDF Reference, Sixth Ed", p.250
  44642. //
  44643. var LabCS = function LabCSClosure() {
  44644. function LabCS(whitePoint, blackPoint, range) {
  44645. this.name = 'Lab';
  44646. this.numComps = 3;
  44647. this.defaultColor = new Float32Array([
  44648. 0,
  44649. 0,
  44650. 0
  44651. ]);
  44652. if (!whitePoint) {
  44653. error('WhitePoint missing - required for color space Lab');
  44654. }
  44655. blackPoint = blackPoint || [
  44656. 0,
  44657. 0,
  44658. 0
  44659. ];
  44660. range = range || [
  44661. -100,
  44662. 100,
  44663. -100,
  44664. 100
  44665. ];
  44666. // Translate args to spec variables
  44667. this.XW = whitePoint[0];
  44668. this.YW = whitePoint[1];
  44669. this.ZW = whitePoint[2];
  44670. this.amin = range[0];
  44671. this.amax = range[1];
  44672. this.bmin = range[2];
  44673. this.bmax = range[3];
  44674. // These are here just for completeness - the spec doesn't offer any
  44675. // formulas that use BlackPoint in Lab
  44676. this.XB = blackPoint[0];
  44677. this.YB = blackPoint[1];
  44678. this.ZB = blackPoint[2];
  44679. // Validate vars as per spec
  44680. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  44681. error('Invalid WhitePoint components, no fallback available');
  44682. }
  44683. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  44684. info('Invalid BlackPoint, falling back to default');
  44685. this.XB = this.YB = this.ZB = 0;
  44686. }
  44687. if (this.amin > this.amax || this.bmin > this.bmax) {
  44688. info('Invalid Range, falling back to defaults');
  44689. this.amin = -100;
  44690. this.amax = 100;
  44691. this.bmin = -100;
  44692. this.bmax = 100;
  44693. }
  44694. }
  44695. // Function g(x) from spec
  44696. function fn_g(x) {
  44697. if (x >= 6 / 29) {
  44698. return x * x * x;
  44699. } else {
  44700. return 108 / 841 * (x - 4 / 29);
  44701. }
  44702. }
  44703. function decode(value, high1, low2, high2) {
  44704. return low2 + value * (high2 - low2) / high1;
  44705. }
  44706. // If decoding is needed maxVal should be 2^bits per component - 1.
  44707. function convertToRgb(cs, src, srcOffset, maxVal, dest, destOffset) {
  44708. // XXX: Lab input is in the range of [0, 100], [amin, amax], [bmin, bmax]
  44709. // not the usual [0, 1]. If a command like setFillColor is used the src
  44710. // values will already be within the correct range. However, if we are
  44711. // converting an image we have to map the values to the correct range given
  44712. // above.
  44713. // Ls,as,bs <---> L*,a*,b* in the spec
  44714. var Ls = src[srcOffset];
  44715. var as = src[srcOffset + 1];
  44716. var bs = src[srcOffset + 2];
  44717. if (maxVal !== false) {
  44718. Ls = decode(Ls, maxVal, 0, 100);
  44719. as = decode(as, maxVal, cs.amin, cs.amax);
  44720. bs = decode(bs, maxVal, cs.bmin, cs.bmax);
  44721. }
  44722. // Adjust limits of 'as' and 'bs'
  44723. as = as > cs.amax ? cs.amax : as < cs.amin ? cs.amin : as;
  44724. bs = bs > cs.bmax ? cs.bmax : bs < cs.bmin ? cs.bmin : bs;
  44725. // Computes intermediate variables X,Y,Z as per spec
  44726. var M = (Ls + 16) / 116;
  44727. var L = M + as / 500;
  44728. var N = M - bs / 200;
  44729. var X = cs.XW * fn_g(L);
  44730. var Y = cs.YW * fn_g(M);
  44731. var Z = cs.ZW * fn_g(N);
  44732. var r, g, b;
  44733. // Using different conversions for D50 and D65 white points,
  44734. // per http://www.color.org/srgb.pdf
  44735. if (cs.ZW < 1) {
  44736. // Assuming D50 (X=0.9642, Y=1.00, Z=0.8249)
  44737. r = X * 3.1339 + Y * -1.6170 + Z * -0.4906;
  44738. g = X * -0.9785 + Y * 1.9160 + Z * 0.0333;
  44739. b = X * 0.0720 + Y * -0.2290 + Z * 1.4057;
  44740. } else {
  44741. // Assuming D65 (X=0.9505, Y=1.00, Z=1.0888)
  44742. r = X * 3.2406 + Y * -1.5372 + Z * -0.4986;
  44743. g = X * -0.9689 + Y * 1.8758 + Z * 0.0415;
  44744. b = X * 0.0557 + Y * -0.2040 + Z * 1.0570;
  44745. }
  44746. // clamp color values to [0,1] range then convert to [0,255] range.
  44747. dest[destOffset] = r <= 0 ? 0 : r >= 1 ? 255 : Math.sqrt(r) * 255 | 0;
  44748. dest[destOffset + 1] = g <= 0 ? 0 : g >= 1 ? 255 : Math.sqrt(g) * 255 | 0;
  44749. dest[destOffset + 2] = b <= 0 ? 0 : b >= 1 ? 255 : Math.sqrt(b) * 255 | 0;
  44750. }
  44751. LabCS.prototype = {
  44752. getRgb: ColorSpace.prototype.getRgb,
  44753. getRgbItem: function LabCS_getRgbItem(src, srcOffset, dest, destOffset) {
  44754. convertToRgb(this, src, srcOffset, false, dest, destOffset);
  44755. },
  44756. getRgbBuffer: function LabCS_getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
  44757. var maxVal = (1 << bits) - 1;
  44758. for (var i = 0; i < count; i++) {
  44759. convertToRgb(this, src, srcOffset, maxVal, dest, destOffset);
  44760. srcOffset += 3;
  44761. destOffset += 3 + alpha01;
  44762. }
  44763. },
  44764. getOutputLength: function LabCS_getOutputLength(inputLength, alpha01) {
  44765. return inputLength * (3 + alpha01) / 3 | 0;
  44766. },
  44767. isPassthrough: ColorSpace.prototype.isPassthrough,
  44768. fillRgb: ColorSpace.prototype.fillRgb,
  44769. isDefaultDecode: function LabCS_isDefaultDecode(decodeMap) {
  44770. // XXX: Decoding is handled with the lab conversion because of the strange
  44771. // ranges that are used.
  44772. return true;
  44773. },
  44774. usesZeroToOneRange: false
  44775. };
  44776. return LabCS;
  44777. }();
  44778. exports.ColorSpace = ColorSpace;
  44779. }));
  44780. (function (root, factory) {
  44781. factory(root.pdfjsCoreImage = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCoreColorSpace, root.pdfjsCoreStream, root.pdfjsCoreJpx);
  44782. }(this, function (exports, sharedUtil, corePrimitives, coreColorSpace, coreStream, coreJpx) {
  44783. var ImageKind = sharedUtil.ImageKind;
  44784. var assert = sharedUtil.assert;
  44785. var error = sharedUtil.error;
  44786. var info = sharedUtil.info;
  44787. var isArray = sharedUtil.isArray;
  44788. var warn = sharedUtil.warn;
  44789. var Name = corePrimitives.Name;
  44790. var isStream = corePrimitives.isStream;
  44791. var ColorSpace = coreColorSpace.ColorSpace;
  44792. var DecodeStream = coreStream.DecodeStream;
  44793. var JpegStream = coreStream.JpegStream;
  44794. var JpxImage = coreJpx.JpxImage;
  44795. var PDFImage = function PDFImageClosure() {
  44796. /**
  44797. * Decodes the image using native decoder if possible. Resolves the promise
  44798. * when the image data is ready.
  44799. */
  44800. function handleImageData(image, nativeDecoder) {
  44801. if (nativeDecoder && nativeDecoder.canDecode(image)) {
  44802. return nativeDecoder.decode(image);
  44803. } else {
  44804. return Promise.resolve(image);
  44805. }
  44806. }
  44807. /**
  44808. * Decode and clamp a value. The formula is different from the spec because we
  44809. * don't decode to float range [0,1], we decode it in the [0,max] range.
  44810. */
  44811. function decodeAndClamp(value, addend, coefficient, max) {
  44812. value = addend + value * coefficient;
  44813. // Clamp the value to the range
  44814. return value < 0 ? 0 : value > max ? max : value;
  44815. }
  44816. /**
  44817. * Resizes an image mask with 1 component.
  44818. * @param {TypedArray} src - The source buffer.
  44819. * @param {Number} bpc - Number of bits per component.
  44820. * @param {Number} w1 - Original width.
  44821. * @param {Number} h1 - Original height.
  44822. * @param {Number} w2 - New width.
  44823. * @param {Number} h2 - New height.
  44824. * @returns {TypedArray} The resized image mask buffer.
  44825. */
  44826. function resizeImageMask(src, bpc, w1, h1, w2, h2) {
  44827. var length = w2 * h2;
  44828. var dest = bpc <= 8 ? new Uint8Array(length) : bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length);
  44829. var xRatio = w1 / w2;
  44830. var yRatio = h1 / h2;
  44831. var i, j, py, newIndex = 0, oldIndex;
  44832. var xScaled = new Uint16Array(w2);
  44833. var w1Scanline = w1;
  44834. for (i = 0; i < w2; i++) {
  44835. xScaled[i] = Math.floor(i * xRatio);
  44836. }
  44837. for (i = 0; i < h2; i++) {
  44838. py = Math.floor(i * yRatio) * w1Scanline;
  44839. for (j = 0; j < w2; j++) {
  44840. oldIndex = py + xScaled[j];
  44841. dest[newIndex++] = src[oldIndex];
  44842. }
  44843. }
  44844. return dest;
  44845. }
  44846. function PDFImage(xref, res, image, inline, smask, mask, isMask) {
  44847. this.image = image;
  44848. var dict = image.dict;
  44849. if (dict.has('Filter')) {
  44850. var filter = dict.get('Filter').name;
  44851. if (filter === 'JPXDecode') {
  44852. var jpxImage = new JpxImage();
  44853. jpxImage.parseImageProperties(image.stream);
  44854. image.stream.reset();
  44855. image.bitsPerComponent = jpxImage.bitsPerComponent;
  44856. image.numComps = jpxImage.componentsCount;
  44857. } else if (filter === 'JBIG2Decode') {
  44858. image.bitsPerComponent = 1;
  44859. image.numComps = 1;
  44860. }
  44861. }
  44862. // TODO cache rendered images?
  44863. this.width = dict.get('Width', 'W');
  44864. this.height = dict.get('Height', 'H');
  44865. if (this.width < 1 || this.height < 1) {
  44866. error('Invalid image width: ' + this.width + ' or height: ' + this.height);
  44867. }
  44868. this.interpolate = dict.get('Interpolate', 'I') || false;
  44869. this.imageMask = dict.get('ImageMask', 'IM') || false;
  44870. this.matte = dict.get('Matte') || false;
  44871. var bitsPerComponent = image.bitsPerComponent;
  44872. if (!bitsPerComponent) {
  44873. bitsPerComponent = dict.get('BitsPerComponent', 'BPC');
  44874. if (!bitsPerComponent) {
  44875. if (this.imageMask) {
  44876. bitsPerComponent = 1;
  44877. } else {
  44878. error('Bits per component missing in image: ' + this.imageMask);
  44879. }
  44880. }
  44881. }
  44882. this.bpc = bitsPerComponent;
  44883. if (!this.imageMask) {
  44884. var colorSpace = dict.get('ColorSpace', 'CS');
  44885. if (!colorSpace) {
  44886. info('JPX images (which do not require color spaces)');
  44887. switch (image.numComps) {
  44888. case 1:
  44889. colorSpace = Name.get('DeviceGray');
  44890. break;
  44891. case 3:
  44892. colorSpace = Name.get('DeviceRGB');
  44893. break;
  44894. case 4:
  44895. colorSpace = Name.get('DeviceCMYK');
  44896. break;
  44897. default:
  44898. error('JPX images with ' + this.numComps + ' color components not supported.');
  44899. }
  44900. }
  44901. this.colorSpace = ColorSpace.parse(colorSpace, xref, res);
  44902. this.numComps = this.colorSpace.numComps;
  44903. }
  44904. this.decode = dict.getArray('Decode', 'D');
  44905. this.needsDecode = false;
  44906. if (this.decode && (this.colorSpace && !this.colorSpace.isDefaultDecode(this.decode) || isMask && !ColorSpace.isDefaultDecode(this.decode, 1))) {
  44907. this.needsDecode = true;
  44908. // Do some preprocessing to avoid more math.
  44909. var max = (1 << bitsPerComponent) - 1;
  44910. this.decodeCoefficients = [];
  44911. this.decodeAddends = [];
  44912. for (var i = 0, j = 0; i < this.decode.length; i += 2, ++j) {
  44913. var dmin = this.decode[i];
  44914. var dmax = this.decode[i + 1];
  44915. this.decodeCoefficients[j] = dmax - dmin;
  44916. this.decodeAddends[j] = max * dmin;
  44917. }
  44918. }
  44919. if (smask) {
  44920. this.smask = new PDFImage(xref, res, smask, false);
  44921. } else if (mask) {
  44922. if (isStream(mask)) {
  44923. var maskDict = mask.dict, imageMask = maskDict.get('ImageMask', 'IM');
  44924. if (!imageMask) {
  44925. warn('Ignoring /Mask in image without /ImageMask.');
  44926. } else {
  44927. this.mask = new PDFImage(xref, res, mask, false, null, null, true);
  44928. }
  44929. } else {
  44930. // Color key mask (just an array).
  44931. this.mask = mask;
  44932. }
  44933. }
  44934. }
  44935. /**
  44936. * Handles processing of image data and returns the Promise that is resolved
  44937. * with a PDFImage when the image is ready to be used.
  44938. */
  44939. PDFImage.buildImage = function PDFImage_buildImage(handler, xref, res, image, inline, nativeDecoder) {
  44940. var imagePromise = handleImageData(image, nativeDecoder);
  44941. var smaskPromise;
  44942. var maskPromise;
  44943. var smask = image.dict.get('SMask');
  44944. var mask = image.dict.get('Mask');
  44945. if (smask) {
  44946. smaskPromise = handleImageData(smask, nativeDecoder);
  44947. maskPromise = Promise.resolve(null);
  44948. } else {
  44949. smaskPromise = Promise.resolve(null);
  44950. if (mask) {
  44951. if (isStream(mask)) {
  44952. maskPromise = handleImageData(mask, nativeDecoder);
  44953. } else if (isArray(mask)) {
  44954. maskPromise = Promise.resolve(mask);
  44955. } else {
  44956. warn('Unsupported mask format.');
  44957. maskPromise = Promise.resolve(null);
  44958. }
  44959. } else {
  44960. maskPromise = Promise.resolve(null);
  44961. }
  44962. }
  44963. return Promise.all([
  44964. imagePromise,
  44965. smaskPromise,
  44966. maskPromise
  44967. ]).then(function (results) {
  44968. var imageData = results[0];
  44969. var smaskData = results[1];
  44970. var maskData = results[2];
  44971. return new PDFImage(xref, res, imageData, inline, smaskData, maskData);
  44972. });
  44973. };
  44974. PDFImage.createMask = function PDFImage_createMask(imgArray, width, height, imageIsFromDecodeStream, inverseDecode) {
  44975. // |imgArray| might not contain full data for every pixel of the mask, so
  44976. // we need to distinguish between |computedLength| and |actualLength|.
  44977. // In particular, if inverseDecode is true, then the array we return must
  44978. // have a length of |computedLength|.
  44979. var computedLength = (width + 7 >> 3) * height;
  44980. var actualLength = imgArray.byteLength;
  44981. var haveFullData = computedLength === actualLength;
  44982. var data, i;
  44983. if (imageIsFromDecodeStream && (!inverseDecode || haveFullData)) {
  44984. // imgArray came from a DecodeStream and its data is in an appropriate
  44985. // form, so we can just transfer it.
  44986. data = imgArray;
  44987. } else if (!inverseDecode) {
  44988. data = new Uint8Array(actualLength);
  44989. data.set(imgArray);
  44990. } else {
  44991. data = new Uint8Array(computedLength);
  44992. data.set(imgArray);
  44993. for (i = actualLength; i < computedLength; i++) {
  44994. data[i] = 0xff;
  44995. }
  44996. }
  44997. // If necessary, invert the original mask data (but not any extra we might
  44998. // have added above). It's safe to modify the array -- whether it's the
  44999. // original or a copy, we're about to transfer it anyway, so nothing else
  45000. // in this thread can be relying on its contents.
  45001. if (inverseDecode) {
  45002. for (i = 0; i < actualLength; i++) {
  45003. data[i] = ~data[i];
  45004. }
  45005. }
  45006. return {
  45007. data: data,
  45008. width: width,
  45009. height: height
  45010. };
  45011. };
  45012. PDFImage.prototype = {
  45013. get drawWidth() {
  45014. return Math.max(this.width, this.smask && this.smask.width || 0, this.mask && this.mask.width || 0);
  45015. },
  45016. get drawHeight() {
  45017. return Math.max(this.height, this.smask && this.smask.height || 0, this.mask && this.mask.height || 0);
  45018. },
  45019. decodeBuffer: function PDFImage_decodeBuffer(buffer) {
  45020. var bpc = this.bpc;
  45021. var numComps = this.numComps;
  45022. var decodeAddends = this.decodeAddends;
  45023. var decodeCoefficients = this.decodeCoefficients;
  45024. var max = (1 << bpc) - 1;
  45025. var i, ii;
  45026. if (bpc === 1) {
  45027. // If the buffer needed decode that means it just needs to be inverted.
  45028. for (i = 0, ii = buffer.length; i < ii; i++) {
  45029. buffer[i] = +!buffer[i];
  45030. }
  45031. return;
  45032. }
  45033. var index = 0;
  45034. for (i = 0, ii = this.width * this.height; i < ii; i++) {
  45035. for (var j = 0; j < numComps; j++) {
  45036. buffer[index] = decodeAndClamp(buffer[index], decodeAddends[j], decodeCoefficients[j], max);
  45037. index++;
  45038. }
  45039. }
  45040. },
  45041. getComponents: function PDFImage_getComponents(buffer) {
  45042. var bpc = this.bpc;
  45043. // This image doesn't require any extra work.
  45044. if (bpc === 8) {
  45045. return buffer;
  45046. }
  45047. var width = this.width;
  45048. var height = this.height;
  45049. var numComps = this.numComps;
  45050. var length = width * height * numComps;
  45051. var bufferPos = 0;
  45052. var output = bpc <= 8 ? new Uint8Array(length) : bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length);
  45053. var rowComps = width * numComps;
  45054. var max = (1 << bpc) - 1;
  45055. var i = 0, ii, buf;
  45056. if (bpc === 1) {
  45057. // Optimization for reading 1 bpc images.
  45058. var mask, loop1End, loop2End;
  45059. for (var j = 0; j < height; j++) {
  45060. loop1End = i + (rowComps & ~7);
  45061. loop2End = i + rowComps;
  45062. // unroll loop for all full bytes
  45063. while (i < loop1End) {
  45064. buf = buffer[bufferPos++];
  45065. output[i] = buf >> 7 & 1;
  45066. output[i + 1] = buf >> 6 & 1;
  45067. output[i + 2] = buf >> 5 & 1;
  45068. output[i + 3] = buf >> 4 & 1;
  45069. output[i + 4] = buf >> 3 & 1;
  45070. output[i + 5] = buf >> 2 & 1;
  45071. output[i + 6] = buf >> 1 & 1;
  45072. output[i + 7] = buf & 1;
  45073. i += 8;
  45074. }
  45075. // handle remaining bits
  45076. if (i < loop2End) {
  45077. buf = buffer[bufferPos++];
  45078. mask = 128;
  45079. while (i < loop2End) {
  45080. output[i++] = +!!(buf & mask);
  45081. mask >>= 1;
  45082. }
  45083. }
  45084. }
  45085. } else {
  45086. // The general case that handles all other bpc values.
  45087. var bits = 0;
  45088. buf = 0;
  45089. for (i = 0, ii = length; i < ii; ++i) {
  45090. if (i % rowComps === 0) {
  45091. buf = 0;
  45092. bits = 0;
  45093. }
  45094. while (bits < bpc) {
  45095. buf = buf << 8 | buffer[bufferPos++];
  45096. bits += 8;
  45097. }
  45098. var remainingBits = bits - bpc;
  45099. var value = buf >> remainingBits;
  45100. output[i] = value < 0 ? 0 : value > max ? max : value;
  45101. buf = buf & (1 << remainingBits) - 1;
  45102. bits = remainingBits;
  45103. }
  45104. }
  45105. return output;
  45106. },
  45107. fillOpacity: function PDFImage_fillOpacity(rgbaBuf, width, height, actualHeight, image) {
  45108. var smask = this.smask;
  45109. var mask = this.mask;
  45110. var alphaBuf, sw, sh, i, ii, j;
  45111. if (smask) {
  45112. sw = smask.width;
  45113. sh = smask.height;
  45114. alphaBuf = new Uint8Array(sw * sh);
  45115. smask.fillGrayBuffer(alphaBuf);
  45116. if (sw !== width || sh !== height) {
  45117. alphaBuf = resizeImageMask(alphaBuf, smask.bpc, sw, sh, width, height);
  45118. }
  45119. } else if (mask) {
  45120. if (mask instanceof PDFImage) {
  45121. sw = mask.width;
  45122. sh = mask.height;
  45123. alphaBuf = new Uint8Array(sw * sh);
  45124. mask.numComps = 1;
  45125. mask.fillGrayBuffer(alphaBuf);
  45126. // Need to invert values in rgbaBuf
  45127. for (i = 0, ii = sw * sh; i < ii; ++i) {
  45128. alphaBuf[i] = 255 - alphaBuf[i];
  45129. }
  45130. if (sw !== width || sh !== height) {
  45131. alphaBuf = resizeImageMask(alphaBuf, mask.bpc, sw, sh, width, height);
  45132. }
  45133. } else if (isArray(mask)) {
  45134. // Color key mask: if any of the components are outside the range
  45135. // then they should be painted.
  45136. alphaBuf = new Uint8Array(width * height);
  45137. var numComps = this.numComps;
  45138. for (i = 0, ii = width * height; i < ii; ++i) {
  45139. var opacity = 0;
  45140. var imageOffset = i * numComps;
  45141. for (j = 0; j < numComps; ++j) {
  45142. var color = image[imageOffset + j];
  45143. var maskOffset = j * 2;
  45144. if (color < mask[maskOffset] || color > mask[maskOffset + 1]) {
  45145. opacity = 255;
  45146. break;
  45147. }
  45148. }
  45149. alphaBuf[i] = opacity;
  45150. }
  45151. } else {
  45152. error('Unknown mask format.');
  45153. }
  45154. }
  45155. if (alphaBuf) {
  45156. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  45157. rgbaBuf[j] = alphaBuf[i];
  45158. }
  45159. } else {
  45160. // No mask.
  45161. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  45162. rgbaBuf[j] = 255;
  45163. }
  45164. }
  45165. },
  45166. undoPreblend: function PDFImage_undoPreblend(buffer, width, height) {
  45167. var matte = this.smask && this.smask.matte;
  45168. if (!matte) {
  45169. return;
  45170. }
  45171. var matteRgb = this.colorSpace.getRgb(matte, 0);
  45172. var matteR = matteRgb[0];
  45173. var matteG = matteRgb[1];
  45174. var matteB = matteRgb[2];
  45175. var length = width * height * 4;
  45176. var r, g, b;
  45177. for (var i = 0; i < length; i += 4) {
  45178. var alpha = buffer[i + 3];
  45179. if (alpha === 0) {
  45180. // according formula we have to get Infinity in all components
  45181. // making it white (typical paper color) should be okay
  45182. buffer[i] = 255;
  45183. buffer[i + 1] = 255;
  45184. buffer[i + 2] = 255;
  45185. continue;
  45186. }
  45187. var k = 255 / alpha;
  45188. r = (buffer[i] - matteR) * k + matteR;
  45189. g = (buffer[i + 1] - matteG) * k + matteG;
  45190. b = (buffer[i + 2] - matteB) * k + matteB;
  45191. buffer[i] = r <= 0 ? 0 : r >= 255 ? 255 : r | 0;
  45192. buffer[i + 1] = g <= 0 ? 0 : g >= 255 ? 255 : g | 0;
  45193. buffer[i + 2] = b <= 0 ? 0 : b >= 255 ? 255 : b | 0;
  45194. }
  45195. },
  45196. createImageData: function PDFImage_createImageData(forceRGBA) {
  45197. var drawWidth = this.drawWidth;
  45198. var drawHeight = this.drawHeight;
  45199. var imgData = {
  45200. // other fields are filled in below
  45201. width: drawWidth,
  45202. height: drawHeight
  45203. };
  45204. var numComps = this.numComps;
  45205. var originalWidth = this.width;
  45206. var originalHeight = this.height;
  45207. var bpc = this.bpc;
  45208. // Rows start at byte boundary.
  45209. var rowBytes = originalWidth * numComps * bpc + 7 >> 3;
  45210. var imgArray;
  45211. if (!forceRGBA) {
  45212. // If it is a 1-bit-per-pixel grayscale (i.e. black-and-white) image
  45213. // without any complications, we pass a same-sized copy to the main
  45214. // thread rather than expanding by 32x to RGBA form. This saves *lots*
  45215. // of memory for many scanned documents. It's also much faster.
  45216. //
  45217. // Similarly, if it is a 24-bit-per pixel RGB image without any
  45218. // complications, we avoid expanding by 1.333x to RGBA form.
  45219. var kind;
  45220. if (this.colorSpace.name === 'DeviceGray' && bpc === 1) {
  45221. kind = ImageKind.GRAYSCALE_1BPP;
  45222. } else if (this.colorSpace.name === 'DeviceRGB' && bpc === 8 && !this.needsDecode) {
  45223. kind = ImageKind.RGB_24BPP;
  45224. }
  45225. if (kind && !this.smask && !this.mask && drawWidth === originalWidth && drawHeight === originalHeight) {
  45226. imgData.kind = kind;
  45227. imgArray = this.getImageBytes(originalHeight * rowBytes);
  45228. // If imgArray came from a DecodeStream, we're safe to transfer it
  45229. // (and thus detach its underlying buffer) because it will constitute
  45230. // the entire DecodeStream's data. But if it came from a Stream, we
  45231. // need to copy it because it'll only be a portion of the Stream's
  45232. // data, and the rest will be read later on.
  45233. if (this.image instanceof DecodeStream) {
  45234. imgData.data = imgArray;
  45235. } else {
  45236. var newArray = new Uint8Array(imgArray.length);
  45237. newArray.set(imgArray);
  45238. imgData.data = newArray;
  45239. }
  45240. if (this.needsDecode) {
  45241. // Invert the buffer (which must be grayscale if we reached here).
  45242. assert(kind === ImageKind.GRAYSCALE_1BPP);
  45243. var buffer = imgData.data;
  45244. for (var i = 0, ii = buffer.length; i < ii; i++) {
  45245. buffer[i] ^= 0xff;
  45246. }
  45247. }
  45248. return imgData;
  45249. }
  45250. if (this.image instanceof JpegStream && !this.smask && !this.mask && (this.colorSpace.name === 'DeviceGray' || this.colorSpace.name === 'DeviceRGB' || this.colorSpace.name === 'DeviceCMYK')) {
  45251. imgData.kind = ImageKind.RGB_24BPP;
  45252. imgData.data = this.getImageBytes(originalHeight * rowBytes, drawWidth, drawHeight, true);
  45253. return imgData;
  45254. }
  45255. }
  45256. imgArray = this.getImageBytes(originalHeight * rowBytes);
  45257. // imgArray can be incomplete (e.g. after CCITT fax encoding).
  45258. var actualHeight = 0 | imgArray.length / rowBytes * drawHeight / originalHeight;
  45259. var comps = this.getComponents(imgArray);
  45260. // If opacity data is present, use RGBA_32BPP form. Otherwise, use the
  45261. // more compact RGB_24BPP form if allowable.
  45262. var alpha01, maybeUndoPreblend;
  45263. if (!forceRGBA && !this.smask && !this.mask) {
  45264. imgData.kind = ImageKind.RGB_24BPP;
  45265. imgData.data = new Uint8Array(drawWidth * drawHeight * 3);
  45266. alpha01 = 0;
  45267. maybeUndoPreblend = false;
  45268. } else {
  45269. imgData.kind = ImageKind.RGBA_32BPP;
  45270. imgData.data = new Uint8Array(drawWidth * drawHeight * 4);
  45271. alpha01 = 1;
  45272. maybeUndoPreblend = true;
  45273. // Color key masking (opacity) must be performed before decoding.
  45274. this.fillOpacity(imgData.data, drawWidth, drawHeight, actualHeight, comps);
  45275. }
  45276. if (this.needsDecode) {
  45277. this.decodeBuffer(comps);
  45278. }
  45279. this.colorSpace.fillRgb(imgData.data, originalWidth, originalHeight, drawWidth, drawHeight, actualHeight, bpc, comps, alpha01);
  45280. if (maybeUndoPreblend) {
  45281. this.undoPreblend(imgData.data, drawWidth, actualHeight);
  45282. }
  45283. return imgData;
  45284. },
  45285. fillGrayBuffer: function PDFImage_fillGrayBuffer(buffer) {
  45286. var numComps = this.numComps;
  45287. if (numComps !== 1) {
  45288. error('Reading gray scale from a color image: ' + numComps);
  45289. }
  45290. var width = this.width;
  45291. var height = this.height;
  45292. var bpc = this.bpc;
  45293. // rows start at byte boundary
  45294. var rowBytes = width * numComps * bpc + 7 >> 3;
  45295. var imgArray = this.getImageBytes(height * rowBytes);
  45296. var comps = this.getComponents(imgArray);
  45297. var i, length;
  45298. if (bpc === 1) {
  45299. // inline decoding (= inversion) for 1 bpc images
  45300. length = width * height;
  45301. if (this.needsDecode) {
  45302. // invert and scale to {0, 255}
  45303. for (i = 0; i < length; ++i) {
  45304. buffer[i] = comps[i] - 1 & 255;
  45305. }
  45306. } else {
  45307. // scale to {0, 255}
  45308. for (i = 0; i < length; ++i) {
  45309. buffer[i] = -comps[i] & 255;
  45310. }
  45311. }
  45312. return;
  45313. }
  45314. if (this.needsDecode) {
  45315. this.decodeBuffer(comps);
  45316. }
  45317. length = width * height;
  45318. // we aren't using a colorspace so we need to scale the value
  45319. var scale = 255 / ((1 << bpc) - 1);
  45320. for (i = 0; i < length; ++i) {
  45321. buffer[i] = scale * comps[i] | 0;
  45322. }
  45323. },
  45324. getImageBytes: function PDFImage_getImageBytes(length, drawWidth, drawHeight, forceRGB) {
  45325. this.image.reset();
  45326. this.image.drawWidth = drawWidth || this.width;
  45327. this.image.drawHeight = drawHeight || this.height;
  45328. this.image.forceRGB = !!forceRGB;
  45329. return this.image.getBytes(length);
  45330. }
  45331. };
  45332. return PDFImage;
  45333. }();
  45334. exports.PDFImage = PDFImage;
  45335. }));
  45336. (function (root, factory) {
  45337. factory(root.pdfjsCoreObj = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCoreCrypto, root.pdfjsCoreParser, root.pdfjsCoreChunkedStream, root.pdfjsCoreColorSpace);
  45338. }(this, function (exports, sharedUtil, corePrimitives, coreCrypto, coreParser, coreChunkedStream, coreColorSpace) {
  45339. var InvalidPDFException = sharedUtil.InvalidPDFException;
  45340. var MissingDataException = sharedUtil.MissingDataException;
  45341. var XRefParseException = sharedUtil.XRefParseException;
  45342. var assert = sharedUtil.assert;
  45343. var bytesToString = sharedUtil.bytesToString;
  45344. var createPromiseCapability = sharedUtil.createPromiseCapability;
  45345. var error = sharedUtil.error;
  45346. var info = sharedUtil.info;
  45347. var isArray = sharedUtil.isArray;
  45348. var isBool = sharedUtil.isBool;
  45349. var isInt = sharedUtil.isInt;
  45350. var isString = sharedUtil.isString;
  45351. var shadow = sharedUtil.shadow;
  45352. var stringToPDFString = sharedUtil.stringToPDFString;
  45353. var stringToUTF8String = sharedUtil.stringToUTF8String;
  45354. var warn = sharedUtil.warn;
  45355. var createValidAbsoluteUrl = sharedUtil.createValidAbsoluteUrl;
  45356. var Util = sharedUtil.Util;
  45357. var Ref = corePrimitives.Ref;
  45358. var RefSet = corePrimitives.RefSet;
  45359. var RefSetCache = corePrimitives.RefSetCache;
  45360. var isName = corePrimitives.isName;
  45361. var isCmd = corePrimitives.isCmd;
  45362. var isDict = corePrimitives.isDict;
  45363. var isRef = corePrimitives.isRef;
  45364. var isRefsEqual = corePrimitives.isRefsEqual;
  45365. var isStream = corePrimitives.isStream;
  45366. var CipherTransformFactory = coreCrypto.CipherTransformFactory;
  45367. var Lexer = coreParser.Lexer;
  45368. var Parser = coreParser.Parser;
  45369. var ChunkedStream = coreChunkedStream.ChunkedStream;
  45370. var ColorSpace = coreColorSpace.ColorSpace;
  45371. var Catalog = function CatalogClosure() {
  45372. function Catalog(pdfManager, xref, pageFactory) {
  45373. this.pdfManager = pdfManager;
  45374. this.xref = xref;
  45375. this.catDict = xref.getCatalogObj();
  45376. this.fontCache = new RefSetCache();
  45377. assert(isDict(this.catDict), 'catalog object is not a dictionary');
  45378. // TODO refactor to move getPage() to the PDFDocument.
  45379. this.pageFactory = pageFactory;
  45380. this.pagePromises = [];
  45381. }
  45382. Catalog.prototype = {
  45383. get metadata() {
  45384. var streamRef = this.catDict.getRaw('Metadata');
  45385. if (!isRef(streamRef)) {
  45386. return shadow(this, 'metadata', null);
  45387. }
  45388. var encryptMetadata = !this.xref.encrypt ? false : this.xref.encrypt.encryptMetadata;
  45389. var stream = this.xref.fetch(streamRef, !encryptMetadata);
  45390. var metadata;
  45391. if (stream && isDict(stream.dict)) {
  45392. var type = stream.dict.get('Type');
  45393. var subtype = stream.dict.get('Subtype');
  45394. if (isName(type, 'Metadata') && isName(subtype, 'XML')) {
  45395. // XXX: This should examine the charset the XML document defines,
  45396. // however since there are currently no real means to decode
  45397. // arbitrary charsets, let's just hope that the author of the PDF
  45398. // was reasonable enough to stick with the XML default charset,
  45399. // which is UTF-8.
  45400. try {
  45401. metadata = stringToUTF8String(bytesToString(stream.getBytes()));
  45402. } catch (e) {
  45403. info('Skipping invalid metadata.');
  45404. }
  45405. }
  45406. }
  45407. return shadow(this, 'metadata', metadata);
  45408. },
  45409. get toplevelPagesDict() {
  45410. var pagesObj = this.catDict.get('Pages');
  45411. assert(isDict(pagesObj), 'invalid top-level pages dictionary');
  45412. // shadow the prototype getter
  45413. return shadow(this, 'toplevelPagesDict', pagesObj);
  45414. },
  45415. get documentOutline() {
  45416. var obj = null;
  45417. try {
  45418. obj = this.readDocumentOutline();
  45419. } catch (ex) {
  45420. if (ex instanceof MissingDataException) {
  45421. throw ex;
  45422. }
  45423. warn('Unable to read document outline');
  45424. }
  45425. return shadow(this, 'documentOutline', obj);
  45426. },
  45427. readDocumentOutline: function Catalog_readDocumentOutline() {
  45428. var obj = this.catDict.get('Outlines');
  45429. if (!isDict(obj)) {
  45430. return null;
  45431. }
  45432. obj = obj.getRaw('First');
  45433. if (!isRef(obj)) {
  45434. return null;
  45435. }
  45436. var root = { items: [] };
  45437. var queue = [{
  45438. obj: obj,
  45439. parent: root
  45440. }];
  45441. // To avoid recursion, keep track of the already processed items.
  45442. var processed = new RefSet();
  45443. processed.put(obj);
  45444. var xref = this.xref, blackColor = new Uint8Array(3);
  45445. while (queue.length > 0) {
  45446. var i = queue.shift();
  45447. var outlineDict = xref.fetchIfRef(i.obj);
  45448. if (outlineDict === null) {
  45449. continue;
  45450. }
  45451. assert(outlineDict.has('Title'), 'Invalid outline item');
  45452. var data = {
  45453. url: null,
  45454. dest: null
  45455. };
  45456. Catalog.parseDestDictionary({
  45457. destDict: outlineDict,
  45458. resultObj: data,
  45459. docBaseUrl: this.pdfManager.docBaseUrl
  45460. });
  45461. var title = outlineDict.get('Title');
  45462. var flags = outlineDict.get('F') || 0;
  45463. var color = outlineDict.getArray('C'), rgbColor = blackColor;
  45464. // We only need to parse the color when it's valid, and non-default.
  45465. if (isArray(color) && color.length === 3 && (color[0] !== 0 || color[1] !== 0 || color[2] !== 0)) {
  45466. rgbColor = ColorSpace.singletons.rgb.getRgb(color, 0);
  45467. }
  45468. var outlineItem = {
  45469. dest: data.dest,
  45470. url: data.url,
  45471. unsafeUrl: data.unsafeUrl,
  45472. newWindow: data.newWindow,
  45473. title: stringToPDFString(title),
  45474. color: rgbColor,
  45475. count: outlineDict.get('Count'),
  45476. bold: !!(flags & 2),
  45477. italic: !!(flags & 1),
  45478. items: []
  45479. };
  45480. i.parent.items.push(outlineItem);
  45481. obj = outlineDict.getRaw('First');
  45482. if (isRef(obj) && !processed.has(obj)) {
  45483. queue.push({
  45484. obj: obj,
  45485. parent: outlineItem
  45486. });
  45487. processed.put(obj);
  45488. }
  45489. obj = outlineDict.getRaw('Next');
  45490. if (isRef(obj) && !processed.has(obj)) {
  45491. queue.push({
  45492. obj: obj,
  45493. parent: i.parent
  45494. });
  45495. processed.put(obj);
  45496. }
  45497. }
  45498. return root.items.length > 0 ? root.items : null;
  45499. },
  45500. get numPages() {
  45501. var obj = this.toplevelPagesDict.get('Count');
  45502. assert(isInt(obj), 'page count in top level pages object is not an integer');
  45503. // shadow the prototype getter
  45504. return shadow(this, 'num', obj);
  45505. },
  45506. get destinations() {
  45507. function fetchDestination(dest) {
  45508. return isDict(dest) ? dest.get('D') : dest;
  45509. }
  45510. var xref = this.xref;
  45511. var dests = {}, nameTreeRef, nameDictionaryRef;
  45512. var obj = this.catDict.get('Names');
  45513. if (obj && obj.has('Dests')) {
  45514. nameTreeRef = obj.getRaw('Dests');
  45515. } else if (this.catDict.has('Dests')) {
  45516. nameDictionaryRef = this.catDict.get('Dests');
  45517. }
  45518. if (nameDictionaryRef) {
  45519. // reading simple destination dictionary
  45520. obj = nameDictionaryRef;
  45521. obj.forEach(function catalogForEach(key, value) {
  45522. if (!value) {
  45523. return;
  45524. }
  45525. dests[key] = fetchDestination(value);
  45526. });
  45527. }
  45528. if (nameTreeRef) {
  45529. var nameTree = new NameTree(nameTreeRef, xref);
  45530. var names = nameTree.getAll();
  45531. for (var name in names) {
  45532. dests[name] = fetchDestination(names[name]);
  45533. }
  45534. }
  45535. return shadow(this, 'destinations', dests);
  45536. },
  45537. getDestination: function Catalog_getDestination(destinationId) {
  45538. function fetchDestination(dest) {
  45539. return isDict(dest) ? dest.get('D') : dest;
  45540. }
  45541. var xref = this.xref;
  45542. var dest = null, nameTreeRef, nameDictionaryRef;
  45543. var obj = this.catDict.get('Names');
  45544. if (obj && obj.has('Dests')) {
  45545. nameTreeRef = obj.getRaw('Dests');
  45546. } else if (this.catDict.has('Dests')) {
  45547. nameDictionaryRef = this.catDict.get('Dests');
  45548. }
  45549. if (nameDictionaryRef) {
  45550. // Simple destination dictionary.
  45551. var value = nameDictionaryRef.get(destinationId);
  45552. if (value) {
  45553. dest = fetchDestination(value);
  45554. }
  45555. }
  45556. if (nameTreeRef) {
  45557. var nameTree = new NameTree(nameTreeRef, xref);
  45558. dest = fetchDestination(nameTree.get(destinationId));
  45559. }
  45560. return dest;
  45561. },
  45562. get pageLabels() {
  45563. var obj = null;
  45564. try {
  45565. obj = this.readPageLabels();
  45566. } catch (ex) {
  45567. if (ex instanceof MissingDataException) {
  45568. throw ex;
  45569. }
  45570. warn('Unable to read page labels.');
  45571. }
  45572. return shadow(this, 'pageLabels', obj);
  45573. },
  45574. readPageLabels: function Catalog_readPageLabels() {
  45575. var obj = this.catDict.getRaw('PageLabels');
  45576. if (!obj) {
  45577. return null;
  45578. }
  45579. var pageLabels = new Array(this.numPages);
  45580. var style = null;
  45581. var prefix = '';
  45582. var numberTree = new NumberTree(obj, this.xref);
  45583. var nums = numberTree.getAll();
  45584. var currentLabel = '', currentIndex = 1;
  45585. for (var i = 0, ii = this.numPages; i < ii; i++) {
  45586. if (i in nums) {
  45587. var labelDict = nums[i];
  45588. assert(isDict(labelDict), 'The PageLabel is not a dictionary.');
  45589. var type = labelDict.get('Type');
  45590. assert(!type || isName(type, 'PageLabel'), 'Invalid type in PageLabel dictionary.');
  45591. var s = labelDict.get('S');
  45592. assert(!s || isName(s), 'Invalid style in PageLabel dictionary.');
  45593. style = s ? s.name : null;
  45594. var p = labelDict.get('P');
  45595. assert(!p || isString(p), 'Invalid prefix in PageLabel dictionary.');
  45596. prefix = p ? stringToPDFString(p) : '';
  45597. var st = labelDict.get('St');
  45598. assert(!st || isInt(st) && st >= 1, 'Invalid start in PageLabel dictionary.');
  45599. currentIndex = st || 1;
  45600. }
  45601. switch (style) {
  45602. case 'D':
  45603. currentLabel = currentIndex;
  45604. break;
  45605. case 'R':
  45606. case 'r':
  45607. currentLabel = Util.toRoman(currentIndex, style === 'r');
  45608. break;
  45609. case 'A':
  45610. case 'a':
  45611. var LIMIT = 26;
  45612. // Use only the characters A--Z, or a--z.
  45613. var A_UPPER_CASE = 0x41, A_LOWER_CASE = 0x61;
  45614. var baseCharCode = style === 'a' ? A_LOWER_CASE : A_UPPER_CASE;
  45615. var letterIndex = currentIndex - 1;
  45616. var character = String.fromCharCode(baseCharCode + letterIndex % LIMIT);
  45617. var charBuf = [];
  45618. for (var j = 0, jj = letterIndex / LIMIT | 0; j <= jj; j++) {
  45619. charBuf.push(character);
  45620. }
  45621. currentLabel = charBuf.join('');
  45622. break;
  45623. default:
  45624. assert(!style, 'Invalid style "' + style + '" in PageLabel dictionary.');
  45625. }
  45626. pageLabels[i] = prefix + currentLabel;
  45627. currentLabel = '';
  45628. currentIndex++;
  45629. }
  45630. return pageLabels;
  45631. },
  45632. get attachments() {
  45633. var xref = this.xref;
  45634. var attachments = null, nameTreeRef;
  45635. var obj = this.catDict.get('Names');
  45636. if (obj) {
  45637. nameTreeRef = obj.getRaw('EmbeddedFiles');
  45638. }
  45639. if (nameTreeRef) {
  45640. var nameTree = new NameTree(nameTreeRef, xref);
  45641. var names = nameTree.getAll();
  45642. for (var name in names) {
  45643. var fs = new FileSpec(names[name], xref);
  45644. if (!attachments) {
  45645. attachments = Object.create(null);
  45646. }
  45647. attachments[stringToPDFString(name)] = fs.serializable;
  45648. }
  45649. }
  45650. return shadow(this, 'attachments', attachments);
  45651. },
  45652. get javaScript() {
  45653. var xref = this.xref;
  45654. var obj = this.catDict.get('Names');
  45655. var javaScript = [];
  45656. function appendIfJavaScriptDict(jsDict) {
  45657. var type = jsDict.get('S');
  45658. if (!isName(type, 'JavaScript')) {
  45659. return;
  45660. }
  45661. var js = jsDict.get('JS');
  45662. if (isStream(js)) {
  45663. js = bytesToString(js.getBytes());
  45664. } else if (!isString(js)) {
  45665. return;
  45666. }
  45667. javaScript.push(stringToPDFString(js));
  45668. }
  45669. if (obj && obj.has('JavaScript')) {
  45670. var nameTree = new NameTree(obj.getRaw('JavaScript'), xref);
  45671. var names = nameTree.getAll();
  45672. for (var name in names) {
  45673. // We don't really use the JavaScript right now. This code is
  45674. // defensive so we don't cause errors on document load.
  45675. var jsDict = names[name];
  45676. if (isDict(jsDict)) {
  45677. appendIfJavaScriptDict(jsDict);
  45678. }
  45679. }
  45680. }
  45681. // Append OpenAction actions to javaScript array
  45682. var openactionDict = this.catDict.get('OpenAction');
  45683. if (isDict(openactionDict, 'Action')) {
  45684. var actionType = openactionDict.get('S');
  45685. if (isName(actionType, 'Named')) {
  45686. // The named Print action is not a part of the PDF 1.7 specification,
  45687. // but is supported by many PDF readers/writers (including Adobe's).
  45688. var action = openactionDict.get('N');
  45689. if (isName(action, 'Print')) {
  45690. javaScript.push('print({});');
  45691. }
  45692. } else {
  45693. appendIfJavaScriptDict(openactionDict);
  45694. }
  45695. }
  45696. return shadow(this, 'javaScript', javaScript);
  45697. },
  45698. cleanup: function Catalog_cleanup() {
  45699. var promises = [];
  45700. this.fontCache.forEach(function (promise) {
  45701. promises.push(promise);
  45702. });
  45703. return Promise.all(promises).then(function (translatedFonts) {
  45704. for (var i = 0, ii = translatedFonts.length; i < ii; i++) {
  45705. var font = translatedFonts[i].dict;
  45706. delete font.translated;
  45707. }
  45708. this.fontCache.clear();
  45709. }.bind(this));
  45710. },
  45711. getPage: function Catalog_getPage(pageIndex) {
  45712. if (!(pageIndex in this.pagePromises)) {
  45713. this.pagePromises[pageIndex] = this.getPageDict(pageIndex).then(function (a) {
  45714. var dict = a[0];
  45715. var ref = a[1];
  45716. return this.pageFactory.createPage(pageIndex, dict, ref, this.fontCache);
  45717. }.bind(this));
  45718. }
  45719. return this.pagePromises[pageIndex];
  45720. },
  45721. getPageDict: function Catalog_getPageDict(pageIndex) {
  45722. var capability = createPromiseCapability();
  45723. var nodesToVisit = [this.catDict.getRaw('Pages')];
  45724. var currentPageIndex = 0;
  45725. var xref = this.xref;
  45726. var checkAllKids = false;
  45727. function next() {
  45728. while (nodesToVisit.length) {
  45729. var currentNode = nodesToVisit.pop();
  45730. if (isRef(currentNode)) {
  45731. xref.fetchAsync(currentNode).then(function (obj) {
  45732. if (isDict(obj, 'Page') || isDict(obj) && !obj.has('Kids')) {
  45733. if (pageIndex === currentPageIndex) {
  45734. capability.resolve([
  45735. obj,
  45736. currentNode
  45737. ]);
  45738. } else {
  45739. currentPageIndex++;
  45740. next();
  45741. }
  45742. return;
  45743. }
  45744. nodesToVisit.push(obj);
  45745. next();
  45746. }, capability.reject);
  45747. return;
  45748. }
  45749. // Must be a child page dictionary.
  45750. assert(isDict(currentNode), 'page dictionary kid reference points to wrong type of object');
  45751. var count = currentNode.get('Count');
  45752. // If the current node doesn't have any children, avoid getting stuck
  45753. // in an empty node further down in the tree (see issue5644.pdf).
  45754. if (count === 0) {
  45755. checkAllKids = true;
  45756. }
  45757. // Skip nodes where the page can't be.
  45758. if (currentPageIndex + count <= pageIndex) {
  45759. currentPageIndex += count;
  45760. continue;
  45761. }
  45762. var kids = currentNode.get('Kids');
  45763. assert(isArray(kids), 'page dictionary kids object is not an array');
  45764. if (!checkAllKids && count === kids.length) {
  45765. // Nodes that don't have the page have been skipped and this is the
  45766. // bottom of the tree which means the page requested must be a
  45767. // descendant of this pages node. Ideally we would just resolve the
  45768. // promise with the page ref here, but there is the case where more
  45769. // pages nodes could link to single a page (see issue 3666 pdf). To
  45770. // handle this push it back on the queue so if it is a pages node it
  45771. // will be descended into.
  45772. nodesToVisit = [kids[pageIndex - currentPageIndex]];
  45773. currentPageIndex = pageIndex;
  45774. continue;
  45775. } else {
  45776. for (var last = kids.length - 1; last >= 0; last--) {
  45777. nodesToVisit.push(kids[last]);
  45778. }
  45779. }
  45780. }
  45781. capability.reject('Page index ' + pageIndex + ' not found.');
  45782. }
  45783. next();
  45784. return capability.promise;
  45785. },
  45786. getPageIndex: function Catalog_getPageIndex(pageRef) {
  45787. // The page tree nodes have the count of all the leaves below them. To get
  45788. // how many pages are before we just have to walk up the tree and keep
  45789. // adding the count of siblings to the left of the node.
  45790. var xref = this.xref;
  45791. function pagesBeforeRef(kidRef) {
  45792. var total = 0;
  45793. var parentRef;
  45794. return xref.fetchAsync(kidRef).then(function (node) {
  45795. if (isRefsEqual(kidRef, pageRef) && !isDict(node, 'Page') && !(isDict(node) && !node.has('Type') && node.has('Contents'))) {
  45796. throw new Error('The reference does not point to a /Page Dict.');
  45797. }
  45798. if (!node) {
  45799. return null;
  45800. }
  45801. assert(isDict(node), 'node must be a Dict.');
  45802. parentRef = node.getRaw('Parent');
  45803. return node.getAsync('Parent');
  45804. }).then(function (parent) {
  45805. if (!parent) {
  45806. return null;
  45807. }
  45808. assert(isDict(parent), 'parent must be a Dict.');
  45809. return parent.getAsync('Kids');
  45810. }).then(function (kids) {
  45811. if (!kids) {
  45812. return null;
  45813. }
  45814. var kidPromises = [];
  45815. var found = false;
  45816. for (var i = 0; i < kids.length; i++) {
  45817. var kid = kids[i];
  45818. assert(isRef(kid), 'kid must be a Ref.');
  45819. if (kid.num === kidRef.num) {
  45820. found = true;
  45821. break;
  45822. }
  45823. kidPromises.push(xref.fetchAsync(kid).then(function (kid) {
  45824. if (kid.has('Count')) {
  45825. var count = kid.get('Count');
  45826. total += count;
  45827. } else {
  45828. // page leaf node
  45829. total++;
  45830. }
  45831. }));
  45832. }
  45833. if (!found) {
  45834. error('kid ref not found in parents kids');
  45835. }
  45836. return Promise.all(kidPromises).then(function () {
  45837. return [
  45838. total,
  45839. parentRef
  45840. ];
  45841. });
  45842. });
  45843. }
  45844. var total = 0;
  45845. function next(ref) {
  45846. return pagesBeforeRef(ref).then(function (args) {
  45847. if (!args) {
  45848. return total;
  45849. }
  45850. var count = args[0];
  45851. var parentRef = args[1];
  45852. total += count;
  45853. return next(parentRef);
  45854. });
  45855. }
  45856. return next(pageRef);
  45857. }
  45858. };
  45859. /**
  45860. * Helper function used to parse the contents of destination dictionaries.
  45861. * @param {Dict} destDict - The dictionary containing the destination.
  45862. * @param {Object} resultObj - The object where the parsed destination
  45863. * properties will be placed.
  45864. * @param {string} docBaseUrl - (optional) The document base URL that is used
  45865. * when attempting to recover valid absolute URLs from relative ones.
  45866. */
  45867. Catalog.parseDestDictionary = function Catalog_parseDestDictionary(params) {
  45868. // Lets URLs beginning with 'www.' default to using the 'http://' protocol.
  45869. function addDefaultProtocolToUrl(url) {
  45870. if (url.indexOf('www.') === 0) {
  45871. return 'http://' + url;
  45872. }
  45873. return url;
  45874. }
  45875. // According to ISO 32000-1:2008, section 12.6.4.7, URIs should be encoded
  45876. // in 7-bit ASCII. Some bad PDFs use UTF-8 encoding, see Bugzilla 1122280.
  45877. function tryConvertUrlEncoding(url) {
  45878. try {
  45879. return stringToUTF8String(url);
  45880. } catch (e) {
  45881. return url;
  45882. }
  45883. }
  45884. var destDict = params.destDict;
  45885. if (!isDict(destDict)) {
  45886. warn('Catalog_parseDestDictionary: "destDict" must be a dictionary.');
  45887. return;
  45888. }
  45889. var resultObj = params.resultObj;
  45890. if (typeof resultObj !== 'object') {
  45891. warn('Catalog_parseDestDictionary: "resultObj" must be an object.');
  45892. return;
  45893. }
  45894. var docBaseUrl = params.docBaseUrl || null;
  45895. var action = destDict.get('A'), url, dest;
  45896. if (isDict(action)) {
  45897. var linkType = action.get('S').name;
  45898. switch (linkType) {
  45899. case 'URI':
  45900. url = action.get('URI');
  45901. if (isName(url)) {
  45902. // Some bad PDFs do not put parentheses around relative URLs.
  45903. url = '/' + url.name;
  45904. } else if (isString(url)) {
  45905. url = addDefaultProtocolToUrl(url);
  45906. }
  45907. // TODO: pdf spec mentions urls can be relative to a Base
  45908. // entry in the dictionary.
  45909. break;
  45910. case 'GoTo':
  45911. dest = action.get('D');
  45912. break;
  45913. case 'Launch':
  45914. // We neither want, nor can, support arbitrary 'Launch' actions.
  45915. // However, in practice they are mostly used for linking to other PDF
  45916. // files, which we thus attempt to support (utilizing `docBaseUrl`).
  45917. case 'GoToR':
  45918. var urlDict = action.get('F');
  45919. if (isDict(urlDict)) {
  45920. // We assume that we found a FileSpec dictionary
  45921. // and fetch the URL without checking any further.
  45922. url = urlDict.get('F') || null;
  45923. } else if (isString(urlDict)) {
  45924. url = urlDict;
  45925. }
  45926. // NOTE: the destination is relative to the *remote* document.
  45927. var remoteDest = action.get('D');
  45928. if (remoteDest) {
  45929. if (isName(remoteDest)) {
  45930. remoteDest = remoteDest.name;
  45931. }
  45932. if (isString(url)) {
  45933. var baseUrl = url.split('#')[0];
  45934. if (isString(remoteDest)) {
  45935. // In practice, a named destination may contain only a number.
  45936. // If that happens, use the '#nameddest=' form to avoid the link
  45937. // redirecting to a page, instead of the correct destination.
  45938. url = baseUrl + '#' + (/^\d+$/.test(remoteDest) ? 'nameddest=' : '') + remoteDest;
  45939. } else if (isArray(remoteDest)) {
  45940. url = baseUrl + '#' + JSON.stringify(remoteDest);
  45941. }
  45942. }
  45943. }
  45944. // The 'NewWindow' property, equal to `LinkTarget.BLANK`.
  45945. var newWindow = action.get('NewWindow');
  45946. if (isBool(newWindow)) {
  45947. resultObj.newWindow = newWindow;
  45948. }
  45949. break;
  45950. case 'Named':
  45951. var namedAction = action.get('N');
  45952. if (isName(namedAction)) {
  45953. resultObj.action = namedAction.name;
  45954. }
  45955. break;
  45956. case 'JavaScript':
  45957. var jsAction = action.get('JS'), js;
  45958. if (isStream(jsAction)) {
  45959. js = bytesToString(jsAction.getBytes());
  45960. } else if (isString(jsAction)) {
  45961. js = jsAction;
  45962. }
  45963. if (js) {
  45964. // Attempt to recover valid URLs from 'JS' entries with certain
  45965. // white-listed formats, e.g.
  45966. // - window.open('http://example.com')
  45967. // - app.launchURL('http://example.com', true)
  45968. var URL_OPEN_METHODS = [
  45969. 'app.launchURL',
  45970. 'window.open'
  45971. ];
  45972. var regex = new RegExp('^(?:' + URL_OPEN_METHODS.join('|') + ')' + '\\((?:\'|\")(\\S+)(?:\'|\")(?:,|\\))');
  45973. var jsUrl = regex.exec(stringToPDFString(js), 'i');
  45974. if (jsUrl && jsUrl[1]) {
  45975. url = jsUrl[1];
  45976. break;
  45977. }
  45978. }
  45979. default:
  45980. warn('Catalog_parseDestDictionary: Unrecognized link type "' + linkType + '".');
  45981. break;
  45982. }
  45983. } else if (destDict.has('Dest')) {
  45984. // Simple destination link.
  45985. dest = destDict.get('Dest');
  45986. }
  45987. if (isString(url)) {
  45988. url = tryConvertUrlEncoding(url);
  45989. var absoluteUrl = createValidAbsoluteUrl(url, docBaseUrl);
  45990. if (absoluteUrl) {
  45991. resultObj.url = absoluteUrl.href;
  45992. }
  45993. resultObj.unsafeUrl = url;
  45994. }
  45995. if (dest) {
  45996. if (isName(dest)) {
  45997. dest = dest.name;
  45998. }
  45999. if (isString(dest) || isArray(dest)) {
  46000. resultObj.dest = dest;
  46001. }
  46002. }
  46003. };
  46004. return Catalog;
  46005. }();
  46006. var XRef = function XRefClosure() {
  46007. function XRef(stream, password) {
  46008. this.stream = stream;
  46009. this.entries = [];
  46010. this.xrefstms = Object.create(null);
  46011. // prepare the XRef cache
  46012. this.cache = [];
  46013. this.password = password;
  46014. this.stats = {
  46015. streamTypes: [],
  46016. fontTypes: []
  46017. };
  46018. }
  46019. XRef.prototype = {
  46020. setStartXRef: function XRef_setStartXRef(startXRef) {
  46021. // Store the starting positions of xref tables as we process them
  46022. // so we can recover from missing data errors
  46023. this.startXRefQueue = [startXRef];
  46024. },
  46025. parse: function XRef_parse(recoveryMode) {
  46026. var trailerDict;
  46027. if (!recoveryMode) {
  46028. trailerDict = this.readXRef();
  46029. } else {
  46030. warn('Indexing all PDF objects');
  46031. trailerDict = this.indexObjects();
  46032. }
  46033. trailerDict.assignXref(this);
  46034. this.trailer = trailerDict;
  46035. var encrypt = trailerDict.get('Encrypt');
  46036. if (encrypt) {
  46037. var ids = trailerDict.get('ID');
  46038. var fileId = ids && ids.length ? ids[0] : '';
  46039. // The 'Encrypt' dictionary itself should not be encrypted, and by
  46040. // setting `suppressEncryption` we can prevent an infinite loop inside
  46041. // of `XRef_fetchUncompressed` if the dictionary contains indirect
  46042. // objects (fixes issue7665.pdf).
  46043. encrypt.suppressEncryption = true;
  46044. this.encrypt = new CipherTransformFactory(encrypt, fileId, this.password);
  46045. }
  46046. // get the root dictionary (catalog) object
  46047. if (!(this.root = trailerDict.get('Root'))) {
  46048. error('Invalid root reference');
  46049. }
  46050. },
  46051. processXRefTable: function XRef_processXRefTable(parser) {
  46052. if (!('tableState' in this)) {
  46053. // Stores state of the table as we process it so we can resume
  46054. // from middle of table in case of missing data error
  46055. this.tableState = {
  46056. entryNum: 0,
  46057. streamPos: parser.lexer.stream.pos,
  46058. parserBuf1: parser.buf1,
  46059. parserBuf2: parser.buf2
  46060. };
  46061. }
  46062. var obj = this.readXRefTable(parser);
  46063. // Sanity check
  46064. if (!isCmd(obj, 'trailer')) {
  46065. error('Invalid XRef table: could not find trailer dictionary');
  46066. }
  46067. // Read trailer dictionary, e.g.
  46068. // trailer
  46069. // << /Size 22
  46070. // /Root 20R
  46071. // /Info 10R
  46072. // /ID [ <81b14aafa313db63dbd6f981e49f94f4> ]
  46073. // >>
  46074. // The parser goes through the entire stream << ... >> and provides
  46075. // a getter interface for the key-value table
  46076. var dict = parser.getObj();
  46077. // The pdflib PDF generator can generate a nested trailer dictionary
  46078. if (!isDict(dict) && dict.dict) {
  46079. dict = dict.dict;
  46080. }
  46081. if (!isDict(dict)) {
  46082. error('Invalid XRef table: could not parse trailer dictionary');
  46083. }
  46084. delete this.tableState;
  46085. return dict;
  46086. },
  46087. readXRefTable: function XRef_readXRefTable(parser) {
  46088. // Example of cross-reference table:
  46089. // xref
  46090. // 0 1 <-- subsection header (first obj #, obj count)
  46091. // 0000000000 65535 f <-- actual object (offset, generation #, f/n)
  46092. // 23 2 <-- subsection header ... and so on ...
  46093. // 0000025518 00002 n
  46094. // 0000025635 00000 n
  46095. // trailer
  46096. // ...
  46097. var stream = parser.lexer.stream;
  46098. var tableState = this.tableState;
  46099. stream.pos = tableState.streamPos;
  46100. parser.buf1 = tableState.parserBuf1;
  46101. parser.buf2 = tableState.parserBuf2;
  46102. // Outer loop is over subsection headers
  46103. var obj;
  46104. while (true) {
  46105. if (!('firstEntryNum' in tableState) || !('entryCount' in tableState)) {
  46106. if (isCmd(obj = parser.getObj(), 'trailer')) {
  46107. break;
  46108. }
  46109. tableState.firstEntryNum = obj;
  46110. tableState.entryCount = parser.getObj();
  46111. }
  46112. var first = tableState.firstEntryNum;
  46113. var count = tableState.entryCount;
  46114. if (!isInt(first) || !isInt(count)) {
  46115. error('Invalid XRef table: wrong types in subsection header');
  46116. }
  46117. // Inner loop is over objects themselves
  46118. for (var i = tableState.entryNum; i < count; i++) {
  46119. tableState.streamPos = stream.pos;
  46120. tableState.entryNum = i;
  46121. tableState.parserBuf1 = parser.buf1;
  46122. tableState.parserBuf2 = parser.buf2;
  46123. var entry = {};
  46124. entry.offset = parser.getObj();
  46125. entry.gen = parser.getObj();
  46126. var type = parser.getObj();
  46127. if (isCmd(type, 'f')) {
  46128. entry.free = true;
  46129. } else if (isCmd(type, 'n')) {
  46130. entry.uncompressed = true;
  46131. }
  46132. // Validate entry obj
  46133. if (!isInt(entry.offset) || !isInt(entry.gen) || !(entry.free || entry.uncompressed)) {
  46134. error('Invalid entry in XRef subsection: ' + first + ', ' + count);
  46135. }
  46136. // The first xref table entry, i.e. obj 0, should be free. Attempting
  46137. // to adjust an incorrect first obj # (fixes issue 3248 and 7229).
  46138. if (i === 0 && entry.free && first === 1) {
  46139. first = 0;
  46140. }
  46141. if (!this.entries[i + first]) {
  46142. this.entries[i + first] = entry;
  46143. }
  46144. }
  46145. tableState.entryNum = 0;
  46146. tableState.streamPos = stream.pos;
  46147. tableState.parserBuf1 = parser.buf1;
  46148. tableState.parserBuf2 = parser.buf2;
  46149. delete tableState.firstEntryNum;
  46150. delete tableState.entryCount;
  46151. }
  46152. // Sanity check: as per spec, first object must be free
  46153. if (this.entries[0] && !this.entries[0].free) {
  46154. error('Invalid XRef table: unexpected first object');
  46155. }
  46156. return obj;
  46157. },
  46158. processXRefStream: function XRef_processXRefStream(stream) {
  46159. if (!('streamState' in this)) {
  46160. // Stores state of the stream as we process it so we can resume
  46161. // from middle of stream in case of missing data error
  46162. var streamParameters = stream.dict;
  46163. var byteWidths = streamParameters.get('W');
  46164. var range = streamParameters.get('Index');
  46165. if (!range) {
  46166. range = [
  46167. 0,
  46168. streamParameters.get('Size')
  46169. ];
  46170. }
  46171. this.streamState = {
  46172. entryRanges: range,
  46173. byteWidths: byteWidths,
  46174. entryNum: 0,
  46175. streamPos: stream.pos
  46176. };
  46177. }
  46178. this.readXRefStream(stream);
  46179. delete this.streamState;
  46180. return stream.dict;
  46181. },
  46182. readXRefStream: function XRef_readXRefStream(stream) {
  46183. var i, j;
  46184. var streamState = this.streamState;
  46185. stream.pos = streamState.streamPos;
  46186. var byteWidths = streamState.byteWidths;
  46187. var typeFieldWidth = byteWidths[0];
  46188. var offsetFieldWidth = byteWidths[1];
  46189. var generationFieldWidth = byteWidths[2];
  46190. var entryRanges = streamState.entryRanges;
  46191. while (entryRanges.length > 0) {
  46192. var first = entryRanges[0];
  46193. var n = entryRanges[1];
  46194. if (!isInt(first) || !isInt(n)) {
  46195. error('Invalid XRef range fields: ' + first + ', ' + n);
  46196. }
  46197. if (!isInt(typeFieldWidth) || !isInt(offsetFieldWidth) || !isInt(generationFieldWidth)) {
  46198. error('Invalid XRef entry fields length: ' + first + ', ' + n);
  46199. }
  46200. for (i = streamState.entryNum; i < n; ++i) {
  46201. streamState.entryNum = i;
  46202. streamState.streamPos = stream.pos;
  46203. var type = 0, offset = 0, generation = 0;
  46204. for (j = 0; j < typeFieldWidth; ++j) {
  46205. type = type << 8 | stream.getByte();
  46206. }
  46207. // if type field is absent, its default value is 1
  46208. if (typeFieldWidth === 0) {
  46209. type = 1;
  46210. }
  46211. for (j = 0; j < offsetFieldWidth; ++j) {
  46212. offset = offset << 8 | stream.getByte();
  46213. }
  46214. for (j = 0; j < generationFieldWidth; ++j) {
  46215. generation = generation << 8 | stream.getByte();
  46216. }
  46217. var entry = {};
  46218. entry.offset = offset;
  46219. entry.gen = generation;
  46220. switch (type) {
  46221. case 0:
  46222. entry.free = true;
  46223. break;
  46224. case 1:
  46225. entry.uncompressed = true;
  46226. break;
  46227. case 2:
  46228. break;
  46229. default:
  46230. error('Invalid XRef entry type: ' + type);
  46231. }
  46232. if (!this.entries[first + i]) {
  46233. this.entries[first + i] = entry;
  46234. }
  46235. }
  46236. streamState.entryNum = 0;
  46237. streamState.streamPos = stream.pos;
  46238. entryRanges.splice(0, 2);
  46239. }
  46240. },
  46241. indexObjects: function XRef_indexObjects() {
  46242. // Simple scan through the PDF content to find objects,
  46243. // trailers and XRef streams.
  46244. var TAB = 0x9, LF = 0xA, CR = 0xD, SPACE = 0x20;
  46245. var PERCENT = 0x25, LT = 0x3C;
  46246. function readToken(data, offset) {
  46247. var token = '', ch = data[offset];
  46248. while (ch !== LF && ch !== CR && ch !== LT) {
  46249. if (++offset >= data.length) {
  46250. break;
  46251. }
  46252. token += String.fromCharCode(ch);
  46253. ch = data[offset];
  46254. }
  46255. return token;
  46256. }
  46257. function skipUntil(data, offset, what) {
  46258. var length = what.length, dataLength = data.length;
  46259. var skipped = 0;
  46260. // finding byte sequence
  46261. while (offset < dataLength) {
  46262. var i = 0;
  46263. while (i < length && data[offset + i] === what[i]) {
  46264. ++i;
  46265. }
  46266. if (i >= length) {
  46267. break;
  46268. }
  46269. // sequence found
  46270. offset++;
  46271. skipped++;
  46272. }
  46273. return skipped;
  46274. }
  46275. var objRegExp = /^(\d+)\s+(\d+)\s+obj\b/;
  46276. var trailerBytes = new Uint8Array([
  46277. 116,
  46278. 114,
  46279. 97,
  46280. 105,
  46281. 108,
  46282. 101,
  46283. 114
  46284. ]);
  46285. var startxrefBytes = new Uint8Array([
  46286. 115,
  46287. 116,
  46288. 97,
  46289. 114,
  46290. 116,
  46291. 120,
  46292. 114,
  46293. 101,
  46294. 102
  46295. ]);
  46296. var endobjBytes = new Uint8Array([
  46297. 101,
  46298. 110,
  46299. 100,
  46300. 111,
  46301. 98,
  46302. 106
  46303. ]);
  46304. var xrefBytes = new Uint8Array([
  46305. 47,
  46306. 88,
  46307. 82,
  46308. 101,
  46309. 102
  46310. ]);
  46311. // Clear out any existing entries, since they may be bogus.
  46312. this.entries.length = 0;
  46313. var stream = this.stream;
  46314. stream.pos = 0;
  46315. var buffer = stream.getBytes();
  46316. var position = stream.start, length = buffer.length;
  46317. var trailers = [], xrefStms = [];
  46318. while (position < length) {
  46319. var ch = buffer[position];
  46320. if (ch === TAB || ch === LF || ch === CR || ch === SPACE) {
  46321. ++position;
  46322. continue;
  46323. }
  46324. if (ch === PERCENT) {
  46325. // %-comment
  46326. do {
  46327. ++position;
  46328. if (position >= length) {
  46329. break;
  46330. }
  46331. ch = buffer[position];
  46332. } while (ch !== LF && ch !== CR);
  46333. continue;
  46334. }
  46335. var token = readToken(buffer, position);
  46336. var m;
  46337. if (token.indexOf('xref') === 0 && (token.length === 4 || /\s/.test(token[4]))) {
  46338. position += skipUntil(buffer, position, trailerBytes);
  46339. trailers.push(position);
  46340. position += skipUntil(buffer, position, startxrefBytes);
  46341. } else if (m = objRegExp.exec(token)) {
  46342. if (typeof this.entries[m[1]] === 'undefined') {
  46343. this.entries[m[1]] = {
  46344. offset: position - stream.start,
  46345. gen: m[2] | 0,
  46346. uncompressed: true
  46347. };
  46348. }
  46349. var contentLength = skipUntil(buffer, position, endobjBytes) + 7;
  46350. var content = buffer.subarray(position, position + contentLength);
  46351. // checking XRef stream suspect
  46352. // (it shall have '/XRef' and next char is not a letter)
  46353. var xrefTagOffset = skipUntil(content, 0, xrefBytes);
  46354. if (xrefTagOffset < contentLength && content[xrefTagOffset + 5] < 64) {
  46355. xrefStms.push(position - stream.start);
  46356. this.xrefstms[position - stream.start] = 1;
  46357. }
  46358. // Avoid recursion
  46359. position += contentLength;
  46360. } else if (token.indexOf('trailer') === 0 && (token.length === 7 || /\s/.test(token[7]))) {
  46361. trailers.push(position);
  46362. position += skipUntil(buffer, position, startxrefBytes);
  46363. } else {
  46364. position += token.length + 1;
  46365. }
  46366. }
  46367. // reading XRef streams
  46368. var i, ii;
  46369. for (i = 0, ii = xrefStms.length; i < ii; ++i) {
  46370. this.startXRefQueue.push(xrefStms[i]);
  46371. this.readXRef(/* recoveryMode */
  46372. true);
  46373. }
  46374. // finding main trailer
  46375. var dict;
  46376. for (i = 0, ii = trailers.length; i < ii; ++i) {
  46377. stream.pos = trailers[i];
  46378. var parser = new Parser(new Lexer(stream), /* allowStreams = */
  46379. true, /* xref = */
  46380. this, /* recoveryMode = */
  46381. true);
  46382. var obj = parser.getObj();
  46383. if (!isCmd(obj, 'trailer')) {
  46384. continue;
  46385. }
  46386. // read the trailer dictionary
  46387. dict = parser.getObj();
  46388. if (!isDict(dict)) {
  46389. continue;
  46390. }
  46391. // taking the first one with 'ID'
  46392. if (dict.has('ID')) {
  46393. return dict;
  46394. }
  46395. }
  46396. // no tailer with 'ID', taking last one (if exists)
  46397. if (dict) {
  46398. return dict;
  46399. }
  46400. // nothing helps
  46401. // calling error() would reject worker with an UnknownErrorException.
  46402. throw new InvalidPDFException('Invalid PDF structure');
  46403. },
  46404. readXRef: function XRef_readXRef(recoveryMode) {
  46405. var stream = this.stream;
  46406. try {
  46407. while (this.startXRefQueue.length) {
  46408. var startXRef = this.startXRefQueue[0];
  46409. stream.pos = startXRef + stream.start;
  46410. var parser = new Parser(new Lexer(stream), true, this);
  46411. var obj = parser.getObj();
  46412. var dict;
  46413. // Get dictionary
  46414. if (isCmd(obj, 'xref')) {
  46415. // Parse end-of-file XRef
  46416. dict = this.processXRefTable(parser);
  46417. if (!this.topDict) {
  46418. this.topDict = dict;
  46419. }
  46420. // Recursively get other XRefs 'XRefStm', if any
  46421. obj = dict.get('XRefStm');
  46422. if (isInt(obj)) {
  46423. var pos = obj;
  46424. // ignore previously loaded xref streams
  46425. // (possible infinite recursion)
  46426. if (!(pos in this.xrefstms)) {
  46427. this.xrefstms[pos] = 1;
  46428. this.startXRefQueue.push(pos);
  46429. }
  46430. }
  46431. } else if (isInt(obj)) {
  46432. // Parse in-stream XRef
  46433. if (!isInt(parser.getObj()) || !isCmd(parser.getObj(), 'obj') || !isStream(obj = parser.getObj())) {
  46434. error('Invalid XRef stream');
  46435. }
  46436. dict = this.processXRefStream(obj);
  46437. if (!this.topDict) {
  46438. this.topDict = dict;
  46439. }
  46440. if (!dict) {
  46441. error('Failed to read XRef stream');
  46442. }
  46443. } else {
  46444. error('Invalid XRef stream header');
  46445. }
  46446. // Recursively get previous dictionary, if any
  46447. obj = dict.get('Prev');
  46448. if (isInt(obj)) {
  46449. this.startXRefQueue.push(obj);
  46450. } else if (isRef(obj)) {
  46451. // The spec says Prev must not be a reference, i.e. "/Prev NNN"
  46452. // This is a fallback for non-compliant PDFs, i.e. "/Prev NNN 0 R"
  46453. this.startXRefQueue.push(obj.num);
  46454. }
  46455. this.startXRefQueue.shift();
  46456. }
  46457. return this.topDict;
  46458. } catch (e) {
  46459. if (e instanceof MissingDataException) {
  46460. throw e;
  46461. }
  46462. info('(while reading XRef): ' + e);
  46463. }
  46464. if (recoveryMode) {
  46465. return;
  46466. }
  46467. throw new XRefParseException();
  46468. },
  46469. getEntry: function XRef_getEntry(i) {
  46470. var xrefEntry = this.entries[i];
  46471. if (xrefEntry && !xrefEntry.free && xrefEntry.offset) {
  46472. return xrefEntry;
  46473. }
  46474. return null;
  46475. },
  46476. fetchIfRef: function XRef_fetchIfRef(obj, suppressEncryption) {
  46477. if (!isRef(obj)) {
  46478. return obj;
  46479. }
  46480. return this.fetch(obj, suppressEncryption);
  46481. },
  46482. fetch: function XRef_fetch(ref, suppressEncryption) {
  46483. assert(isRef(ref), 'ref object is not a reference');
  46484. var num = ref.num;
  46485. if (num in this.cache) {
  46486. var cacheEntry = this.cache[num];
  46487. return cacheEntry;
  46488. }
  46489. var xrefEntry = this.getEntry(num);
  46490. // the referenced entry can be free
  46491. if (xrefEntry === null) {
  46492. return this.cache[num] = null;
  46493. }
  46494. if (xrefEntry.uncompressed) {
  46495. xrefEntry = this.fetchUncompressed(ref, xrefEntry, suppressEncryption);
  46496. } else {
  46497. xrefEntry = this.fetchCompressed(xrefEntry, suppressEncryption);
  46498. }
  46499. if (isDict(xrefEntry)) {
  46500. xrefEntry.objId = ref.toString();
  46501. } else if (isStream(xrefEntry)) {
  46502. xrefEntry.dict.objId = ref.toString();
  46503. }
  46504. return xrefEntry;
  46505. },
  46506. fetchUncompressed: function XRef_fetchUncompressed(ref, xrefEntry, suppressEncryption) {
  46507. var gen = ref.gen;
  46508. var num = ref.num;
  46509. if (xrefEntry.gen !== gen) {
  46510. error('inconsistent generation in XRef');
  46511. }
  46512. var stream = this.stream.makeSubStream(xrefEntry.offset + this.stream.start);
  46513. var parser = new Parser(new Lexer(stream), true, this);
  46514. var obj1 = parser.getObj();
  46515. var obj2 = parser.getObj();
  46516. var obj3 = parser.getObj();
  46517. if (!isInt(obj1) || parseInt(obj1, 10) !== num || !isInt(obj2) || parseInt(obj2, 10) !== gen || !isCmd(obj3)) {
  46518. error('bad XRef entry');
  46519. }
  46520. if (!isCmd(obj3, 'obj')) {
  46521. // some bad PDFs use "obj1234" and really mean 1234
  46522. if (obj3.cmd.indexOf('obj') === 0) {
  46523. num = parseInt(obj3.cmd.substring(3), 10);
  46524. if (!isNaN(num)) {
  46525. return num;
  46526. }
  46527. }
  46528. error('bad XRef entry');
  46529. }
  46530. if (this.encrypt && !suppressEncryption) {
  46531. xrefEntry = parser.getObj(this.encrypt.createCipherTransform(num, gen));
  46532. } else {
  46533. xrefEntry = parser.getObj();
  46534. }
  46535. if (!isStream(xrefEntry)) {
  46536. this.cache[num] = xrefEntry;
  46537. }
  46538. return xrefEntry;
  46539. },
  46540. fetchCompressed: function XRef_fetchCompressed(xrefEntry, suppressEncryption) {
  46541. var tableOffset = xrefEntry.offset;
  46542. var stream = this.fetch(new Ref(tableOffset, 0));
  46543. if (!isStream(stream)) {
  46544. error('bad ObjStm stream');
  46545. }
  46546. var first = stream.dict.get('First');
  46547. var n = stream.dict.get('N');
  46548. if (!isInt(first) || !isInt(n)) {
  46549. error('invalid first and n parameters for ObjStm stream');
  46550. }
  46551. var parser = new Parser(new Lexer(stream), false, this);
  46552. parser.allowStreams = true;
  46553. var i, entries = [], num, nums = [];
  46554. // read the object numbers to populate cache
  46555. for (i = 0; i < n; ++i) {
  46556. num = parser.getObj();
  46557. if (!isInt(num)) {
  46558. error('invalid object number in the ObjStm stream: ' + num);
  46559. }
  46560. nums.push(num);
  46561. var offset = parser.getObj();
  46562. if (!isInt(offset)) {
  46563. error('invalid object offset in the ObjStm stream: ' + offset);
  46564. }
  46565. }
  46566. // read stream objects for cache
  46567. for (i = 0; i < n; ++i) {
  46568. entries.push(parser.getObj());
  46569. // The ObjStm should not contain 'endobj'. If it's present, skip over it
  46570. // to support corrupt PDFs (fixes issue 5241, bug 898610, bug 1037816).
  46571. if (isCmd(parser.buf1, 'endobj')) {
  46572. parser.shift();
  46573. }
  46574. num = nums[i];
  46575. var entry = this.entries[num];
  46576. if (entry && entry.offset === tableOffset && entry.gen === i) {
  46577. this.cache[num] = entries[i];
  46578. }
  46579. }
  46580. xrefEntry = entries[xrefEntry.gen];
  46581. if (xrefEntry === undefined) {
  46582. error('bad XRef entry for compressed object');
  46583. }
  46584. return xrefEntry;
  46585. },
  46586. fetchIfRefAsync: function XRef_fetchIfRefAsync(obj, suppressEncryption) {
  46587. if (!isRef(obj)) {
  46588. return Promise.resolve(obj);
  46589. }
  46590. return this.fetchAsync(obj, suppressEncryption);
  46591. },
  46592. fetchAsync: function XRef_fetchAsync(ref, suppressEncryption) {
  46593. var streamManager = this.stream.manager;
  46594. var xref = this;
  46595. return new Promise(function tryFetch(resolve, reject) {
  46596. try {
  46597. resolve(xref.fetch(ref, suppressEncryption));
  46598. } catch (e) {
  46599. if (e instanceof MissingDataException) {
  46600. streamManager.requestRange(e.begin, e.end).then(function () {
  46601. tryFetch(resolve, reject);
  46602. }, reject);
  46603. return;
  46604. }
  46605. reject(e);
  46606. }
  46607. });
  46608. },
  46609. getCatalogObj: function XRef_getCatalogObj() {
  46610. return this.root;
  46611. }
  46612. };
  46613. return XRef;
  46614. }();
  46615. /**
  46616. * A NameTree/NumberTree is like a Dict but has some advantageous properties,
  46617. * see the specification (7.9.6 and 7.9.7) for additional details.
  46618. * TODO: implement all the Dict functions and make this more efficient.
  46619. */
  46620. var NameOrNumberTree = function NameOrNumberTreeClosure() {
  46621. function NameOrNumberTree(root, xref) {
  46622. throw new Error('Cannot initialize NameOrNumberTree.');
  46623. }
  46624. NameOrNumberTree.prototype = {
  46625. getAll: function NameOrNumberTree_getAll() {
  46626. var dict = Object.create(null);
  46627. if (!this.root) {
  46628. return dict;
  46629. }
  46630. var xref = this.xref;
  46631. // Reading Name/Number tree.
  46632. var processed = new RefSet();
  46633. processed.put(this.root);
  46634. var queue = [this.root];
  46635. while (queue.length > 0) {
  46636. var i, n;
  46637. var obj = xref.fetchIfRef(queue.shift());
  46638. if (!isDict(obj)) {
  46639. continue;
  46640. }
  46641. if (obj.has('Kids')) {
  46642. var kids = obj.get('Kids');
  46643. for (i = 0, n = kids.length; i < n; i++) {
  46644. var kid = kids[i];
  46645. assert(!processed.has(kid), 'Duplicate entry in "' + this._type + '" tree.');
  46646. queue.push(kid);
  46647. processed.put(kid);
  46648. }
  46649. continue;
  46650. }
  46651. var entries = obj.get(this._type);
  46652. if (isArray(entries)) {
  46653. for (i = 0, n = entries.length; i < n; i += 2) {
  46654. dict[xref.fetchIfRef(entries[i])] = xref.fetchIfRef(entries[i + 1]);
  46655. }
  46656. }
  46657. }
  46658. return dict;
  46659. },
  46660. get: function NameOrNumberTree_get(key) {
  46661. if (!this.root) {
  46662. return null;
  46663. }
  46664. var xref = this.xref;
  46665. var kidsOrEntries = xref.fetchIfRef(this.root);
  46666. var loopCount = 0;
  46667. var MAX_LEVELS = 10;
  46668. var l, r, m;
  46669. // Perform a binary search to quickly find the entry that
  46670. // contains the key we are looking for.
  46671. while (kidsOrEntries.has('Kids')) {
  46672. if (++loopCount > MAX_LEVELS) {
  46673. warn('Search depth limit reached for "' + this._type + '" tree.');
  46674. return null;
  46675. }
  46676. var kids = kidsOrEntries.get('Kids');
  46677. if (!isArray(kids)) {
  46678. return null;
  46679. }
  46680. l = 0;
  46681. r = kids.length - 1;
  46682. while (l <= r) {
  46683. m = l + r >> 1;
  46684. var kid = xref.fetchIfRef(kids[m]);
  46685. var limits = kid.get('Limits');
  46686. if (key < xref.fetchIfRef(limits[0])) {
  46687. r = m - 1;
  46688. } else if (key > xref.fetchIfRef(limits[1])) {
  46689. l = m + 1;
  46690. } else {
  46691. kidsOrEntries = xref.fetchIfRef(kids[m]);
  46692. break;
  46693. }
  46694. }
  46695. if (l > r) {
  46696. return null;
  46697. }
  46698. }
  46699. // If we get here, then we have found the right entry. Now go through the
  46700. // entries in the dictionary until we find the key we're looking for.
  46701. var entries = kidsOrEntries.get(this._type);
  46702. if (isArray(entries)) {
  46703. // Perform a binary search to reduce the lookup time.
  46704. l = 0;
  46705. r = entries.length - 2;
  46706. while (l <= r) {
  46707. // Check only even indices (0, 2, 4, ...) because the
  46708. // odd indices contain the actual data.
  46709. m = l + r & ~1;
  46710. var currentKey = xref.fetchIfRef(entries[m]);
  46711. if (key < currentKey) {
  46712. r = m - 2;
  46713. } else if (key > currentKey) {
  46714. l = m + 2;
  46715. } else {
  46716. return xref.fetchIfRef(entries[m + 1]);
  46717. }
  46718. }
  46719. }
  46720. return null;
  46721. }
  46722. };
  46723. return NameOrNumberTree;
  46724. }();
  46725. var NameTree = function NameTreeClosure() {
  46726. function NameTree(root, xref) {
  46727. this.root = root;
  46728. this.xref = xref;
  46729. this._type = 'Names';
  46730. }
  46731. Util.inherit(NameTree, NameOrNumberTree, {});
  46732. return NameTree;
  46733. }();
  46734. var NumberTree = function NumberTreeClosure() {
  46735. function NumberTree(root, xref) {
  46736. this.root = root;
  46737. this.xref = xref;
  46738. this._type = 'Nums';
  46739. }
  46740. Util.inherit(NumberTree, NameOrNumberTree, {});
  46741. return NumberTree;
  46742. }();
  46743. /**
  46744. * "A PDF file can refer to the contents of another file by using a File
  46745. * Specification (PDF 1.1)", see the spec (7.11) for more details.
  46746. * NOTE: Only embedded files are supported (as part of the attachments support)
  46747. * TODO: support the 'URL' file system (with caching if !/V), portable
  46748. * collections attributes and related files (/RF)
  46749. */
  46750. var FileSpec = function FileSpecClosure() {
  46751. function FileSpec(root, xref) {
  46752. if (!root || !isDict(root)) {
  46753. return;
  46754. }
  46755. this.xref = xref;
  46756. this.root = root;
  46757. if (root.has('FS')) {
  46758. this.fs = root.get('FS');
  46759. }
  46760. this.description = root.has('Desc') ? stringToPDFString(root.get('Desc')) : '';
  46761. if (root.has('RF')) {
  46762. warn('Related file specifications are not supported');
  46763. }
  46764. this.contentAvailable = true;
  46765. if (!root.has('EF')) {
  46766. this.contentAvailable = false;
  46767. warn('Non-embedded file specifications are not supported');
  46768. }
  46769. }
  46770. function pickPlatformItem(dict) {
  46771. // Look for the filename in this order:
  46772. // UF, F, Unix, Mac, DOS
  46773. if (dict.has('UF')) {
  46774. return dict.get('UF');
  46775. } else if (dict.has('F')) {
  46776. return dict.get('F');
  46777. } else if (dict.has('Unix')) {
  46778. return dict.get('Unix');
  46779. } else if (dict.has('Mac')) {
  46780. return dict.get('Mac');
  46781. } else if (dict.has('DOS')) {
  46782. return dict.get('DOS');
  46783. } else {
  46784. return null;
  46785. }
  46786. }
  46787. FileSpec.prototype = {
  46788. get filename() {
  46789. if (!this._filename && this.root) {
  46790. var filename = pickPlatformItem(this.root) || 'unnamed';
  46791. this._filename = stringToPDFString(filename).replace(/\\\\/g, '\\').replace(/\\\//g, '/').replace(/\\/g, '/');
  46792. }
  46793. return this._filename;
  46794. },
  46795. get content() {
  46796. if (!this.contentAvailable) {
  46797. return null;
  46798. }
  46799. if (!this.contentRef && this.root) {
  46800. this.contentRef = pickPlatformItem(this.root.get('EF'));
  46801. }
  46802. var content = null;
  46803. if (this.contentRef) {
  46804. var xref = this.xref;
  46805. var fileObj = xref.fetchIfRef(this.contentRef);
  46806. if (fileObj && isStream(fileObj)) {
  46807. content = fileObj.getBytes();
  46808. } else {
  46809. warn('Embedded file specification points to non-existing/invalid ' + 'content');
  46810. }
  46811. } else {
  46812. warn('Embedded file specification does not have a content');
  46813. }
  46814. return content;
  46815. },
  46816. get serializable() {
  46817. return {
  46818. filename: this.filename,
  46819. content: this.content
  46820. };
  46821. }
  46822. };
  46823. return FileSpec;
  46824. }();
  46825. /**
  46826. * A helper for loading missing data in object graphs. It traverses the graph
  46827. * depth first and queues up any objects that have missing data. Once it has
  46828. * has traversed as many objects that are available it attempts to bundle the
  46829. * missing data requests and then resume from the nodes that weren't ready.
  46830. *
  46831. * NOTE: It provides protection from circular references by keeping track of
  46832. * of loaded references. However, you must be careful not to load any graphs
  46833. * that have references to the catalog or other pages since that will cause the
  46834. * entire PDF document object graph to be traversed.
  46835. */
  46836. var ObjectLoader = function () {
  46837. function mayHaveChildren(value) {
  46838. return isRef(value) || isDict(value) || isArray(value) || isStream(value);
  46839. }
  46840. function addChildren(node, nodesToVisit) {
  46841. var value;
  46842. if (isDict(node) || isStream(node)) {
  46843. var map;
  46844. if (isDict(node)) {
  46845. map = node.map;
  46846. } else {
  46847. map = node.dict.map;
  46848. }
  46849. for (var key in map) {
  46850. value = map[key];
  46851. if (mayHaveChildren(value)) {
  46852. nodesToVisit.push(value);
  46853. }
  46854. }
  46855. } else if (isArray(node)) {
  46856. for (var i = 0, ii = node.length; i < ii; i++) {
  46857. value = node[i];
  46858. if (mayHaveChildren(value)) {
  46859. nodesToVisit.push(value);
  46860. }
  46861. }
  46862. }
  46863. }
  46864. function ObjectLoader(obj, keys, xref) {
  46865. this.obj = obj;
  46866. this.keys = keys;
  46867. this.xref = xref;
  46868. this.refSet = null;
  46869. this.capability = null;
  46870. }
  46871. ObjectLoader.prototype = {
  46872. load: function ObjectLoader_load() {
  46873. var keys = this.keys;
  46874. this.capability = createPromiseCapability();
  46875. // Don't walk the graph if all the data is already loaded.
  46876. if (!(this.xref.stream instanceof ChunkedStream) || this.xref.stream.getMissingChunks().length === 0) {
  46877. this.capability.resolve();
  46878. return this.capability.promise;
  46879. }
  46880. this.refSet = new RefSet();
  46881. // Setup the initial nodes to visit.
  46882. var nodesToVisit = [];
  46883. for (var i = 0; i < keys.length; i++) {
  46884. nodesToVisit.push(this.obj[keys[i]]);
  46885. }
  46886. this._walk(nodesToVisit);
  46887. return this.capability.promise;
  46888. },
  46889. _walk: function ObjectLoader_walk(nodesToVisit) {
  46890. var nodesToRevisit = [];
  46891. var pendingRequests = [];
  46892. // DFS walk of the object graph.
  46893. while (nodesToVisit.length) {
  46894. var currentNode = nodesToVisit.pop();
  46895. // Only references or chunked streams can cause missing data exceptions.
  46896. if (isRef(currentNode)) {
  46897. // Skip nodes that have already been visited.
  46898. if (this.refSet.has(currentNode)) {
  46899. continue;
  46900. }
  46901. try {
  46902. var ref = currentNode;
  46903. this.refSet.put(ref);
  46904. currentNode = this.xref.fetch(currentNode);
  46905. } catch (e) {
  46906. if (!(e instanceof MissingDataException)) {
  46907. throw e;
  46908. }
  46909. nodesToRevisit.push(currentNode);
  46910. pendingRequests.push({
  46911. begin: e.begin,
  46912. end: e.end
  46913. });
  46914. }
  46915. }
  46916. if (currentNode && currentNode.getBaseStreams) {
  46917. var baseStreams = currentNode.getBaseStreams();
  46918. var foundMissingData = false;
  46919. for (var i = 0; i < baseStreams.length; i++) {
  46920. var stream = baseStreams[i];
  46921. if (stream.getMissingChunks && stream.getMissingChunks().length) {
  46922. foundMissingData = true;
  46923. pendingRequests.push({
  46924. begin: stream.start,
  46925. end: stream.end
  46926. });
  46927. }
  46928. }
  46929. if (foundMissingData) {
  46930. nodesToRevisit.push(currentNode);
  46931. }
  46932. }
  46933. addChildren(currentNode, nodesToVisit);
  46934. }
  46935. if (pendingRequests.length) {
  46936. this.xref.stream.manager.requestRanges(pendingRequests).then(function pendingRequestCallback() {
  46937. nodesToVisit = nodesToRevisit;
  46938. for (var i = 0; i < nodesToRevisit.length; i++) {
  46939. var node = nodesToRevisit[i];
  46940. // Remove any reference nodes from the currrent refset so they
  46941. // aren't skipped when we revist them.
  46942. if (isRef(node)) {
  46943. this.refSet.remove(node);
  46944. }
  46945. }
  46946. this._walk(nodesToVisit);
  46947. }.bind(this), this.capability.reject);
  46948. return;
  46949. }
  46950. // Everything is loaded.
  46951. this.refSet = null;
  46952. this.capability.resolve();
  46953. }
  46954. };
  46955. return ObjectLoader;
  46956. }();
  46957. exports.Catalog = Catalog;
  46958. exports.ObjectLoader = ObjectLoader;
  46959. exports.XRef = XRef;
  46960. exports.FileSpec = FileSpec;
  46961. }));
  46962. (function (root, factory) {
  46963. factory(root.pdfjsCorePattern = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCoreFunction, root.pdfjsCoreColorSpace);
  46964. }(this, function (exports, sharedUtil, corePrimitives, coreFunction, coreColorSpace) {
  46965. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  46966. var MissingDataException = sharedUtil.MissingDataException;
  46967. var Util = sharedUtil.Util;
  46968. var assert = sharedUtil.assert;
  46969. var error = sharedUtil.error;
  46970. var info = sharedUtil.info;
  46971. var warn = sharedUtil.warn;
  46972. var isStream = corePrimitives.isStream;
  46973. var PDFFunction = coreFunction.PDFFunction;
  46974. var ColorSpace = coreColorSpace.ColorSpace;
  46975. var ShadingType = {
  46976. FUNCTION_BASED: 1,
  46977. AXIAL: 2,
  46978. RADIAL: 3,
  46979. FREE_FORM_MESH: 4,
  46980. LATTICE_FORM_MESH: 5,
  46981. COONS_PATCH_MESH: 6,
  46982. TENSOR_PATCH_MESH: 7
  46983. };
  46984. var Pattern = function PatternClosure() {
  46985. // Constructor should define this.getPattern
  46986. function Pattern() {
  46987. error('should not call Pattern constructor');
  46988. }
  46989. Pattern.prototype = {
  46990. // Input: current Canvas context
  46991. // Output: the appropriate fillStyle or strokeStyle
  46992. getPattern: function Pattern_getPattern(ctx) {
  46993. error('Should not call Pattern.getStyle: ' + ctx);
  46994. }
  46995. };
  46996. Pattern.parseShading = function Pattern_parseShading(shading, matrix, xref, res, handler) {
  46997. var dict = isStream(shading) ? shading.dict : shading;
  46998. var type = dict.get('ShadingType');
  46999. try {
  47000. switch (type) {
  47001. case ShadingType.AXIAL:
  47002. case ShadingType.RADIAL:
  47003. // Both radial and axial shadings are handled by RadialAxial shading.
  47004. return new Shadings.RadialAxial(dict, matrix, xref, res);
  47005. case ShadingType.FREE_FORM_MESH:
  47006. case ShadingType.LATTICE_FORM_MESH:
  47007. case ShadingType.COONS_PATCH_MESH:
  47008. case ShadingType.TENSOR_PATCH_MESH:
  47009. return new Shadings.Mesh(shading, matrix, xref, res);
  47010. default:
  47011. throw new Error('Unsupported ShadingType: ' + type);
  47012. }
  47013. } catch (ex) {
  47014. if (ex instanceof MissingDataException) {
  47015. throw ex;
  47016. }
  47017. handler.send('UnsupportedFeature', { featureId: UNSUPPORTED_FEATURES.shadingPattern });
  47018. warn(ex);
  47019. return new Shadings.Dummy();
  47020. }
  47021. };
  47022. return Pattern;
  47023. }();
  47024. var Shadings = {};
  47025. // A small number to offset the first/last color stops so we can insert ones to
  47026. // support extend. Number.MIN_VALUE is too small and breaks the extend.
  47027. Shadings.SMALL_NUMBER = 1e-6;
  47028. // Radial and axial shading have very similar implementations
  47029. // If needed, the implementations can be broken into two classes
  47030. Shadings.RadialAxial = function RadialAxialClosure() {
  47031. function RadialAxial(dict, matrix, xref, res) {
  47032. this.matrix = matrix;
  47033. this.coordsArr = dict.getArray('Coords');
  47034. this.shadingType = dict.get('ShadingType');
  47035. this.type = 'Pattern';
  47036. var cs = dict.get('ColorSpace', 'CS');
  47037. cs = ColorSpace.parse(cs, xref, res);
  47038. this.cs = cs;
  47039. var t0 = 0.0, t1 = 1.0;
  47040. if (dict.has('Domain')) {
  47041. var domainArr = dict.getArray('Domain');
  47042. t0 = domainArr[0];
  47043. t1 = domainArr[1];
  47044. }
  47045. var extendStart = false, extendEnd = false;
  47046. if (dict.has('Extend')) {
  47047. var extendArr = dict.getArray('Extend');
  47048. extendStart = extendArr[0];
  47049. extendEnd = extendArr[1];
  47050. }
  47051. if (this.shadingType === ShadingType.RADIAL && (!extendStart || !extendEnd)) {
  47052. // Radial gradient only currently works if either circle is fully within
  47053. // the other circle.
  47054. var x1 = this.coordsArr[0];
  47055. var y1 = this.coordsArr[1];
  47056. var r1 = this.coordsArr[2];
  47057. var x2 = this.coordsArr[3];
  47058. var y2 = this.coordsArr[4];
  47059. var r2 = this.coordsArr[5];
  47060. var distance = Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
  47061. if (r1 <= r2 + distance && r2 <= r1 + distance) {
  47062. warn('Unsupported radial gradient.');
  47063. }
  47064. }
  47065. this.extendStart = extendStart;
  47066. this.extendEnd = extendEnd;
  47067. var fnObj = dict.get('Function');
  47068. var fn = PDFFunction.parseArray(xref, fnObj);
  47069. // 10 samples seems good enough for now, but probably won't work
  47070. // if there are sharp color changes. Ideally, we would implement
  47071. // the spec faithfully and add lossless optimizations.
  47072. var diff = t1 - t0;
  47073. var step = diff / 10;
  47074. var colorStops = this.colorStops = [];
  47075. // Protect against bad domains so we don't end up in an infinte loop below.
  47076. if (t0 >= t1 || step <= 0) {
  47077. // Acrobat doesn't seem to handle these cases so we'll ignore for
  47078. // now.
  47079. info('Bad shading domain.');
  47080. return;
  47081. }
  47082. var color = new Float32Array(cs.numComps), ratio = new Float32Array(1);
  47083. var rgbColor;
  47084. for (var i = t0; i <= t1; i += step) {
  47085. ratio[0] = i;
  47086. fn(ratio, 0, color, 0);
  47087. rgbColor = cs.getRgb(color, 0);
  47088. var cssColor = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  47089. colorStops.push([
  47090. (i - t0) / diff,
  47091. cssColor
  47092. ]);
  47093. }
  47094. var background = 'transparent';
  47095. if (dict.has('Background')) {
  47096. rgbColor = cs.getRgb(dict.get('Background'), 0);
  47097. background = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  47098. }
  47099. if (!extendStart) {
  47100. // Insert a color stop at the front and offset the first real color stop
  47101. // so it doesn't conflict with the one we insert.
  47102. colorStops.unshift([
  47103. 0,
  47104. background
  47105. ]);
  47106. colorStops[1][0] += Shadings.SMALL_NUMBER;
  47107. }
  47108. if (!extendEnd) {
  47109. // Same idea as above in extendStart but for the end.
  47110. colorStops[colorStops.length - 1][0] -= Shadings.SMALL_NUMBER;
  47111. colorStops.push([
  47112. 1,
  47113. background
  47114. ]);
  47115. }
  47116. this.colorStops = colorStops;
  47117. }
  47118. RadialAxial.prototype = {
  47119. getIR: function RadialAxial_getIR() {
  47120. var coordsArr = this.coordsArr;
  47121. var shadingType = this.shadingType;
  47122. var type, p0, p1, r0, r1;
  47123. if (shadingType === ShadingType.AXIAL) {
  47124. p0 = [
  47125. coordsArr[0],
  47126. coordsArr[1]
  47127. ];
  47128. p1 = [
  47129. coordsArr[2],
  47130. coordsArr[3]
  47131. ];
  47132. r0 = null;
  47133. r1 = null;
  47134. type = 'axial';
  47135. } else if (shadingType === ShadingType.RADIAL) {
  47136. p0 = [
  47137. coordsArr[0],
  47138. coordsArr[1]
  47139. ];
  47140. p1 = [
  47141. coordsArr[3],
  47142. coordsArr[4]
  47143. ];
  47144. r0 = coordsArr[2];
  47145. r1 = coordsArr[5];
  47146. type = 'radial';
  47147. } else {
  47148. error('getPattern type unknown: ' + shadingType);
  47149. }
  47150. var matrix = this.matrix;
  47151. if (matrix) {
  47152. p0 = Util.applyTransform(p0, matrix);
  47153. p1 = Util.applyTransform(p1, matrix);
  47154. if (shadingType === ShadingType.RADIAL) {
  47155. var scale = Util.singularValueDecompose2dScale(matrix);
  47156. r0 *= scale[0];
  47157. r1 *= scale[1];
  47158. }
  47159. }
  47160. return [
  47161. 'RadialAxial',
  47162. type,
  47163. this.colorStops,
  47164. p0,
  47165. p1,
  47166. r0,
  47167. r1
  47168. ];
  47169. }
  47170. };
  47171. return RadialAxial;
  47172. }();
  47173. // All mesh shading. For now, they will be presented as set of the triangles
  47174. // to be drawn on the canvas and rgb color for each vertex.
  47175. Shadings.Mesh = function MeshClosure() {
  47176. function MeshStreamReader(stream, context) {
  47177. this.stream = stream;
  47178. this.context = context;
  47179. this.buffer = 0;
  47180. this.bufferLength = 0;
  47181. var numComps = context.numComps;
  47182. this.tmpCompsBuf = new Float32Array(numComps);
  47183. var csNumComps = context.colorSpace.numComps;
  47184. this.tmpCsCompsBuf = context.colorFn ? new Float32Array(csNumComps) : this.tmpCompsBuf;
  47185. }
  47186. MeshStreamReader.prototype = {
  47187. get hasData() {
  47188. if (this.stream.end) {
  47189. return this.stream.pos < this.stream.end;
  47190. }
  47191. if (this.bufferLength > 0) {
  47192. return true;
  47193. }
  47194. var nextByte = this.stream.getByte();
  47195. if (nextByte < 0) {
  47196. return false;
  47197. }
  47198. this.buffer = nextByte;
  47199. this.bufferLength = 8;
  47200. return true;
  47201. },
  47202. readBits: function MeshStreamReader_readBits(n) {
  47203. var buffer = this.buffer;
  47204. var bufferLength = this.bufferLength;
  47205. if (n === 32) {
  47206. if (bufferLength === 0) {
  47207. return (this.stream.getByte() << 24 | this.stream.getByte() << 16 | this.stream.getByte() << 8 | this.stream.getByte()) >>> 0;
  47208. }
  47209. buffer = buffer << 24 | this.stream.getByte() << 16 | this.stream.getByte() << 8 | this.stream.getByte();
  47210. var nextByte = this.stream.getByte();
  47211. this.buffer = nextByte & (1 << bufferLength) - 1;
  47212. return (buffer << 8 - bufferLength | (nextByte & 0xFF) >> bufferLength) >>> 0;
  47213. }
  47214. if (n === 8 && bufferLength === 0) {
  47215. return this.stream.getByte();
  47216. }
  47217. while (bufferLength < n) {
  47218. buffer = buffer << 8 | this.stream.getByte();
  47219. bufferLength += 8;
  47220. }
  47221. bufferLength -= n;
  47222. this.bufferLength = bufferLength;
  47223. this.buffer = buffer & (1 << bufferLength) - 1;
  47224. return buffer >> bufferLength;
  47225. },
  47226. align: function MeshStreamReader_align() {
  47227. this.buffer = 0;
  47228. this.bufferLength = 0;
  47229. },
  47230. readFlag: function MeshStreamReader_readFlag() {
  47231. return this.readBits(this.context.bitsPerFlag);
  47232. },
  47233. readCoordinate: function MeshStreamReader_readCoordinate() {
  47234. var bitsPerCoordinate = this.context.bitsPerCoordinate;
  47235. var xi = this.readBits(bitsPerCoordinate);
  47236. var yi = this.readBits(bitsPerCoordinate);
  47237. var decode = this.context.decode;
  47238. var scale = bitsPerCoordinate < 32 ? 1 / ((1 << bitsPerCoordinate) - 1) : 2.3283064365386963e-10;
  47239. // 2 ^ -32
  47240. return [
  47241. xi * scale * (decode[1] - decode[0]) + decode[0],
  47242. yi * scale * (decode[3] - decode[2]) + decode[2]
  47243. ];
  47244. },
  47245. readComponents: function MeshStreamReader_readComponents() {
  47246. var numComps = this.context.numComps;
  47247. var bitsPerComponent = this.context.bitsPerComponent;
  47248. var scale = bitsPerComponent < 32 ? 1 / ((1 << bitsPerComponent) - 1) : 2.3283064365386963e-10;
  47249. // 2 ^ -32
  47250. var decode = this.context.decode;
  47251. var components = this.tmpCompsBuf;
  47252. for (var i = 0, j = 4; i < numComps; i++, j += 2) {
  47253. var ci = this.readBits(bitsPerComponent);
  47254. components[i] = ci * scale * (decode[j + 1] - decode[j]) + decode[j];
  47255. }
  47256. var color = this.tmpCsCompsBuf;
  47257. if (this.context.colorFn) {
  47258. this.context.colorFn(components, 0, color, 0);
  47259. }
  47260. return this.context.colorSpace.getRgb(color, 0);
  47261. }
  47262. };
  47263. function decodeType4Shading(mesh, reader) {
  47264. var coords = mesh.coords;
  47265. var colors = mesh.colors;
  47266. var operators = [];
  47267. var ps = [];
  47268. // not maintaining cs since that will match ps
  47269. var verticesLeft = 0;
  47270. // assuming we have all data to start a new triangle
  47271. while (reader.hasData) {
  47272. var f = reader.readFlag();
  47273. var coord = reader.readCoordinate();
  47274. var color = reader.readComponents();
  47275. if (verticesLeft === 0) {
  47276. // ignoring flags if we started a triangle
  47277. assert(0 <= f && f <= 2, 'Unknown type4 flag');
  47278. switch (f) {
  47279. case 0:
  47280. verticesLeft = 3;
  47281. break;
  47282. case 1:
  47283. ps.push(ps[ps.length - 2], ps[ps.length - 1]);
  47284. verticesLeft = 1;
  47285. break;
  47286. case 2:
  47287. ps.push(ps[ps.length - 3], ps[ps.length - 1]);
  47288. verticesLeft = 1;
  47289. break;
  47290. }
  47291. operators.push(f);
  47292. }
  47293. ps.push(coords.length);
  47294. coords.push(coord);
  47295. colors.push(color);
  47296. verticesLeft--;
  47297. reader.align();
  47298. }
  47299. mesh.figures.push({
  47300. type: 'triangles',
  47301. coords: new Int32Array(ps),
  47302. colors: new Int32Array(ps)
  47303. });
  47304. }
  47305. function decodeType5Shading(mesh, reader, verticesPerRow) {
  47306. var coords = mesh.coords;
  47307. var colors = mesh.colors;
  47308. var ps = [];
  47309. // not maintaining cs since that will match ps
  47310. while (reader.hasData) {
  47311. var coord = reader.readCoordinate();
  47312. var color = reader.readComponents();
  47313. ps.push(coords.length);
  47314. coords.push(coord);
  47315. colors.push(color);
  47316. }
  47317. mesh.figures.push({
  47318. type: 'lattice',
  47319. coords: new Int32Array(ps),
  47320. colors: new Int32Array(ps),
  47321. verticesPerRow: verticesPerRow
  47322. });
  47323. }
  47324. var MIN_SPLIT_PATCH_CHUNKS_AMOUNT = 3;
  47325. var MAX_SPLIT_PATCH_CHUNKS_AMOUNT = 20;
  47326. var TRIANGLE_DENSITY = 20;
  47327. // count of triangles per entire mesh bounds
  47328. var getB = function getBClosure() {
  47329. function buildB(count) {
  47330. var lut = [];
  47331. for (var i = 0; i <= count; i++) {
  47332. var t = i / count, t_ = 1 - t;
  47333. lut.push(new Float32Array([
  47334. t_ * t_ * t_,
  47335. 3 * t * t_ * t_,
  47336. 3 * t * t * t_,
  47337. t * t * t
  47338. ]));
  47339. }
  47340. return lut;
  47341. }
  47342. var cache = [];
  47343. return function getB(count) {
  47344. if (!cache[count]) {
  47345. cache[count] = buildB(count);
  47346. }
  47347. return cache[count];
  47348. };
  47349. }();
  47350. function buildFigureFromPatch(mesh, index) {
  47351. var figure = mesh.figures[index];
  47352. assert(figure.type === 'patch', 'Unexpected patch mesh figure');
  47353. var coords = mesh.coords, colors = mesh.colors;
  47354. var pi = figure.coords;
  47355. var ci = figure.colors;
  47356. var figureMinX = Math.min(coords[pi[0]][0], coords[pi[3]][0], coords[pi[12]][0], coords[pi[15]][0]);
  47357. var figureMinY = Math.min(coords[pi[0]][1], coords[pi[3]][1], coords[pi[12]][1], coords[pi[15]][1]);
  47358. var figureMaxX = Math.max(coords[pi[0]][0], coords[pi[3]][0], coords[pi[12]][0], coords[pi[15]][0]);
  47359. var figureMaxY = Math.max(coords[pi[0]][1], coords[pi[3]][1], coords[pi[12]][1], coords[pi[15]][1]);
  47360. var splitXBy = Math.ceil((figureMaxX - figureMinX) * TRIANGLE_DENSITY / (mesh.bounds[2] - mesh.bounds[0]));
  47361. splitXBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT, Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitXBy));
  47362. var splitYBy = Math.ceil((figureMaxY - figureMinY) * TRIANGLE_DENSITY / (mesh.bounds[3] - mesh.bounds[1]));
  47363. splitYBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT, Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitYBy));
  47364. var verticesPerRow = splitXBy + 1;
  47365. var figureCoords = new Int32Array((splitYBy + 1) * verticesPerRow);
  47366. var figureColors = new Int32Array((splitYBy + 1) * verticesPerRow);
  47367. var k = 0;
  47368. var cl = new Uint8Array(3), cr = new Uint8Array(3);
  47369. var c0 = colors[ci[0]], c1 = colors[ci[1]], c2 = colors[ci[2]], c3 = colors[ci[3]];
  47370. var bRow = getB(splitYBy), bCol = getB(splitXBy);
  47371. for (var row = 0; row <= splitYBy; row++) {
  47372. cl[0] = (c0[0] * (splitYBy - row) + c2[0] * row) / splitYBy | 0;
  47373. cl[1] = (c0[1] * (splitYBy - row) + c2[1] * row) / splitYBy | 0;
  47374. cl[2] = (c0[2] * (splitYBy - row) + c2[2] * row) / splitYBy | 0;
  47375. cr[0] = (c1[0] * (splitYBy - row) + c3[0] * row) / splitYBy | 0;
  47376. cr[1] = (c1[1] * (splitYBy - row) + c3[1] * row) / splitYBy | 0;
  47377. cr[2] = (c1[2] * (splitYBy - row) + c3[2] * row) / splitYBy | 0;
  47378. for (var col = 0; col <= splitXBy; col++, k++) {
  47379. if ((row === 0 || row === splitYBy) && (col === 0 || col === splitXBy)) {
  47380. continue;
  47381. }
  47382. var x = 0, y = 0;
  47383. var q = 0;
  47384. for (var i = 0; i <= 3; i++) {
  47385. for (var j = 0; j <= 3; j++, q++) {
  47386. var m = bRow[row][i] * bCol[col][j];
  47387. x += coords[pi[q]][0] * m;
  47388. y += coords[pi[q]][1] * m;
  47389. }
  47390. }
  47391. figureCoords[k] = coords.length;
  47392. coords.push([
  47393. x,
  47394. y
  47395. ]);
  47396. figureColors[k] = colors.length;
  47397. var newColor = new Uint8Array(3);
  47398. newColor[0] = (cl[0] * (splitXBy - col) + cr[0] * col) / splitXBy | 0;
  47399. newColor[1] = (cl[1] * (splitXBy - col) + cr[1] * col) / splitXBy | 0;
  47400. newColor[2] = (cl[2] * (splitXBy - col) + cr[2] * col) / splitXBy | 0;
  47401. colors.push(newColor);
  47402. }
  47403. }
  47404. figureCoords[0] = pi[0];
  47405. figureColors[0] = ci[0];
  47406. figureCoords[splitXBy] = pi[3];
  47407. figureColors[splitXBy] = ci[1];
  47408. figureCoords[verticesPerRow * splitYBy] = pi[12];
  47409. figureColors[verticesPerRow * splitYBy] = ci[2];
  47410. figureCoords[verticesPerRow * splitYBy + splitXBy] = pi[15];
  47411. figureColors[verticesPerRow * splitYBy + splitXBy] = ci[3];
  47412. mesh.figures[index] = {
  47413. type: 'lattice',
  47414. coords: figureCoords,
  47415. colors: figureColors,
  47416. verticesPerRow: verticesPerRow
  47417. };
  47418. }
  47419. function decodeType6Shading(mesh, reader) {
  47420. // A special case of Type 7. The p11, p12, p21, p22 automatically filled
  47421. var coords = mesh.coords;
  47422. var colors = mesh.colors;
  47423. var ps = new Int32Array(16);
  47424. // p00, p10, ..., p30, p01, ..., p33
  47425. var cs = new Int32Array(4);
  47426. // c00, c30, c03, c33
  47427. while (reader.hasData) {
  47428. var f = reader.readFlag();
  47429. assert(0 <= f && f <= 3, 'Unknown type6 flag');
  47430. var i, ii;
  47431. var pi = coords.length;
  47432. for (i = 0, ii = f !== 0 ? 8 : 12; i < ii; i++) {
  47433. coords.push(reader.readCoordinate());
  47434. }
  47435. var ci = colors.length;
  47436. for (i = 0, ii = f !== 0 ? 2 : 4; i < ii; i++) {
  47437. colors.push(reader.readComponents());
  47438. }
  47439. var tmp1, tmp2, tmp3, tmp4;
  47440. switch (f) {
  47441. case 0:
  47442. ps[12] = pi + 3;
  47443. ps[13] = pi + 4;
  47444. ps[14] = pi + 5;
  47445. ps[15] = pi + 6;
  47446. ps[8] = pi + 2;
  47447. /* values for 5, 6, 9, 10 are */
  47448. ps[11] = pi + 7;
  47449. ps[4] = pi + 1;
  47450. /* calculated below */
  47451. ps[7] = pi + 8;
  47452. ps[0] = pi;
  47453. ps[1] = pi + 11;
  47454. ps[2] = pi + 10;
  47455. ps[3] = pi + 9;
  47456. cs[2] = ci + 1;
  47457. cs[3] = ci + 2;
  47458. cs[0] = ci;
  47459. cs[1] = ci + 3;
  47460. break;
  47461. case 1:
  47462. tmp1 = ps[12];
  47463. tmp2 = ps[13];
  47464. tmp3 = ps[14];
  47465. tmp4 = ps[15];
  47466. ps[12] = tmp4;
  47467. ps[13] = pi + 0;
  47468. ps[14] = pi + 1;
  47469. ps[15] = pi + 2;
  47470. ps[8] = tmp3;
  47471. /* values for 5, 6, 9, 10 are */
  47472. ps[11] = pi + 3;
  47473. ps[4] = tmp2;
  47474. /* calculated below */
  47475. ps[7] = pi + 4;
  47476. ps[0] = tmp1;
  47477. ps[1] = pi + 7;
  47478. ps[2] = pi + 6;
  47479. ps[3] = pi + 5;
  47480. tmp1 = cs[2];
  47481. tmp2 = cs[3];
  47482. cs[2] = tmp2;
  47483. cs[3] = ci;
  47484. cs[0] = tmp1;
  47485. cs[1] = ci + 1;
  47486. break;
  47487. case 2:
  47488. tmp1 = ps[15];
  47489. tmp2 = ps[11];
  47490. ps[12] = ps[3];
  47491. ps[13] = pi + 0;
  47492. ps[14] = pi + 1;
  47493. ps[15] = pi + 2;
  47494. ps[8] = ps[7];
  47495. /* values for 5, 6, 9, 10 are */
  47496. ps[11] = pi + 3;
  47497. ps[4] = tmp2;
  47498. /* calculated below */
  47499. ps[7] = pi + 4;
  47500. ps[0] = tmp1;
  47501. ps[1] = pi + 7;
  47502. ps[2] = pi + 6;
  47503. ps[3] = pi + 5;
  47504. tmp1 = cs[3];
  47505. cs[2] = cs[1];
  47506. cs[3] = ci;
  47507. cs[0] = tmp1;
  47508. cs[1] = ci + 1;
  47509. break;
  47510. case 3:
  47511. ps[12] = ps[0];
  47512. ps[13] = pi + 0;
  47513. ps[14] = pi + 1;
  47514. ps[15] = pi + 2;
  47515. ps[8] = ps[1];
  47516. /* values for 5, 6, 9, 10 are */
  47517. ps[11] = pi + 3;
  47518. ps[4] = ps[2];
  47519. /* calculated below */
  47520. ps[7] = pi + 4;
  47521. ps[0] = ps[3];
  47522. ps[1] = pi + 7;
  47523. ps[2] = pi + 6;
  47524. ps[3] = pi + 5;
  47525. cs[2] = cs[0];
  47526. cs[3] = ci;
  47527. cs[0] = cs[1];
  47528. cs[1] = ci + 1;
  47529. break;
  47530. }
  47531. // set p11, p12, p21, p22
  47532. ps[5] = coords.length;
  47533. coords.push([
  47534. (-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,
  47535. (-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
  47536. ]);
  47537. ps[6] = coords.length;
  47538. coords.push([
  47539. (-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,
  47540. (-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
  47541. ]);
  47542. ps[9] = coords.length;
  47543. coords.push([
  47544. (-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,
  47545. (-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
  47546. ]);
  47547. ps[10] = coords.length;
  47548. coords.push([
  47549. (-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,
  47550. (-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
  47551. ]);
  47552. mesh.figures.push({
  47553. type: 'patch',
  47554. coords: new Int32Array(ps),
  47555. // making copies of ps and cs
  47556. colors: new Int32Array(cs)
  47557. });
  47558. }
  47559. }
  47560. function decodeType7Shading(mesh, reader) {
  47561. var coords = mesh.coords;
  47562. var colors = mesh.colors;
  47563. var ps = new Int32Array(16);
  47564. // p00, p10, ..., p30, p01, ..., p33
  47565. var cs = new Int32Array(4);
  47566. // c00, c30, c03, c33
  47567. while (reader.hasData) {
  47568. var f = reader.readFlag();
  47569. assert(0 <= f && f <= 3, 'Unknown type7 flag');
  47570. var i, ii;
  47571. var pi = coords.length;
  47572. for (i = 0, ii = f !== 0 ? 12 : 16; i < ii; i++) {
  47573. coords.push(reader.readCoordinate());
  47574. }
  47575. var ci = colors.length;
  47576. for (i = 0, ii = f !== 0 ? 2 : 4; i < ii; i++) {
  47577. colors.push(reader.readComponents());
  47578. }
  47579. var tmp1, tmp2, tmp3, tmp4;
  47580. switch (f) {
  47581. case 0:
  47582. ps[12] = pi + 3;
  47583. ps[13] = pi + 4;
  47584. ps[14] = pi + 5;
  47585. ps[15] = pi + 6;
  47586. ps[8] = pi + 2;
  47587. ps[9] = pi + 13;
  47588. ps[10] = pi + 14;
  47589. ps[11] = pi + 7;
  47590. ps[4] = pi + 1;
  47591. ps[5] = pi + 12;
  47592. ps[6] = pi + 15;
  47593. ps[7] = pi + 8;
  47594. ps[0] = pi;
  47595. ps[1] = pi + 11;
  47596. ps[2] = pi + 10;
  47597. ps[3] = pi + 9;
  47598. cs[2] = ci + 1;
  47599. cs[3] = ci + 2;
  47600. cs[0] = ci;
  47601. cs[1] = ci + 3;
  47602. break;
  47603. case 1:
  47604. tmp1 = ps[12];
  47605. tmp2 = ps[13];
  47606. tmp3 = ps[14];
  47607. tmp4 = ps[15];
  47608. ps[12] = tmp4;
  47609. ps[13] = pi + 0;
  47610. ps[14] = pi + 1;
  47611. ps[15] = pi + 2;
  47612. ps[8] = tmp3;
  47613. ps[9] = pi + 9;
  47614. ps[10] = pi + 10;
  47615. ps[11] = pi + 3;
  47616. ps[4] = tmp2;
  47617. ps[5] = pi + 8;
  47618. ps[6] = pi + 11;
  47619. ps[7] = pi + 4;
  47620. ps[0] = tmp1;
  47621. ps[1] = pi + 7;
  47622. ps[2] = pi + 6;
  47623. ps[3] = pi + 5;
  47624. tmp1 = cs[2];
  47625. tmp2 = cs[3];
  47626. cs[2] = tmp2;
  47627. cs[3] = ci;
  47628. cs[0] = tmp1;
  47629. cs[1] = ci + 1;
  47630. break;
  47631. case 2:
  47632. tmp1 = ps[15];
  47633. tmp2 = ps[11];
  47634. ps[12] = ps[3];
  47635. ps[13] = pi + 0;
  47636. ps[14] = pi + 1;
  47637. ps[15] = pi + 2;
  47638. ps[8] = ps[7];
  47639. ps[9] = pi + 9;
  47640. ps[10] = pi + 10;
  47641. ps[11] = pi + 3;
  47642. ps[4] = tmp2;
  47643. ps[5] = pi + 8;
  47644. ps[6] = pi + 11;
  47645. ps[7] = pi + 4;
  47646. ps[0] = tmp1;
  47647. ps[1] = pi + 7;
  47648. ps[2] = pi + 6;
  47649. ps[3] = pi + 5;
  47650. tmp1 = cs[3];
  47651. cs[2] = cs[1];
  47652. cs[3] = ci;
  47653. cs[0] = tmp1;
  47654. cs[1] = ci + 1;
  47655. break;
  47656. case 3:
  47657. ps[12] = ps[0];
  47658. ps[13] = pi + 0;
  47659. ps[14] = pi + 1;
  47660. ps[15] = pi + 2;
  47661. ps[8] = ps[1];
  47662. ps[9] = pi + 9;
  47663. ps[10] = pi + 10;
  47664. ps[11] = pi + 3;
  47665. ps[4] = ps[2];
  47666. ps[5] = pi + 8;
  47667. ps[6] = pi + 11;
  47668. ps[7] = pi + 4;
  47669. ps[0] = ps[3];
  47670. ps[1] = pi + 7;
  47671. ps[2] = pi + 6;
  47672. ps[3] = pi + 5;
  47673. cs[2] = cs[0];
  47674. cs[3] = ci;
  47675. cs[0] = cs[1];
  47676. cs[1] = ci + 1;
  47677. break;
  47678. }
  47679. mesh.figures.push({
  47680. type: 'patch',
  47681. coords: new Int32Array(ps),
  47682. // making copies of ps and cs
  47683. colors: new Int32Array(cs)
  47684. });
  47685. }
  47686. }
  47687. function updateBounds(mesh) {
  47688. var minX = mesh.coords[0][0], minY = mesh.coords[0][1], maxX = minX, maxY = minY;
  47689. for (var i = 1, ii = mesh.coords.length; i < ii; i++) {
  47690. var x = mesh.coords[i][0], y = mesh.coords[i][1];
  47691. minX = minX > x ? x : minX;
  47692. minY = minY > y ? y : minY;
  47693. maxX = maxX < x ? x : maxX;
  47694. maxY = maxY < y ? y : maxY;
  47695. }
  47696. mesh.bounds = [
  47697. minX,
  47698. minY,
  47699. maxX,
  47700. maxY
  47701. ];
  47702. }
  47703. function packData(mesh) {
  47704. var i, ii, j, jj;
  47705. var coords = mesh.coords;
  47706. var coordsPacked = new Float32Array(coords.length * 2);
  47707. for (i = 0, j = 0, ii = coords.length; i < ii; i++) {
  47708. var xy = coords[i];
  47709. coordsPacked[j++] = xy[0];
  47710. coordsPacked[j++] = xy[1];
  47711. }
  47712. mesh.coords = coordsPacked;
  47713. var colors = mesh.colors;
  47714. var colorsPacked = new Uint8Array(colors.length * 3);
  47715. for (i = 0, j = 0, ii = colors.length; i < ii; i++) {
  47716. var c = colors[i];
  47717. colorsPacked[j++] = c[0];
  47718. colorsPacked[j++] = c[1];
  47719. colorsPacked[j++] = c[2];
  47720. }
  47721. mesh.colors = colorsPacked;
  47722. var figures = mesh.figures;
  47723. for (i = 0, ii = figures.length; i < ii; i++) {
  47724. var figure = figures[i], ps = figure.coords, cs = figure.colors;
  47725. for (j = 0, jj = ps.length; j < jj; j++) {
  47726. ps[j] *= 2;
  47727. cs[j] *= 3;
  47728. }
  47729. }
  47730. }
  47731. function Mesh(stream, matrix, xref, res) {
  47732. assert(isStream(stream), 'Mesh data is not a stream');
  47733. var dict = stream.dict;
  47734. this.matrix = matrix;
  47735. this.shadingType = dict.get('ShadingType');
  47736. this.type = 'Pattern';
  47737. this.bbox = dict.getArray('BBox');
  47738. var cs = dict.get('ColorSpace', 'CS');
  47739. cs = ColorSpace.parse(cs, xref, res);
  47740. this.cs = cs;
  47741. this.background = dict.has('Background') ? cs.getRgb(dict.get('Background'), 0) : null;
  47742. var fnObj = dict.get('Function');
  47743. var fn = fnObj ? PDFFunction.parseArray(xref, fnObj) : null;
  47744. this.coords = [];
  47745. this.colors = [];
  47746. this.figures = [];
  47747. var decodeContext = {
  47748. bitsPerCoordinate: dict.get('BitsPerCoordinate'),
  47749. bitsPerComponent: dict.get('BitsPerComponent'),
  47750. bitsPerFlag: dict.get('BitsPerFlag'),
  47751. decode: dict.getArray('Decode'),
  47752. colorFn: fn,
  47753. colorSpace: cs,
  47754. numComps: fn ? 1 : cs.numComps
  47755. };
  47756. var reader = new MeshStreamReader(stream, decodeContext);
  47757. var patchMesh = false;
  47758. switch (this.shadingType) {
  47759. case ShadingType.FREE_FORM_MESH:
  47760. decodeType4Shading(this, reader);
  47761. break;
  47762. case ShadingType.LATTICE_FORM_MESH:
  47763. var verticesPerRow = dict.get('VerticesPerRow') | 0;
  47764. assert(verticesPerRow >= 2, 'Invalid VerticesPerRow');
  47765. decodeType5Shading(this, reader, verticesPerRow);
  47766. break;
  47767. case ShadingType.COONS_PATCH_MESH:
  47768. decodeType6Shading(this, reader);
  47769. patchMesh = true;
  47770. break;
  47771. case ShadingType.TENSOR_PATCH_MESH:
  47772. decodeType7Shading(this, reader);
  47773. patchMesh = true;
  47774. break;
  47775. default:
  47776. error('Unsupported mesh type.');
  47777. break;
  47778. }
  47779. if (patchMesh) {
  47780. // dirty bounds calculation for determining, how dense shall be triangles
  47781. updateBounds(this);
  47782. for (var i = 0, ii = this.figures.length; i < ii; i++) {
  47783. buildFigureFromPatch(this, i);
  47784. }
  47785. }
  47786. // calculate bounds
  47787. updateBounds(this);
  47788. packData(this);
  47789. }
  47790. Mesh.prototype = {
  47791. getIR: function Mesh_getIR() {
  47792. return [
  47793. 'Mesh',
  47794. this.shadingType,
  47795. this.coords,
  47796. this.colors,
  47797. this.figures,
  47798. this.bounds,
  47799. this.matrix,
  47800. this.bbox,
  47801. this.background
  47802. ];
  47803. }
  47804. };
  47805. return Mesh;
  47806. }();
  47807. Shadings.Dummy = function DummyClosure() {
  47808. function Dummy() {
  47809. this.type = 'Pattern';
  47810. }
  47811. Dummy.prototype = {
  47812. getIR: function Dummy_getIR() {
  47813. return ['Dummy'];
  47814. }
  47815. };
  47816. return Dummy;
  47817. }();
  47818. function getTilingPatternIR(operatorList, dict, args) {
  47819. var matrix = dict.getArray('Matrix');
  47820. var bbox = dict.getArray('BBox');
  47821. var xstep = dict.get('XStep');
  47822. var ystep = dict.get('YStep');
  47823. var paintType = dict.get('PaintType');
  47824. var tilingType = dict.get('TilingType');
  47825. return [
  47826. 'TilingPattern',
  47827. args,
  47828. operatorList,
  47829. matrix,
  47830. bbox,
  47831. xstep,
  47832. ystep,
  47833. paintType,
  47834. tilingType
  47835. ];
  47836. }
  47837. exports.Pattern = Pattern;
  47838. exports.getTilingPatternIR = getTilingPatternIR;
  47839. }));
  47840. (function (root, factory) {
  47841. 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);
  47842. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreParser, coreImage, coreColorSpace, coreMurmurHash3, coreFonts, coreFunction, corePattern, coreCMap, coreMetrics, coreBidi, coreEncodings, coreStandardFonts, coreUnicode, coreGlyphList) {
  47843. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  47844. var IDENTITY_MATRIX = sharedUtil.IDENTITY_MATRIX;
  47845. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  47846. var ImageKind = sharedUtil.ImageKind;
  47847. var OPS = sharedUtil.OPS;
  47848. var TextRenderingMode = sharedUtil.TextRenderingMode;
  47849. var Util = sharedUtil.Util;
  47850. var assert = sharedUtil.assert;
  47851. var createPromiseCapability = sharedUtil.createPromiseCapability;
  47852. var error = sharedUtil.error;
  47853. var info = sharedUtil.info;
  47854. var isArray = sharedUtil.isArray;
  47855. var isNum = sharedUtil.isNum;
  47856. var isString = sharedUtil.isString;
  47857. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  47858. var warn = sharedUtil.warn;
  47859. var Dict = corePrimitives.Dict;
  47860. var Name = corePrimitives.Name;
  47861. var isCmd = corePrimitives.isCmd;
  47862. var isDict = corePrimitives.isDict;
  47863. var isName = corePrimitives.isName;
  47864. var isRef = corePrimitives.isRef;
  47865. var isStream = corePrimitives.isStream;
  47866. var DecodeStream = coreStream.DecodeStream;
  47867. var JpegStream = coreStream.JpegStream;
  47868. var Stream = coreStream.Stream;
  47869. var Lexer = coreParser.Lexer;
  47870. var Parser = coreParser.Parser;
  47871. var isEOF = coreParser.isEOF;
  47872. var PDFImage = coreImage.PDFImage;
  47873. var ColorSpace = coreColorSpace.ColorSpace;
  47874. var MurmurHash3_64 = coreMurmurHash3.MurmurHash3_64;
  47875. var ErrorFont = coreFonts.ErrorFont;
  47876. var FontFlags = coreFonts.FontFlags;
  47877. var Font = coreFonts.Font;
  47878. var IdentityToUnicodeMap = coreFonts.IdentityToUnicodeMap;
  47879. var ToUnicodeMap = coreFonts.ToUnicodeMap;
  47880. var getFontType = coreFonts.getFontType;
  47881. var isPDFFunction = coreFunction.isPDFFunction;
  47882. var PDFFunction = coreFunction.PDFFunction;
  47883. var Pattern = corePattern.Pattern;
  47884. var getTilingPatternIR = corePattern.getTilingPatternIR;
  47885. var CMapFactory = coreCMap.CMapFactory;
  47886. var IdentityCMap = coreCMap.IdentityCMap;
  47887. var getMetrics = coreMetrics.getMetrics;
  47888. var bidi = coreBidi.bidi;
  47889. var WinAnsiEncoding = coreEncodings.WinAnsiEncoding;
  47890. var StandardEncoding = coreEncodings.StandardEncoding;
  47891. var MacRomanEncoding = coreEncodings.MacRomanEncoding;
  47892. var SymbolSetEncoding = coreEncodings.SymbolSetEncoding;
  47893. var ZapfDingbatsEncoding = coreEncodings.ZapfDingbatsEncoding;
  47894. var getEncoding = coreEncodings.getEncoding;
  47895. var getStdFontMap = coreStandardFonts.getStdFontMap;
  47896. var getSerifFonts = coreStandardFonts.getSerifFonts;
  47897. var getSymbolsFonts = coreStandardFonts.getSymbolsFonts;
  47898. var getNormalizedUnicodes = coreUnicode.getNormalizedUnicodes;
  47899. var reverseIfRtl = coreUnicode.reverseIfRtl;
  47900. var getUnicodeForGlyph = coreUnicode.getUnicodeForGlyph;
  47901. var getGlyphsUnicode = coreGlyphList.getGlyphsUnicode;
  47902. var PartialEvaluator = function PartialEvaluatorClosure() {
  47903. var DefaultPartialEvaluatorOptions = {
  47904. forceDataSchema: false,
  47905. maxImageSize: -1,
  47906. disableFontFace: false,
  47907. cMapOptions: {
  47908. url: null,
  47909. packed: false
  47910. }
  47911. };
  47912. function NativeImageDecoder(xref, resources, handler, forceDataSchema) {
  47913. this.xref = xref;
  47914. this.resources = resources;
  47915. this.handler = handler;
  47916. this.forceDataSchema = forceDataSchema;
  47917. }
  47918. NativeImageDecoder.prototype = {
  47919. canDecode: function (image) {
  47920. return image instanceof JpegStream && NativeImageDecoder.isDecodable(image, this.xref, this.resources);
  47921. },
  47922. decode: function (image) {
  47923. // For natively supported JPEGs send them to the main thread for decoding.
  47924. var dict = image.dict;
  47925. var colorSpace = dict.get('ColorSpace', 'CS');
  47926. colorSpace = ColorSpace.parse(colorSpace, this.xref, this.resources);
  47927. var numComps = colorSpace.numComps;
  47928. var decodePromise = this.handler.sendWithPromise('JpegDecode', [
  47929. image.getIR(this.forceDataSchema),
  47930. numComps
  47931. ]);
  47932. return decodePromise.then(function (message) {
  47933. var data = message.data;
  47934. return new Stream(data, 0, data.length, image.dict);
  47935. });
  47936. }
  47937. };
  47938. /**
  47939. * Checks if the image can be decoded and displayed by the browser without any
  47940. * further processing such as color space conversions.
  47941. */
  47942. NativeImageDecoder.isSupported = function NativeImageDecoder_isSupported(image, xref, res) {
  47943. var dict = image.dict;
  47944. if (dict.has('DecodeParms') || dict.has('DP')) {
  47945. return false;
  47946. }
  47947. var cs = ColorSpace.parse(dict.get('ColorSpace', 'CS'), xref, res);
  47948. return (cs.name === 'DeviceGray' || cs.name === 'DeviceRGB') && cs.isDefaultDecode(dict.getArray('Decode', 'D'));
  47949. };
  47950. /**
  47951. * Checks if the image can be decoded by the browser.
  47952. */
  47953. NativeImageDecoder.isDecodable = function NativeImageDecoder_isDecodable(image, xref, res) {
  47954. var dict = image.dict;
  47955. if (dict.has('DecodeParms') || dict.has('DP')) {
  47956. return false;
  47957. }
  47958. var cs = ColorSpace.parse(dict.get('ColorSpace', 'CS'), xref, res);
  47959. return (cs.numComps === 1 || cs.numComps === 3) && cs.isDefaultDecode(dict.getArray('Decode', 'D'));
  47960. };
  47961. function PartialEvaluator(pdfManager, xref, handler, pageIndex, uniquePrefix, idCounters, fontCache, options) {
  47962. this.pdfManager = pdfManager;
  47963. this.xref = xref;
  47964. this.handler = handler;
  47965. this.pageIndex = pageIndex;
  47966. this.uniquePrefix = uniquePrefix;
  47967. this.idCounters = idCounters;
  47968. this.fontCache = fontCache;
  47969. this.options = options || DefaultPartialEvaluatorOptions;
  47970. }
  47971. // Trying to minimize Date.now() usage and check every 100 time
  47972. var TIME_SLOT_DURATION_MS = 20;
  47973. var CHECK_TIME_EVERY = 100;
  47974. function TimeSlotManager() {
  47975. this.reset();
  47976. }
  47977. TimeSlotManager.prototype = {
  47978. check: function TimeSlotManager_check() {
  47979. if (++this.checked < CHECK_TIME_EVERY) {
  47980. return false;
  47981. }
  47982. this.checked = 0;
  47983. return this.endTime <= Date.now();
  47984. },
  47985. reset: function TimeSlotManager_reset() {
  47986. this.endTime = Date.now() + TIME_SLOT_DURATION_MS;
  47987. this.checked = 0;
  47988. }
  47989. };
  47990. var deferred = Promise.resolve();
  47991. var TILING_PATTERN = 1, SHADING_PATTERN = 2;
  47992. PartialEvaluator.prototype = {
  47993. hasBlendModes: function PartialEvaluator_hasBlendModes(resources) {
  47994. if (!isDict(resources)) {
  47995. return false;
  47996. }
  47997. var processed = Object.create(null);
  47998. if (resources.objId) {
  47999. processed[resources.objId] = true;
  48000. }
  48001. var nodes = [resources], xref = this.xref;
  48002. while (nodes.length) {
  48003. var key, i, ii;
  48004. var node = nodes.shift();
  48005. // First check the current resources for blend modes.
  48006. var graphicStates = node.get('ExtGState');
  48007. if (isDict(graphicStates)) {
  48008. var graphicStatesKeys = graphicStates.getKeys();
  48009. for (i = 0, ii = graphicStatesKeys.length; i < ii; i++) {
  48010. key = graphicStatesKeys[i];
  48011. var graphicState = graphicStates.get(key);
  48012. var bm = graphicState.get('BM');
  48013. if (isName(bm) && bm.name !== 'Normal') {
  48014. return true;
  48015. }
  48016. }
  48017. }
  48018. // Descend into the XObjects to look for more resources and blend modes.
  48019. var xObjects = node.get('XObject');
  48020. if (!isDict(xObjects)) {
  48021. continue;
  48022. }
  48023. var xObjectsKeys = xObjects.getKeys();
  48024. for (i = 0, ii = xObjectsKeys.length; i < ii; i++) {
  48025. key = xObjectsKeys[i];
  48026. var xObject = xObjects.getRaw(key);
  48027. if (isRef(xObject)) {
  48028. if (processed[xObject.toString()]) {
  48029. // The XObject has already been processed, and by avoiding a
  48030. // redundant `xref.fetch` we can *significantly* reduce the load
  48031. // time for badly generated PDF files (fixes issue6961.pdf).
  48032. continue;
  48033. }
  48034. xObject = xref.fetch(xObject);
  48035. }
  48036. if (!isStream(xObject)) {
  48037. continue;
  48038. }
  48039. if (xObject.dict.objId) {
  48040. if (processed[xObject.dict.objId]) {
  48041. // stream has objId and is processed already
  48042. continue;
  48043. }
  48044. processed[xObject.dict.objId] = true;
  48045. }
  48046. var xResources = xObject.dict.get('Resources');
  48047. // Checking objId to detect an infinite loop.
  48048. if (isDict(xResources) && (!xResources.objId || !processed[xResources.objId])) {
  48049. nodes.push(xResources);
  48050. if (xResources.objId) {
  48051. processed[xResources.objId] = true;
  48052. }
  48053. }
  48054. }
  48055. }
  48056. return false;
  48057. },
  48058. buildFormXObject: function PartialEvaluator_buildFormXObject(resources, xobj, smask, operatorList, task, initialState) {
  48059. var matrix = xobj.dict.getArray('Matrix');
  48060. var bbox = xobj.dict.getArray('BBox');
  48061. var group = xobj.dict.get('Group');
  48062. if (group) {
  48063. var groupOptions = {
  48064. matrix: matrix,
  48065. bbox: bbox,
  48066. smask: smask,
  48067. isolated: false,
  48068. knockout: false
  48069. };
  48070. var groupSubtype = group.get('S');
  48071. var colorSpace;
  48072. if (isName(groupSubtype, 'Transparency')) {
  48073. groupOptions.isolated = group.get('I') || false;
  48074. groupOptions.knockout = group.get('K') || false;
  48075. colorSpace = group.has('CS') ? ColorSpace.parse(group.get('CS'), this.xref, resources) : null;
  48076. }
  48077. if (smask && smask.backdrop) {
  48078. colorSpace = colorSpace || ColorSpace.singletons.rgb;
  48079. smask.backdrop = colorSpace.getRgb(smask.backdrop, 0);
  48080. }
  48081. operatorList.addOp(OPS.beginGroup, [groupOptions]);
  48082. }
  48083. operatorList.addOp(OPS.paintFormXObjectBegin, [
  48084. matrix,
  48085. bbox
  48086. ]);
  48087. return this.getOperatorList(xobj, task, xobj.dict.get('Resources') || resources, operatorList, initialState).then(function () {
  48088. operatorList.addOp(OPS.paintFormXObjectEnd, []);
  48089. if (group) {
  48090. operatorList.addOp(OPS.endGroup, [groupOptions]);
  48091. }
  48092. });
  48093. },
  48094. buildPaintImageXObject: function PartialEvaluator_buildPaintImageXObject(resources, image, inline, operatorList, cacheKey, imageCache) {
  48095. var self = this;
  48096. var dict = image.dict;
  48097. var w = dict.get('Width', 'W');
  48098. var h = dict.get('Height', 'H');
  48099. if (!(w && isNum(w)) || !(h && isNum(h))) {
  48100. warn('Image dimensions are missing, or not numbers.');
  48101. return;
  48102. }
  48103. var maxImageSize = this.options.maxImageSize;
  48104. if (maxImageSize !== -1 && w * h > maxImageSize) {
  48105. warn('Image exceeded maximum allowed size and was removed.');
  48106. return;
  48107. }
  48108. var imageMask = dict.get('ImageMask', 'IM') || false;
  48109. var imgData, args;
  48110. if (imageMask) {
  48111. // This depends on a tmpCanvas being filled with the
  48112. // current fillStyle, such that processing the pixel
  48113. // data can't be done here. Instead of creating a
  48114. // complete PDFImage, only read the information needed
  48115. // for later.
  48116. var width = dict.get('Width', 'W');
  48117. var height = dict.get('Height', 'H');
  48118. var bitStrideLength = width + 7 >> 3;
  48119. var imgArray = image.getBytes(bitStrideLength * height);
  48120. var decode = dict.getArray('Decode', 'D');
  48121. var inverseDecode = !!decode && decode[0] > 0;
  48122. imgData = PDFImage.createMask(imgArray, width, height, image instanceof DecodeStream, inverseDecode);
  48123. imgData.cached = true;
  48124. args = [imgData];
  48125. operatorList.addOp(OPS.paintImageMaskXObject, args);
  48126. if (cacheKey) {
  48127. imageCache[cacheKey] = {
  48128. fn: OPS.paintImageMaskXObject,
  48129. args: args
  48130. };
  48131. }
  48132. return;
  48133. }
  48134. var softMask = dict.get('SMask', 'SM') || false;
  48135. var mask = dict.get('Mask') || false;
  48136. var SMALL_IMAGE_DIMENSIONS = 200;
  48137. // Inlining small images into the queue as RGB data
  48138. if (inline && !softMask && !mask && !(image instanceof JpegStream) && w + h < SMALL_IMAGE_DIMENSIONS) {
  48139. var imageObj = new PDFImage(this.xref, resources, image, inline, null, null);
  48140. // We force the use of RGBA_32BPP images here, because we can't handle
  48141. // any other kind.
  48142. imgData = imageObj.createImageData(/* forceRGBA = */
  48143. true);
  48144. operatorList.addOp(OPS.paintInlineImageXObject, [imgData]);
  48145. return;
  48146. }
  48147. // If there is no imageMask, create the PDFImage and a lot
  48148. // of image processing can be done here.
  48149. var uniquePrefix = this.uniquePrefix || '';
  48150. var objId = 'img_' + uniquePrefix + ++this.idCounters.obj;
  48151. operatorList.addDependency(objId);
  48152. args = [
  48153. objId,
  48154. w,
  48155. h
  48156. ];
  48157. if (!softMask && !mask && image instanceof JpegStream && NativeImageDecoder.isSupported(image, this.xref, resources)) {
  48158. // These JPEGs don't need any more processing so we can just send it.
  48159. operatorList.addOp(OPS.paintJpegXObject, args);
  48160. this.handler.send('obj', [
  48161. objId,
  48162. this.pageIndex,
  48163. 'JpegStream',
  48164. image.getIR(this.options.forceDataSchema)
  48165. ]);
  48166. return;
  48167. }
  48168. // Creates native image decoder only if a JPEG image or mask is present.
  48169. var nativeImageDecoder = null;
  48170. if (image instanceof JpegStream || mask instanceof JpegStream || softMask instanceof JpegStream) {
  48171. nativeImageDecoder = new NativeImageDecoder(self.xref, resources, self.handler, self.options.forceDataSchema);
  48172. }
  48173. PDFImage.buildImage(self.handler, self.xref, resources, image, inline, nativeImageDecoder).then(function (imageObj) {
  48174. var imgData = imageObj.createImageData(/* forceRGBA = */
  48175. false);
  48176. self.handler.send('obj', [
  48177. objId,
  48178. self.pageIndex,
  48179. 'Image',
  48180. imgData
  48181. ], [imgData.data.buffer]);
  48182. }).then(undefined, function (reason) {
  48183. warn('Unable to decode image: ' + reason);
  48184. self.handler.send('obj', [
  48185. objId,
  48186. self.pageIndex,
  48187. 'Image',
  48188. null
  48189. ]);
  48190. });
  48191. operatorList.addOp(OPS.paintImageXObject, args);
  48192. if (cacheKey) {
  48193. imageCache[cacheKey] = {
  48194. fn: OPS.paintImageXObject,
  48195. args: args
  48196. };
  48197. }
  48198. },
  48199. handleSMask: function PartialEvaluator_handleSmask(smask, resources, operatorList, task, stateManager) {
  48200. var smaskContent = smask.get('G');
  48201. var smaskOptions = {
  48202. subtype: smask.get('S').name,
  48203. backdrop: smask.get('BC')
  48204. };
  48205. // The SMask might have a alpha/luminosity value transfer function --
  48206. // we will build a map of integer values in range 0..255 to be fast.
  48207. var transferObj = smask.get('TR');
  48208. if (isPDFFunction(transferObj)) {
  48209. var transferFn = PDFFunction.parse(this.xref, transferObj);
  48210. var transferMap = new Uint8Array(256);
  48211. var tmp = new Float32Array(1);
  48212. for (var i = 0; i < 256; i++) {
  48213. tmp[0] = i / 255;
  48214. transferFn(tmp, 0, tmp, 0);
  48215. transferMap[i] = tmp[0] * 255 | 0;
  48216. }
  48217. smaskOptions.transferMap = transferMap;
  48218. }
  48219. return this.buildFormXObject(resources, smaskContent, smaskOptions, operatorList, task, stateManager.state.clone());
  48220. },
  48221. handleTilingType: function PartialEvaluator_handleTilingType(fn, args, resources, pattern, patternDict, operatorList, task) {
  48222. // Create an IR of the pattern code.
  48223. var tilingOpList = new OperatorList();
  48224. // Merge the available resources, to prevent issues when the patternDict
  48225. // is missing some /Resources entries (fixes issue6541.pdf).
  48226. var resourcesArray = [
  48227. patternDict.get('Resources'),
  48228. resources
  48229. ];
  48230. var patternResources = Dict.merge(this.xref, resourcesArray);
  48231. return this.getOperatorList(pattern, task, patternResources, tilingOpList).then(function () {
  48232. // Add the dependencies to the parent operator list so they are
  48233. // resolved before sub operator list is executed synchronously.
  48234. operatorList.addDependencies(tilingOpList.dependencies);
  48235. operatorList.addOp(fn, getTilingPatternIR({
  48236. fnArray: tilingOpList.fnArray,
  48237. argsArray: tilingOpList.argsArray
  48238. }, patternDict, args));
  48239. });
  48240. },
  48241. handleSetFont: function PartialEvaluator_handleSetFont(resources, fontArgs, fontRef, operatorList, task, state) {
  48242. // TODO(mack): Not needed?
  48243. var fontName;
  48244. if (fontArgs) {
  48245. fontArgs = fontArgs.slice();
  48246. fontName = fontArgs[0].name;
  48247. }
  48248. var self = this;
  48249. return this.loadFont(fontName, fontRef, this.xref, resources).then(function (translated) {
  48250. if (!translated.font.isType3Font) {
  48251. return translated;
  48252. }
  48253. return translated.loadType3Data(self, resources, operatorList, task).then(function () {
  48254. return translated;
  48255. }, function (reason) {
  48256. // Error in the font data -- sending unsupported feature notification.
  48257. self.handler.send('UnsupportedFeature', { featureId: UNSUPPORTED_FEATURES.font });
  48258. return new TranslatedFont('g_font_error', new ErrorFont('Type3 font load error: ' + reason), translated.font);
  48259. });
  48260. }).then(function (translated) {
  48261. state.font = translated.font;
  48262. translated.send(self.handler);
  48263. return translated.loadedName;
  48264. });
  48265. },
  48266. handleText: function PartialEvaluator_handleText(chars, state) {
  48267. var font = state.font;
  48268. var glyphs = font.charsToGlyphs(chars);
  48269. var isAddToPathSet = !!(state.textRenderingMode & TextRenderingMode.ADD_TO_PATH_FLAG);
  48270. if (font.data && (isAddToPathSet || this.options.disableFontFace)) {
  48271. var buildPath = function (fontChar) {
  48272. if (!font.renderer.hasBuiltPath(fontChar)) {
  48273. var path = font.renderer.getPathJs(fontChar);
  48274. this.handler.send('commonobj', [
  48275. font.loadedName + '_path_' + fontChar,
  48276. 'FontPath',
  48277. path
  48278. ]);
  48279. }
  48280. }.bind(this);
  48281. for (var i = 0, ii = glyphs.length; i < ii; i++) {
  48282. var glyph = glyphs[i];
  48283. buildPath(glyph.fontChar);
  48284. // If the glyph has an accent we need to build a path for its
  48285. // fontChar too, otherwise CanvasGraphics_paintChar will fail.
  48286. var accent = glyph.accent;
  48287. if (accent && accent.fontChar) {
  48288. buildPath(accent.fontChar);
  48289. }
  48290. }
  48291. }
  48292. return glyphs;
  48293. },
  48294. setGState: function PartialEvaluator_setGState(resources, gState, operatorList, task, xref, stateManager) {
  48295. // This array holds the converted/processed state data.
  48296. var gStateObj = [];
  48297. var gStateKeys = gState.getKeys();
  48298. var self = this;
  48299. var promise = Promise.resolve();
  48300. for (var i = 0, ii = gStateKeys.length; i < ii; i++) {
  48301. var key = gStateKeys[i];
  48302. var value = gState.get(key);
  48303. switch (key) {
  48304. case 'Type':
  48305. break;
  48306. case 'LW':
  48307. case 'LC':
  48308. case 'LJ':
  48309. case 'ML':
  48310. case 'D':
  48311. case 'RI':
  48312. case 'FL':
  48313. case 'CA':
  48314. case 'ca':
  48315. gStateObj.push([
  48316. key,
  48317. value
  48318. ]);
  48319. break;
  48320. case 'Font':
  48321. promise = promise.then(function () {
  48322. return self.handleSetFont(resources, null, value[0], operatorList, task, stateManager.state).then(function (loadedName) {
  48323. operatorList.addDependency(loadedName);
  48324. gStateObj.push([
  48325. key,
  48326. [
  48327. loadedName,
  48328. value[1]
  48329. ]
  48330. ]);
  48331. });
  48332. });
  48333. break;
  48334. case 'BM':
  48335. gStateObj.push([
  48336. key,
  48337. value
  48338. ]);
  48339. break;
  48340. case 'SMask':
  48341. if (isName(value, 'None')) {
  48342. gStateObj.push([
  48343. key,
  48344. false
  48345. ]);
  48346. break;
  48347. }
  48348. if (isDict(value)) {
  48349. promise = promise.then(function (dict) {
  48350. return self.handleSMask(dict, resources, operatorList, task, stateManager);
  48351. }.bind(this, value));
  48352. gStateObj.push([
  48353. key,
  48354. true
  48355. ]);
  48356. } else {
  48357. warn('Unsupported SMask type');
  48358. }
  48359. break;
  48360. // Only generate info log messages for the following since
  48361. // they are unlikely to have a big impact on the rendering.
  48362. case 'OP':
  48363. case 'op':
  48364. case 'OPM':
  48365. case 'BG':
  48366. case 'BG2':
  48367. case 'UCR':
  48368. case 'UCR2':
  48369. case 'TR':
  48370. case 'TR2':
  48371. case 'HT':
  48372. case 'SM':
  48373. case 'SA':
  48374. case 'AIS':
  48375. case 'TK':
  48376. // TODO implement these operators.
  48377. info('graphic state operator ' + key);
  48378. break;
  48379. default:
  48380. info('Unknown graphic state operator ' + key);
  48381. break;
  48382. }
  48383. }
  48384. return promise.then(function () {
  48385. if (gStateObj.length > 0) {
  48386. operatorList.addOp(OPS.setGState, [gStateObj]);
  48387. }
  48388. });
  48389. },
  48390. loadFont: function PartialEvaluator_loadFont(fontName, font, xref, resources) {
  48391. function errorFont() {
  48392. return Promise.resolve(new TranslatedFont('g_font_error', new ErrorFont('Font ' + fontName + ' is not available'), font));
  48393. }
  48394. var fontRef;
  48395. if (font) {
  48396. // Loading by ref.
  48397. assert(isRef(font));
  48398. fontRef = font;
  48399. } else {
  48400. // Loading by name.
  48401. var fontRes = resources.get('Font');
  48402. if (fontRes) {
  48403. fontRef = fontRes.getRaw(fontName);
  48404. } else {
  48405. warn('fontRes not available');
  48406. return errorFont();
  48407. }
  48408. }
  48409. if (!fontRef) {
  48410. warn('fontRef not available');
  48411. return errorFont();
  48412. }
  48413. if (this.fontCache.has(fontRef)) {
  48414. return this.fontCache.get(fontRef);
  48415. }
  48416. font = xref.fetchIfRef(fontRef);
  48417. if (!isDict(font)) {
  48418. return errorFont();
  48419. }
  48420. // We are holding `font.translated` references just for `fontRef`s that
  48421. // are not actually `Ref`s, but rather `Dict`s. See explanation below.
  48422. if (font.translated) {
  48423. return font.translated;
  48424. }
  48425. var fontCapability = createPromiseCapability();
  48426. var preEvaluatedFont = this.preEvaluateFont(font, xref);
  48427. var descriptor = preEvaluatedFont.descriptor;
  48428. var fontRefIsRef = isRef(fontRef), fontID;
  48429. if (fontRefIsRef) {
  48430. fontID = fontRef.toString();
  48431. }
  48432. if (isDict(descriptor)) {
  48433. if (!descriptor.fontAliases) {
  48434. descriptor.fontAliases = Object.create(null);
  48435. }
  48436. var fontAliases = descriptor.fontAliases;
  48437. var hash = preEvaluatedFont.hash;
  48438. if (fontAliases[hash]) {
  48439. var aliasFontRef = fontAliases[hash].aliasRef;
  48440. if (fontRefIsRef && aliasFontRef && this.fontCache.has(aliasFontRef)) {
  48441. this.fontCache.putAlias(fontRef, aliasFontRef);
  48442. return this.fontCache.get(fontRef);
  48443. }
  48444. } else {
  48445. fontAliases[hash] = { fontID: Font.getFontID() };
  48446. }
  48447. if (fontRefIsRef) {
  48448. fontAliases[hash].aliasRef = fontRef;
  48449. }
  48450. fontID = fontAliases[hash].fontID;
  48451. }
  48452. // Workaround for bad PDF generators that reference fonts incorrectly,
  48453. // where `fontRef` is a `Dict` rather than a `Ref` (fixes bug946506.pdf).
  48454. // In this case we should not put the font into `this.fontCache` (which is
  48455. // a `RefSetCache`), since it's not meaningful to use a `Dict` as a key.
  48456. //
  48457. // However, if we don't cache the font it's not possible to remove it
  48458. // when `cleanup` is triggered from the API, which causes issues on
  48459. // subsequent rendering operations (see issue7403.pdf).
  48460. // A simple workaround would be to just not hold `font.translated`
  48461. // references in this case, but this would force us to unnecessarily load
  48462. // the same fonts over and over.
  48463. //
  48464. // Instead, we cheat a bit by attempting to use a modified `fontID` as a
  48465. // key in `this.fontCache`, to allow the font to be cached.
  48466. // NOTE: This works because `RefSetCache` calls `toString()` on provided
  48467. // keys. Also, since `fontRef` is used when getting cached fonts,
  48468. // we'll not accidentally match fonts cached with the `fontID`.
  48469. if (fontRefIsRef) {
  48470. this.fontCache.put(fontRef, fontCapability.promise);
  48471. } else {
  48472. if (!fontID) {
  48473. fontID = (this.uniquePrefix || 'F_') + ++this.idCounters.obj;
  48474. }
  48475. this.fontCache.put('id_' + fontID, fontCapability.promise);
  48476. }
  48477. assert(fontID, 'The "fontID" must be defined.');
  48478. // Keep track of each font we translated so the caller can
  48479. // load them asynchronously before calling display on a page.
  48480. font.loadedName = 'g_' + this.pdfManager.docId + '_f' + fontID;
  48481. font.translated = fontCapability.promise;
  48482. // TODO move promises into translate font
  48483. var translatedPromise;
  48484. try {
  48485. translatedPromise = this.translateFont(preEvaluatedFont, xref);
  48486. } catch (e) {
  48487. translatedPromise = Promise.reject(e);
  48488. }
  48489. var self = this;
  48490. translatedPromise.then(function (translatedFont) {
  48491. if (translatedFont.fontType !== undefined) {
  48492. var xrefFontStats = xref.stats.fontTypes;
  48493. xrefFontStats[translatedFont.fontType] = true;
  48494. }
  48495. fontCapability.resolve(new TranslatedFont(font.loadedName, translatedFont, font));
  48496. }, function (reason) {
  48497. // TODO fontCapability.reject?
  48498. // Error in the font data -- sending unsupported feature notification.
  48499. self.handler.send('UnsupportedFeature', { featureId: UNSUPPORTED_FEATURES.font });
  48500. try {
  48501. // error, but it's still nice to have font type reported
  48502. var descriptor = preEvaluatedFont.descriptor;
  48503. var fontFile3 = descriptor && descriptor.get('FontFile3');
  48504. var subtype = fontFile3 && fontFile3.get('Subtype');
  48505. var fontType = getFontType(preEvaluatedFont.type, subtype && subtype.name);
  48506. var xrefFontStats = xref.stats.fontTypes;
  48507. xrefFontStats[fontType] = true;
  48508. } catch (ex) {
  48509. }
  48510. fontCapability.resolve(new TranslatedFont(font.loadedName, new ErrorFont(reason instanceof Error ? reason.message : reason), font));
  48511. });
  48512. return fontCapability.promise;
  48513. },
  48514. buildPath: function PartialEvaluator_buildPath(operatorList, fn, args) {
  48515. var lastIndex = operatorList.length - 1;
  48516. if (!args) {
  48517. args = [];
  48518. }
  48519. if (lastIndex < 0 || operatorList.fnArray[lastIndex] !== OPS.constructPath) {
  48520. operatorList.addOp(OPS.constructPath, [
  48521. [fn],
  48522. args
  48523. ]);
  48524. } else {
  48525. var opArgs = operatorList.argsArray[lastIndex];
  48526. opArgs[0].push(fn);
  48527. Array.prototype.push.apply(opArgs[1], args);
  48528. }
  48529. },
  48530. handleColorN: function PartialEvaluator_handleColorN(operatorList, fn, args, cs, patterns, resources, task, xref) {
  48531. // compile tiling patterns
  48532. var patternName = args[args.length - 1];
  48533. // SCN/scn applies patterns along with normal colors
  48534. var pattern;
  48535. if (isName(patternName) && (pattern = patterns.get(patternName.name))) {
  48536. var dict = isStream(pattern) ? pattern.dict : pattern;
  48537. var typeNum = dict.get('PatternType');
  48538. if (typeNum === TILING_PATTERN) {
  48539. var color = cs.base ? cs.base.getRgb(args, 0) : null;
  48540. return this.handleTilingType(fn, color, resources, pattern, dict, operatorList, task);
  48541. } else if (typeNum === SHADING_PATTERN) {
  48542. var shading = dict.get('Shading');
  48543. var matrix = dict.getArray('Matrix');
  48544. pattern = Pattern.parseShading(shading, matrix, xref, resources, this.handler);
  48545. operatorList.addOp(fn, pattern.getIR());
  48546. return Promise.resolve();
  48547. } else {
  48548. return Promise.reject('Unknown PatternType: ' + typeNum);
  48549. }
  48550. }
  48551. // TODO shall we fail here?
  48552. operatorList.addOp(fn, args);
  48553. return Promise.resolve();
  48554. },
  48555. getOperatorList: function PartialEvaluator_getOperatorList(stream, task, resources, operatorList, initialState) {
  48556. var self = this;
  48557. var xref = this.xref;
  48558. var imageCache = Object.create(null);
  48559. assert(operatorList);
  48560. resources = resources || Dict.empty;
  48561. var xobjs = resources.get('XObject') || Dict.empty;
  48562. var patterns = resources.get('Pattern') || Dict.empty;
  48563. var stateManager = new StateManager(initialState || new EvalState());
  48564. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  48565. var timeSlotManager = new TimeSlotManager();
  48566. return new Promise(function promiseBody(resolve, reject) {
  48567. var next = function (promise) {
  48568. promise.then(function () {
  48569. try {
  48570. promiseBody(resolve, reject);
  48571. } catch (ex) {
  48572. reject(ex);
  48573. }
  48574. }, reject);
  48575. };
  48576. task.ensureNotTerminated();
  48577. timeSlotManager.reset();
  48578. var stop, operation = {}, i, ii, cs;
  48579. while (!(stop = timeSlotManager.check())) {
  48580. // The arguments parsed by read() are used beyond this loop, so we
  48581. // cannot reuse the same array on each iteration. Therefore we pass
  48582. // in |null| as the initial value (see the comment on
  48583. // EvaluatorPreprocessor_read() for why).
  48584. operation.args = null;
  48585. if (!preprocessor.read(operation)) {
  48586. break;
  48587. }
  48588. var args = operation.args;
  48589. var fn = operation.fn;
  48590. switch (fn | 0) {
  48591. case OPS.paintXObject:
  48592. if (args[0].code) {
  48593. break;
  48594. }
  48595. // eagerly compile XForm objects
  48596. var name = args[0].name;
  48597. if (!name) {
  48598. warn('XObject must be referred to by name.');
  48599. continue;
  48600. }
  48601. if (imageCache[name] !== undefined) {
  48602. operatorList.addOp(imageCache[name].fn, imageCache[name].args);
  48603. args = null;
  48604. continue;
  48605. }
  48606. var xobj = xobjs.get(name);
  48607. if (xobj) {
  48608. assert(isStream(xobj), 'XObject should be a stream');
  48609. var type = xobj.dict.get('Subtype');
  48610. assert(isName(type), 'XObject should have a Name subtype');
  48611. if (type.name === 'Form') {
  48612. stateManager.save();
  48613. next(self.buildFormXObject(resources, xobj, null, operatorList, task, stateManager.state.clone()).then(function () {
  48614. stateManager.restore();
  48615. }));
  48616. return;
  48617. } else if (type.name === 'Image') {
  48618. self.buildPaintImageXObject(resources, xobj, false, operatorList, name, imageCache);
  48619. args = null;
  48620. continue;
  48621. } else if (type.name === 'PS') {
  48622. // PostScript XObjects are unused when viewing documents.
  48623. // See section 4.7.1 of Adobe's PDF reference.
  48624. info('Ignored XObject subtype PS');
  48625. continue;
  48626. } else {
  48627. error('Unhandled XObject subtype ' + type.name);
  48628. }
  48629. }
  48630. break;
  48631. case OPS.setFont:
  48632. var fontSize = args[1];
  48633. // eagerly collect all fonts
  48634. next(self.handleSetFont(resources, args, null, operatorList, task, stateManager.state).then(function (loadedName) {
  48635. operatorList.addDependency(loadedName);
  48636. operatorList.addOp(OPS.setFont, [
  48637. loadedName,
  48638. fontSize
  48639. ]);
  48640. }));
  48641. return;
  48642. case OPS.endInlineImage:
  48643. var cacheKey = args[0].cacheKey;
  48644. if (cacheKey) {
  48645. var cacheEntry = imageCache[cacheKey];
  48646. if (cacheEntry !== undefined) {
  48647. operatorList.addOp(cacheEntry.fn, cacheEntry.args);
  48648. args = null;
  48649. continue;
  48650. }
  48651. }
  48652. self.buildPaintImageXObject(resources, args[0], true, operatorList, cacheKey, imageCache);
  48653. args = null;
  48654. continue;
  48655. case OPS.showText:
  48656. args[0] = self.handleText(args[0], stateManager.state);
  48657. break;
  48658. case OPS.showSpacedText:
  48659. var arr = args[0];
  48660. var combinedGlyphs = [];
  48661. var arrLength = arr.length;
  48662. var state = stateManager.state;
  48663. for (i = 0; i < arrLength; ++i) {
  48664. var arrItem = arr[i];
  48665. if (isString(arrItem)) {
  48666. Array.prototype.push.apply(combinedGlyphs, self.handleText(arrItem, state));
  48667. } else if (isNum(arrItem)) {
  48668. combinedGlyphs.push(arrItem);
  48669. }
  48670. }
  48671. args[0] = combinedGlyphs;
  48672. fn = OPS.showText;
  48673. break;
  48674. case OPS.nextLineShowText:
  48675. operatorList.addOp(OPS.nextLine);
  48676. args[0] = self.handleText(args[0], stateManager.state);
  48677. fn = OPS.showText;
  48678. break;
  48679. case OPS.nextLineSetSpacingShowText:
  48680. operatorList.addOp(OPS.nextLine);
  48681. operatorList.addOp(OPS.setWordSpacing, [args.shift()]);
  48682. operatorList.addOp(OPS.setCharSpacing, [args.shift()]);
  48683. args[0] = self.handleText(args[0], stateManager.state);
  48684. fn = OPS.showText;
  48685. break;
  48686. case OPS.setTextRenderingMode:
  48687. stateManager.state.textRenderingMode = args[0];
  48688. break;
  48689. case OPS.setFillColorSpace:
  48690. stateManager.state.fillColorSpace = ColorSpace.parse(args[0], xref, resources);
  48691. continue;
  48692. case OPS.setStrokeColorSpace:
  48693. stateManager.state.strokeColorSpace = ColorSpace.parse(args[0], xref, resources);
  48694. continue;
  48695. case OPS.setFillColor:
  48696. cs = stateManager.state.fillColorSpace;
  48697. args = cs.getRgb(args, 0);
  48698. fn = OPS.setFillRGBColor;
  48699. break;
  48700. case OPS.setStrokeColor:
  48701. cs = stateManager.state.strokeColorSpace;
  48702. args = cs.getRgb(args, 0);
  48703. fn = OPS.setStrokeRGBColor;
  48704. break;
  48705. case OPS.setFillGray:
  48706. stateManager.state.fillColorSpace = ColorSpace.singletons.gray;
  48707. args = ColorSpace.singletons.gray.getRgb(args, 0);
  48708. fn = OPS.setFillRGBColor;
  48709. break;
  48710. case OPS.setStrokeGray:
  48711. stateManager.state.strokeColorSpace = ColorSpace.singletons.gray;
  48712. args = ColorSpace.singletons.gray.getRgb(args, 0);
  48713. fn = OPS.setStrokeRGBColor;
  48714. break;
  48715. case OPS.setFillCMYKColor:
  48716. stateManager.state.fillColorSpace = ColorSpace.singletons.cmyk;
  48717. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  48718. fn = OPS.setFillRGBColor;
  48719. break;
  48720. case OPS.setStrokeCMYKColor:
  48721. stateManager.state.strokeColorSpace = ColorSpace.singletons.cmyk;
  48722. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  48723. fn = OPS.setStrokeRGBColor;
  48724. break;
  48725. case OPS.setFillRGBColor:
  48726. stateManager.state.fillColorSpace = ColorSpace.singletons.rgb;
  48727. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  48728. break;
  48729. case OPS.setStrokeRGBColor:
  48730. stateManager.state.strokeColorSpace = ColorSpace.singletons.rgb;
  48731. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  48732. break;
  48733. case OPS.setFillColorN:
  48734. cs = stateManager.state.fillColorSpace;
  48735. if (cs.name === 'Pattern') {
  48736. next(self.handleColorN(operatorList, OPS.setFillColorN, args, cs, patterns, resources, task, xref));
  48737. return;
  48738. }
  48739. args = cs.getRgb(args, 0);
  48740. fn = OPS.setFillRGBColor;
  48741. break;
  48742. case OPS.setStrokeColorN:
  48743. cs = stateManager.state.strokeColorSpace;
  48744. if (cs.name === 'Pattern') {
  48745. next(self.handleColorN(operatorList, OPS.setStrokeColorN, args, cs, patterns, resources, task, xref));
  48746. return;
  48747. }
  48748. args = cs.getRgb(args, 0);
  48749. fn = OPS.setStrokeRGBColor;
  48750. break;
  48751. case OPS.shadingFill:
  48752. var shadingRes = resources.get('Shading');
  48753. if (!shadingRes) {
  48754. error('No shading resource found');
  48755. }
  48756. var shading = shadingRes.get(args[0].name);
  48757. if (!shading) {
  48758. error('No shading object found');
  48759. }
  48760. var shadingFill = Pattern.parseShading(shading, null, xref, resources, self.handler);
  48761. var patternIR = shadingFill.getIR();
  48762. args = [patternIR];
  48763. fn = OPS.shadingFill;
  48764. break;
  48765. case OPS.setGState:
  48766. var dictName = args[0];
  48767. var extGState = resources.get('ExtGState');
  48768. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  48769. break;
  48770. }
  48771. var gState = extGState.get(dictName.name);
  48772. next(self.setGState(resources, gState, operatorList, task, xref, stateManager));
  48773. return;
  48774. case OPS.moveTo:
  48775. case OPS.lineTo:
  48776. case OPS.curveTo:
  48777. case OPS.curveTo2:
  48778. case OPS.curveTo3:
  48779. case OPS.closePath:
  48780. self.buildPath(operatorList, fn, args);
  48781. continue;
  48782. case OPS.rectangle:
  48783. self.buildPath(operatorList, fn, args);
  48784. continue;
  48785. case OPS.markPoint:
  48786. case OPS.markPointProps:
  48787. case OPS.beginMarkedContent:
  48788. case OPS.beginMarkedContentProps:
  48789. case OPS.endMarkedContent:
  48790. case OPS.beginCompat:
  48791. case OPS.endCompat:
  48792. // Ignore operators where the corresponding handlers are known to
  48793. // be no-op in CanvasGraphics (display/canvas.js). This prevents
  48794. // serialization errors and is also a bit more efficient.
  48795. // We could also try to serialize all objects in a general way,
  48796. // e.g. as done in https://github.com/mozilla/pdf.js/pull/6266,
  48797. // but doing so is meaningless without knowing the semantics.
  48798. continue;
  48799. default:
  48800. // Note: Ignore the operator if it has `Dict` arguments, since
  48801. // those are non-serializable, otherwise postMessage will throw
  48802. // "An object could not be cloned.".
  48803. if (args !== null) {
  48804. for (i = 0, ii = args.length; i < ii; i++) {
  48805. if (args[i] instanceof Dict) {
  48806. break;
  48807. }
  48808. }
  48809. if (i < ii) {
  48810. warn('getOperatorList - ignoring operator: ' + fn);
  48811. continue;
  48812. }
  48813. }
  48814. }
  48815. operatorList.addOp(fn, args);
  48816. }
  48817. if (stop) {
  48818. next(deferred);
  48819. return;
  48820. }
  48821. // Some PDFs don't close all restores inside object/form.
  48822. // Closing those for them.
  48823. for (i = 0, ii = preprocessor.savedStatesDepth; i < ii; i++) {
  48824. operatorList.addOp(OPS.restore, []);
  48825. }
  48826. resolve();
  48827. });
  48828. },
  48829. getTextContent: function PartialEvaluator_getTextContent(stream, task, resources, stateManager, normalizeWhitespace, combineTextItems) {
  48830. stateManager = stateManager || new StateManager(new TextState());
  48831. var WhitespaceRegexp = /\s/g;
  48832. var textContent = {
  48833. items: [],
  48834. styles: Object.create(null)
  48835. };
  48836. var textContentItem = {
  48837. initialized: false,
  48838. str: [],
  48839. width: 0,
  48840. height: 0,
  48841. vertical: false,
  48842. lastAdvanceWidth: 0,
  48843. lastAdvanceHeight: 0,
  48844. textAdvanceScale: 0,
  48845. spaceWidth: 0,
  48846. fakeSpaceMin: Infinity,
  48847. fakeMultiSpaceMin: Infinity,
  48848. fakeMultiSpaceMax: -0,
  48849. textRunBreakAllowed: false,
  48850. transform: null,
  48851. fontName: null
  48852. };
  48853. var SPACE_FACTOR = 0.3;
  48854. var MULTI_SPACE_FACTOR = 1.5;
  48855. var MULTI_SPACE_FACTOR_MAX = 4;
  48856. var self = this;
  48857. var xref = this.xref;
  48858. resources = xref.fetchIfRef(resources) || Dict.empty;
  48859. // The xobj is parsed iff it's needed, e.g. if there is a `DO` cmd.
  48860. var xobjs = null;
  48861. var xobjsCache = Object.create(null);
  48862. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  48863. var textState;
  48864. function ensureTextContentItem() {
  48865. if (textContentItem.initialized) {
  48866. return textContentItem;
  48867. }
  48868. var font = textState.font;
  48869. if (!(font.loadedName in textContent.styles)) {
  48870. textContent.styles[font.loadedName] = {
  48871. fontFamily: font.fallbackName,
  48872. ascent: font.ascent,
  48873. descent: font.descent,
  48874. vertical: font.vertical
  48875. };
  48876. }
  48877. textContentItem.fontName = font.loadedName;
  48878. // 9.4.4 Text Space Details
  48879. var tsm = [
  48880. textState.fontSize * textState.textHScale,
  48881. 0,
  48882. 0,
  48883. textState.fontSize,
  48884. 0,
  48885. textState.textRise
  48886. ];
  48887. if (font.isType3Font && textState.fontMatrix !== FONT_IDENTITY_MATRIX && textState.fontSize === 1) {
  48888. var glyphHeight = font.bbox[3] - font.bbox[1];
  48889. if (glyphHeight > 0) {
  48890. glyphHeight = glyphHeight * textState.fontMatrix[3];
  48891. tsm[3] *= glyphHeight;
  48892. }
  48893. }
  48894. var trm = Util.transform(textState.ctm, Util.transform(textState.textMatrix, tsm));
  48895. textContentItem.transform = trm;
  48896. if (!font.vertical) {
  48897. textContentItem.width = 0;
  48898. textContentItem.height = Math.sqrt(trm[2] * trm[2] + trm[3] * trm[3]);
  48899. textContentItem.vertical = false;
  48900. } else {
  48901. textContentItem.width = Math.sqrt(trm[0] * trm[0] + trm[1] * trm[1]);
  48902. textContentItem.height = 0;
  48903. textContentItem.vertical = true;
  48904. }
  48905. var a = textState.textLineMatrix[0];
  48906. var b = textState.textLineMatrix[1];
  48907. var scaleLineX = Math.sqrt(a * a + b * b);
  48908. a = textState.ctm[0];
  48909. b = textState.ctm[1];
  48910. var scaleCtmX = Math.sqrt(a * a + b * b);
  48911. textContentItem.textAdvanceScale = scaleCtmX * scaleLineX;
  48912. textContentItem.lastAdvanceWidth = 0;
  48913. textContentItem.lastAdvanceHeight = 0;
  48914. var spaceWidth = font.spaceWidth / 1000 * textState.fontSize;
  48915. if (spaceWidth) {
  48916. textContentItem.spaceWidth = spaceWidth;
  48917. textContentItem.fakeSpaceMin = spaceWidth * SPACE_FACTOR;
  48918. textContentItem.fakeMultiSpaceMin = spaceWidth * MULTI_SPACE_FACTOR;
  48919. textContentItem.fakeMultiSpaceMax = spaceWidth * MULTI_SPACE_FACTOR_MAX;
  48920. // It's okay for monospace fonts to fake as much space as needed.
  48921. textContentItem.textRunBreakAllowed = !font.isMonospace;
  48922. } else {
  48923. textContentItem.spaceWidth = 0;
  48924. textContentItem.fakeSpaceMin = Infinity;
  48925. textContentItem.fakeMultiSpaceMin = Infinity;
  48926. textContentItem.fakeMultiSpaceMax = 0;
  48927. textContentItem.textRunBreakAllowed = false;
  48928. }
  48929. textContentItem.initialized = true;
  48930. return textContentItem;
  48931. }
  48932. function replaceWhitespace(str) {
  48933. // Replaces all whitespaces with standard spaces (0x20), to avoid
  48934. // alignment issues between the textLayer and the canvas if the text
  48935. // contains e.g. tabs (fixes issue6612.pdf).
  48936. var i = 0, ii = str.length, code;
  48937. while (i < ii && (code = str.charCodeAt(i)) >= 0x20 && code <= 0x7F) {
  48938. i++;
  48939. }
  48940. return i < ii ? str.replace(WhitespaceRegexp, ' ') : str;
  48941. }
  48942. function runBidiTransform(textChunk) {
  48943. var str = textChunk.str.join('');
  48944. var bidiResult = bidi(str, -1, textChunk.vertical);
  48945. return {
  48946. str: normalizeWhitespace ? replaceWhitespace(bidiResult.str) : bidiResult.str,
  48947. dir: bidiResult.dir,
  48948. width: textChunk.width,
  48949. height: textChunk.height,
  48950. transform: textChunk.transform,
  48951. fontName: textChunk.fontName
  48952. };
  48953. }
  48954. function handleSetFont(fontName, fontRef) {
  48955. return self.loadFont(fontName, fontRef, xref, resources).then(function (translated) {
  48956. textState.font = translated.font;
  48957. textState.fontMatrix = translated.font.fontMatrix || FONT_IDENTITY_MATRIX;
  48958. });
  48959. }
  48960. function buildTextContentItem(chars) {
  48961. var font = textState.font;
  48962. var textChunk = ensureTextContentItem();
  48963. var width = 0;
  48964. var height = 0;
  48965. var glyphs = font.charsToGlyphs(chars);
  48966. var defaultVMetrics = font.defaultVMetrics;
  48967. for (var i = 0; i < glyphs.length; i++) {
  48968. var glyph = glyphs[i];
  48969. var vMetricX = null;
  48970. var vMetricY = null;
  48971. var glyphWidth = null;
  48972. if (font.vertical) {
  48973. if (glyph.vmetric) {
  48974. glyphWidth = glyph.vmetric[0];
  48975. vMetricX = glyph.vmetric[1];
  48976. vMetricY = glyph.vmetric[2];
  48977. } else {
  48978. glyphWidth = glyph.width;
  48979. vMetricX = glyph.width * 0.5;
  48980. vMetricY = defaultVMetrics[2];
  48981. }
  48982. } else {
  48983. glyphWidth = glyph.width;
  48984. }
  48985. var glyphUnicode = glyph.unicode;
  48986. var NormalizedUnicodes = getNormalizedUnicodes();
  48987. if (NormalizedUnicodes[glyphUnicode] !== undefined) {
  48988. glyphUnicode = NormalizedUnicodes[glyphUnicode];
  48989. }
  48990. glyphUnicode = reverseIfRtl(glyphUnicode);
  48991. // The following will calculate the x and y of the individual glyphs.
  48992. // if (font.vertical) {
  48993. // tsm[4] -= vMetricX * Math.abs(textState.fontSize) *
  48994. // textState.fontMatrix[0];
  48995. // tsm[5] -= vMetricY * textState.fontSize *
  48996. // textState.fontMatrix[0];
  48997. // }
  48998. // var trm = Util.transform(textState.textMatrix, tsm);
  48999. // var pt = Util.applyTransform([trm[4], trm[5]], textState.ctm);
  49000. // var x = pt[0];
  49001. // var y = pt[1];
  49002. var charSpacing = textState.charSpacing;
  49003. if (glyph.isSpace) {
  49004. var wordSpacing = textState.wordSpacing;
  49005. charSpacing += wordSpacing;
  49006. if (wordSpacing > 0) {
  49007. addFakeSpaces(wordSpacing, textChunk.str);
  49008. }
  49009. }
  49010. var tx = 0;
  49011. var ty = 0;
  49012. if (!font.vertical) {
  49013. var w0 = glyphWidth * textState.fontMatrix[0];
  49014. tx = (w0 * textState.fontSize + charSpacing) * textState.textHScale;
  49015. width += tx;
  49016. } else {
  49017. var w1 = glyphWidth * textState.fontMatrix[0];
  49018. ty = w1 * textState.fontSize + charSpacing;
  49019. height += ty;
  49020. }
  49021. textState.translateTextMatrix(tx, ty);
  49022. textChunk.str.push(glyphUnicode);
  49023. }
  49024. if (!font.vertical) {
  49025. textChunk.lastAdvanceWidth = width;
  49026. textChunk.width += width * textChunk.textAdvanceScale;
  49027. } else {
  49028. textChunk.lastAdvanceHeight = height;
  49029. textChunk.height += Math.abs(height * textChunk.textAdvanceScale);
  49030. }
  49031. return textChunk;
  49032. }
  49033. function addFakeSpaces(width, strBuf) {
  49034. if (width < textContentItem.fakeSpaceMin) {
  49035. return;
  49036. }
  49037. if (width < textContentItem.fakeMultiSpaceMin) {
  49038. strBuf.push(' ');
  49039. return;
  49040. }
  49041. var fakeSpaces = Math.round(width / textContentItem.spaceWidth);
  49042. while (fakeSpaces-- > 0) {
  49043. strBuf.push(' ');
  49044. }
  49045. }
  49046. function flushTextContentItem() {
  49047. if (!textContentItem.initialized) {
  49048. return;
  49049. }
  49050. textContent.items.push(runBidiTransform(textContentItem));
  49051. textContentItem.initialized = false;
  49052. textContentItem.str.length = 0;
  49053. }
  49054. var timeSlotManager = new TimeSlotManager();
  49055. return new Promise(function promiseBody(resolve, reject) {
  49056. var next = function (promise) {
  49057. promise.then(function () {
  49058. try {
  49059. promiseBody(resolve, reject);
  49060. } catch (ex) {
  49061. reject(ex);
  49062. }
  49063. }, reject);
  49064. };
  49065. task.ensureNotTerminated();
  49066. timeSlotManager.reset();
  49067. var stop, operation = {}, args = [];
  49068. while (!(stop = timeSlotManager.check())) {
  49069. // The arguments parsed by read() are not used beyond this loop, so
  49070. // we can reuse the same array on every iteration, thus avoiding
  49071. // unnecessary allocations.
  49072. args.length = 0;
  49073. operation.args = args;
  49074. if (!preprocessor.read(operation)) {
  49075. break;
  49076. }
  49077. textState = stateManager.state;
  49078. var fn = operation.fn;
  49079. args = operation.args;
  49080. var advance, diff;
  49081. switch (fn | 0) {
  49082. case OPS.setFont:
  49083. // Optimization to ignore multiple identical Tf commands.
  49084. var fontNameArg = args[0].name, fontSizeArg = args[1];
  49085. if (textState.font && fontNameArg === textState.fontName && fontSizeArg === textState.fontSize) {
  49086. break;
  49087. }
  49088. flushTextContentItem();
  49089. textState.fontName = fontNameArg;
  49090. textState.fontSize = fontSizeArg;
  49091. next(handleSetFont(fontNameArg, null));
  49092. return;
  49093. case OPS.setTextRise:
  49094. flushTextContentItem();
  49095. textState.textRise = args[0];
  49096. break;
  49097. case OPS.setHScale:
  49098. flushTextContentItem();
  49099. textState.textHScale = args[0] / 100;
  49100. break;
  49101. case OPS.setLeading:
  49102. flushTextContentItem();
  49103. textState.leading = args[0];
  49104. break;
  49105. case OPS.moveText:
  49106. // Optimization to treat same line movement as advance
  49107. var isSameTextLine = !textState.font ? false : (textState.font.vertical ? args[0] : args[1]) === 0;
  49108. advance = args[0] - args[1];
  49109. if (combineTextItems && isSameTextLine && textContentItem.initialized && advance > 0 && advance <= textContentItem.fakeMultiSpaceMax) {
  49110. textState.translateTextLineMatrix(args[0], args[1]);
  49111. textContentItem.width += args[0] - textContentItem.lastAdvanceWidth;
  49112. textContentItem.height += args[1] - textContentItem.lastAdvanceHeight;
  49113. diff = args[0] - textContentItem.lastAdvanceWidth - (args[1] - textContentItem.lastAdvanceHeight);
  49114. addFakeSpaces(diff, textContentItem.str);
  49115. break;
  49116. }
  49117. flushTextContentItem();
  49118. textState.translateTextLineMatrix(args[0], args[1]);
  49119. textState.textMatrix = textState.textLineMatrix.slice();
  49120. break;
  49121. case OPS.setLeadingMoveText:
  49122. flushTextContentItem();
  49123. textState.leading = -args[1];
  49124. textState.translateTextLineMatrix(args[0], args[1]);
  49125. textState.textMatrix = textState.textLineMatrix.slice();
  49126. break;
  49127. case OPS.nextLine:
  49128. flushTextContentItem();
  49129. textState.carriageReturn();
  49130. break;
  49131. case OPS.setTextMatrix:
  49132. // Optimization to treat same line movement as advance.
  49133. advance = textState.calcTextLineMatrixAdvance(args[0], args[1], args[2], args[3], args[4], args[5]);
  49134. if (combineTextItems && advance !== null && textContentItem.initialized && advance.value > 0 && advance.value <= textContentItem.fakeMultiSpaceMax) {
  49135. textState.translateTextLineMatrix(advance.width, advance.height);
  49136. textContentItem.width += advance.width - textContentItem.lastAdvanceWidth;
  49137. textContentItem.height += advance.height - textContentItem.lastAdvanceHeight;
  49138. diff = advance.width - textContentItem.lastAdvanceWidth - (advance.height - textContentItem.lastAdvanceHeight);
  49139. addFakeSpaces(diff, textContentItem.str);
  49140. break;
  49141. }
  49142. flushTextContentItem();
  49143. textState.setTextMatrix(args[0], args[1], args[2], args[3], args[4], args[5]);
  49144. textState.setTextLineMatrix(args[0], args[1], args[2], args[3], args[4], args[5]);
  49145. break;
  49146. case OPS.setCharSpacing:
  49147. textState.charSpacing = args[0];
  49148. break;
  49149. case OPS.setWordSpacing:
  49150. textState.wordSpacing = args[0];
  49151. break;
  49152. case OPS.beginText:
  49153. flushTextContentItem();
  49154. textState.textMatrix = IDENTITY_MATRIX.slice();
  49155. textState.textLineMatrix = IDENTITY_MATRIX.slice();
  49156. break;
  49157. case OPS.showSpacedText:
  49158. var items = args[0];
  49159. var offset;
  49160. for (var j = 0, jj = items.length; j < jj; j++) {
  49161. if (typeof items[j] === 'string') {
  49162. buildTextContentItem(items[j]);
  49163. } else if (isNum(items[j])) {
  49164. ensureTextContentItem();
  49165. // PDF Specification 5.3.2 states:
  49166. // The number is expressed in thousandths of a unit of text
  49167. // space.
  49168. // This amount is subtracted from the current horizontal or
  49169. // vertical coordinate, depending on the writing mode.
  49170. // In the default coordinate system, a positive adjustment
  49171. // has the effect of moving the next glyph painted either to
  49172. // the left or down by the given amount.
  49173. advance = items[j] * textState.fontSize / 1000;
  49174. var breakTextRun = false;
  49175. if (textState.font.vertical) {
  49176. offset = advance * (textState.textHScale * textState.textMatrix[2] + textState.textMatrix[3]);
  49177. textState.translateTextMatrix(0, advance);
  49178. breakTextRun = textContentItem.textRunBreakAllowed && advance > textContentItem.fakeMultiSpaceMax;
  49179. if (!breakTextRun) {
  49180. // Value needs to be added to height to paint down.
  49181. textContentItem.height += offset;
  49182. }
  49183. } else {
  49184. advance = -advance;
  49185. offset = advance * (textState.textHScale * textState.textMatrix[0] + textState.textMatrix[1]);
  49186. textState.translateTextMatrix(advance, 0);
  49187. breakTextRun = textContentItem.textRunBreakAllowed && advance > textContentItem.fakeMultiSpaceMax;
  49188. if (!breakTextRun) {
  49189. // Value needs to be subtracted from width to paint left.
  49190. textContentItem.width += offset;
  49191. }
  49192. }
  49193. if (breakTextRun) {
  49194. flushTextContentItem();
  49195. } else if (advance > 0) {
  49196. addFakeSpaces(advance, textContentItem.str);
  49197. }
  49198. }
  49199. }
  49200. break;
  49201. case OPS.showText:
  49202. buildTextContentItem(args[0]);
  49203. break;
  49204. case OPS.nextLineShowText:
  49205. flushTextContentItem();
  49206. textState.carriageReturn();
  49207. buildTextContentItem(args[0]);
  49208. break;
  49209. case OPS.nextLineSetSpacingShowText:
  49210. flushTextContentItem();
  49211. textState.wordSpacing = args[0];
  49212. textState.charSpacing = args[1];
  49213. textState.carriageReturn();
  49214. buildTextContentItem(args[2]);
  49215. break;
  49216. case OPS.paintXObject:
  49217. flushTextContentItem();
  49218. if (args[0].code) {
  49219. break;
  49220. }
  49221. if (!xobjs) {
  49222. xobjs = resources.get('XObject') || Dict.empty;
  49223. }
  49224. var name = args[0].name;
  49225. if (xobjsCache.key === name) {
  49226. if (xobjsCache.texts) {
  49227. Util.appendToArray(textContent.items, xobjsCache.texts.items);
  49228. Util.extendObj(textContent.styles, xobjsCache.texts.styles);
  49229. }
  49230. break;
  49231. }
  49232. var xobj = xobjs.get(name);
  49233. if (!xobj) {
  49234. break;
  49235. }
  49236. assert(isStream(xobj), 'XObject should be a stream');
  49237. var type = xobj.dict.get('Subtype');
  49238. assert(isName(type), 'XObject should have a Name subtype');
  49239. if ('Form' !== type.name) {
  49240. xobjsCache.key = name;
  49241. xobjsCache.texts = null;
  49242. break;
  49243. }
  49244. stateManager.save();
  49245. var matrix = xobj.dict.getArray('Matrix');
  49246. if (isArray(matrix) && matrix.length === 6) {
  49247. stateManager.transform(matrix);
  49248. }
  49249. next(self.getTextContent(xobj, task, xobj.dict.get('Resources') || resources, stateManager, normalizeWhitespace, combineTextItems).then(function (formTextContent) {
  49250. Util.appendToArray(textContent.items, formTextContent.items);
  49251. Util.extendObj(textContent.styles, formTextContent.styles);
  49252. stateManager.restore();
  49253. xobjsCache.key = name;
  49254. xobjsCache.texts = formTextContent;
  49255. }));
  49256. return;
  49257. case OPS.setGState:
  49258. flushTextContentItem();
  49259. var dictName = args[0];
  49260. var extGState = resources.get('ExtGState');
  49261. if (!isDict(extGState) || !isName(dictName)) {
  49262. break;
  49263. }
  49264. var gState = extGState.get(dictName.name);
  49265. if (!isDict(gState)) {
  49266. break;
  49267. }
  49268. var gStateFont = gState.get('Font');
  49269. if (gStateFont) {
  49270. textState.fontName = null;
  49271. textState.fontSize = gStateFont[1];
  49272. next(handleSetFont(null, gStateFont[0]));
  49273. return;
  49274. }
  49275. break;
  49276. }
  49277. }
  49278. // switch
  49279. // while
  49280. if (stop) {
  49281. next(deferred);
  49282. return;
  49283. }
  49284. flushTextContentItem();
  49285. resolve(textContent);
  49286. });
  49287. },
  49288. extractDataStructures: function PartialEvaluator_extractDataStructures(dict, baseDict, xref, properties) {
  49289. // 9.10.2
  49290. var toUnicode = dict.get('ToUnicode') || baseDict.get('ToUnicode');
  49291. var toUnicodePromise = toUnicode ? this.readToUnicode(toUnicode) : Promise.resolve(undefined);
  49292. if (properties.composite) {
  49293. // CIDSystemInfo helps to match CID to glyphs
  49294. var cidSystemInfo = dict.get('CIDSystemInfo');
  49295. if (isDict(cidSystemInfo)) {
  49296. properties.cidSystemInfo = {
  49297. registry: cidSystemInfo.get('Registry'),
  49298. ordering: cidSystemInfo.get('Ordering'),
  49299. supplement: cidSystemInfo.get('Supplement')
  49300. };
  49301. }
  49302. var cidToGidMap = dict.get('CIDToGIDMap');
  49303. if (isStream(cidToGidMap)) {
  49304. properties.cidToGidMap = this.readCidToGidMap(cidToGidMap);
  49305. }
  49306. }
  49307. // Based on 9.6.6 of the spec the encoding can come from multiple places
  49308. // and depends on the font type. The base encoding and differences are
  49309. // read here, but the encoding that is actually used is chosen during
  49310. // glyph mapping in the font.
  49311. // TODO: Loading the built in encoding in the font would allow the
  49312. // differences to be merged in here not require us to hold on to it.
  49313. var differences = [];
  49314. var baseEncodingName = null;
  49315. var encoding;
  49316. if (dict.has('Encoding')) {
  49317. encoding = dict.get('Encoding');
  49318. if (isDict(encoding)) {
  49319. baseEncodingName = encoding.get('BaseEncoding');
  49320. baseEncodingName = isName(baseEncodingName) ? baseEncodingName.name : null;
  49321. // Load the differences between the base and original
  49322. if (encoding.has('Differences')) {
  49323. var diffEncoding = encoding.get('Differences');
  49324. var index = 0;
  49325. for (var j = 0, jj = diffEncoding.length; j < jj; j++) {
  49326. var data = xref.fetchIfRef(diffEncoding[j]);
  49327. if (isNum(data)) {
  49328. index = data;
  49329. } else if (isName(data)) {
  49330. differences[index++] = data.name;
  49331. } else {
  49332. error('Invalid entry in \'Differences\' array: ' + data);
  49333. }
  49334. }
  49335. }
  49336. } else if (isName(encoding)) {
  49337. baseEncodingName = encoding.name;
  49338. } else {
  49339. error('Encoding is not a Name nor a Dict');
  49340. }
  49341. // According to table 114 if the encoding is a named encoding it must be
  49342. // one of these predefined encodings.
  49343. if (baseEncodingName !== 'MacRomanEncoding' && baseEncodingName !== 'MacExpertEncoding' && baseEncodingName !== 'WinAnsiEncoding') {
  49344. baseEncodingName = null;
  49345. }
  49346. }
  49347. if (baseEncodingName) {
  49348. properties.defaultEncoding = getEncoding(baseEncodingName).slice();
  49349. } else {
  49350. encoding = properties.type === 'TrueType' ? WinAnsiEncoding : StandardEncoding;
  49351. // The Symbolic attribute can be misused for regular fonts
  49352. // Heuristic: we have to check if the font is a standard one also
  49353. if (!!(properties.flags & FontFlags.Symbolic)) {
  49354. encoding = MacRomanEncoding;
  49355. if (!properties.file) {
  49356. if (/Symbol/i.test(properties.name)) {
  49357. encoding = SymbolSetEncoding;
  49358. } else if (/Dingbats/i.test(properties.name)) {
  49359. encoding = ZapfDingbatsEncoding;
  49360. }
  49361. }
  49362. }
  49363. properties.defaultEncoding = encoding;
  49364. }
  49365. properties.differences = differences;
  49366. properties.baseEncodingName = baseEncodingName;
  49367. properties.hasEncoding = !!baseEncodingName || differences.length > 0;
  49368. properties.dict = dict;
  49369. return toUnicodePromise.then(function (toUnicode) {
  49370. properties.toUnicode = toUnicode;
  49371. return this.buildToUnicode(properties);
  49372. }.bind(this)).then(function (toUnicode) {
  49373. properties.toUnicode = toUnicode;
  49374. return properties;
  49375. });
  49376. },
  49377. /**
  49378. * Builds a char code to unicode map based on section 9.10 of the spec.
  49379. * @param {Object} properties Font properties object.
  49380. * @return {Promise} A Promise that is resolved with a
  49381. * {ToUnicodeMap|IdentityToUnicodeMap} object.
  49382. */
  49383. buildToUnicode: function PartialEvaluator_buildToUnicode(properties) {
  49384. properties.hasIncludedToUnicodeMap = !!properties.toUnicode && properties.toUnicode.length > 0;
  49385. // Section 9.10.2 Mapping Character Codes to Unicode Values
  49386. if (properties.hasIncludedToUnicodeMap) {
  49387. return Promise.resolve(properties.toUnicode);
  49388. }
  49389. // According to the spec if the font is a simple font we should only map
  49390. // to unicode if the base encoding is MacRoman, MacExpert, or WinAnsi or
  49391. // the differences array only contains adobe standard or symbol set names,
  49392. // in pratice it seems better to always try to create a toUnicode
  49393. // map based of the default encoding.
  49394. var toUnicode, charcode, glyphName;
  49395. if (!properties.composite)
  49396. /* is simple font */
  49397. {
  49398. toUnicode = [];
  49399. var encoding = properties.defaultEncoding.slice();
  49400. var baseEncodingName = properties.baseEncodingName;
  49401. // Merge in the differences array.
  49402. var differences = properties.differences;
  49403. for (charcode in differences) {
  49404. glyphName = differences[charcode];
  49405. if (glyphName === '.notdef') {
  49406. // Skip .notdef to prevent rendering errors, e.g. boxes appearing
  49407. // where there should be spaces (fixes issue5256.pdf).
  49408. continue;
  49409. }
  49410. encoding[charcode] = glyphName;
  49411. }
  49412. var glyphsUnicodeMap = getGlyphsUnicode();
  49413. for (charcode in encoding) {
  49414. // a) Map the character code to a character name.
  49415. glyphName = encoding[charcode];
  49416. // b) Look up the character name in the Adobe Glyph List (see the
  49417. // Bibliography) to obtain the corresponding Unicode value.
  49418. if (glyphName === '') {
  49419. continue;
  49420. } else if (glyphsUnicodeMap[glyphName] === undefined) {
  49421. // (undocumented) c) Few heuristics to recognize unknown glyphs
  49422. // NOTE: Adobe Reader does not do this step, but OSX Preview does
  49423. var code = 0;
  49424. switch (glyphName[0]) {
  49425. case 'G':
  49426. // Gxx glyph
  49427. if (glyphName.length === 3) {
  49428. code = parseInt(glyphName.substr(1), 16);
  49429. }
  49430. break;
  49431. case 'g':
  49432. // g00xx glyph
  49433. if (glyphName.length === 5) {
  49434. code = parseInt(glyphName.substr(1), 16);
  49435. }
  49436. break;
  49437. case 'C':
  49438. // Cddd glyph
  49439. case 'c':
  49440. // cddd glyph
  49441. if (glyphName.length >= 3) {
  49442. code = +glyphName.substr(1);
  49443. }
  49444. break;
  49445. default:
  49446. // 'uniXXXX'/'uXXXX{XX}' glyphs
  49447. var unicode = getUnicodeForGlyph(glyphName, glyphsUnicodeMap);
  49448. if (unicode !== -1) {
  49449. code = unicode;
  49450. }
  49451. }
  49452. if (code) {
  49453. // If |baseEncodingName| is one the predefined encodings,
  49454. // and |code| equals |charcode|, using the glyph defined in the
  49455. // baseEncoding seems to yield a better |toUnicode| mapping
  49456. // (fixes issue 5070).
  49457. if (baseEncodingName && code === +charcode) {
  49458. var baseEncoding = getEncoding(baseEncodingName);
  49459. if (baseEncoding && (glyphName = baseEncoding[charcode])) {
  49460. toUnicode[charcode] = String.fromCharCode(glyphsUnicodeMap[glyphName]);
  49461. continue;
  49462. }
  49463. }
  49464. toUnicode[charcode] = String.fromCharCode(code);
  49465. }
  49466. continue;
  49467. }
  49468. toUnicode[charcode] = String.fromCharCode(glyphsUnicodeMap[glyphName]);
  49469. }
  49470. return Promise.resolve(new ToUnicodeMap(toUnicode));
  49471. }
  49472. // If the font is a composite font that uses one of the predefined CMaps
  49473. // listed in Table 118 (except Identity–H and Identity–V) or whose
  49474. // descendant CIDFont uses the Adobe-GB1, Adobe-CNS1, Adobe-Japan1, or
  49475. // Adobe-Korea1 character collection:
  49476. 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'))) {
  49477. // Then:
  49478. // a) Map the character code to a character identifier (CID) according
  49479. // to the font’s CMap.
  49480. // b) Obtain the registry and ordering of the character collection used
  49481. // by the font’s CMap (for example, Adobe and Japan1) from its
  49482. // CIDSystemInfo dictionary.
  49483. var registry = properties.cidSystemInfo.registry;
  49484. var ordering = properties.cidSystemInfo.ordering;
  49485. // c) Construct a second CMap name by concatenating the registry and
  49486. // ordering obtained in step (b) in the format registry–ordering–UCS2
  49487. // (for example, Adobe–Japan1–UCS2).
  49488. var ucs2CMapName = Name.get(registry + '-' + ordering + '-UCS2');
  49489. // d) Obtain the CMap with the name constructed in step (c) (available
  49490. // from the ASN Web site; see the Bibliography).
  49491. return CMapFactory.create(ucs2CMapName, this.options.cMapOptions, null).then(function (ucs2CMap) {
  49492. var cMap = properties.cMap;
  49493. toUnicode = [];
  49494. cMap.forEach(function (charcode, cid) {
  49495. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  49496. // e) Map the CID obtained in step (a) according to the CMap
  49497. // obtained in step (d), producing a Unicode value.
  49498. var ucs2 = ucs2CMap.lookup(cid);
  49499. if (ucs2) {
  49500. toUnicode[charcode] = String.fromCharCode((ucs2.charCodeAt(0) << 8) + ucs2.charCodeAt(1));
  49501. }
  49502. });
  49503. return new ToUnicodeMap(toUnicode);
  49504. });
  49505. }
  49506. // The viewer's choice, just use an identity map.
  49507. return Promise.resolve(new IdentityToUnicodeMap(properties.firstChar, properties.lastChar));
  49508. },
  49509. readToUnicode: function PartialEvaluator_readToUnicode(toUnicode) {
  49510. var cmapObj = toUnicode;
  49511. if (isName(cmapObj)) {
  49512. return CMapFactory.create(cmapObj, this.options.cMapOptions, null).then(function (cmap) {
  49513. if (cmap instanceof IdentityCMap) {
  49514. return new IdentityToUnicodeMap(0, 0xFFFF);
  49515. }
  49516. return new ToUnicodeMap(cmap.getMap());
  49517. });
  49518. } else if (isStream(cmapObj)) {
  49519. return CMapFactory.create(cmapObj, this.options.cMapOptions, null).then(function (cmap) {
  49520. if (cmap instanceof IdentityCMap) {
  49521. return new IdentityToUnicodeMap(0, 0xFFFF);
  49522. }
  49523. var map = new Array(cmap.length);
  49524. // Convert UTF-16BE
  49525. // NOTE: cmap can be a sparse array, so use forEach instead of for(;;)
  49526. // to iterate over all keys.
  49527. cmap.forEach(function (charCode, token) {
  49528. var str = [];
  49529. for (var k = 0; k < token.length; k += 2) {
  49530. var w1 = token.charCodeAt(k) << 8 | token.charCodeAt(k + 1);
  49531. if ((w1 & 0xF800) !== 0xD800) {
  49532. // w1 < 0xD800 || w1 > 0xDFFF
  49533. str.push(w1);
  49534. continue;
  49535. }
  49536. k += 2;
  49537. var w2 = token.charCodeAt(k) << 8 | token.charCodeAt(k + 1);
  49538. str.push(((w1 & 0x3ff) << 10) + (w2 & 0x3ff) + 0x10000);
  49539. }
  49540. map[charCode] = String.fromCharCode.apply(String, str);
  49541. });
  49542. return new ToUnicodeMap(map);
  49543. });
  49544. }
  49545. return Promise.resolve(null);
  49546. },
  49547. readCidToGidMap: function PartialEvaluator_readCidToGidMap(cidToGidStream) {
  49548. // Extract the encoding from the CIDToGIDMap
  49549. var glyphsData = cidToGidStream.getBytes();
  49550. // Set encoding 0 to later verify the font has an encoding
  49551. var result = [];
  49552. for (var j = 0, jj = glyphsData.length; j < jj; j++) {
  49553. var glyphID = glyphsData[j++] << 8 | glyphsData[j];
  49554. if (glyphID === 0) {
  49555. continue;
  49556. }
  49557. var code = j >> 1;
  49558. result[code] = glyphID;
  49559. }
  49560. return result;
  49561. },
  49562. extractWidths: function PartialEvaluator_extractWidths(dict, xref, descriptor, properties) {
  49563. var glyphsWidths = [];
  49564. var defaultWidth = 0;
  49565. var glyphsVMetrics = [];
  49566. var defaultVMetrics;
  49567. var i, ii, j, jj, start, code, widths;
  49568. if (properties.composite) {
  49569. defaultWidth = dict.get('DW') || 1000;
  49570. widths = dict.get('W');
  49571. if (widths) {
  49572. for (i = 0, ii = widths.length; i < ii; i++) {
  49573. start = widths[i++];
  49574. code = xref.fetchIfRef(widths[i]);
  49575. if (isArray(code)) {
  49576. for (j = 0, jj = code.length; j < jj; j++) {
  49577. glyphsWidths[start++] = code[j];
  49578. }
  49579. } else {
  49580. var width = widths[++i];
  49581. for (j = start; j <= code; j++) {
  49582. glyphsWidths[j] = width;
  49583. }
  49584. }
  49585. }
  49586. }
  49587. if (properties.vertical) {
  49588. var vmetrics = dict.get('DW2') || [
  49589. 880,
  49590. -1000
  49591. ];
  49592. defaultVMetrics = [
  49593. vmetrics[1],
  49594. defaultWidth * 0.5,
  49595. vmetrics[0]
  49596. ];
  49597. vmetrics = dict.get('W2');
  49598. if (vmetrics) {
  49599. for (i = 0, ii = vmetrics.length; i < ii; i++) {
  49600. start = vmetrics[i++];
  49601. code = xref.fetchIfRef(vmetrics[i]);
  49602. if (isArray(code)) {
  49603. for (j = 0, jj = code.length; j < jj; j++) {
  49604. glyphsVMetrics[start++] = [
  49605. code[j++],
  49606. code[j++],
  49607. code[j]
  49608. ];
  49609. }
  49610. } else {
  49611. var vmetric = [
  49612. vmetrics[++i],
  49613. vmetrics[++i],
  49614. vmetrics[++i]
  49615. ];
  49616. for (j = start; j <= code; j++) {
  49617. glyphsVMetrics[j] = vmetric;
  49618. }
  49619. }
  49620. }
  49621. }
  49622. }
  49623. } else {
  49624. var firstChar = properties.firstChar;
  49625. widths = dict.get('Widths');
  49626. if (widths) {
  49627. j = firstChar;
  49628. for (i = 0, ii = widths.length; i < ii; i++) {
  49629. glyphsWidths[j++] = widths[i];
  49630. }
  49631. defaultWidth = parseFloat(descriptor.get('MissingWidth')) || 0;
  49632. } else {
  49633. // Trying get the BaseFont metrics (see comment above).
  49634. var baseFontName = dict.get('BaseFont');
  49635. if (isName(baseFontName)) {
  49636. var metrics = this.getBaseFontMetrics(baseFontName.name);
  49637. glyphsWidths = this.buildCharCodeToWidth(metrics.widths, properties);
  49638. defaultWidth = metrics.defaultWidth;
  49639. }
  49640. }
  49641. }
  49642. // Heuristic: detection of monospace font by checking all non-zero widths
  49643. var isMonospace = true;
  49644. var firstWidth = defaultWidth;
  49645. for (var glyph in glyphsWidths) {
  49646. var glyphWidth = glyphsWidths[glyph];
  49647. if (!glyphWidth) {
  49648. continue;
  49649. }
  49650. if (!firstWidth) {
  49651. firstWidth = glyphWidth;
  49652. continue;
  49653. }
  49654. if (firstWidth !== glyphWidth) {
  49655. isMonospace = false;
  49656. break;
  49657. }
  49658. }
  49659. if (isMonospace) {
  49660. properties.flags |= FontFlags.FixedPitch;
  49661. }
  49662. properties.defaultWidth = defaultWidth;
  49663. properties.widths = glyphsWidths;
  49664. properties.defaultVMetrics = defaultVMetrics;
  49665. properties.vmetrics = glyphsVMetrics;
  49666. },
  49667. isSerifFont: function PartialEvaluator_isSerifFont(baseFontName) {
  49668. // Simulating descriptor flags attribute
  49669. var fontNameWoStyle = baseFontName.split('-')[0];
  49670. return fontNameWoStyle in getSerifFonts() || fontNameWoStyle.search(/serif/gi) !== -1;
  49671. },
  49672. getBaseFontMetrics: function PartialEvaluator_getBaseFontMetrics(name) {
  49673. var defaultWidth = 0;
  49674. var widths = [];
  49675. var monospace = false;
  49676. var stdFontMap = getStdFontMap();
  49677. var lookupName = stdFontMap[name] || name;
  49678. var Metrics = getMetrics();
  49679. if (!(lookupName in Metrics)) {
  49680. // Use default fonts for looking up font metrics if the passed
  49681. // font is not a base font
  49682. if (this.isSerifFont(name)) {
  49683. lookupName = 'Times-Roman';
  49684. } else {
  49685. lookupName = 'Helvetica';
  49686. }
  49687. }
  49688. var glyphWidths = Metrics[lookupName];
  49689. if (isNum(glyphWidths)) {
  49690. defaultWidth = glyphWidths;
  49691. monospace = true;
  49692. } else {
  49693. widths = glyphWidths();
  49694. }
  49695. // expand lazy widths array
  49696. return {
  49697. defaultWidth: defaultWidth,
  49698. monospace: monospace,
  49699. widths: widths
  49700. };
  49701. },
  49702. buildCharCodeToWidth: function PartialEvaluator_bulildCharCodeToWidth(widthsByGlyphName, properties) {
  49703. var widths = Object.create(null);
  49704. var differences = properties.differences;
  49705. var encoding = properties.defaultEncoding;
  49706. for (var charCode = 0; charCode < 256; charCode++) {
  49707. if (charCode in differences && widthsByGlyphName[differences[charCode]]) {
  49708. widths[charCode] = widthsByGlyphName[differences[charCode]];
  49709. continue;
  49710. }
  49711. if (charCode in encoding && widthsByGlyphName[encoding[charCode]]) {
  49712. widths[charCode] = widthsByGlyphName[encoding[charCode]];
  49713. continue;
  49714. }
  49715. }
  49716. return widths;
  49717. },
  49718. preEvaluateFont: function PartialEvaluator_preEvaluateFont(dict, xref) {
  49719. var baseDict = dict;
  49720. var type = dict.get('Subtype');
  49721. assert(isName(type), 'invalid font Subtype');
  49722. var composite = false;
  49723. var uint8array;
  49724. if (type.name === 'Type0') {
  49725. // If font is a composite
  49726. // - get the descendant font
  49727. // - set the type according to the descendant font
  49728. // - get the FontDescriptor from the descendant font
  49729. var df = dict.get('DescendantFonts');
  49730. if (!df) {
  49731. error('Descendant fonts are not specified');
  49732. }
  49733. dict = isArray(df) ? xref.fetchIfRef(df[0]) : df;
  49734. type = dict.get('Subtype');
  49735. assert(isName(type), 'invalid font Subtype');
  49736. composite = true;
  49737. }
  49738. var descriptor = dict.get('FontDescriptor');
  49739. if (descriptor) {
  49740. var hash = new MurmurHash3_64();
  49741. var encoding = baseDict.getRaw('Encoding');
  49742. if (isName(encoding)) {
  49743. hash.update(encoding.name);
  49744. } else if (isRef(encoding)) {
  49745. hash.update(encoding.toString());
  49746. } else if (isDict(encoding)) {
  49747. var keys = encoding.getKeys();
  49748. for (var i = 0, ii = keys.length; i < ii; i++) {
  49749. var entry = encoding.getRaw(keys[i]);
  49750. if (isName(entry)) {
  49751. hash.update(entry.name);
  49752. } else if (isRef(entry)) {
  49753. hash.update(entry.toString());
  49754. } else if (isArray(entry)) {
  49755. // 'Differences' entry.
  49756. // Ideally we should check the contents of the array, but to avoid
  49757. // parsing it here and then again in |extractDataStructures|,
  49758. // we only use the array length for now (fixes bug1157493.pdf).
  49759. hash.update(entry.length.toString());
  49760. }
  49761. }
  49762. }
  49763. var toUnicode = dict.get('ToUnicode') || baseDict.get('ToUnicode');
  49764. if (isStream(toUnicode)) {
  49765. var stream = toUnicode.str || toUnicode;
  49766. uint8array = stream.buffer ? new Uint8Array(stream.buffer.buffer, 0, stream.bufferLength) : new Uint8Array(stream.bytes.buffer, stream.start, stream.end - stream.start);
  49767. hash.update(uint8array);
  49768. } else if (isName(toUnicode)) {
  49769. hash.update(toUnicode.name);
  49770. }
  49771. var widths = dict.get('Widths') || baseDict.get('Widths');
  49772. if (widths) {
  49773. uint8array = new Uint8Array(new Uint32Array(widths).buffer);
  49774. hash.update(uint8array);
  49775. }
  49776. }
  49777. return {
  49778. descriptor: descriptor,
  49779. dict: dict,
  49780. baseDict: baseDict,
  49781. composite: composite,
  49782. type: type.name,
  49783. hash: hash ? hash.hexdigest() : ''
  49784. };
  49785. },
  49786. translateFont: function PartialEvaluator_translateFont(preEvaluatedFont, xref) {
  49787. var baseDict = preEvaluatedFont.baseDict;
  49788. var dict = preEvaluatedFont.dict;
  49789. var composite = preEvaluatedFont.composite;
  49790. var descriptor = preEvaluatedFont.descriptor;
  49791. var type = preEvaluatedFont.type;
  49792. var maxCharIndex = composite ? 0xFFFF : 0xFF;
  49793. var cMapOptions = this.options.cMapOptions;
  49794. var properties;
  49795. if (!descriptor) {
  49796. if (type === 'Type3') {
  49797. // FontDescriptor is only required for Type3 fonts when the document
  49798. // is a tagged pdf. Create a barbebones one to get by.
  49799. descriptor = new Dict(null);
  49800. descriptor.set('FontName', Name.get(type));
  49801. descriptor.set('FontBBox', dict.getArray('FontBBox'));
  49802. } else {
  49803. // Before PDF 1.5 if the font was one of the base 14 fonts, having a
  49804. // FontDescriptor was not required.
  49805. // This case is here for compatibility.
  49806. var baseFontName = dict.get('BaseFont');
  49807. if (!isName(baseFontName)) {
  49808. error('Base font is not specified');
  49809. }
  49810. // Using base font name as a font name.
  49811. baseFontName = baseFontName.name.replace(/[,_]/g, '-');
  49812. var metrics = this.getBaseFontMetrics(baseFontName);
  49813. // Simulating descriptor flags attribute
  49814. var fontNameWoStyle = baseFontName.split('-')[0];
  49815. var flags = (this.isSerifFont(fontNameWoStyle) ? FontFlags.Serif : 0) | (metrics.monospace ? FontFlags.FixedPitch : 0) | (getSymbolsFonts()[fontNameWoStyle] ? FontFlags.Symbolic : FontFlags.Nonsymbolic);
  49816. properties = {
  49817. type: type,
  49818. name: baseFontName,
  49819. widths: metrics.widths,
  49820. defaultWidth: metrics.defaultWidth,
  49821. flags: flags,
  49822. firstChar: 0,
  49823. lastChar: maxCharIndex
  49824. };
  49825. return this.extractDataStructures(dict, dict, xref, properties).then(function (properties) {
  49826. properties.widths = this.buildCharCodeToWidth(metrics.widths, properties);
  49827. return new Font(baseFontName, null, properties);
  49828. }.bind(this));
  49829. }
  49830. }
  49831. // According to the spec if 'FontDescriptor' is declared, 'FirstChar',
  49832. // 'LastChar' and 'Widths' should exist too, but some PDF encoders seem
  49833. // to ignore this rule when a variant of a standard font is used.
  49834. // TODO Fill the width array depending on which of the base font this is
  49835. // a variant.
  49836. var firstChar = dict.get('FirstChar') || 0;
  49837. var lastChar = dict.get('LastChar') || maxCharIndex;
  49838. var fontName = descriptor.get('FontName');
  49839. var baseFont = dict.get('BaseFont');
  49840. // Some bad PDFs have a string as the font name.
  49841. if (isString(fontName)) {
  49842. fontName = Name.get(fontName);
  49843. }
  49844. if (isString(baseFont)) {
  49845. baseFont = Name.get(baseFont);
  49846. }
  49847. if (type !== 'Type3') {
  49848. var fontNameStr = fontName && fontName.name;
  49849. var baseFontStr = baseFont && baseFont.name;
  49850. if (fontNameStr !== baseFontStr) {
  49851. info('The FontDescriptor\'s FontName is "' + fontNameStr + '" but should be the same as the Font\'s BaseFont "' + baseFontStr + '"');
  49852. // Workaround for cases where e.g. fontNameStr = 'Arial' and
  49853. // baseFontStr = 'Arial,Bold' (needed when no font file is embedded).
  49854. if (fontNameStr && baseFontStr && baseFontStr.indexOf(fontNameStr) === 0) {
  49855. fontName = baseFont;
  49856. }
  49857. }
  49858. }
  49859. fontName = fontName || baseFont;
  49860. assert(isName(fontName), 'invalid font name');
  49861. var fontFile = descriptor.get('FontFile', 'FontFile2', 'FontFile3');
  49862. if (fontFile) {
  49863. if (fontFile.dict) {
  49864. var subtype = fontFile.dict.get('Subtype');
  49865. if (subtype) {
  49866. subtype = subtype.name;
  49867. }
  49868. var length1 = fontFile.dict.get('Length1');
  49869. var length2 = fontFile.dict.get('Length2');
  49870. var length3 = fontFile.dict.get('Length3');
  49871. }
  49872. }
  49873. properties = {
  49874. type: type,
  49875. name: fontName.name,
  49876. subtype: subtype,
  49877. file: fontFile,
  49878. length1: length1,
  49879. length2: length2,
  49880. length3: length3,
  49881. loadedName: baseDict.loadedName,
  49882. composite: composite,
  49883. wideChars: composite,
  49884. fixedPitch: false,
  49885. fontMatrix: dict.getArray('FontMatrix') || FONT_IDENTITY_MATRIX,
  49886. firstChar: firstChar || 0,
  49887. lastChar: lastChar || maxCharIndex,
  49888. bbox: descriptor.getArray('FontBBox'),
  49889. ascent: descriptor.get('Ascent'),
  49890. descent: descriptor.get('Descent'),
  49891. xHeight: descriptor.get('XHeight'),
  49892. capHeight: descriptor.get('CapHeight'),
  49893. flags: descriptor.get('Flags'),
  49894. italicAngle: descriptor.get('ItalicAngle'),
  49895. coded: false
  49896. };
  49897. var cMapPromise;
  49898. if (composite) {
  49899. var cidEncoding = baseDict.get('Encoding');
  49900. if (isName(cidEncoding)) {
  49901. properties.cidEncoding = cidEncoding.name;
  49902. }
  49903. cMapPromise = CMapFactory.create(cidEncoding, cMapOptions, null).then(function (cMap) {
  49904. properties.cMap = cMap;
  49905. properties.vertical = properties.cMap.vertical;
  49906. });
  49907. } else {
  49908. cMapPromise = Promise.resolve(undefined);
  49909. }
  49910. return cMapPromise.then(function () {
  49911. return this.extractDataStructures(dict, baseDict, xref, properties);
  49912. }.bind(this)).then(function (properties) {
  49913. this.extractWidths(dict, xref, descriptor, properties);
  49914. if (type === 'Type3') {
  49915. properties.isType3Font = true;
  49916. }
  49917. return new Font(fontName.name, fontFile, properties);
  49918. }.bind(this));
  49919. }
  49920. };
  49921. return PartialEvaluator;
  49922. }();
  49923. var TranslatedFont = function TranslatedFontClosure() {
  49924. function TranslatedFont(loadedName, font, dict) {
  49925. this.loadedName = loadedName;
  49926. this.font = font;
  49927. this.dict = dict;
  49928. this.type3Loaded = null;
  49929. this.sent = false;
  49930. }
  49931. TranslatedFont.prototype = {
  49932. send: function (handler) {
  49933. if (this.sent) {
  49934. return;
  49935. }
  49936. var fontData = this.font.exportData();
  49937. handler.send('commonobj', [
  49938. this.loadedName,
  49939. 'Font',
  49940. fontData
  49941. ]);
  49942. this.sent = true;
  49943. },
  49944. loadType3Data: function (evaluator, resources, parentOperatorList, task) {
  49945. assert(this.font.isType3Font);
  49946. if (this.type3Loaded) {
  49947. return this.type3Loaded;
  49948. }
  49949. var translatedFont = this.font;
  49950. var loadCharProcsPromise = Promise.resolve();
  49951. var charProcs = this.dict.get('CharProcs');
  49952. var fontResources = this.dict.get('Resources') || resources;
  49953. var charProcKeys = charProcs.getKeys();
  49954. var charProcOperatorList = Object.create(null);
  49955. for (var i = 0, n = charProcKeys.length; i < n; ++i) {
  49956. loadCharProcsPromise = loadCharProcsPromise.then(function (key) {
  49957. var glyphStream = charProcs.get(key);
  49958. var operatorList = new OperatorList();
  49959. return evaluator.getOperatorList(glyphStream, task, fontResources, operatorList).then(function () {
  49960. charProcOperatorList[key] = operatorList.getIR();
  49961. // Add the dependencies to the parent operator list so they are
  49962. // resolved before sub operator list is executed synchronously.
  49963. parentOperatorList.addDependencies(operatorList.dependencies);
  49964. }, function (reason) {
  49965. warn('Type3 font resource \"' + key + '\" is not available');
  49966. var operatorList = new OperatorList();
  49967. charProcOperatorList[key] = operatorList.getIR();
  49968. });
  49969. }.bind(this, charProcKeys[i]));
  49970. }
  49971. this.type3Loaded = loadCharProcsPromise.then(function () {
  49972. translatedFont.charProcOperatorList = charProcOperatorList;
  49973. });
  49974. return this.type3Loaded;
  49975. }
  49976. };
  49977. return TranslatedFont;
  49978. }();
  49979. var OperatorList = function OperatorListClosure() {
  49980. var CHUNK_SIZE = 1000;
  49981. var CHUNK_SIZE_ABOUT = CHUNK_SIZE - 5;
  49982. // close to chunk size
  49983. function getTransfers(queue) {
  49984. var transfers = [];
  49985. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  49986. for (var i = 0, ii = queue.length; i < ii; i++) {
  49987. switch (fnArray[i]) {
  49988. case OPS.paintInlineImageXObject:
  49989. case OPS.paintInlineImageXObjectGroup:
  49990. case OPS.paintImageMaskXObject:
  49991. var arg = argsArray[i][0];
  49992. // first param in imgData
  49993. if (!arg.cached) {
  49994. transfers.push(arg.data.buffer);
  49995. }
  49996. break;
  49997. }
  49998. }
  49999. return transfers;
  50000. }
  50001. function OperatorList(intent, messageHandler, pageIndex) {
  50002. this.messageHandler = messageHandler;
  50003. this.fnArray = [];
  50004. this.argsArray = [];
  50005. this.dependencies = Object.create(null);
  50006. this._totalLength = 0;
  50007. this.pageIndex = pageIndex;
  50008. this.intent = intent;
  50009. }
  50010. OperatorList.prototype = {
  50011. get length() {
  50012. return this.argsArray.length;
  50013. },
  50014. /**
  50015. * @returns {number} The total length of the entire operator list,
  50016. * since `this.length === 0` after flushing.
  50017. */
  50018. get totalLength() {
  50019. return this._totalLength + this.length;
  50020. },
  50021. addOp: function (fn, args) {
  50022. this.fnArray.push(fn);
  50023. this.argsArray.push(args);
  50024. if (this.messageHandler) {
  50025. if (this.fnArray.length >= CHUNK_SIZE) {
  50026. this.flush();
  50027. } else if (this.fnArray.length >= CHUNK_SIZE_ABOUT && (fn === OPS.restore || fn === OPS.endText)) {
  50028. // heuristic to flush on boundary of restore or endText
  50029. this.flush();
  50030. }
  50031. }
  50032. },
  50033. addDependency: function (dependency) {
  50034. if (dependency in this.dependencies) {
  50035. return;
  50036. }
  50037. this.dependencies[dependency] = true;
  50038. this.addOp(OPS.dependency, [dependency]);
  50039. },
  50040. addDependencies: function (dependencies) {
  50041. for (var key in dependencies) {
  50042. this.addDependency(key);
  50043. }
  50044. },
  50045. addOpList: function (opList) {
  50046. Util.extendObj(this.dependencies, opList.dependencies);
  50047. for (var i = 0, ii = opList.length; i < ii; i++) {
  50048. this.addOp(opList.fnArray[i], opList.argsArray[i]);
  50049. }
  50050. },
  50051. getIR: function () {
  50052. return {
  50053. fnArray: this.fnArray,
  50054. argsArray: this.argsArray,
  50055. length: this.length
  50056. };
  50057. },
  50058. flush: function (lastChunk) {
  50059. if (this.intent !== 'oplist') {
  50060. new QueueOptimizer().optimize(this);
  50061. }
  50062. var transfers = getTransfers(this);
  50063. var length = this.length;
  50064. this._totalLength += length;
  50065. this.messageHandler.send('RenderPageChunk', {
  50066. operatorList: {
  50067. fnArray: this.fnArray,
  50068. argsArray: this.argsArray,
  50069. lastChunk: lastChunk,
  50070. length: length
  50071. },
  50072. pageIndex: this.pageIndex,
  50073. intent: this.intent
  50074. }, transfers);
  50075. this.dependencies = Object.create(null);
  50076. this.fnArray.length = 0;
  50077. this.argsArray.length = 0;
  50078. }
  50079. };
  50080. return OperatorList;
  50081. }();
  50082. var StateManager = function StateManagerClosure() {
  50083. function StateManager(initialState) {
  50084. this.state = initialState;
  50085. this.stateStack = [];
  50086. }
  50087. StateManager.prototype = {
  50088. save: function () {
  50089. var old = this.state;
  50090. this.stateStack.push(this.state);
  50091. this.state = old.clone();
  50092. },
  50093. restore: function () {
  50094. var prev = this.stateStack.pop();
  50095. if (prev) {
  50096. this.state = prev;
  50097. }
  50098. },
  50099. transform: function (args) {
  50100. this.state.ctm = Util.transform(this.state.ctm, args);
  50101. }
  50102. };
  50103. return StateManager;
  50104. }();
  50105. var TextState = function TextStateClosure() {
  50106. function TextState() {
  50107. this.ctm = new Float32Array(IDENTITY_MATRIX);
  50108. this.fontName = null;
  50109. this.fontSize = 0;
  50110. this.font = null;
  50111. this.fontMatrix = FONT_IDENTITY_MATRIX;
  50112. this.textMatrix = IDENTITY_MATRIX.slice();
  50113. this.textLineMatrix = IDENTITY_MATRIX.slice();
  50114. this.charSpacing = 0;
  50115. this.wordSpacing = 0;
  50116. this.leading = 0;
  50117. this.textHScale = 1;
  50118. this.textRise = 0;
  50119. }
  50120. TextState.prototype = {
  50121. setTextMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  50122. var m = this.textMatrix;
  50123. m[0] = a;
  50124. m[1] = b;
  50125. m[2] = c;
  50126. m[3] = d;
  50127. m[4] = e;
  50128. m[5] = f;
  50129. },
  50130. setTextLineMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  50131. var m = this.textLineMatrix;
  50132. m[0] = a;
  50133. m[1] = b;
  50134. m[2] = c;
  50135. m[3] = d;
  50136. m[4] = e;
  50137. m[5] = f;
  50138. },
  50139. translateTextMatrix: function TextState_translateTextMatrix(x, y) {
  50140. var m = this.textMatrix;
  50141. m[4] = m[0] * x + m[2] * y + m[4];
  50142. m[5] = m[1] * x + m[3] * y + m[5];
  50143. },
  50144. translateTextLineMatrix: function TextState_translateTextMatrix(x, y) {
  50145. var m = this.textLineMatrix;
  50146. m[4] = m[0] * x + m[2] * y + m[4];
  50147. m[5] = m[1] * x + m[3] * y + m[5];
  50148. },
  50149. calcTextLineMatrixAdvance: function TextState_calcTextLineMatrixAdvance(a, b, c, d, e, f) {
  50150. var font = this.font;
  50151. if (!font) {
  50152. return null;
  50153. }
  50154. var m = this.textLineMatrix;
  50155. if (!(a === m[0] && b === m[1] && c === m[2] && d === m[3])) {
  50156. return null;
  50157. }
  50158. var txDiff = e - m[4], tyDiff = f - m[5];
  50159. if (font.vertical && txDiff !== 0 || !font.vertical && tyDiff !== 0) {
  50160. return null;
  50161. }
  50162. var tx, ty, denominator = a * d - b * c;
  50163. if (font.vertical) {
  50164. tx = -tyDiff * c / denominator;
  50165. ty = tyDiff * a / denominator;
  50166. } else {
  50167. tx = txDiff * d / denominator;
  50168. ty = -txDiff * b / denominator;
  50169. }
  50170. return {
  50171. width: tx,
  50172. height: ty,
  50173. value: font.vertical ? ty : tx
  50174. };
  50175. },
  50176. calcRenderMatrix: function TextState_calcRendeMatrix(ctm) {
  50177. // 9.4.4 Text Space Details
  50178. var tsm = [
  50179. this.fontSize * this.textHScale,
  50180. 0,
  50181. 0,
  50182. this.fontSize,
  50183. 0,
  50184. this.textRise
  50185. ];
  50186. return Util.transform(ctm, Util.transform(this.textMatrix, tsm));
  50187. },
  50188. carriageReturn: function TextState_carriageReturn() {
  50189. this.translateTextLineMatrix(0, -this.leading);
  50190. this.textMatrix = this.textLineMatrix.slice();
  50191. },
  50192. clone: function TextState_clone() {
  50193. var clone = Object.create(this);
  50194. clone.textMatrix = this.textMatrix.slice();
  50195. clone.textLineMatrix = this.textLineMatrix.slice();
  50196. clone.fontMatrix = this.fontMatrix.slice();
  50197. return clone;
  50198. }
  50199. };
  50200. return TextState;
  50201. }();
  50202. var EvalState = function EvalStateClosure() {
  50203. function EvalState() {
  50204. this.ctm = new Float32Array(IDENTITY_MATRIX);
  50205. this.font = null;
  50206. this.textRenderingMode = TextRenderingMode.FILL;
  50207. this.fillColorSpace = ColorSpace.singletons.gray;
  50208. this.strokeColorSpace = ColorSpace.singletons.gray;
  50209. }
  50210. EvalState.prototype = {
  50211. clone: function CanvasExtraState_clone() {
  50212. return Object.create(this);
  50213. }
  50214. };
  50215. return EvalState;
  50216. }();
  50217. var EvaluatorPreprocessor = function EvaluatorPreprocessorClosure() {
  50218. // Specifies properties for each command
  50219. //
  50220. // If variableArgs === true: [0, `numArgs`] expected
  50221. // If variableArgs === false: exactly `numArgs` expected
  50222. var getOPMap = getLookupTableFactory(function (t) {
  50223. // Graphic state
  50224. t['w'] = {
  50225. id: OPS.setLineWidth,
  50226. numArgs: 1,
  50227. variableArgs: false
  50228. };
  50229. t['J'] = {
  50230. id: OPS.setLineCap,
  50231. numArgs: 1,
  50232. variableArgs: false
  50233. };
  50234. t['j'] = {
  50235. id: OPS.setLineJoin,
  50236. numArgs: 1,
  50237. variableArgs: false
  50238. };
  50239. t['M'] = {
  50240. id: OPS.setMiterLimit,
  50241. numArgs: 1,
  50242. variableArgs: false
  50243. };
  50244. t['d'] = {
  50245. id: OPS.setDash,
  50246. numArgs: 2,
  50247. variableArgs: false
  50248. };
  50249. t['ri'] = {
  50250. id: OPS.setRenderingIntent,
  50251. numArgs: 1,
  50252. variableArgs: false
  50253. };
  50254. t['i'] = {
  50255. id: OPS.setFlatness,
  50256. numArgs: 1,
  50257. variableArgs: false
  50258. };
  50259. t['gs'] = {
  50260. id: OPS.setGState,
  50261. numArgs: 1,
  50262. variableArgs: false
  50263. };
  50264. t['q'] = {
  50265. id: OPS.save,
  50266. numArgs: 0,
  50267. variableArgs: false
  50268. };
  50269. t['Q'] = {
  50270. id: OPS.restore,
  50271. numArgs: 0,
  50272. variableArgs: false
  50273. };
  50274. t['cm'] = {
  50275. id: OPS.transform,
  50276. numArgs: 6,
  50277. variableArgs: false
  50278. };
  50279. // Path
  50280. t['m'] = {
  50281. id: OPS.moveTo,
  50282. numArgs: 2,
  50283. variableArgs: false
  50284. };
  50285. t['l'] = {
  50286. id: OPS.lineTo,
  50287. numArgs: 2,
  50288. variableArgs: false
  50289. };
  50290. t['c'] = {
  50291. id: OPS.curveTo,
  50292. numArgs: 6,
  50293. variableArgs: false
  50294. };
  50295. t['v'] = {
  50296. id: OPS.curveTo2,
  50297. numArgs: 4,
  50298. variableArgs: false
  50299. };
  50300. t['y'] = {
  50301. id: OPS.curveTo3,
  50302. numArgs: 4,
  50303. variableArgs: false
  50304. };
  50305. t['h'] = {
  50306. id: OPS.closePath,
  50307. numArgs: 0,
  50308. variableArgs: false
  50309. };
  50310. t['re'] = {
  50311. id: OPS.rectangle,
  50312. numArgs: 4,
  50313. variableArgs: false
  50314. };
  50315. t['S'] = {
  50316. id: OPS.stroke,
  50317. numArgs: 0,
  50318. variableArgs: false
  50319. };
  50320. t['s'] = {
  50321. id: OPS.closeStroke,
  50322. numArgs: 0,
  50323. variableArgs: false
  50324. };
  50325. t['f'] = {
  50326. id: OPS.fill,
  50327. numArgs: 0,
  50328. variableArgs: false
  50329. };
  50330. t['F'] = {
  50331. id: OPS.fill,
  50332. numArgs: 0,
  50333. variableArgs: false
  50334. };
  50335. t['f*'] = {
  50336. id: OPS.eoFill,
  50337. numArgs: 0,
  50338. variableArgs: false
  50339. };
  50340. t['B'] = {
  50341. id: OPS.fillStroke,
  50342. numArgs: 0,
  50343. variableArgs: false
  50344. };
  50345. t['B*'] = {
  50346. id: OPS.eoFillStroke,
  50347. numArgs: 0,
  50348. variableArgs: false
  50349. };
  50350. t['b'] = {
  50351. id: OPS.closeFillStroke,
  50352. numArgs: 0,
  50353. variableArgs: false
  50354. };
  50355. t['b*'] = {
  50356. id: OPS.closeEOFillStroke,
  50357. numArgs: 0,
  50358. variableArgs: false
  50359. };
  50360. t['n'] = {
  50361. id: OPS.endPath,
  50362. numArgs: 0,
  50363. variableArgs: false
  50364. };
  50365. // Clipping
  50366. t['W'] = {
  50367. id: OPS.clip,
  50368. numArgs: 0,
  50369. variableArgs: false
  50370. };
  50371. t['W*'] = {
  50372. id: OPS.eoClip,
  50373. numArgs: 0,
  50374. variableArgs: false
  50375. };
  50376. // Text
  50377. t['BT'] = {
  50378. id: OPS.beginText,
  50379. numArgs: 0,
  50380. variableArgs: false
  50381. };
  50382. t['ET'] = {
  50383. id: OPS.endText,
  50384. numArgs: 0,
  50385. variableArgs: false
  50386. };
  50387. t['Tc'] = {
  50388. id: OPS.setCharSpacing,
  50389. numArgs: 1,
  50390. variableArgs: false
  50391. };
  50392. t['Tw'] = {
  50393. id: OPS.setWordSpacing,
  50394. numArgs: 1,
  50395. variableArgs: false
  50396. };
  50397. t['Tz'] = {
  50398. id: OPS.setHScale,
  50399. numArgs: 1,
  50400. variableArgs: false
  50401. };
  50402. t['TL'] = {
  50403. id: OPS.setLeading,
  50404. numArgs: 1,
  50405. variableArgs: false
  50406. };
  50407. t['Tf'] = {
  50408. id: OPS.setFont,
  50409. numArgs: 2,
  50410. variableArgs: false
  50411. };
  50412. t['Tr'] = {
  50413. id: OPS.setTextRenderingMode,
  50414. numArgs: 1,
  50415. variableArgs: false
  50416. };
  50417. t['Ts'] = {
  50418. id: OPS.setTextRise,
  50419. numArgs: 1,
  50420. variableArgs: false
  50421. };
  50422. t['Td'] = {
  50423. id: OPS.moveText,
  50424. numArgs: 2,
  50425. variableArgs: false
  50426. };
  50427. t['TD'] = {
  50428. id: OPS.setLeadingMoveText,
  50429. numArgs: 2,
  50430. variableArgs: false
  50431. };
  50432. t['Tm'] = {
  50433. id: OPS.setTextMatrix,
  50434. numArgs: 6,
  50435. variableArgs: false
  50436. };
  50437. t['T*'] = {
  50438. id: OPS.nextLine,
  50439. numArgs: 0,
  50440. variableArgs: false
  50441. };
  50442. t['Tj'] = {
  50443. id: OPS.showText,
  50444. numArgs: 1,
  50445. variableArgs: false
  50446. };
  50447. t['TJ'] = {
  50448. id: OPS.showSpacedText,
  50449. numArgs: 1,
  50450. variableArgs: false
  50451. };
  50452. t['\''] = {
  50453. id: OPS.nextLineShowText,
  50454. numArgs: 1,
  50455. variableArgs: false
  50456. };
  50457. t['"'] = {
  50458. id: OPS.nextLineSetSpacingShowText,
  50459. numArgs: 3,
  50460. variableArgs: false
  50461. };
  50462. // Type3 fonts
  50463. t['d0'] = {
  50464. id: OPS.setCharWidth,
  50465. numArgs: 2,
  50466. variableArgs: false
  50467. };
  50468. t['d1'] = {
  50469. id: OPS.setCharWidthAndBounds,
  50470. numArgs: 6,
  50471. variableArgs: false
  50472. };
  50473. // Color
  50474. t['CS'] = {
  50475. id: OPS.setStrokeColorSpace,
  50476. numArgs: 1,
  50477. variableArgs: false
  50478. };
  50479. t['cs'] = {
  50480. id: OPS.setFillColorSpace,
  50481. numArgs: 1,
  50482. variableArgs: false
  50483. };
  50484. t['SC'] = {
  50485. id: OPS.setStrokeColor,
  50486. numArgs: 4,
  50487. variableArgs: true
  50488. };
  50489. t['SCN'] = {
  50490. id: OPS.setStrokeColorN,
  50491. numArgs: 33,
  50492. variableArgs: true
  50493. };
  50494. t['sc'] = {
  50495. id: OPS.setFillColor,
  50496. numArgs: 4,
  50497. variableArgs: true
  50498. };
  50499. t['scn'] = {
  50500. id: OPS.setFillColorN,
  50501. numArgs: 33,
  50502. variableArgs: true
  50503. };
  50504. t['G'] = {
  50505. id: OPS.setStrokeGray,
  50506. numArgs: 1,
  50507. variableArgs: false
  50508. };
  50509. t['g'] = {
  50510. id: OPS.setFillGray,
  50511. numArgs: 1,
  50512. variableArgs: false
  50513. };
  50514. t['RG'] = {
  50515. id: OPS.setStrokeRGBColor,
  50516. numArgs: 3,
  50517. variableArgs: false
  50518. };
  50519. t['rg'] = {
  50520. id: OPS.setFillRGBColor,
  50521. numArgs: 3,
  50522. variableArgs: false
  50523. };
  50524. t['K'] = {
  50525. id: OPS.setStrokeCMYKColor,
  50526. numArgs: 4,
  50527. variableArgs: false
  50528. };
  50529. t['k'] = {
  50530. id: OPS.setFillCMYKColor,
  50531. numArgs: 4,
  50532. variableArgs: false
  50533. };
  50534. // Shading
  50535. t['sh'] = {
  50536. id: OPS.shadingFill,
  50537. numArgs: 1,
  50538. variableArgs: false
  50539. };
  50540. // Images
  50541. t['BI'] = {
  50542. id: OPS.beginInlineImage,
  50543. numArgs: 0,
  50544. variableArgs: false
  50545. };
  50546. t['ID'] = {
  50547. id: OPS.beginImageData,
  50548. numArgs: 0,
  50549. variableArgs: false
  50550. };
  50551. t['EI'] = {
  50552. id: OPS.endInlineImage,
  50553. numArgs: 1,
  50554. variableArgs: false
  50555. };
  50556. // XObjects
  50557. t['Do'] = {
  50558. id: OPS.paintXObject,
  50559. numArgs: 1,
  50560. variableArgs: false
  50561. };
  50562. t['MP'] = {
  50563. id: OPS.markPoint,
  50564. numArgs: 1,
  50565. variableArgs: false
  50566. };
  50567. t['DP'] = {
  50568. id: OPS.markPointProps,
  50569. numArgs: 2,
  50570. variableArgs: false
  50571. };
  50572. t['BMC'] = {
  50573. id: OPS.beginMarkedContent,
  50574. numArgs: 1,
  50575. variableArgs: false
  50576. };
  50577. t['BDC'] = {
  50578. id: OPS.beginMarkedContentProps,
  50579. numArgs: 2,
  50580. variableArgs: false
  50581. };
  50582. t['EMC'] = {
  50583. id: OPS.endMarkedContent,
  50584. numArgs: 0,
  50585. variableArgs: false
  50586. };
  50587. // Compatibility
  50588. t['BX'] = {
  50589. id: OPS.beginCompat,
  50590. numArgs: 0,
  50591. variableArgs: false
  50592. };
  50593. t['EX'] = {
  50594. id: OPS.endCompat,
  50595. numArgs: 0,
  50596. variableArgs: false
  50597. };
  50598. // (reserved partial commands for the lexer)
  50599. t['BM'] = null;
  50600. t['BD'] = null;
  50601. t['true'] = null;
  50602. t['fa'] = null;
  50603. t['fal'] = null;
  50604. t['fals'] = null;
  50605. t['false'] = null;
  50606. t['nu'] = null;
  50607. t['nul'] = null;
  50608. t['null'] = null;
  50609. });
  50610. function EvaluatorPreprocessor(stream, xref, stateManager) {
  50611. this.opMap = getOPMap();
  50612. // TODO(mduan): pass array of knownCommands rather than this.opMap
  50613. // dictionary
  50614. this.parser = new Parser(new Lexer(stream, this.opMap), false, xref);
  50615. this.stateManager = stateManager;
  50616. this.nonProcessedArgs = [];
  50617. }
  50618. EvaluatorPreprocessor.prototype = {
  50619. get savedStatesDepth() {
  50620. return this.stateManager.stateStack.length;
  50621. },
  50622. // |operation| is an object with two fields:
  50623. //
  50624. // - |fn| is an out param.
  50625. //
  50626. // - |args| is an inout param. On entry, it should have one of two values.
  50627. //
  50628. // - An empty array. This indicates that the caller is providing the
  50629. // array in which the args will be stored in. The caller should use
  50630. // this value if it can reuse a single array for each call to read().
  50631. //
  50632. // - |null|. This indicates that the caller needs this function to create
  50633. // the array in which any args are stored in. If there are zero args,
  50634. // this function will leave |operation.args| as |null| (thus avoiding
  50635. // allocations that would occur if we used an empty array to represent
  50636. // zero arguments). Otherwise, it will replace |null| with a new array
  50637. // containing the arguments. The caller should use this value if it
  50638. // cannot reuse an array for each call to read().
  50639. //
  50640. // These two modes are present because this function is very hot and so
  50641. // avoiding allocations where possible is worthwhile.
  50642. //
  50643. read: function EvaluatorPreprocessor_read(operation) {
  50644. var args = operation.args;
  50645. while (true) {
  50646. var obj = this.parser.getObj();
  50647. if (isCmd(obj)) {
  50648. var cmd = obj.cmd;
  50649. // Check that the command is valid
  50650. var opSpec = this.opMap[cmd];
  50651. if (!opSpec) {
  50652. warn('Unknown command "' + cmd + '"');
  50653. continue;
  50654. }
  50655. var fn = opSpec.id;
  50656. var numArgs = opSpec.numArgs;
  50657. var argsLength = args !== null ? args.length : 0;
  50658. if (!opSpec.variableArgs) {
  50659. // Postscript commands can be nested, e.g. /F2 /GS2 gs 5.711 Tf
  50660. if (argsLength !== numArgs) {
  50661. var nonProcessedArgs = this.nonProcessedArgs;
  50662. while (argsLength > numArgs) {
  50663. nonProcessedArgs.push(args.shift());
  50664. argsLength--;
  50665. }
  50666. while (argsLength < numArgs && nonProcessedArgs.length !== 0) {
  50667. if (!args) {
  50668. args = [];
  50669. }
  50670. args.unshift(nonProcessedArgs.pop());
  50671. argsLength++;
  50672. }
  50673. }
  50674. if (argsLength < numArgs) {
  50675. // If we receive too few args, it's not possible to possible
  50676. // to execute the command, so skip the command
  50677. info('Command ' + fn + ': because expected ' + numArgs + ' args, but received ' + argsLength + ' args; skipping');
  50678. args = null;
  50679. continue;
  50680. }
  50681. } else if (argsLength > numArgs) {
  50682. info('Command ' + fn + ': expected [0,' + numArgs + '] args, but received ' + argsLength + ' args');
  50683. }
  50684. // TODO figure out how to type-check vararg functions
  50685. this.preprocessCommand(fn, args);
  50686. operation.fn = fn;
  50687. operation.args = args;
  50688. return true;
  50689. } else {
  50690. if (isEOF(obj)) {
  50691. return false;
  50692. }
  50693. // no more commands
  50694. // argument
  50695. if (obj !== null) {
  50696. if (!args) {
  50697. args = [];
  50698. }
  50699. args.push(obj);
  50700. assert(args.length <= 33, 'Too many arguments');
  50701. }
  50702. }
  50703. }
  50704. },
  50705. preprocessCommand: function EvaluatorPreprocessor_preprocessCommand(fn, args) {
  50706. switch (fn | 0) {
  50707. case OPS.save:
  50708. this.stateManager.save();
  50709. break;
  50710. case OPS.restore:
  50711. this.stateManager.restore();
  50712. break;
  50713. case OPS.transform:
  50714. this.stateManager.transform(args);
  50715. break;
  50716. }
  50717. }
  50718. };
  50719. return EvaluatorPreprocessor;
  50720. }();
  50721. var QueueOptimizer = function QueueOptimizerClosure() {
  50722. function addState(parentState, pattern, fn) {
  50723. var state = parentState;
  50724. for (var i = 0, ii = pattern.length - 1; i < ii; i++) {
  50725. var item = pattern[i];
  50726. state = state[item] || (state[item] = []);
  50727. }
  50728. state[pattern[pattern.length - 1]] = fn;
  50729. }
  50730. function handlePaintSolidColorImageMask(iFirstSave, count, fnArray, argsArray) {
  50731. // Handles special case of mainly LaTeX documents which use image masks to
  50732. // draw lines with the current fill style.
  50733. // 'count' groups of (save, transform, paintImageMaskXObject, restore)+
  50734. // have been found at iFirstSave.
  50735. var iFirstPIMXO = iFirstSave + 2;
  50736. for (var i = 0; i < count; i++) {
  50737. var arg = argsArray[iFirstPIMXO + 4 * i];
  50738. var imageMask = arg.length === 1 && arg[0];
  50739. if (imageMask && imageMask.width === 1 && imageMask.height === 1 && (!imageMask.data.length || imageMask.data.length === 1 && imageMask.data[0] === 0)) {
  50740. fnArray[iFirstPIMXO + 4 * i] = OPS.paintSolidColorImageMask;
  50741. continue;
  50742. }
  50743. break;
  50744. }
  50745. return count - i;
  50746. }
  50747. var InitialState = [];
  50748. // This replaces (save, transform, paintInlineImageXObject, restore)+
  50749. // sequences with one |paintInlineImageXObjectGroup| operation.
  50750. addState(InitialState, [
  50751. OPS.save,
  50752. OPS.transform,
  50753. OPS.paintInlineImageXObject,
  50754. OPS.restore
  50755. ], function foundInlineImageGroup(context) {
  50756. var MIN_IMAGES_IN_INLINE_IMAGES_BLOCK = 10;
  50757. var MAX_IMAGES_IN_INLINE_IMAGES_BLOCK = 200;
  50758. var MAX_WIDTH = 1000;
  50759. var IMAGE_PADDING = 1;
  50760. var fnArray = context.fnArray, argsArray = context.argsArray;
  50761. var curr = context.iCurr;
  50762. var iFirstSave = curr - 3;
  50763. var iFirstTransform = curr - 2;
  50764. var iFirstPIIXO = curr - 1;
  50765. // Look for the quartets.
  50766. var i = iFirstSave + 4;
  50767. var ii = fnArray.length;
  50768. while (i + 3 < ii) {
  50769. if (fnArray[i] !== OPS.save || fnArray[i + 1] !== OPS.transform || fnArray[i + 2] !== OPS.paintInlineImageXObject || fnArray[i + 3] !== OPS.restore) {
  50770. break;
  50771. }
  50772. // ops don't match
  50773. i += 4;
  50774. }
  50775. // At this point, i is the index of the first op past the last valid
  50776. // quartet.
  50777. var count = Math.min((i - iFirstSave) / 4, MAX_IMAGES_IN_INLINE_IMAGES_BLOCK);
  50778. if (count < MIN_IMAGES_IN_INLINE_IMAGES_BLOCK) {
  50779. return i;
  50780. }
  50781. // assuming that heights of those image is too small (~1 pixel)
  50782. // packing as much as possible by lines
  50783. var maxX = 0;
  50784. var map = [], maxLineHeight = 0;
  50785. var currentX = IMAGE_PADDING, currentY = IMAGE_PADDING;
  50786. var q;
  50787. for (q = 0; q < count; q++) {
  50788. var transform = argsArray[iFirstTransform + (q << 2)];
  50789. var img = argsArray[iFirstPIIXO + (q << 2)][0];
  50790. if (currentX + img.width > MAX_WIDTH) {
  50791. // starting new line
  50792. maxX = Math.max(maxX, currentX);
  50793. currentY += maxLineHeight + 2 * IMAGE_PADDING;
  50794. currentX = 0;
  50795. maxLineHeight = 0;
  50796. }
  50797. map.push({
  50798. transform: transform,
  50799. x: currentX,
  50800. y: currentY,
  50801. w: img.width,
  50802. h: img.height
  50803. });
  50804. currentX += img.width + 2 * IMAGE_PADDING;
  50805. maxLineHeight = Math.max(maxLineHeight, img.height);
  50806. }
  50807. var imgWidth = Math.max(maxX, currentX) + IMAGE_PADDING;
  50808. var imgHeight = currentY + maxLineHeight + IMAGE_PADDING;
  50809. var imgData = new Uint8Array(imgWidth * imgHeight * 4);
  50810. var imgRowSize = imgWidth << 2;
  50811. for (q = 0; q < count; q++) {
  50812. var data = argsArray[iFirstPIIXO + (q << 2)][0].data;
  50813. // Copy image by lines and extends pixels into padding.
  50814. var rowSize = map[q].w << 2;
  50815. var dataOffset = 0;
  50816. var offset = map[q].x + map[q].y * imgWidth << 2;
  50817. imgData.set(data.subarray(0, rowSize), offset - imgRowSize);
  50818. for (var k = 0, kk = map[q].h; k < kk; k++) {
  50819. imgData.set(data.subarray(dataOffset, dataOffset + rowSize), offset);
  50820. dataOffset += rowSize;
  50821. offset += imgRowSize;
  50822. }
  50823. imgData.set(data.subarray(dataOffset - rowSize, dataOffset), offset);
  50824. while (offset >= 0) {
  50825. data[offset - 4] = data[offset];
  50826. data[offset - 3] = data[offset + 1];
  50827. data[offset - 2] = data[offset + 2];
  50828. data[offset - 1] = data[offset + 3];
  50829. data[offset + rowSize] = data[offset + rowSize - 4];
  50830. data[offset + rowSize + 1] = data[offset + rowSize - 3];
  50831. data[offset + rowSize + 2] = data[offset + rowSize - 2];
  50832. data[offset + rowSize + 3] = data[offset + rowSize - 1];
  50833. offset -= imgRowSize;
  50834. }
  50835. }
  50836. // Replace queue items.
  50837. fnArray.splice(iFirstSave, count * 4, OPS.paintInlineImageXObjectGroup);
  50838. argsArray.splice(iFirstSave, count * 4, [
  50839. {
  50840. width: imgWidth,
  50841. height: imgHeight,
  50842. kind: ImageKind.RGBA_32BPP,
  50843. data: imgData
  50844. },
  50845. map
  50846. ]);
  50847. return iFirstSave + 1;
  50848. });
  50849. // This replaces (save, transform, paintImageMaskXObject, restore)+
  50850. // sequences with one |paintImageMaskXObjectGroup| or one
  50851. // |paintImageMaskXObjectRepeat| operation.
  50852. addState(InitialState, [
  50853. OPS.save,
  50854. OPS.transform,
  50855. OPS.paintImageMaskXObject,
  50856. OPS.restore
  50857. ], function foundImageMaskGroup(context) {
  50858. var MIN_IMAGES_IN_MASKS_BLOCK = 10;
  50859. var MAX_IMAGES_IN_MASKS_BLOCK = 100;
  50860. var MAX_SAME_IMAGES_IN_MASKS_BLOCK = 1000;
  50861. var fnArray = context.fnArray, argsArray = context.argsArray;
  50862. var curr = context.iCurr;
  50863. var iFirstSave = curr - 3;
  50864. var iFirstTransform = curr - 2;
  50865. var iFirstPIMXO = curr - 1;
  50866. // Look for the quartets.
  50867. var i = iFirstSave + 4;
  50868. var ii = fnArray.length;
  50869. while (i + 3 < ii) {
  50870. if (fnArray[i] !== OPS.save || fnArray[i + 1] !== OPS.transform || fnArray[i + 2] !== OPS.paintImageMaskXObject || fnArray[i + 3] !== OPS.restore) {
  50871. break;
  50872. }
  50873. // ops don't match
  50874. i += 4;
  50875. }
  50876. // At this point, i is the index of the first op past the last valid
  50877. // quartet.
  50878. var count = (i - iFirstSave) / 4;
  50879. count = handlePaintSolidColorImageMask(iFirstSave, count, fnArray, argsArray);
  50880. if (count < MIN_IMAGES_IN_MASKS_BLOCK) {
  50881. return i;
  50882. }
  50883. var q;
  50884. var isSameImage = false;
  50885. var iTransform, transformArgs;
  50886. var firstPIMXOArg0 = argsArray[iFirstPIMXO][0];
  50887. if (argsArray[iFirstTransform][1] === 0 && argsArray[iFirstTransform][2] === 0) {
  50888. isSameImage = true;
  50889. var firstTransformArg0 = argsArray[iFirstTransform][0];
  50890. var firstTransformArg3 = argsArray[iFirstTransform][3];
  50891. iTransform = iFirstTransform + 4;
  50892. var iPIMXO = iFirstPIMXO + 4;
  50893. for (q = 1; q < count; q++, iTransform += 4, iPIMXO += 4) {
  50894. transformArgs = argsArray[iTransform];
  50895. if (argsArray[iPIMXO][0] !== firstPIMXOArg0 || transformArgs[0] !== firstTransformArg0 || transformArgs[1] !== 0 || transformArgs[2] !== 0 || transformArgs[3] !== firstTransformArg3) {
  50896. if (q < MIN_IMAGES_IN_MASKS_BLOCK) {
  50897. isSameImage = false;
  50898. } else {
  50899. count = q;
  50900. }
  50901. break;
  50902. }
  50903. }
  50904. }
  50905. // different image or transform
  50906. if (isSameImage) {
  50907. count = Math.min(count, MAX_SAME_IMAGES_IN_MASKS_BLOCK);
  50908. var positions = new Float32Array(count * 2);
  50909. iTransform = iFirstTransform;
  50910. for (q = 0; q < count; q++, iTransform += 4) {
  50911. transformArgs = argsArray[iTransform];
  50912. positions[q << 1] = transformArgs[4];
  50913. positions[(q << 1) + 1] = transformArgs[5];
  50914. }
  50915. // Replace queue items.
  50916. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectRepeat);
  50917. argsArray.splice(iFirstSave, count * 4, [
  50918. firstPIMXOArg0,
  50919. firstTransformArg0,
  50920. firstTransformArg3,
  50921. positions
  50922. ]);
  50923. } else {
  50924. count = Math.min(count, MAX_IMAGES_IN_MASKS_BLOCK);
  50925. var images = [];
  50926. for (q = 0; q < count; q++) {
  50927. transformArgs = argsArray[iFirstTransform + (q << 2)];
  50928. var maskParams = argsArray[iFirstPIMXO + (q << 2)][0];
  50929. images.push({
  50930. data: maskParams.data,
  50931. width: maskParams.width,
  50932. height: maskParams.height,
  50933. transform: transformArgs
  50934. });
  50935. }
  50936. // Replace queue items.
  50937. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectGroup);
  50938. argsArray.splice(iFirstSave, count * 4, [images]);
  50939. }
  50940. return iFirstSave + 1;
  50941. });
  50942. // This replaces (save, transform, paintImageXObject, restore)+ sequences
  50943. // with one paintImageXObjectRepeat operation, if the |transform| and
  50944. // |paintImageXObjectRepeat| ops are appropriate.
  50945. addState(InitialState, [
  50946. OPS.save,
  50947. OPS.transform,
  50948. OPS.paintImageXObject,
  50949. OPS.restore
  50950. ], function (context) {
  50951. var MIN_IMAGES_IN_BLOCK = 3;
  50952. var MAX_IMAGES_IN_BLOCK = 1000;
  50953. var fnArray = context.fnArray, argsArray = context.argsArray;
  50954. var curr = context.iCurr;
  50955. var iFirstSave = curr - 3;
  50956. var iFirstTransform = curr - 2;
  50957. var iFirstPIXO = curr - 1;
  50958. var iFirstRestore = curr;
  50959. if (argsArray[iFirstTransform][1] !== 0 || argsArray[iFirstTransform][2] !== 0) {
  50960. return iFirstRestore + 1;
  50961. }
  50962. // transform has the wrong form
  50963. // Look for the quartets.
  50964. var firstPIXOArg0 = argsArray[iFirstPIXO][0];
  50965. var firstTransformArg0 = argsArray[iFirstTransform][0];
  50966. var firstTransformArg3 = argsArray[iFirstTransform][3];
  50967. var i = iFirstSave + 4;
  50968. var ii = fnArray.length;
  50969. while (i + 3 < ii) {
  50970. if (fnArray[i] !== OPS.save || fnArray[i + 1] !== OPS.transform || fnArray[i + 2] !== OPS.paintImageXObject || fnArray[i + 3] !== OPS.restore) {
  50971. break;
  50972. }
  50973. // ops don't match
  50974. if (argsArray[i + 1][0] !== firstTransformArg0 || argsArray[i + 1][1] !== 0 || argsArray[i + 1][2] !== 0 || argsArray[i + 1][3] !== firstTransformArg3) {
  50975. break;
  50976. }
  50977. // transforms don't match
  50978. if (argsArray[i + 2][0] !== firstPIXOArg0) {
  50979. break;
  50980. }
  50981. // images don't match
  50982. i += 4;
  50983. }
  50984. // At this point, i is the index of the first op past the last valid
  50985. // quartet.
  50986. var count = Math.min((i - iFirstSave) / 4, MAX_IMAGES_IN_BLOCK);
  50987. if (count < MIN_IMAGES_IN_BLOCK) {
  50988. return i;
  50989. }
  50990. // Extract the (x,y) positions from all of the matching transforms.
  50991. var positions = new Float32Array(count * 2);
  50992. var iTransform = iFirstTransform;
  50993. for (var q = 0; q < count; q++, iTransform += 4) {
  50994. var transformArgs = argsArray[iTransform];
  50995. positions[q << 1] = transformArgs[4];
  50996. positions[(q << 1) + 1] = transformArgs[5];
  50997. }
  50998. // Replace queue items.
  50999. var args = [
  51000. firstPIXOArg0,
  51001. firstTransformArg0,
  51002. firstTransformArg3,
  51003. positions
  51004. ];
  51005. fnArray.splice(iFirstSave, count * 4, OPS.paintImageXObjectRepeat);
  51006. argsArray.splice(iFirstSave, count * 4, args);
  51007. return iFirstSave + 1;
  51008. });
  51009. // This replaces (beginText, setFont, setTextMatrix, showText, endText)+
  51010. // sequences with (beginText, setFont, (setTextMatrix, showText)+, endText)+
  51011. // sequences, if the font for each one is the same.
  51012. addState(InitialState, [
  51013. OPS.beginText,
  51014. OPS.setFont,
  51015. OPS.setTextMatrix,
  51016. OPS.showText,
  51017. OPS.endText
  51018. ], function (context) {
  51019. var MIN_CHARS_IN_BLOCK = 3;
  51020. var MAX_CHARS_IN_BLOCK = 1000;
  51021. var fnArray = context.fnArray, argsArray = context.argsArray;
  51022. var curr = context.iCurr;
  51023. var iFirstBeginText = curr - 4;
  51024. var iFirstSetFont = curr - 3;
  51025. var iFirstSetTextMatrix = curr - 2;
  51026. var iFirstShowText = curr - 1;
  51027. var iFirstEndText = curr;
  51028. // Look for the quintets.
  51029. var firstSetFontArg0 = argsArray[iFirstSetFont][0];
  51030. var firstSetFontArg1 = argsArray[iFirstSetFont][1];
  51031. var i = iFirstBeginText + 5;
  51032. var ii = fnArray.length;
  51033. while (i + 4 < ii) {
  51034. 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) {
  51035. break;
  51036. }
  51037. // ops don't match
  51038. if (argsArray[i + 1][0] !== firstSetFontArg0 || argsArray[i + 1][1] !== firstSetFontArg1) {
  51039. break;
  51040. }
  51041. // fonts don't match
  51042. i += 5;
  51043. }
  51044. // At this point, i is the index of the first op past the last valid
  51045. // quintet.
  51046. var count = Math.min((i - iFirstBeginText) / 5, MAX_CHARS_IN_BLOCK);
  51047. if (count < MIN_CHARS_IN_BLOCK) {
  51048. return i;
  51049. }
  51050. // If the preceding quintet is (<something>, setFont, setTextMatrix,
  51051. // showText, endText), include that as well. (E.g. <something> might be
  51052. // |dependency|.)
  51053. var iFirst = iFirstBeginText;
  51054. 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) {
  51055. count++;
  51056. iFirst -= 5;
  51057. }
  51058. // Remove (endText, beginText, setFont) trios.
  51059. var iEndText = iFirst + 4;
  51060. for (var q = 1; q < count; q++) {
  51061. fnArray.splice(iEndText, 3);
  51062. argsArray.splice(iEndText, 3);
  51063. iEndText += 2;
  51064. }
  51065. return iEndText + 1;
  51066. });
  51067. function QueueOptimizer() {
  51068. }
  51069. QueueOptimizer.prototype = {
  51070. optimize: function QueueOptimizer_optimize(queue) {
  51071. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  51072. var context = {
  51073. iCurr: 0,
  51074. fnArray: fnArray,
  51075. argsArray: argsArray
  51076. };
  51077. var state;
  51078. var i = 0, ii = fnArray.length;
  51079. while (i < ii) {
  51080. state = (state || InitialState)[fnArray[i]];
  51081. if (typeof state === 'function') {
  51082. // we found some handler
  51083. context.iCurr = i;
  51084. // state() returns the index of the first non-matching op (if we
  51085. // didn't match) or the first op past the modified ops (if we did
  51086. // match and replace).
  51087. i = state(context);
  51088. state = undefined;
  51089. // reset the state machine
  51090. ii = context.fnArray.length;
  51091. } else {
  51092. i++;
  51093. }
  51094. }
  51095. }
  51096. };
  51097. return QueueOptimizer;
  51098. }();
  51099. exports.OperatorList = OperatorList;
  51100. exports.PartialEvaluator = PartialEvaluator;
  51101. }));
  51102. (function (root, factory) {
  51103. factory(root.pdfjsCoreAnnotation = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreColorSpace, root.pdfjsCoreObj, root.pdfjsCoreEvaluator);
  51104. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreColorSpace, coreObj, coreEvaluator) {
  51105. var AnnotationBorderStyleType = sharedUtil.AnnotationBorderStyleType;
  51106. var AnnotationFieldFlag = sharedUtil.AnnotationFieldFlag;
  51107. var AnnotationFlag = sharedUtil.AnnotationFlag;
  51108. var AnnotationType = sharedUtil.AnnotationType;
  51109. var OPS = sharedUtil.OPS;
  51110. var Util = sharedUtil.Util;
  51111. var isString = sharedUtil.isString;
  51112. var isArray = sharedUtil.isArray;
  51113. var isInt = sharedUtil.isInt;
  51114. var stringToBytes = sharedUtil.stringToBytes;
  51115. var stringToPDFString = sharedUtil.stringToPDFString;
  51116. var warn = sharedUtil.warn;
  51117. var Dict = corePrimitives.Dict;
  51118. var isDict = corePrimitives.isDict;
  51119. var isName = corePrimitives.isName;
  51120. var isRef = corePrimitives.isRef;
  51121. var Stream = coreStream.Stream;
  51122. var ColorSpace = coreColorSpace.ColorSpace;
  51123. var Catalog = coreObj.Catalog;
  51124. var ObjectLoader = coreObj.ObjectLoader;
  51125. var FileSpec = coreObj.FileSpec;
  51126. var OperatorList = coreEvaluator.OperatorList;
  51127. /**
  51128. * @class
  51129. * @alias AnnotationFactory
  51130. */
  51131. function AnnotationFactory() {
  51132. }
  51133. AnnotationFactory.prototype = /** @lends AnnotationFactory.prototype */
  51134. {
  51135. /**
  51136. * @param {XRef} xref
  51137. * @param {Object} ref
  51138. * @param {PDFManager} pdfManager
  51139. * @param {string} uniquePrefix
  51140. * @param {Object} idCounters
  51141. * @returns {Annotation}
  51142. */
  51143. create: function AnnotationFactory_create(xref, ref, pdfManager, uniquePrefix, idCounters) {
  51144. var dict = xref.fetchIfRef(ref);
  51145. if (!isDict(dict)) {
  51146. return;
  51147. }
  51148. var id = isRef(ref) ? ref.toString() : 'annot_' + (uniquePrefix || '') + ++idCounters.obj;
  51149. // Determine the annotation's subtype.
  51150. var subtype = dict.get('Subtype');
  51151. subtype = isName(subtype) ? subtype.name : null;
  51152. // Return the right annotation object based on the subtype and field type.
  51153. var parameters = {
  51154. xref: xref,
  51155. dict: dict,
  51156. ref: isRef(ref) ? ref : null,
  51157. subtype: subtype,
  51158. id: id,
  51159. pdfManager: pdfManager
  51160. };
  51161. switch (subtype) {
  51162. case 'Link':
  51163. return new LinkAnnotation(parameters);
  51164. case 'Text':
  51165. return new TextAnnotation(parameters);
  51166. case 'Widget':
  51167. var fieldType = Util.getInheritableProperty(dict, 'FT');
  51168. fieldType = isName(fieldType) ? fieldType.name : null;
  51169. switch (fieldType) {
  51170. case 'Tx':
  51171. return new TextWidgetAnnotation(parameters);
  51172. case 'Ch':
  51173. return new ChoiceWidgetAnnotation(parameters);
  51174. }
  51175. warn('Unimplemented widget field type "' + fieldType + '", ' + 'falling back to base field type.');
  51176. return new WidgetAnnotation(parameters);
  51177. case 'Popup':
  51178. return new PopupAnnotation(parameters);
  51179. case 'Highlight':
  51180. return new HighlightAnnotation(parameters);
  51181. case 'Underline':
  51182. return new UnderlineAnnotation(parameters);
  51183. case 'Squiggly':
  51184. return new SquigglyAnnotation(parameters);
  51185. case 'StrikeOut':
  51186. return new StrikeOutAnnotation(parameters);
  51187. case 'FileAttachment':
  51188. return new FileAttachmentAnnotation(parameters);
  51189. default:
  51190. if (!subtype) {
  51191. warn('Annotation is missing the required /Subtype.');
  51192. } else {
  51193. warn('Unimplemented annotation type "' + subtype + '", ' + 'falling back to base annotation.');
  51194. }
  51195. return new Annotation(parameters);
  51196. }
  51197. }
  51198. };
  51199. var Annotation = function AnnotationClosure() {
  51200. // 12.5.5: Algorithm: Appearance streams
  51201. function getTransformMatrix(rect, bbox, matrix) {
  51202. var bounds = Util.getAxialAlignedBoundingBox(bbox, matrix);
  51203. var minX = bounds[0];
  51204. var minY = bounds[1];
  51205. var maxX = bounds[2];
  51206. var maxY = bounds[3];
  51207. if (minX === maxX || minY === maxY) {
  51208. // From real-life file, bbox was [0, 0, 0, 0]. In this case,
  51209. // just apply the transform for rect
  51210. return [
  51211. 1,
  51212. 0,
  51213. 0,
  51214. 1,
  51215. rect[0],
  51216. rect[1]
  51217. ];
  51218. }
  51219. var xRatio = (rect[2] - rect[0]) / (maxX - minX);
  51220. var yRatio = (rect[3] - rect[1]) / (maxY - minY);
  51221. return [
  51222. xRatio,
  51223. 0,
  51224. 0,
  51225. yRatio,
  51226. rect[0] - minX * xRatio,
  51227. rect[1] - minY * yRatio
  51228. ];
  51229. }
  51230. function getDefaultAppearance(dict) {
  51231. var appearanceState = dict.get('AP');
  51232. if (!isDict(appearanceState)) {
  51233. return;
  51234. }
  51235. var appearance;
  51236. var appearances = appearanceState.get('N');
  51237. if (isDict(appearances)) {
  51238. var as = dict.get('AS');
  51239. if (as && appearances.has(as.name)) {
  51240. appearance = appearances.get(as.name);
  51241. }
  51242. } else {
  51243. appearance = appearances;
  51244. }
  51245. return appearance;
  51246. }
  51247. function Annotation(params) {
  51248. var dict = params.dict;
  51249. this.setFlags(dict.get('F'));
  51250. this.setRectangle(dict.getArray('Rect'));
  51251. this.setColor(dict.getArray('C'));
  51252. this.setBorderStyle(dict);
  51253. this.appearance = getDefaultAppearance(dict);
  51254. // Expose public properties using a data object.
  51255. this.data = {};
  51256. this.data.id = params.id;
  51257. this.data.subtype = params.subtype;
  51258. this.data.annotationFlags = this.flags;
  51259. this.data.rect = this.rectangle;
  51260. this.data.color = this.color;
  51261. this.data.borderStyle = this.borderStyle;
  51262. this.data.hasAppearance = !!this.appearance;
  51263. }
  51264. Annotation.prototype = {
  51265. /**
  51266. * @private
  51267. */
  51268. _hasFlag: function Annotation_hasFlag(flags, flag) {
  51269. return !!(flags & flag);
  51270. },
  51271. /**
  51272. * @private
  51273. */
  51274. _isViewable: function Annotation_isViewable(flags) {
  51275. return !this._hasFlag(flags, AnnotationFlag.INVISIBLE) && !this._hasFlag(flags, AnnotationFlag.HIDDEN) && !this._hasFlag(flags, AnnotationFlag.NOVIEW);
  51276. },
  51277. /**
  51278. * @private
  51279. */
  51280. _isPrintable: function AnnotationFlag_isPrintable(flags) {
  51281. return this._hasFlag(flags, AnnotationFlag.PRINT) && !this._hasFlag(flags, AnnotationFlag.INVISIBLE) && !this._hasFlag(flags, AnnotationFlag.HIDDEN);
  51282. },
  51283. /**
  51284. * @return {boolean}
  51285. */
  51286. get viewable() {
  51287. if (this.flags === 0) {
  51288. return true;
  51289. }
  51290. return this._isViewable(this.flags);
  51291. },
  51292. /**
  51293. * @return {boolean}
  51294. */
  51295. get printable() {
  51296. if (this.flags === 0) {
  51297. return false;
  51298. }
  51299. return this._isPrintable(this.flags);
  51300. },
  51301. /**
  51302. * Set the flags.
  51303. *
  51304. * @public
  51305. * @memberof Annotation
  51306. * @param {number} flags - Unsigned 32-bit integer specifying annotation
  51307. * characteristics
  51308. * @see {@link shared/util.js}
  51309. */
  51310. setFlags: function Annotation_setFlags(flags) {
  51311. this.flags = isInt(flags) && flags > 0 ? flags : 0;
  51312. },
  51313. /**
  51314. * Check if a provided flag is set.
  51315. *
  51316. * @public
  51317. * @memberof Annotation
  51318. * @param {number} flag - Hexadecimal representation for an annotation
  51319. * characteristic
  51320. * @return {boolean}
  51321. * @see {@link shared/util.js}
  51322. */
  51323. hasFlag: function Annotation_hasFlag(flag) {
  51324. return this._hasFlag(this.flags, flag);
  51325. },
  51326. /**
  51327. * Set the rectangle.
  51328. *
  51329. * @public
  51330. * @memberof Annotation
  51331. * @param {Array} rectangle - The rectangle array with exactly four entries
  51332. */
  51333. setRectangle: function Annotation_setRectangle(rectangle) {
  51334. if (isArray(rectangle) && rectangle.length === 4) {
  51335. this.rectangle = Util.normalizeRect(rectangle);
  51336. } else {
  51337. this.rectangle = [
  51338. 0,
  51339. 0,
  51340. 0,
  51341. 0
  51342. ];
  51343. }
  51344. },
  51345. /**
  51346. * Set the color and take care of color space conversion.
  51347. *
  51348. * @public
  51349. * @memberof Annotation
  51350. * @param {Array} color - The color array containing either 0
  51351. * (transparent), 1 (grayscale), 3 (RGB) or
  51352. * 4 (CMYK) elements
  51353. */
  51354. setColor: function Annotation_setColor(color) {
  51355. var rgbColor = new Uint8Array(3);
  51356. // Black in RGB color space (default)
  51357. if (!isArray(color)) {
  51358. this.color = rgbColor;
  51359. return;
  51360. }
  51361. switch (color.length) {
  51362. case 0:
  51363. // Transparent, which we indicate with a null value
  51364. this.color = null;
  51365. break;
  51366. case 1:
  51367. // Convert grayscale to RGB
  51368. ColorSpace.singletons.gray.getRgbItem(color, 0, rgbColor, 0);
  51369. this.color = rgbColor;
  51370. break;
  51371. case 3:
  51372. // Convert RGB percentages to RGB
  51373. ColorSpace.singletons.rgb.getRgbItem(color, 0, rgbColor, 0);
  51374. this.color = rgbColor;
  51375. break;
  51376. case 4:
  51377. // Convert CMYK to RGB
  51378. ColorSpace.singletons.cmyk.getRgbItem(color, 0, rgbColor, 0);
  51379. this.color = rgbColor;
  51380. break;
  51381. default:
  51382. this.color = rgbColor;
  51383. break;
  51384. }
  51385. },
  51386. /**
  51387. * Set the border style (as AnnotationBorderStyle object).
  51388. *
  51389. * @public
  51390. * @memberof Annotation
  51391. * @param {Dict} borderStyle - The border style dictionary
  51392. */
  51393. setBorderStyle: function Annotation_setBorderStyle(borderStyle) {
  51394. this.borderStyle = new AnnotationBorderStyle();
  51395. if (!isDict(borderStyle)) {
  51396. return;
  51397. }
  51398. if (borderStyle.has('BS')) {
  51399. var dict = borderStyle.get('BS');
  51400. var dictType = dict.get('Type');
  51401. if (!dictType || isName(dictType, 'Border')) {
  51402. this.borderStyle.setWidth(dict.get('W'));
  51403. this.borderStyle.setStyle(dict.get('S'));
  51404. this.borderStyle.setDashArray(dict.getArray('D'));
  51405. }
  51406. } else if (borderStyle.has('Border')) {
  51407. var array = borderStyle.getArray('Border');
  51408. if (isArray(array) && array.length >= 3) {
  51409. this.borderStyle.setHorizontalCornerRadius(array[0]);
  51410. this.borderStyle.setVerticalCornerRadius(array[1]);
  51411. this.borderStyle.setWidth(array[2]);
  51412. if (array.length === 4) {
  51413. // Dash array available
  51414. this.borderStyle.setDashArray(array[3]);
  51415. }
  51416. }
  51417. } else {
  51418. // There are no border entries in the dictionary. According to the
  51419. // specification, we should draw a solid border of width 1 in that
  51420. // case, but Adobe Reader did not implement that part of the
  51421. // specification and instead draws no border at all, so we do the same.
  51422. // See also https://github.com/mozilla/pdf.js/issues/6179.
  51423. this.borderStyle.setWidth(0);
  51424. }
  51425. },
  51426. /**
  51427. * Prepare the annotation for working with a popup in the display layer.
  51428. *
  51429. * @private
  51430. * @memberof Annotation
  51431. * @param {Dict} dict - The annotation's data dictionary
  51432. */
  51433. _preparePopup: function Annotation_preparePopup(dict) {
  51434. if (!dict.has('C')) {
  51435. // Fall back to the default background color.
  51436. this.data.color = null;
  51437. }
  51438. this.data.hasPopup = dict.has('Popup');
  51439. this.data.title = stringToPDFString(dict.get('T') || '');
  51440. this.data.contents = stringToPDFString(dict.get('Contents') || '');
  51441. },
  51442. loadResources: function Annotation_loadResources(keys) {
  51443. return new Promise(function (resolve, reject) {
  51444. this.appearance.dict.getAsync('Resources').then(function (resources) {
  51445. if (!resources) {
  51446. resolve();
  51447. return;
  51448. }
  51449. var objectLoader = new ObjectLoader(resources.map, keys, resources.xref);
  51450. objectLoader.load().then(function () {
  51451. resolve(resources);
  51452. }, reject);
  51453. }, reject);
  51454. }.bind(this));
  51455. },
  51456. getOperatorList: function Annotation_getOperatorList(evaluator, task, renderForms) {
  51457. if (!this.appearance) {
  51458. return Promise.resolve(new OperatorList());
  51459. }
  51460. var data = this.data;
  51461. var appearanceDict = this.appearance.dict;
  51462. var resourcesPromise = this.loadResources([
  51463. 'ExtGState',
  51464. 'ColorSpace',
  51465. 'Pattern',
  51466. 'Shading',
  51467. 'XObject',
  51468. 'Font'
  51469. ]);
  51470. // ProcSet
  51471. // Properties
  51472. var bbox = appearanceDict.getArray('BBox') || [
  51473. 0,
  51474. 0,
  51475. 1,
  51476. 1
  51477. ];
  51478. var matrix = appearanceDict.getArray('Matrix') || [
  51479. 1,
  51480. 0,
  51481. 0,
  51482. 1,
  51483. 0,
  51484. 0
  51485. ];
  51486. var transform = getTransformMatrix(data.rect, bbox, matrix);
  51487. var self = this;
  51488. return resourcesPromise.then(function (resources) {
  51489. var opList = new OperatorList();
  51490. opList.addOp(OPS.beginAnnotation, [
  51491. data.rect,
  51492. transform,
  51493. matrix
  51494. ]);
  51495. return evaluator.getOperatorList(self.appearance, task, resources, opList).then(function () {
  51496. opList.addOp(OPS.endAnnotation, []);
  51497. self.appearance.reset();
  51498. return opList;
  51499. });
  51500. });
  51501. }
  51502. };
  51503. Annotation.appendToOperatorList = function Annotation_appendToOperatorList(annotations, opList, partialEvaluator, task, intent, renderForms) {
  51504. var annotationPromises = [];
  51505. for (var i = 0, n = annotations.length; i < n; ++i) {
  51506. if (intent === 'display' && annotations[i].viewable || intent === 'print' && annotations[i].printable) {
  51507. annotationPromises.push(annotations[i].getOperatorList(partialEvaluator, task, renderForms));
  51508. }
  51509. }
  51510. return Promise.all(annotationPromises).then(function (operatorLists) {
  51511. opList.addOp(OPS.beginAnnotations, []);
  51512. for (var i = 0, n = operatorLists.length; i < n; ++i) {
  51513. opList.addOpList(operatorLists[i]);
  51514. }
  51515. opList.addOp(OPS.endAnnotations, []);
  51516. });
  51517. };
  51518. return Annotation;
  51519. }();
  51520. /**
  51521. * Contains all data regarding an annotation's border style.
  51522. *
  51523. * @class
  51524. */
  51525. var AnnotationBorderStyle = function AnnotationBorderStyleClosure() {
  51526. /**
  51527. * @constructor
  51528. * @private
  51529. */
  51530. function AnnotationBorderStyle() {
  51531. this.width = 1;
  51532. this.style = AnnotationBorderStyleType.SOLID;
  51533. this.dashArray = [3];
  51534. this.horizontalCornerRadius = 0;
  51535. this.verticalCornerRadius = 0;
  51536. }
  51537. AnnotationBorderStyle.prototype = {
  51538. /**
  51539. * Set the width.
  51540. *
  51541. * @public
  51542. * @memberof AnnotationBorderStyle
  51543. * @param {integer} width - The width
  51544. */
  51545. setWidth: function AnnotationBorderStyle_setWidth(width) {
  51546. if (width === (width | 0)) {
  51547. this.width = width;
  51548. }
  51549. },
  51550. /**
  51551. * Set the style.
  51552. *
  51553. * @public
  51554. * @memberof AnnotationBorderStyle
  51555. * @param {Object} style - The style object
  51556. * @see {@link shared/util.js}
  51557. */
  51558. setStyle: function AnnotationBorderStyle_setStyle(style) {
  51559. if (!style) {
  51560. return;
  51561. }
  51562. switch (style.name) {
  51563. case 'S':
  51564. this.style = AnnotationBorderStyleType.SOLID;
  51565. break;
  51566. case 'D':
  51567. this.style = AnnotationBorderStyleType.DASHED;
  51568. break;
  51569. case 'B':
  51570. this.style = AnnotationBorderStyleType.BEVELED;
  51571. break;
  51572. case 'I':
  51573. this.style = AnnotationBorderStyleType.INSET;
  51574. break;
  51575. case 'U':
  51576. this.style = AnnotationBorderStyleType.UNDERLINE;
  51577. break;
  51578. default:
  51579. break;
  51580. }
  51581. },
  51582. /**
  51583. * Set the dash array.
  51584. *
  51585. * @public
  51586. * @memberof AnnotationBorderStyle
  51587. * @param {Array} dashArray - The dash array with at least one element
  51588. */
  51589. setDashArray: function AnnotationBorderStyle_setDashArray(dashArray) {
  51590. // We validate the dash array, but we do not use it because CSS does not
  51591. // allow us to change spacing of dashes. For more information, visit
  51592. // http://www.w3.org/TR/css3-background/#the-border-style.
  51593. if (isArray(dashArray) && dashArray.length > 0) {
  51594. // According to the PDF specification: the elements in a dashArray
  51595. // shall be numbers that are nonnegative and not all equal to zero.
  51596. var isValid = true;
  51597. var allZeros = true;
  51598. for (var i = 0, len = dashArray.length; i < len; i++) {
  51599. var element = dashArray[i];
  51600. var validNumber = +element >= 0;
  51601. if (!validNumber) {
  51602. isValid = false;
  51603. break;
  51604. } else if (element > 0) {
  51605. allZeros = false;
  51606. }
  51607. }
  51608. if (isValid && !allZeros) {
  51609. this.dashArray = dashArray;
  51610. } else {
  51611. this.width = 0;
  51612. }
  51613. } else // Adobe behavior when the array is invalid.
  51614. if (dashArray) {
  51615. this.width = 0;
  51616. }
  51617. },
  51618. // Adobe behavior when the array is invalid.
  51619. /**
  51620. * Set the horizontal corner radius (from a Border dictionary).
  51621. *
  51622. * @public
  51623. * @memberof AnnotationBorderStyle
  51624. * @param {integer} radius - The horizontal corner radius
  51625. */
  51626. setHorizontalCornerRadius: function AnnotationBorderStyle_setHorizontalCornerRadius(radius) {
  51627. if (radius === (radius | 0)) {
  51628. this.horizontalCornerRadius = radius;
  51629. }
  51630. },
  51631. /**
  51632. * Set the vertical corner radius (from a Border dictionary).
  51633. *
  51634. * @public
  51635. * @memberof AnnotationBorderStyle
  51636. * @param {integer} radius - The vertical corner radius
  51637. */
  51638. setVerticalCornerRadius: function AnnotationBorderStyle_setVerticalCornerRadius(radius) {
  51639. if (radius === (radius | 0)) {
  51640. this.verticalCornerRadius = radius;
  51641. }
  51642. }
  51643. };
  51644. return AnnotationBorderStyle;
  51645. }();
  51646. var WidgetAnnotation = function WidgetAnnotationClosure() {
  51647. function WidgetAnnotation(params) {
  51648. Annotation.call(this, params);
  51649. var dict = params.dict;
  51650. var data = this.data;
  51651. data.annotationType = AnnotationType.WIDGET;
  51652. data.fieldName = this._constructFieldName(dict);
  51653. data.fieldValue = Util.getInheritableProperty(dict, 'V', /* getArray = */
  51654. true);
  51655. data.alternativeText = stringToPDFString(dict.get('TU') || '');
  51656. data.defaultAppearance = Util.getInheritableProperty(dict, 'DA') || '';
  51657. var fieldType = Util.getInheritableProperty(dict, 'FT');
  51658. data.fieldType = isName(fieldType) ? fieldType.name : null;
  51659. this.fieldResources = Util.getInheritableProperty(dict, 'DR') || Dict.empty;
  51660. data.fieldFlags = Util.getInheritableProperty(dict, 'Ff');
  51661. if (!isInt(data.fieldFlags) || data.fieldFlags < 0) {
  51662. data.fieldFlags = 0;
  51663. }
  51664. data.readOnly = this.hasFieldFlag(AnnotationFieldFlag.READONLY);
  51665. // Hide signatures because we cannot validate them.
  51666. if (data.fieldType === 'Sig') {
  51667. this.setFlags(AnnotationFlag.HIDDEN);
  51668. }
  51669. }
  51670. Util.inherit(WidgetAnnotation, Annotation, {
  51671. /**
  51672. * Construct the (fully qualified) field name from the (partial) field
  51673. * names of the field and its ancestors.
  51674. *
  51675. * @private
  51676. * @memberof WidgetAnnotation
  51677. * @param {Dict} dict - Complete widget annotation dictionary
  51678. * @return {string}
  51679. */
  51680. _constructFieldName: function WidgetAnnotation_constructFieldName(dict) {
  51681. // Both the `Parent` and `T` fields are optional. While at least one of
  51682. // them should be provided, bad PDF generators may fail to do so.
  51683. if (!dict.has('T') && !dict.has('Parent')) {
  51684. warn('Unknown field name, falling back to empty field name.');
  51685. return '';
  51686. }
  51687. // If no parent exists, the partial and fully qualified names are equal.
  51688. if (!dict.has('Parent')) {
  51689. return stringToPDFString(dict.get('T'));
  51690. }
  51691. // Form the fully qualified field name by appending the partial name to
  51692. // the parent's fully qualified name, separated by a period.
  51693. var fieldName = [];
  51694. if (dict.has('T')) {
  51695. fieldName.unshift(stringToPDFString(dict.get('T')));
  51696. }
  51697. var loopDict = dict;
  51698. while (loopDict.has('Parent')) {
  51699. loopDict = loopDict.get('Parent');
  51700. if (loopDict.has('T')) {
  51701. fieldName.unshift(stringToPDFString(loopDict.get('T')));
  51702. }
  51703. }
  51704. return fieldName.join('.');
  51705. },
  51706. /**
  51707. * Check if a provided field flag is set.
  51708. *
  51709. * @public
  51710. * @memberof WidgetAnnotation
  51711. * @param {number} flag - Hexadecimal representation for an annotation
  51712. * field characteristic
  51713. * @return {boolean}
  51714. * @see {@link shared/util.js}
  51715. */
  51716. hasFieldFlag: function WidgetAnnotation_hasFieldFlag(flag) {
  51717. return !!(this.data.fieldFlags & flag);
  51718. }
  51719. });
  51720. return WidgetAnnotation;
  51721. }();
  51722. var TextWidgetAnnotation = function TextWidgetAnnotationClosure() {
  51723. function TextWidgetAnnotation(params) {
  51724. WidgetAnnotation.call(this, params);
  51725. // The field value is always a string.
  51726. this.data.fieldValue = stringToPDFString(this.data.fieldValue || '');
  51727. // Determine the alignment of text in the field.
  51728. var alignment = Util.getInheritableProperty(params.dict, 'Q');
  51729. if (!isInt(alignment) || alignment < 0 || alignment > 2) {
  51730. alignment = null;
  51731. }
  51732. this.data.textAlignment = alignment;
  51733. // Determine the maximum length of text in the field.
  51734. var maximumLength = Util.getInheritableProperty(params.dict, 'MaxLen');
  51735. if (!isInt(maximumLength) || maximumLength < 0) {
  51736. maximumLength = null;
  51737. }
  51738. this.data.maxLen = maximumLength;
  51739. // Process field flags for the display layer.
  51740. this.data.multiLine = this.hasFieldFlag(AnnotationFieldFlag.MULTILINE);
  51741. this.data.comb = this.hasFieldFlag(AnnotationFieldFlag.COMB) && !this.hasFieldFlag(AnnotationFieldFlag.MULTILINE) && !this.hasFieldFlag(AnnotationFieldFlag.PASSWORD) && !this.hasFieldFlag(AnnotationFieldFlag.FILESELECT) && this.data.maxLen !== null;
  51742. }
  51743. Util.inherit(TextWidgetAnnotation, WidgetAnnotation, {
  51744. getOperatorList: function TextWidgetAnnotation_getOperatorList(evaluator, task, renderForms) {
  51745. var operatorList = new OperatorList();
  51746. // Do not render form elements on the canvas when interactive forms are
  51747. // enabled. The display layer is responsible for rendering them instead.
  51748. if (renderForms) {
  51749. return Promise.resolve(operatorList);
  51750. }
  51751. if (this.appearance) {
  51752. return Annotation.prototype.getOperatorList.call(this, evaluator, task, renderForms);
  51753. }
  51754. // Even if there is an appearance stream, ignore it. This is the
  51755. // behaviour used by Adobe Reader.
  51756. if (!this.data.defaultAppearance) {
  51757. return Promise.resolve(operatorList);
  51758. }
  51759. var stream = new Stream(stringToBytes(this.data.defaultAppearance));
  51760. return evaluator.getOperatorList(stream, task, this.fieldResources, operatorList).then(function () {
  51761. return operatorList;
  51762. });
  51763. }
  51764. });
  51765. return TextWidgetAnnotation;
  51766. }();
  51767. var ChoiceWidgetAnnotation = function ChoiceWidgetAnnotationClosure() {
  51768. function ChoiceWidgetAnnotation(params) {
  51769. WidgetAnnotation.call(this, params);
  51770. // Determine the options. The options array may consist of strings or
  51771. // arrays. If the array consists of arrays, then the first element of
  51772. // each array is the export value and the second element of each array is
  51773. // the display value. If the array consists of strings, then these
  51774. // represent both the export and display value. In this case, we convert
  51775. // it to an array of arrays as well for convenience in the display layer.
  51776. this.data.options = [];
  51777. var options = params.dict.getArray('Opt');
  51778. if (isArray(options)) {
  51779. for (var i = 0, ii = options.length; i < ii; i++) {
  51780. var option = options[i];
  51781. this.data.options[i] = {
  51782. exportValue: isArray(option) ? option[0] : option,
  51783. displayValue: isArray(option) ? option[1] : option
  51784. };
  51785. }
  51786. }
  51787. // Determine the field value. In this case, it may be a string or an
  51788. // array of strings. For convenience in the display layer, convert the
  51789. // string to an array of one string as well.
  51790. if (!isArray(this.data.fieldValue)) {
  51791. this.data.fieldValue = [this.data.fieldValue];
  51792. }
  51793. // Process field flags for the display layer.
  51794. this.data.combo = this.hasFieldFlag(AnnotationFieldFlag.COMBO);
  51795. this.data.multiSelect = this.hasFieldFlag(AnnotationFieldFlag.MULTISELECT);
  51796. }
  51797. Util.inherit(ChoiceWidgetAnnotation, WidgetAnnotation, {
  51798. getOperatorList: function ChoiceWidgetAnnotation_getOperatorList(evaluator, task, renderForms) {
  51799. var operatorList = new OperatorList();
  51800. // Do not render form elements on the canvas when interactive forms are
  51801. // enabled. The display layer is responsible for rendering them instead.
  51802. if (renderForms) {
  51803. return Promise.resolve(operatorList);
  51804. }
  51805. return Annotation.prototype.getOperatorList.call(this, evaluator, task, renderForms);
  51806. }
  51807. });
  51808. return ChoiceWidgetAnnotation;
  51809. }();
  51810. var TextAnnotation = function TextAnnotationClosure() {
  51811. var DEFAULT_ICON_SIZE = 22;
  51812. // px
  51813. function TextAnnotation(parameters) {
  51814. Annotation.call(this, parameters);
  51815. this.data.annotationType = AnnotationType.TEXT;
  51816. if (this.data.hasAppearance) {
  51817. this.data.name = 'NoIcon';
  51818. } else {
  51819. this.data.rect[1] = this.data.rect[3] - DEFAULT_ICON_SIZE;
  51820. this.data.rect[2] = this.data.rect[0] + DEFAULT_ICON_SIZE;
  51821. this.data.name = parameters.dict.has('Name') ? parameters.dict.get('Name').name : 'Note';
  51822. }
  51823. this._preparePopup(parameters.dict);
  51824. }
  51825. Util.inherit(TextAnnotation, Annotation, {});
  51826. return TextAnnotation;
  51827. }();
  51828. var LinkAnnotation = function LinkAnnotationClosure() {
  51829. function LinkAnnotation(params) {
  51830. Annotation.call(this, params);
  51831. var data = this.data;
  51832. data.annotationType = AnnotationType.LINK;
  51833. Catalog.parseDestDictionary({
  51834. destDict: params.dict,
  51835. resultObj: data,
  51836. docBaseUrl: params.pdfManager.docBaseUrl
  51837. });
  51838. }
  51839. Util.inherit(LinkAnnotation, Annotation, {});
  51840. return LinkAnnotation;
  51841. }();
  51842. var PopupAnnotation = function PopupAnnotationClosure() {
  51843. function PopupAnnotation(parameters) {
  51844. Annotation.call(this, parameters);
  51845. this.data.annotationType = AnnotationType.POPUP;
  51846. var dict = parameters.dict;
  51847. var parentItem = dict.get('Parent');
  51848. if (!parentItem) {
  51849. warn('Popup annotation has a missing or invalid parent annotation.');
  51850. return;
  51851. }
  51852. this.data.parentId = dict.getRaw('Parent').toString();
  51853. this.data.title = stringToPDFString(parentItem.get('T') || '');
  51854. this.data.contents = stringToPDFString(parentItem.get('Contents') || '');
  51855. if (!parentItem.has('C')) {
  51856. // Fall back to the default background color.
  51857. this.data.color = null;
  51858. } else {
  51859. this.setColor(parentItem.getArray('C'));
  51860. this.data.color = this.color;
  51861. }
  51862. // If the Popup annotation is not viewable, but the parent annotation is,
  51863. // that is most likely a bug. Fallback to inherit the flags from the parent
  51864. // annotation (this is consistent with the behaviour in Adobe Reader).
  51865. if (!this.viewable) {
  51866. var parentFlags = parentItem.get('F');
  51867. if (this._isViewable(parentFlags)) {
  51868. this.setFlags(parentFlags);
  51869. }
  51870. }
  51871. }
  51872. Util.inherit(PopupAnnotation, Annotation, {});
  51873. return PopupAnnotation;
  51874. }();
  51875. var HighlightAnnotation = function HighlightAnnotationClosure() {
  51876. function HighlightAnnotation(parameters) {
  51877. Annotation.call(this, parameters);
  51878. this.data.annotationType = AnnotationType.HIGHLIGHT;
  51879. this._preparePopup(parameters.dict);
  51880. // PDF viewers completely ignore any border styles.
  51881. this.data.borderStyle.setWidth(0);
  51882. }
  51883. Util.inherit(HighlightAnnotation, Annotation, {});
  51884. return HighlightAnnotation;
  51885. }();
  51886. var UnderlineAnnotation = function UnderlineAnnotationClosure() {
  51887. function UnderlineAnnotation(parameters) {
  51888. Annotation.call(this, parameters);
  51889. this.data.annotationType = AnnotationType.UNDERLINE;
  51890. this._preparePopup(parameters.dict);
  51891. // PDF viewers completely ignore any border styles.
  51892. this.data.borderStyle.setWidth(0);
  51893. }
  51894. Util.inherit(UnderlineAnnotation, Annotation, {});
  51895. return UnderlineAnnotation;
  51896. }();
  51897. var SquigglyAnnotation = function SquigglyAnnotationClosure() {
  51898. function SquigglyAnnotation(parameters) {
  51899. Annotation.call(this, parameters);
  51900. this.data.annotationType = AnnotationType.SQUIGGLY;
  51901. this._preparePopup(parameters.dict);
  51902. // PDF viewers completely ignore any border styles.
  51903. this.data.borderStyle.setWidth(0);
  51904. }
  51905. Util.inherit(SquigglyAnnotation, Annotation, {});
  51906. return SquigglyAnnotation;
  51907. }();
  51908. var StrikeOutAnnotation = function StrikeOutAnnotationClosure() {
  51909. function StrikeOutAnnotation(parameters) {
  51910. Annotation.call(this, parameters);
  51911. this.data.annotationType = AnnotationType.STRIKEOUT;
  51912. this._preparePopup(parameters.dict);
  51913. // PDF viewers completely ignore any border styles.
  51914. this.data.borderStyle.setWidth(0);
  51915. }
  51916. Util.inherit(StrikeOutAnnotation, Annotation, {});
  51917. return StrikeOutAnnotation;
  51918. }();
  51919. var FileAttachmentAnnotation = function FileAttachmentAnnotationClosure() {
  51920. function FileAttachmentAnnotation(parameters) {
  51921. Annotation.call(this, parameters);
  51922. var file = new FileSpec(parameters.dict.get('FS'), parameters.xref);
  51923. this.data.annotationType = AnnotationType.FILEATTACHMENT;
  51924. this.data.file = file.serializable;
  51925. this._preparePopup(parameters.dict);
  51926. }
  51927. Util.inherit(FileAttachmentAnnotation, Annotation, {});
  51928. return FileAttachmentAnnotation;
  51929. }();
  51930. exports.Annotation = Annotation;
  51931. exports.AnnotationBorderStyle = AnnotationBorderStyle;
  51932. exports.AnnotationFactory = AnnotationFactory;
  51933. }));
  51934. (function (root, factory) {
  51935. factory(root.pdfjsCoreDocument = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreObj, root.pdfjsCoreParser, root.pdfjsCoreCrypto, root.pdfjsCoreEvaluator, root.pdfjsCoreAnnotation);
  51936. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreObj, coreParser, coreCrypto, coreEvaluator, coreAnnotation) {
  51937. var MissingDataException = sharedUtil.MissingDataException;
  51938. var Util = sharedUtil.Util;
  51939. var assert = sharedUtil.assert;
  51940. var error = sharedUtil.error;
  51941. var info = sharedUtil.info;
  51942. var isArray = sharedUtil.isArray;
  51943. var isArrayBuffer = sharedUtil.isArrayBuffer;
  51944. var isString = sharedUtil.isString;
  51945. var shadow = sharedUtil.shadow;
  51946. var stringToBytes = sharedUtil.stringToBytes;
  51947. var stringToPDFString = sharedUtil.stringToPDFString;
  51948. var warn = sharedUtil.warn;
  51949. var isSpace = sharedUtil.isSpace;
  51950. var Dict = corePrimitives.Dict;
  51951. var isDict = corePrimitives.isDict;
  51952. var isName = corePrimitives.isName;
  51953. var isStream = corePrimitives.isStream;
  51954. var NullStream = coreStream.NullStream;
  51955. var Stream = coreStream.Stream;
  51956. var StreamsSequenceStream = coreStream.StreamsSequenceStream;
  51957. var Catalog = coreObj.Catalog;
  51958. var ObjectLoader = coreObj.ObjectLoader;
  51959. var XRef = coreObj.XRef;
  51960. var Linearization = coreParser.Linearization;
  51961. var calculateMD5 = coreCrypto.calculateMD5;
  51962. var OperatorList = coreEvaluator.OperatorList;
  51963. var PartialEvaluator = coreEvaluator.PartialEvaluator;
  51964. var Annotation = coreAnnotation.Annotation;
  51965. var AnnotationFactory = coreAnnotation.AnnotationFactory;
  51966. var Page = function PageClosure() {
  51967. var LETTER_SIZE_MEDIABOX = [
  51968. 0,
  51969. 0,
  51970. 612,
  51971. 792
  51972. ];
  51973. function Page(pdfManager, xref, pageIndex, pageDict, ref, fontCache) {
  51974. this.pdfManager = pdfManager;
  51975. this.pageIndex = pageIndex;
  51976. this.pageDict = pageDict;
  51977. this.xref = xref;
  51978. this.ref = ref;
  51979. this.fontCache = fontCache;
  51980. this.uniquePrefix = 'p' + this.pageIndex + '_';
  51981. this.idCounters = { obj: 0 };
  51982. this.evaluatorOptions = pdfManager.evaluatorOptions;
  51983. this.resourcesPromise = null;
  51984. }
  51985. Page.prototype = {
  51986. getPageProp: function Page_getPageProp(key) {
  51987. return this.pageDict.get(key);
  51988. },
  51989. getInheritedPageProp: function Page_getInheritedPageProp(key) {
  51990. var dict = this.pageDict, valueArray = null, loopCount = 0;
  51991. var MAX_LOOP_COUNT = 100;
  51992. // Always walk up the entire parent chain, to be able to find
  51993. // e.g. \Resources placed on multiple levels of the tree.
  51994. while (dict) {
  51995. var value = dict.get(key);
  51996. if (value) {
  51997. if (!valueArray) {
  51998. valueArray = [];
  51999. }
  52000. valueArray.push(value);
  52001. }
  52002. if (++loopCount > MAX_LOOP_COUNT) {
  52003. warn('Page_getInheritedPageProp: maximum loop count exceeded.');
  52004. break;
  52005. }
  52006. dict = dict.get('Parent');
  52007. }
  52008. if (!valueArray) {
  52009. return Dict.empty;
  52010. }
  52011. if (valueArray.length === 1 || !isDict(valueArray[0]) || loopCount > MAX_LOOP_COUNT) {
  52012. return valueArray[0];
  52013. }
  52014. return Dict.merge(this.xref, valueArray);
  52015. },
  52016. get content() {
  52017. return this.getPageProp('Contents');
  52018. },
  52019. get resources() {
  52020. // For robustness: The spec states that a \Resources entry has to be
  52021. // present, but can be empty. Some document omit it still, in this case
  52022. // we return an empty dictionary.
  52023. return shadow(this, 'resources', this.getInheritedPageProp('Resources'));
  52024. },
  52025. get mediaBox() {
  52026. var obj = this.getInheritedPageProp('MediaBox');
  52027. // Reset invalid media box to letter size.
  52028. if (!isArray(obj) || obj.length !== 4) {
  52029. obj = LETTER_SIZE_MEDIABOX;
  52030. }
  52031. return shadow(this, 'mediaBox', obj);
  52032. },
  52033. get view() {
  52034. var mediaBox = this.mediaBox;
  52035. var cropBox = this.getInheritedPageProp('CropBox');
  52036. if (!isArray(cropBox) || cropBox.length !== 4) {
  52037. return shadow(this, 'view', mediaBox);
  52038. }
  52039. // From the spec, 6th ed., p.963:
  52040. // "The crop, bleed, trim, and art boxes should not ordinarily
  52041. // extend beyond the boundaries of the media box. If they do, they are
  52042. // effectively reduced to their intersection with the media box."
  52043. cropBox = Util.intersect(cropBox, mediaBox);
  52044. if (!cropBox) {
  52045. return shadow(this, 'view', mediaBox);
  52046. }
  52047. return shadow(this, 'view', cropBox);
  52048. },
  52049. get rotate() {
  52050. var rotate = this.getInheritedPageProp('Rotate') || 0;
  52051. // Normalize rotation so it's a multiple of 90 and between 0 and 270
  52052. if (rotate % 90 !== 0) {
  52053. rotate = 0;
  52054. } else if (rotate >= 360) {
  52055. rotate = rotate % 360;
  52056. } else if (rotate < 0) {
  52057. // The spec doesn't cover negatives, assume its counterclockwise
  52058. // rotation. The following is the other implementation of modulo.
  52059. rotate = (rotate % 360 + 360) % 360;
  52060. }
  52061. return shadow(this, 'rotate', rotate);
  52062. },
  52063. getContentStream: function Page_getContentStream() {
  52064. var content = this.content;
  52065. var stream;
  52066. if (isArray(content)) {
  52067. // fetching items
  52068. var xref = this.xref;
  52069. var i, n = content.length;
  52070. var streams = [];
  52071. for (i = 0; i < n; ++i) {
  52072. streams.push(xref.fetchIfRef(content[i]));
  52073. }
  52074. stream = new StreamsSequenceStream(streams);
  52075. } else if (isStream(content)) {
  52076. stream = content;
  52077. } else {
  52078. // replacing non-existent page content with empty one
  52079. stream = new NullStream();
  52080. }
  52081. return stream;
  52082. },
  52083. loadResources: function Page_loadResources(keys) {
  52084. if (!this.resourcesPromise) {
  52085. // TODO: add async getInheritedPageProp and remove this.
  52086. this.resourcesPromise = this.pdfManager.ensure(this, 'resources');
  52087. }
  52088. return this.resourcesPromise.then(function resourceSuccess() {
  52089. var objectLoader = new ObjectLoader(this.resources.map, keys, this.xref);
  52090. return objectLoader.load();
  52091. }.bind(this));
  52092. },
  52093. getOperatorList: function Page_getOperatorList(handler, task, intent, renderInteractiveForms) {
  52094. var self = this;
  52095. var pdfManager = this.pdfManager;
  52096. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream', []);
  52097. var resourcesPromise = this.loadResources([
  52098. 'ExtGState',
  52099. 'ColorSpace',
  52100. 'Pattern',
  52101. 'Shading',
  52102. 'XObject',
  52103. 'Font'
  52104. ]);
  52105. // ProcSet
  52106. // Properties
  52107. var partialEvaluator = new PartialEvaluator(pdfManager, this.xref, handler, this.pageIndex, this.uniquePrefix, this.idCounters, this.fontCache, this.evaluatorOptions);
  52108. var dataPromises = Promise.all([
  52109. contentStreamPromise,
  52110. resourcesPromise
  52111. ]);
  52112. var pageListPromise = dataPromises.then(function (data) {
  52113. var contentStream = data[0];
  52114. var opList = new OperatorList(intent, handler, self.pageIndex);
  52115. handler.send('StartRenderPage', {
  52116. transparency: partialEvaluator.hasBlendModes(self.resources),
  52117. pageIndex: self.pageIndex,
  52118. intent: intent
  52119. });
  52120. return partialEvaluator.getOperatorList(contentStream, task, self.resources, opList).then(function () {
  52121. return opList;
  52122. });
  52123. });
  52124. var annotationsPromise = pdfManager.ensure(this, 'annotations');
  52125. return Promise.all([
  52126. pageListPromise,
  52127. annotationsPromise
  52128. ]).then(function (datas) {
  52129. var pageOpList = datas[0];
  52130. var annotations = datas[1];
  52131. if (annotations.length === 0) {
  52132. pageOpList.flush(true);
  52133. return pageOpList;
  52134. }
  52135. var annotationsReadyPromise = Annotation.appendToOperatorList(annotations, pageOpList, partialEvaluator, task, intent, renderInteractiveForms);
  52136. return annotationsReadyPromise.then(function () {
  52137. pageOpList.flush(true);
  52138. return pageOpList;
  52139. });
  52140. });
  52141. },
  52142. extractTextContent: function Page_extractTextContent(task, normalizeWhitespace, combineTextItems) {
  52143. var handler = {
  52144. on: function nullHandlerOn() {
  52145. },
  52146. send: function nullHandlerSend() {
  52147. }
  52148. };
  52149. var self = this;
  52150. var pdfManager = this.pdfManager;
  52151. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream', []);
  52152. var resourcesPromise = this.loadResources([
  52153. 'ExtGState',
  52154. 'XObject',
  52155. 'Font'
  52156. ]);
  52157. var dataPromises = Promise.all([
  52158. contentStreamPromise,
  52159. resourcesPromise
  52160. ]);
  52161. return dataPromises.then(function (data) {
  52162. var contentStream = data[0];
  52163. var partialEvaluator = new PartialEvaluator(pdfManager, self.xref, handler, self.pageIndex, self.uniquePrefix, self.idCounters, self.fontCache, self.evaluatorOptions);
  52164. return partialEvaluator.getTextContent(contentStream, task, self.resources, /* stateManager = */
  52165. null, normalizeWhitespace, combineTextItems);
  52166. });
  52167. },
  52168. getAnnotationsData: function Page_getAnnotationsData(intent) {
  52169. var annotations = this.annotations;
  52170. var annotationsData = [];
  52171. for (var i = 0, n = annotations.length; i < n; ++i) {
  52172. if (intent) {
  52173. if (!(intent === 'display' && annotations[i].viewable) && !(intent === 'print' && annotations[i].printable)) {
  52174. continue;
  52175. }
  52176. }
  52177. annotationsData.push(annotations[i].data);
  52178. }
  52179. return annotationsData;
  52180. },
  52181. get annotations() {
  52182. var annotations = [];
  52183. var annotationRefs = this.getInheritedPageProp('Annots') || [];
  52184. var annotationFactory = new AnnotationFactory();
  52185. for (var i = 0, n = annotationRefs.length; i < n; ++i) {
  52186. var annotationRef = annotationRefs[i];
  52187. var annotation = annotationFactory.create(this.xref, annotationRef, this.pdfManager, this.uniquePrefix, this.idCounters);
  52188. if (annotation) {
  52189. annotations.push(annotation);
  52190. }
  52191. }
  52192. return shadow(this, 'annotations', annotations);
  52193. }
  52194. };
  52195. return Page;
  52196. }();
  52197. /**
  52198. * The `PDFDocument` holds all the data of the PDF file. Compared to the
  52199. * `PDFDoc`, this one doesn't have any job management code.
  52200. * Right now there exists one PDFDocument on the main thread + one object
  52201. * for each worker. If there is no worker support enabled, there are two
  52202. * `PDFDocument` objects on the main thread created.
  52203. */
  52204. var PDFDocument = function PDFDocumentClosure() {
  52205. var FINGERPRINT_FIRST_BYTES = 1024;
  52206. var EMPTY_FINGERPRINT = '\x00\x00\x00\x00\x00\x00\x00' + '\x00\x00\x00\x00\x00\x00\x00\x00\x00';
  52207. function PDFDocument(pdfManager, arg, password) {
  52208. if (isStream(arg)) {
  52209. init.call(this, pdfManager, arg, password);
  52210. } else if (isArrayBuffer(arg)) {
  52211. init.call(this, pdfManager, new Stream(arg), password);
  52212. } else {
  52213. error('PDFDocument: Unknown argument type');
  52214. }
  52215. }
  52216. function init(pdfManager, stream, password) {
  52217. assert(stream.length > 0, 'stream must have data');
  52218. this.pdfManager = pdfManager;
  52219. this.stream = stream;
  52220. var xref = new XRef(this.stream, password, pdfManager);
  52221. this.xref = xref;
  52222. }
  52223. function find(stream, needle, limit, backwards) {
  52224. var pos = stream.pos;
  52225. var end = stream.end;
  52226. var strBuf = [];
  52227. if (pos + limit > end) {
  52228. limit = end - pos;
  52229. }
  52230. for (var n = 0; n < limit; ++n) {
  52231. strBuf.push(String.fromCharCode(stream.getByte()));
  52232. }
  52233. var str = strBuf.join('');
  52234. stream.pos = pos;
  52235. var index = backwards ? str.lastIndexOf(needle) : str.indexOf(needle);
  52236. if (index === -1) {
  52237. return false;
  52238. }
  52239. /* not found */
  52240. stream.pos += index;
  52241. return true;
  52242. }
  52243. /* found */
  52244. var DocumentInfoValidators = {
  52245. get entries() {
  52246. // Lazily build this since all the validation functions below are not
  52247. // defined until after this file loads.
  52248. return shadow(this, 'entries', {
  52249. Title: isString,
  52250. Author: isString,
  52251. Subject: isString,
  52252. Keywords: isString,
  52253. Creator: isString,
  52254. Producer: isString,
  52255. CreationDate: isString,
  52256. ModDate: isString,
  52257. Trapped: isName
  52258. });
  52259. }
  52260. };
  52261. PDFDocument.prototype = {
  52262. parse: function PDFDocument_parse(recoveryMode) {
  52263. this.setup(recoveryMode);
  52264. var version = this.catalog.catDict.get('Version');
  52265. if (isName(version)) {
  52266. this.pdfFormatVersion = version.name;
  52267. }
  52268. try {
  52269. // checking if AcroForm is present
  52270. this.acroForm = this.catalog.catDict.get('AcroForm');
  52271. if (this.acroForm) {
  52272. this.xfa = this.acroForm.get('XFA');
  52273. var fields = this.acroForm.get('Fields');
  52274. if ((!fields || !isArray(fields) || fields.length === 0) && !this.xfa) {
  52275. // no fields and no XFA -- not a form (?)
  52276. this.acroForm = null;
  52277. }
  52278. }
  52279. } catch (ex) {
  52280. info('Something wrong with AcroForm entry');
  52281. this.acroForm = null;
  52282. }
  52283. },
  52284. get linearization() {
  52285. var linearization = null;
  52286. if (this.stream.length) {
  52287. try {
  52288. linearization = Linearization.create(this.stream);
  52289. } catch (err) {
  52290. if (err instanceof MissingDataException) {
  52291. throw err;
  52292. }
  52293. info(err);
  52294. }
  52295. }
  52296. // shadow the prototype getter with a data property
  52297. return shadow(this, 'linearization', linearization);
  52298. },
  52299. get startXRef() {
  52300. var stream = this.stream;
  52301. var startXRef = 0;
  52302. var linearization = this.linearization;
  52303. if (linearization) {
  52304. // Find end of first obj.
  52305. stream.reset();
  52306. if (find(stream, 'endobj', 1024)) {
  52307. startXRef = stream.pos + 6;
  52308. }
  52309. } else {
  52310. // Find startxref by jumping backward from the end of the file.
  52311. var step = 1024;
  52312. var found = false, pos = stream.end;
  52313. while (!found && pos > 0) {
  52314. pos -= step - 'startxref'.length;
  52315. if (pos < 0) {
  52316. pos = 0;
  52317. }
  52318. stream.pos = pos;
  52319. found = find(stream, 'startxref', step, true);
  52320. }
  52321. if (found) {
  52322. stream.skip(9);
  52323. var ch;
  52324. do {
  52325. ch = stream.getByte();
  52326. } while (isSpace(ch));
  52327. var str = '';
  52328. while (ch >= 0x20 && ch <= 0x39) {
  52329. // < '9'
  52330. str += String.fromCharCode(ch);
  52331. ch = stream.getByte();
  52332. }
  52333. startXRef = parseInt(str, 10);
  52334. if (isNaN(startXRef)) {
  52335. startXRef = 0;
  52336. }
  52337. }
  52338. }
  52339. // shadow the prototype getter with a data property
  52340. return shadow(this, 'startXRef', startXRef);
  52341. },
  52342. get mainXRefEntriesOffset() {
  52343. var mainXRefEntriesOffset = 0;
  52344. var linearization = this.linearization;
  52345. if (linearization) {
  52346. mainXRefEntriesOffset = linearization.mainXRefEntriesOffset;
  52347. }
  52348. // shadow the prototype getter with a data property
  52349. return shadow(this, 'mainXRefEntriesOffset', mainXRefEntriesOffset);
  52350. },
  52351. // Find the header, remove leading garbage and setup the stream
  52352. // starting from the header.
  52353. checkHeader: function PDFDocument_checkHeader() {
  52354. var stream = this.stream;
  52355. stream.reset();
  52356. if (find(stream, '%PDF-', 1024)) {
  52357. // Found the header, trim off any garbage before it.
  52358. stream.moveStart();
  52359. // Reading file format version
  52360. var MAX_VERSION_LENGTH = 12;
  52361. var version = '', ch;
  52362. while ((ch = stream.getByte()) > 0x20) {
  52363. // SPACE
  52364. if (version.length >= MAX_VERSION_LENGTH) {
  52365. break;
  52366. }
  52367. version += String.fromCharCode(ch);
  52368. }
  52369. if (!this.pdfFormatVersion) {
  52370. // removing "%PDF-"-prefix
  52371. this.pdfFormatVersion = version.substring(5);
  52372. }
  52373. return;
  52374. }
  52375. },
  52376. // May not be a PDF file, continue anyway.
  52377. parseStartXRef: function PDFDocument_parseStartXRef() {
  52378. var startXRef = this.startXRef;
  52379. this.xref.setStartXRef(startXRef);
  52380. },
  52381. setup: function PDFDocument_setup(recoveryMode) {
  52382. this.xref.parse(recoveryMode);
  52383. var self = this;
  52384. var pageFactory = {
  52385. createPage: function (pageIndex, dict, ref, fontCache) {
  52386. return new Page(self.pdfManager, self.xref, pageIndex, dict, ref, fontCache);
  52387. }
  52388. };
  52389. this.catalog = new Catalog(this.pdfManager, this.xref, pageFactory);
  52390. },
  52391. get numPages() {
  52392. var linearization = this.linearization;
  52393. var num = linearization ? linearization.numPages : this.catalog.numPages;
  52394. // shadow the prototype getter
  52395. return shadow(this, 'numPages', num);
  52396. },
  52397. get documentInfo() {
  52398. var docInfo = {
  52399. PDFFormatVersion: this.pdfFormatVersion,
  52400. IsAcroFormPresent: !!this.acroForm,
  52401. IsXFAPresent: !!this.xfa
  52402. };
  52403. var infoDict;
  52404. try {
  52405. infoDict = this.xref.trailer.get('Info');
  52406. } catch (err) {
  52407. info('The document information dictionary is invalid.');
  52408. }
  52409. if (infoDict) {
  52410. var validEntries = DocumentInfoValidators.entries;
  52411. // Only fill the document info with valid entries from the spec.
  52412. for (var key in validEntries) {
  52413. if (infoDict.has(key)) {
  52414. var value = infoDict.get(key);
  52415. // Make sure the value conforms to the spec.
  52416. if (validEntries[key](value)) {
  52417. docInfo[key] = typeof value !== 'string' ? value : stringToPDFString(value);
  52418. } else {
  52419. info('Bad value in document info for "' + key + '"');
  52420. }
  52421. }
  52422. }
  52423. }
  52424. return shadow(this, 'documentInfo', docInfo);
  52425. },
  52426. get fingerprint() {
  52427. var xref = this.xref, hash, fileID = '';
  52428. var idArray = xref.trailer.get('ID');
  52429. if (idArray && isArray(idArray) && idArray[0] && isString(idArray[0]) && idArray[0] !== EMPTY_FINGERPRINT) {
  52430. hash = stringToBytes(idArray[0]);
  52431. } else {
  52432. if (this.stream.ensureRange) {
  52433. this.stream.ensureRange(0, Math.min(FINGERPRINT_FIRST_BYTES, this.stream.end));
  52434. }
  52435. hash = calculateMD5(this.stream.bytes.subarray(0, FINGERPRINT_FIRST_BYTES), 0, FINGERPRINT_FIRST_BYTES);
  52436. }
  52437. for (var i = 0, n = hash.length; i < n; i++) {
  52438. var hex = hash[i].toString(16);
  52439. fileID += hex.length === 1 ? '0' + hex : hex;
  52440. }
  52441. return shadow(this, 'fingerprint', fileID);
  52442. },
  52443. getPage: function PDFDocument_getPage(pageIndex) {
  52444. return this.catalog.getPage(pageIndex);
  52445. },
  52446. cleanup: function PDFDocument_cleanup() {
  52447. return this.catalog.cleanup();
  52448. }
  52449. };
  52450. return PDFDocument;
  52451. }();
  52452. exports.Page = Page;
  52453. exports.PDFDocument = PDFDocument;
  52454. }));
  52455. (function (root, factory) {
  52456. factory(root.pdfjsCorePdfManager = {}, root.pdfjsSharedUtil, root.pdfjsCoreStream, root.pdfjsCoreChunkedStream, root.pdfjsCoreDocument);
  52457. }(this, function (exports, sharedUtil, coreStream, coreChunkedStream, coreDocument) {
  52458. var warn = sharedUtil.warn;
  52459. var createValidAbsoluteUrl = sharedUtil.createValidAbsoluteUrl;
  52460. var shadow = sharedUtil.shadow;
  52461. var NotImplementedException = sharedUtil.NotImplementedException;
  52462. var MissingDataException = sharedUtil.MissingDataException;
  52463. var createPromiseCapability = sharedUtil.createPromiseCapability;
  52464. var Util = sharedUtil.Util;
  52465. var Stream = coreStream.Stream;
  52466. var ChunkedStreamManager = coreChunkedStream.ChunkedStreamManager;
  52467. var PDFDocument = coreDocument.PDFDocument;
  52468. var BasePdfManager = function BasePdfManagerClosure() {
  52469. function BasePdfManager() {
  52470. throw new Error('Cannot initialize BaseManagerManager');
  52471. }
  52472. BasePdfManager.prototype = {
  52473. get docId() {
  52474. return this._docId;
  52475. },
  52476. get docBaseUrl() {
  52477. var docBaseUrl = null;
  52478. if (this._docBaseUrl) {
  52479. var absoluteUrl = createValidAbsoluteUrl(this._docBaseUrl);
  52480. if (absoluteUrl) {
  52481. docBaseUrl = absoluteUrl.href;
  52482. } else {
  52483. warn('Invalid absolute docBaseUrl: "' + this._docBaseUrl + '".');
  52484. }
  52485. }
  52486. return shadow(this, 'docBaseUrl', docBaseUrl);
  52487. },
  52488. onLoadedStream: function BasePdfManager_onLoadedStream() {
  52489. throw new NotImplementedException();
  52490. },
  52491. ensureDoc: function BasePdfManager_ensureDoc(prop, args) {
  52492. return this.ensure(this.pdfDocument, prop, args);
  52493. },
  52494. ensureXRef: function BasePdfManager_ensureXRef(prop, args) {
  52495. return this.ensure(this.pdfDocument.xref, prop, args);
  52496. },
  52497. ensureCatalog: function BasePdfManager_ensureCatalog(prop, args) {
  52498. return this.ensure(this.pdfDocument.catalog, prop, args);
  52499. },
  52500. getPage: function BasePdfManager_getPage(pageIndex) {
  52501. return this.pdfDocument.getPage(pageIndex);
  52502. },
  52503. cleanup: function BasePdfManager_cleanup() {
  52504. return this.pdfDocument.cleanup();
  52505. },
  52506. ensure: function BasePdfManager_ensure(obj, prop, args) {
  52507. return new NotImplementedException();
  52508. },
  52509. requestRange: function BasePdfManager_requestRange(begin, end) {
  52510. return new NotImplementedException();
  52511. },
  52512. requestLoadedStream: function BasePdfManager_requestLoadedStream() {
  52513. return new NotImplementedException();
  52514. },
  52515. sendProgressiveData: function BasePdfManager_sendProgressiveData(chunk) {
  52516. return new NotImplementedException();
  52517. },
  52518. updatePassword: function BasePdfManager_updatePassword(password) {
  52519. this.pdfDocument.xref.password = this.password = password;
  52520. if (this._passwordChangedCapability) {
  52521. this._passwordChangedCapability.resolve();
  52522. }
  52523. },
  52524. passwordChanged: function BasePdfManager_passwordChanged() {
  52525. this._passwordChangedCapability = createPromiseCapability();
  52526. return this._passwordChangedCapability.promise;
  52527. },
  52528. terminate: function BasePdfManager_terminate() {
  52529. return new NotImplementedException();
  52530. }
  52531. };
  52532. return BasePdfManager;
  52533. }();
  52534. var LocalPdfManager = function LocalPdfManagerClosure() {
  52535. function LocalPdfManager(docId, data, password, evaluatorOptions, docBaseUrl) {
  52536. this._docId = docId;
  52537. this._docBaseUrl = docBaseUrl;
  52538. this.evaluatorOptions = evaluatorOptions;
  52539. var stream = new Stream(data);
  52540. this.pdfDocument = new PDFDocument(this, stream, password);
  52541. this._loadedStreamCapability = createPromiseCapability();
  52542. this._loadedStreamCapability.resolve(stream);
  52543. }
  52544. Util.inherit(LocalPdfManager, BasePdfManager, {
  52545. ensure: function LocalPdfManager_ensure(obj, prop, args) {
  52546. return new Promise(function (resolve, reject) {
  52547. try {
  52548. var value = obj[prop];
  52549. var result;
  52550. if (typeof value === 'function') {
  52551. result = value.apply(obj, args);
  52552. } else {
  52553. result = value;
  52554. }
  52555. resolve(result);
  52556. } catch (e) {
  52557. reject(e);
  52558. }
  52559. });
  52560. },
  52561. requestRange: function LocalPdfManager_requestRange(begin, end) {
  52562. return Promise.resolve();
  52563. },
  52564. requestLoadedStream: function LocalPdfManager_requestLoadedStream() {
  52565. return;
  52566. },
  52567. onLoadedStream: function LocalPdfManager_onLoadedStream() {
  52568. return this._loadedStreamCapability.promise;
  52569. },
  52570. terminate: function LocalPdfManager_terminate() {
  52571. return;
  52572. }
  52573. });
  52574. return LocalPdfManager;
  52575. }();
  52576. var NetworkPdfManager = function NetworkPdfManagerClosure() {
  52577. function NetworkPdfManager(docId, pdfNetworkStream, args, evaluatorOptions, docBaseUrl) {
  52578. this._docId = docId;
  52579. this._docBaseUrl = docBaseUrl;
  52580. this.msgHandler = args.msgHandler;
  52581. this.evaluatorOptions = evaluatorOptions;
  52582. var params = {
  52583. msgHandler: args.msgHandler,
  52584. url: args.url,
  52585. length: args.length,
  52586. disableAutoFetch: args.disableAutoFetch,
  52587. rangeChunkSize: args.rangeChunkSize
  52588. };
  52589. this.streamManager = new ChunkedStreamManager(pdfNetworkStream, params);
  52590. this.pdfDocument = new PDFDocument(this, this.streamManager.getStream(), args.password);
  52591. }
  52592. Util.inherit(NetworkPdfManager, BasePdfManager, {
  52593. ensure: function NetworkPdfManager_ensure(obj, prop, args) {
  52594. var pdfManager = this;
  52595. return new Promise(function (resolve, reject) {
  52596. function ensureHelper() {
  52597. try {
  52598. var result;
  52599. var value = obj[prop];
  52600. if (typeof value === 'function') {
  52601. result = value.apply(obj, args);
  52602. } else {
  52603. result = value;
  52604. }
  52605. resolve(result);
  52606. } catch (e) {
  52607. if (!(e instanceof MissingDataException)) {
  52608. reject(e);
  52609. return;
  52610. }
  52611. pdfManager.streamManager.requestRange(e.begin, e.end).then(ensureHelper, reject);
  52612. }
  52613. }
  52614. ensureHelper();
  52615. });
  52616. },
  52617. requestRange: function NetworkPdfManager_requestRange(begin, end) {
  52618. return this.streamManager.requestRange(begin, end);
  52619. },
  52620. requestLoadedStream: function NetworkPdfManager_requestLoadedStream() {
  52621. this.streamManager.requestAllChunks();
  52622. },
  52623. sendProgressiveData: function NetworkPdfManager_sendProgressiveData(chunk) {
  52624. this.streamManager.onReceiveData({ chunk: chunk });
  52625. },
  52626. onLoadedStream: function NetworkPdfManager_onLoadedStream() {
  52627. return this.streamManager.onLoadedStream();
  52628. },
  52629. terminate: function NetworkPdfManager_terminate() {
  52630. this.streamManager.abort();
  52631. }
  52632. });
  52633. return NetworkPdfManager;
  52634. }();
  52635. exports.LocalPdfManager = LocalPdfManager;
  52636. exports.NetworkPdfManager = NetworkPdfManager;
  52637. }));
  52638. (function (root, factory) {
  52639. factory(root.pdfjsCoreWorker = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCorePdfManager);
  52640. }(this, function (exports, sharedUtil, corePrimitives, corePdfManager) {
  52641. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  52642. var InvalidPDFException = sharedUtil.InvalidPDFException;
  52643. var MessageHandler = sharedUtil.MessageHandler;
  52644. var MissingPDFException = sharedUtil.MissingPDFException;
  52645. var UnexpectedResponseException = sharedUtil.UnexpectedResponseException;
  52646. var PasswordException = sharedUtil.PasswordException;
  52647. var PasswordResponses = sharedUtil.PasswordResponses;
  52648. var UnknownErrorException = sharedUtil.UnknownErrorException;
  52649. var XRefParseException = sharedUtil.XRefParseException;
  52650. var arrayByteLength = sharedUtil.arrayByteLength;
  52651. var arraysToBytes = sharedUtil.arraysToBytes;
  52652. var assert = sharedUtil.assert;
  52653. var createPromiseCapability = sharedUtil.createPromiseCapability;
  52654. var error = sharedUtil.error;
  52655. var info = sharedUtil.info;
  52656. var warn = sharedUtil.warn;
  52657. var setVerbosityLevel = sharedUtil.setVerbosityLevel;
  52658. var Ref = corePrimitives.Ref;
  52659. var LocalPdfManager = corePdfManager.LocalPdfManager;
  52660. var NetworkPdfManager = corePdfManager.NetworkPdfManager;
  52661. var globalScope = sharedUtil.globalScope;
  52662. var WorkerTask = function WorkerTaskClosure() {
  52663. function WorkerTask(name) {
  52664. this.name = name;
  52665. this.terminated = false;
  52666. this._capability = createPromiseCapability();
  52667. }
  52668. WorkerTask.prototype = {
  52669. get finished() {
  52670. return this._capability.promise;
  52671. },
  52672. finish: function () {
  52673. this._capability.resolve();
  52674. },
  52675. terminate: function () {
  52676. this.terminated = true;
  52677. },
  52678. ensureNotTerminated: function () {
  52679. if (this.terminated) {
  52680. throw new Error('Worker task was terminated');
  52681. }
  52682. }
  52683. };
  52684. return WorkerTask;
  52685. }();
  52686. /** @implements {IPDFStream} */
  52687. var PDFWorkerStream = function PDFWorkerStreamClosure() {
  52688. function PDFWorkerStream(params, msgHandler) {
  52689. this._queuedChunks = [];
  52690. var initialData = params.initialData;
  52691. if (initialData && initialData.length > 0) {
  52692. this._queuedChunks.push(initialData);
  52693. }
  52694. this._msgHandler = msgHandler;
  52695. this._isRangeSupported = !params.disableRange;
  52696. this._isStreamingSupported = !params.disableStream;
  52697. this._contentLength = params.length;
  52698. this._fullRequestReader = null;
  52699. this._rangeReaders = [];
  52700. msgHandler.on('OnDataRange', this._onReceiveData.bind(this));
  52701. msgHandler.on('OnDataProgress', this._onProgress.bind(this));
  52702. }
  52703. PDFWorkerStream.prototype = {
  52704. _onReceiveData: function PDFWorkerStream_onReceiveData(args) {
  52705. if (args.begin === undefined) {
  52706. if (this._fullRequestReader) {
  52707. this._fullRequestReader._enqueue(args.chunk);
  52708. } else {
  52709. this._queuedChunks.push(args.chunk);
  52710. }
  52711. } else {
  52712. var found = this._rangeReaders.some(function (rangeReader) {
  52713. if (rangeReader._begin !== args.begin) {
  52714. return false;
  52715. }
  52716. rangeReader._enqueue(args.chunk);
  52717. return true;
  52718. });
  52719. assert(found);
  52720. }
  52721. },
  52722. _onProgress: function PDFWorkerStream_onProgress(evt) {
  52723. if (this._rangeReaders.length > 0) {
  52724. // Reporting to first range reader.
  52725. var firstReader = this._rangeReaders[0];
  52726. if (firstReader.onProgress) {
  52727. firstReader.onProgress({ loaded: evt.loaded });
  52728. }
  52729. }
  52730. },
  52731. _removeRangeReader: function PDFWorkerStream_removeRangeReader(reader) {
  52732. var i = this._rangeReaders.indexOf(reader);
  52733. if (i >= 0) {
  52734. this._rangeReaders.splice(i, 1);
  52735. }
  52736. },
  52737. getFullReader: function PDFWorkerStream_getFullReader() {
  52738. assert(!this._fullRequestReader);
  52739. var queuedChunks = this._queuedChunks;
  52740. this._queuedChunks = null;
  52741. return new PDFWorkerStreamReader(this, queuedChunks);
  52742. },
  52743. getRangeReader: function PDFWorkerStream_getRangeReader(begin, end) {
  52744. var reader = new PDFWorkerStreamRangeReader(this, begin, end);
  52745. this._msgHandler.send('RequestDataRange', {
  52746. begin: begin,
  52747. end: end
  52748. });
  52749. this._rangeReaders.push(reader);
  52750. return reader;
  52751. },
  52752. cancelAllRequests: function PDFWorkerStream_cancelAllRequests(reason) {
  52753. if (this._fullRequestReader) {
  52754. this._fullRequestReader.cancel(reason);
  52755. }
  52756. var readers = this._rangeReaders.slice(0);
  52757. readers.forEach(function (rangeReader) {
  52758. rangeReader.cancel(reason);
  52759. });
  52760. }
  52761. };
  52762. /** @implements {IPDFStreamReader} */
  52763. function PDFWorkerStreamReader(stream, queuedChunks) {
  52764. this._stream = stream;
  52765. this._done = false;
  52766. this._queuedChunks = queuedChunks || [];
  52767. this._requests = [];
  52768. this._headersReady = Promise.resolve();
  52769. stream._fullRequestReader = this;
  52770. this.onProgress = null;
  52771. }
  52772. // not used
  52773. PDFWorkerStreamReader.prototype = {
  52774. _enqueue: function PDFWorkerStreamReader_enqueue(chunk) {
  52775. if (this._done) {
  52776. return;
  52777. }
  52778. // ignore new data
  52779. if (this._requests.length > 0) {
  52780. var requestCapability = this._requests.shift();
  52781. requestCapability.resolve({
  52782. value: chunk,
  52783. done: false
  52784. });
  52785. return;
  52786. }
  52787. this._queuedChunks.push(chunk);
  52788. },
  52789. get headersReady() {
  52790. return this._headersReady;
  52791. },
  52792. get isRangeSupported() {
  52793. return this._stream._isRangeSupported;
  52794. },
  52795. get isStreamingSupported() {
  52796. return this._stream._isStreamingSupported;
  52797. },
  52798. get contentLength() {
  52799. return this._stream._contentLength;
  52800. },
  52801. read: function PDFWorkerStreamReader_read() {
  52802. if (this._queuedChunks.length > 0) {
  52803. var chunk = this._queuedChunks.shift();
  52804. return Promise.resolve({
  52805. value: chunk,
  52806. done: false
  52807. });
  52808. }
  52809. if (this._done) {
  52810. return Promise.resolve({
  52811. value: undefined,
  52812. done: true
  52813. });
  52814. }
  52815. var requestCapability = createPromiseCapability();
  52816. this._requests.push(requestCapability);
  52817. return requestCapability.promise;
  52818. },
  52819. cancel: function PDFWorkerStreamReader_cancel(reason) {
  52820. this._done = true;
  52821. this._requests.forEach(function (requestCapability) {
  52822. requestCapability.resolve({
  52823. value: undefined,
  52824. done: true
  52825. });
  52826. });
  52827. this._requests = [];
  52828. }
  52829. };
  52830. /** @implements {IPDFStreamRangeReader} */
  52831. function PDFWorkerStreamRangeReader(stream, begin, end) {
  52832. this._stream = stream;
  52833. this._begin = begin;
  52834. this._end = end;
  52835. this._queuedChunk = null;
  52836. this._requests = [];
  52837. this._done = false;
  52838. this.onProgress = null;
  52839. }
  52840. PDFWorkerStreamRangeReader.prototype = {
  52841. _enqueue: function PDFWorkerStreamRangeReader_enqueue(chunk) {
  52842. if (this._done) {
  52843. return;
  52844. }
  52845. // ignore new data
  52846. if (this._requests.length === 0) {
  52847. this._queuedChunk = chunk;
  52848. } else {
  52849. var requestsCapability = this._requests.shift();
  52850. requestsCapability.resolve({
  52851. value: chunk,
  52852. done: false
  52853. });
  52854. this._requests.forEach(function (requestCapability) {
  52855. requestCapability.resolve({
  52856. value: undefined,
  52857. done: true
  52858. });
  52859. });
  52860. this._requests = [];
  52861. }
  52862. this._done = true;
  52863. this._stream._removeRangeReader(this);
  52864. },
  52865. get isStreamingSupported() {
  52866. return false;
  52867. },
  52868. read: function PDFWorkerStreamRangeReader_read() {
  52869. if (this._queuedChunk) {
  52870. return Promise.resolve({
  52871. value: this._queuedChunk,
  52872. done: false
  52873. });
  52874. }
  52875. if (this._done) {
  52876. return Promise.resolve({
  52877. value: undefined,
  52878. done: true
  52879. });
  52880. }
  52881. var requestCapability = createPromiseCapability();
  52882. this._requests.push(requestCapability);
  52883. return requestCapability.promise;
  52884. },
  52885. cancel: function PDFWorkerStreamRangeReader_cancel(reason) {
  52886. this._done = true;
  52887. this._requests.forEach(function (requestCapability) {
  52888. requestCapability.resolve({
  52889. value: undefined,
  52890. done: true
  52891. });
  52892. });
  52893. this._requests = [];
  52894. this._stream._removeRangeReader(this);
  52895. }
  52896. };
  52897. return PDFWorkerStream;
  52898. }();
  52899. /** @type IPDFStream */
  52900. var PDFNetworkStream;
  52901. /**
  52902. * Sets PDFNetworkStream class to be used as alternative PDF data transport.
  52903. * @param {IPDFStream} cls - the PDF data transport.
  52904. */
  52905. function setPDFNetworkStreamClass(cls) {
  52906. PDFNetworkStream = cls;
  52907. }
  52908. var WorkerMessageHandler = {
  52909. setup: function wphSetup(handler, port) {
  52910. var testMessageProcessed = false;
  52911. handler.on('test', function wphSetupTest(data) {
  52912. if (testMessageProcessed) {
  52913. return;
  52914. }
  52915. // we already processed 'test' message once
  52916. testMessageProcessed = true;
  52917. // check if Uint8Array can be sent to worker
  52918. if (!(data instanceof Uint8Array)) {
  52919. handler.send('test', 'main', false);
  52920. return;
  52921. }
  52922. // making sure postMessage transfers are working
  52923. var supportTransfers = data[0] === 255;
  52924. handler.postMessageTransfers = supportTransfers;
  52925. // check if the response property is supported by xhr
  52926. var xhr = new XMLHttpRequest();
  52927. var responseExists = 'response' in xhr;
  52928. // check if the property is actually implemented
  52929. try {
  52930. var dummy = xhr.responseType;
  52931. } catch (e) {
  52932. responseExists = false;
  52933. }
  52934. if (!responseExists) {
  52935. handler.send('test', false);
  52936. return;
  52937. }
  52938. handler.send('test', {
  52939. supportTypedArray: true,
  52940. supportTransfers: supportTransfers
  52941. });
  52942. });
  52943. handler.on('configure', function wphConfigure(data) {
  52944. setVerbosityLevel(data.verbosity);
  52945. });
  52946. handler.on('GetDocRequest', function wphSetupDoc(data) {
  52947. return WorkerMessageHandler.createDocumentHandler(data, port);
  52948. });
  52949. },
  52950. createDocumentHandler: function wphCreateDocumentHandler(docParams, port) {
  52951. // This context is actually holds references on pdfManager and handler,
  52952. // until the latter is destroyed.
  52953. var pdfManager;
  52954. var terminated = false;
  52955. var cancelXHRs = null;
  52956. var WorkerTasks = [];
  52957. var docId = docParams.docId;
  52958. var docBaseUrl = docParams.docBaseUrl;
  52959. var workerHandlerName = docParams.docId + '_worker';
  52960. var handler = new MessageHandler(workerHandlerName, docId, port);
  52961. // Ensure that postMessage transfers are correctly enabled/disabled,
  52962. // to prevent "DataCloneError" in older versions of IE (see issue 6957).
  52963. handler.postMessageTransfers = docParams.postMessageTransfers;
  52964. function ensureNotTerminated() {
  52965. if (terminated) {
  52966. throw new Error('Worker was terminated');
  52967. }
  52968. }
  52969. function startWorkerTask(task) {
  52970. WorkerTasks.push(task);
  52971. }
  52972. function finishWorkerTask(task) {
  52973. task.finish();
  52974. var i = WorkerTasks.indexOf(task);
  52975. WorkerTasks.splice(i, 1);
  52976. }
  52977. function loadDocument(recoveryMode) {
  52978. var loadDocumentCapability = createPromiseCapability();
  52979. var parseSuccess = function parseSuccess() {
  52980. var numPagesPromise = pdfManager.ensureDoc('numPages');
  52981. var fingerprintPromise = pdfManager.ensureDoc('fingerprint');
  52982. var encryptedPromise = pdfManager.ensureXRef('encrypt');
  52983. Promise.all([
  52984. numPagesPromise,
  52985. fingerprintPromise,
  52986. encryptedPromise
  52987. ]).then(function onDocReady(results) {
  52988. var doc = {
  52989. numPages: results[0],
  52990. fingerprint: results[1],
  52991. encrypted: !!results[2]
  52992. };
  52993. loadDocumentCapability.resolve(doc);
  52994. }, parseFailure);
  52995. };
  52996. var parseFailure = function parseFailure(e) {
  52997. loadDocumentCapability.reject(e);
  52998. };
  52999. pdfManager.ensureDoc('checkHeader', []).then(function () {
  53000. pdfManager.ensureDoc('parseStartXRef', []).then(function () {
  53001. pdfManager.ensureDoc('parse', [recoveryMode]).then(parseSuccess, parseFailure);
  53002. }, parseFailure);
  53003. }, parseFailure);
  53004. return loadDocumentCapability.promise;
  53005. }
  53006. function getPdfManager(data, evaluatorOptions) {
  53007. var pdfManagerCapability = createPromiseCapability();
  53008. var pdfManager;
  53009. var source = data.source;
  53010. if (source.data) {
  53011. try {
  53012. pdfManager = new LocalPdfManager(docId, source.data, source.password, evaluatorOptions, docBaseUrl);
  53013. pdfManagerCapability.resolve(pdfManager);
  53014. } catch (ex) {
  53015. pdfManagerCapability.reject(ex);
  53016. }
  53017. return pdfManagerCapability.promise;
  53018. }
  53019. var pdfStream;
  53020. try {
  53021. if (source.chunkedViewerLoading) {
  53022. pdfStream = new PDFWorkerStream(source, handler);
  53023. } else {
  53024. assert(PDFNetworkStream, 'pdfjs/core/network module is not loaded');
  53025. pdfStream = new PDFNetworkStream(data);
  53026. }
  53027. } catch (ex) {
  53028. pdfManagerCapability.reject(ex);
  53029. return pdfManagerCapability.promise;
  53030. }
  53031. var fullRequest = pdfStream.getFullReader();
  53032. fullRequest.headersReady.then(function () {
  53033. if (!fullRequest.isStreamingSupported || !fullRequest.isRangeSupported) {
  53034. // If stream or range are disabled, it's our only way to report
  53035. // loading progress.
  53036. fullRequest.onProgress = function (evt) {
  53037. handler.send('DocProgress', {
  53038. loaded: evt.loaded,
  53039. total: evt.total
  53040. });
  53041. };
  53042. }
  53043. if (!fullRequest.isRangeSupported) {
  53044. return;
  53045. }
  53046. // We don't need auto-fetch when streaming is enabled.
  53047. var disableAutoFetch = source.disableAutoFetch || fullRequest.isStreamingSupported;
  53048. pdfManager = new NetworkPdfManager(docId, pdfStream, {
  53049. msgHandler: handler,
  53050. url: source.url,
  53051. password: source.password,
  53052. length: fullRequest.contentLength,
  53053. disableAutoFetch: disableAutoFetch,
  53054. rangeChunkSize: source.rangeChunkSize
  53055. }, evaluatorOptions, docBaseUrl);
  53056. pdfManagerCapability.resolve(pdfManager);
  53057. cancelXHRs = null;
  53058. }).catch(function (reason) {
  53059. pdfManagerCapability.reject(reason);
  53060. cancelXHRs = null;
  53061. });
  53062. var cachedChunks = [], loaded = 0;
  53063. var flushChunks = function () {
  53064. var pdfFile = arraysToBytes(cachedChunks);
  53065. if (source.length && pdfFile.length !== source.length) {
  53066. warn('reported HTTP length is different from actual');
  53067. }
  53068. // the data is array, instantiating directly from it
  53069. try {
  53070. pdfManager = new LocalPdfManager(docId, pdfFile, source.password, evaluatorOptions, docBaseUrl);
  53071. pdfManagerCapability.resolve(pdfManager);
  53072. } catch (ex) {
  53073. pdfManagerCapability.reject(ex);
  53074. }
  53075. cachedChunks = [];
  53076. };
  53077. var readPromise = new Promise(function (resolve, reject) {
  53078. var readChunk = function (chunk) {
  53079. try {
  53080. ensureNotTerminated();
  53081. if (chunk.done) {
  53082. if (!pdfManager) {
  53083. flushChunks();
  53084. }
  53085. cancelXHRs = null;
  53086. return;
  53087. }
  53088. var data = chunk.value;
  53089. loaded += arrayByteLength(data);
  53090. if (!fullRequest.isStreamingSupported) {
  53091. handler.send('DocProgress', {
  53092. loaded: loaded,
  53093. total: Math.max(loaded, fullRequest.contentLength || 0)
  53094. });
  53095. }
  53096. if (pdfManager) {
  53097. pdfManager.sendProgressiveData(data);
  53098. } else {
  53099. cachedChunks.push(data);
  53100. }
  53101. fullRequest.read().then(readChunk, reject);
  53102. } catch (e) {
  53103. reject(e);
  53104. }
  53105. };
  53106. fullRequest.read().then(readChunk, reject);
  53107. });
  53108. readPromise.catch(function (e) {
  53109. pdfManagerCapability.reject(e);
  53110. cancelXHRs = null;
  53111. });
  53112. cancelXHRs = function () {
  53113. pdfStream.cancelAllRequests('abort');
  53114. };
  53115. return pdfManagerCapability.promise;
  53116. }
  53117. var setupDoc = function (data) {
  53118. var onSuccess = function (doc) {
  53119. ensureNotTerminated();
  53120. handler.send('GetDoc', { pdfInfo: doc });
  53121. };
  53122. var onFailure = function (e) {
  53123. if (e instanceof PasswordException) {
  53124. if (e.code === PasswordResponses.NEED_PASSWORD) {
  53125. handler.send('NeedPassword', e);
  53126. } else if (e.code === PasswordResponses.INCORRECT_PASSWORD) {
  53127. handler.send('IncorrectPassword', e);
  53128. }
  53129. } else if (e instanceof InvalidPDFException) {
  53130. handler.send('InvalidPDF', e);
  53131. } else if (e instanceof MissingPDFException) {
  53132. handler.send('MissingPDF', e);
  53133. } else if (e instanceof UnexpectedResponseException) {
  53134. handler.send('UnexpectedResponse', e);
  53135. } else {
  53136. handler.send('UnknownError', new UnknownErrorException(e.message, e.toString()));
  53137. }
  53138. };
  53139. ensureNotTerminated();
  53140. var cMapOptions = {
  53141. url: data.cMapUrl === undefined ? null : data.cMapUrl,
  53142. packed: data.cMapPacked === true
  53143. };
  53144. var evaluatorOptions = {
  53145. forceDataSchema: data.disableCreateObjectURL,
  53146. maxImageSize: data.maxImageSize === undefined ? -1 : data.maxImageSize,
  53147. disableFontFace: data.disableFontFace,
  53148. cMapOptions: cMapOptions
  53149. };
  53150. getPdfManager(data, evaluatorOptions).then(function (newPdfManager) {
  53151. if (terminated) {
  53152. // We were in a process of setting up the manager, but it got
  53153. // terminated in the middle.
  53154. newPdfManager.terminate();
  53155. throw new Error('Worker was terminated');
  53156. }
  53157. pdfManager = newPdfManager;
  53158. handler.send('PDFManagerReady', null);
  53159. pdfManager.onLoadedStream().then(function (stream) {
  53160. handler.send('DataLoaded', { length: stream.bytes.byteLength });
  53161. });
  53162. }).then(function pdfManagerReady() {
  53163. ensureNotTerminated();
  53164. loadDocument(false).then(onSuccess, function loadFailure(ex) {
  53165. ensureNotTerminated();
  53166. // Try again with recoveryMode == true
  53167. if (!(ex instanceof XRefParseException)) {
  53168. if (ex instanceof PasswordException) {
  53169. // after password exception prepare to receive a new password
  53170. // to repeat loading
  53171. pdfManager.passwordChanged().then(pdfManagerReady);
  53172. }
  53173. onFailure(ex);
  53174. return;
  53175. }
  53176. pdfManager.requestLoadedStream();
  53177. pdfManager.onLoadedStream().then(function () {
  53178. ensureNotTerminated();
  53179. loadDocument(true).then(onSuccess, onFailure);
  53180. });
  53181. }, onFailure);
  53182. }, onFailure);
  53183. };
  53184. handler.on('GetPage', function wphSetupGetPage(data) {
  53185. return pdfManager.getPage(data.pageIndex).then(function (page) {
  53186. var rotatePromise = pdfManager.ensure(page, 'rotate');
  53187. var refPromise = pdfManager.ensure(page, 'ref');
  53188. var viewPromise = pdfManager.ensure(page, 'view');
  53189. return Promise.all([
  53190. rotatePromise,
  53191. refPromise,
  53192. viewPromise
  53193. ]).then(function (results) {
  53194. return {
  53195. rotate: results[0],
  53196. ref: results[1],
  53197. view: results[2]
  53198. };
  53199. });
  53200. });
  53201. });
  53202. handler.on('GetPageIndex', function wphSetupGetPageIndex(data) {
  53203. var ref = new Ref(data.ref.num, data.ref.gen);
  53204. var catalog = pdfManager.pdfDocument.catalog;
  53205. return catalog.getPageIndex(ref);
  53206. });
  53207. handler.on('GetDestinations', function wphSetupGetDestinations(data) {
  53208. return pdfManager.ensureCatalog('destinations');
  53209. });
  53210. handler.on('GetDestination', function wphSetupGetDestination(data) {
  53211. return pdfManager.ensureCatalog('getDestination', [data.id]);
  53212. });
  53213. handler.on('GetPageLabels', function wphSetupGetPageLabels(data) {
  53214. return pdfManager.ensureCatalog('pageLabels');
  53215. });
  53216. handler.on('GetAttachments', function wphSetupGetAttachments(data) {
  53217. return pdfManager.ensureCatalog('attachments');
  53218. });
  53219. handler.on('GetJavaScript', function wphSetupGetJavaScript(data) {
  53220. return pdfManager.ensureCatalog('javaScript');
  53221. });
  53222. handler.on('GetOutline', function wphSetupGetOutline(data) {
  53223. return pdfManager.ensureCatalog('documentOutline');
  53224. });
  53225. handler.on('GetMetadata', function wphSetupGetMetadata(data) {
  53226. return Promise.all([
  53227. pdfManager.ensureDoc('documentInfo'),
  53228. pdfManager.ensureCatalog('metadata')
  53229. ]);
  53230. });
  53231. handler.on('GetData', function wphSetupGetData(data) {
  53232. pdfManager.requestLoadedStream();
  53233. return pdfManager.onLoadedStream().then(function (stream) {
  53234. return stream.bytes;
  53235. });
  53236. });
  53237. handler.on('GetStats', function wphSetupGetStats(data) {
  53238. return pdfManager.pdfDocument.xref.stats;
  53239. });
  53240. handler.on('UpdatePassword', function wphSetupUpdatePassword(data) {
  53241. pdfManager.updatePassword(data);
  53242. });
  53243. handler.on('GetAnnotations', function wphSetupGetAnnotations(data) {
  53244. return pdfManager.getPage(data.pageIndex).then(function (page) {
  53245. return pdfManager.ensure(page, 'getAnnotationsData', [data.intent]);
  53246. });
  53247. });
  53248. handler.on('RenderPageRequest', function wphSetupRenderPage(data) {
  53249. var pageIndex = data.pageIndex;
  53250. pdfManager.getPage(pageIndex).then(function (page) {
  53251. var task = new WorkerTask('RenderPageRequest: page ' + pageIndex);
  53252. startWorkerTask(task);
  53253. var pageNum = pageIndex + 1;
  53254. var start = Date.now();
  53255. // Pre compile the pdf page and fetch the fonts/images.
  53256. page.getOperatorList(handler, task, data.intent, data.renderInteractiveForms).then(function (operatorList) {
  53257. finishWorkerTask(task);
  53258. info('page=' + pageNum + ' - getOperatorList: time=' + (Date.now() - start) + 'ms, len=' + operatorList.totalLength);
  53259. }, function (e) {
  53260. finishWorkerTask(task);
  53261. if (task.terminated) {
  53262. return;
  53263. }
  53264. // ignoring errors from the terminated thread
  53265. // For compatibility with older behavior, generating unknown
  53266. // unsupported feature notification on errors.
  53267. handler.send('UnsupportedFeature', { featureId: UNSUPPORTED_FEATURES.unknown });
  53268. var minimumStackMessage = 'worker.js: while trying to getPage() and getOperatorList()';
  53269. var wrappedException;
  53270. // Turn the error into an obj that can be serialized
  53271. if (typeof e === 'string') {
  53272. wrappedException = {
  53273. message: e,
  53274. stack: minimumStackMessage
  53275. };
  53276. } else if (typeof e === 'object') {
  53277. wrappedException = {
  53278. message: e.message || e.toString(),
  53279. stack: e.stack || minimumStackMessage
  53280. };
  53281. } else {
  53282. wrappedException = {
  53283. message: 'Unknown exception type: ' + typeof e,
  53284. stack: minimumStackMessage
  53285. };
  53286. }
  53287. handler.send('PageError', {
  53288. pageNum: pageNum,
  53289. error: wrappedException,
  53290. intent: data.intent
  53291. });
  53292. });
  53293. });
  53294. }, this);
  53295. handler.on('GetTextContent', function wphExtractText(data) {
  53296. var pageIndex = data.pageIndex;
  53297. var normalizeWhitespace = data.normalizeWhitespace;
  53298. var combineTextItems = data.combineTextItems;
  53299. return pdfManager.getPage(pageIndex).then(function (page) {
  53300. var task = new WorkerTask('GetTextContent: page ' + pageIndex);
  53301. startWorkerTask(task);
  53302. var pageNum = pageIndex + 1;
  53303. var start = Date.now();
  53304. return page.extractTextContent(task, normalizeWhitespace, combineTextItems).then(function (textContent) {
  53305. finishWorkerTask(task);
  53306. info('text indexing: page=' + pageNum + ' - time=' + (Date.now() - start) + 'ms');
  53307. return textContent;
  53308. }, function (reason) {
  53309. finishWorkerTask(task);
  53310. if (task.terminated) {
  53311. return;
  53312. }
  53313. // ignoring errors from the terminated thread
  53314. throw reason;
  53315. });
  53316. });
  53317. });
  53318. handler.on('Cleanup', function wphCleanup(data) {
  53319. return pdfManager.cleanup();
  53320. });
  53321. handler.on('Terminate', function wphTerminate(data) {
  53322. terminated = true;
  53323. if (pdfManager) {
  53324. pdfManager.terminate();
  53325. pdfManager = null;
  53326. }
  53327. if (cancelXHRs) {
  53328. cancelXHRs();
  53329. }
  53330. var waitOn = [];
  53331. WorkerTasks.forEach(function (task) {
  53332. waitOn.push(task.finished);
  53333. task.terminate();
  53334. });
  53335. return Promise.all(waitOn).then(function () {
  53336. // Notice that even if we destroying handler, resolved response promise
  53337. // must be sent back.
  53338. handler.destroy();
  53339. handler = null;
  53340. });
  53341. });
  53342. handler.on('Ready', function wphReady(data) {
  53343. setupDoc(docParams);
  53344. docParams = null;
  53345. });
  53346. // we don't need docParams anymore -- saving memory.
  53347. return workerHandlerName;
  53348. }
  53349. };
  53350. function initializeWorker() {
  53351. if (!('console' in globalScope)) {
  53352. var consoleTimer = {};
  53353. var workerConsole = {
  53354. log: function log() {
  53355. var args = Array.prototype.slice.call(arguments);
  53356. globalScope.postMessage({
  53357. targetName: 'main',
  53358. action: 'console_log',
  53359. data: args
  53360. });
  53361. },
  53362. error: function error() {
  53363. var args = Array.prototype.slice.call(arguments);
  53364. globalScope.postMessage({
  53365. targetName: 'main',
  53366. action: 'console_error',
  53367. data: args
  53368. });
  53369. throw 'pdf.js execution error';
  53370. },
  53371. time: function time(name) {
  53372. consoleTimer[name] = Date.now();
  53373. },
  53374. timeEnd: function timeEnd(name) {
  53375. var time = consoleTimer[name];
  53376. if (!time) {
  53377. error('Unknown timer name ' + name);
  53378. }
  53379. this.log('Timer:', name, Date.now() - time);
  53380. }
  53381. };
  53382. globalScope.console = workerConsole;
  53383. }
  53384. var handler = new MessageHandler('worker', 'main', self);
  53385. WorkerMessageHandler.setup(handler, self);
  53386. handler.send('ready', null);
  53387. }
  53388. // Worker thread (and not node.js)?
  53389. if (typeof window === 'undefined' && !(typeof module !== 'undefined' && module.require)) {
  53390. initializeWorker();
  53391. }
  53392. exports.setPDFNetworkStreamClass = setPDFNetworkStreamClass;
  53393. exports.WorkerTask = WorkerTask;
  53394. exports.WorkerMessageHandler = WorkerMessageHandler;
  53395. }));
  53396. (function (root, factory) {
  53397. factory(root.pdfjsCoreNetwork = {}, root.pdfjsSharedUtil, root.pdfjsCoreWorker);
  53398. }(this, function (exports, sharedUtil, coreWorker) {
  53399. var OK_RESPONSE = 200;
  53400. var PARTIAL_CONTENT_RESPONSE = 206;
  53401. function NetworkManager(url, args) {
  53402. this.url = url;
  53403. args = args || {};
  53404. this.isHttp = /^https?:/i.test(url);
  53405. this.httpHeaders = this.isHttp && args.httpHeaders || {};
  53406. this.withCredentials = args.withCredentials || false;
  53407. this.getXhr = args.getXhr || function NetworkManager_getXhr() {
  53408. return new XMLHttpRequest();
  53409. };
  53410. this.currXhrId = 0;
  53411. this.pendingRequests = Object.create(null);
  53412. this.loadedRequests = Object.create(null);
  53413. }
  53414. function getArrayBuffer(xhr) {
  53415. var data = xhr.response;
  53416. if (typeof data !== 'string') {
  53417. return data;
  53418. }
  53419. var length = data.length;
  53420. var array = new Uint8Array(length);
  53421. for (var i = 0; i < length; i++) {
  53422. array[i] = data.charCodeAt(i) & 0xFF;
  53423. }
  53424. return array.buffer;
  53425. }
  53426. var supportsMozChunked = function supportsMozChunkedClosure() {
  53427. try {
  53428. var x = new XMLHttpRequest();
  53429. // Firefox 37- required .open() to be called before setting responseType.
  53430. // https://bugzilla.mozilla.org/show_bug.cgi?id=707484
  53431. // Even though the URL is not visited, .open() could fail if the URL is
  53432. // blocked, e.g. via the connect-src CSP directive or the NoScript addon.
  53433. // When this error occurs, this feature detection method will mistakenly
  53434. // report that moz-chunked-arraybuffer is not supported in Firefox 37-.
  53435. x.open('GET', 'https://example.com');
  53436. x.responseType = 'moz-chunked-arraybuffer';
  53437. return x.responseType === 'moz-chunked-arraybuffer';
  53438. } catch (e) {
  53439. return false;
  53440. }
  53441. }();
  53442. NetworkManager.prototype = {
  53443. requestRange: function NetworkManager_requestRange(begin, end, listeners) {
  53444. var args = {
  53445. begin: begin,
  53446. end: end
  53447. };
  53448. for (var prop in listeners) {
  53449. args[prop] = listeners[prop];
  53450. }
  53451. return this.request(args);
  53452. },
  53453. requestFull: function NetworkManager_requestFull(listeners) {
  53454. return this.request(listeners);
  53455. },
  53456. request: function NetworkManager_request(args) {
  53457. var xhr = this.getXhr();
  53458. var xhrId = this.currXhrId++;
  53459. var pendingRequest = this.pendingRequests[xhrId] = { xhr: xhr };
  53460. xhr.open('GET', this.url);
  53461. xhr.withCredentials = this.withCredentials;
  53462. for (var property in this.httpHeaders) {
  53463. var value = this.httpHeaders[property];
  53464. if (typeof value === 'undefined') {
  53465. continue;
  53466. }
  53467. xhr.setRequestHeader(property, value);
  53468. }
  53469. if (this.isHttp && 'begin' in args && 'end' in args) {
  53470. var rangeStr = args.begin + '-' + (args.end - 1);
  53471. xhr.setRequestHeader('Range', 'bytes=' + rangeStr);
  53472. pendingRequest.expectedStatus = 206;
  53473. } else {
  53474. pendingRequest.expectedStatus = 200;
  53475. }
  53476. var useMozChunkedLoading = supportsMozChunked && !!args.onProgressiveData;
  53477. if (useMozChunkedLoading) {
  53478. xhr.responseType = 'moz-chunked-arraybuffer';
  53479. pendingRequest.onProgressiveData = args.onProgressiveData;
  53480. pendingRequest.mozChunked = true;
  53481. } else {
  53482. xhr.responseType = 'arraybuffer';
  53483. }
  53484. if (args.onError) {
  53485. xhr.onerror = function (evt) {
  53486. args.onError(xhr.status);
  53487. };
  53488. }
  53489. xhr.onreadystatechange = this.onStateChange.bind(this, xhrId);
  53490. xhr.onprogress = this.onProgress.bind(this, xhrId);
  53491. pendingRequest.onHeadersReceived = args.onHeadersReceived;
  53492. pendingRequest.onDone = args.onDone;
  53493. pendingRequest.onError = args.onError;
  53494. pendingRequest.onProgress = args.onProgress;
  53495. xhr.send(null);
  53496. return xhrId;
  53497. },
  53498. onProgress: function NetworkManager_onProgress(xhrId, evt) {
  53499. var pendingRequest = this.pendingRequests[xhrId];
  53500. if (!pendingRequest) {
  53501. // Maybe abortRequest was called...
  53502. return;
  53503. }
  53504. if (pendingRequest.mozChunked) {
  53505. var chunk = getArrayBuffer(pendingRequest.xhr);
  53506. pendingRequest.onProgressiveData(chunk);
  53507. }
  53508. var onProgress = pendingRequest.onProgress;
  53509. if (onProgress) {
  53510. onProgress(evt);
  53511. }
  53512. },
  53513. onStateChange: function NetworkManager_onStateChange(xhrId, evt) {
  53514. var pendingRequest = this.pendingRequests[xhrId];
  53515. if (!pendingRequest) {
  53516. // Maybe abortRequest was called...
  53517. return;
  53518. }
  53519. var xhr = pendingRequest.xhr;
  53520. if (xhr.readyState >= 2 && pendingRequest.onHeadersReceived) {
  53521. pendingRequest.onHeadersReceived();
  53522. delete pendingRequest.onHeadersReceived;
  53523. }
  53524. if (xhr.readyState !== 4) {
  53525. return;
  53526. }
  53527. if (!(xhrId in this.pendingRequests)) {
  53528. // The XHR request might have been aborted in onHeadersReceived()
  53529. // callback, in which case we should abort request
  53530. return;
  53531. }
  53532. delete this.pendingRequests[xhrId];
  53533. // success status == 0 can be on ftp, file and other protocols
  53534. if (xhr.status === 0 && this.isHttp) {
  53535. if (pendingRequest.onError) {
  53536. pendingRequest.onError(xhr.status);
  53537. }
  53538. return;
  53539. }
  53540. var xhrStatus = xhr.status || OK_RESPONSE;
  53541. // From http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.2:
  53542. // "A server MAY ignore the Range header". This means it's possible to
  53543. // get a 200 rather than a 206 response from a range request.
  53544. var ok_response_on_range_request = xhrStatus === OK_RESPONSE && pendingRequest.expectedStatus === PARTIAL_CONTENT_RESPONSE;
  53545. if (!ok_response_on_range_request && xhrStatus !== pendingRequest.expectedStatus) {
  53546. if (pendingRequest.onError) {
  53547. pendingRequest.onError(xhr.status);
  53548. }
  53549. return;
  53550. }
  53551. this.loadedRequests[xhrId] = true;
  53552. var chunk = getArrayBuffer(xhr);
  53553. if (xhrStatus === PARTIAL_CONTENT_RESPONSE) {
  53554. var rangeHeader = xhr.getResponseHeader('Content-Range');
  53555. var matches = /bytes (\d+)-(\d+)\/(\d+)/.exec(rangeHeader);
  53556. var begin = parseInt(matches[1], 10);
  53557. pendingRequest.onDone({
  53558. begin: begin,
  53559. chunk: chunk
  53560. });
  53561. } else if (pendingRequest.onProgressiveData) {
  53562. pendingRequest.onDone(null);
  53563. } else if (chunk) {
  53564. pendingRequest.onDone({
  53565. begin: 0,
  53566. chunk: chunk
  53567. });
  53568. } else if (pendingRequest.onError) {
  53569. pendingRequest.onError(xhr.status);
  53570. }
  53571. },
  53572. hasPendingRequests: function NetworkManager_hasPendingRequests() {
  53573. for (var xhrId in this.pendingRequests) {
  53574. return true;
  53575. }
  53576. return false;
  53577. },
  53578. getRequestXhr: function NetworkManager_getXhr(xhrId) {
  53579. return this.pendingRequests[xhrId].xhr;
  53580. },
  53581. isStreamingRequest: function NetworkManager_isStreamingRequest(xhrId) {
  53582. return !!this.pendingRequests[xhrId].onProgressiveData;
  53583. },
  53584. isPendingRequest: function NetworkManager_isPendingRequest(xhrId) {
  53585. return xhrId in this.pendingRequests;
  53586. },
  53587. isLoadedRequest: function NetworkManager_isLoadedRequest(xhrId) {
  53588. return xhrId in this.loadedRequests;
  53589. },
  53590. abortAllRequests: function NetworkManager_abortAllRequests() {
  53591. for (var xhrId in this.pendingRequests) {
  53592. this.abortRequest(xhrId | 0);
  53593. }
  53594. },
  53595. abortRequest: function NetworkManager_abortRequest(xhrId) {
  53596. var xhr = this.pendingRequests[xhrId].xhr;
  53597. delete this.pendingRequests[xhrId];
  53598. xhr.abort();
  53599. }
  53600. };
  53601. var assert = sharedUtil.assert;
  53602. var createPromiseCapability = sharedUtil.createPromiseCapability;
  53603. var isInt = sharedUtil.isInt;
  53604. var MissingPDFException = sharedUtil.MissingPDFException;
  53605. var UnexpectedResponseException = sharedUtil.UnexpectedResponseException;
  53606. /** @implements {IPDFStream} */
  53607. function PDFNetworkStream(options) {
  53608. this._options = options;
  53609. var source = options.source;
  53610. this._manager = new NetworkManager(source.url, {
  53611. httpHeaders: source.httpHeaders,
  53612. withCredentials: source.withCredentials
  53613. });
  53614. this._rangeChunkSize = source.rangeChunkSize;
  53615. this._fullRequestReader = null;
  53616. this._rangeRequestReaders = [];
  53617. }
  53618. PDFNetworkStream.prototype = {
  53619. _onRangeRequestReaderClosed: function PDFNetworkStream_onRangeRequestReaderClosed(reader) {
  53620. var i = this._rangeRequestReaders.indexOf(reader);
  53621. if (i >= 0) {
  53622. this._rangeRequestReaders.splice(i, 1);
  53623. }
  53624. },
  53625. getFullReader: function PDFNetworkStream_getFullReader() {
  53626. assert(!this._fullRequestReader);
  53627. this._fullRequestReader = new PDFNetworkStreamFullRequestReader(this._manager, this._options);
  53628. return this._fullRequestReader;
  53629. },
  53630. getRangeReader: function PDFNetworkStream_getRangeReader(begin, end) {
  53631. var reader = new PDFNetworkStreamRangeRequestReader(this._manager, begin, end);
  53632. reader.onClosed = this._onRangeRequestReaderClosed.bind(this);
  53633. this._rangeRequestReaders.push(reader);
  53634. return reader;
  53635. },
  53636. cancelAllRequests: function PDFNetworkStream_cancelAllRequests(reason) {
  53637. if (this._fullRequestReader) {
  53638. this._fullRequestReader.cancel(reason);
  53639. }
  53640. var readers = this._rangeRequestReaders.slice(0);
  53641. readers.forEach(function (reader) {
  53642. reader.cancel(reason);
  53643. });
  53644. }
  53645. };
  53646. /** @implements {IPDFStreamReader} */
  53647. function PDFNetworkStreamFullRequestReader(manager, options) {
  53648. this._manager = manager;
  53649. var source = options.source;
  53650. var args = {
  53651. onHeadersReceived: this._onHeadersReceived.bind(this),
  53652. onProgressiveData: source.disableStream ? null : this._onProgressiveData.bind(this),
  53653. onDone: this._onDone.bind(this),
  53654. onError: this._onError.bind(this),
  53655. onProgress: this._onProgress.bind(this)
  53656. };
  53657. this._url = source.url;
  53658. this._fullRequestId = manager.requestFull(args);
  53659. this._headersReceivedCapability = createPromiseCapability();
  53660. this._disableRange = options.disableRange || false;
  53661. this._contentLength = source.length;
  53662. // optional
  53663. this._rangeChunkSize = source.rangeChunkSize;
  53664. if (!this._rangeChunkSize && !this._disableRange) {
  53665. this._disableRange = true;
  53666. }
  53667. this._isStreamingSupported = false;
  53668. this._isRangeSupported = false;
  53669. this._cachedChunks = [];
  53670. this._requests = [];
  53671. this._done = false;
  53672. this._storedError = undefined;
  53673. this.onProgress = null;
  53674. }
  53675. PDFNetworkStreamFullRequestReader.prototype = {
  53676. _validateRangeRequestCapabilities: function PDFNetworkStreamFullRequestReader_validateRangeRequestCapabilities() {
  53677. if (this._disableRange) {
  53678. return false;
  53679. }
  53680. var networkManager = this._manager;
  53681. var fullRequestXhrId = this._fullRequestId;
  53682. var fullRequestXhr = networkManager.getRequestXhr(fullRequestXhrId);
  53683. if (fullRequestXhr.getResponseHeader('Accept-Ranges') !== 'bytes') {
  53684. return false;
  53685. }
  53686. var contentEncoding = fullRequestXhr.getResponseHeader('Content-Encoding') || 'identity';
  53687. if (contentEncoding !== 'identity') {
  53688. return false;
  53689. }
  53690. var length = fullRequestXhr.getResponseHeader('Content-Length');
  53691. length = parseInt(length, 10);
  53692. if (!isInt(length)) {
  53693. return false;
  53694. }
  53695. this._contentLength = length;
  53696. // setting right content length
  53697. if (length <= 2 * this._rangeChunkSize) {
  53698. // The file size is smaller than the size of two chunks, so it does
  53699. // not make any sense to abort the request and retry with a range
  53700. // request.
  53701. return false;
  53702. }
  53703. return true;
  53704. },
  53705. _onHeadersReceived: function PDFNetworkStreamFullRequestReader_onHeadersReceived() {
  53706. if (this._validateRangeRequestCapabilities()) {
  53707. this._isRangeSupported = true;
  53708. }
  53709. var networkManager = this._manager;
  53710. var fullRequestXhrId = this._fullRequestId;
  53711. if (networkManager.isStreamingRequest(fullRequestXhrId)) {
  53712. // We can continue fetching when progressive loading is enabled,
  53713. // and we don't need the autoFetch feature.
  53714. this._isStreamingSupported = true;
  53715. } else if (this._isRangeSupported) {
  53716. // NOTE: by cancelling the full request, and then issuing range
  53717. // requests, there will be an issue for sites where you can only
  53718. // request the pdf once. However, if this is the case, then the
  53719. // server should not be returning that it can support range
  53720. // requests.
  53721. networkManager.abortRequest(fullRequestXhrId);
  53722. }
  53723. this._headersReceivedCapability.resolve();
  53724. },
  53725. _onProgressiveData: function PDFNetworkStreamFullRequestReader_onProgressiveData(chunk) {
  53726. if (this._requests.length > 0) {
  53727. var requestCapability = this._requests.shift();
  53728. requestCapability.resolve({
  53729. value: chunk,
  53730. done: false
  53731. });
  53732. } else {
  53733. this._cachedChunks.push(chunk);
  53734. }
  53735. },
  53736. _onDone: function PDFNetworkStreamFullRequestReader_onDone(args) {
  53737. if (args) {
  53738. this._onProgressiveData(args.chunk);
  53739. }
  53740. this._done = true;
  53741. if (this._cachedChunks.length > 0) {
  53742. return;
  53743. }
  53744. this._requests.forEach(function (requestCapability) {
  53745. requestCapability.resolve({
  53746. value: undefined,
  53747. done: true
  53748. });
  53749. });
  53750. this._requests = [];
  53751. },
  53752. _onError: function PDFNetworkStreamFullRequestReader_onError(status) {
  53753. var url = this._url;
  53754. var exception;
  53755. if (status === 404 || status === 0 && /^file:/.test(url)) {
  53756. exception = new MissingPDFException('Missing PDF "' + url + '".');
  53757. } else {
  53758. exception = new UnexpectedResponseException('Unexpected server response (' + status + ') while retrieving PDF "' + url + '".', status);
  53759. }
  53760. this._storedError = exception;
  53761. this._headersReceivedCapability.reject(exception);
  53762. this._requests.forEach(function (requestCapability) {
  53763. requestCapability.reject(exception);
  53764. });
  53765. this._requests = [];
  53766. this._cachedChunks = [];
  53767. },
  53768. _onProgress: function PDFNetworkStreamFullRequestReader_onProgress(data) {
  53769. if (this.onProgress) {
  53770. this.onProgress({
  53771. loaded: data.loaded,
  53772. total: data.lengthComputable ? data.total : this._contentLength
  53773. });
  53774. }
  53775. },
  53776. get isRangeSupported() {
  53777. return this._isRangeSupported;
  53778. },
  53779. get isStreamingSupported() {
  53780. return this._isStreamingSupported;
  53781. },
  53782. get contentLength() {
  53783. return this._contentLength;
  53784. },
  53785. get headersReady() {
  53786. return this._headersReceivedCapability.promise;
  53787. },
  53788. read: function PDFNetworkStreamFullRequestReader_read() {
  53789. if (this._storedError) {
  53790. return Promise.reject(this._storedError);
  53791. }
  53792. if (this._cachedChunks.length > 0) {
  53793. var chunk = this._cachedChunks.shift();
  53794. return Promise.resolve(chunk);
  53795. }
  53796. if (this._done) {
  53797. return Promise.resolve({
  53798. value: undefined,
  53799. done: true
  53800. });
  53801. }
  53802. var requestCapability = createPromiseCapability();
  53803. this._requests.push(requestCapability);
  53804. return requestCapability.promise;
  53805. },
  53806. cancel: function PDFNetworkStreamFullRequestReader_cancel(reason) {
  53807. this._done = true;
  53808. this._headersReceivedCapability.reject(reason);
  53809. this._requests.forEach(function (requestCapability) {
  53810. requestCapability.resolve({
  53811. value: undefined,
  53812. done: true
  53813. });
  53814. });
  53815. this._requests = [];
  53816. if (this._manager.isPendingRequest(this._fullRequestId)) {
  53817. this._manager.abortRequest(this._fullRequestId);
  53818. }
  53819. this._fullRequestReader = null;
  53820. }
  53821. };
  53822. /** @implements {IPDFStreamRangeReader} */
  53823. function PDFNetworkStreamRangeRequestReader(manager, begin, end) {
  53824. this._manager = manager;
  53825. var args = {
  53826. onDone: this._onDone.bind(this),
  53827. onProgress: this._onProgress.bind(this)
  53828. };
  53829. this._requestId = manager.requestRange(begin, end, args);
  53830. this._requests = [];
  53831. this._queuedChunk = null;
  53832. this._done = false;
  53833. this.onProgress = null;
  53834. this.onClosed = null;
  53835. }
  53836. PDFNetworkStreamRangeRequestReader.prototype = {
  53837. _close: function PDFNetworkStreamRangeRequestReader_close() {
  53838. if (this.onClosed) {
  53839. this.onClosed(this);
  53840. }
  53841. },
  53842. _onDone: function PDFNetworkStreamRangeRequestReader_onDone(data) {
  53843. var chunk = data.chunk;
  53844. if (this._requests.length > 0) {
  53845. var requestCapability = this._requests.shift();
  53846. requestCapability.resolve({
  53847. value: chunk,
  53848. done: false
  53849. });
  53850. } else {
  53851. this._queuedChunk = chunk;
  53852. }
  53853. this._done = true;
  53854. this._requests.forEach(function (requestCapability) {
  53855. requestCapability.resolve({
  53856. value: undefined,
  53857. done: true
  53858. });
  53859. });
  53860. this._requests = [];
  53861. this._close();
  53862. },
  53863. _onProgress: function PDFNetworkStreamRangeRequestReader_onProgress(evt) {
  53864. if (!this.isStreamingSupported && this.onProgress) {
  53865. this.onProgress({ loaded: evt.loaded });
  53866. }
  53867. },
  53868. get isStreamingSupported() {
  53869. return false;
  53870. },
  53871. // TODO allow progressive range bytes loading
  53872. read: function PDFNetworkStreamRangeRequestReader_read() {
  53873. if (this._queuedChunk !== null) {
  53874. var chunk = this._queuedChunk;
  53875. this._queuedChunk = null;
  53876. return Promise.resolve({
  53877. value: chunk,
  53878. done: false
  53879. });
  53880. }
  53881. if (this._done) {
  53882. return Promise.resolve({
  53883. value: undefined,
  53884. done: true
  53885. });
  53886. }
  53887. var requestCapability = createPromiseCapability();
  53888. this._requests.push(requestCapability);
  53889. return requestCapability.promise;
  53890. },
  53891. cancel: function PDFNetworkStreamRangeRequestReader_cancel(reason) {
  53892. this._done = true;
  53893. this._requests.forEach(function (requestCapability) {
  53894. requestCapability.resolve({
  53895. value: undefined,
  53896. done: true
  53897. });
  53898. });
  53899. this._requests = [];
  53900. if (this._manager.isPendingRequest(this._requestId)) {
  53901. this._manager.abortRequest(this._requestId);
  53902. }
  53903. this._close();
  53904. }
  53905. };
  53906. coreWorker.setPDFNetworkStreamClass(PDFNetworkStream);
  53907. exports.PDFNetworkStream = PDFNetworkStream;
  53908. exports.NetworkManager = NetworkManager;
  53909. }));
  53910. }.call(pdfjsLibs));
  53911. exports.WorkerMessageHandler = pdfjsLibs.pdfjsCoreWorker.WorkerMessageHandler;
  53912. }));